Einzelnen Beitrag anzeigen

Benutzerbild von chaosben
chaosben

Registriert seit: 27. Apr 2005
Ort: Görlitz
1.358 Beiträge
 
Delphi XE2 Professional
 
#11

AW: Druckaufträge überwachen und Programm starten

  Alt 25. Aug 2011, 14:07
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
Benjamin Schwarze
If I have seen further it is by standing on the shoulders of Giants. (Isaac Newton)
  Mit Zitat antworten Zitat