C # API Get system DPI zoom multiple and resolution size

Source: Internet
Author: User

Source: C # API gets system DPI zoom multiple and resolution size

Using System;  Using System.Drawing;    Using System.Runtime.InteropServices; Namespace Xydes {public class PrimaryScreen {#region Win32 API [DllImport ("user32.d                  ll ")] static extern IntPtr GetDC (IntPtr ptr);                  [DllImport ("Gdi32.dll")] static extern int GetDeviceCaps (INTPTR hdc,//Handle to DC                  int NIndex//index of capability); [DllImport ("user32.dll", EntryPoint = "ReleaseDC")] static extern IntPtr ReleaseDC (IntPtr hWnd, IntPtr H          DC);                  #endregion #region DeviceCaps constant const int horzres = 8;                  const int vertres = 10;                  const int LOGPIXELSX = 88;                  const int logpixelsy = 90;                  const int desktopvertres = 117;          const int desktophorzres = 118; #endregion #region Properties//<summary>///Get screen resolution current physical size///</summary> public static size Workingarea {                      get {IntPtr hdc = GetDC (IntPtr.Zero);                      Size size = new size (); Size.                      Width = GetDeviceCaps (hdc, horzres); Size.                      Height = GetDeviceCaps (hdc, vertres);                      ReleaseDC (IntPtr.Zero, HDC);                      return size;              }}///<summary>///current system dpi_x size is usually///</summary> public static int Dpix {get {IntPtr hdc = GetDC (in                      Tptr.zero);                      int Dpix = GetDeviceCaps (hdc, LOGPIXELSX);                      ReleaseDC (IntPtr.Zero, HDC);                  return Dpix; }}///<summary>//Current system dpi_y size is generally </summary&Gt public static int Dpiy {get {IntPtr hdc = GetDC (intp Tr.                      Zero);                      int Dpix = GetDeviceCaps (Hdc,logpixelsy);                      ReleaseDC (IntPtr.Zero, HDC);                  return Dpix; }}///<summary>//Get the desktop resolution size of the real setting///</summary> P Ublic static Size DESKTOP {get {IntPtr hdc = GetDC (I                      Ntptr.zero);                      Size size = new size (); Size.                      Width = GetDeviceCaps (hdc,desktophorzres); Size.                      Height = GetDeviceCaps (hdc, desktopvertres);                      ReleaseDC (IntPtr.Zero, HDC);                      return size;              }}///<summary>//Get width Scaling percentage///</summary> public static Float ScaleX {get {IntPtr hdc = GetDC (IntPtr.Zero);                      int t = GetDeviceCaps (hdc, desktophorzres);                      int d = GetDeviceCaps (hdc, horzres);                       float ScaleX = (float) getdevicecaps (hdc, desktophorzres)/(float) getdevicecaps (hdc, horzres);                      ReleaseDC (IntPtr.Zero, HDC);                  return ScaleX;              }}///<summary>//Get height Scaling percentage///</summary> public static float ScaleY {get {IntPtr hdc = getd                      C (IntPtr.Zero);                      float ScaleY = (float) (float) GetDeviceCaps (hdc, desktopvertres)/(float) getdevicecaps (hdc, vertres);                      ReleaseDC (IntPtr.Zero, HDC);                  return ScaleY;   }} #endregion}}


C # API Get system DPI zoom multiple and resolution size

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.