Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Apply the New Vista APIs to Sidebar Gadgets, Part 1  : Page 6

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


advertisement
Machine Information
You can obtain detailed information about the processors and power status on your system with the following objects:
  • System.Machine
  • System.Machine.CPU
  • System.Machine.PowerStatus
System.Machine.CPU and System.Machine
The System.Machine.CPU object contains information about the CPU of the computer running the gadget. The System.Machine object exposes a collection of System.Machine.CPU objects through its System.Machine.CPUs collection.

The following code example displays the detailed information of the current machine hosting the gadget and then displays the name and usage percentage for each CPU (in a multicore processor).

var result = document.getElementById("result"); result.innerHTML = "Available Memory: " + System.Machine.availableMemory + "MB<br/>"; result.innerHTML += "Total Memory: " + System.Machine.totalMemory + "MB<br/>"; result.innerHTML += "Processor Architecture: " + System.Machine.processorArchitecture + "<br/>"; //---get all CPUs--- var cpus = System.Machine.CPUs; //---display name and usage of each CPU--- for (i=0; i<cpus.count; i++) { result.innerHTML += "<b>" + cpus.item(i).name + "</b><br/>"; result.innerHTML += cpus.item(i).usagePercentage + "<br/>"; } cpus = null; result = null;

Figure 4 shows the result when the gadget is run on my computer.



Figure 4. Running the Gadget: Displaying the detailed information of a system.

System.Machine.PowerStatus
The System.Machine.PowerStatus object returns detailed information about the power status of the computer hosting the gadget.

The System.Machine.PowerStatus object has one event, powerLineStatusChanged, which specifies a function that is called whenever the system is switched from adapter power to battery power, or vice versa.

The gadget in Listing 5 shows the detailed power status of your computer. When the page is loaded, you first print out the power status of your computer. You then set the powerLineStatusChanged event to the PowerLineStatusChanged event handler so that this event handler will be called whenever there is a change in power status (such as when you switch from battery power to adapter power, and vice versa).

The PowerLineStatusChanged() function is fired whenever there is a change in power status (such as the notebook computer is connected to a power source).

This article has examined the first four objects exposed by Windows Sidebar. Stay tuned for Part 2, which will discuss the email, network, sound, and time and time zone objects.



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.

 

 

Sitemap