关于当前打印任务

zjl317 2003-09-02 08:58:53
1、怎样知道当前正在打印的打印任务已完成打印的百分比?
2、怎样知道当前打印任务已完成打印?

...全文
35 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Drate 2003-09-03
  • 打赏
  • 举报
回复
获取打印机的文档状态

其中主要程序如下:

type

TMainFrm = class(TForm)

Pages: TPageControl;

PrinterSht: TTabSheet;

PrinterLst: TListBox;

...

private

procedure SpollerStatus(var Msg:TWMSpoolerStatus); message WM_SPOOLERSTATUS;

...

uses

WinSpool, ExtCtrls;

procedure TMainFrm.SpollerStatus(var Msg:TWMSpoolerStatus);

var

tbt:Byte;

Needed,Returned:DWORD;

ResultBuffer:Pointer;

i,x,Count:Integer;

Pi:PJobInfo1;

hPrinter:THandle;

List:TListBox;

Lbl:TLabel;

begin

for i:=1 to Pages.PageCount-1 do begin

hPrinter:=Pages.Pages[i].Tag;

List:=Pages.Pages[i].Controls[0] as TListBox;

Lbl:=((Pages.Pages[i].Controls[1] as TPanel)

.Controls[0] as TLabel);

List.Clear;

EnumJobs(hPrinter,0,Msg.JobsLeft,1,@tbt,0,Needed,Returned);

if Needed=0 then begin

Lbl.Caption:='0 个作业';

Continue;

end;

Count:=Needed;

if Count<=0 then begin

Lbl.Caption:='0 个作业';

Continue;

end;

GetMem(ResultBuffer,Count);

try

EnumJobs(hPrinter,0,Msg.JobsLeft,1,ResultBuffer,Needed,Needed,Returned);

if Returned>Msg.JobsLeft then begin

Lbl.Caption:='0 个作业';

Continue;

end;

Lbl.Caption:=IntToStr(Returned)+' 个作业';

Pi:=ResultBuffer;

for x:=0 to Returned-1 do begin

List.Items.Add(Pi^.pDocument);

Pi:=PJobInfo1(LongInt(Pi)+Sizeof(Pi^));

end;

finally

FreeMem(ResultBuffer,Count);

end;

end;

Msg.Result:=0;

end;

procedure TMainFrm.FormCreate(Sender: TObject);

var

tbt:Byte;

Needed,Returned:DWORD;

ResultBuffer:Pointer;

x,Count:Integer;

Pi:PPrinterInfo1;

Sheet:TTabSheet;

hPrinter:THandle;

Panel:TPanel;

begin

PrinterLst.Clear;

EnumPrinters(PRINTER_ENUM_LOCAL,'',1,@tbt,0,Needed,Returned);

if Needed=0 then Exit;

Count:=Needed;

GetMem(ResultBuffer,Count);

EnumPrinters(PRINTER_ENUM_LOCAL,'',1,ResultBuffer,Needed,Needed,Returned);

Pi:=ResultBuffer;

for x:=0 to Returned-1 do begin

PrinterLst.Items.Add(Pi^.pName);

Pi:=PPrinterInfo1(LongInt(Pi)+Sizeof(Pi^));

Sheet:=TTabSheet.Create(Self);

with Sheet do begin

PageControl:=Pages;

Caption:=PrinterLst.Items[PrinterLst.Items.Count-1];

OpenPrinter(PChar(Caption),hPrinter,nil);

Tag:=hPrinter;

ClosePrinter(hPrinter);

with TListBox.Create(Self) do begin

Parent:=Sheet;

Align:=alClient;

end;

Panel:=TPanel.Create(Self);

with Panel do begin

Parent:=Sheet;

Align:=alTop;

Height:=20;

BevelOuter:=bvNone;

end;

with TLabel.Create(Self) do begin

Parent:=Panel;

Left:=10;

Top:=3;

Caption:='0 个作业';

end;

end;

end;

FreeMem(ResultBuffer,Count);

end;

procedure TMainFrm.FormDestroy(Sender: TObject);

var

i,j:Integer;

begin

for i:=1 to Pages.PageCount-1 do

with Pages.Pages[i] do begin

((Controls[1] as TPanel).Controls[0] as TLabel).Free;

for j:=0 to ControlCount-1 do

Controls[0].Free;

Free;

end;

end;





---有这两篇 文章 ,我想应该就差不多行了吧
Drate 2003-09-03
  • 打赏
  • 举报
回复
获取打印机的打印任务列表

如何在程序里判断一个打印作业已经进入打印队列(也就是可以在打印管理程序里看到该作业的信息),或者说如何察看打印队列里已有的作业信息?

看下面的这个例程。还有测试代码。

uses WinSpool;

type JOB_INFO_1_ARRAY = Array of JOB_INFO_1;

Function GetSpoolerJobs(sPrinterName : String) : JOB_INFO_1_ARRAY;

var

i : Integer;

hPrinter : THandle;

bResult : Boolean;

cbBuf : DWORD;

pcbNeeded : DWORD;

pcReturned : DWORD;

aJobs : Array[0..99] of JOB_INFO_1;

begin

cbBuf := 1000;

bResult := OpenPrinter(PChar(sPrinterName), hPrinter, Nil);

if NOT bResult then begin

ShowMessage('Error opening the printer');

exit;

end;

bResult := EnumJobs(hPrinter,0,Length(aJobs),1,@aJobs,cbBuf,pcbNeeded,pcReturned);

if NOT bResult then begin

ShowMessage('Error Getting Jobs information');

exit;

end;

for i:=0 to pcReturned-1 do begin

if aJobs[i].pDocument <> Nil then begin

SetLength(Result, Length(Result)+1);

Result[Length(Result)-1] := aJobs[i];

end;

end;

end;

测试例子:

1- 创建工程有 StringGrid 和一个 Timer.

2- StringGrid 'ColCount' and “RowCount” 值为 20

3- Timer的 “Interval” 属性值 500.

4- “OnTime” 实践中写这个代码

procedure TForm1.Timer1Timer(Sender: TObject);

var

i, ii : Integer;

aJobs : JOB_INFO_1_ARRAY;

begin

for i:=0 to StringGrid1.ColCount-1 do

for ii:=0 to StringGrid1.RowCount-1 do StringGrid1.Cells[i,ii] := '';

aJobs := GetSpoolerJobs('\ibmserverLaserJet 1100');//正在打印的打印机名字,这里我的打印机时网打。这里你要自己改

for i:=0 to Length(aJobs)-1 do begin

StringGrid1.Cells[i,0] := aJobs[i].pPrinterName;

StringGrid1.Cells[i,1] := aJobs[i].pMachineName;

StringGrid1.Cells[i,2] := aJobs[i].pUserName;

StringGrid1.Cells[i,3] := aJobs[i].pDocument;

StringGrid1.Cells[i,4] := aJobs[i].pDatatype;

StringGrid1.Cells[i,5] := aJobs[i].pStatus;

StringGrid1.Cells[i,6] := IntToStr(aJobs[i].Status);

case aJobs[i].Status of

JOB_STATUS_PAUSED: StringGrid1.Cells[i,6] := 'JOB_STATUS_PAUSED';

JOB_STATUS_ERROR: StringGrid1.Cells[i,6] := 'JOB_STATUS_ERROR';

JOB_STATUS_DELETING: StringGrid1.Cells[i,6] := 'JOB_STATUS_DELETING';

JOB_STATUS_SPOOLING: StringGrid1.Cells[i,6] := 'JOB_STATUS_SPOOLING';

JOB_STATUS_PRINTING: StringGrid1.Cells[i,6] := 'JOB_STATUS_PRINTING';

JOB_STATUS_OFFLINE: StringGrid1.Cells[i,6] := 'JOB_STATUS_OFFLINE';

JOB_STATUS_PAPEROUT: StringGrid1.Cells[i,6] := 'JOB_STATUS_PAPEROUT';

JOB_STATUS_PRINTED: StringGrid1.Cells[i,6] := 'JOB_STATUS_PRINTED';

JOB_STATUS_DELETED: StringGrid1.Cells[i,6] := 'JOB_STATUS_DELETED';

JOB_STATUS_BLOCKED_DEVQ: StringGrid1.Cells[i,6] := 'JOB_STATUS_BLOCKED_DEVQ';

JOB_STATUS_USER_INTERVENTION: StringGrid1.Cells[i,6] := 'JOB_STATUS_USER_INTERVENTION';

JOB_STATUS_RESTART: StringGrid1.Cells[i,6] := 'JOB_STATUS_RESTART';

JOB_POSITION_UNSPECIFIED: StringGrid1.Cells[i,6] := 'JOB_POSITION_UNSPECIFIED';

else StringGrid1.Cells[i,6] := 'Unknown status...';

end;

end;

StringGrid1.Refresh;

end;

5- 运行程序,打印程序测之

 

OK,用上面的程序就可以完成你的任务了



zjl317 2003-09-03
  • 打赏
  • 举报
回复
晕,没人知道?
zjl317 2003-09-02
  • 打赏
  • 举报
回复
我知道难度很大,唉,自己UP

5,391

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧