Solved

How to get the count of printed pages from any application

Posted on 2002-03-09
3
214 Views
Last Modified: 2010-04-05
Hi All,

How can i get the printed pages from any Application on my computer.

i want to write a small Application to monitoring how many pages already printed from my computer , and the printer is not local installed.

Hope for a good tips

Thanks Willy
0
Comment
Question by:wchandra
3 Comments
 
LVL 9

Accepted Solution

by:
ginsonic earned 150 total points
ID: 6852493
Try this :

unit Unit1;


interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls,WinSpool,Printers ;

type
TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
private
  { Private declarations }
public
  { Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);

 const
   MaxJobs = 1024;
 type
   TArrayofJobs = array[1..1024] of TJobInfo2;
 var
   NumJobs : integer;
   pcbNeed,pcReturned:DWord;
   i : integer;
   Device : array[0..255] of char;
   Driver : array[0..255] of char;
   Port   : array[0..255] of char;
   hPrinter: THandle;
   hDeviceMode: THandle;
   Buffer: Pointer;
   TmpWinDir : array[0..255] of Char;
   Windir : string;

 begin
   if GetWindowsDirectory(TmpWinDir, sizeof(TmpWinDir)) <> 0 then
     Windir := Strpas(TmpWinDir) + '\SPOOL\PRINTERS\'
   else
     Windir := 'C:\WINDOWS\SPOOL\PRINTERS\';

   Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
   if not WinSpool.OpenPrinter(@Device, hPrinter, nil) then exit;

   ListBox1.items.clear;

   GetPrinter(hPrinter, 2, nil,0,@pcbNeed);
   GetMem(Buffer, pcbNeed);

  if EnumJobs(hPrinter, 0, NumJobs, 2, Buffer, pcbNeed, pcbNeed,pcReturned) then
     begin
       for i := 1 to pcReturned do
         begin
           ListBox1.items.add('TotalPages='+Inttostr(TarrayofJobs(buffer^)[i].TotalPages));
           ListBox1.items.add('PagesPrinted='+Inttostr(TarrayofJobs(buffer^)[i].PagesPrinted));

           SetJob(hPrinter, TArrayofJobs(buffer^)[i].JobId, 0, nil,JOB_CONTROL_CANCEL);
         end;
     end;
   FreeMem(Buffer, pcbNeed);

   WinSpool.ClosePrinter(hPrinter);
 end;

end.
0
 

Expert Comment

by:CleanupPing
ID: 9343289
wchandra:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 7

Expert Comment

by:knightmad
ID: 9470508
Wow, Its been a long time since this comment have been visited!

wchandra,
No comment has been added lately (19 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to ginsonic http:#6852493

-- Please DO NOT accept this comment as an answer ! --

Thanks,

knightmad
EE Cleanup Volunteer

Remember you (all) can object this recommendation if you disagree, just leave a post here explaining why are you objecting and what should be done instead.
Within 7 days probably this thread will be closed, so, hurry up! : )
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 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

21 Experts available now in Live!

Get 1:1 Help Now