(Declarations)
Const SEE_MASK_NOCLOSEPROCESS = &H40
Const SEE_MASK_FLAG_NO_UI = &H400
Private Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
Declare Function ShellExecuteEx Lib "shell32.dll"_
Alias "ShellExecuteEx" (SEI As SHELLEXECUTEINFO) As Long
Declare Function TerminateProcess Lib "kernel32"_
Alias "TerminateProcess" (Byval hProcess As Long, Byval uExitCode As Long) As Long
Sub Initialize
Dim SEI As SHELLEXECUTEINFO
SEI.cbSize = Len(SEI)
SEI.fMask = SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_FLAG_NO_UI
SEI.lpVerb = "open"
SEI.lpFile = "c:\sample.txt"
SEI.nShow = 1
SEI.hInstApp = 0
SEI.lpIDList = 0
Call ShellExecuteEx(SEI)
Messagebox "Application opened.", 0, "Success"
Call TerminateProcess(SEI.hProcess, 0)
End Sub
provided by Julian Robichaux at nsftools.com.
SNTT , show-n-tell thursday
Very nice. Several times, I've written apps or snippets that print attachements, without knowing which what application to use to do it. I've usually parsed out the extension then picked from a pre determined list of "known apps"
ReplyDeleteWithout doing any research myself, I suspect that your DLL call will let windows to the work. My guess is that SEI.lpVerb = "print" would do the trick. I don't have a need for it now, but, I've added this to my library.
You are correct, ShellExecuteEx looks up the file association and launches the file using the default application. There are a number of other verbs that can be used.
ReplyDeleteGreat! Just what I needed, thanks a lot.
ReplyDelete