升级后的 MFC 应用程序看起来仍然很旧

2021-12-30 00:00:00 mfc visual-studio-2015 visual-c++-6

我有一个用 VC6 编写的 MFC 应用程序.我已经将它升级到 VS2015,它可以构建和运行.该应用程序是一个主 exe,其中包含许多带有对话框的 DLL.

I have an MFC application written with VC6. I have upgraded it to VS2015 and it builds and runs. The application is a main exe with many DLL's that have dialogs in them.

然而,该应用程序仍然看起来像是用 VC6 构建的.没有一个 GUI 组件具有 Windows 7 的外观和感觉,它们仍然看起来很旧.

However the application still looks like it is built with VC6. None of the GUI components have the Windows 7 look and feel, they all still look old style.

如何让我现有的应用程序看起来更现代?

How can I make my existing application look more modern?

推荐答案

你至少应该在你的项目中添加这一行,例如添加到 stdafx.h

You should at least add this line to your project, for example add it to stdafx.h

#pragma comment(linker,""/manifestdependency:type='win32' 
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' 
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'"")

或者将以下内容添加到您的清单文件中:

Or add the following to your manifest file:

<dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="*"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
</dependency>

另见 启用视觉风格

所有者绘制控件变得更加复杂.请参阅此参考:使用具有自定义和所有者绘制的控件

It gets more complicated for owner draw controls. See this reference: Using Visual Styles with Custom and Owner-Drawn Controls

对于 ListView 和 TreeView 控件,您可以调用此函数以获得更现代的外观(尽管它在 Windows 10 中没有任何区别)

For ListView and TreeView controls, you can call this function for a more modern look (although it doesn't make any difference in Windows 10)

SetWindowTheme(m_ListView.m_hWnd, L"Explorer", NULL);
SetWindowTheme(m_TreeView.m_hWnd, L"Explorer", NULL);

* #pragma comment 是特定于 Visual Studio 的.对于其他编译器,您需要修改清单文件

* #pragma comment is Visual Studio specific. For other compilers you need to modify the manifest file

相关文章