|
-
Jun 23rd, 2000, 12:55 AM
#1
Thread Starter
New Member
I want to be able to open a file from within my VB app, based on the file's extension (e.g. if the file is file.doc,the file would open in Word). This is basically the same behavior you get if you click on a file who has his extension registered in the file types.
Shell and CreateProcess both require the app name (in my example above, I'd have to use 'word.exe file.doc'). I'd like a call that would simply tell Windows to open the file with the app that it thinks should be used with that file.
Any ideas? Thanks.
-
Jun 23rd, 2000, 01:07 AM
#2
Frenzied Member
Use the ShellExecute API, which uses the associated application to open a file.
http://www.vbapi.com/ref/s/shellexecute.html
-
Jun 23rd, 2000, 01:09 AM
#3
New Member
'Yes, you need to use the ShellExecute API.
'The declaration is:
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
'Constants which are used to determine the state of the app when it loads...
Private Const SW_SHOWNORMAL = 1
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_SHOWNOACTIVATE = 4
Private Const SW_SHOWMINNOACTIVE = 7
Private Const SW_SHOWNA = 8
Private Const SW_SHOWDEFAULT = 10
'Then call it in code like this:
ShellExecute hwnd, "open", "http://www.vb-world.net", "", "", SW_SHOWNORMAL
'The last variable can be replaced with any of the constants above. It can be used to open websites with the default browser, and email messages with the current email program, or replace with a path and filename to open a document with its' associated application.
'Enjoy.
-
Jun 26th, 2000, 01:29 AM
#4
Thread Starter
New Member
Thanks, both JFrench and Seawood, your advice was exactly what I needed. I can't believe I overlooked ShellExecute before.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|