'This example will show you how to launch a file with his associate program.<br>
'It will do the same action that occur when you Double Click on the file.<br>
'For Example, if when you double click on mp3 file it launch with Winamp,<br>
'This code will do the same.<br>
'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)<br>
'Insert this code to the module :<br>
<br>
#If Win32 Then<br>
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _<br>
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile _<br>
As String, ByVal lpParameters As String, ByVal lpDirectory As String, _<br>
ByVal nShowCmd As Long) As Long<br>
Declare Function GetDesktopWindow Lib "user32" () As Long<br>
#Else<br>
Declare Function ShellExecute Lib "SHELL" (ByVal hwnd%, _<br>
ByVal lpszOp$, ByVal lpszFile$, ByVal lpszParams$, _<br>
ByVal lpszDir$, ByVal fsShowCmd%) As Integer<br>
Declare Function GetDesktopWindow Lib "USER" () As Integer<br>
#End If<br>
Public Const SW_SHOWNORMAL = 1<br>
<br>
'Insert this code to your form:<br>
<br>
Function StartDoc(DocName As String) As Long<br>
Dim Scr_hDC As Long<br>
Scr_hDC = GetDesktopWindow()<br>
StartDoc = ShellExecute(Scr_hDC, "Open", DocName, "", "C:\", SW_SHOWNORMAL)<br>
End Function<br>
<br>
Private Sub Form_Load()<br>
Dim r As Long<br>
'Replace the c:\mp3\song.mp3 with the file you want to launch<br>
r = StartDoc("c:\mp3\song.mp3"<br>
End Sub<br>
<br>
<br>
Eric <p>Eric De Decker<br><a href=mailto:vbg.be@vbgroup.nl>vbg.be@vbgroup.nl</a><br><a href=
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.