Alternar Impressora Padrão

Delphi

10/03/2003

Olá pessoal,

Como faço para colocar uma impressora que não está padrão (HP DeskJet 840) para padrão e outra padrão (HP LaserJet 1000) para não-padrão?

Grato por sua atenção,

Ilano.


Ilanocf

Ilanocf

Curtidas 0

Respostas

Anonymous

Anonymous

10/03/2003

ilanocf,

Estou enviando um procedure para alterar a impressora padrão do windows.

-------------------------------------------------------------------------------------
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
-------------------------------------------------------------------------------------

Abraços,

Bruno Roberto.


GOSTEI 0
POSTAR