PrinterDCFromName en FWH 12.04 (Solucionado)

PrinterDCFromName en FWH 12.04 (Solucionado)

Postby AngelSalom » Thu Apr 10, 2014 8:49 am

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,
Last edited by AngelSalom on Fri Apr 25, 2014 1:30 pm, edited 1 time in total.
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 727
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España

Re: PrinterDCFromName en FWH 12.04

Postby Antonio Linares » Fri Apr 11, 2014 7:40 am

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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: PrinterDCFromName en FWH 12.04

Postby AngelSalom » Fri Apr 11, 2014 8: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: 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
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 727
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España

Re: PrinterDCFromName en FWH 12.04

Postby Antonio Linares » Sat Apr 12, 2014 9:51 am

Angel,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: PrinterDCFromName en FWH 12.04

Postby AngelSalom » Mon Apr 14, 2014 9:06 am

Estoy haciendo las pruebas con una impresora PDF y al hacer el msginfo devuelve :

Code: Select all  Expand view
PDFCreator,winspool,Ne01:
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 727
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España

Re: PrinterDCFromName en FWH 12.04

Postby AngelSalom » Wed Apr 23, 2014 7:47 pm

¡Up! :D
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 727
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España

Re: PrinterDCFromName en FWH 12.04

Postby karinha » Wed Apr 23, 2014 7:56 pm

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


João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7804
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: PrinterDCFromName en FWH 12.04

Postby AngelSalom » Fri Apr 25, 2014 1:30 pm

karinha, funcionó perfecto. Muchas gracias.
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 727
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España

Re: PrinterDCFromName en FWH 12.04 (Solucionado)

Postby AntoninoP » Wed Feb 25, 2015 9:00 am

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
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: PrinterDCFromName en FWH 12.04 (Solucionado)

Postby AntoninoP » Wed Feb 25, 2015 9:43 am

I soved it!!
I do:
Code: Select all  Expand view

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

:D
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 50 guests