Click here to Skip to main content
6,630,586 members and growing! (16,685 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.1WinXP, Win2003, Visual Studio, MFC, Dev
Posted:14 Sep 2003
Views:114,144
Bookmarked:73 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
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


Member

Occupation: Program Manager
Company: Microsoft
Location: United States United States

Other popular C / C++ Language articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 48 (Total in Forum: 48) (Refresh)FirstPrevNext
GeneralManifest dependency reduces performance? Pinmembermala P12:28 30 Sep '08  
QuestionIs it possible to enable xp theme in win32 application without manifest..? Pinmemberbasawaraj2:09 17 May '08  
GeneralEnable (or Embed ) XP theme in win32 application Pinmemberbasawaraj21:51 15 May '08  
GeneralRe: Enable (or Embed ) XP theme in win32 application Pinmembervijay shankar2:25 12 Jun '08  
Generalvc4.0 PinmemberRiick6:01 12 May '08  
GeneralSomething isn't right here Pinmemberalan9312:05 26 Aug '07  
GeneralRe: Something isn't right here PinmemberPriya_Sundar20:40 17 Mar '08  
GeneralDoes not work for a simple Win32 APP Pinmembersamwise_i13:30 16 Mar '07  
GeneralRe: Does not work for a simple Win32 APP Pinmemberanvil_of_crom0:27 19 Nov '07  
Generalhow do you rollback ? Pinmembersperate133:50 2 Feb '07  
GeneralRe: how do you rollback ? Pinmembersperate135:15 2 Feb '07  
GeneralIs This Needed? Pinmemberalan934:43 27 Jul '06  
GeneralRe: Is This Needed? PinmemberfiuygloINS7:42 18 Aug '07  
Generalworks like a charm Pinmembervjedlicka6:01 18 Jul '06  
GeneralUsing Windows XP Styles in WIN32 Applications Pinmemberprem kumar singh20:51 20 Dec '06  
GeneralVisual Studio 2005 linking errors. PinmemberXanblax14:29 14 Dec '05  
GeneralRe: Visual Studio 2005 linking errors. PinmemberXanblax14:36 14 Dec '05  
AnswerRe: Visual Studio 2005 linking errors. PinsupporterKluch19:28 15 Dec '05  
GeneralRe: Visual Studio 2005 linking errors. PinmemberXanblax9:35 16 Dec '05  
GeneralRe: Visual Studio 2005 linking errors. Pinmember4jb9:56 4 Jul '09  
GeneralRe: Visual Studio 2005 linking errors. [modified] Pinmembersciencekrishnan23:31 20 Jul '09  
GeneralRe: Visual Studio 2005 linking errors. Pinmembersciencekrishnan2:06 22 Jul '09  
GeneralRe: Visual Studio 2005 linking errors. PinmemberNoName236:03 5 Apr '07  
GeneralExtending this to applications running in Win 2000 PinmemberAndyzyx13:21 16 Jul '05  
GeneralRe: Extending this to applications running in Win 2000 PinmemberAnna-Jayne Metcalfe8:07 6 Oct '05  

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-2009
Web10 | Advertise on the Code Project