Jump List Helpers: create and manage Jump List with Windows Forms

Jump List Helpers is a library that allows to add Jump List to Windows Forms Applications and to be notified when a command is selected (instead of starting a new application instance, that is the default behaviour).

The library is available on NuGet too.

For more information, you can refer to the article Jump List con Windows Forms (in Italian) that I have written for DotNetToscana.

Building the Sample

The code you can download from this page contains a Class Library, named JumpListHelpers, that provides all you need to add and manage Jump List to your applications. It also includes a Windows Forms Application, JumpListManagerExample, that shows some examples of its usage:




WPF 4 provides a native support for Jump List. Instead, if we use Windows Forms, we must adopt the Windows API Code Pack, a managed wrapper that allows to access to the Windows API functions. Available on NuGet too, it provides all you need to manage Jump Lists within our Windows Forms Applications.

Unfortunately, a limit of Jump Lists (no matter the technology we use) is that the commands shown are able to start programs, URLs and files only: it isn't possible to send command directly to the application instance that owns the Jump List.

So, I developed Jump List Helpers, a library built on top of Windows API Code Pack that is able to overcome this limitation. It allows to add commands to the Jump List that start external programs and commands that can be received by the application itself via a normal event.

Its usage is very simple. For example, the following code creates the Jump List shown in the previous screenshot:
Modifica script|Remove
private void MainForm_Shown(object sender, EventArgs e) 
    JumpListManager.AddCategorySelfLink("Commands""First command""Command1"); 
    JumpListManager.AddCategorySelfLink("Commands""Second command""Command2");  
    JumpListManager.AddCategorySelfLink("Commands""Third command""Command3");  
    JumpListManager.AddCategoryLink("Links""Around and About .NET World""http://blogs.ugidotnet.org/marcom""shell32.dll"220);  
    JumpListManager.AddTaskLink("Start Notepad""notepad.exe""notepad.exe"); 
    JumpListManager.AddTaskLink("Start Calculator""calc.exe""calc.exe");  
    JumpListManager.AddTaskLink("Start Paint""mspaint.exe""mspaint.exe");  
Note that Jump Lists require a visible form when they are created, otherwise we'll get an exception. So, we can define then inside the form Shown event handler. The first threed methods include the term Self in the name, so they define commands that belong to our application. The others are normal command that starts external program or open an Internet address.

The next step is to modify our program so that it receives the selected command (Command1, Command2 and Command3 in the example), instead of starting a new instance. So, when the program starts, we must check if a previous instance is already running and, in such a situation, send it the selected command.

Jump List Helpers provides a series of methods and events that makes these checks really simple.

First of all, we must open the Program.cs file and modify the Main method so it looks like the following:
Modifica script|Remove
static void Main() 
    ProgramManager.Run(typeof(MainForm), "JumpListManager Example"); 
The ProgramManager.Run method requires the type of the application main form and its title. Internally, it verifies whether we are starting the program for the first time: in this case, it behaves like the standard Main method. Otherwise, if retrieves the existing instance and pass to it the command line arguments: if the application has been started through the Jump List, they are the commands that we have set when we have created it (Command1, Command2 or Command3).

Now, we need to modify our application main form so that it is able to receive Jump List command. Let's change its declaration so that it inherits from JumpListMainFormBase (contained in Jump List Helpers) and then add an handler for the JumpListCommandReceived event:
Modifica script|Remove
public partial class MainForm : JumpListMainFormBase 
    public MainForm()     
        this.JumpListCommandReceived += new EventHandler(MainForm_JumpListCommandReceived);     
    void MainForm_JumpListCommandReceived(object sender, CommandEventArgs e)     
        MessageBox.Show("Comando ricevuto: " + e.CommandName, "JumpListManager Example", MessageBoxButtons.OK, MessageBoxIcon.Information);  
    // ... 
That's it: now, when we select one of the "self" command in the Jump List, the JumpListCommandReceived event handler will be called with the right parameter.

You can find a more complex example in the Windows Forms Application that is available in the ZIP file.


More Information