Page 1 of 1

PrinterDCFromName en FWH 12.04 (Solucionado)

PostPosted: Thu Apr 10, 2014 8:49 am
by AngelSalom
Buenos días amigos, estoy teniendo un problema con la función PrinterDCFromName() que viene definida en printdc.c

Code: Select all  Expand view
HB_FUNC( PRINTERDCFROMNAME ) // ( cDriver, cModel, cPort )
{
   LPDEVMODE  lpDevMode;

   lpDevMode  = (LPDEVMODE) GlobalLock( pd.hDevMode );

   hb_retnl( ( LONG ) CreateDC( ( LPSTR ) hb_parc( 1 ),
                    ( LPSTR ) hb_parc( 2 ),
                    ( LPSTR ) hb_parc( 3 ),
                    lpDevMode ) );

   GlobalUnlock( pd.hDevMode );
}


El tema es que al intentar obtener un "handle" éste siempre me devuelve cero y no se consigue procesar la impresión :

Code: Select all  Expand view
::hDC = PrinterDcFromName( , cModel, )


He estado mirando en el foro y veo que ya se estuvo discutiendo acerca de este problema http://forums.fivetechsupport.com/viewtopic.php?f=3&t=27403&start=0 pero no se si finalmente se ha llegado a una conclusión.

Gracias,

Re: PrinterDCFromName en FWH 12.04

PostPosted: Fri Apr 11, 2014 7:40 am
by Antonio Linares
Angel,

Por favor comprueba que tengas este código en la Clase TPrinter (printer.prg):

Code: Select all  Expand view
METHOD New( cDocument, lUser, lPreview, cModel, lModal, lSelection, cFile ) CLASS TPrinter

   local aOffset
   local cPrinter

   DEFAULT cDocument  := "FiveWin Report" ,;
       lUser := .f., lPreview := .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
      ::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     = .f.
   ::lPreview  = lPreview
   ::lStarted  = .F.
   ::lModified = .F.
   ::lPrvModal = lModal

   if ! Empty( cFile ) .and. Lower( Right( cFile, 3 ) ) == "pdf"
      ::cFile   = cFile
      ::lMeta     = .t.
   elseif ::lPreview
      ::lMeta     = .t.
   endif

   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

Re: PrinterDCFromName en FWH 12.04

PostPosted: Fri Apr 11, 2014 8:25 am
by AngelSalom
Hola Antonio, lo acabo de comprobar y así lo tengo. De hecho lo rectifiqué en base al hilo que menciono en el anterior mensaje.

Code: Select all  Expand view
METHOD New( cDocument, lUser, lPreview, cModel, lModal, lSelection, cFile ) CLASS TPrinter

   local aOffset
   local cPrinter

   DEFAULT cDocument  := "FiveWin Report" ,;
       lUser := .f., lPreview := .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
      MSGINFO (CMODEL)
      ::hDC = PrinterDcFromName( , cModel, )
      MSGINFO ( ::hDC )
   endif

...
 


He puesto un par de Msginfo en el lugar donde debe crearse. La variable cModel me informa correctamente de la impresora que le paso pero ::hDC obtiene un valor cero.
Gracias

Re: PrinterDCFromName en FWH 12.04

PostPosted: Sat Apr 12, 2014 9:51 am
by Antonio Linares
Angel,

Puedes hacer MsgInfo( cModel ) y ver que valor te aparece ? gracias

Re: PrinterDCFromName en FWH 12.04

PostPosted: Mon Apr 14, 2014 9:06 am
by AngelSalom
Estoy haciendo las pruebas con una impresora PDF y al hacer el msginfo devuelve :

Code: Select all  Expand view
PDFCreator,winspool,Ne01:

Re: PrinterDCFromName en FWH 12.04

PostPosted: Wed Apr 23, 2014 7:47 pm
by AngelSalom
¡Up! :D

Re: PrinterDCFromName en FWH 12.04

PostPosted: Wed Apr 23, 2014 7:56 pm
by karinha
Hola, mira se es esto que necesitas:

Code: Select all  Expand view

//----------------------------------------------------------------------------//

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

   local aOffset
   local cPrinter

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

   if lUser

      ::hDC := GetPrintDC( GetActiveWindow(), lSelection, PrnGetPagNums() )

      if ::hDC != 0
         cModel = ::GetModel() + "," + ::GetDriver() + "," + ::GetPort()
      endif

   elseif cModel == nil  // Modified: 16/01/2014

      ::hDC  := GetPrintDefault( GetActiveWindow() )

      cModel = ::GetModel() + "," + ::GetDriver() + "," + ::GetPort()

      SetPrintDefault( cModel ) // NEW !!!  // 16/01/2014  Joao

   else

      cPrinter := GetProfString( "windows", "device" , "" )

      WriteProfString( "windows", "device", cModel )

      SysRefresh()

      PrinterInit()

      ::hDC := GetPrintDefault( GetActiveWindow() )

      SysRefresh()

      WriteProfString( "windows", "device", cPrinter  )

      SetPrintDefault( cPrinter ) // NEW !!!  Antonio Linares

   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     = .f.
   ::lPreview  = lPreview
   ::lStarted  = .F.
   ::lModified = .F.
   ::lPrvModal = lModal

   if ! Empty( cFile ) .and. Lower( Right( cFile, 3 ) ) == "pdf"
      ::cFile   = cFile
      ::lMeta     = .t.
   elseif ::lPreview
      ::lMeta     = .t.
   endif

   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



Re: PrinterDCFromName en FWH 12.04

PostPosted: Fri Apr 25, 2014 1:30 pm
by AngelSalom
karinha, funcionó perfecto. Muchas gracias.

Re: PrinterDCFromName en FWH 12.04 (Solucionado)

PostPosted: Wed Feb 25, 2015 9:00 am
by AntoninoP
Hello,
I am using FWH v. 15.01 and when I do:
Code: Select all  Expand view
oDevice        := TPrinter():New("TLPosWin report",,lPreview,wModel,,)

returns a printer without hDC.
I checked the method
Code: Select all  Expand view
METHOD New( cDocument, lUser, lPreview, cModel, lModal, lSelection, cFile ) CLASS TPrinter

and it does not have the modifications by karinha.
I setup the wModel with this code:
Code: Select all  Expand view
wModel      := PrnGetName()  + "," + PrnGetDrive() + "," + PrnGetPort()


Is there a way to make the code working without modify FiveH32.lib?
thanks,
Antonino Perricone

Re: PrinterDCFromName en FWH 12.04 (Solucionado)

PostPosted: Wed Feb 25, 2015 9:43 am
by AntoninoP
I soved it!!
I do:
Code: Select all  Expand view

SetPrintDefault(wModel)
oDevice        := TPrinter():New("TLPosWin report",,lPreview,,,)
 

:D