From 37f806f1d6e6806ba76679f0d7fc3daafec687e9 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 21 Jul 2019 23:55:02 +0200 Subject: [PATCH] Release the HDC in wxGetSystemMetrics and wxSystemParametersInfo Use WindowHDC instead of calling ::GetDC() manually and never calling ::ReleaseDC() on it. Closes https://github.com/wxWidgets/wxWidgets/pull/1437 --- src/msw/window.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/msw/window.cpp b/src/msw/window.cpp index b396437249..90ab60fae0 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -4750,8 +4750,9 @@ int wxGetSystemMetrics(int nIndex, const wxWindow* win) if ( s_pfnGetSystemMetricsForDpi ) { - const int y = ::GetDeviceCaps(::GetDC(tlw->GetHWND()), LOGPIXELSY); - return s_pfnGetSystemMetricsForDpi(nIndex, (UINT)y); + WindowHDC hdc(tlw->GetHWND()); + const int dpi = ::GetDeviceCaps(hdc, LOGPIXELSY); + return s_pfnGetSystemMetricsForDpi(nIndex, (UINT)dpi); } } #else @@ -4782,8 +4783,9 @@ bool wxSystemParametersInfo(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWi if ( s_pfnSystemParametersInfoForDpi ) { - const int y = ::GetDeviceCaps(::GetDC(tlw->GetHWND()), LOGPIXELSY); - if ( s_pfnSystemParametersInfoForDpi(uiAction, uiParam, pvParam, fWinIni, y) == TRUE ) + WindowHDC hdc(tlw->GetHWND()); + const int dpi = ::GetDeviceCaps(hdc, LOGPIXELSY); + if ( s_pfnSystemParametersInfoForDpi(uiAction, uiParam, pvParam, fWinIni, (UINT)dpi) == TRUE ) { return true; }