Page 1 of 1

[class][v1/v2] taskbar ornaments and controls

Posted: 02 Aug 2017, 09:01
by Helgef
Introduction
This class implements some of the taskbar extensions discussed here (msdn).
For a full introduction and documentation, please visit the github wiki.
There are two versions available, one for (recent) AHK v1.1 and one for AHK v2 (2.0-a081-cad307c). The version for v2 is cleverly named taskbarInterface_v2.ahk

Graphical preview - a selection
Image
Button controls in the thumbnail preview window, the thumbnail preview is clipped to only show a listbox of the gui.
Image
Progress bar and icon overlay.

Download
Source and self-contained examples are available at github. Direct download: v1.02_with_examples.rar.
Mini tutorial
To highlight the ease of use. I give a mini tutorial.

Part 1 - show an icon overlay.
Image
Code

Part 2 - show a progress bar behind the taskbar icon.
Image
Code

Part 3 - Add two buttons to the thumbnail preview.
Image
Code
Real use example
Please try out wolf_II's nice app Anagrams (v2.13+), for a real use example of this class.

Misc
Feel free to use this in whichever modified or non-modified state you wish, for any peaceful purpose. No credits or references needed.

Have fun and good luck :wave:

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 02 Aug 2017, 09:46
by TheDewd
This is crazy good! Thanks for sharing! Does it work with Windows 10?

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 02 Aug 2017, 09:55
by Helgef
Thanks. I have tested it only briefly on win 10 and saw no problems. All development is done on win7 though. However, I have seen nothing in the documentation of the used apis, suggesting there would be any compabillity issues with win10.

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 02 Aug 2017, 15:55
by wolf_II
Thank you for sharing this class. I really love it. :clap: :thumbup:

I have posted an update to Anagrams that includes credit and link to here.

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 02 Aug 2017, 18:35
by Delta Pythagorean
This is actually quite impressive! I think I'll implement this into some of my programs for later use!

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 02 Aug 2017, 21:57
by joedf
Holy moly, nice! :D

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 03 Aug 2017, 03:58
by Helgef
Thanks for your kind words.

I have added a mini tutorial to the first post. To give a quick insight on how to use this.

Cheers.

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 03 Aug 2017, 09:23
by boiler
Very nice work. Will be quite useful. Thank you for sharing this with us.

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 04 Aug 2017, 15:50
by gwarble
very nice, thanks for sharing

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 10 Aug 2017, 13:59
by jeeswg
@Helgef: many thanks for this.

I would be interested to know if some of these methods can be applied to external taskbar buttons. The main problem is how to get a pointer to the interface. [EDIT:] This can be done simply by using ComObjCreate as shown in the DllCall example below.

[EDIT:] These links were useful, especially the DllCall one:
[advanced] Using raw COM interfaces in AHK - Tutorials - AutoHotkey Community
https://autohotkey.com/board/topic/8107 ... es-in-ahk/
[AHK_L + AHK v2] COM Classes Framework (CCF) - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/6620 ... ework-ccf/
interfaces · maul-esel/COM-Classes Wiki · GitHub
https://github.com/maul-esel/COM-Classe ... interfaces
GitHub - maul-esel/COM-Classes: AHK classes that implement COM interfaces
https://github.com/maul-esel/COM-Classes
[the final example here relates to taskbar buttons:]
DllCall
https://autohotkey.com/docs/commands/DllCall.htm

[EDIT:] After reading up on everything, I wrote an example that shows how to change the colour of taskbar buttons for any window (red/yellow/green):
Distinguishing Between Multiple Windows of Same Application - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 88#p164288

==================================================

To create the object and to make the taskbar button change colour like a progress bar see the 'initInterface' and 'setProgress' functions:
taskbarInterface/taskbarInterface.ahk at master · HelgeffegleH/taskbarInterface · GitHub
https://github.com/HelgeffegleH/taskbar ... erface.ahk

Also see:
ITaskbarList interface (Windows)
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
ITaskbarList3 interface (Windows)
https://msdn.microsoft.com/en-us/librar ... s.85).aspx

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 10 Aug 2017, 16:15
by Helgef
@boiler and gwarble, cheers!
Hello jeeswg :wave:
Regarding applying to external taskbar buttons, I assume you mean buttons belonging to windows not owned by your application. I did write in the documentation that the window must belong to the application, I took that from memory :D I'm somewhat certain I read it somewhere. Your example suggests that at least the progress method can be applied to unowned windows, nice! But keep in mind, whenever the button is destroyed, eg when the window is hidden and then shown again, you need to re-apply the progess. My implementation handles that, but not for windows which doesn't belong to the script.
The main problem is how to get a pointer to the interface.
I'm not certain what you mean.

Cheers.

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 12 Aug 2017, 10:07
by rommmcek
Very impressive! Helgef for Administrator!
Btw: Showing Icon image in the thumbnail seems to be Dpi depended. I'm using Gui, new, hwndhWnd -DPIScale.

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 13 Aug 2017, 03:34
by Helgef
Hello rommmcek.
Good observeration! In a non-example context, one should probably not hardcode the clip coordinates, but rather scale them using A_ScreenDPI, or as you suggest, use -DPIScale. I made a note in the documentation.
@ jeeswg. I saw your edit, which relates to my uncertainty. Note that the when I use the word interface I mean the explicit graphical connection link between the user and the taskbar. taskbarInterface.ahk is not an implementation of the ITaskbarList abstract (data type / class template) interface, it is (partly) a wrapper around window's implementation of that abstract interface.
From your link, ITaskbarList3
Remarks wrote: When to Implement
An implementation of this interface is provided in Windows as CLSID_TaskbarList. This interface is not implemented by third parties.
Cheers.

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 15 Aug 2017, 23:55
by jeeswg
I was interested in whether ITaskbarList/2/3/4 could be used to list all the windows with taskbar buttons. AFAIK there is not a method to do this.

I had hoped that if you tried some of the ITaskbarList/ITaskbarList3 methods using hWnds (e.g. all visible windows retrieved via WinGet) that did/didn't have a taskbar button, the return value, success/failure, would give you a way to determine which hWnds had taskbar buttons and which didn't. Unfortunately the methods I tested appeared to return 0 every time, whether the window had a taskbar button or not.

Anyhow, I mention this in case I missed something, and the approach could be made to work somehow, or if anyone has an alternative approach other than checking window styles/extended styles. Cheers.

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 17 Aug 2017, 13:02
by Helgef
jeeswg, you could check if the functions set A_LastError on failure, I do not remember.
if anyone has an alternative approach other than checking window styles/extended styles
Can you do it by style?

Cheers.
Edit:
jeeswg wrote:qwerty12 wrote a function for listing taskbar buttons:
Nice :thumbup:
Although, a bit off topic ;)
Edit-cheers!

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 17 Aug 2017, 13:42
by jeeswg
Thanks Helgef, A_LastError is a good suggestion but it didn't appear to work.

I've tried adding/removing a tab, and getting the window style/ExStyle before/after, (see the code,) but it didn't show any difference.

I've posted my code, in case I've missed something:

Code: Select all

;useful example at the bottom of:
;DllCall
;https://autohotkey.com/docs/commands/DllCall.htm

;it appears that the return value is always 0, so we don't have info re. identifying which windows have a taskbar button
q:: ;try to set taskbar value, if it fails then check for an error message that would indicate that the window doesn't have a taskbar button
IID_ITaskbarList := "{56FDF342-FD6D-11d0-958A-006097C9A090}"
IID_ITaskbarList3 := "{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}"
CLSID_TaskbarList := "{56FDF344-FD6D-11d0-958A-006097C9A090}"
;itbl := ComObjCreate(CLSID_TaskbarList, IID_ITaskbarList)
itbl := ComObjCreate(CLSID_TaskbarList, IID_ITaskbarList3)

DetectHiddenWindows, Off
WinGet, vWinList, List
DetectHiddenWindows, On
DllCall(vtable(itbl,3), Ptr,itbl) ;HrInit
Loop, % vWinList
{
	hWnd := vWinList%A_Index%
	WinGetTitle, vWinTitle, % "ahk_id " hWnd
	if (vWinTitle = "Untitled - Notepad")
	{
		WinGet, vWinStyle1, Style, % "ahk_id " hWnd
		WinGet, vWinExStyle1, ExStyle, % "ahk_id " hWnd
		DllCall(vtable(itbl,5), Ptr,itbl, Ptr,hWnd) ;DeleteTab
		WinGet, vWinStyle2, Style, % "ahk_id " hWnd
		WinGet, vWinExStyle2, ExStyle, % "ahk_id " hWnd
		DllCall(vtable(itbl,4), Ptr,itbl, Ptr,hWnd) ;AddTab
		WinGet, vWinStyle3, Style, % "ahk_id " hWnd
		WinGet, vWinExStyle3, ExStyle, % "ahk_id " hWnd
		MsgBox, % vWinStyle1 " " vWinExStyle1 "`r`n" vWinStyle2 " " vWinExStyle2 "`r`n" vWinStyle3 " " vWinExStyle3
	}

	DllCall("kernel32\SetLastError", UInt,12345) ;12345 is a 'random' number
	vRet := DllCall(vtable(itbl,9), Ptr,itbl, Ptr,hWnd, Int64,100, Int64,100) ;SetProgressValue
	;vRet := DllCall(vtable(itbl,10), Ptr,itbl, Ptr,hWnd, UInt,0) ;SetProgressState
	;vRet := DllCall(vtable(itbl,5), Ptr,itbl, Ptr,hWnd) ;DeleteTab ;removes taskbar buttons but not alt+tab icons
	;vRet := DllCall(vtable(itbl,6), Ptr,itbl, Ptr,hWnd) ;ActivateTab
	;vRet := DllCall(vtable(itbl,7), Ptr,itbl, Ptr,hWnd) ;SetActiveAlt
	vLastError := A_LastError
	vOutput .= hWnd "|" vRet "|" vLastError "|" vWinTitle "`r`n"
}
Clipboard := vOutput
MsgBox, % "done"
ObjRelease(itbl)
return

;==================================================

vtable(ptr, n) {
    ; 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), n*A_PtrSize)
}

;==================================================
[EDIT:] Btw I was curious as to whether some of the techniques in the script could be used to invoke (open) a specific Internet Explorer tab (or list the tabs, although listing the tabs can be done via COM).

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 25 Aug 2017, 21:02
by jeeswg
qwerty12 wrote a function for listing taskbar buttons:
Script to close all open windows - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 53#p151753

Code: Select all

q:: ;list taskbar buttons
;[GetTaskbarVisibleWindows function]
;Script to close all open windows - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=5&t=32434&p=151753#p151753

DetectHiddenWindows, On
vOutput := ""
for _, hWnd in GetTaskbarVisibleWindows()
{
	WinGetTitle, vWinTitle, % "ahk_id " hWnd
	vOutput .= vWinTitle "`r`n"
}
MsgBox, % SubStr(vOutput, 1, -2)
return

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 27 Apr 2020, 08:37
by zotune
Great script. Would it be possible to set overlay icons on external apps? That would be awesome.

Re: [class][v1/v2] taskbar ornaments and controls

Posted: 28 Apr 2020, 00:22
by Helgef
Thank you zotune :). The documentation says the application must own the window, so it is not supported. You can try though, I believe some features might work for unowned windows.

Cheers.