关于IHTMLInputTextElement ,谁能帮我改下代码吗?谢谢了
IHTMLDocument2 *pIHTMLDocument2 = NULL;
pIHTMLDocument2 = (IHTMLDocument2*)m_WebB.GetDocument();
//EnumFrame( pIHTMLDocument2 );//递归枚举当前 IHTMLDocument2 上的子框架fram
HRESULT hr;
CComBSTR bstrTitle;
pIHTMLDocument2-> get_title( &bstrTitle );//取得文档标题
USES_CONVERSION;
bool bSub = FALSE;
CString strTitle =OLE2CT(bstrTitle);
CComQIPtr < IHTMLElementCollection > spElementCollection;
hr = pIHTMLDocument2-> get_forms( &spElementCollection );//取得表单集合
if ( FAILED( hr ) )
{
allInfo+= "获取表单的集合 IHTMLElementCollection 错误\r\n ";
return;
}
long nFormCount=0;//取得表单数目
hr = spElementCollection-> get_length( &nFormCount );
if ( FAILED( hr ) )
{
allInfo+= "获取表单数目错误\r\n ";
return;
}
for(long i=0; i <nFormCount; i++)
{
IDispatch *pDisp = NULL;//取得第 i 项表单
hr = spElementCollection-> item( CComVariant( i ), CComVariant(), &pDisp );
if ( FAILED( hr ) )continue;
CComQIPtr < IHTMLFormElement > spFormElement = pDisp;
pDisp-> Release();
long nElemCount=0;//取得表单中 域 的数目
hr = spFormElement-> get_length( &nElemCount );
if ( FAILED( hr ) )continue;
for(long j=0; j <nElemCount; j++)
{
/************************************************************************/
/*以下这部分,谢谢,只需要可以找到 */
/************************************************************************/
IHTMLInputTextElement pPwdElement;
HRESULT hr = spFormElement-> QueryInterface(IID_IHTMLInputTextElement,(void**)&pPwdElement);
if(SUCCEEDED(hr))
{
CComBSTR type;
pPwdElement-> get_name(&type);
CString strType = OLE2CT(type);
MessageBox(strType);
}
}
//想提交这个表单吗?删除下面语句的注释吧
//spFormElement-> submit();
}
[解决办法]
HRESULT hr = spFormElement-> QueryInterface(IID_IHTMLInputTextElement,(void**)&pPwdElement);
form不是input,不支持IHTMLInputTextElement
你怎么不枚举form内的input了?
[解决办法]
提示你,如果那个元素有ID,而后如下:
IHTMLDocument2 pDoc2;
...//得到 pDoc2实际的指针
IHTMLDocument3* pDoc3=NULL;
pDoc2-> queryinterface(IID_IHTMLDocument3,(void **)&pDoc3);
IHTMLElement* pElem=NULL;
pDoc3-> getElementById( "你的元素ID ",(IHTMLElement **)&pElem);
IHTMLInputTextElement* pInpTx=NULL;
pElem-> queryinterface(IID_IHTMLInputTextElement,(void **)&pInpTx);
总之,IE DOM的编程模型和Javascript其实是一样的。
[解决办法]
for(long i=0; i <nFormCount; i++)
{
IDispatch *pDisp = NULL;//取得第 i 项表单
hr = spElementCollection-> item( CComVariant( i ), CComVariant(), &pDisp );
if ( FAILED( hr ) )continue;
CComQIPtr < IHTMLFormElement > spFormElement = pDisp;
pDisp-> Release();
long nElemCount=0;//取得表单中 域 的数目
hr = spFormElement-> get_length( &nElemCount );
if ( FAILED( hr ) )continue;
for(long j=0; j <nElemCount; j++)
{
/************************************************************************/
/*以下这部分,谢谢,只需要可以找到 */
/************************************************************************/
IDispatch *pDisp = NULL;//--------------取得表单内第 i 项的元素
hr = spElementCollection-> item( CComVariant( i ), CComVariant(), &pDisp );
if ( FAILED( hr && !pDisp) )continue;
IHTMLInputTextElement pPwdElement;
HRESULT hr = pDisp -> QueryInterface(IID_IHTMLInputTextElement,(void**)&pPwdElement);
pDisp-> Release();
if(SUCCEEDED(hr))
{
CComBSTR type;
pPwdElement-> get_name(&type);
CString strType = OLE2CT(type);
MessageBox(strType);
pPwdElement-> Release();
}
}
[解决办法]
贴错了,应该是
/************************************************************************/
/*以下这部分,谢谢,只需要可以找到 */
/************************************************************************/
IDispatch *pDisp = NULL;//--------------取得表单内第 i 项的元素
hr = spFormElement-> item( CComVariant( i ), CComVariant(), &pDisp );
if ( FAILED( hr && !pDisp) )continue;