用chtmlview打开的带框架的网页,如何取得框架中所有包含的网页的html源文件?
解决方案 »
- MFC 程序在别人电脑上菜单栏莫名其妙变宽了
- 位图打印问题,快崩溃了!!!
- multimon.h
- 无聊,大家来给俺估个价~~~,随便调侃。
- 怎么打包发布我做好的地个exe文件啊?
- 高手请来指教一下:我想在一个对话框程序中,动态的添加属性页,并且在每个属性页中动态的添加编辑控件,请问要怎么做啊,最好有DEMO,谢谢
- 急问一个问题!
- 请教如何使鼠标输入无效,就好像正在使用鼠标时,鼠标插头拨掉时的那样无效,但光标依然存在
- 如何设计游戏外挂(提供相关代码,相关资料,相关技术网站,UP者,都有份)
- VC 串口通讯 急等
- 有没有一起学习 代理服务器的兄弟?我找到了http代理的源代码。希望共同学习。
- activex控件中的通用控件的状态恢复问题。
see http://support.microsoft.com/kb/q271868/
BOOL CHtmlView::GetFrameSource( IDispatch *pDisp, CString& refString )
{
BOOL bRetVal = FALSE;
HRESULT hr = S_OK;
if ( pDisp != NULL )
{
CComQIPtr<IWebBrowser2> pBrowser = pDisp;
if ( pBrowser != NULL )
{
IDispatch *pDispDoc = NULL;
hr = pBrowser->get_Document(&pDispDoc);
if ( !( FAILED(hr) || !pDisp ) )
{
CComQIPtr<IPersistStreamInit> pStmInit = pDisp;
if ( !pStmInit )
{
HGLOBAL hMemory;
hMemory = GlobalAlloc(GMEM_MOVEABLE, 0);
if (hMemory != NULL)
{
CComQIPtr<IPersistStreamInit> spPSI = pDispDoc;
if( spPSI != NULL)
{
CComPtr<IStream> spStream;
if (SUCCEEDED(CreateStreamOnHGlobal(hMemory, TRUE, &spStream)))
{
spPSI->Save(spStream, FALSE);
LPCTSTR pstr = (LPCTSTR) GlobalLock(hMemory);
if (pstr != NULL)
{
// Stream is always ANSI, but CString
// assignment operator will convert implicitly.
bRetVal = TRUE;
TRY
{
refString = pstr;
}
CATCH_ALL(e)
{
bRetVal = FALSE;
DELETE_EXCEPTION(e);
}
END_CATCH_ALL if(bRetVal == FALSE)
GlobalFree(hMemory);
else
GlobalUnlock(hMemory);
}
}
}
}
}
}
RELEASE(pDispDoc);
}
}
return bRetVal;
}但是只能用在DocumentComplete里,因为我不知道怎么获得pDisp,好像只有在DocumentComplete里才能获得框架各页的pDisp,这样没有通用性,我想要实现的是像GetSource一样的功能,就是只要网页下载完毕,就可以在任意时刻获得框架html源文件,而不是只能在DocumentComplete里
最好能直接告诉我该怎么做,不要让我在一堆资料里自己找
下面是代码,老大帮我看看有没有什么错,还有什么需要改进的地方。
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)
{
// Stream is always ANSI, but CString
// assignment operator will convert implicitly.
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;
}