资讯   |   开发   |   选机中心   |   产品大全 | IBM | 惠普 | 联想 | 戴尔 | 苹果 | 神舟
更多: | 华硕 | 明基 | 方正 | 紫光 | TCL | 夏新 | 联宝 | 宏碁 | 七喜 | 长城 | 清华同方 | 海尔 | 三星 | 东芝 | 索尼 | 富士通 | LG | 技术 | ddnoon
当前位置:笔记本 > 软件开发 >
Advertisement
文章正文

高手请进,关于连接点和dispid的问题

类型:转载   责任编辑:asp.net   日期:2007/05/23


热门软件下载:


   

问题的起因:  
  应用程序内,加入了WebBrowser。并已经成功的在DocumentComplete事件中获得了IHTMLDocument2接口。  
   
  问题的描述:  
  现在需要对WebBrowser中的动作进行监控,那么需要建立     应用程序和IHTMLDocument2之间的连接,但是却找不到   IHTMLDocument2   的dispid。  
   
  做过尝试:下载了   “在你的应用程序中集成WebBrowser控件”的源代码,发现,其中少了好几个关键文件,而且该代码也是从底层堆积木似的作上来的,太复杂。  
   
  附上部分代码:  
   
  //头文件  
   
  class   COFDialog   :  
      public   IDispEventImpl<IDC_EXPLORER1,COFDialog>  
  {  
  public:  
          BEGIN_SINK_MAP(COFDialog)  
  SINK_ENTRY(IDC_EXPLORER1,   259,   DocumentCompleteExplorer1)  
          END_SINK_MAP()  
   
        void   __stdcall   DocumentCompleteExplorer1(LPDISPATCH   pDisp,   VARIANT*   URL);  
        CComPtr<IWebBrowser2>   m_spBrowser;  
        VARIANT_BOOL   m_init;  
        IHTMLDocument2*   m_pHTMLDocument2;  
  }  
   
  //CPP文件  
   
  void   __stdcall   COFDialog::DocumentCompleteExplorer1(LPDISPATCH   pDisp,   VARIANT*   URL)  
  {  
  if(m_init)  
  m_pHTMLDocument2->Release();  
  CComPtr<IDispatch>   spDispatch;  
  m_spBrowser->get_Document(&spDispatch);  
  spDispatch->QueryInterface(IID_IHTMLDocument2,(void**)&m_pHTMLDocument2);  
  m_init   =   VARIANT_TRUE;  
   
  //下面这些代码是后来我参照“在你的应用程序中集成WebBrowser控件”加入的,接下来不知道怎么做了。  
  CComPtr<IConnectionPointContainer>   spConnectionPointContainer;  
  HRESULT   hr   =   m_pHTMLDocument2->QueryInterface(IID_IConnectionPointContainer,(void**)&spConnectionPointContainer);  
  CComPtr<IConnectionPoint>   spConnectionPoint;  
  hr   =   spConnectionPointContainer->FindConnectionPoint(DIID_HTMLDocumentEvents,&spConnectionPoint);  
  }  
   
   
  望各位同仁熟悉这一块的给个解决办法,在下实在不胜感激。  
   
   
 

网友回答:

发表者:nwpulipeng

混分

发表者:tlg007

用VC的OLE/COM   Object   Viewer   打开WebBrowser对应的dll/ocx文件  
   
  菜单:  
  File/View   TypeLib...  
   
  然后查看其连接点出接口信息,  
  ,自己实现一个继承于IDispatch的  
  接口,重载虚函数Invoke,根据传入  
  的Dispid调用相应的你的函数。  
   
  最后生成该接口的实例,连接到WebBrowser的连接点上  
   
   
  范例代码如下:  
   
  HRESULT   hr   =   m_smsWrap->QueryInterface(IID_IConnectionPointContainer,(void**)&m_pConnectionPointContainer);  
  if(!m_pConnectionPointContainer)    
  {  
  m_smsWrap->Release();  
  return   false;  
  }  
  hr   =   m_pConnectionPointContainer->FindConnectionPoint(DIID___SmsGwWrap,&m_pConnectionPoint);  
  if(!m_pConnectionPoint)    
  {  
  m_pConnectionPointContainer->Release();  
  m_smsWrap->Release();  
  return   false;  
  }  
  hr   =   m_pConnectionPoint->Advise((IUnknown*)((CMyUnknown*)this),&m_dwCookie);  
  if(hr   !=   S_OK)  
  {  
  m_pConnectionPointContainer->Release();  
  m_pConnectionPoint->Release();  
  m_smsWrap->Release();  
  return   false;  
  }  
   
   
  class   xxx   :public   IDispatch  
  {  
        protected:  
                  DWORD   m_dwCookie;  
                  IConnectionPointContainer   *m_pConnectionPointContainer;  
                  IConnectionPoint   *m_pConnectionPoint;  
        .......  
  }


 

 
热门推荐笔记本: 清华同方笔记本
相关文章:
笔记本相关:
IT技术文章:
webmaster:popbb@126.com   最佳浏览:1024X768 MSIE
©2007 popbb.net All Rights Reserved