<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9</title>
    <atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Niners/c4f.Arian-Kulp/Posts/RSS"></atom:link>
    <itunes:summary></itunes:summary>
    <itunes:author>Microsoft</itunes:author>
    <itunes:subtitle></itunes:subtitle>
    <image>
      <url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
      <title>Channel 9</title>
      <link>http://channel9.msdn.com/Niners/c4f.Arian-Kulp/Posts</link>
    </image>
    <itunes:image href=""></itunes:image>
    <itunes:category text="Technology"></itunes:category>
    <description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
    <link>http://channel9.msdn.com/Niners/c4f.Arian-Kulp/Posts</link>
    <language>en</language>
    <pubDate>Wed, 22 May 2013 03:33:54 GMT</pubDate>
    <lastBuildDate>Wed, 22 May 2013 03:33:54 GMT</lastBuildDate>
    <generator>Rev9</generator>
    <c9:totalResults>2</c9:totalResults>
    <c9:pageCount>1</c9:pageCount>
    <c9:pageSize>25</c9:pageSize>
  <item>
      <title>Windows 7: Jump Lists</title>
      <description><![CDATA[
<p>In this article, learn how to provide quick access to links and actions in your Windows 7 application by creating a Jump List.</p>

<h3>Introduction</h3>
<p>Windows 7 includes a wealth of new features for developers to take advantage of.&nbsp; This includes better rendering subsystems, new sensor and location API's, file libraries, federated search, and of course, the improved taskbar.&nbsp; My last article discussed
 the taskbar's ability to show custom previews and toolbar icons.&nbsp; This article focuses on Jump Lists - the replacement for notification area context menus.</p>
<p>To get started, download <a href="http://www.microsoft.com/exPress/" target="_blank">
Visual Studio 2008 Express Edition</a> or higher (C# or VB).&nbsp; Or, just go for <a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" target="_blank">
Visual Studio 2010 Beta 2</a> - it's available now and well worth the download.&nbsp; All Express editions are free, and either 2008 or 2010 versions will work fine with this article's accompanying code.</p>
<h3>What's a Jump List?</h3>
<p>Jump Lists are a new concept in Windows 7 that allow developers to provide shortcuts for users right from their icon's context menu in the taskbar or Start menu.&nbsp; The shortcuts could be simple links to the documents folder or a library for a given application,
 or links back to the same application with a parameter passed to cause something to happen.</p>
<p>You can use this method in Live Messenger to change online status, display the new message window, or open web pages relating to the application.&nbsp; In the end, all of these are shortcuts.&nbsp; Shortcuts to URL's, or shortcuts back to the executable with an argument
 that causes some change to occur.</p>
<h3>Windows API Code Pack</h3>
<p>The Windows API Code Pack lets you take advantage of specific features of Windows Vista and Windows 7 that aren't available across the general framework, as well as native features that don't make sense in the common CLR used across all the supported configurations.
 Much of it consists of interop wrappers. </p>
<p>With the Code Pack, you get access to the new taskbar, Direct2D, DirectWrite, shell properties, Jump Lists, and more. The download also includes numerous sample code projects to get you started, so there's no excuse for avoiding new features!
</p>
<h3>Adding a Jump List</h3>
<p>Adding a Jump List is easy.&nbsp; After you create the list itself, add items (shortcuts to files or folders, and tasks) to it.&nbsp; Then, you can choose how a user's recent or frequently used documents show up.&nbsp; Windows manages the user documents list, which relieves
 you of some work. </p>
<p>It's important to note that in order to make a change to the list, you have to recreate the entire thing.&nbsp; In other words, you'll replace the old list with a new one, rather than updating it.
</p>
<p>Here's how the process works: </p>
<p>First, add the two required references from the Windows API Code Pack.&nbsp; You can either build a project and reference the DLL's, or directly add projects to your solution:
</p>
<p></p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9933039/image_6.png"><img title="Windows API Code Pack references" border="0" alt="Windows API Code Pack references" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9933039/image_thumb_1.png" width="244" height="84"></a></p>
<p>For convenience, you can add the namespaces to your <em>using </em>block to shorten typing later:
</p>
<p><strong>Visual Basic</strong></p>
<pre class="csharpcode"><span class="kwrd">Imports</span> Microsoft.WindowsAPICodePack.Taskbar
<span class="kwrd">Imports</span> Microsoft.WindowsAPICodePack.Shell</pre>
<p><strong>Visual C#</strong></p>
<pre class="csharpcode"><span class="kwrd">using</span> Microsoft.WindowsAPICodePack.Taskbar;
<span class="kwrd">using</span> Microsoft.WindowsAPICodePack.Shell;</pre>
<p>&nbsp;</p>
<p>The <em>Microsoft.WindowsAPICodePack.Taskbar.JumpList </em>class is where most of the action is.&nbsp; There's a static factory method,
<em>CreateJumpList</em>, to create the list.&nbsp; Always start by calling this method, even if the application has created a Jump List in the past.</p>
<p><strong>Visual Basic</strong></p>
<pre class="csharpcode"><span class="kwrd">Private</span> <span class="kwrd">Sub</span> CreateJumpList()
    <span class="kwrd">Dim</span> jl <span class="kwrd">As</span> JumpList = JumpList.CreateJumpList()</pre>
<p><strong>Visual C#</strong></p>
<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">void</span> CreateJumpList()
{
    JumpList jl = JumpList.CreateJumpList();</pre>
<p>&nbsp;</p>
<p>Next, you have several options, depending on what you need in the list.&nbsp; The most basic group is the list of files.&nbsp; You can choose to show Recent files, Frequent files, or neither-but you can't have both.&nbsp; If you don't make a choice here, you'll get Recent
 files automatically, as long as you have a registered file type. </p>
<p><strong>Visual Basic</strong></p>
<pre class="csharpcode"><span class="rem">' Show user files: Recent, Frequent, or None</span>
jl.KnownCategoryToDisplay = JumpListKnownCategoryType.Recent</pre>
<p><strong>Visual C#</strong></p>
<p><span class="rem">// Show user files: Recent, Frequent, or None</span> <br>
jl.KnownCategoryToDisplay = JumpListKnownCategoryType.Recent; <br>
</p>
<p>Now you can add one or more custom categories of items.&nbsp; These are either folders or files.&nbsp; There are two very important rules:</p>
<ol>
<li>The files/folders must exist!&nbsp; If necessary, check the path before adding the
<em>JumpListItem </em>or you'll have a crash.&nbsp; </li><li>The files you add have to be of a type registered for your application, or you'll crash. Even worse: the exception won't occur on the line where you add it, but rather when you're done setting it up and try to refresh the list.
</li></ol>
<p>I've commented out the last item here, but you would use a <em>JumpListItem </em>
for actual file system files, and <em>JumpListLink </em>objects for non-filesystem references.&nbsp; Again, don't add a JumpListItem unless you know that it exists and that you're registered to handle it.</p>
<p><strong>Visual Basic</strong></p>
<pre class="csharpcode"><span class="rem">' Add my own links (nouns)</span>
<span class="kwrd">Dim</span> catActions <span class="kwrd">As</span> <span class="kwrd">New</span> JumpListCustomCategory(<span class="str">&quot;Destinations&quot;</span>)

catActions.AddJumpListItems(
    <span class="kwrd">New</span> JumpListLink(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), <span class="str">&quot;My Pictures&quot;</span>), _
    <span class="kwrd">New</span> JumpListLink(<span class="str">&quot;http://blogs.msdn.com/coding4fun&quot;</span>, <span class="str">&quot;Visit Coding4Fun&quot;</span>), _
    <span class="kwrd">New</span> JumpListLink(<span class="str">&quot;http://code.msdn.microsoft.com/WindowsAPICodePack&quot;</span>, <span class="str">&quot;Windows API Code Pack&quot;</span>))
    <span class="rem">'new JumpListItem(@&quot;c:\Test1.c4f&quot;)</span>

jl.AddCustomCategories(catActions)</pre>
<p><strong>Visual C#</strong></p>
<pre class="csharpcode"><span class="rem">// Add my own links (nouns)</span>
JumpListCustomCategory catActions = <span class="kwrd">new</span> JumpListCustomCategory(<span class="str">&quot;Destinations&quot;</span>);
catActions.AddJumpListItems(
    <span class="kwrd">new</span> JumpListLink(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), <span class="str">&quot;My Pictures&quot;</span>),
    <span class="kwrd">new</span> JumpListLink(<span class="str">&quot;http://blogs.msdn.com/coding4fun&quot;</span>, <span class="str">&quot;Visit Coding4Fun&quot;</span>),
    <span class="kwrd">new</span> JumpListLink(<span class="str">&quot;http://code.msdn.microsoft.com/WindowsAPICodePack&quot;</span>, <span class="str">&quot;Windows API Code Pack&quot;</span>)
    <span class="rem">//new JumpListItem(@&quot;c:\Test1.c4f&quot;)</span>
    );

jl.AddCustomCategories( catActions);</pre>
<p>You can add one or more tasks as&nbsp; links to system executables by using the <em>
AddUserTasks </em>method of the JumpList object.&nbsp; Either create multiple objects and add them as a variable argument list, or add them one at a time, as I have here.</p>
<p><strong>Visual Basic</strong></p>
<pre class="csharpcode"><span class="rem">' Add our user tasks (verbs)</span>
jl.AddUserTasks(<span class="kwrd">New</span> JumpListLink(Path.Combine(systemFolder, <span class="str">&quot;notepad.exe&quot;</span>), <span class="str">&quot;Open Notepad&quot;</span>) _
    <span class="kwrd">With</span> {.IconReference = <span class="kwrd">New</span> IconReference(Path.Combine(systemFolder, <span class="str">&quot;notepad.exe&quot;</span>), 0)})</pre>
<p><strong>Visual C#</strong></p>
<pre class="csharpcode">jl.AddUserTasks(<span class="kwrd">new</span> JumpListLink(Path.Combine(systemFolder, <span class="str">&quot;notepad.exe&quot;</span>), <span class="str">&quot;Open Notepad&quot;</span>)
{
    IconReference = <span class="kwrd">new</span> IconReference(Path.Combine(systemFolder, <span class="str">&quot;notepad.exe&quot;</span>), 0)
});</pre>
<p>The <em>IconReference</em> property sets a pointer to the icon by referencing a DLL or EXE and then an index.&nbsp; Specifying an EXE with &quot;0&quot; is a good way to get the default icon for an executable that you are linking to.</p>
<p>You can add a separator to the list whenever you need to.&nbsp; The <i>JumpListSeparator
</i>class represents a separator and can be added using the <i>AddUserTasks </i>call.
</p>
<p><strong>Visual Basic</strong></p>
<pre class="csharpcode">jl.AddUserTasks(<span class="kwrd">New</span> JumpListSeparator())</pre>
<p><strong>Visual C#</strong></p>
<pre class="csharpcode">jl.AddUserTasks(<span class="kwrd">new</span> JumpListSeparator());</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>The final links in our Jump List link back to our own executable. This is the most common use of Jump Lists.&nbsp; Just having a Recent/Frequent list is nice, but being able to trigger actions on the program itself-even when it's not started-is really handy.&nbsp;
 It's almost like a menu of command line options! </p>
<p>Commands in the list that invoke actions on the application itself involve calling the same application with different arguments.&nbsp; Remember that this isn't a true menu; you won't receive a
<em>Click</em> event.&nbsp; Instead, you need to deal with an argument that's passed to you, even if you're already running.
</p>
<p>Remember that the first argument on the command line is always the fully-qualified location to the running executable.&nbsp; The
<i>Arguments </i>property lets you specify command line arguments that users don't directly see.&nbsp; For this sample application, I've defined three dummy arguments.&nbsp; If one of these is passed in, the application changes the background color of a label and indicates
 which argument it was. </p>
<p></p>
<p><strong>Visual Basic</strong></p>
<pre class="csharpcode">jl.AddUserTasks(<span class="kwrd">New</span> JumpListLink(<span class="kwrd">Assembly</span>.GetEntryAssembly().Location, <span class="str">&quot;Action 1 (Green)&quot;</span>) _
    <span class="kwrd">With</span> {.Arguments = <span class="str">&quot;-1&quot;</span>, .IconReference = <span class="kwrd">New</span> IconReference(<span class="kwrd">Assembly</span>.GetEntryAssembly().Location, 0)})</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><strong>Visual C#</strong></p>
<pre class="csharpcode">jl.AddUserTasks(<span class="kwrd">new</span> JumpListLink(Assembly.GetEntryAssembly().Location, <span class="str">&quot;Action 1 (Green)&quot;</span>)
{
    IconReference = <span class="kwrd">new</span> IconReference(Assembly.GetEntryAssembly().Location, 0),
    Arguments = <span class="str">&quot;-1&quot;</span>
});</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9933039/image_12.png"><img title="Sample JumpList" border="0" alt="Sample JumpList" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9933039/image_thumb_2.png" width="267" height="367"></a>
</p>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<h3>Invoking Self Actions</h3>
<p>Windows Live Messenger uses Jump List actions for setting its own available status, and Windows Media Player has Jump List actions for skipping tracks or stopping.&nbsp; Likewise, you can add tasks that invoke actions on the same executable.&nbsp; If the application
 isn't running (remember that the Jump List is still available), this will cause it to be launched with the right argument.&nbsp; That's no problem.&nbsp; What if it's already running though?</p>
<p>The key is to find a way to pass messages between running instances.&nbsp; When the application starts up, check to see if another instance is running by using a
<em>Mutex </em>(see <em>Program.cs</em>).&nbsp; If not, just use the arguments directly.&nbsp; If it is running, send the information about the parameter to the other instance and then quit.&nbsp; You could use temporary files, shared registry keys, or memory-mapped files.&nbsp;
 I find it easiest to use window messages.</p>
<p>You can find the code to create custom message ID's, to find the right window, and to send the message in my
<em>WindowsMessageHelper </em>class.</p>
<p>From the main window code, override the <em>WndProc </em>method.&nbsp; This is the message loop for everything: mouse events, key events, window closing, and much more.&nbsp; Ensure that the message is something you need; otherwise pass it on to the underlying handler.</p>
<p>If the application is already running, post a message.&nbsp; If not, start as usual and watch your message queue.&nbsp; If you see a message of interest, take some action (in this case, just showing a message and changing a color).&nbsp;
</p>
<p>The only other tricky thing to remember, is that you might startup as the only instance, and
<em>also </em>have a parameter.&nbsp; For example, if the user clicked a task on the Jump List but the application isn't running.&nbsp; I take the easy way out and check for parameters after fully starting up and then post to my own queue if needed!&nbsp; That simplifies
 some of the logic anyway.</p>
<p>If you don't mind using the <strong>Microsoft.VisualBasic.ApplicationServices</strong> namespace from C#, then you can take advantage of the VB SingleInstance application mode.&nbsp; This removes the need for any explicit mutex, interop, or message passing.&nbsp;
 You can find some great information about this on Jocelyn Villaraza's excellent <a href="http://aimeegurl.com/2009/11/13/making-your-win7-jumplists-trigger-on-the-same-application-instance/" target="_blank">
blog post</a>.</p>
<h3>Registering a File Type</h3>
<p>Remember: unless you're registered as a file handler for the type, you can't show recent or frequent files or point to individual files.&nbsp; Register to be a file handler by creating a registry write operation to a key under HKEY_CLASSES.&nbsp;
</p>
<p>The problem is, you can't write to the HKEY_CLASSES branch of the registry without proper permissions.&nbsp; By default, permission is only granted to the Administrators group.&nbsp; You really don't want to require that your application run under administrative privileges-that
 would be <i>so </i>Windows XP! </p>
<p>There are two alternatives: you could create a second application that can run elevated in order to perform the registration.&nbsp; This is how the samples do it with the Windows API Code Pack. A better method is to create a custom installer for the project and
 perform the association there.&nbsp; Installers always require administrative rights, and they only need to run once.
</p>
<p></p>
<h3>Creating the Installer</h3>
<p>To create the installer, first add a setup project to your solution, following the usual steps. Then, from the
<b>Project types </b>list, click <b>Other Project Types | Setup and Deployment</b>.&nbsp; In the
<b>Templates </b>list, click <b>Setup Project</b>. Give it a name, then add it.</p>
<h3><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9933039/image_10.png"><img title="New project types" border="0" alt="New project types" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9933039/image_thumb_4.png" width="640" height="463"></a>
</h3>
<p>From <strong>Solution Explorer</strong>, right-click the setup project, then click the
<strong>View | File Types </strong>menu command.</p>
<h3><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9933039/image_8.png"><img title="View File Types" border="0" alt="View File Types" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9933039/image_thumb_3.png" width="418" height="264"></a>
</h3>
<p>From the File Types list, right-click <strong>File Types on Target Machine</strong>, and then click
<strong>Add File Type</strong>.&nbsp; Fill out the properties to name the file type and provide the extension.&nbsp; For
<strong>Command</strong>, be sure to set it to the Primary output of the main project.&nbsp;
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9933039/image_16.png"><img title="File type properties" border="0" alt="File type properties" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9933039/image_thumb_6.png" width="342" height="194"></a>
</p>
<p>The file type should appear like the following in the <strong>File Types </strong>
tab:</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9933039/image_14.png"><img title="File Types list" border="0" alt="File Types list" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/9933039/image_thumb_5.png" width="196" height="87"></a>
</p>
<p>Now you have a registered file type.&nbsp; You still need to modify your setup project to copy the primary output (the EXE) to Program Files and customize any other properties in the setup project, but these are the special steps for file types.&nbsp; If in doubt,
 take a look at sample code to see how the Setup project is configured.</p>
<h3>Conclusion</h3>
<p></p>
<p></p>
<p></p>
<p>Working with the Windows API Code Pack makes it much easier to customize the taskbar and add Jump Lists, and gives you a great experience that really integrates well with the system.&nbsp; Download Visual Studio Express, grab the Windows API Code Pack, and start
 digging in.</p>
<p>The new features won't work on machines prior to Windows 7, so be sure to check that they're supported.</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/c4f.Arian-Kulp/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:b31966c53e384bc0ab3f9e7600ca8ef7">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Windows-7-Jump-Lists</comments>
      <itunes:summary>
In this article, learn how to provide quick access to links and actions in your Windows 7 application by creating a Jump List. 

Introduction
Windows 7 includes a wealth of new features for developers to take advantage of.&amp;nbsp; This includes better rendering subsystems, new sensor and location API&#39;s, file libraries, federated search, and of course, the improved taskbar.&amp;nbsp; My last article discussed
 the taskbar&#39;s ability to show custom previews and toolbar icons.&amp;nbsp; This article focuses on Jump Lists - the replacement for notification area context menus. 
To get started, download 
Visual Studio 2008 Express Edition or higher (C# or VB).&amp;nbsp; Or, just go for 
Visual Studio 2010 Beta 2 - it&#39;s available now and well worth the download.&amp;nbsp; All Express editions are free, and either 2008 or 2010 versions will work fine with this article&#39;s accompanying code. 
What&#39;s a Jump List?
Jump Lists are a new concept in Windows 7 that allow developers to provide shortcuts for users right from their icon&#39;s context menu in the taskbar or Start menu.&amp;nbsp; The shortcuts could be simple links to the documents folder or a library for a given application,
 or links back to the same application with a parameter passed to cause something to happen. 
You can use this method in Live Messenger to change online status, display the new message window, or open web pages relating to the application.&amp;nbsp; In the end, all of these are shortcuts.&amp;nbsp; Shortcuts to URL&#39;s, or shortcuts back to the executable with an argument
 that causes some change to occur. 
Windows API Code Pack
The Windows API Code Pack lets you take advantage of specific features of Windows Vista and Windows 7 that aren&#39;t available across the general framework, as well as native features that don&#39;t make sense in the common CLR used across all the supported configurations.
 Much of it consists of interop wrappers.  
With the Code Pack, you get access to the new taskbar, Direct2D, DirectWrite, shell properties, Jump Li</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Windows-7-Jump-Lists</link>
      <pubDate>Wed, 09 Dec 2009 21:59:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Windows-7-Jump-Lists</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/9933039_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/9933039_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Arian Kulp </dc:creator>
      <itunes:author>Arian Kulp </itunes:author>
      <slash:comments>13</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Windows-7-Jump-Lists/RSS</wfw:commentRss>
      <category>Windows 7</category>
      <category>windows miscellaneous</category>
    </item>
  <item>
      <title>Wallpaper Cycler</title>
      <description><![CDATA[<span id="c4fmetadata">
<table cellspacing="0" cellpadding="1" width="100%" border="0">
<tbody>
<tr class="entry_overview">
<td width="50">&nbsp;</td>
<td><span class="entry_description">This sample demonstrate simple wallpaper cycler. It expects a folder in which it will find images. Upon startup, it will change the wallpaper, and it will even modify the placement behavior based on the size of the image
 found.</span></td>
</tr>
<tr>
<td colspan="2">
<div class="entry_author">Arian Kulp </div>
<div class="entry_company"><a href="http://www.ariankulp.com">Arian Kulp's Blog</a></div>
<br>
<div class="entry_details"><b>Difficulty: </b><span class="entry_details_input">Easy</span></div>
<div class="entry_details"><b>Time Required:</b> <span class="entry_details_input">
1-3 hours</span></div>
<div class="entry_details"><b>Cost: </b><span class="entry_details_input">Free</span></div>
<div class="entry_details"><b>Software: </b><span class="entry_details_input"><a href="http://msdn.com/express/">Visual Basic or Visual C# Express Editions</a></span></div>
<div class="entry_details"><b>Hardware: </b><span class="entry_details_input"></span></div>
<div class="entry_details"><b>Download: </b>
<ul>
<li><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1067250/WallpaperCycler_CS.msi">C# Download</a>
</li><li><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1067250/WallpaperCycler_VB.msi">VB Download</a>
</li></ul>
</div>
</td>
</tr>
</tbody>
</table>
</span>
<p>A number of articles ago, a simple wallpaper utility was written. I thought it would be nice to put together some of the concepts that we've looked at recently and create a new, enhanced wallpaper changer. Specifically, this application is no longer based
 on a specific file. Instead, it expects a folder in which it will find images. Upon startup, it will change the wallpaper, and it will even modify the placement behavior based on the size of the image found.</p>
<p>You can read the article now, but for added benefit download a copy of Visual Studio 2005 Express Edition for
<a href="http://www.microsoft.com/express/">C# or Visual Basic</a>. These are free if downloaded during most of 2006, and provide all of the tools necessary to create great applications. After you install Visual Studio Express, download the code for this article from the links at the top. Choose from C# or
 Visual Basic, according to your personal preference—the applications are functionally identical.</p>
<p>As with most recent <a href="/coding4fun/inthebox/default.aspx">In the Box</a> columns, this application will start with no visible interface beyond its notification icon in the system tray. The available options will be to display the settings, change the
 wallpaper on-demand, or exit. The &quot;Show Settings&quot; option is in bold. This is a visual cue that if you double-click the icon, this is the action that will take place. There is no built-in support for this feature. Simply set the menu item's
<b>Font.Bold</b> property to &quot;True&quot; and create a <b>MouseDoubleClick</b> event handler for the
<b>NotifyIcon</b> control.</p>
<img alt="" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1067250/wallpaper2_1.gif" border="0">
<p><b>Figure 1: The notification icon menu</b></p>
<h1>Scanning folders</h1>
<p>The heart of the application is its ability to scan a folder randomly to find an image to display as the desktop background. This is surprisingly easy using the
<b>System.IO.Directory</b> class. Its static/shared <b>GetFiles </b>method returns a collection of all files in a given folder. You can optionally pass a wildcard pattern, and a recursive qualifier. It would have made sense to specify a wildcard pattern including
 extensions like .JPG and .GIF, but apparently only a single expression can be used. The third parameter takes an argument of type
<b>System.IO.SearchOption</b>. This is where you can specify a top-level file listing (<b>TopDirectoryOnly</b>), or a recursive (<b>AllDirectories</b>) one.</p>
<p><b>Visual Basic</b></p>
<pre><code>' Specify top-level or sub-folders
Dim opt As System.IO.SearchOption = _
     System.IO.SearchOption.TopDirectoryOnly

If subfoldersCheckbox.Checked Then
    opt = System.IO.SearchOption.AllDirectories

End If

' Grab complete list of files
Dim files As String() = System.IO.Directory.GetFiles( _
    picturesPathTextBox.Text, &quot;*&quot;, opt)
</code></pre>
<p><b>Visual C#</b></p>
<pre><code>// Specify top-level or sub-folders
System.IO.SearchOption opt = System.IO.SearchOption.TopDirectoryOnly;
if( FsubfoldersCheckbox.Checked ) opt = 
    System.IO.SearchOption.AllDirectories;

// Grab complete list of files
string[] files = System.IO.Directory.GetFiles(
picturesPathTextBox.Text, &quot;*&quot;, opt);
</code></pre>
<p>At this point, the <b>files</b> object contains an array of strings. Each entry is a fully-qualified filename from within the supplied folder. It would be nice to just randomly select an entry from this collection, but recall that we were not able to filter
 based on file extension. This must be done now. Two other exclusions also apply. First, we don't want to select the file that was used last time (we save one time back). Second, we don't want to select the temporary image that we generate (discussed later).
 The following code demonstrates copying the array into a generic List collection, element by element, provided that each element meets our exacting criteria.</p>
<p><b>Visual Basic</b></p>
<pre><code>' Filter list to remove non-images, last image shown,
' and the app-generated BMP file from a previous run.
Dim filteredFiles As New List(Of String)()

For Each file As String In files

    Dim ext As String = file.Substring(file.LastIndexOf(&quot;.&quot;))

    If &quot;.jpg .bmp .gif&quot;.IndexOf(ext) &gt; -1 AndAlso _
        file.EndsWith(&quot;coding4fun-desktop.bmp&quot;) = False AndAlso _
        Not file = My.Settings.LastImageShown Then

        filteredFiles.Add(file)
    End If
Next</code></pre>
<p><b>Visual C#</b></p>
<pre><code>// Filter list to remove non-images, last image shown,
// and the app-generated BMP file from a previous run.

List&lt;String&gt; filteredFiles = new List&lt;string&gt;();
foreach (string file in files)
{
    string ext = file.Substring(file.LastIndexOf(&quot;.&quot;));

    if (&quot;.jpg .bmp .gif&quot;.IndexOf(ext) &gt; -1 &amp;&amp;

        !file.EndsWith(&quot;coding4fun-desktop.bmp&quot;) &amp;&amp;
        file != settings.LastImageShown)
    {
        filteredFiles.Add(file);
    }
}</code></pre>
<p>After all of this processing, it is possible that no files remain in our collection. Perhaps the folder was empty initially, none of the files were images, or the only image found was used last time. Either nothing will be returned, or a random index will
 be generated to grab one element out of the collection. Recall that these elements are full pathnames. We will save that pathname as the
<b>LastImageShown</b> setting, create a <b>Bitmap</b> object given the pathname, then return that object.</p>
<p><b>Visual Basic</b></p>
<pre><code>' Make sure there are any files left
If filteredFiles.Count = 0 Then Return Nothing

' Randomly grab a file
Dim filename As String = filteredFiles(rnd.Next(filteredFiles.Count))


' Remember last image shown
My.Settings.LastImageShown = filename
My.Settings.Save()

' Return the bitmap object from this filename
Return New Bitmap(filename)
</code></pre>
<p><b>Visual C#</b></p>
<pre><code>// Make sure there are any files left
if (filteredFiles.Count == 0) 
    return null;


// Randomly grab a file
string filename = filteredFiles[rnd.Next(filteredFiles.Count)];

// Remember last image shown
settings.LastImageShown = filename;
settings.Save();

// Return the bitmap object from this filename
return new Bitmap(filename);</code></pre>
<p>Finally the image is saved as a BMP file in the <i>My Pictures</i> folder, and passed to the appropriate system API function,
<b>SystemParametersInfo</b><code>,</code> to effect the change. Most of this is the same as in the original
<a href="/coding4fun/inthebox/wallpaper/default.aspx">In the Box</a> column referenced above, but the original required an image to be in BMP format to begin with. As it turns out, once you have loaded an image into a
<b>Bitmap </b>object, saving as a BMP file format is a single line of code:</p>
<p><b>Visual Basic</b></p>
<pre><code>' Convert to BMP and save

img.Save(picturesPath, System.Drawing.Imaging.ImageFormat.Bmp)</code></pre>
<p><b>Visual C#</b></p>
<pre><code>// Convert to BMP and save)
img.Save(picturesPath, System.Drawing.Imaging.ImageFormat.Bmp);</code></pre>
<p>Study the <b>SetDesktopBackground</b> static/shared method in <b>WindowsAPI.vb/.cs</b> to see the implementation details.</p>
<p><b>Settings</b></p>
<p>Because the image to display can vary wildly each time, the settings dialog includes a number of behavioral settings. The first checkbox allows you to specify if sub-folders should be scanned or not. If you are pointing at a collection of home photos divided
 into sub-folders for albums, this could be useful.</p>
<p>The three <b>ComboBox</b> controls allow some flexibility in how images are displayed depending on their size relative to the desktop size. By default, images larger than the desktop will be stretched to fit. Now the term &quot;stretched&quot; is taken from the Windows
<b>Display</b> control panel. It's a bit of a misnomer, since what it really means is &quot;stretched or shrunk&quot; in either direction to exactly fill the screen. It's really ugly if you have a widescreen display and conventional (4:3) images.</p>
<p>Images smaller than the screen will be centered. The final category, Tiled, is a bit more flexible. If you have very small images, you may want to tile them for a repeating pattern. Just specify how small is small (128 pixels in both directions, by default),
 specify the action (it doesn't need to be Tiled), and watch it go. I personally like the defaults, but it made some sense to allow them to be preferences so anyone can change them easily.</p>
<img alt="" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1067250/wallpaper2_2.gif" border="0">
<p><b>Figure 2: Settings dialog</b></p>
<p>All of the settings directly correspond to project settings defined in Visual Studio. This nifty feature lets you define settings at the user or application level, set a datatype, and even a default value. Then, to complete the coolness, you can actually
 databind these settings to the controls. All you need to do is load and save when necessary. The mechanics of copying data between controls and settings are taken care of for you!</p>
<img alt="" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1067250/wallpaper2_3.gif" border="0">
<p><b>Figure 3: Databinding settings</b></p>
<p><b>Working with the Registry</b></p>
<p>The application must write to the registry in order to set the stretched/tiled/centered attributes. This is very easy using the
<b>Registry </b>object. Just use a static property, such as <b>CurrentUser </b>to access the HKEY_CURRENT_USER key. You can dig deeper by using a method like
<b>OpenSubKey </b>to open nested keys and access their values. The wallpaper cycler application also uses the registry to add itself to Windows startup. The auto-start
<b>CheckBox</b> control calls some shared/static methods in the <b>WindowsAPI </b>
class to add and remove itself:</p>
<p><b>Visual Basic</b></p>
<pre><code>' Based on checkbox, call API functions to add or remove
' application path from registry Run section for current user.

If autostartCheckbox.Checked Then
    WindowsAPI.AddStartupItem(&quot;BackgroundCycler&quot;, _ 
    System.Reflection.Assembly.GetEntryAssembly().Location)
Else
    WindowsAPI.RemoveStartupItem(&quot;BackgroundCycler&quot;)

End If
</code></pre>
<p><b>Visual C#</b></p>
<pre><code>
// Based on checkbox, call API functions to add or remove
// application path from registry Run section for current user.
            if (autostartCheckbox.Checked)
            {
                WindowsAPI.AddStartupItem(&quot;BackgroundCycler&quot;,
                    System.Reflection.Assembly.GetEntryAssembly().Location);
            }
            else

            {
                WindowsAPI.RemoveStartupItem(&quot;BackgroundCycler&quot;);
            }</code></pre>
<p>Notice the call to <b>System.Reflection.Assembly </b>class. The <b>GetEntryAssembly
</b>method returns a reference to the assembly that contained the startup code for the current application. The
<b>Location </b>property returns the assembly filename, in this case the path to the executable file. In the
<b>AddStartupItem </b>method, the sub-key for the current user's <b>Run </b>entries is opened, and a new value is added. So simple, but so powerful:</p>
<p><b>Visual Basic</b></p>
<pre><code>Dim key As RegistryKey = _
    Registry.CurrentUser.OpenSubKey( _
    &quot;Software\Microsoft\Windows\CurrentVersion\Run&quot;, True)
key.SetValue(name, path)</code></pre>
<p><b>Visual C#</b></p>
<pre><code>RegistryKey key = Registry.CurrentUser.OpenSubKey(
                @&quot;Software\Microsoft\Windows\CurrentVersion\Run&quot;, true);

            key.SetValue(name, path);
</code></pre>
<h1>Potential Enhancements</h1>
<p>The application is ready to use, and fun too! You can change wallpaper frequently, even if your images are not already in BMP format, and you don't need to go into Desktop properties to do it. It might also be fun to add an option to automatically change
 images on a timed interval. Another challenge would be to provide the ability to download images at random from URLs. You could provide a URL to an image gallery, scan the HTML for image links, then randomly select one to download, convert, and show as wallpaper.
 Lots of options!</p>
<h1>Conclusion</h1>
<p>I hope this got you thinking about things to do with the <b>Bitmap </b>object, the
<b>Registry </b>object, and desktop interaction. Be sure to visit <a href="http://msdn.microsoft.com/vstudio/express/">
http://msdn.microsoft.com/vstudio/express/</a> to download your preferred version of Visual Studio 2005 Express Edition. Then, take a look at the source code for this project, learn, and do even more. Good luck, and best of all, have fun!</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/c4f.Arian-Kulp/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:741c8f5444cc4959a3db9e7600d85c36">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Wallpaper-Cycler</comments>
      <itunes:summary>



&amp;nbsp;
This sample demonstrate simple wallpaper cycler. It expects a folder in which it will find images. Upon startup, it will change the wallpaper, and it will even modify the placement behavior based on the size of the image
 found.



Arian Kulp 
Arian Kulp&#39;s Blog

Difficulty: Easy
Time Required: 
1-3 hours
Cost: Free
Software: Visual Basic or Visual C# Express Editions
Hardware: 
Download: 

C# Download
VB Download







A number of articles ago, a simple wallpaper utility was written. I thought it would be nice to put together some of the concepts that we&#39;ve looked at recently and create a new, enhanced wallpaper changer. Specifically, this application is no longer based
 on a specific file. Instead, it expects a folder in which it will find images. Upon startup, it will change the wallpaper, and it will even modify the placement behavior based on the size of the image found. 
You can read the article now, but for added benefit download a copy of Visual Studio 2005 Express Edition for
C# or Visual Basic. These are free if downloaded during most of 2006, and provide all of the tools necessary to create great applications. After you install Visual Studio Express, download the code for this article from the links at the top. Choose from C# or
 Visual Basic, according to your personal preference—the applications are functionally identical. 
As with most recent In the Box columns, this application will start with no visible interface beyond its notification icon in the system tray. The available options will be to display the settings, change the
 wallpaper on-demand, or exit. The &amp;quot;Show Settings&amp;quot; option is in bold. This is a visual cue that if you double-click the icon, this is the action that will take place. There is no built-in support for this feature. Simply set the menu item&#39;s
Font.Bold property to &amp;quot;True&amp;quot; and create a MouseDoubleClick event handler for the
NotifyIcon control. 

Figure 1: The notification icon menu 
Scanning folders
Th</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Wallpaper-Cycler</link>
      <pubDate>Mon, 13 Nov 2006 06:16:02 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Wallpaper-Cycler</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/1067250_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/1067250_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Arian Kulp </dc:creator>
      <itunes:author>Arian Kulp </itunes:author>
      <slash:comments>10</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Wallpaper-Cycler/RSS</wfw:commentRss>
      <category>image</category>
      <category>wall paper</category>
    </item>    
</channel>
</rss>