Einzelnen Beitrag anzeigen

haidomingo

Registriert seit: 23. Jul 2009
23 Beiträge
 
#8

Re: How to set use printer offline

  Alt 8. Nov 2009, 19:20
The new code:

Delphi-Quellcode:
procedure TForm24.Button1Click(Sender: TObject);
var
  HPrinter : THandle;
  InfoSize,
  BytesNeeded: Cardinal;
  PI2: PPrinterInfo2;
  PrinterDefaults: TPrinterDefaults;
  SelectedPrinter: string;

begin
  SelectedPrinter:=Printer.Printers[Printer.PrinterIndex];
  with PrinterDefaults do begin
    DesiredAccess := PRINTER_ACCESS_USE;
    pDatatype := nil;
    pDevMode := nil;
  end;
  if OpenPrinter(PChar(SelectedPrinter), HPrinter, @PrinterDefaults) then
  try
    if not GetPrinter(HPrinter, 2, nil, 0, @BytesNeeded) then begin
      PI2 := AllocMem(BytesNeeded);
      try
        InfoSize := SizeOf(TPrinterInfo2);
        if GetPrinter(HPrinter, 2, PI2, BytesNeeded, @BytesNeeded) then begin
           ShowMessage(IntToStr(PI2^.Attributes)); // Show 1601
           PI2^.Attributes:=PI2^.Attributes and not (PRINTER_ATTRIBUTE_WORK_OFFLINE);
           SetPrinter(Hprinter, 2, PI2, 0);
           ShowMessage(IntToStr(PI2^.Attributes));//Show 577
        end;
      finally
        FreeMem(PI2, BytesNeeded);
      end;
    end;
  finally
    ClosePrinter(HPrinter);
  end;
but the printer status is not changed (1601)
seems that the call to SetPrinter has no effect.

many thanks
  Mit Zitat antworten Zitat