5,699,997 members and growing! (19,323 online)
Email Password   helpLost your password?
Languages » C / C++ Language » General     Beginner

Using Windows XP Styles in your MFC/WIN32 Applications

By Kluch

A simple and short guide to adding and using XP styles in your MFC/Win32 application.
VC6, VC7, VC7.1, C++Windows, WinXP, Win2003, Visual Studio, MFC, Dev

Posted: 14 Sep 2003
Updated: 14 Sep 2003
Views: 97,156
Bookmarked: 65 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
46 votes for this Article.
Popularity: 6.63 Rating: 3.99 out of 5
5 votes, 11.1%
1
2 votes, 4.4%
2
1 vote, 2.2%
3
10 votes, 22.2%
4
27 votes, 60.0%
5

Introduction

I wanted to try and write an article for the The Code Project and thought this would be a good start. It's a little short but hopefully a few people will find it useful. If you have any suggestions on the article let me know.

So what's it about?

This article will show you how to quickly and easily add the capability to use themes under XP. This means whatever theme the user is using under Windows XP will control the look of your application. See the example below:

Sample image

Windows 95, 98, ME, 2000

Sample image

Windows XP

Manifest yourself

One of the first things that need to be done to use XP Styles in your MFC application is to create the manifest XML file for your application. You can paste the following code into a new notepad document and save it in a file called manifest.xml. Save this file in your project directory. It's not required, but you can fill in the description and name of your application if you would like.

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

Once that is completed, you will want to add the manifest.xml file to your project in the resource editor. In Visual Studio 6, hit Ctrl+R to add a new resource, select all files and double click manifest.xml to add the file. When you see the custom resource dialog, enter the number "24" as the resource type and hit OK. Once imported, right click on the resource to open the properties window and change the ID to the number "1".

Just one line...

To initialize everything you need to call InitCommonControls() in your program. I usually put this in the InitInstance() function but you can also use in the InitDialog() and still have it work. It should look something like this:

//Make sure this is here so you can use XP Styles
InitCommonControls();

Now when you run your program you should see XP style controls in your program, unless of course you have Windows XP set to the classic style which then everything will pretty much look the same.

I want more info!

If you're looking for some more information on using XP themes in your code I would recommend checking one of the best resources I have found for information on MSDN. The page is here.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Kluch


Supporter

Occupation: Web Developer
Location: United States United States

Other popular C / C++ Language articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 45 (Total in Forum: 45) (Refresh)FirstPrevNext
GeneralManifest dependency reduces performance?membermala P12:28 30 Sep '08  
QuestionIs it possible to enable xp theme in win32 application without manifest..?memberbasawaraj2:09 17 May '08  
GeneralEnable (or Embed ) XP theme in win32 applicationmemberbasawaraj21:51 15 May '08  
GeneralRe: Enable (or Embed ) XP theme in win32 applicationmembervijay shankar2:25 12 Jun '08  
Generalvc4.0memberRiick6:01 12 May '08  
GeneralSomething isn't right herememberalan9312:05 26 Aug '07  
GeneralRe: Something isn't right herememberPriya_Sundar20:40 17 Mar '08  
GeneralDoes not work for a simple Win32 APPmembersamwise_i13:30 16 Mar '07  
GeneralRe: Does not work for a simple Win32 APPmemberanvil_of_crom0:27 19 Nov '07  
Generalhow do you rollback ?membersperate133:50 2 Feb '07  
GeneralRe: how do you rollback ?membersperate135:15 2 Feb '07  
GeneralIs This Needed?memberalan934:43 27 Jul '06  
GeneralRe: Is This Needed?memberfiuygloINS7:42 18 Aug '07  
Generalworks like a charmmembervjedlicka6:01 18 Jul '06  
GeneralUsing Windows XP Styles in WIN32 Applicationsmemberprem kumar singh20:51 20 Dec '06  
GeneralVisual Studio 2005 linking errors.memberXanblax14:29 14 Dec '05  
GeneralRe: Visual Studio 2005 linking errors.memberXanblax14:36 14 Dec '05  
AnswerRe: Visual Studio 2005 linking errors.supporterKluch19:28 15 Dec '05  
GeneralRe: Visual Studio 2005 linking errors.memberXanblax9:35 16 Dec '05  
GeneralRe: Visual Studio 2005 linking errors.memberNoName236:03 5 Apr '07  
GeneralExtending this to applications running in Win 2000memberAndyzyx13:21 16 Jul '05  
GeneralRe: Extending this to applications running in Win 2000memberAnna-Jayne Metcalfe8:07 6 Oct '05  
GeneralMSFlexGrid Control not themedmemberJoe Colosi5:18 8 Jun '05  
Generalneed help pleasememberKingKonni21:57 22 Feb '05  
GeneralWorks greatmemberrichard sancenot23:23 3 Aug '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 14 Sep 2003
Editor: Smitha Vijayan
Copyright 2003 by Kluch
Everything else Copyright © CodeProject, 1999-2008
Web17 | Advertise on the Code Project