-
May 21st, 2003, 10:17 AM
#1
Shellexecute, Multiple files
I need to open multiple files without opening the same program several times. How can I open several files, using only one shellexecute call.
The following code works put opens two instance of the aplication.
I need only one instance of the aplication
sfile1="C:\data.pdb"
sfile2="C:\prod.pdb"
ShellExecute Me.hwnd, "", sfile1, sCommand, sWorkDir, 1
ShellExecute Me.hwnd, "", sfile2, sCommand, sWorkDir, 1
Please help...
-
May 21st, 2003, 01:31 PM
#2
Possible Answer
I'm not sure if this is going to solve your problem completely but here goes. You can place the following code in a module, or directly in your form if you prefer. What this function does is it opens a given filename in whatever application your system associates with the given filetype, ie.(*.mp3, *.doc, etc.)
'Place this in general declarations
#If Win32 Then
'32 bit declare
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
#Else
'16 bit declare
Declare Function ShellExecute Lib "shell.dll" _
(ByVal hWnd As Integer, ByVal lpszOp As String, ByVal lpszFile As String, ByVal spszParams As String, ByVal lpszDir As String, ByVal fsShowCmd As Integer) As Integer
#End If
'Constant declarations
Const SW_SHOWNORMAL = 1
Const SW_SHOWMINIMIZED = 2
Const SW_SHOWMAXIMIZED = 3
'Now insert this function
Public Function LaunchFile(Filename As String, Optional Action As Integer, Optional WindowState As Integer) As Long
Dim RetVal As Long
Dim LAction As String
'If Window state is not specified, set to normal
If WindowState = 0 Then WindowState = SW_SHOWNORMAL
'Assign action
If Action = 0 Then
LAction = "Open"
Else
LAction = "Print"
End If
'Call the function
RetVal = ShellExecute(0&, _
LAction, _
Filename, _
vbNullString, _
vbNullString, _
WindowState)
LaunchFile = RetVal
End Function
'Now all you need to do is call this function and pass it the appropriate parameters and your all set.
Dim blSuccess as boolean
blSuccess = LaunchFile(Filename, 0, 1)
'If the file opened successfully, this function returns true.
Hope this helps!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|