IHTMLTextArea 的 put_value 方法实现的设置 文本框的输入内容:
问题:对于网页打开后就显示在页面上的 TextArea 可以正常输入;
但是 对于通过单击触发临时生成的 对话框内的 TextArea 可以找到 并且能 进行put_value,但是内容没有输入进去。
void CWriteTextAreaView::WriteText()
{
IHTMLElementCollection* pObjAllElement = NULL;
IHTMLDocument2* pObjDocument = NULL; pObjDocument = (IHTMLDocument2 *)GetHtmlDocument();
pObjDocument->get_all(&pObjAllElement);
VARIANT name;
CComBSTR tag;
long a;
pObjAllElement->get_length(&a); name.vt = VT_I4;
for(int i=0; i<a; i++)
{
name.lVal = i;
IDispatch * pDispatch = NULL;
HRESULT res = pObjAllElement->item(name, name, &pDispatch);
if(FAILED(res))
continue; IHTMLTextAreaElement* spTextArea; //寻找文本区域
HRESULT rsc = pDispatch->QueryInterface(IID_IHTMLTextAreaElement, (void**)&spTextArea);
if(FAILED(rsc))
continue; BSTR bstrType;
spTextArea->get_type(&bstrType);
CString strType(bstrType);
if(strType.CompareNoCase("textarea") == 0) //类型判断
{
CString strContent = "测试";
HRESULT hr=spTextArea-> put_value(strContent.AllocSysString());
if(hr!=S_OK)
MessageBox( "写出错 ");
}
}
}
问题:对于网页打开后就显示在页面上的 TextArea 可以正常输入;
但是 对于通过单击触发临时生成的 对话框内的 TextArea 可以找到 并且能 进行put_value,但是内容没有输入进去。
void CWriteTextAreaView::WriteText()
{
IHTMLElementCollection* pObjAllElement = NULL;
IHTMLDocument2* pObjDocument = NULL; pObjDocument = (IHTMLDocument2 *)GetHtmlDocument();
pObjDocument->get_all(&pObjAllElement);
VARIANT name;
CComBSTR tag;
long a;
pObjAllElement->get_length(&a); name.vt = VT_I4;
for(int i=0; i<a; i++)
{
name.lVal = i;
IDispatch * pDispatch = NULL;
HRESULT res = pObjAllElement->item(name, name, &pDispatch);
if(FAILED(res))
continue; IHTMLTextAreaElement* spTextArea; //寻找文本区域
HRESULT rsc = pDispatch->QueryInterface(IID_IHTMLTextAreaElement, (void**)&spTextArea);
if(FAILED(rsc))
continue; BSTR bstrType;
spTextArea->get_type(&bstrType);
CString strType(bstrType);
if(strType.CompareNoCase("textarea") == 0) //类型判断
{
CString strContent = "测试";
HRESULT hr=spTextArea-> put_value(strContent.AllocSysString());
if(hr!=S_OK)
MessageBox( "写出错 ");
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货