Search Tools Links Login

Dynamically Add WebBrowser Control at runtime without a Reference

Posted: 2002-06-01
By: ArchiveBot
Viewed: 263

Filed Under:

VB6 Code Cache

No attachments for this post


Allows VB applications to determine at run-time if Internet Explorer (4.0 or later) is installed, and if so, creates a WebBrowser. If not, a trappable error allows program to continue.

Original Author: Dave Slinn

Code

Add a menu item named 'mnuCreate' with a caption of "&Create
WebBrowser"


Place the following code into a standard VB 6.0 form.






Private m_WebControl As VBControlExtender



Private Sub Form_Resize()

On Error Resume Next

    ' resize webbrowser to entire size of form

    m_WebControl.Move 0, 0, ScaleWidth, ScaleHeight

End Sub



Private Sub mnuCreate_Click()

On Error GoTo ErrHandler



    ' attempting to add WebBrowser here ('Shell.Explorer.2' is registered

    ' with Windows if a recent (>= 4.0) version of Internet Explorer is installed

    Set m_WebControl = Controls.Add("Shell.Explorer.2", "webctl", Me)



    ' if we got to here, there was no problem creating the WebBrowser

    ' so we should size it properly and ensure it's visible

    m_WebControl.Move 0, 0, ScaleWidth, ScaleHeight

    m_WebControl.Visible = True



    ' use the Navigate method of the WebBrowser control to open a

    ' web page

    m_WebControl.object.navigate "http://www.planet-source-code.com"



    Exit Sub

ErrHandler:

    MsgBox "Could not create WebBrowser control", vbInformation

End Sub




Comments on this post

No comments have been added for this post.

You must be logged in to make a comment.