关于ESCAPE 这个API的用法(200分)

  • 主题发起人 主题发起人 LeonSu
  • 开始时间 开始时间
L

LeonSu

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.btn7Click(Sender: TObject);
var
s: WideString;
MyEscape:Integer;
begin
with Printerdo
begin
begin
Doc;
if Escape(Printer.Handle,QUERYESCSUPPORT,Sizeof(MyEscape),@MyEscape,Nil)<=0 then
raise Exception.Create('ERROR!');//如果不要这两句,则会出现非法调用的错误
s:=' ABCDEFGH';
Escape(Printer.Canvas.Handle,PASSTHROUGH,Length(s),@s,nil);
EndDoc;
end;
end;
程序始终要触发“ERROR!”错误。也就是说,我用ESCAPE没成功过
调用ESCAPE这个API倒底该如何做呢?
PS:不要叫我用assignfile或assignprn
 
MSDN 原文
Escape
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
Handle to 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
Pointer to the input structure required for the specified escape.
lpvOutData
Pointer 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.
Windows NT: To get extended error information, callGetLastError.
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 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&quot;x11&quot;
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&quot;x11&quot;
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&quot;x11&quot;
paper, that cannot print on the leftmost 0.25&quot;
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&quot;x11&quot;
paper, that cannot print on the topmost 0.5&quot;
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 applications:
Escape Description
QUERYESCSUPPORT 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.

QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in wingdi.h.
Import Library: Use gdi32.lib.
See Also
 
这篇文章我早就读过
 
没人回答吗????????????????
 
后退
顶部