hot key assigned in third party menu is not worked as expected in tool window

Answered hot key assigned in third party menu is not worked as expected in tool window

  • 2012年3月8日 上午 09:18
     
     

    We have developed wpf form which use context menu and hot key assigned to it. Menu includes Copy/Paste such as Ctrl+Alt+C and Ctrl+Alt+V. They work fine when run as standalone application. But when I set them to the Content of other Tool Window in another visual studio 2010 add-ins, there is nothing happen. The questions are:

    1/ Why?

    2/ Is there any solutions that can convert that form in order to be compatible with visual studio addin?

所有回覆

  • 2012年3月8日 下午 04:32
    版主
     
     提議的解答

    WPF bindings won't generally work in VS because we run the message loop, not WPF.

    Edit:  You should be able to get this to work if you override your window pane's PreProcessMessage method and inside of your override call ComponentDispatcher.RaiseThreadMessage (dont' call the base impl of PreProcessMessage).

    Ryan


  • 2012年3月12日 上午 07:29
     
     

    Can you send me peaces of code for process the copy/paste command on the tool window. 

    Thanks in advance

  • 2012年3月12日 下午 09:06
    版主
     
     已答覆 包含代碼

    In your WindowPane derived class you would have this:

    protected virtual bool PreProcessMessage(ref Message m) 
    {
        System.Windows.Interop.MSG interopMsg = ConvertToInteropMsg(m);
        wasHandled = ComponentDispatcher.RaiseThreadMessage(ref interopMsg);
    
        return wasHandled;
    }
    
    private System.Windows.Interop.MSG ConvertToInteropMsg(Message m)
    {
        System.Windows.Interop.MSG msg = new System.Windows.Interop.MSG();
    
        msg.hwnd = m.HWnd;
        msg.lParam = m.LParam;
        msg.message = m.Msg;
        msg.wParam = m.WParam;
    
        return msg;
    }
    

  • 2012年3月13日 上午 04:22
     
     

    I have found out that the key Ctrl+Alt+V is one of compound key for the visual studio commands. And once we use the hot key duplicated with or existed in visual studio command, the status bar of visual studio show us that key are handled by visual studio.

    I used your code but the debugger don't step in the PreProcessMessage. Any idea?

    And all the popup can't handle the key Esc as default.

  • 2012年3月13日 上午 05:07
    版主
     
     

    Is focus inside your toolwindow? You would have to post repro code, I have used that override numerous times and it does indeed work.

    Ryan

  • 2012年3月14日 上午 02:51
     
     

    Hi Ryan

    I have just change virtual to override and your code work well, thanks so much for your helping and attention.

  • 2012年3月14日 上午 05:05
    版主
     
     

    Whoops, that is what I get for writing code in the browser :(. Sorry about that.

    Ryan