procedure SetDefaultPrinter2K(PrinterName: String);
var
I: Integer;
Device : PChar;
Driver : Pchar;
Port : Pchar;
HdeviceMode: Thandle;
aPrinter : TPrinter;
begin
Printer.PrinterIndex := -1;
getmem( device, 255);
getmem( Driver, 255);
getmem( Port, 255);
aPrinter := TPrinter.create;
for I := 0 to Printer.printers.Count-1do
begin
if pos(uppercase(PrinterName),uppercase(Printer.printers)) >0 then
begin
aprinter.printerindex := i;
aPrinter.getprinter( device, driver, port, HdeviceMode);
StrCat(Device, ',');
StrCat(Device, Driver );
StrCat(Device, Port );
WriteProfileString('windows', 'device', Device );
StrCopy( Device, 'windows' );
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, Longint(@Device));
end;
end;
freemem( device, 255);
freemem( Driver, 255);
freemem( Port, 255);
aPrinter.free;
end;