Visual Studio 从 2005 升级到 2015,C++ GUI 保留 XP 主题而不是系统主题
Visual Studio upgrade from 2005 to 2015, C++ GUI keeps XP theme not system theme
我最近将一个项目从 VS2005 迁移到 VS2015。在这样做时,我的项目现在拒绝使用系统外观并使用 windows 98 外观。 2005 年建成时,它确实使用了系统外观。
描述对话框的 .rc
文件与我复制并粘贴原始文件相同。属性都是一样的。
我搜索了一下,一种可能性是 FlatStyle 属性,它可以设置为系统,但是 none 我的对话框有这个 属性。
此外,我查看了 this 并尝试了这些建议,但 none 似乎有效。
我认为这个问题是我必须在 2015 年禁用的设置,以便应用程序适应系统的外观和感觉。
那么如何让我的应用适配当前系统呢?
这是一个对话框示例:
STYLE DS_SETFONT | DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_ACCEPTFILES | WS_EX_APPWINDOW
要允许您的应用使用视觉样式,您需要通过清单文件指定要使用 ComCtl32.dll
版本 6 或更高版本。 Windows 附带此文件的多个版本,因此您需要指定您想要更新的版本。
另请注意,正如@Mgetz 在评论中提到的,较新的 dll 需要 Unicode 才能正常工作,因此请确保在项目中将字符集设置为 Unicode
一般属性。
您可以自己生成文件,或者让Visual Studio根据源代码中的项目依赖项和链接器指令自动生成。
所以,最简单的方法是让链接器生成它。打开项目的 Linker
属性,select 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='*'\"")
或者,您可以手动生成清单文件。根据 Enabling Visual Styles 文章,它应该是这样的(<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>
我最近将一个项目从 VS2005 迁移到 VS2015。在这样做时,我的项目现在拒绝使用系统外观并使用 windows 98 外观。 2005 年建成时,它确实使用了系统外观。
描述对话框的 .rc
文件与我复制并粘贴原始文件相同。属性都是一样的。
我搜索了一下,一种可能性是 FlatStyle 属性,它可以设置为系统,但是 none 我的对话框有这个 属性。
此外,我查看了 this 并尝试了这些建议,但 none 似乎有效。
我认为这个问题是我必须在 2015 年禁用的设置,以便应用程序适应系统的外观和感觉。
那么如何让我的应用适配当前系统呢?
这是一个对话框示例:
STYLE DS_SETFONT | DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_ACCEPTFILES | WS_EX_APPWINDOW
要允许您的应用使用视觉样式,您需要通过清单文件指定要使用 ComCtl32.dll
版本 6 或更高版本。 Windows 附带此文件的多个版本,因此您需要指定您想要更新的版本。
另请注意,正如@Mgetz 在评论中提到的,较新的 dll 需要 Unicode 才能正常工作,因此请确保在项目中将字符集设置为 Unicode
一般属性。
您可以自己生成文件,或者让Visual Studio根据源代码中的项目依赖项和链接器指令自动生成。
所以,最简单的方法是让链接器生成它。打开项目的 Linker
属性,select 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='*'\"")
或者,您可以手动生成清单文件。根据 Enabling Visual Styles 文章,它应该是这样的(<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>