Win32 API 日本語リファレンス
ホームUI.Controls › BeginBufferedAnimation

BeginBufferedAnimation

関数
状態間の遷移を補間するバッファアニメーション描画を開始する。
DLLUXTHEME.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// UXTHEME.dll
#include <windows.h>

INT_PTR BeginBufferedAnimation(
    HWND hwnd,
    HDC hdcTarget,
    const RECT* prcTarget,
    BP_BUFFERFORMAT dwFormat,
    BP_PAINTPARAMS* pPaintParams,   // optional
    BP_ANIMATIONPARAMS* pAnimationParams,
    HDC* phdcFrom,
    HDC* phdcTo
);

パラメーター

名前方向説明
hwndHWNDinアニメーションを再生するウィンドウのハンドルです。
hdcTargetHDCinバッファーをアニメーション表示する対象 DC のハンドルです。
prcTargetRECT*in描画を行う対象 DC の領域を指定する構造体へのポインターです。
dwFormatBP_BUFFERFORMATinバッファーの形式です。
pPaintParamsBP_PAINTPARAMS*inoptional描画操作のパラメーターを定義する構造体へのポインターです。この値は NULL にできます。
pAnimationParamsBP_ANIMATIONPARAMS*inアニメーション操作のパラメーターを定義する構造体へのポインターです。
phdcFromHDC*outこの関数が返ると、NULL でない場合、この値はアプリケーションがアニメーションの開始状態を描画すべき DC のハンドルを指します。
phdcToHDC*outこの関数が返ると、NULL でない場合、この値はアプリケーションがアニメーションの最終状態を描画すべき DC のハンドルを指します。

戻り値の型: INT_PTR

公式ドキュメント

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

戻り値

Type: HANIMATIONBUFFER

バッファーペイントアニメーションのハンドルです。

解説(Remarks)

BeginBufferedAnimation は、複数の WM_PAINT メッセージを生成することで、これら2つの状態の間の中間フレームの描画を処理します。

BeginBufferedAnimation は、BufferedPaintRenderAnimation を呼び出すべき WM_PAINT メッセージを生成するタイマーを開始します。これらのメッセージの間、BufferedPaintRenderAnimation は中間フレームを描画したときに TRUE を返し、アプリケーションがそれ以上描画する必要がないことを示します。

アニメーションの継続時間が0の場合は、phdcTo のみが返され、phdcFromNULL に設定されます。この場合、アプリケーションは BeginBufferedPaint と同様の動作を得るために、phdcTo を使用して最終状態を描画する必要があります。

Examples

次のコード例は、この関数の使用方法を示しています。

#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);
    }
}
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// UXTHEME.dll
#include <windows.h>

INT_PTR BeginBufferedAnimation(
    HWND hwnd,
    HDC hdcTarget,
    const RECT* prcTarget,
    BP_BUFFERFORMAT dwFormat,
    BP_PAINTPARAMS* pPaintParams,   // optional
    BP_ANIMATIONPARAMS* pAnimationParams,
    HDC* phdcFrom,
    HDC* phdcTo
);
[DllImport("UXTHEME.dll", ExactSpelling = true)]
static extern IntPtr BeginBufferedAnimation(
    IntPtr hwnd,   // HWND
    IntPtr hdcTarget,   // HDC
    IntPtr prcTarget,   // RECT*
    int dwFormat,   // BP_BUFFERFORMAT
    IntPtr pPaintParams,   // BP_PAINTPARAMS* optional
    IntPtr pAnimationParams,   // BP_ANIMATIONPARAMS*
    IntPtr phdcFrom,   // HDC* out
    IntPtr phdcTo   // HDC* out
);
<DllImport("UXTHEME.dll", ExactSpelling:=True)>
Public Shared Function BeginBufferedAnimation(
    hwnd As IntPtr,   ' HWND
    hdcTarget As IntPtr,   ' HDC
    prcTarget As IntPtr,   ' RECT*
    dwFormat As Integer,   ' BP_BUFFERFORMAT
    pPaintParams As IntPtr,   ' BP_PAINTPARAMS* optional
    pAnimationParams As IntPtr,   ' BP_ANIMATIONPARAMS*
    phdcFrom As IntPtr,   ' HDC* out
    phdcTo As IntPtr   ' HDC* out
) As IntPtr
End Function
' hwnd : HWND
' hdcTarget : HDC
' prcTarget : RECT*
' dwFormat : BP_BUFFERFORMAT
' pPaintParams : BP_PAINTPARAMS* optional
' pAnimationParams : BP_ANIMATIONPARAMS*
' phdcFrom : HDC* out
' phdcTo : HDC* out
Declare PtrSafe Function BeginBufferedAnimation Lib "uxtheme" ( _
    ByVal hwnd As LongPtr, _
    ByVal hdcTarget As LongPtr, _
    ByVal prcTarget As LongPtr, _
    ByVal dwFormat As Long, _
    ByVal pPaintParams As LongPtr, _
    ByVal pAnimationParams As LongPtr, _
    ByVal phdcFrom As LongPtr, _
    ByVal phdcTo As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

BeginBufferedAnimation = ctypes.windll.uxtheme.BeginBufferedAnimation
BeginBufferedAnimation.restype = ctypes.c_ssize_t
BeginBufferedAnimation.argtypes = [
    wintypes.HANDLE,  # hwnd : HWND
    wintypes.HANDLE,  # hdcTarget : HDC
    ctypes.c_void_p,  # prcTarget : RECT*
    ctypes.c_int,  # dwFormat : BP_BUFFERFORMAT
    ctypes.c_void_p,  # pPaintParams : BP_PAINTPARAMS* optional
    ctypes.c_void_p,  # pAnimationParams : BP_ANIMATIONPARAMS*
    ctypes.c_void_p,  # phdcFrom : HDC* out
    ctypes.c_void_p,  # phdcTo : HDC* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('UXTHEME.dll')
BeginBufferedAnimation = Fiddle::Function.new(
  lib['BeginBufferedAnimation'],
  [
    Fiddle::TYPE_VOIDP,  # hwnd : HWND
    Fiddle::TYPE_VOIDP,  # hdcTarget : HDC
    Fiddle::TYPE_VOIDP,  # prcTarget : RECT*
    Fiddle::TYPE_INT,  # dwFormat : BP_BUFFERFORMAT
    Fiddle::TYPE_VOIDP,  # pPaintParams : BP_PAINTPARAMS* optional
    Fiddle::TYPE_VOIDP,  # pAnimationParams : BP_ANIMATIONPARAMS*
    Fiddle::TYPE_VOIDP,  # phdcFrom : HDC* out
    Fiddle::TYPE_VOIDP,  # phdcTo : HDC* out
  ],
  Fiddle::TYPE_INTPTR_T)
#[link(name = "uxtheme")]
extern "system" {
    fn BeginBufferedAnimation(
        hwnd: *mut core::ffi::c_void,  // HWND
        hdcTarget: *mut core::ffi::c_void,  // HDC
        prcTarget: *const RECT,  // RECT*
        dwFormat: i32,  // BP_BUFFERFORMAT
        pPaintParams: *mut BP_PAINTPARAMS,  // BP_PAINTPARAMS* optional
        pAnimationParams: *mut BP_ANIMATIONPARAMS,  // BP_ANIMATIONPARAMS*
        phdcFrom: *mut *mut core::ffi::c_void,  // HDC* out
        phdcTo: *mut *mut core::ffi::c_void  // HDC* out
    ) -> isize;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("UXTHEME.dll")]
public static extern IntPtr BeginBufferedAnimation(IntPtr hwnd, IntPtr hdcTarget, IntPtr prcTarget, int dwFormat, IntPtr pPaintParams, IntPtr pAnimationParams, IntPtr phdcFrom, IntPtr phdcTo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'UXTHEME_BeginBufferedAnimation' -Namespace Win32 -PassThru
# $api::BeginBufferedAnimation(hwnd, hdcTarget, prcTarget, dwFormat, pPaintParams, pAnimationParams, phdcFrom, phdcTo)
#uselib "UXTHEME.dll"
#func global BeginBufferedAnimation "BeginBufferedAnimation" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; BeginBufferedAnimation hwnd, hdcTarget, varptr(prcTarget), dwFormat, varptr(pPaintParams), varptr(pAnimationParams), phdcFrom, phdcTo   ; 戻り値は stat
; hwnd : HWND -> "sptr"
; hdcTarget : HDC -> "sptr"
; prcTarget : RECT* -> "sptr"
; dwFormat : BP_BUFFERFORMAT -> "sptr"
; pPaintParams : BP_PAINTPARAMS* optional -> "sptr"
; pAnimationParams : BP_ANIMATIONPARAMS* -> "sptr"
; phdcFrom : HDC* out -> "sptr"
; phdcTo : HDC* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "UXTHEME.dll"
#cfunc global BeginBufferedAnimation "BeginBufferedAnimation" sptr, sptr, var, int, var, var, sptr, sptr
; res = BeginBufferedAnimation(hwnd, hdcTarget, prcTarget, dwFormat, pPaintParams, pAnimationParams, phdcFrom, phdcTo)
; hwnd : HWND -> "sptr"
; hdcTarget : HDC -> "sptr"
; prcTarget : RECT* -> "var"
; dwFormat : BP_BUFFERFORMAT -> "int"
; pPaintParams : BP_PAINTPARAMS* optional -> "var"
; pAnimationParams : BP_ANIMATIONPARAMS* -> "var"
; phdcFrom : HDC* out -> "sptr"
; phdcTo : HDC* out -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT_PTR BeginBufferedAnimation(HWND hwnd, HDC hdcTarget, RECT* prcTarget, BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS* pPaintParams, BP_ANIMATIONPARAMS* pAnimationParams, HDC* phdcFrom, HDC* phdcTo)
#uselib "UXTHEME.dll"
#cfunc global BeginBufferedAnimation "BeginBufferedAnimation" intptr, intptr, var, int, var, var, intptr, intptr
; res = BeginBufferedAnimation(hwnd, hdcTarget, prcTarget, dwFormat, pPaintParams, pAnimationParams, phdcFrom, phdcTo)
; hwnd : HWND -> "intptr"
; hdcTarget : HDC -> "intptr"
; prcTarget : RECT* -> "var"
; dwFormat : BP_BUFFERFORMAT -> "int"
; pPaintParams : BP_PAINTPARAMS* optional -> "var"
; pAnimationParams : BP_ANIMATIONPARAMS* -> "var"
; phdcFrom : HDC* out -> "intptr"
; phdcTo : HDC* out -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	uxtheme = windows.NewLazySystemDLL("UXTHEME.dll")
	procBeginBufferedAnimation = uxtheme.NewProc("BeginBufferedAnimation")
)

// hwnd (HWND), hdcTarget (HDC), prcTarget (RECT*), dwFormat (BP_BUFFERFORMAT), pPaintParams (BP_PAINTPARAMS* optional), pAnimationParams (BP_ANIMATIONPARAMS*), phdcFrom (HDC* out), phdcTo (HDC* out)
r1, _, err := procBeginBufferedAnimation.Call(
	uintptr(hwnd),
	uintptr(hdcTarget),
	uintptr(prcTarget),
	uintptr(dwFormat),
	uintptr(pPaintParams),
	uintptr(pAnimationParams),
	uintptr(phdcFrom),
	uintptr(phdcTo),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT_PTR
function BeginBufferedAnimation(
  hwnd: THandle;   // HWND
  hdcTarget: THandle;   // HDC
  prcTarget: Pointer;   // RECT*
  dwFormat: Integer;   // BP_BUFFERFORMAT
  pPaintParams: Pointer;   // BP_PAINTPARAMS* optional
  pAnimationParams: Pointer;   // BP_ANIMATIONPARAMS*
  phdcFrom: Pointer;   // HDC* out
  phdcTo: Pointer   // HDC* out
): NativeInt; stdcall;
  external 'UXTHEME.dll' name 'BeginBufferedAnimation';
result := DllCall("UXTHEME\BeginBufferedAnimation"
    , "Ptr", hwnd   ; HWND
    , "Ptr", hdcTarget   ; HDC
    , "Ptr", prcTarget   ; RECT*
    , "Int", dwFormat   ; BP_BUFFERFORMAT
    , "Ptr", pPaintParams   ; BP_PAINTPARAMS* optional
    , "Ptr", pAnimationParams   ; BP_ANIMATIONPARAMS*
    , "Ptr", phdcFrom   ; HDC* out
    , "Ptr", phdcTo   ; HDC* out
    , "Ptr")   ; return: INT_PTR
●BeginBufferedAnimation(hwnd, hdcTarget, prcTarget, dwFormat, pPaintParams, pAnimationParams, phdcFrom, phdcTo) = DLL("UXTHEME.dll", "int BeginBufferedAnimation(void*, void*, void*, int, void*, void*, void*, void*)")
# 呼び出し: BeginBufferedAnimation(hwnd, hdcTarget, prcTarget, dwFormat, pPaintParams, pAnimationParams, phdcFrom, phdcTo)
# hwnd : HWND -> "void*"
# hdcTarget : HDC -> "void*"
# prcTarget : RECT* -> "void*"
# dwFormat : BP_BUFFERFORMAT -> "int"
# pPaintParams : BP_PAINTPARAMS* optional -> "void*"
# pAnimationParams : BP_ANIMATIONPARAMS* -> "void*"
# phdcFrom : HDC* out -> "void*"
# phdcTo : HDC* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "uxtheme" fn BeginBufferedAnimation(
    hwnd: ?*anyopaque, // HWND
    hdcTarget: ?*anyopaque, // HDC
    prcTarget: [*c]RECT, // RECT*
    dwFormat: i32, // BP_BUFFERFORMAT
    pPaintParams: [*c]BP_PAINTPARAMS, // BP_PAINTPARAMS* optional
    pAnimationParams: [*c]BP_ANIMATIONPARAMS, // BP_ANIMATIONPARAMS*
    phdcFrom: ?*anyopaque, // HDC* out
    phdcTo: ?*anyopaque // HDC* out
) callconv(std.os.windows.WINAPI) isize;
proc BeginBufferedAnimation(
    hwnd: pointer,  # HWND
    hdcTarget: pointer,  # HDC
    prcTarget: ptr RECT,  # RECT*
    dwFormat: int32,  # BP_BUFFERFORMAT
    pPaintParams: ptr BP_PAINTPARAMS,  # BP_PAINTPARAMS* optional
    pAnimationParams: ptr BP_ANIMATIONPARAMS,  # BP_ANIMATIONPARAMS*
    phdcFrom: pointer,  # HDC* out
    phdcTo: pointer  # HDC* out
): int {.importc: "BeginBufferedAnimation", stdcall, dynlib: "UXTHEME.dll".}
pragma(lib, "uxtheme");
extern(Windows)
ptrdiff_t BeginBufferedAnimation(
    void* hwnd,   // HWND
    void* hdcTarget,   // HDC
    RECT* prcTarget,   // RECT*
    int dwFormat,   // BP_BUFFERFORMAT
    BP_PAINTPARAMS* pPaintParams,   // BP_PAINTPARAMS* optional
    BP_ANIMATIONPARAMS* pAnimationParams,   // BP_ANIMATIONPARAMS*
    void* phdcFrom,   // HDC* out
    void* phdcTo   // HDC* out
);
ccall((:BeginBufferedAnimation, "UXTHEME.dll"), stdcall, Int,
      (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{RECT}, Int32, Ptr{BP_PAINTPARAMS}, Ptr{BP_ANIMATIONPARAMS}, Ptr{Cvoid}, Ptr{Cvoid}),
      hwnd, hdcTarget, prcTarget, dwFormat, pPaintParams, pAnimationParams, phdcFrom, phdcTo)
# hwnd : HWND -> Ptr{Cvoid}
# hdcTarget : HDC -> Ptr{Cvoid}
# prcTarget : RECT* -> Ptr{RECT}
# dwFormat : BP_BUFFERFORMAT -> Int32
# pPaintParams : BP_PAINTPARAMS* optional -> Ptr{BP_PAINTPARAMS}
# pAnimationParams : BP_ANIMATIONPARAMS* -> Ptr{BP_ANIMATIONPARAMS}
# phdcFrom : HDC* out -> Ptr{Cvoid}
# phdcTo : HDC* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
intptr_t BeginBufferedAnimation(
    void* hwnd,
    void* hdcTarget,
    void* prcTarget,
    int32_t dwFormat,
    void* pPaintParams,
    void* pAnimationParams,
    void* phdcFrom,
    void* phdcTo);
]]
local uxtheme = ffi.load("uxtheme")
-- uxtheme.BeginBufferedAnimation(hwnd, hdcTarget, prcTarget, dwFormat, pPaintParams, pAnimationParams, phdcFrom, phdcTo)
-- hwnd : HWND
-- hdcTarget : HDC
-- prcTarget : RECT*
-- dwFormat : BP_BUFFERFORMAT
-- pPaintParams : BP_PAINTPARAMS* optional
-- pAnimationParams : BP_ANIMATIONPARAMS*
-- phdcFrom : HDC* out
-- phdcTo : HDC* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('UXTHEME.dll');
const BeginBufferedAnimation = lib.func('__stdcall', 'BeginBufferedAnimation', 'intptr_t', ['void *', 'void *', 'void *', 'int32_t', 'void *', 'void *', 'void *', 'void *']);
// BeginBufferedAnimation(hwnd, hdcTarget, prcTarget, dwFormat, pPaintParams, pAnimationParams, phdcFrom, phdcTo)
// hwnd : HWND -> 'void *'
// hdcTarget : HDC -> 'void *'
// prcTarget : RECT* -> 'void *'
// dwFormat : BP_BUFFERFORMAT -> 'int32_t'
// pPaintParams : BP_PAINTPARAMS* optional -> 'void *'
// pAnimationParams : BP_ANIMATIONPARAMS* -> 'void *'
// phdcFrom : HDC* out -> 'void *'
// phdcTo : HDC* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("UXTHEME.dll", {
  BeginBufferedAnimation: { parameters: ["pointer", "pointer", "pointer", "i32", "pointer", "pointer", "pointer", "pointer"], result: "isize" },
});
// lib.symbols.BeginBufferedAnimation(hwnd, hdcTarget, prcTarget, dwFormat, pPaintParams, pAnimationParams, phdcFrom, phdcTo)
// hwnd : HWND -> "pointer"
// hdcTarget : HDC -> "pointer"
// prcTarget : RECT* -> "pointer"
// dwFormat : BP_BUFFERFORMAT -> "i32"
// pPaintParams : BP_PAINTPARAMS* optional -> "pointer"
// pAnimationParams : BP_ANIMATIONPARAMS* -> "pointer"
// phdcFrom : HDC* out -> "pointer"
// phdcTo : HDC* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
intptr_t BeginBufferedAnimation(
    void* hwnd,
    void* hdcTarget,
    void* prcTarget,
    int32_t dwFormat,
    void* pPaintParams,
    void* pAnimationParams,
    void* phdcFrom,
    void* phdcTo);
C, "UXTHEME.dll");
// $ffi->BeginBufferedAnimation(hwnd, hdcTarget, prcTarget, dwFormat, pPaintParams, pAnimationParams, phdcFrom, phdcTo);
// hwnd : HWND
// hdcTarget : HDC
// prcTarget : RECT*
// dwFormat : BP_BUFFERFORMAT
// pPaintParams : BP_PAINTPARAMS* optional
// pAnimationParams : BP_ANIMATIONPARAMS*
// phdcFrom : HDC* out
// phdcTo : HDC* out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Uxtheme extends StdCallLibrary {
    Uxtheme INSTANCE = Native.load("uxtheme", Uxtheme.class);
    long BeginBufferedAnimation(
        Pointer hwnd,   // HWND
        Pointer hdcTarget,   // HDC
        Pointer prcTarget,   // RECT*
        int dwFormat,   // BP_BUFFERFORMAT
        Pointer pPaintParams,   // BP_PAINTPARAMS* optional
        Pointer pAnimationParams,   // BP_ANIMATIONPARAMS*
        Pointer phdcFrom,   // HDC* out
        Pointer phdcTo   // HDC* out
    );
}
@[Link("uxtheme")]
lib LibUXTHEME
  fun BeginBufferedAnimation = BeginBufferedAnimation(
    hwnd : Void*,   # HWND
    hdcTarget : Void*,   # HDC
    prcTarget : RECT*,   # RECT*
    dwFormat : Int32,   # BP_BUFFERFORMAT
    pPaintParams : BP_PAINTPARAMS*,   # BP_PAINTPARAMS* optional
    pAnimationParams : BP_ANIMATIONPARAMS*,   # BP_ANIMATIONPARAMS*
    phdcFrom : Void*,   # HDC* out
    phdcTo : Void*   # HDC* out
  ) : LibC::SSizeT
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef BeginBufferedAnimationNative = IntPtr Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Int32, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef BeginBufferedAnimationDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, int, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final BeginBufferedAnimation = DynamicLibrary.open('UXTHEME.dll')
    .lookupFunction<BeginBufferedAnimationNative, BeginBufferedAnimationDart>('BeginBufferedAnimation');
// hwnd : HWND -> Pointer<Void>
// hdcTarget : HDC -> Pointer<Void>
// prcTarget : RECT* -> Pointer<Void>
// dwFormat : BP_BUFFERFORMAT -> Int32
// pPaintParams : BP_PAINTPARAMS* optional -> Pointer<Void>
// pAnimationParams : BP_ANIMATIONPARAMS* -> Pointer<Void>
// phdcFrom : HDC* out -> Pointer<Void>
// phdcTo : HDC* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function BeginBufferedAnimation(
  hwnd: THandle;   // HWND
  hdcTarget: THandle;   // HDC
  prcTarget: Pointer;   // RECT*
  dwFormat: Integer;   // BP_BUFFERFORMAT
  pPaintParams: Pointer;   // BP_PAINTPARAMS* optional
  pAnimationParams: Pointer;   // BP_ANIMATIONPARAMS*
  phdcFrom: Pointer;   // HDC* out
  phdcTo: Pointer   // HDC* out
): NativeInt; stdcall;
  external 'UXTHEME.dll' name 'BeginBufferedAnimation';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "BeginBufferedAnimation"
  c_BeginBufferedAnimation :: Ptr () -> Ptr () -> Ptr () -> Int32 -> Ptr () -> Ptr () -> Ptr () -> Ptr () -> IO CIntPtr
-- hwnd : HWND -> Ptr ()
-- hdcTarget : HDC -> Ptr ()
-- prcTarget : RECT* -> Ptr ()
-- dwFormat : BP_BUFFERFORMAT -> Int32
-- pPaintParams : BP_PAINTPARAMS* optional -> Ptr ()
-- pAnimationParams : BP_ANIMATIONPARAMS* -> Ptr ()
-- phdcFrom : HDC* out -> Ptr ()
-- phdcTo : HDC* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let beginbufferedanimation =
  foreign "BeginBufferedAnimation"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> int32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning intptr_t)
(* hwnd : HWND -> (ptr void) *)
(* hdcTarget : HDC -> (ptr void) *)
(* prcTarget : RECT* -> (ptr void) *)
(* dwFormat : BP_BUFFERFORMAT -> int32_t *)
(* pPaintParams : BP_PAINTPARAMS* optional -> (ptr void) *)
(* pAnimationParams : BP_ANIMATIONPARAMS* -> (ptr void) *)
(* phdcFrom : HDC* out -> (ptr void) *)
(* phdcTo : HDC* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library uxtheme (t "UXTHEME.dll"))
(cffi:use-foreign-library uxtheme)

(cffi:defcfun ("BeginBufferedAnimation" begin-buffered-animation :convention :stdcall) :int64
  (hwnd :pointer)   ; HWND
  (hdc-target :pointer)   ; HDC
  (prc-target :pointer)   ; RECT*
  (dw-format :int32)   ; BP_BUFFERFORMAT
  (p-paint-params :pointer)   ; BP_PAINTPARAMS* optional
  (p-animation-params :pointer)   ; BP_ANIMATIONPARAMS*
  (phdc-from :pointer)   ; HDC* out
  (phdc-to :pointer))   ; HDC* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $BeginBufferedAnimation = Win32::API::More->new('UXTHEME',
    'LPARAM BeginBufferedAnimation(HANDLE hwnd, HANDLE hdcTarget, LPVOID prcTarget, int dwFormat, LPVOID pPaintParams, LPVOID pAnimationParams, HANDLE phdcFrom, HANDLE phdcTo)');
# my $ret = $BeginBufferedAnimation->Call($hwnd, $hdcTarget, $prcTarget, $dwFormat, $pPaintParams, $pAnimationParams, $phdcFrom, $phdcTo);
# hwnd : HWND -> HANDLE
# hdcTarget : HDC -> HANDLE
# prcTarget : RECT* -> LPVOID
# dwFormat : BP_BUFFERFORMAT -> int
# pPaintParams : BP_PAINTPARAMS* optional -> LPVOID
# pAnimationParams : BP_ANIMATIONPARAMS* -> LPVOID
# phdcFrom : HDC* out -> HANDLE
# phdcTo : HDC* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型