一、 简介 众所周知,Visual Basic 5.0(VB5.0)提供了为实现高级Windows程序所需的完备工具与机制,它的强大功能已被广大软件开发人员所共识;Explorer在当今Internet的迅猛发展中,又起着功不可灭的作用,它处理HTML的身手使每一使用者叹服,如果将VB5.0和Explorer联姻,这不仅仅是锦上添花,而是如虎添翼。从理论上讲,VB5.0为Internet提供了各方面的专门技术,而Explorer又可使用VBScript为其扩展功能,但在具体实施中,编程人员会遇到这样或那样的问题,现在我们给出一个经过调试业已成功的实例,仿照此方法,用户可在自己VB5.0程序的任何地方调用Explore,为使用“帮助文件”或“超级连接”提供方便。 二、 实现方法 首先在VB5.0菜单上选“工程/部件”,然后选Microsoft Internet controls和Microsoft common Dialog Control 5.0两个控件,使工具栏上增加WebBrowser和Commodialog两个图标,然后在Form1窗体上,如图一所示,引入两个Label,一个Text,三个Command,一个CommoDialog,三个Command的Caption分别为“浏览”、“打开HTM”和“取消”,为书写方便将Commodialog的名字定为cd。 在程序中,生成一个InternetExplorer类型的目标ii,通过方法ii.Navigate text1,navNoreadfromcache的调用,使得HTML文件名由text1.text给出,亦即通过Text1给出URL,这样一来,用户不但可通过VB5.0程序自由地开启Explorer窗口,而且URL和窗口的外观也由VB5.0来决定,为了更加清晰,把Explorer的View/options/general中的Standard Buttons,Address Bar,Links,Text Labels选择去掉。 其中,URL可直接输入,也可通过浏览来选择。 三、 程序 Dim ii Private Sub Command1_Click() Cd.Flags = &H200 Cd.Filter = "HTML files (*.htm)|*.htm|Text Files" & _ "(*.txt)|*.txt|All Files (*.*)|*.*" Cd.ShowOpen Text1 = Cd.filename Command2.Visible = True End Sub Private Sub Command2_Click() Set ii = GetObject("", "INTERNETEXPLORER.APPLICATION") ii.Navigate Text1, navNoReadFromCache ii.Visible = 1 ii.Top = 0 ii.Left = 0 ii.Width = Form1.Width ii.Height = Screen.Height End Sub Private Sub Command3_Click() Text1 = "" Unload Me End Sub
Private Sub Form_Load() Form1.Top = Screen.Height / 4 Form1.Left = 0 Form1.Width = Screen.Width Form1.Height = Screen.Height / 2 Form1.BackColor = QBColor(2) Label1.BackStyle = 0 Label1.FontName = "黑体" Label1.FontSize = 14 Label1.ForeColor = QBColor(7) Label2.BackStyle = 0 Label2.Caption = "H T M L" Label2.FontName = "brush script" Label2.FontSize = 24 Command2.Visible = False End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Set ii = GetObject("", "INTERNETEXPLORER.APPLICATION") ii.Navigate Text1, navNoReadFromCache ii.Visible = 1 ii.Top = 0 ii.Left = 0 ii.Width = Form1.Width ii.Height = Screen.Height End If End Sub  
|