且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将 Windows 应用程序清单中的 dpiAware 属性设置为“每个监视器"?在 Visual Studio 中?

更新时间:2021-07-17 15:53:07

Windows 10 中的新功能是 dpiAwarenessdpiAware,因此我们需要更新此示例少量.现在,这很好,因为如果 dpiAwareness 不存在,那么设置将从 dpiAware 继承.

New in Windows 10 is dpiAwareness as well as dpiAware, so we need to update this example a bit. Now, it is fine because if dpiAwareness does not exist, then the settings will be inherited from dpiAware.

要全面启用 DPI 感知,使用最新的 Win10 支持(有关其他可能的选项,请参阅参考 URL),其中包括permonitor"和permonitorv2",其中我将使用系统"代替系统",因为您的问题会问它.

To enable DPI awareness in full, with the latest Win10 support (see Ref URL for other possible options), which includes 'permonitor' and 'permonitorv2', which I will use instead of 'system' because your question asks it.

<asmv3:application>
  <asmv3:windowsSettings>
    <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware> <!-- legacy -->
    <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">permonitorv2,permonitor</dpiAwareness> <!-- falls back to pm if pmv2 is not available -->
  </asmv3:windowsSettings>
</asmv3:application>

禁用,你会做相反的事情(不需要dpiAwareness,因为我们不支持它):

To disable, you'd do the opposite (no need for dpiAwareness since we don't support it):

<asmv3:application>
  <asmv3:windowsSettings>
    <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">unaware</dpiAware>
  </asmv3:windowsSettings>
</asmv3:application>

如果您碰巧使用 GDI 对象来绘制您自己的一些东西,那么甚至还有gdiScaling".

Then there is even 'gdiScaling' if you happen to use GDI objects to paint some of your own stuff.

<asmv3:application>
  <asmv3:windowsSettings>
    <gdiScaling xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">true</gdiScaling>
  </asmv3:windowsSettings>
</asmv3:application>

参考:微软在最新的 Windows 10 版本中的 DPI Awareness(也有关于如何让你的代码意识到 DPI 的教程,即使对于较大的项目来说有点乏味)

Reference: Microsoft on DPI Awareness as of latest Windows 10 build (also has tutorials on how to make your code DPI aware, even if it is a little tedious for larger projects)