A Simple Way to Enable a Windows XP Look and Feel for VC++ 6.0 MFC Applications
2007-03-03 17:39
615 查看
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:
![]() | Running under Windows 2000 |
![]() | Running under Windows XP before the changes |
![]() | Running under Windows XP after the changes |
Alexander Simanov
Downloads
I've created a simple project (MFC dialog-based), demonstrating this technique.Download demo project - 20 Kb.
![](https://oscdn.geek-share.com/Uploads/Images/Content/200704/3265256e1829867776800a12a086c838.gif)
![](https://oscdn.geek-share.com/Uploads/Images/Content/201911/10/750c547f8a78583fd3516e02e7518385.gif)
Cach鬠the world?s fastest object database, does away with mapping. Free download.
![](https://oscdn.geek-share.com/Uploads/Images/Content/201911/10/9dc5f253963fa7f8b2052cb74f8ae66f.gif)
Migrating Apps to Modern Times: Ready for bigger markets? Learn about the NXT initiative for ISVs.
![](https://oscdn.geek-share.com/Uploads/Images/Content/201911/10/a4d8b0cda1d6dc54ae9c2f69b4ef50d6.gif)
Microsoft Mobile & Embedded DevCon 2007--Las Vegas, May 1-3. Register now and save $400!
![](https://oscdn.geek-share.com/Uploads/Images/Content/201911/10/ea58e27ee401070e1947f93cc93087cc.gif)
Manage the application life cycle. Get your free Microsoft Team Foundation Server Resource Kit.
![](https://oscdn.geek-share.com/Uploads/Images/Content/201911/10/0ea2e31f5fd18d1b5a3ba3707d798acb.gif)
Developing Intelligent Communications? Visit the Avaya Developer Connection Center on DevX.
alex@simanov.com.
相关文章推荐
- Debugging Applications for Microsoft .NET and Microsoft Windows: Notes-Prerequisites to Debugging
- How To Enable or Disable Simple File Sharing in Windows XP
- busdog is a filter driver for MS Windows (XP and above) to sniff USB traffic.
- Flash Professional CS5 will enable you to build applications for iPhone and iPod touch using ActionScript 3.
- [zz]Common loading points for viruses, worms, and Trojan horse programs on Windows 2000/XP/2003
- Debugging Applications for Microsoft .NET and Microsoft Windows: Notes-The Debugging Process
- QueryBuilder: A Simple Way to Read and Write Query Strings
- How to Enable Read-Only Client Drive Mapping and Clipboard Mapping for XenApp
- chromiumembedded - A simple framework for embedding chromium browser windows in other applications. - Google Project Hosting
- Windows XP + VC 6.0 + WinXP_DDK + DriverStudio 3.2
- How to enable Edit and Continue feature for Web Application Projects?
- chromiumembedded - A simple framework for embedding chromium browser windows in other applications. - Google Project Hosting
- 如何设置Java桌面程序界面外观(How to Set the Look and Feel)
- How to compile and run a simple java file in jenkins on Windows
- windows xp vc 6.0编译最新net-snmp源码
- How to Monitor Your Network Usage in Windows 8 (And Prevent Paying For The Extra Bandwidth)
- Windows XP + VC 6.0 + WinXP_DDK + DriverStudio 3.2
- 翻 译:Veritas.Netbackup.Enterprise.Server.6.0.Backup.Planning.And.Performance.Tuning.Guide.For.Unix,.Windows,.And.Linux
- How to enable Apache, OC4J and OPMN logging in Oracle Applications R12
- Preparing for Application and Service Deployment-Adding an HTTPS Endpoint to a Windows Azure Cloud