Udostępnij przez


Jak utworzyć kontrolkę animacji

W tym temacie pokazano, jak utworzyć kontrolkę animacji. Towarzyszący przykład kodu C++ tworzy kontrolkę animacji w oknie dialogowym. Umieszcza kontrolkę animacji poniżej określonej kontrolki i ustawia wymiary kontrolki animacji na podstawie wymiarów ramki w klipie Audio-Video Przeplatane (AVI).

Co musisz wiedzieć

Technologie

  • elementy sterujące Windows

Warunki wstępne

  • C/C++
  • Programowanie interfejsu użytkownika systemu Windows
  • Pliki AVI

Instrukcje

Krok 1. Utwórz instancję kontrolki animacji.

Użyj makra Animate_Create, aby utworzyć wystąpienie kontrolki animacji.

// 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); 

Krok 2. Położenie kontrolki animacji.

Pobierz współrzędne ekranu określonego przycisku sterującego.

// nIDCtl - identifier of the control below which the animation control is to be positioned.
GetWindowRect(GetDlgItem(hwndDlg, nIDCtl), &rc); 

Przekonwertuj współrzędne lewego dolnego rogu na współrzędne klienta.

POINT pt;
pt.x = rc.left; 
pt.y = rc.bottom; 
ScreenToClient(hwndDlg, &pt); 

Umieść kontrolkę animacji poniżej określonego przycisku kontrolki.

// 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);

Krok 3. Otwórz klip AVI.

Wywołaj makro Animate_Open, aby otworzyć klip AVI i wyświetlić pierwszą ramkę w kontrolce animacji. Wywołaj funkcję ShowWindow, aby ustawić widoczność kontrolki animacji.

Animate_Open(hwndAnim, "SEARCH.AVI"); 
ShowWindow(hwndAnim, SW_SHOW); 

Kompletny przykład

// 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; 
} 

informacje o kontrolkach animacji

Dokumentacja referencyjna kontroli animacji

Używanie kontrolek animacji

Animacja