Windows 7 Taskbar: User Tasks

February 23, 2009

tags:
3 comments

In the previous installment in this series, we have seen how the default support for recent and frequent documents provided by the operating system can give our application’s jump list a default vivid appearance without any effort on our part.  We have also seen that in specialized custom scenarios, it’s possible to add items to the recent/frequent categories explicitly.

In this post, we will look into customizing the jump list with user tasks, which are shortcuts to functionality our application can provide.  As you might remember, user tasks are the verbs in our vocabulary: Windows Media Player provides a “Resume last playlist” task and Sticky Notes provides a “New note” task.

A user task is usually an IShellLink object that launches your application (or another application) with specific command line arguments.  Tasks cannot be categorized, but they can be separated using a special separator object.  Here’s an example of a jump list that uses a separator between two tasks:

image

Adding tasks to the application’s jump list is as easy as one-two-three using the managed wrapper library (Windows7.DesktopIntegration).  Here’s all the code required to build the jump list section illustrated in the above screenshot:

_jumpListManager.AddUserTask(new ShellLink

{

    Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "notepad.exe"),

    Title = "Launch Notepad",

    IconLocation = shell32DllPath,

    IconIndex = 14

});

_jumpListManager.AddUserTask(new Separator());

_jumpListManager.AddUserTask(new ShellLink

{

    Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "calc.exe"),

    Title = "Launch Calculator",

    IconLocation = shell32DllPath,

    IconIndex = 15

});

_jumpListManager.Refresh();

(There’s also one line of code required to initialize the jump list manager, which we have seen in the previous post.)

Note that for each ShellLink object you are required to provide a path, a title and preferably also an icon location and index (I’m using the icons embedded into shell32.dll in the above example).  Other potentially useful properties on the ShellLink class include Arguments (for command-line arguments), WorkingDirectory and ShowCommand (for determining how the window will be shown).

Of course it is now your responsibility to integrate this functionality into your application.  For example, if you wanted to implement a “Resume last playlist” command in your custom media player, you would need to provide some sort of communication mechanism between the process launched by the user task and the existing media player process, if it were already loaded.  This is outside of the scope of what a framework can provide for you – but various creative solutions are possible.

Add comment
facebook linkedin twitter email

Leave a Reply to Soum Cancel Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

3 comments

  1. SoumFebruary 24, 2009 ב 3:37 AM

    Hi, thanks for the series of posts. Seriously appreciated.

    You said in the last post that clearing the jump list should not be done very frequently. Did you mean just the ones with auto-destinations enabled or the custom ones as well?

    Because I have an application that displays data from a database. It would make sense to have a frequent category there. Currently, I disable auto destinations, and track the frequent items myself. Whenever the list changes, I clear the list and populate it again. Is there any way to modify the list without clearing and starting over again?

    Reply
  2. Sasha GoldshteinFebruary 24, 2009 ב 1:30 PM

    What I was referring to is the recent/frequent automatic categories — you shouldn’t be clearing them unless there’s an exceptional scenario.

    W.r.t. custom destionation lists (the subject of the next post), you obviously will have to clear the list to re-populate it with items. That’s OK and is by design. Still, you should strive to refrain from doing things that would SURPRISE the user (that’s always true :-)).

    Reply
  3. Talking ClipboardMay 11, 2009 ב 8:56 AM

    Is there any sample, and how to make sure that the same app will work on XP also and on Win 7 with these new features?

    Reply