BeginBufferedAnimation 関数 (uxtheme.h)

バッファー内のアニメーション操作を開始します。 アニメーションは、指定された期間にわたる 2 つのバッファーの内容間のクロスフェードで構成されます。

構文

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 メッセージを生成することで、これら 2 つの状態間の中間フレームの描画を処理します。

BeginBufferedAnimation は、BufferedPaintRenderAnimation を呼び出す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