如何更改默认打印机 急!!(100分)

  • 主题发起人 主题发起人 lyshw
  • 开始时间 开始时间
L

lyshw

Unregistered / Unconfirmed
GUEST, unregistred user!
如何更改默认打印机
 
Hubdog的葵花宝典里面的。
This grabs the selected printer in a ComboBox and makes it the default
printer.
Use this on form create (or whatever)...
ComboBox1.Items := Printer.Printers;
{populates ComboBox}
ComboBox1.ItemIndex := Printer.PrinterIndex;
{sets display to current
printer}
then
, assuming you have a Button5...
procedure TForm1.Button5Click(Sender: TObject);
var
Device: array[0..255] of Char;
Driver: array[0..255] of char;
Port: array[0..255] of char;
s : array[0..255] of Char;
hDeviceMode: THandle;
begin
Printer.PrinterIndex := ComboBox1.ItemIndex;
Printer.GetPrinter (Device, Driver, Port, hDeviceMode);
StrCopy (s, Device);
StrCat (s, ',');
StrCat (s, Driver);
StrCat (s, ',');
StrCat (s, Port);
WriteProfileString ('windows', 'device', s);
StrCopy (s, 'windows');
SendMessage (HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@s));
end;
 
窗体上有个TComBox,命名为cb1
窗体名为Form1
procedure TForm1.FormCreate(Sender: TObject);
begin
cb1.items.assign(printer.printers);
end;

procedure TForm1.Button1Click(Sender: TObject);
var LPrinter:string;
PrinIniFile:Tinifile;
LStr:string;
begin
LStr:=printer.Printers[cb1.itemindex];
delete(Lstr,pos(' on ',Lstr),Length(LStr));
PrinIniFile:=TIniFile.Create('WIN.ini');
try
LPrinter:=PrinIniFile.ReadString('Devices',LStr,'');
PrinIniFile.writestring('windows','device',LStr+','+LPrinter);
finally
PrinIniFile.free;
end;
end;

 
谢谢各位老师了
 
后退
顶部