用QRePort,怎么样可以在win98与win2000或NT下都能自定义纸张的大小?(100分)

  • 主题发起人 zengyixun
  • 开始时间
Z

zengyixun

Unregistered / Unconfirmed
GUEST, unregistred user!
用QRePort,怎么样可以在win98与win2000或NT下都能自定义纸张的大小?[red][/red][black][/black]
 
没有人知道吗?
 
一样呀,只是在2000下自定义纸张稍微有些不一样。
开始-》设定-》打印机-》文件-》服务器属性
这里面就有自定义纸张大小。
在QuickRep中,自定义纸张都是一样的。
 
我晕,我不是这个意思,我是说用代码控制,比如:
我设置一个纸张为长2000mm,高度为800mm,怎么样设置自定义的纸张就是这么大,要我的报表
在打印之前自动设置为它。
 
看看我的解决方法,只在2000和NT下试过,在98下据说api的调用有所不同,
象DEVMODE结构有些参数在98下无效。
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1215448
 
to mor:
不错,你说的可能有用,不过,我是不要打印设置窗口,这么说吧,我想写一个自定义纸张的
打印函数。参数为操作系统的认定,与纸张的长,纸张的高,然后调用这个函数后,一切就
设定好了,不用自己去对打印页面进行设置。
Function myprint_page(option_sys,width,height:integer;):boolean;//1为98,2为NT,3为2000
 
to mor:
不错,你说的可能有用,不过,我是不要打印设置窗口,这么说吧,我想写一个自定义纸张的
打印函数。参数为操作系统的认定,与纸张的长,纸张的高,然后调用这个函数后,一切就
设定好了,不用自己去对打印页面进行设置。
Function myprint_page(option_sys,width,height:integer):boolean;//1为98,2为NT,3为2000
 
还有人吗
 
怎么没有人呢?
 
去看看前面的问题吧,这个问题已经被讨论过很多遍了。当然每个人都可能会碰到一些特殊
的情况,但你的问题是一个通用型的问题,有通用的解决方法。
solution1:用Delphi.Printers.TPrinter类,一般的问题都能解决,如果这个类不能解决,
或者结果不理想的话就直接调用api函数吧。
solution2:用Delphi.WinSpool里申明好的外部函数,直接调用api,有什么不明白的去MSDN上
查。
这里附上用API的解决方法(TPrinter的方法前面的问题里讲的很详细了):
用OpenPrinter函数,通过这个方法可以得到打印机的句柄.
BOOL OpenPrinter(
LPTSTR pPrinterName, // printer or server name
LPHANDLE phPrinter, // printer or server handle
LPPRINTER_DEFAULTS pDefault // printer defaults
);

Parameters
pPrinterName
in Pointer to a null-terminated string that specifies the name of the printer
or print server.
Windows NT/2000/XP: If NULL, it indicates the local printer server.
phPrinter
out Pointer to a variable that receives a handle to the open printer or print
server object.
Windows 2000/XP: The phPrinter parameter can return an Xcv handle for use with
the XcvData function. For more information about XcvData, see the Microsoft
Windows 2000 Driver Development Kit.
pDefault
in Pointer to a PRINTER_DEFAULTS structure. This value can be NULL.
Return Values
If the function succeeds, the return value is a nonzero value.
If the function fails, the return value is zero. To get extended error
information, call GetLastError.
用SetForm来给一个特定的打印机设定纸张.
SetForm
The SetForm function sets the form information for the specified printer.
BOOL SetForm(
HANDLE hPrinter, // handle to printer object
LPTSTR pFormName, // form name
DWORD Level, // information level
LPBYTE pForm // form buffer
);

Parameters
hPrinter
in Handle to the printer for which the form information is set. Use the
OpenPrinter or AddPrinter function to retrieve a printer handle.
pFormName
in Pointer to a null-terminated string that specifies the form name for
which the form information is set.
Level
in Specifies the version of the structure to which pForm points. This
value must be 1.
pForm
in Pointer to a FORM_INFO_1 structure.
Return Values
If the function succeeds, the return value is a nonzero value.
If the function fails, the return value is zero. To get extended error
information, call GetLastError.
SetForm的第四个参数中设定你的自定义纸张.
typedef struct _FORM_INFO_1 {
DWORD Flags;
LPTSTR pName;
SIZEL Size;
RECTL ImageableArea;
} FORM_INFO_1, *PFORM_INFO_1;

Members
Flags
Specifies the form properties. The following values are defined. Value Meaning
FORM_USER If this bit flag is set, the form has been defined by the user.
Forms with this flag set are defined in the registry.
FORM_BUILTIN If this bit-flag is set, the form is part of the spooler. Form
definitions with this flag setdo
not appear in the registry.
FORM_PRINTER If this bit flag is set, the form is associated with a certain
printer, and its definition appears in the registry.

pName
Pointer to a null-terminated string that specifies the name of the form.
Size
Specifies the width and height, in thousandths of millimeters, of the form.
ImageableArea
Specifies the width and height, in thousandths of millimeters, of the form.
Requirements
Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Unsupported.
Header: Declared in Winspool.h;
include Windows.h.
Unicode: Declared as Unicode and ANSI structures.
以上的函数我在NT/2000/XP全部用过,98下没试过.
 
接受答案了.
 
顶部