Richards Blog My life in SD

1Jun/100

Windows Gadget – gadget.xml

This is an example of how to create a gadgets XML Manifest. The structure is pretty simple to do, and a the Microsoft documentation can be found here (http://msdn.microsoft.com/en-us/library/aa965879(VS.85).aspx). Note the below image comes from this link.

There are some required elements that need to be present to ensure that your manifest will validate, these are them:

  • <name> Value displayed on the picker (Richard’s Test)
  • <version> This is used when installing your gadget, if there is another gadget with the same name, the version will be compared to decide if the install should continue.
  • <hosts> Container for the host elements.
    • <base> Provides the file type and API version of the gadget
      • “Type” Required – Expected HTML
      • “src” Required – entry point into the gadget
  • <permissions> The expected value is Full.
  • <platform> The platform the gadget requires to run
    • “MinPlatformVersion” Required – Expected value is 1.0
  • <defaultImage> [Optional] Graphic that is displayed while the gadget is being dragged from the picker
    • “src” Required – Path to the image file

There are some additional elements that can be added to the manifest, they are:

  • <namespace> Not used yet, but am assuming that this will allow multiple widgets to run of the same type, each with their own settings.
  • <author> Information about you
    • “name” Required – your name
      • <info> More information
        • “url” a URL link to something about you
    • <logo> Wrapper for your logo
      • “src” The path to your logo
      • <copyright> You guesses it, this is the copyright message
      • <description> Displayed in the users gadget dialog box
      • <icon> Add an icon for your gadget
        • “Height” <int> Height of your image
        • “Width” <int> The width of your image
        • “src” Path to your image

That’s all there is to it, this is the source from my first gadget.xml file I created:

<?xml version="1.0" encoding="utf-8" ?>
<gadget>
  <name>Richard Test</name>
  <version>1.0.0.0</version>
  <author name="Richard Niemand">
    <info url="http://www.rn.co.za/" text="Vist my site" />
	<logo src="images/logo.png"/>
  </author>
  <copyright>&#169; Richard Niemand.</copyright>
  <description>"HelloWorld" Sidebar gadget sample.</description>
  <icons>
      <icon height="64" width="64" src="images/logo.png"/>
  </icons>
  <hosts>
    <host name="sidebar">
      <base type="HTML" apiVersion="1.0.0" src="html/Gadget.html" />
      <permissions>Full</permissions>
      <platform minPlatformVersion="1.0" />
    </host>
  </hosts>
</gadget>
13May/100

Windows Gadgets – Setting Settings

When working with windows Vista\7 Gadgets, you will need to make use of System.Gadget.Settings if you want to share a value through the lifespan of your gadget.

These settings are cleared out when your gadget is closed, so you will have to re-load them each time your gadget comes back to life. The quickest way of doing this is storing your settings in a XML file (to a set path) and reading that back into System.Gadget.Settings. Below are some code snippets for reading and writing to System.Gadget.Settings.

System.Gadget.Settings.write(strName, varValue)
//http://msdn.microsoft.com/en-us/library/ms723662(VS.85).aspx
 
System.Gadget.Settings.writeString(strName, strValue)
//http://msdn.microsoft.com/en-us/library/aa359285(VS.85).aspx
 
Var bob = System.Gadget.Settings.read(strName)
//http://msdn.microsoft.com/en-us/library/ms723656(VS.85).aspx
 
strSetting = System.Gadget.Settings.readString(strName)
//http://msdn.microsoft.com/en-us/library/aa359283(VS.85).aspx