S
Supermay
Unregistered / Unconfirmed
GUEST, unregistred user!
我想监视打印机的事件
procedure TForm1.Button3Click(Sender: TObject);
Const
TimeOut=1000;
Var
PrinterNamechar;
PrinterHandle : THandle;
chgObject:THandle;
pdwChangeWORD;
LCardinal:Cardinal;
pPrnNotifyPrinterNotifyOptions;
pPrnNotifyInfoPrinterNotifyInfo;
fcnReturn:LongBool;
begin
pdwChange:=PRINTER_CHANGE_ALL;
GetMem(pPrnNotify,SizeOf(TPrinterNotifyOptions));
GetMem(pPrnNotifyInfo,SizeOf(TPrinterNotifyInfo));
PrinterName:=Pchar(Printers.Printer.Printers.Strings[0]);
if OpenPrinter(PrinterName,PrinterHandle,nil) then
begin
chgObject:=FindFirstPrinterChangeNotification(PrinterHandle,pdwChange, 0,pPrnNotify);
if chgObject>0 then
begin
//WaitForSingleObject(chgObject,TimeOut);//这里总是会超时,会释放ChgObject
with pPrnNotify^do
begin
Version := 1;
Flags := PRINTER_NOTIFY_OPTIONS_REFRESH;
Count := 1;
pTypes := nil;
end;
fcnReturn :=FindNextPrinterChangeNotification(chgObject,pdwChange,pPrnNotify,Pointer(pPrnNotifyInfo));
if fcnReturn then
begin
///////////////////////////////////////////////////////////////////////
Case pPrnNotifyInfo^.aData[0].wType of//得不到正确的值, JOB_NOTIFY_TYPE://这里只有这两个值
begin
Self.Memo1.Lines.Add('JOB_NOTIFY_TYPE');
end;
PRINTER_NOTIFY_TYPE:
begin
Self.Memo1.Lines.Add('PRINTER_NOTIFY_TYPE');
end;
end;
//pdwChange总是为0,
//Check pdwChange,PrnNotify,pPrnNotifyInfo
///////////////////////////////////////////////////////////////////
end;
end;
FreePrinterNotifyInfo(pPrnNotifyInfo);
ClosePrinter(PrinterHandle);
end;
end;
如何处理?
procedure TForm1.Button3Click(Sender: TObject);
Const
TimeOut=1000;
Var
PrinterNamechar;
PrinterHandle : THandle;
chgObject:THandle;
pdwChangeWORD;
LCardinal:Cardinal;
pPrnNotifyPrinterNotifyOptions;
pPrnNotifyInfoPrinterNotifyInfo;
fcnReturn:LongBool;
begin
pdwChange:=PRINTER_CHANGE_ALL;
GetMem(pPrnNotify,SizeOf(TPrinterNotifyOptions));
GetMem(pPrnNotifyInfo,SizeOf(TPrinterNotifyInfo));
PrinterName:=Pchar(Printers.Printer.Printers.Strings[0]);
if OpenPrinter(PrinterName,PrinterHandle,nil) then
begin
chgObject:=FindFirstPrinterChangeNotification(PrinterHandle,pdwChange, 0,pPrnNotify);
if chgObject>0 then
begin
//WaitForSingleObject(chgObject,TimeOut);//这里总是会超时,会释放ChgObject
with pPrnNotify^do
begin
Version := 1;
Flags := PRINTER_NOTIFY_OPTIONS_REFRESH;
Count := 1;
pTypes := nil;
end;
fcnReturn :=FindNextPrinterChangeNotification(chgObject,pdwChange,pPrnNotify,Pointer(pPrnNotifyInfo));
if fcnReturn then
begin
///////////////////////////////////////////////////////////////////////
Case pPrnNotifyInfo^.aData[0].wType of//得不到正确的值, JOB_NOTIFY_TYPE://这里只有这两个值
begin
Self.Memo1.Lines.Add('JOB_NOTIFY_TYPE');
end;
PRINTER_NOTIFY_TYPE:
begin
Self.Memo1.Lines.Add('PRINTER_NOTIFY_TYPE');
end;
end;
//pdwChange总是为0,
//Check pdwChange,PrnNotify,pPrnNotifyInfo
///////////////////////////////////////////////////////////////////
end;
end;
FreePrinterNotifyInfo(pPrnNotifyInfo);
ClosePrinter(PrinterHandle);
end;
end;
如何处理?