2008. február 14., csütörtök

How to open the printer properties window


Problem/Question/Abstract:

Is there any API call that opens the printer properties window? You can open it clicking the right mouse button in a printer icon and choosing properties from the context menu.

Answer:

uses
  WinSpool;

procedure TForm1.Button2Click(Sender: TObject);
var
  hPrinter: THandle;
  Device: array[0..255] of char;
  Driver: array[0..255] of char;
  Port: array[0..255] of char;
  hDeviceMode: THandle;
begin
  {can use other index than default or omit this statement if printer
                already selected}
  Printer.PrinterIndex := -1;
  Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
  if WinSpool.OpenPrinter(@Device, hPrinter, nil) then
  try
    PrinterProperties(Handle, hPrinter);
  finally
    WinSpool.ClosePrinter(hPrinter);
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése