type
TTaskBarPos = (_TOP, _BOTTOM, _LEFT, _RIGHT, _NONE);
function GetTaskBarPos(
Handle: THandle): TTaskBarPos;
var
hTaskbar: HWND;
T: TRect;
scrW, scrH: Integer;
CurrentScreen: TMonitor;
begin
Result := _BOTTOM;
hTaskbar := FindWindow('
Shell_TrayWnd',
nil);
if hTaskbar <> 0
then
begin
CurrentScreen := Screen.MonitorFromWindow(
Handle);
GetWindowRect(hTaskbar, T);
scrW := CurrentScreen.Width;
scrH := CurrentScreen.Height;
if (T.Top > scrH
div 2)
and (T.Right >= scrW)
then
Result := _BOTTOM
else if (T.Top < scrH
div 2)
and (T.Bottom <= scrW
div 2)
then
Result := _TOP
else if (T.Left < scrW
div 2)
and (T.Top <= 0)
then
Result := _LEFT
else
if T.Left >= scrW
div 2
then
Result := _RIGHT;
end;
end;
function GetTaskBarDimension(
Handle: THandle): Integer;
var
SysTray:
Winapi.Windows.HWND;
Rect: TRect;
begin
Result := -1;
SysTray := FindWindow('
Shell_TrayWnd',
nil);
if SysTray <> INVALID_HANDLE_VALUE
then
begin
if GetWindowRect(SysTray, Rect)
then
begin
case GetTaskBarPos(
Handle)
of
_LEFT, _RIGHT:
if GetWindowRect(SysTray, Rect)
then
Result := Rect.Right - Rect.Left;
_TOP:
if GetWindowRect(SysTray, Rect)
then
Result := Rect.Bottom;
_BOTTOM:
if GetWindowRect(SysTray, Rect)
then
begin
Result := Screen.MonitorFromWindow(
Handle).Height - Rect.Top;
end;
end;
end;
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
var
Form: TForm;
TaskbarPos: TTaskBarPos;
CurrentScreen: TMonitor;
TaskBarHeight: Integer;
begin
Form := TForm.Create(Self);
Form.BorderStyle := bsNone;
Form.Caption := '
';
Form.Width := 345;
Form.Height := 145;
CurrentScreen := Screen.MonitorFromWindow(
Handle);
TaskbarPos := GetTaskBarPos(Form.Handle);
TaskBarHeight := GetTaskBarDimension(Form.Handle);
case TaskbarPos
of
_TOP:
begin
Form.Top := TaskBarHeight;
Form.Left := CurrentScreen.Width - Form.Width;
end;
_BOTTOM:
begin
Form.Top := CurrentScreen.Height - TaskBarHeight - Form.Height;
Form.Left := CurrentScreen.Width - Form.Width;
end;
_LEFT:
begin
Form.Top := CurrentScreen.Height - Form.Height;
Form.Left := TaskBarHeight;
end;
_RIGHT:
begin
Form.Top := CurrentScreen.Height - Form.Height;
Form.Left := CurrentScreen.Width - Form.Width - TaskBarHeight;
end;
end;
Form.Show;
end;