网络打印的计费问题(200分)

  • 主题发起人 主题发起人 devuser
  • 开始时间 开始时间
D

devuser

Unregistered / Unconfirmed
GUEST, unregistred user!
我们学校的局域网有台激光打印机,在我们的机器上安装网络打印机然后打印到
这台机器上。现在计划开发一个程序,安装在服务器(打印机连在服务器),实行
对每个人打印计费,数据库我没有问题,但是如何跟踪打印机的打印,并确定打印
的来源,以及打印页数。那位做过此类工作的大虾能告诉我一二......
 
我以前写了一个,希望对你有帮助:

type
TMainFrm = class(TForm)
Pages: TPageControl;
PrinterSht: TTabSheet;
PrinterLst: TListBox;
...

private
procedure SpollerStatus(var Msg:TWMSpoolerStatus);
message WM_SPOOLERSTATUS;
...
uses
WinSpool, ExtCtrls;

procedure TMainFrm.SpollerStatus(var Msg:TWMSpoolerStatus);
var
tbt:Byte;
Needed,Returned:DWORD;
ResultBuffer:Pointer;
i,x,Count:Integer;
Pi:PJobInfo1;
hPrinter:THandle;
List:TListBox;
Lbl:TLabel;
begin

for i:=1 to Pages.PageCount-1do
begin

hPrinter:=Pages.Pages.Tag;
List:=Pages.Pages.Controls[0] as TListBox;
Lbl:=((Pages.Pages.Controls[1] as TPanel)
.Controls[0] as TLabel);
List.Clear;
EnumJobs(hPrinter,0,Msg.JobsLeft,1,@tbt,0,Needed,Returned);
if Needed=0 then
begin

Lbl.Caption:='0 个作业';
Continue;
end;

Count:=Needed;
if Count<=0 then
begin

Lbl.Caption:='0 个作业';
Continue;
end;

GetMem(ResultBuffer,Count);
try
EnumJobs(hPrinter,0,Msg.JobsLeft,1,ResultBuffer,Needed,Needed,Returned);
if Returned>Msg.JobsLeft then
begin

Lbl.Caption:='0 个作业';
Continue;
end;

Lbl.Caption:=IntToStr(Returned)+' 个作业';
Pi:=ResultBuffer;
for x:=0 to Returned-1do
begin

List.Items.Add(Pi^.pDocument);
Pi:=PJobInfo1(LongInt(Pi)+Sizeof(Pi^));
end;

finally
FreeMem(ResultBuffer,Count);
end;

end;

Msg.Result:=0;
end;


procedure TMainFrm.FormCreate(Sender: TObject);
var
tbt:Byte;
Needed,Returned:DWORD;
ResultBuffer:Pointer;
x,Count:Integer;
Pi:PPrinterInfo1;
Sheet:TTabSheet;
hPrinter:THandle;
Panel:TPanel;
begin

PrinterLst.Clear;
EnumPrinters(PRINTER_ENUM_LOCAL,'',1,@tbt,0,Needed,Returned);
if Needed=0 then
Exit;
Count:=Needed;
GetMem(ResultBuffer,Count);
EnumPrinters(PRINTER_ENUM_LOCAL,'',1,ResultBuffer,Needed,Needed,Returned);
Pi:=ResultBuffer;
for x:=0 to Returned-1do
begin

PrinterLst.Items.Add(Pi^.pName);
Pi:=PPrinterInfo1(LongInt(Pi)+Sizeof(Pi^));
Sheet:=TTabSheet.Create(Self);
with Sheetdo
begin

PageControl:=Pages;
Caption:=PrinterLst.Items[PrinterLst.Items.Count-1];
OpenPrinter(PChar(Caption),hPrinter,nil);
Tag:=hPrinter;
ClosePrinter(hPrinter);
with TListBox.Create(Self)do
begin

Parent:=Sheet;
Align:=alClient;

end;

Panel:=TPanel.Create(Self);
with Paneldo
begin

Parent:=Sheet;
Align:=alTop;
Height:=20;
BevelOuter:=bvNone;
end;

with TLabel.Create(Self)do
begin

Parent:=Panel;
Left:=10;
Top:=3;
Caption:='0 个作业';
end;

end;

end;

FreeMem(ResultBuffer,Count);
end;


procedure TMainFrm.FormDestroy(Sender: TObject);
var
i,j:Integer;
begin

for i:=1 to Pages.PageCount-1do

with Pages.Pagesdo
begin

((Controls[1] as TPanel).Controls[0] as TLabel).Free;
for j:=0 to ControlCount-1do

Controls[0].Free;
Free;
end;

end;



 
上面的师兄回答的非常棒。为什么没有其他的弟兄的回答
.
 
怎么得到打印的用户?
 
接受答案了.
 
后退
顶部