Jump to content

Control Taskbar Buttons


wraithdu
 Share

Recommended Posts

I finally found a solution for a problem I had a while ago, which was the good old "Minimize to Tray" option, without resorting to hiding the window. The ITaskbarList COM interface can Add, Delete, and Activate taskbar buttons from window handles. One caveat is that the window must have the $WS_CAPTION style. It was necessary to implement these methods via plugin, since AutoIt is unable to access this COM interface.

On success the functions return 0 (S_OK). If an error occurred, they return 1 and set @error to 1 as well.

The Visual Studio project is attached, with the DLL in the Release folder. The sample script should be pretty explanatory.

Functions -

/****************************************************************************
* ActivateTab()
*
* Activates an item on the taskbar. The window is not actually activated;
* the window's item on the taskbar is merely displayed as active.
* 
* ActivateTab(hWnd)
*----------
* AddTab()
*
* Adds an item to the taskbar.
* 
* AddTab(hWnd)
*----------
* DeleteTab()
*
* Deletes an item from the taskbar. 
* 
* DeleteTab(hWnd)
*----------
* SetActiveAlt()
*
* Marks a taskbar item as active but does not visually activate it. 
* 
* SetActiveAlt(hWnd)
*
****************************************************************************/

Example -

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_PlugIn_Funcs=ActivateTab,AddTab,DeleteTab,SetActiveAlt
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GuiConstantsEx.au3>
#include <Constants.au3>

Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 1)

$h_DLL = PluginOpen("ITBL_plugin.dll")
$hwnd = GUICreate("Test GUI", 200, 100)
$cbox = GUICtrlCreateCheckbox("Hide my taskbar button", 20, 20)
GUISetState()

Sleep(1000)
DeleteTab($hwnd)
Sleep(1000)
AddTab($hwnd)
Sleep(1000)
; make sure window is not active to see this effect
ActivateTab($hwnd)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $cbox
            Switch BitAND(GUICtrlRead($cbox), $GUI_CHECKED)
                Case $GUI_CHECKED
                    DeleteTab($hwnd)
                Case Else
                    AddTab($hwnd)
            EndSwitch
        Case $GUI_EVENT_MINIMIZE
            ; hide taskbar button
            DeleteTab($hwnd)
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    $msg = TrayGetMsg()
    Switch $msg
        Case $TRAY_EVENT_PRIMARYDOWN
            GUISetState(@SW_RESTORE)
    EndSwitch
WEnd

PluginClose($h_DLL)

ITBL_plugin.zip

Edited by wraithdu
Link to comment
Share on other sites

I've tried converting this into AutoIt, but like you I came across a lot of problems.

The first problem I ran into is that I was unable to find a ProgID with the specified CLSID.

if anyone else wants to check it out, it's in: HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{56FDF344-FD6D-11d0-958A-006097C9A090}

Your script works great, but there's just got to be a way to do this in AutoIt.

Link to comment
Share on other sites

  • 2 weeks later...

I just noticed your reply. I did some digging through the AutoIt help file. There are 3 things that are needed by AutoIt to use a COM object. They are -

1. VersionIndependentProgID

2. a TypeLib assignment

3. the IDispatch interface

ITaskbarList is an interface, not an object, so it has none of the 3 requirements. I don't know how to search for objects that use a specific interface. Your only chance for using this directly in AutoIt would be to find an object that AutoIt can access (has the above 3 requirements) and exposes the ITaskbarList interface and methods.

Link to comment
Share on other sites

Well, wecould do something, if we had

a) full com/ole support :(

:mellow: had DllCall for Pointers and knew the structure of such an Interface, this is easier to implement for the developers:

$ITaskbarList = "ptr lpVtbl"
$ITaskbarListVtbl = "ptr QueryInterface; ptr AddRef; ptr Release; ptr HrInit; ptr AddTab; ptr DeleteTab; ptr ActivateTab; ptr SetActiveAlt")

Global Const $HRESULT =  "LONG"
        
;CALL THE FUNCS, e.g. AddTab:

    Local $List = DllStructCreate($ITaskbarList,$lpITaskbarList) ; get pointer to pointertable
    Local $Funcs = DllStructCreate($ITaskbarListVtbl,DllStructGetData($List,1)) ; get func pointer list
    Local $lpAddTab = DllStructGetData($Funcs,"AddTab") ; the function pointer
    DllCall(0,$HRESULT,$lpAddTab,"ptr",$lpITaskbarList,"hwnd",$WindowHandle) ; Call a func by pointer

i found the Interface here: http://blog.csdn.net/everandforever/archiv.../22/461208.aspx

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

OK, here is an example completely in AutoIt :mellow: (needs MemoryDLL.au3, since DLLCall doesn't support pointers)

#include <WinAPI.au3>
#include "MemoryDLL\MemoryDLL.au3"
$ITaskbarList = "ptr lpVtbl"
$ITaskbarListVtbl = "ptr QueryInterface; ptr AddRef; ptr Release; ptr HrInit; ptr AddTab; ptr DeleteTab; ptr ActivateTab; ptr SetActiveAlt"

Global Const $HRESULT =  "LONG"
;~ $ITaskbarList_QueryInterface = DllCallbackRegister("ITaskbarList_QueryInterface",$HRESULT,"ptr;ptr;ptr")
    ;HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
        ;ITaskbarList * This,
        ;/* [in] */ REFIID riid,
        ;/* [iid_is][out] */ void **ppvObject);

;~ $ITaskbarList_AddRef = DllCallbackRegister("ITaskbarList_AddRef",$HRESULT,"ptr")
    ;ULONG ( STDMETHODCALLTYPE *AddRef )(
        ;ITaskbarList * This);
        
;~ $ITaskbarList_Release = DllCallbackRegister("ITaskbarList_Release",$HRESULT,"ptr")
    ;ULONG ( STDMETHODCALLTYPE *Release )(
        ;ITaskbarList * This);
    
;~ $ITaskbarList_HrInit = DllCallbackRegister("ITaskbarList_HrInit",$HRESULT,"ptr")
    ;HRESULT ( STDMETHODCALLTYPE *HrInit )(
        ;ITaskbarList * This);

;~ $ITaskbarList_AddTab = DllCallbackRegister("ITaskbarList_AddTab",$HRESULT,"ptr;hwnd")
    ;HRESULT ( STDMETHODCALLTYPE *AddTab )(
        ;ITaskbarList * This,
        ;/* [in] */ HWND hwnd);
        
;~ $ITaskbarList_DeleteTab = DllCallbackRegister("ITaskbarList_DeleteTab",$HRESULT,"ptr;hwnd")
    ;HRESULT ( STDMETHODCALLTYPE *DeleteTab )(
        ;ITaskbarList * This,
        ;/* [in] */ HWND hwnd);

;~ $ITaskbarList_ActivateTab = DllCallbackRegister("ITaskbarList_ActivateTab",$HRESULT,"ptr;hwnd")
    ;HRESULT ( STDMETHODCALLTYPE *ActivateTab )(
        ;ITaskbarList * This,
        ;/* [in] */ HWND hwnd);
    
;~ $ITaskbarList_SetActiveAlt = DllCallbackRegister("ITaskbarList_SetActiveAlt",$HRESULT,"ptr;hwnd")
    ;HRESULT ( STDMETHODCALLTYPE *SetActiveAlt )(
        ;ITaskbarList * This,
        ;/* [in] */ HWND hwnd);
        
;CALL THE FUNCS, e.g. AddTab:
$OLE32 = DllOpen("ole32.dll")

Global Const $CLSCTX_INPROC_SERVER = 1
Global Const $CLSCTX_LOCAL_SERVER = 4
Global Const $CLSCTX_SERVER = BitOR($CLSCTX_INPROC_SERVER , $CLSCTX_LOCAL_SERVER)

; Prog@ndy
Func _GUIDStruct($IID)
    $IID = StringRegExpReplace($IID,"([}{])","")
    $IID = StringSplit($IID,"-")
    Local $_GUID =  "DWORD Data1;  ushort Data2;  ushort Data3;  BYTE Data4[8];"
    Local $GUID = DllStructCreate($_GUID)
    If $IID[0] = 5 Then $IID[4] &= $IID[5]
    If $IID[0] > 5 Or $IID[0] < 4 Then Return SetError(1,0,0)
    DllStructSetData($GUID,1,Dec($IID[1]))
    DllStructSetData($GUID,2,Dec($IID[2]))
    DllStructSetData($GUID,3,Dec($IID[3]))
    DllStructSetData($GUID,4,Binary("0x"&$IID[4]))
    Return $GUID
EndFunc

;~ $IID_ITaskbarList = _GUIDStruct("56FDF344-FD6D-11D0-958A006097C9A090")
$IID_ITaskbarList = _GUIDStruct("{56FDF342-FD6D-11d0-958A-006097C9A090}")
$CLSID_TaskBarlist = _GUIDStruct("56FDF344-FD6D-11D0-958A006097C9A090")
;~ $CLSID_TaskBarlist = _GUIDStruct("{56FDF342-FD6D-11d0-958A-006097C9A090}")


; Initialise OLE
DllCall($OLE32,"long","CoInitialize","ptr",0)

; Create the ITaskbarlist interface
$ret = DllCall($OLE32,"long_ptr","CoCreateInstance","ptr",DllStructGetPtr($CLSID_TaskBarlist),"ptr",0,"dword",$CLSCTX_SERVER, "ptr",DllStructGetPtr($IID_ITaskbarList),"ptr*",0)
$lpITaskbarList = $ret[5]

; get the interface
Local $COM_Interface_ITaskbarList = DllStructCreate($ITaskbarList,$lpITaskbarList)
Local $COM_Interface_ITaskbarList_FunctionTable = DllStructCreate($ITaskbarListVtbl,DllStructGetData($COM_Interface_ITaskbarList,1))
    

MemoryFuncInit()
MemoryFuncCall($HRESULT,DllStructGetData($COM_Interface_ITaskbarList_FunctionTable,"HrInit"),"ptr",$lpITaskbarList)


#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_PlugIn_Funcs=ActivateTab,AddTab,DeleteTab,SetActiveAlt
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GuiConstantsEx.au3>
#include <Constants.au3>

Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 1)

;~ $h_DLL = PluginOpen("ITBL_plugin.dll")
$hwnd = GUICreate("Test GUI", 200, 100)
$cbox = GUICtrlCreateCheckbox("Hide my taskbar button", 20, 20)
GUISetState()

Sleep(1000)
MemoryFuncCall($HRESULT,DllStructGetData($COM_Interface_ITaskbarList_FunctionTable,"DeleteTab"),"ptr",$lpITaskbarList,"hwnd",$hwnd)
Sleep(1000)
MemoryFuncCall($HRESULT,DllStructGetData($COM_Interface_ITaskbarList_FunctionTable,"AddTab"),"ptr",$lpITaskbarList,"hwnd",$hwnd)

MsgBox(0, '', "Please Activate another window the next 2 seconds")
Sleep(3000)
; make sure window is not active to see this effect
MemoryFuncCall($HRESULT,DllStructGetData($COM_Interface_ITaskbarList_FunctionTable,"ActivateTab"),"ptr",$lpITaskbarList,"hwnd",$hwnd)
MsgBox(0, '', "Did you see? Button is activated without the window")
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $cbox
            Switch BitAND(GUICtrlRead($cbox), $GUI_CHECKED)
                Case $GUI_CHECKED
                    MemoryFuncCall($HRESULT,DllStructGetData($COM_Interface_ITaskbarList_FunctionTable,"DeleteTab"),"ptr",$lpITaskbarList,"hwnd",$hwnd)
                Case Else
                    MemoryFuncCall($HRESULT,DllStructGetData($COM_Interface_ITaskbarList_FunctionTable,"AddTab"),"ptr",$lpITaskbarList,"hwnd",$hwnd)
            EndSwitch
        Case $GUI_EVENT_MINIMIZE
            ; hide taskbar button
            DeleteTab($hwnd)
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    $msg = TrayGetMsg()
    Switch $msg
        Case $TRAY_EVENT_PRIMARYDOWN
            GUISetState(@SW_RESTORE)
    EndSwitch
WEnd

Func OnAutoItExit()
    MemoryFuncCall($HRESULT,DllStructGetData($COM_Interface_ITaskbarList_FunctionTable,"Release"),"ptr",$lpITaskbarList)
    MemoryFuncExit()
    DllCall($OLE32,"long","CoUninitialize")
EndFunc

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Well, i'm not sure. Does the MemoryFuncCall work on Vista or with data execution protection in x64 ?

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Well, your plugin could work :mellow: The problem is, MemoryFuncCall uses _WinAPI_WriteProcessMemory to write the func pointer to a known Func name.. Donst know if DEP on x64 does allow it ...

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

I made a UDF out of your tab control stuff. I will use this often because I don't want my title to show in the taskbar so instead of having explorer be its parent, I will use this! Thanks.

For Type param use: 0 for Delete, 1 for Create, and 2 for Activate

TabControl.au3

#include-once

Global $_MDCodeBuffer, $_MDLoadOffset, $_MDGetOffset, $_MDFreeOffset
Global $_MFHookPtr, $_MFHookBak, $_MFHookApi = "LocalCompact"

Func _TabControl($Hwnd, $Type)
    Switch $Type
        Case 0
            $Type = "DeleteTab"
        Case 1
            $Type = "AddTab"
        Case 2
            $Type = "ActivateTab"
        Case Else
            Return 0
    EndSwitch
    $ITaskbarList = "ptr lpVtbl"
    $ITaskbarListVtbl = "ptr QueryInterface; ptr AddRef; ptr Release; ptr HrInit; ptr AddTab; ptr DeleteTab; ptr ActivateTab; ptr SetActiveAlt"
    $HRESULT = "LONG"
    $OLE32 = DllOpen("ole32.dll")
    $CLSCTX_SERVER = BitOR(1, 4)
    $IID_ITaskbarList = _GUIDStruct("{56FDF342-FD6D-11d0-958A-006097C9A090}")
    $CLSID_TaskBarlist = _GUIDStruct("56FDF344-FD6D-11D0-958A006097C9A090")
    DllCall($OLE32, "long", "CoInitialize", "ptr", 0)
    $ret = DllCall($OLE32, "long_ptr", "CoCreateInstance", "ptr", DllStructGetPtr($CLSID_TaskBarlist), "ptr", 0, "dword", $CLSCTX_SERVER, "ptr", DllStructGetPtr($IID_ITaskbarList), "ptr*", 0)
    $lpITaskbarList = $ret[5]
    $COM_Interface_ITaskbarList = DllStructCreate("ptr lpVtbl", $lpITaskbarList)
    $COM_Interface_ITaskbarList_FunctionTable = DllStructCreate($ITaskbarListVtbl, DllStructGetData($COM_Interface_ITaskbarList, 1))
    MemoryFuncInit()
    MemoryFuncCall($HRESULT, DllStructGetData($COM_Interface_ITaskbarList_FunctionTable, "HrInit"), "ptr", $lpITaskbarList)
    MemoryFuncCall($HRESULT, DllStructGetData($COM_Interface_ITaskbarList_FunctionTable, $Type), "ptr", $lpITaskbarList, "hwnd", $hwnd)
    MemoryFuncCall($HRESULT, DllStructGetData($COM_Interface_ITaskbarList_FunctionTable, "Release"), "ptr", $lpITaskbarList)
    MemoryFuncExit()
    DllCall($OLE32, "long", "CoUninitialize")
    DllClose($OLE32)
    Return 1
EndFunc   ;==>_HideTab

Func _GUIDStruct($IID)
    $IID = StringRegExpReplace($IID, "([}{])", "")
    $IID = StringSplit($IID, "-")
    Local $_GUID = "DWORD Data1;  ushort Data2;  ushort Data3;  BYTE Data4[8];"
    Local $GUID = DllStructCreate($_GUID)
    If $IID[0] = 5 Then $IID[4] &= $IID[5]
    If $IID[0] > 5 Or $IID[0] < 4 Then Return SetError(1, 0, 0)
    DllStructSetData($GUID, 1, Dec($IID[1]))
    DllStructSetData($GUID, 2, Dec($IID[2]))
    DllStructSetData($GUID, 3, Dec($IID[3]))
    DllStructSetData($GUID, 4, Binary("0x" & $IID[4]))
    Return $GUID
EndFunc   ;==>_GUIDStruct

Func MemoryFuncInit()
    Local $KernelHandle = DllCall("kernel32.dll", "ptr", "LoadLibrary", "str", "kernel32.dll")
    Local $HookPtr = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $KernelHandle[0], "str", $_MFHookApi)
    $_MFHookPtr = $HookPtr[0]

    $_MFHookBak = DllStructCreate("ubyte[7]")
    DllCall("kernel32.dll", "int", "WriteProcessMemory", "ptr", -1, "ptr", DllStructGetPtr($_MFHookBak), "ptr", $_MFHookPtr, "uint", 7, "uint*", 0)

    DllCall("kernel32.dll", "int", "WriteProcessMemory", "ptr", -1, "ptr", $_MFHookPtr, "byte*", 0xB8, "uint", 1, "uint*", 0)
    DllCall("kernel32.dll", "int", "WriteProcessMemory", "ptr", -1, "ptr", $_MFHookPtr + 5, "ushort*", 0xE0FF, "uint", 2, "uint*", 0)
EndFunc

Func MemoryFuncCall($RetType, $Address, $Type1 = "", $Param1 = 0, $Type2 = "", $Param2 = 0, $Type3 = "", $Param3 = 0, $Type4 = "", $Param4 = 0, $Type5 = "", $Param5 = 0, $Type6 = "", $Param6 = 0, $Type7 = "", $Param7 = 0, $Type8 = "", $Param8 = 0, $Type9 = "", $Param9 = 0, $Type10 = "", $Param10 = 0, $Type11 = "", $Param11 = 0, $Type12 = "", $Param12 = 0, $Type13 = "", $Param13 = 0, $Type14 = "", $Param14 = 0, $Type15 = "", $Param15 = 0, $Type16 = "", $Param16 = 0, $Type17 = "", $Param17 = 0, $Type18 = "", $Param18 = 0, $Type19 = "", $Param19 = 0, $Type20 = "", $Param20 = 0)
    If Not IsDllStruct($_MFHookBak) Then MemoryFuncInit()

    MemoryFuncSet($Address)
    Local $DllCallStr = 'DllCall("kernel32.dll", "' & $RetType & '", "' & $_MFHookApi & '"', $n, $i
    For $i = 4 To @NumParams Step 2
        $n = ($i - 2) / 2
        $DllCallStr &= ', $Type' & $n & ', $Param' & $n
    Next
    $DllCallStr &= ')'
    Local $Ret = Execute($DllCallStr)
    Return $Ret
EndFunc

Func MemoryFuncSet($Address)
    DllCall("kernel32.dll", "int", "WriteProcessMemory", "ptr", -1, "ptr", $_MFHookPtr + 1, "uint*", $Address, "uint", 4, "uint*", 0)
EndFunc

Func MemoryFuncExit()
    DllCall("kernel32.dll", "int", "WriteProcessMemory", "ptr", -1, "ptr", $_MFHookPtr, "ptr", DllStructGetPtr($_MFHookBak), "uint", 7, "uint*", 0)
    $_MFHookBak = 0
EndFunc

Func MemoryDllInit()
    If IsDllStruct($_MDCodeBuffer) Then Return

    Local $Opcode = '0xFFFFFFFFFFFFFFFFB800000000FFE0B800000000FFE0B800000000FFE0B800000000FFE0B800000000FFE0B800000000FFE0B800000000FFE0B800000000FFE0B800000000FFE0B800000000FFE0B800000000FFE0B800000000FFE0B800000000FFE0B800000000FFE0B800000000FFE0B800000000FFE05589E55156578B7D088B750C8B4D10FCF3A45F5E595DC359585A5153E8000000005B81EBC511400089832C114000899330114000E8000000005981E9DD114000518B912C114000E80B0000007573657233322E646C6C005850FFD2598B9130114000E80C0000004D657373616765426F784100595150FFD289839E114000E8000000005981E927124000518B912C114000E80D0000006B65726E656C33322E646C6C005850FFD2598B9130114000E80A0000006C737472636D70694100595150FFD2898335114000E8000000005981E971124000518B912C114000E80D0000006B65726E656C33322E646C6C005850FFD2598B9130114000E80D0000005669727475616C416C6C6F6300595150FFD289833C114000E8000000005981E9BE124000518B912C114000E80D0000006B65726E656C33322E646C6C005850FFD2598B9130114000E80C0000005669727475616C4672656500595150FFD2898343114000E8000000005981E90A134000518B912C114000E80D0000006B65726E656C33322E646C6C005850FFD2598B9130114000E80F0000005669727475616C50726F7465637400595150FFD289834A114000E8000000005981E959134000518B912C114000E80D0000006B65726E656C33322E646C6C005850FFD2598B9130114000E80E00000052746C5A65726F4D656D6F727900595150FFD2898351114000E8000000005981E9A7134000518B912C114000E80D0000006B65726E656C33322E646C6C005850FFD2598B9130114000E80D0000004C6F61644C6962726172794100595150FFD2898358114000E8000000005981E9F4134000518B912C114000E80D0000006B65726E656C33322E646C6C005850FFD2598B9130114000E80F00000047657450726F634164647265737300595150FFD289835F114000E8000000005981E943144000518B912C114000E80D0000006B65726E656C33322E646C6C005850FFD2598B9130114000E80D00000049734261645265616450747200595150FFD2898366114000E8000000005981E990144000518B912C114000E80D0000006B65726E656C33322E646C6C005850FFD2598B9130114000E80F00000047657450726F636573734865617000595150FFD289836D114000E8000000005981E9DF144000518B912C114000E80D0000006B65726E656C33322E646C6C005850FFD2598B9130114000E80A00000048656170416C6C6F6300595150FFD2898374114000E8000000005981'
        $Opcode &= 'E929154000518B912C114000E80D0000006B65726E656C33322E646C6C005850FFD2598B9130114000E809000000486561704672656500595150FFD289837B114000E8000000005981E972154000518B912C114000E80D0000006B65726E656C33322E646C6C005850FFD2598B9130114000E80C000000476C6F62616C416C6C6F6300595150FFD2898382114000E8000000005981E9BE154000518B912C114000E80D0000006B65726E656C33322E646C6C005850FFD2598B9130114000E80E000000476C6F62616C5265416C6C6F6300595150FFD2898390114000E8000000005981E90C164000518B912C114000E80D0000006B65726E656C33322E646C6C005850FFD2598B9130114000E80B000000476C6F62616C4672656500595150FFD2898389114000E8000000005981E957164000518B912C114000E80D0000006B65726E656C33322E646C6C005850FFD2598B9130114000E80C000000467265654C69627261727900595150FFD28983971140005B59585150E8B40A000059C35990585A515250E8E60B0000C35A585250E8930C000059C34D5A50000200000004000F00FFFF0000B80000000000000040001A0000000000535048494E5820432D2D20302E3233394A616E20313920323030370060000000BA0E000E1FB409CD21B8014CCD21466F722057696E3332206F6E6C79210D0A24504500004C010100000000000000000000000000E0008EA10B0100EF000400000000000000000000001000000010000000000000000040000010000000020000010000000000000004000000000000000020000000020000000000000300010000800000000800000000010000100000000000001000000070110000E5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000434F44450000000000100000001000000004000000020000000000000000000000000000600000E0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000031C040C20C005589E5B878563412FFE0C8040000538B450803450C0345100345140345188945FC5BC9C21400C8040000538B45088B008B5D0C03038B5D1003038B5D1403038B5D1803038945FC8B5D088B036BC00A89038B5D0C8B036BC00A89038B5D108B036BC00A'
        $Opcode &= '89038B5D148B036BC00A89038B5D188B036BC00A89038B45FC5BC9C214006A0A58C35589E58B450801C05DC204005589E58B450803450C5DC208005589E58B450803450C0345105DC20C005589E58B450803450C0345100345145DC210005589E58B450803450C0345100345140345185DC214005589E58B450803450C03451003451403451803451C0345205DC21C005589E58B450803450C03451003451403451803451C03452003452403452803452C03453003453403453803453C0345405DC23C005589E58B450803450C03451003451403451803451C03452003452403452803452C03453003453403453803453C03454003454403454803454C0345500345545DC2500000000000000000000000000006120000010000000B0000000B00000098110000C4110000F0110000871000008B100000F9100000971000002D110000A4100000B4100000C7100000DD1000002C1000001010000012120000181200001E120000251200002B12000032120000381200003E120000441200004A1200004F12000000000100020003000400050006000700080009000A0054657374444C4C2E646C6C0046756E63300046756E63310046756E6331350046756E63320046756E6332300046756E63330046756E63340046756E63350046756E633700746573740074657374320000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C804000068C2164000BE80244000FF36BE84244000FF36E8DDF4FFFF8945FC85C00F851000000068AE1D4000FF159424400083C404C9C35468D01D4000FF159424400083C40868D51D4000FF75FCE895F9FFFF89C2BB8C2440008B1B6A026A016A1452E822F3FFFF6A'
        $Opcode &= '056A046A036A00E815F3FFFF6A086A076A066A00E808F3FFFF6A0B6A0A6A096A00E8FBF2FFFF6A0E6A0D6A0C6A00E8EEF2FFFF6A116A106A0F6A00E8E1F2FFFF6A146A136A126A00E8D4F2FFFF5068DC1D4000FF159424400083C4085468D01D4000FF159424400083C408FF75FCE819F9FFFF68E91D4000FF159424400083C404C9C343616E2774206C6F6164206C6962726172792066726F6D206D656D6F72792E0D0A0025580D0A0046756E63323000526573756C743A2025640D0A0066696E697368005589E551505356578B45108B4804894DF88B000FB750148D7C101831DBEB69837F100075318B450C8B40388945FC09C07E526A046800100000508B470C0345F850E805F3FFFF89C6897708FF75FC56E80CF3FFFFEB2E6A046800100000FF77108B470C0345F850E8DFF2FFFF89C6FF77108B47140345085056E836F3FFFF83C40C8977084383C7288B45108B000FB7400639C37C8A5F5E5BC9C35589E583EC245356578B5D088B030FB750148D7C101831F6E9BB000000F74724000000200F95C083E0018945F4F74724000000400F95C083E0018945F0F74724000000800F95C083E0018945ECF747240000000274126800400000FF7710FF7708E852F2FFFFEB6C8B55EC8B4DF08B45F4C1E0048D8CC8D42340008B14918955F8F7472400000004740666814DF800028B47108945FC09C0751EF6472440740A8B038B40208945FCEB0EF647248074088B038B40248945FC837DFC0074168D45E850FF75F8FF7710FF7708E8EFF1FFFF09C075004683C7288B030FB7400639C60F8C37FFFFFF5F5E5BC9C35589E583EC1C53568B5D0C8B45088B70048B0089C181C1A00000008379040074778B0101F08945FCEB668B45FC8B0001F08945F48B45FC83C0088945F831C9EB358B55F80FB712C1FA0C8955F08B45F80FB70025FF0F00008945EC89D009C0741083F803750B8B45EC0345F48945E80118418345F8028B55FC8B520483EA08D1EA39D172BC8B45FC89C20350048955FC8B45FC83380075925E5BC9C35589E583EC185356578B5D0831F6468B7B048B0305800000008945FC837804000F841E0100008B0001F88945F8E9F70000008B45F88B400C01F850E806F1FFFF8945EC83F8FF750731F6E9F5000000837B080074176A408B530C42C1E20252FF7308E817F1FFFF894308EB128B530C42C1E202526A40E8F5F0FFFF894308837B0800750731F6E9B90000008B530C8B4B0C41894B0C8B4B088B45EC8904918B45F883380074118B0801F9894DF48B401001F88945F0EB628B45F88B481001F9894DF48B401001F88945F0EB4D8B45F4F7000000008074130FB70050FF75ECE86AF0FFFF8B55F08902EB1B8B45F48B0001F88945E883C00250FF75ECE84DF0FFFF8B55F089028B45F0833800750431F6EB108345F4048345F0048B'
        $Opcode &= '45F483380075AB09F6741F8345F8146A14FF75F8E821F0FFFF09C0750D8B55F8837A0C000F85EEFEFFFF89F05F5E5BC9C35589E583EC145356578B45088945FC6681384D5A740731C0E91E0100008B45FC8B403C89C6037508813E50450000740731C0E9040100006A046800200000FF7650FF7634E896EFFFFF89C309DB75136A046800200000FF76506A00E87FEFFFFF89C309DB750731C0E9CE000000E89EEFFFFF6A146A0050E89BEFFFFF89C7895F0483670C0083670800836710006A046800100000FF765053E842EFFFFF6A046800100000FF765453E832EFFFFF8945F88B45FC8B503C0356545250FF75F8E885EFFFFF8B45FC8B403C0345F889078958345756FF7508E8B9FBFFFF83C41889D82B46348945F4740A5057E82AFDFFFF83C40857E8BDFDFFFF5909C0743557E82BFCFFFF598B078378280074228B078B402801D88945F0741A6A006A0153FF55F08945EC09C0740BC747100100000089F8EB0957E8BF0000005931C05F5E5BC9C35589E583EC0C5356578B45088B4804894DF8834DF4FF8B0089C783C778837F0400750731C0E9860000008B070345F88945FC83781800740683781400750431C0EB6E8B45FC8B482089CF037DF88B402489C3035DF831F6EB218B070345F850FF750CE831EEFFFF09C075080FB7038945F4EB0F4683C70483C3028B45FC3B701872D7837DF4FF750431C0EB248B45FC8B40143945F4760431C0EB158B5DF88B55F48B4DFC8B491C01D98B149189D001D85F5E5BC9C208005589E5515356578B7D0809FF746E837F100074198B078B40280347048945FC6A006A00FF7704FF55FC83671000837F0800742631F6EB158B5F08833CB3FF740B8B5F08FF34B3E8F8EDFFFF463B770C7CE6FF7708E8DCEDFFFF837F0400740F68008000006A00FF7704E881EDFFFFE8A6EDFFFF576A0050E8ABEDFFFF5F5E5BC9C3'

    $_MDLoadOffset = (StringInStr($Opcode, "59585A51") - 1) / 2 - 1
    $_MDGetOffset = (StringInStr($Opcode, "5990585A51") - 1) / 2 - 1
    $_MDFreeOffset = (StringInStr($Opcode, "5A585250") - 1) / 2 - 1

    $_MDCodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
    DllStructSetData($_MDCodeBuffer, 1, $Opcode)

    If Not IsDllStruct($_MFHookBak) Then MemoryFuncInit()
EndFunc

Func MemoryDllExit()
    MemoryFuncExit()
    $_MDCodeBuffer = 0
EndFunc

Func MemoryDllOpen($DllBinary)
    If Not IsDllStruct($_MDCodeBuffer) Then MemoryDllInit()

    Local $Ret = DllCall("kernel32.dll", "hwnd", "LoadLibraryA", "str", "kernel32.dll")
    Local $GetProcAddress = DllCall("kernel32.dll", "uint", "GetProcAddress", "hwnd", $Ret[0], "str", "GetProcAddress")
    Local $LoadLibraryA = DllCall("kernel32.dll", "uint", "GetProcAddress", "hwnd", $Ret[0], "str", "LoadLibraryA")

    Local $DllBuffer = DllStructCreate("byte[" & BinaryLen($DllBinary) & "]")
    DllStructSetData($DllBuffer, 1, $DllBinary)

    MemoryFuncSet(DllStructGetPtr($_MDCodeBuffer) + $_MDLoadOffset)
    Local $Module = DllCall("kernel32.dll", "uint", $_MFHookApi, "uint", $LoadLibraryA[0], "uint", $GetProcAddress[0], "ptr", DllStructGetPtr($DllBuffer))

    $DllBuffer = 0
    Return $Module[0]
EndFunc

Func MemoryDllClose($Module)
    MemoryFuncSet(DllStructGetPtr($_MDCodeBuffer) + $_MDFreeOffset)
    DllCall("kernel32.dll", "none", $_MFHookApi, "uint", $Module)
EndFunc

Func MemoryDllCall($Module, $RetType, $Funcname, $Type1 = "", $Param1 = 0, $Type2 = "", $Param2 = 0, $Type3 = "", $Param3 = 0, $Type4 = "", $Param4 = 0, $Type5 = "", $Param5 = 0, $Type6 = "", $Param6 = 0, $Type7 = "", $Param7 = 0, $Type8 = "", $Param8 = 0, $Type9 = "", $Param9 = 0, $Type10 = "", $Param10 = 0, $Type11 = "", $Param11 = 0, $Type12 = "", $Param12 = 0, $Type13 = "", $Param13 = 0, $Type14 = "", $Param14 = 0, $Type15 = "", $Param15 = 0, $Type16 = "", $Param16 = 0, $Type17 = "", $Param17 = 0, $Type18 = "", $Param18 = 0, $Type19 = "", $Param19 = 0, $Type20 = "", $Param20 = 0)
    Local $Ret, $OpenFlag = False
    Local Const $MaxParams = 20
    If (@NumParams < 3) Or (@NumParams > $MaxParams * 2 + 3) Or (Mod(@NumParams, 2) = 0) Then
        SetError(2)
        Return 0
    EndIf

    If Not IsNumber($Module) Then
        $OpenFlag = True
        $Module = MemoryDllOpen($Module)
    EndIf

    If $Module = 0 Then
        If $OpenFlag Then MemoryDllClose($Module)
        SetError(1)
        Return 0
    EndIf

    MemoryFuncSet(DllStructGetPtr($_MDCodeBuffer) + $_MDGetOffset)
    $Ret = DllCall("kernel32.dll", "uint", $_MFHookApi, "uint", $Module, "str", $Funcname)
    If $Ret[0] = 0 Then 
        SetError(3)
        Return 0
    EndIf

    MemoryFuncSet($Ret[0])
    Local $DllCallStr = 'DllCall("kernel32.dll", "' & $RetType & '", "' & $_MFHookApi & '"', $n, $i
    For $i = 5 To @NumParams Step 2
        $n = ($i - 3) / 2
        $DllCallStr &= ', $Type' & $n & ', $Param' & $n
    Next
    $DllCallStr &= ')'
    $Ret = Execute($DllCallStr)

    If $OpenFlag Then MemoryDllClose($Module)
    SetError(0)
    Return $Ret
EndFunc
Edited by TehWhale
Link to comment
Share on other sites

  • 1 month later...

Hm.. very nice, can be usefull! ... I have one question about the subject: can it be used to get the text of the buttons on the task bar? or better, get the handels of the windows that having those buttons on the taskbar :).

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

This interface cannot do those things, no.

But take a look at this, which goes about it a different way (and better IMO, wish I would have thought of it first) -

#include <GuiConstantsEx.au3>
#include <Constants.au3>
#include <GuiToolbar.au3>

Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 1)

$hwnd = GUICreate("Test GUI", 200, 100)
$cbox = GUICtrlCreateCheckbox("Hide my taskbar button", 20, 20)
$hToolbar = ControlGetHandle("[CLASS:Shell_TrayWnd]", "", "ToolbarWindow324")

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $cbox
            Switch BitAND(GUICtrlRead($cbox), $GUI_CHECKED)
                Case $GUI_CHECKED
                    TabState($hwnd)
                Case Else
                    TabState($hwnd, False)
            EndSwitch
        Case $GUI_EVENT_MINIMIZE
            ; hide taskbar button
            TabState($hwnd)
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    $msg = TrayGetMsg()
    Switch $msg
        Case $TRAY_EVENT_PRIMARYDOWN
            GUISetState(@SW_RESTORE)
            If BitAND(GUICtrlRead($cbox), $GUI_CHECKED) <> $GUI_CHECKED Then TabState($hwnd, False)
    EndSwitch
WEnd

Func FindTab($hwnd)
    $text = WinGetTitle($hwnd)
    Local $count = _GUICtrlToolbar_ButtonCount($hToolbar)
    For $i = 0 To $count - 1
        Local $ID = _GUICtrlToolbar_IndexToCommand($hToolbar, $i)
        If StringInStr(_GUICtrlToolbar_GetButtonText($hToolbar, $ID), $text) Then
            Return $ID
        EndIf
    Next
    Return -1 ; can't find button
EndFunc

Func TabState($hwnd, $hide = True)
    Local $ID = FindTab($hwnd)
    If $ID <> -1 Then
        _GUICtrlToolbar_HideButton($hToolbar, $ID, $hide)
    EndIf
EndFunc
Link to comment
Share on other sites

This interface cannot do those things, no.

But take a look at this, which goes about it a different way (and better IMO, wish I would have thought of it first) -

Perfect, thank you, here is what i needed:

#include <GuiToolbar.au3>

$sTaskBarWindows = _WinListTaskBarWindows()
ConsoleWrite($sTaskBarWindows)

Func _WinListTaskBarWindows()
    Local $sRet_List = ""
    Local $hTaskBar = ControlGetHandle("[CLASS:Shell_TrayWnd]", "", "ToolbarWindow322")
    Local $iButton_Count = _GUICtrlToolbar_ButtonCount($hTaskBar)
    
    For $i = 1 To $iButton_Count - 1 Step 2
        $sRet_List &= _GUICtrlToolbar_GetButtonText($hTaskBar, _GUICtrlToolbar_IndexToCommand($hTaskBar, $i)) & @CRLF
    Next
    
    Return $sRet_List
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

  • 3 weeks later...

Here's an update to the above function. This one is much more reliable, as it doesn't match window titles which can be duplicated or even be blank, rather it finds the button's owner's window handle. It is also safe for both XP and Vista as it finds the correct control handle dynamically (you can see the parent-child progression using Spy++).

#include <GuiConstantsEx.au3>
#include <Constants.au3>
#include <GuiToolbar.au3>

Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 1)

Global $hToolbar = _FindToolbarWindow()
Global $gui = GUICreate("Test GUI", 200, 100)
Global $cbox = GUICtrlCreateCheckbox("Hide my taskbar button", 20, 20)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $cbox
            Switch BitAND(GUICtrlRead($cbox), $GUI_CHECKED)
                Case $GUI_CHECKED
                    _HideToolbarButton($gui, $hToolbar)
                Case Else
                    _HideToolbarButton($gui, $hToolbar, False)
            EndSwitch
        Case $GUI_EVENT_MINIMIZE
            ; hide taskbar button
            _HideToolbarButton($gui, $hToolbar)
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    $msg = TrayGetMsg()
    Switch $msg
        Case $TRAY_EVENT_PRIMARYDOWN
            GUISetState(@SW_RESTORE)
            If BitAND(GUICtrlRead($cbox), $GUI_CHECKED) <> $GUI_CHECKED Then _HideToolbarButton($gui, $hToolbar, False)
    EndSwitch
WEnd

Func _FindToolbarWindow()
    ; find explorer toolbar window
    ; XP+
    Local $hDesktop = _WinAPI_GetDesktopWindow()
    Local $hTray = _FindWindowEx($hDesktop, 0, "Shell_TrayWnd", "")
    Local $hReBar = _FindWindowEx($hTray, 0, "ReBarWindow32", "")
    Local $hTask = _FindWindowEx($hReBar, 0, "MSTaskSwWClass", "")
    Return _FindWindowEx($hTask, 0, "ToolbarWindow32", "")
EndFunc

Func _FindWindowEx($hParent, $hChild, $sClass, $sWindow)
    ; must create structs and use ptrs to account for passing a true NULL as classname or window title
    ; simply using "wstr" and "" does NOT work
    Local $s1, $s2
    If $sClass == "" Then
        $sClass = 0
    Else
        $s1 = DllStructCreate("wchar[256]")
        DllStructSetData($s1, 1, $sClass)
        $sClass = DllStructGetPtr($s1)
    EndIf
    If $sWindow == "" Then
        $sWindow = 0
    Else
        $s2 = DllStructCreate("wchar[256]")
        DllStructSetData($s2, 1, $sWindow)
        $sWindow = DllStructGetPtr($s2)
    EndIf
    Local $ret = DllCall("user32.dll", "hwnd", "FindWindowExW", "hwnd", $hParent, "hwnd", $hChild, "ptr", $sClass, "ptr", $sWindow)
    $s1 = 0
    $s2 = 0
    Return $ret[0]
EndFunc

Func _FindToolbarButton($hwnd, $hTB)
    Local $return = -1
    Local $s = DllStructCreate("ptr")
    ; open process owning toolbar control
    Local $PID
    _WinAPI_GetWindowThreadProcessId($hTB, $PID)
    Local $hProcess = _WinAPI_OpenProcess(0x410, False, $PID)
    If $hProcess Then
        Local $count = _GUICtrlToolbar_ButtonCount($hTB)
        For $i = 0 To $count - 1
            Local $ID = _GUICtrlToolbar_IndexToCommand($hTB, $i)
            ; button param is ptr to owner's window handle, stored in target process's memory space :)
            Local $dwData = _GUICtrlToolbar_GetButtonParam($hTB, $ID)
            ; read the window handle from the explorer process
            Local $ret = DllCall("kernel32.dll", "int", "ReadProcessMemory", "ptr", $hProcess, "ptr", $dwData, "ptr", DllStructGetPtr($s), "uint", 4, "uint*", 0)
            If $ret[5] Then
                If $hwnd == DllStructGetData($s, 1) Then
                    $return = $ID
                    ExitLoop
                EndIf
            EndIf
        Next
        _WinAPI_CloseHandle($hProcess)
    EndIf
    Return $return
EndFunc

Func _HideToolbarButton($hwnd, $hTB, $hide = True)
    Local $ID = _FindToolbarButton($hwnd, $hTB)
    If $ID <> -1 Then
        _GUICtrlToolbar_HideButton($hTB, $ID, $hide)
    EndIf
EndFunc
Edited by wraithdu
Link to comment
Share on other sites

@wraithdu

Thanks, it's really more reliable now, because the text returned from button is not always full window title, it's cuted (due to some kind of button text limit i think).

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

  • 2 months later...

Hi all,

This is a great Script. You should just make necessary changes to qualify for an UDF (i will sure try it if i get to remember this when i am finished with my current work!)

i just hid those sampling works and whoa, i was able to use it as an include file and it works wonders. i havent tested all the possible function manipulations, but it just works wonders on hiding the taskbar button.. all i did was to add this to my script.

#include <_TaskBarControl.au3>

$frmMain = GUICreate("MyWindow")

_HideToolbarButton($frmMain, $hToolbar)
works wonders for me. just what i wanted :-)

i am not bothered about showing the task bar button again at the moment, in case i use it and find anything, i wil post here. pretty useful :-)

PS: I am not sure if this is the best way of doing it (seeing there is many a solution available, as always) but this is working for me thanks a lot.

_TaskBarControl.au3

Edited by rajeshontheweb
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...