Επεξεργασία

Κοινή χρήση μέσω


Create the Main Animation Objects

To use Windows Animation in your application, the first step is to create a small set of main animation objects.

Overview

Use the CoCreateInstance function to create the animation manager, animation timer, and transition library objects.

These objects will be needed to create and display animations, so they usually should not be released until the application is shutting down. If there is no chance that any registered callbacks could have created a reference cycle, releasing the objects is sufficient for a proper cleanup. Otherwise, the application can clean up by clearing the callbacks (passing NULL in the place of each) or by calling the animation manager's Shutdown method.

Example Code

The following example code is taken from MainWindow.cpp in the Windows Animation samples; see the CMainWindow::InitializeAnimation method.

// Create the animation manager object

HRESULT hr = CoCreateInstance(
    CLSID_UIAnimationManager,
    NULL,
    CLSCTX_INPROC_SERVER,
    IID_PPV_ARGS(&m_pAnimationManager)
    );

if (SUCCEEDED(hr))
{
    // Create the animation timer object

    hr = CoCreateInstance(
        CLSID_UIAnimationTimer,
        NULL,
        CLSCTX_INPROC_SERVER,
        IID_PPV_ARGS(&m_pAnimationTimer)
        );

    if (SUCCEEDED(hr))
    {
        // Create the transition library object

        hr = CoCreateInstance(
            CLSID_UIAnimationTransitionLibrary,
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_PPV_ARGS(&m_pTransitionLibrary)
            );

        ...

    }

    ...

}

Note the following definitions from MainWindow.h.

class CMainWindow
{

    ...

private:

    // Animation components

    IUIAnimationManager *m_pAnimationManager;
    IUIAnimationTimer *m_pAnimationTimer;
    IUIAnimationTransitionLibrary *m_pTransitionLibrary;

    ...

};

Next Step

After completing this step, the next step is: Create Animation Variables.

CoCreateInstance

IUIAnimationManager

IUIAnimationTimer

IUIAnimationTransitionLibrary

Windows Animation Overview