Click here to Skip to main content
15,881,248 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.7K   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

 
AnswerRe: Visual Studio 2005 linking errors. Pin
MKlucher15-Dec-05 18:28
MKlucher15-Dec-05 18:28 
GeneralRe: Visual Studio 2005 linking errors. Pin
Xanblax16-Dec-05 8:35
Xanblax16-Dec-05 8:35 
GeneralRe: Visual Studio 2005 linking errors. Pin
4jb4-Jul-09 8:56
4jb4-Jul-09 8:56 
GeneralRe: Visual Studio 2005 linking errors. [modified] Pin
sciencekrishnan20-Jul-09 22:31
sciencekrishnan20-Jul-09 22:31 
GeneralRe: Visual Studio 2005 linking errors. Pin
sciencekrishnan22-Jul-09 1:06
sciencekrishnan22-Jul-09 1:06 
GeneralRe: Visual Studio 2005 linking errors. Pin
NoName235-Apr-07 5:03
NoName235-Apr-07 5:03 
GeneralExtending this to applications running in Win 2000 Pin
Andyzyx16-Jul-05 12:21
Andyzyx16-Jul-05 12:21 
GeneralRe: Extending this to applications running in Win 2000 Pin
Anna-Jayne Metcalfe6-Oct-05 7:07
Anna-Jayne Metcalfe6-Oct-05 7:07 
GeneralMSFlexGrid Control not themed Pin
Joe Colosi8-Jun-05 4:18
Joe Colosi8-Jun-05 4:18 
Generalneed help please Pin
KingKonni22-Feb-05 20:57
KingKonni22-Feb-05 20:57 
GeneralWorks great Pin
richard sancenot3-Aug-04 22:23
richard sancenot3-Aug-04 22:23 
GeneralTrouble with CToolbar Pin
manero30-Jan-04 2:57
manero30-Jan-04 2:57 
GeneralRe: Trouble with CToolbar Pin
What's my name?5-Feb-06 13:23
What's my name?5-Feb-06 13:23 
QuestionRe: Trouble with CToolbar Pin
flyingxu8-Nov-06 15:29
flyingxu8-Nov-06 15:29 
GeneralRe: Trouble with CToolbar Pin
kj_kho30-Jul-08 19:23
kj_kho30-Jul-08 19:23 
QuestionHow to enable XP style in MFC dll Pin
salonent8-Oct-03 19:39
salonent8-Oct-03 19:39 
AnswerRe: How to enable XP style in MFC dll Pin
dick m23-Dec-04 19:49
dick m23-Dec-04 19:49 
AnswerRe: How to enable XP style in MFC dll Pin
Shail_Srivastav15-Feb-05 1:21
Shail_Srivastav15-Feb-05 1:21 
AnswerRe: How to enable XP style in MFC dll Pin
Anonymous4-May-05 13:10
Anonymous4-May-05 13:10 
GeneralRe: How to enable XP style in MFC dll Pin
marijan_s3-Aug-07 10:43
marijan_s3-Aug-07 10:43 
GeneralWin 2000 Pin
olis23-Sep-03 3:14
olis23-Sep-03 3:14 
GeneralRe: Win 2000 Pin
MKlucher24-Sep-03 16:55
MKlucher24-Sep-03 16:55 
Generalpassword character Pin
Anonymous17-Sep-03 9:16
Anonymous17-Sep-03 9:16 
GeneralRe: password character Pin
MKlucher20-Sep-03 10:38
MKlucher20-Sep-03 10:38 
GeneralRe: password character Pin
jutapy22-Sep-03 20:56
jutapy22-Sep-03 20:56 

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.