0

使用 New Add-in Wizard 创建 Visual C++/ATL 加载项项目。
生成的代码:

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

获取事件对象和 WindowEvents:

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

如何添加事件处理程序?

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

感谢您的任何提示或参考...

更新,尝试 Alien01 的建议:

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

1>正在编译...
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) :参见 'EnvDTE::_WindowEvents'
1>c:\work\visstudio_addin\cbaddin3\cbaddin3\connect.cpp(43) 的声明:错误 C2061:语法错误:标识符“_dispWindowEvents_WindowActivatedEventHandler”

4

1 回答 1

0
You can try using

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

然后定义处理程序

   public : 
   void WindowCreated(EnvDTE.Window window)
    {
        // some code
    }
于 2009-07-06T13:21:41.490 回答