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"
#Resource "gbsnippets.pbr"
Type spriteInfo
w As Long
h As Long
x As Long
y As Long
dx As Long
dy As Long
hBMP As DWord
End Type
Global hDlg As DWord, sprite As spriteInfo, iCount As Long
Global hLst as DWord, hBMP as DWord
Global canvasW As Long, canvasH As Long, hSprite As DWord
%ID_Graphic = 300 : %ID_Timer = 400 : %Delta = 2
Function PBMain() As Long
canvasW = 300 : canvasH = 300
Dialog New Pixels, 0, "Graphic Control Test",300,300,400,400, %WS_SysMenu, 0 To hDlg
Control Add Graphic, hDlg, %ID_Graphic,"", 0,0,canvasW,canvasH, %WS_Visible Or %SS_Sunken
Definesprite
Graphic Attach hDlg, %ID_Graphic
Graphic Color %Black,%White
Graphic Clear
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_InitDialog
SetTimer(CB.Hndl, %ID_Timer, 20, ByVal %NULL) 'uses callback messages
Case %WM_Timer
Incr iCount : Dialog Set Text hDlg, Str$(iCount)
Movesprite
Drawsprite
Control Redraw hDlg, %ID_Graphic
Case %WM_Destroy
KillTimer CB.Hndl, %ID_Timer
Case %WM_Command
If CB.Ctl = %ID_Graphic Then
End If
End Select
End Function
Sub Drawsprite
Graphic Clear
Graphic Copy sprite.hBMP, 0 To (sprite.x, sprite.y)
End Sub
Sub Movesprite
sprite.x = sprite.x + sprite.dx
sprite.y = sprite.y + sprite.dy
If sprite.x < 0 Then
sprite.x = 0
sprite.dx = %Delta
ElseIf sprite.x + sprite.w > canvasW Then
sprite.x = canvasW - sprite.w
sprite.dx = - %Delta
End If
If sprite.y < 0 Then
sprite.y = 0
sprite.dy = %Delta
ElseIf sprite.y + sprite.h > canvasH Then
sprite.y = canvasH - sprite.h
sprite.dy = - %Delta
End If
End Sub
Sub Definesprite
sprite.w = 32
sprite.h = 32
sprite.x = 50
sprite.y = 150
sprite.dx = %Delta
sprite.dy = %Delta
Graphic Bitmap New 32,32 to hBMP
sprite.hBMP = hBMP
Graphic Attach hBMP,0
'create imagelist w,h,depth,size
ImageList New Icon 32,32,24,100 To hLst
ImageList Add Icon hLst, "mos001"
Graphic ImageList (0,0), hLst, 1,0,%ILD_Normal
Graphic Attach hDlg, %ID_Graphic
End Sub
'gbs_00452
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm