Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking Files using application in Visual Basic 6.0 3

Status
Not open for further replies.

Askeladden

Programmer
Jan 28, 2004
87
NO
Hi, I am in the middle of a Visual Basic 6.0 project, and I am stuck on one thing. I want the program, if double clicking on a file that is listed in a list box, to execute the file using the application belonging to that file. (example: double clicking on a file with a '.doc' extension, brings the '.doc' file up in Word. Same thing with an Exel (.xls) file, or an Acrobat Reader (.pfd) file, etc.)
Thanks for any assistance that can be provided :)
 
Use the shell command

Shell(pathname[,windowstyle])

The Shell function syntax has thesenamed arguments:

Part Description
pathname Required; Variant (String). Name of the program to execute and any requiredarguments orcommand-line switches; may include directory or folder and drive.
windowstyle Optional. Variant (Integer) corresponding to the style of the window in which the program is to be run. If windowstyle is omitted, the program is started minimized with focus.


The windowstyle named argument has these values:

Constant Value Description
vbHide 0 Window is hidden and focus is passed to the hidden window.
vbNormalFocus 1 Window has focus and is restored to its original size and position.
vbMinimizedFocus 2 Window is displayed as an icon with focus.
vbMaximizedFocus 3 Window is maximized with focus.
vbNormalNoFocus 4 Window is restored to its most recent size and position. The currently active window remains active.
vbMinimizedNoFocus 6 Window is displayed as an icon. The currently active window remains active.


**********************************
May the Code Be With You...
----------
x50-8 (X Fifty Eigt)
 
I think you'll need more than this.

Shell "C:\test.doc" gives invalid procedure for me.
The help says it is to launch executables, not documents.

You will possibly need to find out what program is associated with the document, using this API call:

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

example of usage:

'declare a buffer large enough to hold the result
Dim szResult As String * 2000

'call the API
FindExecutable "test.doc", "C:\", szResult

'the result is a string somewhere in a 2000 byt buffer
'crop it at the first CHR(0)
szResult = Left$(szResult, InStr(szResult, Chr(0)) - 1)

'launch the associated program, and tell it the name
'of the file
'this may need to be mangled if there are
'spaces in the path

VBA.Interaction.Shell szResult & " C:\test.doc"

 
Hmm, good point jeff

**********************************
May the Code Be With You...
----------
x50-8 (X Fifty Eigt)
 
thanks to both of you for the new ideas you have given me. But the program will have to activate different application. The application should be activated together with the file that is listed in a listbox.
Do any of you have an idea how this could be done?
Thank ahead of time. :)
 
Also, JeffTullin, do you think you can explain a little more indepthabout API call.

Also could you explain this function:

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

And what might be in it's body.

Thanks
 
A simpler solution may be to use the ShellExecute API:


where you can also find a VB example

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top