From 1c33294cf5f74f005c52de86f3af3b8cbce16a73 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 19 Mar 2022 22:46:58 +0100 Subject: [PATCH] Add debugging check for using possibly incorrect DPI in wxMSW When calling GetDPI() for a window which is not created itself yet and doesn't have any valid top level parent neither, we have no choice but to fall back on using the screen DPI, but this doesn't always work correctly for the systems using multiple monitors with different DPIs, so warn when this happens -- any situations when it does indicate a potential bug that should be fixed. See #22193. --- src/msw/window.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/msw/window.cpp b/src/msw/window.cpp index fcd3279269..afc5cb8518 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -4872,6 +4872,17 @@ wxSize wxWindowMSW::GetDPI() const { hwnd = GetHwndOf(topWin); } + + if ( hwnd == NULL ) + { + // We shouldn't be using this function without a valid HWND because + // we can't really find the correct DPI to use in this case for a + // system with multiple monitors using different DPIs, so warn + // about doing it but still return the screen DPI which will often, + // if not always, be the correct value to use anyhow. + wxLogDebug("Using possibly wrong DPI for %s", wxDumpWindow(this)); + return wxGetDPIofHDC(ScreenHDC()); + } } wxSize dpi = GetWindowDPI(hwnd);