码迷,mamicode.com
首页 > Windows程序 > 详细

获取Windows DPI

时间:2017-03-31 23:48:53      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:screen   height   ica   public   1.2   nbsp   .com   ice   graph   

如何获取下图中的125%呢?

技术分享

 

 [DllImport("gdi32.dll")]
        static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
        public enum DeviceCap
        {
            VERTRES = 10,
            DESKTOPVERTRES = 117,

            // http://pinvoke.net/default.aspx/gdi32/GetDeviceCaps.html
        }


        private float GetScalingFactor()
        {
            Graphics g = Graphics.FromHwnd(IntPtr.Zero);
            IntPtr desktop = g.GetHdc();
            int LogicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.VERTRES);
            int PhysicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.DESKTOPVERTRES);

            float ScreenScalingFactor = (float)PhysicalScreenHeight / (float)LogicalScreenHeight;

            return ScreenScalingFactor; // 1.25 = 125%
        }

 

获取Windows DPI

标签:screen   height   ica   public   1.2   nbsp   .com   ice   graph   

原文地址:http://www.cnblogs.com/songqiang/p/6653756.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!