怎样判断已知窗口有否被其他窗口遮住?
不在最顶端的窗口不一定会被遮住

解决方案 »

  1.   

    可以考虑通过 WindowFromPoint、ChildWindowFromPoint 来取窗口进行判断
    或者通过枚举窗口并取窗口位置来进行计算
      

  2.   

    调用以下函数,返回 0 为完全不可见,1 为完全可见,-1 为部分可见。
    int IsWindowVisibleEx(HWND hwnd)
    {
    int nResult = 0;
    if(::IsWindow(hwnd))
    {
    HDC hdc = GetDC(hwnd);
    RECT rcClip, rcClient;
    GetClientRect(hwnd,  &rcClient);
    nResult = GetClipBox(hdc, &rcClip);
    ReleaseDC(hwnd, hdc));if(nResult == NULLREGION) // Totally obscured
    nResult = 0;
    else if(nResult == SIMPLEREGION && EqualRect(&rcClip, &rcClient)) // Completely visible
    nResult = 1;
    else // Partially visible
    nResult = -1;
    }
    }
    return nResult;
    }
      

  3.   

    CWnd::IsWindowVisible
    BOOL IsWindowVisible( ) const;Return ValueNonzero if CWnd is visible (has the WS_VISIBLE style bit set, and parent window is visible). Because the return value reflects the state of the WS_VISIBLE style bit, the return value may be nonzero even though CWnd is totally obscured by other windows.如果CWnd可见(被设值了WS_VISIBLE风格位,其父窗口可见),则返回非零值。因为返回值反映了WS_VISIBLE风格位的状态,因此即使CWnd被其它窗口完全遮住,返回值也可以是非零值 ResDetermines the visibility state of the given window. 这个函数确定给定窗口的视觉状态。 A window possesses a visibility state indicated by the WS_VISIBLE style bit. When this style bit is set with a call to the ShowWindow member function, the window is displayed and subsequent drawing to the window is displayed as long as the window has the style bit set.窗口具有在WS_VISIBLE风格位中指定的可视状态。当用ShowWindow成员函数设置了这个风格位时,将显示窗口,后来在窗口中的绘图也一直显示。 Any drawing to a window that has the WS_VISIBLE style will not be displayed if the window is covered by other windows or is clipped by its parent window.当窗口被其它窗口覆盖或被父窗口裁剪时,在具有WS_VISIBLE风格位的窗口内的绘图将不会显示。