Site hosted by Angelfire.com: Build your free website today!

Home
DelphiZeus
Visual Themes in XP
An XML file as a Manifest enables XP Themes

Home



Windows XP Visual Themes

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 -
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity
    version="1.2.3.4"
    processorArchitecture="*"
    name="Company.Product.Program"
    type="win32"
  />
  <description>Program Description Here</description>
  <dependency> 
    <dependentAssembly>
      <assemblyIdentity
        type="win32" 
        name="Microsoft.Windows.Common-Controls"
        version="6.0.0.0"
        publicKeyToken="6595b64144ccf1df"
        language="*"
        processorArchitecture="*"
      />
    </dependentAssembly>
  </dependency>
</assembly>

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 -
      name="Microsoft.Windows.Common-Controls"
and
      version="6.0.0.0"

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.
  Please Notice - Changing the data of element attributes in the -
<?xml>
<assembly>
<dependency>
element tags can PREVENT your program from running in XP. (You will get a system ERROR message, and the program will not run). So you should use the code for these elements as presented above. Your options seem to be -

  1. if this manifest is with your program then it has the XP Themes visual control drawing style.
  2. if this manifest is NOT with your program then it will NOT have the Themes visual style.
The "Program Information" XML data element arguments, that you can change in this XML file (that I know of) are in the first <assemblyIdentity> and the <description> element tags, which are in the RED color in the XML code above. The first is in <assemblyIdentity>

the Red Text below can be changed

version="1.2.3.4"
      If you want to, , you can place the Version numbers of your program here.

name="Company.Product.Program"
      Text for names, that would indicate your program's name. But I have no Idea about the syntax used here or what the separator periods may or may not be used for. I have used text without periods and it will not prevent the program from running.

Next is the description element -

<description>Program Description here</description>
      The Red Text can be changed to a description of your program.
MS says that this <description> element is OPTIONAL, so you can leave it out of the XML file. Just leave out all of the element tag above.

. . . . . HOWEVER, I could not find any time that these data element arguments (version, name and description) are ever used by the operating system, so you probally do not need to change the text in these, since it may not be used anyway (In XP).
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 -

  • <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  • <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  • <dependency>   </dependency>
  • <dependentAssembly>   </dependentAssembly>
  • <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" publicKeyToken="6595b64144ccf1df" language="*" processorArchitecture="*" />
Technical Note:   The <assemblyIdentity> arguments of   language="*"   and   processorArchitecture="*"   can be changed. The   *   in these arguments is for a wildcard or "Any-Type", and the system does NOT check for language or processorArchitecture with the "*" argument. It is possible to add a language or processorArchitecture argument such as   processorArchitecture="x86"   but I did not see any references in the MS manifest information for the values you might use for these arguments. If you feel that the language or processorArchitecture are important to your program's functioning in XP, then you can try and find out about these, But I do not know about this and will not offer any comments or code about it.

    NOTE : Smaller File Size -
If you want to have a smaller mainifest XML file you can use this manifest code below instead. It does not have a <description> element tag and has fewer spaces and line feeds. . .
      Manifest XML Code -

<?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



Getting your program to use a Manifest File

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;

  and

InitCommonControls;

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 Resources

You 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 -
program InUnits;

uses
  InUnitsU, ApiFormU;

{$R *.RES}
{$R XPTheme.RES}

begin
if MakeApp then
  RunMsgLoop;
end.
Red text is the added code. Now recompile the InUnits program.
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


       

Lesson -     One  Two  Three  Four  Five  Six  Seven  Eight  Nine  Ten  Eleven  Twelve  Thirteen  Fourteen




H O M E