问题1、
Printer() 第一次调用时创建的全局变量TPrinter实例, 使用comboBox1.Items.assign(Printer.Printers) 可将系统已安装的打印机列表填到comboBox中,书上设置Printer.PrinterIndex可改变默认打印机。 但在comboBox的onChange事件中Printer.PrinterIndex:=comboBox1.ItemIndex并没有改变windows系统的默认打印机,请问Printer.PrinterIndex只是改变Delphi应用程序的默认打印机吗?它与windows的默认打印机有没关系??? Printer.getPrinter 、Printer.SetPrinter是操作什么打印机的???问题2、
在comboBox中选取不同的打印机时,如何取得该打印机当前状态、支持的字体、页面大小的列表,并改变该打印机当前使用的字体,页面大小?问题3、
如何通过delphi应用程序改系windows系统的默认找印机???
小第先谢了
Printer() 第一次调用时创建的全局变量TPrinter实例, 使用comboBox1.Items.assign(Printer.Printers) 可将系统已安装的打印机列表填到comboBox中,书上设置Printer.PrinterIndex可改变默认打印机。 但在comboBox的onChange事件中Printer.PrinterIndex:=comboBox1.ItemIndex并没有改变windows系统的默认打印机,请问Printer.PrinterIndex只是改变Delphi应用程序的默认打印机吗?它与windows的默认打印机有没关系??? Printer.getPrinter 、Printer.SetPrinter是操作什么打印机的???问题2、
在comboBox中选取不同的打印机时,如何取得该打印机当前状态、支持的字体、页面大小的列表,并改变该打印机当前使用的字体,页面大小?问题3、
如何通过delphi应用程序改系windows系统的默认找印机???
小第先谢了
解决方案 »
- 把下面代码转换成C++ builder
- 为什么用PrintDialog选择打印机后打印出来仍旧在默认的打印上?
- 有参加CodeGear发布日的朋友进来谈谈自己感受啦~
- 如何在TreeView指定位置添加结点
- 密码验证问题 在线等待 急啊
- 问一下很菜的问题啊,我想让edit不能输入空格与大小写字母,怎样做简单啊!
- 动态建立两个数据表(paradox表)的问题?
- 一个简单问题
- 100分求教!怎样用FastReport生成这样的报表?
- 用delphi 5.0 在A客户端写得程序,运行良好。把它拷贝到B上运行,就出现错误。 高手
- 没办法,高分求助一个问题(回答正确的还要加分),up者有分
- 求贴Sock Proxy服务端的详细代码(有说明最好)?要求不用控件(先100分,不够的话,我开贴再放)
comboBox1.Items:=RpDev.Printers;
RpDev.SelectPrinter(comboBox1.Items[i],false);
strIni: array[0..MAX_PATH] of Char;
arrWindows: array[0..64] of Char;
begin
GetWindowsDirectory(strIni, SizeOf(strIni));
StrCat(strIni, '\win.ini');
with TIniFile.Create(strIni) do
try
WriteString('windows', 'device', 'HP LaserJet 4 Plus,HPPCL5MS,LPT1:');
finally
Free;
end;StrCopy(arrWindows, 'windows');
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@arrWindows));
end;
procedure TForm1.formcreate(Sender: TObject);
begin
ComboBox1.Items := Printer.Printers;
ComboBox1.ItemIndex := Printer.PrinterIndex;
end;
//随便放到哪个按钮里就行了
procedure TForm1.Button1Click(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;
printers;
/////////
with printer do
begin
try
beginDoc;
canvas.Font.Name:='宋体'; //这里应该可以控制吧~~~~
canvas.Font.style:=[FsBold];
canvas.Font.size:=11;
canvas.Textout(200,250,'aaaaaa');
finally
EndDoc;
end;
end;
主要解答者: wzrlover 提交人: mrzho
感谢: wzrlover
审核者: windindance 社区对应贴子: 查看
A : 如何在程序里控制打印纸张大小(A3,A4)和打印方向?不想打开设置窗口
---------------------------------------------------------------
Uses Printer;
.........
procedure TForm1.Button1Click(Sender: TObject);
var
ADevice, ADriver, APort: array[0..255] of Char;
DeviceHandle: THandle;
DevMode: PDeviceMode;
begin
//初始化打印机
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
if DeviceHandle = 0 then
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
end;
if DeviceHandle = 0 then
Raise Exception.Create('不能初始化打印机!')
else
DevMode := GlobalLock(DeviceHandle);
if DeviceHandle <> 0 then
begin
with DevMode^ do
begin
dmFields := dmFields or DM_ORIENTATION;
//在下面这里设置打印方向
dmOrientation := DMORIENT_LANDSCAPE; //DMORIENT_PORTRAIT
dmPaperSize := DMPAPER_A3;
Printer.SetPrinter(ADevice, ADriver, APort, DeviceHandle);
GlobalUnLock(DeviceHandle);
end;
end;
PrinterSetupDialog1.Execute; //验证一下设置是否成功了
end;
*************如何设定打印机的纸张大小?
主要解答者: jyh149129 提交人: myboor
感谢: h_x_k
审核者: lxpbuaa 社区对应贴子: 查看
A : 做的套打程序,纸张不标准,想自己设定,不知如何实现
printer.pagewidth是只读属性
---------------------------------------------------------------
参考这个
var hDMode: THandle;
PDMode: PDEVMODE;
Printer.GetPrinter(Device, Driver, Port, hDMode);
if hDMode <> 0 then
begin
pDMode := GlobalLock(hDMode);
if pDMode <> nil then
begin
pDMode^.dmFields := DM_PAPERSIZE or DM_PAPERWIDTH or DM_PAPERLENGTH;
pDMode^.dmPaperSize := DMPAPER_USER;
pDMode^.dmPaperWidth := APaperWidth;
pDMode^.dmPaperLength := APaperHeight;
pDMode^.dmFields:=pDMode^.dmFields or DM_ORIENTATION;
pDMode^.DMORIENTATION:= Direct;
end;
end;
//打印机设置的纸张大小
---------------------------------------------------------------
试试这个吧
在执行打印前调用以下函数:
procedure SetPaperSize(X, Y: Integer);
// 单位是0.1mm
// A4时 Printer.Pagewidth:=1440; A5时 Printer.Pagewidth:=1049;
// B5时 Printer.Pagewidth:=1290; 16K时 Printer.Pagewidth:=1035;
// lq1600宽行打印机这个值宽度最大为42cm左右, 长度大约2m。
//改变devicemode结构
var
Device: array[0..255] of char;
Driver: array[0..255] of char;
Port: array[0..255] of char;
hDMode: THandle;
PDMode: PDEVMODE;
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(Device, Driver, Port, hDMode);
if hDMode <> 0 then
begin
pDMode := GlobalLock(hDMode);
if pDMode <> nil then
begin
if (x = 0) or (y = 0) then
begin
{Set to legal}
pDMode^.dmFields := pDMode^.dmFields or dm_PaperSize;
{pDMode^.dmPaperSize := DMPAPER_LEGAL; changed by wulianmin}
pDMode^.dmPaperSize := DMPAPER_FANFOLD_US;
end
else
begin
{Set to custom size}
pDMode^.dmFields := pDMode^.dmFields or
DM_PAPERSIZE or
DM_PAPERWIDTH or
DM_PAPERLENGTH;
pDMode^.dmPaperSize := DMPAPER_USER;
pDMode^.dmPaperWidth := x {SomeValueInTenthsOfAMillimeter};
pDMode^.dmPaperLength := y {SomeValueInTenthsOfAMillimeter};
end;
{设定纸张来源}
pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;
pDMode^.dmDefaultSource := DMBIN_MANUAL;
GlobalUnlock(hDMode);
end;
end;
Printer.PrinterIndex := Printer.PrinterIndex;
//以下开始打印
Printer.BeginDoc;
Printer.Canvas.TextOut(100,100, 'Test 1');
Printer.EndDoc;
end;