Windows 7 Taskbar: User Tasks
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:
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.