因此,軟件研制者都想開發自己的瀏覽器,而Visual Basic 5.0就提供了這種功能。筆者曾經用Visual Basic 5.0開發出簡單的瀏覽器,編譯出可執行文件后很。ㄖ挥33K),并成功地把它集成到其它軟件中。下面給出制作步驟和程序清單,稍加修改就可做出自己喜歡的瀏覽器。
1.打開一應用,打開一個Form(brower);
2.在Brower里加入Toolbar控件toolbar1,增加常用的命令按鈕(如back、next、stop、refresh、home、Search、open、exit等),同時加入Imagelist控件imagelist1,并加入自己喜歡的圖形,然后和toolbar1中的命令按鈕對應起來。
3.加入定時器Timer控件timer1,并設置好;
4.加入Label控件label1,Caption設為“Web地址”,加入Combobox控件combo1,加入Statusbar控件statusbar1.加入Webbrowser控件browser1;
5.然后寫入以下程序代碼:
PublicStartingAddressAsString
DimflagAsBoolean
PrivateSubForm—Load()
OnErrorResumeNext
Me.Show
ToolBar1.Refresh
Open″d:\vb5\brow.ini″ForInputAs#2
′打開上次的WEBIP地址
Input#2,StartingAddress
Close#2
IfLen(StartingAddress)>0Then
combo1.Text=StartingAddress
combo1.AddItemStartingAddress
webbrowser1.NavigateStartingAddress
EndIf
EndSub
PrivateSubwebbrowser1—DownloadComplete()
OnErrorResumeNext
Me.Caption=webbrowser1.LocationName
EndSub
PrivateSubwebbrowser1—NavigateComplete(ByValURLAsString)
DimiAsInteger
DimbFoundAsBoolean
Me.Caption=webbrowser1.LocationName
Fori=0Tocombo1.ListCount-1
Ifcombo1.List(i)=webbrowser1.LocationURL
Then
bFound=True
ExitFor
EndIf
Nexti
flag=True
IfbFoundThen
combo1.RemoveItemi
EndIf
combo1.AddItemwebbrowser1.LocationURL,0
combo1.ListIndex=0
MousePointer=0
webbrowser1.Navigatecombo1.Text
StatusBar1.Panels(1).Text=″當前頁面″+combo1.Text
flag=False
EndSub
PrivateSubcombo1—Click()
IfflagThenExitSub
Timer1.Enabled=True
MousePointer=11
StatusBar1.Panels(1).Text=″正在連接″+combo1.Text+″......″
webbrowser1.Navigatecombo1.Text
EndSub
PrivateSubcombo1—KeyPress(KeyAsciiAsInteger)
OnErrorResumeNext
IfKeyAscii=vbKeyReturnThen
combo1—Click
End If
End Sub
PrivateSubTimer1-Timer()
Ifwebbrowser1.Busy=FalseThen
Timer1.Enabled=False
Me.Caption=webbrowser1.LocationName
Else
Me.Caption=″Working...″
EndIf
EndSub
PrivateSubToolBar1-ButtonClick(ByValButtonAsButton)
OnErrorResumeNext
Timer1.Enabled=True
SelectCaseButton.Key
Case″exit″
UnloadMe
Case″Back″
webbrowser1.GoBack
Case″Forward″
webbrowser1.GoForward
Case″Refresh″
webbrowser1.Refresh
Case″Home″
webbrowser1.GoHome
Case″Search″
webbrowser1.GoSearch
Case″open″
CommonDialog1.ShowOpen
combo1.Text=CommonDialog1.filename
Case″Stop″
Timer1.Enabled=False
MousePointer=0
webbrowser1.Stop
Me.Caption=webbrowser1.LocationName
EndSelect
EndSub
該程序經編譯后即是一簡單普通瀏覽器,可方便地集成到其他軟件中去。
延伸閱讀
文章來源于領測軟件測試網 http://www.kjueaiud.com/