Windows 7 Jump Lists are one of the most noticeable and useful features of the new operating system. After a few weeks of using Windows 7, Jump Lists quickly become an integral part of day-to-day application launch and usage, and the Start Menu and common file dialogs are rarely needed for commonly used files and tasks. For this reason, spending some time and effort in the design and implementation of an efficient Jump List is an import activity when developing applications that will be used on Windows 7.
The Jump List shown in Figure 1 is the basic out-of-the-box Jump List for an MFC 10 application running on Windows 7. It has a list of pretty meager options–the ability to open and close the application, a list of recently open documents and the option of pinning the application to the Taskbar. In contrast, Figure 2 shows the rich Jump List provided by iTunes 9, which provides a list of recently played songs, and the ability to initiate application tasks like going to the iTunes music store.
The default Jump List will contain Recent items as shown in Figure 1 if the Visual C++ application is associated with a file extension, and the files have been opened from Windows Explorer. When documents are opened from the shell, Windows calls
SHAddToRecentDocs in addition to opening the document. The call to
SHAddToRecentDocs results in a shortcut to the document being added to the Recent Items folder, and this will be used in Windows 7 for populating the default jump list for an application.
Jump list items are divided into two categories–destinations and tasks. Destinations are ‘things’ like folders or files, and are shown at the top of a Jump List. Tasks are actions that a user can perform in an application, and are based on the COM
IShellLink has been available since Windows 95, and is the COM interface that Windows shortcut execution is built upon. Windows 7 provides inbuilt Tasks related to the Taskbar (as shown in Figure 1) such as the ability to pin an application to the Taskbar, and also provides standardized destinations like recent documents. Tasks and Destinations also have a significant behavioral distinction in that the end-user has the ability to customize and remove Destinations, but there is no in-built support for Task customization exposed to the end-user.
The main prerequisite for Windows 7 Jump List support is the Application ID (AppID), which is used to link various elements such as Windows, Jump Lists and Processes to a Task Bar button. If an application does not explicitly set an
AppID, Windows 7 can calculate one, but it is recommended to explicitly set the AppID. Fortunately, the MFC 10 AppWizard will automatically generate the code to set the
AppID in the constructor of the
CWinApp -derived class:
// TODO: replace application ID string below with unique ID string; recommended
// format for string is CompanyName.ProductName.SubProduct.VersionInformation
The CJumpList class provided by MFC for managing jump lists (which will be covered in some detail below) also provides a
SetAppID method, but if this is not explicitly called prior to the CJumpList object being initialized, the
m_pszAppID will be used to initialize the jump list, and there is no need to explicitly call
CJumpList::SetAppID unless the application is managing a different jump list.
The App Wizard generated application, document and view classes do not include a
CJumpList member variable, and one needs to be added to take advantage of jump list functionality. In the sample application (a Word Pad style application), the member variable will be added to the
CWinApp-derived class, and a call to
CJumpList.InitializeList will be added to the
Calling CJumpList.InitializeList is not needed to call most methods of
CJumpList, but if any interaction with the existing jump list, such as determining the maximum number of jump list slots available, is required,
InitializeList must be called first.
The next call to
CJumpList in the sample application after
InitializeList is to add the ‘known’ Destination category of Frequent documents. While Windows 7 will automatically add Recent documents to a Jump List as discussed earlier in the article, Frequent documents needs to be manually added. With the manual manipulation of the jump list to add Frequent documents, the implicit addition of Recent documents will no longer occur, and this needs to be manually added too if its continued presence is desired. The actual call is quite simple, and is followed by a call to commit the jump list (which will store the saved jump list in the registry), resulting in the jump list shown in Figure 3. While the Frequent and Recent lists for the sample application are similar, it can be seen the
QuickEdit2 document is in the Frequent list but not in the Recent list.
Figure 3 – Customized Application Jump List
Adding a task using the
CJumpList is also a relatively easy task. Tasks are strongly tied to Windows’ shortcuts (which are built on the
IShellLink COM interface), and a task can be added either by directly providing a pointer to a
IShellLink item or by providing the parameters, such as the command line and arguments, that can be used to create a shell link. Task also have a title, which is the actual text displayed to the user on the jump list, and can optionally contain an icon.
For the sample word processing application, a task that launches the dictionary.com website seems appropriate, and this can be simply added with the code shown below, resulting in the final jump list displayed in Figure 4.
NULL, _T(“Dictionary.com”), NULL, 0);
Figure 4. Jump List with Task to launch Dictionary.com
Windows 7 Jump Lists provide a convenient way for users to interact with an application, and, by default, Windows 7 will provide a number of jump list items available for all applications. Visual C++ applications can use the MFC CJumpList class to customize an application’s jump list, and known categories, custom categories and tasks can be added to the jump list with the simple API provided. As jump lists are persisted in the registry, there is no need for an application to provide a helper DLL to implement jump list functionality, and jump lists will be avialble even when an application is not running.