Link to home
Start Free TrialLog in
Avatar of scooterhead
scooterhead

asked on

Opening the associated application

I have an application which uses a listview control to display icons that have associated Word documents with them and others that have TIFF images associated with them....(ex.  icon#1 = c:\windows\temp\doc1.doc icon#2 = c:\windows\temp\image1.tif).  I would like for the user to be able to double click the icon and the document or image to open in the associated application designated in the File Types list.  Any help would be appreciated...
Avatar of Erick37
Erick37
Flag of United States of America image

"HOWTO: Use ShellExecute to Launch Associated File"

http://support.microsoft.com/support/kb/articles/Q170/9/18.asp
Avatar of wsh2
wsh2

Try This.. <smile>

Syntax:

booReturn = xShellByExtension(strFileName)


<----- Code Begin ----->

Option Explicit

Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
  (ByVal lpFile As String, _
  ByVal lpDirectory As String, _
  ByVal lpResult As String) _
  As Long

Public Function xShellByExtension _
(ByVal strFileName As String) _
As Boolean

  Dim strProgram As String
  Dim lngReturn As Long
 
  ' Get Program PathName
  strProgram = Space(255)
  lngReturn = FindExecutable(strFileName, "", strProgram)
  If lngReturn < 32 _
  Then
    MsgBox (strFileName & " FILE NOT FOUND")
    Exit Function
  End If
  strProgram = Left$(strProgram, InStr(1, strProgram, Chr(0)) - 1)
 
  ' Execute Program with FileName as Parameter 1
  Dim StrCommand As String
  StrCommand = """ & strProgram & """ _
     & """ & strFileName & """
  lngReturn = Shell(strCommand, vbNormalFocus)
  If lngReturn > 0 _
  Then
    xShellByExtension = True 'Successful
  Else
    MsgBox (strCommand & vbCrLf & " PROGRAM NOT FOUND")
    xShellByExtension = False 'UNSUCCESSFUL
  End If
 
End Function

<----- Code End ----->
ASKER CERTIFIED SOLUTION
Avatar of caraf_g
caraf_g

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of scooterhead

ASKER

Thank you