动态改变网页内容(CHtmlView/CWebBrowser2/IE
来源:百度文库 编辑:神马文学网 时间:2024/04/30 02:57:35
很多时候,我们需要动态的修改网页的内容。
早先COM集中营曾有篇文章介绍过,源代码:http://263.csdn.net/FileBBS/files/2001_9/T_642_1.zip
其中基本代码如下:
void CMainFrame::OnChangehtml()
{
IHTMLDocument2 *pHTMLDocument=NULL;
IPersistStreamInit *pPSI=NULL;
IStream *pStream=NULL;
HGLOBAL hHTMLText;
if (!(pHTMLDocument = (IHTMLDocument2*)m_pHtmlView->m_browser.GetDocument()))//m_pHtmlView是CHtmlView或者WebBrowser
return;
if (FAILED(pHTMLDocument->QueryInterface(&pPSI)))
{
return;
}
pHTMLDocument->clear();
pPSI->InitNew();
LPCTSTR strText = m_pSourceView->LockBuffer();
DWORD dwLength= strlen(strText);
hHTMLText = GlobalAlloc(GMEM_FIXED, dwLength);
memset(hHTMLText, 0, dwLength);
memcpy(hHTMLText, strText, dwLength);
m_pSourceView->UnlockBuffer();
CreateStreamOnHGlobal(hHTMLText, TRUE, &pStream);
ULARGE_INTEGER libNewSize;
libNewSize.QuadPart = dwLength;
pStream->SetSize(libNewSize);
pPSI->Load(pStream);
pStream->Release();
pPSI->Release();
}
网页内容倒是动态改变了,但你查看一下网页属性会发现,网页变成了:about:blank
很痛苦是吧,变成空白页了,呵呵~~
下面方法利用IHtmlDocument2的方法动态改变网页内容,而不改变网页属性
BOOL CXXXXView::put_bodyHtml(CString cs)
{
IHTMLDocument2* pHtmlDoc2 = (IHTMLDocument2*)GetHtmlDocument();
if( pHtmlDoc2)
{
HRESULT hr = S_OK;
IHTMLElement *pBodyElement;
hr=pHtmlDoc2->get_body( &pBodyElement);
if(pBodyElement!=NULL)
{
BSTR pbBody = cs.AllocSysString();
hr=pBodyElement->put_innerHTML(pbBody); //类似的还有put_innerTEXT
pBodyElement->Release();
}
pHtmlDoc2->Release();
if( hr==S_FALSE) return FALSE;
else return TRUE;
}
else return FALSE;
}
到时候你只需要这样调用:put_BodyHtml("a string");
早先COM集中营曾有篇文章介绍过,源代码:http://263.csdn.net/FileBBS/files/2001_9/T_642_1.zip
其中基本代码如下:
void CMainFrame::OnChangehtml()
{
IHTMLDocument2 *pHTMLDocument=NULL;
IPersistStreamInit *pPSI=NULL;
IStream *pStream=NULL;
HGLOBAL hHTMLText;
if (!(pHTMLDocument = (IHTMLDocument2*)m_pHtmlView->m_browser.GetDocument()))//m_pHtmlView是CHtmlView或者WebBrowser
return;
if (FAILED(pHTMLDocument->QueryInterface(&pPSI)))
{
return;
}
pHTMLDocument->clear();
pPSI->InitNew();
LPCTSTR strText = m_pSourceView->LockBuffer();
DWORD dwLength= strlen(strText);
hHTMLText = GlobalAlloc(GMEM_FIXED, dwLength);
memset(hHTMLText, 0, dwLength);
memcpy(hHTMLText, strText, dwLength);
m_pSourceView->UnlockBuffer();
CreateStreamOnHGlobal(hHTMLText, TRUE, &pStream);
ULARGE_INTEGER libNewSize;
libNewSize.QuadPart = dwLength;
pStream->SetSize(libNewSize);
pPSI->Load(pStream);
pStream->Release();
pPSI->Release();
}
网页内容倒是动态改变了,但你查看一下网页属性会发现,网页变成了:about:blank
很痛苦是吧,变成空白页了,呵呵~~
下面方法利用IHtmlDocument2的方法动态改变网页内容,而不改变网页属性
BOOL CXXXXView::put_bodyHtml(CString cs)
{
IHTMLDocument2* pHtmlDoc2 = (IHTMLDocument2*)GetHtmlDocument();
if( pHtmlDoc2)
{
HRESULT hr = S_OK;
IHTMLElement *pBodyElement;
hr=pHtmlDoc2->get_body( &pBodyElement);
if(pBodyElement!=NULL)
{
BSTR pbBody = cs.AllocSysString();
hr=pBodyElement->put_innerHTML(pbBody); //类似的还有put_innerTEXT
pBodyElement->Release();
}
pHtmlDoc2->Release();
if( hr==S_FALSE) return FALSE;
else return TRUE;
}
else return FALSE;
}
到时候你只需要这样调用:put_BodyHtml("a string");
动态改变网页内容(CHtmlView/CWebBrowser2/IE
实现Web页面内容动态改变的dhtml操作
IE网页打不开
用静态的URL地址显示动态网页内容_惠'blog
用XML JSP实现网页内容动态显示的方案_技巧_网页_IT专家网
用XML JSP实现网页内容动态显示的方案_技巧_网页_IT专家网
ie浏览器网页出现错误
从注册表中改回IE网页
IE浏览器打不开网页,怎么办?
IE浏览器打不开网页怎么办?
网页内容复制
内容如何提取网页
编辑网页内容
网页内容不能复制?
网页动态文字特效代码
破解网页内容不能复制
破解网页内容不能复
破解网页内容不能复制...
怎样快速复制网页内容
IE为什么有很多网页打不开?
IE为什么有很多网页打不开?
IE为什么有很多网页打不开?.
ie打不开网页的原因与解决方法
IE网页面字体变小怎么办