Home |
Visual Themes in XP An XML file as a Manifest enables XP Themes |
Home |
If you are working in the XP windows version or newer, then you will notice that all of the programs that are presented here have NOT had the XP Themes visual styles for the controls (buttons, combo boxes). That is because there is no part of these programs that tell the XP system to use the "Theme" visual style with them. A "Manifest File" is what signals the system to use the Theme drawing for main window borders and system controls. The XP windows system will look for a "Themes Manifest" in the compiled resources of a program, or for a "Manifest File" in the program's folder, to determine if the Themes visual style is to be used. If it finds the "Themes Manifest", it will change the way it draws form borders, buttons, combo boxes and many other controls. In this lesson, you will be shown how to create the "Themes Manifest" (an XML file) and use it in your programs. |
The XP Theme Manifest
Application Manifest is a term that MS uses for an XML data file that has operating system requirements in it. The windows XP system or newer will look in two places for an "Application Manifest" file to use with your program. The system will first look for the manifest file in the Folder where the program is located. If it does not find that file, then the system looks in the compiled resources of that program for the resource type of RT_MANIFEST (value 24) and the resource identifier of CREATEPROCESS_MANIFEST_RESOURCE_ID (value 1). It will read this manifest as a data container in the XML format. This XML file will have several data element tags with some data that the system may or may not use. I do not want to try and explain using the XML markup language, and you do NOT need to know anything about using XML inorder to to make and use an XP Application Theme Manifest. You can copy and then paste the next XML code into a text editor (NotePad) and save it as a manifest file. . . Here is the code for a XP Theme manifest XML file. . . Manifest XML Code -
This Application Manifest is used by the system to find out about the requirements of a program inorder to function correctly, things like language and processorArchitecture. The element attibutes that give information about using Themes is the - The version of 6 for the Common-Controls Library tells the system this program can use Themes. You can see several Data Element Tags like <assembly> and <dependency>, and you might think there are some "Options" for you that will depend on the "Data" you place in the arguments of the data element tags, but as far as I can determine, in this - manifestVersion="1.0" - you may have few options. Changing of the data in the XML element attributes does NOT seem to offer many options for the programmer.
the Red Text below can be changed version="1.2.3.4" name="Company.Product.Program"
Next is the description element - <description>Program Description here</description>
So you can use this same Theme Manifest code in all of your programs that need XP Visual Themes, although you could change the version, name and description to something that is better for you like "a Joe Smith Program". WARNING - If I changed the following elements, it would produce a system error message and the program would NOT run in XP -
NOTE : Smaller File Size - |
<?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="*" name="Co.Prd.Prg" type="win32" /> <dependency><dependentAssembly><assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" publicKeyToken="6595b64144ccf1df" language="*" processorArchitecture="*" /> </dependentAssembly></dependency></assembly> |
Some web pages at Microsoft Developers Network about Themes, where you can find some general information about themes and manifests - Using Windows XP Visual Styles Using Windows XP Visual Styles With Controls on Windows Forms |
First I will show you how to place a manifest file in your programs folder which will tell the system to have Visual Themes applied to the system controls in that program, this method is not used very much. But a better method (used by most programs) might be to place the manifest in the compiled resources of the program, which I will describe later.
Manifest in Folder You can just pace a "Manufest File" in the program's folder. Copy and Paste the manifest XML code above into a plain ASCI text editor like MS NotePad. Now save this code as a text file with a file extention of .MANIFEST in the same folder as the program. You will need to have the program's file name as the manifest file name, like this - MyProgram.exe.manifest With TWO periods in the file name. You MUST use this manifest File Name arangement (program.exe.manifest) in order for the system to find and use the manifest file. . .In lesson Five, if you used the same program file name as Fonts.dpr, your program will compile to file name Fonts.exe , to use this Fonts program as a "Theme" program you will save the XML code above as file name - Fonts.exe.manifest in the folder where Fonts.exe is located. If you now run the Fonts.exe program in XP with themes enabled, it should now have the visual Themes applied to the controls (buttons) of the Fonts program.That's right, you do NOT have to recompile or change the Fonts.exe program at all, just have a manifest file. You can save this manifest file for most any 32 bit windows GUI program (even older program made before XP release), and the standard controls of that program may then paint in the Themes style (if the common controls have been initilized). IMPORTANT - But this will not always work correctly for a program, the program MUST call the API function InitCommonControls; in order to have the controls (even standard controls like BUTTON) be visible. If the program does NOT call InitCommonControls; , it will still run in XP, but the controls will NOT be seen on the form. So you will need to add InitCommonControls; to your program's code if it is not there, and recompile it. In the first Lessons here at DelphiZeus, I did NOT include the InitCommonControls; , so if you add the manifest to these first programs like - Dialogs.exe, Dialog2.exe or ButEdit.exe, the program will run, but you will NOT see any controls (buttons, edits, static) because the InitCommonControls; is not in those programs. so if you want to add the manifest to these, you will also need to add the uses CommCtrl; andInitCommonControls; to their code and recompile them.Technical Note -The Fonts.exe program does not have the InitCommonControls; in it's code, but still works with the manifest, this program does have the Commdlg in the uses clause, and calls the system Font Dialog Box, so I guess this will also allow the manifest to work, although I could NOT find any MS information reference about this. Manifest in Program's ResourcesYou can also compile a resource with the Delphi resource compiler BRCC32.exe, and have this manifest file in the resource, then place this resource in your program. When the program runs in XP, the system first looks in the folder and then in the programs resources for the manifest file. A resource manifest may be better, because the manifest file is contained inside of your program. First save the Text of the manifest XML code (copy and paste from the manifest XML code above) as a file named "ThemeXP.manifest" where the BRCC32.exe can find it. Next you will need to create a Resource Creation file with this one line of code - 1 24 "ThemeXP.manifest"IMPORTANT - You MUST use the 1 and 24 resource Identifiers or it will NOT work. The constant CREATEPROCESS_MANIFEST_RESOURCE_ID is defined as 1 , and the constant RT_MANIFEST is defined as 24 . Now save this Resource Creation file as file name "XPTheme.rc" . You must compile this XPTheme.rc file with the Delphi BRCC32.exe RES compilier, and you should get a resource file named "XPTheme.RES" . You will need to include this resource in your program, and be sure that InitCommonControls; is also in the program code. In the last lesson about InUnits you could change the .DPR program file like this -
Now when you run the InUnits.exe file in XP, it should have the XP Theme style controls. NOTE: About the resource file names above. You do not need to use the same file names that I did for the manifest file or the resource creation file. Most of the instuction references about manifest resources will name the manifest file with a .MANIFEST file extention, but you can use ANY file name or extention such as "Theme.xml" or "XPM.txt" for this resource file. . . . And you can use any resource creation file name like "ManXP.rc" , "manifest.rc" or "theme.rc" . |
I have talked about the first version and use of the Application Manifest file, this first version seems to have limited usefulness, and can "Turn On" Theme use for a program. You should be able to make your programs run with the "Theme" style look by including the Application Manifest. |
Next
The following Lesson is about a "One Size Fits All" universal unit called MakeApp.
13. MakeApp a Reuseable Universal Unit