CHtmlView能不能打开一个字符串buffer里面的网页?

GolemZ 2003-11-08 10:15:18
他提供的Navigate(),和Navigate2()似乎只能打开URL地址和本地文件,
有哪位高手知道能不能用他来打开一个buffer里面的html网页?


...全文
69 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
tangmingdeng 2003-11-13
  • 打赏
  • 举报
回复
HRESULT LoadWebOCFromStream(IDispatch* pHtmlDoc , IStream* pStream)
{
HRESULT hr;

IPersistStreamInit* pPersistStreamInit = NULL;

// Query for IPersistStreamInit.
hr = pHtmlDoc->QueryInterface( IID_IPersistStreamInit, (void**)&pPersistStreamInit );
if ( SUCCEEDED(hr) )
{
// Initialize the document.
hr = pPersistStreamInit->InitNew();
if ( SUCCEEDED(hr) )
{
// Load the contents of the stream.
hr = pPersistStreamInit->Load( pStream );
}
pPersistStreamInit->Release();
}
return hr;
}


void Load()
{
HRESULT hr;
IUnknown* pUnkBrowser = NULL;
IStream* pStream = NULL;
HGLOBAL hHTMLText;

static char szHTMLText[] = "<html><h1>Stream Test</h1><p>This HTML content is being\
loaded from a stream.</html>";
// Is this the DocumentComplete event for the top frame window?
// Check COM identity: compare IUnknown interface pointers.
hr = m_wndBrowser.GetApplication()->QueryInterface( IID_IUnknown, (void**)&pUnkBrowser );
if ( SUCCEEDED(hr) )
{
hHTMLText = GlobalAlloc( GPTR, lstrlen(szHTMLText)+1 );
if ( hHTMLText )
{
lstrcpy( (char*)hHTMLText, szHTMLText );
hr = CreateStreamOnHGlobal( hHTMLText, TRUE, &pStream );
if ( SUCCEEDED(hr) )
{
// Call the helper function to load the WebOC from the stream.
LoadWebOCFromStream( m_wndBrowser.GetDocument(), pStream );
pStream->Release();
}
//GlobalFree( hHTMLText );
}

}
pUnkBrowser->Release();
}

其中m_wndBrowser为IWebBrowser2的一个对象.有何疑问请QQ:76445055
蒋晟 2003-11-09
  • 打赏
  • 举报
回复
用Document对象的IPersistStream接口
参见http://www.csdn.net/develop/read_article.asp?id=18465
GolemZ 2003-11-08
  • 打赏
  • 举报
回复
可是那样会影响速度,有没有不用临时文件的办法?

MilitaryMiniatures 2003-11-08
  • 打赏
  • 举报
回复
一个简单的想法:
你可以在Windows的临时目录下创建一个html文件,然后把buffer中的内容写入到该文件中,然后就可以调用Navigate了。
MilitaryMiniatures 2003-11-08
  • 打赏
  • 举报
回复
别的方法暂时还不知道。

3,055

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧