![]() |
Desktop Development »
Desktop Gadgets »
General
Intermediate
License: The Code Project Open License (CPOL)
Lights Out - Building a Gadget for the Vista Side BarBy AcousticAn introduction to building sidebar gadgets for the Vista side bar |
Windows, Visual Studio, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||


I�ve been enjoying
C:\Users\<user name>\AppData\Local\Microsoft\Windows Sidebar\LightsOut.gadget\
<?xml version="1.0" encoding="utf-8" ?>
<gadget>
<name>Lights Out</name>
<namespace>microsoft.windows</namespace>
<version>1.0.0.0</version>
<author name="Microsoft Corporation">
<logo src="icon.png" />
</author>
<copyright>� 2006</copyright>
<description>Lights Out - A classic puzzle game</description>
<icons>
<icon height="48" width="48" src="icon.png" />
</icons>
<hosts>
<host name="sidebar">
<base type="HTML" apiVersion="1.0.0" src="LightsOut.html" />
<permissions>Full</permissions>
<platform minPlatformVersion="1.0" />
<defaultImage src="drag.png" />
</host>
</hosts>
</gadget>
The actual "guts" of a gadget are handled by standard javascripts or vbscripts, and the Gadget API. That�s great news for those who already know a scripting language since there�ll be virtually no ramp up time for you. In this example, all of the Lights Out UI is built with standard javascripts; nothing special at all. Rather than outline how Lights Out works, which isn�t terribly interesting, let's take a look at how javascript (or any IE supported scripting language) integrates with the Gadget API.
function loadSettings()
{
// Assign an event handler/function to the Gadget
// API onSettingsClosing event
System.Gadget.onSettingsClosing = settingsClosing;
//Reading settings using the Gadget API
if (System.Gadget.Settings.read("SettingExist") == true)
{
var index = System.Gadget.Settings.read("currentPuzzle");
InitializeLayout(index);
ShowCurrent();
}
self.focus;
document.body.focus();
}
// Handles the API's settings closing event
function settingsClosing()
{
...
}
The code for the Gadget API can be run inline with your script as if it's an extension of the javascript or vbscript languages. The good news is that it makes writing gadget scripts very easy. The cost of ease, however, is that you can't develop the gadget is Windows XP. I ended up using XP for writing the initial script and drafting the images, then switching to Vista to finalize the settings and layout.
The most important aspect of the API in this example is the way events are handled. The settings page close event, for example, is easily registered by setting the onSettingsClosing event property to a function within your script. This model is very useful for responding to events such as the settings page opening or closing, or the entire gadget being docked or undocked. In this Lights Out example, the settings page allows the user to visually select a level to play. If the user clicks the OK button, the main UI's script responds to the onSettingsClosed event in order to read the newly changed settings and load the appropriate level.
On a side note, this gadget could have used a Flyout just as easily as a settings page. I just felt like using settings for this example since it's more commonly used.
The settings API contains for methods for storing runtime settings, and seems to work much like a standard .NET hashtable. The System.Gadget.Settings namespace contains for methods for settings management,
read(<setting name>)
readString(<settingName>)
write(<setting name>, <setting value>)
writeString(<setting name>, <setting value>)The down side to the settings is that they�re not persisted when the gadget is closed. Persisted settings are possible, but beyond the scope of this introductory article. Here's a sample of the settings page, also built on standard HTML and javascript.
I hope you see now that a little HTML, javascript, and maybe some CSS are all you need to play with the Side Bar. It's reall is almot too simple.
The last step to creating a gadget is packaging it for deployment because, of course, you'll want to share your amazing creating with everyone. This is arguably the easiest step of the entire process. To create an installable gadget package you only need to do the following:
That's it! It's just a renamed zip file. Users simply execute the .gadget file, and Vista handles the rest of the installation including creating the correct folder, copying all the files, and adding a new instance of the gadget to the side bar (For those of you running Vista, the LightsOut.gadget file insize the source code download is fully functional).
There you have it! Creating gadgets is quick, easy, and requires almost no new learning. For those interested, I spend about 70% of the time for the Lights Out gadget creating the images. That�s saying quite a lot if you ask me.
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 15 Jan 2007 Editor: Chris Maunder |
Copyright 2007 by Acoustic Everything else Copyright © CodeProject, 1999-2009 Web18 | Advertise on the Code Project |