2016-02-03 4 views
0

У меня есть настольное приложение. Я добавил меню jumplist. Это меню появляется в Jumplist, когда я нажимаю правой кнопкой мыши значок на панели задач. Проблема в том, что когда я нажимаю на элемент меню, он не выполняет никаких действий (т. Е. Мое приложение его ловит). Я взял код со следующей ссылки и настроил его соответствующим образом (Примечание: этот код jumplist также не работает также на моем компьютере). Я использую Visual Studio 2013 и окна 10.Мое настольное приложение не может поймать событие щелчка jumplist

http://www.codeproject.com/Articles/103913/How-to-Create-a-Custom-Jumplist-with-Custom-Events

В Program.cs я добавил следующий код.

[STAThread] 
    private static void Main() 
    { 
     bool firstInstance = false; 
     Mutex mtx = new Mutex(true, "Jumplist.demo", out firstInstance); 

     if (firstInstance) 
     { 
      Application.EnableVisualStyles(); 
      Application.SetCompatibleTextRenderingDefault(false); 
      Application.Run(new frmSelect()); 
     } 
     else 
     { 
      // Send argument to running window 
      HandleCmdLineArgs(); 
     } 

    } 

    public static void HandleCmdLineArgs() 
    { 
     if (Environment.GetCommandLineArgs().Length > 1) 
     { 
      switch (Environment.GetCommandLineArgs()[1]) 
      { 
       case "-1": 
        MessageBox.Show(@"-1"); 
        break; 
       case "-2": 
        MessageBox.Show(@"-2"); 
        break; 
       case "-3": 
        MessageBox.Show(@"-3"); 
        break; 
      } 
     } 
    } 
} 

Myjumplist класс имеет следующий код

public class MYJumpList 
{ 
    private JumpList jumpList; 


    /// <summary> 
    /// Creating a JumpList for the application 
    /// </summary> 
    /// <param name="windowHandle"></param> 
    public goJumpList(IntPtr windowHandle) 
    { 
     TaskbarManager.Instance.ApplicationId = "MyJumplist"; 
     jumpList = JumpList.CreateJumpListForIndividualWindow(TaskbarManager.Instance.ApplicationId, windowHandle); 
     jumpList.KnownCategoryToDisplay = JumpListKnownCategoryType.Recent; 
     BuildList(); 
    } 

    public void AddToRecent(string destination) 
    { 
     jumpList.AddToRecent(destination); 
     jumpList.Refresh(); 
    } 

    /// <summary> 
    /// Builds the Jumplist 
    /// </summary> 
    private void BuildList() 
    { 
     JumpListLink jlItem1 = new JumpListLink(Assembly.GetEntryAssembly().Location, "Item1"); 
     jlItem1.Arguments = "-1"; 

     JumpListLink jlItem2 = new JumpListLink(Assembly.GetEntryAssembly().Location, "Item2"); 
     jlItem2.Arguments = "-2"; 

     JumpListLink jlItem3 = new JumpListLink(Assembly.GetEntryAssembly().Location, "Item3"); 
     jlItem3.Arguments = "-3"; 

     jumpList.AddUserTasks(jlItem1); 
     jumpList.AddUserTasks(jlItem2); 
     jumpList.AddUserTasks(jlItem3); 
     jumpList.AddUserTasks(new JumpListSeparator()); 
     jumpList.Refresh(); 
    } 
} 

Моя основная форма Конструктор имеет следующие Jumplist строки кода

jumpList = new MyJumpList(this.Handle); 

Я не знаю, где это неправильно. Пожалуйста, дайте мне любую помощь, чтобы применить Jumplist в моем applicaiton

ответ

0

с большим количеством исследований и борьбы я переставить код и, наконец, я могу сделать Jumplist работать в VS 2013 и окна 10. В Program.cs я использовал следующий код.

private static void Main(string[] args) 
    { 
     if (args.Any()) 
     { 
      try 
      { 
       var proc = Process.GetCurrentProcess(); 

       Process[] processes = Process.GetProcessesByName(proc.ProcessName); 

       if (processes.Length > 1) 
       { 
        //iterate through all running target applications  
        foreach (Process p in processes) 
        { 
         if (p.Id != proc.Id) 
         { 
          if (args[0] == "Item1") 
           SendMessage(p.MainWindowHandle, Item1Value, IntPtr.Zero, IntPtr.Zero); 
          if (args[0] == "Item2") 
           SendMessage(p.MainWindowHandle, Item2Value, IntPtr.Zero, IntPtr.Zero); 
          if (args[0] == "Item3") 
           SendMessage(p.MainWindowHandle, Item3Value, IntPtr.Zero, IntPtr.Zero); 

          Environment.Exit(0); 
         } 
        } 
       } 
      } 
      catch (Exception) 
      { 


      } 
     } 

     Application.EnableVisualStyles(); 
     Application.SetCompatibleTextRenderingDefault(false); 

     if (args.Any()) 
     { 
      if (args[0] == "Item1") Application.Run(new frmSelect(Item1Value)); 
      if (args[0] == "Item2") Application.Run(new frmSelect(Item2Value)); 
      if (args[0] == "Item3") Application.Run(new frmSelect(Item3Value)); 
     } 
     else 
     { 
      Application.Run(new frmSelect()); 
     } 


    } 

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] 
    private static extern IntPtr SendMessage(IntPtr hwnd, uint Msg, IntPtr wParam, IntPtr lParam); 
    private const int Item1Value = 0xA123; 
    private const int Item2Value = 0xA124; 
    private const int Item3Value = 0xA125; 
} 

Моя основная форма показан метод имеет следующий код

private void frmSelect_Shown(object sender, EventArgs e) 
    { 
     var appPath = Assembly.GetEntryAssembly().Location; 
     var jumpList = JumpList.CreateJumpList(); 
     var category = new JumpListCustomCategory("MyApp"); 

     category.AddJumpListItems(
      new JumpListLink(appPath, "Item1") {Arguments = "Item1"}, 
      new JumpListLink(appPath, "Item2") {Arguments = "Item2"}, 
      new JumpListLink(appPath, "Item3") {Arguments = "Item3"}); 

     jumpList.AddCustomCategories(category); 
     jumpList.Refresh(); 
    } 

метод WndProc в моей основной форме имеет следующий код

protected override void WndProc(ref Message message) 
    { 
     if (message.Msg == Item1Value) messagebox.show("Item1 Clicked"); // here we can call relevant method 
     if (message.Msg == Item2Value) messagebox.show("Item2 Clicked"); // here we can call relevant method 
     if (message.Msg == Irem3Value) messagebox.show("Item3 Clicked"); // here we can call relevant method 

     base.WndProc(ref message); 
    } 

Я надеюсь, что любое тело может применить этот простой метод использовать список переходов в приложениях.

+0

Используйте опцию редактирования исходного вопроса, чтобы добавить дополнительную информацию. Ответы - это полные ответы, а не дополнительные сведения. – Jacobr365

Смежные вопросы