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

  • Question

  • 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?

    Thursday, March 8, 2012 9:18 AM

Answers

  • 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;
    }
    

    Monday, March 12, 2012 9:06 PM

All replies

  • 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


    Thursday, March 8, 2012 4:32 PM
  • Can you send me peaces of code for process the copy/paste command on the tool window. 

    Thanks in advance

    Monday, March 12, 2012 7:29 AM
  • 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;
    }
    

    Monday, March 12, 2012 9:06 PM
  • 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.

    Tuesday, March 13, 2012 4:22 AM
  • 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

    Tuesday, March 13, 2012 5:07 AM
  • Hi Ryan

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

    Wednesday, March 14, 2012 2:51 AM
  • Whoops, that is what I get for writing code in the browser :(. Sorry about that.

    Ryan

    Wednesday, March 14, 2012 5:05 AM