Share via


BeginBufferedAnimation 함수(uxtheme.h)

버퍼링된 애니메이션 작업을 시작합니다. 애니메이션은 지정된 시간 동안 두 버퍼의 콘텐츠 간 교차 페이드로 구성됩니다.

구문

HANIMATIONBUFFER BeginBufferedAnimation(
        HWND               hwnd,
        HDC                hdcTarget,
        const RECT         *prcTarget,
        BP_BUFFERFORMAT    dwFormat,
  [in]  BP_PAINTPARAMS     *pPaintParams,
  [in]  BP_ANIMATIONPARAMS *pAnimationParams,
  [out] HDC                *phdcFrom,
  [out] HDC                *phdcTo
);

매개 변수

hwnd

형식: HWND

애니메이션이 재생되는 창에 대한 핸들입니다.

hdcTarget

형식: HDC

버퍼에 애니메이션 효과를 주는 대상 DC의 핸들입니다.

prcTarget

형식: const RECT*

그릴 대상 DC의 영역을 지정하는 구조체에 대한 포인터입니다.

dwFormat

형식: BP_BUFFERFORMAT

버퍼의 형식입니다.

[in] pPaintParams

형식: BP_PAINTPARAMS*

페인트 작업 매개 변수를 정의하는 구조체에 대한 포인터입니다. 이 값은 NULL일 수 있습니다.

[in] pAnimationParams

형식: BP_ANIMATIONPARAMS*

애니메이션 작업 매개 변수를 정의하는 구조체에 대한 포인터입니다.

[out] phdcFrom

형식: HDC*

이 함수가 반환되면 이 값은 애플리케이션이 애니메이션의 초기 상태를 그려야 하는 DC 핸들( NULL이 아닌 경우)을 가리킵니다.

[out] phdcTo

형식: HDC*

이 함수가 반환되면 이 값은 애플리케이션이 애니메이션의 최종 상태를 그려야 하는 DC 핸들( NULL이 아닌 경우)을 가리킵니다.

반환 값

형식: HANIMATIONBUFFER

버퍼링된 페인트 애니메이션에 대한 핸들입니다.

설명

BeginBufferedAnimation 은 여러 WM_PAINT 메시지를 생성하여 두 상태 간에 중간 프레임을 그리는 것을 처리합니다.

BeginBufferedAnimationBufferedPaintRenderAnimation을 호출해야 하는 WM_PAINT 메시지를 생성하는 타이머를 시작합니다. 이러한 메시지 중에 BufferedPaintRenderAnimation 은 중간 프레임을 그릴 때 TRUE 를 반환하여 애플리케이션에 더 이상 그리기 작업이 없음을 나타냅니다.

애니메이션 기간이 0이면 phdcTo 만 반환되고 phdcFromNULL로 설정됩니다. 이 경우 애플리케이션은 phdcTo 를 사용하여 최종 상태를 그려 BeginBufferedPaint와 유사한 동작을 가져와야 합니다.

예제

다음 코드 예제에서는 이 함수를 사용하는 방법을 보여줍니다.

#include <windows.h>
#include <tchar.h>
#include <uxtheme.h>

#pragma comment(lib, "uxtheme.lib")

#define WNDCLASSNAME L"BufferedPaintSample_WndClass"
#define ANIMATION_DURATION 500

bool g_fCurrentState = true;
bool g_fNewState = true;

void StartAnimation(HWND hWnd)
{
    g_fNewState = !g_fCurrentState;
    InvalidateRect(hWnd, NULL, TRUE);
}

void Paint(HWND hWnd, HDC hdc, bool state)
{
    RECT rc;
    GetClientRect(hWnd, &rc);
    FillRect(hdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH));
    LPCTSTR pszIconId = state ? IDI_APPLICATION : IDI_ERROR;
    HICON hIcon = LoadIcon(NULL, pszIconId);
    if (hIcon)
    {
        DrawIcon(hdc, 10, 10, hIcon);
        DestroyIcon(hIcon);
    }
}

void OnPaint(HWND hWnd)
{
    PAINTSTRUCT ps;
    HDC hdc = BeginPaint(hWnd, &ps);
    if (hdc)
    {
        // See if this paint was generated by a soft-fade animation
        if (!BufferedPaintRenderAnimation(hWnd, hdc))
        {
            BP_ANIMATIONPARAMS animParams;
            ZeroMemory(&animParams, sizeof(animParams));
            animParams.cbSize = sizeof(BP_ANIMATIONPARAMS);
            animParams.style = BPAS_LINEAR;
            
            // Check if animation is needed. If not set dwDuration to 0
            animParams.dwDuration = (g_fCurrentState != g_fNewState ? ANIMATION_DURATION : 0);

            RECT rc;
            GetClientRect(hWnd, &rc);

            HDC hdcFrom, hdcTo;
            HANIMATIONBUFFER hbpAnimation = BeginBufferedAnimation(hWnd, hdc, &rc,
                BPBF_COMPATIBLEBITMAP, NULL, &animParams, &hdcFrom, &hdcTo);
            if (hbpAnimation)
            {
                if (hdcFrom)
                {
                    Paint(hWnd, hdcFrom, g_fCurrentState);
                }
                if (hdcTo)
                {
                    Paint(hWnd, hdcTo, g_fNewState);
                }

                g_fCurrentState = g_fNewState;
                EndBufferedAnimation(hbpAnimation, TRUE);
            }
            else
            {
                Paint(hWnd, hdc, g_fCurrentState);
            }
        }
        
        EndPaint(hWnd, &ps);
    }
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_LBUTTONDOWN:
        StartAnimation(hWnd);
        break;
    case WM_PAINT:
        OnPaint(hWnd);
        break;
    case WM_SIZE:
        BufferedPaintStopAllAnimations(hWnd);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

int WINAPI _tWinMain(HINSTANCE hInstance,
     HINSTANCE hPrevInstance,
     LPSTR     lpCmdLine,
     int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    if (SUCCEEDED(BufferedPaintInit()))
    {
        WNDCLASSEX wcex;
        ZeroMemory(&wcex, sizeof(wcex));
        wcex.cbSize = sizeof(WNDCLASSEX);
        wcex.style = CS_HREDRAW|CS_VREDRAW;
        wcex.lpfnWndProc = WndProc;
        wcex.hInstance = hInstance;
        wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
        wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        wcex.lpszClassName = WNDCLASSNAME;
        RegisterClassEx(&wcex);

        HWND hWnd = CreateWindow(WNDCLASSNAME, L"Buffered Paint Sample", 
            WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, 
            CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

        if (hWnd)
        {
            ShowWindow(hWnd, nCmdShow);
            UpdateWindow(hWnd);

            MSG msg;
            while (GetMessage(&msg, NULL, 0, 0))
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }

        BufferedPaintUnInit();
    }

    return 0;
}

void BufferedPaint(HDC hdc, const RECT *prcPaint)
{
    BP_PAINTPARAMS paintParams = {0};
    paintParams.cbSize = sizeof(paintParams);

    HDC hdcBuffer;
    HPAINTBUFFER hBufferedPaint = BeginBufferedPaint(hdc, prcPaint, 
        BPBF_COMPATIBLEBITMAP, &paintParams, &hdcBuffer);

    if (hBufferedPaint)
    {
        // Application specific painting code
        AppPaint(hdcBuffer, prcPaint);
        EndBufferedPaint(hBufferedPaint, TRUE);
    }
    else
    {
        // Error occurred, default to unbuffered painting
        AppPaint(hdc, prcPaint);
    }
}

요구 사항

요구 사항
지원되는 최소 클라이언트 Windows Vista [데스크톱 앱만 해당]
지원되는 최소 서버 Windows Server 2008 [데스크톱 앱만 해당]
대상 플랫폼 Windows
헤더 uxtheme.h
DLL UxTheme.dll