【问题标题】:How do I get visual themes on Win32 dialogs generated from resource files?如何获得从资源文件生成的 Win32 对话框的视觉主题?
【发布时间】:2011-06-02 16:40:02
【问题描述】:

我在资源文件中定义了一个对话框。但是,它使用的是 Windows 95 风格的按钮等。如何为这些控件使用视觉主题(即 XP 及更高版本中添加的主题)?

【问题讨论】:

    标签: c++ windows resources dialog


    【解决方案1】:

    您需要将清单文件嵌入到可执行文件中,告诉 Windows 您想要启用主题的控件版本 (there's MSDN documentation specifically for this topic)。这确实是出于兼容性原因,因为some people really like to write programs that mess around with the internal data structures of other programs

    在 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 在下面的 cmets 中提到的,Windows 2000 ignores theming manifests,所以这在 Windows 2000、Windows XP 和更高版本中应该仍然有效。此外,一些框架(如 MFC)定义了 #pragma 并为您执行初始化。

    【讨论】:

    • 是否在 Windows 2000 上运行的清单中断中添加对“6.0.0.0”版本的依赖?
    • 当我创建一个新的MFC项目时,我发现这一切都为我完成了。 #pragmastdafx.h 中,InitCommonControlsExInitInstance 中。
    • Windows 2000 会忽略清单,因此您所要做的就是进行正确的初始化调用。 msdn.microsoft.com/en-us/library/ff563660%28v=vs.85%29.aspx
    • @Mark Ransom:谢谢,我不知道。
    • @Mark:我没有使用 MFC(因此我很困惑)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-16
    • 2021-07-04
    • 1970-01-01
    • 2012-07-28
    • 2010-09-08
    • 2020-08-21
    相关资源
    最近更新 更多