DELPHI 指定打印机打印
有两台打印机A,B
我打印报表1时,用A打印机打印,打印报表2时,用B打印机打印
我是这样写的:
打印A时,调用SETPRINTER(0)
打印B时,调用SETPRINTER(1)
可是第一次先打报表1时,再打报表2,就总是打到打印机1
如果第一次先打报表2时,再打报表1,就总是打到打印机2
不知是什么问题?
procedure TPayFrm.SetPrinter(serno:integer);
var
Mydevice,Mydriver,MyPort:array[0..255] of char;
MyHandle:THandle;
i:integer;
begin
if printer.Printers.Count=1 then exit;
printer.PrinterIndex:=Serno;
Printer.GetPrinter(Mydevice,
MyDriver,
MyPort,
MyHandle);
StrCat(MyDevice,',');
StrCat(MyDevice,MyDriver);
StrCat(MyDevice,',');
StrCat(Mydevice,MyPort);
//write win.ini
WriteProfileString('WINDOWS','DEVICE',Mydevice);
//tell all application that windows ini file has changed ,
//this will cause them all to recheck default printer
SendMessage(HWND_BROADCAST,
WM_WININICHANGE,
0,
LongInt(pChar('windows'))
);
end;