如何获取从资源文件生成的 Win32 对话框的视觉主题?

发布于 2024-10-09 17:57:00 字数 82 浏览 0 评论 0原文

我在资源文件中定义了一个对话框。然而,它使用的是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸠书 2024-10-16 17:57:00

您需要将清单文件嵌入到可执行文件中,告诉 Windows 您想要启用主题的控件版本 (有专门针对此主题的 MSDN 文档)。这实际上是出于兼容性原因,因为 有些人真的喜欢写扰乱其他程序内部数据结构的程序

在 Visual C++ 中,最简单的方法可能是通过 #pragma

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

这会导致链接器将类似以下内容添加到生成的清单文件中:

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

您还需要调用 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:

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

This causes the linker to add something like this to the generated manifest file:

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文