Simple clear advice in plain English

Grappling with gadgets

Discover how to create a Windows gadget and some new uses for C++ on the web

The init() function loads settings and initialises the gadget, while the two div containers will be updated dynamically with the latest data. The < g:background> element is one of three presentation tags specific to gadgets. In this case it sets the background to a transparent bitmap.

Countdown.html has four Javascript functions, which you would normally save in an external file, but for this example that is not necessary.

The functions are:
timeUntil(targetDate): a utility function that calculates the time remaining before the specified date.
update(): calls timeUntil, and updates the div areas with appropriate text.

init(): loads values from settings to set two global variables, a string that describes the event (theWhat) and the date it takes place (theWhen).

Finally it calls setInterval to set up a timer to make regular calls to the update function.
settingsclosed(event): an event handler that fires when the setting dialogue closes.

There are global variables and statements at the top of the script block:
var theWhat;
var theWhen;
var intervalid;

// Handler for the settings closing event.
System.Gadget.onSettingsClosed = settingsclosed;
//create a settings UI
System.Gadget.settingsUI = “settings.html”;

The settings.html file has a table with four input fields. It could be improved by a Javascript date selector. It has two functions: loadsettings(), which initialises the fields from existing values, and closesettings, the event handler that fires when the dialogue closes.

How to save settings
The Windows Gadget API includes provision for a settings dialogue, and for loading and saving settings. You use two methods:
System.Gadget.Settings.writeString()
and System.Gadget.Settings.readString()
to save and restore key ­ value pairs.

During development if you save settings and then remove Gadget to make some changes, the settings do not persist. Even if you simply remove and replace the gadget from the sidebar, the settings disappear.

Reader Comments

   

Add your comment

All fields must be completed. Your email address will not be displayed or used to send marketing messages.

All messages will be checked by moderators before appearing on the site.

See our Privacy Policy for more information.

Related articles

Q&A: Old games, new Windows

Run old PC games on newer operating systems

Hands on: Coding for the desktop

How to develop widgets for the Yahoo Widget Engine, formerly Konfabulator

Hands On - Web development - To Flash or not to Flash

A reader's query about problems with their browser's Back button when using framesets got me thinking about changing web standards. The Back button may seem a minor detail, but the problem...

Question & Answer

Q.Why are some of the keys on my keyboard doing strange...

> Read the answer

Q.Is my phone’s Bluetooth any use?

> Read the answer

Q.Can I switch boot drives so that I can work on older...

> Read the answer

Best deals on the web

img

Samsung RV520-A07

£359.98- Buy it now

img

Acer Aspire 5750G (LX.RXP02.019)

£399.99- Buy it now

img

Apple MacBook Pro (MD313B/A)

£904.37- Buy it now

Latest issue & subscription deals

Poll

Are you concerned about viruses that target mobile phones?

Jargon Buster

Computing terms explained in plain English

Restore point

A Windows backup of system files and settings.

Great shopping deals from Computeractive