Re: View a PDF in VB6

Tech-Archive recommends: Speed Up your PC by fixing your registry



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
>


.



Relevant Pages

  • RE: Converting VB6 Fileopen/input/close to vb.net
    ... swallow and spit it out as a single string. ... stand alone components set for those VB6 file methods(such as FileOpen, ... Dim file_num As Integer = FreeFile ... For standard binary file read/write, in .NET, you can use BinaryReader ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Use of Mid Statement in VB.Net
    ... Dim buffer as New String(" "c, ... If you use VB6, then stick to your own group. ... Microsoft for the change in the language paradigm that VB.Net introduced. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Converting Quick Basic to Visual Basic
    ... "Bill McCarthy" wrote in message ... VB3 or earlier applications cannot be opened directly by VB6 IDE, and also require replacement of control libraries etc, etc. ... You still declare a String the same way and you assign and use strings the same way. ... could you imagine if every object had to have an ansi string property and a unicode string property for each property. ...
    (microsoft.public.vb.general.discussion)
  • Re: Using a dll vs. ocx
    ... The wrapper for VB6 appears to be a class. ... dll command in VFP. ... DECLARE integer AUDIOAnalyzeFile IN "AudioGenie2.dll" string ...
    (microsoft.public.fox.programmer.exchange)
  • Re: COM interop and Object Required
    ... string String ... int Long ... public class ComObject: IComInterface ... In VB6 I have added a reference to this class. ...
    (microsoft.public.dotnet.languages.csharp)