如何创建动画控件
本主题演示了如何创建动画控件。 随附的 C++ 代码示例在对话框中创建了一个动画控件。 它将动画控件放置在指定控件的下方,并根据音频视频交错 (AVI) 剪辑中帧的尺寸来设置动画控件的尺寸。
需要了解的事项
技术
先决条件
- C/C++
- Windows 用户界面编程
- AVI 文件
说明
步骤 1:创建一个动画控件实例。
使用 Animate_Create 宏来创建动画控件实例。
// IDC_ANIMATE - identifier of the animation control.
// hwndDlg - handle to the dialog box.
RECT rc;
hwndAnim = Animate_Create(hwndDlg, IDC_ANIMATE,
WS_BORDER | WS_CHILD, g_hinst);
步骤 2:定位动画控件。
获取指定控件按钮的屏幕坐标。
// nIDCtl - identifier of the control below which the animation control is to be positioned.
GetWindowRect(GetDlgItem(hwndDlg, nIDCtl), &rc);
将左下角的坐标转换为客户端坐标。
POINT pt;
pt.x = rc.left;
pt.y = rc.bottom;
ScreenToClient(hwndDlg, &pt);
将动画控件定位在指定控件按钮的下方。
// CX_FRAME, CY_FRAME - width and height of the frames in the AVI clip.
SetWindowPos(hwndAnim, 0, pt.x, pt.y + 20,
CX_FRAME, CY_FRAME,
SWP_NOZORDER | SWP_DRAWFRAME);
步骤 3:打开 AVI 剪辑。
调用 Animate_Open 宏以打开 AVI 剪辑,并在动画控件中显示第一帧。 调用 ShowWindow 函数以便让动画控件可见。
Animate_Open(hwndAnim, "SEARCH.AVI");
ShowWindow(hwndAnim, SW_SHOW);
完整示例
// 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;
// Create the animation control.
// IDC_ANIMATE - identifier of the animation control.
// hwndDlg - handle to the dialog box.
RECT rc;
hwndAnim = Animate_Create(hwndDlg, IDC_ANIMATE,
WS_BORDER | WS_CHILD, g_hinst);
// Get the screen coordinates of the specified control button.
// nIDCtl - identifier of the control below which the animation control is to be positioned.
GetWindowRect(GetDlgItem(hwndDlg, nIDCtl), &rc);
// Convert the coordinates of the lower-left corner to
// client coordinates.
POINT pt;
pt.x = rc.left;
pt.y = rc.bottom;
ScreenToClient(hwndDlg, &pt);
// Position the animation control below the Stop button.
// CX_FRAME, CY_FRAME - width and height of the frames in the AVI clip.
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;
}
相关主题