documentacion de funciones gdi+

User avatar
Antonio Linares
Site Admin
Posts: 42825
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 126 times
Been thanked: 117 times
Contact:

Re: documentacion de funciones gdi+

Post by Antonio Linares »

Manuel,

Eres increible :-)

La has probado ? Funciona bien ? :-)

Muchisimas gracias!!!
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
mastintin
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: documentacion de funciones gdi+

Post by mastintin »

Si. de momento me funciona bien todo el código que tengo salvo los paths de dibujo que no sé exactamente que les pasa .... :?
Subo aqui todo el código que tengo ahora mismo ....

..................... edito ..................
resuelto . subo de nuevo el codigo con correccion dee bugs.

el fichero tgdiplus.prg

Code: Select all | Expand

// GdiPlus support classes. (c) FiveTech Software 2011-2013#include "FiveWin.ch"#DEFINE GDI_PEN_ROUND   1//----------------------------------------------------------------------------//CLASS Graphics   DATA   hGraphics   METHOD New( hDC, lNoHighQuality )   METHOD SetHighQuality() INLINE GdiPlusHighQuality( ::hGraphics )   METHOD SetNormalQuality() INLINE GdiPlusNormalQuality( ::hGraphics )   METHOD DrawLine( oPen, nLeft, nTop, nRight, nBottom ) INLINE ;          GdiPlusDrawLine( ::hGraphics, If( ! Empty( oPen ), oPen:hPen, NIL ),;          nLeft, nTop, nRight, nBottom )   METHOD DrawRect( oPen, oBrush, nLeft, nTop, nWidth, nHight ) INLINE ;          GdiPlusDrawRect( ::hGraphics, If( ! Empty( oPen ), oPen:hPen, NIL ),;          If( ! Empty( oBrush ), oBrush:hBrush, NIL ), nLeft, nTop, nWidth, nHight )   METHOD DrawEllipse( oPen, oBrush, nLeft, nTop, nWidth, nHight ) INLINE ;          GdiPlusDrawEllipse( ::hGraphics, If( ! Empty( oPen ), oPen:hPen, NIL ),;          If( ! Empty( oBrush ), oBrush:hBrush, NIL), nLeft, nTop, nWidth, nHight )   METHOD DrawArc( oPen, nLeft, nTop, nWidth, nHeight,startAngle, sweepAngle ) INLINE ;           GdiPlusDrawArc( oPen:hPen, nLeft, nTop, nWidth, nHeight, startAngle, sweepAngle )       METHOD DrawPath( oPen, oPath ) INLINE GdiPlusDrawPath( ::hGraphics, oPen:hPen, oPath:hPath )      METHOD DrawImage( oBmp,nTop,nleft, nWidth, nHeight )                  METHOD Destroy()   DESTRUCTOR Destroy()ENDCLASS//----------------------------------------------------------------------------//METHOD New( hDC , lNoHighQuality ) CLASS Graphics   ::hGraphics = GdiPlusNewGraphics( hDC )   SetPageUnit2Pixel( ::hGraphics )   DEFAULT lNoHighQuality := .F.   if lNoHighQuality    ::SetNormalQuality()   else    ::SetHighQuality()   endifreturn Self//----------------------------------------------------------------------------//METHOD Destroy() CLASS Graphics   GdiPlusDeleteGraphics( ::hGraphics )   ::hGraphics = nilreturn nil//----------------------------------------------------------------------------//METHOD DrawImage( oImage, nTop, nleft, nWidth, nHeight ) CLASS Graphics if Empty(nWidth ) .or. Empty( nHeight )     GdiPlusDrawImage( ::hGraphics, oImage:hImage, nTop, nLeft ) else    GdiPlusDrawImage(  ::hGraphics, oImage:hImage,nTop,nLeft, nWidth, nHeight ) endifReturn nil//----------------------------------------------------------------------------//CLASS Pen   DATA   hPen   METHOD New( nTrans, nRed, nGreen, nBlue, nSize, lRound, lAlign )   METHOD SetSize( nSize ) INLINE GdiPlusPenSize( ::hPen , nSize )   METHOD SetStyle( nStyle )   METHOD SetInset( ) INLINE GdiPlusAlign( ::hPen )   METHOD SetNoInset( ) INLINE GdiPlusNoAlign( ::hPen )      METHOD SetColor( nTrans, nRed, nGreen, nBlue ) INLINE ;                GdiPlusPenSetClr( ::hPen, nTrans, nRed, nGreen, nBlue )   METHOD Destroy()   DESTRUCTOR Destroy()ENDCLASS//----------------------------------------------------------------------------//METHOD New( nTrans, nRed, nGreen, nBlue, nSize, lRound, lAlign ) CLASS Pen   ::hPen = GdiPlusNewPen( nTrans, nRed, nGreen, nBlue )   DEFAULT nSize := 1 , lRound := .F. , lAlign := .F.   ::SetSize( nSize )   if lRound        ::SetStyle ( GDI_PEN_ROUND )     endif         if lAlign          ::SetAlign ( )     endifreturn Self//----------------------------------------------------------------------------//METHOD SetStyle( nStyle ) CLASS Pen   do case        case nStyle == GDI_PEN_ROUND               GdiPlusPenStyle( ::hPen, 2 )   endcasereturn nil//----------------------------------------------------------------------------//METHOD Destroy() CLASS Pen   GdiPlusDeletePen( ::hPen )   ::hPen = nilreturn nil//----------------------------------------------------------------------------//CLASS Brush   DATA   hBrush   METHOD NewSolidBrush( nTrans, nRed, nGreen, nBlue )   METHOD Destroy()   DESTRUCTOR Destroy()ENDCLASS//----------------------------------------------------------------------------//METHOD NewSolidBrush( nTrans, nRed, nGreen, nBlue ) CLASS Brush   ::hBrush = GdiPlusNewSolidBrush( nTrans, nRed, nGreen, nBlue )return Self//----------------------------------------------------------------------------//METHOD Destroy() CLASS Brush   GdiPlusDeleteBrush( ::hBrush )   ::hBrush = nilreturn nil//----------------------------------------------------------------------------//init procedure GdiPlusStart()   GdiPlusStartup()return//----------------------------------------------------------------------------//exit procedure GdiPlusEnd()   GdiPlusShutdown()return//----------------------------------------------------------------------------//CLASS Path   DATA   hPath   METHOD New()   METHOD Destroy()   METHOD AddLINE ( nLeft, nTop, nRight, nBottom ) INLINE ;          GdiPlusPathAddLine( ::hPath, nLeft, nTop, nRight, nBottom )             METHOD AddRectangle ( nLeft, nTop, nRight, nBottom ) INLINE ;          GdiPlusPathAddRectangle ( ::hPath, nLeft, nTop, nRight, nBottom )          METHOD AddRoundRect( x, y, width, height, nRadius )            METHOD AddArc( nLeft, nTop, nWidth, nHeight, nStartAngle, nSweepAngle ) INLINE ;          GdiPlusPathAddArc( ::hPath, nLeft, nTop, nWidth, nHeight, nStartAngle, nSweepAngle )          METHOD CloseFigure() INLINE GdiPlusPathCloseFigure( ::hPath )        DESTRUCTOR Destroy()ENDCLASS//----------------------------------------------------------------------------//METHOD New() CLASS Path   ::hPath = GdiPlusCreatePath()return Self//----------------------------------------------------------------------------//METHOD AddRoundRect( x, y, width, height, nRadius ) CLASS Path    if ( nRadius == 0)        ::AddRectangle( x, y, width, height )   else                  ::AddLine( x + nRadius, y, x + width - nRadius, y )        ::AddArc( x + width - nRadius, y, nRadius, nRadius, 270, 90 )        ::AddLine( x + width, y + nRadius, x + width, y + height - nRadius )        ::AddArc( x + width - nRadius, y + height - nRadius, nRadius, nRadius, 0, 90 )        ::AddLine( x + width - nRadius, y + height, x + nRadius, y + height )        ::AddArc( x, y + height - nRadius, nRadius, nRadius, 90, 90 )        ::AddLine( x, y + height - nRadius, x, y + nRadius )        ::AddArc( x, y, nRadius, nRadius, 180, 90 )                ::CloseFigure()     endifReturn nil//----------------------------------------------------------------------------//METHOD Destroy() CLASS Path   GdiPlusDeletePath( ::hPath )   ::hPath = nilreturn nil//----------------------------------------------------------------------------//CLASS GDIImage   DATA hImage   DATA aCLSID    DATa aExtIni, aExtEnd      METHOD New(cFile)   METHOD Destroy()   METHOD Save( cFile )   DESTRUCTOR Destroy()ENDCLASS//----------------------------------------------------------------------------//METHOD New( cFile ) CLASS GDIImage   ::hImage = GdiPlusCreateImageFromFile( AnsiToWide( cFile ) )   ::aExtIni := { "BMP", "JPG", "GIF", "TIF", "PNG" }   ::aExtEnd := { "BMP", "JPG", "GIF", "TIF", "PNG" }   ::aCLSID := { "{557CF400-1A04-11D3-9A73-0000F81EF32E}" ,;                               "{557CF401-1A04-11D3-9A73-0000F81EF32E}" ,;                               "{557CF402-1A04-11D3-9A73-0000F81EF32E}" ,;                               "{557CF405-1A04-11D3-9A73-0000F81EF32E}" ,;                               "{557CF406-1A04-11D3-9A73-0000F81EF32E}"  ;               }return Self//----------------------------------------------------------------------------//METHOD Save( cFile ) CLASS GDIImagelocal cExtension := Upper(cFileExt(cFile))local cCLSID local nScan:= aScan( ::aExtEnd, cExtension ) if nScan == 0    msginfo( "Formato no soportado" )    Return .f. endif  cCLSID := ::aCLSID[ nScan ]  cCLSID = AnsiToWide( cCLSID )  cFile  = AnsiToWide( cFile )  GdiPlusImageSave( ::hImage, cFile, cCLSID )Return nil//----------------------------------------------------------------------------//METHOD Destroy() CLASS GDIImage      ::hImage = nil   return nil//----------------------------------------------------------------------------//Function GDIPlusConvertImage( cImageIni, cImageEnd )local cExtIni := Upper(cFileExt( cImageIni ))local cExtEnd := Upper(cFileExt( cImageEnd ))local oImagelocal nScan if cImageIni == cImageEnd   msginfo( "Error. La imagen inicial y final son la misma" )    Return .f.endifoImage:= GDIImage():New( cImageIni ) if( nScan:= aScan( oImage:aExtIni, cExtIni )) == 0     Msginfo( " el archivo "+ cImageIni + " tiene un formato no soportado")     return .f. endif    if( nScan:= aScan( oImage:aExtEnd, cExtEnd )) == 0     Msginfo( " el archivo "+ cImageEnd + " tiene un formato no soportado")     return .f. endif  oImage:Save( cImageEnd )oImage:Destroy()Return nil//----------------------------------------------------------------------------// 



el fichero gdiplus.cpp

Code: Select all | Expand

// GdiPlus support (c) FiveTech Software#include <hbapi.h>#include <windows.h>#include <gdiplus.h>using namespace Gdiplus;GdiplusStartupInput gdiplusStartupInput;ULONG_PTR   gdiplusToken;//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSNEWGRAPHICS ){   hb_retnl( ( HB_LONG ) new Graphics( ( HDC ) hb_parnl( 1 ) ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDELETEGRAPHICS ){   delete ( ( Graphics * ) hb_parnl( 1 ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSHIGHQUALITY ){   Graphics * graphics = ( Graphics * ) hb_parnl( 1 );   graphics->SetSmoothingMode( SmoothingModeHighQuality );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSNORMALQUALITY ){   Graphics * graphics = ( Graphics * ) hb_parnl( 1 );   graphics->SetSmoothingMode( SmoothingModeDefault );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSNEWPEN ){     Color clr = Color( hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ), hb_parnl( 4 ) );   hb_retnl( ( HB_LONG ) new Pen( clr ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSPENSIZE ){   Pen * pen = ( Pen * ) hb_parnl( 1 );   pen->SetWidth( hb_parnl( 2 ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSPENSETCLR ){     Pen * pen = ( Pen * ) hb_parnl( 1 );        Color clr = Color( hb_parnl( 2 ), hb_parnl( 3 ), hb_parnl( 4 ), hb_parnl( 5 ) );     hb_retni( pen->SetColor( clr ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSPENSTYLE ){   Pen * pen = ( Pen * ) hb_parnl( 1 );   pen->SetLineCap( ( LineCap ) hb_parnl( 2 ), ( LineCap ) hb_parnl( 2 ),                     ( DashCap ) hb_parnl( 2 ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSALIGN ){   Pen * pen = ( Pen * ) hb_parnl( 1 );   pen->SetAlignment(PenAlignmentInset);}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSNOALIGN ){   Pen * pen = ( Pen * ) hb_parnl( 1 );   pen->SetAlignment(PenAlignmentCenter);}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDELETEPEN ){   delete ( ( Pen * ) hb_parnl( 1 ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSNEWSOLIDBRUSH ){     Color clr = Color( hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ), hb_parnl( 4 ) );   hb_retnl( ( HB_LONG ) new SolidBrush( clr ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDELETEBRUSH ){   delete ( ( Brush * ) hb_parnl( 1 ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDRAWLINE ){   Graphics * graphics = ( Graphics * ) hb_parnl( 1 );     if HB_ISNUM( 2 )   // if pen-object     {        Pen * pen = ( Pen * ) hb_parnl( 2 );                  graphics->DrawLine( pen, ( float ) hb_parnd( 3 ),                   ( float ) hb_parnd( 4 ), ( float ) hb_parnd( 5 ),                   ( float ) hb_parnd( 6 ) );   }}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDRAWRECT ){   Graphics * graphics = ( Graphics * ) hb_parnl( 1 ); //  Pen * pen = ( Pen * ) hb_parnl( 2 );   float nLeft = hb_parnd( 4 );   float nTop = hb_parnd( 5 );   float nWidth =  hb_parnd( 6 );   float nHeight = hb_parnd( 7 );    if HB_ISNUM( 3 )    // if brush-object    {       Brush * brush = ( Brush * ) hb_parnl( 3 );       graphics->FillRectangle( brush, nLeft, nTop, nWidth, nHeight );    }    if HB_ISNUM( 2 )    //if pen-object    {       Pen * pen = ( Pen * ) hb_parnl( 2 );       graphics->DrawRectangle( pen, nLeft, nTop, nWidth, nHeight );    }}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDRAWELLIPSE ){   Graphics * graphics = ( Graphics * ) hb_parnl( 1 ); //  Pen * pen = ( Pen * ) hb_parnl( 2 );   float nLeft = hb_parnd( 4 );   float nTop = hb_parnd( 5 );   float nWidth =  hb_parnd( 6 );   float nHeight = hb_parnd( 7 );     if HB_ISNUM( 3 )   //if brush-object     {        Brush * brush = ( Brush * ) hb_parnl( 3 );        graphics->FillEllipse( brush, nLeft, nTop, nWidth, nHeight );     }         if HB_ISNUM( 2 )   //if pen-object     {       Pen * pen = ( Pen * ) hb_parnl( 2 );       graphics->DrawEllipse( pen, nLeft, nTop, nWidth, nHeight );     }}//----------------------------------------------------------------------------///*HB_FUNC( GDIPLUSDRAWTEXT ){    Graphics * graphics = ( Graphics * ) hb_parnl( 1 );        //  if HB_ISNUM( 3 )   //if brush-object //   {        Brush * brush = ( Brush * ) hb_parnl( 3 );  //  }         graphics->DrawString(hb_parc(2) , -1,NUL,NUL,NUL, brush );     }*///----------------------------------------------------------------------------//HB_FUNC( GDIPLUSCREATEPATH ){     hb_retnl( ( HB_LONG ) new GraphicsPath()  );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSPATHSTARTFIGURE ){     GraphicsPath * graphicPath = ( GraphicsPath * ) hb_parnl( 1 );     graphicPath->StartFigure();}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDELETEPATH ){   delete ( ( GraphicsPath * ) hb_parnl( 1 ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSPATHADDLINE ){     GraphicsPath * graphicPath = ( GraphicsPath * ) hb_parnl( 1 );          int nLeft = hb_parnd( 2 );   int nTop = hb_parnd( 3 );   int nRight =  hb_parnd( 4 );   int nBottom = hb_parnd( 5 );          graphicPath->AddLine(  nLeft, nTop, nRight, nBottom ) ;}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSPATHADDRECTANGLE ){     GraphicsPath * graphicPath = ( GraphicsPath * ) hb_parnl( 1 );     int nLeft = hb_parnd( 2 );   int nTop = hb_parnd( 3 );   int nRight =  hb_parnd( 4 );   int nBottom = hb_parnd( 5 );     Rect pathRect = Rect(  nLeft, nTop, nRight, nBottom  );         graphicPath->AddRectangle( pathRect ) ;     }//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSPATHADDARC ){     GraphicsPath * graphicPath = ( GraphicsPath * ) hb_parnl( 1 );     int nLeft = hb_parnd( 2 );   int nTop = hb_parnd( 3 );   int nRight =  hb_parnd( 4 );   int nBottom = hb_parnd( 5 );   float startAngle =  hb_parnd( 6 );   float sweepAngle = hb_parnd( 7 );      Rect pathRect = Rect(  nLeft, nTop, nRight, nBottom  );             graphicPath->AddArc( pathRect, startAngle, sweepAngle ) ;     }//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSPATHCLOSEFIGURE ){     GraphicsPath * graphicPath = ( GraphicsPath * ) hb_parnl( 1 );     graphicPath->CloseFigure();}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDRAWPATH ){ Graphics * graphics = ( Graphics * ) hb_parnl( 1 ); Pen * pen = ( Pen * ) hb_parnl( 2 ); GraphicsPath * graphicPath = ( GraphicsPath * ) hb_parnl( 3 );  graphics->DrawPath( pen, graphicPath ); }//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSCREATEPOINTF ){     float nLeft = hb_parnd( 1 );   float nTop = hb_parnd( 2 );     hb_retnl( ( HB_LONG )new PointF( nLeft , nTop ) ); }  //----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDRAWARC ){     Graphics * graphics = ( Graphics * ) hb_parnl( 1 );    Pen * pen = ( Pen * ) hb_parnl( 2 );      float nLeft = hb_parnd( 3 );   float nTop = hb_parnd( 4 );   float nWidth =  hb_parnd( 5 );   float nHeight = hb_parnd( 6 );   float startAngle =  hb_parnd( 7 );   float sweepAngle = hb_parnd( 8 );     // Draw the arc.   graphics->DrawArc( pen, nLeft, nTop, nWidth, nHeight, startAngle, sweepAngle);} //----------------------------------------------------------------------------//HB_FUNC( GDIPLUSSTARTUP ){   hb_retl( GdiplusStartup( &gdiplusToken, &gdiplusStartupInput, NULL ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSSHUTDOWN ){   GdiplusShutdown( gdiplusToken );}//----------------------------------------------------------------------------//HB_FUNC( SETPAGEUNIT2PIXEL ){   Graphics * graphics = ( Graphics * ) hb_parnl( 1 );   graphics->SetPageUnit( UnitPixel ); // Unit to Pixel}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSCREATEIMAGEFROMFILE ){     Image * newImage =  new Image(  (LPCWSTR) hb_parc(1)  );    hb_retnl( ( HB_LONG ) newImage ); }//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDRAWIMAGE ){     int iParams = hb_pcount();        Graphics * graphics = ( Graphics * ) hb_parnl( 1 );    Image * newImage = ( Image * ) hb_parnl( 2 );  int nLeft ;  int nTop ;  int nWidth ;  int nHeight;         switch (iParams){        case 4:      nLeft = hb_parni( 3 );      nTop = hb_parni( 4 );        graphics->DrawImage( newImage, nLeft, nTop );       case 6:     nLeft = hb_parni( 3 );     nTop = hb_parni( 4 );     nWidth =  hb_parni( 5 );     nHeight = hb_parni( 6 );         graphics->DrawImage( newImage, nLeft, nTop,nWidth,nHeight);     }       }//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSIMAGESAVE ){   Image * newImage = ( Image * ) hb_parnl( 1 );  CLSID cClsid ;  LPWSTR file = (LPWSTR) hb_parc(2);  LPWSTR identificador =  (LPWSTR) hb_parc(3);  CLSIDFromString( identificador, &cClsid ) ;   newImage->Save( file , &cClsid, NULL);}//----------------------------------------------------------------------------// 
User avatar
Antonio Linares
Site Admin
Posts: 42825
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 126 times
Been thanked: 117 times
Contact:

Re: documentacion de funciones gdi+

Post by Antonio Linares »

Manuel,

Muchísimas gracias :-)

Tienes algún ejemplo actualizado que demuestre todo lo nuevo que le has añadido ?

Incluida para la próxima versión de FWH :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 42825
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 126 times
Been thanked: 117 times
Contact:

Re: documentacion de funciones gdi+

Post by Antonio Linares »

Manuel,

Puestos a pedir podrias proporcionarme el texto descriptivo en Español de las mejoras realizadas en ese ficheros respecto a la versión anterior ?

Para incluirlo en el whatsnew.txt

Gracias! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
mastintin
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: documentacion de funciones gdi+

Post by mastintin »

Antonio, tengo algún cambio mas en los ficheros . Este fin de semana intento subir los ficheros mas actuales , un ejemplo de las nuevas funciones y un texto con los cambios .
User avatar
Antonio Linares
Site Admin
Posts: 42825
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 126 times
Been thanked: 117 times
Contact:

Re: documentacion de funciones gdi+

Post by Antonio Linares »

Muchas gracias, cuando puedas :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
mastintin
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: documentacion de funciones gdi+

Post by mastintin »

Subo ahora los archivos y dejo para mañana o pasado el ejemplo ....

el archivo nuevoenGdiplus.txt

Code: Select all | Expand

* nuevos metodos para la clase Graphics :     DrawArc : Permite dibujar un arco .    DrawPath: Dibuja los trazos de un path previamente creado    DrawImage: pinta una Imagen dentro de los formatos soportados por gdi+ .     DrawRoundRect : Utilizamos internamente el objeto path para dibujar un Roundrect.      * nuevo metodo para la calse Pen:    SetColor : permite definir un nuevo color para el pen  sin tener que construir uno nuevo :               sus parametros son Transparencia, nRed, nGreen, nBlue por ese orden.               * Nueva clase path : permite dibujar varios y distintos trazos y luego pintarlos en pantalla.   Sus metodos son :       New : crea un nuevo path    Destroy : lo destruye.    AddLine : Añade una linea.    AddRectangle : Añade un rectangulo          AddRoundRect : Añade un roundRect.      AddArc : Añade un Arco.      CloseFigure : Cierra una figura dibujada con los anteriores metodos .      ( para ejemplo de uso  se puede mirar el codigo usado para el methodo addroundrect) .    * Nueva clase GDIBmp : Permite el uso de imagenes.   Sus metodos son :       New( cFile, cResname ) : Crea el objeto GdiBmp , este puede ser creado desde un archivo o desde recursos si se trata de un bmp ( por el momento )      Destroy : destruye el objeto       Save( cFile ) Graba el objeto en un nuevo archivo que puede ser cualquiera de los formatos soportados.    * Nueva Funcion GDIPlusConvertImage( cImageIni, cImageEnd )       Permite pasar una imagen de un formato a otro ,solo expecificando un archivo origen y un archivo destino . 




el archivo tgdiplus.prg

Code: Select all | Expand

// GdiPlus support classes. (c) FiveTech Software 2011-2013#include "FiveWin.ch"#DEFINE GDI_PEN_ROUND   1//----------------------------------------------------------------------------//CLASS Graphics   DATA   hGraphics   METHOD New( hDC, lNoHighQuality )   METHOD SetHighQuality() INLINE GdiPlusHighQuality( ::hGraphics )   METHOD SetNormalQuality() INLINE GdiPlusNormalQuality( ::hGraphics )   METHOD DrawLine( oPen, nLeft, nTop, nRight, nBottom ) INLINE ;          GdiPlusDrawLine( ::hGraphics, If( ! Empty( oPen ), oPen:hPen, NIL ),;          nLeft, nTop, nRight, nBottom )   METHOD DrawRect( oPen, oBrush, nLeft, nTop, nWidth, nHight ) INLINE ;          GdiPlusDrawRect( ::hGraphics, If( ! Empty( oPen ), oPen:hPen, NIL ),;          If( ! Empty( oBrush ), oBrush:hBrush, NIL ), nLeft, nTop, nWidth, nHight )   METHOD DrawEllipse( oPen, oBrush, nLeft, nTop, nWidth, nHight ) INLINE ;          GdiPlusDrawEllipse( ::hGraphics, If( ! Empty( oPen ), oPen:hPen, NIL ),;          If( ! Empty( oBrush ), oBrush:hBrush, NIL), nLeft, nTop, nWidth, nHight )   METHOD DrawArc( oPen, nLeft, nTop, nWidth, nHeight,startAngle, sweepAngle ) INLINE ;           GdiPlusDrawArc( oPen:hPen, nLeft, nTop, nWidth, nHeight, startAngle, sweepAngle )       METHOD DrawPath( oPen, oPath ) INLINE GdiPlusDrawPath( ::hGraphics, oPen:hPen, oPath:hPath )      METHOD DrawImage( oBmp,nTop,nleft, nWidth, nHeight )       METHOD DrawRoundRect(oPen, oBrush, nLeft, nTop, nWidth, nHight )              METHOD Destroy()   DESTRUCTOR Destroy()ENDCLASS//----------------------------------------------------------------------------//METHOD New( hDC , lNoHighQuality ) CLASS Graphics   ::hGraphics = GdiPlusNewGraphics( hDC )   SetPageUnit2Pixel( ::hGraphics )   DEFAULT lNoHighQuality := .F.   if lNoHighQuality    ::SetNormalQuality()   else    ::SetHighQuality()   endifreturn Self//----------------------------------------------------------------------------//METHOD Destroy() CLASS Graphics   GdiPlusDeleteGraphics( ::hGraphics )   ::hGraphics = nilreturn nil//----------------------------------------------------------------------------//METHOD DrawImage( oImage, nTop, nleft, nWidth, nHeight ) CLASS Graphics if Empty(nWidth ) .or. Empty( nHeight )     GdiPlusDrawImage( ::hGraphics, oImage:hBmp, nTop, nLeft ) else    GdiPlusDrawImage(  ::hGraphics, oImage:hBmp,nTop,nLeft, nWidth, nHeight ) endifReturn nil//----------------------------------------------------------------------------//METHOD DrawRoundRect(oPen, oBrush, nLeft, nTop, nWidth, nHeight ) CLASS Graphics local oPath:= Path():new()        oPath:AddRoundRect( nLeft, nTop, nWidth, nHeight,8  )       ::DrawPath( oPen, oPath )       Return nil//----------------------------------------------------------------------------//CLASS Pen   DATA   hPen   METHOD New( nTrans, nRed, nGreen, nBlue, nSize, lRound, lAlign )   METHOD SetSize( nSize ) INLINE GdiPlusPenSize( ::hPen , nSize )   METHOD SetStyle( nStyle )   METHOD SetInset( ) INLINE GdiPlusAlign( ::hPen )   METHOD SetNoInset( ) INLINE GdiPlusNoAlign( ::hPen )      METHOD SetColor( nTrans, nRed, nGreen, nBlue ) INLINE ;                GdiPlusPenSetClr( ::hPen, nTrans, nRed, nGreen, nBlue )   METHOD Destroy()   DESTRUCTOR Destroy()ENDCLASS//----------------------------------------------------------------------------//METHOD New( nTrans, nRed, nGreen, nBlue, nSize, lRound, lAlign ) CLASS Pen   ::hPen = GdiPlusNewPen( nTrans, nRed, nGreen, nBlue )   DEFAULT nSize := 1 , lRound := .F. , lAlign := .F.   ::SetSize( nSize )   if lRound        ::SetStyle ( GDI_PEN_ROUND )     endif         if lAlign          ::SetAlign ( )     endifreturn Self//----------------------------------------------------------------------------//METHOD SetStyle( nStyle ) CLASS Pen   do case        case nStyle == GDI_PEN_ROUND               GdiPlusPenStyle( ::hPen, 2 )   endcasereturn nil//----------------------------------------------------------------------------//METHOD Destroy() CLASS Pen   GdiPlusDeletePen( ::hPen )   ::hPen = nilreturn nil//----------------------------------------------------------------------------//CLASS Brush   DATA   hBrush   METHOD NewSolidBrush( nTrans, nRed, nGreen, nBlue )   METHOD Destroy()   DESTRUCTOR Destroy()ENDCLASS//----------------------------------------------------------------------------//METHOD NewSolidBrush( nTrans, nRed, nGreen, nBlue ) CLASS Brush   ::hBrush = GdiPlusNewSolidBrush( nTrans, nRed, nGreen, nBlue )return Self//----------------------------------------------------------------------------//METHOD Destroy() CLASS Brush   GdiPlusDeleteBrush( ::hBrush )   ::hBrush = nilreturn nil//----------------------------------------------------------------------------//init procedure GdiPlusStart()   GdiPlusStartup()return//----------------------------------------------------------------------------//exit procedure GdiPlusEnd()   GdiPlusShutdown()return//----------------------------------------------------------------------------//CLASS Path   DATA   hPath   METHOD New()   METHOD Destroy()   METHOD AddLINE ( nLeft, nTop, nRight, nBottom ) INLINE ;          GdiPlusPathAddLine( ::hPath, nLeft, nTop, nRight, nBottom )             METHOD AddRectangle ( nLeft, nTop, nRight, nBottom ) INLINE ;          GdiPlusPathAddRectangle ( ::hPath, nLeft, nTop, nRight, nBottom )          METHOD AddRoundRect( x, y, width, height, nRadius )            METHOD AddArc( nLeft, nTop, nWidth, nHeight, nStartAngle, nSweepAngle ) INLINE ;          GdiPlusPathAddArc( ::hPath, nLeft, nTop, nWidth, nHeight, nStartAngle, nSweepAngle )          METHOD CloseFigure() INLINE GdiPlusPathCloseFigure( ::hPath )        DESTRUCTOR Destroy()ENDCLASS//----------------------------------------------------------------------------//METHOD New() CLASS Path   ::hPath = GdiPlusCreatePath()return Self//----------------------------------------------------------------------------//METHOD AddRoundRect( x, y, width, height, nRadius ) CLASS Path    if ( nRadius == 0)        ::AddRectangle( x, y, width, height )   else                  ::AddLine( x + nRadius, y, x + width - nRadius, y )        ::AddArc( x + width - nRadius, y, nRadius, nRadius, 270, 90 )        ::AddLine( x + width, y + nRadius, x + width, y + height - nRadius )        ::AddArc( x + width - nRadius, y + height - nRadius, nRadius, nRadius, 0, 90 )        ::AddLine( x + width - nRadius, y + height, x + nRadius, y + height )        ::AddArc( x, y + height - nRadius, nRadius, nRadius, 90, 90 )        ::AddLine( x, y + height - nRadius, x, y + nRadius )        ::AddArc( x, y, nRadius, nRadius, 180, 90 )                ::CloseFigure()     endifReturn nil//----------------------------------------------------------------------------//METHOD Destroy() CLASS Path   GdiPlusDeletePath( ::hPath )   ::hPath = nilreturn nil//----------------------------------------------------------------------------//CLASS GDIBmp   DATA hBmp   DATA aCLSID    DATa aExtIni, aExtEnd      METHOD New( cFile, cResname )   METHOD Destroy()   METHOD Save( cFile )        DESTRUCTOR Destroy()ENDCLASS//----------------------------------------------------------------------------//METHOD New( cFile , cResname ) CLASS GDIBmplocal aBmpPal     ::aExtIni := { "BMP", "JPG", "GIF", "TIF", "PNG","EMF","WMF","ICO" }   ::aExtEnd := { "BMP", "JPG", "GIF", "TIF", "PNG" }   ::aCLSID := { "{557CF400-1A04-11D3-9A73-0000F81EF32E}" ,;                               "{557CF401-1A04-11D3-9A73-0000F81EF32E}" ,;                               "{557CF402-1A04-11D3-9A73-0000F81EF32E}" ,;                               "{557CF405-1A04-11D3-9A73-0000F81EF32E}" ,;                               "{557CF406-1A04-11D3-9A73-0000F81EF32E}" ,;                               "{557CF403-1A04-11D3-9A73-0000F81EF32E}" ,;                               "{557CF404-1A04-11D3-9A73-0000F81EF32E}" ,;                               "{557CF407-1A04-11D3-9A73-0000F81EF32E}" ;               }         if ! Empty( cResName )       aBmpPal    = PalBmpLoad( cResName )       ::hBmp = GdiPlusCreateImageFromRes( aBmpPal[ 1 ], aBmpPal[ 2 ] )    elseif File( cFile )       ::hBmp = GdiPlusCreateImageFromFile( AnsiToWide( cFile ) )      else       msginfo( "ficheros no encontrados" )       endif                                 return Self//----------------------------------------------------------------------------//METHOD Save( cFile ) CLASS GDIBmplocal cExtension := Upper(cFileExt(cFile))local cCLSID local nScan:= aScan( ::aExtEnd, cExtension ) if nScan == 0    msginfo( "Formato no soportado" )    Return .f. endif  cCLSID := ::aCLSID[ nScan ]  cCLSID = AnsiToWide( cCLSID )  cFile  = AnsiToWide( cFile )  GdiPlusImageSave( ::hBmp, cFile, cCLSID )Return nil//----------------------------------------------------------------------------//METHOD Destroy() CLASS GDIBmp      ::hBmp = nil   return nil//----------------------------------------------------------------------------//Function GDIPlusConvertImage( cImageIni, cImageEnd )local cExtIni := Upper(cFileExt( cImageIni ))local cExtEnd := Upper(cFileExt( cImageEnd ))local oImagelocal nScan if cImageIni == cImageEnd   msginfo( "Error. La imagen inicial y final son la misma" )    Return .f.endifoImage:= GDIBmp():New( cImageIni ) if( nScan:= aScan( oImage:aExtIni, cExtIni )) == 0     Msginfo( " el archivo "+ cImageIni + " tiene un formato no soportado")     return .f. endif    if( nScan:= aScan( oImage:aExtEnd, cExtEnd )) == 0     Msginfo( " el archivo "+ cImageEnd + " tiene un formato no soportado")     return .f. endif  oImage:Save( cImageEnd )oImage:Destroy()Return nil//----------------------------------------------------------------------------// 


el archivo gdiplus.cpp

Code: Select all | Expand

// GdiPlus support (c) FiveTech Software#include <hbapi.h>#include <windows.h>#include <gdiplus.h>using namespace Gdiplus;GdiplusStartupInput gdiplusStartupInput;ULONG_PTR   gdiplusToken;//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSNEWGRAPHICS ){   hb_retnl( ( HB_LONG ) new Graphics( ( HDC ) hb_parnl( 1 ) ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDELETEGRAPHICS ){   delete ( ( Graphics * ) hb_parnl( 1 ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSHIGHQUALITY ){   Graphics * graphics = ( Graphics * ) hb_parnl( 1 );   graphics->SetSmoothingMode( SmoothingModeHighQuality );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSNORMALQUALITY ){   Graphics * graphics = ( Graphics * ) hb_parnl( 1 );   graphics->SetSmoothingMode( SmoothingModeDefault );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSNEWPEN ){     Color clr = Color( hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ), hb_parnl( 4 ) );   hb_retnl( ( HB_LONG ) new Pen( clr ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSPENSIZE ){   Pen * pen = ( Pen * ) hb_parnl( 1 );   pen->SetWidth( hb_parnl( 2 ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSPENSETCLR ){     Pen * pen = ( Pen * ) hb_parnl( 1 );        Color clr = Color( hb_parnl( 2 ), hb_parnl( 3 ), hb_parnl( 4 ), hb_parnl( 5 ) );     hb_retni( pen->SetColor( clr ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSPENSTYLE ){   Pen * pen = ( Pen * ) hb_parnl( 1 );   pen->SetLineCap( ( LineCap ) hb_parnl( 2 ), ( LineCap ) hb_parnl( 2 ),                     ( DashCap ) hb_parnl( 2 ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSALIGN ){   Pen * pen = ( Pen * ) hb_parnl( 1 );   pen->SetAlignment(PenAlignmentInset);}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSNOALIGN ){   Pen * pen = ( Pen * ) hb_parnl( 1 );   pen->SetAlignment(PenAlignmentCenter);}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDELETEPEN ){   delete ( ( Pen * ) hb_parnl( 1 ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSNEWSOLIDBRUSH ){     Color clr = Color( hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ), hb_parnl( 4 ) );   hb_retnl( ( HB_LONG ) new SolidBrush( clr ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDELETEBRUSH ){   delete ( ( Brush * ) hb_parnl( 1 ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDRAWLINE ){   Graphics * graphics = ( Graphics * ) hb_parnl( 1 );     if HB_ISNUM( 2 )   // if pen-object     {        Pen * pen = ( Pen * ) hb_parnl( 2 );                  graphics->DrawLine( pen, ( float ) hb_parnd( 3 ),                   ( float ) hb_parnd( 4 ), ( float ) hb_parnd( 5 ),                   ( float ) hb_parnd( 6 ) );   }}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDRAWRECT ){   Graphics * graphics = ( Graphics * ) hb_parnl( 1 ); //  Pen * pen = ( Pen * ) hb_parnl( 2 );   float nLeft = hb_parnd( 4 );   float nTop = hb_parnd( 5 );   float nWidth =  hb_parnd( 6 );   float nHeight = hb_parnd( 7 );    if HB_ISNUM( 3 )    // if brush-object    {       Brush * brush = ( Brush * ) hb_parnl( 3 );       graphics->FillRectangle( brush, nLeft, nTop, nWidth, nHeight );    }    if HB_ISNUM( 2 )    //if pen-object    {       Pen * pen = ( Pen * ) hb_parnl( 2 );       graphics->DrawRectangle( pen, nLeft, nTop, nWidth, nHeight );    }}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDRAWELLIPSE ){   Graphics * graphics = ( Graphics * ) hb_parnl( 1 ); //  Pen * pen = ( Pen * ) hb_parnl( 2 );   float nLeft = hb_parnd( 4 );   float nTop = hb_parnd( 5 );   float nWidth =  hb_parnd( 6 );   float nHeight = hb_parnd( 7 );     if HB_ISNUM( 3 )   //if brush-object     {        Brush * brush = ( Brush * ) hb_parnl( 3 );        graphics->FillEllipse( brush, nLeft, nTop, nWidth, nHeight );     }         if HB_ISNUM( 2 )   //if pen-object     {       Pen * pen = ( Pen * ) hb_parnl( 2 );       graphics->DrawEllipse( pen, nLeft, nTop, nWidth, nHeight );     }}//----------------------------------------------------------------------------///*HB_FUNC( GDIPLUSDRAWTEXT ){    Graphics * graphics = ( Graphics * ) hb_parnl( 1 );        //  if HB_ISNUM( 3 )   //if brush-object //   {        Brush * brush = ( Brush * ) hb_parnl( 3 );  //  }         graphics->DrawString(hb_parc(2) , -1,NUL,NUL,NUL, brush );     }*///----------------------------------------------------------------------------//HB_FUNC( GDIPLUSCREATEPATH ){     hb_retnl( ( HB_LONG ) new GraphicsPath()  );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSPATHSTARTFIGURE ){     GraphicsPath * graphicPath = ( GraphicsPath * ) hb_parnl( 1 );     graphicPath->StartFigure();}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDELETEPATH ){   delete ( ( GraphicsPath * ) hb_parnl( 1 ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSPATHADDLINE ){     GraphicsPath * graphicPath = ( GraphicsPath * ) hb_parnl( 1 );          int nLeft = hb_parnd( 2 );   int nTop = hb_parnd( 3 );   int nRight =  hb_parnd( 4 );   int nBottom = hb_parnd( 5 );          graphicPath->AddLine(  nLeft, nTop, nRight, nBottom ) ;}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSPATHADDRECTANGLE ){     GraphicsPath * graphicPath = ( GraphicsPath * ) hb_parnl( 1 );     int nLeft = hb_parnd( 2 );   int nTop = hb_parnd( 3 );   int nRight =  hb_parnd( 4 );   int nBottom = hb_parnd( 5 );     Rect pathRect = Rect(  nLeft, nTop, nRight, nBottom  );         graphicPath->AddRectangle( pathRect ) ;     }//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSPATHADDARC ){     GraphicsPath * graphicPath = ( GraphicsPath * ) hb_parnl( 1 );     int nLeft = hb_parnd( 2 );   int nTop = hb_parnd( 3 );   int nRight =  hb_parnd( 4 );   int nBottom = hb_parnd( 5 );   float startAngle =  hb_parnd( 6 );   float sweepAngle = hb_parnd( 7 );      Rect pathRect = Rect(  nLeft, nTop, nRight, nBottom  );             graphicPath->AddArc( pathRect, startAngle, sweepAngle ) ;     }//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSPATHCLOSEFIGURE ){     GraphicsPath * graphicPath = ( GraphicsPath * ) hb_parnl( 1 );     graphicPath->CloseFigure();}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDRAWPATH ){ Graphics * graphics = ( Graphics * ) hb_parnl( 1 ); Pen * pen = ( Pen * ) hb_parnl( 2 ); GraphicsPath * graphicPath = ( GraphicsPath * ) hb_parnl( 3 );  graphics->DrawPath( pen, graphicPath ); }//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSCREATEPOINTF ){     float nLeft = hb_parnd( 1 );   float nTop = hb_parnd( 2 );     hb_retnl( ( HB_LONG )new PointF( nLeft , nTop ) ); }  //----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDRAWARC ){     Graphics * graphics = ( Graphics * ) hb_parnl( 1 );    Pen * pen = ( Pen * ) hb_parnl( 2 );      float nLeft = hb_parnd( 3 );   float nTop = hb_parnd( 4 );   float nWidth =  hb_parnd( 5 );   float nHeight = hb_parnd( 6 );   float startAngle =  hb_parnd( 7 );   float sweepAngle = hb_parnd( 8 );     // Draw the arc.   graphics->DrawArc( pen, nLeft, nTop, nWidth, nHeight, startAngle, sweepAngle);} //----------------------------------------------------------------------------//HB_FUNC( GDIPLUSSTARTUP ){   hb_retl( GdiplusStartup( &gdiplusToken, &gdiplusStartupInput, NULL ) );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSSHUTDOWN ){   GdiplusShutdown( gdiplusToken );}//----------------------------------------------------------------------------//HB_FUNC( SETPAGEUNIT2PIXEL ){   Graphics * graphics = ( Graphics * ) hb_parnl( 1 );   graphics->SetPageUnit( UnitPixel ); // Unit to Pixel}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSCREATEIMAGEFROMFILE ){     Bitmap * newImage =  new Bitmap(  (LPCWSTR) hb_parc(1)  );    hb_retnl( ( HB_LONG ) newImage ); }//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSCREATEIMAGEFROMRES ){     Bitmap * newImage =  new Bitmap(  (HBITMAP) hb_parnl(1), (HPALETTE) hb_parnl(2)  );    hb_retnl( ( HB_LONG ) newImage );}//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSDRAWIMAGE ){     int iParams = hb_pcount();        Graphics * graphics = ( Graphics * ) hb_parnl( 1 );    Bitmap * newImage = ( Bitmap * ) hb_parnl( 2 );  int nLeft ;  int nTop ;  int nWidth ;  int nHeight;         switch (iParams){        case 4:      nLeft = hb_parni( 3 );      nTop = hb_parni( 4 );        graphics->DrawImage( newImage, nLeft, nTop );       case 6:     nLeft = hb_parni( 3 );     nTop = hb_parni( 4 );     nWidth =  hb_parni( 5 );     nHeight = hb_parni( 6 );         graphics->DrawImage( newImage, nLeft, nTop,nWidth,nHeight);     }       }//----------------------------------------------------------------------------//HB_FUNC( GDIPLUSIMAGESAVE ){   Bitmap * newImage = ( Bitmap * ) hb_parnl( 1 );  CLSID cClsid ;  LPWSTR file = (LPWSTR) hb_parc(2);  LPWSTR identificador =  (LPWSTR) hb_parc(3);  CLSIDFromString( identificador, &cClsid ) ;   newImage->Save( file , &cClsid, NULL);}//----------------------------------------------------------------------------// 
User avatar
mastintin
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: documentacion de funciones gdi+

Post by mastintin »

el ejemplo gdiplus3.prg

Code: Select all | Expand

// GdiPlus example following Microsoft tutorial:// http://msdn.microsoft.com/en-us/library ... 95(v=VS.85).aspx#include "FiveWin.ch" //----------------------------------------------------------------------------//function Main()   local oWnd   DEFINE WINDOW oWnd TITLE "Testing GDI+ Class" FROM 5,5 TO 600, 800 PIXEL //  ownd:setcolor(nrgb(120,120,120),nrgb(120,120,120))      @28,4 button "rectangle" size 120,30 Action Drawrectangle(ownd)   @28,24 button "roundrect" size 120,30 Action Drawroundrect(ownd)   @28,44 button "drawImage" size 120,30 Action DrawImage(ownd)   @28,64 button "drawEllipse" size 120,30 Action DrawEllipse(ownd)    @28,84 button "drawlight" size 120,30 Action Drawlight(ownd)     ACTIVATE WINDOW oWnd return nil//----------------------------------------------------------------------------//function Drawrectangle(ownd)local hdc:= oWnd:getdc()local oGraphics := Graphics():New( ownd:hDC ) local oPen := Pen():New( 255, 0, 0, 255 , 10 , .T.)      oGraphics:DrawRect( oPen,  , 300, 300, 70, 60 )            oGraphics:destroy()               oWnd:releasedc() Return nilfunction Drawroundrect(ownd)local hdc:= oWnd:getdc()local oGraphics := Graphics():New( ownd:hDC )  local oPen2 := Pen():New( 255, 255, 0, 0 , 3 ) local oPath:= Path():new()        oPath:AddRoundRect( 30, 30 , 50, 50 , 9  )            oGraphics:DrawPath( oPen2, oPath )                oGraphics:destroy()                     oWnd:releasedc() Return nilfunction DrawImage(ownd)local hdc:= oWnd:getdc()local oGraphics := Graphics():New( ownd:hDC ) local oImage:= GDIBmp():new("C:\fwh\bitmaps\pngs\image2.png" )       oGraphics:DrawImage( oImage , 60 ,60 )            oGraphics:destroy()                      oWnd:releasedc() Return nilfunction DrawEllipse(ownd)local hdc:= oWnd:getdc()local oGraphics := Graphics():New( ownd:hDC ) local oBrush2 := Brush():NewSolidBrush( 150, 0, 255, 167 ) local oPen2 := Pen():New( 255, 255, 0, 0 , 3 )        oGraphics:DrawEllipse( oPen2, oBrush2  , 500, 100, 60, 60 )            oGraphics:destroy()                      oWnd:releasedc() Return nilfunction Drawlight(ownd)local hdc:= oWnd:getdc()local oGraphics := Graphics():New( ownd:hDC ) local oPenlocal n  oPen := Pen():New(  255 , 0, 0 , 0 , .T.)  oGraphics:DrawRoundRect( oPen, , 400 , 200,  100 , 150  )      oPen:setColor( 255 , 214, 234, 249 )    oPen:setsize(1)   for n = 1 to 10       oPen:setcolor( 255-n*25 , 214, 234, 249 )                           oGraphics:DrawRoundRect( oPen, , 400-n , 200-n,  100+n*2 , 150+ n*2  )                  next     open:destroy()      oGraphics:destroy()                oWnd:releasedc() Return nil 
User avatar
Antonio Linares
Site Admin
Posts: 42825
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 126 times
Been thanked: 117 times
Contact:

Re: documentacion de funciones gdi+

Post by Antonio Linares »

Manuel,

Añadido a FWH y probado, todo ok :-)

Muchisimas gracias :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
jmartial
Posts: 458
Joined: Tue Mar 14, 2006 7:26 pm

Re: documentacion de funciones gdi+

Post by jmartial »

Manuel,

¿Cómo se compila gdiplus.cpp con bcc582?

Como un prg con #pragma o necesita algunos parámetros ?
Un Saludo,
Joaquín Martínez
User avatar
mastintin
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: documentacion de funciones gdi+

Post by mastintin »

jmartial wrote:Manuel,

¿Cómo se compila gdiplus.cpp con bcc582?

Como un prg con #pragma o necesita algunos parámetros ?


gdiplus.cpp ya viene includo en las librerías de fwh por defecto, y no necesitas hacer nada para usarlo . Si le haces alguna modificación al fichero gdiplus.cpp solo tienes que incluirlo al compilar como si fuera un archivo c mas .
Yo para las pruebas tengo un buildh.bat modificado que he llamado buildhgdi.bat con una linea modificada ...

echo -O2 -e%1.exe -I%hdir%\include -I%bcdir%\include -I%bcdir%\include\dinkumware %1.c gdiplus.cpp > b32.bc

y luego al linkar ...

echo %1.obj gdiplus.obj tgdiplus.obj , + >> b32.bc
jmartial
Posts: 458
Joined: Tue Mar 14, 2006 7:26 pm

Re: documentacion de funciones gdi+

Post by jmartial »

Ok!

Gracias Manuel, lo pruebo.
User avatar
mastintin
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: documentacion de funciones gdi+

Post by mastintin »

jmartial wrote:Ok!

Gracias Manuel, lo pruebo.


Coloca esta función dentro del gdiplus.cpp ...

Code: Select all | Expand

HB_FUNC( GDIPLUSHBMPFROMFILE ){  FILE * fil = fopen (  hb_parc(1) , "rb" ) ;  fseek ( fil , 0 , SEEK_END ) ;  int filesize = ftell ( fil ) ;  fseek ( fil , 0 , SEEK_SET ) ;  HGLOBAL hglobal = GlobalAlloc ( GMEM_MOVEABLE , filesize ) ;  char * adr = (char *)GlobalLock ( hglobal ) ;  int nbytes = fread ( adr , 1 , filesize , fil ) ;  fclose ( fil ) ;  if ( nbytes != filesize )      {       MessageBox( GetActiveWindow(), "fallo", "No carga la imagen", 0x30 );      } ;  LPSTREAM pstm = NULL ;  GlobalUnlock ( hglobal ) ; CreateStreamOnHGlobal ( hglobal, TRUE, &pstm ) ; Bitmap  *original = new  Bitmap( pstm,FALSE ); HBITMAP   handle; original->GetHBITMAP( Color( 0,0,0 ), &handle ); delete original ; pstm->Release(); GlobalFree( hglobal ); hb_retnl( ( HB_LONG ) handle );} 
User avatar
mastintin
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: documentacion de funciones gdi+

Post by mastintin »

el dialogo esta construido desde código o desde recursos ? . Lo pregunto para ver que es lo que tienes que cambiar en tu archivo bitmap.prg .
Coloca también en alguno de tus prgs ( por ejemplo en el bitmap.prg que tendremos que modificar un poco ) la siguiente función :

Code: Select all | Expand

FUNCTION cGetBmpName( cBmp )   LOCAL aName:={}   LOCAL aToken   LOCAL nLen   IF ValType( cBmp ) != "N"      aToken:= hb_atokens(cBmp,"|")      nLen := Len(aToken )      IF nLen == 1         aName:= { cBmp , nil, nil }      ELSEIF nLen == 2         aName:= { AllTrim(aToken[1]) , Val(aToken[2]),  nil }      ELSEIF nLen == 3         aName:= { AllTrim(aToken[1]) , Val(aToken[2]),   Val(aToken[2]) }      ELSE         aName:=  { AllTrim(aToken[1]) , nil ,  nil }      ENDIF   ELSE      aName:= { cBmp , nil, nil }   ENDIF RETURN aName 
User avatar
mastintin
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: documentacion de funciones gdi+

Post by mastintin »

Nueva version de la función anterior mas completa ....

Code: Select all | Expand

HB_FUNC( GDIPLUSHBMPFROMFILE ){FILE * fil = fopen (  hb_parc(1) , "rb" ) ;  fseek ( fil , 0 , SEEK_END ) ;  int filesize = ftell ( fil ) ;  fseek ( fil , 0 , SEEK_SET ) ;  HGLOBAL hglobal = GlobalAlloc ( GMEM_MOVEABLE , filesize ) ;  char * adr = (char *)GlobalLock ( hglobal ) ;  int nbytes = fread ( adr , 1 , filesize , fil ) ;  fclose ( fil ) ;  if ( nbytes != filesize )      {       MessageBox( GetActiveWindow(), "fallo", "No carga la imagen", 0x30 );      } ; LPSTREAM pstm = NULL ; GlobalUnlock ( hglobal ) ; CreateStreamOnHGlobal ( hglobal, TRUE, &pstm ) ; Bitmap  *original = new  Bitmap( pstm,FALSE ); int nWidth  = hb_parni(2) ; int nHeight = hb_parni(3) ; Bitmap* newImage  = new Bitmap( nWidth, nHeight, original->GetPixelFormat() ); Graphics * graphics = new Graphics( newImage ); graphics->DrawImage( original ,0, 0, nWidth, nHeight);HBITMAP   handle; newImage->GetHBITMAP( Color( 0,0,0 ), &handle ); delete graphics ; delete original ;delete newImage ; pstm->Release(); GlobalFree( hglobal ); hb_retnl( ( HB_LONG ) handle ); 
Post Reply