gpt4 book ai didi

delphi - 获取任务栏位置?

转载 作者:行者123 更新时间:2023-12-02 13:35:34 24 4
gpt4 key购买 nike

我使用以下方式隐藏了我的主应用程序:

Application.ShowMainForm:= False;

应用程序使用 TTrayIcon,我已为其分配了弹出菜单。

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

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

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

提前致谢。

最佳答案

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

SHAppBarMessage(ABM_GETTASKBARPOS, appBarData);

以及“主”显示器的尺寸:

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

您可以确定任务栏是否位于

  • 顶部
  • 底部

屏幕的尺寸及其大小。

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

这样你就可以弹出你的 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;

enter image description here

关于delphi - 获取任务栏位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6565048/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com