-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtaskbar.pas
668 lines (574 loc) · 21.6 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
{
Taskbar unit
Description:
This unit gets info from windows taskbar, position, icons
}
unit taskbar;
interface
uses classes, windows, graphics, registry, dwmapi, oleacc, variants, forms;
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}';
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;
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 = class
private
_reg: TRegistry;
_position: TTaskPosition; // Position on the screen
_rect: TRect; // Shell_TrayWnd
_translucent: Boolean;
_handle: THandle;
_notaskbar: Boolean;
_transstyle: Integer;
_monitor: Integer;
_monitorRect: TRect;
_monitorId: Integer;
_start: TTaskComponent;
_trayButton1: TTaskComponent;
_trayButton2: TTaskComponent;
_trayDummySearchControl: TTaskComponent;
_reBarWindow32: TTaskComponent;
_WorkerW: TTaskComponent;
_MSTaskSwWClass: TTaskComponent;
_MSTaskListWClass: TTaskComponent;
_trayNotifyWnd: TTaskComponent;
_appsBtnLeft, _appsBtnRight: Integer;
_appsBtnTop, _appsBtnBottom: Integer;
function _IsTransparent: Boolean;
procedure HideStartBtn;
procedure ShowStartBtn;
function _getIconsRect: TRect;
public
property Handle: THandle read _handle;
property Position: TTaskPosition 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 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;
constructor Create(monitor: Integer = 1);
destructor Destroy; override;
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;
procedure UpdateTaskbarHandle;
function GetMonitor: TMonitor;
function IsStartMenuVisible: Boolean;
end;
TTaskbars = class(TList)
private
function Get(Index: Integer): PTaskbar;
public
function Add(Value: TTaskbar): Integer;
procedure Refresh;
procedure CenterAppsButtons(center: Boolean = True; relative: Boolean = False);
procedure Notify(Ptr: Pointer; Action: TListNotification); override;
property Items[Index: Integer]: PTaskbar read Get; default;
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.CenterAppsButtons(center: Boolean = True; relative: Boolean = False);
var
aLeft, aTop: Integer;
begin
if _start.Handle = 0 then Exit; // make sure taskbar exists
// if _appsBtnLeft = 0 then Exit; // #TODO taskbar being sides centering is not handled yet
if not center then
begin
if _monitor = 1 then
SetWindowPos(_MSTaskListWClass.Handle, 0, 0, 0, _MSTaskSwWClass.Rect.Width, _MSTaskSwWClass.Rect.Height, SWP_NOACTIVATE)
else if _monitor = 2 then
SetWindowPos(_MSTaskListWClass.Handle, 0, 0, 0, _WorkerW.Rect.Width, _WorkerW.Rect.Height, SWP_NOACTIVATE)
end
else
begin
//center buttons
if (Position = TTaskPos.Left) or (Position = TTaskPos.Right) then
begin
if _monitor = 1 then
begin
if (_appsBtnBottom - _appsBtnTop + 6) > _MSTaskSwWClass.Rect.Height then Exit;
if relative then
aTop := (_MSTaskSwWClass.Rect.Height div 2) - ((_appsBtnBottom - _appsBtnTop) div 2)
else
aTop := (_rect.Height div 2) - _MSTaskSwWClass.Rect.Top - ((_appsBtnBottom - _appsBtnTop) div 2);
SetWindowPos(_MSTaskListWClass.Handle, 0, 0, aTop, _MSTaskListWClass.Rect.Width, (_appsBtnBottom - _appsBtnTop + 6), SWP_NOACTIVATE);
end
else if _monitor = 2 then
begin
if (abs(_appsBtnBottom - _appsBtnTop) + 6) > abs(_WorkerW.Rect.Bottom - _WorkerW.Rect.Top) then Exit;
if relative then
aTop := (_WorkerW.Rect.Height div 2) - ((_appsBtnBottom - _appsBtnTop) div 2)
else
aTop := (_rect.Height div 2) - abs(_WorkerW.Rect.Top-_rect.Top) - ((_appsBtnBottom - _appsBtnTop) div 2);
SetWindowPos(_MSTaskListWClass.Handle, 0, 0, aTop, _MSTaskListWClass.Rect.Width, (_appsBtnBottom - _appsBtnTop + 6), SWP_NOACTIVATE);
end;
end
else
begin
// if taskbar buttons width is full, there is no need to adjust, 6 is a margin constant
if _monitor = 1 then
begin
if (_appsBtnRight - _appsBtnLeft + 6) > _MSTaskSwWClass.Rect.Width then Exit;
if relative then
aLeft := (_MSTaskSwWClass.Rect.Width div 2) - ((_appsBtnRight - _appsBtnLeft) div 2)
else
aLeft := (_rect.Width div 2) - _MSTaskSwWClass.Rect.Left - ((_appsBtnRight - _appsBtnLeft) div 2);
SetWindowPos(_MSTaskListWClass.Handle, 0, aLeft, 0, (_appsBtnRight - _appsBtnLeft + 6), _MSTaskListWClass.Rect.Height, SWP_NOACTIVATE);
end
else if _monitor = 2 then
begin
if (abs(_appsBtnRight - _appsBtnLeft) + 6) > abs(_WorkerW.Rect.Right - _WorkerW.Rect.Left) then Exit;
if relative then
aLeft := (_WorkerW.Rect.Width div 2) - ((_appsBtnRight - _appsBtnLeft) div 2)
else
aLeft := (_rect.Width div 2) - abs(_WorkerW.Rect.Left-_rect.Left) - ((_appsBtnRight - _appsBtnLeft) div 2);
SetWindowPos(_MSTaskListWClass.Handle, 0, aLeft, 0, (_appsBtnRight - _appsBtnLeft + 6), _MSTaskListWClass.Rect.Height, SWP_NOACTIVATE);
end;
end;
end;
end;
constructor TTaskbar.Create(monitor: Integer = 1);
begin
_transstyle := ACCENT_ENABLE_TRANSPARENTGRADIENT;
_monitor := monitor;
if _monitor = 1 then
_handle := FindWindow('Shell_TrayWnd', nil)
else if _monitor = 2 then
_handle := FindWindow('Shell_SecondaryTrayWnd', nil);
if _handle = 0 then
_notaskbar := True
else
_notaskbar := False;
end;
destructor TTaskbar.Destroy;
begin
inherited;
end;
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 _monitor = Result.MonitorNum + 1 then
begin
_monitorrect := Result.BoundsRect;
_monitorId := Result.MonitorNum + 1;
end;
end;
procedure TTaskbar.Hide(handle: THandle);
begin
if handle = 0 then Exit;
ShowWindow(handle, SW_HIDE);
end;
procedure TTaskbar.HideStartBtn;
begin
Hide(_start.Handle);
end;
procedure TTaskbar.NotifyAreaVisible(visible: Boolean);
begin
if visible then
Show(_trayNotifyWnd.Handle)
else
Hide(_trayNotifyWnd.Handle);
end;
procedure TTaskbar.Show(handle: THandle);
begin
if handle = 0 then Exit;
ShowWindow(handle, SW_SHOWNOACTIVATE);
end;
procedure TTaskbar.ShowStartBtn;
begin
Show(_start.Handle);
end;
procedure TTaskbar.StartBtnVisible(visible: Boolean);
begin
if visible then
Show(_start.Handle)
else
Hide(_start.Handle);
end;
procedure TTaskbar.Transparent;
var
accent: AccentPolicy;
data: WindowCompositionAttributeData;
begin
if _notaskbar then Exit;
accent.AccentState := _transstyle;
accent.GradientColor := $00000000;
accent.AccentFlags := 2; // 2: seems to hide the border
data.Attribute := WCA_ACCENT_POLICY;
data.SizeOfData := SizeOf(accent);
data.Data := @accent;
if _transstyle = ACCENT_ENABLE_TRANSPARENTGRADIENT then
SetWindowCompositionAttribute(_handle, data);
end;
procedure TTaskbar.UpdateTaskbarHandle;
begin
if _monitor = 1 then
_handle := FindWindow('Shell_TrayWnd', nil)
else if _monitor = 2 then
_handle := FindWindow('Shell_SecondaryTrayWnd', nil);
if _handle = 0 then
_notaskbar := True
else
_notaskbar := False;
end;
procedure TTaskbar.UpdateTaskbarInfo;
var
res: HRESULT;
acc: IAccessible;
childArray: array of OleVariant;
iChildCount, iObtained: Integer;
i, j, iBtnCount, iBtnObtained: Integer;
taskbarCaption, childName: WideString;
childAccessible: IAccessible;
childDispatch: IDispatch;
buttonsArray: array of OleVariant;
btnName: WideString;
btnRect: TRect;
firstBtnLeft, firstBtnRight: Boolean;
firstBtnTop, firstBtnBottom: Boolean;
begin
if _notaskbar then Exit;
GetWindowRect(_handle, _rect);
if _monitor = 1 then
begin
_reBarWindow32.Handle := FindWindowEx(_handle, 0, 'ReBarWindow32', nil);
if _reBarWindow32.Handle = 0 then Exit;
GetWindowRect(_reBarWindow32.Handle, _reBarWindow32.Rect);
_MSTaskSwWClass.Handle := FindWindowEx(_reBarWindow32.Handle, 0, 'MSTaskSwWClass', nil);
if _MSTaskSwWClass.Handle = 0 then Exit;
GetWindowRect(_MSTaskSwWClass.Handle, _MSTaskSwWClass.Rect);
_MSTaskListWClass.Handle := FindWindowEx(_MSTaskSwWClass.Handle, 0, 'MSTaskListWClass', nil);
end
else if _monitor = 2 then
begin
_WorkerW.Handle := FindWindowEx(_handle, 0, 'WorkerW', nil);
if _WorkerW.Handle = 0 then Exit;
GetWindowRect(_WorkerW.Handle, _WorkerW.Rect);
_MSTaskListWClass.Handle := FindWindowEx(_WorkerW.Handle, 0, 'MSTaskListWClass', nil);
end;
if _MSTaskListWClass.Handle = 0 then Exit;
GetWindowRect(_MSTaskListWClass.Handle, _MSTaskListWClass.Rect);
GetMonitor; // it updates taskbar's _monitorrect
if _monitorId = _monitor then
begin
if (_rect.Width > _rect.Height)
and (MonitorRect.Top = _rect.Top)
then
Position := TTaskPos.Top
else if (_rect.Width > _rect.Height)
and (MonitorRect.Bottom = _rect.Bottom)
then
Position := TTaskPos.Bottom
else if (_rect.Width < _rect.Height)
and (MonitorRect.Left = _rect.Left)
then
Position := TTaskPos.Left
else if (_rect.Width < _rect.Height)
and (MonitorRect.Right = _rect.Right)
then
Position := TTaskPos.Right;
end;
_start.Handle := FindWindowEx(_handle, 0, 'Start', nil);
if _start.Handle = 0 then Exit;
GetWindowRect(_start.Handle, _start.Rect);
if _monitor = 1 then
_trayNotifyWnd.Handle := FindWindowEx(_handle, 0, 'TrayNotifyWnd', nil)
else if _monitor = 2 then
_trayNotifyWnd.Handle := FindWindowEx(_handle, 0, 'ClockButton', nil);
if _trayNotifyWnd.Handle = 0 then Exit;
GetWindowRect(_trayNotifyWnd.Handle, _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(_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
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 (Position = TTaskPos.Left) or (Position = TTaskPos.Right) then
begin
if firstBtnTop then
begin
firstBtnTop := False;
_appsBtnTop := btnRect.Top;
end
else
begin
if btnRect.Top < _appsBtnTop then
_appsBtnTop := btnRect.Top;
end;
if firstBtnBottom then
begin
firstBtnBottom := False;
_appsBtnBottom := btnRect.Top + btnRect.Bottom;
end
else
begin
if btnRect.Top + btnRect.Bottom > _appsBtnBottom then
_appsBtnBottom := btnRect.Top + btnRect.Bottom;
end;
end
else
begin
if firstBtnLeft then
begin
firstBtnLeft := False;
_appsBtnLeft := btnRect.Left;
end
else
begin
if btnRect.Left < _appsBtnLeft then
_appsBtnLeft := btnRect.Left;
end;
if firstBtnRight then
begin
firstBtnRight := False;
_appsBtnRight := btnRect.Left + btnRect.Right;
end
else
begin
if btnRect.Left + btnRect.Right > _appsBtnRight then
_appsBtnRight := btnRect.Left + btnRect.Right;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
function TTaskbar.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;
end;
function TTaskbar._getIconsRect: TRect;
begin
Result := _MSTaskListWClass.Rect;
Result.Right := _appsBtnRight;
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: TTaskbar): Integer;
begin
Result := inherited Add(Value);
end;
procedure TTaskbars.CenterAppsButtons(center, relative: Boolean);
var
I: Integer;
begin
for I := 0 to Count - 1 do
Items[I].CenterAppsButtons(center, relative);
end;
function TTaskbars.Get(Index: Integer): PTaskbar;
begin
Result := PTaskbar(inherited Get(Index));
end;
procedure TTaskbars.Notify(Ptr: Pointer; Action: TListNotification);
begin
inherited;
if Action = lnDeleted then
FreeMem(Ptr);
end;
procedure TTaskbars.Refresh;
var
LHDesktop: HWND;
LHWindow: HWND;
LHParent: HWND;
LExStyle: DWORD;
I: integer;
AppClassName: array[0..255] of char;
Cloaked: Cardinal;
Taskbar: TTaskbar;
begin
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
Taskbar := TTaskbar.Create();
Add(Taskbar);
end;
LHWindow:=GetWindow(LHWindow, GW_HWNDNEXT);
end;
end;
end.