to jiangsheng(蒋晟):
IE版本是:5.00.3315.1000

解决方案 »

  1.   

    HRESULT LoadWebBrowserFromStream(IWebBrowser* pWebBrowser, IStream* pStream)
    {
    HRESULT hr;
    IDispatch* pHtmlDoc = NULL;
    IPersistStreamInit* pPersistStreamInit = NULL;    // Retrieve the document object.
        hr = pWebBrowser->get_Document( &pHtmlDoc );
        if ( SUCCEEDED(hr) )
        {
            // Query for IPersistStreamInit.
            hr = pHtmlDoc->QueryInterface( IID_IPersistStreamInit,  (void**)&pPersistStreamInit );
            if ( SUCCEEDED(hr) )
            {
                // Initialize the document.
                hr = pPersistStreamInit->InitNew();
                if ( SUCCEEDED(hr) )
                {
                    // Load the contents of the stream.
                    hr = pPersistStreamInit->Load( pStream );
                }
                pPersistStreamInit->Release();
            }
        }
    }
      

  2.   

    to jiangsheng(蒋晟):
    谢谢,Let me try.....
      

  3.   

    to jiangsheng(蒋晟):
    报相同的错,你写的一个函数好像跟我用语句写的没多大区别吧???出错的地方是Get_Document方法的调用,你帮我调调这一小段就好了,谢谢~~~~to lyneville(心佛):
    没有办法了,懂这方面的人不多,只好出此下策了,呵呵~~~~~
      

  4.   

    to jiangsheng(蒋晟):
    我再看了一次,好像你的意思是说我调用的对象以及顺序都错了,right???
      

  5.   

    你的webbrowser里面至少要有一个文档(about:blank也可以)才能开始工作:(
      

  6.   

    to jiangsheng(蒋晟):
    这里好像只提到了如何Load,Load完后怎么通过IHTMLDocument2接口进行处理呢????http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/tutorials/WebOCStream.asp?frame=true
      

  7.   

    to jiangsheng(蒋晟):
    怎么设置我的webbrowser里的文档呢????
      

  8.   

    虽然不知道你究竟要拿HTMLDocument2做什么, 但看的出你的基本思路有问题
      

  9.   

    to mickeyx(alanet.51.net):
    问题出在哪??如何解决??
      

  10.   

    to mickeyx(alanet.51.net):
    问题出在哪??如何解决??
      

  11.   


    回复人: superrg(秀华) (2002-1-21 17:26:56)  得0分 
    to jiangsheng(蒋晟):
    这里好像只提到了如何Load,Load完后怎么通过IHTMLDocument2接口进行处理呢????http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/tutorials/WebOCStream.asp?frame=true
      
    Navigating to about:blank(这个你没看?)
    The IWebBrowser2::Navigate2 method of the IWebBrowser2 interface enables you to navigate the browser to a URL. In the following sample code, the IWebBrowser2::Navigate2 method is used to navigate to the about:blank page. Navigating to this empty page ensures that MSHTML is loaded and that the HTML elements are available through the Dynamic HTML (DHTML) Object Model.This example demonstrates how to navigate the WebBrowser control to an empty page. The variable m_pBrowser contains the IWebBrowser2 interface pointer obtained from the WebBrowser control.m_pBrowser->Navigate2( _T("about:blank"), NULL, NULL, NULL, NULL );
    Availability of the DHTML Object Model
    The DHTML Object Model is used to access and manipulate the contents of an HTML page and is not available until the page is loaded. Your application determines that a page is loaded by handling the DWebBrowserEvents2::DocumentComplete event of the WebBrowser control. This event may be fired once for each frame in the page, and once when the top frame of the document is loaded. You can determine if the DWebBrowserEvents2::DocumentComplete event is for the top frame by comparing the IDispatch interface pointer passed by this event with that of the WebBrowser control.This sample handler code for the WebBrowser DWebBrowserEvents2::DocumentComplete event demonstrates how to determine if this event is for the top frame, which indicates that the HTML page has loaded. This sample also demonstrates how to create a stream from a block of memory—in this case a string that contains the HTML content to be displayed.Hide Examplevoid myObject::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
    {
    HRESULT hr;
    IUnknown* pUnkBrowser = NULL;
    IUnknown* pUnkDisp = NULL;
    IStream* pStream = NULL;
    HGLOBAL hHTMLText;
    static char szHTMLText[] = "<html><h1>Stream Test</h1><p>This HTML content is/
        being loaded from a stream.</html>";    // Is this the DocumentComplete event for the top frame window?
        // Check COM identity: compare IUnknown interface pointers.
        hr = m_pBrowser->QueryInterface( IID_IUnknown,  (void**)&pUnkBrowser );
        if ( SUCCEEDED(hr) )
        {
            hr = pDisp->QueryInterface( IID_IUnknown,  (void**)&pUnkDisp );
            if ( SUCCEEDED(hr) )
            {
                if ( pUnkBrowser == pUnkDisp )
                {   // This is the DocumentComplete event for the top frame - page is loaded!
                    // Create a stream containing the HTML.
                    // Alternatively, this stream may have been passed to us.
                    hHTMLText = GlobalAlloc( GPTR, lstrlen(szHTMLText)+1 );
                    if ( hHTMLText )
                    {
                        lstrcpy( (char*)hHTMLText, szHTMLText );
                        hr = CreateStreamOnHGlobal( hHTMLText, TRUE, &pStream );
                        if ( SUCCEEDED(hr) )
                        {
                           // Call the helper function to load the Web Browser from the stream.
                           LoadWebBrowserFromStream( m_pBrowser, pStream  );
                           pStream->Release();
                        }
                        GlobalFree( hHTMLText );
                    }
                }
                pUnkDisp->Release();
            }
            pUnkBrowser->Release();
        }
    }
    Using QueryInterface to Obtain the IPersistStreamInit Interface
    The IWebBrowser2::get_Document property on the WebBrowser control retrieves the document object that represents the DHTML Object Model for the top frame. MSHTML implements the IPersistStreamInit interface to provide the ability to load and save HTML using a stream, through the document object. The IDispatch interface for the document object can be queried for the IPersistStreamInit interface pointer using QueryInterface with an identifier of IID_IPersistStreamInit, as shown in the following code example.Hide ExampleHRESULT LoadWebBrowserFromStream(IWebBrowser* pWebBrowser, IStream* pStream)
    {
    HRESULT hr;
    IDispatch* pHtmlDoc = NULL;
    IPersistStreamInit* pPersistStreamInit = NULL;    // Retrieve the document object.
        hr = pWebBrowser->get_Document( &pHtmlDoc );
        if ( SUCCEEDED(hr) )
        {
            // Query for IPersistStreamInit.
            hr = pHtmlDoc->QueryInterface( IID_IPersistStreamInit,  (void**)&pPersistStreamInit );
            if ( SUCCEEDED(hr) )
            {
                // Initialize the document.
                hr = pPersistStreamInit->InitNew();
                if ( SUCCEEDED(hr) )
                {
                    // Load the contents of the stream.
                    hr = pPersistStreamInit->Load( pStream );
                }
                pPersistStreamInit->Release();
            }
        }
    }
    Using the IPersistStreamInit Interface to Load HTML Content
    The IPersistStreamInit interface has InitNew and Load methods that are used to initialize and load an HTML document from a stream. The InitNew method initializes the stream to a known state and the Load method loads the HTML content from the stream.In the previous sample code, the HTML document is initialized and the HTML content is loaded from the stream.Note  In Microsoft Internet Explorer 5, more than one call to the Load method of the IPersist interfaces is supported. In earlier versions, only one call to Load per instance of MSHTML is supported.
    Offline Reading
    The following articles provide information about the Component Object Model (COM).Inside OLE, 2nd Edition, by Kraig Brockschmidt (Microsoft Press) 
    Understanding ActiveX and OLE, by David Chappell (Microsoft Press) 
    Inside COM, by Dale Rogerson (Microsoft Press) 
      

  12.   

    to jiangsheng(蒋晟):
    现在看完了,照着做,结果运行时还是报错:
    内存0X00000000不能为read~~~~~~~
      

  13.   

    你要干什么?如果只是要修改/重写网页内容的话可以不用IStream,直接用IHTMLDocument2的write方法就可以了
      

  14.   

    to sxbyl(白菜):
    如果直接用IHTMLDocument2的write方法,IHTMLDocument2的URL属性就会丢掉了,再解释脚本以及取Links都会出现问题~~~~~~
      

  15.   

    hr = pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pDoc);
    printf("hr = %d\n",hr);
    //这里报错了
      

  16.   

    事件DocumentComplete发生了没有?
      

  17.   

    to jiangsheng(蒋晟):
    我想既然是LoadStream的,应该不用等吧??否则应该如何等待事件的发生呢???
      

  18.   

    to jiangsheng(蒋晟):
    怎么等???
      

  19.   

    在DocumentComplete事件处理里面LoadWebBrowserFromStream
    void myObject::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
    {
    HRESULT hr;
    IUnknown* pUnkBrowser = NULL;
    IUnknown* pUnkDisp = NULL;
    IStream* pStream = NULL;
    HGLOBAL hHTMLText;
    static char szHTMLText[] = "<html><h1>Stream Test</h1><p>This HTML content is/
        being loaded from a stream.</html>";    // Is this the DocumentComplete event for the top frame window?
        // Check COM identity: compare IUnknown interface pointers.
        hr = m_pBrowser->QueryInterface( IID_IUnknown,  (void**)&pUnkBrowser );
        if ( SUCCEEDED(hr) )
        {
            hr = pDisp->QueryInterface( IID_IUnknown,  (void**)&pUnkDisp );
            if ( SUCCEEDED(hr) )
            {
                if ( pUnkBrowser == pUnkDisp )
                {  // This is the DocumentComplete event for the top frame - page is loaded!
                    // Create a stream containing the HTML.
                    // Alternatively, this stream may have been passed to us.
                    hHTMLText = GlobalAlloc( GPTR, lstrlen(szHTMLText)+1 );
                    if ( hHTMLText )
                    {
                        lstrcpy( (char*)hHTMLText, szHTMLText );
                        hr = CreateStreamOnHGlobal( hHTMLText, TRUE, &pStream );
                        if ( SUCCEEDED(hr) )
                        {
                          // Call the helper function to load the Web Browser from the stream.
                          LoadWebBrowserFromStream( m_pBrowser, pStream  );
                          pStream->Release();
                        }
                        GlobalFree( hHTMLText );
                    }
                }
                pUnkDisp->Release();
            }
            pUnkBrowser->Release();
        }
    }
      

  20.   

    没有界面的怎么捕获HTML事件?
      

  21.   

    to jiangsheng(蒋晟):
    必须要界面吗????
    好像walkall也是没有界面的呀~~~~~~~~~
      

  22.   

    to jiangsheng(蒋晟):
    应该是有事件的,不过怎么调用具体我就不清楚了~~~~~~~
      

  23.   

    不行等两秒钟算了,载入about:blank用两秒钟吗?
      

  24.   

    to jiangsheng(蒋晟):
    应该不用两秒,但我见过一个例子,很奇怪的,必须要弹出一个MessageBox才能载入成功,否则就什么也不干的~~~~~~~~我也试过在那个例子中::Sleep(20000),但还是载入失败的,所以我想,等两秒钟还是不能解决问题的~~~~~~~~
      

  25.   

    to jiangsheng(蒋晟):
    如果我要开一千几百个线程,用有界面的应该怎么做呢????
      

  26.   

    to mickeyx(alanet.51.net):
    我的基本思路如何不正确呀???你的邮箱是什么来的???
      

  27.   

    WalkAll是个好东西,我这么改就可以了
    HRESULT CApp::LoadURLFromMoniker()
    {
    //load m_szURL
    //use m_pMSHTML
        IPersistStreamInit *pPersist = NULL;
        m_pMSHTML->QueryInterface(IID_IPersistStreamInit, 
                           (LPVOID *) &pPersist);
        if (pPersist)
        {
    pPersist->InitNew();
    IStream* pStream;
    HRESULT hr = NOERROR;
    char szWebSite[] = "http://www.163.net";
    (URLOpenBlockingStream( 0, szWebSite, &pStream, 0, 0));
    pPersist->Load(pStream);
    pPersist->Release();
    }
    return S_OK;
    }
      

  28.   

    to masterz():
    也就是说一定要新建一个类,用事件来触发分析IHTMLDocument2的各个元素罗??是不是呀??怎么联系你???
      

  29.   

    可以在使用LOADPERSIST 接口的时候,设置一个回调函数,函数中POST一个消息,主线程中等直到LOAD完毕的消息,我试过,要代码留下地址.恐怕明天了
      

  30.   

    to horizon_tj(地平线):
    当然要代码,越快越好,谢谢,我的地址是:
    [email protected]
      

  31.   

    对的,一定要实现有关的接口(接口需要有类实现)才能使用event sink联系到html document的事件。
      

  32.   

    to all:
    由于时间关系,本人不打算再等了,现在准备结贴,至于问题解决不了只能走另一种方案了。为感谢大家对本人的帮助,现请下列高手移步到下贴处再拿三百分,贴的地址为:
    http://211.157.102.21/expert/topic/488/488742.shtm
    高手名单列表如下:
    masterz()
    jiangsheng(蒋晟);
    另外,如果horizon_tj(地平线)有调试用的源代码请速寄我一份,我的邮箱为
    [email protected],收到源码后我再给你送分,谢谢;
    而mickeyx(alanet.51.net),我进过你的网站看你的产品,的确很有名家风范,可惜一直未能谋面,本人随时恭候您指点一二,很希望有机会跟你合作,做一个成功的产品,要专家分要人民币都不成问题,谢谢~~~~~
      

  33.   

    我也想要代码,给我一份吧;)
    [email protected]
      

  34.   

    [email protected]
    能给代码我学习吗?谢谢
      

  35.   

    虽然晚了点,但是我想讲两句。
    这个问题,其实可以用捕获异步事件而不是同步的流(IStream)来解决。
    采用异步事件,将事件的响应和处理的类连接到IWebbrowser控件上,然后捕捉documentcomplete事件,在该事件中就可以得到IhtmlDocument接口。
      

  36.   

    superrg:
    看http://www.csdn.net/Expert/topic/492/492702.shtm
      

  37.   

    http://www.csdn.net/expert/topic/489/489821.shtm