C++ builder中动态改变浏览器中的内容
先在浏览器中放一个浏览器控件,名字叫wb,然后用下面的代码来实现
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
IDispatch *wdoc = static_cast<IDispatch *>(wb->Document);
IHTMLDocument2* pHtmlDoc2 = static_cast<IHTMLDocument2 *>(wdoc);
if(pHtmlDoc2){
HRESULT hr = S_OK;
IHTMLElement *pBodyElement;
hr=pHtmlDoc2->get_body(&pBodyElement);
if(pBodyElement!=NULL)
{
BSTR pbBody = L"中文测试";
hr=pBodyElement->put_innerHTML(pbBody); //类似的还有put_innerTEXT
pBodyElement->Release();
}
pHtmlDoc2->Release();
//if( hr==S_FALSE) return FALSE;
//else return TRUE;
}
//else return FALSE;
}
已经实验过的,在2009中中文UTF8是正常显示的,貌似先前加载的css和js也是可以使用的,如果浏览器没有先加载过网页这段代码是不能使用的,不会报错
Written by gegewan on 十月 4th, 2008 with
no comments.
Read more articles on C/C++.
- [+] Digg: Feature this article
- [+] Del.icio.us: Bookmark this article
- [+] Furl: Bookmark this article