Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can I get the number of jobs in print queue
Message
From
07/01/2003 05:59:39
 
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00737034
Message ID:
00738689
Views:
24
S. Berenisker's code uses EnumJobs function to return the number of job.

Declare Integer EnumJobs in WinSpool.Drv as WS_EnumJobs ;
Integer hPrinter, ;
Integer FirstJob, ;
Integer NoJobs, ;
Integer Level, ;
String @pJob, ;
Integer cbBuf, ;
Integer @pcbNeeded, ;
Integer @pcReturned
*****
the 4th parameter of this function is LEVEL. this will take the value 1.
The Level parameter passed in tells the API which kind of structure you want returned.

this is the structure of level 1

***** VB CODE to return the number of copies.

'\\ JOB_INFO_1 - Standard print job info
Private Type JOB_INFO_1
JobId As Long
lpPrinterName As String
lpMachinename As String
lpUserName As String
lpDocumentName As String
lpDataType As String
lpStatus As String
Status As PrintJobStatuses
Priority As Long
Position As Long
TotalPages As Long
PagesPrinted As Long
Submitted As SYSTEMTIME
End Type

Dim lRet As Long
Dim pcbSizeRequired As Long, pcbBytesReturned As Long
Dim buffer() As Long

ReDim Preserve buffer(0) As Long '\\ Allocate a 1 byte buffer

lRet = EnumJobs(mhPrinter, 0, 255, 1, buffer(0), UBound(buffer), pcbSizeRequired, pcbBytesReturned)

'\\ Need to resize our array to cope with this data
ReDim Preserve buffer(0 To (pcbSizeRequired / 4) + 3) As Long
lRet = EnumJobs(mhPrinter, 0, 255, 1, buffer(0), UBound(buffer) * 4, pcbSizeRequired, pcbBytesReturned)

Dim pJobId As Long
Dim JobIds() As Long

For pJobId = 0 To (pcbBytesReturned - 1)
Redim Preserve JobIds(pJobId) As Long
JobIds(pJobId) = buffer(pJobId * 16)
Next pJobId


Private Declare Function GetJob Lib "winspool.drv" Alias "GetJobA" _
(ByVal hPrinter As Long, _
ByVal JobId As Long, _
ByVal Level As Long, _
buffer As Long, _
ByVal pbSize As Long, _
pbSizeNeeded As Long) As Long

This takes the JobId as returned by the call to EnumJobs and returns the level 1 structure filled with the details of that queued print job.
Dim lRet As Long
Dim SizeNeeded As Long
Dim buffer() As Long

'\\ Get the required buffer size...
ReDim Preserve buffer(0 To 1) As Long
lRet = GetJob(mhPrinter, mJobId, 1, buffer(0), UBound(buffer), SizeNeeded)

If SizeNeeded > 0 Then
ReDim Preserve buffer(0 To (SizeNeeded / 4) + 3) As Long
lRet = GetJob(mhPrinter, mJobId, 1, buffer(0), UBound(buffer) * 4, SizeNeeded)
Dim mJOB_INFO_1 As JOB_INFO_1
'\\ Fill the JOB_INFO_1 structure from the buffer
With mJOB_INFO_1
.JobId = buffer(0)
.lpPrinterName = StringFromPointer(buffer(1), 1024)
.lpMachinename = StringFromPointer(buffer(2), 1024)
.lpUserName = StringFromPointer(buffer(3), 1024)
.lpDocumentName = StringFromPointer(buffer(4), 1024)
.lpDataType = StringFromPointer(buffer(5), 1024)
.lpStatus = StringFromPointer(buffer(6), 1024)
.Status = buffer(7)
.Priority = buffer(8)
.Position = buffer(9)
.TotalPages = buffer(10)
.PagesPrinted = buffer(11)
With .Submitted
.wYear = LoWord(buffer(12))
.wMonth = HiWord(buffer(12))
.wDayOfWeek = LoWord(buffer(13))
.wDay = HiWord(buffer(13))
.wHour = LoWord(buffer(14))
.wMinute = HiWord(buffer(14))
.wSecond = LoWord(buffer(15))
.wMilliseconds = HiWord(buffer(15))
End With
End With
End If
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform