让你的程序变成xp风格

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

http://blog.youkuaiyun.com/limigy/article/details/650008

 

 A Simple Way to Enable a Windows XP Look and Feel for VC++ 6.0 MFC Applications

 Alexander Simanov (view profile)
November 7, 2002

Environment: VC6 SP5, Windows 2000 SP2, and Windows XP SP1

The main reason for writing this article is that Visual C++ 6.0 wizards-generated MFC applications don't use the XP look and feel controls if you run them under XP. If you are using Microsoft Visual C++.NET, that is not an issue. I had a goal to develop an application running under any Microsoft 32-bit OS and use the new UI look and feel if it runs under XP.

The solution is very simple. All you need to do is add a custom resource to the project and add a couple of lines to the InitInstance method of the CWinApp derived class.

1. Create a Manifest File

Microsoft has introduced a new type of resource called Manifest. Well, technically it's not a type of resource; it is just an XML file included to the app as a custom resource with ID=1, which describes the application and its dependencies. If an executable file contains this resource, Windows XP will identify it and force the application to use the specific versions of libraries.Our goal is to enforce usage of new Windows Common Controls library (version 6).

Here is an example of a simple manifest file that I've used to solve this task:

<?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="Microsoft.Windows.YourApplication" type="win32"/><description>YourApplication</description><dependency><dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /></dependentAssembly></dependency></assembly>


 

Create a file with its contents as shown above in the project resources folder (res by default). Replace YourApplication with an appropriate name. That should do it for our case. For further information about manifest files, see the MSDN for Visual Studio .NET.

2. Add a Resource to the .rc File

First, let's add two lines to the resource.h file. Just copy and paste the following:

#define IDR_MANIFEST 1 #define RT_MANIFEST 24


Now, open the application custom resource file. Usually, it's located in the res directory;the default extention is .rc2. Manually add the following line:

 

// Add manually edited resources here... IDR_MANIFEST RT_MANIFEST MOVEABLE PURE "res//ApplicationManifestXMLFile"

Replace ApplicationManifestXMLFile with the actual file name.

3. Modify the InitInstance Method

It's really simple. Just copy and paste two calls at the beginning of the InitInstance method:

BOOL MoneyApp::InitInstance(){ InitCommonControls(); // initialize common control library CWinApp::InitInstance(); // call parent class method #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a  // shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC // statically #endif  // the rest of the code }


 

4. Conclusion

This is it. No magic, but it works. You've got all the dialog controls, menus, and toolbars looking like their brothers and sisters in native XP applications. You can still develop under Windows 2000, but now I know that the UI of your applications will have a nice look under XP.

These screenshots illustrate how the same application looks under Windows 2000 and Windows XP:

If you have any questions or ideas about this article, please drop me a couple of lines atalex@simanov.com.

 


 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

http://www.cppblog.com/zgysx/archive/2006/10/31/14413.html

使程序界面具有xp风格(在vs2003和vs2005中) 

 

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

http://topic.youkuaiyun.com/t/20060705/17/4862544.html

palmax:

To   楼主:
我的意思就是先用DrawFrameControl自己先画出控件,然后在自己去画xp风格,画的方法可以参考一下CButtonST类(google搜一下)

另外我要说一句,使用manifest是治标不治本的方法,因为此方法呈现xp风格的前提是系统中有uxtheme.dll,并且当前系统主题不是“windows经典”,否则还是没有xp风格的,正是因为manifest对系统的依赖比较大,因为建议自己绘制xp风格,摆脱对系统的依赖

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值