Click here to Skip to main content
15,868,010 members
Articles / Desktop Programming / MFC
Article

Using Windows XP Styles in your MFC/WIN32 Applications

Rate me:
Please Sign up or sign in to vote.
4.80/5 (48 votes)
14 Sep 20032 min read 260.2K   2.4K   94   56
A simple and short guide to adding and using XP styles in your MFC/Win32 application.

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
<?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:

XML
//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


Written By
Program Manager Microsoft
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionManifest file Pin
Deepa_R11-Dec-15 18:06
Deepa_R11-Dec-15 18:06 
QuestionArrow sign for Tree Control instead of plus/minus sign Pin
Member 789460112-Jun-14 18:47
Member 789460112-Jun-14 18:47 
QuestionMust use a manifest File Pin
sayer19-Dec-12 14:48
sayer19-Dec-12 14:48 
QuestionXP Style for Custom contro Pin
Prakash Elangovan23-Aug-12 1:25
Prakash Elangovan23-Aug-12 1:25 
GeneralThanks! Pin
Alan Balkany16-Jul-10 16:02
Alan Balkany16-Jul-10 16:02 
GeneralWindows 7? [modified] Pin
billyjoesunday22-Jan-10 10:32
billyjoesunday22-Jan-10 10:32 
GeneralAnother Way Pin
heiitx7-Dec-09 0:24
heiitx7-Dec-09 0:24 
GeneralRe: Another Way Pin
metalinspired17-Dec-09 10:53
metalinspired17-Dec-09 10:53 
QuestionManifest dependency reduces performance? Pin
mala P30-Sep-08 11:28
mala P30-Sep-08 11:28 
QuestionIs it possible to enable xp theme in win32 application without manifest..? Pin
basawaraj17-May-08 1:09
basawaraj17-May-08 1:09 
GeneralEnable (or Embed ) XP theme in win32 application Pin
basawaraj15-May-08 20:51
basawaraj15-May-08 20:51 
GeneralRe: Enable (or Embed ) XP theme in win32 application Pin
vijay shankar12-Jun-08 1:25
vijay shankar12-Jun-08 1:25 
Generalvc4.0 Pin
Riick12-May-08 5:01
Riick12-May-08 5:01 
GeneralSomething isn't right here Pin
alan9326-Aug-07 11:05
alan9326-Aug-07 11:05 
GeneralRe: Something isn't right here Pin
Priya_Sundar17-Mar-08 19:40
Priya_Sundar17-Mar-08 19:40 
GeneralDoes not work for a simple Win32 APP Pin
samwise_i16-Mar-07 12:30
samwise_i16-Mar-07 12:30 
GeneralRe: Does not work for a simple Win32 APP Pin
anvil_of_crom18-Nov-07 23:27
anvil_of_crom18-Nov-07 23:27 
Questionhow do you rollback ? Pin
sperate132-Feb-07 2:50
sperate132-Feb-07 2:50 
AnswerRe: how do you rollback ? Pin
sperate132-Feb-07 4:15
sperate132-Feb-07 4:15 
QuestionIs This Needed? Pin
alan9327-Jul-06 3:43
alan9327-Jul-06 3:43 
AnswerRe: Is This Needed? Pin
fiuygloINS18-Aug-07 6:42
fiuygloINS18-Aug-07 6:42 
Generalworks like a charm Pin
vjedlicka18-Jul-06 5:01
vjedlicka18-Jul-06 5:01 
GeneralUsing Windows XP Styles in WIN32 Applications Pin
prem kumar singh20-Dec-06 19:51
prem kumar singh20-Dec-06 19:51 
GeneralVisual Studio 2005 linking errors. Pin
Xanblax14-Dec-05 13:29
Xanblax14-Dec-05 13:29 
GeneralRe: Visual Studio 2005 linking errors. Pin
Xanblax14-Dec-05 13:36
Xanblax14-Dec-05 13:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.