要允许您的应用使用视觉样式,您需要通过清单文件指定要使用ComCtl32.dll
版本 6 或更高版本。Windows 附带此文件的多个版本,因此您需要指定您想要一个较新的版本。
另请注意,正如@Mgetz 在评论中提到的那样,较新的 dll 需要Unicode才能正常工作,因此请确保Unicode
在项目的常规属性中将字符集设置为。
您可以自己生成文件,也可以让 Visual Studio 根据源代码中的项目依赖项和链接器指令自动生成文件。
因此,最简单的方法是让链接器生成它。打开Linker
项目的属性,选择Manifest
页面,并确保将Generate Manifest
其设置为Yes
. 然后将以下指令放在源代码中:
// broken into several lines for readability, as usual make sure there
// are no backspaces after trailing backslashes if copy/pasting
#pragma comment(linker, "\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
或者,您可以手动生成清单文件。根据启用视觉样式文章,它应该看起来像这样(<dependency>
属性是相关的):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="*"
name="CompanyName.ProductName.YourApplication"
type="win32"
/>
<description>Your application description here.</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>