From f68993111cd7dfc81e2beb977bd513981067df33 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 17 Apr 2022 16:53:42 +0100 Subject: [PATCH] Change DPI awareness only for ChooseFont() duration Extract ChooseFont() in a small helper function to ensure that the DPI awareness is restored as soon as it returns. No real changes yet. --- src/msw/fontdlg.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/msw/fontdlg.cpp b/src/msw/fontdlg.cpp index c70b55ac50..253d65f4d2 100644 --- a/src/msw/fontdlg.cpp +++ b/src/msw/fontdlg.cpp @@ -88,6 +88,14 @@ wxString wxFontDialog::GetTitle() const return m_title; } +// Tiny wrapper calling ::ChooseFont() with system DPI awareness, as the +// standard dialog doesn't work correctly when using per-monitor awareness. +static BOOL wxMSWChooseFont(CHOOSEFONT* pCF) +{ + wxMSWImpl::AutoSystemDpiAware dpiAwareness; + return ::ChooseFont(pCF); +} + int wxFontDialog::ShowModal() { WX_HOOK_MODAL_DIALOG(); @@ -153,9 +161,7 @@ int wxFontDialog::ShowModal() chooseFontStruct.Flags = flags; - wxMSWImpl::AutoSystemDpiAware dpiAwareness; - - if ( ChooseFont(&chooseFontStruct) != 0 ) + if ( wxMSWChooseFont(&chooseFontStruct) != 0 ) { wxRGBToColour(m_fontData.m_fontColour, chooseFontStruct.rgbColors); m_fontData.m_chosenFont = wxFont(wxNativeFontInfo(logFont, this));