From c0c6a4b826eb6e8639feafca5eb412fbd8a419ce Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 22 Jul 2018 14:20:38 +0200 Subject: [PATCH] Add DPI Aware replacement of SystemParametersInfo Use SystemParametersInfoForDpi when this function is available and the DPI is known. Otherwise keep using SystemParametersInfo. --- include/wx/msw/private.h | 4 ++++ src/msw/window.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/wx/msw/private.h b/include/wx/msw/private.h index 575c598558..a1bdd9d5f4 100644 --- a/include/wx/msw/private.h +++ b/include/wx/msw/private.h @@ -302,6 +302,10 @@ HCURSOR wxBitmapToHCURSOR(const wxBitmap& bmp, int hotSpotX, int hotSpotY); extern int wxGetSystemMetrics(int nIndex, const wxWindow* win); +extern bool wxSystemParametersInfo(UINT uiAction, UINT uiParam, + PVOID pvParam, UINT fWinIni, + const wxWindow* win); + #if wxUSE_OWNER_DRAWN // Draw the bitmap in specified state (this is used by owner drawn controls) diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 021e161b70..b396437249 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -4761,6 +4761,41 @@ int wxGetSystemMetrics(int nIndex, const wxWindow* win) return ::GetSystemMetrics(nIndex); } +/*extern*/ +bool wxSystemParametersInfo(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni, const wxWindow* win) +{ +#if wxUSE_DYNLIB_CLASS + const wxTopLevelWindow* tlw = wxGetWinTLW(win); + + if ( tlw ) + { + typedef int (WINAPI * SystemParametersInfoForDpi_t)(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni, UINT dpi); + static SystemParametersInfoForDpi_t s_pfnSystemParametersInfoForDpi = NULL; + static bool s_initDone = false; + + if ( !s_initDone ) + { + wxLoadedDLL dllUser32("user32.dll"); + wxDL_INIT_FUNC(s_pfn, SystemParametersInfoForDpi, dllUser32); + s_initDone = true; + } + + if ( s_pfnSystemParametersInfoForDpi ) + { + const int y = ::GetDeviceCaps(::GetDC(tlw->GetHWND()), LOGPIXELSY); + if ( s_pfnSystemParametersInfoForDpi(uiAction, uiParam, pvParam, fWinIni, y) == TRUE ) + { + return true; + } + } + } +#else + wxUnusedVar(win); +#endif // wxUSE_DYNLIB_CLASS + + return ::SystemParametersInfo(uiAction, uiParam, pvParam, fWinIni) == TRUE; +} + // --------------------------------------------------------------------------- // colours and palettes // ---------------------------------------------------------------------------