애니메이션 컨트롤을 만드는 방법
이 항목에서는 애니메이션 컨트롤을 만드는 방법을 보여 줍니다. 함께 제공되는 C++ 코드 예는 대화 상자에서 애니메이션 컨트롤을 만듭니다. 지정된 컨트롤 아래에 애니메이션 컨트롤을 배치하고 AVI(Audio-Video Interleaved) 클립의 프레임 크기를 기반으로 애니메이션 컨트롤의 크기를 설정합니다.
알아야 하는 작업
기술
필수 구성 요소
- 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;
}
관련 항목