Author: Jonas Bilinkevicius
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:
1 { ... }
2 var
3 Device: array[0..255] of char;
4 Driver: array[0..255] of char;
5 Port: array[0..255] of char;
6 hDeviceMode: THandle;
7 begin
8 Printer.PrinterIndex := ....; {select printer to make default}
9 Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
10 StrCat(Device, ',');
11 StrCat(Device, Driver);
12 StrCat(Device, ',');
13 StrCat(Device, Port);
14 WriteProfileString('windows', 'device', Device);
15 StrCopy(Device, 'windows');
16 SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, longint(@Device));
17 end;
|