From 6fb86323f5223eca5085a609df0beda00954cc81 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Tue, 1 Oct 2019 23:41:14 +0200 Subject: [PATCH] Use associated window in wxMSWDCImpl::GetPPI() --- src/msw/dc.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 72e89c9acd..999d724996 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -2452,10 +2452,24 @@ void wxMSWDCImpl::DoGetSizeMM(int *w, int *h) const wxSize wxMSWDCImpl::GetPPI() const { - int x = ::GetDeviceCaps(GetHdc(), LOGPIXELSX); - int y = ::GetDeviceCaps(GetHdc(), LOGPIXELSY); + // As documented by MSDN, GetDeviceCaps() returns the same value for all + // HDCs on the system, and so can't be used to retrieve the correct value + // for the HDCs associated with the windows on monitors other than the + // primary one if they use different DPI. Hence prefer to get this + // information from the associated window, if possible. + wxSize ppi; + if ( m_window ) + { + ppi = m_window->GetDPI(); + } - return wxSize(x, y); + if ( !ppi.x || !ppi.y ) + { + ppi.x = ::GetDeviceCaps(GetHdc(), LOGPIXELSX); + ppi.y = ::GetDeviceCaps(GetHdc(), LOGPIXELSY); + } + + return ppi; } double wxMSWDCImpl::GetContentScaleFactor() const