2017-10-05 79 views
0

我正在写一个windows程序,让用户在1920 * 1080和3840 * 2160之间切换分辨率,这意味着在FHD和4K之间。如何让屏幕在Windows中缩放?

我试图使用“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执行重新缩放后的分辨率。

所以我想知道如何获得比例因子(100%,200%,250%等)编程就像在Windows显示设置10 display settings in Windows 10

回答

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

+0

感谢回答我,但我不知道如何使用GetDpiForMonitor,因为我不知道该如何声明和初始化HMONITOR和MONITOR_DPI_TYPE正确 –

+1

@LuftSchlafer:参见[EnumDisplayMonitors](https://msdn.microsoft .COM/EN-US /库/ dd162610.aspx)。 – IInspectable