Beranda > Delphi > Monitoring a printer with Delphi

Monitoring a printer with Delphi

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls;

type
TForm1 = class(TForm)
ListView1: TListView;
PrinterSetupDialog1: TPrinterSetupDialog;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
uses
WinSpool, Printers;

procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
j, k: cardinal;
pi: TJobInfo1;
ph: Thandle;
a: array [0..1024] of Char;
b: array [0..1024] of Char;
c: array [0..1024] of Char;
begin
if not PrinterSetupDialog1.Execute then
Exit;
Printer.GetPrinter(@a[0],@b[0],@c[0]

,j);
i:=0;
j:=0;
k:=0;
ph:=0;
if OpenPrinter(@a[0],ph,nil) then                               // Here
raise Exception.Create(‘Can”t access printer’);
while EnumJobs(ph,i,1,1,@pi,sizeof(pi),j,k) do
with ListView1.Items.Add do
begin
Caption:=’Job #’+IntToStr(i);
with SubItems do
begin
Add(pi.pPrinterName);
Add(pi.pMachineName);
Add(pi.pUserName);
Add(pi.pDocument);
case pi.Status of
JOB_STATUS_PRINTING:
Add(‘PRINTING’);
JOB_STATUS_DELETING:
Add(‘DELETING’);
JOB_STATUS_PAUSED:
Add(‘PAUSED’);
JOB_STATUS_SPOOLING:
Add(‘SPOOLING’);
JOB_STATUS_ERROR:
Add(‘ERROR’);
JOB_STATUS_OFFLINE:
Add(‘OFFLINE’);
JOB_STATUS_PAPEROUT:
Add(‘PAPEROUT’);
JOB_STATUS_PRINTED:
Add(‘PRINTED’);
JOB_STATUS_DELETED:
Add(‘DELETED’);
JOB_STATUS_RESTART:
Add(‘RESTART’);
else
Add(‘Other/Unknown’);
end;
Add(IntToStr(pi.PagesPrinted)+’/’+IntToStr(pi.TotalPages));
end;
Inc(i);
if i>10 then
break;
end;
ClosePrinter(ph);
end;

end.

Iklan
Kategori:Delphi
  1. Belum ada komentar.
  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: