首页 > 解决方案 > 如何使用我自己的清单文件并将其嵌入到使用 Visual Studio 2017 的可执行文件中?

问题描述

我正在尝试使用 PerMonitorV2 DPI 感知,它会在 DPI 更改时调整非客户区的大小。MSDN 文档建议使用清单设置 DPI 感知模式: 为进程设置默认 DPI 感知

VS Configuration Properties 的 Manifest Tool 部分仅提供了三个 DPI Awareness 选项:None(不知道)、Hight DPI AwarePer Monitor DPI Aware(似乎是 PerMonitorV1),所以我需要找到一些方法来覆盖这些 DPI 设置,但我不知道该怎么做。(我最好的猜测是以某种方式提供我自己的清单文件,而不是依靠 Visual Studio 来生成一个。)

标签: winapivisual-studio-2017manifestdpi-aware

解决方案


在清单工具设置中,您可以定义 Visual Studio 将与默认清单合并的附加清单片段。默认清单仍将提供<dpiAware>标签,作为不理解<dpiAwareness>标签的旧版本操作系统的后备。

脚步:

  1. 打开项目配置,选择“Manifest Tool”>“Input and Output”。
  2. 在“其他清单文件”字段中,输入要包含的清单片段的文件名。该路径是相对于您的项目文件夹的。

    片段看起来像这样。请注意,我从MSDN 示例中删除了<dpiAware>标记

    <?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>
          <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
        </windowsSettings>
      </application>
    </assembly>
    
  3. 从“DPI Awareness”组合框中选择“High DPI Aware”。如上所述,这是旧 Windows 版本的备用值。

结果:

这是我使用应用程序向导创建的 Win32 项目的合并清单。它嵌入在应用程序的资源中。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
      <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
    </windowsSettings>
  </application>
</assembly>

如果你有两个<dpiAware>标签,你忘了<dpiAware>从清单片段中删除。


推荐阅读