.: Home :: Contact Us :.  
  



Hans Dietrich Software

free and licensed software

   

Manifests and Theming in Windows Applications image image image image

Beginning with XP, all versions of Windows have supported theming, a term applied to the visual effects that collectively make controls more attractive and more responsive to mouse (cursor) movements. In this article, I will discuss what theming is and practical techniques for implementing theming across multiple platforms and multiple versions of Visual Studio, from VS6 through VS2010.

Theming Demos

Here are some screenshots to illustrate what theming is:

XP - Theming Disabled
screenshot
XP - Theming Enabled
screenshot
Win7 - Theming Disabled
screenshot
Win7 - Theming Enabled
screenshot

As you see, the themed demos display nice colors and 3D effects for the controls. In addition to the above visual effects, when theming is enabled, controls are displayed in a "hot" state when the cursor hovers above them.

How to Enable Application Theming

For MFC and other C++ programs, theming is enabled using manifests. The remarkable thing about manifests is that no source code changes are required to your application, in order to take full advantage of theming. The only requirement is that a manifest be included.

How to Include an Application Manifest

When you create a new MFC project with VS2008 or VS2010, you will find the following added to stdafx.h:
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' 
                version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' 
                language='*'\"")
#elif defined _M_IA64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' 
                version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' 
                language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' 
                version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' 
                language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' 
                version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' 
                language='*'\"")
#endif
#endif
If you are not interested in compiling the application with VS6, then you are done. The above #pragma commands will work for any processor architecture, for both VS2008 and VS2010.

However, if you want to compile under both VS6 and a recent version of Visual Studio, then this won't work. If you tried the same lines from stdafx.h in VS6, you will see this:

Linking...
ManifestTest.obj : warning LNK4044: unrecognized option "manifestdependency:type='win32' 
    name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' 
    publicKeyToken='6595b64144ccf1df' language='*'"; ignored
ManifestTestDlg.obj : warning LNK4044: unrecognized option "manifestdependency:type='win32' 
    name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' 
    publicKeyToken='6595b64144ccf1df' language='*'"; ignored
StdAfx.obj : warning LNK4044: unrecognized option "manifestdependency:type='win32' 
    name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' 
    publicKeyToken='6595b64144ccf1df' language='*'"; ignor
So the VS6 linker does not recognize the syntax of the #pragma commands. This brings us to the second way of embedding a manifest.

Embedding a Manifest File

The second way is just as simple as adding lines to stdafx.h. To embed a manifest file, we will add some lines to the resource (.rc) file:
/////////////////////////////////////////////////////////////////////////////
//
// RT_MANIFEST
//

1                       RT_MANIFEST             "app.manifest"
The app.manifest file looks like this:
<?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="appname"
    type="win32"
/>
<description>description</description>
<dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="*"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
</dependency>
</assembly>
Note that the line processorArchitecture="*" means that the same manifest file can be used for both x86 and x64 platforms.

OK, we edit the .rc file, comment out the lines in stdafx.h, and then make one other change: we change the settings for the Manifest Tool.

screenshot

And when we run the demo, it is themed.

Summary

To embed a manifest file for use in both VS6 and more recent versions of Visual Studio, include app.manifest in the application .rc file.

Revision History

Version 1.0 - 2011 April 8

  • Initial public release.

Free download