这是正常现象。你可以说这是VC的BUG,也可以说是多字符集考虑。资源文件rc中,对每个部分都有关于字符集的设定,大部分资源都是单一属性的,不能在其它字符集下使用。如果需要多字符集,甚至多国语言,你需要对每种字符集定制单独的资源。如果你的一个资源在所有字符集下都使用,其实是无法保障正确显示的。如果是新建项目的时候选择了多字节的话,那么运行前后设计的窗口风格会不一样,如下:
那么怎么做使得在多字节下对话框运行前后都是一样的风格呢?
方法一就是把stdAfx.h中的代码做如下修改即可:
#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_IA64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' 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
修改成如下:
#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_IA64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' 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
其实就是把
#if _UNICODE
#endif
注释掉,否则你把
#if _UNICODE
A code
#endif
中间的A code 拿出来也可以的,即变成这样:
#if _UNICODE
#endif
A code
方法二采用manifest来辅助修改界面风格
1. 将下面这段XML保存到你的工程目录下,文件名为XPStyle.manifest(注意后缀不是xml)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="X86"
name="XP style manifest"
type="Win32"
/>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="Win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
2. 在VC中点添加资源, 将XPStyle.manifest文件作为资源文件加入到你的工程中,
填资源类型号为24(这是因为manifest格式文件不是VC的常规资源文件), 资源ID为IDR_XP_STYLE.
(1).如果是dll工程,则在Resource.h中修改:
#define IDR_XP_STYLE 2
并在StdAfx.h中添加
#define ISOLATION_AWARE_ENABLED 1
(2).如果是exe工程,则在Resource.h中修改:
#define IDR_XP_STYLE 1
3. 点击全部编译,运行你的程序看看,是不是很酷.