API Animation Control

- Alyce Alyce May 23, 2011
API Animation Control | What is an animation control? | Why use an animation control? | Creating an Animation Control | Animation Control Styles | Animation Control Messages | Demo

What is an animation control?

An animation control displays an AVI clip. An AVI clip is a series of bitmap frames like a movie. Animation controls can only display AVI clips that do not contain audio.

Why use an animation control?

The control plays the frames of an animation automatically. You can use Liberty BASIC sprite animation for games and similar applications, but sprites require your program to handle all of the action. If you need a small animation, the animation control handles the action and makes the code shorter and the programming easier! Animation controls often appear in a dialog during file copying or downloading or searching. An animation looks like this:


Creating an Animation Control

Use CreateWindowExA to create an animation control. You will need to use GetWindowLongA to get the instance handle of your program window. The classname for an animation control is "SysAnimate32". You must include the style bits for the type of animation control desired. The styles are listed below. If you want multiple styles, put the bits together with OR like this:

In addition to the animation control styles, you must specify that the control is a child window, and that it is visible.

Animation Control Styles

Liberty BASIC does not recogize these windows constants for animation control styles, so you must set the values yourself. Instead of _ACM_OPEN use: ACM.OPEN = 1124

  • ACM.OPEN = 1124

  • ACS.AUTOPLAY = 4. Starts playing the animation as soon as the AVI clip is opened.

  • ACS.CENTER = 1. Centers the animation in the animation control's window.

  • ACS.TIMER = 8. By default, the control creates a thread to play the AVI clip. If you set this flag, the control plays the clip without creating a thread; internally the control uses a Win32 timer to synchronize playback.

  • ACS.TRANSPARENT = 2. Allows you to match an animation's background color to that of the underlying window, creating a "transparent" background.

Animation Control Messages

These messages are sent with SendMessageA. If an animation control has the ACS_AUTOPLAY style, it begins playing as soon as it is opened, so there is no need to send an ACM_PLAY. message. If it does not have the autoplay style, it must be sent a message to open it, and another one to play it.

  • ACM.OPEN = 1124. Opens an AVI clip and displays its first frame in an animation control.

  • ACM.PLAY = 1125. Plays an AVI clip in an animation control. The control plays the clip in the background while the thread continues executing.

  • ACM.STOP = 1126. Stops playing an AVI clip in an animation control.


An animated torch AVI is included here. You may download it to your computer by right-clicking and selecting "Save As."

'Alyce Watson
    'put your filename here:
    anifile$ =  "torchani.avi"  'avi file name
    class$           = "SysAnimate32"   'class for control
    ACS.TRANSPARENT  = 2    'transparent background - style
    ACS.AUTOPLAY     = 4    'play as soon as opened - style
    ACM.OPEN         = 1124 'open file - message
    'initialize common controls:
    calldll #comctl32, "InitCommonControls",_
    re as void
    WindowWidth = 300 : WindowHeight = 100
    UpperLeftX = Int((DisplayWidth-WindowWidth)/2)
    UpperLeftY = Int((DisplayHeight-WindowHeight)/2)
button #main.default, "Exit",[quit],UL,220,10,70,24
statictext #main.tip, "Isn't this cool?",80,20,100,130
open "Animation Control" for window as #main
print #main, "trapclose [quit]"
    hwndParent = hwnd(#main)
    ' Get window instance handle
    CallDLL #user32, "GetWindowLongA",_
    hwndParent As ulong,_GWL_HINSTANCE As long,_
    hInstance As ulong   'instance handle
    ' Create animation control, use autoplay flag, transparent background
    ' Must be a child window, and must be visible
    calldll #user32, "CreateWindowExA",_
    0 As long,_                  ' extended style
    class$ as ptr,_              ' class name
    "" as ptr,_                  ' caption = none
    style as long,_              ' style
    10 as long,_                 ' left x
    10 as long,_                 ' top y
    0 as long,_                  ' width = 0
    0 as long,_                  ' height = 0
    hwndParent as ulong,_        ' parent hWnd
    0 as ulong,_                 ' handle to menu = 0
    hInstance as ulong,_         ' hInstance
    "" as ptr,_                  ' pointer to window creation data = none
    hwndAC as ulong              ' animation control handle
    'send message to open file, which will play automatically
    calldll #user32, "SendMessageA",_
    hwndAC as ulong,ACM.OPEN as long,_
    0 as long,anifile$ as ptr,_
    re as long
[quit] close #main : end

API Animation Control | What is an animation control? | Why use an animation control? | Creating an Animation Control | Animation Control Styles | Animation Control Messages | Demo