Printer escapes such as PASSTHROUGH allow applications to access certain facilities of output devices that are not directly available through the graphics device interface (GDI). The PASSTHROUGH printer escape allows the application to send data directly to the printer, bypassing the standard print-driver code.
The sample program listed below sends native PCL codes to the printer to change the page orientation and the paper bin. A Hewlett-Packard LaserJet is the assumed default printer.
NOTE: This is not a recommended solution. For a better solution for 32-bit, please see the following article in the Microsoft Knowledge Base:
An Important NoteThe Windows API Escape() function is provided in Windows versions 3.0 and 3.1 for backward compatibility with earlier versions of Microsoft Windows. Applications are supposed to use the GDI DeviceCapabilities() and ExtDeviceMode() functions instead of the Escape() function, but neither DeviceCapabilities() nor ExtDeviceMode() can be called directly from Visual Basic. This is because they are exported by the printer driver, not by the Windows GDI. The only way to use ExtDeviceMode() or DeviceCapabilities() in Visual Basic is to create a DLL and call them from there.
There have been reports of problems using the PASSTHROUGH escape with the driver HPPCL5A.DRV. This is the version of the printer driver for the HP LaserJet III series that shipped with Windows 3.1. A more recent version of the driver (HPPCL5MS.DRV), which has no known problems with the PASSTHROUGH escape, is available in the Windows Driver Library (WDL). To obtain the latest driver for the HP LaserJet III series, download the self-extracting file HPPCL5.EXE from the WDL.
Steps to Create Example
- Start Visual Basic or from the File menu, choose New Project (ALT, F, N) if Visual Basic is already running. Form1 is created by default.
- Add the following code to the general declarations section of Form1:
' Enter the entire Declare statement on one, single line.
Private Declare Function Escape Lib "Gdi" (ByVal Hdc%, ByVal nEscape%,
ByVal ncount%, ByVal indata$, ByVal oudata as Any) As Integer
Const PASSTHROUGH = 19
Const RevLandScape = "&l3O" ' PCL command to change Paper
' orientation to Reverse Landscape.
Const Portrait = "&l0O" ' PCL command to change paper
' orientation to Portrait.
Const ManualFeed = "&l3H" ' PCL command to change Paper Bin
' to Manual Feed Envelope.
Const AutoFeed = "&l1H" ' PCL command to change Paper Bin
' to Paper Tray AutoFeed
- Add a list box (List1) to Form1.
- Add the following code to Form1's Form_Load event procedure:
Sub Form_Load ()
List1.AddItem "HP/PCL Reverse Landscape"
List1.AddItem "HP/PCL Portrait"
List1.AddItem "HP/PCL Manual Feed Envelope"
List1.AddItem "HP/PCL Paper Tray Auto Feed"
- Add the following code to the List1_Click event procedure:
Select Case List1.ListIndex
PCL_Escape$ = Chr$(27) + RevLandScape
PCL_Escape$ = Chr$(27) + Portrait
PCL_Escape$ = Chr$(27) + ManualFeed
PCL_Escape$ = Chr$(27) + AutoFeed
' Enter the following two lines as one, single line:
PCL_Escape$ = Chr$(Len(PCL_Escape$) MOD 256)
+ Chr$(Len(PCL_Escape$) \ 256) + PCL_Escape$
Result% = Escape%(Printer.hDC, PASSTHROUGH, 0, PCL_Escape$, 0&)
Select Case Result%
' Enter each Case statement on one, single line.
Case Is < 0: MsgBox "The PASSTHROUGH Escape is not
supported by this printer driver.", 48
Case 0: MsgBox "An error occurred sending the escape
Case Is > 0: MsgBox "Escape Successfully sent.
Sending test printout to printer."
Printer.Print "Test case of "; List1.Text
- From the Run menu, choose Start (ALT, R, S) to run the program. List1 is filled with four escape sequences to send to the printer.
- Select any of the options in the list box. A message box appears to indicate the success of the operation.
ID do Artigo: 96795 - Última Revisão: 13 de jul de 2004 - Revisão: 1