【问题标题】:How get screen scale in windows?如何在 Windows 中获得屏幕比例?
【发布时间】:2017-10-05 09:30:49
【问题描述】:

我正在编写一个 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;

例如,如果我使用 3840*2160 的分辨率,我预计程序会给我 3840*2160 的分辨率。但是,程序只输出 1536x864,这是 Windows 执行重新缩放后的分辨率。

所以我想知道如何像 Windows 10 中的显示设置一样以编程方式获取缩放因子(100%、200%、250% 等)。 display settings in Windows 10

【问题讨论】:

    标签: c++ windows winapi


    【解决方案1】:

    您的应用程序似乎收到了虚拟化 DPI 数据。要接收正确的指标,您需要提供正确的应用程序清单,包括高 DPI 支持和系统兼容性条目。见High DPI

    <?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>
    

    要获得缩放,您可以致电GetDpiForMonitor

    【讨论】:

    • 感谢您的回复,但我不知道如何使用 GetDpiForMonitor,因为我不知道如何正确声明和初始化 HMONITOR 和 MONITOR_DPI_TYPE
    • @LuftSchlafer:见EnumDisplayMonitors
    猜你喜欢
    • 1970-01-01
    • 2014-06-08
    • 2015-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-19
    • 2018-09-28
    相关资源
    最近更新 更多