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_VisibleA = 500
%ID_VisibleB = 600
%ID_Timer = 700
Global hDlg, hbmpADC, hsourceA, hsourceAdc as dword
Global hbmpBDC, hsourceB, hsourceBdc as dword
Function PBMain() As Long
Dialog New Pixels, 0, "Rotate",200,150,700,350, %WS_OverlappedWindow To hDlg
'gbRuler image
Control Add Graphic, hDlg, %ID_VisibleA, "", 25,25,300,300
Graphic Attach hDlg, %ID_VisibleA
Graphic Get DC To hbmpADC
Graphic Render "ruler.bmp", (0,0)-(299,299)
Graphic Bitmap New 300,300 to hSourceA
Graphic Attach hSourceA,0
Graphic Get DC to hsourceADC
Graphic Copy hDlg, %ID_VisibleA
Graphic Attach hdlg, %ID_VisibleA, redraw
'cowgirl image
Control Add Graphic, hDlg, %ID_VisibleB, "", 350,25,300,300
Graphic Attach hDlg, %ID_VisibleB
Graphic Get DC To hbmpBDC
Graphic Render "cowgirl.bmp", (0,0)-(299,299)
Graphic Bitmap New 300,300 to hSourceB
Graphic Attach hSourceB,0
Graphic Get DC to hsourceBDC
Graphic Copy hDlg, %ID_VisibleB
Graphic attach hdlg, %ID_VisibleB, 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, 25, ByVal %NULL)
Case %WM_Timer
theta = theta + .05
theta = 0.5
RotateImage(theta, hsourceADC, hbmpADC) : Graphic Attach hDlg, %ID_VisibleA : Graphic ReDraw
RotateImage(theta, hsourceBDC, hbmpBDC) : Graphic Attach hDlg, %ID_VisibleB : Graphic ReDraw
Case %WM_LButtonDblClk
Static rFlag As Long
rFlag = rFlag Xor 1
If rFlag Then KillTimer CB.Hndl, %ID_Timer Else SetTimer(CB.Hndl, %ID_Timer, 15, ByVal %NULL)
End Select
End Function
Function RotateImage(theta As Single, hSrc As Dword, hDest As Dword) As Long
Dim PlgPts(0 To 2) As PointAPI
Local XCenter, YCenter As Long
XCenter = 149 : YCenter = 149
' newx = XCenter + (x - XCenter) * Cos(theta) - (y - YCenter) * Sin(theta)
' newy = YCenter + (x - XCenter) * Sin(theta) + (y - YCenter) * Cos(theta)
PlgPts(0).X = XCenter + (0 - XCenter) * Cos(theta) - (0 - YCenter) * Sin(theta) 'upper-left in target
PlgPts(0).Y = YCenter + (0 - XCenter) * Sin(theta) + (0 - YCenter) * Cos(theta)
PlgPts(1).X = XCenter + (299 - XCenter) * Cos(theta) - (0 - YCenter) * Sin(theta) 'upper-right in target
PlgPts(1).Y = YCenter + (299 - XCenter) * Sin(theta) + (0 - YCenter) * Cos(theta)
PlgPts(2).X = XCenter + (0 - XCenter) * Cos(theta) - (299 - YCenter) * Sin(theta) 'lower left in target
PlgPts(2).Y = YCenter + (0 - XCenter) * Sin(theta) + (299 - YCenter) * Cos(theta)
SetStretchBltMode hsrc,%HALFTONE
SetBrushOrgEx hsrc,0,0, ByVal %NULL
PlgBlt(hDest, PlgPts(0), hSrc, 0, 0, 300, 300, 0&, 0, 0) ' Draw rotated image
End Function
'gbs_00908
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm