Date: 02-16-2022
Return to Index
created by gbSnippets
'Displaying a slideshow of images is a common need for programmers. In general,
'the task has 3 parts:
' - getting the list of image
' - selecting which of the list to show
' - displaing the image (for a limited time).
'Primary Code:
'In this example, resource images are used. The Choose$ statement is used to cycle
'through a pre-specified selection of the resource images. A graphic control is
'used to display the images.
ImgName = Choose$(Counter Mod 4, "cowgirl", "smallface", "about", "face", "update")
Graphic Render ImgName, (0,0)-(99,99)
'The list of images could equally have been read from a folder using DIR$, from a
'text file giving the list of images. Another easy option would have been to randomly
'selected from items the list (just put the list in an array and use RND to select
'elements from the list.
'Compilable Example: (Jose Includes)
'This example resizes all images to 100x100 - the size of the graphic control.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Resource "gbsnippets.pbr"
%ID_Timer1 = 500 : %ID_Timer2 = 501
Global hDlg As DWord
Function PBMain () As Long
Dialog New Pixels, 0, "Timer",,, 150,100, %WS_OverlappedWindow To hDlg
Control Add Graphic, hDlg, 100, "", 0,0,200,200
Graphic Attach hDlg, 100
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_Timer1, 2000, ByVal %NULL) 'uses callback messages
Dialog Post CB.Hndl, %WM_Timer, %ID_TIMER1, 0 ' optional - forces an initial %WM_TIMER "event"
Case %WM_Timer
Local ImgName As String
Static Counter As Long
Incr Counter
ImgName = Choose$(Counter Mod 2, "cowgirl", "smallface", "about") 'use as many images as you wish, using Mod (n-2)
Graphic Render ImgName, (0,0)-(99,99)
Case %WM_Destroy
KillTimer CB.Hndl, %ID_Timer1
End Select
End Function
'gbs_00571
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm