Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Apply the New Vista APIs to Sidebar Gadgets, Part 2 : Page 4

Explore the various Windows Vista Sidebar gadget objects and how they can be used to enhance the functionality of your gadget.

If your gadget needs to play system sounds or sound files, use the System.Sound object.

The beep() method generates a simple beep tone on the system's speakers, while the playSound() method plays a specified sound file:

System.Sound.beep(); System.Sound.playSound( "\\windows\\media\\Windows Critical Stop.wav");

Time and Time Zones
You can obtain information about the different time zones using the following objects:
  • System.Time
  • System.Time.TimeZone
The System.Time object enables you to obtain time information for the current system. It exposes a System.Time.timezones collection of System.Time.TimeZone objects.

Here's how you can obtain the collection of System.Time.TimeZone objects:

var timeZones = System.Time.timeZones;

The System.Time object has only one method, getLocalTime(), which returns the local time based on the specified time zone. It also has only one property, currentTimeZone, which returns the current time zone as a System.Time.TimeZone object.

The following example shows you how you can display the current time in the current time zone:

var result = document.getElementById("result"); var timeZone = System.Time.currentTimeZone; result.innerHTML = "Local Time: " + System.Time.getLocalTime(timeZone);

Figure 4. Time Zones: Retrieving all the details of the various time zones available.

The System.Time.TimeZone object contains detailed information about a specific time zone. The following example shows you how to retrieve all the details of the various time zones available (see Figure 4 for the output):

var result = document.getElementById("result"); var timeZones = System.Time.timeZones; for (var i=0; i<timeZones.count; i++) { var oTimeZone = timeZones.item(i); result.innerHTML += "Name: " + oTimeZone.name + "<br/>" + "Bias: " + oTimeZone.bias + "<br/>" + "Display Name: " + oTimeZone.displayName + "<br/>" + "DST Bias: " + oTimeZone.DSTBias + "<br/>" + "DST Date: " + oTimeZone.DSTDate + "<br/>" + "Standard Bias: " + oTimeZone.standardBias + "<br/>" + "Standard Date: " + oTimeZone.standardDate + "<br/>" + "Standard Display Name: " + oTimeZone.standardDisplayName + "<br/>"; }

Vista's Potential
Now that you've examined the various objects exposed by Windows Sidebar, your gadget should be capable of harnessing all the additional functionalities available in Windows Vista.

Wei-Meng Lee is a Microsoft MVP and founder of Developer Learning Solutions, a technology company specializing in hands-on training on the latest Microsoft technologies. He is an established developer and trainer specializing in .NET and wireless technologies. Wei-Meng speaks regularly at international conferences and has authored and coauthored numerous books on .NET, XML, and wireless technologies. He writes extensively on topics ranging from .NET to Mac OS X. He is also the author of the .NET Compact Framework Pocket Guide, ASP.NET 2.0: A Developer's Notebook (both from O'Reilly Media, Inc.), and Programming Sudoku (Apress). Here is Wei-Meng's blog.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.