IHTMLDocument2 *pIHTMLDocument2 = NULL;
pIHTMLDocument2 = (IHTMLDocument2*)m_WebB.GetDocument();
//EnumFrame( pIHTMLDocument2 );//递归枚举当前 IHTMLDocument2 上的子框架framHRESULT 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();
}

解决方案 »

  1.   

    一直取不到IHTMLInputTextElement,能帮我改下吗?
    就是源码里最后一段,就几行,谢谢了:)
      

  2.   

    HRESULT hr = spFormElement->QueryInterface(IID_IHTMLInputTextElement,(void**)&pPwdElement);
    form不是input,不支持IHTMLInputTextElement
    你怎么不枚举form内的input了?
      

  3.   

    提示你,如果那个元素有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其实是一样的。
      

  4.   


    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();
    }
    }
      

  5.   

    贴错了,应该是/************************************************************************/
    /*以下这部分,谢谢,只需要可以找到                              */
    /************************************************************************/
    IDispatch *pDisp = NULL;//--------------取得表单内第 i 项的元素
    hr = spFormElement->item( CComVariant( i ), CComVariant(), &pDisp );
    if ( FAILED( hr &&  !pDisp) )continue;