ATL,VS2008扩展:向WindowEvents添加事件处理程序

时间:2009-07-06 12:10:38

标签: c++ atl vsx

使用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);`

获取Events对象和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 GT; Connect.cpp
1> c:\ work \ visstudio_addin \ cbaddin3 \ cbaddin3 \ connect.cpp(43):错误C2039:'WindowActivated':不是'EnvDTE :: _ WindowEvents'的成员
1 GT; 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'

1 个答案:

答案 0 :(得分:0)

You can try using

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

然后定义处理程序

   public : 
   void WindowCreated(EnvDTE.Window window)
    {
        // some code
    }