Animation Control Example

To create an Animation control specify ANIMATE_CLASS as the window class or use the API function Animate_Create. To register the class set the ICC_ANIMATE_CLASS flag for the dwICC member of the INITCOMMONCONTROLSEX structure.

//Animation Control
#include <windows.h>
#include <commctrl.h>
#pragma comment(lib, "comctl32.lib")
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
MSG msg;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
wc.lpszMenuName = NULL;
wc.lpszClassName = TEXT("myWindowClass");
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&wc);

CreateWindowEx(WS_EX_CLIENTEDGE,TEXT("myWindowClass"),TEXT("Animate control"), WS_VISIBLE | WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, 340, 120, NULL, NULL, hInstance, NULL);

while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

//WndProc procedure. Application acts on messages
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
//load common control class ICC_ANIMATE_CLASS from the dynamic-link library (DLL).
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_ANIMATE_CLASS;
InitCommonControlsEx(&icex);
HWND hwndAnim = NULL;

// Create the animation control.ACS_TRANSPARENT means the AVI clip is drawn using a transparent background
hwndAnim = Animate_Create(hwnd, 1, ACS_TRANSPARENT|WS_CHILD, NULL);
SetWindowPos(hwndAnim, 0, 30, 20, 100, 60, SWP_NOZORDER | SWP_DRAWFRAME);
// Open the AVI clip, and show the animation control.
Animate_Open(hwndAnim, "file copy.AVI");
Animate_Play(hwndAnim, 0, -1, -1);

/*
To stop Animation:
Animate_Stop(hwndAnim);
To close Animation
Animate_Close(hwndAnim);
*/
ShowWindow(hwndAnim, SW_SHOW);
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}