RPreview mal en xp - SOLUCIONADO (a medias)

Re: RPreview mal en xp

Postby rolando » Fri Oct 11, 2013 3:29 pm

Antonio,

Hice como dices, algo así:

Code: Select all  Expand view
 FillRect( hDC, oRect:aRect, GetStockObject( 0 ) )
   PlayEMF( hDC, hEMF, oRect:cRect )
OutputDebugString( "Pasó 1")
   hDib        := DibFromBitmap( hBmp )
OutputDebugString( "Pasó 2")
   cBuf        := DibToStr( hDib )
OutputDebugString( "Pasó 3")
   GlobalFree( hDib )


Y llega al "Pasó 2", de lo cual surge que la línea que lo detiene es:
Code: Select all  Expand view
cBuf        := DibToStr( hDib )


Rolando :D
User avatar
rolando
 
Posts: 593
Joined: Sat May 12, 2007 11:47 am
Location: San Nicolás - BA - ARGENTINA

Re: RPreview mal en xp

Postby carlos vargas » Fri Oct 11, 2013 3:44 pm

Code: Select all  Expand view

 FillRect( hDC, oRect:aRect, GetStockObject( 0 ) )
   PlayEMF( hDC, hEMF, oRect:cRect )
OutputDebugString( "Pasó 1")
   hDib        := DibFromBitmap( hBmp )
OutputDebugString( "Pasó 2")
   if hDib<>0
      OutputDebugString( "hDib Valido" )
   else
      OutputDebugString( "hDib No Valido" )
   endif
   cBuf        := DibToStr( hDib )
OutputDebugString( "Pasó 3")
   GlobalFree( hDib )
 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1683
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: RPreview mal en xp

Postby rolando » Fri Oct 11, 2013 4:01 pm

Carlos,

"Dib No Valido"

No entiendo de "C" pero esto me hace pensar que falla en la función "HB_FUNC( DIBFROMBITMAP )" contenida en el "dibbmp.c"

Como decía el Chapulín Colorado: Y ahora, ¿Quién podrá ayudarme?.

Gracias.

Rolando :D
User avatar
rolando
 
Posts: 593
Joined: Sat May 12, 2007 11:47 am
Location: San Nicolás - BA - ARGENTINA

Re: RPreview mal en xp

Postby carlos vargas » Fri Oct 11, 2013 5:26 pm

Y como decia Jack, vamos por partes :-)
Code: Select all  Expand view


 FillRect( hDC, oRect:aRect, GetStockObject( 0 ) )
   PlayEMF( hDC, hEMF, oRect:cRect )
OutputDebugString( "Pasó 1")
   if hBmp<>0 /// nuevo
      OutputDebugString( "hBmp Valido" )
   else
      OutputDebugString( "hBmp No Valido" )
   endif        ////
   hDib        := DibFromBitmap( hBmp )
OutputDebugString( "Pasó 2")
   if hDib<>0
      OutputDebugString( "hDib Valido" )
   else
      OutputDebugString( "hDib No Valido" )
   endif
   cBuf        := DibToStr( hDib )
OutputDebugString( "Pasó 3")
   GlobalFree( hDib )
 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1683
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: RPreview mal en xp

Postby carlos vargas » Fri Oct 11, 2013 5:34 pm

Code: Select all  Expand view


static function Emf2Jpeg( cEMF )

   local cJpeg    := cFileSetExt( cEMF, "jpg" )
   local hDC1, hDC, hDib, hDib2, hMem, hBmp, hOldBmp, hEMF
   local cBuf, oRect, lRet := .f.
   local nFormat

   cBuf         := MemoRead( cEMF )
   oRect        := TRect():New( 0, 0, Bin2L( SubStr( cBuf, 21, 4 ) ) / 2, ;
                                  Bin2L( SubStr( cBuf, 17, 4 ) ) / 2  )
   hEMF        := GetEnhMetaFile( cEMF )
   hDC1        := GetDC( GetDesktopWindow() )
   hDC         := CreateCompatibleDC( hDC1 )
   hBmp        := CreateCompatibleBitmap( hDC1, oRect:nWidth, oRect:nHeight )
   hOldBmp     := SelectObject( hDC, hBmp )
   FillRect( hDC, oRect:aRect, GetStockObject( 0 ) )
   PlayEMF( hDC, hEMF, oRect:cRect )

   OutputDebugString( "hEMF: " + alltrim( str( hEMF ) ) )
   OutputDebugString( "hDC1: " + alltrim( str( hDC1 ) ) )
   OutputDebugString( "hDC: " + alltrim( str( hDC ) ) )
   OutputDebugString( "hBmp: " + alltrim( str( hBmp ) ) )
   OutputDebugString( "hOldBmp: " + alltrim( str( hOldBmp ) ) )
   ...
 

un valor diferente de cero indica ok, un valor de cero = problemas.
por favor indica los resultados.

salu2
carlos vargas
Last edited by carlos vargas on Fri Oct 11, 2013 5:46 pm, edited 1 time in total.
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1683
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: RPreview mal en xp

Postby carlos vargas » Fri Oct 11, 2013 5:38 pm

Antonio, la función memoread la he usado antes para leer archivo binarios y en ocasiones me fallaba leyendo menos del tamaño real del archivo en cuestión, en su lugar use FileStr de CA-Tools y cero problemas.
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1683
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: RPreview mal en xp

Postby rolando » Fri Oct 11, 2013 5:49 pm

Carlos:

Pasó 1 hBmp No Valido Pasó 2 hDib No Valido

Siguiento tu ejemplo agregué:

Code: Select all  Expand view
cBuf         := MemoRead( cEMF )
   oRect        := TRect():New( 0, 0, Bin2L( SubStr( cBuf, 21, 4 ) ) / 2, ;
                                  Bin2L( SubStr( cBuf, 17, 4 ) ) / 2  )
   hEMF        := GetEnhMetaFile( cEMF )
   hDC1        := GetDC( GetDesktopWindow() )
   hDC         := CreateCompatibleDC( hDC1 )
if hDC<>0 //
      OutputDebugString( "hDC Valido1" )
   else
      OutputDebugString( "hDC No Valido1" )
endif      
   
   hBmp        := CreateCompatibleBitmap( hDC1, oRect:nWidth, oRect:nHeight )
if hBmp<>0 //
      OutputDebugString( "hBmp Valido1" )
   else
      OutputDebugString( "hBmp No Valido1" )
endif  
   
   hOldBmp     := SelectObject( hDC, hBmp )
   FillRect( hDC, oRect:aRect, GetStockObject( 0 ) )
   PlayEMF( hDC, hEMF, oRect:cRect )
OutputDebugString( "Pasó 1")
 //  hDib        := DibFromBitmap( hBmp )
  if hBmp<>0 /// nuevo
      OutputDebugString( "hBmp Valido2" )
   else
      OutputDebugString( "hBmp No Valido2" )
  endif        ////
   hDib        := DibFromBitmap( hBmp )
OutputDebugString( "Pasó 2")
if hDib<>0
      OutputDebugString( "hDib Valido" )
  else
      OutputDebugString( "hDib No Valido" )
endif
   
   cBuf        := DibToStr( hDib )
   
OutputDebugString( "Pasó 3")
   GlobalFree( hDib )


y ahora entrega:

hDC Valido1 hBmp No Valido1 Pasó 1 hBmp No Valido2 Pasó 2h Dib No Valido

Si no me equivoco habría que buscar en la "CreateCompatibleBitmap( hDC1, oRect:nWidth, oRect:nHeight )"

Rolando :D
User avatar
rolando
 
Posts: 593
Joined: Sat May 12, 2007 11:47 am
Location: San Nicolás - BA - ARGENTINA

Re: RPreview mal en xp

Postby carlos vargas » Fri Oct 11, 2013 6:00 pm

rolando prueba con el codigo anterio, el problema es un valor no valido para hBmp, pero este valor depende de otro hDC1 y este de hDC, por eso mejor validemos todos las variables:

Code: Select all  Expand view

static function Emf2Jpeg( cEMF )

   local cJpeg    := cFileSetExt( cEMF, "jpg" )
   local hDC1, hDC, hDib, hDib2, hMem, hBmp, hOldBmp, hEMF
   local cBuf, oRect, lRet := .f.
   local nFormat

   cBuf         := MemoRead( cEMF )
   oRect        := TRect():New( 0, 0, Bin2L( SubStr( cBuf, 21, 4 ) ) / 2, ;
                                  Bin2L( SubStr( cBuf, 17, 4 ) ) / 2  )
   hEMF        := GetEnhMetaFile( cEMF )
   hDC1        := GetDC( GetDesktopWindow() )
   hDC         := CreateCompatibleDC( hDC1 )
   hBmp        := CreateCompatibleBitmap( hDC1, oRect:nWidth, oRect:nHeight )
   hOldBmp     := SelectObject( hDC, hBmp )
   FillRect( hDC, oRect:aRect, GetStockObject( 0 ) )
   PlayEMF( hDC, hEMF, oRect:cRect )

   OutputDebugString( "GetDesktopWindows: " + alltrim( str( GetDesktopWindow() ) ) )
   OutputDebugString( "hEMF: " + alltrim( str( hEMF ) ) )
   OutputDebugString( "hDC1: " + alltrim( str( hDC1 ) ) )
   OutputDebugString( "hDC: " + alltrim( str( hDC ) ) )
   OutputDebugString( "hBmp: " + alltrim( str( hBmp ) ) )
   OutputDebugString( "hOldBmp: " + alltrim( str( hOldBmp ) ) )
   ...
 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1683
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: RPreview mal en xp

Postby rolando » Fri Oct 11, 2013 6:11 pm

Carlos,

GetDesktopWindows: 65556
hEMF: -1404692056
hDC1: 50409525
hDC: 318840043
hBmp: 0
hOldBmp: 0
Pasó 1
hBmp No Valido
Pasó 2
hDib No Valido

Rolando :D
User avatar
rolando
 
Posts: 593
Joined: Sat May 12, 2007 11:47 am
Location: San Nicolás - BA - ARGENTINA

Re: RPreview mal en xp

Postby carlos vargas » Fri Oct 11, 2013 6:14 pm

OutputDebugString( "GetDesktopWindows: " + alltrim( str( GetDesktopWindow() ) ) )
OutputDebugString( "hEMF: " + alltrim( str( hEMF ) ) )
OutputDebugString( "hDC1: " + alltrim( str( hDC1 ) ) )
OutputDebugString( "hDC: " + alltrim( str( hDC ) ) )
OutputDebugString( "hBmp: " + alltrim( str( hBmp ) ) )
OutputDebugString( "hOldBmp: " + alltrim( str( hOldBmp ) ) )

OutputDebugString( "oRect:nWidth: " + alltrim( str( oRect:nWidth ) ) ) //NEW
OutputDebugString( "oRect:nHeight: " + alltrim( str( oRect:nHeight ) ) ) //NEW
OutputDebugString( "cBuf: " + cBuf ) //NEW
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1683
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: RPreview mal en xp

Postby rolando » Fri Oct 11, 2013 6:21 pm

Code: Select all  Expand view
GetDesktopWindows: 65556
hEMF: -1270473830
hDC1: -1358886322
hDC: -1191112475
hBmp: 0
hOldBmp: 0
oRect:nWidth: 13668.00
oRect:nHeight: 2097.00
cBuf:
Pasó 1
hBmp No Valido
Pasó 2
hDib No Valido
User avatar
rolando
 
Posts: 593
Joined: Sat May 12, 2007 11:47 am
Location: San Nicolás - BA - ARGENTINA

Re: RPreview mal en xp

Postby carlos vargas » Fri Oct 11, 2013 6:30 pm

la función CreateCompatibleBitMap, es solamente un wrapper a api de windows, y aparenta estar correcta, a exepcion de que los parametros numero 2 y 3 segun el SDK de MS deben ser Enteros y no Long como esta en codigo de FWH, pero aun así no debería haber problemas, asi que no es por aca el problemas

ya validamos el valor del primer parametro pasado, veamos la validacion de los dos ultimos parametros.

es muy probable que en la estructura oRect sea el problema a falta de saber el valor de cBuf
Code: Select all  Expand view

   ...
   oRect        := TRect():New( 0, 0, Bin2L( SubStr( cBuf, 21, 4 ) ) / 2, ;
                                  Bin2L( SubStr( cBuf, 17, 4 ) ) / 2  )
   ...
   hBmp        := CreateCompatibleBitmap( hDC1, oRect:nWidth, oRect:nHeight )
   ...
 


Code: Select all  Expand view

#pragma BEGINDUM

#include <Windows.h>
#include <hbapi.h>

HB_FUNC( CREATECOMPATIBLEBITMAP ) // hDC, nWidth, nHeight
{
   /* hb_retnl( ( LONG ) CreateCompatibleBitmap( ( HDC ) hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ) ) );*/

   hb_retnl( ( LONG ) CreateCompatibleBitmap( ( HDC ) hb_parnl( 1 ), hb_parni( 2 ), hb_parni( 3 ) ) );
}

#pragma ENDDUMP
 


HBITMAP CreateCompatibleBitmap(
_In_ HDC hdc,
_In_ int nWidth,
_In_ int nHeight
);

Parameters
hdc [in]
A handle to a device context.
nWidth [in]
The bitmap width, in pixels.
nHeight [in]
The bitmap height, in pixels.
Return value
If the function succeeds, the return value is a handle to the compatible bitmap (DDB).
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1683
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: RPreview mal en xp

Postby carlos vargas » Fri Oct 11, 2013 6:32 pm

veamos el contenido de cbuf y oRect:nWidth y oRect:nHeight
Code: Select all  Expand view

OutputDebugString( "GetDesktopWindows: " + alltrim( str( GetDesktopWindow() ) ) )
OutputDebugString( "hEMF: " + alltrim( str( hEMF ) ) )
OutputDebugString( "hDC1: " + alltrim( str( hDC1 ) ) )
OutputDebugString( "hDC: " + alltrim( str( hDC ) ) )
OutputDebugString( "hBmp: " + alltrim( str( hBmp ) ) )
OutputDebugString( "hOldBmp: " + alltrim( str( hOldBmp ) ) )

OutputDebugString( "oRect:nWidth: " + alltrim( str( oRect:nWidth ) ) ) //NEW
OutputDebugString( "oRect:nHeight: " + alltrim( str( oRect:nHeight ) ) ) //NEW
OutputDebugString( "cBuf: " + cBuf ) //NEW
 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1683
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: RPreview mal en xp

Postby carlos vargas » Fri Oct 11, 2013 6:36 pm

Antonio, a rolando le dan estos valores:
oRect:nWidth: 13668.00
oRect:nHeight: 2097.00
cBuf:

en los casos de los valores de oRect:nWidth y oRect:nHeigh, no son valores mas altos de los esperados?
y el caso de cBuf, por que lo muestra vacio?

salu2
carlos vargas
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1683
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: RPreview mal en xp

Postby rolando » Fri Oct 11, 2013 6:37 pm

Carlos,

Agregué la función reformada y ahora indica:

Code: Select all  Expand view
GetDesktopWindows: 65556
hEMF: 742797656
hDC1: -1107225722
hDC: 1174483280
hBmp: 0
hOldBmp: 0
oRect:nWidth: 13668.00
oRect:nHeight: 2097.00
cBuf:
Pasó 1
hBmp No Valido
Pasó 2
hDib No Valido


Rolando :D
User avatar
rolando
 
Posts: 593
Joined: Sat May 12, 2007 11:47 am
Location: San Nicolás - BA - ARGENTINA

PreviousNext

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 87 guests