アニメーション コントロールを作成する方法
このトピックではアニメーション コントロールを作成する方法について説明します。 付属の 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;
}
関連トピック