FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Escalar BMP capturado con WndBitmap
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: Escalar BMP capturado con WndBitmap
Posted: Wed Dec 16, 2009 08:36 PM
Holas,

mas pruebas

Code (fw): Select all Collapse
#include "fivewin.ch"

FUNCTION  main()
   LOCAL oDlg, oBmp

   DEFINE DIALOG oDlg FROM 1,1 TO 20,20
   @ 0,0 BITMAP oBmp OF oDlg NOBORDER SIZE 25, 37
   ACTIVATE DIALOG oDlg NOWAIT
   createBmp( oDlg, oBmp )
   MSGINFO('HOLA')

   return nil

FUNCTION createBmp( oDlg, oBmp )

local hDC1 := GetDC( GetDesktopWindow() )
local hDC := CreateCompatibleDC( hDC1 )
LOCAL hDib
local hBmp := CreateCompatibleBitmap( hDC1, 50, 75 )
local hOldBmp := SelectObject( hDC, hBmp )
local hEMF := GetEnhMetaFile( '1.emf' )

PlayEnhMetaFile( oDlg:getDC(), hEMF, oDlg:hWnd )

rectangle( hDc, 0,0,60,80 )

PlayEnhMetaFile( hDc, hEMF, oBmp:hWnd )

DrawBitmap( oDlg:GetDC(), hBmp, 0, 0, 50, 75 )


hDib := DibFromBitmap( hBmp )
DibWrite( "file.bmp" , hDib )
GloBalFree( hDib )

CloseEnhMetafile( hEMF )

SelectObject( hDC, hOldBmp )
DeleteDC( hDC )


RETURN( NIL )


Bueno como veran en el codigo hay mucho que comentar:

1.- Para poder dibujar el EMF tuve que crear un objeto bmp para conseguir sus atributos de tamaño, y asi usar

PlayEnhMetaFile( hDc, hEMF, oBmp:hWnd )

2.- Para que no salga negro el BMP tuve que pintar un rectangulo inicialmente, para tener fondo blanco

rectangle( hDc, 0,0,60,80 )

3.- DrawBitmap( oDlg:GetDC(), hBmp, 0, 0, 50, 75 ) esto no muestra el BMP

4.- Pero si se puede dibujar sobre el dialogo como se muetra en el ejemplo (es imperativo que el dialogo sea NOWAIT)

5.- Si corren el ejemplo, claro tienes que tener un archivo 1.emf, veran que se crea el BMP con el EMF dibujado en el

En conclusion no tengo absolutamente nada claro, ya que la solucion presentada es muy complicada y fuera de lo normal segun yo,
habra que seguir trabajando

Comentarios Antonio, Daniel??

saludos

Marcelo
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Escalar BMP capturado con WndBitmap
Posted: Thu Dec 17, 2009 12:22 AM
Hola Marcelo...

te dejo una forma mas facil de hacerlo con una ligera modificacion la funcion
Code (fw): Select all Collapse
#include "fivewin.ch"

FUNCTION  main()
   LOCAL oDlg, oBmp

   DEFINE DIALOG oDlg FROM 1,1 TO 20,20
   @ 0,0 BITMAP oBmp OF oDlg 

   ACTIVATE DIALOG oDlg ;
            ON INIT ( DeleteObject( oBmp:hBitmap ), ;
                      oBmp:hBitmap := createBmp( oBmp, ::nWidth, ::nHeight ) )

return nil

FUNCTION createBmp( oBmp, nWidth, nHeight )

local hDC1 := GetDC( GetDesktopWindow() )
local hDC := CreateCompatibleDC( hDC1 )
LOCAL hDib
local hBmp := CreateCompatibleBitmap( hDC1, nWidth, nHeight )
local hOldBmp := SelectObject( hDC, hBmp )
local hEMF := GetEnhMetaFile( 'invoice.emf' )

FillRect( hDC, { 0, 0, nHeight, nWidth }, GetStockObject( 0 ) )

MyPlayEnhMetaFile( hDC, hEMF, { 0, 0, nHeight, nWidth } )


hDib := DibFromBitmap( hBmp )
DibWrite( "file.bmp" , hDib )
GloBalFree( hDib )

CloseEnhMetafile( hEMF )

SelectObject( hDC, hOldBmp )
DeleteDC( hDC )



RETURN( hBmp )
 


#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>
HB_FUNC( MYPLAYENHMETAFILE )
{
   RECT rect;
   BOOL lRet;

   rect.top    = hb_parvnl( 3, 1 );
   rect.left   = hb_parvnl( 3, 2 );
   rect.bottom = hb_parvnl( 3, 3 );
   rect.right  = hb_parvnl( 3, 4 );

   lRet = ( BOOL ) PlayEnhMetaFile( ( HDC ) hb_parnl( 1 ), ( HENHMETAFILE ) hb_parnl( 2 ), &rect );

   if( ! lRet && lRet != ERROR_SUCCESS ) 
   {
      char sBuffer[ 200 ];
      
      wsprintf( sBuffer, "Error (%d) showing Enhanced Metafile\n\nError description:", GetLastError() );
        MessageBox( NULL, sBuffer, ( LPSTR ) "Printing EMF", MB_OK | MB_ICONEXCLAMATION );
   }

   hb_retl( lRet );
}

#pragma ENDDUMP
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: Escalar BMP capturado con WndBitmap
Posted: Thu Dec 17, 2009 03:39 PM

Daniel,

gracias

Saludos

Marcelo

Continue the discussion