From 06dd1081012155e77a0c014fa8ae14aec1ecc73d Mon Sep 17 00:00:00 2001 From: walterlv Date: Fri, 21 Aug 2026 10:18:13 +0800 Subject: [PATCH] Fix Per-Monitor DPI awareness issue, now support Per-Monitor (V2). See: https://blog.walterlv.com/post/windows-high-dpi-development-for-wpf.html --- QuickLook/App.config | 4 ++-- QuickLook/App.xaml.cs | 11 ---------- QuickLook/NativeMethods/SHCore.cs | 33 ---------------------------- QuickLook/Properties/AssemblyInfo.cs | 4 ---- QuickLook/app.manifest | 11 +++++----- 5 files changed, 8 insertions(+), 55 deletions(-) delete mode 100644 QuickLook/NativeMethods/SHCore.cs diff --git a/QuickLook/App.config b/QuickLook/App.config index ea4e4a2e6..becd609fe 100644 --- a/QuickLook/App.config +++ b/QuickLook/App.config @@ -4,8 +4,8 @@ - + - \ No newline at end of file + diff --git a/QuickLook/App.xaml.cs b/QuickLook/App.xaml.cs index 9184585ff..5aabc8268 100644 --- a/QuickLook/App.xaml.cs +++ b/QuickLook/App.xaml.cs @@ -20,7 +20,6 @@ using QuickLook.NativeMethods; using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; @@ -60,16 +59,6 @@ static App() RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; } - // Explicitly set to PerMonitor to avoid being overridden by the system - if (SHCore.SetProcessDpiAwareness(SHCore.PROCESS_DPI_AWARENESS.PROCESS_PER_MONITOR_DPI_AWARE) is uint result) - { - Debug.WriteLine( - result == 0 ? - "DPI Awareness applied successfully" : - $"DPI Awareness manual setup failed. Error Code: {result}" - ); - } - // Occurs when the resolution of an assembly fails AppDomain.CurrentDomain.AssemblyResolve += (_, e) => { diff --git a/QuickLook/NativeMethods/SHCore.cs b/QuickLook/NativeMethods/SHCore.cs deleted file mode 100644 index ec5bf304b..000000000 --- a/QuickLook/NativeMethods/SHCore.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright © 2017-2026 QL-Win Contributors -// -// This file is part of QuickLook program. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -using System.Runtime.InteropServices; - -namespace QuickLook.NativeMethods; - -internal static class SHCore -{ - public enum PROCESS_DPI_AWARENESS - { - PROCESS_DPI_UNAWARE, - PROCESS_SYSTEM_DPI_AWARE, - PROCESS_PER_MONITOR_DPI_AWARE - } - - [DllImport("shcore.dll")] - public static extern uint SetProcessDpiAwareness(PROCESS_DPI_AWARENESS awareness); -} diff --git a/QuickLook/Properties/AssemblyInfo.cs b/QuickLook/Properties/AssemblyInfo.cs index a079d812a..e35fc4ade 100644 --- a/QuickLook/Properties/AssemblyInfo.cs +++ b/QuickLook/Properties/AssemblyInfo.cs @@ -18,7 +18,6 @@ using System.Reflection; using System.Runtime.InteropServices; using System.Windows; -using System.Windows.Media; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information @@ -65,6 +64,3 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] - -// If .NET Version is higher than 4.6.2 (Not include 4.6.2), use the following line -// [assembly: DisableDpiAwareness] diff --git a/QuickLook/app.manifest b/QuickLook/app.manifest index acf296f7c..6b9f0b545 100644 --- a/QuickLook/app.manifest +++ b/QuickLook/app.manifest @@ -53,14 +53,15 @@ - - - + + PerMonitorV2 + true true - - \ No newline at end of file +