Mega Code Archive

 
Categories / Delphi / Printing
 

Change the windows default printer

The following code changes the default printer. Attention - this is a systemwide change and will affect other applications. Since this is discouraged, do it only if you have a really good reason. program dummy; // sample code by Peter Below var Device: array [0..255] of Char; Driver: array [0..255] of Char; Port: array [0..255] of Char; hDeviceMode: THandle; begin Printer.PrinterIndex := 1; {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.