Solved

Info on WINSPOOL.PAS

Posted on 1998-09-18
6
1,355 Views
Last Modified: 2009-07-31
I need to count the pages printed from a PC. Printing is done from delphi applications I wrote, so I have control of th e print button.  The problem is that some of the printing is done from a WebBrowser component for which I only call a method Print. In other words I can code that runs when the user clicks on the print button. It looks like there is enough functionality in WINSPOOL.PAS to do this querying info from Print MAnager.  Does anybody know how to do this ?  I am thinkg of a function that would read info from print manager right after the print button is clicked. Events would be even better.

Thank you.
0
Comment
Question by:gilles2
  • 3
  • 3
6 Comments
 
LVL 5

Expert Comment

by:inter
Comment Utility
Yes your are right, the info can be retreived using the

BOOL GetJob(
    HANDLE hPrinter,      // handle of printer
    DWORD JobId,      // job identifier value
    DWORD Level,      // data-structure level
    LPBYTE pJob,      // address of data-structure array
    DWORD cbBuf,      // count of bytes in array
    LPDWORD pcbNeeded );

before you should open the printer with OpenPrinter and havi the hPrinter handle. If I have a printer at hand I can test this. Anyway after succesfully opening the printer you call
var
  JobInfo :TJobInfo1;
  needed : DWORD;
begin
  OpenPrinter('Hp1',hPrinter,nil);
  if hPrinter <> 0 then
  begin
    GetJob(hPrinter, 1, 1, JobInfo, Sizeof(JobInfo), needed);
  end;
  ClosePrinter(hPrinter);
end;

upon return JobInfo has the following info init:
  TJobInfo1A = record
   JobId: DWORD;
   pPrinterName: PAnsiChar;
   pMachineName: PAnsiChar;
   pUserName: PAnsiChar;
   pDocument: PAnsiChar;
   pDatatype: PAnsiChar;
   pStatus: PAnsiChar;
   Status: DWORD;
   Priority: DWORD;
   Position: DWORD;
   TotalPages: DWORD;  <- What you want
   PagesPrinted: DWORD;
   Submitted: TSystemTime;
  end;
But we should have some delay if you can print in background...
regards, igor
0
 

Author Comment

by:gilles2
Comment Utility
Thank you. That's exacly what I am looking for. I am having problems with


    GetJob(hPrinter, 1, 1, JobInfo, Sizeof(JobInfo), needed);

It expects a pointer for JobInfo. I tried just putting @ in front of it. It then compiles but crashes at runtime. Any suggestion ?

0
 
LVL 5

Accepted Solution

by:
inter earned 200 total points
Comment Utility
Hi friend, I have able to makeout the following code work. To test
include printers.pas in uses together with winspool.pas. Add a list box to your for called LB and make the following a procedure(bind to a button or what ever)


var
  JobInfo: PJobInfo1;
  hPrinter: integer;
  returned, needed: DWORD;
begin
  lb.clear;
  getmem(JobInfo, 1000);
  try
    if OpenPrinter(PChar(printer.printers[0]), hPrinter, nil) then
    begin
      if EnumJobs(hPrinter, 0, 1, 1, JobInfo, 1000, needed, returned) then
      begin
        with JobInfo^ do
        begin
          lb.items.add('JobId: ' + IntToStr(JobId));
          lb.items.add(pPrinterName);
          lb.items.add(pMachineName);
          lb.items.add(pUserName);
          lb.items.add(pDocument);
          lb.items.add(pDatatype);
          lb.items.add(pStatus);
          lb.items.add('Status: ' + IntToStr(Status));
          lb.items.add('Priority:' + IntToStr(Priority));
          lb.items.add('Position:' + IntToStr(Position));
          lb.items.add('TotalPages: ' + IntToStr(TotalPages));
          lb.items.add('PagesPrinted:' + IntToStr(PagesPrinted));
//         Submitted: TSystemTime;
        end;
      end;
      ClosePrinter(hPrinter);
    end;
  finally
    freemem(JobInfo, 1000);
  end;
end;

regards, igor
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:gilles2
Comment Utility
Thank you. It works. My only problem now is that I have to capture the info at the right time. Some jobs are in and out in no time. The option I am looking at right now is to use the message WM_SpoolerStatus(var Msg: TWMSPOOLERSTATUS); message WM_SPOOLERSTATUS;

This is called when jobs are added or removed from the queue. If the idle state of the printer is 'Paused' then I can print, the method WM_SpoolerStatus gets called when the job is added to the spooler, I get the job info, restart the printer. The job then prints. When it is finished printing (WM_SpoolerStatus is called again and I can see that Msg.JobsLeft has decreased) then I pause the printer again.

Does it make sense to you ?

Of course the problem now is how do I pause and restart the printer.

Thank you.
0
 

Author Comment

by:gilles2
Comment Utility
Thank you. I got everything working now. Using the pausing seems to work.
0
 
LVL 5

Expert Comment

by:inter
Comment Utility
Hi,
Sorry friend I was out at weekend. Thanks, now here for antthing...
regards, igor
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now