Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-报表

[access报表]获得某一台网络打印机有几份等待打印的报表

时 间:2008-09-04 08:11:37
作 者:fan0217   ID:3202  城市:绵阳
摘 要:获得某一台网络打印机有几份等待打印的报表
正 文:

CODE:
'Constants Definition
Public Const CCHDEVICENAME = 32
Public Const CCHFORMNAME = 32
Public Const PRINTER_ACCESS_ADMINISTER = &H4
Public Const PRINTER_ACCESS_USE = &H8

'Types Definition
Public Type DEVMODE
dmDeviceName As String * CCHDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCHFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Long
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type

Public Type PRINTER_DEFAULTS
pDatatype As String
pDevMode As DEVMODE
DesiredAccess As Long
End Type

'API Declarations
Public Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" _
(ByVal pPrinterName As String, phPrinter As Long, _
pDefault As PRINTER_DEFAULTS) As Long

Public Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" _
(ByVal HPrinter As Long, ByVal FirstJob As Long, ByVal NoJobs As Long, _
ByVal Level As Long, pJob As Byte, ByVal cdBuf As Long, _
pcbNeeded As Long, pcReturned As Long) As Long

Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

'取得指定的打印机,目前有多少 Jobs (最大值为 128)
'打印机的名称可以是 mapping 的网络路径名称,例如: "\\myserver\myprinter"
'测试预设打印机的 Queue(Printer.DeviceName)
'MsgBox "打印机中尚有 " & GetPrinterQueue(Printer.DeviceName) & " 份报表", 64, "讯息"
Function GetPrinterQueue(PrinterName As String) As Long
Dim PrinterStruct As PRINTER_DEFAULTS
Dim HPrinter As Long
Dim ret As Boolean
Dim JobStruct(0 To 127) As Byte
Dim pcbNeeded As Long
Dim pcReturned As Long
Dim TempByte As Byte

'设定 Printer structure 初值
PrinterStruct.pDatatype = vbNullString
PrinterStruct.pDevMode.dmSize = Len(PrinterStruct.pDevMode)
PrinterStruct.DesiredAccess = PRINTER_ACCESS_USE
'取得打印机的 Handle
ret = OpenPrinter(PrinterName, HPrinter, PrinterStruct)
'取得打印机的 active jobs
ret = EnumJobs(HPrinter, 0, 127, 1, TempByte, 0, pcbNeeded, pcReturned)
If pcbNeeded = 0 Then
GetPrinterQueue = 0
Else
ret = EnumJobs(HPrinter, 0, 127, 1, JobStruct(0), pcbNeeded, pcbNeeded, pcReturned)
GetPrinterQueue = pcReturned
End If
'关闭打印机
ret = CloseHandle(HPrinter)
End Function



Access软件网官方交流QQ群 (群号:54525238)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助