解决 Win32 系统控件都是老式的问题

将下列代码加入头文件顶部即可:

#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif

 简单来说,你看到的大部分 Win32 窗口方框都是由公共控件库(Common Control Library) Comctl32.dll 实现的窗口。要使应用程序能够显示出与操作系统版本匹配的视觉样式,必须使用ComCtl32.dll 版本 6.0 或更高版本;但在没有任何定义的默认情况下,应用程序使用 User32.dll 中定义的用户控件(User Controls)和 ComCtl32.dll 版本 5.0 中定义的公共控件(Common Controls)。如果要求指定应用程序使用 ComCtl32.dll 版本 6.0 或更高,则必须添加应用程序清单(manifest,如其他答主所述)或编译器指令(#pragma)使得使应用程序能够指定它需要的程序集(Assembly,一组由不同版本 dll 组成的对象列表)版本。

具体可参考官方文档 Enabling Visual Styles

ComCtl32.dll 版本 6.0 不可再发行(redistributable),也就是说只有当应用程序在对应的 Windows 版本上运行时,这些对应的样式效果可用,也就是说你不能在 Windows 11 上编译程序之后拿到 Windows XP 上运行,要求其用这种方法显示 Windows 11 的效果。关于不同操作系统内置的对应版本:[2]

Version Distribution Platform
5.81 Microsoft Internet Explorer 5.01
Microsoft Internet Explorer 5.5
Microsoft Internet Explorer 6
5.82 Windows Server 2003
Windows Vista
Windows Server 2008
Windows 7
6.0 Windows Server 2003
6.10 Windows Vista
Windows Server 2008
Windows 7

声明

原文链接:https://www.zhihu.com/question/489914730

posted @ 2022-03-25 20:35  SeaYJ  阅读(45)  评论(0编辑  收藏  举报
回到顶部