vb 如何调用默认浏览器

点击Command1,调用默认浏览器,进入网页www.baidu.com该怎么写
2024年11月18日 08:11
有4个网友回答
网友(1):

  默认浏览器不是IE浏览器,VB可以打开自行设置的默认浏枣慧巧览器来浏览网页。

  可以用以下两种代码方式打开。

  代码1)用Shell函数直接调用explorer.exe来打开网页。

  Private Sub Command1_Click() Dim strOpen strOpen = Shell("explorer.exe "碧搏
& Text1, 1)End SubPrivate Sub Form_Load() Text1 =
"http://zhidao.baidu.com"End Sub

  代码2)使用Api函数ShellExecute实现打开网页。

  Option Explicit 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 Dim strUrl As String Private Sub OpenUrl(tUrl As
String) ShellExecute Me.hwnd, "Open", tUrl, 0, 0, 0End SubPrivate Sub
Command1_Click() strUrl = Text1.Text OpenUrl (strUrl)End SubPrivate Sub
Form_Load() Text1 = "http://zhidao.baidu.com/"End Sub

  凳键两种方式都能在设置谷歌浏览器为默认浏览器状况下,打开想看的网页。

网友(2):

shell"笑坦http//碰汪桐陵慎www.baidu.com/"

网友(3):

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

Private Sub Command1_Click()
ShellExecute Me.hWnd, vbNullString, "www.baidu.com "衡败, vbNullString, vbNullString, SW_SHOWNORMAL
End Sub

网友(4):

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 Sub Command1_Click()

Dim Result
Result = ShellExecute(0, vbNullString, "http://www.baidu.com/", vbNullString, vbNullString, SW_SHOWNORMAL)
If Result <冲陵= 32 Then
MsgBox "调用浏览器错误!袭毁", vbOKOnly + vbCritical, "错误:", 0
End If

End Sub