-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
taskbar.pas
1034 lines (917 loc) · 34 KB
/
taskbar.pas
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
{
Taskbar unit
Description:
This unit gets info from windows taskbar, position, icons
}
unit taskbar;
interface
uses classes, windows, graphics, registry, dwmapi, oleacc, variants, forms, sysutils, shellapi, messages;
const
WCA_ACCENT_POLICY = 19;
ACCENT_DISABLED = 0;
ACCENT_ENABLE_GRADIENT = 1;
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2;
ACCENT_ENABLE_BLURBEHIND = 3;
ACCENT_ENABLE_ACRYLICBLURBEHIND = 4;
//https://stackoverflow.com/a/22105803/537347 Windows 8 or newer only
IID_AppVisibility: TGUID = '{2246EA2D-CAEA-4444-A3C4-6DE827E44313}';
CLSID_AppVisibility: TGUID = '{7E5FE3D9-985F-4908-91F9-EE19F9FD1514}';
//IID_IAppVisibilityEvents: TGUID = '{6584CE6B-7D82-49C2-89C9-C6BC02BA8C38}';
CLSID_IVirtualDesktopManager: TGUID = '{AA509086-5CA9-4C25-8f95-589d3c07b48a}';
CLSID_VirtualDesktopPinnedApps: TGUID = '{b5a399e7-1c87-46b8-88e9-fc5747b171bd}';
CLSID_ImmersiveShell: TGUID = '{C2F03A33-21F5-47FA-B4BB-156362A2F239}';
type
MONITOR_APP_VISIBILITY = (
MAV_UNKNOWN = 0,
MAV_NO_APP_VISIBLE = 1,
MAV_APP_VISIBLE = 2
);
// *********************************************************************//
// Interface: IAppVisibilityEvents
// Flags: (0)
// GUID: {6584CE6B-7D82-49C2-89C9-C6BC02BA8C38}
// *********************************************************************//
IAppVisibilityEvents = interface(IUnknown)
['{6584CE6B-7D82-49C2-89C9-C6BC02BA8C38}']
function AppVisibilityOnMonitorChanged(hMonitor: HMONITOR;
previousMode: MONITOR_APP_VISIBILITY;
currentMode: MONITOR_APP_VISIBILITY):HRESULT; stdcall;
function LauncherVisibilityChange(currentVisibleState: BOOL): HRESULT; stdcall;
end;
// *********************************************************************//
// Interface: IAppVisibility
// Flags: (0)
// GUID: {2246EA2D-CAEA-4444-A3C4-6DE827E44313}
// *********************************************************************//
IAppVisibility = interface(IUnknown)
['{2246EA2D-CAEA-4444-A3C4-6DE827E44313}']
function GetAppVisibilityOnMonitor(monitor: HMONITOR; out pMode: MONITOR_APP_VISIBILITY): HRESULT; stdcall;
function IsLauncherVisible(out pfVisible: BOOL): HRESULT; stdcall;
function Advise(pCallBack: IAppVisibilityEvents; out pdwCookie: DWORD): HRESULT; stdcall;
function Unadvise(dwCookie: DWORD): HRESULT; stdcall;
end;
// *********************************************************************//
// Interface: IVirtualDesktopManager
// Flags: (0)
// GUID: {a5cd92ff-29be-454c-8d04-d82879fb3f1b}
// *********************************************************************//
IVirtualDesktopManager = interface(IUnknown)
['{a5cd92ff-29be-454c-8d04-d82879fb3f1b}']
function IsWindowOnCurrentVirtualDesktop(topLevelWindow: HWND; out onCurrentDesktop: BOOL): HRESULT; stdcall;
function GetWindowDesktopId(topLevelWindow: HWND; out desktopId: TGUID): HRESULT; stdcall;
function MoveWindowToDesktop(topLevelWindow: HWND; var desktopId: TGUID): HRESULT; stdcall;
end;
AccentPolicy = packed record
AccentState: Integer;
AccentFlags: Integer;
GradientColor: Integer;
AnimationId: Integer;
end;
WindowCompositionAttributeData = packed record
Attribute: Cardinal;
Data: Pointer;
SizeOfData: Integer;
end;
TTaskPos = record
public const
Left = string('left');
Top = string('top');
Right = string('right');
Bottom = string('bottom');
end;
//TTaskPosition = string;
TTaskComponent = record
Handle: THandle;
Rect: TRect;
end;
PTaskbar = ^TTaskbar;
TTaskbar = record
private
// _reg: TRegistry;
_position: UINT; // Position on the screen
_rect: TRect; // Shell_TrayWnd
_translucent: Boolean;
_handle: THandle;
_notaskbar: Boolean;
_transstyle: Integer;
//_monitor: Integer;
_monitorRect: TRect;
_monitorId: Integer;
_mainTaskbar: Boolean;
_start: TTaskComponent;
_trayButton1: TTaskComponent;
_trayButton2: TTaskComponent;
_trayDummySearchControl: TTaskComponent;
_reBarWindow32: TTaskComponent;
_WorkerW: TTaskComponent;
_MSTaskSwWClass: TTaskComponent;
_MSTaskListWClass: TTaskComponent;
_trayNotifyWnd: TTaskComponent;
_clientRect: TRect;
_appsBtnLeft, _appsBtnRight: Integer;
_appsBtnTop, _appsBtnBottom: Integer;
_timestamp: LongInt;
// function _IsTransparent: Boolean;
// procedure HideStartBtn;
// procedure ShowStartBtn;
// function _getIconsRect: TRect;
public
property StartButton: TTaskComponent read _start;
property TrayWnd: TTaskComponent read _trayNotifyWnd;
property MSTaskListWClass: TTaskComponent read _MSTaskListWClass;
property Handle: THandle read _handle;
property Position: UINT read _position write _position;
property MonitoID: Integer read _monitorId;
property MonitorRect: TRect read _monitorRect;
property Rect: TRect read _rect;
// property IsTransparent: Boolean read _IsTransparent;
property TransStyle: Integer read _transstyle write _transstyle;
property MainTaskbar: Boolean read _mainTaskbar;
//property AppsLeft: Integer read _appsBtnLeft;
//property AppsRight: Integer read _appsBtnRight;
// property MSTaskListRect: TRect read _getIconsRect;
property MSTaskRect: TRect read _MSTaskSwWClass.Rect;
property TrayRect: TRect read _trayNotifyWnd.Rect;
property StartRect: TRect read _start.Rect;
end;
{ constructor Create(hWnd: THandle);
procedure Transparent;
procedure UpdateTaskbarInfo;
procedure CenterAppsButtons(center: Boolean = True; relative: Boolean = False);
procedure Hide(handle: THandle);
procedure Show(handle: THandle);
procedure StartBtnVisible(visible: Boolean = True);
procedure NotifyAreaVisible(visible: Boolean = True);
procedure FullTaskBar;
function GetMonitor: TMonitor;
function IsStartMenuVisible: Boolean;
function ListMainTaskbarElements:TStringList;
end;}
TTaskbars = class(TList)
private
FCount: Integer;
FUpdating: Boolean;
function Get(Index: Integer): PTaskbar;
function GetMainTaskbar: PTaskbar;
function GetAutoHideInfo: Boolean;
procedure SetAutoHide(state: Boolean);
function GetSmallIcons: Boolean;
function GetAnimationState: Boolean;
procedure SetSmallIcons(Value: Boolean);
procedure SetAnimationState(Value: Boolean);
public
function Add(Value: PTaskbar): Integer;
procedure Refresh;
procedure CenterAppsButtons(center: Boolean = True; relative: Boolean = False);
procedure StartBtnVisible(Index: Integer;visible: Boolean = True);
procedure NotifyAreaVisible(visible: Boolean = True);
procedure Notify(Ptr: Pointer; Action: TListNotification); override;
property Items[Index: Integer]: PTaskbar read Get; default;
property MainTaskbar: PTaskbar read GetMainTaskbar;
property Autohide: Boolean read GetAutoHideInfo write SetAutoHide;
property SmallIcons: Boolean read GetSmallIcons write SetSmallIcons;
property TaskbarAnimation: Boolean read GetAnimationState write SetAnimationState;
procedure UpdateTaskbarInfo;
procedure Transparent(Value: Boolean = True);
procedure BeginUpdate;
procedure EndUpdate;
function IsStartMenuVisible: Boolean;
procedure PinTaskbar(lnkFile: PChar; pin: Boolean = True; defaultSize: DWORD = 0);
procedure RestoreAllStarts;
procedure RestoreOpacity(Handle: THandle);
destructor Destroy; override;
end;
function SetWindowCompositionAttribute(hWnd: HWND; var data: WindowCompositionAttributeData): Integer; stdcall;
external User32 name 'SetWindowCompositionAttribute';
function AccessibleChildren(paccContainer: Pointer; iChildStart: LONGINT;
cChildren: LONGINT; out rgvarChildren: OleVariant;
out pcObtained: LONGINT): HRESULT; stdcall;
external 'OLEACC.DLL' name 'AccessibleChildren';
implementation
{ TTaskbar }
uses ActiveX, Shlobj, ComObj;
(*procedure TTaskbar.FullTaskBar;
begin
if _start.Handle = 0 then Exit;
if _appsBtnLeft = 0 then Exit;
SetWindowPos(_MSTaskSwWClass.Handle, 0, 0, 0, _rect.Width, _MSTaskSwWClass.Rect.Height, SWP_NOSENDCHANGING);
end;
function TTaskbar.GetMonitor: TMonitor;
var
I: Integer;
begin
if _notaskbar then Exit;
Result := Screen.MonitorFromRect(_rect);
// if _maonitor = Result.MonitorNum + 1 then
begin
_monitorrect := Result.BoundsRect;
_monitorId := Result.MonitorNum + 1;
end;
end;
function EnumChildWindowsProc(Wnd: HWND; lst: TStringList): Bool; export; stdcall;
var
ClsName: array[0..255] of char;
stl: DWORD;
titlelen: Integer;
title: String;
begin
GetClassName(Wnd,ClsName, 255);
stl := GetWindowLong(Wnd, GWL_STYLE);
if {(stl and WS_VISIBLE = WS_VISIBLE)
and} (GetParent(Wnd) = StrToInt(lst[0]))
then
begin
titlelen := GetWindowTextLength(Wnd);
SetLength(title, titlelen);
GetWindowText(Wnd, PChar(title), titlelen + 1);
lst.Add(String(ClsName) + ' ' + ' ' + title + ' '+inttostr(wnd));
end;
Result := True;
end;
function TTaskbar.ListMainTaskbarElements:TStringList;
var
list: TStringList;
begin
list := TStringList.Create;
// list.Add(IntToStr(FindWindowEx(Self.Handle,0, 'ReBarWindow32', nil)));
// EnumChildWindows(FindWindowEx(Self.Handle,0, 'ReBarWindow32', nil), @EnumChildWindowsProc, LParam(list));
list.Add(IntToStr(Self.Handle));
EnumChildWindows(Self.Handle, @EnumChildWindowsProc, LParam(list));
Result := list;
end;
function TTaskbar._IsTransparent: Boolean;
begin
_translucent := False;
_reg := TRegistry.Create;
try
_reg.RootKey := HKEY_CURRENT_USER;
if _reg.OpenKeyReadOnly('Software\Microsoft\Windows\CurrentVersion\Themes\Personalize') then
begin
if _reg.ReadInteger('EnableTransparency') = 1 then
_translucent := True;
_reg.CloseKey;
end;
finally
_reg.Free;
end;
Result := _translucent;
end;*)
{ TTaskbars }
function TTaskbars.Add(Value: PTaskbar): Integer;
begin
Result := inherited Add(Value);
end;
procedure TTaskbars.BeginUpdate;
begin
FUpdating := True;
end;
procedure TTaskbars.CenterAppsButtons(center, relative: Boolean);
var
I: Integer;
aLeft, aTop: Integer;
begin
if FUpdating then Exit;
for I := 0 to Count - 1 do
begin
if Items[I]._start.Handle = 0 then Exit; // make sure taskbar exists
// restore size if not centering
if not center then
begin
if Items[I].MainTaskbar then
SetWindowPos( Items[I]._MSTaskListWClass.Handle, 0, 0, 0,
Items[I]._MSTaskSwWClass.Rect.Width,
Items[I]._MSTaskSwWClass.Rect.Height, SWP_NOACTIVATE)
else
SetWindowPos( Items[I]._MSTaskListWClass.Handle, 0, 0, 0,
Items[I]._WorkerW.Rect.Width,
Items[I]._WorkerW.Rect.Height, SWP_NOACTIVATE)
end
//center buttons
else
begin
// vertical centering
if (Items[I].Position = ABE_LEFT) or (Items[I].Position = ABE_RIGHT) then
begin
if Items[I].MainTaskbar then
begin
if (Items[I]._appsBtnBottom - Items[I]._appsBtnTop + 6) > Items[I]._MSTaskSwWClass.Rect.Height then Exit;
if relative then
aTop := (Items[I]._MSTaskSwWClass.Rect.Height div 2) - ((Items[I]._appsBtnBottom - Items[I]._appsBtnTop) div 2)
else
aTop := (Items[I]._rect.Height div 2) - Items[I]._MSTaskSwWClass.Rect.Top - ((Items[I]._appsBtnBottom - Items[I]._appsBtnTop) div 2);
SetWindowPos( Items[I]._MSTaskListWClass.Handle, 0, 0, aTop,
Items[I]._MSTaskListWClass.Rect.Width,
(Items[I]._appsBtnBottom - Items[I]._appsBtnTop + 6), SWP_NOACTIVATE );
end
else
begin
if (abs(Items[I]._appsBtnBottom - Items[I]._appsBtnTop) + 6) > abs(Items[I]._WorkerW.Rect.Bottom - Items[I]._WorkerW.Rect.Top) then Exit;
if relative then
aTop := (Items[I]._WorkerW.Rect.Height div 2) - ((Items[I]._appsBtnBottom - Items[I]._appsBtnTop) div 2)
else
aTop := (Items[I]._rect.Height div 2) - abs(Items[I]._WorkerW.Rect.Top-Items[I]._rect.Top) - ((Items[I]._appsBtnBottom - Items[I]._appsBtnTop) div 2);
SetWindowPos( Items[I]._MSTaskListWClass.Handle, 0, 0, aTop,
Items[I]._MSTaskListWClass.Rect.Width,
(Items[I]._appsBtnBottom - Items[I]._appsBtnTop + 6), SWP_NOACTIVATE);
end;
end
// horizontal centering
else
begin
// if taskbar buttons width is full, there is no need to adjust, 6 is a margin constant
if Items[I].MainTaskbar then
begin
if (Items[I]._appsBtnRight - Items[I]._appsBtnLeft + 6) > Items[I]._MSTaskSwWClass.Rect.Width then Exit;
if relative then
aLeft := (Items[I]._MSTaskSwWClass.Rect.Width div 2) - ((Items[I]._appsBtnRight - Items[I]._appsBtnLeft) div 2)
else
aLeft := (Items[I]._rect.Width div 2) - Items[I]._MSTaskSwWClass.Rect.Left - ((Items[I]._appsBtnRight - Items[I]._appsBtnLeft) div 2);
SetWindowPos( Items[I]._MSTaskListWClass.Handle, 0, aLeft, 0,
(Items[I]._appsBtnRight - Items[I]._appsBtnLeft + 6),
Items[I]._MSTaskListWClass.Rect.Height, SWP_NOACTIVATE);
end
else
begin
if (abs(Items[I]._appsBtnRight - Items[I]._appsBtnLeft) + 6) > abs(Items[I]._WorkerW.Rect.Right - Items[I]._WorkerW.Rect.Left) then Exit;
if relative then
aLeft := (Items[I]._WorkerW.Rect.Width div 2) - ((Items[I]._appsBtnRight - Items[I]._appsBtnLeft) div 2)
else
aLeft := (Items[I]._rect.Width div 2) - abs(Items[I]._WorkerW.Rect.Left-Items[I]._rect.Left) - ((Items[I]._appsBtnRight - Items[I]._appsBtnLeft) div 2);
SetWindowPos( Items[I]._MSTaskListWClass.Handle, 0, aLeft, 0,
(Items[I]._appsBtnRight - Items[I]._appsBtnLeft + 6),
Items[I]._MSTaskListWClass.Rect.Height, SWP_NOACTIVATE);
end;
end;
end;
end;
end;
destructor TTaskbars.Destroy;
var
I: Integer;
begin
// for I := 0 to Count - 1 do
// begin
// Items[I]._position := '';
// FreeMem(Items[I]); // notify handles it instead
// end;
inherited;
end;
procedure TTaskbars.EndUpdate;
begin
FUpdating := False;
end;
function TTaskbars.Get(Index: Integer): PTaskbar;
begin
Result := PTaskbar(inherited Get(Index));
end;
function TTaskbars.GetAnimationState: Boolean;
var
reg: TRegistry;
begin
reg := TRegistry.Create;
try
reg.RootKey := HKEY_CURRENT_USER;
reg.OpenKeyReadOnly('SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced');
if reg.ReadInteger('TaskbarAnimations') = 1 then Result := True
else
Result := False;
finally
reg.Free;
end;
end;
function TTaskbars.GetAutoHideInfo: Boolean;
var
ABData: TAppBarData;
begin
Result := False;
if (SHAppBarMessage(ABM_GETSTATE, ABData) and ABS_AUTOHIDE) = ABS_AUTOHIDE then
Result := True;
end;
function TTaskbars.GetMainTaskbar: PTaskbar;
var
I: Integer;
found: Boolean;
begin
Result := nil;
found := False;
if FUpdating then Exit;
I := 0;
if Count > 0 then
while (I < Count) or not found do
begin
if Items[I].MainTaskbar then
begin
Result := Items[I];
found := True;
end;
Inc(I);
end;
end;
function TTaskbars.GetSmallIcons: Boolean;
var
reg: TRegistry;
begin
reg := TRegistry.Create;
try
reg.RootKey := HKEY_CURRENT_USER;
reg.OpenKeyReadOnly('SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced');
if reg.ReadInteger('TaskbarSmallIcons') = 1 then Result := True
else
Result := False;
finally
reg.Free;
end;
end;
function TTaskbars.IsStartMenuVisible: Boolean;
var
acc: IAppVisibility;
res: HRESULT;
isLauncherVisible: BOOL;
begin
Result := False;
// Initialization of COM is required to use the AppVisibility (CLSID_AppVisibility) object
res := CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
if Succeeded(res) then
begin
// Create the App Visibility component
res := CoCreateInstance(CLSID_AppVisibility, nil, CLSCTX_ALL, IID_AppVisibility, acc);
if Succeeded(res) then
begin
res := acc.IsLauncherVisible(isLauncherVisible);
if Succeeded(res) then
Result := Boolean(isLauncherVisible);
end;
end;
CoUninitialize;
end;
procedure TTaskbars.Notify(Ptr: Pointer; Action: TListNotification);
begin
inherited;
if Action = lnDeleted then
begin
//TTaskbar(Ptr^)._position := '';
FreeMem(Ptr);
end;
end;
procedure TTaskbars.NotifyAreaVisible(visible: Boolean);
var
I: Integer;
begin
if FUpdating then Exit;
for I := 0 to Count - 1 do
if visible then
ShowWindow(Items[I]._trayNotifyWnd.Handle, SW_SHOWNOACTIVATE)
else
ShowWindow(Items[I]._trayNotifyWnd.Handle, SW_HIDE);
end;
procedure TTaskbars.PinTaskbar(lnkFile: PChar; pin: Boolean = True;
defaultSize: DWORD = 0);
var
pPEB: Pointer;
dwOrigLen, dwLen: DWORD;
pLdrModule: Pointer;
Windir: String;
szBuff: PChar;
mHandle: HMODULE;
Buff: WideString;
BufLen: Integer;
vShell, vFolder, vFolderItem, vItemVerbs: Variant;
vPath, vApp: Variant;
i: Integer;
sItem: String;
begin
Windir := GetEnvironmentVariable('WINDIR');
asm
MOV EAX, FS:[$30]
MOV pPEB, EAX
end;
pLdrModule := Pointer(PDWORD(DWORD(pPEB) + $C)^);
pLdrModule := Pointer(PDWORD(DWORD(pLdrModule) + $C)^);
dwOrigLen := PDWORD(DWORD(pLdrModule) + $24)^;
szBuff := PChar(PDWORD(DWORD(pLdrModule) + $28)^);
dwLen := lstrlenW(PChar(Windir+'\Explorer.exe')) * 2;
PDWORD(DWORD(pLdrModule) + $24)^ := dwLen;
PDWORD(DWORD(pLdrModule) + $28)^ := DWORD(PChar(Windir+'\Explorer.exe'));
mHandle := LoadLibrary(PChar(Windir + '\System32\Shell32.dll'));
if mHandle <> 0 then
try
SetLength(Buff, 1024);
if pin then
BufLen := LoadStringW(mHandle, 5386, PChar(Buff), Length(Buff))
else
BufLen := LoadStringW(mHandle, 5387, PChar(Buff), Length(Buff));
if BufLen > 0 then
begin
SetLength(Buff, BufLen);
vShell := CreateOleObject('Shell.Application');
vPath := ExtractFilePath(lnkFile);
vFolder := vShell.NameSpace(vPath);
vApp := ExtractFileName(lnkFile);
vFolderItem := vFolder.ParseName(vApp);
vItemVerbs := vFolderItem.Verbs;
for i := 0 to vItemVerbs.Count do
begin
sItem := vItemVerbs.Item(i).Name;
if (sItem = buff) then
begin
vItemVerbs.Item(i).DoIt;
break;
end;
end;
end;
finally
FreeLibrary(mHandle);
end;
// restore PEB name
if defaultSize <> 0 then
PDWORD(DWORD(pLdrModule) + $24)^ := defaultSize
else
PDWORD(DWORD(pLdrModule) + $24)^ := dwOrigLen;
PDWORD(DWORD(pLdrModule) + $28)^ := DWORD(szBuff);
end;
(*
Creates/Updates/Removes taskbars
*)
procedure TTaskbars.Refresh;
var
LHDesktop: HWND;
LHWindow: HWND;
LHParent: HWND;
LExStyle: DWORD;
I: integer;
AppClassName: array[0..255] of char;
Cloaked: Cardinal;
Taskbar: PTaskbar;
curTime: LongInt;
AFound: Boolean;
begin
if FUpdating then Exit;
BeginUpdate;
// Unix timestamp
curTime := Round((Now - TDateTime(25569.0)) * 86400);
LHDesktop:=GetDesktopWindow;
LHWindow:=GetWindow(LHDesktop,GW_CHILD);
while LHWindow <> 0 do
begin
GetClassName(LHWindow, AppClassName, 255);
LHParent:=GetWindowLong(LHWindow,GWL_HWNDPARENT);
LExStyle:=GetWindowLong(LHWindow,GWL_EXSTYLE);
if IsWindowVisible(LHWindow)
and (AppClassName = 'Shell_TrayWnd')
or (AppClassName = 'Shell_SecondaryTrayWnd')
and ((LHParent=0)or(LHParent=LHDesktop))
and (Screen.MonitorFromWindow(LHWindow).MonitorNum <> 0)
then
begin
// check if taskbar is already registered
AFound := False;
if Count > 0 then
begin
for I := 0 to Count - 1 do
if (Items[I]._handle = LHWindow)
and (not AFound)
and (Items[I]._timestamp <> curTime)
then
begin
// already found, update timestamp
Items[I]._timestamp := curTime;
AFound := True;
end;
end;
if not AFound then
begin
GetMem(Taskbar, SizeOf(TTaskbar));
Taskbar^._handle := LHWindow;
Taskbar^._timestamp := curTime;
//Taskbar := TTaskbar.Create(LHWindow);
//Taskbar._timestamp := curTime;
if AppClassName = 'Shell_TrayWnd' then
begin
Taskbar^._mainTaskbar := True;
Taskbar^._reBarWindow32.Handle := FindWindowEx(LHWindow, 0, 'ReBarWindow32', nil);
Taskbar^._MSTaskSwWClass.Handle := FindWindowEx(Taskbar^._reBarWindow32.Handle, 0, 'MSTaskSwWClass', nil);
Taskbar^._MSTaskListWClass.Handle := FindWindowEx(Taskbar^._MSTaskSwWClass.Handle, 0, 'MSTaskListWClass', nil);
Taskbar^._trayNotifyWnd.Handle := FindWindowEx(LHWindow, 0, 'TrayNotifyWnd', nil)
end
else
begin
Taskbar^._mainTaskbar := False;
Taskbar^._WorkerW.Handle := FindWindowEx(LHWindow, 0, 'WorkerW', nil);
Taskbar^._MSTaskListWClass.Handle := FindWindowEx(Taskbar^._WorkerW.Handle, 0, 'MSTaskListWClass', nil);
Taskbar^._trayNotifyWnd.Handle := FindWindowEx(LHWindow, 0, 'ClockButton', nil);
end;
Taskbar^._start.Handle := FindWindowEx(LHWindow, 0, 'Start', nil);
Add(Taskbar);
end;
end;
LHWindow:=GetWindow(LHWindow, GW_HWNDNEXT);
end;
// delete destroyed taskbars
for I := Count - 1 downto 0 do
if Items[I]._timestamp <> curTime then
Delete(I);
EndUpdate;
// check if it was correctly created
if Self.MainTaskbar = nil then
Self.Refresh;
end;
procedure TTaskbars.RestoreAllStarts;
var
I: Integer;
begin
if FUpdating then Exit;
for I := 0 to Count - 1 do
ShowWindow(Items[I]._start.Handle, SW_SHOWNOACTIVATE);
end;
procedure TTaskbars.RestoreOpacity(Handle: THandle);
var
counter: UINT64;
begin
// hacky ugly way to restore opacity, it might fail if start menu is gone
// bcoz, launching start menu restores opacity, but we need to hide it after
SendMessageTimeout(Handle,WM_SYSCOMMAND,SC_TASKLIST,0,SMTO_ABORTIFHUNG, 3000, 0);
counter := GetTickCount64;
while (GetTickCount64 - counter < 3000) do
begin
if IsStartMenuVisible then
begin
keybd_event(VK_LWIN, 0, 0, 0);
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);
counter := counter - 3000;
end;
Sleep(1);
end;
// this restores secondary taskbars too
SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, LongInt(PChar('TraySettings')));
end;
procedure TTaskbars.SetAnimationState(Value: Boolean);
var
reg: TRegistry;
begin
reg := TRegistry.Create;
try
reg.RootKey := HKEY_CURRENT_USER;
reg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced', False);
if Value then
reg.WriteInteger('TaskbarAnimations', 1)
else
reg.WriteInteger('TaskbarAnimations', 0);
SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, LongInt(PChar('TraySettings')));
finally
reg.Free;
end;
end;
procedure TTaskbars.SetAutoHide(state: Boolean);
var
ABData: TAppBarData;
begin
ABData.cbSize := SizeOf(ABData);
if not state then
ABData.lParam := ABS_ALWAYSONTOP
else
ABData.lParam := ABS_AUTOHIDE;
SHAppBarMessage(ABM_SETSTATE,ABData);
end;
procedure TTaskbars.SetSmallIcons(Value: Boolean);
var
reg: TRegistry;
begin
reg := TRegistry.Create;
try
reg.RootKey := HKEY_CURRENT_USER;
reg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced', False);
if Value then
reg.WriteInteger('TaskbarSmallIcons', 1)
else
reg.WriteInteger('TaskbarSmallIcons', 0);
SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, LongInt(PChar('TraySettings')));
finally
reg.Free;
end;
end;
procedure TTaskbars.StartBtnVisible(Index:Integer; Visible: Boolean);
begin
if FUpdating then Exit;
if visible then
ShowWindow(Items[Index]._start.Handle, SW_SHOWNOACTIVATE)
else
ShowWindow(Items[Index]._start.Handle, SW_HIDE);
end;
procedure TTaskbars.Transparent(Value: Boolean = True);
var
I: Integer;
accent: AccentPolicy;
data: WindowCompositionAttributeData;
begin
if FUpdating then Exit;
for I := 0 to Count - 1 do
begin
//if _notaskbar then Exit;
//Items[I]._transstyle := ACCENT_ENABLE_TRANSPARENTGRADIENT;
if Value then
accent.AccentState := ACCENT_ENABLE_TRANSPARENTGRADIENT //Items[I]._transstyle;
else
accent.AccentState := ACCENT_ENABLE_GRADIENT;
accent.GradientColor := $00000000;
if Value then
accent.AccentFlags := not $20 and not $40 and not $80 and not $100
else // draw left, top, right and bottom borders
accent.AccentFlags := $20 or $40 or $80 or $100;
data.Attribute := WCA_ACCENT_POLICY;
data.SizeOfData := SizeOf(accent);
data.Data := @accent;
// if Items[I]._transstyle = ACCENT_ENABLE_TRANSPARENTGRADIENT then
SetWindowCompositionAttribute(Items[I].Handle, data);
end;
end;
procedure TTaskbars.UpdateTaskbarInfo;
var
n, i, j: Integer;
res: HRESULT;
acc: IAccessible;
childArray: array of OleVariant;
iChildCount, iObtained: Integer;
iBtnCount, iBtnObtained: Integer;
taskbarCaption, childName: WideString;
childAccessible: IAccessible;
childDispatch: IDispatch;
buttonsArray: array of OleVariant;
btnName: WideString;
btnRect: TRect;
firstBtnLeft, firstBtnRight: Boolean;
firstBtnTop, firstBtnBottom: Boolean;
AMonitor: TMonitor;
ABData: TAppBarData;
begin
if FUpdating then Exit;
for n := 0 to Count - 1 do
begin
// if _notaskbar then Exit;
// Update taskbar's rect data
GetWindowRect(Items[n]._handle, Items[n]._rect);
if Items[n].MainTaskbar then
begin
if Items[n]._reBarWindow32.Handle <> 0 then
GetWindowRect(Items[n]._reBarWindow32.Handle, Items[n]._reBarWindow32.Rect);
if Items[n]._MSTaskSwWClass.Handle <> 0 then
GetWindowRect(Items[n]._MSTaskSwWClass.Handle, Items[n]._MSTaskSwWClass.Rect);
end
else
begin
if Items[n]._WorkerW.Handle <> 0 then
GetWindowRect(Items[n]._WorkerW.Handle, Items[n]._WorkerW.Rect);
end;
if Items[n]._MSTaskListWClass.Handle <> 0 then
GetWindowRect(Items[n]._MSTaskListWClass.Handle, Items[n]._MSTaskListWClass.Rect);
//GetMonitor; // it updates taskbar's _monitorrect
AMonitor := Screen.MonitorFromRect(Items[n]._rect);
// if _maonitor = Result.MonitorNum + 1 then
begin
Items[n]._monitorrect := AMonitor.BoundsRect;
Items[n]._monitorId := AMonitor.MonitorNum + 1;
end;
// if _monitorId = _monitor then
if Items[n].MainTaskbar then
begin
if SHAppBarMessage(ABM_GETTASKBARPOS, ABData) <> 0 then
begin
Items[n]._rect := ABData.rc;
Items[n].Position := ABData.uEdge;
end;
end
else
begin
if (Items[n]._rect.Width > Items[n]._rect.Height)
and (Items[n].MonitorRect.Top = Items[n]._rect.Top)
then
Items[n].Position := ABE_TOP
else if (Items[n]._rect.Width > Items[n]._rect.Height)
and (Items[n].MonitorRect.Bottom = Items[n]._rect.Bottom)
then
Items[n].Position := ABE_BOTTOM
else if (Items[n]._rect.Width < Items[n]._rect.Height)
and (Items[n].MonitorRect.Left = Items[n]._rect.Left)
then
Items[n].Position := ABE_LEFT
else if (Items[n]._rect.Width < Items[n]._rect.Height)
and (Items[n].MonitorRect.Right = Items[n]._rect.Right)
then
Items[n].Position := ABE_RIGHT;
end;
if Items[n]._start.Handle <> 0 then
GetWindowRect(Items[n]._start.Handle, Items[n]._start.Rect);
if Items[n]._trayNotifyWnd.Handle <> 0 then
GetWindowRect(Items[n]._trayNotifyWnd.Handle, Items[n]._trayNotifyWnd.Rect);
{_trayDummySearchControl.Handle := FindWindowEx(_handle, 0, 'TrayDummySearchControl', nil);
if _trayDummySearchControl.Handle > 0 then
GetWindowRect(_trayDummySearchControl.Handle, _trayDummySearchControl.Rect);}
// Get Width and Rect of taskbar application's buttons
firstBtnLeft := True;
firstBtnRight := True;
firstBtnTop := True;
firstBtnBottom := True;
res := AccessibleObjectFromWindow(Items[n]._MSTaskListWClass.Handle, 0, IID_IAccessible, acc);
if res = S_OK then
begin
// Let's first get access to the button's container
if acc.Get_accName(CHILDID_SELF, taskbarCaption) = S_OK then
begin
//
end
else Exit;
// now that we found the main taskbar's button wrapper, we get the children objects
if (acc.Get_accChildCount(iChildCount) = S_OK) and (iChildCount > 0) then
begin
SetLength(childArray, iChildCount);
if AccessibleChildren(Pointer(acc), 0, iChildCount, childArray[0], iObtained) = S_OK then
begin
for i := 0 to (iObtained - 1) do
begin
childDispatch := nil;
if VarType(childArray[i]) = varDispatch then // varInteger is not needed since we are traversing in similar objects now
begin
childDispatch := childArray[i];
if (childDispatch <> nil) and (childDispatch.QueryInterface(iAccessible, childAccessible) = S_OK) then
begin
if (childAccessible.Get_accName(CHILDID_SELF, childName) = S_OK) and (childName = taskbarCaption) then
begin
//
if (childAccessible.Get_accChildCount(iBtnCount) = S_OK) and (iBtnCount > 0) then
begin
SetLength(buttonsArray, iBtnCount);
if AccessibleChildren(Pointer(childAccessible), 0, iBtnCount, buttonsArray[0], iBtnObtained) = S_OK then
begin
//childAccessible.accLocation(_appsBtnLeft, _appsBtnTop, _appsBtnRight, _appsBtnBottom, CHILDID_SELF);
for j := 0 to iBtnObtained - 1 do
begin
if VarType(buttonsArray[j]) = varInteger then // now we must make sure it is an integer type, because this time
// we found the buttons, which don't contain anymore child objects
begin
if childAccessible.Get_accName(buttonsArray[j], btnName) = S_OK then
begin
childAccessible.accLocation(btnRect.Left, btnRect.Top, btnRect.Right, btnRect.Bottom, buttonsArray[j]);
// now we must make sure the button found has width and height major than 0
if (btnRect.Bottom > 0) and (btnRect.Right> 0) then
begin
if (Items[n].Position = ABE_LEFT) or (Items[n].Position = ABE_RIGHT) then
begin
if firstBtnTop then
begin
firstBtnTop := False;
Items[n]._appsBtnTop := btnRect.Top;
end
else
begin
if btnRect.Top < Items[n]._appsBtnTop then
Items[n]._appsBtnTop := btnRect.Top;
end;
if firstBtnBottom then
begin
firstBtnBottom := False;
Items[n]._appsBtnBottom := btnRect.Top + btnRect.Bottom;
end
else
begin
if btnRect.Top + btnRect.Bottom > Items[n]._appsBtnBottom then
Items[n]._appsBtnBottom := btnRect.Top + btnRect.Bottom;
end;
end
else
begin
if firstBtnLeft then
begin
firstBtnLeft := False;
Items[n]._appsBtnLeft := btnRect.Left;
end
else
begin
if btnRect.Left < Items[n]._appsBtnLeft then
Items[n]._appsBtnLeft := btnRect.Left;