Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
%id_timer = 500
Global hDlg, hsource, hbmpdc, hsourcedc as dword
Function PBMain() As Long
Dialog New Pixels, 0, "PlgBlt Rotation",200,150,300,300, %WS_OverlappedWindow To hDlg
Control Add Graphic, hDlg, 200, "", 0,0,300,300
Graphic Attach hDlg, 200
Graphic Get DC To hbmpDC
Graphic Render "cowgirl.bmp", (0,0)-(299,299)
Graphic Bitmap New 300,300 to hSource
Graphic Attach hSource,0
graphic get dc to hsourceDC
Graphic Copy hDlg, 200
graphic attach hdlg, 200, redraw
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Static theta As Single
select cASE CB.MSG
Case %WM_InitDialog
SetTimer(CB.Hndl, %ID_Timer, 15, ByVal %NULL) 'uses callback messages
Case %WM_Timer
theta = theta + .05
RotateImage(theta)
Graphic ReDraw
end select
End Function
Function RotateImage(theta As Single) As Long
Dim PlgPts(0 To 2) As PointAPI
' newx = XCenter + (x - XCenter) * Cos(theta) - (y - YCenter) * Sin(theta)
' newy = YCenter + (x - XCenter) * Sin(theta) + (y - YCenter) * Cos(theta)
PlgPts(0).X = 150 + (0 - 150) * Cos(theta) - (0 - 150) * Sin(theta) 'upper-left in target
PlgPts(0).Y = 150 + (0 - 150) * Sin(theta) + (0 - 150) * Cos(theta)
PlgPts(1).X = 150 + (299 - 150) * Cos(theta) - (0 - 150) * Sin(theta) 'upper-right in target
PlgPts(1).Y = 150 + (299 - 150) * Sin(theta) + (0 - 150) * Cos(theta)
PlgPts(2).X = 150 + (0 - 150) * Cos(theta) - (299 - 150) * Sin(theta) 'lower left in target
PlgPts(2).Y = 150 + (0 - 150) * Sin(theta) + (299 - 150) * Cos(theta)
PlgBlt(hbmpdc, PlgPts(0), hsourceDC, 0, 0, 300, 300, 0&, 0, 0) ' Draw rotated image
End Function
'gbs_00899
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm