Author: Jonas Bilinkevicius
\I'm trying to determine the edge and rectangle of the Windows taskbar, using the
SHAppBarMessage API - but how do I get the Windows taskbar handle?
Answer:
I put a procedure together that gets all the information one would want to get
about the TaskBar: Pos (Rect), Edge, window handle, and whether it's set to be
AutoHide or AlwaysOnTop. I got the parameter and return information by following
the parameter value entries within the Win32 Programmers' reference Online Help
file. I also used a 1 second timer to fire the ButtonClick, so that I could test
dragging and resizing the TaskBar. I'm not sure if the "Edge section" of code
(ABM_GETAUTOHIDEBAR) will work properly if there are other AppBars on the system.
1
2 procedure GetTaskBarData(var AppBarInfo: TAppBarData; var AutoHide, AlwaysOnTop:
3 boolean);
4 var
5 i, RetVal: Cardinal;
6 begin
7 fillchar(AppBarInfo, sizeof(AppBarInfo), 0);
8 AppBarInfo.cbSize := sizeof(AppBarInfo);
9 RetVal := ShAppBarMessage(ABM_GETSTATE, AppBarInfo);
10 AutoHide := RetVal and ABS_AUTOHIDE > 0;
11 AlwaysOnTop := RetVal and ABS_ALWAYSONTOP > 0;
12 for i := 0 to 3 do
13 begin {ask all the edges}
14 AppBarInfo.uEdge := i; {then drop the Taskbar Handle into AppBarInfo}
15 AppBarInfo.hWnd := ShAppBarMessage(ABM_GETAUTOHIDEBAR, AppBarInfo);
16 if AppBarInfo.hWnd <> 0 then
17 break;
18 {the Taskbar's edge value is left in uEdge by the break}
19 end;
20 SHAppBarMessage(ABM_GETTASKBARPOS, AppBarInfo);
21 end;
22
23 procedure TForm1.Button1Click(Sender: TObject);
24 var
25 ABI: TAppBarData;
26 AHide, AlOnTop: Boolean;
27 s: string;
28 begin
29 GetTaskBarData(ABI, AHide, AlOnTop);
30 with ABI do
31 begin
32 caption := format('%d %d %d %d', [rc.left, rc.top, rc.right, rc.bottom]);
33 case uEdge of
34 ABE_BOTTOM: s := 'Bottom';
35 ABE_LEFT: s := 'Left';
36 ABE_RIGHT: s := 'Right';
37 ABE_TOP: S := 'Top';
38 end;
39 if AHide then
40 s := s + ' AutoHide';
41 if AlOnTop then
42 s := s + ' AlwaysOnTop';
43 caption := caption + ' ' + s;
44 end;
45 end;
|