locked
Adding Jump list to an Windows Forms application RRS feed

  • Question

  • So, I want to add a simple jump list to my Winforms program, where it has three tasks: open the launcher, launch a program and  access the manual. I tried to implement it using nugets and some code found on MSDN, but I couldn't implement it. Am I missing something? Or I have to re-write it with Windows Presentation Framework?
    • Moved by CoolDadTx Friday, February 5, 2016 3:12 PM Winforms related
    Friday, February 5, 2016 9:43 AM

Answers

  • I suggest you take a look at the sample here:

    https://code.msdn.microsoft.com/windowsapps/Jump-List-with-Windows-db005b99

    Looks like there's a helper class and working code.

    private void MainForm_Shown(object sender, EventArgs e) 
    { 
        
        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");  
         
        JumpListManager.Refresh(); 
    }

    If you like the sample, please don't forget to click that 5th star and give the author a bit of encouragement.

    ( 4 ratings out of 3,552 free downloads. I bet he's really enthusiastic about putting more samples together. )

    .

    This accessing the manual stuff?

    I hope that will work using a command line switch because I think that's all you're going to get from this.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Saturday, February 6, 2016 4:29 PM

All replies

  • Look into the WInAPI code pack.
    Friday, February 5, 2016 3:11 PM
  • Look into the WInAPI code pack.

    I did downloaded the pack and I have this sample code (to make sure that it works) I found on MSDN:

     private void AddTask(object sender, RoutedEventArgs e)
            {
                // Configure a new JumpTask.
                var jumpTask1 = new JumpTask
                {
                    ApplicationPath =
                        Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86), "calc.exe"),
                    IconResourcePath =
                        Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86), "calc.exe"),
                    Title = "Calculator",
                    Description = "Open Calculator.",
                    CustomCategory = "User Added Tasks"
                };
                // Get the path to Calculator and set the JumpTask properties.
                // Get the JumpList from the application and update it.
                var jumpList1 = JumpList.GetJumpList(System.Windows.Application.Current);
                jumpList1.JumpItems.Add(jumpTask1);
                JumpList.AddToRecentCategory(jumpTask1);
                jumpList1.Apply();
            }
            private void ClearJumpList(object sender, RoutedEventArgs e)
            {
                var jumpList1 = JumpList.GetJumpList(System.Windows.Application.Current);
                jumpList1.JumpItems.Clear();
                jumpList1.Apply();
            }
            private void SetNewJumpList(object sender, RoutedEventArgs e)
            {
                //Configure a new JumpTask
                var jumpTask1 = new JumpTask
                {
                    ApplicationPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "write.exe"),
                    IconResourcePath =
                        Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "write.exe"),
                    Title = "WordPad",
                    Description = "Open WordPad.",
                    CustomCategory = "Jump List 2"
                };
                // Get the path to WordPad and set the JumpTask properties.
                // Create and set the new JumpList.
                JumpList jumpList2 = new JumpList();
                jumpList2.JumpItems.Add(jumpTask1);
                JumpList.SetJumpList(System.Windows.Application.Current, jumpList2);
            }

    What do I do now?


    Saturday, February 6, 2016 2:15 PM
  • I suggest you take a look at the sample here:

    https://code.msdn.microsoft.com/windowsapps/Jump-List-with-Windows-db005b99

    Looks like there's a helper class and working code.

    private void MainForm_Shown(object sender, EventArgs e) 
    { 
        
        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");  
         
        JumpListManager.Refresh(); 
    }

    If you like the sample, please don't forget to click that 5th star and give the author a bit of encouragement.

    ( 4 ratings out of 3,552 free downloads. I bet he's really enthusiastic about putting more samples together. )

    .

    This accessing the manual stuff?

    I hope that will work using a command line switch because I think that's all you're going to get from this.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Saturday, February 6, 2016 4:29 PM
  • It's almost set up, but I get this error:

    Error CS0123: No overload for 'MainForm_JumpListCommandReceived' matches delegate 'EventHandler' (30, 39)

    JumpListCommandReceived += new EventHandler(MainForm_JumpListCommandReceived);
    

    Saturday, February 6, 2016 5:56 PM
  • you could try removing the += and after.

    Type += and let intellisense create a handler for you.

    That'll have the correct signature it's expecting.

    Then paste your code into that new handler.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Saturday, February 6, 2016 9:25 PM
  • The error means that your MainForm_JumpListCommandReceived method doesn't match the signature it was expecting. You are wrapping it in an EventHandler which means the signature would need to be

    void MainForm_JumpListCommandReceived ( object sender, EventArgs e)

    However the JumpListCommandReceived event requires a method with the following signature.

    void MainForm_JumpListCommandReceived ( object sender, CommandEventArgs e )

    Remove the new EventHandler call around the line and it should work, assuming you have defined the method signature correctly.

    JumpListCommandReceived += MainForm_JumpListCommandReceived

    Saturday, February 6, 2016 10:03 PM
  • Now for some reason, I get this error during debug (right on the start up):

    Additional information: Unable to load the file or the formation 'JumpListHelpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or a similar component. Requires formation with a strong name. (Exception from HRESULT: 0x80131044)

    I set it up as shown both on the linked site and on the sample code (I aquired the dll file via NuGet).


    Sunday, February 7, 2016 12:33 AM
  • Is this a normal Winforms app or one that is hosted inside a larger app? Alternatively is it partially trusted?  The error would indicate that it expected a strongly named assembly but that wouldn't be for a normal Winforms app.

    Ensure the Copy Local property for the 3 assemblies related to jump lists is True and that they are in the output window.  It might be useful to post the entire exception including any inner exceptions. It would also be useful to see the code where the exception is being thrown.

    Sunday, February 7, 2016 2:27 AM
  • That is a normal Winforms app (or a standalone if it makes more sense).

    I placed a few breakpoints to check if there was an error caused somewhere, but it always kept crashing at startup. Same error as I posted before. 

    System.IO.FileLoadException was unhandled
    Message: An unhandled exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll
    Additional information: Unable to load the file or the formation 'JumpListHelpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or a similar component. Requires formation with a strong name. (Exception from HRESULT: 0x80131044)

    EDIT: Could it be because I'm using VS2015? The sample program wasn't working right when I opened it with that.
    Sunday, February 7, 2016 10:27 PM
  • The exception itself doesn't line up with the exception you'd get for loading a normal assembly.  Specifically it doesn't say anything about a formation so that is really odd.  VS2015 shouldn't be a problem.  You didn't happen to install any of the components into the GAC or anything did you? It might be necessary to turn on the fusion logger to see what is going on.

    Before you get that far though I'd recommend creating a new Winforms app, add the NuGet package into the project, add a call to the library so it triggers a load and then see if it works. If it does then it is a problem with your project. Perhaps you turned on delay signing or something? Are you targeting Any CPU for the platform?  Does the exception have an inner exception with more information?  Did you confirm that the assembly is in the output directory along with the WinAPICodePack assemblies?

    Monday, February 8, 2016 12:57 AM
  • Hi AceOfAces_Mod,

    Maybe you could refer to the following code(sample):

    public partial class Form1 : Form
    
        {
    
            public Form1()
    
            {
    
                InitializeComponent();
    
            }
    
            public struct LinkStruct
    
            {
    
                public string Name;
    
                public string URL;
    
            }
    
            List<LinkStruct> linklist = new List<LinkStruct>();
    
            private int PageIndex = 0;
    
            //display link list
    
            private void DisPlayLink(List<LinkStruct> LinkList, int pageIndex)
    
            {
    
                foreach (Control con in gbJump.Controls)
    
                {
    
                    if (con is Label)
    
                    {
    
                        con.Visible = false;
    
                    }
    
                }
    
                for (int i = 0; i < 5; i++)
    
                {
    
                    if (pageIndex * 5 + i < LinkList.Count)
    
                    {
    
                        Label lb = gbJump.Controls.Find("lbLink" + (i + 1).ToString(), false)[0] as Label;
    
                        lb.Text = LinkList[pageIndex * 5 + i].Name;
    
                        lb.Visible = true;
    
                    }
    
                }
    
            }
    
            //visit link
    
            private void VisitLink(Label lb)
    
            {
    
                try
    
                {
    
                    string url = linklist.Where(o => o.Name == lb.Text).ToArray()[0].URL;
    
                    //use ie to open this url
    
                    System.Diagnostics.Process.Start("iexplore.exe", url);
    
                }
    
                catch (Exception exp)
    
                { }
    
            }
    
            //click lable event
    
            private void lbLink_Click(object sender, EventArgs e)
    
            {
    
                VisitLink(sender as Label);
    
            }
    
            //page up
    
            private void btnUp_Click(object sender, EventArgs e)
    
            {
    
                if (PageIndex > 0)
    
                {
    
                    PageIndex--;
    
                    DisPlayLink(linklist, PageIndex);
    
                }
    
            }
    
            //page down
    
            private void btnDown_Click(object sender, EventArgs e)
    
            {
    
                if (PageIndex < linklist.Count / 5)
    
                {
    
                    PageIndex++;
    
                    DisPlayLink(linklist, PageIndex);
    
                }
    
            }
    
            //add jump link
    
            private void btnAdd_Click(object sender, EventArgs e)
    
            {
    
                LinkStruct ls = new LinkStruct();
    
                ls.Name = txtName.Text.Trim();
    
                ls.URL = txtLink.Text.Trim();
    
                if (!linklist.Contains(ls))
    
                {
    
                    linklist.Add(ls);
    
                }
    
                else
    
                {
    
                    MessageBox.Show(txtName.Text + " is exist!");
    
                }
    
            }
    
        }
    

    Process Class

    Regards,

    Moonlight


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, February 19, 2016 9:44 AM