Open an External File, URL, Email and System Apps in VB6
The ShellExecute function allows you to open external application, specific URL location, email address or launch system applications upon clicking on a single button.1. Start a new Standard Exe Project.
2. Add this code in General Declarations.
3. Add a command button on your form, change its name to cmdOpen.
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
4. DoubleClick on the form and try any of the codes below.
'# Open file (quotes are used so that the actual value that is passed is "C:\test.txt"
Private Sub cmdOpen_Click()
ShellExecute 0, vbNullString, """"C:\test.txt"""", vbNullString, vbNullString, vbNormalFocus
End Sub
'# Open url
Private Sub cmdOpen_Click()
ShellExecute 0, vbNullString, "http://tutorpinoy.blogspot.com", vbNullString, vbNullString, vbNormalFocus
End Sub
'# Open email address
Private Sub cmdOpen_Click()
ShellExecute 0, vbNullString, "mailto:tu2rpinoy@gmail.com", vbNullString, vbNullString, vbNormalFocus
End Sub
'#Open System Apps
Private Sub cmdOpen_Click()
ShellExecute 0, vbNullString, "Notepad", vbNullString, vbNullString, vbNormalFocus
End Sub
This comment has been removed by a blog administrator.
ReplyDelete