Vista Gadgets
Written by Ian Elliot   
Sunday, 28 June 2009
Article Index
Vista Gadgets
Second Gadget
A debug flyout
Are we there yet?
Date setting
Advanced gadgets

 

The Vista Sidebar contains mini-applications called "Gadgets" that are built using HTML, XML and script. Vista comes with a range of pre-built Gadgets including Weather, online news and a CPU monitor. If your memory goes back as far as Windows 98 you might remember an earlier attempt at providing similar facilities - Active Desktop. This sank without trace mainly due to worries about security and the lack of always-on Internet connection. This time around the idea looks a much better proposition and it's worth creating Gadgets - and it isn't difficult.

Vista Gadgets

Vista standard Gadgets

A basic Gadget

The first important thing to realise is that a Gadget is just an HTML page plus script run in the context of the Sidebar. However the Sidebar does provide a range of functions and other facilities that are not standard in a browser window. It is mostly this "Gadget API" that makes Gadgets, and what you can do with them, more than just a web page.

The simplest Gadget HTML file is:

<html>
<head>
<title>My First Gadget</title>
</head><body>Gadget Starter</body>
</html>

This HTML file can be created using NotePad or any text editor you care to use that can save a simple text file.

You need to create a new directory in:

\Users\user name\AppData\Local\
Microsoft\Windows Sidebar\Gadgets\

Gadgets stored in this directory are only available to the named user. If you want your Gadget to be available to all users you need to create the directory in:

\Program Files\Windows Sidebar\Gadgets

If you can't see these directories then make sure you have used Folders,Options to display hidden files.

The directory name has to take the form name.gadget. For our example create a directory, in the Gadget directory of your choice, called MyGadget1.gadget and save into this directory the HTML listed above in a file called MyGadget1.HTML. All that we need to complete our first Gadget is an XML manifest file that describes the Gadget to the Sidebar so that it can load it and provide additional information to the user.

There are lots of optional XML tags that can be included in the manifest but the simplest manifest for our Gadget is:

<?xml version="1.0" encoding="utf-8" ?>
<gadget>
<name>My First Gadget </name>
<version>1.0.0.0</version>
<hosts>
<host name="sidebar">
<base type="HTML" apiVersion="1.0.0"
src="/MyGadget1.html" />
<permissions>Full</permissions>
<platform minPlatformVersion="1.0" />
</host>
</hosts>
</gadget>

The name tag isdisplayed in the Gadget Gallery and on the Sidebar window and the version is used to check and resolve problems if different versions of the same Gadget are installed. The Hosts section will in the future allow you to specify a range of possible hosts for the Gadget. At the moment the only possibility is the Sidebar. The base tag gives the type of the Gadget, always HTML; the name of the source file containing the HTML; and script for the Gadget, the file that is actually loaded if the user selects the Gadget. The manifest has to be stored in the same directory and it is always called gadget.xml. With these two files stored in the Gadget directory you can now click on the "+" button at the top of the Sidebar and the Gadget Gallery will appear complete with My First Gadget, which will be installed if you double click on it.

It's worth saying at this early stage that you can package a Gadget in a ZIP or CAB file. For example, if you place all of the Gadget's files, not including the directory, into a ZIP and change the extension to .gadget, then your Gadget will be installed into the Gadget directory when the user double-clicks on it.

fig2

My First Gadget ready for installation

<ASIN: 0672329689>



Last Updated ( Sunday, 28 June 2009 )