function TPrintMai_frm.getjob(): integer;
var
Needed, Returned: DWORD;
i, Count: integer;
tbt: byte;
pNeeded: PDword;
P2: PJobInfo1;
PPI: pPRINTERINFO2;
Printer: TPrinter;
Device, Driver, Port: array[0..255] of Char;
PPr, DevMode: Cardinal;
hPrinter: THandle;
begin
result := 0;
Printer := TPrinter.Create;
//创建Printer对象
try
Printer.GetPrinter(Device, Driver, Port, DevMode);
//取得打印机的名称,驱动程序,端口号
if not OpenPrinter(@device, hPrinter, nil) then
//取得打印机的句柄
begin
ShowMessage('OpenPrinter' + SysErrorMessage(GetLastError));
//Exit;
end;
PNeeded := AllocMem(8024);
//分配内存空间
P2 := AllocMem(8048);
PPI := AllocMem(8048);
//接受打印机信息结构
if not GetPrinter(hPrinter, 2, PPI, 8048, PNeeded) then
//取得打印机队列中的任务数
begin
ShowMessage('GetPrinter' + SysErrorMessage(GetLastError));
end;
//取得打印机状态
if Enumjobs(hPrinter, 0, 1, 2, p2, 8048, Needed, Returned) then
begin
if P2.JobId = 0 then
result := 0;
if P2.JobId > 0 then
begin
result := PPI.cJobs;
end
end
else
ShowMessage('Enumjobs' + SysErrorMessage(GetLastError));
//关闭打印机,释放内存空间
finally
FreeMem(PNeeded);
FreeMem(p2);
FreeMem(PPI);
Printer.Free;
ClosePrinter(hPrinter);
end;
end;
//我用这个法子检测打印机中还有没有打印任务,你参考一下吧