How to get detailed information about the Windows taskbar programmatically (Views: 708)
Problem/Question/Abstract: 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. procedure GetTaskBarData(var AppBarInfo: TAppBarData; var AutoHide, AlwaysOnTop: boolean); var i, RetVal: Cardinal; begin fillchar(AppBarInfo, sizeof(AppBarInfo), 0); AppBarInfo.cbSize := sizeof(AppBarInfo); RetVal := ShAppBarMessage(ABM_GETSTATE, AppBarInfo); AutoHide := RetVal and ABS_AUTOHIDE > 0; AlwaysOnTop := RetVal and ABS_ALWAYSONTOP > 0; for i := 0 to 3 do begin {ask all the edges} AppBarInfo.uEdge := i; {then drop the Taskbar Handle into AppBarInfo} AppBarInfo.hWnd := ShAppBarMessage(ABM_GETAUTOHIDEBAR, AppBarInfo); if AppBarInfo.hWnd <> 0 then break; {the Taskbar's edge value is left in uEdge by the break} end; SHAppBarMessage(ABM_GETTASKBARPOS, AppBarInfo); end; procedure TForm1.Button1Click(Sender: TObject); var ABI: TAppBarData; AHide, AlOnTop: Boolean; s: string; begin GetTaskBarData(ABI, AHide, AlOnTop); with ABI do begin caption := format('%d %d %d %d', [rc.left, rc.top, rc.right, rc.bottom]); case uEdge of ABE_BOTTOM: s := 'Bottom'; ABE_LEFT: s := 'Left'; ABE_RIGHT: s := 'Right'; ABE_TOP: S := 'Top'; end; if AHide then s := s + ' AutoHide'; if AlOnTop then s := s + ' AlwaysOnTop'; caption := caption + ' ' + s; end; end; |