-
Notifications
You must be signed in to change notification settings - Fork 71
/
TaskbarList3.ahk
380 lines (313 loc) · 10.7 KB
/
TaskbarList3.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
/*
class: TaskbarList3
wraps the *ITaskbarList3* interface and exposes methods that support the unified launching and switching taskbar button functionality added in Windows 7. This functionality includes thumbnail representations and switch targets based on individual tabs in a tabbed application, thumbnail toolbars, notification and status overlays, and progress indicators.
Authors:
- maul.esel (https://github.com/maul-esel)
License:
- *LGPL* (http://www.gnu.org/licenses/lgpl-2.1.txt)
Documentation:
- *class documentation* (http://maul-esel.github.com/COM-Classes/master/TaskbarList3)
- *msdn* (http://msdn.microsoft.com/en-us/library/windows/desktop/dd391692)
Requirements:
AutoHotkey - AHK v2 alpha
OS - Windows 7, Windows Server 2008 R2 or higher
Base classes - _CCF_Error_Handler_, Unknown, TaskbarList, TaskbarList2
Constant classes - TBPFLAG
Structure classes - THUMBBUTTON, RECT
*/
class TaskbarList3 extends TaskbarList2
{
/*
Field: CLSID
This is CLSID_TaskbarList. It is required to create an instance.
*/
static CLSID := "{56FDF344-FD6D-11d0-958A-006097C9A090}"
/*
Field: IID
This is IID_ITaskbarList3. It is required to create an instance.
*/
static IID := "{ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf}"
/*
Method: SetProgressValue
sets the current value of a taskbar progressbar
Parameters:
HWND hWin - the window handle of your gui
INT value - the value to set, in percent
Returns:
BOOL success - true on success, false otherwise.
Example:
(start code)
ITBL3 := new TaskbarList3()
ITBL3.HrInit()
Gui +LastFound
ITBL3.SetProgressValue(WinExist(), 50)
(end code)
*/
SetProgressValue(hWin, value)
{
return this._Error(DllCall(NumGet(this.vt+09*A_PtrSize), "Ptr", this.ptr, "uint", hWin, "int64", value, "int64", 100))
}
/*
Method: SetProgressState
sets the current state and thus the color of a taskbar progressbar
Parameters:
HWND hWin - the window handle of your gui
UINT state - the state to set. You may use the fields of the TBPFLAG class for convenience.
Returns:
BOOL success - true on success, false otherwise.
Example:
(start code)
ITBL3 := new TaskbarList3()
ITBL3.HrInit()
Gui +LastFound
ITBL3.SetProgressState(hWin, TBPFLAG.PAUSED)
(end code)
Remarks:
- There's still a difference between setting progress to 0 or turning it off.
- original function by Lexikos
*/
SetProgressState(hWin, state)
{
return this._Error(DllCall(NumGet(this.vt+10*A_PtrSize), "Ptr", this.ptr, "uint", hWin, "uint", state))
}
/*
Method: RegisterTab
Informs the taskbar that a new tab or document thumbnail has been provided for display in an application's taskbar group flyout.
Parameters:
HWND hTab - the handle to the window to be registered as a tab
HWND hWin - the handle to thew window to hold the tab.
Returns:
BOOL success - true on success, false otherwise.
Example:
(start code)
ITBL3 := new TaskbarList3()
ITBL3.HrInit()
ITBL3.RegisterTab(WinExist("Firefox"), WinExist())
(end code)
*/
RegisterTab(hTab, hWin)
{
return this._Error(DllCall(NumGet(this.vt+11*A_PtrSize), "Ptr", this.ptr, "UInt", hTab, "UInt", hWin))
}
/*
Method: UnRegisterTab
Removes a thumbnail from an application's preview group when that tab or document is closed in the application.
Parameters:
HWND hTab - the handle to the window whose thumbnail gonna be removed.
Returns:
BOOL success - true on success, false otherwise.
Example:
(start code)
ITBL3 := new TaskbarList3()
ITBL3.HrInit()
ITBL3.UnRegisterTab(WinExist("ahk_class AutoHotkey"))
(end code)
*/
UnRegisterTab(hTab)
{
return this._Error(DllCall(NumGet(this.vt+12*A_PtrSize), "Ptr", this.ptr, "UInt", hTab))
}
/*
Method: SetTabOrder
Inserts a new thumbnail into an application's group flyout or moves an existing thumbnail to a new position in the application's group.
Parameters:
HWND hTab - the handle to the window to be inserted or moved.
HWND hBefore - the handle of the tab window whose thumbnail that hwndTab is inserted to the left of.
Returns:
BOOL success - true on success, false otherwise.
Example:
(start code)
ITBL3 := new TaskbarList3()
ITBL3.HrInit()
ITBL3.SetTabOrder(WinExist("ahk_class AutoHotkey"))
(end code)
*/
SetTabOrder(hTab, hBefore := 0)
{
return this._Error(DllCall(NumGet(this.vt+13*A_PtrSize), "Ptr", this.ptr, "UInt", hTab, "UInt", hBefore))
}
/*
Method: SetTabActive
Informs the taskbar that a tab or document window has been made the active window.
Parameters:
HWND hTab - the handle to the tab to become active.
HWND hWin - the handle to the window holding that tab.
Returns:
BOOL success - true on success, false otherwise.
Example:
(start code)
ITBL3 := new TaskbarList3()
ITBL3.HrInit()
ITBL3.SetTabActive(WinExist("ahk_class AutoHotkey"), WinExist())
(end code)
*/
SetTabActive(hTab, hWin)
{
return this._Error(DllCall(NumGet(this.vt+14*A_PtrSize), "Ptr", this.ptr, "UInt", hTab, "UInt", hWin, "UInt", 0))
}
/*
Method: ThumbBarAddButtons
Adds a thumbnail toolbar with a specified set of buttons to the thumbnail image of a window in a taskbar button flyout.
Parameters:
HWND hWin - the handle to the window to work on
THUMBBUTTON[] array - an array of THUMBBUTTON instances, either as AHK array or as pointer to an array in memory.
[opt] UINT count - if "array" is a memory pointer, specify the number of buttons in the array here. If ommitted and "array" is an AHK array, the number is calculated using the array's maxIndex() method.
Returns:
BOOL success - true on success, false otherwise.
Remarks:
- You cannot delete buttons later, and you *cannot add buttons later*. Only call this method 1 time!
- The array may not have more than 7 members.
*/
ThumbBarAddButtons(hWin, array, count := 0)
{
local bool, free_mem := false
if IsObject(array)
count := count ? count : array.maxIndex(), array := this.ParseArray(array), free_mem := true
bool := this._Error(DllCall(NumGet(this.vt + 15 * A_PtrSize), "ptr", this.ptr, "uptr", hWin, "UInt", count, "UPtr", array))
if free_mem
CCFramework.FreeMemory(array)
return bool
}
/*
Method: ThumbBarUpdateButtons
Shows, enables, disables, or hides buttons in a thumbnail toolbar as required by the window's current state.
Parameters:
HWND hWin - the handle to the window to work on
THUMBBUTTON[] array - an array of THUMBBUTTON instances, either as AHK array or as pointer to an array in memory.
[opt] UINT count - if "array" is a memory pointer, specify the number of buttons in the array here. If ommitted and "array" is an AHK array, the number is calculated using the array's maxIndex() method.
Returns:
BOOL success - true on success, false otherwise.
*/
ThumbBarUpdateButtons(hWin, array, count := 0)
{
local bool, free_mem := false
if IsObject(array)
count := count ? count : array.maxIndex(), array := this.ParseArray(array), free_mem := true
bool := this._Error(DllCall(NumGet(this.vt + 16 * A_PtrSize), "ptr", this.ptr, "uptr", hWin, "UInt", count, "UPtr", array))
if free_mem
CCFramework.FreeMemory(array)
return bool
}
/*
Method: ThumbBarSetImageList
Specifies an image list that contains button images for the toolbar
Parameters:
HWND hWin - the handle to the window to work on
HIMAGELIST il - the handle to the imagelist
Returns:
BOOL success - true on success, false otherwise.
*/
ThumbBarSetImageList(hWin, il)
{
return this._Error(DllCall(NumGet(this.vt+17*A_PtrSize), "Ptr", this.ptr, "uint", hWin, "uint", il))
}
/*
Method: SetOverlayIcon
set the overlay icon for a taskbar button
Parameters:
HWND hGui - the window handle of your gui
HICON Icon - handle to an icon
STR altText - an alt text version of the information conveyed by the overlay, for accessibility purposes.
Returns:
BOOL success - true on success, false otherwise.
Remarks:
To get a HICON, you might use LoadImage (http://msdn.microsoft.com/de-de/library/ms648045).
Example:
(start code)
ITBL3 := new TaskbarList3()
ITBL3.HrInit()
ITBL3.SetOverlayIcon(WinExist(), DllCall("LoadIcon", "UInt", 0, "UInt", 32516), "an overlay icon")
(end code)
*/
SetOverlayIcon(hWin, Icon, altText := "")
{
return this._Error(DllCall(NumGet(this.vt+18*A_PtrSize), "Ptr", this.ptr, "uint", hWin, "uint", Icon, "str", altText))
}
/*
Method: SetThumbnailTooltip
set a custom tooltip for your thumbnail
Parameters:
HWND hGui - the window handle of your gui
STR Tooltip - the text to set as your tooltip
Returns:
BOOL success - true on success, false otherwise.
Example:
(start code)
ITBL3 := new TaskbarList3()
ITBL3.HrInit()
ITBL3.SetThumbnailTooltip(WinExist(), "my custom tooltip")
(end code)
*/
SetThumbnailTooltip(hWin, Tooltip)
{
return this._Error(DllCall(NumGet(this.vt+19*A_PtrSize), "Ptr", this.ptr, "UInt", hWin, "str", Tooltip))
}
/*
Method: SetThumbnailClip
limit the taskbar thumbnail of a gui to a specified size instead of the whole window
Parameters:
HWND hGui - the window handle of your gui
RECT clip - a RECT instance describing the area to show in the taskbar thumbnail (or a RECT memory pointer)
Returns:
BOOL success - true on success, false otherwise.
Example:
(start code)
ITBL3 := new TaskbarList3()
ITBL3.HrInit()
Gui +LastFound
ITBL3.SetThumbnailClip(WinExist(), new RECT(0, 0, 100, 100))
(end code)
*/
SetThumbnailClip(hWin, clip)
{
return this._Error(DllCall(NumGet(this.vt+20*A_PtrSize), "Ptr", this.ptr, "UInt", hWin, "UPtr", IsObject(clip) ? clip.ToStructPtr() : clip))
}
/*
group: private methods
Method: ParseArray
parses an array of AHK THUMBBUTTON class instances to an array of THUMBBUTTON memory structures
Parameters:
THUMBBUTTON[] array - an array of THUMBBUTTON instances (see the bottom of this page).
Returns:
UPTR pointer - the pointer to the array in memory. When no longer needed, you should free this by calling CCFramework.FreeMemory() on it.
*/
ParseArray(array)
{
static item_size := THUMBBUTTON.GetRequiredSize()
local count := array.MaxIndex(), ptr
if (count > 7)
count := 7
ptr := CCFramework.AllocateMemory(item_size * count)
for each, button in array ; loop through all button definitions
{
button.ToStructPtr(ptr + item_size * (A_Index - 1))
if (A_Index == 7) ; only 7 buttons allowed
break
}
return ptr
}
/*
group: More about thumbbar buttons
Reacting to clicks:
To react, you must monitor the WM_Command message.
(start code)
OnMessage(0x111, "WM_COMMAND")
; ... add the thumbbuttons & show
WM_COMMAND(wp)
{
static THBN_CLICKED := 0x1800
if (HIWORD(wp) = THBN_CLICKED)
Msgbox 64,,% "The button with the id " . LOWORD(wp) . " was clicked.", 3
}
; these functions below were copied from windows header files
HIWORD(lparam)
{
return lparam >> 16
}
LOWORD(lparam)
{
return lparam & 0xFFFF
}
(end code)
*/
}