📜 ⬆️ ⬇️

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

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

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


')
In the jump list there may be several different types of items: tasks, links to recent open documents and links to permanent documents. In addition, these positions can be fixed. 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 presented 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 any document of a given format. Unfortunately, we are not able to directly intercept the event of clicking on an item in the jump list. Every time we select a new item, a new instance of the application will be launched. This is primarily due to the fact that the 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 this functionality can be implemented in our applications. To work with the 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 moment of creating the button of 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);
}


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

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

_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 object of the ShellLink type is created here, in which the path to the application, the header and the icon are passed. I added two tasks to my application and got the following result.



Another option to fill in the jump list is to link to documents that were uploaded earlier. For these purposes, I created several text files with the extension “.myapp” and associated this type of files with my application. When starting the application, I check whether the file name is passed as a parameter when the application is started. If the name is set, then I read this file and add it to the list of previously downloaded files. For these purposes there is an AddToRecent method.

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


Now from Windows Explorer I will open these files. This will launch my demo application (if we correctly associated this type of file with the application). At the same time, when calling the jump list, I will see that links to previously opened files have appeared in the “Recent” category.



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 of placing positions in the jump list is to create links to permanent documents / programs. In this case, we can also group these positions into categories. For these purposes there is an AddCustomDestination method.

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


I added several such links to the jump list and got the following result.



This figure shows that there are two additional groups with links inside.

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



Thus, we can use additional functionality provided by the Windows 7 taskbar to ensure the most comfortable user experience.

Demo application:
Taskbar-JumpLists.zip

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

Good luck to you in building your applications for Windows7!

Source: https://habr.com/ru/post/60792/


All Articles