Re: View a PDF in VB6
- From: "Amnon Rapoport" <Amnon-Planium@xxxxxxxxxxxxxxxx>
- Date: Wed, 7 Dec 2005 08:07:18 +0200
Brandon Hi,
The following code 'should' solve the problem. I use it to load and display
an Excel file generated within my VB6 application or an RTF file generated
by my app. I assume that it will solve your problem with PDF files.
Use copy/paste to the VB6 environement and it will all look fine within the
VB6 editor.
Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA"
(ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As
String) As Long
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 Function StartWithinAssociatedApplicationM(strFileName As String, _
lngFormhWnd As Long, _
lngTextIndex1 As Long, _
lngTextIndex2 As Long, _
lngTextIndex4 As Long, _
lngTextIndex5 As Long)
Dim lngRetVal As Long
Dim strParentExecutable As String * 512
Dim strChr As String * 1
Dim strDummy As String, intPos As Integer, strExe As String,
strWordProcFile As String
Dim strDefaultDirectory As String
Dim strOnlyFileName As String
On Error Resume Next
If Dir(strFileName) = "" Then
Screen.MousePointer = 0
varRC = MsgBox(GetLangText(lngTextIndex1) & " (" &
strFileName & ")", vbExclamation + vbOKOnly, App.Title) 'FAX
document 'fax_eng.rtf' could not be found
'Unload frmOrder
DoEvents
Exit Function
End If
lngRetVal = FindExecutable(strFileName, strDummy,
strParentExecutable)
If lngRetVal < 33 Then
'Error message
End If
varRC = ShowTraceText("File to 'OPEN' is " & strFileName)
varRC = ShowTraceText("Executable found in
StartWithinAssociatedApplicationM is " & strParentExecutable)
strParentExecutable = Trim$(strParentExecutable)
'Find the 'Null' terminator
For intPos = 1 To Len(strParentExecutable)
strChr = mid$(strParentExecutable, intPos, 1)
If strChr = Chr$(0) Then
strWordProcFile =
Trim(mid$(strParentExecutable, 1, intPos - 1)) 'chop off after and
including the Null terminator
Exit For
End If
Next intPos
strWordProcFile = Trim$(strWordProcFile)
varRC = ShowTraceText("Executable trimmed in
StartWithinAssociatedApplicationM is " & strWordProcFile)
strDefaultDirectory = GetPartOfPathP(strFileName, 1)
strDefaultDirectory = mid$(strDefaultDirectory, 1,
Len(strDefaultDirectory) - 1)
strOnlyFileName = Chr(34) & GetPartOfPathP(strFileName, 4) & Chr(34)
If strWordProcFile = "" Or LCase(mid$(strWordProcFile,
Len(strWordProcFile) - 3, 4)) <> ".exe" Or Dir(strWordProcFile) = "" Then
'No program to open the file kkkk could be found. You will have to use an
editor to open the file and print it.
' try to load the file itself
varRC = ShowTraceText("StartWithinAssociatedApplicationM -
Try to load the file itself")
lngRetVal = ShellExecute(lngFormhWnd, "open",
strOnlyFileName, "", strDefaultDirectory, 1)
If lngRetVal < 33 Then 'See reference in
MSDN - ShellExecute - return values
varRC = MsgBox(GetLangText(lngTextIndex4) & " " &
strFileName & ". " & GetLangText(lngTextIndex5) & ".", vbExclamation +
vbOKOnly, App.Title)
Else
Exit Function
End If
' varRC = MsgBox(GetLangText(4880) & ":" & " (" &
strFileName & ") " & vbCrLf & vbCrLf & GetLangText(lngTextIndex2),
vbExclamation + vbOKOnly, App.Title)
Exit Function
End If
'Load the associated word processor
'varRC = ShowTraceText("Before ShellExecute:" & vbCrLf &
"strFileName = " & strFileName & vbCrLf & " strWordProcFile = " &
strWordProcFile)
varRC = ShowTraceText("Before ShellExecute:" & vbCrLf &
"strDefaultDirectory = " & strDefaultDirectory & vbCrLf & " strOnlyFileName
= " & strOnlyFileName & vbCrLf & " strWordProcFile = " & strWordProcFile)
lngRetVal = ShellExecute(lngFormhWnd, "open", strWordProcFile,
strOnlyFileName, strDefaultDirectory, 1)
'lngRetVal = ShellExecute(lngFormhWnd, "open", strWordProcFile,
strOnlyFileName , strDefaultDirectory, 1)
If lngRetVal < 33 Then 'See reference in MSDN -
ShellExecute - return values
varRC = MsgBox(GetLangText(lngTextIndex4) & " " &
strFileName & ". " & GetLangText(lngTextIndex5) & ".", vbExclamation +
vbOKOnly, App.Title)
End If
End Function
Good luck
Garry
"Brandon Teachman" <bteachman@xxxxxxxxx> wrote in message
news:BFAA6C01.ACE%bteachman@xxxxxxxxxxxx
> Guys,
>
> I am looking for a way to view PDF files inside a Visual Basic 6
> application with out purchasing any software. I currently have some
> applications that do this by opening adobe reader when the program opens,
> then calls it when needed. Any one have any ideas.
>
> Thank You,
>
> Bob "I love My Job" Programmer
>
.
- Prev by Date: Re: i want code to create OU in AD.
- Next by Date: Re: i want code to create OU in AD.
- Previous by thread: What was SAPI 4 distributed with/on, and when?
- Next by thread: Re: View a PDF in VB6
- Index(es):
Relevant Pages
|