An animation control is a window that displays an Audio-Video Interleaved (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.
One common use for an animation control is to indicate system activity during a lengthy operation. This is possible because the operation thread continues executing while the AVI clip is displayed. For example, the Find dialog box of Microsoft® Windows® Explorer displays a moving magnifying glass as the system searches for a file.
An animation control can display an AVI clip originating from either an uncompressed AVI file or from an AVI file that was compressed using run-length (BI_RLE8) encoding. You can add the AVI clip to your application as an AVI resource, or the clip can accompany your application as a separate AVI file.
An animation control belongs to the ANIMATE_CLASS window class. You create
an animation control by using the
If you create an animation control within a dialog box or from a dialog box resource, the control is automatically destroyed when the user closes the dialog box. If you create an animation control within a window, you must explicitly destroy the control.
An application sends messages to an animation control to open, play, stop, and close the corresponding AVI clip. Each message has one or more macros that you can use instead of sending the message explicitly.
After creating an animation control, an application sends the
If the animation control has the
An animation control can send two notification messages,
To close the AVI file or AVI resource and remove it from memory, an
application can use the
This section describes the window messages handled by the window procedure for the ANIMATE_CLASS window class.
| Message | Processing performed |
|---|---|
| Frees the AVI file or AVI resource associated with the animation control. | |
| Frees the AVI file or AVI resource, frees an internal data
structure, and then calls the |
|
| Erases the window background using the current background color for static controls. | |
| Allocates and initializes an internal data structure and then calls DefWindowProc. | |
| Returns the HTTRANSPARENT hit test value. | |
| Draws an AVI frame in the animation control. | |
| Checks if the control has the ACS_CENTER style. If the control does not, it calls DefWindowProc. Otherwise, it centers the animation in the control, invalidates the control, and then calls DefWindowProc. |
The following function creates an animation control in a dialog box. The animation control is positioned below the specified control, and the dimensions of the animation control are based on the dimensions of a frame in the AVI clip.
// CreateAnimationCtrl - creates an animation control, positions it
// below the specified control in a dialog box,
// and opens the AVI clip for the animation control.
// Returns the handle to the animation control.
// hwndDlg - handle to the dialog box.
// nIDCtl - identifier of the control below which the animation control
// is to be positioned.
//
// Constants
// IDC_ANIMATE - identifier of the animation control.
// CX_FRAME, CY_FRAME - width and height of the frames
// in the AVI clip.
HWND CreateAnimationCtrl(HWND hwndDlg, int nIDCtl)
{
HWND hwndAnim = NULL;
RECT rc;
POINT pt;
// Create the animation control.
hwndAnim = Animate_Create(hwndDlg, IDC_ANIMATE,
WS_BORDER | WS_CHILD, g_hinst);
// Get the screen coordinates of the specified control button.
GetWindowRect(GetDlgItem(hwndDlg, nIDCtl), &rc);
// Convert the coordinates of the lower-left corner to
// client coordinates.
pt.x = rc.left;
pt.y = rc.bottom;
ScreenToClient(hwndDlg, &pt);
// Position the animation control below the Stop button.
SetWindowPos(hwndAnim, 0, pt.x, pt.y + 20,
CX_FRAME, CY_FRAME,
SWP_NOZORDER | SWP_DRAWFRAME);
// Open the AVI clip, and show the animation control.
Animate_Open(hwndAnim, "SEARCH.AVI");
ShowWindow(hwndAnim, SW_SHOW);
return hwndAnim;
}
The following function uses the animation control macros to control the display of the AVI clip in an animation control.
// DoAnimation - plays, stops, or closes an animation control's
// AVI clip, depending on the value of an action flag.
// hwndAnim - handle to an animation control
// nAction - flag that determines whether to play, stop, or close
// the AVI clip.
void DoAnimation(HWND hwndAnim, int nAction)
{
switch (nAction) {
case PLAYIT:
// Play the clip continuously starting with the
// first frame.
Animate_Play(hwndAnim, 0, -1, -1);
break;
case STOPIT:
Animate_Stop(hwndAnim);
break;
case CLOSEIT:
Animate_Close(hwndAnim);
break;
default:
break;
}
return;
}