如何在MFC应用程序中获取系统的当前DPI? [英] How to get the current DPI of a system in MFC Application?

查看:539
本文介绍了如何在MFC应用程序中获取系统的当前DPI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的MFC应用程序,该应用程序在Windows 7中的默认DPI(96 dpi)下运行良好,但是当我将DPI增加150%时,UI会失真.我在某些级别使用滚动条已解决问题,请参阅msdn文章.我想知道如何使用MFC代码获取系统的当前DPI,从而设置对话框的高度和宽度.

I have an existing MFC application which runs fine in default DPI ( 96 dpi) in Windows 7. But when I increase the DPI by 150 % the UI gets distorted. I have fixed issues using scroll bars at certain level and referred to msdn article. I am wondering how can I get the current DPI of a system using MFC code so that set the height and widht of a dialog.

请提出建议!

推荐答案

首先,您需要获取屏幕的设备上下文.这很简单,只需调用GetDC,就像这样:

First you need to get the device context for your screen. This is easy, just call GetDC, like this:

HDC screen = GetDC(0);

然后,您要求该设备上下文的设备功能.在您的情况下,您需要每英寸沿X轴和Y轴的像素:

Then you ask for the device capabilities of that device context. In your case, you need the pixels along the X- and Y-axis per inch:

int dpiX = GetDeviceCaps (screen, LOGPIXELSX);
int dpiY = GetDeviceCaps (screen, LOGPIXELSY);

(请参见 http://msdn.microsoft .com/en-us/library/dd144877(v = vs.85).aspx 了解有关GetDeviceCaps的更多信息.

(see http://msdn.microsoft.com/en-us/library/dd144877(v=vs.85).aspx for more information about GetDeviceCaps).

最后,再次释放设备上下文:

Finally, release the device context again:

ReleaseDC (0, screen);

这篇关于如何在MFC应用程序中获取系统的当前DPI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆