一台机器连两台打印机,程序如何控制. 急急急!!!

webnote 2004-07-05 10:15:13
我要在软件中实现打印发票和一般统计报表的功能,我现在想在一台机器上安装两台打印机,一台票据打印机用来打印发票,另一台普通打印机用来打印报表.问题是我怎样才能实现在"打印发票"时,系统会自动用票据打印机来打印,打印报表时用普能打印机来打印.
...全文
123 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
aiirii 2004-07-05
  • 打赏
  • 举报
回复
http://community.borland.com/article/0,1410,28936,00.html
aiirii 2004-07-05
  • 打赏
  • 举报
回复
http://www.latiumsoftware.com/en/delphi/00025.php
Setting Windows default printer programmatically

uses IniFiles, SysUtils, Messages;

type
TDevice = record
Name, Driver, Port: string;
end;

var
Devices: array of TDevice;
DDevice: TDevice; // current default printer

procedure TForm1.FormCreate(Sender: TObject);
var
WinIni: TIniFile;
DevList: TStringList;
device: string;
i, p: integer;
begin
WinIni := TIniFile.Create('WIN.INI');

// Get the current default printer
device := WinIni.ReadString('windows', 'device', ',,');
if device = '' then device := ',,';
p := Pos(',', device);
DDevice.Name := Copy(device, 1, p-1);
device := Copy(device, p+1, Length(device)-p);
p := Pos(',', device);
DDevice.Driver := Copy(device, 1, p-1);
DDevice.Port := Copy(device, p+1, Length(device)-p);

// Get the printers list
DevList := TStringList.Create;
WinIni.ReadSectionValues('Devices', DevList);

// Store the printers list in a dynamic array
SetLength(Devices, DevList.Count);
for i := 0 to DevList.Count - 1 do begin
device := DevList[i];
p := Pos('=', device);
Devices[i].Name := Copy(device, 1, p-1);
device := Copy(device, p+1, Length(device)-p);
p := Pos(',', device);
Devices[i].Driver := Copy(device, 1, p-1);
Devices[i].Port := Copy(device, p+1, Length(device)-p);

// Add the printer to the ListBox
ListBox1.Items.Add(Devices[i].Name
+ ' (' + Devices[i].Port + ')');

// Is the current default printer?
if (CompareText(Devices[i].Name, DDevice.Name) = 0) and
(CompareText(Devices[i].Driver, DDevice.Driver) = 0) and
(CompareText(Devices[i].Port, DDevice.Port) = 0) then
ListBox1.ItemIndex := i; // Make it the selected printer
end;
WinIni.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
WinIni: TIniFile;
begin
if ListBox1.ItemIndex = -1 then exit;
DDevice := Devices[ListBox1.ItemIndex];
WinIni := TIniFile.Create('WIN.INI');
WinIni.WriteString('windows', 'device', DDevice.Name
+ ',' + DDevice.Driver + ',' + DDevice.Port);
WinIni.Free;
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0,
LPARAM(pchar('windows')));
end;

procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
Button1Click(Sender);
end;
ahyf 2004-07-05
  • 打赏
  • 举报
回复
当然可以,打印对话框,不是可以选择输出到哪能打印机吗?

2,498

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧