如果有这方面的代码就更好了,谢谢!

解决方案 »

  1.   

    有没有在C++环境就能用的方法,我不想用MFC的控件,因为这样要嵌入好多MFC的类库!
      

  2.   

    这个可以实现,不过我只有BCB6的例子,不会VC .
      

  3.   

    能Send给我一份吗?[email protected] ,3X!
      

  4.   

    This sample demostrates how to create an Internet Explorer window and control it.class CAutomationDlg : public CDialog
    {
    .....
    CComQIPtr<IWebBrowser2> m_pWebBrowser2;
    DWORD m_dwCookie;
    BOOL m_bOwnIE;
    afx_msg void DocumentComplete(IDispatch *pDisp,VARIANT *URL);
    afx_msg void OnQuit();
    void AdviseSinkIE();
    void UnadvisesinkIE();
    void NavigateToSamplePage(BOOL bIE);
    CString m_strFileToFind;
    DECLARE_DISPATCH_MAP();
    .....
    }
    BEGIN_DISPATCH_MAP(CAutomationDlg, CDialog)
    DISP_FUNCTION_ID(CAutomationDlg, "OnQuit",DISPID_ONQUIT,OnQuit,VT_EMPTY, VTS_NONE)
    DISP_FUNCTION_ID(CAutomationDlg, "DocumentComplete",DISPID_DOCUMENTCOMPLETE,DocumentComplete,
     VT_EMPTY, VTS_DISPATCH VTS_PVARIANT)
    .....
    END_DISPATCH_MAP()
    void CAutomationDlg::OnQuit()
    {
    //detach to avoid AV caused by invalid reference.
    if(m_pWebBrowser2)
    {
    UnadvisesinkIE();
    m_pWebBrowser2=(LPUNKNOWN)NULL;
    }
    }
    void CAutomationDlg::AdviseSinkIE()
    {
    if(m_pWebBrowser2)
    {
    LPUNKNOWN pUnkSink = GetIDispatch(FALSE);
    AfxConnectionAdvise((LPUNKNOWN)m_pWebBrowser2, 
    DIID_DWebBrowserEvents2,pUnkSink,FALSE,&m_dwCookie); 
    }
    }
    void CAutomationDlg::UnadvisesinkIE()
    {
    if(m_dwCookie != 0&&m_pWebBrowser2!=NULL)
    {
    LPUNKNOWN pUnkSink = GetIDispatch(FALSE);
    AfxConnectionUnadvise((LPUNKNOWN)m_pWebBrowser2, DIID_DWebBrowserEvents2, pUnkSink, FALSE, m_dwCookie);
    m_dwCookie = 0;
    }
    }
    void CAutomationDlg::CreateNewShellWindow(BOOL bIE)
    {
    if(!UpdateData())return;
    //Detach the previous instance
    if(m_pWebBrowser2)
    {
    if(m_bOwnIE)
    {
    m_pWebBrowser2->Quit();
    m_bOwnIE=FALSE;
    }
    UnadvisesinkIE();
    m_pWebBrowser2=(LPUNKNOWN)NULL;
    }
    if(bIE)
    {
    // create a new IE instance and show it 
    m_pWebBrowser2.CoCreateInstance(CLSID_InternetExplorer);
    m_bOwnIE=TRUE;
    HRESULT hr;
    hr = m_pWebBrowser2->put_StatusBar(VARIANT_TRUE);
    hr = m_pWebBrowser2->put_ToolBar(VARIANT_TRUE);
    hr = m_pWebBrowser2->put_MenuBar(VARIANT_TRUE);
    hr = m_pWebBrowser2->put_Visible(VARIANT_TRUE);
    //sink for the Quit and DocumentComplete events
    AdviseSinkIE();
    NavigateToSamplePage(bIE);
    }
    ......
    void CAutomationDlg::NavigateToSamplePage(BOOL bIE)
    {
    if(bIE)
    {
    if(!::PathIsURL(m_strFileToFind))
    m_strFileToFind=_T("http://blog.joycode.com/jiangsheng");
    COleVariant vaURL((LPCTSTR)m_strFileToFind);
    m_pWebBrowser2->Navigate2(
    &vaURL,COleVariant((long) 0, VT_I4),
    COleVariant((LPCTSTR)NULL, VT_BSTR),
    COleSafeArray(),
    COleVariant((LPCTSTR)NULL, VT_BSTR)
    );
    }
    .....
    void CAutomationDlg::DocumentComplete(IDispatch *pDisp,VARIANT *URL)
    {
    //HTML DOM is available AFTER DocumentComplete is fired.
    //For more information, please visit KB article 
    //"How To Determine When a Page Is Done Loading in WebBrowser Control"
    //http://support.microsoft.com/kb/q180366/

    CComQIPtr<IUnknown,&IID_IUnknown> pWBUK(m_pWebBrowser2);
    CComQIPtr<IUnknown,&IID_IUnknown> pSenderUK(pDisp);
    USES_CONVERSION;
    TRACE(_T("Page downloading complete:\r\n"));
    CComBSTR bstrName;
    m_pWebBrowser2->get_LocationName(&bstrName);
    CComBSTR bstrURL;
    m_pWebBrowser2->get_LocationURL(&bstrURL);
    TRACE(_T("Name:[ %s ]\r\nURL: [ %s ]\r\n"),
    OLE2T(bstrName),
    OLE2T(bstrURL));
    if (pWBUK== pSenderUK)
    {
    CComQIPtr<IDispatch> pHTMLDocDisp;
    m_pWebBrowser2->get_Document(&pHTMLDocDisp);
    CComQIPtr<IHTMLDocument2> pHTMLDoc(pHTMLDocDisp);
    if(pHTMLDoc)
    {
    CComBSTR bstrNewTitle(_T("Sheng Jiang's Automation Test"));
    pHTMLDoc->put_title(bstrNewTitle);
    CComQIPtr<IHTMLElementCollection> ecAll;
    pHTMLDoc->get_all(&ecAll);
    if(ecAll)
    {
    CComPtr<IDispatch> pTagLineDisp;
    ecAll->item(COleVariant(_T("tagline")),COleVariant((long)0),&pTagLineDisp);
    CComQIPtr<IHTMLElement> eTagLine(pTagLineDisp);
    if(eTagLine)
    {
    eTagLine->put_innerText(CComBSTR(_T("Command what is yours, conquer what is not. --Kane")));
    }
    }
    }
    }
    To handle button click in your application, check the MSDN article
     "Handling HTML Element Events (Internet Explorer - Hosting MSHTML"
    (http://msdn.microsoft.com/workshop/browser/mshtml/tutorials/sink.asp)
      

  5.   

    做成ActiveX控件,实现IDispatch,然后在网页脚本里面创建,js是用类似这样的语法:
    oCtrl = new ActiveXObject("CppLib.IeCtrl");然后oCtrl.XXX这样来使用