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

本文将介绍如何确定打印机当前是否存在未完成的任务队列,包括Windows和Mac系统的操作步骤,帮助你了解打印机的工作状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

happybasic

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值