Leaderboard
Popular Content
Showing content with the highest reputation on 08/29/2024 in all areas
-
Here is an attempt to approximate the ITaskbarList3 interface, which was quite a headache for me, since all C++ is new to me https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/shell/taskbar-extensions.md https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-itaskbarlist3 The code may have omissions or excesses, as for the writing where I was stuck and did not understand asking the AI So if someone more experienced has any tips, I'd be happy to hear them everything takes place in the taskbar thumbnail, is displayed when the mouse pointer get over the taskbar icon I put it as a UDF in a separate file so that the main script is cleaner Example.au3 ; https://www.autoitscript.com/forum/topic/212223-itaskbarlist4-interface/?do=edit ;---------------------------------------------------------------------------------------- ; Title...........: Example.au3 ; Description.....: Example howto use ITaskbarList3 interface ; AutoIt Version..: 3.3.16.1 Author: ioa747 Script Version: 0.0.0.3 ; Note............: Testet in Win10 22H2 ;---------------------------------------------------------------------------------------- #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include "TaskbarList.au3" ; * <-- Global $bRedyflag = False ; Register to receive the message that our button is ready GUIRegisterMsg(_WinAPI_RegisterWindowMessage("TaskbarButtonCreated"), "_TaskbarReady") ; Create a sample GUI window Global $hGUI = GUICreate("ITaskbarList Example", 330, 200) Global $idIcon = GUICtrlCreateIcon(@ScriptDir & "\Res\imageres-81.ico", -1, 200, 5, 128, 128) Global $idButton = GUICtrlCreateButton("Click Me", 10, 10) Global $ImageList1 = _GUIImageList_Create(32, 32, 5) _GUIImageList_AddIcon($ImageList1, @ScriptDir & "\Res\prev.ico", 0, True) _GUIImageList_AddIcon($ImageList1, @ScriptDir & "\Res\play.ico", 0, True) _GUIImageList_AddIcon($ImageList1, @ScriptDir & "\Res\stop.ico", 0, True) _GUIImageList_AddIcon($ImageList1, @ScriptDir & "\Res\next.ico", 0, True) GUISetState(@SW_SHOW, $hGUI) Global Enum $iTBtnPrev = 1000, $iTBtnPlay, $iTBtnStop, $iTBtnNext ; Register a handler for WM_COMMAND messages GUIRegisterMsg($WM_COMMAND, "_OnThumbnailButtonClick") ; Add a button to the taskbar thumbnail toolbar ; dwMask, iId, iBitmap, hIcon, szTip, dwFlags Global $dwMask = BitOR($THB_BITMAP, $THB_TOOLTIP, $THB_FLAGS) Global $aTButtons[4][6] = [ _ [$dwMask, $iTBtnPrev, 0, 0, "prev", 0], _ [$dwMask, $iTBtnPlay, 1, 0, "play", 0], _ [$dwMask, $iTBtnStop, 2, 0, "stop", 0], _ [$dwMask, $iTBtnNext, 3, 0, "next", 0]] While Not $bRedyflag Sleep(10) WEnd TB_ThumbBarSetImageList($hGUI, $ImageList1) TB_ThumbBarAddButtons($hGUI, 4, $aTButtons) ; Selects a portion of a window's client area to display as that window's thumbnail in the taskbar. TB_SetThumbnailClip($hGUI, 200, 0, 200 + 128, 128) ; Specifies or updates the text of the tooltip that is displayed when the mouse pointer rests on an individual preview thumbnail in a taskbar button flyout. Local $sTxt = "" $sTxt &= " Title...........: Example.au3" & @CRLF $sTxt &= " Description.....: Example howto use ITaskbarList3 " & @CRLF $sTxt &= " AutoIt Version..: 3.3.16.1 Script Version: 1.0" TB_SetThumbnailTooltip($hGUI, $sTxt) Global $hIcon Global $iCnt = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton ; Applies an overlay to a taskbar button to indicate application status or a notification to the user. $iCnt += 1 ConsoleWrite("$iCnt=" & $iCnt & @CRLF) $hIcon = TB_GetIconHandle($iCnt > 10 ? @ScriptDir & "\Res\trffc14.ico" : @ScriptDir & "\Res\" & $iCnt & ".ico") TB_SetOverlayIcon($hGUI, $hIcon, String($iCnt)) EndSwitch WEnd GUIDelete($hGUI) ;-------------------------------------------------------------------------------------------------------------------------------- ; Function to handle the taskbar ready event Func _TaskbarReady($hWnd, $msg, $wParam, $lParam) Switch $hWnd Case $hGUI ; The taskbar button is ready ConsoleWrite("--- Taskbar button ready ---" & @CRLF) $bRedyflag = True EndSwitch EndFunc ;==>_TaskbarReady ;-------------------------------------------------------------------------------------------------------------------------------- ; Function to handle thumbnail button clicks Func _OnThumbnailButtonClick($hWnd, $msg, $wParam, $lParam) ; Extract the button ID from the wParam Local $iButtonID = BitAND($wParam, 0xFFFF) Switch $iButtonID Case 1000 ; progress status in Thumbnail icon ConsoleWrite("- progress status in Thumbnail icon Button Clicked: " & $iButtonID & @CRLF) ; Load an icon $hIcon = TB_GetIconHandle(@ScriptDir & "\Res\comres-15.ico") TB_SetOverlayIcon($hGUI, $hIcon, "Wait") For $i = 1 To 100 TB_SetProgress($hGUI, $i, 100) Sleep(25) Next TB_Flash($hGUI, 4, 300) $hIcon = TB_GetIconHandle($iCnt > 10 ? @ScriptDir & "\Res\trffc14.ico" : @ScriptDir & "\Res\" & $iCnt & ".ico") TB_SetOverlayIcon($hGUI, $hIcon, String($iCnt)) Case 1001 ; Flash the taskbar icon RED ConsoleWrite("- Flash the taskbar icon RED Button Clicked: " & $iButtonID & @CRLF) For $i = 1 To 4 TB_SetProgressState($hGUI, 4) Sleep(300) TB_SetProgressState($hGUI, 0) Sleep(300) Next TB_SetProgressState($hGUI, 0) Sleep(1000) For $i = 1 To 4 TB_SetProgressState($hGUI, 4) TB_SetProgress($hGUI, 100, 100) Sleep(300) TB_SetProgressState($hGUI, 0) TB_SetProgress($hGUI, 0, 100) Sleep(300) Next TB_SetProgressState($hGUI, 0) Case 1002 ; Flash the taskbar icon YELLOW ConsoleWrite("- Flash the taskbar icon YELLOW Button Clicked: " & $iButtonID & @CRLF) For $i = 1 To 4 TB_SetProgressState($hGUI, 8) Sleep(300) TB_SetProgressState($hGUI, 0) Sleep(300) Next TB_SetProgressState($hGUI, 0) Sleep(1000) For $i = 1 To 4 TB_SetProgressState($hGUI, 8) TB_SetProgress($hGUI, 100, 100) Sleep(300) TB_SetProgressState($hGUI, 0) TB_SetProgress($hGUI, 0, 100) Sleep(300) Next TB_SetProgressState($hGUI, 0) Case 1003 ; progress status in Thumbnail icon ConsoleWrite("- progress status in Thumbnail icon Button Clicked: " & $iButtonID & @CRLF) ; Load an icon $hIcon = TB_GetIconHandle(@ScriptDir & "\Res\comres-15.ico") TB_SetOverlayIcon($hGUI, $hIcon, "Wait") For $i = 1 To 100 Switch $i Case 60 To 84 TB_SetProgressState($hGUI, 8) ;YELLOW Case 85 To 100 TB_SetProgressState($hGUI, 4) ;RED EndSwitch TB_SetProgress($hGUI, $i, 100) Sleep(25) Next TB_Flash($hGUI, 4, 300) TB_SetProgressState($hGUI, 0) $hIcon = TB_GetIconHandle($iCnt > 10 ? @ScriptDir & "\Res\trffc14.ico" : @ScriptDir & "\Res\" & $iCnt & ".ico") TB_SetOverlayIcon($hGUI, $hIcon, String($iCnt)) EndSwitch EndFunc ;==>_OnThumbnailButtonClick TaskbarList.au3 #include-once #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Description=ITaskbarList4 interface #AutoIt3Wrapper_Res_Fileversion=0.0.0.3 #AutoIt3Wrapper_Res_ProductName=TaskbarList.au3 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; https://www.autoitscript.com/forum/topic/212223-itaskbarlist4-interface ; https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/shell/taskbar-extensions.md ; https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-registertab ; https://www.autoitscript.com/forum/topic/139260-autoit-snippets/?do=findComment&comment=1536397 ; Images must be 32-bit and of dimensions GetSystemMetrics(SM_CXICON) x GetSystemMetrics(SM_CYICON). #include <WinAPISysWin.au3> #include <GuiImageList.au3> #Region ;**** CONSTANTS **** ; THUMBBUTTONFLAGS Used by THUMBBUTTON to control specific states and behaviors of the button. Global Enum $THBF_ENABLED, $THBF_DISABLED, $THBF_DISMISSONCLICK, $THBF_NOBACKGROUND = 4, $THBF_HIDDEN = 8, $THBF_NONINTERACTIVE = 10 ; THUMBBUTTONMASK Used by the THUMBBUTTON structure to specify which members of that structure contain valid data. Global Enum $THB_BITMAP = 1, $THB_ICON, $THB_TOOLTIP = 4, $THB_FLAGS = 8 ; Used by the ITaskbarList3::SetProgressState method to specify tab properties. Global Enum $TBPF_NOPROGRESS, $TBPF_INDETERMINATE, $TBPF_NORMAL, $TBPF_ERROR = 4, $TBPF_PAUSED = 8 ; Used by the ITaskbarList4::SetTabProperties method to specify tab properties. Global Enum $STPF_NONE, $STPF_USEAPPTHUMBNAILALWAYS, $STPF_USEAPPTHUMBNAILWHENACTIVE, $STPF_USEAPPPEEKALWAYS = 4, $STPF_USEAPPPEEKWHENACTIVE = 8 Global Const $sCLSID_TaskbarList = "{56FDF344-FD6D-11D0-958A-006097C9A090}" ; Win2000 Global Const $sIID_ITaskbarList2 = "{602D4995-B13A-429b-A66E-1935E44F4317}" ; WinXP Global Const $sIID_ITaskbarList3 = "{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}" ; Win7 Global Const $sIID_ITaskbarList4 = "{C43DC798-95D1-4BEA-9030-BB99E2983A1A}" ; Win7 Global Const $tagITaskbarList = _ "HrInit hresult();" & _ "AddTab hresult(hwnd);" & _ "DeleteTab hresult(hwnd);" & _ "ActivateTab hresult(hwnd);" & _ "SetActiveAlt hresult(hwnd);" Global Const $tagITaskbarList2 = $tagITaskbarList & _ "MarkFullscreenWindow hresult(hwnd;boolean);" Global Const $tagITaskbarList3 = $tagITaskbarList2 & _ "SetProgressValue hresult(hwnd;uint64;uint64);" & _ "SetProgressState hresult(hwnd;int);" & _ "RegisterTab hresult(hwnd;hwnd);" & _ "UnregisterTab hresult(hwnd);" & _ "SetTabOrder hresult(hwnd;hwnd);" & _ "SetTabActive hresult(hwnd;hwnd;dword);" & _ "ThumbBarAddButtons hresult(hwnd;uint;ptr);" & _ "ThumbBarUpdateButtons hresult(hwnd;uint;ptr);" & _ "ThumbBarSetImageList hresult(hwnd;ptr);" & _ "SetOverlayIcon hresult(hwnd;ptr;wstr);" & _ "SetThumbnailTooltip hresult(hwnd;wstr);" & _ "SetThumbnailClip hresult(hwnd;ptr);" Global Const $tagITaskbarList4 = $tagITaskbarList3 & _ "SetTabProperties hresult(hwnd;int);" ; Used by methods of the ITaskbarList3 interface to define buttons used in a toolbar embedded in a window's thumbnail representation. Global Const $tagTHUMBBUTTON = "dword dwMask;" & _ "uint iId;" & _ "uint iBitmap;" & _ "handle hIcon;" & _ "wchar szTip[260];" & _ "dword dwFlags" #EndRegion ;**** CONSTANTS **** Global Const $g__oTB = __TB_Init() ; #INTERNAL_USE_ONLY# ----------------------------------------------------------------------------------------------------------- ; Name...........: __TB_Init() ; Description....: Initializes the taskbar list object. ; Syntax.........: __TB_Init() ; Parameters.....: None. ; Return values..: $oTB, an object representing the taskbar list. ; Author ........: ioa747 ; Notes .........: ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist-hrinit ;-------------------------------------------------------------------------------------------------------------------------------- Func __TB_Init() Local $oTB = ObjCreateInterface($sCLSID_TaskbarList, $sIID_ITaskbarList3, $tagITaskbarList3) $oTB.HrInit() Return $oTB EndFunc ;==>__TB_Init #Region ;**** ITaskbarList interface **** ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_ActivateTab ; Description....: Activates an item on the taskbar. The window is not actually activated. ; Syntax.........: TB_ActivateTab($hWnd) ; Parameters.....: $hWnd - Handle to the tab control. ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: ioa747 ; Notes .........: ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist-activatetab ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_ActivateTab($hWnd) Return $g__oTB.ActivateTab($hWnd) EndFunc ;==>TB_ActivateTab ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_AddTab ; Description....: Adds a new tab to the taskbar. ; Syntax.........: TB_AddTab($hWnd) ; Parameters.....: $hWnd - A handle to the window to be added to the taskbar. ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: ioa747 ; Notes .........: ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist-addtab ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_AddTab($hWnd) Return $g__oTB.AddTab($hWnd) EndFunc ;==>TB_AddTab ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_DeleteTab ; Description....: Deletes a tab from the taskbar. ; Syntax.........: DeleteTab($hWnd) ; Parameters.....: $hWnd - A handle to the window to be deleted from the taskbar. ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: ioa747 ; Notes .........: ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist-deletetab ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_DeleteTab($hWnd) Return $g__oTB.DeleteTab($hWnd) EndFunc ;==>TB_DeleteTab ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_SetActiveAlt ; Description....: Sets the active alternate for a toolbar control. ; Syntax.........: TB_SetActiveAlt($hWnd) ; Parameters.....: $hWnd - A handle to the window to be marked as active. ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: ioa747 ; Notes .........: This function is only available on Windows Win2000 and later versions of the operating system. ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist-setactivealt ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_SetActiveAlt($hWnd) Return $g__oTB.SetActiveAlt($hWnd) EndFunc ;==>TB_SetActiveAlt #EndRegion ;**** ITaskbarList interface **** #Region ;**** ITaskbarList2 interface **** ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_MarkFullscreenWindow ; Description....: Marks a window as fullscreen. ; Syntax.........: TB_MarkFullscreenWindow($hWnd, $bFullscreen) ; Parameters.....: $hWnd - The handle of the window to be marked. ; $bFullscreen - Boolean value indicating whether the window should be marked as fullscreen (True) or not (False). ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: ioa747 ; Notes .........: his function is only available on Windows WinXP and later versions of the operating system. ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist2-markfullscreenwindow ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_MarkFullscreenWindow($hWnd, $bFullscreen) Return $g__oTB.MarkFullscreenWindow($hWnd, $bFullscreen) EndFunc ;==>TB_MarkFullscreenWindow #EndRegion ;**** ITaskbarList2 interface **** #Region ;**** ITaskbarList3 interface **** ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_RegisterTab ; Description....: Registers a tab in the thumbnail toolbar. ; Syntax.........: TB_RegisterTab($hWndTab, $hWndMDI) ; Parameters.....: $hWndTab - Handle to the tab window. ; $hWndMDI - The handle of the main window (the MDI client area). ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: ioa747 ; Notes .........: ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-registertab ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_RegisterTab($hWndTab, $hWndMDI) Return $g__oTB.RegisterTab($hWndTab, $hWndMDI) EndFunc ;==>TB_RegisterTab ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_SetOverlayIcon ; Description....: Sets the overlay icon for a toolbar button. ; Syntax.........: TB_SetOverlayIcon($hWnd, $hIcon, $sAltText = "") ; Parameters.....: $hWnd - The handle of the window whose associated taskbar button receives the overlay. ; $hIcon - Handle to the icon to be used as the overlay image. ; $sAltText - Alternative text for the button. If this parameter is an empty string, ; the function will use the current value of the TB_SETTOOLTIPS message. ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: ioa747 ; Notes .........: This function is only available on Windows Vista and later. ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-setoverlayicon ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_SetOverlayIcon($hWnd, $hIcon, $sAltText = "") Return $g__oTB.SetOverlayIcon($hWnd, $hIcon, $sAltText) EndFunc ;==>TB_SetOverlayIcon ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_SetProgressState ; Description....: Sets the progress state of a taskbar button. ; Syntax.........: TB_SetProgressState($hWnd, $iFlags) ; Parameters.....: $hWnd - The handle of the window in which the progress of an operation is being shown. ; $iFlags - Flags that specify the new progress state. Can be one of the following values: ; | (0) $TBPF_NOPROGRESS - Stops displaying progress and returns the button to its normal state. ; | (1) $TBPF_INDETERMINATE - The progress indicator does not grow in size, but cycles repeatedly along the length of the taskbar button. ; | (2) $TBPF_NORMAL - The progress indicator grows in size from left to right in proportion to the estimated amount of the operation completed. ; | (4) $TBPF_ERROR - The progress indicator turns red to show that an error has occurred in one of the windows that is broadcasting progress. ; | (8) $TBPF_PAUSED - The progress indicator turns yellow to show that progress is currently stopped in one of the windows but can be resumed by the user. ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: ioa747 ; Notes .........: ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-setprogressstate ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_SetProgressState($hWnd, $iFlags) Return $g__oTB.SetProgressState($hWnd, $iFlags) EndFunc ;==>TB_SetProgressState ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_SetProgress ; Description....: Sets the progress value of a taskbar button. ; Syntax.........: TB_SetProgress($hWnd, $iCurrent, $iCompleted) ; Parameters.....: $hWnd - The handle of the window whose associated taskbar button is being used as a progress indicator. ; $iCurrent - The current progress value. ; $iCompleted - The completed progress value. ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: nine ; Notes .........: ; Link ..........: https://www.autoitscript.com/forum/topic/139260-autoit-snippets/page/26/#comment-1536397 ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_SetProgress($hWnd, $iCurrent, $iCompleted) Return $g__oTB.SetProgressValue($hWnd, $iCurrent, $iCompleted) EndFunc ;==>TB_SetProgress ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_SetTabActive ; Description....: Sets the active tab in a thumbnail tooltip control. ; Syntax.........: TB_SetTabActive($hWndTab, $hWndMDI, $iReserved = 0) ; Parameters.....: $hWndTab - Handle of the active tab window. This handle must already be registered through RegisterTab. ; $hWndMDI - The handle of the main window (the MDI client area). ; $iReserved - Reserved for future use. Must be set to zero. ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: ioa747 ; Notes .........: Note that this function is likely only useful in the context of an MDI application, ; where multiple tabs are managed by a single client area. ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-settabactive ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_SetTabActive($hWndTab, $hWndMDI, $iReserved = 0) Return $g__oTB.SetTabActive($hWndTab, $hWndMDI, $iReserved) EndFunc ;==>TB_SetTabActive ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_SetTabOrder ; Description....: Sets the tab order of a toolbar control. ; Syntax.........: TB_SetTabOrder($hWndTab, $hWndInsertBefore) ; Parameters.....: $hWndTab - The handle of the tab window whose thumbnail is being placed. This value is required, must already be registered through ITaskbarList3::RegisterTab ; $hWndInsertBefore - Handle to the window that will precede the specified window in the tab order. ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: ioa747 ; Notes .........: ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-settaborder ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_SetTabOrder($hWndTab, $hWndInsertBefore) Return $g__oTB.SetTabOrder($hWndTab, $hWndInsertBefore) EndFunc ;==>TB_SetTabOrder ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_SetThumbnailClip ; Description....: Selects a portion of a window's client area to display as that window's thumbnail in the taskbar. ; Syntax.........: TB_SetThumbnailClip($hWnd, $iLeft, $iTop, $iRight, $iBottom) ; Parameters.....: $hWnd - The handle to a window represented in the taskbar. ; $iLeft - The left coordinate of the clipping rectangle. ; $iTop - The top coordinate of the clipping rectangle. ; $iRight - The right coordinate of the clipping rectangle. ; $iBottom - The bottom coordinate of the clipping rectangle. ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: ioa747 ; Notes .........: ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-setthumbnailclip ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_SetThumbnailClip($hWnd, $iLeft, $iTop, $iRight, $iBottom) Local $tRECTClip = DllStructCreate($tagRECT) DllStructSetData($tRECTClip, "Left", $iLeft) DllStructSetData($tRECTClip, "Top", $iTop) DllStructSetData($tRECTClip, "Right", $iRight) DllStructSetData($tRECTClip, "Bottom", $iBottom) Return $g__oTB.SetThumbnailClip($hWnd, DllStructGetPtr($tRECTClip)) EndFunc ;==>TB_SetThumbnailClip ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_SetThumbnailTooltip ; Description....: Sets a tooltip for a thumbnail in the taskbar. ; Syntax.........: TB_SetThumbnailTooltip($hWnd, $sTooltip) ; Parameters.....: $hWnd - Handle to the window that contains the thumbnail. ; $sTooltip - Tooltip text to be displayed. ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: ioa747 ; Notes .........: The tooltip will be displayed when the user hovers their mouse over the thumbnail. ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-setthumbnailtooltip ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_SetThumbnailTooltip($hWnd, $sTooltip) Return $g__oTB.SetThumbnailTooltip($hWnd, $sTooltip) EndFunc ;==>TB_SetThumbnailTooltip ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_ThumbBarAddButtons ; Description....: Adds buttons to the thumbnail toolbar. ; Syntax.........: TB_ThumbBarAddButtons($hWnd, $iButtonCount, $aButtons) ; Parameters.....: $hWnd - Handle to the window that contains the thumbnail image. ; $iButtonCount - Number of buttons to add. ; $aButtons - Array of button data. Each element in the array should be a structure with the following fields: ; - dwMask - Mask of valid fields in this structure. Can be a combination of THUMBBUTTONMASK ; $THB_BITMAP = 1, $THB_ICON, $THB_TOOLTIP = 4, $THB_FLAGS = 8 ; - iId - Unique identifier for the button. This value is returned in the $iButtonIndex parameter of the TB_ThumbBarButtonPressed notification code. ; - iBitmap - Handle to the bitmap that will be displayed on the button. ; - hIcon - Handle to the icon that will be displayed on the button. ; - szTip - Tooltip text for the button. ; - dwFlags - Flags that specify the behavior of the button. Can be a combination of THUMBBUTTONFLAGS ; $THBF_ENABLED=0, $THBF_DISABLED=1, $THBF_DISMISSONCLICK=2, $THBF_NOBACKGROUND=4, $THBF_HIDDEN=8, $THBF_NONINTERACTIVE=10. ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: ioa747 ; Notes .........: ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-thumbbaraddbuttons ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_ThumbBarAddButtons($hWnd, $iButtonCount, $aButtons) ; Create a struct for each button ; dwFlags(THBF_ENABLED=0, THBF_DISABLED=0x1, THBF_DISMISSONCLICK=0x2, THBF_NOBACKGROUND=0x4, THBF_HIDDEN=0x8, THBF_NONINTERACTIVE=0x10) ; Get the size of the THUMBBUTTON structure Local $iStructSize = DllStructGetSize(DllStructCreate($tagTHUMBBUTTON)) ; Calculate the total memory size needed for all button structures Local $pButtonsMemory = DllStructCreate("byte[" & ($iStructSize * $iButtonCount) & "]") If @error Then MsgBox(16, "Error", "Failed to create memory structure for buttons. Error: " & @error) Return EndIf ; Loop through and initialize each button structure For $i = 0 To $iButtonCount - 1 ; Create a THUMBBUTTON struct at the correct memory location Local $pCurrentButton = DllStructCreate($tagTHUMBBUTTON, DllStructGetPtr($pButtonsMemory) + ($iStructSize * $i)) If @error Then MsgBox(16, "Error", "Failed to create DllStruct for button " & ($i + 1) & ". Error: " & @error) Return EndIf ; Populate the struct with button data DllStructSetData($pCurrentButton, "dwMask", $aButtons[$i][0]) DllStructSetData($pCurrentButton, "iId", $aButtons[$i][1]) DllStructSetData($pCurrentButton, "iBitmap", $aButtons[$i][2]) DllStructSetData($pCurrentButton, "hIcon", $aButtons[$i][3]) DllStructSetData($pCurrentButton, "szTip", $aButtons[$i][4]) DllStructSetData($pCurrentButton, "dwFlags", $aButtons[$i][5]) ; Validate if data was set correctly If @error Then MsgBox(16, "Error", "Failed to set data for button " & ($i + 1) & ". Error: " & @error) Return EndIf Next ; Call the ThumbBarAddButtons method Local $hResult = $g__oTB.ThumbBarAddButtons($hWnd, $iButtonCount, DllStructGetPtr($pButtonsMemory)) If $hResult <> 0 Then MsgBox(16, "Error", "Failed to add thumbnail toolbar buttons. HRESULT: " & $hResult) EndIf EndFunc ;==>TB_ThumbBarAddButtons ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_ThumbBarSetImageList ; Description....: Sets the image list for a thumb bar. ; Syntax.........: TB_ThumbBarSetImageList($hWnd, $hImageList) ; Parameters.....: $hWnd - The handle of the window whose thumbnail representation contains the toolbar to be updated. ; $hImageList - Handle to an image list containing the images for the thumb bar. ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: ioa747 ; Notes .........: ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-thumbbarsetimagelist ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_ThumbBarSetImageList($hWnd, $hImageList) $g__oTB.ThumbBarSetImageList($hWnd, $hImageList) EndFunc ;==>TB_ThumbBarSetImageList ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_ThumbBarUpdateButtons ; Description....: Updates the buttons in a thumbnail toolbar. ; Syntax.........: TB_ThumbBarUpdateButtons($hWnd, $iButtonCount, $aButtons) ; Parameters.....: $hWnd - The handle of the window whose thumbnail representation contains the toolbar. ; $iButtonCount- Number of buttons in the array. ; $aButtons - Array of button data. Each element in the array should be a structure with the following fields: ; - dwMask - Mask of valid fields in this structure. Can be a combination of THUMBBUTTONMASK ; $THB_BITMAP = 1, $THB_ICON, $THB_TOOLTIP = 4, $THB_FLAGS = 8 ; - iId - Unique identifier for the button. This value is returned in the $iButtonIndex parameter of the TB_ThumbBarButtonPressed notification code. ; - iBitmap - Handle to the bitmap that will be displayed on the button. ; - hIcon - Handle to the icon that will be displayed on the button. ; - szTip - Tooltip text for the button. ; - dwFlags - Flags that specify the behavior of the button. Can be a combination of THUMBBUTTONFLAGS ; $THBF_ENABLED=0, $THBF_DISABLED=1, $THBF_DISMISSONCLICK=2, $THBF_NOBACKGROUND=4, $THBF_HIDDEN=8, $THBF_NONINTERACTIVE=10. ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: ioa747 ; Notes .........: ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-thumbbarupdatebuttons ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_ThumbBarUpdateButtons($hWnd, $iButtonCount, $aButtons) ; Create a struct for each button ; dwFlags(THBF_ENABLED=0, THBF_DISABLED=0x1, THBF_DISMISSONCLICK=0x2, THBF_NOBACKGROUND=0x4, THBF_HIDDEN=0x8, THBF_NONINTERACTIVE=0x10) ; Get the size of the THUMBBUTTON structure Local $iStructSize = DllStructGetSize(DllStructCreate($tagTHUMBBUTTON)) ; Calculate the total memory size needed for all button structures Local $pButtonsMemory = DllStructCreate("byte[" & ($iStructSize * $iButtonCount) & "]") If @error Then MsgBox(16, "Error", "Failed to create memory structure for buttons. Error: " & @error) Return EndIf ; Loop through and initialize each button structure For $i = 0 To $iButtonCount - 1 ; Create a THUMBBUTTON struct at the correct memory location Local $pCurrentButton = DllStructCreate($tagTHUMBBUTTON, DllStructGetPtr($pButtonsMemory) + ($iStructSize * $i)) If @error Then MsgBox(16, "Error", "Failed to create DllStruct for button " & ($i + 1) & ". Error: " & @error) Return EndIf ; Populate the struct with button data DllStructSetData($pCurrentButton, "dwMask", $aButtons[$i][0]) DllStructSetData($pCurrentButton, "iId", $aButtons[$i][1]) DllStructSetData($pCurrentButton, "iBitmap", $aButtons[$i][2]) DllStructSetData($pCurrentButton, "hIcon", $aButtons[$i][3]) DllStructSetData($pCurrentButton, "szTip", $aButtons[$i][4]) DllStructSetData($pCurrentButton, "dwFlags", $aButtons[$i][5]) ; Validate if data was set correctly If @error Then MsgBox(16, "Error", "Failed to set data for button " & ($i + 1) & ". Error: " & @error) Return EndIf Next ; Call the ThumbBarUpdateButtons method Local $hResult = $g__oTB.ThumbBarUpdateButtons($hWnd, $iButtonCount, DllStructGetPtr($pButtonsMemory)) If $hResult <> 0 Then MsgBox(16, "Error", "Failed to Update thumbnail toolbar buttons. HRESULT: " & $hResult) EndIf EndFunc ;==>TB_ThumbBarUpdateButtons ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_UnregisterTab ; Description....: Unregisters a tab from the toolbar. ; Syntax.........: TB_UnregisterTab($hWndTab) ; Parameters.....: $hWndTab - The handle of the tab window whose thumbnail is being removed. ; This is the same value with which the thumbnail was registered as part the group through RegisterTab ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: ioa747 ; Notes .........: ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist3-unregistertab ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_UnregisterTab($hWndTab) Return $g__oTB.UnregisterTab($hWndTab) EndFunc ;==>TB_UnregisterTab #EndRegion ;**** ITaskbarList3 interface **** #Region ;**** ITaskbarList4 interface **** ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_SetTabProperties ; Description....: Sets the properties of a tab in a toolbar control. ; Syntax.........: TB_SetTabProperties($hWndTab, $stpFlags) ; Parameters.....: $hWndTab - The handle of the tab window that is to have properties set. This handle must already be registered through RegisterTab. ; $stpFlags - A combination of the following values: ; |(0) STPF_NONE : No specific property values are specified. ; The default behavior is used: the tab window provides a thumbnail and peek image, either live or static as appropriate. ; |(1) $STPF_USEAPPTHUMBNAILALWAYS : Always use the thumbnail provided by the main application frame window rather than a thumbnail provided by the individual tab window. ; Do not combine this value with STPF_USEAPPTHUMBNAILWHENACTIVE; doing so will result in an error. ; |(2) $STPF_USEAPPTHUMBNAILWHENACTIVE : When the application tab is active and a live representation of its window is available, ; use the main application's frame window thumbnail. At other times, use the tab window thumbnail. ; Do not combine this value with STPF_USEAPPTHUMBNAILALWAYS; doing so will result in an error. ; |(4) $STPF_USEAPPPEEKALWAYS : Always use the peek image provided by the main application frame window rather than a peek image provided by the individual tab window. ; Do not combine this value with STPF_USEAPPPEEKWHENACTIVE; doing so will result in an error. ; |(8) $STPF_USEAPPPEEKWHENACTIVE : When the application tab is active and a live representation of its window is available, ; show the main application frame in the peek feature. At other times, use the tab window. ; Do not combine this value with STPF_USEAPPPEEKALWAYS; doing so will result in an error. ; Return values..: Success - Returns a zero value if successful ; Failure - Returns a non-zero value indicating the error code. ; Author ........: ioa747 ; Notes .........: ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist4-settabproperties ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_SetTabProperties($hWndTab, $stpFlags) Return $g__oTB.SetTabProperties($hWndTab, $stpFlags) EndFunc ;==>TB_SetTabProperties #EndRegion ;**** ITaskbarList4 interface **** #Region ;**** Extra **** ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_Flash ; Description....: Flashes a taskbar button. ; Syntax.........: TB_Flash($hWnd, $iTimes = 3, $iDelay = 300) ; Parameters.....: $hWnd - Handle to the taskbar button. ; $iTimes - Number of times to flash (default is 3). ; $iDelay - Delay between flashes in milliseconds (default is 300). ; Return values..: None. ; Author ........: nine ; Notes .........: This function uses the TaskbarButton class to interact with taskbar buttons. For more information, see the AutoIt documentation. ; Link ..........: https://www.autoitscript.com/forum/topic/139260-autoit-snippets/page/26/#comment-1536397 ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_Flash($hWnd, $iTimes = 3, $iDelay = 300) For $i = 1 To $iTimes $g__oTB.SetProgressState($hWnd, 0) Sleep($iDelay) $g__oTB.SetProgressValue($hWnd, 100, 100) Sleep($iDelay) Next $g__oTB.SetProgressState($hWnd, 0) EndFunc ;==>TB_Flash ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: TB_GetIconHandle ; Description....: Returns a handle to an icon. ; Syntax.........: TB_GetIconHandle($iconFilePath, $iconIndex = 0) ; Parameters.....: $iconFilePath - The path of the file that contains the icon. ; $iconIndex - The index of the icon in the file. Default is 0. ; Return values..: Success - A handle to the icon. ; Failure - 0, and sets @error to 1. ; Author ........: ioa747 ; Notes .........: This function uses the ExtractIcon function from the shell32.dll library. ; Link ..........: https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-extracticona ; Dependencies...: _WinAPI_GetModuleHandle, DllCall ;-------------------------------------------------------------------------------------------------------------------------------- Func TB_GetIconHandle($iconFilePath, $iconIndex = 0) Local $hInstance = _WinAPI_GetModuleHandle(0) Local $aResult = DllCall("shell32.dll", "hwnd", "ExtractIcon", "hwnd", $hInstance, "str", $iconFilePath, "uint", $iconIndex) If @error Then Return SetError(1, 0, 0) EndIf Return $aResult[0] EndFunc ;==>TB_GetIconHandle #EndRegion ;**** Extra **** Please, every comment is appreciated! leave your comments and experiences here! Thank you very much ITaskbarList_V3.7z1 point
-
ITaskbarList4 interface
argumentum reacted to ioa747 for a topic
@argumentum Thank you The same description is left over from the copy paste, since I didn't deal with them, they stayed like that I also didn't understand many things, and many of them are related to applications with multiple tabs, the so-called (TDI) or multiple-document interface (MDI) application's ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: SetActiveAlt method from: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist-setactivealt SetActiveAlt marks the item associated with hwnd as the currently active item for the window's process without changing the pressed state of any item. Any user action that would activate a different tab in that process will activate the tab associated with hwnd instead. The active state of the window's item is not guaranteed to be preserved when the process associated with hwnd is not active. To ensure that a given tab is always active, call SetActiveAlt whenever any of your windows are activated. Calling SetActiveAlt with a NULL hwnd clears this state. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: MarkFullscreenWindow method from: https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-itaskbarlist2-markfullscreenwindow Setting the value of fFullscreen to TRUE, the Shell treats this window as a full-screen window, and the taskbar is moved to the bottom of the z-order when this window is active. Setting the value of fFullscreen to FALSE removes the full-screen marking, but does not cause the Shell to treat the window as though it were definitely not full-screen. With a FALSE fFullscreen value, the Shell depends on its automatic detection facility to specify how the window should be treated, possibly still flagging the window as full-screen. Since Windows 7, call SetProp(hwnd, L”NonRudeHWND”, reinterpret_cast<HANDLE>(TRUE)) before showing a window to indicate to the Shell that the window should not be treated as full-screen. This ensures the taskbar does not adjust itself to be below the window in z-order. This is similar to ITaskbarList2::MarkFullscreenWindow(FALSE) except the Shell will not fallback to its automatic detection facility and will not treat the window as full-screen. example: #include <GUIConstants.au3> #include "TaskbarList.au3" ; * <-- Local $hGUI = GUICreate("My Custom GUI", @DesktopWidth, @DesktopHeight, -8, 0, $WS_OVERLAPPEDWINDOW) Local $idButton_1 = GUICtrlCreateButton("Exit", 50, 100, 85, 25) Local $idButton_2 = GUICtrlCreateButton("Normal", 50, 130, 85, 25) Local $idButton_3 = GUICtrlCreateButton("Full Screen", 50, 160, 85, 25) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idButton_1 Exit Case $idButton_2 TB_MarkFullscreenWindow($hGUI, False) Case $idButton_3 TB_MarkFullscreenWindow($hGUI, True) EndSwitch WEnd1 point -
InputBox with increased font size
dmob reacted to pixelsearch for a topic
Hi everybody I needed to increase the font size of the text typed in the InputBox function, because it appears too small to my eyes. This is how I scripted it, maybe it will be helpful to users who need it for the same reason. #include <WinAPIGdiInternals.au3> #include <WinAPISysWin.au3> #Include <WindowsConstants.au3> Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration Global $g_sTitle ; 1 global variable for _TimerProc() $g_sTitle = "InputBox with increased font size" Local $sTextInput = _InputBox($g_sTitle, "Enter a string", "", " M", 300, 150) ; M means Mandatory ConsoleWrite("$sTextInput = >" & $sTextInput & "<" & @crlf) ;=========================================== Func _InputBox($g_sTitle, $sPrompt, $sDefault = "", $sPasswordChar = "", $iWidth = -1, $iHeight = -1, $iLeft = Default, $iTop = Default, $iTimeOut = 0, $hWnd = 0) Local $hTimerProc = DllCallbackRegister('_TimerProc', 'none', 'hwnd;uint;uint_ptr;dword') Local $iTimerID = _WinAPI_SetTimer(0, 0, 10, DllCallbackGetPtr($hTimerProc)) Local $sTextInput = InputBox($g_sTitle, $sPrompt, $sDefault, $sPasswordChar, $iWidth, $iHeight, $iLeft, $iTop, $iTimeOut, $hWnd) _WinAPI_KillTimer(0, $iTimerID) DllCallbackFree($hTimerProc) Return $sTextInput EndFunc ;==>_InputBox ;=========================================== Func _TimerProc($hWnd, $iMsg, $iTimerID, $iTime) If WinActive($g_sTitle) Then _WinAPI_KillTimer(0, $iTimerID) Local $hCtrl = ControlGetHandle($g_sTitle, "", "Edit1") ; control where the InputBox string is typed Local $hFont = _WinAPI_CreateFont(16, 0) _SendMessage($hCtrl, $WM_SETFONT, $hFont, False) ; False = do not redraw the control immediately _WinAPI_DeleteObject($hFont) EndIf EndFunc ;==>_TimerProc Have a great day1 point -
Simple Google Translate
dmob reacted to pixelsearch for a topic
1 point -
When processing files, especially large ones, you will always lose battle if riding AutoIt. Not to mention RAM suffocation. So, what if I leave the whole process on a level that is few steps below me and just collect the cream? Script includes functions and small example: Opt("MustDeclareVars", 1) Global $sFile = FileOpenDialog("Choose file", "", "All files (*)") If @error Then Exit Global $hTimer, $iTimer, $sData ;------------------------------------------------------------------------ ; CRC32: $hTimer = TimerInit() $sData = _CRC32ForFile($sFile) $iTimer = TimerDiff($hTimer) ConsoleWrite("! CRC32 took " & $iTimer & " ms" & @CRLF) ConsoleWrite("Result: " & $sData & @CRLF & @CRLF) ;------------------------------------------------------------------------ ; MD4: $hTimer = TimerInit() $sData = _MD4ForFile($sFile) $iTimer = TimerDiff($hTimer) ConsoleWrite("! MD4 took " & $iTimer & " ms" & @CRLF) ConsoleWrite("Result: " & $sData & @CRLF & @CRLF) ;------------------------------------------------------------------------ ; MD5: $hTimer = TimerInit() $sData = _MD5ForFile($sFile) $iTimer = TimerDiff($hTimer) ConsoleWrite("! MD5 took " & $iTimer & " ms" & @CRLF) ConsoleWrite("Result: " & $sData & @CRLF & @CRLF) ;------------------------------------------------------------------------ ; SHA1: $hTimer = TimerInit() $sData = _SHA1ForFile($sFile) $iTimer = TimerDiff($hTimer) ConsoleWrite("! SHA1 took " & $iTimer & " ms" & @CRLF) ConsoleWrite("Result: " & $sData & @CRLF & @CRLF) ;------------------------------------------------------------------------ ; Functions... ; #FUNCTION# ;=============================================================================== ; ; Name...........: _CRC32ForFile ; Description ...: Calculates CRC32 value for the specific file. ; Syntax.........: _CRC32ForFile ($sFile) ; Parameters ....: $sFile - Full path to the file to process. ; Return values .: Success - Returns CRC32 value in form of hex string ; - Sets @error to 0 ; Failure - Returns empty string and sets @error: ; |1 - CreateFile function or call to it failed. ; |2 - CreateFileMapping function or call to it failed. ; |3 - MapViewOfFile function or call to it failed. ; |4 - RtlComputeCrc32 function or call to it failed. ; Author ........: trancexx ; ;========================================================================================== Func _CRC32ForFile($sFile) Local $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFileW", _ "wstr", $sFile, _ "dword", 0x80000000, _ ; GENERIC_READ "dword", 3, _ ; FILE_SHARE_READ|FILE_SHARE_WRITE "ptr", 0, _ "dword", 3, _ ; OPEN_EXISTING "dword", 0, _ ; SECURITY_ANONYMOUS "ptr", 0) If @error Or $a_hCall[0] = -1 Then Return SetError(1, 0, "") EndIf Local $hFile = $a_hCall[0] $a_hCall = DllCall("kernel32.dll", "ptr", "CreateFileMappingW", _ "hwnd", $hFile, _ "dword", 0, _ ; default security descriptor "dword", 2, _ ; PAGE_READONLY "dword", 0, _ "dword", 0, _ "ptr", 0) If @error Or Not $a_hCall[0] Then DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return SetError(2, 0, "") EndIf DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Local $hFileMappingObject = $a_hCall[0] $a_hCall = DllCall("kernel32.dll", "ptr", "MapViewOfFile", _ "hwnd", $hFileMappingObject, _ "dword", 4, _ ; FILE_MAP_READ "dword", 0, _ "dword", 0, _ "dword", 0) If @error Or Not $a_hCall[0] Then DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Return SetError(3, 0, "") EndIf Local $pFile = $a_hCall[0] Local $iBufferSize = FileGetSize($sFile) Local $a_iCall = DllCall("ntdll.dll", "dword", "RtlComputeCrc32", _ "dword", 0, _ "ptr", $pFile, _ "int", $iBufferSize) If @error Or Not $a_iCall[0] Then DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Return SetError(4, 0, "") EndIf DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Local $iCRC32 = $a_iCall[0] Return SetError(0, 0, Hex($iCRC32)) EndFunc ;==>_CRC32ForFile ; #FUNCTION# ;=============================================================================== ; ; Name...........: _MD4ForFile ; Description ...: Calculates MD4 value for the specific file. ; Syntax.........: _MD4ForFile ($sFile) ; Parameters ....: $sFile - Full path to the file to process. ; Return values .: Success - Returns MD4 value in form of hex string ; - Sets @error to 0 ; Failure - Returns empty string and sets @error: ; |1 - CreateFile function or call to it failed. ; |2 - CreateFileMapping function or call to it failed. ; |3 - MapViewOfFile function or call to it failed. ; |4 - MD4Init function or call to it failed. ; |5 - MD4Update function or call to it failed. ; |6 - MD4Final function or call to it failed. ; Author ........: trancexx ; ;========================================================================================== Func _MD4ForFile($sFile) Local $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFileW", _ "wstr", $sFile, _ "dword", 0x80000000, _ ; GENERIC_READ "dword", 3, _ ; FILE_SHARE_READ|FILE_SHARE_WRITE "ptr", 0, _ "dword", 3, _ ; OPEN_EXISTING "dword", 0, _ ; SECURITY_ANONYMOUS "ptr", 0) If @error Or $a_hCall[0] = -1 Then Return SetError(1, 0, "") EndIf Local $hFile = $a_hCall[0] $a_hCall = DllCall("kernel32.dll", "ptr", "CreateFileMappingW", _ "hwnd", $hFile, _ "dword", 0, _ ; default security descriptor "dword", 2, _ ; PAGE_READONLY "dword", 0, _ "dword", 0, _ "ptr", 0) If @error Or Not $a_hCall[0] Then DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return SetError(2, 0, "") EndIf DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Local $hFileMappingObject = $a_hCall[0] $a_hCall = DllCall("kernel32.dll", "ptr", "MapViewOfFile", _ "hwnd", $hFileMappingObject, _ "dword", 4, _ ; FILE_MAP_READ "dword", 0, _ "dword", 0, _ "dword", 0) If @error Or Not $a_hCall[0] Then DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Return SetError(3, 0, "") EndIf Local $pFile = $a_hCall[0] Local $iBufferSize = FileGetSize($sFile) Local $tMD4_CTX = DllStructCreate("dword i[2];" & _ "dword buf[4];" & _ "ubyte in[64];" & _ "ubyte digest[16]") DllCall("advapi32.dll", "none", "MD4Init", "ptr", DllStructGetPtr($tMD4_CTX)) If @error Then DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Return SetError(4, 0, "") EndIf DllCall("advapi32.dll", "none", "MD4Update", _ "ptr", DllStructGetPtr($tMD4_CTX), _ "ptr", $pFile, _ "dword", $iBufferSize) If @error Then DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Return SetError(5, 0, "") EndIf DllCall("advapi32.dll", "none", "MD4Final", "ptr", DllStructGetPtr($tMD4_CTX)) If @error Then DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Return SetError(6, 0, "") EndIf DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Local $sMD4 = Hex(DllStructGetData($tMD4_CTX, "digest")) Return SetError(0, 0, $sMD4) EndFunc ;==>_MD4ForFile ; #FUNCTION# ;=============================================================================== ; ; Name...........: _MD5ForFile ; Description ...: Calculates MD5 value for the specific file. ; Syntax.........: _MD5ForFile ($sFile) ; Parameters ....: $sFile - Full path to the file to process. ; Return values .: Success - Returns MD5 value in form of hex string ; - Sets @error to 0 ; Failure - Returns empty string and sets @error: ; |1 - CreateFile function or call to it failed. ; |2 - CreateFileMapping function or call to it failed. ; |3 - MapViewOfFile function or call to it failed. ; |4 - MD5Init function or call to it failed. ; |5 - MD5Update function or call to it failed. ; |6 - MD5Final function or call to it failed. ; Author ........: trancexx ; ;========================================================================================== Func _MD5ForFile($sFile) Local $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFileW", _ "wstr", $sFile, _ "dword", 0x80000000, _ ; GENERIC_READ "dword", 3, _ ; FILE_SHARE_READ|FILE_SHARE_WRITE "ptr", 0, _ "dword", 3, _ ; OPEN_EXISTING "dword", 0, _ ; SECURITY_ANONYMOUS "ptr", 0) If @error Or $a_hCall[0] = -1 Then Return SetError(1, 0, "") EndIf Local $hFile = $a_hCall[0] $a_hCall = DllCall("kernel32.dll", "ptr", "CreateFileMappingW", _ "hwnd", $hFile, _ "dword", 0, _ ; default security descriptor "dword", 2, _ ; PAGE_READONLY "dword", 0, _ "dword", 0, _ "ptr", 0) If @error Or Not $a_hCall[0] Then DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return SetError(2, 0, "") EndIf DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Local $hFileMappingObject = $a_hCall[0] $a_hCall = DllCall("kernel32.dll", "ptr", "MapViewOfFile", _ "hwnd", $hFileMappingObject, _ "dword", 4, _ ; FILE_MAP_READ "dword", 0, _ "dword", 0, _ "dword", 0) If @error Or Not $a_hCall[0] Then DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Return SetError(3, 0, "") EndIf Local $pFile = $a_hCall[0] Local $iBufferSize = FileGetSize($sFile) Local $tMD5_CTX = DllStructCreate("dword i[2];" & _ "dword buf[4];" & _ "ubyte in[64];" & _ "ubyte digest[16]") DllCall("advapi32.dll", "none", "MD5Init", "ptr", DllStructGetPtr($tMD5_CTX)) If @error Then DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Return SetError(4, 0, "") EndIf DllCall("advapi32.dll", "none", "MD5Update", _ "ptr", DllStructGetPtr($tMD5_CTX), _ "ptr", $pFile, _ "dword", $iBufferSize) If @error Then DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Return SetError(5, 0, "") EndIf DllCall("advapi32.dll", "none", "MD5Final", "ptr", DllStructGetPtr($tMD5_CTX)) If @error Then DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Return SetError(6, 0, "") EndIf DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Local $sMD5 = Hex(DllStructGetData($tMD5_CTX, "digest")) Return SetError(0, 0, $sMD5) EndFunc ;==>_MD5ForFile ; #FUNCTION# ;=============================================================================== ; ; Name...........: _SHA1ForFile ; Description ...: Calculates SHA1 value for the specific file. ; Syntax.........: _SHA1ForFile ($sFile) ; Parameters ....: $sFile - Full path to the file to process. ; Return values .: Success - Returns SHA1 value in form of hex string ; - Sets @error to 0 ; Failure - Returns empty string and sets @error: ; |1 - CreateFile function or call to it failed. ; |2 - CreateFileMapping function or call to it failed. ; |3 - MapViewOfFile function or call to it failed. ; |4 - CryptAcquireContext function or call to it failed. ; |5 - CryptCreateHash function or call to it failed. ; |6 - CryptHashData function or call to it failed. ; |7 - CryptGetHashParam function or call to it failed. ; Author ........: trancexx ; ;========================================================================================== Func _SHA1ForFile($sFile) Local $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFileW", _ "wstr", $sFile, _ "dword", 0x80000000, _ ; GENERIC_READ "dword", 3, _ ; FILE_SHARE_READ|FILE_SHARE_WRITE "ptr", 0, _ "dword", 3, _ ; OPEN_EXISTING "dword", 0, _ ; SECURITY_ANONYMOUS "ptr", 0) If @error Or $a_hCall[0] = -1 Then Return SetError(1, 0, "") EndIf Local $hFile = $a_hCall[0] $a_hCall = DllCall("kernel32.dll", "ptr", "CreateFileMappingW", _ "hwnd", $hFile, _ "dword", 0, _ ; default security descriptor "dword", 2, _ ; PAGE_READONLY "dword", 0, _ "dword", 0, _ "ptr", 0) If @error Or Not $a_hCall[0] Then DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return SetError(2, 0, "") EndIf DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Local $hFileMappingObject = $a_hCall[0] $a_hCall = DllCall("kernel32.dll", "ptr", "MapViewOfFile", _ "hwnd", $hFileMappingObject, _ "dword", 4, _ ; FILE_MAP_READ "dword", 0, _ "dword", 0, _ "dword", 0) If @error Or Not $a_hCall[0] Then DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Return SetError(3, 0, "") EndIf Local $pFile = $a_hCall[0] Local $iBufferSize = FileGetSize($sFile) Local $a_iCall = DllCall("advapi32.dll", "int", "CryptAcquireContext", _ "ptr*", 0, _ "ptr", 0, _ "ptr", 0, _ "dword", 1, _ ; PROV_RSA_FULL "dword", 0xF0000000) ; CRYPT_VERIFYCONTEXT If @error Or Not $a_iCall[0] Then DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Return SetError(4, 0, "") EndIf Local $hContext = $a_iCall[1] $a_iCall = DllCall("advapi32.dll", "int", "CryptCreateHash", _ "ptr", $hContext, _ "dword", 0x00008004, _ ; CALG_SHA1 "ptr", 0, _ ; nonkeyed "dword", 0, _ "ptr*", 0) If @error Or Not $a_iCall[0] Then DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) DllCall("advapi32.dll", "int", "CryptReleaseContext", "ptr", $hContext, "dword", 0) Return SetError(5, 0, "") EndIf Local $hHashSHA1 = $a_iCall[5] $a_iCall = DllCall("advapi32.dll", "int", "CryptHashData", _ "ptr", $hHashSHA1, _ "ptr", $pFile, _ "dword", $iBufferSize, _ "dword", 0) If @error Or Not $a_iCall[0] Then DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) DllCall("advapi32.dll", "int", "CryptDestroyHash", "ptr", $hHashSHA1) DllCall("advapi32.dll", "int", "CryptReleaseContext", "ptr", $hContext, "dword", 0) Return SetError(6, 0, "") EndIf Local $tOutSHA1 = DllStructCreate("byte[20]") $a_iCall = DllCall("advapi32.dll", "int", "CryptGetHashParam", _ "ptr", $hHashSHA1, _ "dword", 2, _ ; HP_HASHVAL "ptr", DllStructGetPtr($tOutSHA1), _ "dword*", 20, _ "dword", 0) If @error Or Not $a_iCall[0] Then DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) DllCall("advapi32.dll", "int", "CryptDestroyHash", "ptr", $hHashSHA1) DllCall("advapi32.dll", "int", "CryptReleaseContext", "ptr", $hContext, "dword", 0) Return SetError(7, 0, "") EndIf DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) DllCall("advapi32.dll", "int", "CryptDestroyHash", "ptr", $hHashSHA1) Local $sSHA1 = Hex(DllStructGetData($tOutSHA1, 1)) DllCall("advapi32.dll", "int", "CryptReleaseContext", "ptr", $hContext, "dword", 0) Return SetError(0, 0, $sSHA1) EndFunc ;==>_SHA1ForFile Results are in form of hex strings, but that is easily changed to fit your needs. First time is the hardest - you will see what I mean if you run it (file mapping related). Try it on something big.1 point