// mainunit
if GetNPrinterJobs= 0
then
ShellExecute(
Handle, '
printto', PChar(documentname), PChar(S),
nil, SW_HIDE);
end;
// diese functionen stehen in der fncunit
function GetNPrinterJobs : Integer;
type
TJobs =
array [0..1000]
of JOB_INFO_1;
PJobs = ^TJobs;
var
hPrinter: THandle;
bytesNeeded, numJobs, i: Cardinal;
pJ: PJobs;
begin
Result := 0;
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;
Result := numJobs;
finally
ClosePrinter(hPrinter);
end;
Freemem(Pj);
end;
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;