INF: Determining Visible Window Area When Windows Overlap

ID Number: Q75236

3.00

WINDOWS

Summary:

There is no Windows API that reports the portion of an application's

window that is not obscured by other windows. To determine which areas

of the window are covered, it is necessary to walk through the window

list managed by Windows.

Each window that precedes the application's window is "above" that

window on the screen. Using the IntersectRect() function, check the

rectangle of the window with any windows above to see if they

intersect. Any window that is above the application's window and

intersects its window rectangle obscures part of the application's

window. By accumulating the positions of all windows that overlap the

application's window, it is possible to determine which areas of the

window are covered and which are not.

The following sample code demonstrates this procedure:

GetWindowRect(hWnd, &rMyRect); /* Get the window dimensions

* for the current window.

*/

/* Start from the current window and use the GetWindow()

* function to move through the previous window handles.

*/

for (hPrevWnd = hWnd;

(hNextWnd = GetWindow(hPrevWnd, GW_HWNDPREV)) != NULL;

hPrevWnd = hNextWnd)

{

/* Get the window rectangle dimensions of the window that

* is higher Z-Order than the application's window.

*/

GetWindowRect(hNextWnd, &rOtherRect);

/* Check to see if this window is visible and if intersects

* with the rectangle of the application's window. If it does,

* call MessageBeep(). This intersection is an area of this

* application's window that is not visible.

*/

if (IsWindowVisible(hNextWnd) &&

IntersectRect(&rDestRect, &rMyRect, &rOtherRect))

{

MessageBeep(0);

}

}