转载:https://www.cnblogs.com/findumars/p/5086797.html
bool CTestTray2Dlg::IsCoveredByOtherWindow(HWND hWnd) { RECT rcTarget; ::GetWindowRect(hWnd, &rcTarget); bool isChild = (WS_CHILD == (::GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)); if (::GetDesktopWindow() == hWnd) hWnd = ::GetWindow(::GetTopWindow(hWnd), GW_HWNDLAST); do{ HWND hCurWnd = hWnd; while(NULL != (hWnd = ::GetNextWindow(hWnd, GW_HWNDPREV))){ if (::IsWindowVisible(hWnd)){ RECT rcWnd; ::GetWindowRect(hWnd, &rcWnd); if(!((rcWnd.right < rcTarget.left) || (rcWnd.left > rcTarget.right) || (rcWnd.bottom < rcTarget.top) || (rcWnd.top > rcTarget.bottom))){ return true; } } } if(isChild){ hWnd = ::GetParent(hCurWnd); isChild = hWnd ? (WS_CHILD == (::GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)) : false; } else break; }while(true); return false; }
大意是自底向上层层遍历窗口,检查是否有窗口与指定窗口有重叠的地方。