Procedure SetDefaultPrinter;
var
Device : array[0..cchDeviceName] of char;
Driver : array[0..MAX_PATH] of char;
DriverPort : string;
Port : array[0..MAX_PATH] of char;
hDMode : THandle;
s : array[0..64] of char;
WinIni : TIniFile;
WinIniFileName : array[0..MAX_PATH] of char;
begin
if PrinterSetupDialog.Execute then
begin
Printer.GetPrinter(@Device, @Driver, @Port, hDMode);
// For some reason "Driver" is never defined here by GetPrinter.
// Let's get "Driver,Port" from the Win.INI file "Devices" section
GetWindowsDirectory(WinIniFileName, SizeOf(WinIniFileName));
StrCat(WinIniFileName, 'win.ini');
WinIni := TIniFile.Create(WinIniFileName);
try
// Lookup Driver,Port in INI file "Devices" section
DriverPort := WinIni.ReadString('devices', Device, '');
// Update INI "Windows" section -- this is the Windows default printer
WinIni.WriteString('windows', 'device', Device + ',' + DriverPort)
finally
WinIni.Free
end; // try
// Flush INI cache
WritePrivateProfileString(NIL, NIL, NIL, WinIniFileName);
// Broadcast system wide message about win.ini change
s := 'windows';
SendMessage(HWND_BROADCAST, WM_WININICHANGE,0, Cardinal(@s));
end; // if PrinterSetupDialog.Execute
end; // SetDefaultPrinter
Assinar:
Postar comentários (Atom)
Nenhum comentário:
Postar um comentário