<?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>Aimee Gurl... &#187; sample code</title>
	<atom:link href="http://aimeegurl.com/tag/sample-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://aimeegurl.com</link>
	<description>for as long as i can remember, technology has always fascinated me</description>
	<lastBuildDate>Thu, 29 Jul 2010 03:28:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>TechFriday: Jumping into Jumplists</title>
		<link>http://aimeegurl.com/2009/07/10/techfriday-jumping-into-jumplists/</link>
		<comments>http://aimeegurl.com/2009/07/10/techfriday-jumping-into-jumplists/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 17:48:35 +0000</pubDate>
		<dc:creator>Aimee</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[jumplist]]></category>
		<category><![CDATA[sample code]]></category>
		<category><![CDATA[techfriday]]></category>
		<category><![CDATA[Windows7]]></category>

		<guid isPermaLink="false">http://aimeegurl.com/2009/07/10/techfriday-jumping-into-jumplists/</guid>
		<description><![CDATA[<p id="top" />
<p>Everybody’s excited about Windows 7 and there might be a few of you guys out there wanting to take advantage of some of the new features of the OS in your applications. In this post, I’ll show you how you can quickly add Jumplist support to your existing application (Yes, even WinForms applications)</p>
<p>In [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p>Everybody’s excited about Windows 7 and there might be a few of you guys out there wanting to take advantage of some of the new features of the OS in your applications. In this post, I’ll show you how you can quickly add Jumplist support to your existing application (Yes, even WinForms applications)</p>
<p>In order to keep things simple, let’s just make the assumption that this existing application of mine has 3 very useful screens: Default, Green Mode and Red Mode ( I’m a developer, I’m not very creative ) </p>
<p><a href="http://aimeegurl.com/wp-content/uploads/2009/07/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://aimeegurl.com/wp-content/uploads/2009/07/image_thumb.png" width="588" height="371" /></a> </p>
<p>Because I want to save my user some additional clicks to get into green / red mode, I can take advantage of a new feature of Windows 7 called Jumplists: when a user right-clicks on my app’s icon on the Windows 7 task bar, this menu pops up and gives him access to tasks that we expect him to frequent. There are a lot of tutorials out there that teach how to add Recent/Frequent documents to this list. The samples included in the library we’ll be using will show you how.</p>
<p><a href="http://aimeegurl.com/wp-content/uploads/2009/07/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://aimeegurl.com/wp-content/uploads/2009/07/image_thumb1.png" width="306" height="229" /></a> .</p>
<p>For this example, we’ll learn how to use our applications existing custom functions (and icons) with Windows 7 jumplists but first, download <a href="http://code.msdn.microsoft.com/Windows7Taskbar">the Windows 7 Taskbar Developer Resource</a></p>
<p>For this example, I have a very simple Hello Windows 7 application. In the application, I have a menu bar that loads up additional screens. In this case, it’s just the same screen and switching the colors, but it could easily be a function that will load up another UserControl with different functions. Productivity is key, so I’d like to allow my user to go straight to these screens on startup. </p>
<p><a href="http://aimeegurl.com/wp-content/uploads/2009/07/image2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://aimeegurl.com/wp-content/uploads/2009/07/image_thumb2.png" width="1028" height="550" /></a> </p>
<p>In order to enable this, I’ve made a method that will allow the application to switch between user screens based on command line arguments when launching the application.</p>
<pre class="code"><span style="color: blue">private void </span>ProcessArguments()
{
    <span style="color: blue">string</span>[] args = <span style="color: #2b91af">Environment</span>.GetCommandLineArgs();

    <span style="color: blue">if </span>(args.Length &gt; 1)
    {
        <span style="color: blue">if </span>(args[1].Equals(<span style="color: #a31515">&quot;/r&quot;</span>))
        {
            LoadRedScreen();
        }
        <span style="color: blue">else if </span>(args[1].Equals(<span style="color: #a31515">&quot;/g&quot;</span>))
        {
            LoadGreenScreen();
        }

    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>In this piece of code, I’m basically checking that IF there are arguments passed when running the application, I’ll be calling a method to load the appropriate UserControl (We’ve already seen that this is the same method invoked by the menu item in our Menubar).</p>
<p>Now we start using the libraries provided for us to make it easier to integrate with the Windows 7 Taskbar. But first let’s import the namespace of the library, plus some additional ones we will be using along the way</p>
<pre class="code"><span style="color: blue">using </span>Windows7.DesktopIntegration;
<span style="color: blue">using </span>System.IO;
<span style="color: blue">using </span>System.Reflection;</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Next we add the following properties to the form:</p>
<pre class="code"><span style="color: blue">string </span>appID = <span style="color: #a31515">&quot;Hello Windows 7&quot;</span>;
<span style="color: #2b91af">JumpListManager </span>jlm;
    </pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The key thing here is the JumpListManager but if you want more information on the appID and all the goodness it brings, visit <a title="http://windowsteamblog.com/blogs/developers/archive/2009/06/18/developing-for-the-windows-7-taskbar-application-id.aspx" href="http://windowsteamblog.com/blogs/developers/archive/2009/06/18/developing-for-the-windows-7-taskbar-application-id.aspx">http://windowsteamblog.com/blogs/developers/archive/2009/06/18/developing-for-the-windows-7-taskbar-application-id.aspx</a>. The next thing I have to do is override </p>
<pre class="code"><span style="color: blue">protected override void </span>WndProc(<span style="color: blue">ref </span><span style="color: #2b91af">Message </span>m)
{
    <span style="color: blue">base</span>.WndProc(<span style="color: blue">ref </span>m);
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Before we start jumping into adding jumplists, we want to remember that since this is an existing application meant to be run in existing versions of Windows, we’d like to make sure that we’ll only execute the additional code IF the application is running in Windows 7, otherwise, operate as usual. To do this, we check whether the OS version is 6.1 or greater (RC builds still register Major version as 6) with this code:</p>
<pre class="code"><span style="color: #2b91af">OperatingSystem </span>os = <span style="color: #2b91af">Environment</span>.OSVersion;
<span style="color: blue">if </span>((os.Version.Major == 6 &amp;&amp; os.Version.Minor &gt;= 1) || os.Version.Major &gt; 6)
{
    <span style="color: green">//some code
</span>}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Now for the fun part. The OS message that we want to lookout for is the message that tells us that the taskbar button has been created. Then we can start adding the Jumplist items to the button.</p>
<pre class="code"><span style="color: blue">if </span>(m.Msg == <span style="color: #2b91af">Windows7Taskbar</span>.TaskbarButtonCreatedMessage)
{
    <span style="color: blue">try
    </span>{

        jlm = <span style="color: blue">new </span><span style="color: #2b91af">JumpListManager</span>(appID);
        jlm.UserRemovedItems += <span style="color: blue">delegate </span>{ };

        <span style="color: blue">string </span>strAppDir = <span style="color: #2b91af">Path</span>.GetDirectoryName(<span style="color: #2b91af">Assembly</span>.GetEntryAssembly().Location);
        <span style="color: blue">string </span>app = <span style="color: #2b91af">Assembly</span>.GetEntryAssembly().GetName().Name + <span style="color: #a31515">&quot;.exe&quot;</span>;

        jlm.AddUserTask(<span style="color: blue">new </span><span style="color: #2b91af">ShellLink
        </span>{
            Title = <span style="color: #a31515">&quot;Color it Red!&quot;</span>,
            Path = <span style="color: #2b91af">Path</span>.Combine(strAppDir, app),
            Arguments = <span style="color: #a31515">&quot;/r&quot;</span>,
            IconLocation = <span style="color: #2b91af">Path</span>.Combine(strAppDir, <span style="color: #a31515">@&quot;ico\Red.ico&quot;</span>)

        });

        jlm.AddUserTask(<span style="color: blue">new </span><span style="color: #2b91af">ShellLink
        </span>{
            Title = <span style="color: #a31515">&quot;Color it Green!&quot;</span>,
            Path = <span style="color: #2b91af">Path</span>.Combine(strAppDir, app),
            Arguments = <span style="color: #a31515">&quot;/g&quot;</span>,
            IconLocation = <span style="color: #2b91af">Path</span>.Combine(strAppDir, <span style="color: #a31515">@&quot;ico\green.ico&quot;</span>)
        });
        jlm.Refresh();

        ProcessArguments();
    }
    <span style="color: blue">catch </span>(<span style="color: #2b91af">Exception</span>)
    {

    }</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Let’s break this down. </p>
<p><a href="http://aimeegurl.com/wp-content/uploads/2009/07/image3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://aimeegurl.com/wp-content/uploads/2009/07/image_thumb3.png" width="316" height="45" /></a> </p>
<p>We start by creating a new instance of the JumpListManager passing the appID we’ve assigned to our app. Next we register to the UserRemovedItems event as this is required if we want to refresh the JumpList after adding items to it. In this case, we do nothing when any items are removed.</p>
<p><a href="http://aimeegurl.com/wp-content/uploads/2009/07/image4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://aimeegurl.com/wp-content/uploads/2009/07/image_thumb4.png" width="649" height="49" /></a> </p>
<p>Here, we get the directory where the application is running as well as the app name itself, so we can tell the JumpList link what to invoke when it is clicked. Basically it’s emulating running your app from a command prompt and passing the arguments (if any). Now we can proceed to adding our JumpList items.</p>
<p><a href="http://aimeegurl.com/wp-content/uploads/2009/07/image5.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://aimeegurl.com/wp-content/uploads/2009/07/image_thumb5.png" width="516" height="165" /></a> </p>
<p>I’ve mentioned we can add a few other things such as Recent Documents &amp; Frequent Documents&#160; but you’ll find lots of resources on this on the net as well as the samples for the library. In this case, we’re adding a new User Task to the jumplist which results in having these links under a “Tasks” header as below:</p>
<p><a href="http://aimeegurl.com/wp-content/uploads/2009/07/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://aimeegurl.com/wp-content/uploads/2009/07/image_thumb1.png" width="306" height="229" /></a></p>
<p>Path, Arguments, and IconLocation are pretty self explanatory. </p>
<p><a href="http://aimeegurl.com/wp-content/uploads/2009/07/image6.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://aimeegurl.com/wp-content/uploads/2009/07/image_thumb6.png" width="227" height="496" /></a> </p>
<p>I need to make sure my icons are available to my application so here I’ve placed all my custom icons in one directory and set the property so the IDE knows to copy these files to the output directory.</p>
<p><a href="http://aimeegurl.com/wp-content/uploads/2009/07/image7.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://aimeegurl.com/wp-content/uploads/2009/07/image_thumb7.png" width="177" height="41" /></a> </p>
<p>After defining my JumpList links, I can call a Refresh on the JumpListManager so it loads up all my new links. After this, I make a call to my ProcessArguments method. This will make sure it runs the additional code if any arguments were passed when running the application. Of course, if you see that your users may want to run your app from a command line and pass arguments manually, you might want to put this call outside of the if statement or anywhere before your first form completes loading.</p>
<p>It’s that easy! If you got lost on the way, here’s the source to this project. If you manage to get your JumpLists going, feel free post a link to your app! <img src='http://aimeegurl.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p><iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 66px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-bdfb7845c22e26b6.skydrive.live.com/embedrowdetail.aspx/Projects/TechFriday/Hello%20Windows%207.zip" frameborder="0" marginwidth="0" scrolling="no"></iframe></p>
<p><strong>RESOURCES:</strong></p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=12100526-ed26-476b-8e20-69662b8546c1">Windows 7 RC Training Kit for Developers</a></p>
<p>Managed APIs in this sample&#160; </p>
<ul>
<li>Windows 7 Taskbar &#8211; <a title="http://code.msdn.microsoft.com/Windows7Taskbar" href="http://code.msdn.microsoft.com/Windows7Taskbar">http://code.msdn.microsoft.com/Windows7Taskbar</a> </li>
</ul>
<p>Other Managed APIs available:</p>
<ul>
<li>Windows API Code Pack for Microsoft .NET Framework &#8211; <a title="http://code.msdn.microsoft.com/WindowsAPICodePack" href="http://code.msdn.microsoft.com/WindowsAPICodePack">http://code.msdn.microsoft.com/WindowsAPICodePack</a> </li>
<li>Windows 7 Taskbar Extensions &#8211; <a title="http://windows7taskbarext.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=22682" href="http://windows7taskbarext.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=22682">http://windows7taskbarext.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=22682</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://aimeegurl.com/2009/07/10/techfriday-jumping-into-jumplists/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Silverlight 2 &amp; Dynamics CRM</title>
		<link>http://aimeegurl.com/2008/11/27/silverlight-2-dynamics-crm/</link>
		<comments>http://aimeegurl.com/2008/11/27/silverlight-2-dynamics-crm/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 06:52:06 +0000</pubDate>
		<dc:creator>Aimee</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[dynamics crm]]></category>
		<category><![CDATA[sample code]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://aimeegurl.com/2008/11/27/silverlight-2-dynamics-crm/</guid>
		<description><![CDATA[<p id="top" />
<p>I was doing some research on Silverlight 2 &#38; Dynamics CRM integration and found this post by Humberto Lezama Guadarrama where he posts a sample project that demonstrates how to consume Dynamics CRM Services directly from Silverlight 2. I was getting an initialize error when I tried to run the code though. This [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p>I was doing some research on Silverlight 2 &amp; Dynamics CRM integration and found <a href="http://blogs.msdn.com/lezamax/archive/2008/11/05/sample-silverlight-2-and-crm.aspx">this post</a> by <a href="http://blogs.msdn.com/lezamax">Humberto Lezama Guadarrama</a> where he posts a sample project that demonstrates how to consume Dynamics CRM Services directly from Silverlight 2. I was getting an initialize error when I tried to run the code though. <a href="http://blogs.microsoft.co.il/blogs/alex_golesh/archive/2008/07/22/quick-silverlight-tip-quot-initializeerror-2103-invalid-or-malformed-application-quot-what-is-it-and-how-to-deal-with-it.aspx">This post</a> helped me fix that. Turns out, there were some inconsistencies in the namespace declarations in the project properties. I’ve modified the code and uploaded them here for those of you who want to straight away run it without having to do the MODs yourself. </p>
<p><iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 26px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-bdfb7845c22e26b6.skydrive.live.com/embedrow.aspx/Projects/CRMSilverlightDirect-MOD.zip" frameborder="0" marginwidth="0" scrolling="no"></iframe></p>
<p><em>Note: to run the project, you should have Dynamics CRM installed and you’ll need to modify the server name and org name in the code to get it to work. </em></p>
]]></content:encoded>
			<wfw:commentRss>http://aimeegurl.com/2008/11/27/silverlight-2-dynamics-crm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
