FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour RPreview mal en xp - SOLUCIONADO (a medias)
Posts: 593
Joined: Sat May 12, 2007 11:47 AM
Re: RPreview mal en xp
Posted: Fri Oct 11, 2013 03:29 PM
Antonio,

Hice como dices, algo as铆:

Code (fw): Select all Collapse
  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 (fw): Select all Collapse
cBuf        := DibToStr( hDib )


Rolando :-)
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: RPreview mal en xp
Posted: Fri Oct 11, 2013 03:44 PM
Code (fw): Select all Collapse
聽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)
Posts: 593
Joined: Sat May 12, 2007 11:47 AM
Re: RPreview mal en xp
Posted: Fri Oct 11, 2013 04: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

Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: RPreview mal en xp
Posted: Fri Oct 11, 2013 05:26 PM
Y como decia Jack, vamos por partes :-)
Code (fw): Select all Collapse
聽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)
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: RPreview mal en xp
Posted: Fri Oct 11, 2013 05:34 PM
Code (fw): Select all Collapse
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
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: RPreview mal en xp
Posted: Fri Oct 11, 2013 05: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)
Posts: 593
Joined: Sat May 12, 2007 11:47 AM
Re: RPreview mal en xp
Posted: Fri Oct 11, 2013 05:49 PM
Carlos:

Pas贸 1 hBmp No Valido Pas贸 2 hDib No Valido

Siguiento tu ejemplo agregu茅:

Code (fw): Select all Collapse
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 :-)
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: RPreview mal en xp
Posted: Fri Oct 11, 2013 06: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 (fw): Select all Collapse
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)
Posts: 593
Joined: Sat May 12, 2007 11:47 AM
Re: RPreview mal en xp
Posted: Fri Oct 11, 2013 06: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

Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: RPreview mal en xp
Posted: Fri Oct 11, 2013 06: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: " + alltrim( str( oRect:nWidth ) ) ) //NEW
OutputDebugString( "oRect: " + alltrim( str( oRect:nHeight ) ) ) //NEW
OutputDebugString( "cBuf: " + cBuf ) //NEW
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 593
Joined: Sat May 12, 2007 11:47 AM
Re: RPreview mal en xp
Posted: Fri Oct 11, 2013 06:21 PM
Code (fw): Select all Collapse
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
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: RPreview mal en xp
Posted: Fri Oct 11, 2013 06: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 (fw): Select all Collapse
   ...
   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 (fw): Select all Collapse
#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)
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: RPreview mal en xp
Posted: Fri Oct 11, 2013 06:32 PM
veamos el contenido de cbuf y oRect:nWidth y oRect:nHeight
Code (fw): Select all Collapse
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: " + alltrim( str( oRect:nWidth ) ) ) //NEW
OutputDebugString( "oRect: " + alltrim( str( oRect:nHeight ) ) ) //NEW
OutputDebugString( "cBuf: " + cBuf ) //NEW
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: RPreview mal en xp
Posted: Fri Oct 11, 2013 06:36 PM
Antonio, a rolando le dan estos valores:

oRect: 13668.00
oRect: 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)
Posts: 593
Joined: Sat May 12, 2007 11:47 AM
Re: RPreview mal en xp
Posted: Fri Oct 11, 2013 06:37 PM
Carlos,

Agregu茅 la funci贸n reformada y ahora indica:

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