for another test I enhanced my example. I intergrated a second function for printing, but only with (x)Harbour functions, using the Win32Prn object. Please see function Test2 (..). This sample is now working with xHarbour and Harbour.
- Code: Select all Expand view RUN
- #include "FiveWin.ch"
#include "Objects.ch"
Procedure Main ()
LOCAL oPrn, oPrint,oFnt, cPrinter := ""
LOCAL oWnd, oBrw
LOCAL aPrn := {}
LOCAL cDef, i := 1
#ifdef __HARBOUR__ // GetPrinters() and GetDefaultPrinter() do not work in Harbour
aPrn := aGetPrinters ()
cDef := ""
#else
aPrn := GetPrinters ()
cDef := GetDefaultPrinter()
#endif
IF Empty (aPrn)
MsgAlert ("No Printers found" )//+ CRLF +;
RETURN
ENDIF
DEFINE DIALOG oWnd FROM 2, 2 TO 21, 50 TITLE "Available Printers"
@ 1, 2 LISTBOX oBrw FIELDS aPrn[ i ] ;
HEADERS "Printer Array" ;
FIELDSIZES 200 ;
OF oWnd ;
SIZE 100, 100
oBrw:bGoTop = { || i := 1 }
oBrw:bGoBottom = { || i := Eval( oBrw:bLogicLen )}
oBrw:bSkip = { | nWant, nOld | nOld := i, i += nWant, ;
i := Max( 1, Min( i, Eval( oBrw:bLogicLen ) ) ),;
i - nOld }
oBrw:bLogicLen = { || Len( aPrn ) }
oBrw:cAlias = "Array" // Just put something
@ 7.8,2 SAY "Default printer: " + cDef
@ 1,20 BUTTON "&Print (FW)" OF oWnd ACTION Testprint (aPrn[i])
@ 2,20 BUTTON "&Print (xH)" OF oWnd ACTION Test2 (aPrn[i])
@ 3,20 BUTTON "&End " OF oWnd ACTION oWnd:End()
ACTIVATE DIALOG oWnd CENTERED
RETURN
//-----------------------------------------------------------------------
PROCEDURE TestPrint(cPrn)
LOCAL oFnt, oPrint
LOCAL cText := "Dies ist ein Testtext zum drucken"
IF MsgYesNo ("Print to " + cPrn)
PRINT oPrint NAME "Formular" TO (cPrn)
DEFINE FONT oFnt NAME "ARIAL" SIZE 0,12 OF oPrint
oPrint:SetCopies (2)
oPrint:SetLandscape()
oPrint:Setup () // check the settings
PAGE
oPrint:CmSay (1,1, cText,oFnt)
ENDPAGE
ENDPRINT
oFnt:End()
ENDIF
RETURN
#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 )
#define FW_DONTCARE 0
#define FW_THIN 100
#define FW_EXTRALIGHT 200
#define FW_LIGHT 300
#define FW_NORMAL 400
#define FW_MEDIUM 500
#define FW_SEMIBOLD 600
#define FW_BOLD 700
#define FW_EXTRABOLD 800
#define FW_HEAVY 900
#define DMPAPER_A4 9
FUNCTION Test2 (cPrn)
LOCAL oPrinter
LOCAL aFonts, cFont, nFont
oPrinter := Win32Prn():new( cPrn) // Create printer object and configure print job
oPrinter:landscape := .F.
oPrinter:formType := DMPAPER_A4
oPrinter:copies := 2 // <--- 2 copies !!
IF .NOT. oPrinter:create() // Create device context
Alert( "Cannot create device context" )
QUIT
ENDIF
IF .NOT. oPrinter:startDoc( "xHarbour test page" ) // Create print job
Alert( "Cannot create document" )
QUIT
ENDIF
oPrinter:textOut( "Text in default font" ) // Text in fixed 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]
oPrinter:setFont( cFont ) // Text in proportional font
oPrinter:textOut( "Text in Arial font" )
oPrinter:bold( FW_EXTRABOLD )
oPrinter:textOut( oPrinter:fontName )
oPrinter:bold( FW_NORMAL )
oPrinter:newLine()
oPrinter:setColor( RGB_YELLOW, RGB_BLUE ) // Colored text
oPrinter:textOut( "Yellow on Blue" )
oPrinter:newLine()
oPrinter:setPen( PS_DASH, 5, RGB_GREEN ) // Draw colored line across page
oPrinter:line( oPrinter:posX, ;
oPrinter:posY, ;
oPrinter:rightMargin, ;
oPrinter:posY )
oPrinter:endDoc() // Send output to printer
oPrinter:destroy() // Release GDI device context
RETURN (nil)
Printing with the Win32Prn object is working as exspected, 2 copies are printed.
So it seems to be a bug in the print engine of fivewin. The settings are correct, but they seem not to be regnognized by the printer object and they are not sent to the printer.
Please, Antonio, could you check this ?