-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
96 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Windows.Media; | ||
|
||
namespace Wpf.Ui.Violeta.Win32; | ||
|
||
public static class DpiAware | ||
{ | ||
/// <summary> | ||
/// <see cref="DisableDpiAwarenessAttribute"/> | ||
/// </summary> | ||
public static bool SetProcessDpiAwareness() | ||
{ | ||
if (NTdll.RtlGetVersion(out NTdll.OSVERSIONINFOEX osv) == NTdll.NTStatus.STATUS_SUCCESS) | ||
{ | ||
Version osVersion = new(osv.MajorVersion, osv.MinorVersion, osv.BuildNumber, osv.PlatformId); | ||
|
||
if (Environment.OSVersion.Platform == PlatformID.Win32NT && osVersion >= new Version(6, 3)) | ||
{ | ||
if (SHCore.SetProcessDpiAwareness(SHCore.PROCESS_DPI_AWARENESS.PROCESS_PER_MONITOR_DPI_AWARE) == 0) | ||
{ | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Wpf.Ui.Violeta.Win32; | ||
|
||
internal static class SHCore | ||
{ | ||
[DllImport("shcore.dll")] | ||
public static extern uint SetProcessDpiAwareness(PROCESS_DPI_AWARENESS awareness); | ||
|
||
[DllImport("shcore.dll")] | ||
public static extern int GetDpiForMonitor(nint hmonitor, MONITOR_DPI_TYPE dpiType, out uint dpiX, out uint dpiY); | ||
|
||
public enum PROCESS_DPI_AWARENESS | ||
{ | ||
PROCESS_DPI_UNAWARE, | ||
PROCESS_SYSTEM_DPI_AWARE, | ||
PROCESS_PER_MONITOR_DPI_AWARE, | ||
} | ||
|
||
public enum MONITOR_DPI_TYPE | ||
{ | ||
MDT_EFFECTIVE_DPI = 0, | ||
MDT_ANGULAR_DPI, | ||
MDT_RAW_DPI, | ||
MDT_DEFAULT = MDT_EFFECTIVE_DPI, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters