如何获取从资源文件生成的 Win32 对话框的视觉主题?
我在资源文件中定义了一个对话框。然而,它使用的是 Windows 95 风格的按钮等。如何为这些控件使用视觉主题(即 XP 及更高版本中添加的主题)?
I've got a dialog defined in a resource file. However, it's using the Windows 95 style buttons and such. How do I use visual themes (i.e. those added in XP and later) for these controls?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将清单文件嵌入到可执行文件中,告诉 Windows 您想要启用主题的控件版本 (有专门针对此主题的 MSDN 文档)。这实际上是出于兼容性原因,因为 有些人真的喜欢写扰乱其他程序内部数据结构的程序。
在 Visual C++ 中,最简单的方法可能是通过
#pragma
:这会导致链接器将类似以下内容添加到生成的清单文件中:
您还需要调用
InitCommonControlsEx()
注册适当的控件类或对话框不会出现。正如 Mark Ransom 在下面的评论中提到的,Windows 2000 忽略主题清单 ,因此这在 Windows 2000、Windows XP 及更高版本中应该仍然有效。此外,一些框架(例如 MFC)定义了#pragma 并为您执行初始化。
You need to embed a manifest file into the executable that tells Windows you want the version of the controls that have themes enabled (there's MSDN documentation specifically for this topic). This is really for compatibility reasons because some people really like to write programs that mess around with the internal data structures of other programs.
In Visual C++, probably the easiest way to do this is via a
#pragma
:This causes the linker to add something like this to the generated manifest file:
You also need to call
InitCommonControlsEx()
to register the appropriate control classes, or the dialog box won't appear.As Mark Ransom has mentioned in the comments below, Windows 2000 ignores theming manifests, so this should still work in Windows 2000, Windows XP and later. Also, some frameworks like MFC define the
#pragma
and performs the initialization for you.