涉及到风格问题,当用Visual Studio 2005/2008创建MFC程序时,如果选择Unicode编码方式则程序自动具有XP控件风格;如果没有选择或选择多字符集编码方式,则需要如下操作:
将下面的内容保存到一个文件名为***.manifest的文件中,放到res目录下,***可以使用你的程序的名称或者任意。
<?xmlversion="1.0" encoding="UTF-8"standalone="yes"?>
<assemblyxmlns="urn:schemas-microsoft-com:asm.v1"manifestVersion="1.0">
<assemblyIdentity
name="Wiegand.Application"
processorArchitecture="x86"
version="1.0.0.0"
type="win32"/>
<description>Demofor the Application MFC class.</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="x86"
publicKeyToken="6595b64144ccf1df"
language="*"/>
</dependentAssembly>
</dependency>
</assembly>
然后把这个文件添加到项目中,重新生成即可。
为什么需要这样呢?因为微软为Windows XP提供了Themes服务,Themes可以让程序具有“XP风格”。因为微软更新了Comctl32.dll(ver 6.0)这个“XP风格”的控件,并且还为了保留传统的Windows界面风格,特地留下了Comctl32.dll(v5.8)。当在VS2005中建 立MFC工程,并且使用Unicode模式时,程序会自动引入XP风格。否则需要手动引入,方法就是写一个.manifest文件,用它来引入XP风格。
当然VC6.0要做到XP风格也可以:
1) 创建一个.manifest文件的资源.
在res/文件夹下创建一个跟以程序名加.manifest的文件,如果程序为test.exe,则创建test.exe.manifest文件,文件内容如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
processorArchitecture="x86"
version="5.1.0.0"
type="win32"
name="name.exe"/>
<description>Application</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
publicKeyToken="6595b64144ccf1df"
language="*"
processorArchitecture="x86"/>
</dependentAssembly>
</dependency>
</assembly>
注意要使用 utf-8编码保存。
2) 将新定义的资源加入到.rc2文件中,类型设为24。
打开res/文件夹下的.rc2文件,在其中加入如下定义:
124 MOVEABLE PURE “res/test.exe.manifest”
其中的文件地址按1) 步中修改的设置即可,之后编译即可,为了使程序界面可能充分利用系统的界面特性,可以将界面字体设置为TrueType类型的,利用Windows XP等系统的屏幕字体平滑特性。
VC2008要改为系统风格,还可如下操作:
如果程序字符集使用UNICODE编码,则默认就是使用系统界面风格的,如果选择其它的类型,则编辑下stdafx.h,最后面部分加上这么一段:
#ifdefined _M_IX86
#pragmacomment(linker,”/manifestdependency:”type=’win32′ name=’Microsoft.Windows.Common-Controls’ version=’6.0.0.0′processorArchitecture=’x86′ publicKeyToken=’6595b64144ccf1df’language=’*'”")
#elifdefined _M_IA64
#pragmacomment(linker,”/manifestdependency:”type=’win32′ name=’Microsoft.Windows.Common-Controls’ version=’6.0.0.0′processorArchitecture=’ia64′ publicKeyToken=’6595b64144ccf1df’language=’*'”")
#elifdefined _M_X64
#pragmacomment(linker,”/manifestdependency:”type=’win32′ name=’Microsoft.Windows.Common-Controls’ version=’6.0.0.0′processorArchitecture=’amd64′ publicKeyToken=’6595b64144ccf1df’language=’*'”")
#else
#pragmacomment(linker,”/manifestdependency:”type=’win32′ name=’Microsoft.Windows.Common-Controls’ version=’6.0.0.0′processorArchitecture=’*’ publicKeyToken=’6595b64144ccf1df’language=’*'”")
#endif