获取任务栏位置? [英] Get Taskbar Position?

查看:126
本文介绍了获取任务栏位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  Application.ShowMainForm:= False; 

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



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



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



简单来说,我希望我的应用程序出现在上面(或下一个)系统时钟的任务栏的角落。 / p>

提前感谢

解决方案

使用 SHAppBarMessage 获取任务栏的位置:

  SHAppBarMes圣人(ABM_GETTASKBARPOS,appBarData); 

与主监视器的大小一起:

  nScreenWidth:= GetSystemMetrics(SM_CXSCREEN); 
nScreenHeight:= GetSystemMetrics(SM_CYSCREEN);

如果任务栏位于




  • 顶部

  • left

  • bottom

  • right



的屏幕及其大小。

  {从其窗口rect计算任务栏位置。但是,在$ $ $ $ $ 
可能是任务栏稍大于或小于
屏幕大小。所以我们在这里允许一些宽容。
}
如果NearlyEqual(rcTaskbar.Left,0,TASKBAR_X_TOLERANCE)和
NearlyEqual(rcTaskbar.Right,nScreenWidth,TASKBAR_X_TOLERANCE)然后
begin
//任务栏处于顶部或底部
如果NearlyEqual(rcTaskbar.Top,0,TASKBAR_Y_TOLERANCE)然后
FTaskbarPlacement:= ABE_TOP
else
FTaskbarPlacement:= ABE_BOTTOM;
end
else
begin
//任务栏在左边或右边
如果NearlyEqual(rcTaskbar.Left,0,TASKBAR_X_TOLERANCE)然后
FTaskbarPlacement: = ABE_LEFT
else
FTaskbarPlacement:= ABE_RIGHT;
结束

您可以弹出您的烤面包:



$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
Self.Top:= rcTaskbar.Bottom - Self.Height;
结束
ABE_LEFT:
开始
Self.Left:= rcTaskbar.Right;
Self.Top:= rcTaskbar.Bottom - Self.Height;
结束
ABE_TOP:
begin
Self.Left:= rcTaskbar.Right - Self.Height;
Self.Top:= rcTaskbar.Bottom;
结束
else // ABE_BOTTOM
//任务栏在底部或隐形
Self.Left:= rcTaskbar.Right - Self.Width;
Self.Top:= rcTaskbar.Top - Self.Height;
结束


I have my main Application hidden using:

Application.ShowMainForm:= False;

The Application uses a TTrayIcon which I have assigned a Popup menu to.

By using and selecting one of the Popup menus in the Tray Icon I want to make my Application visible again, but I want the position of the Application to popup above the Taskbar.

By default the Windows Taskbar is at the bottom, so in this case my Application would appear in the bottom right just above the clock - of course the Taskbar can be moved and sized by the user so I need a way of knowing definitively these metrics.

Simply put, I want my Application to appear in the corner of the Taskbar above (or next) to the System clock.

Thanks in advance.

解决方案

Use SHAppBarMessage to get the location of the taskbar:

SHAppBarMessage(ABM_GETTASKBARPOS, appBarData);

That, along with the size of the "primary" monitor:

nScreenWidth := GetSystemMetrics(SM_CXSCREEN);
nScreenHeight := GetSystemMetrics(SM_CYSCREEN);

and you can work out if the Taskbar is located at the

  • top
  • left
  • bottom
  • right

of the screen, and its size.

{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;

With that you can pop up your toast:

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;

这篇关于获取任务栏位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆