tags:

views:

230

answers:

1

Used the New Add-in Wizard to create a Visual C++ / ATL add-in project.
Generated code:

HRESULT hr = S_OK;  
pApplication->QueryInterface(__uuidof(DTE2), (LPVOID*)&m_pDTE);    
pAddInInst->QueryInterface(__uuidof(AddIn), (LPVOID*)&m_pAddInInstance);`

Get the Events object, and the WindowEvents:

m_pDTE->get_Events(&m_pEvents);  
m_pEvents->get_WindowEvents(0, &m_pWinEvents);

How to add an event handler?

if (NULL != m_pWinEvents) {  
    m_pWinEvents += ????  
}

Thanks for any hints or references...

UPDATE, trying Alien01's suggestion:

m_pWinEvents->WindowActivated += new _dispWindowEvents_WindowActivatedEventHandler(this.WindowActivated);

1>Compiling...
1>Connect.cpp
1>c:\work\visstudio_addin\cbaddin3\cbaddin3\connect.cpp(43) : error C2039: 'WindowActivated' : is not a member of 'EnvDTE::_WindowEvents'
1> c:\work\visstudio_addin\cbaddin3\cbaddin3\debug\dte80a.tlh(1006) : see declaration of 'EnvDTE::_WindowEvents'
1>c:\work\visstudio_addin\cbaddin3\cbaddin3\connect.cpp(43) : error C2061: syntax error : identifier '_dispWindowEvents_WindowActivatedEventHandler'

A: 
You can try using

m_pWinEvents. WindowCreated += 
  new _dispWindowEvents_WindowCreatedEventHandler(this.WindowCreated);

and then define handler

   public : 
   void WindowCreated(EnvDTE.Window window)
    {
        // some code
    }
Alien01
Thanks for the reply, added your suggestion to OP.
Number8
MSDN link for more info http://msdn.microsoft.com/en-us/library/ms165650(VS.80).aspxCode Project linkhttp://www.codeproject.com/KB/macros/vsnowediting.aspx
Alien01
The MSDN library link describes C#. I have that version building successfully (there is a problem loading it.)The CodeProject link also uses C# (despite what its tags say).Thanks for the links, though.
Number8