Repository navigation
SysWin Gui Animate
Home › All Categories › sys/win › sys/win/gui › Animate
Opens, plays, stops and closes silent AVI clips in an animation control.
An animation control plays a short silent video clip, the kind shown while a file is copied or
a search runs. The clip must be an AVI file, uncompressed or RLE-compressed, with no sound; it
comes from a file or from an AVI resource of a module. Create the control with
CWindow.AddControl( "Animate", ... ), which gives it the ACS_TRANSPARENT style, or with
PropSheet.Create. Every function here takes the control's handle
first and is written with the namespace: Animate.Play( hAnimate, 0, -1, -1 ).
The control plays on a thread of its own, so the program carries on while it runs. Frames are
numbered from 0, and only the first 65536 can be addressed. Without the ACS_CENTER style the
control resizes itself to the clip when it opens one; with it, the clip is centred in the
control. ACS_AUTOPLAY starts each clip as soon as it is opened.
#import "sys/win"
#import "sys/win/gui"
using win, guiA window that plays clock.avi, from the program's folder, over and over, with a button that
stops and restarts it.
#import "sys/win"
#import "sys/win/gui"
using win, gui
const IDC_ANIM = 101
const IDC_TOGGLE = 102
declare function WndProc( byval hwnd as HWND, byval uMsg as UINT, byval wParam as WPARAM, byval lParam as LPARAM ) as LRESULT
function main() as long
SetProcessDpiAwareness( PROCESS_SYSTEM_DPI_AWARE )
EnableVisualStyles()
dim pWindow as CWindow = "AnimateDemo"
dim hWin as HWND = pWindow.Create( NULL, "Animation", @WndProc )
pWindow.SetClientSize( 300, 200 )
pWindow.Center()
dim hAnim as HWND = pWindow.AddControl( "Animate", hWin, IDC_ANIM, "", 20, 20, 260, 120, _
WS_VISIBLE or ACS_CENTER or ACS_TRANSPARENT )
pWindow.AddControl( "Button", hWin, IDC_TOGGLE, "&Stop", 110, 155, 80, 28 )
if Animate.OpenClip( hAnim, "clock.avi" ) then
Animate.Play( hAnim, 0, -1, -1 )
else
SetWindowText( hWin, "clock.avi could not be opened" )
end if
return pWindow.DoEvents( SW_NORMAL )
end function
function WndProc( byval hwnd as HWND, byval uMsg as UINT, byval wParam as WPARAM, byval lParam as LPARAM ) as LRESULT
select case uMsg
case WM_COMMAND
if CBCTL( wParam, lParam ) = IDC_TOGGLE andalso CBCTLMSG( wParam, lParam ) = BN_CLICKED then
dim hAnim as HWND = GetDlgItem( hwnd, IDC_ANIM )
if Animate.IsPlaying( hAnim ) then
Animate.Stop( hAnim )
SetWindowText( cast( HWND, lParam ), "&Play" )
else
Animate.Play( hAnim, 0, -1, -1 )
SetWindowText( cast( HWND, lParam ), "&Stop" )
end if
end if
return 0
case WM_DESTROY
Animate.CloseClip( GetDlgItem( hwnd, IDC_ANIM ) )
PostQuitMessage( 0 )
return 0
end select
return DefWindowProcW( hwnd, uMsg, wParam, lParam )
end function
end main()| Function | Does |
|---|---|
| OpenClip | Opens a clip from a file or from the program's resources. |
| OpenEx | Opens a clip from the resources of a given module. |
| Play | Plays a run of frames, a number of times or for ever. |
| Stop | Stops playing. |
| IsPlaying | Says whether a clip is playing. |
| SeekFrame | Shows one frame. |
| CloseClip | Closes the clip. |
function OpenClip( byval hAnimate as HWND, byval pwzName as wstring ptr ) as booleanOpens a clip and shows its first frame (or starts it, with ACS_AUTOPLAY). pwzName is the
path of an AVI file, or the name of an AVI resource of the module that created the control;
for a numbered resource pass cast( wstring ptr, id ). A clip already open is closed first.
Returns true on success; false when the file or resource is missing or is not a clip the
control can play.
Example
if Animate.OpenClip( hCtrl, "search.avi" ) = false then print "cannot open search.avi"Microsoft Learn: ACM_OPEN
function OpenEx( byval hAnimate as HWND, byval hInstance as HINSTANCE, byval pwzName as wstring ptr ) as booleanOpens a clip from the resources of the module hInstance, for example a DLL loaded with
LoadLibraryW. pwzName is the resource's name, or cast( wstring ptr, id ).
Returns true on success.
Example
dim hRes as HMODULE = LoadLibraryW( "myclips.dll" )
if hRes then Animate.OpenEx( hCtrl, hRes, cast( wstring ptr, 101 ) )Microsoft Learn: ACM_OPEN
function Play( byval hAnimate as HWND, byval from as UINT, byval _to as UINT, byval rep as UINT ) as booleanPlays frames from to _to of the open clip, rep times, in the background.
| Parameter | Meaning |
|---|---|
from |
The first frame, from 0. |
_to |
The last frame; -1 is the end of the clip. |
rep |
How many times to play it; -1 is for ever, until Stop. |
Returns true on success; false when no clip is open.
Example
Animate.Play( hCtrl, 0, -1, 1 ) ' once throughMicrosoft Learn: ACM_PLAY
function Stop( byval hAnimate as HWND ) as booleanStops the clip; the frame on show stays.
Returns true on success.
Example
Animate.Stop( hCtrl )Microsoft Learn: ACM_STOP
function IsPlaying( byval hAnimate as HWND ) as booleanIt needs version 6 of the common controls: call EnableVisualStyles() at start-up or give the
program a manifest. Without it the control does not know the request and the answer is always
false.
Returns true while a clip is playing, false when it is stopped or none is open.
Example
if Animate.IsPlaying( hCtrl ) then Animate.Stop( hCtrl )Microsoft Learn: ACM_ISPLAYING
function SeekFrame( byval hAnimate as HWND, byval frame as UINT ) as booleanShows frame frame of the open clip and stays there: Play from frame to frame,
once.
Returns true on success; false when no clip is open.
Example
Animate.SeekFrame( hCtrl, 0 ) ' back to the first pictureMicrosoft Learn: Animate_Seek
function CloseClip( byval hAnimate as HWND ) as booleanCloses the open clip and clears the control.
Returns the control's reply to an open request without a clip, which is false even when
an open clip was closed: it is not a success flag.
Example
Animate.CloseClip( hCtrl )Microsoft Learn: Animate_Close
- sys/win/gui
-
PropSheet for
PropSheet.Create, which creates an animation control -
CWindow for
AddControl( "Animate", ... ) - Resources
- ProgBar
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing