ejemplos tomados de
www.allapi.net
Ejemplo 1
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_SHOWNORMAL = 1
Private Sub Form_Load()
'KPD-Team 1998
'URL:
http://www.allapi.net/
'E-Mail:
[email protected]
'Send an E-Mail to the KPD-Team
ShellExecute Me.hwnd, vbNullString, "mailto:
[email protected]", vbNullString, "C:\", SW_SHOWNORMAL
End Sub
*****************
ejemplo 2
'Example by Joel (
[email protected])
'This example requires a command button (Command1)
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize 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
Const SW_SHOWNORMAL = 1
Const SE_ERR_NOASSOC = 31
Const sOperation As String = "open" ' Constants for shell operations
Const sRun As String = "RUNDLL32.EXE"
Const sParameters As String = "shell32.dll,OpenAs_RunDLL "
Private Function shelldoc(sfile As String)
Dim sPath As String, RetVal As Long, _
lRet As Long
lRet = ShellExecute(GetDesktopWindow(), sOperation, sfile, _
vbNullString, vbNullString, SW_SHOWNORMAL)
If lRet = SE_ERR_NOASSOC Then ' No association exists
'Create a buffer
sPath = Space(255)
'Get the system directory
RetVal = GetSystemDirectory(sPath, 255)
'Remove all unnecessary chr$(0)'s
'and move on the stack
sPath = Left$(sPath, RetVal)
lRet = ShellExecute(GetDesktopWindow(), "open", sRun, _
sParameters + sfile, sPath, SW_SHOWNORMAL)
End If
End Function
Private Sub Command1_Click()
' Change the file extensions so that one
' has a program associated with it and the
' other does not.
Call shelldoc("C:\myfile.txt")
Call shelldoc("C:\myfile.sarsaparilla")
End Sub