Erstellen eines Animationssteuerelements
In diesem Thema wird veranschaulicht, wie ein Animationssteuerelement erstellt wird. Im zugehörigen C++-Codebeispiel wird ein Animationssteuerelement in einem Dialogfeld erstellt. Es positioniert das Animationssteuerelement unter einem angegebenen Steuerelement und legt die Abmessungen des Animationssteuerelements basierend auf den Abmessungen eines Frames im clip Audio-Video Interleaved (AVI) fest.
Wichtige Informationen
Technologien
Voraussetzungen
- C/C++
- Windows Benutzeroberfläche-Programmierung
- AVI-Dateien
Instructions
Schritt 1: Erstellen sie eine Instanz des Animationssteuerelements.
Verwenden Sie das Makro Animieren _ erstellen, um eine Instanz des Animationssteuerelements zu erstellen.
// 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);
Schritt 2: Positionieren des Animationssteuerelements.
Abrufen der Bildschirmkoordinaten der angegebenen Steuerelementschaltfläche.
// nIDCtl - identifier of the control below which the animation control is to be positioned.
GetWindowRect(GetDlgItem(hwndDlg, nIDCtl), &rc);
Konvertieren Sie die Koordinaten der unteren linken Ecke in Clientkoordinaten.
POINT pt;
pt.x = rc.left;
pt.y = rc.bottom;
ScreenToClient(hwndDlg, &pt);
Positionieren Sie das Animationssteuerelement unterhalb der angegebenen Steuerelementschaltfläche.
// 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);
Schritt 3: Öffnen Sie den AVI-Clip.
Rufen Sie das Makro Animieren _ öffnen auf, um den AVI-Clip zu öffnen und den ersten Frame im Animationssteuerelement anzuzeigen. Rufen Sie die ShowWindow-Funktion auf, um das Animationssteuerelement sichtbar zu machen.
Animate_Open(hwndAnim, "SEARCH.AVI");
ShowWindow(hwndAnim, SW_SHOW);
Vollständiges Beispiel
// 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;
}