I have seen a lot of requests for a tab oriented Web Browser in VB6, but so far I have not found one that meets my requirements. It did not seem like a major problem, so I decided to embark on a solution. Although .NET offers the ability to work with Internet Explorer to expose the Tab capabilities, VB6 does not offer the same because of it's lack of "inheritance". But what VB6 does offer is flexibility. Short of "Thread Management", there is virtually nothing that cannot be done in VB6 because of it's ability to interface with any COM object. The Multiple Document Interface (MDI) offers the ability to manage several child windows under the control of and within a single parent window.
If you have an up-to-date version of VB6, you already have a Web Browser template. Open up a new project and delete the default Form1. Add an MDI form and add a WebBrowser form. The WebBrowser form should already be configured as an MDIChild. Change the StartUp Object to the MDI form and change the Border Style of frmBrowser to None. Change the Scrollbars property on the MDI form to False. Add a module to the project. You will need this later, but for now we simply need 3 global dimensions;
It would be appropriate to add a TabStrip or SSTab control to the MDI form, but neither of these controls has an Align property and cannot be used in an MDI form. Instead, add a StatusBar, align it to the top of the form, and adjust it's height.
Add a menu to the MDI form, and add one menu item (mnuChild) "Add Child Window". To the click event, add the following code:
Add a command button called cmdExit with a single bold "X" caption to the left of the cboAddress combo box on the frmBrowser form, and delete or comment out the following code:
Assuming that you are using Internet Explorer 6 or better, transfer the code in the brwWebBrowser_NavigateComplete routine (that ended up in the General sub routines), to the brwWebBrowser_NavigateComplete2 routine.
At this point, you are ready to test your new project. The program should load the default home page configured in Internet Explorer as a child window. You can add windows using the Add Child Window menu item, but it needs a little more code to use the tabs properly.
The StatusBar does not indicate the selected item and the above code provides that funtion by raising the selected item.
Now we need to provide for a new window created from a link on the web page. Add the following code to the frmBrowser form:
These 2 routines load the link into a new tab and block popup windows.
This provides the basic format, but a lot of work still remains to make it truly functional. You can add the following code to the cmdExit click routine:
This will exit the TAB that it is located on, but you must remember to adjust the form array to reflect that it no longer exists.
J.A. Coutts
If you have an up-to-date version of VB6, you already have a Web Browser template. Open up a new project and delete the default Form1. Add an MDI form and add a WebBrowser form. The WebBrowser form should already be configured as an MDIChild. Change the StartUp Object to the MDI form and change the Border Style of frmBrowser to None. Change the Scrollbars property on the MDI form to False. Add a module to the project. You will need this later, but for now we simply need 3 global dimensions;
Code:
Global frm() As Object 'frmBrowser Array
Global nTab As Long 'Number of tabs
Global cTab As Long 'Current tab (0 based)
Add a menu to the MDI form, and add one menu item (mnuChild) "Add Child Window". To the click event, add the following code:
Code:
Private Sub mnuChild_Click()
Call CreateForm(nTab)
nTab = nTab + 1
cTab = cTab + 1
End Sub
'Add the same code to the Load method of the MDI form:
Private Sub MDIForm_Load()
Call CreateForm(nTab)
nTab = nTab + 1
End Sub
'as well as the following sub routine:
Sub CreateForm(nFrm As Long)
ReDim Preserve frm(nFrm)
Set frm(nFrm) = New frmBrowser
If nFrm = 0 Then
frm(nFrm).cmdExit.Visible = False
frm(nFrm).brwWebBrowser.GoHome
Else
StatusBar1.Panels.Add nFrm + 1, , "About:blank"
Debug.Print "Panel " & StatusBar1.Panels.Item(nFrm + 1).Index
StatusBar1.Panels(nFrm + 1).ToolTipText = "Browser TAB" & Str$(nFrm)
StatusBar1.Panels(nFrm + 1).Bevel = 2
End If
frm(nFrm).Show
End Sub
Code:
Private Sub Form_Load()
' On Error Resume Next
' Me.Show
' tbToolBar.Refresh
' Form_Resize
' cboAddress.Move 50, lblAddress.Top + lblAddress.Height + 15
' If Len(StartingAddress) > 0 Then
' cboAddress.Text = StartingAddress
' cboAddress.AddItem cboAddress.Text
' 'try to navigate to the starting address
' timTimer.Enabled = True
' brwWebBrowser.Navigate StartingAddress
' End If
End Sub
'Change the DownLoadComplete routine to update the StatusBar Tab instead of the form caption:
Private Sub brwWebBrowser_DownloadComplete()
On Error Resume Next
MDIForm1.StatusBar1.Panels(cTab + 1).Text = brwWebBrowser.LocationName
End Sub
At this point, you are ready to test your new project. The program should load the default home page configured in Internet Explorer as a child window. You can add windows using the Add Child Window menu item, but it needs a little more code to use the tabs properly.
Code:
To the StatusBar1 Panel Click routine, add the following code:
Private Sub StatusBar1_PanelClick(ByVal Panel As MSComctlLib.Panel)
Call ResetPanels
cTab = Panel.Index - 1
Panel.Bevel = 2
frm(cTab).SetFocus
Debug.Print "TAB " & cTab
End Sub
'as well as the ResetPanels sub routine:
Sub ResetPanels()
Dim cPanel As Panel
For Each cPanel In StatusBar1.Panels
cPanel.Bevel = 1
Next cPanel
End Sub
Now we need to provide for a new window created from a link on the web page. Add the following code to the frmBrowser form:
Code:
Private Sub brwWebBrowser_NewWindow2(ppDisp As Object, Cancel As Boolean)
Cancel = IsPopupWindow
If Cancel = False Then
ReDim Preserve frm(nTab)
Set frm(nTab) = New frmBrowser
MDIForm1.StatusBar1.Panels.Add nTab + 1, , "About:blank"
Debug.Print "Panel " & MDIForm1.StatusBar1.Panels.Item(nTab + 1).Index
MDIForm1.StatusBar1.Panels(nTab + 1).Bevel = 2
MDIForm1.StatusBar1.Panels(nTab + 1).ToolTipText = "Browser TAB" & Str$(nTab)
Set ppDisp = frm(nTab).brwWebBrowser.object
frm(nTab).Show
cTab = nTab
nTab = nTab + 1
End If
Debug.Print "Opened in new window!"
End Sub
'and the accompanying sub routine:
Private Function IsPopupWindow() As Boolean
On Error Resume Next
If brwWebBrowser.Document.activeElement.tagName = "BODY" Or _
brwWebBrowser.Document.activeElement.tagName = "IFRAME" Then
IsPopupWindow = True
Else
IsPopupWindow = False
End If
End Function
This provides the basic format, but a lot of work still remains to make it truly functional. You can add the following code to the cmdExit click routine:
Code:
Private Sub cmdExit_Click()
Unload Me
End Sub
J.A. Coutts