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源文件