I have been doing software development professionally and personally so I decided to check out what this new gadget thing for Vista is. Well I finished up my first gadget which is just a simple combination of javascript and css. The link is as follows for the zip file that contains the gadget: http://www.anthonyw.net/SystemInfo.gadget.zip
Additionally I have done some things with enumerating CPUs so that if anyone makes a call to System.Machine.CPUs they can process all of them. The following code is easy to follow.
<script type="text/javascript">
var compName = "Your computer is: " + System.Environment.getEnvironmentVariable("COMPUTERNAME") + "\n";
var availMem = "Available memory: " + System.Machine.availableMemory + "mb\n";
var procType = "Processor Type: " + System.Machine.processorArchitecture + "\n";
var cpuObj = System.Machine.CPUs;
var cpuCount = System.Machine.CPUs.count;
var cpuStats = "Processor count: " + cpuCount + "\n";
var cpuTemp = "";
var procStat = "";
var intervalID;
function getInfo()
{
intervalID = setInterval(refresh, 1000);
}
function refresh()
{
availMem = "Available memory: " + System.Machine.availableMemory + "mb\n"
for(var i = 0; i < cpuCount; i++)
{
cpuTemp = cpuObj.item(i);
var utilization = cpuTemp.usagePercentage;
procStat = procStat + "CPU " + (i+1) + ": " + Math.round(utilization) + "%\n";
}
gadgetContent.innerText = compName + availMem + procType + cpuStats + procStat;
procStat = "";
}
</script>
</head>
<body onload="getInfo()">
<div id="gadgetContent"></div>
</body>

Just wrote my first gadget.
Emadkb
Oh, that's bad, we want those documented and used! Thanks for mentioning that they went away, we'll get them back up soon.
Brian
Rituparna MSFT
If anyone is looking for an example of how to use the above documented features, this is how I decided to implement it in my gadget:
<script type="text/javascript">
var compName = null; //computer name
var availMem = null; //available memory
var procType = null; //processor type
var cpuObj = null; // cpuObjects
var cpuCount = null; // number of processors
var cpuStats = null; // count string
var cpuTemp = null; // temp variable
var procStat = null; // processor stats
var intervalID = null; // timer id
var visible = null;
function initialize()
{
//do some initialization stuff
compName = "Your computer is: " + System.Environment.getEnvironmentVariable("COMPUTERNAME") + "\n";
availMem = "Available memory: " + System.Machine.availableMemory + "mb\n";
procType = "Processor Type: " + System.Machine.processorArchitecture + "\n";
cpuObj = System.Machine.CPUs;
cpuCount = System.Machine.CPUs.count;
cpuStats = "Processor count: " + cpuCount + "\n";
cpuTemp = "";
procStat = "";
for(var i = 0; i < cpuCount; i++)
{
cpuTemp = cpuObj.item(i);
var utilization = cpuTemp.usagePercentage;
procStat = procStat + "CPU " + (i+1) + ": " + Math.round(utilization) + "%\n";
}
gadgetContent.innerText = compName + availMem + procType + cpuStats + procStat;
procStat = "";
System.Gadget.visibilityChanged = isVisible;
intervalID = setInterval(update, 1000);
}
function isVisible()
{
if (System.Gadget.visible)
{
visible = true;
}
else
{
visible = false;
}
}
function update()
{
if (visible)
{
// perform updates here
isDirty = false;
availMem = "Available memory: " + System.Machine.availableMemory + "mb\n"
for(var i = 0; i < cpuCount; i++)
{
cpuTemp = cpuObj.item(i);
var utilization = cpuTemp.usagePercentage;
procStat = procStat + "CPU " + (i+1) + ": " + Math.round(utilization) + "%\n";
}
gadgetContent.innerText = compName + availMem + procType + cpuStats + procStat;
procStat = "";
isDirty = true;
}
}
Greg_Dodd
Now since this polls every second it def did eat cpu cycles in the background but that has now changed.
Thanks
byronfromwesleyan
Well I have only coded in javascript for about a period of 4 hours now since yesterday. Is thare a set of commands such that i can do a boolean test Persay isFocused
I acutally found an answer, the pages is located here:
http://blogs.msdn.com/sidebar/archive/2006/08/18/706495.aspx - Brian T's page.
Chuck Cobb
visibilityChanged Event
This event is triggered when the gadget visibilty has changed, and will run the specified script code when the event occurs.
Syntax
Event property System.Gadget.visibilityChanged = handler
Event Handler Parameters
visible Property
Called from within a gadget as a means to determine whether or not the gadget is visible.
Syntax
Possible Values
Example
System.Gadget.visibilityChanged = areWeVisible;
{
if (System.Gadget.visible)
{
//Gadget now visible
} else {
//Gadget now hidden
}
}
simon_
You're still firing a timer and running a little javascript every second; try this:
devstuff