Lister les documents en cours d'impression

uses
Winspool, Printers;

function GetCurrentPrinterHandle: THandle;
var
Device, Driver, Port : array[0..255] of char;
hDeviceMode: THandle;
begin
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
if not OpenPrinter(@Device, Result, nil) then
RaiseLastWin32Error;
end;

Function SavePChar( p: PChar ): PChar;
const
error: PChar = 'Nil';
begin
if not Assigned(p) then
result := error
else
result := p;
end;

procedure TForm1.Button1Click(Sender: TObject);
type
TJobs = Array [0..1000] of JOB_INFO_1;
PJobs = ^TJobs;
var
hPrinter : THandle;
bytesNeeded, numJobs, i: Cardinal;
pJ: PJobs;
begin
hPrinter:= GetCurrentPrinterHandle;
try
EnumJobs(hPrinter, 0, 1000, 1, Nil, 0, bytesNeeded,
numJobs);
pJ := AllocMem(bytesNeeded);
If not EnumJobs(hPrinter, 0, 1000, 1, pJ, bytesNeeded,
bytesNeeded, numJobs)
Then
RaiseLastWin32Error;

memo1.clear;
if numJobs = 0 Then
memo1.lines.add('No jobs in queue')
else
For i:= 0 to Pred(numJobs) Do
memo1.lines.add( Format(
'Printer %s, Job %s, Status (%d): %s',
[SavePChar(pJ^[i].pPrinterName),
SavePChar(pJ^[i].pDocument), pJ^[i].Status, SavePChar(pJ^[i].pStatus)] ));
finally
ClosePrinter(hPrinter);
end;


end;
end.
Ajouter un commentaire
Pseudo
Adresse email
Site internet (optionnel)
Votre commentaire
Fiche de l'article
Mise a jour13/03/2002
VisualisationVu 826 fois
PublicInternaute zz
CategorieDelphi - Trucs et astuces - Systeme
Auteur de l'article
SwissDelphiCenter SwissDelphiCenter
connecté le 02/11/2011
329 articles dans la section
Contacter l'auteur