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.
Related articles
Q.Why are some of the keys on my keyboard doing strange...
Q.Is my phone’s Bluetooth any use?
Q.Can I switch boot drives so that I can work on older...
Old Street roundabout is being touted by the Government as the UK's answer to Silicon Valley, but it seems our best innovations are coming from all over the UK
|
|
|
|
|
Computeractive Excel (2010) Online tutorialPrice: £19.99 |
Computeractive Word (2010) Online TutorialPrice: £19.99 |
Computeractive Powerpoint (2010) Online TutorialPrice: £19.99 |
Angry BirdsPrice: £9.99 |
Back Issue CD-Rom 14 (2011)Price: £15.99 |