Click here to Skip to main content
15,891,184 members
Articles / Web Development / HTML
Article

Windows Vista Gadgets

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
24 Sep 2011CPOL1 min read 29K   408   17   6
This article explains how to create a Windows Vista Gadget
AddGadget_small.jpg

Sidebar.jpg

Introduction

In this article, I have described the steps to create a Windows Vista Gadget. I have demonstrated the article with an example of a digital clock gadget.

Background

Windows Vista Gadgets are small applications which are hosted on the Sidebar. Windows Vista Gadgets are simply made up of HTML and JavaScript code.

User-created gadgets are stored in the following folder:

C:\Users\<current user>\AppData\Local\Microsoft\Windows Sidebar\Gadgets

Every gadget is stored in its own folder under the above mentioned folder. The folder name should be the same as the gadget name followed by the .gadget extension.

Every gadget has two files associated with it. One is an HTML file with embedded JavaScript code to define the functionality of the gadget. The other file is an XML file called gadget.xml and is also known as the gadget manifest.

Using the Code

In the HTML file, the style element is used to specify the layout and format of the gadget. The script element is used to specify the content and working of the gadget. Finally a span element is used to display the gadget.

Following is the HTML/JavaScript code for our digital clock gadget (DigitalClock.html):

HTML
<html>
<head>
    <title>Digital Clock</title>
    <style>
        body
        {
            margin: 0;
            width: 130px;
            height: 65px;
        }
        #gadgetContent
        {
            width: 130px;
            top: 24px;
            text-align: center;
            position: absolute;
            font-family: Verdana;
            font-size: 10pt;
        }
    </style>
    <script language="javascript">
        function showtime()
        {
            var now=new Date();		// Find current date
            var h=now.getHours();	// Find current hour
            var m=now.getMinutes();	// Find current minute
            var s=now.getSeconds();	// Find current second
            h=(h<10)?"0"+h:h;		// Convert hour to 2 digits
            m=(m<10)?"0"+m:m;		// Convert minute to 2 digits
            s=(s<10)?"0"+s:s;		// Convert second to 2 digits
            gadgetContent.innerHTML="<h2><font color='red'>"+h+":</font>
		<font color='lime'>"+m+":</font><font color='cyan'>"+s+"</font></h2>";
					// Set time on the span element
            setTimeout("showtime()",1000);	// Display time after every one second
        }
    </script>
</head>
<body onload="showtime()" bgcolor="black">
    <span id="gadgetContent"></span>
</body>
</html>

The gadget manifest file is an XML file which describes the properties of the gadget.

Following is the code of the gadget.xml file:

XML
<?xml version="1.0" encoding="utf-8" ?>
<gadget>
    <name>DigitalClock</name>
    <namespace>Example.Azim</namespace>
    <version>1.0.0.0</version>
    <author name="Azim">
        <info url="www.example.com" />
    </author>
    <copyright>Azim</copyright>
    <description>Digital Clock</description>
    <hosts>
        <host name="sidebar">
            <base type="HTML" apiVersion="1.0.0" src="DigitalClock.html" />
            <platform minPlatformVersion="1.0" />
            <permissions>Full</permissions>
        </host>
    </hosts>
</gadget>

Perform the following steps to add the gadget to the sidebar.

  • Create a folder called DigitalClock.gadget in the following folder:
    C:\Users\<current user>\AppData\Local\Microsoft\Windows Sidebar\Gadgets 
  • Copy the files DigitalClock.html and gadget.xml into the DigitalClock.gadget folder.
  • Right click on the sidebar and select Add Gadgets... option.
  • Select the DigitalClock gadget.

Points of Interest

This was a very simple gadget. But more complex gadgets can be created as your knowledge of JavaScript becomes better.

History

  • 24th September, 2011: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Instructor / Trainer NIIT, India
India India
I am a trainer by profession. Currently I am working with iFuture Technologies(India) as a Senior Faculty. I enjoy programming as a hobby. During my career I have seen the growth and decline of many technologies, many of them being my favorites like Flash, WPF, Windows Mobile Development. Few of my current favorites are Android, Xamarin and Python, though I also like traditional and evergreen languages like PHP, C#, Visual Basic and Java.

Apart from computers, my favorite pastime is bicycling.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey7-Nov-12 0:34
professionalManoj Kumar Choubey7-Nov-12 0:34 
GeneralRe: My vote of 5 Pin
Azim Zahir7-Nov-12 18:08
Azim Zahir7-Nov-12 18:08 
QuestionThanks Pin
Drjslab24-Sep-11 22:57
Drjslab24-Sep-11 22:57 
AnswerRe: Thanks Pin
Azim Zahir24-Sep-11 23:17
Azim Zahir24-Sep-11 23:17 
GeneralGadgets Pin
DaveAuld24-Sep-11 20:04
professionalDaveAuld24-Sep-11 20:04 
Good start and basic intro, however, I would remove the reference to Vista, as this may put others off.

You may be interested in my gadget articles;
1) Windows 7 Sidebar Gadget - CodeProject Reputation Watcher[^]

2) GadgetPacker - Windows Gadget Build Tool[^]

Cheers,
Dave
Find Me On: Web|Facebook|Twitter|LinkedIn

Folding Stats: Team CodeProject


GeneralRe: Gadgets Pin
Azim Zahir24-Sep-11 22:36
Azim Zahir24-Sep-11 22:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.