呼叫內定的Brower以Open URL


來源:太多網站提及,於此也做一記錄

利用ShellExecute()來做到內定Brower/Mail 的呼叫,而ShellExecute的用法請查
如何直接開啟一個文件

'需2個 Label
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
Const SW_SHOW = 5
Const SW_SHOWMAXIMIZED = 3
Const SW_SHOWNOACTIVATE = 4

Private Sub Form_Load()
Label1.Caption = "VB心得筆記"
Label1.ForeColor = vbRed
Label2.Caption = "與我聯絡"
Label2.ForeColor = vbRed
End Sub
Private Sub Label1_Click()
  Call ShellExecute(Me.hWnd, "open", "http://sunh.hosp.ncku.edu.tw/~cww/", "", "", SW_SHOWMAXIMIZED)
End Sub

Private Sub Label2_Click()
  Call ShellExecute(Me.hWnd, "open", "mailto:cww5@mail.ncku.edu.tw", "", "", SW_SHOW)
End Sub

'但有一個更快的方式,便是使用Shell指令來呼叫 start.exe
'eg. Shell "Start mailto:cww5@mail.ncku.edu.tw"
'eg. Shell "Start http://http://sunh.hosp.ncku.edu.tw/~cww"