FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour PrinterDCFromName en FWH 12.04 (Solucionado)
Posts: 728
Joined: Fri Oct 07, 2005 07:38 AM
PrinterDCFromName en FWH 12.04 (Solucionado)
Posted: Thu Apr 10, 2014 08:49 AM
Buenos d铆as amigos, estoy teniendo un problema con la funci贸n PrinterDCFromName() que viene definida en printdc.c

Code (fw): Select all Collapse
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 (fw): Select all Collapse
::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,
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: PrinterDCFromName en FWH 12.04
Posted: Fri Apr 11, 2014 07:40 AM
Angel,

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

Code (fw): Select all Collapse
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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 728
Joined: Fri Oct 07, 2005 07:38 AM
Re: PrinterDCFromName en FWH 12.04
Posted: Fri Apr 11, 2014 08:25 AM
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 (fw): Select all Collapse
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
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: PrinterDCFromName en FWH 12.04
Posted: Sat Apr 12, 2014 09:51 AM

Angel,

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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 728
Joined: Fri Oct 07, 2005 07:38 AM
Re: PrinterDCFromName en FWH 12.04
Posted: Mon Apr 14, 2014 09:06 AM
Estoy haciendo las pruebas con una impresora PDF y al hacer el msginfo devuelve :

Code (fw): Select all Collapse
PDFCreator,winspool,Ne01:
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
Posts: 728
Joined: Fri Oct 07, 2005 07:38 AM
Re: PrinterDCFromName en FWH 12.04
Posted: Wed Apr 23, 2014 07:47 PM

隆Up! :D

Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: PrinterDCFromName en FWH 12.04
Posted: Wed Apr 23, 2014 07:56 PM
Hola, mira se es esto que necesitas:

Code (fw): Select all Collapse
//----------------------------------------------------------------------------//

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


Jo茫o Santos - S茫o Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 728
Joined: Fri Oct 07, 2005 07:38 AM
Re: PrinterDCFromName en FWH 12.04
Posted: Fri Apr 25, 2014 01:30 PM

karinha, funcion贸 perfecto. Muchas gracias.

Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: PrinterDCFromName en FWH 12.04 (Solucionado)
Posted: Wed Feb 25, 2015 09:00 AM
Hello,
I am using FWH v. 15.01 and when I do:
Code (fw): Select all Collapse
oDevice 聽 聽 聽 聽:= TPrinter():New("TLPosWin report",,lPreview,wModel,,)

returns a printer without hDC.
I checked the method
Code (fw): Select all Collapse
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 (fw): Select all Collapse
wModel 聽 聽 聽:= PrnGetName() 聽+ "," + PrnGetDrive() + "," + PrnGetPort()


Is there a way to make the code working without modify FiveH32.lib?
thanks,
Antonino Perricone
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: PrinterDCFromName en FWH 12.04 (Solucionado)
Posted: Wed Feb 25, 2015 09:43 AM
I soved it!!
I do:
Code (fw): Select all Collapse
SetPrintDefault(wModel)
oDevice        := TPrinter():New("TLPosWin report",,lPreview,,,)

:-)

Continue the discussion