c++ 获取屏幕显示比例

时间:2021-02-07 16:20:11

c++ 获取屏幕显示比例

屏幕默认的显示比例是100%,但是有些用户喜欢调到“中等”或“较大”,这样的话,就可能导致我们开发的应用超出屏幕边界。因此,我们要获取屏幕显示比例,做出相应的处理。

Primary display DPI scale factor

Similarly, you can get the pixel density by using the LOGPIXELSX and LOGPIXELSY indices:

syntax
// Get desktop dc
desktopDc = GetDC(NULL);
// Get native resolution
horizontalDPI = GetDeviceCaps(desktopDc,LOGPIXELSX);
verticalDPI = GetDeviceCaps(desktopDc,LOGPIXELSY);

These results are returned in a coordinate system in which 96 corresponds to 100%, as shown inTable 2 DPI Scale Factors.

c++ 获取屏幕显示比例


参考链接:https://docs.microsoft.com/zh-cn/windows-hardware/manufacture/desktop/dpi-related-apis-and-registry-settings