load HTML using IE stream

Just starting out? Need help? Post your questions and find answers here.
Jose
User
User
Posts: 34
Joined: Sat Apr 26, 2003 9:20 pm

load HTML using IE stream

Post by Jose »

Hi All,

Found this at microsoft;
The IPersistStreamInit interface, and its associated methods, can be used to load HTML content from a stream using the WebBrowser control...

Exactly what I would like to do :)

They provide this code, which i am struggling to convert to PB.

Code: Select all

void myObject::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
    HRESULT hr;
    IUnknown* pUnkBrowser = NULL;
    IUnknown* pUnkDisp = NULL;
    IStream* pStream = NULL;
    HGLOBAL hHTMLText;
    static TCHAR 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.
			
                size_t = cchLength;
                //  TODO: Safely determine the length of szHTMLText in TCHAR.
                hHTMLText = GlobalAlloc( GPTR, cchLength+1 );
				
                if ( hHTMLText )
                {
                    size_t cchMax = 256;
                    StringCchCopy((TCHAR*)hHTMLText, cchMax + 1, szHTMLText);
                    //  TODO: Add error handling code here.

                    hr = CreateStreamOnHGlobal( hHTMLText, TRUE, &pStream );
                    if ( SUCCEEDED(hr) )
                    {
                       // Call the helper function to load the browser from the stream.
                       LoadWebBrowserFromStream( m_pBrowser, pStream  );
                       pStream->Release();
                    }
                    GlobalFree( hHTMLText );
                }
            }
            pUnkDisp->Release();
        }
        pUnkBrowser->Release();
    }
}

; and this next bit too

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();
        }
    }
}
The http://msdn.microsoft.com/library/defau ... stream.asp article at microsoft.

I would want to use a WebGadget then load the HTML into it using this IPersistStreamInit interface.

Can anybody help get this working in PB?

Thanks
Hiller
User
User
Posts: 15
Joined: Mon Mar 29, 2004 12:32 am
Location: Ukraine
Contact:

Post by Hiller »

Can I wrong but WebBrowser in description of msdn the same that and in Pure Basic WebGadget (ATL Browser in msdn) :?

http://msdn.microsoft.com/library/en-us ... ntrols.asp
Jose
User
User
Posts: 34
Joined: Sat Apr 26, 2003 9:20 pm

Post by Jose »

@Hiller
Not sure what you mean!, had a look at the link, and this is what PB does for the WebGadget or I guess something like that.

There are many examples here on how to populate the webgadget, and even more examples here on how to use javascript to populate the webgadget with html, but this code above uses the IPersistStreamInit interface to write html into a web browser control (webdaget) directly.

If only I could figure out how to call these COM methods and pass the parameters as shown above.

Help please!
Hiller
User
User
Posts: 15
Joined: Mon Mar 29, 2004 12:32 am
Location: Ukraine
Contact:

Post by Hiller »

I think WebBrowse<>WebGadget.
Webgadget class in ATL.dll
WebBrowse class in msHtml.dll

See in msdn -> download -> example Atl Browser (C ++)

Maybe I'm wrong. :?
Jose
User
User
Posts: 34
Joined: Sat Apr 26, 2003 9:20 pm

Post by Jose »

Thanks Hiller
Post Reply