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 WithEvents lblURL As Label
Private Sub Form_Load()
Set lblURL = Controls.Add("VB.Label", "lblURL", Me)
With lblURL
.Left = 1000
.Top = 1000
.AutoSize = True
.Caption = "http://www.163.com"
.Visible = True
.FontUnderline = True
.ForeColor = vbBlue
.MousePointer = vbUpArrow
End With
End Sub
Private Sub lblURL_Click()
ShellExecute Me.hwnd, "open", lblURL.Caption, vbNullString, vbNullString, ByVal 0&
End Sub
接上
*****************************
不好意思!
还应该在程序中做如下次声明:
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 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 Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.ForeColor = vbBlue
End Sub
Private Sub Label1_Click()
On Error GoTo Errhandle
'Shell "C:\Program Files\Internet Explorer\IEXPLORE.EXE mailto:cuizm@163.com", vbMinimizedFocus
' ShellExecute Me.hwnd, "open", "mailto:CuiZM@163.com", vbNullString, vbNullString, 1
ShellExecute Me.hwnd, "open", "www.sohu.com", vbNullString,
Exit Sub
Errhandle:
MsgBox Err.Description, vbExclamation
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.ForeColor = vbRed
End Sub
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 Label1_Click()
ShellExecute Me.hWnd, "open", "http://www.csdn.net", vbNullString, vbNullString, SW_SHOW
首先,在窗体声明部分,加入如下的代码,就能引用API函数ShellExecute: 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
首先声明
Public 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
Public Const SW_SHOW = 5