如何从资源文件生成的Win32对话框中获取视觉主题? [英] How do I get visual themes on Win32 dialogs generated from resource files?

查看:210
本文介绍了如何从资源文件生成的Win32对话框中获取视觉主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在资源文件中定义的对话框。但是,它使用Windows 95样式按钮等。

解决方案

你需要嵌入一个清单将文件写入可执行文件,告诉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 ='*'\)

这将导致链接器向生成的清单文件添加如下内容:

 <依赖性> 
< 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 并为您执行初始化。


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?

解决方案

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.

这篇关于如何从资源文件生成的Win32对话框中获取视觉主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆