Click to See Complete Forum and Search --> : Opening a file with its default application


rick
April 25th, 2001, 04:02 PM
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
rguay@i4i.com
www.i4i.com

Rick
April 25th, 2001, 04:02 PM
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
rguay@i4i.com
www.i4i.com

softweng
April 25th, 2001, 05:51 PM
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