Hide/Show Task Bar Icon Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
WarlordAkamu67
Posts: 219
Joined: 21 Mar 2023, 06:52

Hide/Show Task Bar Icon

Post by WarlordAkamu67 » 01 Jun 2023, 15:14

I am looking for a script that will hide/show a task bar icon(s). I know very little (might as well be nothing) about using DLL calls properly.

I tried updating a script from the showcase, but the function now tries to return a ComObject.

Code: Select all

toggle := 1

;  Methods in ITaskbarList's VTable:
;    IUnknown:
;      0 QueryInterface  -- use ComObjQuery() instead
;      1 AddRef          -- use ObjAddRef() instead
;      2 Release         -- use ObjRelease() instead
;    ITaskbarList:
;      3 HrInit
;      4 AddTab
;      5 DeleteTab
;      6 ActivateTab
;      7 SetActiveAlt

F1:: {
global
IID_ITaskbarList  := "{56FDF342-FD6D-11d0-958A-006097C9A090}"
CLSID_TaskbarList := "{56FDF344-FD6D-11d0-958A-006097C9A090}"

; Create the TaskbarList object and store its address in tbl.
tbl := ComObject(CLSID_TaskbarList, IID_ITaskbarList)

toggle := !toggle

if (!toggle) {
activeHwnd := WinExist("A")
	DllCall(vtable(tbl,3), "ptr", tbl)                     ; tbl.HrInit()
	DllCall(vtable(tbl,5), "ptr", tbl, "ptr", activeHwnd)  ; tbl.DeleteTab(activeHwnd)
} else {
	DllCall(vtable(tbl,4), "ptr", tbl, "ptr", activeHwnd)  ; tbl.AddTab(activeHwnd)
}

; Non-dispatch objects must always be manually freed.
ObjRelease(tbl)
}

vtable(ptr, n) {
global
    ; NumGet(ptr+0) returns the address of the object's virtual function
    ; table (vtable for short). The remainder of the expression retrieves
    ; the address of the nth function's address from the vtable.
    return NumGet(NumGet(ptr+0, "UPtr"), n*A_PtrSize, "UPtr")
}

return

neogna2
Posts: 590
Joined: 15 Sep 2016, 15:44

Re: Hide/Show Task Bar Icon  Topic is solved

Post by neogna2 » 02 Jun 2023, 04:29

v2 has ComCall for vtable methods. You find the v2 example code to hide/show a taskbar item at
https://www.autohotkey.com/docs/v2/lib/ComCall.htm#ExTaskbar

You could also continue to use DllCall in v2, but then your code has to pass a pointer to the vtable() function and also pass pointers (not COM objects) as DllCall parameters. So for example change from your
DllCall(vtable(tbl,4), "ptr", tbl, "ptr", activeHwnd) ; tbl.AddTab(activeHwnd)
to
DllCall(vtable(tbl.ptr, 4), "Ptr", tbl.ptr, "Ptr", activeHwnd) ; tbl.AddTab(activeHwnd)

See also https://www.autohotkey.com/docs/v2/lib/ComObject.htm#Return_Value about the Ptr property of VT_UNKNOWN COM objects.

User avatar
WarlordAkamu67
Posts: 219
Joined: 21 Mar 2023, 06:52

Re: Hide/Show Task Bar Icon

Post by WarlordAkamu67 » 02 Jun 2023, 05:41

@neogna2 Thanks a bunch!

chopin11
Posts: 8
Joined: 03 Jun 2023, 01:43

Re: Hide/Show Task Bar Icon

Post by chopin11 » 03 Jun 2023, 01:52

#NoTrayIcon

User avatar
boiler
Posts: 16923
Joined: 21 Dec 2014, 02:44

Re: Hide/Show Task Bar Icon

Post by boiler » 03 Jun 2023, 02:03

chopin11 wrote: #NoTrayIcon
They’re not talking about the icons in the system tray, which is what that hides. They are referring to icons on the the main task bar. And #NoTrayIcon doesn’t allow you to show it again once it’s hidden.

Post Reply

Return to “Ask for Help (v2)”