?
Solved

Determine if Printer Spooler is empty

Posted on 2000-01-28
13
Medium Priority
?
1,367 Views
Last Modified: 2010-04-04
How can I determine if the Printer Spooler is empty? I am using Delphi 4 on Windows NT 4 SP 6.
0
Comment
Question by:skymag
  • 4
  • 3
  • 3
  • +2
13 Comments
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2396354
If Printer.Printing then showmessage('Still working')
Else
  Showmessage('Ready for another job, boss!!');
 
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2396355
If Printer.Printing then showmessage('Still working')
Else
  Showmessage('Ready for another job, boss!!');
 
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2396357
Sorry, I seemed to have stuttered there! It's awfully c-c-c-cold here...<g>
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 

Author Comment

by:skymag
ID: 2396442
Hi there. Hehe, here it is very warm in Cape Town, South Africa. The printer is still printing and the Printer.Printing is already false and the print spooler is still showing the print job as well. Any ideas?
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2396480
Look at Windows.GetPrinter with level 2. In the status field of the level-2-structure you should get the printer status.
Or call EnumJobs.

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2396506
Oh, well, I realize now, that the status field in not too informational under winNT. So better use EnumJobs.
0
 

Author Comment

by:skymag
ID: 2396657
Hi Madshi

I am trying the following code and it doesn't want to work. Please give me some advice here.

function TPrinterManager.PrinterPrinting: Boolean;
var
  arJob: array [0..100] of JOB_INFO_1;
begin
  Result := False;
    if EnumJobs(hndPrinter, 0, 1, 1, @arJob,Sizeof(arJob), pcbNeeded, pcbReturned) then
       begin
         if arJob[0].Status = JOB_STATUS_PRINTING then
            Result := TRUE;
     end;
end;
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2396678
How about a more detailed error description  :-) ?
Does EnumJobs fail or does the status field not contain PRINTING?
If EnumJobs fails, please tell me the GetLastError value.

Regards, Madshi.
0
 

Author Comment

by:skymag
ID: 2396739
Hi Madshi, hehe, I must be getting tired here not to even tell you exactly what is happening. Look at my Procdeure. There you will see where I use prPrintMan.PrinterPrinting twice. The first time EnumJobs returns true and I am able to get the status. But the second time it EnumJobs returns false. The print job is still in the spooler but it is busy printing. The fisrt time however the printer is paused until I get the money for the continue printing.


procedure TfMain.giPrintClick(Sender: TObject);
var
  prPrintMan: TPrinterManager;
  vPages: Integer;
begin
  { Check to see if there is a printer driver installed }
  if Printer.Printers.Count = 0 then
     begin
       ShowMessage('Sorry, there is no Printer on this particular CyberXpress.');
       Exit;
     end;

  try
    ActivityManager.SetFreeSite(vFreeSite);
    ActivityManager.ResetTimer;

    giPrint.Enabled := False;

    if not vFreeSite then
       MoneyTimer.Enabled := False;

    fPrintInfo.lPrintInfo.Caption := 'Calculating print costs';
    fPrintInfo.Show;
    Application.ProcessMessages;

    prPrintMan := TPrinterManager.Create();
    prPrintMan.CancelPrinting;
    prPrintMan.ReadyForPrinting;
    lStatusBar.Caption := 'Printing Page ...';
    InvokeOleCMD(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER);

    vPages := 0;
    while vPages = 0 do begin
      Application.ProcessMessages;
      vPages := prPrintMan.FindPages;
    end;

    if prPrintMan.PrinterPrinting then
       ShowMessage('Printing ....');

    fPrintInfo.Close;

    CollectPrintMoney(vPages * 100);

    { Show Printing Progress }
    fPrintInfo.lPrintInfo.Caption := 'Printing Current Page ...';
    fPrintInfo.Show;
    Application.ProcessMessages;

    if vMoneyCollectOk then
       prPrintMan.DoPrinting
    else
       prPrintMan.CancelPrinting;

    if not vFreeSite then
       MoneyTimer.Enabled := True;

    prPrintMan.Free;
  finally
    giPrint.Enabled := True;

    { Close Printing Progress }
    while prPrintMan.PrinterPrinting do
          begin
            Beep;
            Application.ProcessMessages;
          end;
  end;
end;

I hope this makes sense to you. The { Close Printing Progress } there is a beep which is just my test for now.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2396755
Okay, please tell me GetLastError, after EnumJobs failed.
0
 
LVL 17

Expert Comment

by:inthe
ID: 2396760
from borland support:

Article #16727: Detecting how many jobs are in the print spooler

 Question and Answer Database

FAQ1727D.txt   Detecting how many jobs are in the print spooler
Category   :Windows API
Platform    :All
Product    :All 32 bit  

Question:
Is there any way to detect how many jobs are in the Windows print
spooler at any given time?


Answer:
The Windows print spooler regularly broadcasts a system wide
WM_SPOOLERSTATUS message each time a job is added or deleted from the
spooler que. The following example demonstrates trapping for this
message.

Example:

type
  TForm1 = class(TForm)
    Label1: TLabel;
  private
    { Private declarations }
    procedure WM_SpoolerStatus(var Msg : TWMSPOOLERSTATUS);
      message WM_SPOOLERSTATUS;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WM_SpoolerStatus(var Msg : TWMSPOOLERSTATUS);
begin
  Lable1.Caption := IntToStr(msg.JobsLeft) +
                    ' Jobs currenly in spooler';
  msg.Result := 0;
end;

Regards Barry
0
 
LVL 2

Expert Comment

by:PeterLarsen
ID: 2397045
Listening..
0
 
LVL 17

Accepted Solution

by:
inthe earned 100 total points
ID: 2445483
answered in comment above..
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Suggested Courses
Course of the Month5 days, 18 hours left to enroll

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question