C++ 如何在windows中获得屏幕比例?

C++ 如何在windows中获得屏幕比例?,c++,windows,winapi,C++,Windows,Winapi,我正在编写一个windows程序,它允许用户在1920*1080和3840*2160之间切换分辨率,也就是说在FHD和4K之间切换分辨率 我尝试使用“GetSystemMetrics”来获得当前分辨率 //Algorithm #1 //Get current resolution and resolution scaling. xScreenResolution = GetSystemMetrics(SM_CXSCREEN); yScreenResolution = GetSystemMetri

我正在编写一个windows程序,它允许用户在1920*1080和3840*2160之间切换分辨率,也就是说在FHD和4K之间切换分辨率

我尝试使用“GetSystemMetrics”来获得当前分辨率

//Algorithm #1
//Get current resolution and resolution scaling.
xScreenResolution = GetSystemMetrics(SM_CXSCREEN);
yScreenResolution = GetSystemMetrics(SM_CYSCREEN);
cout << "Current Resolution is: " << xScreenResolution << "x" << yScreenResolution << endl;
//算法#1
//获取当前分辨率和分辨率缩放。
xScreenResolution=GetSystemMetrics(SM_CXSCREEN);
yScreenResolution=GetSystemMetrics(SM_CYSCREEN);

cout看起来您的应用程序接收虚拟化的DPI数据。要获得正确的指标,您需要提供适当的应用程序清单,包括高DPI支持和系统兼容性条目。看



.

感谢您的回复,但我不知道如何使用GetDPiFormMonitor,因为我不知道如何声明和初始化HMONITOR和MONITOR\u DPI\u类型properly@LuftSchlafer:见。
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <application xmlns="urn:schemas-microsoft-com:asm.v3">
        <windowsSettings>
            <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True/PM</dpiAware>
        </windowsSettings>
    </application>
    <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
        <application>
            <!-- Windows 10 -->
            <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
        </application>
    </compatibility>
</assembly>