RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Driving Sidebar Gadgets with ActiveX and C#

Although simple Sidebar gadgets are "DHTML applets" with limited functionality, you can enhance them using .NET components exposed as ActiveX controls through COM Interop.

he Windows Sidebar is one of the most striking features of the new Vista desktop. It's a sort of virtual "desktop appliance" which hosts DHTML applets in Windows Explorer. With Vista and its Sidebar, you can enhance the formerly static Windows desktop with myriad widgets and doodads, appropriately named "Gadgets." By default the Sidebar comes packed with some useful (or maybe just fun) gadgets, such as an RSS streamer, a sticky notepad, a clock/calendar, a CPU meter, and one of those 'slide the tile' games where you try to make the complete picture—but who needs another one of those?

Why the SideBar? Why Now?
You might ask why Microsoft has bothered to raise the Sidebar to desktop prominence in Vista—after all, isn't that what the Office Suite and Start menu are for? Well yes, but the Sidebar has more features. For example, you can hide the Sidebar, or float it somewhat transparently over other apps. It's convenient, because it makes commonly-used applications easy to find, and it's easily recallable from a hidden state by clicking a tiny icon in the system tray. Another purpose of the Sidebar is to "look pretty!" That's no joke—it's in the documentation. And as long as people who are more artistic than I am are writing the majority of gadgets, I do believe that will remain a primary reason for the Sidebar's existence.

Author's Note: Vista was still in RTM at the time of this writing, so there is little "user provided" documentation on the subject.

What's in a Gadget?
A gadget is a DHTML applet. These applets consist of HTML (the user interface), JavaScript (interactivity), and other web content files. Gadgets are almost exactly like any other DHTML applet that you'd host in Internet Explorer, except that they are packaged slightly differently, and have a special API extension available to allow them to integrate with or "plug-in" to the hosting system.

You can store gadget files wherever you like in the file system—with one caveat: The top-level folder must be named <Something>.gadget, where <Something> is a name of your choice.

Every gadget has an XML file that contains a manifest file. The manifest is a simple XML file containing information that describes the gadget and its parts to the host. The gadget manifest must be named gadget.xml and reside directly within the <Something>.gadget folder. Here's an example gadget manifest.

<?xml version="1.0" encoding="utf-8" ?>
  <name>QuickMailr </name>
  <author name="Dave Dolan">
    <info url="www.davedolan.com" />
  <description>Email a tiny bit of text using an Active X 
      control written in C#!</description>
    <host name="sidebar">
      <base type="HTML" apiVersion="1.0.0" src="gadget.html" />
      <platform minPlatformVersion="0.3" />
  <version value="" MinPlatformVersion="0.1"/>
The elements of a gadget manifest file are similar for all gadgets. All gadget manifests contain standard elements such as the name, version, author, and src attributes under the gadget element. The name and version elements are self explanatory. The author element lets you give yourself credit (or blame) for the gadget, and the optional info element under it lets you provide a website link. The hosts element is there so you can specify a hosting application; although at the present time, there is only one available host—the Sidebar, which you specify in the manifest in lowercase letters as in the preceding example. The permissions element theoretically allows you to vary the rights afforded your gadget, but for the time being you must use Full (which turns out to be quite a lot of permissions).

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date