如何在htmlview中触发页面中的按钮

发布网友

我来回答

1个回答

热心网友

void CHtmlradioselView::submit()
LPDISPATCH lpdisp=this->GetHtmlDocument();
IHTMLDocument2* spHtmlDocument=NULL;
HRESULT hr=lpdisp->QueryInterface(IID_IHTMLDocument2,(void**)&spHtmlDocument);

IHTMLElementCollection* pColl=NULL;
hr=spHtmlDocument->get_all(&pColl);
if(pColl!=NULL&&SUCCEEDED(hr))
LPDISPATCH pdisp=NULL;
IHTMLInputElement* pelem=NULL;
long num=0;
pColl->get_length(&num);
for(int i=0;i<num;i++)
hr=pColl->item(COleVariant((short)i),COleVariant((short)i),&pdisp);
if(SUCCEEDED(hr)&&pdisp!=NULL)
hr=pdisp->QueryInterface(IID_IHTMLInputElement,(void**)&pelem);
if(SUCCEEDED(hr)&&pelem!=NULL)
bool bfind=false;
BSTR bstrtype;
pelem->get_type(&bstrtype);
if(wcsicmp(bstrtype,L"submit")==0)
IHTMLElement* petmp =NULL;
pelem->QueryInterface(IID_IHTMLElement,(void**)&petmp);
petmp->click();
petmp->Release();
bfind=true;
SysFreeString(bstrtype);
pelem->Release();
if(bfind)
break;
pdisp->Release();
pColl->Release();
if(spHtmlDocument!=NULL)
spHtmlDocument->Release();
if(lpdisp!=NULL)
lpdisp->Release();

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com