Skip to content

Commit cd64b5b

Browse files
committed
- Added StartMenu launcher visibility detection
- MSTaskListRect detection - Taskbar transparency correctly set now - Multipl taskbar separation in progress
1 parent cfe6324 commit cd64b5b

File tree

1 file changed

+158
-4
lines changed

1 file changed

+158
-4
lines changed

taskbar.pas

Lines changed: 158 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,50 @@ interface
1212

1313
const
1414
WCA_ACCENT_POLICY = 19;
15+
ACCENT_DISABLED = 0;
1516
ACCENT_ENABLE_GRADIENT = 1;
1617
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2;
1718
ACCENT_ENABLE_BLURBEHIND = 3;
19+
ACCENT_ENABLE_ACRYLICBLURBEHIND = 4;
1820

21+
//https://stackoverflow.com/a/22105803/537347 Windows 8 or newer only
22+
IID_AppVisibility: TGUID = '{2246EA2D-CAEA-4444-A3C4-6DE827E44313}';
23+
CLSID_AppVisibility: TGUID = '{7E5FE3D9-985F-4908-91F9-EE19F9FD1514}';
24+
//IID_IAppVisibilityEvents: TGUID = '{6584CE6B-7D82-49C2-89C9-C6BC02BA8C38}';
1925
type
26+
27+
MONITOR_APP_VISIBILITY = (
28+
MAV_UNKNOWN = 0,
29+
MAV_NO_APP_VISIBLE = 1,
30+
MAV_APP_VISIBLE = 2
31+
);
32+
// *********************************************************************//
33+
// Interface: IAppVisibilityEvents
34+
// Flags: (0)
35+
// GUID: {6584CE6B-7D82-49C2-89C9-C6BC02BA8C38}
36+
// *********************************************************************//
37+
IAppVisibilityEvents = interface(IUnknown)
38+
['{6584CE6B-7D82-49C2-89C9-C6BC02BA8C38}']
39+
function AppVisibilityOnMonitorChanged(hMonitor: HMONITOR;
40+
previousMode: MONITOR_APP_VISIBILITY;
41+
currentMode: MONITOR_APP_VISIBILITY):HRESULT; stdcall;
42+
function LauncherVisibilityChange(currentVisibleState: BOOL): HRESULT; stdcall;
43+
end;
44+
45+
46+
// *********************************************************************//
47+
// Interface: IAppVisibility
48+
// Flags: (0)
49+
// GUID: {2246EA2D-CAEA-4444-A3C4-6DE827E44313}
50+
// *********************************************************************//
51+
IAppVisibility = interface(IUnknown)
52+
['{2246EA2D-CAEA-4444-A3C4-6DE827E44313}']
53+
function GetAppVisibilityOnMonitor(monitor: HMONITOR; out pMode: MONITOR_APP_VISIBILITY): HRESULT; stdcall;
54+
function IsLauncherVisible(out pfVisible: BOOL): HRESULT; stdcall;
55+
function Advise(pCallBack: IAppVisibilityEvents; out pdwCookie: DWORD): HRESULT; stdcall;
56+
function Unadvise(dwCookie: DWORD): HRESULT; stdcall;
57+
end;
58+
2059
AccentPolicy = packed record
2160
AccentState: Integer;
2261
AccentFlags: Integer;
@@ -44,6 +83,7 @@ TTaskComponent = record
4483
Rect: TRect;
4584
end;
4685

86+
PTaskbar = ^TTaskbar;
4787
TTaskbar = class
4888
private
4989
_reg: TRegistry;
@@ -72,7 +112,9 @@ TTaskbar = class
72112
function _IsTransparent: Boolean;
73113
procedure HideStartBtn;
74114
procedure ShowStartBtn;
115+
function _getIconsRect: TRect;
75116
public
117+
property Handle: THandle read _handle;
76118
property Position: TTaskPosition read _position write _position;
77119
property MonitoID: Integer read _monitorId;
78120
property MonitorRect: TRect read _monitorRect;
@@ -82,7 +124,8 @@ TTaskbar = class
82124

83125
property AppsLeft: Integer read _appsBtnLeft;
84126
property AppsRight: Integer read _appsBtnRight;
85-
property MSTaskList: TRect read _MSTaskListWClass.Rect;
127+
property MSTaskListRect: TRect read _getIconsRect;
128+
property MSTaskRect: TRect read _MSTaskSwWClass.Rect;
86129
property TrayRect: TRect read _trayNotifyWnd.Rect;
87130
property StartRect: TRect read _start.Rect;
88131

@@ -98,6 +141,18 @@ TTaskbar = class
98141
procedure FullTaskBar;
99142
procedure UpdateTaskbarHandle;
100143
function GetMonitor: TMonitor;
144+
function IsStartMenuVisible: Boolean;
145+
end;
146+
147+
TTaskbars = class(TList)
148+
private
149+
function Get(Index: Integer): PTaskbar;
150+
public
151+
function Add(Value: TTaskbar): Integer;
152+
procedure Refresh;
153+
procedure CenterAppsButtons(center: Boolean = True; relative: Boolean = False);
154+
procedure Notify(Ptr: Pointer; Action: TListNotification); override;
155+
property Items[Index: Integer]: PTaskbar read Get; default;
101156
end;
102157

103158
function SetWindowCompositionAttribute(hWnd: HWND; var data: WindowCompositionAttributeData): Integer; stdcall;
@@ -112,6 +167,8 @@ implementation
112167

113168
{ TTaskbar }
114169

170+
uses ActiveX, Shlobj, ComObj;
171+
115172
procedure TTaskbar.CenterAppsButtons(center: Boolean = True; relative: Boolean = False);
116173
var
117174
aLeft, aTop: Integer;
@@ -211,7 +268,7 @@ procedure TTaskbar.FullTaskBar;
211268

212269
if _appsBtnLeft = 0 then Exit;
213270

214-
SetWindowPos(_MSTaskSwWClass.Handle, 0, 0, 0, _rect.Width, _MSTaskSwWClass.Rect.Height, SWP_NOACTIVATE);
271+
SetWindowPos(_MSTaskSwWClass.Handle, 0, 0, 0, _rect.Width, _MSTaskSwWClass.Rect.Height, SWP_NOSENDCHANGING);
215272
end;
216273

217274
function TTaskbar.GetMonitor: TMonitor;
@@ -240,6 +297,7 @@ procedure TTaskbar.HideStartBtn;
240297
Hide(_start.Handle);
241298
end;
242299

300+
243301
procedure TTaskbar.NotifyAreaVisible(visible: Boolean);
244302
begin
245303
if visible then
@@ -277,12 +335,14 @@ procedure TTaskbar.Transparent;
277335
if _notaskbar then Exit;
278336

279337
accent.AccentState := _transstyle;
280-
// accent.GradientColor := $00000000;
338+
accent.GradientColor := $00000000;
339+
accent.AccentFlags := 2; // 2: seems to hide the border
281340
data.Attribute := WCA_ACCENT_POLICY;
282341
data.SizeOfData := SizeOf(accent);
283342
data.Data := @accent;
284343

285-
SetWindowCompositionAttribute(_handle, data);
344+
if _transstyle = ACCENT_ENABLE_TRANSPARENTGRADIENT then
345+
SetWindowCompositionAttribute(_handle, data);
286346
end;
287347

288348
procedure TTaskbar.UpdateTaskbarHandle;
@@ -493,6 +553,37 @@ procedure TTaskbar.UpdateTaskbarInfo;
493553
end;
494554
end;
495555

556+
function TTaskbar.IsStartMenuVisible: Boolean;
557+
var
558+
acc: IAppVisibility;
559+
res: HRESULT;
560+
isLauncherVisible: BOOL;
561+
begin
562+
Result := False;
563+
// Initialization of COM is required to use the AppVisibility (CLSID_AppVisibility) object
564+
res := CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
565+
if Succeeded(res) then
566+
begin
567+
// Create the App Visibility component
568+
res := CoCreateInstance(CLSID_AppVisibility, nil, CLSCTX_ALL, IID_AppVisibility, acc);
569+
if Succeeded(res) then
570+
begin
571+
res := acc.IsLauncherVisible(isLauncherVisible);
572+
if Succeeded(res) then
573+
Result := Boolean(isLauncherVisible);
574+
end;
575+
576+
end;
577+
578+
end;
579+
580+
function TTaskbar._getIconsRect: TRect;
581+
begin
582+
Result := _MSTaskListWClass.Rect;
583+
584+
Result.Right := _appsBtnRight;
585+
end;
586+
496587
function TTaskbar._IsTransparent: Boolean;
497588
begin
498589
_translucent := False;
@@ -511,4 +602,67 @@ function TTaskbar._IsTransparent: Boolean;
511602
Result := _translucent;
512603
end;
513604

605+
{ TTaskbars }
606+
607+
function TTaskbars.Add(Value: TTaskbar): Integer;
608+
begin
609+
Result := inherited Add(Value);
610+
end;
611+
612+
procedure TTaskbars.CenterAppsButtons(center, relative: Boolean);
613+
var
614+
I: Integer;
615+
begin
616+
for I := 0 to Count - 1 do
617+
Items[I].CenterAppsButtons(center, relative);
618+
end;
619+
620+
function TTaskbars.Get(Index: Integer): PTaskbar;
621+
begin
622+
Result := PTaskbar(inherited Get(Index));
623+
end;
624+
625+
procedure TTaskbars.Notify(Ptr: Pointer; Action: TListNotification);
626+
begin
627+
inherited;
628+
629+
if Action = lnDeleted then
630+
FreeMem(Ptr);
631+
end;
632+
633+
procedure TTaskbars.Refresh;
634+
var
635+
LHDesktop: HWND;
636+
LHWindow: HWND;
637+
LHParent: HWND;
638+
LExStyle: DWORD;
639+
I: integer;
640+
AppClassName: array[0..255] of char;
641+
Cloaked: Cardinal;
642+
Taskbar: TTaskbar;
643+
begin
644+
LHDesktop:=GetDesktopWindow;
645+
LHWindow:=GetWindow(LHDesktop,GW_CHILD);
646+
647+
while LHWindow <> 0 do
648+
begin
649+
GetClassName(LHWindow, AppClassName, 255);
650+
LHParent:=GetWindowLong(LHWindow,GWL_HWNDPARENT);
651+
LExStyle:=GetWindowLong(LHWindow,GWL_EXSTYLE);
652+
653+
if IsWindowVisible(LHWindow)
654+
and (AppClassName = 'Shell_TrayWnd')
655+
or (AppClassName = 'Shell_SecondaryTrayWnd')
656+
and ((LHParent=0)or(LHParent=LHDesktop))
657+
and (Screen.MonitorFromWindow(LHWindow).MonitorNum <> 0)
658+
then
659+
begin
660+
Taskbar := TTaskbar.Create();
661+
Add(Taskbar);
662+
end;
663+
LHWindow:=GetWindow(LHWindow, GW_HWNDNEXT);
664+
end;
665+
666+
end;
667+
514668
end.

0 commit comments

Comments
 (0)