Creating an Animation Control

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");

ShowWindow(hwndAnim, SW_SHOW);

return hwndAnim;

}