1和1互质吗:VB中如何打印已有的PDF文档
来源:百度文库 编辑:杭州交通信息网 时间:2024/06/01 11:53:39
调用Shell
Option Explicit
Private Const WAIT_FAILED = &HFFFFFFFF
Public Declare Function WaitForInputIdle Lib "user32" ( _
ByVal hProcess As Long, _
ByVal dwMilliseconds As Long _
) As Long
Public Declare Function WaitForSingleObject Lib "Kernel32" ( _
ByVal hHandle As Long, _
ByVal dwMilliseconds As Long _
) As Long
Private Declare Function TerminateProcess Lib "Kernel32" ( _
ByVal hProcess As Long, _
ByVal uExitCode As Long _
) As Long
Private Declare Function ShellExecuteEx Lib "shell32.dll" Alias "ShellExecuteExA" ( _
lpExecInfo As SHELLEXECUTEINFO _
) As Long
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
'SHELLEXECUTEINFO fMask-Konstanten
Private Const SEE_MASK_NOCLOSEPROCESS = &H40 'F黮lt die Struktur Option hProcess mit dem Process Handle der gestarteten Anwendung
Private Const WAIT_OBJECT_0 = &H0 'Das
'SHELLEXECUTEINFO nShow-Konstanten
Public Enum ShowConstants
WVersteckt = 0 'Versteckt das Fenster
WNormal = 1 'Zeigt es ganz normal an
WMaximiert = 3 'Maximiert das Fenster
WMinimiert = 6 'Minimiert das Fenster
End Enum
Public Enum WaitConstants
wcNone = 0
wcInitialisiert = 1
WCTermination = 2
End Enum
Public Function ShellAndWait(ByVal Operation As String, _
ByVal FilePath As String, _
Optional Parameter As String, _
Optional WorkingFolder As String, _
Optional WindowSize As ShowConstants = 1, _
Optional WaitFor As WaitConstants = 0, _
Optional Milliseconds As Long = -1, _
Optional CloseProcess As Boolean = False) As String
Dim RetVal As Long
Dim ShExInfo As SHELLEXECUTEINFO
'//////////////////////////////////////////////////////////////////////////////
' Initialisierung
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
If WorkingFolder = "" Then WorkingFolder = FilePath
With ShExInfo
.cbSize = Len(ShExInfo)
.fMask = SEE_MASK_NOCLOSEPROCESS
.hwnd = 0
.lpVerb = Operation
.lpFile = FilePath
.lpParameters = Parameter
.lpDirectory = WorkingFolder
.nShow = WindowSize
End With
'/////////////////////////////////////////////////////////////////////////////
' Anwendung ausf党ren
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
RetVal = ShellExecuteEx(ShExInfo)
If RetVal = 0 Then
'Ein Fehler ist aufgetreten
' ShellAndWait = ShellExecError(ShExInfo.hInstApp)
Exit Function
End If
'/////////////////////////////////////////////////////////////////////////////
' Warten auf Prozess
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
If WaitFor <> wcNone Then
If WaitFor = wcInitialisiert Then
' Warten bis die Anwendung initialisiert ist
RetVal = WaitForInputIdle(ShExInfo.hProcess, Milliseconds)
Else
' Warten bis die Anwendung beendet
RetVal = WaitForSingleObject(ShExInfo.hProcess, Milliseconds)
End If
If RetVal = WAIT_FAILED Then ShellAndWait = "Warten auf Prozess fehlgeschlagen."
End If
'/////////////////////////////////////////////////////////////////////////////
' SCHLIE逧N DES PROZESSES
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
If CloseProcess = True Then
RetVal = TerminateProcess(ShExInfo.hProcess, 1)
If RetVal <> 0 Then ShellAndWait = "Schlie遝n der Anwendung fehlgeschlagen."
End If
End Function
打印命令
ShellAndWait "print", Filename, "", vbNullChar, WVersteckt, WCTermination, 60000, True