Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to stop and delete all print jobs through code Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
07-Oct-02
Category
Reporting /Printing
Language
Delphi 2.x
Views
139
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I can stop and delete current printing jobs from the "Printer Manager". Can I do it 
in my code, too? I want to stop all print jobs and delete them in my program.

Answer:

Try the PurgeJobsOnCurrentPrinter procedure given below. Not tested!

1   uses
2     winspool, printers;
3   
4   {GetCurrentPrinterHandle:
5   Retrieves the handle of the current printer and returns an API printer handle for 
6   the
7   current printer. Uses WinSpool.OpenPrinter to get a printer handle. The caller takes
8   ownership of the handle and must call ClosePrinter on it once the handle is no 
9   longer
10  needed. Failing to do that creates a serious resource leak! Raises EWin32Error if 
11  the
12  OpenPrinter call fails.}
13  
14  function GetCurrentPrinterHandle: THandle;
15  const
16    Defaults: TPrinterDefaults = (pDatatype: nil; pDevMode: nil; DesiredAccess:
17      PRINTER_ACCESS_USE or PRINTER_ACCESS_ADMINISTER);
18  var
19    Device, Driver, Port: array[0..255] of char;
20    hDeviceMode: THandle;
21  begin
22    Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
23    if not OpenPrinter(@Device, Result, @Defaults) then
24      RaiseLastWin32Error;
25  end;
26  
27  {Kill all pending jobs on the current printer}
28  
29  procedure PurgeJobsOnCurrentPrinter;
30  var
31    hPrinter: THandle;
32  begin
33    hPrinter := GetCurrentPrinterHandle;
34    try
35      if not WinSpool.SetPrinter(hPrinter, 0, nil, PRINTER_CONTROL_PURGE) then
36        RaiseLastWin32Error;
37    finally
38      ClosePrinter(hPrinter);
39    end;
40  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC