From 09033e25ed2d8545118a31da58c0e016d6d1d2d2 Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Sun, 28 Aug 2022 20:10:31 +1000 Subject: [PATCH] DPI Fixes for Windows 7 --- src/Eto.WinForms/Win32.dpi.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Eto.WinForms/Win32.dpi.cs b/src/Eto.WinForms/Win32.dpi.cs index 5cba0257d9..65568044da 100644 --- a/src/Eto.WinForms/Win32.dpi.cs +++ b/src/Eto.WinForms/Win32.dpi.cs @@ -118,9 +118,14 @@ public static Eto.Drawing.RectangleF GetLogicalBounds(this swf.Screen screen) return new Eto.Drawing.RectangleF(GetLogicalLocation(screen), GetLogicalSize(screen)); } - public static bool IsSystemDpiAware => Win32.GetProcessDpiAwareness(IntPtr.Zero, out var awareness) == 0 && awareness == Win32.PROCESS_DPI_AWARENESS.SYSTEM_DPI_AWARE; + public static bool IsSystemDpiAware => PerMonitorDpiSupported ? + (Win32.GetProcessDpiAwareness(IntPtr.Zero, out var awareness) == 0 && awareness == Win32.PROCESS_DPI_AWARENESS.SYSTEM_DPI_AWARE) : + Win32.IsProcessDPIAware(); - public static float SystemDpi => Win32.GetDpiForSystem() / 96f; + [DllImport("gdi32.dll")] + public static extern int GetDeviceCaps(IntPtr hdc, int nIndex); + + public static float SystemDpi => (PerMontiorThreadDpiSupported ? Win32.GetDpiForSystem() : (uint)Win32.GetDeviceCaps(IntPtr.Zero, 88 /*LOGPIXELSX*/)) / 96f; class ScreenHelper : LogicalScreenHelper { @@ -223,6 +228,10 @@ public static void GetMonitorInfo(this swf.Screen screen, ref MONITORINFOEX info [DllImport("shcore.dll")] public static extern uint GetProcessDpiAwareness(IntPtr handle, out PROCESS_DPI_AWARENESS awareness); + [DllImport("User32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool IsProcessDPIAware(); + [DllImport("User32.dll")] static extern DPI_AWARENESS_CONTEXT SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT dpiContext);