|
-
Nov 15th, 2000, 03:20 PM
#1
Thread Starter
New Member
I am writing an application that reads a database of .pdf files.
When they choose one, I want to shell out to adobe reader. How do I find out if adobe reader is installed, and then get the path to it so I can shell out to it and have the correct file opened?
I found some code that uses 'PrivateProfileString', but that is not supported in my VB.
Thanks,
Mike
-
Nov 15th, 2000, 04:26 PM
#2
Member
Here's one way...
Try using the ShellExecute API.
Put the following code in a module:
Code:
Public 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
Public Const SW_MAXIMIZE = 3
Public Const SW_MINIMIZE = 6
Public Const SW_RESTORE = 9
and, place the following code onto Form1 with a command button called Command1:
Code:
Private Sub Command1_Click()
Dim retval As Long
Dim pstrFileName As String
Dim pstrDirOfFile As String
pstrFileName = "Sample.pdf" ' Of course, you'll want
pstrDirOfFile = "C:\SampleDir\" ' to change these. :)
retval = ShellExecute(Form1.hwnd, "open", pstrPathToFile & pstrFileName, "", _
pstrDirOfFile, SW_RESTORE)
End Sub
If there is no program associated with the file you are trying to open, nothing happens... if there is a program associated with it, it will open in that program.
-
Nov 15th, 2000, 04:57 PM
#3
Member
Constants...
I forgot to add all of the constants before...
(As you can see if there is no associated program, the retval is 31)
Here goes:
Code:
Const ERROR_BAD_FORMAT = 11
Const SE_ERR_ACCESSDENIED = 5
Const SE_ERR_ASSOCINCOMPLETE = 27
Const SE_ERR_DDEBUSY = 30
Const SE_ERR_DDEFAIL = 29
Const SE_ERR_DDETIMEOUT = 28
Const SE_ERR_DLLNOTFOUND = 32
Const SE_ERR_FNF = 2
Const SE_ERR_NOASSOC = 31
Const SE_ERR_OOM = 8
Const SE_ERR_PNF = 3
Const SE_ERR_SHARE = 26
Const SW_HIDE = 0
Const SW_MAXIMIZE = 3
Const SW_MINIMIZE = 6
Const SW_RESTORE = 9
Const SW_SHOW = 5
Const SW_SHOWMAXIMIZED = 3
Const SW_SHOWMINIMIZED = 2
Const SW_SHOWMINNOACTIVE = 7
Const SW_SHOWNA = 8
Const SW_SHOWNOACTIVATE = 4
Const SW_SHOWNORMAL = 1
These will make it easier to tell the user why "nothing" is happening.
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
|