public static bool IsObscuredWindow(IntPtr windowHandle)
{
if (windowHandle == null ||
windowHandle == IntPtr.Zero ||
!User32Interop.IsWindowVisible(windowHandle))
{
return false;
}
IntPtr hWnd = windowHandle;
// store windows we have already visited
var windowCache = new HashSet<IntPtr> { hWnd };
User32Interop.RECT windowRect;
User32Interop.GetWindowRect(hWnd, out windowRect);
// check if any of the windows intersects with our window
while ((hWnd = User32Interop.GetWindow(hWnd, User32Interop.GW_HWNDPREV)) != IntPtr.Zero &&
!windowCache.Contains(hWnd))
{
User32Interop.RECT rect;
User32Interop.RECT intersection;
windowCache.Add(hWnd);
if (User32Interop.IsWindowVisible(hWnd) &&
!IsMinimized(hWnd) &&
User32Interop.GetWindowRect(hWnd, out rect) &&
User32Interop.IntersectRect(out intersection, ref windowRect, ref rect))
{
return true;
}
}
return false;
}