if(phd)
{
     IHTMLElementCollection *pForm;
     if(SUCCEEDED(phd->get_all(&pForm)))
    {
long len;
pForm->get_length(&len); //How many elements on this form?
for(int i = 0; i < len; i++)
{
           IHTMLButtonElement *lpButton;
pd = NULL;
pForm->item(CComVariant(i),CComVariant(i),&pd);
if(pd)
{
                        pd->QueryInterface(&lpButton);
               if(lpButton)
     {
      //pd->QueryInterface(&lpButton);
      BSTR ppName,ppType;
     lpButton->get_name(&ppName);
            }
}
pd->Release();
pd = NULL;
}
pForm->Release();
pForm = NULL;
}

解决方案 »

  1.   

    ///////////////////////////////////////////////////////////////////////////////////////
    //click submit button of IE window
    //If it works, it is written by masterz,otherwise I don't
    //know who writes it^_^
    ///////////////////////////////////////////////////////////////////////////////////////
    void CGetIESrcDlg::NavigateToUrl()
    {
    // Import the following files in your stdafx.h
    // #import <mshtml.tlb> // Internet Explorer 5
    // #import <shdocvw.dll>
    //  Refer to "Connect to Internet Explorer Instances, From your own Process. " in www.codeguru.com
    SHDocVw::IShellWindowsPtr m_spSHWinds;
    CoInitialize(NULL);
    if(m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) == S_OK)
    {
    IDispatchPtr spDisp;
    long nCount = m_spSHWinds->GetCount();
    for (long i = 0; i < nCount; i++)
    {
    _variant_t va(i, VT_I4);
    spDisp = m_spSHWinds->Item(va);
    SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
    if (spBrowser != NULL)
    {
    IDispatchPtr spDisp;
    if(spBrowser->get_Document(&spDisp) == S_OK && spDisp!= 0 )
    {
    MSHTML::IHTMLDocument2Ptr spHtmlDocument(spDisp);
    MSHTML::IHTMLElementPtr spHtmlElement;
    if(spHtmlDocument==NULL)
    continue;
    spHtmlDocument->get_body(&spHtmlElement);
    if(spHtmlDocument==NULL)
    continue;
    HRESULT hr;
    MSHTML::IHTMLElementCollection* pColl=NULL;
    hr=spHtmlDocument->get_all(&pColl);
    if(pColl!=NULL&&SUCCEEDED(hr))
    {
    MSHTML::IHTMLElement* pElem=NULL;
    _variant_t index;
    index.vt=VT_I4;
    index.intVal=0;
    _variant_t name("Submit");
    IDispatchPtr disp;
    disp=pColl->item(name,index);
    if(disp==NULL)
    hr=E_FAIL;
    else
    {
    hr=disp->QueryInterface(&pElem);
    }
    if (SUCCEEDED(hr)&& pElem != NULL)
    {
    //
    BSTR bstrhtml;
    pElem->get_outerHTML(&bstrhtml);
    CString str(bstrhtml);
    AfxMessageBox(str);
    pElem->click();
    pElem->Release();
    }
    pColl->Release();
    }
    } }
    } }
    else {
    AfxMessageBox("Shell Windows interface is not avilable");
    }
    CoUninitialize();
    }