BOOL CALLBACK EnumerateCallback(HWND window, LPARAM lParam)
{
HICON hIcon;
+ HWND hwndOwner;
UNREFERENCED_PARAMETER(lParam);
if (!IsWindowVisible(window))
return TRUE;
- if (GetWindow(window, GW_OWNER) != NULL)
+ hwndOwner = GetWindow(window, GW_OWNER);
+ if (hwndOwner && IsWindowVisible(hwndOwner))
return TRUE;
GetClassNameW(window, windowText, _countof(windowText));
return TRUE;
}
-// Function mostly compatible with the normal EnumWindows,
+// Function mostly compatible with the normal EnumChildWindows,
// except it lists in Z-Order and it doesn't ensure consistency
// if a window is removed while enumerating
-void EnumWindowsZOrder(WNDENUMPROC callback, LPARAM lParam)
+void EnumChildWindowsZOrder(HWND hwnd, WNDENUMPROC callback, LPARAM lParam)
{
- HWND next = GetTopWindow(NULL);
+ HWND next = GetTopWindow(hwnd);
while (next != NULL)
{
- if(!callback(next, lParam))
- break;
+ if (!hwnd && !IsWindowVisible(next))
+ {
+ // UPDATE: Seek also the owned windows of the hidden top-level window.
+ EnumChildWindowsZOrder(next, callback, lParam);
+ }
+
+ if (!callback(next, lParam))
+ break;
+
next = GetWindow(next, GW_HWNDNEXT);
}
}
if (!isOpen)
{
windowCount=0;
- EnumWindowsZOrder(EnumerateCallback, 0);
+ EnumChildWindowsZOrder(NULL, EnumerateCallback, 0);
if (windowCount < 2)
return FALSE;
Esc = TRUE;
windowCount = 0;
- EnumWindowsZOrder(EnumerateCallback, 0);
+ EnumChildWindowsZOrder(NULL, EnumerateCallback, 0);
if (windowCount < 2)
return 0;