Created
March 8, 2015 01:06
-
-
Save emoacht/468a351c9682c7033eba to your computer and use it in GitHub Desktop.
Check an app's DPI awareness.
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
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