How to get the current DPI of a system in MFC Application?(如何在 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 MFC 应用程序中获取系统的当前 DPI?


- 从python回调到c++的选项 2022-11-16
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 近似搜索的工作原理 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- C++ 协变模板 2021-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- STL 中有 dereference_iterator 吗? 2022-01-01