请那位高手帮我解决以下打印机纸张设置问题?300分(200分)

X

xj_wzj

Unregistered / Unconfirmed
GUEST, unregistred user!
我自定义纸张120*70cm,可是打印出来的尺寸太小,
x := GetDeviceCaps(printer.Handle,PHYSICALOFFSETX);
y := GetDeviceCaps(printer.Handle,PHYSICALOFFSETY);
通过API调用获取打印区域边界为4.2*12.0。如何通过API调用设置打印区域边界?
 
先在
开始->设置->打印机->设置 看看!
再考虑用API
 
动态改变纸张尺寸,应用平台在Win 98/NT/2000,所以必须通过API动态改变.
 
SetViewportOrg (hPrnDC, xOffset, yOffset);


How to Use a Program to Calculate Print Margins
Last reviewed: May 25, 1995
Article ID: Q122037
The information in this article applies to:
Microsoft Windows Software Development Kit (SDK) for Windows versions 3.0 and 3.1
Microsoft Win32 SDK, versions 3.1, 3.5, 3.51, and 4.0

SUMMARY
The Windows Software Development Kit (SDK)do
es not provide a function to calculate printer margins directly. An application can calculate this information using a combination of printer escapes and calls to the GetDeviceCaps() function in Windows or by using GetDeviceCaps() in Windows NT. This article discusses those functions and provides code fragments as illustrations.

MORE INFORMATION
An application can determine printer margins as follows:

Calculate the left and top margins
a. Determine the upper left corner of the printable area by using the

GETPRINTINGOFFSET printer escape in Windows or by calling
GetDeviceCaps() with the PHYSICALOFFSETX and PHYSICALOFFSETY
indices in Windows NT. For example:

// Init our pt struct in case escape not supported
pt.x = 0;
pt.y = 0;

// In Windows NT, the following 2 calls replace GETPRINTINGOFFSET:
// pt.x = GetDeviceCaps(hPrnDC, PHYSICALOFFSETX);
// pt.y = GetDeviceCaps(hPrnDC, PHYSICALOFFSETY);

// In Windows, use GETPRINTINGOFFSET to fill the POINT struct
// Drivers are not required to support the GETPRINTINGOFFSET escape,
// so call the QUERYESCSUPPORT printer escape to make sure
// it is supported.
Escape (hPrnDC, GETPRINTINGOFFSET, NULL, NULL, (LPPOINT) &pt);
b. Determine the number of pixels required to yield the desired margin

(x and y offsets) by calling GetDeviceCaps() using the LOGPIXELSX and
LOGPIXELSY flags.

// Figure out how much you need to offset output. Note the
// use of the "max" macro. It is possible that you are asking for
// margins that are not possible on this printer. For example, the HP
// LaserJet has a 0.25" unprintable area so we cannot get margins of
// 0.1".

xOffset = max (0, GetDeviceCaps (hPrnDC, LOGPIXELSX) *
nInchesWeWant - pt.x);
yOffset = max (0, GetDeviceCaps (hPrnDC, LOGPIXELSY) *
nInchesWeWant - pt.y);
// Whendo
ing all the output, you can either offset it by the above
// values or call SetViewportOrg() to set the point (0,0) at
// the margin offset you calculated.
SetViewportOrg (hPrnDC, xOffset, yOffset);
... all other output here ...

calculate the bottom and right margins
a. Obtain the total size of the physical page (including printable and

unprintable areas) by using the GETPHYSPAGESIZE printer escape in
Windows or by calling GetDeviceCaps() with the PHYSICALWIDTH and
PHYSICALHEIGHT indices in Windows NT.
b. Determine the number of pixels required to yield the desired right

and bottom margins by calling GetDeviceCaps using the LOGPIXELSX and
LOGPIXELSY flags.
c. Calculate the size of the printable area with GetDeviceCaps() using

the HORZRES and VERTRES flags.
The following code fragment illustrates steps 2a through 2c:

// In Windows NT, the following 2 calls replace GETPHYSPAGESIZE
// pt.x = GetDeviceCaps(hPrnDC, PHYSICALWIDTH);
// pt.y = GetDeviceCaps(hPrnDC, PHYSICALHEIGHT);
// In Windows, use GETPHYSPAGESIZE to fill the POINT struct
// Drivers are not required to support the GETPHYSPAGESIZE escape,
// so call the QUERYESCSUPPORT printer escape to make sure
// it is supported.
Escape (hPrnDC, GETPHYSPAGESIZE, NULL, NULL, (LPPOINT) &pt);
xOffsetOfRightMargin = xOffset +
GetDeviceCaps (hPrnDC, HORZRES) -
pt.x -
GetDeviceCaps (hPrnDC, LOGPIXELSX) *
wInchesWeWant;
yOffsetOfBottomMargin = yOffset +
GetDeviceCaps (hPrnDC, VERTRES) -
pt.y -
GetDeviceCaps (hPrnDC, LOGPIXELSY) *
wInchesWeWant;

NOTE: Now, you can clip all output to the rectangle bounded by xOffset, yOffset, xOffsetOfRightMargin, and yOffsetOfBottomMargin.
For further information about margins, query in the Microsoft Knowledge Base by using these words:

GETPHYSPAGESIZE and GETPRINTINGOFFSET and GetDeviceCaps

 
是纸张吗?可以参考:
http://www.delphibbs.com/delphibbs/dispq.asp?lid=606836
http://www.delphibbs.com/delphibbs/dispq.asp?lid=110131
http://www.delphibbs.com/delphibbs/dispq.asp?lid=565730
http://www.delphibbs.com/delphibbs/dispq.asp?lid=173480
 
x := GetDeviceCaps(printer.Handle,PHYSICALOFFSETX);
// 返回42
y := GetDeviceCaps(printer.Handle,PHYSICALOFFSETY);
// 返回120
如何通过API调用设置打印区域边界?
 
这个就不太清楚了,晚上查查看。
 
非要用API吗!看了看很烦杂啊!,用Tprinter就能解决的,或者调用PrintDialog
或PrinterSetupDialog都可以呀!(不懂的说,唉期待高手!)
 
由于共享报表的纸张大小是自定义的,用户自定义的纸张类型又很多。
应用环境又不一样,有的是Win98、有的是Win2000。所以通过PrinterSetupDialog就不行。
在我的程序里使用自定义纸张大小,但是发现打印区域边界不为零。如何解决?
那为高手能为我提供一种解决办法。
 
请高手帮忙!!!
 
x := GetDeviceCaps(printer.Handle,PHYSICALOFFSETX);
// 返回42
y := GetDeviceCaps(printer.Handle,PHYSICALOFFSETY);
// 返回120
这两个只是取回打印机的边界范围,是以象素表示的。要设置边界,还必须取回打印机
的分辨率:每cm多少象素,有这样一个api函数。具体我记不清了。
 
如何在WINDOWS中控制打印字体的长宽,而不受限于SIZE 的限制

首先为了达到这个功能,可以采用Windows的逻辑字体(LogFont)
可以使用 CreateFont 或 CreateFontIndirect 这两个Windows API
函数来定义任何想要的字体,由于 CreateFont 所需的参数甚多通常
我们使用 CreateFontIndirect 来建立所需的逻辑字体,这个API函数
在Delphi中的声明为
function CreateFontIndirect(const p1: TLogFont): HFONT;
stdcall;
其中只有一个参数 p1: TLogfont
所有有关字体的参数完全通过这个
TLogfont结构来传送,Windows将根据结构中的内容创建出相应的逻辑
字体,在Delphi的Windows.pas中TLogFont是这样定义的

TLogFontA = packed record
lfHeight: Longint;
lfWidth: Longint;
lfEscapement: Longint;
lfOrientation: Longint;
lfWeight: Longint;
lfItalic: Byte;
lfUnderline: Byte;
lfStrikeOut: Byte;
lfCharSet: Byte;
lfOutPrecision: Byte;
lfClipPrecision: Byte;
lfQuality: Byte;
lfPitchAndFamily: Byte;
lfFaceName: array[0..LF_FACESIZE - 1] of AnsiChar;
end;

TLogFontW = packed record
lfHeight: Longint;
lfWidth: Longint;
lfEscapement: Longint;
lfOrientation: Longint;
lfWeight: Longint;
lfItalic: Byte;
lfUnderline: Byte;
lfStrikeOut: Byte;
lfCharSet: Byte;
lfOutPrecision: Byte;
lfClipPrecision: Byte;
lfQuality: Byte;
lfPitchAndFamily: Byte;
lfFaceName: array[0..LF_FACESIZE - 1] of WideChar;
end;

TLogFont = TLogFontA;

其中涉及到很多参数,其中

lfHeight: Longint;
指定以逻辑单位标定的字体高度,取值可为正负或零,对于需要随意
定义字体高度的情况下通常取负值,以保证获得实际尺寸的字体。

lfWidth: Longint;
用于指定字体的平均宽度,由于Windows系统下的大多数字体都是比例
字体因而采用平均宽度这个表示方法。若指定为0,则系统会自动根据
适当的比例自动处理宽度。

lfEscapement: Longint;
指定输出方向与当前坐标系X轴之间的以十分之一度为单位的角度。

lfOrientation: Longint;
指定每个字符与当前坐标系X轴之间的以十分之一度为单位的角度。在
Windows95中这个值等同于lfEscpement。

lfWeight: Longint;
指定范围为从0至1000的字体加重程度,400是标准字体700为加重字体,
0表示采用默认值。

lfItalic: Byte;
不为0表示采用斜体字。

lfUnderline: Byte;
不为0表示带下划线。

lfStrikeOut: Byte;
不为0表示带穿透线。

lfCharSet: Byte;
指定字体集。

lfOutPrecision: Byte;
指定输出精度。用于确定对前面一些设定值的精确程度。

lfClipPrecision: Byte;
指定裁剪精度。裁剪是Windows图形环境下的一种特殊处理,简单说就是
去掉图形中落在视图以外的部分,有助于提高图形的处理速度。

lfQuality: Byte;
指定输出质量。

lfPitchAndFamily: Byte;
指定字体的Pitch和Family。

lfFaceName: array[0..LF_FACESIZE - 1] of AnsiChar;
指定采用的字体名称。

在建立逻辑字体时,我们通常使用

lfHeight和lfWidth来确定字体的尺寸,使用lfEscapement和lfOrientation
来确定字体的输出方向,使用lfWeight
lfItalic
lfUnderline

lfStrikeOut
来确定字体的加重,斜体,下划线和穿透线,使用lfCharSet
来确定字体的字符集,通常采用系统默认的字符集。
对于lfOutPrecision
lfClipPrecision
lfQuality一般应用于对屏幕之外
的输出设备,通常采用默认值。采用lfPitchAndFamily来确定采用定宽或可
变字体和字体的家族。以lfFaceName来通过名称选择采用的字体。
另外应当注意在Windows环境下,每种字体具体输出为何种形式取决于很多
因素,需要对以上这些参数进行有效的组合才能达到所要的效果。
 
在我的程序里使用自定义纸张大小,但是发现打印区域边界不为零。如何解决?
呵呵,当然不为零了,这个问题浪费了我2个月的时间来实现,
打印时, 要根据具体的打印机用API计算一个调整数值,然后打印时在原来尺寸的基础上加上(还是减去,我忘了)这个数值的一半来调整。具体在我的“房地产开发估价管理系统”和“房屋安全鉴定管理系统”(http://yckxzjj.vip.sina.com/下载)中实现,但源代码一时不在身边,所以.....
 
顶部