2008年8月9日星期六

VB打开网页全方法集

网址打开全方法集合:
1.基于start.exe
+++++++++++++++++++源码1++++++++++++++++++++++
url="http://hi.baidu.com/tanry"
shell "start " & url,0
+++++++++++++++++++源码2++++++++++++++++++++++
url="http://hi.baidu.com/tanry"
shell "cmd.exe /c start " & url,0

2.基于文件浏览器(explorer.exe)
+++++++++++++++++++源码+++++++++++++++++++++++
url = "http://hi.baidu.com/tanry"
Shell "explorer " & url, 0

3.基于IE浏览器的
+++++++++++++++++++源码1(使用IE对象)++++++++++
Dim Browser As Object
url="http://hi.baidu.com/tanry"

Set Browser = CreateObject("InternetExplorer.Application")

Browser.Visible = True

Browser.Navigate (url)
+++++++++++++++++++源码2++++++++++++++++++++++
Private Sub cmd1_Click()
url = "http://hi.baidu.com/tanry"
exe = Environ("programfiles") & "\Internet Explorer\IEXPLORE.EXE"
Shell exe & Space(1) & url, 1
End Sub

5.基于API的
'API函数声明 :
+++++++++++++++++++源码++++++++++++++++++++++
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long,ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Const SW_SHOWNORMAL = 1



'函数返回值为大于32的整数表明成功执行调用,小于或等于32表明调用失'败。

'例如:

Dim Result

Result = ShellExecute(0, vbNullString, "http://hi.baidu.com/tanry", vbNullString, vbNullString, SW_SHOWNORMAL)

If Result <= 32 Then

MsgBox "调用浏览器错误!", vbOKOnly + vbCritical, "错误:", 0

End If

6.基于WebBrowser控件的
+++++++++++++++++++源码++++++++++++++++++++++

url="http://www.baidu.com"
WebBrowser1.Navigate url