<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ioan Lazarciuc&#039;s Weblog &#187; Gadget</title>
	<atom:link href="http://www.lazarciuc.ro/ioan/tag/gadget/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lazarciuc.ro/ioan</link>
	<description>I program, therefore I exist.</description>
	<lastBuildDate>Mon, 19 Dec 2011 06:24:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Debugging Silverlight Sidebar Gadgets from Visual Studio</title>
		<link>http://www.lazarciuc.ro/ioan/2010/07/28/debugging-silverlight-sidebar-gadgets-from-visual-studio/</link>
		<comments>http://www.lazarciuc.ro/ioan/2010/07/28/debugging-silverlight-sidebar-gadgets-from-visual-studio/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 22:16:06 +0000</pubDate>
		<dc:creator>cretz</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[Gadget]]></category>
		<category><![CDATA[Sidebar]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://www.lazarciuc.ro/ioan/2010/07/28/debugging-silverlight-sidebar-gadgets-from-visual-studio/</guid>
		<description><![CDATA[Ever since I started working with Windows Sidebar gadgets I’ve been debugging them the same way: enabling script debugging in the IE options (for JavaScript based gadgets) and then using the “Attach to Process” command from Visual Studio. When I created a template (posts here and here) that speeds up development of Silverlight Sidebar gadgets, [...]]]></description>
			<content:encoded><![CDATA[<p>Ever since I started working with Windows Sidebar gadgets I’ve been debugging them the same way: enabling script debugging in the IE options (for JavaScript based gadgets) and then using the “Attach to Process” command from Visual Studio.</p>
<p>When I created a template (posts <a href="http://www.lazarciuc.ro/ioan/2008/08/02/creating-a-vista-sidebar-gadget-using-microsoft-silverlight/" target="_blank">here</a> and <a href="http://www.lazarciuc.ro/ioan/2010/04/09/update-for-silverlight-sidebar-gadget-project-template/" target="_blank">here</a>) that speeds up development of Silverlight Sidebar gadgets, I wanted to offer the smoothest development experience possible. Ironically, that in itself has been a very bumpy ride. The last hurdle I had to cross was to provide the familiar debug experience (F5).</p>
<p> <span id="more-51"></span>
<p>My first attempt at this was just to set appropriate start options for the Web project that is in the template:</p>
<ul>
<li>Post build event that installs the gadget (runs a generated .gadget file) </li>
<li>%ProgramFiles(x86)%\Windows Sidebar\sidebar.exe as the start program </li>
</ul>
<p>This attempt failed with a very suggestive error:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SidebarAttach" border="0" alt="SidebarAttach" src="http://www.lazarciuc.ro/ioan/wp-content/uploads/2010/07/SidebarAttach.png" width="429" height="161" /> </p>
<p>I ran into this error every time the debugger was attached by the start options (F5, not using the Attach to Process command) and a Silverlight gadget was running in the Sidebar. I even tried to start debugging the sidebar when no Silverlight gadget ran, then added the Silverlight gadget to the Sidebar, but it was no use: same result.</p>
<p>I tried to get help with this error, but I could not find anything on it. The issue also seems like a very isolated corner case that does not affect too many people, so it would be tough to get any help.</p>
<p>While trying to find a workaround for F5 debugging, I wondered if I could run a custom app that manipulates the right Visual Studio instance to run the Attach to Process command and attach to sidebar.exe. Luckily, I was in Michael Leonard’s office at the time, because I got a quick answer: he had done similar things in the past. Half an hour later I had a code snippet about getting the Visual Studio automation object corresponding to a specific VS instance. Many thanks to Michael Leonard and Adam Nathan for getting the wheels turning on this.</p>
<p>The other parts of the solution flowed naturally:</p>
<ul>
<li>You can attach to the Visual Studio instance that has a specific solution open (info <a href="http://msdn.microsoft.com/en-us/library/ms228755.aspx" target="_blank">here</a>). </li>
<li>You can start the sidebar if it’s not already running (<a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx" target="_blank">System.Diagnostics.Process.Start</a>) </li>
<li>You can launch the “Attach to Process” command using the DTE objects (info <a href="http://msdn.microsoft.com/en-us/library/envdte.process.attach.aspx" target="_blank">here</a>). </li>
<li>You can pass the full solution path as a command line parameter from the Visual Studio project Debug options (though not for all projects; for web projects it won’t work because macros are not supported). </li>
<li>You can provide a transparent retry logic for COM calls that fail due to the destination being busy (info <a href="http://msdn.microsoft.com/en-us/library/ms228772.aspx" target="_blank">here</a>; note the part about the single-thread apartment requirement). </li>
</ul>
<p>I incorporated the custom app and the required build events into a new version of the Silverlight Windows Gadget template, available both in <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/bf347eb6-99bd-4c99-89d0-6ca3fe1eb54e" target="_blank">C#</a> and <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/01606aa9-d60d-47cc-8037-e7ba937d3a52" target="_blank">VB</a> flavour.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lazarciuc.ro/ioan/2010/07/28/debugging-silverlight-sidebar-gadgets-from-visual-studio/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Update for Silverlight Sidebar Gadget Project Template</title>
		<link>http://www.lazarciuc.ro/ioan/2010/04/09/update-for-silverlight-sidebar-gadget-project-template/</link>
		<comments>http://www.lazarciuc.ro/ioan/2010/04/09/update-for-silverlight-sidebar-gadget-project-template/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 17:41:42 +0000</pubDate>
		<dc:creator>cretz</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Gadget]]></category>
		<category><![CDATA[project template]]></category>
		<category><![CDATA[Sidebar]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://www.lazarciuc.ro/ioan/2010/04/09/update-for-silverlight-sidebar-gadget-project-template/</guid>
		<description><![CDATA[For the past few weeks I’ve been working on fixing a number of bugs signalled about the Silverlight Gadget Template I created a while ago. I’ve had to work around some strange issues and try everything I could to make the gadget development experience as pleasant as possible. I’d like to thank Kiran Bachu for [...]]]></description>
			<content:encoded><![CDATA[<p>For the past few weeks I’ve been working on fixing a number of bugs signalled about the <a href="http://www.lazarciuc.ro/ioan/2008/08/02/creating-a-vista-sidebar-gadget-using-microsoft-silverlight/" target="_blank">Silverlight Gadget Template</a> I created a while ago. I’ve had to work around some strange issues and try everything I could to make the gadget development experience as pleasant as possible. I’d like to thank Kiran Bachu for his valuable support in finding bugs and testing the gadget template.</p>
<p>Version <strong>1.8</strong> of the gadget is released for the following Visual Studio/Silverlight version combinations:</p>
<p><span id="more-39"></span>
<p>&#160;</p>
<table border="0" cellspacing="0" cellpadding="2" width="439">
<tbody>
<tr>
<td valign="top" width="132">&nbsp;</td>
<td valign="top" width="133"><strong>Silverlight 3.0 RTW</strong></td>
<td valign="top" width="172"><strong>Silverlight 4.0 RTW or Newer</strong></td>
</tr>
<tr>
<td valign="top" width="132"><strong>Visual Studio 2008</strong></td>
<td valign="top" width="133">Ver. 1.0 available <a href="http://www.lazarciuc.ro/ioan/wp-content/uploads/2010/SilverlightSidebarGadget_2008_3RTW.vsi" target="_blank">here</a></td>
<td valign="top" width="172">N/A (not supported)</td>
</tr>
<tr>
<td valign="top" width="132"><strong>Visual Studio 2010</strong></td>
<td valign="top" width="133">Available for <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/bf347eb6-99bd-4c99-89d0-6ca3fe1eb54e" target="_blank">C#</a> and <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/01606aa9-d60d-47cc-8037-e7ba937d3a52" target="_blank">VB</a></td>
<td valign="top" width="172">Available for <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/bf347eb6-99bd-4c99-89d0-6ca3fe1eb54e" target="_blank">C#</a> and <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/01606aa9-d60d-47cc-8037-e7ba937d3a52" target="_blank">VB</a></td>
</tr>
</tbody>
</table>
<p>I modified the CSS for the HTML page that hosts the flyout and the gadget itself in order to eliminate all margins and padding. You can set these from the Silverlight controls.</p>
<p>I fixed the issue with docking/undocking the gadget. Aside from a JS bug I had, there was also some weird Silverlight behaviour that cause the freeze on some machines.</p>
<p>I exposed the SettingsClosed event for both the docked and undocked Silverlight controls and fixed an issue related to saving settings values.</p>
<p>I added build events for the SilverlightGadgetWeb project that create a .gadget file that can be used to install/update the gadget. I also added code to actually install/update the gadget on each build. I did this in order to provide an easy way of trying out code changes.</p>
<p><strike>I tried to fix the Silverlight application references in the SilverlightGadgetWeb project, but the only way that can be achieved is by providing a custom wizard for the project template that requires installation in the GAC. For now I think this requirement would be too strong for the template installation process. Aside from re-adding the Silverlight project references I also recommend setting the project dependencies manually to make sure that the project is the last one to be built in the solution. You can do this by right clicking the web project, choosing “Project Dependencies…” and then selecting all the Silverlight projects.</strike> (see below for details)</p>
<p>I also tried to arrange for “F5 debugging” in Visual Studio, but it was not possible. I managed to set the sidebar as the start program for the web project, but the debugger failed to attach to the process if the Silverlight gadget was running. Even if attaching succeeds at start-up (when no Silverlight gadget runs), when I added a Silverlight gadget the debugger crashed. In conclusion, Debug-&gt;Attach to Process is still the best way to debug gadgets.</p>
<p>I will be adding more versions of the template as soon as I get around to it, so stay tuned if your development configuration is not available yet. </p>
<p><strong>UPDATE:</strong> In version 1.5 of the template I created a project template wizard to properly create Silverlight application references for the SilverlightGadgetWeb project and to establish a correct build order. This wizard also prompts for the Silverlight version to use when creating the projects.</p>
<p><strong>UPDATE:</strong> In version 1.6 of the template I fixed the F5 debugging scenario by providing a fake SilverlightGadgetDebugger project in the template that runs a custom app which attaches the Visual Studio instance to the Sidebar process (more info on the workaround <a href="http://www.lazarciuc.ro/ioan/2010/07/28/debugging-silverlight-sidebar-gadgets-from-visual-studio/" target="_blank">here</a>). Starting with this version, I’m also providing a Visual Basic.NET flavour of the template. For the download link, check the table above.</p>
<p><strong>UPDATE:</strong> Version 1.7 of the template offers a fully automated debug experience within Visual Studio 2010 for the gadgets. In short, the SilverlightGadgetDebugger&#160; project will close any running version of the Sidebar and start a new one containing only the gadget to be debugged. When debugging/running is done, the original Sidebar (if it was running) is restored. Also, a bug involving detection of the 32 bit Program Files folder (which was used to detect installed Silverlight versions and locate the 32 bit Sidebar) has been fixed.</p>
<p><strong>UPDATE:</strong> Version 1.8 of the template offers support for debugging 64 bit gadgets. This can be done by setting the Target Platform to “x64” for the SilverlightGadgetDebugger. Changes to the Target Platform require a reload of the SilverlightGadgetDebugger project, because Visual Studio does not update the values of the parameters used in command line parameters for debugging.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lazarciuc.ro/ioan/2010/04/09/update-for-silverlight-sidebar-gadget-project-template/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
		<item>
		<title>Creating a Vista Sidebar Gadget Using Microsoft Silverlight</title>
		<link>http://www.lazarciuc.ro/ioan/2008/08/02/creating-a-vista-sidebar-gadget-using-microsoft-silverlight/</link>
		<comments>http://www.lazarciuc.ro/ioan/2008/08/02/creating-a-vista-sidebar-gadget-using-microsoft-silverlight/#comments</comments>
		<pubDate>Sat, 02 Aug 2008 14:25:53 +0000</pubDate>
		<dc:creator>cretz</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Gadget]]></category>
		<category><![CDATA[Sidebar]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[template. visual studio]]></category>

		<guid isPermaLink="false">http://www.lazarciuc.ro/ioan/2008/08/02/creating-a-vista-sidebar-gadget-using-microsoft-silverlight/</guid>
		<description><![CDATA[Introduction Some while ago I did a post on how to create a Vista Sidebar gadget using JavaScript. I also mentioned that I tried to create the gadget using XBAP or Silverlight, but due to the limitations in those technologies at that time, I decided that I had to give up on too much of [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>Some while ago I did a <a title="Creating Sidebar Gadgets using JavaScript only" href="http://www.lazarciuc.ro/ioan/2007/11/01/creating-a-windows-vista-sidebar-gadget/" target="_blank">post</a> on how to create a Vista Sidebar gadget using JavaScript. I also mentioned that I tried to create the gadget using XBAP or Silverlight, but due to the limitations in those technologies at that time, I decided that I had to give up on too much of the Sidebar gadget specific functionality (flyouts, cross domain data retrieval).</p>
<p>More than 6 months have passed since then and now I am pleased to announce that I've changed my opinion regarding Silverlight Sidebar gadgets. Due to the fact that the Silverlight technology has matured a lot (version 2.0 beta 2 is now available), Sidebar gadgets can be developed using this technology, without sacrificing any Sidebar gadget specific functionality. This is due to the fact that there is full interoperability between Silverlight and the JavaScript code. Also, cross domain calls are now allowed in Silverlight, so retrieving data is no longer an issue. Furthermore, it has been greatly enhanced due to the fact that one can consume <a title="MSDN on Windows Communication Foundation" href="http://msdn.microsoft.com/en-us/library/ms735119.aspx" target="_blank">WCF</a> services using Silverlight.</p>
</p>
<p> <span id="more-18"></span>
</p>
<h3>Getting Started</h3>
<p>The first step is to have a look over the &quot;classic&quot; <a href="http://www.lazarciuc.ro/ioan/2007/11/01/creating-a-windows-vista-sidebar-gadget/" target="_blank">way</a> of developing Sidebar gadgets. Even though most of the &quot;hard work&quot; can now be done in Silverlight, the &quot;wiring&quot;, the guts of the whole gadget are still the classic ones, relying on JavaScript and HTML. Next, if you are not familiar with Silverlight development, I recommend you spend some time getting comfortable with Silverlight. For this you can visit <a href="http://www.silverlight.net">http://www.silverlight.net</a> and try out the tutorials there.</p>
<p>The result of my inquiries in this subject is a Visual Studio project template that can be used to quickly start development for a Silverlight Sidebar gadget. I got inspired by the template <a title="Tim Heuer&#39;s Project Tempalte for Sidebar Gadgets" href="http://timheuer.com/blog/archive/2007/03/11/14010.aspx" target="_blank">Tim Heuer</a> has created for jump starting Sidebar gadget development using just JavaScript/HTML. The requirements for installing and using the template are:</p>
<ul>
<li>Microsoft Visual Studio 2008 (Standard or better) </li>
<li>Microsoft Silverlight 2.0 beta 2 </li>
<li>Silverlight Tools Beta 2 for Visual Studio 2008 </li>
</ul>
<p>After downloading the template installer from <a title="Silverlight Sidebar Gadget Project Template Installer" href="http://www.lazarciuc.ro/ioan/wp-content/uploads/2008/SilverlightSidebarGadget.vsi" target="_blank">here</a>, in order to install it, just run the downloaded file. The Visual Studio Content Installer will handle the rest (click next and ignore security warnings, because I did not sign the template).</p>
<p>After installing the template, in order to create a new Sidebar gadget, in Visual Studio click File-&gt;New-&gt;Project. You will notice that under the C# node, at the bottom, under &quot;My Templates&quot;, a new entry has appeared: &quot;Silverlight Sidebar Gadget&quot;. Give the solution a name and then click Ok.</p>
<p><a href="http://www.lazarciuc.ro/ioan/wp-content/uploads/2008/CreatingaVistaSidebarGadgetUsingSilverli_DEE6/NewProject.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="NewProject" src="http://www.lazarciuc.ro/ioan/wp-content/uploads/2008/CreatingaVistaSidebarGadgetUsingSilverli_DEE6/NewProject_thumb.jpg" width="468" height="333" /></a></p>
<p>You will notice that 6 projects have been automatically added to the newly created solution: SilverlightSidebarGadgetWeb, SilverlightGadgetDocked, SilverlightGadgetUnDocked, SilverlightGadgetSettings, SilverlightGadgetFlyout and SilverlightGadgetUtilities. In order, these correspond to: the main gadget web site project that will actually end up being deployed (all content and code is added to this site), the Silverlight control that is displayed when the gadget is docked, the Silverlight control that is displayed when the gadget is undocked, the Silverlight control that is displayed on the settings page of the gadget, the Silverlight control that is displayed on the flyout page of the gadget and a utilities library for Silverlight, providing a managed code API for Sidebar gadgets. This API translates to calls in the JavaScript Sidebar Gadget API.</p>
<p><strong>IMPORTANT:</strong> Due to limitations in the way the template is built, the Silverlight applications have to be added to the gadget's main project manually. This can be done by going to the Property Pages for the website project, the Silverlight Applications tab and then click add for each additional Silverlight project. Clear the &quot;Add a test page that references the control&quot; checkbox, and make sure the &quot;Enable Silverlight debugging&quot;checkbox is checked if you want debugging capabilities for Silverlight. Silverlight and JavaScript simultaneous debugging is not possible at the current time (Silverlight debugging requires disabling Script debugging from IE).</p>
<p><a href="http://www.lazarciuc.ro/ioan/wp-content/uploads/2008/CreatingaVistaSidebarGadgetUsingSilverli_DEE6/AddSilverlightApplications.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="AddSilverlightApplications" src="http://www.lazarciuc.ro/ioan/wp-content/uploads/2008/CreatingaVistaSidebarGadgetUsingSilverli_DEE6/AddSilverlightApplications_thumb.jpg" width="470" height="334" /></a></p>
<p>In a later version of the project template this will no longer be required, but for that I have to add a custom Wizard to the project template that can prepare the projects in the template.</p>
<p>The code is commented, so I'm not going to cover it in detail. Also, for Sidebar gadget development guidance, read my previous <a title="Creating Sidebar Gadgets using JavaScript only" href="http://www.lazarciuc.ro/ioan/2007/11/01/creating-a-windows-vista-sidebar-gadget/" target="_blank">post</a> on the topic. The gadget is set up to use Silverlight controls for each page of the gadget. This is not required, and Silverlight controls can be removed from the project (along with their projects form the solution) as needed. There are 2 main classes defined in the SilverlightGadgetUtilities class: SilverlightGadget and SilverlightGadgetEvents. The first is used to access the JavaScript Sidebar Gadget API. The second is used to expose the JavaScript events related to a gadget as managed events in the Silverlight controls.</p>
<h3>Known &quot;bumps&quot;</h3>
<p>There are some things that will simply not work, no matter how hard you try to get them to work. Usually this is due to the fact that the current Sidebar gadget API or the gadget user experience provided by Microsoft does not allow it. These &quot;hick-ups&quot; are specified in the documentation comments of the classes or directly as comments.</p>
<p>Due to the fact that the Gadget JavaScript object does not allow attaching multiple event handlers for the same event, one must take care what event handler is registered for a particular event. Possible outcomes are: events that do not get triggered at all in the Silverlight controls, events that get triggered only in some Silverlight controls.</p>
<p>Due to the user experience with Sidebar gadgets, some events cannot be triggered in Silverlight controls: the Docked, Undocked events, all gadget events in the flyout, etc.</p>
<p>Some properties from the SilverlightGadget class are read-only even though the Sidebar gadget JavaScript API specifies that they are read-write. This is due to the fact that attempting to set those properties resulted in exceptions at runtime and those exceptions are most probably caused by the JavaScript API itself.</p>
<p>I tried to &quot;discover&quot; all such &quot;bumps&quot; that might appear and document them in the template directly. If there is something I missed or you have a question, please <a href="http://www.lazarciuc.ro/ioan/contact/" target="_blank">contact me</a> or post a comment and I will try to modify the template to fix or document the issue. Also, any suggestions on improving this project template are welcomed.</p>
<p>I'm looking forward to seeing many Silverlight Sidebar gadgets being developed. If you create such a gadget using this project template, please let me know by posting a comment with a link to the Live Gallery page of the gadget or a link to a page describing it.</p>
<p>Once again, the link for the Visual Studio project template is displayed below.</p>
<p>FILE: <a href="http://www.lazarciuc.ro/ioan/wp-content/uploads/2008/SilverlightSidebarGadget.vsi" target="_blank">SilverlightSidebarGadget.vsi</a></p>
<p><strong>UPDATE: </strong>If you have Microsoft Visual Studio 2008 SP1 installed, you will need the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=50A9EC01-267B-4521-B7D7-C0DBA8866434&amp;displaylang=en" target="_blank">Microsoft Visual Studio Tools Beta 2 for Visual Studio 2008</a> in order to be able to create Silverlight projects. This also means that you cannot use the provided template without installing the new version of the Silverlight Tools.</p>
<p><strong>UPDATE 2:</strong> I’ve upgraded the projects in the template for Silverlight 3 Beta. The corresponding template can be found <a href="http://www.lazarciuc.ro/ioan/wp-content/uploads/2008/SilverlightSidebarGadget_3Beta.vsi" target="_blank">here</a>.</p>
<p><strong>UPDATE 3:</strong> I’ve created a version of the template for Silverlight 2 final. The corresponding template can be found <a href="http://www.lazarciuc.ro/ioan/wp-content/uploads/2008/SilverlightSidebarGadget_2.vsi" target="_blank">here</a>.</p>
<p><strong>UPDATE 4:</strong> I’ve upgraded the projects in the template for Silverlight 3 RTW. The corresponding template can be found <a href="http://www.lazarciuc.ro/ioan/wp-content/uploads/2009/SilverlightSidebarGadget_3RTW.vsi" target="_blank">here</a>.</p>
<p><strong>UPDATE 5:</strong> I’ve created a version of the template using Visual Basic projects. The corresponding template can be found <a href="http://www.lazarciuc.ro/ioan/wp-content/uploads/2009/SilverlightSidebarGadget_3RTW_vb.vsi" target="_blank">here</a>.</p>
<p><strong>UPDATE 6:</strong> I’ve created a version of the template for Visual Studio 2010, using the new extension format. The corresponding template can be found <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/bf347eb6-99bd-4c99-89d0-6ca3fe1eb54e" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lazarciuc.ro/ioan/2008/08/02/creating-a-vista-sidebar-gadget-using-microsoft-silverlight/feed/</wfw:commentRss>
		<slash:comments>59</slash:comments>
		</item>
		<item>
		<title>Creating a Windows Vista Sidebar Gadget</title>
		<link>http://www.lazarciuc.ro/ioan/2007/11/01/creating-a-windows-vista-sidebar-gadget/</link>
		<comments>http://www.lazarciuc.ro/ioan/2007/11/01/creating-a-windows-vista-sidebar-gadget/#comments</comments>
		<pubDate>Wed, 31 Oct 2007 23:39:20 +0000</pubDate>
		<dc:creator>cretz</dc:creator>
				<category><![CDATA[Beginnings]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Gadget]]></category>
		<category><![CDATA[Sidebar]]></category>
		<category><![CDATA[Vista]]></category>

		<guid isPermaLink="false">http://www.lazarciuc.ro/ioan/2007/11/01/creating-a-windows-vista-sidebar-gadget/</guid>
		<description><![CDATA[I think this post should begin with a few sayings: "Never say never", "When hell freezes over", "Once in a blue moon", "I would rather shoot myself", "Over my dead body", but the best suited one for this post comes from Ciprian Jichici, the Microsoft Regional Director from Romania: "In this line of business, there's [...]]]></description>
			<content:encoded><![CDATA[<p>I think this post should begin with a few sayings: "Never say never", "When hell freezes over", "Once in a blue moon", "I would rather shoot myself", "Over my dead body", but the best suited one for this post comes from <a TITLE="Ciprian Jichici's Website" HREF="http://www.ciprianjichici.ro/" TARGET="_blank">Ciprian Jichici</a>, the <a TITLE="Microsoft Regional Director Website" HREF="http://microsoftregionaldirectors.com/" TARGET="_blank">Microsoft Regional Director</a> from Romania: "In this line of business, there's no room for talibanisms".</p>
<p>I will be talking about developing Sidebar gadgets. These Sidebar gadgets are small applications that offer useful information, do frequent tasks more easily, or just offer a good laugh for the Windows Vista user. Until recently, I've been trying very hard to stay away from technologies like JavaScipt and PHP because it is my personal opinion that they fall miles away from a proper programming language (C#, VB.NET, C++). I won't go into the details of why I dislike these languages.</p>
<p>Microsoft launched a <a TITLE="Gadget Competition Website for Romania" HREF="http://www.gadgetcompetition.com/" TARGET="_blank">competition</a> for Sidebar gadget developers with some very nice prizes. The competition takes place in several countries, including Romania. So, I decided to participate. The only problem is that the only fully supported programming model for developing Sidebar gadgets is HTML application + JavaScript.</p>
<p><span id="more-14"></span></p>
<p>I've spent several weeks trying to find another way to develop gadgets. I found out that by using <a TITLE="A site for information aobut XBAP" HREF="http://www.xbap.org/" TARGET="_blank">XBAP</a>(XAML Browser Application), one can obtain a gadget that can be programmed using <a TITLE="MSDN WPF Site" HREF="http://msdn2.microsoft.com/en-us/library/ms754130.aspx" TARGET="_blank">WPF</a> (Windows Presentation Foundation) - more information on that <a TITLE="How to Create a Sidebar Gadget using XBAP" HREF="http://blogs.msdn.com/jbeavers/archive/2007/05/30/creating-the-simple-xbap-sidebar-gadget.aspx" TARGET="_blank">here</a>. There are real drawbacks to this approach: no flyouts, no access to the gadget settings API, no access to the Gadget API, which are all accessible from JavaScript. Also, <a TITLE="Silverlight Website" HREF="http://www.microsoft.com/silverlight/" TARGET="_blank">Silverlight</a> can be used to create a Sidebar gadget. While this significantly improves access to the JavaScipt API's, there are still drawbacks. More on creating gadgets using Silverlight <a HREF="http://blogs.msdn.com/charles_sterling/archive/2007/05/14/writing-a-windows-sidebar-gadget-in-silverlight-dead-simple.aspx" TARGET="_blank">here</a> and <a HREF="http://blog.benhall.me.uk/2007/05/vista-sidebar-gadget-using-silverlight.html" TARGET="_blank">here</a>. The decision was tough to make, but unavoidable: JavaScript won, due to the fact that my gadget needed settings, flyouts and a standard installation experience (no dependencies on Silverlight).</p>
<p>Now the phrase "there's no room for talibanisms" makes sense: you never know when you will be forced to do things you don't particularly enjoy (such as JavaScript). All these being said, I shall move on the the task at hand. The best place to start when learning to develop gadgets is the <a TITLE="Basic Tutorial for Sidebar Gadget Development" HREF="http://microsoftgadgets.com/Sidebar/DevelopmentOverview.aspx" TARGET="_blank">Overview Site</a> from Microsoft. The ABCs of developing gadgets are covered there. Tim Heuer has made a project template for Visual Studio in order to help people getting started in gadget development. The template is available <a TITLE="Visual Studio Project Template for Gadget Development" HREF="http://www.timheuer.com/blog/archive/2007/03/11/14010.aspx" TARGET="_blank">here</a>.</p>
<p>From here, the purpose of the new gadget has to be formulated. It can be as simple as "Hello World", or as complicated as interfacing with your Windows Media Player. The first step is to go over to the <a TITLE="Live Gallery for Sidebar Gadgets" HREF="http://vista.gallery.microsoft.com/vista/SideBar.aspx" TARGET="_blank">Live Gallery</a> dedicated to Vista Sidebar Gadgets and have a look at what's out there. I settled on creating a gadget that would display the postal code (ZIP) for a given address from Romania. I chose this because I had been searching too many times for postal codes on websites. The gadget is a very welcomed shortcut. The data is to be obtained from one of the many sites that offer Romanian ZIP search. The only requirement is to be able to pass the search string as a query string directly in the URL to keep things simple. I settled on <a HREF="http://coduri-postale.ro">http://coduri-postale.ro</a>.</p>
<p>The next step is to get up to date with some basic <a TITLE="JavaScript Tutorial" HREF="http://www.w3schools.com/js/default.asp" TARGET="_blank">JavaScript</a>: <a TITLE="HTML DOM" HREF="http://www.w3schools.com/htmldom/dom_reference.asp" TARGET="_blank">HTML DOM</a>, <a TITLE="CSS Refference" HREF="http://www.w3schools.com/css/css_intro.asp" TARGET="_blank">CSS</a>, <a TITLE="Regular Expressions" HREF="http://www.devarticles.com/c/a/JavaScript/Regular-expressions-in-JavaScript/" TARGET="_blank">Regular Expressions</a>, the <a TITLE="Sidebar Gadget API Refference" HREF="http://msdn2.microsoft.com/en-us/library/aa965853.aspx" TARGET="_blank">Sidebar Gadget API</a>. Now it's time to take a look at the structure generated by the Visual Studio template.</p>
<p>A Sidebar gadget has at least 2 files: a HTML file which defines the look of the gadget and an XML file which defines information about the gadget such as the name, version, author, description. However, usually, a gadget contains more files such as: HTML files for various flyouts, JS files for the JavaScript functions that are called and CSS files for defining styles in a civilized manner.</p>
<p>The main file of the gadget is called by default, gadget.html. It contains 2 div tags, one with the ID "docked" and one "undocked". As you can imagine, one holds the contents while docked, the other while undocked. In JavaScript, the events System.Gadget.onDock and System.Gadget.onUndock are defined in order to handle the switch between modes. The event handlers are set in the Init function found in the utils.js file.</p>
<p STYLE="border-right-color: #808080; border-right-width: 1px; border-right-style: solid; padding-right: 4px; border-top-color: #808080; border-top-width: 1px; border-top-style: solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin-top: 20px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; overflow: auto; border-left-color: #808080; border-left-width: 1px; border-left-style: solid; width: 97.50%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom-color: #808080; border-bottom-width: 1px; border-bottom-style: solid">&nbsp;</p>
<p STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">&nbsp;</p>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"><span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">body</span> <span STYLE="color: #ff0000">onload</span><span STYLE="color: #0000ff">="init();"</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">div</span> <span STYLE="color: #ff0000">id</span><span STYLE="color: #0000ff">="docked"</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> Gadget Docked</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">br</span><span STYLE="color: #0000ff">/&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">input</span> <span STYLE="color: #ff0000">type</span><span STYLE="color: #0000ff">="button"</span> <span STYLE="color: #ff0000">value</span><span STYLE="color: #0000ff">="Flyout"</span> <span STYLE="color: #ff0000">onclick</span><span STYLE="color: #0000ff">="flyout();"</span> <span STYLE="color: #0000ff">/&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;/</span><span STYLE="color: #800000">div</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">div</span> <span STYLE="color: #ff0000">id</span><span STYLE="color: #0000ff">="undocked"</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> Gadget Undocked</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;/</span><span STYLE="color: #800000">div</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"><span STYLE="color: #0000ff">&lt;/</span><span STYLE="color: #800000">body</span><span STYLE="color: #0000ff">&gt;</span></pre>
<p>The gadget.xml file contains the name, author, description of the gadget, but also it specifies the main source file for the gadget in the &lt;base&gt; node from &lt;hosts&gt;. The file also contains the path to an icon which represents the gadget and an image to display (defaultImage in &lt;hosts&gt;) while dragging the gadget (only when dragging it from the "Add Gadgets" window).</p>
<p STYLE="border-right-color: #808080; border-right-width: 1px; border-right-style: solid; padding-right: 4px; border-top-color: #808080; border-top-width: 1px; border-top-style: solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin-top: 20px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; overflow: auto; border-left-color: #808080; border-left-width: 1px; border-left-style: solid; width: 97.50%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom-color: #808080; border-bottom-width: 1px; border-bottom-style: solid">&nbsp;</p>
<p STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">&nbsp;</p>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"><span STYLE="color: #0000ff">&lt;?</span><span STYLE="color: #800000">xml</span> <span STYLE="color: #ff0000">version</span><span STYLE="color: #0000ff">="1.0"</span> <span STYLE="color: #ff0000">encoding</span><span STYLE="color: #0000ff">="utf-8"</span> ?<span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"><span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">gadget</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #008000">&lt;!-- The name will appear on the Gadget Tile and settings window --&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">name</span><span STYLE="color: #0000ff">&gt;</span>[ YOUR GADGET NAME ]<span STYLE="color: #0000ff">&lt;/</span><span STYLE="color: #800000">name</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">namespace</span><span STYLE="color: #0000ff">&gt;</span>[YOUR CUSTOM NAMESPACE]<span STYLE="color: #0000ff">&lt;/</span><span STYLE="color: #800000">namespace</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">version</span><span STYLE="color: #0000ff">&gt;</span>1.0.0.0<span STYLE="color: #0000ff">&lt;/</span><span STYLE="color: #800000">version</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">author</span> <span STYLE="color: #ff0000">name</span><span STYLE="color: #0000ff">="[AUTHOR NAME]"</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">info</span> <span STYLE="color: #ff0000">url</span><span STYLE="color: #0000ff">="[URL FOR INFO]"</span> <span STYLE="color: #0000ff">/&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #008000">&lt;!-- The logo file will display on the more details window of the Gadget Tile window --&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">logo</span> <span STYLE="color: #ff0000">src</span><span STYLE="color: #0000ff">="logo.png"</span> <span STYLE="color: #0000ff">/&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;/</span><span STYLE="color: #800000">author</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">copyright</span><span STYLE="color: #0000ff">&gt;</span>© [COPYRIGHT INFO]<span STYLE="color: #0000ff">&lt;/</span><span STYLE="color: #800000">copyright</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #008000">&lt;!-- The description displays in the Gadget Tile window when the Gadget is selected --&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">description</span><span STYLE="color: #0000ff">&gt;</span>[YOUR DESCRIPTION]<span STYLE="color: #0000ff">&lt;/</span><span STYLE="color: #800000">description</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">icons</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">icon</span> <span STYLE="color: #ff0000">height</span><span STYLE="color: #0000ff">="48"</span> <span STYLE="color: #ff0000">width</span><span STYLE="color: #0000ff">="48"</span> <span STYLE="color: #ff0000">src</span><span STYLE="color: #0000ff">="icon.png"</span> <span STYLE="color: #0000ff">/&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;/</span><span STYLE="color: #800000">icons</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">hosts</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">host</span> <span STYLE="color: #ff0000">name</span><span STYLE="color: #0000ff">="sidebar"</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">base</span> <span STYLE="color: #ff0000">type</span><span STYLE="color: #0000ff">="HTML"</span> <span STYLE="color: #ff0000">apiVersion</span><span STYLE="color: #0000ff">="1.0.0"</span> <span STYLE="color: #ff0000">src</span><span STYLE="color: #0000ff">="gadget.html"</span> <span STYLE="color: #0000ff">/&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">permissions</span><span STYLE="color: #0000ff">&gt;</span>Full<span STYLE="color: #0000ff">&lt;/</span><span STYLE="color: #800000">permissions</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">platform</span> <span STYLE="color: #ff0000">minPlatformVersion</span><span STYLE="color: #0000ff">="1.0"</span> <span STYLE="color: #0000ff">/&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;</span><span STYLE="color: #800000">defaultImage</span> <span STYLE="color: #ff0000">src</span><span STYLE="color: #0000ff">="drag.png"</span> <span STYLE="color: #0000ff">/&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;/</span><span STYLE="color: #800000">host</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">&lt;/</span><span STYLE="color: #800000">hosts</span><span STYLE="color: #0000ff">&gt;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"><span STYLE="color: #0000ff">&lt;/</span><span STYLE="color: #800000">gadget</span><span STYLE="color: #0000ff">&gt;</span></pre>
<p><a HREF="http://11011.net/software/vspaste"></a><a HREF="http://11011.net/software/vspaste"></a></p>
<p>The size of the gadget (or the flyout) can be changed by changing the size of the body of the html, either from CSS, HTML or JavaScript.  If the gadget has two different size when docked or undocked, then one should change the size of the html body using JavaScript in the event handlers for the Dock and Undock events. The utils.js file contains a function ShowOrHide that takes an HTML element and a boolean and hides(or shows) the element, along with any of its children. The function flyout() from utils.js creates a new flyout by specifying the file property of System.Gadget.Flyout, and then setting show to true.</p>
<p>One can specify a settings HTML page by setting the settingsUI property of System.Gadget. The settings page cannot be opened programmatically, only by the user's action (the settings button that the runtime creates for each gadget that supports settings automatically). The event onSettingsClosed is raised whenever the settings page closes, either by pressing ok or cancel. The onSettingsClosing event can be handled in order to save settings. It's handlers have a parameter which has a property closeAction. If this property is event.Action.commit, where event is the parameter passed to the handler, then the ok button was pressed. In order to write settings, one calls the write method and for reading, the read method of System.Gadget.Settings.</p>
<p STYLE="border-right-color: #808080; border-right-width: 1px; border-right-style: solid; padding-right: 4px; border-top-color: #808080; border-top-width: 1px; border-top-style: solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin-top: 20px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; overflow: auto; border-left-color: #808080; border-left-width: 1px; border-left-style: solid; width: 97.50%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom-color: #808080; border-bottom-width: 1px; border-bottom-style: solid">&nbsp;</p>
<p STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">&nbsp;</p>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">SystemGadget.Settings.write(<span STYLE="color: #006080">"settingname"</span>,settingvalue);</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">System.Gadget.Settings.read(<span STYLE="color: #006080">"settingname"</span>);</pre>
<p>When loading the settings page, it is the responsibility of the page (through JavaScript) to read its settings and update the fields in the settings html in order to reflect the current values of the settings. This is the purpose of the loadSettings function available in the settings.html file from the template.</p>
<p>This covers all the main aspects in the template for Sidebar gadgets. Another very useful thing to master is the XMLHttpRequest object in JavaScript. This is used in order to obtain the contents of another page (any webpage) asynchronously. This object is part of the AJAX web programming paradigm. Unfortunately, like CSS, HTML and JavaScript, each browser has its own way of looking at this object. There are at least 3 methods of constructing the XMLHttpRequest  object, the bad news being that only one will work for a browser. So you have to try each method, catching exceptions along the way, until the object creation does not throw an exception or all the methods are exhausted, in the worst case. The good news is that for Sidebar gadgets, only Internet Explorer has to be taken into account. Sample code for creating the request object can be found below.</p>
<p STYLE="border-right-color: #808080; border-right-width: 1px; border-right-style: solid; padding-right: 4px; border-top-color: #808080; border-top-width: 1px; border-top-style: solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin-top: 20px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; overflow: auto; border-left-color: #808080; border-left-width: 1px; border-left-style: solid; width: 97.50%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom-color: #808080; border-bottom-width: 1px; border-bottom-style: solid">&nbsp;</p>
<p STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">&nbsp;</p>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"><span STYLE="color: #0000ff">var</span> xmlhttp = <span STYLE="color: #0000ff">false</span>;</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">try</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> {</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> xmlhttp = <span STYLE="color: #0000ff">new</span> ActiveXObject(<span STYLE="color: #006080">"Msxml2.XMLHTTP"</span>);</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> }</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">catch</span> (e)</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> {</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> xmlhttp = <span STYLE="color: #0000ff">new</span> ActiveXObject(<span STYLE="color: #006080">"Microsoft.XMLHTTP"</span>);</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> }</pre>
<p>The simplest usage scenario involves using the GET http verb in order to simply retrieve a page.</p>
<p STYLE="border-right-color: #808080; border-right-width: 1px; border-right-style: solid; padding-right: 4px; border-top-color: #808080; border-top-width: 1px; border-top-style: solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin-top: 20px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; overflow: auto; border-left-color: #808080; border-left-width: 1px; border-left-style: solid; width: 97.50%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom-color: #808080; border-bottom-width: 1px; border-bottom-style: solid">&nbsp;</p>
<p STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">&nbsp;</p>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"><span STYLE="color: #0000ff">var</span> ret;</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">xmlhttp.open(<span STYLE="color: #006080">"GET"</span>, url, <span STYLE="color: #0000ff">true</span>);</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">xmlhttp.onreadystatechange=<span STYLE="color: #0000ff">function</span>()</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">{</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">if</span> (xmlhttp.readyState==4)</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">if</span> (xmlhttp.status==200)</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> {</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> ret=xmlhttp.responseText;</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #008000">//do something with ret;</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> }</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">else</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> {</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #008000">//anything other than success can </span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #008000">//be treated as an error</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> }</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">}</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">xmlhttp.send(<span STYLE="color: #0000ff">null</span>);</pre>
<p>The open method takes as parameters the HTTP verb (GET, POST, etc.), the URL for the page to fetch and a boolean that when set to true allows JavaScript to launch the request asynchronously, meaning it keeps on processing the code. If set to false, the execution of JavaScript code stops until the data is fetched or an error occurs. The send method sends the request to the specified web server. If working asynchronously, you can define an event handler for the onreadystatechange event defined by the XMLHttpRequest object to monitor progress. The readyState property indicates the state of the object (4 mean request completed, response available). The status property holds the HTTP status of the response, 200 meaning OK. The actual response can be accessed using the responseText property. When fetching an ordinary webpage, this string will contain the actual HTML of the page.</p>
<p>Sometimes it's useful to do a POST request in order to get to a page that cannot be accessed through an URL. For example for filling out a form in order to obtain some search results (that are not accessible through URL query string parameters). Besides changing the GET into POST, you must also specify the form parameters just as you would query string parameters,only without "?" ('par1=val1&amp;par2=val2') and pass the resulted string to the send method of the request object. Also, some HTTP header have to be set: Content-Type to "application/x-www-form-urlencoded" in order to pass the parameters of the form, Content-length to the length of the string of parameters and Connection to "close" in order to specify that the connection is to be closed once the response is obtained.</p>
<p STYLE="border-right-color: #808080; border-right-width: 1px; border-right-style: solid; padding-right: 4px; border-top-color: #808080; border-top-width: 1px; border-top-style: solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin-top: 20px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; overflow: auto; border-left-color: #808080; border-left-width: 1px; border-left-style: solid; width: 97.50%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom-color: #808080; border-bottom-width: 1px; border-bottom-style: solid">&nbsp;</p>
<p STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">&nbsp;</p>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">xmlhttp.open(<span STYLE="color: #006080">"POST"</span>, url, <span STYLE="color: #0000ff">false</span>);</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">xmlhttp.setRequestHeader(<span STYLE="color: #006080">"Content-type"</span>, <span STYLE="color: #006080">"application/x-www-form-urlencoded"</span>);</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">xmlhttp.setRequestHeader(<span STYLE="color: #006080">"Content-length"</span>, parameters.length);</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">xmlhttp.setRequestHeader(<span STYLE="color: #006080">"Connection"</span>, <span STYLE="color: #006080">"close"</span>);</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"><span STYLE="color: #0000ff">var</span> ret;</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">xmlhttp.onreadystatechange=<span STYLE="color: #0000ff">function</span>()</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">{</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">if</span> (xmlhttp.readyState==4)</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">if</span> (xmlhttp.status==200)</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> {</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> ret=xmlhttp.responseText;</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #008000">//do something with ret</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> }</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #0000ff">else</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> {</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> <span STYLE="color: #008000">// error occurred</span></pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px"> }</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">}</pre>
<pre STYLE="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 0em; overflow: visible; width: 100%; color: #000000; border-top-style: none; line-height: 12pt; padding-top: 0px">xmlhttp.send(parameters);</pre>
<p>This concludes a basic, but comprehensive article on developing Sidebar gadgets. Even though I was not very specific, I hope you will have no problem stating your own gadget after reading this post.</p>
<p>Currently I have developed 2 gadgets: one to display postal codes from Romania and one to search for schedule and route information for urban transportation in a few major cities from Romania. The source code for these gadget can be obtained by installing them, then by getting the contents of the "C:\Users\%YourUser%\AppData\Local\Microsoft\Windows Sidebar\Gadgets\GadgetName" folder. Also, these two gadgets are competing in the Romanian edition of <a TITLE="International Gadget Competition website" HREF="http://www.gadgetcompetition.com" TARGET="_blank">Gadget Competition</a>. You can download and vote for my gadgets by clicking the two screenshots below.</p>
<p><a TITLE="Romanian Postal Codes" HREF="http://www.gadgetcompetition.ro/ro/ro/GadgetDetail.aspx?g=3990b9c3-c0b3-4695-a7ce-215c5391ac0a" TARGET="_blank"><img ID="id" SRC="http://www.lazarciuc.ro/ioan/wp-content/uploads/2007/Gadgets/RPC.JPG" /></a> <a TITLE="Romanian Urban Transportation Guide" HREF="http://www.gadgetcompetition.ro/ro/ro/GadgetDetail.aspx?g=44cf1503-baaf-44c3-998d-640cae10086a" TARGET="_blank"><img ID="id" SRC="http://www.lazarciuc.ro/ioan/wp-content/uploads/2007/Gadgets/RUTG.JPG" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lazarciuc.ro/ioan/2007/11/01/creating-a-windows-vista-sidebar-gadget/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

