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"
Global hDlg, hbmp, htarget, hbmpdc, htargetdc As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",200,150,350,350, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Control Add Graphic, hDlg, 200, "", 10,40,100,100
Graphic Attach hDlg, 200
Graphic Get DC To hbmpDC
Graphic Render "cowgirl.bmp", (0,0)-(99,99)
Control Add Graphic, hDlg, 300, "", 130,40,200,200
Graphic Attach hDlg, 300
Graphic Get DC To hTargetDC
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If Cb.Msg = %WM_Command And Cb.Ctl = 100 And Cb.CtlMsg = %BN_Clicked Then
Static thetA As Single
THETA = THETA + 0.1
RotateImage(THETA)
Graphic ReDraw
End If
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 = 100 + (0 - 50) * Cos(theta) - (0 - 50) * Sin(theta) 'upper-left in target
PlgPts(0).Y = 100 + (0 - 50) * Sin(theta) + (0 - 50) * Cos(theta)
PlgPts(1).X = 100 + (99 - 50) * Cos(theta) - (0 - 50) * Sin(theta) 'upper-right in target
PlgPts(1).Y = 100 + (99 - 50) * Sin(theta) + (0 - 50) * Cos(theta)
PlgPts(2).X = 100 + (0 - 50) * Cos(theta) - (99 - 50) * Sin(theta) 'lower left in target
PlgPts(2).Y = 100 + (0 - 50) * Sin(theta) + (99 - 50) * Cos(theta)
' PlgPts(0).X = 0 'upper-left in target
' PlgPts(0).Y = 0
' PlgPts(1).X = 99 'upper-right in target
' PlgPts(1).Y = 0
' PlgPts(2).X = 0 'lower left in target
' PlgPts(2).Y = 99
PlgBlt(hTargetDC, PlgPts(0), hbmpDC, 0, 0, 100, 100, 0&, 0, 0) ' Draw rotated image
End Function
'gbs_00898
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm