-
Notifications
You must be signed in to change notification settings - Fork 71
/
taskbarInterface.ahk
1627 lines (1576 loc) · 71.7 KB
/
taskbarInterface.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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;#include ../../classes/threadFunc/threadFunc.ahk
class taskbarInterface {
static hookWindowClose:=true ; Use SetWinEventHook to automatically clear the interface when its window is destroyed.
static manualClearInterface:=false ; Set to false to automatically clear com interface when the last reference to an object derived from the taskbarInterface class is released. call taskbarInterface.clearInterface()
__new(hwnd,onButtonClickFunction:="",mute:=false){
this.mute:=mute ; By default, errors are thrown. Set mute:=true to suppress exceptions.
if taskbarInterface.allInterfaces.HasKey(hwnd){
this.lastError:=Exception("There is already an interface for this window.",-1)
if mute
Exit
else
throw this.lastError
}
this.dim:=this.queryButtonIconSize() ; this is used by addToImageList.
taskbarInterface.allInterfaces[hwnd]:=this ; allInterfaces array is used for routing the callbacks.
this.hwnd:=hwnd ; Handle to the window whose taskbar preview will recieve the buttons
if !taskbarInterface.init ; On first call here, initialise the com object and turn on button messages. (WM_COMMAND)
taskbarInterface.initInterface() ; Note, must init com before any interface functions are called.
this.setButtonCallback(onButtonClickFunction)
if taskbarInterface.hookWindowClose
this.allowHooking:=true
}
; Context: this = "new taskbarInterface(...)"
; Note, further down the context switches to this=taskbarInterface, for convenience. The switch is clearly marked.
;
; User methods.
;
; Button methods,
; Creates a toolbar with up to seven buttons,
; thee toolbar itself cannot be removed without re-creating the window itself.
;
; - in the following n is the button number, n ∈ [1,7]⊂ℤ
showButton(n){
; Show button n
static THBF_HIDDEN:=0x8
this.updateThumbButtonFlags(n,0,THBF_HIDDEN) ; Add flag 0, remove 0x8 (THBF_HIDDEN)
return this.ThumbBarUpdateButtons(n) ; Update
}
hideButton(n){
; Hide button n
static THBF_HIDDEN:=0x8
this.updateThumbButtonFlags(n,THBF_HIDDEN,0) ; Update flag THBF_HIDDEN:=0x8
return this.ThumbBarUpdateButtons(n) ; Update
}
disableButton(n){
; disable button n
; The button becomes unclickable and grays out.
static THBF_DISABLED:=0x1
this.updateThumbButtonFlags(n,THBF_DISABLED,0) ; Update flag, add THBF_DISABLED:=0x8
return this.ThumbBarUpdateButtons(n) ; Update
}
enableButton(n){
; reenable button n
; the button becomes clickable and regains its
; color.
static THBF_DISABLED:=0x1
this.updateThumbButtonFlags(n,0,THBF_DISABLED) ; Update flag, remove THBF_DISABLED:=0x8
return this.ThumbBarUpdateButtons(n) ; Update
}
setButtonImage(n,nIL){
; Set image for button n.
; nIL is the index of the image to set in the image list, you can add images to the image list via the addToImageList() method
static THB_BITMAP:=0x1
this.updateThumbButtonMask(n,THB_BITMAP,0)
this.setThumbButtoniBitmap(n,nIL)
this.ThumbBarSetImageList()
return this.ThumbBarUpdateButtons(n) ; Update
}
addToImageList(bitmap,bitmapIsHandle:=false){
; Add bitmaps to the imagelist for the buttons
; bitmap, a handle to a bitmap or a path to an image, or and object on the form: [path,iconNumber], eg, bitmap:=[shell32.dll, 37]. Path is relative to script directory if not full.
; specify bitmapIsHandle:=true if bitmap is a handle to a bitmap.
; Returns the added images index in the imagelist. The first image has index 1, second 2 and so on...
; When specifying a handle, call queryButtonIconSize() to obtain the required size of the bitmap. See queryButtonIconSize() below.
local file, iconNumber,hBmp, index
if !this.hImageList
this.hImageList:=IL_Create(7,1)
if bitmapIsHandle {
index:=IL_Add(this.hImageList,"hBitmap:" . bitmap)
} else {
if IsObject(bitmap)
file:=bitmap[1], iconNumber:="Icon" . bitmap[2]
else
file:=bitmap, iconNumber:=""
hBmp:=LoadPicture(file, iconNumber . " Gdi+ w" this.dim.w " h" this.dim.h)
if !hBmp {
this.lastError:=Exception("Invalid file name")
if this.mute
return this.lastError
else
throw this.lastError
}
index:=IL_Add(this.hImageList, "hBitmap:" . hBmp)
}
return index
}
destroyImageList(){
; Destroys the image list for the button images.
; return 1 on success, throws exception or returns exception on failure (depends on mute), returns blank if no imagelist exists.
if (this.hImageList && IL_Destroy(this.hImageList)) {
this.hImageList:=""
return 1
} else if this.hImageList {
this.lastError:=Exception("ImageList destroy failed.")
if this.mute
return this.lastError
else
throw this.lastError
}
return
}
setButtonIcon(n,hIcon){
; Set button icon for button n
; Call queryButtonIconSize() to obtain the required size of the icon. See queryButtonIconSize() below.
static THB_ICON:=0x2
this.updateThumbButtonMask(n,THB_ICON,0) ; Update mask THB_ICON
this.setThumbButtonhIcon(n,hIcon) ; Set the icon handle
return this.ThumbBarUpdateButtons(n) ; Update
}
queryButtonIconSize(){ ; Moved here for convenience
; Returns the required pixel width and height for the button icons.
; Example:
; sz:=taskbarInterface.queryButtonIconSize()
; Msgbox, % "The icon width must be: " sz.w "`nThe icon height must be: " sz.h
local SM_CXICON,SM_CYICON
SysGet, SM_CXICON, 11
SysGet, SM_CYICON, 12
return {w:SM_CXICON, h:SM_CYICON}
}
setButtonToolTip(n,text:=""){
; Sets the tooltip for button n, that is shown when the
; mouse cursors hover over the button for a few seconds.
; Omit text to remove tooltip.
static THB_TOOLTIP:=0x4
if (text!="")
this.updateThumbButtonMask(n,THB_TOOLTIP,0) ; Update mask THB_TOOLTIP, add
this.setThumbButtonToolTipText(n,text) ; Update the text
this.ThumbBarUpdateButtons(n) ; Update the buttons
if (text="")
this.updateThumbButtonMask(n,0,THB_TOOLTIP) ; Update mask THB_TOOLTIP, remove
return
}
dismissPreviewOnButtonClick(n,dismiss:=true){
; Call with dismiss:=true to make button n's click
; to cause the thumbnail preview to be dismissed
; (close). To show again, hover mouse on taskbar icon.
; Call with dismiss:=false to invoke the default
; behaviour, i.e, no dismiss on click.
static THBF_DISMISSONCLICK := 0x2
if dismiss
this.updateThumbButtonFlags(n,THBF_DISMISSONCLICK,0) ; Update flag, add THBF_DISMISSONCLICK:=0x2
else
this.updateThumbButtonFlags(n,0,THBF_DISMISSONCLICK) ; Update flag, remove THBF_DISMISSONCLICK:=0x2
return this.ThumbBarUpdateButtons(n) ; Update
}
removeButtonBackground(n){
; Remove the background (and/or border) of button n.
; The button has a background by default
static THBF_NOBACKGROUND := 0x4
this.updateThumbButtonFlags(n,THBF_NOBACKGROUND,0) ; Update flag, add THBF_NOBACKGROUND:=0x4
return this.ThumbBarUpdateButtons(n) ; Update
}
reAddButtonBackground(n){
; Readd the background (and/or) border of button n.
; Only needed to call if removeButtonBackground(n) was
; previously called
static THBF_NOBACKGROUND := 0x4
this.updateThumbButtonFlags(n,0,THBF_NOBACKGROUND) ; Update flag, remove THBF_NOBACKGROUND:=0x4
return this.ThumbBarUpdateButtons(n) ; Update
}
setButtonNonInteractive(n){
; Set button n to be non-interactive,
; similar to disableButton(n), but the button doesn't gray out.
static THBF_NONINTERACTIVE := 0x10
this.updateThumbButtonFlags(n,THBF_NONINTERACTIVE,0) ; Update flag, add THBF_NONINTERACTIVE:=0x10
return this.ThumbBarUpdateButtons(n) ; Update
}
setButtonInteractive(n){
; Set button n to be interactive again.
static THBF_NONINTERACTIVE := 0x10
this.updateThumbButtonFlags(n,0,THBF_NONINTERACTIVE) ; Update flag, remove THBF_NONINTERACTIVE:=0x10
return this.ThumbBarUpdateButtons(n) ; Update
}
setButtonCallback(onButtonClickFunction:=""){
; For changing or specifying the onButtonClick callback function.
if onButtonClickFunction {
this.callback:= new threadFunc(onButtonClickFunction,,,,this.mute) ; Pass a func / bound func object or function name.
} else {
this.callback:=""
return this.stopThisButtonMonitor()
}
if !this.THUMBBUTTON
this.createButtons() ; Create the buttons for this interface.
taskbarInterface.turnOnButtonMessages() ; If monitoring is off, turn on.
taskbarInterface.startTaskbarMsgMonitor()
this.isDisabled:=false ; By default, the interface is not disabled, us stopThisButtonMonitor() to disable.
return
}
;
; End Button methods
;
; Misc interface methods:
setTaskbarIcon(smallIconHandle,bigIconHandle:=""){
; Url:
; - https://msdn.microsoft.com/en-us/library/windows/desktop/ms632643(v=vs.85).aspx (WM_SETICON message)
; Associates a new large or small icon with a window. The system displays the large icon in the ALT+TAB dialog box, and the small icon in the window caption.
static:=WM_SETICON:=0x80,ICON_SMALL:=0,ICON_BIG:=1
if !bigIconHandle
bigIconHandle:=smallIconHandle
this.smallIconHandle:=smallIconHandle
this.bigIconHandle:=bigIconHandle
this.PostMessage(this.hWnd,WM_SETICON,ICON_SMALL,smallIconHandle)
this.PostMessage(this.hWnd,WM_SETICON,ICON_BIG,bigIconHandle)
return
}
; setProgress - The underlying function is called SetProgressValue, but
; I think the word Type is more descriptive of its function.
; Displays or updates a progress bar hosted in a taskbar button to show the
; specific percentage completed of the full operation.
; Url:
; - https://msdn.microsoft.com/en-us/library/windows/desktop/dd391698(v=vs.85).aspx (ITaskbarList3::SetProgressValue method)
setProgress(value:=0){
; value in range (0,100)
this.progressValue:=value
if !this.flashTimer
this.preFlashSettings[1]:=value
return this.SetProgressValue(value)
}
; SetProgressType(type) - The underlying function is called SetProgressState, but
; I think the word Type is more descriptive of its function.
;
; Sets the type and state of the progress indicator displayed on a taskbar button.
; Url:
; - https://msdn.microsoft.com/en-us/library/windows/desktop/dd391697(v=vs.85).aspx (ITaskbarList3::SetProgressState)
; HWND hwnd,
; TBPFLAG tbpFlags
; Flags that control the current state of the progress button. Specify only one
; of the following flags; all states are mutually exclusive of all others.
;
; TBPF_NOPROGRESS (0x00000000)
; Stops displaying progress and returns the button to its normal state. Call this
; method with this flag to dismiss the progress bar when the operation is
; complete or canceled.
; TBPF_INDETERMINATE (0x00000001)
; The progress indicator does not grow in size, but cycles repeatedly along the
; length of the taskbar button. This indicates activity without specifying what
; proportion of the progress is complete. Progress is taking place, but there is
; no prediction as to how long the operation will take.
; TBPF_NORMAL (0x00000002)
; The progress indicator grows in size from left to right in proportion to the
; estimated amount of the operation completed. This is a determinate progress
; indicator; a prediction is being made as to the duration of the operation.
; TBPF_ERROR (0x00000004)
; The progress indicator turns red to show that an error has occurred in one of
; the windows that is broadcasting progress. This is a determinate state. If the
; progress indicator is in the indeterminate state, it switches to a red
; determinate display of a generic percentage not indicative of actual progress.
; TBPF_PAUSED (0x00000008)
; The progress indicator turns yellow to show that progress is currently stopped
; in one of the windows but can be resumed by the user. No error condition
; exists and nothing is preventing the progress from continuing. This is a
; determinate state. If the progress indicator is in the indeterminate state, it
; switches to a yellow determinate display of a generic percentage not
; indicative of actual progress.
SetProgressType(type:="Normal"){
static dictionary:={Off:0,INDETERMINATE:1,Normal:2, Green:2, Error:4, Red:4,Paused:8,Pause:8,Yellow:8}
local p
this.progressType:= (p:=dictionary[type]) ? p : 0
if !this.flashTimer
this.preFlashSettings[2]:=type
return this.setProgressState()
}
preFlashSettings:=[] ; For restoring taskbar progress / color after flash
flashTaskbarIcon(color:="off", nFlashes:=5, flashTime:=250, offTime:=250){
; Flash the background of the taskbar icon by setting it to progress 100 for flashTime ms every
; offTime ms, nFlashes times. Valid colors are green,red,yellow. (translates to
; normal, error, paused progresstype)
; Uses a timer to let script run "in parallel"
this.stopTimer() ; Stop any currently running timer.
this.flashParams:=[color, nFlashes, flashTime, offTime]
if (color="Off" || color="")
return
this.flashesRemaining:=nFlashes
this.flashOn(color,flashTime,offTime)
return
}
setTaskbarIconColor(color:="off"){
; Set the background color of the taskbar icon (sets progress to 100 with appropriate progressState)
; Color, "green", "yellow" or "red"
this.SetProgressType(color)
if (color!="off" || color="")
this.setProgress(100)
return
}
; setThumbnailToolTip(text)
; Url:
; - https://msdn.microsoft.com/en-us/library/windows/desktop/dd391702(v=vs.85).aspx (ITaskbarList3::SetThumbnailTooltip method)
; 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.
; Input:
; Text, string specifying the new text to show as tooltip when
; mouse cursor hovers the thumbnail preview in the taskbar
; Specify an empty strin, text:="" to remove the tooltip.
setThumbnailToolTip(text:=""){
this.tooltipText:=text
return this._setThumbnailToolTip()
}
; Url:
; - https://msdn.microsoft.com/en-us/library/windows/desktop/dd391696(v=vs.85).aspx (ITaskbarList3::SetOverlayIcon method)
; HWND hwnd,
; HICON hIcon, (opt)
; LPCWSTR pszDescription (opt)
; Notes:
; - To display an overlay icon, the taskbar must be in the default large
; icon mode. If the taskbar is configured through Taskbar and Start Menu
; Properties to show small icons, overlays cannot be applied and calls to
; this method are ignored.
; - The handle of an icon to use as the overlay. This should be a small icon,
; measuring 16x16 pixels at 96 dpi. If an overlay icon is already applied to
; the taskbar button, that existing overlay is replaced.
;
; Omit the handle paramter to remove the icon.
;
; To use a bitmap as the overlay icon, you can use LoadPictureType to load a bitmap as an icon, see https://github.com/HelgeffegleH/LoadPictureType
setOverlayIcon(hIcon:=0,text:=""){
this.overlayIconHandle:=hIcon, this.overlayIconDescription:=text
return this._SetOverlayIcon()
}
; setThumbnailClip()
; Selects a portion of a window's client area to display as that window's thumbnail in the taskbar
; Url:
; - https://msdn.microsoft.com/en-us/library/windows/desktop/dd391701(v=vs.85).aspx (ITaskbarList3::SetThumbnailClip method)
; rect:
; The RECT structure defines the coordinates of the upper-left and lower-right corners of a rectangle
; Url:
; - https://msdn.microsoft.com/en-us/library/windows/desktop/dd162897(v=vs.85).aspx (RECT structure)
; LONG left;
; LONG top;
; LONG right;
; LONG bottom;
; Input
; left (x1)
; - The x-coordinate of the upper-left corner of the rectangle.
; top (y1)
; - The y-coordinate of the upper-left corner of the rectangle.
; right (x2)
; - The x-coordinate of the lower-right corner of the rectangle.
; bottom (y2)
; - The y-coordinate of the lower-right corner of the rectangle.
; Call without any parameters to reset to default
setThumbnailClip(left:="",top:="",right:="",bottom:=""){
local rect
if (left="" || top="" || right="" || bottom=""){
this.thumbnailClipRect:=""
return this._setThumbnailClip(0)
}
this.thumbnailClipRect:=[left,top,right,bottom] ; For restoring
VarSetCapacity(rect,16,0)
Numput(left,rect,0,"Int") , Numput(top,rect,4,"Int")
Numput(right,rect,8,"Int"), Numput(bottom,rect,12,"Int")
return this._setThumbnailClip(&rect)
}
static nCustomPreviews:=0 ; Number of custom thumbnail previews enabled. Used for tracking when to turn on / off message handling.
static nCustomPeekPreviews:=0 ; Number of custom peek previews enabled. Used for tracking when to turn on / off message handling.
enableCustomThumbnailPreview(bitmapOrBitmapFunc,rate:=0, autoDeleteBitmap:=true, addBorder:=false){
; bitmapOrBitmapFunc, a bitmap handle or func object that takes three parameters, max width and max height of the bitmap and a reference to the interface.
; the bitmapFunc should return a bitmap handle to used as thumbnail preview for the interface's window. If passing a bitmap, rate must be 0.
; rate, the rate in ms at which the bitmap will be updated, bitmapFunc will be called every rate ms. Set rate 0 if passing a bitmap as bitmapOrBitmapFunc.
; autoDeleteBitmap, set to true to let the interface dispose of the bitmap when it is finished with it.
; addBorder, set to true to draw a border around the bitmap.
; Note: if not providing a custom peek preview, it is recommended that you call the (instance) method disallowPeek().
static WM_DWMSENDICONICTHUMBNAIL:=0x323 ; Note: 0x323 > 0x312 => msg is buffered.
local bitmapFunc
if this.CustomThumbnailPreviewEnabled ; If already enabled, do nothing
return
if !taskbarInterface.nCustomPreviews { ; Turn on message handler when calling this method the first time.
taskbarInterface.WM_DWMSENDICONICTHUMBNAILfn:=ObjBindMethod(taskbarInterface,"WM_DWMSENDICONICTHUMBNAIL")
OnMessage(WM_DWMSENDICONICTHUMBNAIL,taskbarInterface.WM_DWMSENDICONICTHUMBNAILfn)
}
taskbarInterface.nCustomPreviews++ ; Increment counter, to track when to turn on / off message handler
rate := (IsObject(bitmapOrBitmapFunc) && rate=0) ? 1 : rate ; If user doesn't follow instructions, try to save the day.
bitmapFunc:= IsObject(bitmapOrBitmapFunc) || rate=0 ? bitmapOrBitmapFunc : IsFunc(bitmapOrBitmapFunc) ? func(bitmapOrBitmapFunc) : 0 ; Store the bitmap provider function.
this.bitmapFunc:= new threadFunc(bitmapFunc,,,,this.mute)
if !this.bitmapFunc { ; If invalid bitmapFunc, return/throw exception
this.lastError:=Exception("The provided bitmap (function) is not a valid.", -1)
if this.mute
return this.lastError
else
throw this.lastError
}
this.thumbrate:=rate
this.saveThumbBitmap:= rate=0 ? true : false
if !rate
this.thumbHbm:=bitmapOrBitmapFunc
this.deleteBMPThumbnailPreview:=autoDeleteBitmap
this.dwSITFlagsThumbnailPreview:=addBorder
this.Dwm_SetWindowAttributeHasIconicBitmap(this.hwnd,1) ; See dwm lib for details.
this.Dwm_SetWindowAttributeForceIconicRepresentaion(this.hwnd,1)
this.Dwm_InvalidateIconicBitmaps(this.hwnd)
return this.CustomThumbnailPreviewEnabled:=true
}
disableCustomThumbnailPreview(){
static WM_DWMSENDICONICTHUMBNAIL:=0x323
local tf
if (!this.CustomThumbnailPreviewEnabled || !taskbarInterface.nCustomPreviews)
return
if (tf:=this.invalidateThumbTimerFn){
SetTimer, % tf, Delete
this.invalidateThumbTimerFn:=""
}
taskbarInterface.nCustomPreviews--
if !taskbarInterface.nCustomPreviews ; Turn off message handler when the last custom preview has been disabled
OnMessage(WM_DWMSENDICONICTHUMBNAIL,taskbarInterface.WM_DWMSENDICONICTHUMBNAILfn,0), taskbarInterface.WM_DWMSENDICONICTHUMBNAILfn:=""
this.CustomThumbnailPreviewEnabled:=0
this.bitmapFunc:=""
if !this.CustomPeekPreviewEnabled {
this.Dwm_SetWindowAttributeHasIconicBitmap(this.hwnd,0) ; Restores the default preview, provided by the OS.
this.Dwm_SetWindowAttributeForceIconicRepresentaion(this.hwnd,0)
}
this.freeThumbnailPreviewBMP() ; Conditionally
return
}
enableCustomPeekPreview(bitmapOrBitmapFunc,rate:=0,x:="",y:="",autoDeleteBitmap:=true, addBorder:=false){
; bitmapOrBitmapFunc, a bitmap handle or func object that takes three parameters, max width and max height of the bitmap and a reference to the interface.
; the bitmapFunc should return a bitmap handle to used as thumbnail preview for the interface's window. If passing a bitmap, rate must be 0.
; rate, the rate in ms at which the bitmap will be updated, bitmapFunc will be called every rate ms. Set rate 0 if passing a bitmap as bitmapOrBitmapFunc.
; x,y, offset for the bitmap.
; autoDeleteBitmap, set to true to let the interface dispose of the bitmap when it is finished with it.
; addBorder, set to true to draw a border around the bitmap.
; If you have previously called disallowPeek(), call allowPeek()
static WM_DWMSENDICONICLIVEPREVIEWBITMAP:=0x326 ; Note: 0x323 > 0x312 => msg is buffered.
local peekbitmapFunc
if this.CustomPeekPreviewEnabled ; If already enabled, do nothing
return
if !taskbarInterface.nCustomPeekPreviews { ; Turn on message handler when calling this method the first time.
taskbarInterface.WM_DWMSENDICONICLIVEPREVIEWBITMAPfn:=ObjBindMethod(taskbarInterface,"WM_DWMSENDICONICLIVEPREVIEWBITMAP")
OnMessage(WM_DWMSENDICONICLIVEPREVIEWBITMAP,taskbarInterface.WM_DWMSENDICONICLIVEPREVIEWBITMAPfn)
}
taskbarInterface.nCustomPeekPreviews++ ; Increment counter, to track when to turn on / off message handler
rate := (IsObject(bitmapOrBitmapFunc) && rate=0) ? 1 : rate ; If user doesn't follow instructions, try to save the day.
peekbitmapFunc:= IsObject(bitmapOrBitmapFunc) || rate=0 ? bitmapOrBitmapFunc : IsFunc(bitmapOrBitmapFunc) ? func(bitmapOrBitmapFunc) : 0 ; Store the bitmap provider function.
this.peekbitmapFunc:= new threadFunc(peekbitmapFunc,,,,this.mute)
if !this.peekbitmapFunc { ; If invalid bitmapOrBitmapFunc, return/throw exception
this.lastError:=Exception("The provided bitmap (function) is not a valid.", -1)
if this.mute
return this.lastError
else
throw this.lastError
}
this.peekrate:=rate
this.savePeekBitmap:= rate=0 ? true : false
if !rate
this.peekHbm:=bitmapOrBitmapFunc
this.peekX:=x
this.peeky:=y
this.deleteBMPPeekPreview:=autoDeleteBitmap
this.dwSITFlagsPeekPreview:=addBorder
this.Dwm_SetWindowAttributeHasIconicBitmap(this.hwnd,1) ; See dwm lib for details.
this.Dwm_SetWindowAttributeForceIconicRepresentaion(this.hwnd,1)
this.Dwm_InvalidateIconicBitmaps(this.hwnd)
return this.CustomPeekPreviewEnabled:=true
}
disableCustomPeekPreview(){
local tf
static WM_DWMSENDICONICLIVEPREVIEWBITMAP:=0x326
if (!this.CustomPeekPreviewEnabled || !taskbarInterface.nCustomPeekPreviews)
return
if (tf:=this.invalidatePeekTimerFn) {
SetTimer, % tf, Delete
this.invalidatePeekTimerFn:=""
}
taskbarInterface.nCustomPeekPreviews--
if !taskbarInterface.nCustomPeekPreviews ; Turn off message handler when the last custom preview has been disabled
OnMessage(WM_DWMSENDICONICLIVEPREVIEWBITMAP,taskbarInterface.WM_DWMSENDICONICLIVEPREVIEWBITMAPfn,0), taskbarInterface.WM_DWMSENDICONICLIVEPREVIEWBITMAPfn:=""
this.CustomPeekPreviewEnabled:=0
this.peekbitmapFunc:=""
if !this.CustomThumbnailPreviewEnabled {
this.Dwm_SetWindowAttributeHasIconicBitmap(this.hwnd,0) ; Restores the default preview, provided by the OS.
this.Dwm_SetWindowAttributeForceIconicRepresentaion(this.hwnd,0)
}
this.freePeekPreviewBMP() ; Conditionally
return
}
disallowPeek(){ ; See dwm lib for details (Dwm_SetWindowAttributeDisallowPeek)
return this.Dwm_SetWindowAttributeDisallowPeek(this.hwnd,true) ; Disallow peek if no custom peekpreview
}
allowPeek(){ ; See dwm lib for details (Dwm_SetWindowAttributeDisallowPeek)
return this.Dwm_SetWindowAttributeDisallowPeek(this.hwnd,false) ; Do not disallow peek.
}
excludeFromPeek(){ ; See dwm lib for details (Dwm_SetWindowAttributeExcludeFromPeek)
return this.Dwm_SetWindowAttributeExcludeFromPeek(this.hwnd,true)
}
unexcludeFromPeek(){ ; See dwm lib for details (Dwm_SetWindowAttributeExcludeFromPeek)
return this.Dwm_SetWindowAttributeExcludeFromPeek(this.hwnd,false)
}
; Misc
refreshButtons(){
;
; https://msdn.microsoft.com/en-us/library/windows/hardware/ff561808(v=vs.85).aspx
;
; Misnomer. refreshInterface might be more accurate. Leave for now...
if this.THUMBBUTTON {
if this.hImageList
this.ThumbBarSetImageList()
this.ThumbBarAddButtons()
this.ThumbBarUpdateButtons(1,7)
}
this._SetOverlayIcon()
if this.thumbnailClipRect
this.setThumbnailClip(this.thumbnailClipRect*)
if (this.tooltipText!="")
this._setThumbnailToolTip()
; The following handles flashTimers and progress
if (this.progressValue!="" && !this.flashTimer)
this.SetProgressValue()
if (this.progressType!="" && !this.flashTimer)
this.setProgressState()
if this.flashesRemaining && IsObject(this.flashParams) {
this.flashParams[2]:=this.flashesRemaining
this.flashtaskbaricon(this.flashParams*)
}
return
}
restoreTaskbar(){
; Restores the taskbar for the window.
this.deleteTab()
Sleep,50
this.addTab()
this.disableCustomPeekPreview()
this.disableCustomThumbnailPreview()
}
stopThisButtonMonitor(){
; This will dismiss the callback, the message monitor is still on. To turn off message monitor use stopAllButtonMonitor()
; Default is message monitoring on
return this.isDisabled:=true
}
restartThisButtonMonitor(){
; This will reenable the button click callbacks.
; If all message monitor is off, i.e., stopAllButtonMonitor() was called,
; restart by calling restartAllButtonMonitor()
; Default is message monitoring on
return this.isDisabled:=false
}
exemptFromHook(){
return this.allowHooking:=false
}
unexemptFromHook(){
return this.allowHooking:=true
}
getLastError(){
; Returns the last error object from exception(...)
return this.lastError
}
; Moved queryButtonIconSize to button method section, for convenience
; Class methods, affects all interfaces
refreshAllButtons(){
local k, interface
for k, interface in taskbarInterface.allInterfaces
interface.refreshButtons()
return
}
clearAll(exiting:=false){
local k, interface
if !IsObject(taskbarInterface.allInterfaces)
return
for k, interface in taskbarInterface.allInterfaces
interface.clear()
if exiting
taskbarInterface.clearInterface()
return
}
static allDisabled:=true ; All message monitor is disabled before any objects has been derived from this class.
stopAllButtonMonitor(){
; turns off button message monitor, default is on.
if taskbarInterface.allDisabled
return
return taskbarInterface.turnOffButtonMessages(), taskbarInterface.allDisabled:=true
}
restartAllButtonMonitor(){
; turns on button message monitor, deafult is on, hence no need to call if you didn't turn it off
if taskbarInterface.allDisabled
return taskbarInterface.turnOnButtonMessages(), taskbarInterface.startTaskbarMsgMonitor(), taskbarInterface.allDisabled:=false
}
static templates:=[] ; Holds all templates
static hasTemplates:=0
makeTemplate(templateFunction,WinTitle:="",excludeWinTitle:="") {
templateFunction := new threadFunc(templateFunction,,,,true)
if !templateFunction
return Exception("Template function invalid",-1)
++taskbarInterface.hasTemplates
if !taskbarInterface.init ; Initialise com and message monitor if needed
taskbarInterface.initInterface()
WinTitle := IsObject(WinTitle) ? WinTitle : (WinTitle!="" ? StrSplit(WinTitle,",") : "")
excludeWinTitle := IsObject(excludeWinTitle) ? excludeWinTitle : (excludeWinTitle!="" ? StrSplit(excludeWinTitle,",") : "")
return taskbarInterface.templates.Push({include:WinTitle,exclude:excludeWinTitle,templateFunction:templateFunction}) ; Returns the templates position in the template array, pass this number to removeTemplate to remove this template later
}
removeTemplate(n){
if !taskbarInterface.hasTemplates
return
if !(--taskbarInterface.hasTemplates){
taskbarInterface.UnhookWinEvent() ; Unhook EVENT_OBJECT_SHOW
if taskbarInterface.hookWindowClose
taskbarInterface.SetWinEventHook() ; Restart hook with narrower event range, EVENT_OBJECT_DESTROY -> EVENT_OBJECT_DESTROY
}
return taskbarInterface.templates.Delete(n)
}
;
; End user methods
;
;
; Internal methods
; Meta functions
;
__Call(fn,p*){
; For verifying correct input. maybe change this.
if InStr( ",showButton,hideButton,setButtonImage,setButtonIcon,enableButton,disableButton"
. ",setButtonToolTip,dismissPreviewOnButtonClick,removeButtonBackground"
. ",reAddButtonBackground,setButtonNonInteractive,setButtonInteractive,", "," . fn . ",") {
if this.isFreed {
this.lastError:=Exception("This interface has freed its memory, it cannot be used.",-1)
if this.mute
return this.lastError
else
throw this.lastError ; If the user tries to alter the apperance or function of the interface after memory was free, throw an exception.
} else if (!this.THUMBBUTTON && taskbarInterface.init) {
this.createButtons()
}
this.verifyId(p[1])
}
}
__Delete(){
local bool
if !IsObject(taskbarInterface) ; We are probably exiting the script.
return
if (bool:=(!taskbarInterface.manualClearInterface && taskbarInterface.arrayIsEmpty(taskbarInterface.allInterfaces))) && !taskbarInterface.hasTemplates ; If the last interface is released and no templates, release com.
taskbarInterface.clearInterface()
else if bool
taskbarInterface.turnOffButtonMessages(), taskbarInterface.stopTaskbarMsgMonitor()
return
}
arrayIsEmpty(arr){
return !arr._NewEnum().next()
}
; Internal methods for flashtaskbaricon():
; flashOn(), flashOff()
flashOn(type,flashTime,offTime){
local fn
this.SetProgressType(type) ; Set progresstype according to color choise
this.setProgress(100) ; Set 100 progress to fill taskbar icon with the color
fn:=ObjBindMethod(this,"flashOff",type,flashTime,offTime) ; Make a timer for turning off the color
this.flashTimer:=fn ;
SetTimer, % fn, % -flashTime ;
return
}
flashOff(type,flashTime,offTime){
local fn
this.SetProgressType("Off") ; Turn off the progress/color
if !(--this.flashesRemaining){ ; Decrement flash count, return if appropriate
this.setProgressType(this.preFlashSettings[2]) ; For reference: this.preFlashSettings:=[this.progressValue,this.unmappedProgressType]
this.setProgress(this.preFlashSettings[1])
this.preFlashSettings:=""
return this.flashTimer:=""
}
fn:=ObjBindMethod(this,"flashOn",type,flashTime,offTime) ; Make a timer for turning on the color
this.flashTimer:=fn ;
SetTimer, % fn, % -offTime ;
return
}
stopTimer(){
; Terminates the flashTimer when appropriate.
; Typically from refreshButtons() or clear()
local fn
if this.flashTimer {
fn:=this.flashTimer
SetTimer, % fn, Delete
this.flashTimer:=""
this.flashParams:=""
this.progressValue:=""
this.progessType:=""
}
return
}
; End internal methods for flashTaskbarIcon()
clear(){
; Edit: There is no need to manually call this. The taskbarInterface class will clear every thing for you.
; Hence, this is developer notes:
; Call this function before clearing your last reference to any object derived from this class.
; Turn off timer if on.
this.stopTimer()
; Disable (and free) custom preview bitmaps
this.disableCustomThumbnailPreview()
this.disableCustomPeekPreview()
this.destroyImageList()
; Free memory
this.freeMemory()
; Free thumbnail/peek preview bitmaps, if needed
this.freeThumbnailPreviewBMP()
this.freePeekPreviewBMP()
; Remove from allInterfaces array
taskbarInterface.allInterfaces.Delete(this.hwnd)
return
}
freeMemory(){
if this.THUMBBUTTON
this.GlobalFree(this.THUMBBUTTON)
this.isFreed:=true, this.THUMBBUTTON:=""
return
}
; Help functions for freeing preview bitmaps, called by clear and disable peek/thumb preview functions
freeThumbnailPreviewBMP(){
if (this.deleteBMPThumbnailPreview && this.thumbHbm)
this.freeBitmap(this.thumbHbm), this.thumbHbm:=""
return
}
freePeekPreviewBMP(){
if (this.deleteBMPPeekPreview && this.peekHbm)
this.freeBitmap(this.peekHbm), this.peekHbm:=""
return
}
PostMessage(hWnd,Msg,wParam,lParam){
; Url:
; - https://msdn.microsoft.com/en-us/library/windows/desktop/ms644944(v=vs.85).aspx
; Used by setTaskbarIcon()
return DllCall("User32.dll\PostMessage", "Ptr", hWnd, "Uint", Msg, "Uptr", wParam, "Ptr", lParam)
}
verifyId(iId){
; Ensures the button number iId, is in the correct range.
; Avoids unexpected behaviour by passing an address outside of allocated memory in this.THUMBBUTTON
; This is called when appropriate form __Call()
if (iId<1 || iId>7 || round(iId)!=iId) {
this.lastError:=Exception("Button number must be an integer in the in range 1 to 7 (inclusive)",-2)
if this.mute
Exit
else
throw this.lastError
}
return 1
}
createButtons(){
; Creates 7 buttons. All hidden. This is because ThumbBarAddButtons() can only be called once, it seems. This is for convenience.
; All buttons will have the THB_FLAGS mask.
static THB_FLAGS:=0x00000008
static THBF_HIDDEN:=0x8
local structOffset
if this.THUMBBUTTON {
this.lastError:=Exception("Buttons already created, clear this instance or make a refresh")
if this.mute
return this.lastError
else
throw this.lastError
}
this.THUMBBUTTON:=this.GlobalAlloc(this.thumbButtonSize*7)
loop, 7 {
structOffset:=this.thumbButtonSize*(A_Index-1)
NumPut(A_Index,this.THUMBBUTTON+structOffset, 4, "Uint") ; Specify the ids: 1,...,7
this.updateThumbButtonMask(A_Index,THB_FLAGS,0) ; update the mask: THB_FLAGS
this.updateThumbButtonFlags(A_Index,THBF_HIDDEN,0) ; Update flag: THBF_HIDDEN:=0x8
}
this.ThumbBarAddButtons()
return
}
; Update/get/set methods for the THUMBBUTTON struct array.
; The update functions call the get functions, modifies the values and then set.
; The caller of update() then calls ThumbBarUpdateButtons() when finished
; Update
/*
Masks:
THB_BITMAP = 0x00000001,
THB_ICON = 0x00000002,
THB_TOOLTIP = 0x00000004,
THB_FLAGS = 0x00000008
*/
updateThumbButtonMask(iId,add:=0,remove:=0){
local dwMask
dwMask:=this.getThumbButtonMask(iId)
dwMask&remove?dwMask-=remove:""
dwMask|=add
return this.setThumbButtonMask(iId,dwMask)
}
/*
Flags:
THBF_ENABLED = 0x00000000,
THBF_DISABLED = 0x00000001,
THBF_DISMISSONCLICK = 0x00000002,
THBF_NOBACKGROUND = 0x00000004,
THBF_HIDDEN = 0x00000008,
THBF_NONINTERACTIVE = 0x00000010
*/
updateThumbButtonFlags(iId,add:=0,remove:=0){
local dwFlags
dwFlags:=this.getThumbButtonFlags(iId)
dwFlags&remove?dwFlags-=remove:""
dwFlags|=add
return this.setThumbButtonFlags(iId,dwFlags)
}
; Item and struct offsets are specified for maintainabillity
; Write values to adress at this.THUMBBUTTON + structOffset + itemOffset
; Get
getThumbButtonMask(iId){
static itemOffset := 0 ; dwMask
local structOffset := this.thumbButtonSize*(iId-1)
return NumGet(this.THUMBBUTTON+itemOffset+structOffset, "Uint")
}
getThumbButtonFlags(iId){
static itemOffset := 8+2*A_PtrSize+260*2 ; dwFlags
local structOffset := this.thumbButtonSize*(iId-1)
return NumGet(this.THUMBBUTTON+itemOffset+structOffset,0,"Uint")
}
; Set
setThumbButtonMask(iId,dwMask){
static itemOffset := 0 ; dwMask
local structOffset := this.thumbButtonSize*(iId-1)
return NumPut(dwMask, this.THUMBBUTTON+itemOffset+structOffset, "Uint")
}
setThumbButtoniBitmap(iId,iBitmap){
; The imagelist index is zero base, hence iBitmap-1. User should supply 1-based index
static itemOffset := 8 ; iBitmap
local structOffset := this.thumbButtonSize*(iId-1)
return NumPut(iBitmap-1, this.THUMBBUTTON+itemOffset+structOffset, "Ptr")
}
setThumbButtonhIcon(iId,hIcon){
static itemOffset := 8+A_PtrSize ; hIcon
local structOffset := this.thumbButtonSize*(iId-1)
return NumPut(hIcon, this.THUMBBUTTON+itemOffset+structOffset, "Ptr")
}
setThumbButtonToolTipText(iId,text:=""){
static itemOffset := 8+2*A_PtrSize ; szTip
local structOffset := this.thumbButtonSize*(iId-1)
return StrPut(SubStr(text,1,259), this.THUMBBUTTON+structOffset+itemOffset, 260, "UTF-16") ; Make sure tooltip text isn't too long
}
setThumbButtonFlags(iId,dwFlags){
static itemOffset := 8+2*A_PtrSize+260*2 ; dwFlags
local structOffset := this.thumbButtonSize*(iId-1)
return NumPut(dwFlags, this.THUMBBUTTON+structOffset+itemOffset, "Uint")
}
;
; Com Interface wrapper functions
; The bound funcs are made in initInterface()
addTab(){
return taskbarInterface.vTable.addTabFn.Call("Ptr", this.hWnd) ; return 0 is ok!
}
deleteTab(){
return taskbarInterface.vTable.deleteTabFn.Call("Ptr", this.hWnd) ; return 0 is ok!
}
activateTab(){
return taskbarInterface.vTable.activateTabFn.Call("Ptr", this.hWnd) ; return 0 is ok!
}
setActiveAlt(){
return taskbarInterface.vTable.setActiveAltFn.Call("Ptr", this.hWnd) ; return 0 is ok!
}
clearActiveAlt(){
return taskbarInterface.vTable.setActiveAltFn.Call("Ptr", 0) ; return 0 is ok!
}
registerTab(){
return taskbarInterface.vTable.RegisterTabFn.Call("Ptr", this.hWnd, "Ptr", this.hWnd) ; return 0 is ok!
}
ThumbBarAddButtons(){
; This function can only be called once it seems. Make one call and add all buttons hidden. Then use ThumbBarUpdateButtons() to "add" and "remove" buttons via the THBF_HIDDEN flag
; Max buttons is 7
return taskbarInterface.vTable.ThumbBarAddButtonsFn.Call("Ptr", this.hWnd, "Uint", 7, "Ptr", this.THUMBBUTTON) ; return 0 is ok!
}
ThumbBarUpdateButtons(iId,n:=1){
return taskbarInterface.vTable.ThumbBarUpdateButtonsFn.Call("Ptr", this.hWnd, "Uint", 1*n, "Ptr", this.THUMBBUTTON+this.thumbButtonSize*(iId-1)) ; return 0 is ok!
}
ThumbBarSetImageList(){
return taskbarInterface.vTable.ThumbBarSetImageListFn.Call("Ptr", this.hWnd, "Ptr", this.hImageList)
}
_setThumbnailToolTip(){
return taskbarInterface.vTable.ThumbnailToolTipFn.Call("Ptr", this.hWnd, "Str", this.tooltipText)
}
setProgressState(){
return taskbarInterface.vTable.SetProgressStateFn.Call("Ptr", this.hWnd, "Uint", this.progressType)
}
setProgressValue(){
return taskbarInterface.vTable.SetProgressValueFn.Call("Ptr", this.hWnd, "Int64", this.progressValue, "Int64", 100) ; 100 is max progress (done)
}
_setOverlayIcon(){
return taskbarInterface.vTable.setOverlayIconFn.Call("Ptr", this.hWnd, "Ptr", this.overlayIconHandle, "Str", this.overlayIconDescription)
}
_setThumbnailClip(rect){
return taskbarInterface.vTable.ThumbnailClipFn.Call("Ptr", this.hWnd, "Ptr", rect)
}
;
; Static variables
;
static allInterfaces:=[] ; Tracks all interfaces, for callbacks.
static init:=0 ; For first time use initialising of the com object.
; THUMBBUTTON struct:
static thumbButtonSize:=A_PtrSize=4?540:552 ; Size calculations according to:
/*
; URL:
; - https://msdn.microsoft.com/en-us/library/windows/desktop/dd391559(v=vs.85).aspx (THUMBBUTTON structure)
;
; offsets: Contribution to size (bytes):
THUMBBUTTONMASK dwMask 0 ... 4
UINT iId 4 ... 4
UINT iBitmap 8 ... 4
; ... 64-bit: add 4 bytes spacing, pointer address, adr, needs to be mod(adr,A_PtrSize)=0
HICON hIcon 8+A_PtrSize ... A_PtrSize
WCHAR szTip[260] 8+2*A_PtrSize ... 260*2
THUMBBUTTONFLAGS dwFlags 8+2*A_PtrSize+260*2 ... 4
; Sum: 32-bit: 4+4+4+0+A_PtrSize+260*2+4=540, 540/A_PtrSize=135, no spacing needed. EDIT: FIXED miscalculation thumbuttonSize = 540, not 544 ...
; Sum: 64-bit: 4+4+4+4+A_PtrSize+260*2+4=548, 548/A_PtrSize=68.5 -> add 4 bytes, 552/A_PtrSize=69 (mod(552,A_Ptrsize)=0).
; 64-bit: add 4 bytes spacing to next struct in array
; Summary: size:= A_PtrSize=4?544:552
*/
;
; NOTE:
;
; < > < > < > < > < > < > Context: < > < > < > < > < > < >
; < > < > < > < > < > < > this = taskbarInterface < > < > < > < > < > < >
; < > < > < > < > < > < > < > < > < > < > < > < >
;
;
initInterface(){
; Url:
; - https://msdn.microsoft.com/en-us/library/windows/desktop/bb774652(v=vs.85).aspx (ITaskbarList interface)
; Initilises the com object.
static CLSID_TaskbarList := "{56FDF344-FD6D-11d0-958A-006097C9A090}"
static IID_ITaskbarList3 := "{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}"
local hr
this.hComObj := ComObjCreate(CLSID_TaskbarList, IID_ITaskbarList3)
if !this.hComObj {
this.lastError:=Exception("ComObjCreate failed",-2)
if this.mute
return this.lastError
else
throw this.lastError
}
; Get the address to the vTable.
this.vTablePtr:=NumGet(this.hComObj+0,0,"Ptr")
; Create function objects for the interface, for convenience and clarity
; Name: Number:
; For convenience when freeing the interface, add all bound funcs to one array
;this.vTable:={}
this.vTable:=[]
this.vTable["HrInitFn"] := Func("DllCall").Bind(NumGet(this.vTablePtr+ 3*A_PtrSize,0,"Ptr"), "Ptr", this.hComObj) ; HrInit ( 3)
this.vTable["addTabFn"] := Func("DllCall").Bind(NumGet(this.vTablePtr+ 4*A_PtrSize,0,"Ptr"), "Ptr", this.hComObj) ; AddTab ( 4)
this.vTable["deleteTabFn"] := Func("DllCall").Bind(NumGet(this.vTablePtr+ 5*A_PtrSize,0,"Ptr"), "Ptr", this.hComObj) ; DeleteTab ( 5)
this.vTable["activateTabFn"] := Func("DllCall").Bind(NumGet(this.vTablePtr+ 6*A_PtrSize,0,"Ptr"), "Ptr", this.hComObj) ; ActivateTab ( 6)
this.vTable["setActiveAltFn"] := Func("DllCall").Bind(NumGet(this.vTablePtr+ 7*A_PtrSize,0,"Ptr"), "Ptr", this.hComObj) ; SetActiveAlt ( 7)
this.vTable["SetProgressValueFn"] := Func("DllCall").Bind(NumGet(this.vTablePtr+ 9*A_PtrSize,0,"Ptr"), "Ptr", this.hComObj) ; SetProgressValue ( 9)
this.vTable["SetProgressStateFn"] := Func("DllCall").Bind(NumGet(this.vTablePtr+10*A_PtrSize,0,"Ptr"), "Ptr", this.hComObj) ; SetProgressState (10)
this.vTable["RegisterTabFn"] := Func("DllCall").Bind(NumGet(this.vTablePtr+11*A_PtrSize,0,"Ptr"), "Ptr", this.hComObj) ; RegisterTab (11)
this.vTable["UnregisterTabFn"] := Func("DllCall").Bind(NumGet(this.vTablePtr+12*A_PtrSize,0,"Ptr"), "Ptr", this.hComObj) ; UnregisterTab (12)
this.vTable["SetTabOrderFn"] := Func("DllCall").Bind(NumGet(this.vTablePtr+13*A_PtrSize,0,"Ptr"), "Ptr", this.hComObj) ; SetTabOrder (13)
this.vTable["SetTabActiveFn"] := Func("DllCall").Bind(NumGet(this.vTablePtr+14*A_PtrSize,0,"Ptr"), "Ptr", this.hComObj) ; SetTabActive (14)
this.vTable["ThumbBarAddButtonsFn"] := Func("DllCall").Bind(NumGet(this.vTablePtr+15*A_PtrSize,0,"Ptr"), "Ptr", this.hComObj) ; ThumbBarAddButtons (15)
this.vTable["ThumbBarUpdateButtonsFn"] := Func("DllCall").Bind(NumGet(this.vTablePtr+16*A_PtrSize,0,"Ptr"), "Ptr", this.hComObj) ; ThumbBarUpdateButtons (16)
this.vTable["ThumbBarSetImageListFn"] := Func("DllCall").Bind(NumGet(this.vTablePtr+17*A_PtrSize,0,"Ptr"), "Ptr", this.hComObj) ; ThumbBarSetImageList (17)
this.vTable["SetOverlayIconFn"] := Func("DllCall").Bind(NumGet(this.vTablePtr+18*A_PtrSize,0,"Ptr"), "Ptr", this.hComObj) ; SetOverlayIcon (18)
this.vTable["ThumbnailToolTipFn"] := Func("DllCall").Bind(NumGet(this.vTablePtr+19*A_PtrSize,0,"Ptr"), "Ptr", this.hComObj) ; SetThumbnailTooltip (19)
this.vTable["ThumbnailClipFn"] := Func("DllCall").Bind(NumGet(this.vTablePtr+20*A_PtrSize,0,"Ptr"), "Ptr", this.hComObj) ; SetThumbnailClip (20)
hr:=this.vTable.HrInitFn.Call() ; Init the interface.
if hr {
this.lastError:=Exception("Com failed to initialise.",-2)
if this.mute
return this.lastError
else
throw this.lastError
}
this.CoInitialize() ; This might not be needed, it calls CoUnInitialize if needed.
this.startTaskbarMsgMonitor()
; Hook
this.SetWinEventHook()
this.init:=1 ; Success!
return
}
clearInterface(){
local hr
this.turnOffButtonMessages()
hr := ObjRelease(this.hComObj)
if hr {
this.lastError:=Exception("Com realease failed",-2)
if this.mute
return this.lastError
else
throw this.lastError
}
; Remove message handling