2009. augusztus 3., hétfő

How to determine the size of the Windows taskbar


Problem/Question/Abstract:

How to determine the size of the Windows taskbar

Answer:

Solve 1:

You need to get the Rect in the rc member of the APPBARData structure and subtract the top from the bottom.

procedure TForm1.Button1Click(Sender: TObject);
var
  appbardata: TAppBarData;
  Rect: TRect;
  taskBarHeight: Integer;
begin
  AppBarData.cbSize := 0;
  AppBarData.hWnd := 0;
  AppBarData.rc.Left := 0;
  AppBarData.rc.Top := 0;
  AppBarData.rc.Bottom := 0;
  AppBarData.rc.Right := 0;
  SHAppBarMessage(ABM_GETTASKBARPOS, appbardata);
  Rect := appbardata.rc;
  taskBarHeight := Rect.Bottom - Rect.Top;
  ShowMessage(IntToStr(taskBarHeight));
end;


Solve 2:

function GetTaskBarSize: TRect;
var
  wnd: HWND;
begin
  wnd := FindWindow('Shell_TrayWnd', nil);
  if wnd > 0 then
    GetWindowRect(wnd, Result)
  else
    Result := Rect(0, 0, 0, 0);
end;


Solve 3:

This is one way to get the height of the taskbar:

function GetTaskBarRect: TRect;
var
  TBData: TAppBarData;
begin
  TBData.cbSize := sizeof(TAppBarData);
  SHAppBarMessage(ABM_GETTASKBARPOS, TBData);
  Result := TBData.rc;
end;

Nincsenek megjegyzések:

Megjegyzés küldése