CppWebbrowser得到网页内容并改变内容的方法

本文介绍了一种使用 C++ 在 Web 浏览器控件中更新网页内容的方法,包括修改 HTML 文档的 body 内容及调整 favicon。通过具体代码示例展示了如何获取并设置网页元素,以及如何根据不同域名条件来改变 favicon 的路径。

void __fastcall Tooowebb::Frame11CppWebBrowser1NavigateComplete2(

TObject *Sender, LPDISPATCH pDisp, TVariant *URL)

{

// return;

// easyiemain->ListBox32->Items->Add(Pan42->Caption+"..test tt...3=="+easyiemain->Pan60->Caption);

int kn;

// kn=Pan42->Caption.ToInt();

AnsiString tmp;

tmp=ListBox27->Items->Strings[1]+"favicon.ico";

// tmp=Panel128->Caption+"/favicon.ico";

tmp=Panel128->Caption;

if(tmp.AnsiPos(".sohu.com"))

tmp="http://blog.sohu.com/favicon.ico";

// tmp="gifs/rose1.gif";

ListBox27->Items->Strings[1]=tmp;

try{

{

AnsiString filename = "myformdata.ini";

IHTMLDocument2 * pDoc = NULL;

IHTMLElementCollection * pAllElem = NULL;

IHTMLElement *pElem = NULL;

IHTMLInputTextElement * pInput = NULL;

VARIANT name;

long p;

BSTR bstrSrc;

AnsiString rt, env;

char buf[2048];

name.vt = VT_I4;

IDispatch * WebDocument = static_cast<IDispatch *>(mm[kn]->CppWebBrowser1->Document);

IHTMLDocument2 *HTMLDocument = static_cast<IHTMLDocument2 *>(WebDocument);

pDoc = HTMLDocument;

if(pDoc!=NULL)

{

IHTMLElement *pBodyElement;

pDoc->get_body( &pBodyElement);

AnsiString mtmp="<html><body><h1><font color=FF0000>Hello,world!</font></h1></body></html>";

//pBodyElement->put_innerHTML(mtmp);

AnsiString StrTemp;

StrTemp="123hello";

mtmp=ListBox27->Items->Text;

//mtmp=ListBox32->Items->Text;

StrTemp=mtmp;

//StrTemp=easyiemain->ListBox5->Items->Text;

WideString WideTemp=WideString(StrTemp);

//pBodyElement->get_innerHTML(&bstrSrc);

// StrTemp=AnsiString(bstrSrc);

bstrSrc=WideTemp.c_bstr();

pBodyElement->put_innerHTML(bstrSrc);

pDoc->Release();

}

else

{

ShowMessage("xx--..2"+mm[kn]->Label1->Caption+"..");

}

}

}catch(...)

{

}

}

//---------------------------------------------------------------------------

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

moneytree

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值