Results 1 to 5 of 5

Thread: Running file with associated app?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Location
    Leicester, UK
    Posts
    92

    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!

  2. #2
    Matthew Gates
    Guest
    You can use the ShellExecute API function to do this.


    VB Code:
    1. Private Declare Function ShellExecute Lib "shell32.dll" _
    2. Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As _
    3. String, ByVal lpFile As String, ByVal lpParameters As String, ByVal _
    4. lpDirectory As String, ByVal nShowCmd As Long) As Long
    5.  
    6. Private Sub OpenFile(sFile As String)
    7.     ShellExecute Me.hwnd, vbNullString, sFile, vbNullString, vbNullString, 1
    8. End Sub
    9.  
    10. Private Sub Command1_Click()
    11.     Call OpenFile("C:\MyFile.txt")
    12. End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Location
    Leicester, UK
    Posts
    92

    thanx

    thanx m8

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Location
    Leicester, UK
    Posts
    92

    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?

  5. #5
    Matthew Gates
    Guest
    It's already there.

    VB Code:
    1. Private Sub OpenFile(sFile As String)
    2.     ShellExecute Me.hwnd, vbNullString, sFile, vbNullString, vbNullString, 1
    3. 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:
    1. Private Sub OpenFile(sFile As String)
    2.     ShellExecute Me.hwnd, vbNullString, sFile, vbNullString, vbNullString, vbNormalFocus
    3. 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
  •  



Click Here to Expand Forum to Full Width