打印机状态问题(200分)

  • 主题发起人 主题发起人 chenqg
  • 开始时间 开始时间
C

chenqg

Unregistered / Unconfirmed
GUEST, unregistred user!
我用下列函数编写监视打印机状态的程序,但好像只能监视系统打印缓冲区的打印任务。
即打印任务提交打印机后,即使没有完成打印,程序也提示“no job”。
如何监视打印机的打印任务是否完成,而不是即使打印缓冲区?急判大侠解答!
=======================================
OpenPrinter 或取指定的打印机(或打印服务器)的句柄
GetJob 获取指定打印机的打印作业
EnumPrinters 列举可用的打印机
EnumJobs 初始化一个JOB_INFO_1或JOB_INFO_2结构数组
-------来自hubdog的葵花宝典:枚举打印机缓冲池打印任务----------------
uses Printers, WinSpool;
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: Integer;
begin
if OpenPrinter(PChar(PrinterName),PrinterHandle,nil) then
begin
if
EnumJobs(PrinterHandle,FirstJob,LastJob 1,InfoLevel,@Jobs,SizeOf(Jobs),BytesNeed
ed,NumJobs) then
begin
JobList.Clear;
for I := 0 to NumJobs-1do
with Jobsdo
JobList.Add(Format('%s
(%s)',[StrPas(pDocument),PrinterStatusText(Status)]));
end;
ClosePrinter(PrinterHandle);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
GetJobs('HP Laserjet 4P',Memo1.Lines);
end;
 
不知道管用不,你看看
function CheckPrinter:boolean;
var
temp:byte;
begin

temp:=GetPrinterStatus;
Result:=not ( ((temp and $80)=0) //打印机忙
or ((temp and $20)<>0) //打印机缺纸
or ((temp and $10)=0) //打印机未联机
or ((temp and $08)=0) );
//打印机出错;
end;
 
我也想知道
 
后退
顶部