CHtmlView读取带框架的网页的函数。

 BOOL GetFrameSource( CString& refString, long frameIndex =0)

frameIndex 为框架集的序号

0 代表主框架,如果frameIndex 大于总的框架数则返回FALSE

BOOL CHtmlView::GetFrameSource( CString& refString, long frameIndex )
{
 BOOL bRetVal = FALSE;
 if( frameIndex == 0 )
 {
  bRetVal = GetSource( refString );
 }
 else if( frameIndex > 0 )
 {
  frameIndex = frameIndex - 1;
  CComQIPtr<IDispatch> pDisp = GetHtmlDocument();

  if ( pDisp != NULL )
  {
   CComQIPtr<IHTMLDocument2> pHtmlDoc = pDisp;

   if ( pHtmlDoc != NULL )
   {
    CComQIPtr<IHTMLFramesCollection2> pFrames;
    pHtmlDoc->get_frames( &pFrames );

    if ( pFrames != NULL )
    {
     long frameCount = 0;
     pFrames->get_length( &frameCount );

     if ( frameCount > frameIndex )
     {
      COleVariant varIndex( frameIndex, VT_I4 );
      COleVariant varpDisp;
      pFrames->item( varIndex, varpDisp );
      CComQIPtr<IDispatch> pDispDoc = varpDisp.pdispVal;

      if( pDispDoc != NULL )
      {
       CComQIPtr<IHTMLWindow2> pHtmlWnd = pDispDoc;

       if( pHtmlWnd != NULL )
       {
        CComQIPtr<IHTMLDocument2> pHtmlDocf;
        pHtmlWnd->get_document( &pHtmlDocf );

        if( pHtmlDocf != NULL )
        {
         HGLOBAL hMemory;
         hMemory = GlobalAlloc( GMEM_MOVEABLE, 0);

         if (hMemory != NULL)
         {
          CComQIPtr<IPersistStreamInit> spPSI = pHtmlDocf;

          if( spPSI != NULL)
          {
           CComPtr<IStream> spStream;
           if ( SUCCEEDED( CreateStreamOnHGlobal(hMemory, TRUE, &spStream) ) )
           {
            spPSI->Save( spStream, FALSE );
            LPCTSTR pstr = (LPCTSTR) GlobalLock( hMemory );
            if ( pstr != NULL )
            {
             bRetVal = TRUE;
             TRY
             {                      
              refString = pstr;
             }
             CATCH_ALL(e)
             {
              bRetVal = FALSE;
              DELETE_EXCEPTION(e);
             }
             END_CATCH_ALL

             if( bRetVal == FALSE )
              GlobalFree( hMemory );
             else
              GlobalUnlock( hMemory );
            }
           }
          }
         }
        }
       }
      }
     }
    }
   }
  }
 }

 return bRetVal;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值