CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Location
    Ottawa, Ont
    Posts
    120

    Opening a file with its default application

    Hey,


    I need to open a file in code using the windows default application method...

    Like doulble clicking on the file in explorer and having the application start and opening the file automaticaly.


    thanks,

    Rick
    [email protected]
    www.i4i.com

  2. #2
    Join Date
    May 1999
    Location
    Ottawa, Ont
    Posts
    120

    Opening a file with its default application

    Hey,


    I need to open a file in code using the windows default application method...

    Like doulble clicking on the file in explorer and having the application start and opening the file automaticaly.


    thanks,

    Rick
    [email protected]
    www.i4i.com

  3. #3
    Join Date
    Mar 2000
    Location
    Arizona, USA
    Posts
    493

    Re: Opening a file with its default application

    Use The ShellExecute API. It will open the file with whatever program is associated with it

    option Explicit

    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 Command1_Click()
    Dim retval as Long

    '//Open HTML File In Default Browser
    retval = ShellExecute(Form1.hwnd, "open", "C:\Test.htm", "", "c:\", 1)

    End Sub

    private Sub Command2_Click()
    Dim retval as Long

    '//Open Text File
    retval = ShellExecute(Form1.hwnd, "open", "C:\Test.txt", "", "c:\", 1)

    End Sub

    private Sub Command3_Click()
    Dim retval as Long

    '//Open Word Document
    retval = ShellExecute(Form1.hwnd, "open", "C:\Test.doc", "", "c:\", 1)

    End Sub





    Kris
    Software Engineer
    Phoenix,AZ
    Kris
    Software Engineer
    Phoenix, AZ USA

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

Featured