Animation

>> Monday, October 19, 2009


You want to view a .AVI file in your window. Use the Animtion control.

+ 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 Audio-Video Interleaved (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.
// hwnd - handle to the window.
// hwndBtn - handle 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 hwnd, int nIDCtl)
{
HWND hwndAnim = NULL;
RECT rc;
POINT pt;

// Create the animation control.
hwndAnim = Animate_Create(hwnd, IDC_ANIMATE, WS_BORDER | WS_CHILD, g_hinst);

// Get the screen coordinates of the specified control button.
GetWindowRect(hwndBtn, &rc);

// Convert the coordinates of the lower-left corner to
// client coordinates.
pt.x = rc.left;
pt.y = rc.bottom;
ScreenToClient(hwnd, &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, "video.AVI");
ShowWindow(hwndAnim, SW_SHOW);

return hwndAnim;
}

+ Controlling the AVI Clip
The following function uses the animation control macros to control the display of the AVI clip in an animation control. Use it inside the window procedure.
// 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 ;
}

0 comments: