当前位置:主页>仓库管理软件> 列表

EnumJobs取不到打印页数?(内附程序) 找qq软件管理

进销存软件版1楼: 以下程序取到的页数TotalPages始终为0,为什么?
function TGetJobsNT.GetJob: string;
const
InfoLevel = 1;
FirstJob = 0;
LastJob = 19;
var
Jobs: array[FirstJob..LastJob] of TJobInfo1;
BytesNeeded, NumJobs: Dword;
hPrinter: THandle;
JobsRecord: string;
begin
JobsRecord := '''';
if OpenPrinter(Pchar(FPrinterName), hPrinter, nil) then
begin
WaitForPrinterChange(hPrinter, PRINTER_CHANGE_ADD_JOB);
if EnumJobs(hPrinter, FirstJob, LastJob + 1, InfoLevel, @Jobs, SizeOf(Jobs),
BytesNeeded, NumJobs) then
begin
if NumJobs <> 0 then
begin
with Jobs[NumJobs - 1] do
begin
JobsRecord := JobsRecord + StrPas(pDocument) + #9;
JobsRecord := JobsRecord + StrPas(pPrinterName) + #9;
JobsRecord := JobsRecord + StrPas(pMachineName) + #9;
JobsRecord := JobsRecord + StrPas(pUserName) + #9;
JobsRecord := JobsRecord + IntToStr(TotalPages) + #9;
JobsRecord := JobsRecord +
DateTimeToStr(SystemTimeToDateTime(Submitted) + 8 / 24) + #9;
end;
end;
end;
ClosePrinter(hPrinter);
end;
Result := JobsRecord;
end;

2楼: 使用定时器。
执行一下你的程序。试试,如果还是零,程序错误。估计是打印机读取不正确。
名称不对。 如qq软件管理

3楼: TO:蓝叶菱
  程序能对打印任务做出反应,只是不能正确得到页数。
  

4楼: 我怎么没有遇见过,
以前好像也有过,不过我用定时器,每秒都读取页数,结果是正确的。

5楼: TO:蓝叶菱
 用定时器反复测试之后,已经能够取到页数了。
虽然稳定性不高,同一个任务有时会取到很多条,但你的分是少不了了。
请到这里取分:http://www.delphibbs.com/delphibbs/dispq.asp?lid=3378581

在这里还想同大家讨论一下
WaitForPrinterChange(hPrinter, PRINTER_CHANGE_ADD_JOB);
理论上这样触发程序应该是更科学的,但是为什么之后取不到页数。

6楼: 以前也要写这类程序。当时,朋友建议我使用,FindFirstPrinterChangeNotification这个东东~~

进销存软件版7楼: 帮你顶一下吧 呵呵 

8楼: 学习