win32:检测开始菜单是否自动隐藏?

发布于 2024-09-28 19:18:35 字数 220 浏览 1 评论 0 原文

我想在屏幕底部放置一个窗口。如果开始菜单存在,我希望它位于开始菜单的顶部。如果不是(或者它是自动隐藏的),我仍然希望它位于与开始菜单所在的位置相同的位置,这意味着会有几个像素的间隙。

目前,我获取显示器工作区域,将窗口定位在底部,并且始终偏移 20 像素左右。如果开始菜单不存在,此方法效果很好。然而,如果是这样,工作区域也会缩小(这是应该的),并且我最终会进行双偏移。

我该如何解决这个问题?

I want to position a window at the bottom of the screen. If the start menu is present, I want it to lie along the top of the start menu. If it is not (or it is auto-hidden), I still want it to be in the same position as it would be if the start menu was there, meaning there will be a gap of a few pixels.

Currently I get the monitor work area, position the window at the bottom, and always offset by 20 pixels or so. If the start menu isn't there, this works well. If it is, however, the work area also shrinks (as it should), and I end up double-offsetting.

How would I fix the issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久隐师 2024-10-05 19:18:35

要使屏幕的工作区域不被系统任务栏或应用程序桌面工具栏遮挡,可以使用 SystemParametersInfo(),其中 SPI_GETWORKAREA 作为 uiAction 参数。 pvParam 参数必须指向一个 RECT 结构,该结构接收工作区域的坐标(以虚拟屏幕坐标表示)。例如:

  RECT rectWorkArea;
  SystemParametersInfo(SPI_GETWORKAREA, 0, &rectWorkArea, 0);

正如您在评论中所说,要获取任务栏的边框,我们可以调用 SHAppBarMessage(ABM_GETTASKBARPOS, ...)

来确定任务栏的位置(当前是否位于屏幕的底部、顶部、左侧或右侧),您可以使用以下计算:

  type
    TTaskBarPos = (_TOP, _BOTTOM, _LEFT, _RIGHT);
  var
    iScrW, iScrH: Longint;

  iScrW := GetSystemMetrics(SM_CXSCREEN);
  iScrH := GetSystemMetrics(SM_CXSCREEN);

  if (rectTaskbar.Top > iScrH div 2) and (rectTaskbar.Right >= iScrW) then
    Result := _BOTTOM
  else if (rectTaskbar.Top < iScrH div 2) and (rectTaskbar.Bottom <= iScrW div 2) then
    Result := _TOP
  else if (rectTaskbar.Left < iScrW div 2) and (rectTaskbar.Top <= 0) then
    Result := _LEFT
  else
    Result := _RIGHT;

它们应该足以解决您当前的问题。但是,如果您需要(出于其他原因)了解自动隐藏和始终置顶状态的当前任务栏设置,则可以使用 SHAppBarMessage(ABM_GETSTATE, ...)

如果您需要收到任务栏的自动隐藏或始终位于顶部状态已更改的通知,则必须拦截 ABN_STATEANGE 消息。

To get the work area of the screen not obscured by the system taskbar or by application desktop toolbars, you can use SystemParametersInfo() with SPI_GETWORKAREA as uiAction parameter. The pvParam parameter must point to a RECT structure that receives the coordinates of the work area, expressed in virtual screen coordinates. For example:

  RECT rectWorkArea;
  SystemParametersInfo(SPI_GETWORKAREA, 0, &rectWorkArea, 0);

As you said in the comment, to get the bounding rectangle of the taskbar, we can call SHAppBarMessage(ABM_GETTASKBARPOS, ...)

To determine the position of the taskbar (whether it is currently at the bottom, top, left, or right of the screen), you could use the following calculation:

  type
    TTaskBarPos = (_TOP, _BOTTOM, _LEFT, _RIGHT);
  var
    iScrW, iScrH: Longint;

  iScrW := GetSystemMetrics(SM_CXSCREEN);
  iScrH := GetSystemMetrics(SM_CXSCREEN);

  if (rectTaskbar.Top > iScrH div 2) and (rectTaskbar.Right >= iScrW) then
    Result := _BOTTOM
  else if (rectTaskbar.Top < iScrH div 2) and (rectTaskbar.Bottom <= iScrW div 2) then
    Result := _TOP
  else if (rectTaskbar.Left < iScrW div 2) and (rectTaskbar.Top <= 0) then
    Result := _LEFT
  else
    Result := _RIGHT;

They should be enough to solve your current problem. However, if you need to know (for another reason) the current taskbar settings of the autohide and always-on-top states, you can use SHAppBarMessage(ABM_GETSTATE, ...).

If you need to be notified that that the taskbar's autohide or always-on-top state has changed, you have to intercept ABN_STATECHANGE message.

暮倦 2024-10-05 19:18:35

您的项目中是否正在使用或可以访问 .NET?

如果是这样,您可以使用 Screen.PrimaryScreen.WorkingArea.Height 属性来确定屏幕底部(不包括任务栏)。

您还可以通过获取 Screen.PrimaryScreen.Bounds.Height 属性(其中包括总高度值中的任务栏)来获取总屏幕高度。

比较这些值,如果它们相同,则任务栏不存在。否则,任务栏是,您可以进行相应的调整。

Are you are using or have access to .NET in your project?

If so, you can use the Screen.PrimaryScreen.WorkingArea.Height property to determine the bottom of the screen excluding the task bar.

You can also grab the total screen height by getting the Screen.PrimaryScreen.Bounds.Height property (which includes the task bar in the total height value).

Comparing these values, if they're the same, the task bar isn't present. Otherwise, the task bar is and you can adjust accordingly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文