Windows 7 Taskbar: Jump Lists

February 20, 2009

tags:
5 comments

imageThe Start Menu has long been with us; it provides a launch surface for applications and recent documents.  The Vista Start Menu revolutionized the accessibility of these applications and documents by giving us the amazing Search box which can enhance productivity in so many ways.  However, in spite of these improvements, it still cannot provide access to tasks and documents that are specific to a single application.  When the application is up, it can show us a menu or offer common tasks – but if the application is not running, the only thing we can do is start it up.

With the consolidation and revolution of launch surfaces that is integral in the design of the Windows 7 desktop, EVERY application now has a start menu.  This start menu, termed the jump list, gives every application a place for categorized destinations and tasks that are specific to that application.

There are two manifestations of the jump list in the current Windows 7 UI: As part of the traditional Start Menu, and as a popup menu from the application’s taskbar button.

Here’s a screenshot of my own start menu, showing the Windows Live Writer and Windows Media Player jump lists:

image image

Alternatively, here’s a screenshot of the popup jump list from the Windows Live Writer and Windows Media Player taskbar buttons:

imageimage

There are several things worth paying attention to in these screenshots (other than the completely fictitious .avi files :-) )  – the jump list seems to have many customizable parts that are different across different applications (and we have just two examples to look at!).  Let us examine a sample jump list that demonstrates more functionality.  This is the same jump list you can see by launching the Windows7.DesktopIntegration.MainDemo project, registering the file type (Administrative –> Register File Extensions) and then clicking the Build Jump List button.

image

Let’s start bottom to top.  The three items at the bottom of the menu are the so-called taskbar tasks.  These are items you would see for every application out there, and they give you the option of launching the app, pinning/unpinning it from the taskbar and closing its window (if it’s running).

Going up the list is the Tasks subsection, within which the so-called user tasks reside.  Despite the name, the application (and not the user) provides these tasks.  These are typically shortcuts (IShellLink objects) that provide some general functionality, usually related to the application.  For example, the Windows Media Player user tasks are “Resume last playlist” and “Play all music shuffled”.  These tasks do not depend on any document, and are verbs in our vocabulary.

Next in the list we see the Recent category, which is one of the predefined categories provided by the operating system.  In this category we find a collection of destinations, which are usually documents your application can handle and open.  Destinations are nouns, usually IShellItem objects, but IShellLink objects can be treated as destinations as well.  By the way, as I mentioned in a previous post, if your application doesn’t have a well-defined file type, it doesn’t mean you can’t have virtual items in the list (for example, IShellLink objects that pass a parameter to your application telling it what to do).

The Recent category is not the only system-provided category.  As we’ve seen above in the Windows Media Player example, another category provided by the system is the Frequent category.  It usually doesn’t make sense to include both, but you could if you really wanted to.  The last system-provided category is the Pinned category (not displayed in the above screenshot), which contains items that the user explicitly asked to see on the jump list by right-clicking and selecting “Pin to this list”.  There is no programmatic way to control this category – it’s purely up to the user’s discretion.

Next in the list we see two custom categories, which again contain an assortment of destinations.  Some of them have customized icons – these are the IShellLink destinations.

That’s awesome, you say?  How do we put our goodies in our application’s jump list, you ask?  Well, going down the native Win32 path might be a little unpleasant, so luckily we have the managed wrappers handy.

First things first.  In this post, we will look at how to take advantage of what the operating system can do for us – how to use the Recent and Frequent categories.  In subsequent posts, we will look into custom categories and user tasks.

So let’s get to it.  What does the Windows Shell consider a recent or frequent item?  Well, it’s just a file, that your application is associated with in the registry (not necessarily as the default handler), and that was either:

  • Used to launch your application directly (e.g. double-clicking a file in Windows Explorer)
  • Selected by the user in a common file dialog (open/save)
  • Specified as the parameter to the SHAddToRecentDocs API function

The first two scenarios require you to do … absolutely nothing! – and you get the Recent or Frequent category for free.  The third scenario requires mild interop, which happens to be part of the managed wrapper as well (specifically in JumpListManager.AddToRecent).

Let’s see how it works.  First of all, you need a registered file association with the extension in question.  There are lots of walkthroughs for doing this, including this detailed MSDN page.  For convenience, the Windows7.DesktopIntegration.Registration console application shows how to register a file type association.  It’s nowhere near recommended or thoroughly tested, but it works well enough in the Windows7.DesktopIntegration.MainDemo demo app.

Next, you need to ensure that you let the shell know when you open or save a document that belongs to your application.  The easy way of doing this is to go through the common file dialogs, which in Windows 7 include the concept of Libraries (not covered today…).  If you resort to using your own custom UI for opening/saving files, you should call SHAddToRecentDocs explicitly to let the shell know what you’re doing.

Let’s take a look at the code from the Windows7.DesktopIntegration.MainDemo application which shows how easy it is to add a recent item to the jump list explicitly:

_jumpListManager = this.CreateJumpListManager();

_jumpListManager.UserRemovedItems += (o, e) => {};

_jumpListManager.AddToRecent(Path.Combine(_thisAppDataPath, "mary.txt"));

Let’s do it step by step:

  1. You need an instance of JumpListManager.  It can be created after you have a taskbar button, so as before, wait for the “TaskbarButtonCreated” message and then create an instance.
  2. The default category is Recent, so if you want the Frequent category you need to set the JumpListManager.EnabledAutoDestinationType property to ApplicationDestinationType.Frequent.
  3. You need to register for the JumpListManager.UserRemovedItems event – this event is invoked if, when building the jump list, we detect the user removed an item from the jump list.  (We will discuss this in more detail in a subsequent post.)
  4. You need to call JumpListManager.AddToRecentDocs with the file name you want to add (it’s also possible to provide an IShellItem or IShellLink, but we won’t go there just yet).
  5. If at any time you want to clear the jump list*, you can call JumpListManager.ClearApplicationDestinations and the recent/frequent category will become empty.  (Custom categories are not cleared by this method; the pinned category can’t be cleared programmatically at all.)

* Note that you shouldn’t just go around clearing the jump list randomly or when the application starts.  The reasonable use cases for clearing the recent/frequent category might be if the user requests to do so through the application UI (e.g. “Clear History”), if the user uninstalls the application, etc.

So there we have it – our application is now jump list-enabled, at least in the sense that its recent/frequent documents now show up as part of the jump list!  Note that if you already have a file association in place, and are using the common file dialogs to open/save files, you don’t need to do anything to get this functionality working.

In the next post, we will look at custom destinations and user tasks, which are explicit new mechanisms that aren’t triggered on for you by the system.

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published. Required fields are marked *

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=""> <strike> <strong>

5 comments

  1. Win7TesterJune 17, 2009 ב 6:48 PM

    Anyone know how to add a C# .AddUserTask which opens say a new tab in an existing application form as seen in WinFox (https://brentf.com/blog/software/winfox-ndash-firefox-and-windows-7/) rather than opening another separate windows application?

    At the moment the code for accomplishing opening a separate application is:

    _jumpListManager.AddUserTask(new ShellLink
    {
    Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), “AppName.exe”),
    Title = “AppName”,
    Category = “Applications”,
    IconLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), “AppName.exe”),
    IconIndex = 0
    });

    Surely, if WinFox has implemented it it must exist as an API to use under Windows 7? Also I have seen this in IE8 under Windows 7 (http://geekswithblogs.net/sergun/archive/2009/06/01/windows-7-programming-taskbar.-part-10-final-part-ndash-jumplists.aspx)

    and in Outlook as part of Office 2010 (http://www.ithinkdiff.com/office-2010-will-also-use-jumplists-in-windows-7/)

    so it must be possible?

    Can anyone help?

    Reply
  2. DanielNovember 14, 2009 ב 4:17 AM

    I don’t want to see the recent and frequent option…how do I eliminate them. Thanks!!

    Reply
    1. AhikananaFebruary 10, 2014 ב 1:43 AM

      This might be several years late & no one cares anymore, but I found a solution that works for the Start Menu (Taskbar is unchanged):

      1) Open Registry editor (Start > “regedit”)
      2) Navigate to [HKEY_CLASSES_ROOT\lnkfile]
      3) Delete the string called “IsShortcut”
      4) Restart Windows Explorer (I do this by opening Task Manager CTRL + ALT + DEL > Processes > explorer.exe > End Process; then go to “Applications” tab > New Task > “explorer” > ENTER.

      Result: Arrows will still display to the right of the Start Menu item, but the submenu will no longer open even when clicking on the arrow.

      Performing this Registry edit has one unintended consequence, i.e., you will no longer be able to use right-click to “Pin to Taskbar”, “Pin to Start Menu” or “Unpin from Start Menu”. Other options (“Open”, “Run as administrator”, “Remove from this list” & “Properties”) are unaffected. This might be ideal in public (e.g., libraries & hotel guest amenities) or corporate environments or when no new programs will be installed on the system & no new items need to be pinned to the Start Menu.

      Doing this is up to you. You can always add the string back if you don’t like it or if you need to Pin/Unpin items in the Start Menu.

      Reply
  3. RaffaeleOctober 7, 2011 ב 4:37 PM

    Hi there

    In my case the jump list are working fine when opening local excel-files. When i try to open remote excel-files (company’s share). It lists only my last document, eventhough I opened 10 remote files…

    Locally opened files are working fine. The fileserver is running with Samba….

    In another company, running a Windows Server 2008r2, the jumplist works correctly.

    Reply
  4. AlanDOctober 6, 2012 ב 6:11 PM

    Hi
    Can you help me with my problem?
    My explorer’s jumplist just show ‘frequent’ but not ‘recent’.
    I want the ‘recent’.
    I should download some JumpListManager app or program from you first?

    Reply