感谢您使用微软产品。您可以使用API函数EnumJobs通过打印机上的任务信息,包括文件名,文件来源的机器名和打印的页数,EnumJobs把这些信息存储在JOB_INFO_1结构中。代码中还将用到OpenPrinter,ClosePrinter,CopyMemory等API函数对打印机和内存进行相关操作。如下例: Private Sub Command1_Click()
Dim pd As PRINTER_DEFAULTS
Dim baBuffer() As Byte
Dim udtJOB_INFO_1 As JOB_INFO_1
pd.pDevMode = 0
pd.pDatatype = vbNullString
pd.DesiredAccess = PRINTER_ACCESS_USE nzResult = OpenPrinter(Combo1.List(Combo1.ListIndex), hPrinter, pd)
If nzResult = 0 Then Exit Sub
End If
'First you call EnumJobs() to find out how much memory you need
nzResult = EnumJobs(hPrinter, 0, &HFFFFFFFF, 1, ByVal 0&, 0, dwNeeded,
dwReturned)
If nzResult = 0 And Err.LastDllError <> ERROR_INSUFFICIENT_BUFFER Then
ClosePrinter hPrinter
Exit Sub
End If
If dwNeeded = 0 Then
Text1 = "There are no jobs on this printer"
Exit Sub
End If
'Allocate enough memory for the JOB_INFO_1 structures plus
'the extra data - dwNeeded from the previous call tells you
'the total size needed
ReDim baBuffer(dwNeeded - 1) As Byte
'Call EnumJobs() again and let it fill out our structures
If EnumJobs(hPrinter, 0, &HFFFFFFFF, 1, baBuffer(0), dwNeeded,
dwNeeded, dwReturned) = False Then
ClosePrinter hPrinter
Exit Sub
End If
ClosePrinter hPrinter
Text1 = ""
'Loop through the jobs and access each one
For i = 0 To dwReturned - 1
'Copy data from buffer into JOB_INFO_1 structure
CopyMemory udtJOB_INFO_1, baBuffer(i * LenB(udtJOB_INFO_1)),
LenB(udtJOB_INFO_1)
With udtJOB_INFO_1
Text1 = Text1 & StringFromPointer(.pDocument) & " : " & .TotalPages
End With
Next
End Sub
Public Function StringFromPointer(ByVal lpString As Long) As String
Dim s As String
s = String$(255, vbNullChar)
lstrcpy s, lpString
StringFromPointer = Left$(s, InStr(s, vbNullChar) - 1)
End FunctionEnumJobs的详细信息请参考:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_2cj7.asp纸张大小可通过函数DocumentProperties获得
下面的链接提供了详细信息和示例代码。
DocumentProperties
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_7k1f.asp
Q180645 FIX: Cannot Change Page Settings During Print Job
http://support.microsoft.com/support/kb/articles/q180/6/45.asp- 微软全球技术中心 VB技术支持本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查
(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
Dim pd As PRINTER_DEFAULTS
Dim baBuffer() As Byte
Dim udtJOB_INFO_1 As JOB_INFO_1
pd.pDevMode = 0
pd.pDatatype = vbNullString
pd.DesiredAccess = PRINTER_ACCESS_USE nzResult = OpenPrinter(Combo1.List(Combo1.ListIndex), hPrinter, pd)
If nzResult = 0 Then Exit Sub
End If
'First you call EnumJobs() to find out how much memory you need
nzResult = EnumJobs(hPrinter, 0, &HFFFFFFFF, 1, ByVal 0&, 0, dwNeeded,
dwReturned)
If nzResult = 0 And Err.LastDllError <> ERROR_INSUFFICIENT_BUFFER Then
ClosePrinter hPrinter
Exit Sub
End If
If dwNeeded = 0 Then
Text1 = "There are no jobs on this printer"
Exit Sub
End If
'Allocate enough memory for the JOB_INFO_1 structures plus
'the extra data - dwNeeded from the previous call tells you
'the total size needed
ReDim baBuffer(dwNeeded - 1) As Byte
'Call EnumJobs() again and let it fill out our structures
If EnumJobs(hPrinter, 0, &HFFFFFFFF, 1, baBuffer(0), dwNeeded,
dwNeeded, dwReturned) = False Then
ClosePrinter hPrinter
Exit Sub
End If
ClosePrinter hPrinter
Text1 = ""
'Loop through the jobs and access each one
For i = 0 To dwReturned - 1
'Copy data from buffer into JOB_INFO_1 structure
CopyMemory udtJOB_INFO_1, baBuffer(i * LenB(udtJOB_INFO_1)),
LenB(udtJOB_INFO_1)
With udtJOB_INFO_1
Text1 = Text1 & StringFromPointer(.pDocument) & " : " & .TotalPages
End With
Next
End Sub
Public Function StringFromPointer(ByVal lpString As Long) As String
Dim s As String
s = String$(255, vbNullChar)
lstrcpy s, lpString
StringFromPointer = Left$(s, InStr(s, vbNullChar) - 1)
End FunctionEnumJobs的详细信息请参考:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_2cj7.asp纸张大小可通过函数DocumentProperties获得
下面的链接提供了详细信息和示例代码。
DocumentProperties
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_7k1f.asp
Q180645 FIX: Cannot Change Page Settings During Print Job
http://support.microsoft.com/support/kb/articles/q180/6/45.asp- 微软全球技术中心 VB技术支持本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查
(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货