CHtmlView读取带框架的网页的函数。
2006-06-19 17:54
127 查看
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;
}
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;
}
相关文章推荐
- frame框架怎么实现读取某个网页的特定位置
- 【框架-MFC】CHtmlView(chenlu-1):将网页嵌入MFC的视图中
- 字符设备关键函数与编程框架
- 第一个网页框架(自己的百度)
- 用正则表达式去截取网页里文字的方法。参数为读取的网页源代码
- Discuz 5.0 中读取纯真IP数据库函数分析
- php之读取文件的函数
- 使用Jsoup函数包抓取网页内容
- 想要主框架与子框架的菜单项有相同的响应函数
- 使用JS设置cookie和读取cookie的函数
- Spring MVC框架下在java代码中访问applicationContext.xml文件中配置的文件(可以用于读取配置文件内容)
- 爬虫程序(一)---读取网页
- 防止别人用IFRAME框架嵌套调用自己网页的方FA
- TP框架中内置查询IP函数
- 开源的java游戏引擎及框架(包括有网页引擎)
- 静态网页的大体框架
- 网页框架布局
- pandas的read_csv()函数读取的文件路径找不到报错
- javascript实现让网页逃不出框架
- 浅析busybox查找命令和调用相应命令函数的实现流程框架