在VC中使用XP样式

  涉及到风格问题,当用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.dllver 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


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#ifndef _BTNST_H #define _BTNST_H // Uncomment the following line to enable support for sound effects #define BTNST_USE_SOUND #if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000 // Return values #ifndef BTNST_OK #define BTNST_OK 0 #endif #ifndef BTNST_INVALIDRESOURCE #define BTNST_INVALIDRESOURCE 1 #endif #ifndef BTNST_FAILEDMASK #define BTNST_FAILEDMASK 2 #endif #ifndef BTNST_INVALIDINDEX #define BTNST_INVALIDINDEX 3 #endif #ifndef BTNST_INVALIDALIGN #define BTNST_INVALIDALIGN 4 #endif #ifndef BTNST_BADPARAM #define BTNST_BADPARAM 5 #endif #ifndef BTNST_INVALIDPRESSEDSTYLE #define BTNST_INVALIDPRESSEDSTYLE 6 #endif // Dummy identifier for grayscale icon #ifndef BTNST_AUTO_GRAY #define BTNST_AUTO_GRAY (HICON)(0xffffffff - 1L) #endif class CXPButton : public CButton { public: CXPButton(); ~CXPButton(); enum { ST_ALIGN_HORIZ = 0, // Icon/bitmap on the left, text on the right ST_ALIGN_VERT, // Icon/bitmap on the top, text on the bottom ST_ALIGN_HORIZ_RIGHT, // Icon/bitmap on the right, text on the left ST_ALIGN_OVERLAP // Icon/bitmap on the same space as text }; enum { BTNST_COLOR_BK_IN = 0, // Background color when mouse is INside BTNST_COLOR_FG_IN, // Text color when mouse is INside BTNST_COLOR_BK_OUT, // Background color when mouse is OUTside BTNST_COLOR_FG_OUT, // Text color when mouse is OUTside BTNST_COLOR_BK_FOCUS, // Background color when the button is focused BTNST_COLOR_FG_FOCUS, // Text color when the button is focused BTNST_MAX_COLORS }; enum { BTNST_PRESSED_LEFTRIGHT = 0, // Pressed style from left to right (as usual) BTNST_PRESSED_TOPBOTTOM // Pressed style from top to bottom }; // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CXPButton) public: virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); virtual BOOL PreTranslateMessage(MSG* pMsg); protected: virtual void PreSubclassWindow(); //}

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值