Getting the printers status
Uses WinSpool;
function GetCurrentPrinterStatus: DWORD;
var
hPrinter: THandle;
Device :
array[0..255]
of char;
Driver :
array[0..255]
of char;
Port :
array[0..255]
of char;
hDeviceMode: THandle;
bytesNeeded: Cardinal;
pPI: PPrinterInfo2;
Defaults: TPrinterDefaults;
begin
Assert( Printer.PrinterIndex >= 0 );
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
FillChar( Defaults, Sizeof(Defaults), 0 );
Defaults.DesiredAccess:=
{PRINTER_ACCESS_ADMINISTER or} PRINTER_ACCESS_USE;
Win32Check(WinSpool.OpenPrinter(@Device, hPrinter, @Defaults ));
try
WinSpool.GetPrinter(
hPrinter,
2,
Nil, 0, @bytesNeeded );
GetMem( pPI, bytesNeeded );
try
Win32Check(WinSpool.GetPrinter(
hPrinter, 2,
pPI, bytesNeeded, @bytesNeeded ));
Result := pPI^.Status;
finally
FreeMem( pPI );
end;
finally
WinSpool.ClosePrinter( hPrinter );
end;
end;
Check the
API docs
for PRINTER_INFO_2, it tells you what flags may
appear
in the status returned by this
function. You test
for the
presence
of a specfic flag via an expression like
if (Status
and PRINTER_STATUS_ERROR) <> 0
then