Hier hätten wir noch ein Stück simplen kurzen Code:
Delphi-Quellcode:
TMyThread = class(TThread)
protected
FPrinter : THandle;
procedure Execute; override;
public
constructor Create(APrinter : THandle); reintroduce;
end;
//...
constructor TMyThread.Create(APrinter : THandle);
begin
FPrinter := APrinter;
inherited Create(false);
end;
procedure TMyThread.Execute;
var
change : THandle;
changed : Cardinal;
info : Pointer;
s : String;
begin
change := FindFirstPrinterChangeNotification(FPrinter, PRINTER_CHANGE_JOB, 0, nil);
while not Terminated do
begin
if WaitForSingleObject(change, 500) <> WAIT_TIMEOUT then
begin
if FindNextPrinterChangeNotification(change, changed, nil, info) then
begin
case changed of
PRINTER_CHANGE_ADD_JOB: s := 'add job';
PRINTER_CHANGE_SET_JOB: s := 'set job';
PRINTER_CHANGE_DELETE_JOB: s := 'delete job';
PRINTER_CHANGE_WRITE_JOB: s := 'write job';
end;
Synchronize(procedure begin ShowMessage(s) end);
FreePrinterNotifyInfo(info);
end;
end;
end;
FindClosePrinterChangeNotification(change);
end;
Getestet unter Win7_64 mit D2009 .. funzt