Improvements on handling DPI changed situations.

Xun Li lixunown@outlook.com
Sun Aug 25 14:55:09 GMT 2024


After commit 64f8b310 enables the setup to handle DPI changed situation (e.g. Change the zoom of current display or move the window to another display with different zoom level), here is the extra code to better handling it. It is required to make the window size not too big or too small after DPI changed.

From c8f8291b90fb538e10bc6b2fa2ddb801da5823fd Mon Sep 17 00:00:00 2001
From: Li Xun <lixunown@outlook.com>
Date: Sun, 25 Aug 2024 22:44:54 +0800
Subject: [PATCH] Handle WM_DPICHANGED

Since Per Moniter V2 DPI Awareness is declared in manifest,
we need to handle it to make the size of window being
correct.
---
 proppage.cc | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/proppage.cc b/proppage.cc
index d177f2d..76ec873 100644
--- a/proppage.cc
+++ b/proppage.cc
@@ -27,6 +27,11 @@
 #include "Exception.h"
 #include "LogFile.h"

+// Old version of Windows SDK doesn't define it.
+#ifndef WM_DPICHANGED
+#define WM_DPICHANGED 0x02E0
+#endif
+
 bool PropertyPage::DoOnceForSheet = true;

 /*
@@ -361,6 +366,21 @@ PropertyPage::DialogProc (UINT message, WPARAM wParam, LPARAM lParam)
                // similar delegation as with WM_MOUSEWHEEL
         return OnTimerMessage (message, wParam, lParam);

+      case WM_DPICHANGED:
+      {
+        // The following code is used to support the Per Monitor V2 DPI Awareness
+        // declared in manifest. Without this, the window will be too small
+        // or too big after DPI changed.
+        RECT* const prcNewWindow = (RECT*)lParam;
+        SetWindowPos(GetHWND (),
+          NULL,
+          prcNewWindow -> left,
+          prcNewWindow -> top,
+          prcNewWindow -> right - prcNewWindow -> left,
+          prcNewWindow -> bottom - prcNewWindow -> top,
+          SWP_NOZORDER | SWP_NOACTIVATE);
+        return TRUE;
+      }
       default:
         break;
     }
--
2.46.0.windows.1


More information about the Cygwin mailing list