如何设置或提取一个IE窗口中文本框的内容 一个IE窗口打开的页面中有两个文本框,我需要用一个程序来设置或提取该文本框的内容。我无html基础,请说得较为清楚详细些。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://topic.csdn.net/t/20020608/15/788611.html 这是一段伪代码,可以参考:function setInnerText (elementId, text) { var element; if (document.getElementById) { element = document.getElementById(elementId); } else if (document.all) { element = document.all[elementId]; } if (element) { if (typeof element.textContent != 'undefined') { element.textContent = text; } else if (typeof element.innerText != 'undefined') { element.innerText = text; } else if (typeof element.removeChild != 'undefined') { while (element.hasChildNodes()) { element.removeChild(element.lastChild); } element.appendChild(document.createTextNode(text)); } } } http://support.microsoft.com/kb/176792/en-ushttp://community.csdn.net/Expert/topic/5166/5166830.xml?temp=9.692019E-02 http://topic.csdn.net/t/20020608/15/788611.html找本书看看也好啊 CComPtr<IHTMLDocument3> pDoc3;hr = pDoc2->QueryInterface(IID_IHTMLDocument3,(void**)&pDoc3) ;if(hr==S_OK){CComBSTR bstrName("INPUT");CComPtr<IHTMLElementCollection> pElemCollINPUT;hr=pDoc3->getElementsByTagName(bstrName,&pElemCollFrame);if (hr==S_OK){long pLength;hr=pElemCollINPUT->get_length(&pLength);if(hr==S_OK){for(int i=0;i<pLength;i++){IDispatch *pDispInputText=NULL;CComVariant vIndex=i;hr=pElemCollINPUT->item(vIndex,vIndex,&pDispInputText);if(hr==S_OK){CComPtr<IHTMLInputTextElement> pElemInputText;hr=pDispFrame->QueryInterface(IID_IHTMLInputTextElement,(void**)&pElemInputText); if(hr==S_OK){ CComBSTR strVal; pElemInputText->get_value(&strVal);//得到文本值 pElemInputText->put_value(strVaL);//设置文本值}}pDispInputText->Release();}}}} void TfrmMain::SetInputValue(AnsiString _sTitle, AnsiString _sContent){ AnsiString sType; IHTMLDocument2 *pDocument = NULL; IHTMLElementCollection *pCollection = NULL; IHTMLElementCollection *pInputCollection = NULL; IDispatch *dsInput = NULL; if( lvNewWork->Selected == NULL ) return; if( S_OK!=CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,(void **)&pDocument) ) return; pDocument->get_all(&pCollection); if( pCollection==NULL ) goto return1; VARIANT var; var.vt = VT_BSTR; var.bstrVal = L"INPUT"; pCollection->tags(var,&dsInput); if( dsInput == NULL ) goto return1; dsInput->QueryInterface( IID_IHTMLElementCollection, (void **)&pInputCollection); long lInputCount; pInputCollection->get_length(&lInputCount); for( long l = 0; l < lInputCount; l++ ) { _variant_t index = l; IDispatch* pDisp; HRESULT hr=pInputCollection->item(index,index,&pDisp); if( pDisp == NULL ) continue; IHTMLInputElement *pElement = NULL; pDisp->QueryInterface(IID_IHTMLInputElement,(void**)&pElement); if( pElement == NULL ) continue; BSTR bstemp; pElement->get_type(&bstemp); sType = bstemp; ::SysFreeString(bstemp); if( sType=="text") { pElement->get_name(&bstemp); sType = bstemp; ::SysFreeString(bstemp); int iType = GetInputType(sType); AnsiString sContent; if( iType == 1 ) { btnCopyTitleClick(btnCopyTitle); } else if( iType == 2) { btnCopyTitleClick(btnContentCopy); } if( iType ) { sContent = Clipboard()->AsText; //bstemp = TStringConverter<TCHAR>::AnsiToWide(sContent.c_str()); _bstr_t val(sContent.c_str()); pElement->put_value(bstemp); //delete [] bstemp; } } pDisp->Release(); pElement->Release(); }return1: if( pDocument )pDocument->Release(); if( pCollection ) pCollection->Release(); if( dsInput ) dsInput->Release(); if( pInputCollection ) pInputCollection->Release();} 通过IE的IHtmlDocument 接口逐步获取对应的IHtmlElement,然后取得属性Value值 http://www.vckbase.com/code/listcode.asp?mclsid=17&sclsid=1711里面有原代码,参考一下 VS2010 radio的问题 时间函数的设定 窗口过程用到的的CALLBACK 是回调函数的意思吗 tabctrl控件 右上角的两个button,点击时会重画标签,请问是响应哪个消息? 紧急求助!哪位大侠有ttf2bdf工具即失量字库转换为bdf字库的工具? file read and write ? 简单问题,先到先得分。 能否用VC应用程序来实现DOS的Ping 小软件的价格? 请教关于中文字符串的排序 请问一个 线程创建"控件listbox"的问题
function setInnerText (elementId, text) {
var element;
if (document.getElementById) {
element = document.getElementById(elementId);
}
else if (document.all) {
element = document.all[elementId];
}
if (element) {
if (typeof element.textContent != 'undefined') {
element.textContent = text;
}
else if (typeof element.innerText != 'undefined') {
element.innerText = text;
}
else if (typeof element.removeChild != 'undefined') {
while (element.hasChildNodes()) {
element.removeChild(element.lastChild);
}
element.appendChild(document.createTextNode(text));
}
}
} http://support.microsoft.com/kb/176792/en-us
http://community.csdn.net/Expert/topic/5166/5166830.xml?temp=9.692019E-02
找本书看看也好啊
hr = pDoc2->QueryInterface(IID_IHTMLDocument3,(void**)&pDoc3) ;
if(hr==S_OK)
{
CComBSTR bstrName("INPUT");
CComPtr<IHTMLElementCollection> pElemCollINPUT;
hr=pDoc3->getElementsByTagName(bstrName,&pElemCollFrame);
if (hr==S_OK)
{
long pLength;
hr=pElemCollINPUT->get_length(&pLength);
if(hr==S_OK)
{
for(int i=0;i<pLength;i++)
{
IDispatch *pDispInputText=NULL;
CComVariant vIndex=i;
hr=pElemCollINPUT->item(vIndex,vIndex,&pDispInputText);
if(hr==S_OK)
{
CComPtr<IHTMLInputTextElement> pElemInputText;
hr=pDispFrame->QueryInterface(IID_IHTMLInputTextElement,(void**)&pElemInputText);
if(hr==S_OK)
{
CComBSTR strVal;
pElemInputText->get_value(&strVal);//得到文本值
pElemInputText->put_value(strVaL);//设置文本值
}
}
pDispInputText->Release();
}
}
}
}
{
AnsiString sType;
IHTMLDocument2 *pDocument = NULL;
IHTMLElementCollection *pCollection = NULL;
IHTMLElementCollection *pInputCollection = NULL;
IDispatch *dsInput = NULL; if( lvNewWork->Selected == NULL ) return;
if( S_OK!=CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,(void **)&pDocument) ) return;
pDocument->get_all(&pCollection);
if( pCollection==NULL ) goto return1;
VARIANT var;
var.vt = VT_BSTR;
var.bstrVal = L"INPUT";
pCollection->tags(var,&dsInput);
if( dsInput == NULL ) goto return1;
dsInput->QueryInterface( IID_IHTMLElementCollection, (void **)&pInputCollection); long lInputCount;
pInputCollection->get_length(&lInputCount);
for( long l = 0; l < lInputCount; l++ )
{
_variant_t index = l;
IDispatch* pDisp;
HRESULT hr=pInputCollection->item(index,index,&pDisp);
if( pDisp == NULL ) continue;
IHTMLInputElement *pElement = NULL;
pDisp->QueryInterface(IID_IHTMLInputElement,(void**)&pElement);
if( pElement == NULL ) continue;
BSTR bstemp;
pElement->get_type(&bstemp);
sType = bstemp;
::SysFreeString(bstemp);
if( sType=="text")
{
pElement->get_name(&bstemp);
sType = bstemp;
::SysFreeString(bstemp);
int iType = GetInputType(sType);
AnsiString sContent;
if( iType == 1 )
{
btnCopyTitleClick(btnCopyTitle);
}
else if( iType == 2)
{
btnCopyTitleClick(btnContentCopy);
}
if( iType )
{
sContent = Clipboard()->AsText;
//bstemp = TStringConverter<TCHAR>::AnsiToWide(sContent.c_str());
_bstr_t val(sContent.c_str());
pElement->put_value(bstemp);
//delete [] bstemp;
}
}
pDisp->Release();
pElement->Release(); }
return1:
if( pDocument )pDocument->Release();
if( pCollection ) pCollection->Release();
if( dsInput ) dsInput->Release();
if( pInputCollection ) pInputCollection->Release();
}
里面有原代码,参考一下