I am currently using an implementation of the ShellExecuteEx API that prints all the .PDFs I send to it. However, it does not seem to wait until the process of the first print job closes before it prints the next print job (i.e. does not print in order). Below is the code I am currently using. Please provide guidance on how I can adjust the code properly. Thanks
CODE...
*****DECLARATIONS SECTION*****
Private Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
Public Const SEE_MASK_NOCLOSEPROCESS = &H40
Public Const SW_SHOWNORMAL = 1
Public Const INFINITE = &HFFFF
Public Const WAIT_TIMEOUT = &H102
Public Declare Function ShellExecuteEx Lib "shell32.dll" Alias "ShellExecuteExA" (lpExecInfo As _
SHELLEXECUTEINFO) As Long
Public Declare Function WaitForSingleObject Lib "kernel32.dll" (ByVal hHandle As Long, ByVal _
dwMilliseconds As Long) As Long
*****FUNCTION SECTION*****
Public Function Shell_X(formhwnd As String, filename As String, action As String, showstyle) As Integer
Dim sx As SHELLEXECUTEINFO
Dim proc As PROCESS_INFORMATION
Dim retval As Long
' Load the information needed for action
' into the structure.
With sx
' Size of the structure
.cbSize = Len(sx)
' Use the hProcess element of the structure.
.fMask = SEE_MASK_NOCLOSEPROCESS
' Handle to the window calling this function.
.hwnd = formhwnd
' The action to perform: print the file.
.lpVerb = action 'I WILL USE 'PRINT' HERE
' The file to open.
.lpFile = filename
' No additional parameters are needed here.
.lpParameters = ""
' Simply display the window.
.nShow = showstyle
End With
' Open the file using its associated program.
retval = ShellExecuteEx(sx)
If retval <> 0 Then
' Wait for the opened process to close
' before continuing. Instead
' of waiting once for a time of INFINITE,
' this example repeatedly checks to see if the
' process is still open.
' This allows the DoEvents VB function to be
' called, preventing
' the program from appearing to lock up
' while it waits.
Do While retval = WAIT_TIMEOUT
DoEvents
retval = WaitForSingleObject(sx.hProcess, 0)
Loop
End If
End Function
*****END OF CODE*****
To call this function, I would simply do something like this...
For i = 1 to 5
Rtn = Shell_X(Me.hWnd, "c:\myfile" & i & ".pdf", "print", SW_HIDE)
Next i
Game Over, Man!