FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour FWH 8.12 Printer problem
Posts: 363
Joined: Wed Feb 15, 2006 02:06 PM
Re: FWH 8.12 Printer problem
Posted: Thu Jan 15, 2009 03:33 PM

Hold off on that version - just doing some more tests and on my machine the following seems to happen:

If you specify a printer, it always prints to default printer
If you don't specify a printer, the printer selection box appears and correctly prints to correct printer

I've linked version 7.12 of printer and all works ok so i will try and find the differences

Posts: 363
Joined: Wed Feb 15, 2006 02:06 PM
Re: FWH 8.12 Printer problem
Posted: Thu Jan 15, 2009 03:47 PM
Antonio,

I've been doing some tests and i think this should be the correct code:

Method New

METHOD New( cDocument, lUser, lMeta, cModel, lModal, lSelection ) CLASS TPrinter

   local aOffset
   local cPrinter

   DEFAULT cDocument  := "FiveWin Report" ,;
       lUser := .f., lMeta := .f., lModal := .f., lSelection := .f.

   if lUser
      ::hDC := GetPrintDC( GetActiveWindow(), lSelection, PrnGetPagNums() )
      if ::hDC != 0
         cModel = ::GetModel() + "," + ::GetDriver() + "," + ::GetPort()
      endif
   elseif cModel == nil
      ::hDC  := GetPrintDefault( GetActiveWindow() )
      if ::hDC != 0
         cModel = ::GetModel() + "," + ::GetDriver() + "," + ::GetPort()
      endif
   else
      cPrinter := GetProfString( "windows", "device" , "" )
      WriteProfString( "windows", "device", cModel )
      SysRefresh()
      PrinterInit()
      ::hDC := GetPrintDefault( GetActiveWindow() )
      SysRefresh()
      WriteProfString( "windows", "device", cPrinter  )
//      PrinterInit()
//      DeleteDC( ::hDC )
//      ::hDC = PrinterDCfromName( cModel )      
   endif

   if ::hDC != 0
      aOffset    = PrnOffset( ::hDC )
      ::nXOffset = aOffset[ 1 ]
      ::nYOffset = aOffset[ 2 ]
      ::nOrient  = ::GetOrientation()
   elseif ComDlgXErr() != 0
      MsgStop( "There are no printers installed!"  + CRLF + ;
               "Please exit this application and install a printer." )
      ::nXOffset = 0
      ::nYOffset = 0
   else                
      ::nXOffset = 0    
      ::nYOffset = 0    
      ::nOrient  = DMORIENT_PORTRAIT   
   endif

   ::cDocument = cDocument
   ::cModel    = cModel
   ::nPage     = 0
   ::nPad      = 0
   ::lMeta     = lMeta
   ::lStarted  = .F.
   ::lModified = .F.
   ::lPrvModal = lModal

   if !lMeta
      ::hDcOut = ::hDC
   else
      ::aMeta  = {}
      ::cDir   = GetEnv( "TEMP" )

      if Empty( ::cDir )
         ::cDir = GetEnv( "TMP" )
      endif

      if Right( ::cDir, 1 ) == "\"
         ::cDir = SubStr( ::cDir, 1, Len( ::cDir ) - 1 )
      endif

      if ! Empty( ::cDir )
         if ! lIsDir( ::cDir )
            ::cDir = GetWinDir()
         endif
      else
         ::cDir := GetWinDir()
      endif
   endif

return Self


I think this is what you initially stated in your first post

Function PrintBegin

function PrintBegin( cDoc, lUser, lPreview, xModel, lModal, lSelection )

   local aPrn
   local cText, cDevice
   local nScan

   if xModel == nil
      return oPrinter := TPrinter():New( cDoc, lUser, lPreview,, lModal, lSelection )
   endif

   cText := StrTran( GetProfString( "Devices" ),Chr(0), chr(13)+chr(10))
   aPrn  := Array( Mlcount( cText, 250 ) )

   Aeval(aPrn, {|v,e| aPrn[e] := Trim(Memoline(cText, 250, e)) } )

   if Valtype(xModel) == "N"
      if xModel < 0 .or. xModel > len(aPrn)
         nScan := 0
      else
         nScan := xModel
      endif
   else
      if ( nScan := Ascan( aPrn, {|v| Upper( xModel ) == Upper( v ) } ) ) == 0 
         nScan = Ascan( aPrn, {|v| Upper( xModel ) $ Upper( v ) } ) 
      endif      
   endif

   if nScan == 0
      MsgBeep()
      return oPrinter := TPrinter():New( cDoc, .T., lPreview,, lModal, lSelection )
   endif

   cText   := GetProfString( "Devices", aPrn[ nScan ] )
   cDevice := aPrn[ nScan ] + "," + cText

return oPrinter := TPrinter():New( cDoc, .f., lPreview, cDevice, lModal, lSelection )


This should revert back to it's original state

The above code changes seem to work fine on my system when i specify a printer and also when i dont specify a printer and choose from the printer selection list

Regards,

Pete
Posts: 130
Joined: Sat Oct 08, 2005 09:38 PM
Re: FWH 8.12 Printer problem
Posted: Thu Jan 15, 2009 03:50 PM
I confirm the bug. It always prints to the default printer.

If you are using Win XP, the best solution is to uncomment these lines
      cPrinter := GetProfString( "windows", "device" , "" )
      WriteProfString( "windows", "device", cModel )
      SysRefresh()
      PrinterInit()
      ::hDC := GetPrintDefault( GetActiveWindow() )
      SysRefresh()
      WriteProfString( "windows", "device", cPrinter  )

and comment these
      PrinterInit()
      DeleteDC( ::hDC )
      ::hDC = PrinterDCfromName( cModel )

Regards,
Birol Betoncu
Birol Betoncu
birol.betoncu@gmail.com
Using Harbour, FWH 19.05, BCC7
Posts: 363
Joined: Wed Feb 15, 2006 02:06 PM
Re: FWH 8.12 Printer problem
Posted: Thu Jan 15, 2009 03:55 PM

Emailed :)

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: FWH 8.12 Printer problem
Posted: Thu Jan 15, 2009 03:57 PM

Birol,

Ok, thanks for the info.

Now we know whats going on. A FWH user commented us about that change because there were some problems with Windows Vista SP2 printing but it seems as such change breaks XP compatibility.

So, for now, we revert those changes.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 130
Joined: Sat Oct 08, 2005 09:38 PM
Re: FWH 8.12 Printer problem
Posted: Thu Jan 15, 2009 04:05 PM

OK, thanks for your reply.

Birol Betoncu
birol.betoncu@gmail.com
Using Harbour, FWH 19.05, BCC7
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: FWH 8.12 Printer problem
Posted: Thu Jan 15, 2009 04:06 PM

Pete,

Thanks for the file.

Its fine. We have the same code :-)

We don't apply Enrico's proposed change. We revert back the recent changes in Class TPrinter.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: FWH 8.12 Printer problem
Posted: Thu Jan 15, 2009 04:50 PM
Works fine here (XP Pro SP3) with my fix and the following sample (Fax is not the default printer):

#include "FiveWin.ch"


FUNCTION MAIN()

    LOCAL oPrn, oFnt

    PRINT oPrn TO "Fax"
        DEFINE FONT oFnt NAME "Arial" SIZE 0, -10 OF oPrn

        PAGE
            oPrn:Say( 0, 0, "TEST", oFnt )
        ENDPAGE
    ENDPRINT

    RELEASE FONT oFnt

    RETURN NIL


EMG

Continue the discussion