xHarbour Reference Documentation > Class Reference (textmode) |
Creates a new Win32Prn object.
Win32Prn():new( [<cPrinterName>] ) --> oWin32Prn
The function returns a new Win32Prn object and method :new() initializes the object.
Objects of class Win32Prn provide the means for printing using the Windows Graphical Device Interface (GDI). For this reason, an application using Win32Prn objects must be created as GUI application. Text mode applications, or console applications, cannot use the Win32Prn class.
After a Win32Prn object is initialized with the :new() method, it must request system recources with its :create() method. Before this method is called, a print job can be configured with instance variables of a Win32Prn object. They define the paper format, print orientation or number of copies to print. A Win32Prn object can only be used for printing when its :create() method is called.
A print job is started with the method :startDoc() after which various print output methods can be called. They define the actual output that appears on paper. :startDoc() defines the document name to print for the Windows GDI printer spooler and initiates a print job. The print job must be finished with method :endDoc(). Print output is sent to the printer after :endDoc() is called.
When a print job is finished, a Win32Prn object must release GDI system resources with its :destroy() method. As a result, the following programming pattern must be applied for successful GDI printing:
oPrinter := Win32Prn():new() // creates the object oPrinter:create() // requests system resources oPrinter:startDoc() // begins a document oPrinter:textOut( "Hello World" ) // print output methods oPrinter:endDoc() // ends document definition and prints oPrinter:destroy() // releases system resources
Coordinate system for GDI printing
The coordinate system has its origin in the upper left corner of a page. X and Y coordinates are measured in pixels. The X coordinate increases from left to right (horizontal coordinate), and the Y coordinate increases from the top to the bottom of a page (vertical coordinate).
To support the DOS Clipper dot-matrix printing style, the Win32Prn class has methods allowing for a row/column oriented positioning of print output. These methods emulate functions of the same name, like :pRow(), :pCol() or :setPrc().
Fonts
The default font is a DOS Clipper compatible fixed font (Courier New). A list of all available fonts can be obtained with method :getFonts(). Text is printed using the currently selected font, which is defined with method :setFont().
Printing text
Text is output at the current print position with method :textOut(), or at a particular X/Y coordinate with method :textOutAt(). The text color can be selected with method :setColor().
Printing lines
A variety of methods are available for drawing basic graphical elements, such as :arc(), :box() or :line(). The color and line style for these graphical elements is defined with method :setPen(). This method creates a pen capable of drawing lines.
Colors
Colors for GDI printing must be provided as numeric RGB color values. The console mode SetColor() strings cannot be used as color definition. RGB color values are calculated from three numeric values between 0 and 255. They define the intensity for Red, Green and Blue. An RGB color value can be calulated as follows:
FUNCTION RGB( nRed, nGreen, nBlue ) RETURN ( nRed + ( nGreen * 256 ) + ( nBlue * 65536 ) )
See also: | SET PRINTER, Win32Bmp() |
Category: | Object functions , Printer functions , xHarbour extensions |
Header: | wingdi.ch |
Source: | rtl\win32prn.prg |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example demonstrates basic print output using different // fonts, colors and graphical elements. // Note: create the EXE using the -gui switch #include "WinGdi.ch" #define RGB_BLACK RGB( 0, 0, 0 ) #define RGB_RED RGB( 255, 0, 0 ) #define RGB_GREEN RGB( 0,255, 0 ) #define RGB_BLUE RGB( 0, 0,255 ) #define RGB_CYAN RGB( 0,255,255 ) #define RGB_YELLOW RGB( 255,255, 0 ) #define RGB_MAGENTA RGB( 255, 0,255 ) #define RGB_WHITE RGB( 255,255,255 ) PROCEDURE Main LOCAL cPrinter := "EPSON Stylus DX5000 Series" LOCAL oPrinter LOCAL aFonts, cFont, nFont // Create printer object and configure print job oPrinter := Win32Prn():new( cPrinter ) oPrinter:landscape := .F. oPrinter:formType := DMPAPER_A4 oPrinter:copies := 1 // Create device context IF .NOT. oPrinter:create() Alert( "Cannot create device context" ) QUIT ENDIF // Create print job IF .NOT. oPrinter:startDoc( "xHarbour test page" ) Alert( "Cannot create document" ) QUIT ENDIF // Text in fixed font oPrinter:textOut( "Text in default font" ) oPrinter:bold( FW_EXTRABOLD ) oPrinter:textOut( oPrinter:fontName ) oPrinter:bold( FW_NORMAL ) oPrinter:newLine() aFonts := oPrinter:getFonts() nFont := AScan( aFonts, ; {|a| "ARIAL" $ Upper(a[1]) } ) cFont := aFonts[nFont,1] // Text in proportional font oPrinter:setFont( cFont ) oPrinter:textOut( "Text in Arial font" ) oPrinter:bold( FW_EXTRABOLD ) oPrinter:textOut( oPrinter:fontName ) oPrinter:bold( FW_NORMAL ) oPrinter:newLine() // Colored text oPrinter:setColor( RGB_YELLOW, RGB_BLUE ) oPrinter:textOut( "Yellow on Blue" ) oPrinter:newLine() // Draw colored line across page oPrinter:setPen( PS_DASH, 5, RGB_GREEN ) oPrinter:line( oPrinter:posX, ; oPrinter:posY, ; oPrinter:rightMargin, ; oPrinter:posY ) // Send output to printer oPrinter:endDoc() // Release GDI device context oPrinter:destroy() RETURN FUNCTION RGB( nRed, nGreen, nBlue ) RETURN ( nRed + ( nGreen * 256 ) + ( nBlue * 65536 ) )
http://www.xHarbour.com