Determine if Printer Spooler is empty

How can I determine if the Printer Spooler is empty? I am using Delphi 4 on Windows NT 4 SP 6.
skymagAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DrDelphiCommented:
If Printer.Printing then showmessage('Still working')
Else
  Showmessage('Ready for another job, boss!!');
 
0
DrDelphiCommented:
If Printer.Printing then showmessage('Still working')
Else
  Showmessage('Ready for another job, boss!!');
 
0
DrDelphiCommented:
Sorry, I seemed to have stuttered there! It's awfully c-c-c-cold here...<g>
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

skymagAuthor Commented:
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
MadshiCommented:
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
MadshiCommented:
Oh, well, I realize now, that the status field in not too informational under winNT. So better use EnumJobs.
0
skymagAuthor Commented:
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
MadshiCommented:
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
skymagAuthor Commented:
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
MadshiCommented:
Okay, please tell me GetLastError, after EnumJobs failed.
0
intheCommented:
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
PeterLarsenCommented:
Listening..
0
intheCommented:
answered in comment above..
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.