EnumJobs取不到打印页数?(内附程序)(50分)

  • 主题发起人 主题发起人 king.gray
  • 开始时间 开始时间
K

king.gray

Unregistered / Unconfirmed
GUEST, unregistred user!
以下程序取到的页数TotalPages始终为0,为什么?<br>function TGetJobsNT.GetJob: string;<br>const<br> &nbsp;InfoLevel = 1;<br> &nbsp;FirstJob = 0;<br> &nbsp;LastJob = 19;<br>var<br> &nbsp;Jobs: array[FirstJob..LastJob] of TJobInfo1;<br> &nbsp;BytesNeeded, NumJobs: Dword;<br> &nbsp;hPrinter: THandle;<br> &nbsp;JobsRecord: string;<br>begin<br> &nbsp;JobsRecord := '';<br> &nbsp;if OpenPrinter(Pchar(FPrinterName), hPrinter, nil) then<br> &nbsp;begin<br> &nbsp; &nbsp;WaitForPrinterChange(hPrinter, PRINTER_CHANGE_ADD_JOB);<br> &nbsp; &nbsp;if EnumJobs(hPrinter, FirstJob, LastJob + 1, InfoLevel, @Jobs, SizeOf(Jobs),<br> &nbsp; &nbsp; &nbsp;BytesNeeded, NumJobs) then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;if NumJobs &lt;&gt; 0 then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;with Jobs[NumJobs - 1] do<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JobsRecord := JobsRecord + StrPas(pDocument) + #9;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JobsRecord := JobsRecord + StrPas(pPrinterName) + #9;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JobsRecord := JobsRecord + StrPas(pMachineName) + #9;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JobsRecord := JobsRecord + StrPas(pUserName) + #9;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JobsRecord := JobsRecord + IntToStr(TotalPages) + #9;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;JobsRecord := JobsRecord +<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DateTimeToStr(SystemTimeToDateTime(Submitted) + 8 / 24) + #9;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;ClosePrinter(hPrinter);<br> &nbsp;end;<br> &nbsp;Result := JobsRecord;<br>end;
 
使用定时器。<br> &nbsp; 执行一下你的程序。试试,如果还是零,程序错误。估计是打印机读取不正确。<br>名称不对。
 
TO:蓝叶菱<br>  程序能对打印任务做出反应,只是不能正确得到页数。<br>  
 
我怎么没有遇见过,<br> &nbsp;以前好像也有过,不过我用定时器,每秒都读取页数,结果是正确的。
 
TO:蓝叶菱<br> 用定时器反复测试之后,已经能够取到页数了。<br>虽然稳定性不高,同一个任务有时会取到很多条,但你的分是少不了了。<br>请到这里取分:http://www.delphibbs.com/delphibbs/dispq.asp?lid=3378581<br><br>在这里还想同大家讨论一下<br>WaitForPrinterChange(hPrinter, PRINTER_CHANGE_ADD_JOB);<br>理论上这样触发程序应该是更科学的,但是为什么之后取不到页数。
 
以前也要写这类程序。当时,朋友建议我使用,FindFirstPrinterChangeNotification这个东东~~
 
帮你顶一下吧 呵呵 
 
后退
顶部