|
|
用VB开发IE |
|
|
作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站 |
用VB开发IE
随着网络用户的增加和Internet的普及与发展,浏览器已成为最受网络用户欢迎的软件之一。广大软件研制者特别是MIS开发者都希望把浏览器集成到自己的软件中来,使自己的软件能浏览WEB页面而功能更强大、更具特色。目前市场上流行的浏览器软件种类及版本很多。但要把它方便地集成到自己的软件中去,却受到以下几个方面的限制:浏览器带有各自的运行环境和配置文件;浏览器很大,集成到自己的软件中后运行效率低;开发者更想让浏览器具有自己的特色。
因此,软件研制者都想开发自己的浏览器,而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
该程序经编译后即是一简单普通浏览器,可方便地集成到其他软件中去。 
|
|
相关文章:相关软件: |
|