Make a Vista sidebar gadget
Vista users will be aware of the sidebar and the gadgets that it can contain. Although the sidebar has been dismissed by many as a hog of screen real estate, I personally think it is quite useful. I suspect that most SWiSH’ers are not aware of how easy it is to make great looking sidebar gadgets using SWiSH Max2 or SWiSH miniMax2.
A Sidebar Gadget is specified by:
1. gadget.xml – an xml file that defines the author, the name and the purpose of the gadget. This information is displayed in the Gadget Gallery (the dialog that is displayed when you add a new Gadget to the sidebar).
2. .html and other support files (e.g. .swf) that define what the gadget does. Gadgets are run by Internet Explorer 7 (or later) without any surrounding frame. Typically Gadget functionality is the result of Javascript programming, however by using Max2 or miniMax2, the Javascript component can be reduced to about 5 lines. These Javascript lines can be simply cut and pasted into the html produced by Max2 or miniMax2.
3. Optionally a png, jpeg or gif image file can be referenced by the .xml file to allow an icon of the gadget to be displayed by the Gadget Gallery.
Step 1. The xml file.
Create a file named “gadget.xml” in the folder:
C:\Users\<username>\AppData\Local\Microsoft\Windows Sidebar\Gadgets\yourname.gadget\
The folder name yourname.gadget can be called anything as long as it is unique and ends with .gadget
The xml should contain the following code which can be edited using a text editor such as notepad to suit your needs.
<?xml version="1.0" encoding="utf-8" ?>
<gadget>
<name>SWiSH Clock Gadget</name>
<namespace>SWiSHzone.com</namespace>
<version>1.0.0.0</version>
<author name="SWiSHzone.com">
<info url="www.swishzone.com" />
</author>
<copyright>© 2009</copyright>
<description>Example Clock gadget based on Max2 clock example</description>
<icons>
<icon height="48" width="48" src="gadget.PNG" />
</icons>
<hosts>
<host name="sidebar">
<base type="HTML" apiVersion="1.0.0" src="analog_clock.html" />
<permissions>Full</permissions>
<platform minPlatformVersion="1.0" />
</host>
</hosts>
</gadget>
The significant lines that may require alteration are:
<icon height="48" width="48" src="gadget.PNG" />
and
<base type="HTML" apiVersion="1.0.0" src="analog_clock.html" />
The first line should be modified so that it references whatever image you have chosen for your icon. The second line should be modified to refer to the html file of your movie. The .html, .swf and image files should all reside in the same gadget folder. The other lines can be altered to your needs. Once you have completed your gadget, see what the xml file looks like by viewing the details associated with your gadget.
Step 2. The html file and main movie
Create your movie so that it has a width of no more than 130 pixels. 130 is the maximum size that can be displayed by the side bar. The source file analog_clock.swi is included in the Clock zip file referenced below. I used the analog clock example as the basis of my gadget. I wanted a gadget that not only showed the time, but also showed the current date. To save sidebar space, I also wanted it to optionally display a calendar so that future dates could be looked up quickly without having to load an additional gadget.
Using SWiSH Max2, or miniMax2, export your movie to html+swf. Save both files to the gadget folder. In a text editor, open the html file and add the following above the </head> item:
<script type="text/javascript">
document.onreadystatechange = function()
{
if(document.readyState=="complete")
{
document.body.style.height = 130;
document.body.style.width = 130;
document.body.style.margin = 0;
}
}
</script>
This defines the java script that will setup the initial size of the gadget. The quoted size should match the export size of your movie. Note that the width must be no more than 130.
Step 3. The Image icon
Run the .html file in a browser and use Alt-Print Scrn to capture an image of the running gadget. In Paint (or some other image application) cut the required image out of the screen capture and save that image to gadget.PNG (or whatever image file format you choose). Update the .xml file if you name the image file something else.
Your gadget is now ready to run. You can add the gadget to the side bar using the + button at the top of the side bar. If the Windows sidebar is not visible, press the Vista orb start button then type sidebar into the search area and press enter. This will guide you to activate the sidebar.
Samples
I have provided two sample gadgets clock and calc.
These are intended to demonstrate how to create a gadget. Simply unzip the contents including sub folders into:
C:\Users\<username>\AppData\Local\Microsoft\Windows Sidebar\Gadgets\
i.e. you’ll end up with
C:\Users\<username>\AppData\Local\Microsoft\Windows Sidebar\Gadgets\swishclock\…
Select the ‘+’ button on the sidebar and this new gadget should be visible in the list of available gadgets. Right-click and select ‘Add’ to include the sidebar, or drag-drop it onto the sidebar.
That’s it. Have fun and feel free to ask questions.
Notes:
I have tried to keep this example as simple as possible. The following notes may assist users that attempt to create a more advanced gadget.
Although the following are possible, this gadget does not do the following:
1. Resize when detached from the sidebar.
2. Provide support for user settings. (this requires knowledge of javascript and flash variables).
If your movie captures mouse drags (eg. my calculator demonstration), then it may not be possible to position the gadget within the sidebar unless you resize the gadget to be 120 wide and 130 high, but leave the java script section with a size of 130 x 130. This leaves a border on the left and right hand sides so that the gadget can be dragged.
I attempted to use a transparent background using “wmode”. However I could not get this to work. I assume it is related to IE7 and its display of gadgets. If anyone has any luck with this, please leave a comment.
I noticed that the originally published clock gadget did not update the displayed date after midnight. This was corrected and the source files in this article were updated on March 27 2009. The revised source should show 2009.03.27.0 in the xml version information.
For more information on gadget creation, google “develop sidebar gadgets vista”.


(10 votes, average: 4.70 out of 5)

when i try to add it to the sidebar by ziping it and adding .gadget i get “this is not a vaild gadget package.”
i made a simple “hello world” with this as a source: http://laymensterm.blogspot.com/2008/12/create-vista-sidebar-gadget.html
oh and, i can’t just drag the folder with helloworld.gadget as folder name, wont show up in the sidebar.
thanks in advice.
When you zip the gadget file, do not include the surrounding folder.
With the examples I have provided, unzip the clock example to a folder.
Then rezip the files:
analog_clock.html,
analog_clock.swf,
gadget.png and
gadget.xml
as myclock.zip and then rename that zip file to be myclock.gadget
Double clicking on myclock.gadget installs it on my system.
I don’t really want to comment on other peoples work / blogs, but at a guess, check that the .xml file is named gadget.xml and that it is in the correct format. I think Microsoft may have updated the sidebar xml format between vista pre-release and main release so some gadget information is unfortunately out of date.
hello, i just read your tutorial and found it helpful though it doesnt seem to solve my prob.
So well I just wanted to give the undocked notes-gadget a different/more realistic look by rotating it a little on the right (or left). To keep the text inline with the rotated frame i learnt i must inject the g:text rotation element into the .js files. I thought it was easy but after several attempts i realised my limitations. Could you take a look at the gadget and modify it for me ? I really dont know who else i can ask. Desperate.
thank you,
anne.
http://msdn.microsoft.com/en-us/library/aa359347.aspx
http://img257.imageshack.us/img257/6789/captureur4.jpg
Hi Anne,
I’m sorry, it sounds like your solution requires javascript, and from your description, I think your javascript is better than mine. If the notepad was authored in Max2 (or Flash) you would only need to alter the _rotation attribute of the movie clip. Unfortunately the notepad was not created in Flash.
Regards,
Jon
The style of writing is very familiar . Have you written guest posts for other bloggers?
Hi,
I have written other blog articles for SWiSHzone.com but not for other external blogs.
Regards,
Jon
I did as you said, and even downloaded your, it installs but i add and windows explorer comes up asks for permission to use flash player, then it goes to sidebar but its just a box with a red x at the top. The same for yours and mine.. Any suggestions?
Hi,
Unfortunately I do not see the same thing.
When you open a flash web page in windows explorer do you get the same question? Try opening the gadget html page directly in IE rather than via the sidebar. If you do get the same question then you probably need to look into your player / browser settings. It may be that you have not yet enabled the flash player active X component to work with IE. Unfortunately I do not know exactly what to suggest.
Regards,
Jon
i have new idea from this article. thank!
Hi!
This is so cool, You get to make your own sidebar gadget. If I could I would do it. and if you’re new to this place, Try it, What’s the worst thing that can happen? I did it!
Love, Me!!!!!!
Hi!
This is so cool, You get to make your own sidebar gadget. If I could I would do it. and if you’re new to this place, Try it, What’s the worst thing that can happen? I did it! It’s an asome place to be!!!!!!!!!!!!!!!!
Love, Me!!!!!!
I’m haveing the same problem. I had the clock gadget working before. I created my own, it installed, I tried to add it and IExplorer wanted to install Adobe software. I let it run and the only thing that appears is a box with a red “X”.
i have new idea from this article. thank!
Thanks for the hint… Looking forward for Windows 7 anyway…
I am also looking forward to windows 7.
Vista was not one of their best.
“”"very informative, thanks =)”"