From f21227d78e755f3a9e3efc627b8b7e4bbc01fa23 Mon Sep 17 00:00:00 2001 From: Lamparter <71598437+Lamparter@users.noreply.github.com> Date: Sun, 11 May 2025 12:02:58 +0100 Subject: [PATCH 1/2] Clean up code for `GetDpiForWindow` --- src/Files.App.CsWin32/NativeMethods.txt | 1 - src/Files.App/Data/Models/AppModel.cs | 7 ++++--- src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs | 5 ----- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Files.App.CsWin32/NativeMethods.txt b/src/Files.App.CsWin32/NativeMethods.txt index aee2e82f99b3..ba743b7c4fe8 100644 --- a/src/Files.App.CsWin32/NativeMethods.txt +++ b/src/Files.App.CsWin32/NativeMethods.txt @@ -97,7 +97,6 @@ SendMessage IsWindowVisible COPYDATASTRUCT WINDOW_LONG_PTR_INDEX -GetDpiForWindow CallWindowProc MINMAXINFO SUBCLASSPROC diff --git a/src/Files.App/Data/Models/AppModel.cs b/src/Files.App/Data/Models/AppModel.cs index 63577cfd65c6..e11187bb44a6 100644 --- a/src/Files.App/Data/Models/AppModel.cs +++ b/src/Files.App/Data/Models/AppModel.cs @@ -4,6 +4,8 @@ using Microsoft.UI.Xaml.Controls; using System.Runtime.InteropServices; using Windows.ApplicationModel.DataTransfer; +using Windows.Win32; +using Windows.Win32.Foundation; namespace Files.App.Data.Models { @@ -127,10 +129,9 @@ public string PCloudDrivePath /// /// Gets or sets a value indicating the AppWindow DPI. - /// TODO update value if the DPI changes /// - private float _AppWindowDPI = Win32PInvoke.GetDpiForWindow(MainWindow.Instance.WindowHandle) / 96f; - public float AppWindowDPI + private float _AppWindowDPI = PInvoke.GetDpiForWindow((HWND)MainWindow.Instance.WindowHandle) / 96f; + public float AppWindowDPI // TODO: Update value if the DPI changes { get => _AppWindowDPI; set => SetProperty(ref _AppWindowDPI, value); diff --git a/src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs b/src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs index 9af7345111ec..3c85c9ab7445 100644 --- a/src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs +++ b/src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs @@ -76,11 +76,6 @@ public static extern bool SetEvent( IntPtr hEvent ); - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - public static extern int GetDpiForWindow( - IntPtr hwnd - ); - [DllImport("ole32.dll")] public static extern uint CoWaitForMultipleObjects( uint dwFlags, From 6929f23e97a2539ba9010a2fb05201b1d256c78e Mon Sep 17 00:00:00 2001 From: Lamparter <71598437+Lamparter@users.noreply.github.com> Date: Sun, 11 May 2025 18:17:14 +0100 Subject: [PATCH 2/2] Remove TODO comment --- src/Files.App/Data/Models/AppModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/Data/Models/AppModel.cs b/src/Files.App/Data/Models/AppModel.cs index e11187bb44a6..8b7e213ab34a 100644 --- a/src/Files.App/Data/Models/AppModel.cs +++ b/src/Files.App/Data/Models/AppModel.cs @@ -131,7 +131,7 @@ public string PCloudDrivePath /// Gets or sets a value indicating the AppWindow DPI. /// private float _AppWindowDPI = PInvoke.GetDpiForWindow((HWND)MainWindow.Instance.WindowHandle) / 96f; - public float AppWindowDPI // TODO: Update value if the DPI changes + public float AppWindowDPI { get => _AppWindowDPI; set => SetProperty(ref _AppWindowDPI, value);