A Simple Way to Enable a Windows XP Look and Feel for VC++ 6.0 MFC Applications Rating: ![]() ![]() ![]() ![]() ![]()
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 FileMicrosoft 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"?> 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 FileFirst, let's add two lines to the resource.h file. Just copy and paste the following: #define IDR_MANIFEST 1 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... Replace ApplicationManifestXMLFile with the actual file name. 3. Modify the InitInstance MethodIt's really simple. Just copy and paste two calls at the beginning of the InitInstance method: BOOL MoneyApp::InitInstance() 4. ConclusionThis 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 at alex@simanov.com. |
让你的程序变成xp风格
最新推荐文章于 2024-08-18 23:52:40 发布