如何讲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));------这句代码有错误吗,是什么意思,有高手能为我指点一下吗?
...全文
12 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
蒋晟 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.
回复
相关推荐
发帖
HTML/XML
创建于2007-09-28

3054

社区成员

VC/MFC HTML/XML
申请成为版主
帖子事件
创建了帖子
2002-05-27 11:29
社区公告
暂无公告