在DELPHI下怎样用打印机自己的指令集来控制它的打印行为 (100分)

  • 主题发起人 主题发起人 guhejianxin
  • 开始时间 开始时间
G

guhejianxin

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠:
我遇到了用打印机自己的指令集,在DELPHI下直接控制
打印机的问题,但我不知道DELPHI与打印机指令集之间怎么联系起来,也请
帮我一个忙!!!
 
刚在DFW上抄来的:
assignfile(f,'lpt');
rewriter(f);
writerln(f,chr(13)+chr(10));
close(f);
 
应该把其中一行改了:
writerln(f,chr(27)+chr(?));
因为Chr(27)是国家标准的ESC指令,后面跟的那些有不同的功能,其详细功能要看看打印机
的说明书,各种打印机都不是尽相同的。
 
http://211.101.4.25/delphibbs/dispq.asp?lid=584736
上面有我写的关于直接控制打印机的代码。这个程序现在还在用。
如果修改一下,还把控制码可以送往网络打印机。
至于要灵活控制,你自己参照着做就行了,我当时没有仔细考虑,达到基本功能就交差了。
关于技术的细节问题及思路,在《DELPHI开发人员指南》中有详细论述。
 
USB打印机可以用吗
 
我也说几句,TPRINTER常用的方法
begin
DOC 启动打印任务,如果成功,调用ENDDOC来结束打印
NEWPAGE 从新的一页开始打印
ABORT 终止打印
 
我用quickrep打印完后,总是走纸,怎么设其不走纸?
 
Function Escape(hdc:Hdc;
nEscape,cbInput:Integer;
lpvInData:LPCSTR;
lpvOutData:LPVOID):Integer;
 
goodfox2002:
不明白怎么用法。细说一下好吗?
 
这是一个API函数。我当时成功的控制连续打印的纸张长度调整。
下面是D3.0的一个例子:
Var
PageMargin:Tpoint;
MyEscape:Integer;
begin

PageMargin.x:=0;
PageMargin.y:=0;
MyEscape:=GETPRINTINGOFFSET;
if Escape(Printer.Canvas.Handle,QUERYESCSUPPORT,Sizeof(MyEscape),@MyEscape,Nil)>0 then

//监测驱动程序是否支持该控制码
begin

if Escape(printer.canvas.handle,GETPRINTINGOFFSET,0,nil,@PageMargin)<=0
//调用成功后返回>0
then
begin

PageMargin.x:=0;
PageMargin.y:=0;
end;

end;

end;


//下面是API的Help文本,你用具体打印机的说明书试一试。
The Escape function allows applications to access capabilities of a particular device not directly available through GDI. Escape calls made by an application are translated and sent to the driver.

int Escape(

HDC hdc, // handle to device context 打印机句柄
int nEscape, // escape function 控制码
int cbInput, // number of bytes in input structure 输入数据字节数
LPCSTR lpvInData, // pointer to input structure 控制码输入数据结构
LPVOID lpvOutData // pointer to output structure 控制码返回数据结构
);


Parameters

hdc

Identifies the device context.

nEscape

Specifies the escape function to be performed. This parameter must be one of the predefined escape values. Use the ExtEscape function if your application defines a private escape value.

cbInput

Specifies the number of bytes of data pointed to by the lpvInData parameter.

lpvInData

Points to the input structure required for the specified escape.

lpvOutData

Points to the structure that receives output from this escape. This parameter should be NULL if no data is returned.



Return Values

If the function succeeds, the return value is greater than zero, except with the QUERYESCSUPPORT printer escape, which checks for implementation only. If the escape is not implemented, the return value is zero.
If the function fails, the return value is an error. To get extended error information, call GetLastError.

Errors

If the function fails, the return value is one of the following values.

Value Meaning
SP_ERROR General error. If SP_ERROR is returned, Escape may set the last error code to:ERROR_INVALID_PARAMETER
ERROR_DISK_FULL
ERROR_NOT_ENOUGH_MEMORY
ERROR_PRINT_CANCELLED
SP_OUTOFDISK Not enough disk space is currently available for spooling, and no more space will become available.
SP_OUTOFMEMORY Not enough memory is available for spooling.
SP_USERABORT The user terminated the job through Windows Print Manager.


Remarks

The Win32 API provides six new functions that supersede some printer escapes:

Function Description
AbortDoc Terminates a print job. Supersedes the ABORTDOC escape.
EndDoc Ends a print job. Supersedes the ENDDOC escape.
EndPage Ends a page. Supersedes the NEWFRAME escape. Unlike NEWFRAME, this function is always called after printing a page.
SetAbortProc Sets the abort function for a print job. Supersedes the SETABORTPROC escape.
StartDoc Starts a print job. Supersedes the STARTDOC escape.
StartPage Prepares printer driver to receive data.


The Win32 API provides six new indexes for the GetDeviceCaps function that supersede some printer escapes:

Index Description
PHYSICALWIDTH For printing devices: the width of the physical page, in device units. For example, a printer set to print at 600 dpi on 8.5"x11" paper has a physical width value of 5100 device units. Note that the physical page is almost always greater than the printable area of the page, and never smaller.
PHYSICALHEIGHT For printing devices: the height of the physical page, in device units. For example, a printer set to print at 600 dpi on 8.5"x11" paper has a physical height value of 6600 device units. Note that the physical page is almost always greater than the printable area of the page, and never smaller.
PHYSICALOFFSETX For printing devices: the distance from the left edge of the physical page to the left edge of the printable area, in device units. For example, a printer set to print at 600 dpi on 8.5"x11" paper, that cannot print on the leftmost 0.25" of paper, has a horizontal physical offset of 150 device units.
PHYSICALOFFSETY For printing devices: the distance from the top edge of the physical page to the top edge of the printable area, in device units. For example, a printer set to print at 600 dpi on 8.5"x11" paper, that cannot print on the topmost 0.5" of paper, has a vertical physical offset of 300 device units.


Of the original printer escapes, only the following can be used by Win32-based application:

Escape Description
QUERYYESCSUPPORT Determines whether a particular escape is implemented by the device driver.


Following is a list of the obsolete printer escapes that are supported only for compatibility with 16-bit versions of Windows:

Escape Description
ABORTDOC Stops the current print job and erases everything the application has written to the device since the last ENDDOC escape.
ENDDOC Ends a print job started by the STARTDOC escape.
GETPHYSPAGESIZE Retrieves the physical page size and copies it to the specified location.
GETPRINTINGOFFSET Retrieves the offset from the upper-left corner of the physical page where the actual printing or drawing begin
s.
GETSCALINGFACTOR Retrieves the scaling factors for the x-axis and the y-axis of a printer.
NEWFRAME Informs the printer that the application has finished writing to a page.
NEXTBAND Informs the printer that the application has finished writing to a band.
PASSTHROUGH Allows the application to send data directly to a printer.
SETABORTPROC Sets the Abort function for a print job.
STARTDOC Informs a printer driver that a new print job is starting.


See Also

AbortDoc, EndDoc, EndPage, ExtEscape, SetAbortProc, StartDoc, StartPage, ResetDC
 
后退
顶部