Esta es la rutina que gira lo que estés pintando en un DC en un momento dado
Un saludo
include "fivewin.ch"
static oWnd
static nAngle := 0
function main()
DEFINE WINDOW oWnd TITLE "Rotando bitmap"
oWnd:bKeyDown := {|nKey,nFlags| oWnd:cTitle := "Rotando bitmap. " + str(nKey), if( nKey == 37, nAngle -= 5, if( nKey == 39, nAngle += 5, nil) ), oWnd:Refresh() }
ACTIVATE WINDOW oWnd ON PAINT Pinta(hDC)
return 0
function pinta( hDC )
local hBitmap := ReadBitmap(hDC, "compass.bmp" )
local i
if hBitmap != 0
// el tamaño del bitmap es 211 x 211
i = Begin_Rotate( hDC, nAngle, 211/2, 211/2 )
DrawBitmap( hDC, hBitmap, 0, 0 )
End_Rotate(hDC, i )
DeleteObject( hBitmap )
endif
return nil
pragma BEGINDUMP
include <hbapi.h>
include <windows.h>
include <math.h>
HB_FUNC( BEGIN_ROTATE )
{
HDC hDc = (HDC) hb_parnl( 1 );
int nGraphicsMode = SetGraphicsMode(hDc, GM_ADVANCED);
XFORM xform;
double fangle;
int m_iAngle = hb_parni( 2 );
POINT centerPt;
centerPt.y = hb_parni( 3 );
centerPt.x = hb_parni( 4 );
if ( m_iAngle != 0 )
{
fangle = (double)m_iAngle / 180 * 3.1415926;
xform.eM11 = (float)cos(fangle);
xform.eM12 = (float)sin(fangle);
xform.eM21 = (float)-sin(fangle);
xform.eM22 = (float)cos(fangle);
xform.eDx = (float)(centerPt.x - cos(fangle)centerPt.x + sin(fangle)centerPt.y);
xform.eDy = (float)(centerPt.y - cos(fangle)centerPt.y - sin(fangle)centerPt.x);
SetWorldTransform(hDc, &xform);
}
hb_retni( nGraphicsMode );
}
HB_FUNC( END_ROTATE )
{
HDC hDc = (HDC) hb_parnl( 1 );
XFORM xform;
int nGraphicsMode = hb_parni( 2 );
xform.eM11 = (float)1.0;
xform.eM12 = (float)0;
xform.eM21 = (float)0;
xform.eM22 = (float)1.0;
xform.eDx = (float)0;
xform.eDy = (float)0;
SetWorldTransform(hDc, &xform);
SetGraphicsMode(hDc, nGraphicsMode);
hb_ret();
}
pragma ENDDUMP