如何讲HTML代码直接写到TWebBrowser里面?

hangzhou_joe 2002-05-27 11:29:17
在ChinaOk (授人以鱼,不如授人以渔) 的帖子里有一段代码,
http://www.csdn.net/expert/topic/638/638770.xml?temp=.2672388
但是似乎有错误,
我对delphi还不是很了解
(WebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(ms));------这句代码有错误吗,是什么意思,有高手能为我指点一下吗?
...全文
41 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2002-09-07
  • 打赏
  • 举报
回复
Note In Microsoft® Internet Explorer 5, more than one call to the Load method of the IPersist interfaces is supported. In earlier versions, only one call to Load per instance of MSHTML is supported

BUG: IPersistStreamInit Not Available for a FRAME in a FRAMESET

Q271868


The information in this article applies to:

Microsoft Internet Explorer (Programming) version 5.5

You can use the IHTMLDocument2::write method to add content to the WebBrowser control. Make sure that you call the IHTMLDocument2::open method first and the IHTMLDocument2::close method last. To obtain the IHTMLDocument2 interface, perform the following steps:

<!--这里要加上一步(MSDN居然漏了)从得到的框架IDispatch查询IWebbrowser2接口>

Load a blank file into the WebBrowser control.
Call the IWebBrowser2::get_Document method to obtain the IDispatch interface of the document.
Call QueryInterface on the IDispatch pointer, and ask for IHTMLDocument2.
This code does not work for Internet Explorer versions 5.01 and earlier because these versions cannot obtain the IWebBrowser2 control (and therefore IHTMLDocument2) of a FRAME that was created using IHTMLDocument2::write.
Tasehouny 2002-09-06
  • 打赏
  • 举报
回复
masterz() MS的方法对于TOP 帧是有效的,但如果我的页面中包含了多个帧,那么就不能能获得正确的IPersistStreamInit Interface 了!

CComPtr<IHTMLFramesCollection2> pFrameCol ;
hr = m_pMainDoc->get_frames(&pFrameCol);
ASSERT(pFrameCol != NULL);
_variant_t vIndex("MainFrame");
_variant_t vDispatch;
hr = pFrameCol->item(&vIndex,&vDispatch);
ASSERT(SUCCEEDED(hr));
CComPtr<IHTMLWindow2> pIWin2;
hr = vDispatch.pdispVal->QueryInterface(IID_IHTMLWindow2, (void**)&pIWin2);
ASSERT(pIWin2 != NULL);

#ifdef _DEBUG
BSTR bsName;
hr = pIWin2->get_name(&bsName);
ASSERT(SUCCEEDED(hr));

CString strName(bsName);
ASSERT(strName == "MainFrame");
#endif
hr = pIWin2->get_document(&m_pMainFrameDoc);
ASSERT(SUCCEEDED(hr));

CComQIPtr<IPersistStreamInit>pPSI(m_pMainFrameDoc);


HRESULT hr = pPSI->InitNew(); //这里返回错误代码E_NOTIMPL


如果说从 m_pMainDoc 查询到的IPersistStreamInit接口,调用InitNew()方法肯定是成功的! 如此说来,如果是帧,则不能用Loading HTML content from a Stream 方法更新页面了?

用write可以,但如果页面复杂或者大一点,就会出现堆分配错误!如何解决呢????

masterz 2002-05-27
  • 打赏
  • 举报
回复
see "Loading HTML content from a Stream " in MSDN.
masterz 2002-05-27
  • 打赏
  • 举报
回复
"Loading HTML content from a Stream" in MSDN.

3,055

社区成员

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

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