6.8 KiB
Animation Control
Animation control is one control, which can be used to display animations; it is very simple and easy to use.
You can create an animation control by calling CreateWindow function with
CTRL_ANIMATION as the control class name.
ANIMATION Object
Before creating an animation control, you must create an object of ANIMATION.
This object is actually a linked list structure, and each node of the linked
list represents a frame of the animation object. An object of ANIMATION is
represented by the following two structures:
What the ANIMATION structure describes are the global properties of objects
of animation, and includes the width and height of an animation, number of
frames, time scale used for indicating delaying (1 means 10ms), and the header
pointer to the linked list of animation frames.
ANIMATIONFRAME structure presents a single animation frame, and includes the
following information:
- Offset of the current animation frame in the global animation, and the width and height of the frame. Since an animation frame may only change partial image information, so including only the changed part in the frame structure will significantly reduce the amount of data for frames.
- Delay time of the current frame. Calculate the display time of the current
frame with
time_unitin theANIMATIONobject as the scale. - Image information of the current frame. When you use
NEWGALinterface, the image is represented by a memoryDC;otherwise aBITMAPobject represents the image.
An application can construct an ANIMATION object itself, and can also call
the following function to directly create an ANIMATION object from an image
file in GIF98a format.
The above-mentioned function will read the image information of the animation
GIF from the data area in GIF98a format, and then create an ANIMATION
object.
After an application creates an ANIMATION object, and can both display it,
also can create an animation control to display the animation. When you call
CreateWindow function to create an animation control, you can pass the
created ANIMATION object to the animation control and the animation control
will use the ANIMATION object to display the animation automatically. For
example, an ANIMATION object is created from a GIF file in the following
code fragment, and then using the object creates an animation control:
It should be noted that you could pass the pointer to the ANIMATION object
into an animation control through dwAddData argument when calling
CreateWindow function.
Styles of Animation Control
At present, there are three styles for an animation control:
ANS_AUTOLOOP:An animation control will display the animation circularly after the style is used.ANS_SCALED:The display image can be scaled.ANS_FITTOANI:Fit the control size follows the animation.
Messages of Animation Control
Messages of animation controls are very simple. There are the following several message currently, which can be used to control the display action of an animation control.
ANM_SETANIMATION:Set anANIMATIONobject.ANM_GETANIMATION:Get the currentANIMATIONobject.ANM_STARTPLAY:Start playing the animation. Before sendingANM_STARTPLAYto an animation control, the animation control will only display the first frame image of theANIMATIONobject; and only afterANM_STARTPLAYmessage is sent, the animation control can display an animation according to the information inANIMATIONobject.ANM_PAUSE_RESUME:Pause/Resume playing. This message is used to pause the play of an animation (during playing), or used to resume the play of an animation (when the animation has been paused).ANM_STOPPLAY:Stop the play of an animation. The animation control displays the first frame of theANIAMTION.
Sample Program
Code in List 1 illustrates the use of an animation control. Please refer to
animation.c file of the demo program package mg-samples of this guide for
complete source code.
List 1 Use of animation control
Figure 1 Use of an animation control
In the program within List 1, banner.gif file in the current directory is
loaded when the main window is created, and the corresponding ANIMATION
object is created. Then two animation controls are created. The first animation
control start playing the animation immediately after created, and the second
animation control won’t play until the user clicks the window. Figure 1 shows
the running effect of the sample program, in which what the first animation
control displays is the second frame of banner.gif file, and the second
animation control displays the first frame.
-- Main.XiaodongLi - 26 Oct 2009
<< | Table of Contents | >>
