删除打印任务:
uses Printers, WinSpool
// 删除打印任务
function RemoveJob(PrinterName: String;
JobId: DWORD): boolean;
var
hPrinter: THandle;
pd: PRINTER_DEFAULTS;
begin
// You need a printer handle, open the printer
pd.DesiredAccess := PRINTER_ALL_ACCESS;
pd.pDatatype := nil;
pd.pDevMode := nil;
// 打开打印机
if OpenPrinter(PChar(PrinterName),hPrinter,@pd) then
Result := SetJob( hPrinter, JobId, 0, nil, JOB_CONTROL_DELETE )
else
Result := false;
end;
//----------------------------------------------------------------------------
//使用示例
FPrinterName: string;
procedure TForm1.FormCreate(Sender: TObject);
begin
lbPrinters.Items.Assign(Printer.Printers);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
lbJobs.Items.Clear;
if lbPrinters.ItemIndex >= 0 then
begin
FPrinterName := lbPrinters.Items.Strings[lbPrinters.ItemIndex];
GetJobs(FPrinterName, lbJobs.Items )
end else
FPrinterName := '';
end;
procedure TForm1.Button2Click(Sender: TObject);
var
JobId: DWORD;
begin
if lbJobs.ItemIndex >= 0 then
begin
JobId := DWORD(lbJobs.Items.Objects[lbJobs.ItemIndex]);
if RemoveJob( FPrinterName, JobId ) then
begin
showMessage('删除打印机:' + FPrinterName +
'上的任务:' + lbJobs.Items.Strings[lbJobs.ItemIndex] + '成功');
GetJobs(FPrinterName, lbJobs.Items )
end else
showMessage('删除打印机:' + FPrinterName +
'上的任务:' + lbJobs.Items.Strings[lbJobs.ItemIndex] + '失败');
end;
end;
//------------------------------------------------------------------------------
// 取打印机当前任务见
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2451480