Programming Windows 7: Taskbar. Part 10 (final) - JumpLists

    One of the most important taskbar features in Windows 7 is Jump Lists. Jump lists are displayed if you select the application icon in the taskbar and press the right mouse button. If the application uses the functionality of JumpLists, then in addition to standard actions (pin, close), a number of additional actions will appear that facilitate our daily work.

    This functionality of the taskbar is actively used by various applications. For example, Windows Media Player displays playlist switching options. Internet Explorer and Windows Explorer contain jump lists with links to the last places you went to. Windows Live Messanger displays status switching options.



    The jump list may contain several different types of elements: tasks, links to recently opened documents, and links to permanent documents. In addition, these positions can be consolidated. Such items will not disappear from the jump list over time. This is convenient, for example, if we often work with the same document. Schematically jump list can be represented as follows.



    In fact, each item in the jump list is a link to a program or file. So, for example, we can run a calculator, or some document of a given format. Unfortunately, we do not have the ability to directly intercept the event of clicking on an item in the jump list. Each time we select the next item, a new instance of the application will be launched. This is primarily due to the fact that jump list can be called even when the application is not running. In this case, it should be pinned on the taskbar. For example, the following figure shows that Internet Explorer is not currently running, but we can open the jump list.



    So, let's see how similar functionality can be implemented in our applications. To work with jump list, we need an object of type JumpListManager, which is part of the .NET Interop Sample Library. It is necessary to create it at the time of creating the button for our application on the taskbar. For these purposes, you can override the WndProc method as follows.

    protected override void WndProc(ref Message m)
    {
    if (m.Msg == Windows7Taskbar.TaskbarButtonCreatedMessage)
    {
    _jumpListManager = WindowsFormsExtensions.CreateJumpListManager(this);
    _jumpListManager.UserRemovedItems += (o, e) =>
    {
    e.CancelCurrentOperation = false;
    };
    // add items
    _jumpListManager.Refresh();
    }
    base.WndProc(ref m);
    }


    Notice the Refresh method call after creating the JumpListManager object. A call to this method is necessary to update the positions in the jump list. Also required is subscribing to the UserRemovedItems event. It is executed when an attempt is made to remove obsolete items from the jump list. Let's now try to add new positions to the jump list. For these purposes, there are wrapper classes and the necessary methods for the JumpListManager object.

    The simplest type of items in a jump list is tasks. The task may be to launch an external application or our application with some parameters. In WLM, task state switching is implemented as tasks. The jump list uses the AddUserTask method to create the task.

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


    As you can see, a new ShellLink type object is created here, into which the path to the application, the title and the icon are passed. I added two tasks to my application and got the following result.



    Another option to populate the jump list is links to documents that were previously downloaded. For these purposes, I created several text files with the extension “.myapp” and associated this type of files with my application. When the application starts, I check if the file name is passed as a parameter when the application starts. If a name is given, then I read this file and add it to the list of previously downloaded files. For these purposes, the AddToRecent method exists. Now from Windows Explorer I will open these files. This will launch my demo application (if we correctly associated this type of files with the application). At the same time, when I call jump list, I will see that in the “Recent” category there are links to previously opened files.

    if (File.Exists(Environment.GetCommandLineArgs().Skip(1).FirstOrDefault() ?? String.Empty) == true)
    {
    _jumpListManager.AddToRecent(Environment.GetCommandLineArgs().Skip(1).FirstOrDefault() ?? String.Empty);
    }






    I can consolidate the positions with which I work most often. In this case, I can quickly open the documents I need through the jump list.



    Another way to place items on a jump list is to create links to permanent documents / programs. In this case, we can also group these positions into categories. For these purposes, the AddCustomDestination method exists. I added some of these links to the jump list and got the following result.

    _jumpListManager.AddCustomDestination(new ShellLink
    {
    Path = @"about.txt",
    Title = "About",
    Category = "My application",
    IconLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "shell32.dll"),
    IconIndex = 11
    });






    This figure shows that two additional groups appeared with links inside.

    A great feature of the jump list is that its contents are also available on the Start menu. So, for example, if we actively use this functionality, then this can also be used from the start menu.



    Thus, we can use the additional functionality that the Windows 7 taskbar provides us to ensure the most comfortable user experience. Sample

    Application:
    Taskbar-JumpLists.zip

    This concludes a series of articles on taskbar programming for Windows 7. I hope this information is useful to you and your applications. I want to especially note that the implementation of the capabilities of the Windows 7 taskbar for your applications will not require much effort, but the result will not be long in coming - it will be much more pleasant and convenient to communicate with your application.

    I wish you success in building your applications for Windows7!

    Also popular now: