枚举IHTMLDocument2中所有IFRAME的内容

  1. #include <mshtml.h>
  2. #include <afxhtml.h>
  3. #include <atlbase.h>
  4. #include <oleacc.h>
  5. #include <MsHtmcid.h>
  6. void EnumFrame( IHTMLDocument2 *pHTML )
  7. {
  8.     CComQIPtr<IOleContainer> spContainer( pHTML );
  9.     if( spContainer )
  10.     {
  11.         CComPtr<IEnumUnknown> spEnumerator; // 注:参数OLECONTF_EMBEDDINGS // 表示列举容器内的所有嵌入对象
  12.         HRESULT hr = spContainer->EnumObjects(OLECONTF_EMBEDDINGS, &spEnumerator);
  13.         if( spEnumerator )
  14.         {
  15.             CComPtr<IUnknown> spUnk;
  16.             while (spEnumerator->Next(1, &spUnk, NULL) == S_OK)
  17.             {
  18.                 CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> spWB(spUnk);
  19.                 spUnk=NULL;
  20.                 if ( spWB )
  21.                 {
  22.                     
  23.                     CComPtr<IDispatch> spDocDisp;
  24.                     hr = spWB->get_Document(&spDocDisp); 
  25.                     CComQIPtr<IHTMLDocument2> spHTML (spDocDisp) ;
  26.                     
  27.                     HGLOBAL hMemory;
  28.                     hMemory = GlobalAlloc(GMEM_MOVEABLE, 0);
  29.                     CComPtr<IStream> spStream;
  30.                     CComQIPtr<IPersistStreamInit> spPersistStream = spDocDisp;
  31.                     if (SUCCEEDED(CreateStreamOnHGlobal(hMemory, TRUE, &spStream)))
  32.                     {
  33.                         spPersistStream->Save(spStream, FALSE);
  34.                         LPCTSTR pstr = (LPCTSTR) GlobalLock(hMemory);
  35.                         if (pstr != NULL)
  36.                         {
  37.                             // Stream is always ANSI, but CString 
  38.                             // assignment operator will convert implicitly.
  39.                             CString html(pstr);
  40.                           
  41.                                                     
  42.                              
  43.                         
  44.                                AfxMessageBox(html);
  45.                         }
  46.                     }
  47.                     
  48.                     EnumFrame( spHTML );
  49.                     
  50.                 }
  51.             }
  52.         }
  53.     }
  54. }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值