Click here to Skip to main content
12,559,073 members (41,554 online)
Click here to Skip to main content
Add your own
alternative version


51 bookmarked

Applying Windows XP Visual Styles to Applications

, 30 Sep 2003 CPOL
Rate this:
Please Sign up or sign in to vote.
Apply Windows XP visual styles to applications without a rebuild.


I've wanted to write an article for The Code Project as it's provided me with some very useful information in the past and it would be nice to give something back. The main problem was finding an appropriate topic for a first article, which I hope I've now found. So here goes...


With Windows XP came themes, which is basically just a new look for all the common controls such as buttons and scroll bars. The following images give you an idea of what to expect.

Sample image

Classic Windows

Sample image

Windows XP Themes

This takes a bit of getting used to, especially if you've been using Windows for a long time, but if you stick with it for a while I'm sure you will learn to like it as I have. The downside to the new themes is that you need to tell Windows that your application should make use of the new style common controls. As far as I'm aware there are two ways of achieving this:

  • Create an application manifest file named MyApp.exe.manifest in the same directory as the application
  • Create an application manifest file and add it to the list of resources built into the application

Neither option was appropriate for our software package as it contains over 500 functions, each being a separate EXE file. This would have meant generating several hundred manifest files and, if the first method was selected, modifying the CD production mechanism to add the files to the installation CD and modifying the setup program to install them. This would have been a very time consuming process and also not very flexible should the manifest file format change in the future.

The solution I came up with was to dynamically add the application manifest resource outside of the build procedure which gives us the advantage of keeping the application manifest in one source module allowing changes to be made quickly should the format change. This article explains how to do it.

Using the code

The code is contained within one function, shown below, that can be simply dropped into any program as required. The only drawback is that the resource manipulation API functions are only supported under NT based operating systems. I've tried to document the code as fully as possible but if there is anything missing or unclear, please let me know and I will change it.

// Add the XP style manifest to a specified applcation 
DWORD AddManifest(const char *szFilespec, 
   const char *szProgName,const char *szProgDesc)
    // This is the formatting string used to create the manifest
    static LPSTR szFormat=    
     "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
     "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
            "<assemblyIdentity "
            "version=\"\" "
            "processorArchitecture=\"x86\" "
            "name=\"%s\" "
            "type=\"win32\" />" 
            "<assemblyIdentity type=\"win32\" "
                "name=\"Microsoft.Windows.Common-Controls\" "
                "version=\"\" " 
                "publicKeyToken=\"6595b64144ccf1df\" "
                "language="\""*\" " 

    // Load the EXE so we can check if the resource already exists
    HMODULE hMod=LoadLibrary(szFilespec);
    if (NULL==hMod)
    // Attempt to find the manifest (resource type 24, id 1)

    // The EXE must be released before we can update the resources

    // If the manifest resource is not already present in the EXE
    if (NULL==hRes)
        // Load the program ready for updating
        HANDLE hUpdate=BeginUpdateResource(szFilespec,FALSE);
        if (NULL==hUpdate)

        // Allocate a buffer to store the manifest string
        char *szManifest=new char[strlen(szFormat)+
                                  (szProgName ? strlen(szProgName) : 0)+
                                  (szProgDesc ? strlen(szProgDesc) : 0)+1];

        // Format the manifest to include the
        // specified program name and company name
           szProgName ? szProgName : "",szProgDesc ? szProgDesc : "");
        // Add the manifest resource to the list
        // of updates to be made (resource type 24, id 1)
        BOOL bUpdateSuccessful=UpdateResource( hUpdate,
        // If the update was rejected
        if (!bUpdateSuccessful)
            // Save the last error code
            DWORD dwLastError=GetLastError();

            // Release the memory allocated for the manifest string
            delete[] szManifest;

            // Abandon the resource changes and exit

        // Release the memory allocated for the manifest string
        delete[] szManifest;

        // Apply the change to the specified EXE file
        if (!EndUpdateResource(hUpdate,FALSE))

    // Resource modified successfully

Points of interest

The most annoying problem I encountered while developing this function is that the manifest resource cannot be added if the specified file is open in any way. This includes the use of LoadLibrary() to check if the resource already exists! All the functions used return success values and you will be totally unaware that the update has failed until you try to run the application.

More information

My main source of information for this article can be found on MSDN here. Alternatively there is an excellent article by Kluch on this site here.


Well that's it, my first article written and ready to be picked apart by the Code Project community. I'd just like to say a quick "thank you" to Kluch whose article gave me both the inspiration and information necessary to write this article. I await your comments...


01-10-2003 - First edition


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Steve Thresher
Software Developer (Senior) Axis First
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralRe: How about dll projects? Pin
isCrazy31-Mar-04 5:12
memberisCrazy31-Mar-04 5:12 
GeneralRe: How about dll projects? Pin
Hatim Rih13-Apr-04 22:49
sussHatim Rih13-Apr-04 22:49 
GeneralRe: How about dll projects? Pin
timtanbin27-Sep-04 14:25
membertimtanbin27-Sep-04 14:25 
GeneralRe: How about dll projects? Pin
Ramesh Soni27-Dec-06 2:55
memberRamesh Soni27-Dec-06 2:55 
GeneralRe: How about dll projects? Pin
norbert_barbosa29-Mar-06 21:14
membernorbert_barbosa29-Mar-06 21:14 
GeneralRe: How about dll projects? Pin
Steve Thresher29-Mar-06 21:49
memberSteve Thresher29-Mar-06 21:49 
GeneralRe: How about dll projects? Pin
sciencekrishnan21-Jul-09 0:41
membersciencekrishnan21-Jul-09 0:41 
GeneralPerfect for me! Pin
porcus15-Jan-04 11:56
sussporcus15-Jan-04 11:56 
This was a perfect solution for me! You see, I have been trying to figure out how to add the manifest as a resource using a command-line utility without having to do this through the IDE after building the executable... but I have been unable to figure out how to do this in a more automated fashion until now.

Using this nifty little utility, I created a custom post-build event that ran this program upon creation of my output executable. This way, the manifest is added automatically, without an external manifest file needing to exist in any particular location. How convenient! Big Grin | :-D

Still, I would love to know of a more conventional way to add resources (such as an assembly manifest for the purposes of getting the visual styles to work) to an already-built executable using a command-line utility instead of having to load the assembly in the .NET IDE and manually doing adding the resource. I would indeed be intrigued if anyone has a solution for this!...

Notwithstanding, this was a brilliant idea! Smile | :) Thanks!

Paul Miller
GeneralRe: Perfect for me! Pin
Steve Thresher16-Jan-04 0:56
memberSteve Thresher16-Jan-04 0:56 
GeneralCould not get it to compile. Pin
WREY3-Oct-03 20:01
memberWREY3-Oct-03 20:01 
GeneralRe: Could not get it to compile. Pin
Steve Thresher4-Oct-03 1:44
memberSteve Thresher4-Oct-03 1:44 
GeneralRe: Could not get it to compile. Pin
WREY4-Oct-03 8:28
memberWREY4-Oct-03 8:28 
GeneralRe: Could not get it to compile. Pin
Steve Thresher6-Oct-03 9:13
memberSteve Thresher6-Oct-03 9:13 
GeneralRe: Could not get it to compile. Pin
WREY6-Oct-03 9:40
memberWREY6-Oct-03 9:40 
GeneralNice Article Pin
TomP2-Oct-03 4:00
memberTomP2-Oct-03 4:00 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161026.1 | Last Updated 1 Oct 2003
Article Copyright 2003 by Steve Thresher
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid