-
-
Save arlm/d77023c2bbe507a0a3e387782e8a4ba3 to your computer and use it in GitHub Desktop.
Check an app's DPI awareness.
This file contains hidden or 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
public partial class App : Application | |
{ | |
protected override void OnStartup(StartupEventArgs e) | |
{ | |
base.OnStartup(e); | |
MessageBox.Show( | |
String.Format("IsProcessDPIAware: {0}", IsProcessDPIAware()) + Environment.NewLine + | |
String.Format("GetDpiAwareness: {0}", GetDpiAwareness())); | |
} | |
[DllImport("User32.dll", SetLastError = true)] | |
[return: MarshalAs(UnmanagedType.Bool)] | |
public static extern bool IsProcessDPIAware(); | |
[DllImport("Shcore.dll", SetLastError = true)] | |
public static extern int GetProcessDpiAwareness( | |
IntPtr hprocess, | |
out PROCESS_DPI_AWARENESS value); | |
public enum PROCESS_DPI_AWARENESS | |
{ | |
/// <summary> | |
/// Not DPI aware | |
/// </summary> | |
Process_DPI_Unaware = 0, | |
/// <summary> | |
/// System DPI aware | |
/// </summary> | |
Process_System_DPI_Aware = 1, | |
/// <summary> | |
/// Per-Monitor DPI aware | |
/// </summary> | |
Process_Per_Monitor_DPI_Aware = 2 | |
} | |
public static PROCESS_DPI_AWARENESS? GetDpiAwareness() | |
{ | |
PROCESS_DPI_AWARENESS value; | |
var result = GetProcessDpiAwareness( | |
IntPtr.Zero, // Current process | |
out value); | |
if (result != 0) // 0 means S_OK. | |
return null; | |
return value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment