Seven Steps to Taking Advantage of Windows XP Themes
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:
- Design your application as normal. Where possible, set the FlatStyle property of your controls to System. This is very important.
- 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.
- Create a new file on your machine and call it "MyManifest.manifest". Using Notepad, or similar program, add the following text to this file:
- 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.
- 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.
- 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.
- 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.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" 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="126.96.36.199" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> </assembly>
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.