对word编程,使用非默认打印机打印word文档,如何?(200分)

  • 主题发起人 主题发起人 无粮野鹤
  • 开始时间 开始时间

无粮野鹤

Unregistered / Unconfirmed
GUEST, unregistred user!
对word编程,打印一个已经存在的word文档,如果要用指定的打印机(例打印到传真机)
而不用默认打印机(例Epson LQ-1600KII)。解决的方法之一是先把"Print to Fax"设置为
默认,然后打印,之后产生新问题----不知如何恢复原来的默认打印机?

下列c++代码供你参考:
Variant V;
V = CreateOleObject("Word.Basic");
V.Exec(Procedure("FileOpen")<<"C://My Documents//Temp.doc");
V.Exec(Procedure("FilePrintSetup")<<"Print to Fax");
V.Exec(Procedure("FilePrint")<<0<<0<<0<<""<<""<<""<<0<<2<<""<<0<<0<<0<<"C://My Documents//Temp.doc");

无论用delphi或c++builder回答都有大!
急急急!
 
用PrinterDialog呀
 
2k系统中可以这样的,不知道98是不是可以!
在窗体中加入combobox和两个button
你自己TRY!
我测试通过!

procedure TForm1.Button1Click(Sender: TObject);
begin
ComboBox1.Items := Printer.Printers; {populates ComboBox}
ComboBox1.ItemIndex := Printer.PrinterIndex; {sets display to current printer}
end;

procedure TForm1.Button2Click(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;
 
后退
顶部