2010. augusztus 13., péntek

How to set the default printer in Windows


Problem/Question/Abstract:

Does anyone know how to set a particular printer as the default printer programmatically in Windows (both 98 and NT) in Delphi?

Answer:

Change default printer:

{ ... }
var
  Device: array[0..255] of char;
  Driver: array[0..255] of char;
  Port: array[0..255] of char;
  hDeviceMode: THandle;
begin
  Printer.PrinterIndex := ....; {select printer to make default}
  Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
  StrCat(Device, ',');
  StrCat(Device, Driver);
  StrCat(Device, ',');
  StrCat(Device, Port);
  WriteProfileString('windows', 'device', Device);
  StrCopy(Device, 'windows');
  SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, longint(@Device));
end;

Nincsenek megjegyzések:

Megjegyzés küldése