首页 > 学院 > 开发设计 > 正文

如何获取windows DPI设置值(Set Custom Text Size)

2019-11-11 05:01:05
字体:
来源:转载
供稿:网友

首先添加引用:using System.Management;

 [DllImport("user32.dll")]        static extern IntPtr GetDC(IntPtr ptr);        [DllImport("user32.dll", EntryPoint = "ReleaseDC")]        public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);        [DllImport("gdi32.dll")]        public static extern IntPtr CreateDC(        string lpszDriver, // 驱动名称        string lpszDevice, // 设备名称        string lpszOutput, // 可设置为null        Int64 lpInitData // optional PRinter data        );        [DllImport("gdi32.dll")]        public static extern int GetDeviceCaps(        IntPtr hdc, // handle to DC        int nIndex // index of capability        );        [DllImport("user32.dll")]        internal static extern bool SetProcessDPIAware();        const int LOGPIXELSX = 88;        const int LOGPIXELSY = 90;
//在方法中添加如下代码进行获取
 SetProcessDPIAware(); //这句很重要            IntPtr screenDC = GetDC(IntPtr.Zero);            int dpi_x = GetDeviceCaps(screenDC, LOGPIXELSX);//96 是100%、120 是125%            int dpi_y = GetDeviceCaps(screenDC,LOGPIXELSY);            ReleaseDC(IntPtr.Zero, screenDC);


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表