Solved

How to get the count of printed pages from any application

Posted on 2002-03-09
3
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month5 days, 19 hours left to enroll

627 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