|
-
Aug 7th, 2001, 02:02 AM
#1
Thread Starter
Lively Member
Running file with associated app?
How can i run a file with its associated app, like the Run dialog does? Its for a voice recognition project im working on, you tell it that when you say something, it can run a file or run a built in function?
Thanx!
-
Aug 7th, 2001, 02:10 AM
#2
You can use the ShellExecute API function to do this.
VB Code:
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 OpenFile(sFile As String)
ShellExecute Me.hwnd, vbNullString, sFile, vbNullString, vbNullString, 1
End Sub
Private Sub Command1_Click()
Call OpenFile("C:\MyFile.txt")
End Sub
-
Aug 7th, 2001, 02:23 AM
#3
Thread Starter
Lively Member
-
Aug 7th, 2001, 02:50 AM
#4
Thread Starter
Lively Member
one last thing...
How do i get the Focus to come to the app just launched, like with x=Shell then u just put vbNormalFocus, but how do i do this herE?
-
Aug 7th, 2001, 03:58 AM
#5
It's already there.
VB Code:
Private Sub OpenFile(sFile As String)
ShellExecute Me.hwnd, vbNullString, sFile, vbNullString, vbNullString, 1
End Sub
It's the 1 at the end. I put a 1 instead of the vbNormalFocus constant.
If you wish the change it, you'll get the same result.
VB Code:
Private Sub OpenFile(sFile As String)
ShellExecute Me.hwnd, vbNullString, sFile, vbNullString, vbNullString, vbNormalFocus
End Sub
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
|