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.

Download and copy the filecopy.avi file in the main directory of the visual studio projectory

#include <windows.h> #include <commctrl.h> #pragma comment(lib,"comctl32.lib") #define ID_ANIMATE 1 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); static HWND hwndAnim = NULL; 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 + 1); wc.lpszMenuName = NULL; wc.lpszClassName = TEXT("myWindowClass"); wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION); RegisterClassEx(&wc); CreateWindowEx( WS_EX_CLIENTEDGE, TEXT("myWindowClass"), TEXT("Animation Control"), WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 340, 150, NULL, NULL, hInstance, NULL); while(GetMessage(&msg,NULL,0,0)>0) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CREATE: { INITCOMMONCONTROLSEX icex; // Load animation common control icex.dwSize = sizeof(INITCOMMONCONTROLSEX); icex.dwICC = ICC_ANIMATE_CLASS; InitCommonControlsEx(&icex); // Create animation control hwndAnim = CreateWindow( ANIMATE_CLASS, NULL, WS_CHILD | WS_VISIBLE | ACS_TRANSPARENT, 30, 20, 100, 60, hwnd, (HMENU)ID_ANIMATE, ((LPCREATESTRUCT)lParam)->hInstance, NULL); // Open AVI animation file Animate_Open( hwndAnim, TEXT("file copy.avi")); // Play continuously Animate_Play( hwndAnim, 0, -1, 1); break; } case WM_CLOSE: if(hwndAnim) { Animate_Stop(hwndAnim); Animate_Close(hwndAnim); } DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd,msg,wParam,lParam); } return 0; }