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

发布于 2024-07-26 16:41:34 字数 1125 浏览 2 评论 0原文

使用新建插件向导创建 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>Connect.cpp
1>c:\work\visstudio_addin\cbaddin3\cbaddin3\connect.cpp(43) : 错误 C2039: 'WindowActivated' : 不是 '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”

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'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

日裸衫吸 2024-08-02 16:41:34
You can try using

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

然后定义处理程序

   public : 
   void WindowCreated(EnvDTE.Window window)
    {
        // some code
    }
You can try using

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

and then define handler

   public : 
   void WindowCreated(EnvDTE.Window window)
    {
        // some code
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文