+ DWORD ExStyle, OwnerExStyle;
+
+ for (;;)
+ {
+ // A window with WS_EX_APPWINDOW is treated as if it has no owner
+ ExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
+ if (ExStyle & WS_EX_APPWINDOW)
+ break;
+
+ // Is the owner visible?
+ // An window with WS_EX_TOOLWINDOW is treated as if it weren't visible
+ hwndOwner = GetWindow(hwnd, GW_OWNER);
+ OwnerExStyle = GetWindowLong(hwndOwner, GWL_EXSTYLE);
+ if (!IsWindowVisible(hwndOwner) || (OwnerExStyle & WS_EX_TOOLWINDOW))
+ break;
+
+ hwnd = hwndOwner;
+ }
+
+ return hwnd;
+}
+
+// c.f. http://blogs.msdn.com/b/oldnewthing/archive/2007/10/08/5351207.aspx
+BOOL IsAltTabWindow(HWND hwnd)
+{