Procedure TForm1.GetJobs(PrinterName: String;
JobList: TStrings);
Const
InfoLevel = 1;
FirstJob = 0;
LastJob = 19;
Var
Jobs: Array[FirstJob..LastJob] Of TJobInfo1;
BytesNeeded, I, NumJobs: Dword;
PrinterHandle : THandle;
begin
If OpenPrinter(PChar(PrinterName), PrinterHandle, Nil) then
begin
If
EnumJobs(PrinterHandle, FirstJob, LastJob, InfoLevel, @Jobs, SizeOf(Jobs), BytesNeeded, NumJobs) then
begin
if Numjobs=0 then
begin
showmessage('当前打印机没有打印任务!');
exit;
end;
JobList.Clear;
For I := 0 To NumJobs - 1do
With Jobsdo
JobList.Add(Format('%s(%s)',[StrPas(pDocument),PrinterStatusText(Status)]));
end;
ClosePrinter(PrinterHandle);
end;
end;
Function TForm1.PrinterStatusText(Status: Integer): String;
begin
Case Status Of
0: Result := 'Waiting';
JOB_STATUS_PAUSED: Result := 'Paused';
JOB_STATUS_ERROR: Result := 'Error';
JOB_STATUS_DELETING: Result := 'Deleting';
JOB_STATUS_SPOOLING: Result := 'Spooling';
JOB_STATUS_PRINTING: Result := 'Printing';
JOB_STATUS_OFFLINE: Result := 'Offline';
JOB_STATUS_PAPEROUT: Result := 'Paper Out';
JOB_STATUS_PRINTED: Result := 'Printed';
JOB_STATUS_DELETED: Result := 'Deleted';
JOB_STATUS_BLOCKED_DEVQ: Result := 'Blocked';
JOB_STATUS_USER_INTERVENTION: Result := 'User Intervention';
JOB_STATUS_RESTART: Result := 'Restart';
else
Result := 'Status ' + IntToStr(Status);
end;
end;
Procedure TForm1.Button2Click(Sender: TObject);
begin
GetJobs('HP Laserjet 6P', Memo1.Lines);
end;