From 515e9b9f89ed2af8e541d19493929c0be2556066 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 12 Jun 2024 13:39:44 +0100 Subject: [PATCH] Windowing: Avoid recursively calling WM_NCHITTEST in contains() --- .../native/juce_Windowing_windows.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp index fd353b0d8a95..f3ba42d8b198 100644 --- a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp +++ b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp @@ -1782,8 +1782,22 @@ class HWNDComponentPeer final : public ComponentPeer if (! r.withZeroOrigin().contains (localPos)) return false; - auto w = WindowFromPoint (D2DUtilities::toPOINT (convertLogicalScreenPointToPhysical (localPos + getScreenPosition(), - hwnd))); + const auto screenPos = convertLogicalScreenPointToPhysical (localPos + getScreenPosition(), hwnd); + + if (trueIfInAChildWindow) + { + // Quick check to see whether the point is inside the client bounds + RECT rect; + GetClientRect (hwnd, &rect); + POINT points[2]; + memcpy (points, &rect, sizeof (points)); + MapWindowPoints (hwnd, nullptr, points, (UINT) std::size (points)); + memcpy (&rect, points, sizeof (points)); + + return PtInRect (&rect, D2DUtilities::toPOINT (screenPos)); + } + + auto w = WindowFromPoint (D2DUtilities::toPOINT (screenPos)); return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0)); }