Wednesday, January 31, 2007


Creating a Sidebar Gadget for Windows Vista


This gadget is provided only for educational purposes and does not endorse in any way for using the gadget to view Dilbert cartoon strip on your Vista sidebar, for personal or commercial use. If you want to see the daily cartoon strip you need to go to the website All Dilbert cartoon related images are copyrighted materials © Scott Adams, Inc.


With the broadest ever release of Microsoft Vista World wide, 2007 opens the door to an era of gadget development. Gadgets are small, light weight but powerful applications which stay on the Windows Vista Sidebar. The coolest thing about a gadget is that it is not dependent on any particular language or technologies, and you don't need to be a rocket scientist to create a gadget. Basic knowledge of HTML and Javascript is enough for that, but you can also program in any Microsoft language for windows/web to extend a gadget. Once you know the basic rules of gadget development, only sky is the limit for productivity and innovations.

This article describes a simple Windows Vista Sidebar Gadget which delivers the Daily Dilbert cartoon to your desktop.

There is a RSS Feed available from which gives you the contents of the daily dilbert in a form of an xml file. The idea behind, is to read that file, parse the content and display it beautifully in your sidebar. The user can view cartoons for last 5 days. The benefit is, for all those (like me) who want to start there day with the Dilbert strip, don't have to go to the website or even open the feed, to see it. Just click on the date in the sidebar gadget and a flyout window will show you the cartoon of the day.

This article also discusses five common features of Sidebar gadget development:

  1. Create: A simple gadget with minimum files
  2. Use of Ajax: Read an XML file from a website (RSS feed) Get and parse the RSS Feed for the Dilbert cartoon from
  3. Parse XML : Extract the path of the image
  4. Rich Display: The gadget's look and feel
  5. FlyOut: A simple implementation of Windows Sidebar Flyout to display the image

In Action

To hold your interest, here is how it looks in the sidebar.

DailyDilbert in Action

Lets Begin

Create a simple Gadget

To create a no-gimmick gadget you need just two files, an html file (main.html) and an xml file for configuration (gadget.xml), both of these files need to be inside a folder DailyDilbert.Gadget which should be placed inside Windows Sidebar/Gadgets folder

An HTML can be just a simple html with some text and a height: 200px; width: 130px; to accomodate in the size of the Gadget window

An XML file (manifest) with the name Gadget.xml is necessary to be in the same folder with the following format

More information from this link

No rocket science here , name of the gadget "Daily Dilbert" as seen above, namespace basically to group more than one gadget (reserved for future use) you can write here "mynamespace". MinPlatformVersion. Required. The expected value is "1.0."

You have the icon.png which will be displayed at the "Add gadget" Window below and the logo.png which will be displayed near the copyright section in the right bottom corner of the "Add gadget" Window. dragicon.png which will be used when the Gadget is dragged inside the "Add Gadget" Window. The base type gives the type of application you have in the sidebar here we have HTML.

"Permission" controls the amount of permission in the gadget. A "Full" permission is required, if you want to access a webpage through the gadget. With these two files you can deploy and test your gadget in the sidebar. <permission> tag and <type> tag will be more flexible in future version of gadget development.

Normally a Gadget will have these files

Gadget Manifest: An XML file defining the gadget properties, including name, icon and description
HTML file Defines the core code for the gadget
HTML settings file Exposes gadget settings for the user to change
Images, Script and Style Sheets for use in the HTML
Icon For use in the gadget picker

Here is the overview of the architecture

Architecture overview

You can get more details on these here

That said, let's build our gadget now as per the initial idea Daily Dilbert. More information on elements of sidebar manifest can also be found here

Images Used

When you create a sidebar gadget one of the important things you might want to take care is , the look and feel

The Drag Icon:
About image:

These are the images used for the gadget

Get the RSS Feed

Once you have your gadget images ready , i created an html file main.html and a gadget.xml file with the configuration below The html file will have five elements "DIV" to get the feed data

The Feed for the Gadget

We have the URL which we call using an MSXML2.XMLHTTP object the core of the AJAX till the feed gets loaded. Here is the magial javascript for this

function getRSS() {
loading.innerText = "Connecting...";
rssObj = new ActiveXObject("Msxml2.XMLHTTP");"GET", "", true);
rssObj.onreadystatechange = function() {
if (rssObj.readyState === 4) {
if (rssObj.status === 200) {
loading.innerText = "";
rssXML = rssObj.responseXML;
page = 0;
if (chkConn) { clearInterval(chkConn); }
} else {
var chkConn;
loading.innerText = "Unable to connect...";
chkConn = setInterval(getRSS, 30 * 60000);
} else {
loading.innerText = "Connecting...";

Now since we have the feed we need to create a flyout out of the image in the feed. Here is the parseRSS function which does this.

Here is how it looks when you click on a standard feed weekdays a sunday clip will be different.

function parseRSS(page) {
if (!page) { page = 0; }
start = page * 5;
end = (page * 5) + 5;
rssItems = rssXML.getElementsByTagName("item");
rssTitle = null; rssAuthors = null; rssSummary = null; rssLink = null;

if (end > rssItems.length)
end = rssItems.length
for (i=start; i<end; /> rssItems.length)
rssTitle = rssItems[i].firstChild.text;
rssSummary = rssItems[i].getElementsByTagName("description");
rssSummary = rssSummary[0].text;
var position_http=rssSummary.indexOf('http');
var position_gif=rssSummary.indexOf('.gif');
var position_jpg=rssSummary.indexOf('.jpg');
var position_img =0;
System.Gadget.Flyout.file = "DilbertFlyout.html";

if (position_gif >0)
rssItem= Mid(rssSummary,position_http,position_img + 4);

cell = i - (page * 5);
document.getElementById("cell" + (cell)).innerHTML = '

<div onclick="showFlyout(\'' + rssItem + '\');" align="center"> '
+ Mid(rssTitle,10,25) + '
';//'+ cell + '::' + i + '::' + page + '::' + start + '::' + end + '
document.getElementById("cell" + (cell)).title =
"Click to show/hide";


What we do is check and parse the image string from the description tag of the feed and set the size of the flyout window accordingly. A sunday strip is a JPEG and a normal weekday image is a gif image with different sizes as you can see above. Once you have the feed and the image URL you call a function which creates the Dilbert in the Flyout Window

function BuildDilbertOfTheDay()

document.write('<"" />');

more information on the flyout here

To resize the flyout we need a small onload function on the flyout.html Body Onload event

function startUpPage() {
//Resize the page
= System.Gadget.document.parentWindow.myWidthVariable;
= System.Gadget.document.parentWindow.myHeightVariable;

Daily Dilbert in Action: A cartoon clip for sunday


Article History

And thanks

For coming so far! I hope you find this useful, and add a comment if you do and take care.

awesome article, thanks
Very cool! But I found a couple of bugs in your gadget... Are you planning on releasing an update (to the DailyDilbert.gadget)?

First bug:

When in "minime" mode, all the date links read: "April 22". They work for the correct day (bottom is "today", next up is "yesterday", etc.), but they all have the same date listed.

Second bug:

When we get a "Sunday" strip, it is taller than the regular daily strip, so it doesn't quite fit in the flyout. It cuts off the bottom 10% of the strip (which doesn't usually hurt it too much - but it does mean you miss some of the subtle image gags).

Other than this - this is my favorite gadget!!! Thanks for the cool work.
robin get the latest version 2.5
Eggselent! (that's me drumming my fingers together)

This is way cool! Thanks again!

Dilbert has gone prime time!

For the past week or two, this gadget has been displaying some WEIRD dates. the links themselves seemed to work and I decided today to go look for a fix. No fix here. HOWEVER, this GREAT TUTORIAL taught me how to fix it MYSELF!

I replaced all instances of ''

with ''

in the DailyDilbert.js, reloaded the gadget and VIOLA!


I am DEFINITELY gonna try to make a Gadget now!
or you can DOWNLOAD version 2.5 from here

or Direct Link
Post a Comment

Links to this post:

Create a Link

<< Home