如何检测自动隐藏的任务栏是否可见? [英] How to detect if autohidden taskbar is visible or not?

查看:452
本文介绍了如何检测自动隐藏的任务栏是否可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我需要检测在C + + / Qt如果任务栏,设置为自动隐藏是否可见在屏幕上。我已经尝试已经下面的解决方案,不幸的是没有成功:

At the moment I need to detect in C++/Qt if a taskbar, which is set to "autohide" is visible on the screen or not. I have tried already following solution, unfortunately with no success:


  1. 使用uState =(UINT)检查自动隐藏状态SHAppBarMessage(ABM_GETSTATE ,pabd),这只返回是否设置了自动隐藏属性。

  1. Checked the autohide state with uState = (UINT) SHAppBarMessage(ABM_GETSTATE, pabd), this only returns whether autohide property is set or not

使用SystemParametersInfo获取工作区(SPI_GETWORKAREA,0,&rectWorkArea,0);不幸的是,当任务栏设置为autohiden时,工作区域总是与整个屏幕大小相同,即使它实际上在屏幕上可见。

Getting work area with SystemParametersInfo(SPI_GETWORKAREA, 0, &rectWorkArea, 0); Unfortunately the work area is always of size of the entire screen, when taskbar is set to "autohiden", even if it is actually visible on the screen

带有SHAppBarMessage的应用数据库数据(ABM_GETTASKBARPOS,& abd);使用此函数,我可以获得任务栏的大小和坐标,但是它们总是返回,就好像任务栏是可见的,即使它被隐藏。

Geting AppBarData with SHAppBarMessage(ABM_GETTASKBARPOS, &abd); With this function I can get both size and coordinates of the taskbar, however they are always returned as if the taskbar is being visible, even if it is hidden.

所以用这些方法我不能告诉,是否在任务栏上打开自动隐藏在给定的时刻在屏幕上是否可见:-(

So with those methods I cannot tell, whether taskbar with "autohide" on is at given moment visible on the screen or not :-(

我会感谢任何帮助: - )

I would appreciate any help :-)

推荐答案

HWND hTaskbarWnd = FindWindow("Shell_TrayWnd", null);
bool isVisible = IsWindowVisible(hTaskbarWnd);

bool IsTaskbarWndVisible() {
HWND hTaskbarWnd = FindWindow("Shell_TrayWnd", null);
HMONITOR hMonitor = MonitorFromWindow(hTaskbarWnd , MONITOR_DEFAULTTONEAREST);
MONITORINFO info = { sizeof(MONITORINFO) };
if (GetMonitorInfo(hMonitor, &info))
{
  RECT rect;
  GetWindowRect(hTaskbarWnd , &rect);
  if ((rect.top >= info.rcMonitor.bottom - 4) ||
      (rect.right <= 2) ||
      (rect.bottom <= 4) ||
      (rect.left >= info.rcMonitor.right - 2))
  return false;

  return true;
}

这篇关于如何检测自动隐藏的任务栏是否可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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