procedure TForm1.Button1Click(Sender: TObject);
var
Device: Array[0..(cchDeviceName -1)] of char;
Driver: Array[0..(MAX_PATH -1)] of char;
Port: Array[0..32] 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
case pDMode.dmPaperSize of
DMPAPER_USER: showmessage('纸张类型:自定义');
DMPAPER_A3: showmessage('纸张类型:A3');
DMPAPER_A4: showmessage('纸张类型:A4');
DMPAPER_A5: showmessage('纸张类型:A5');
DMPAPER_B4: showmessage('纸张类型:B4');
DMPAPER_B5: showmessage('纸张类型:B5');
else showmessage('纸张类型:其它');
end;
GlobalUnLock(HDMode);
Printer.PrinterIndex := Printer.PrinterIndex;
end; end;
end;
var
Device: Array[0..(cchDeviceName -1)] of char;
Driver: Array[0..(MAX_PATH -1)] of char;
Port: Array[0..32] 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
case pDMode.dmPaperSize of
DMPAPER_USER: showmessage('纸张类型:自定义');
DMPAPER_A3: showmessage('纸张类型:A3');
DMPAPER_A4: showmessage('纸张类型:A4');
DMPAPER_A5: showmessage('纸张类型:A5');
DMPAPER_B4: showmessage('纸张类型:B4');
DMPAPER_B5: showmessage('纸张类型:B5');
else showmessage('纸张类型:其它');
end;
GlobalUnLock(HDMode);
Printer.PrinterIndex := Printer.PrinterIndex;
end; end;
end;
解决方案 »
- 如何使用ADOQuery向Access和SQL Server插入数据
- DELPHI 简单问题
- 急。。。。。。。。
- adoconnection的事务在下面的语句中怎么不能用,提示"当前提供程序不支持事务"!!急
- ado两个表联接为什么不能只编辑一个原表的数据
- 如何在软件中做广告?
- 如可解决使用ActiveSkin 换肤后 Image控件不能显示图像的问题?
- 第一次写了一个C/S的数据库程序,在单机上应用没有问题,可不知如何将它转移到服务器上???????
- 请问在Delphi中怎样使用QReport制作复杂报表
- 如何是程序具有文件管理器的功能(双击时自动启动相应的程序)?
- 一道程序分析題,歡迎delphi高手!!!
- 请问能否在MDI窗体的子窗体中调用父窗体的变量或控件并对起赋值,怎么做?谢谢
1。用TEXTMETRIC取出当前的字体参数
2。打开你要打印的文件计算出在当前打印机环境下文件大小
3。调用drawtext参数hdc指向printer
输出时HDC当然指向Printer,不过我输出不用API,只是想计算可打印区域。
水平偏移量和垂直偏移量用DeviceCapabilities得到纸张宽度-2*水平偏移量=实际可打印宽度
纸张高度-2*垂直偏移量=实际可打印高度很多打印预览程序是没有考虑这一点的,例如cell,
所以能预览,但小于物理偏移量的部分打不出来.
excel中处理了这个问题,左边界不能小于水平偏移量.
非常感谢!用DeviceCapabilities,我现在已用到的有:
DC_PAPERNAMES
DC_PAPERS
DC_BINNAMES
DC_BINS
要获取偏移量该用哪个?我查MSDN没有找到合适的。
参数是一个XXXoffset的常量,具体是什么不记得了.
GetDeviceCaps(HDC hdc, PHYSICALHEIGHT);//实际高度,纸的高度
GetDeviceCaps(HDC hdc, PHYSICALOFFSETX);//宽度的偏移,就是实际宽度与打印机可画得到的区域的X偏差,GetDeviceCaps(HDC hdc, PHYSICALWIDTH)-2*GetDeviceCaps(HDC hdc, PHYSICALOFFSETX)==hdc实际可画的宽度
GetDeviceCaps(HDC hdc, PHYSICALOFFSETY);//高度的偏移,就是实际高度与打印机可画得到的区域的Y偏差,GetDeviceCaps(HDC hdc, PHYSICALHEIGHT)-2*GetDeviceCaps(HDC hdc, PHYSICALOFFSETY)==hdc实际可画的高度