判断打印机是否还有任务队列的方法~
2012-11-16 12:46
225 查看
Private Structure PRINTER_DEFAULTS
Dim pDatatype As String
Dim pDevMode As Integer
Dim DesiredAccess As Integer
End Structure
Private Const PRINTER_ACCESS_ADMINISTER As Integer = &H4
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, ByRef phPrinter As Integer, ByRef pDefault As PRINTER_DEFAULTS) As Integer
Private 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 Integer
Private 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 Short
End Structure
Private 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 SYSTEMTIME
End Structure
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Integer) As Integer
Public 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 If
End Function
与前篇一样这个算是VB6时代的方法,如果你更好的基于.Net的方法,请赐教!happybasic@163.com
Dim pDatatype As String
Dim pDevMode As Integer
Dim DesiredAccess As Integer
End Structure
Private Const PRINTER_ACCESS_ADMINISTER As Integer = &H4
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, ByRef phPrinter As Integer, ByRef pDefault As PRINTER_DEFAULTS) As Integer
Private 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 Integer
Private 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 Short
End Structure
Private 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 SYSTEMTIME
End Structure
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Integer) As Integer
Public 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 If
End Function
与前篇一样这个算是VB6时代的方法,如果你更好的基于.Net的方法,请赐教!happybasic@163.com
相关文章推荐
- 另类判断打印机是否为脱机状态的方法
- java ThreadPool判断是否所有任务都完成的方法
- C#判断节点下是否还有子节点的方法
- 优先队列priority_queue容器的使用方法:出队,入队,删除队首元素,判断是否为空
- 方法一 Java如何判断线程池所有任务是否执行完毕
- C#--第七周实验--任务1--创建物体类PhysicalObject,通过其私有字段来存放重量和体积,通过公有方法判断该物体是否会在水中下沉
- 请使用LinkedList来模拟一个队列(先进先出的特性): 1) 拥有放入对象的方法void put(Object o) 2)取出对象的方法Object get() 3)判断队列当中是否为空的方法b
- C#判断节点下是否还有子节点的方法
- Java 写一个方法判断一个字符串是否对称 "asdfgasdfg"、编写一个程序,将下面的一段文本中的各个单词的字母顺序翻转,
- 用js正确判断用户名cookie是否存在的方法
- 判断用户是否有鼠标动作的方法
- 【js小方法】提交表单是,判断单选框是否被选中
- 判断一个变量是否为空的方法
- PHP判断变量是否为空的几种方法区别
- JDT:判断某方法是否为public
- 对pandas数据判断是否为NaN值的方法详解
- C#+AE 判断点是否在面内的方法
- linux下判断路径是否存在的3种方法
- javascript判断复选框是否选中的方法
- 判断php数组是否为索引数组的实现方法