使用新建加載項嚮導創建Visual C++/ATL加載項項目。
生成的代碼:ATL,VS2008擴展:向WindowEvents添加事件處理程序
HRESULT hr = S_OK;
pApplication->QueryInterface(__uuidof(DTE2), (LPVOID*)&m_pDTE);
pAddInInst->QueryInterface(__uuidof(AddIn), (LPVOID*)&m_pAddInInstance);`
獲取活動對象,並且的WindowEvent:
m_pDTE->get_Events(&m_pEvents);
m_pEvents->get_WindowEvents(0, &m_pWinEvents);
如何添加事件處理程序?
if (NULL != m_pWinEvents) {
m_pWinEvents += ????
}
感謝任何提示或引用...
UPDATE,試圖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':不是'EnvDTE :: _ WindowEvents'的成員1> c:\ work \ visstudi o_addin \ cbaddin3 \ cbaddin3 \ debug \ dte80a.tlh(1006):請參閱'EnvDTE :: _ WindowEvents'聲明
1> c:\ work \ visstudio_addin \ cbaddin3 \ cbaddin3 \ connect.cpp(43):error C2061:syntax錯誤:標識符 '_dispWindowEvents_WindowActivatedEventHandler'
你有沒有在你的類中定義的windowActivated功能? – anand 2009-07-06 14:53:13
是的,我在課堂上有一個WindowActivated()函數。我相信錯誤信息是指 m_pWinEvents-> WindowActivated 和 _dispWindowEvents_WindowActivatedEventHandler。 – Number8 2009-07-06 15:03:27