function FindTaskBar(var ARect: TRect): Integer;
var
AppData: TAppBarData;
begin
// 'Shell_TrayWnd' is the name of the task bar's window
AppData.Hwnd := FindWindow('Shell_TrayWnd', nil);
if AppData.Hwnd = 0 then
RaiseLastWin32Error;
AppData.cbSize := SizeOf(TAppBarData);
// SHAppBarMessage will return False (0) when an error
// happens.
if SHAppBarMessage(ABM_GETTASKBARPOS, AppData) = 0 then
raise Exception.Create('SHAppBarMessage returned false when trying ' +
'to find the Task Bar''s position');
// Otherwise, we had success, so fill in the results.
Result := AppData.uEdge;
ARect := AppData.rc;
end;