用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
该程序经编译后即是一简单普通浏览器,可方便地集成到其他软件中去。