From ed35a143ec5ded2875698aa23f505dd93162a0c8 Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Wed, 5 Feb 2020 12:27:51 +0100 Subject: [PATCH] FancyZones: allow windows with invisible or zero-sized owner to be zonable (#1216) --- src/modules/fancyzones/lib/FancyZones.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/modules/fancyzones/lib/FancyZones.cpp b/src/modules/fancyzones/lib/FancyZones.cpp index 9227980f68..57808c57aa 100644 --- a/src/modules/fancyzones/lib/FancyZones.cpp +++ b/src/modules/fancyzones/lib/FancyZones.cpp @@ -593,13 +593,33 @@ LRESULT CALLBACK FancyZones::s_WndProc(HWND window, UINT message, WPARAM wparam, DefWindowProc(window, message, wparam, lparam); } +static bool HasVisibleOwner(HWND window) noexcept +{ + auto owner = GetWindow(window, GW_OWNER); + if (owner == nullptr) + { + return false; // There is no owner at all + } + if (!IsWindowVisible(owner)) + { + return false; // Owner is invisible + } + RECT rect; + if (!GetWindowRect(owner, &rect)) + { + return true; // Could not get the rect, return true (and filter out the window) just in case + } + // Return false (and allow the window to be zonable) if the owner window size is zero + return rect.top != rect.bottom || rect.left != rect.right; +} + bool FancyZones::IsInterestingWindow(HWND window) noexcept { auto style = GetWindowLongPtr(window, GWL_STYLE); auto exStyle = GetWindowLongPtr(window, GWL_EXSTYLE); // Ignore: if (GetAncestor(window, GA_ROOT) != window || // windows that are not top-level - GetWindow(window, GW_OWNER) != nullptr || // windows that have an owner - like Save As dialogs + HasVisibleOwner(window) || // windows that have an visible owner - like Save As dialogs (style & WS_CHILD) != 0 || // windows that are child elements of other windows - like buttons (style & WS_DISABLED) != 0 || // windows that are disabled (exStyle & WS_EX_TOOLWINDOW) != 0 || // toolbar windows