unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Printers, WinSpool,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
function 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 GetJobs(PrinterName: String; JobList: TStrings);
const
InfoLevel = 1;
FirstJob = 0;
LastJob = 19;
var
Jobs: array [FirstJob..LastJob] of TJobInfo1;
PrinterHandle, BytesNeeded, I, NumJobs:cardinal;// Integer;
begin
if OpenPrinter(PChar(PrinterName),PrinterHandle,nil) then begin
if
EnumJobs(PrinterHandle,FirstJob,LastJob+1,InfoLevel,@Jobs,SizeOf(Jobs),BytesNeeded,NumJobs) then begin
JobList.Clear;
for I := 0 to NumJobs-1 do
with Jobs[I] do
JobList.Add(Format('%s(%s)',[StrPas(pDocument),PrinterStatusText(Status)]));
end;
ClosePrinter(PrinterHandle);
end;
end;
begin
GetJobs('hp deskjet 3500 series',Memo1.Lines);
end;
end.
delphi编程获取打印机的打印任务列表
最新推荐文章于 2022-02-23 13:21:14 发布