From daae7d4ac20986d9ebda4753769541bd645796bb Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Sun, 29 Mar 2020 21:05:41 +0800 Subject: [PATCH] Update. Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- winnativeeventfilter.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/winnativeeventfilter.cpp b/winnativeeventfilter.cpp index 3ec31b4..a71fd10 100644 --- a/winnativeeventfilter.cpp +++ b/winnativeeventfilter.cpp @@ -433,6 +433,14 @@ UINT WinNativeEventFilter::getDpiForWindow(HWND handle) const { } // TODO: Is there an elegant way to acquire the system DPI in // Win7/8/10(before 1607)? + const HDC hdc = GetDC(nullptr); + if (hdc) { + const int dpiX = GetDeviceCaps(hdc, LOGPIXELSX); + const int dpiY = GetDeviceCaps(hdc, LOGPIXELSY); + ReleaseDC(nullptr, hdc); + // Not necessary, just silence a compiler warning. + return dpiX == dpiY ? dpiX : dpiY; + } return m_defaultDPI; }