Microsoft & .NET.NETSeven Steps to Taking Advantage of Windows XP Themes

Seven Steps to Taking Advantage of Windows XP Themes

Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

There’s been a lot written about how to integrate your application with Windows XP themes, most of it complete hogwash. I’ve personally wasted hours trying to figure out how to get it working.

All the online tutorials I’ve encountered, including MSDN, are critically flawed in their “how to” description. This top tip, however, hopefully isn’t.

So, what are Windows XP themes? Themes are a sort of limited, user-selected “skin” for the operating system, a “make it look nice” feature introduced in XP and to be continued and expanded upon in future versions of Windows.

Providing theme support in your applications provides your application with that “integrated” Windows look and sets it up for greater customization in later versions of the operating system.

But how? Firstly, we design our application as normal, occasionally setting a button style to “System“. Then we create a manifest file from a template I’ll provide and add it as a resource to our final .EXE. The contents of this manifest file tell the application to bind itself to “ComCtl6”, the Windows Common Controls component which will then draw the controls for your application and apply the themes as relevant.

And here are the seven easy steps to get it all up-and-running:

  1. Design your application as normal. Where possible, set the FlatStyle property of your controls to System. This is very important.
  2. When you’re ready to roll out the final version of your application, compile your program. Open the Bin folder through Windows Explorer, right-click and select the Version tab. Make a note of the file version exactly as displayed here.
  3. Create a new file on your machine and call it “MyManifest.manifest”. Using Notepad, or similar program, add the following text to this file:
  4. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly 
              manifestVersion="1.0">
    <assemblyIdentity
        version="Insert Your Exact Version Number Here"
        processorArchitecture="X86"
        name="Name of Application"
        type="win32"
    />
    <description>Description of Application</description>
    <dependency>
        <dependentAssembly>
            <assemblyIdentity
                type="win32"
                name="Microsoft.Windows.Common-Controls"
                version="6.0.0.0"
                processorArchitecture="X86"
                publicKeyToken="6595b64144ccf1df"
                language="*"
            />
        </dependentAssembly>
    </dependency>
    </assembly>
    
  5. Back in Visual Studio .NET, open your actual assembly—typically, the .EXE file you just compiled. Click File -> Open -> File… and then select your assembly.
  6. Right-click anywhere on the new window and select ‘Add Resource’. Choose ‘Import’ and select your .MANIFEST file. You will be asked for a ‘Resource type’. Type “RT_MANIFEST” and click OK.
  7. In the Property window, change the ID of the strange screen that has appeared from 101 to 1. Click File -> Close to close this window, and accept any changes. Do the same with the next window, displaying details about your .EXE file, again ensuring you save changes.
  8. Go back to Windows Explorer and give your .EXE application a test run; then uncork the champagne! If you get an error message, it’s likely you either typed out the .MANIFEST file incorrectly, or used the wrong version number—in which case go back and try again.

Figure: My quick and easy Windows XP themed application

About the Author

Karl Moore (MCSD, MVP) is an experienced author living in Yorkshire, England. He is author of numerous technology books, including the new Ultimate VB .NET and ASP.NET Code Book (ISBN 1-59059-106-2, $49.99), plus regularly features at industry conferences and on BBC radio. Moore also runs his own creative consultancy, White Cliff Computing Ltd. Visit his official Web site at www.karlmoore.com.

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories