Skip to content

Commit

Permalink
DPI Fixes for Windows 7
Browse files Browse the repository at this point in the history
  • Loading branch information
hamarb123 committed Aug 28, 2022
1 parent bb66855 commit 09033e2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Eto.WinForms/Win32.dpi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<swf.Screen>
{
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 09033e2

Please sign in to comment.