Solved

How to get the count of printed pages from any application

Posted on 2002-03-09
3
220 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert Jpg /PNG To GIF 5 150
Delphi Dbf export problem to a Visual Foxpro application 6 207
Delphi: how to implement a User Shortcut mapper? 1 119
Delphi XE10 Round Image 2 157
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

861 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