精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>C/C++>>WINDOWS界面设计>>HTML界面>>Sample:Set the Content of a CHtmlView

主题:Sample:Set the Content of a CHtmlView
发信人: jiangsheng()
整理人: wenbobo(2002-12-27 16:00:21), 站内信件
// TODO: Add your specialized creation code here
CComDispatchDriver pHTMLDispatch(GetHtmlDocument());
if(pHTMLDispatch.p){
HRESULT hr;
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pHTMLDocument(pHTMLDi
spatch); 
if(pHTMLDocument.p){
CComPtr<IHTMLElementCollection> pHTMLElementCollection;
hr=pHTMLDocument->get_all(&pHTMLElementCollection);
if(hr==S_OK && pHTMLElementCollection.p!=NULL){
IDispatch* pDisp;
COleVariant varTagName("BODY");
hr=pHTMLElementCollection->tags(varTagName,&pDisp);
if(hr==S_OK){
LONG celem;
CComQIPtr<IHTMLElementCollection, &IID_IHTMLElementCollection> pH
TMLElements(pDisp); 
hr=pHTMLElements->get_length(&celem);
if(hr==S_OK){
for(int i=0;i<celem;i++){
VARIANT varIndex,var2;//var2 is not used because accessing inde
x,not name
varIndex.vt=VT_UINT;
varIndex.lVal=i;
VariantInit(&var2);
hr=pHTMLElements->item(varIndex,var2,&pDisp);
if(hr==S_OK){
CComQIPtr<IHTMLElement, &IID_IHTMLElement> pHTMLElement(pDisp)

if(pHTMLElement){
#ifdef _DEBUG
BSTR bstrTag;
hr=pHTMLElement->get_outerHTML(&bstrTag);
CString strTag=bstrTag;
::afxDump<<strTag;
#endif
//html element
CString strHTMLFile;
strHTMLFile="New Body Here";
CComBSTR bstrHTML(strHTMLFile);
pHTMLElement->put_innerHTML(bstrHTML);
}
if(pDisp)
pDisp->Release();
}
}
}
if(pDisp)
pDisp->Release();
}
}
}
}


--
HE WHO CONTROLS THE PAST, COMMANDS THE FUTURE.
HE WHO CONTROLS THE FUTURE CONQUERS THE PAST.

※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.96.44.196]

[关闭][返回]