好吧,做了一个基本框架,你自己去完善吧。
1、窗体,一个 webbrows(0) ,一个Text1,一个Command1,一个list1
程序代码:
Option Explicit
Private Sub Command1_Click()
web(webindex).URL = Text1.Text
WebBrowser1(webindex).Navigate web(webindex).URL
web(webindex).Title = ""
End Sub
Private Sub Form_Load()
ReDim web(0)
web(0).index = 0
web(0).URL = "About:Black"
End Sub
Private Sub List1_Click()
webindex = List1.ListIndex
Text1.Text = web(webindex).URL
Call viewweb
End Sub
Private Sub WebBrowser1_BeforeNavigate2(index As Integer, ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
Dim i As Long
For i = 0 To UBound(web)
If web(i).index = index Then
Exit For
End If
Next i
web(i).URL = URL
List1.List(i) = URL
End Sub
Private Sub WebBrowser1_DocumentComplete(index As Integer, ByVal pDisp As Object, URL As Variant)
Dim i As Long
For i = 0 To UBound(web)
If web(i).index = index Then
Exit For
End If
Next i
web(i).Title = WebBrowser1(index).Document.Title
List1.List(i) = web(i).Title
End Sub
Private Sub WebBrowser1_NewWindow2(index As Integer, ppDisp As Object, Cancel As Boolean)
'Stop
Call Addweb
Set ppDisp = WebBrowser1(web(webindex).index).Object
End Sub
Public Sub viewlist()
List1.Clear
Dim i As Long
For i = 0 To UBound(web)
If web(i).index <> -1 Then
If web(i).Title <> "" Then
List1.AddItem web(i).Title
Else
List1.AddItem web(i).URL
End If
End If
Next i
End Sub
Public Sub viewweb()
Dim obj As WebBrowser
For Each obj In WebBrowser1
If obj.index = webindex Then
obj.Visible = True
Else
obj.Visible = False
End If
Next
End Sub
2、模块
程序代码:
Option Explicit
Public Type 结构类型
index As Long '对应 webbrows 的index
URL As String '对应 webbrows 的网址
Title As String '网页标题
End Type
Public web() As 结构类型 '保存整个webbrows数据
Public webindex As Long
Public webnext As Long
Public Sub DELweb(id As Long)
Dim obj As WebBrowser
Dim i As Long
Form1.List1.RemoveItem web(id).index '删列表
For Each obj In Form1.WebBrowser1 '删对象
If obj.index = web(id).index Then
Unload obj
Exit For
End If
Next
For i = id To UBound(web()) - 1 '删数据结构
web(i).index = web(i + 1).index
web(i).Title = web(i + 1).Title
web(i).URL = web(i).URL
Next i
web(i).index = -1 '设置不可用
If web(id).index <> -1 Then
webindex = web(id).index '下一个窗口为当前窗口
Else
webindex = 0
End If
Call Form1.viewweb
Call Form1.viewlist
End Sub
Public Sub Addweb()
Dim i As Long, j As Long
Dim webmax As Long
j = -1
For i = 0 To UBound(web)
If webmax < web(i).index Then
webmax = web(i).index
End If
If web(i).index = -1 And j > -1 Then
j = i
End If
Next i
If j = -1 Then
ReDim Preserve web(i)
j = i
End If
webmax = webmax + 1
Load Form1.WebBrowser1(webmax)
web(j).index = webmax
webindex = j
'web(j).url = url
'Form1.WebBrowser1(webmax).Navigate url
Call Form1.viewweb
Call Form1.viewlist
End Sub
-------------
其实,模块里这二个过程,也应该是放在窗体里的,因为模块里操作了窗体上的控件。
已初步实现了你的新页面功能。
关闭页面功能,未实现,只写了一个实现代码,但未经任何测试。