Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
439 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...