Originally is to determine whether the current window is in the front, helpless means exhausted is not, so want to change the idea: To determine whether the specified window is obscured by other windows. Then dig the net three feet, found this:
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;
}
The main idea is to traverse the window from the bottom up layer to check if there are any overlapping windows with the specified window.
Try it, it's OK. Reluctantly solved a problem, thank netizens: Pear (Crabshai)
And his good stickers: http://topic.csdn.net/u/20081007/23/4c84494d-6caa-4eb2-a2c4-2f73c67e8a63.html
http://blog.csdn.net/yuvmen/article/details/4546427
VC to determine whether the specified window is obscured by other windows