Date: Sat, 22 Sep 2001 11:54:41 +0200 Newsgroups: borland.public.delphi.winapi Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Newsreader: Virtual Access by Atlantic Coast PLC, http://www.atlantic-coast.com/va Organization: TeamB Message-ID: Subject: Re: Stop printing job. From: "Peter Below (TeamB)" <100113.1101@compuXXserve.com> Reply-To: 100113.1101@compuXXserve.com References: <3babfab6_1@dnews> NNTP-Posting-Host: 62.226.188.5 X-Trace: dnews 1001152368 62.226.188.5 (22 Sep 2001 02:52:48 -0700) Lines: 54 Path: dnews Xref: dnews borland.public.delphi.winapi:147277 In article <3babfab6_1@dnews>, Samson Fu wrote: > We can stop and delete current printing job from "Printer manager". > Can I do it in my code? I want to STOP all "print jobs" and Delete them in > my program. Try the PurgeJobsOnCurrentPrinter procedure given below. Not tested! Uses Winspool, printers; {-- GetCurrentPrinterHandle -------------------------------------------} {: Retrieves the handle of the current printer @Returns an API printer handle for the current printer @Desc Uses WinSpool.OpenPrinter to get a printer handle. The caller takes ownership of the handle and must call ClosePrinter on it once the handle is no longer needed. Failing to do that creates a serious resource leak!

Requires Printers and WinSpool in the Uses clause. @Raises EWin32Error if the OpenPrinter call fails. }{ Created 30.9.2000 by P. Below -----------------------------------------------------------------------} Function GetCurrentPrinterHandle: THandle; Const Defaults: TPrinterDefaults = ( pDatatype : nil; pDevMode : nil; DesiredAccess : PRINTER_ACCESS_USE or PRINTER_ACCESS_ADMINISTER ); Var Device, Driver, Port : array[0..255] of char; hDeviceMode: THandle; Begin { GetCurrentPrinterHandle } Printer.GetPrinter(Device, Driver, Port, hDeviceMode); If not OpenPrinter(@Device, Result, @Defaults) Then RaiseLastWin32Error; End; { GetCurrentPrinterHandle } {: Kill all pending jobs on the current printer } Procedure PurgeJobsOnCurrentPrinter; Var hPrinter: THandle; Begin hPrinter:= GetCurrentPrinterHandle; try If not WinSpool.SetPrinter( hPrinter, 0, nil, PRINTER_CONTROL_PURGE ) Then RaiseLastWin32Error; finally ClosePrinter( hPrinter ); end; End; { PurgeJobsOnCurrentPrinter } Peter Below (TeamB) 100113.1101@compuserve.com) No e-mail responses, please, unless explicitly requested! Note: I'm unable to visit the newsgroups every day at the moment, so be patient if you don't get a reply immediately.