我的打印机打印时为何不响应wm_spoolserstatus消息 ;(100分)

  • 主题发起人 主题发起人 ccweifen
  • 开始时间 开始时间
C

ccweifen

Unregistered / Unconfirmed
GUEST, unregistred user!
从http://www.delphibbs.com/delphibbs/dispq.asp?lid=417158 上抄来的一段监视
打印机的程序 ,JohnsonGuo大侠的回复 。
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;

程序运行时打印一个文档,但总是显示'0个作业'
 
少了10分, 不好意思
 
后退
顶部