CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

如果监控网页点击事件?

楼主cnuninetwang()2005-06-03 10:43:53 在 C/C++ / C语言 提问

怎样用c   调用windows   api,     完成以下功能:  
  用户点击网页里的某个特殊标签,那么该程序能够自动运行,并把该标签的值以及属性显示出来。  
  谢谢 问题点数:100、回复次数:6Top

1 楼jiangsheng(蒋晟.Net[MVP])回复于 2005-06-03 13:17:41 得分 97

http://msdn.microsoft.com/workshop/browser/mshtml/tutorials/sink.aspTop

2 楼mccxj(老鼠不逛街)回复于 2005-06-03 13:30:59 得分 2

Accessing   an   Element   on   the   Page  
   
  Using   the   IHTMLDocument2   interface   pointer,   you   can   request   a   collection   of   all   elements   in   the   HTML   document   through   the   IHTMLDocument2::all   property.  
   
  Hide   Example  
   
  void   CMyClass::ProcessDocument(IHTMLDocument2*   pDoc)  
  {  
          IHTMLElementCollection*   pElemColl   =   NULL;  
   
          hr   =   pDoc->get_all(&pElemColl);  
          if   (SUCCEEDED(hr))  
          {  
                  //   Obtained   element   collection.  
                  ProcessElementCollection(pElemColl);  
                  pElemColl->Release();  
          }  
  }  
  Top

3 楼mccxj(老鼠不逛街)回复于 2005-06-03 13:31:57 得分 0

Receiving   Element   Events  
   
  Each   element   in   the   DHTML   Object   Model   supports   an   outgoing   HTMLElementEvents2   interface.   This   interface   defines   the   events   that   an   HTML   element   can   fire.   You   implement   this   interface   to   provide   an   event   sink,   which   is   a   Component   Object   Model   (COM)   object   that   implements   an   outgoing   interface   and   is   used   as   the   mechanism   for   firing   events.  
   
  Note     Interfaces   implemented   by   a   server   usually   have   their   methods   called   by   the   client,   but   to   fire   an   event,   the   server   calls   the   respective   method   on   the   client   event   sink.   These   interface   are   called   outgoing   interfaces.   A   COM   object   that   implements   an   outgoing   interface   is   also   known   as   a   connectable   object.  
  The   following   steps   are   required   to   receive   events   from   an   outgoing   interface:  
   
  Implement   the   event   sink.  
   
  The   event   sink   implements   the   appropriate   outgoing   interface   and   methods.   Internet   Explorer   event   interfaces   are   dispinterfaces,   so   calls   to   event   methods   are   made   through   IDispatch::Invoke.   This   means   that   you   only   need   to   implement   the   IDispatch   interface   to   handle   events.  
   
  Determine   if   the   server   is   a   connectable   object.  
   
  Call   QueryInterface   to   retrieve   a   pointer   to   the   IConnectionPointContainer   interface.  
   
  Find   the   appropriate   connection   point.    
   
  Call   the   IConnectionPointContainer::FindConnectionPoint   method   to   find   the   connection   point   you   need.   For   Internet   Explorer   WebBrowser   Control   events,   such   as   DWebBrowserEvents2::DocumentComplete,   this   is   DWebBrowserEvents2.   For   element   events,   this   is   HTMLElementEvents2.   You   can   also   call   the   IConnectionPointContainer::EnumConnectionPoints   to   enumerate   through   all   the   connection   points   a   server   supports.  
   
  Advise   the   connection   point   that   you   want   to   receive   events.  
   
  Using   the   IConnectionPoint   interface   pointer   returned   in   the   previous   step,   call   IConnectionPoint::Advise,   passing   the   IUnknown   interface   pointer   of   your   event   sink.  
   
     
  Note     The   connectable   object   will   use   the   IUnknown   interface   pointer   to   query   the   client   for   the   event   sink   interface.   If   the   event   sink   does   not   support   the   outgoing   interface,   Internet   Explorer   will   query   the   client   for   the   IDispatch   interface.  
  When   you   no   longer   want   to   receive   events,   you   can   call   the   IConnectionPoint::Unadvise   method,   passing   the   cookie   you   received   from   the   call   to   IConnectionPoint::Advise.  
  The   following   sample   code   demonstrates   how   to   begin   receiving   HTML   element   events   for   an   element   on   an   HTML   page.  
   
  Hide   Example  
   
  void   CMyClass::ConnectEvents(IHTMLElement*   pElem)  
  {  
          HRESULT   hr;  
          IConnectionPointContainer*   pCPC   =   NULL;  
          IConnectionPoint*   pCP   =   NULL;  
          DWORD   dwCookie;  
   
          //   Check   that   this   is   a   connectable   object.  
          hr   =   pElem->QueryInterface(IID_IConnectionPointContainer,   (void**)&pCPC);  
   
          if   (SUCCEEDED(hr))  
          {  
                  //   Find   the   connection   point.  
                  hr   =   pCPC->FindConnectionPoint(DIID_HTMLElementEvents2,   &pCP);  
   
                  if   (SUCCEEDED(hr))  
                  {  
                          //   Advise   the   connection   point.  
                          //   pUnk   is   the   IUnknown   interface   pointer   for   your   event   sink  
                          hr   =   pCP->Advise(pUnk,   &dwCookie);  
   
                          if   (SUCCEEDED(hr))  
                          {  
                                  //   Successfully   advised  
                          }  
   
                          pCP->Release();  
                  }  
   
                  pCPC->Release();  
          }  
  }    
  The   following   sample   code   demonstrates   how   you   would   detect   the   firing   of   an   HTMLElementEvents2::onclick   event   in   your   implementation   of   IDispatch::Invoke.  
   
  Hide   Example  
   
  STDMETHODIMP   CEventSink::Invoke(DISPID   dispidMember,  
                                                                  REFIID   riid,  
                                                                  LCID   lcid,  
                                                                  WORD   wFlags,  
                                                                  DISPPARAMS*   pdispparams,  
                                                                  VARIANT*   pvarResult,  
                                                                  EXCEPINFO*   pexcepinfo,  
                                                                  UINT*   puArgErr)  
  {  
          switch   (dispidMember)  
          {  
                  case   DISPID_HTMLELEMENTEVENTS2_ONCLICK:  
                  OnClick();  
                  break;  
   
                  default:  
                  break;  
          }  
   
          return   S_OK;  
  }  
  。。msdn上的实例。。Top

4 楼hzh_net(_风云_)回复于 2005-06-03 13:37:11 得分 1

http://msdn.microsoft.com/workshop/browser/mshtml/tutorials/sink.asp  
   
  这上面有,楼主自己去看  
  ---------------------------------  
   
  呵呵  
   
  ^_^  
   
  Top

5 楼hzh_net(_风云_)回复于 2005-06-03 13:37:51 得分 0

Receiving   Element   Events  
   
  Each   element   in   the   DHTML   Object   Model   supports   an   outgoing   HTMLElementEvents2   interface.   This   interface   defines   the   events   that   an   HTML   element   can   fire.   You   implement   this   interface   to   provide   an   event   sink,   which   is   a   Component   Object   Model   (COM)   object   that   implements   an   outgoing   interface   and   is   used   as   the   mechanism   for   firing   events.  
   
  Note     Interfaces   implemented   by   a   server   usually   have   their   methods   called   by   the   client,   but   to   fire   an   event,   the   server   calls   the   respective   method   on   the   client   event   sink.   These   interface   are   called   outgoing   interfaces.   A   COM   object   that   implements   an   outgoing   interface   is   also   known   as   a   connectable   object.  
  The   following   steps   are   required   to   receive   events   from   an   outgoing   interface:  
   
  Implement   the   event   sink.  
   
  The   event   sink   implements   the   appropriate   outgoing   interface   and   methods.   Internet   Explorer   event   interfaces   are   dispinterfaces,   so   calls   to   event   methods   are   made   through   IDispatch::Invoke.   This   means   that   you   only   need   to   implement   the   IDispatch   interface   to   handle   events.  
   
  Determine   if   the   server   is   a   connectable   object.  
   
  Call   QueryInterface   to   retrieve   a   pointer   to   the   IConnectionPointContainer   interface.  
   
  Find   the   appropriate   connection   point.    
   
  Call   the   IConnectionPointContainer::FindConnectionPoint   method   to   find   the   connection   point   you   need.   For   Internet   Explorer   WebBrowser   Control   events,   such   as   DWebBrowserEvents2::DocumentComplete,   this   is   DWebBrowserEvents2.   For   element   events,   this   is   HTMLElementEvents2.   You   can   also   call   the   IConnectionPointContainer::EnumConnectionPoints   to   enumerate   through   all   the   connection   points   a   server   supports.  
   
  Advise   the   connection   point   that   you   want   to   receive   events.  
   
  Using   the   IConnectionPoint   interface   pointer   returned   in   the   previous   step,   call   IConnectionPoint::Advise,   passing   the   IUnknown   interface   pointer   of   your   event   sink.  
   
     
  Note     The   connectable   object   will   use   the   IUnknown   interface   pointer   to   query   the   client   for   the   event   sink   interface.   If   the   event   sink   does   not   support   the   outgoing   interface,   Internet   Explorer   will   query   the   client   for   the   IDispatch   interface.  
  When   you   no   longer   want   to   receive   events,   you   can   call   the   IConnectionPoint::Unadvise   method,   passing   the   cookie   you   received   from   the   call   to   IConnectionPoint::Advise.  
  The   following   sample   code   demonstrates   how   to   begin   receiving   HTML   element   events   for   an   element   on   an   HTML   page.  
   
  Hide   Example  
   
  void   CMyClass::ConnectEvents(IHTMLElement*   pElem)  
  {  
          HRESULT   hr;  
          IConnectionPointContainer*   pCPC   =   NULL;  
          IConnectionPoint*   pCP   =   NULL;  
          DWORD   dwCookie;  
   
          //   Check   that   this   is   a   connectable   object.  
          hr   =   pElem->QueryInterface(IID_IConnectionPointContainer,   (void**)&pCPC);  
   
          if   (SUCCEEDED(hr))  
          {  
                  //   Find   the   connection   point.  
                  hr   =   pCPC->FindConnectionPoint(DIID_HTMLElementEvents2,   &pCP);  
   
                  if   (SUCCEEDED(hr))  
                  {  
                          //   Advise   the   connection   point.  
                          //   pUnk   is   the   IUnknown   interface   pointer   for   your   event   sink  
                          hr   =   pCP->Advise(pUnk,   &dwCookie);  
   
                          if   (SUCCEEDED(hr))  
                          {  
                                  //   Successfully   advised  
                          }  
   
                          pCP->Release();  
                  }  
   
                  pCPC->Release();  
          }  
  }    
  The   following   sample   code   demonstrates   how   you   would   detect   the   firing   of   an   HTMLElementEvents2::onclick   event   in   your   implementation   of   IDispatch::Invoke.  
   
  Hide   Example  
   
  STDMETHODIMP   CEventSink::Invoke(DISPID   dispidMember,  
                                                                  REFIID   riid,  
                                                                  LCID   lcid,  
                                                                  WORD   wFlags,  
                                                                  DISPPARAMS*   pdispparams,  
                                                                  VARIANT*   pvarResult,  
                                                                  EXCEPINFO*   pexcepinfo,  
                                                                  UINT*   puArgErr)  
  {  
          switch   (dispidMember)  
          {  
                  case   DISPID_HTMLELEMENTEVENTS2_ONCLICK:  
                  OnClick();  
                  break;  
   
                  default:  
                  break;  
          }  
   
          return   S_OK;  
  }  
  Top

6 楼mostideal(三甲)回复于 2005-06-03 14:19:13 得分 0

学习。。。Top

相关问题

  • 网页如何实现双击事件?
  • 请教怎样屏蔽网页中的双击事件,只保留单击事件?
  • [求助]上传后网页的部分按钮不响应点击事件
  • 关于网页的鼠标事件
  • 动态网页 onmouseout事件问题?
  • 请教 在一个按钮的click事件中怎么实现让点击后连接到一个网页,并且打开该网页
  • 在网页上嵌入的applet,鼠标点击事件过于频繁时,桌面上生成如下的文件,然后网页就自动关闭,何解?
  • 使用webbrowser,如何捕获网页上超链接的点击事件,执行自己的代码?
  • 高难问题:如何才能捕获到点击网页上的连接后WebBrowser事件?
  • 着急,如何监视Webbrowser控件里网页操作事件如鼠标点击。

关键词

  • msdn
  • html
  • pelemcoll
  • outgoing
  • sink
  • interface
  • fire
  • ihtmldocument
  • implement
  • element

得分解答快速导航

  • 帖主:cnuninetwang
  • jiangsheng
  • mccxj
  • hzh_net

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo