Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe "gbgauge.exe"
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Graphic
ID_Timer
End Enum
$Ver = "1.0"
Global hDlg As Dword
Global hGraphicDC As Dword
Global gBMP, gDC As Dword, gW,gH As Long
Global rBMP, rDC As Dword
Global sBMP, sDC As Dword, sW,sH As Long
Global Theta As Single, face$
'gW gH = gauge image w/h
'sW sH = sprite image w/h
Function PBMain() As Long
Dialog New Pixels, 0, "gbGauge - Animated Gauge v" + $Ver,300,300,200,250, %WS_OverlappedWindow To hDlg
LoadImages 'gauge and sprite (needle)
CreateGraphicControl
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
Theta = 3 * 3.14 / 4
ShowGauge
SetTimer hDlg, %ID_Timer, 25, 0
Case %WM_Timer
ShowGauge
Theta += 0.01 : If Theta > (9 * 3.14/4) Then Theta = (3*3.14/4)
Case %WM_Command
Select Case Cb.Ctl
End Select
End Select
End Function
Sub CreateGraphicControl
Control Add Graphic, hDlg, %IDC_Graphic,"Push", 0,0,200,200
Graphic Attach hDlg, %IDC_Graphic, ReDraw
Graphic Get DC To hGraphicDC
Control Set Size hDlg, %IDC_Graphic, gW,gH
Dialog Set Client hDlg, gW, gH
End Sub
Sub LoadImages
Graphic Bitmap Load "gauge.bmp", 0, 0 To gBMP
Graphic Attach gBMP, 0
Graphic Get Canvas To gW,gH
Graphic Get Bits To face$
End Sub
Sub ShowGauge
Local x0,y0,x1,y1,r,XCenter,YCenter As Long
'background
Graphic Clear
Graphic Copy gBMP, 0
'place rotated bitmap into the main graphic
Graphic Attach hDlg, %IDC_Graphic, ReDraw
TransparentBlt hGraphicDC,gW/2-sW/2,gH/2-sH/2,sW,sH,rDC,0,0,sW,sH,%Black
'needle/butotn
r = 0.7 * gW/2
x1 = gW/2 + r * Cos(theta) : y1 = gW/2 + r * Sin(theta)
x0 = gW/2 + 12 * Cos(theta-1.57) : y0 = gW/2 + 12 * Sin(theta-1.57) : Graphic Line (x0,y0)-(x1,y1), %Red
x0 = gW/2 + 12 * Cos(theta+1.57) : y0 = gW/2 + 12 * Sin(theta+1.57) : Graphic Line (x0,y0)-(x1,y1), %Red
Graphic Ellipse (gW/2-15,gW/2-15)-(gW/2+15,gW/2+15),%Red
x0 = gW/2 + 18 * Cos(theta) : y0 = gW/2 + 18 * Sin(theta) : Graphic Paint Border (x0,y0), %Red, %Red
Graphic Ellipse (gW/2-15,gW/2-15)-(gW/2+15,gW/2+15),%Black,%rgb_MidnightBlue
Graphic ReDraw
End Sub
'gbs_01415
'Date: 10-17-2014
http://www.garybeene.com/sw/gbsnippets.htm