HOWTO: Use PASSTHROUGH Escape to Send Data Directly to PrinterID: Q96795
|
By using the Windows API Escape() function, your application can pass data
directly to the printer. If the printer driver supports the PASSTHROUGH
printer escape, you can use the Escape() function and the PASSTHROUGH
printer escape to send native printer language codes to the printer driver.
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.
A printer driver that supports the PASSTHROUGH printer escape does not add
native printer language codes to the data stream sent to the printer, so
you can send data directly to the printer. However, Microsoft recommends
that applications not perform functions that consume printer memory, such
as downloading a font or a macro.
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:
Q138594 : HOWTO: Send Raw Data to a Printer by Using the Win32 API
' 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
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"
End Sub
Sub List1_Click
Select Case List1.ListIndex
Case 0:
PCL_Escape$ = Chr$(27) + RevLandScape
Case 1:
PCL_Escape$ = Chr$(27) + Portrait
Case 2:
PCL_Escape$ = Chr$(27) + ManualFeed
Case 3:
PCL_Escape$ = Chr$(27) + AutoFeed
End Select
' Enter the following two lines as one, single line:
PCL_Escape$ = Chr$(Len(PCL_Escape$) MOD 256)
+ Chr$(Len(PCL_Escape$) \ 256) + PCL_Escape$
Printer.Print ""
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
sequence.", 48
Case Is > 0: MsgBox "Escape Successfully sent.
Sending test printout to printer."
Printer.Print "Test case of "; List1.Text
Printer.EndDoc
End Select
End Sub
Additional query words: kbVBp100 kbVBp200 kbVBp300
Keywords : kbprint kbPrinting
Version : WINDOWS:1.0,2.0,3.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: May 19, 1999