博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c# DPI SCale
阅读量:4684 次
发布时间:2019-06-09

本文共 3200 字,大约阅读时间需要 10 分钟。

public class Screen    {        /// Primary Screen                #region Win32 API        [DllImport("user32.dll")]        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 hDc);        #endregion        #region DeviceCaps常量        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 属性        ///         /// 获取屏幕分辨率当前物理大小        ///         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;            }        }        ///         /// 当前系统DPI_X 大小 一般为96        ///         public static int DpiX        {            get            {                IntPtr hdc = GetDC(IntPtr.Zero);                int DpiX = GetDeviceCaps(hdc, LOGPIXELSX);                ReleaseDC(IntPtr.Zero, hdc);                return DpiX;            }        }        ///         /// 当前系统DPI_Y 大小 一般为96        ///         public static int DpiY        {            get            {                IntPtr hdc = GetDC(IntPtr.Zero);                int DpiX = GetDeviceCaps(hdc, LOGPIXELSY);                ReleaseDC(IntPtr.Zero, hdc);                return DpiX;            }        }        ///         /// 获取真实设置的桌面分辨率大小        ///         public static Size DESKTOP        {            get            {                IntPtr hdc = GetDC(IntPtr.Zero);                Size size = new Size();                size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);                size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);                ReleaseDC(IntPtr.Zero, hdc);                return size;            }        }        ///         /// 获取宽度缩放百分比        ///         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;            }        }        ///         /// 获取高度缩放百分比        ///         public static float ScaleY        {            get            {                IntPtr hdc = GetDC(IntPtr.Zero);                float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);                ReleaseDC(IntPtr.Zero, hdc);                return ScaleY;            }        }        #endregion    }

 

posted on
2017-10-23 21:55 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/lged/p/7719223.html

你可能感兴趣的文章
Java多线程-线程的调度(守护线程)
查看>>
Bootstrap 简介(Web前端CSS框架)
查看>>
Bootstrap 概览
查看>>
nginx配置ssl证书实现https访问
查看>>
c# while穷举(凑钱)
查看>>
EnCase v7 could not recognize Chinese character folder names / file names on Linux Platform
查看>>
c#中序列化和反序列化的理解
查看>>
c#Socket通信
查看>>
第七周翻译
查看>>
HTTPS协议的实现原理
查看>>
MvvmLight的Message使用
查看>>
0404 构建之法第四章理解
查看>>
Hunters
查看>>
2018二月实现计划成果及其三月规划
查看>>
封装springmvc处理ajax请求结果
查看>>
jQuery+ localStorage 实现一个简易的计时器
查看>>
tyvj P2018 「Nescafé26」小猫爬山 解题报告
查看>>
类名.class和getClass()区别
查看>>
开发脚本自动部署及监控
查看>>
JavaScript--语句
查看>>