获取任务栏位置?

1 delphi taskbar system-tray

我隐藏了我的主要应用程序:

Application.ShowMainForm:= False;
Run Code Online (Sandbox Code Playgroud)

应用程序使用TTrayIcon,我已经为其分配了一个弹出菜单.

通过使用并选择托盘图标中的一个弹出菜单,我想让我的应用程序再次可见,但我希望应用程序的位置在任务栏上方弹出.

默认情况下,Windows任务栏位于底部,因此在这种情况下,我的应用程序将出现在时钟正上方的右下方 - 当然,任务栏可以由用户移动和调整大小,因此我需要一种明确了解这些指标的方法.

简单地说,我希望我的应用程序出现在系统时钟上方(或下一个)任务栏的角落.

提前致谢.

Ian*_*oyd 8

使用SHAppBarMessage得到任务栏的位置:

SHAppBarMessage(ABM_GETTASKBARPOS, appBarData);
Run Code Online (Sandbox Code Playgroud)

那,以及"主要"监视器的大小:

nScreenWidth := GetSystemMetrics(SM_CXSCREEN);
nScreenHeight := GetSystemMetrics(SM_CYSCREEN);
Run Code Online (Sandbox Code Playgroud)

如果任务栏位于,则可以解决问题

  • 最佳
  • 剩下
  • 底部

屏幕及其大小.

{Calculate taskbar position from its window rect. However,
 on XP it may be that the taskbar is slightly larger or smaller than the
 screen size. Therefore we allow some tolerance here.
}
if NearlyEqual(rcTaskbar.Left, 0, TASKBAR_X_TOLERANCE) and
        NearlyEqual(rcTaskbar.Right, nScreenWidth, TASKBAR_X_TOLERANCE) then
begin
    // Taskbar is on top or on bottom
    if NearlyEqual(rcTaskbar.Top, 0, TASKBAR_Y_TOLERANCE) then
        FTaskbarPlacement := ABE_TOP
    else
        FTaskbarPlacement := ABE_BOTTOM;
end
else
begin
    // Taskbar is on left or on right
    if NearlyEqual(rcTaskbar.Left, 0, TASKBAR_X_TOLERANCE) then
        FTaskbarPlacement := ABE_LEFT
    else
        FTaskbarPlacement := ABE_RIGHT;
end;
Run Code Online (Sandbox Code Playgroud)

有了它,你可以弹出你的祝酒词:

case FTaskbarPlacement of
ABE_RIGHT:
   begin
      Self.Left := rcTaskbar.Left-Self.Width;
      Self.Top := rcTaskbar.Bottom - Self.Height;
   end;
ABE_LEFT:
   begin
      Self.Left := rcTaskbar.Right;
      Self.Top := rcTaskbar.Bottom - Self.Height;
   end;
 ABE_TOP:
    begin
       Self.Left := rcTaskbar.Right - Self.Height;
       Self.Top := rcTaskbar.Bottom;
    end;
 else //ABE_BOTTOM
    // Taskbar is on the bottom or Invisible
    Self.Left := rcTaskbar.Right - Self.Width;
    Self.Top := rcTaskbar.Top - Self.Height;
 end;
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Dav*_*nan 5

在Windows 7上,您可以拨打电话Shell_NotifyIconGetRect().

在Windows的早期版本中,您所能做的就是使用相当奇怪的黑客攻击.