Created
September 25, 2018 06:39
-
-
Save nitinjs/27505e1fba5ab85fb2fe94cb51886999 to your computer and use it in GitHub Desktop.
Allows to get device ppi in C#
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
class Program | |
{ | |
[DllImport("gdi32.dll")] | |
static extern int GetDeviceCaps(IntPtr hdc, int nIndex); | |
[DllImport("user32.dll")] | |
static extern IntPtr GetDC(IntPtr hWnd); | |
/// <summary> | |
/// Logical pixels inch in X | |
/// </summary> | |
const int LOGPIXELSX = 88; | |
/// <summary> | |
/// Logical pixels inch in Y | |
/// </summary> | |
const int LOGPIXELSY = 90; | |
static void Main(string[] args) | |
{ | |
IntPtr hdc = GetDC(IntPtr.Zero); | |
Console.WriteLine(GetDeviceCaps(hdc, LOGPIXELSX)); | |
// or | |
Console.WriteLine(GetDeviceCaps(hdc, LOGPIXELSY)); | |
//Console.ReadKey(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment