locked
How to get mouse events from VS Text Editor in addin ( VS2008 ) RRS feed

  • Question

  • productivity power tools

    I am developing an add-in for VS2008 in C#
    I am try to make some features

    1. "Triple Click to get line"  - mouse single click three times in short time.

    2. "Ctrl + Click" go to definition

    - when i hold down the Ctrl key, I'd like to hight light the symbol where the mouse stop if the symbol has definition.

     

    so, can i catch the mouse click event from text editor ? ( mouse click and mouse move in the )


    Thanks in advance

    Thursday, November 17, 2011 9:13 AM

Answers

  • In 2008 most of the shell is written in native code and uses Win32 for processing.  There are no 'events' for the mouse in Win32, just messages like WM_LBUTTONDOWN.  I am not aware of any good (supported) ways to capture these messages as they are sent from the shell directly to the HWND the mouse is interacting with.  If you were/are dealing with your own toolwindow you can override PreProcessMessage and, I believe, though I would have to check and I don't have the code handy right now, we will send all messages through that method so you could see messages that way.  If however you are trying to say add functionality to the editor this won't work. You could try subclassing the editor's HWND, but that is very much unsupported :)

    Ryan

    • Marked as answer by Leo9987 Sunday, November 20, 2011 3:36 AM
    Thursday, November 17, 2011 3:45 PM
  • Addins cannot make MEF contributions. If you would like to go the MEF route, I would suggest using the VS2010 SDK to create an editor extension. See the links below for guidance:

    Extending the Editor 

    Editor Extension Points

    • Marked as answer by Leo9987 Sunday, November 20, 2011 3:35 AM
    Friday, November 18, 2011 8:57 PM

All replies

  • In 2008 most of the shell is written in native code and uses Win32 for processing.  There are no 'events' for the mouse in Win32, just messages like WM_LBUTTONDOWN.  I am not aware of any good (supported) ways to capture these messages as they are sent from the shell directly to the HWND the mouse is interacting with.  If you were/are dealing with your own toolwindow you can override PreProcessMessage and, I believe, though I would have to check and I don't have the code handy right now, we will send all messages through that method so you could see messages that way.  If however you are trying to say add functionality to the editor this won't work. You could try subclassing the editor's HWND, but that is very much unsupported :)

    Ryan

    • Marked as answer by Leo9987 Sunday, November 20, 2011 3:36 AM
    Thursday, November 17, 2011 3:45 PM
  • The only other possibility I can think of would be to set a hook callback with SetWindowsHookEx for WH_MOUSE. But as Ryan mentioned, this is NOT a supported scenario either. With VS 2010, the new editor does have some support for this, but VS 2008 does not.

    Sincerely,


    Ed Dore
    Thursday, November 17, 2011 6:40 PM
  • Thanks for reply, i will try to use VS2010 if 2010 is better than 2008.( it must be? )


    but i have no idea to catch mouse event in VS2010.

    i could not find some support for this in MSDN.

    how to get it in VS2010?


    Thanks.
    • Edited by Leo9987 Friday, November 18, 2011 1:01 PM
    Friday, November 18, 2011 12:59 PM
  • I think you would want IMouseProcessorProvider, though I am not aware of if AddIns can make MEF contributions.  Packages certainly can, but I don't know if the AddIn directory is processed for MEF contributions.

    Ryan

    Friday, November 18, 2011 8:47 PM
  • Addins cannot make MEF contributions. If you would like to go the MEF route, I would suggest using the VS2010 SDK to create an editor extension. See the links below for guidance:

    Extending the Editor 

    Editor Extension Points

    • Marked as answer by Leo9987 Sunday, November 20, 2011 3:35 AM
    Friday, November 18, 2011 8:57 PM
  • Thanks Ryan, Lance

     

    goole has more imformation with Extending the Editor, 

    i'll try to do that.

     

    Thanks!

    Sunday, November 20, 2011 3:35 AM