Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg, hBMP, hBMPDC, hDC As Dword, r As Single
Enum Equates Singular
IDC_Graphic = 500
IDC_Timer
End Enum
Function PBMain() As Long
Dialog New Pixels, 0, "gbEyes",300,300,200,200, %WS_Popup, %WS_Ex_Layered To hDlg
Dialog Set Color hDlg, %Black, %White
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
SetLayeredWindowAttributes(hDlg, %White, 255, %LWA_ALPHA Or %LWA_Colorkey)
'create an eye
Graphic Bitmap New 50,50 To hBMP
Graphic Attach hBMP, 0
Graphic Color %Black, %White
Graphic Clear
Graphic Ellipse (0,0)-(50,50), %Red, %Red
Graphic Ellipse (25,25)-(40,40), %Black, %Black
Graphic Get DC To hBMPDC
'create the graphic control on which the eye is drawn (fills the dialog)
Control Add Graphic, hDlg, %IDC_Graphic, "", 0,0,200,200
Graphic Attach hDlg, %IDC_Graphic
Graphic Color %Black, %White
Graphic Clear
Graphic Get DC To hDC
'timer
SetTimer(hDlg, %IDC_Timer, 200, ByVal %NULL)
Dialog Set Text hDlg, Time$
Case %WM_ContextMenu
Dialog End hDlg
Case %WM_LButtonDown
If Cb.WParam = %MK_LBUTTON Then SendMessage hDlg, %WM_NCLButtonDown, %HTCaption, ByVal %Null ' force drag
Case %WM_Timer
r += 0.1
DrawEyes r, 0, 0
Graphic ReDraw
End Select
End Function
Sub DrawEyes(theta As Single, x As Long, y As Long)
Local imgW, imgH, XCenter, YCenter As Long
Dim PlgPts(0 To 2) As PointAPI
'rotation of original bitmap to a temporary memory bitmap
imgW = 50 : imgH = 50
XCenter = imgW/2 : YCenter = imgH/2
x = 0 : y = 0 'point in original bitmap
PlgPts(0).X = XCenter + (x - XCenter) * Cos(theta) - (y - YCenter) * Sin(theta) 'upper-left in target
PlgPts(0).Y = YCenter + (x - XCenter) * Sin(theta) + (y - YCenter) * Cos(theta)
x = imgW : y = 0 'point in original bitmap
PlgPts(1).X = XCenter + (x - XCenter) * Cos(theta) - (y - YCenter) * Sin(theta) 'upper-right in target
PlgPts(1).Y = YCenter + (x - XCenter) * Sin(theta) + (y - YCenter) * Cos(theta)
x = 0 : y = imgH 'point in original bitmap
PlgPts(2).X = XCenter + (x - XCenter) * Cos(theta) - (y - YCenter) * Sin(theta) 'lower left in target
PlgPts(2).Y = YCenter + (x - XCenter) * Sin(theta) + (y - YCenter) * Cos(theta)
Graphic Clear
PlgBlt(hDC, PlgPts(0), hBMPDC, 0, 0, imgW, imgH, 0&, 0, 0) ' Draw rotated image
End Sub
'gbs_01404
'Date: 10-17-2014
http://www.garybeene.com/sw/gbsnippets.htm