|
|
Control Panel applet
Originally the Windows Template Library (WTL) was touted as a library for
creating small and efficient tools in C++. You would think, "Oh,
a library for creating Control Panels Applets then. They are small.".
I actually use WTL for nearly all my Windows projects;
some are quite large with more than 200,000 lines of code.
WTL just seems more straight forward compared to using MFC or
even other frameworks with gnarly C++ syntax and WTL is certainly
not a library designed just for small tools.
The Windows Control Panel was one of the areas in Windows Vista that
received some interesting improvements. The Control Panel view has
moved from a strictly pick-an-icon view, to a task-oriented view where you
locate a task (textual link) that matches your desired action.
The Control Panel API dates back to the early Windows. Applets are basically
code compiled in a DLL which exports a The information needed to create a Control Panel Applet is.
Using the codeThis is the minimal code you need to write to create an applet DLL.
The macro takes the form:
The Canonical Name can be used in Windows Vista to launch your applet. The C++ class you define must derive from the CCPlAppletBase
class. The library will manage the communication with the Shell to initialize
the Control Panel properly, and eventually ends up calling the C++ class'
ShowApplet function to allow you to display the Property Page
dialog or other user interface.
You'll need to define a couple of string and icon resources in the resource file.
Make sure to include as many different resolutions as possible in the
icon resource, so it looks good on Windows Vista. Windows Vista will
allow the user to switch to Humongous Large Icon mode that use
256x256 icons in hi-res colours.
The resource names are related to the internal name used when you defined the applet in the code with CPLAPPLET_ENTRY.
There are a couple of alternative ways to register your applet
through the library which will allow you to customize the
resources and the way they are loaded, but this is the easy way.
The sample above takes advantage of the DllRegisterServer
mechanism for installing a COM DLL. Basically it allows you to install
the applet using the
The applet is registered under the "System and Maintenance" category. To change the category you can add a special macro to the applet class.
The following categories are available. Names varies depending on Windows platform.
The
Then import the XML file into the project under the "XML"
resource type.
In the XML task file you describe what command to execute when a given task
is picked by the user.
A neat little trick is to use the new
Given the correct canonical name of your applet, the Control tool will launch it.
Use the Page argument to have a task launch your applet with a custom argument.
You can parse this argument in the ShowApplet function of your C++
class. Most of the time you'll want to pass the Property page number to
give focus to when the applet is initially shown.
And finally - to make sure that your Property Page user interface
is displayed with the correct theming (Windows XP and Vista visual
styles) you should add a manifest.
Then after adding it, change the manifest resource ID in the resource file
from
and add a define to the top of your stdafx.h header.
Don't ask. It's just one of those things you're required to do when
you have a DLL which may have needs (theming, in this case) that
can overrule what needs the hosting executable file has.
If your development environment can automatically generate a manifest
file during the link stage, just make sure that the project's manifest
settings are set to Isolation Aware.
It also appears that the manifest file must contain a trustInfo element in order to prevent an annoying
Application Compatibility popup. You'll need it anyway
if you're aspiring to the Designed for Windows Vista logo,
but be aware of the dreaded
Blue Screen of Death.
Have a look in the sample code available below to see an
example of a working manifest file.
More new thingsFinally there is a couple of other things I haven't mentioned.
Windows Vista finally breaks free of the DLL limitation and allows
you to embed the Control Panel functionality in your Also more widely used in Windows Vista are the Shell Folders. Several of the Control Panel applets defined by Microsoft do not show the regular Property Page interface but rather navigates into the Explorer window and displays its information inlined in Explorer. This can be seen with the Fonts folder, and the Network and Sharing folder. These applets are really Shell Extensions that are rooted below the Control Panel virtual folder. Hopefully I'll be able to bring you some sample code for this kind of applet later. Source Code DependenciesMicrosoft WTL 8.0 LibraryInstallation Guide
See AlsoA Shell Folder Control Panel for Windows VistaDownload Files
Written by Bjarke Viksoe. Article submitted 12/20/2007. To the top
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||