How to detect if autohidden taskbar is visible or not?

让人想犯罪 __ 提交于 2019-11-28 02:19:21

问题


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. Checked the autohide state with uState = (UINT) SHAppBarMessage(ABM_GETSTATE, pabd), this only returns whether autohide property is set or not

  2. 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

  3. 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 :-)


回答1:


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

or

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


来源:https://stackoverflow.com/questions/10085381/how-to-detect-if-autohidden-taskbar-is-visible-or-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!