The Escape Function

The Windows GDI module includes only one function—Escape—to support the additional requirements of printers. The name of this function implies that it is ignored by the GDI module and that it goes straight to the printer driver. In some cases, this is true, but often GDI also does some work during Escape calls.

The general syntax of Escape is:

nResult = Escape (hdcPrinter, nEscapeCode, nCount,

lpsDataIn, lpsDataOut) ;

The nEscapeCode parameter is a subfunction code that is specified using an identifier defined in WINDOWS.H. The last three parameters depend on the subfunction. Although the last two parameters are declared as far pointers to character strings, they are sometimes far pointers to structures. To cast the pointers into far pointers to strings, use (LPSTR).

Not all Escape subfunctions are implemented in all device drivers. In fact, Escape has been designed to be open-ended so that manufacturers of display devices can define their own Escape subfunctions to access certain unique facilities of the devices. The following Escape subfunctions are the ones I discuss in this chapter. They are implemented in all printer drivers:

nEscapeCode Description

STARTDOC Starts a document
ENDDOC Ends a document
SETABORTPROC Sets a pointer to the

”abort procedure“

NEWFRAME Ends the current page
NEXTBAND Gets rectangle coordi-

nates for the next band

nEscapeCode Description

ABORTDOC Aborts printing of

a document

GETPHYSPAGESIZE Gets the physical size

of the paper

QUERYESCSUPPORT Finds out if the driver

supports an Escape code


DEVCAPS2 used the QUERYESCSUPPORT subfunction to list supported Escape functions. The GETPHYSPAGESIZE subfunction returns the size of the paper, which will generally be larger than the printable area obtained from GetDeviceCaps. We'll use other subfunctions in programs later in this chapter. Escape always returns 0 if the subfunction is not implemented and a negative value if an error occurs. A positive value indicates success.