The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: RD on February 19, 2011, 08:02:14 AM

Title: LoadHtmlFromStream
Post by: RD on February 19, 2011, 08:02:14 AM
Html loaded from memory
Applications interact with the web page, I found MSDN, IHTMLDocument2, How can I load a data stream WEB as well?

void DisplayDirect(CString sHtml);
HRESULT LoadHtmlFromStream(IStream* pStream);



void CHTMLDlg::DisplayDirect(CString sHtml)
{
HRESULT hr;
HGLOBAL hHTMLText;
IStream* pStream = NULL;

hHTMLText = GlobalAlloc( GPTR, sHtml.GetLength()+1 );
if (hHTMLText) {
lstrcpy((char*)hHTMLText, sHtml);
hr = CreateStreamOnHGlobal(hHTMLText, TRUE, &pStream );
if (SUCCEEDED(hr)) {
LoadHtmlFromStream(pStream);
pStream->Release();
}
}
}

HRESULT CHMTLDlg::LoadHtmlFromStream(IStream* pStream)
{
HRESULT hr;
IDispatch* pHtmlDoc = NULL;
IPersistStreamInit* pPersistStreamInit = NULL;

internetExplorer.Navigate( _T("about:blank"), NULL, NULL, NULL, NULL );
pHtmlDoc = internetExplorer.GetDocument(); // m_WebBrowser is your control

if (pHtmlDoc)
{
pHtmlDoc->QueryInterface( IID_IPersistStreamInit, (void**)&pPersistStreamInit );
pPersistStreamInit->InitNew();
pPersistStreamInit->Load( pStream );
pPersistStreamInit->Release();
}
return hr;
}

usage

DisplayDirect("<html><body><h1>test</h1></body></html>");