Re: Detailed info for COM based "Web Browser" control in VS.NET 2003

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Grant_Aust (news-i-dont-like-spam_at_carthew.net)
Date: 03/17/05


Date: Thu, 17 Mar 2005 13:11:57 +1000

Hi Ahmed,
I have been looking into this for the last few days. It's ot so easy to
work with an embedded browser due to the lack of informaiont.

You need to add a reference to MSHTML.dll to your project.

See here for info about mshtml.dll;
http://msdn.microsoft.com/workshop/browser/mshtml/overview/overview.asp

The diagram here helps for understanding;
http://msdn.microsoft.com/workshop/browser/overview/overview.asp

Do a search on google for webbrowser and mshtml and the like and you will
find some info.

I am still working through this stuff now.

Here are some code scraps I have found;

' 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.
    '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,
Stream );
    ' pStream->Release();
    ' }
    ' GlobalFree( hHTMLText );
    ' }
    ' }
    ' pUnkDisp->Release();
    ' }
    ' pUnkBrowser->Release();
    ' }
    '}

    ' An application would show the progress bar in response to
DownloadBegin,
    'update the progress bar in response to ProgressChange, and hide the
progress bar
    'in response to DownloadComplete.

    'Dim hDoc As New mshtml.HTMLDocument
    'Do
    ' hDoc = WebBrowser1.Document()
    'Loop While hDoc Is Nothing
    'hDoc.getElementsByTagName("a").item(2).Click()
 



Relevant Pages

  • RE: HTTPS WebRequest and WebResponse
    ... > // Creates an HttpWebRequest for the specified URL. ... > // Displays all the headers present in the response received from the URI. ... > // Obtain a 'Stream' object associated with the response object. ... > StreamReader readStream = new StreamReader(ReceiveStream, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Read everything from socket
    ... There is no standard way to indicate a stream is finished ... line from the RETR command ... Or from the LIST command ... the actual byte length is given of the response steam. ...
    (perl.beginners)
  • HTTPS WebRequest and WebResponse
    ... // Creates an HttpWebRequest for the specified URL. ... // Displays all the headers present in the response received from the URI. ... // Obtain a 'Stream' object associated with the response object. ... StreamReader readStream = new StreamReader(ReceiveStream, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: HttpWebRequest.GetRequestStream times out
    ... Stream sendStream = httpReq.GetRequestStream; ... Stream respstrm = resp.GetResponseStream; ... bytesRead = respstrm.Read; ... Save for the somewhat scary exception handling and the fact that you never read more than 1 kB of the response, ...
    (microsoft.public.dotnet.framework.performance)
  • Re: HttpWebRequest.GetRequestStream times out
    ... When I encounter this exception, this is printed in the log: ... Stream sendStream = httpReq.GetRequestStream; ... you never read more than 1 kB of the response, ... The request timeout is set to 100 seconds, and the requests that time out ...
    (microsoft.public.dotnet.framework.performance)