判断打印机是否还有任务队列的方法~

来源:互联网 发布:淘宝代销货源 编辑:程序博客网 时间:2024/05/15 07:08

Private Structure PRINTER_DEFAULTS  Dim pDatatype As String  Dim pDevMode As Integer  Dim DesiredAccess As IntegerEnd StructurePrivate Const PRINTER_ACCESS_ADMINISTER As Integer = &H4Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, ByRef phPrinter As Integer, ByRef pDefault As PRINTER_DEFAULTS) As IntegerPrivate Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" (ByVal hPrinter As Integer, ByVal FirstJob As Integer, ByVal NoJobs As Integer, ByVal Level As Integer, ByRef pJob As Byte, ByVal cdBuf As Integer, ByRef pcbNeeded As Integer, ByRef pcReturned As Integer) As IntegerPrivate Structure SYSTEMTIME  Dim wYear As Short  Dim wMonth As Short  Dim wDayOfWeek As Short  Dim wDay As Short  Dim wHour As Short  Dim wMinute As Short  Dim wSecond As Short  Dim wMilliseconds As ShortEnd StructurePrivate Structure JOB_INFO_1  Dim JobId As Integer  Dim pPrinterName As Integer  Dim pMachineName As Integer  Dim pUserName As Integer  Dim pDocument As Integer  Dim pDatatype As Integer  Dim pStatus As Integer  Dim Status As Integer  Dim Priority As Integer  Dim Position As Integer  Dim TotalPages As Integer  Dim PagesPrinted As Integer  Dim Submitted As SYSTEMTIMEEnd StructurePrivate Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Integer) As IntegerPublic Function HasJobs(ByVal PrinterName As String) As Integer  Dim hPrinter As Integer  Dim RetVal As Integer  Dim pd As New PRINTER_DEFAULTS  Dim aJi1() As Byte  Dim dwBytesNeed As Integer  Dim dwBytesRet As Integer  Dim lngSize As Integer  Dim JI_1 As JOB_INFO_1  lngSize = Len(JI_1)  pd.DesiredAccess = PRINTER_ACCESS_ADMINISTER  RetVal = OpenPrinter(PrinterName, hPrinter, pd)  ReDim aJi1(lngSize - 1)  RetVal = EnumJobs(hPrinter, 0, 3, 1, aJi1(0), lngSize, dwBytesNeed, dwBytesRet)  If RetVal = 0 And dwBytesNeed = 0 Then    ClosePrinter(hPrinter)    Return -1  End If  ClosePrinter(hPrinter)  If dwBytesNeed = 0 Then    Return 0  Else    Return 1  End IfEnd Function


与前篇一样这个算是VB6时代的方法,如果你更好的基于.Net的方法,请赐教!happybasic@163.com

 

原创粉丝点击