Fixed play back of uncompressed AVI file.
[wine.git] / dlls / comctl32 / animate.c
blobe873ee2cd010c49957b96a655aa41056074ef13e
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2 /*
3 * Animation control
5 * Copyright 1998, 1999 Eric Kohl
6 * 1999 Eric Pouech
8 * NOTES
9 * I will only improve this control once in a while.
10 * Eric <ekohl@abo.rhein-zeitung.de>
12 * TODO:
13 * - check for the 'rec ' list in some AVI files
14 * - implement some missing flags (ACS_TRANSPARENT and ACS_CENTER)
15 * - protection between service thread and wndproc messages handling
16 * concurrent access to infoPtr
20 #include "winbase.h"
21 #include "commctrl.h"
22 #include "driver.h"
23 #include "animate.h"
24 #include "mmsystem.h"
25 #include "services.h"
26 #include "debugtools.h"
28 DEFAULT_DEBUG_CHANNEL(animate)
30 #define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongA(hWnd, 0))
32 static void ANIMATE_Notify(ANIMATE_INFO* infoPtr, UINT notif)
34 SendMessageA(GetParent(infoPtr->hWnd), WM_COMMAND,
35 MAKEWPARAM(GetDlgCtrlID(infoPtr->hWnd), notif),
36 (LPARAM)infoPtr->hWnd);
39 static BOOL ANIMATE_LoadResA(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
41 HRSRC hrsrc;
42 MMIOINFO mminfo;
43 LPVOID lpAvi;
45 hrsrc = FindResourceA(hInst, lpName, "AVI");
46 if (!hrsrc)
47 return FALSE;
49 infoPtr->hRes = LoadResource(hInst, hrsrc);
50 if (!infoPtr->hRes)
51 return FALSE;
53 lpAvi = LockResource(infoPtr->hRes);
54 if (!lpAvi)
55 return FALSE;
57 memset(&mminfo, 0, sizeof(mminfo));
58 mminfo.fccIOProc = FOURCC_MEM;
59 mminfo.pchBuffer = (LPSTR)lpAvi;
60 mminfo.cchBuffer = SizeofResource(hInst, hrsrc);
61 infoPtr->hMMio = mmioOpenA(NULL, &mminfo, MMIO_READ);
63 if (!infoPtr->hMMio) {
64 GlobalFree((HGLOBAL)lpAvi);
65 return FALSE;
68 return TRUE;
72 static BOOL ANIMATE_LoadFileA(ANIMATE_INFO *infoPtr, LPSTR lpName)
74 infoPtr->hMMio = mmioOpenA((LPSTR)lpName, NULL,
75 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
77 if (!infoPtr->hMMio)
78 return FALSE;
80 return TRUE;
84 static LRESULT ANIMATE_DoStop(ANIMATE_INFO *infoPtr)
86 EnterCriticalSection(&infoPtr->cs);
88 /* should stop playing */
89 if (infoPtr->hService) {
90 SERVICE_Delete(infoPtr->hService);
91 infoPtr->hService = 0;
93 if (infoPtr->uTimer) {
94 KillTimer(infoPtr->hWnd, infoPtr->uTimer);
95 infoPtr->uTimer = 0;
98 LeaveCriticalSection(&infoPtr->cs);
100 ANIMATE_Notify(infoPtr, ACN_STOP);
102 return TRUE;
106 static void ANIMATE_Free(ANIMATE_INFO *infoPtr)
108 if (infoPtr->hMMio) {
109 ANIMATE_DoStop(infoPtr);
110 mmioClose(infoPtr->hMMio, 0);
111 if (infoPtr->hRes) {
112 FreeResource(infoPtr->hRes);
113 infoPtr->hRes = 0;
115 if (infoPtr->lpIndex) {
116 HeapFree(GetProcessHeap(), 0, infoPtr->lpIndex);
117 infoPtr->lpIndex = NULL;
119 if (infoPtr->hic) {
120 (infoPtr->fnICClose)(infoPtr->hic);
121 infoPtr->hic = 0;
123 if (infoPtr->inbih) {
124 HeapFree(GetProcessHeap(), 0, infoPtr->inbih);
125 infoPtr->inbih = NULL;
127 if (infoPtr->outbih) {
128 HeapFree(GetProcessHeap(), 0, infoPtr->outbih);
129 infoPtr->outbih = NULL;
131 HeapFree(GetProcessHeap(), 0, infoPtr->indata);
132 HeapFree(GetProcessHeap(), 0, infoPtr->outdata);
133 infoPtr->indata = infoPtr->outdata = NULL;
134 infoPtr->hWnd = 0;
135 infoPtr->hMMio = 0;
136 memset(&infoPtr->mah, 0, sizeof(infoPtr->mah));
137 memset(&infoPtr->ash, 0, sizeof(infoPtr->ash));
138 infoPtr->nFromFrame = infoPtr->nToFrame = infoPtr->nLoop = infoPtr->currFrame = 0;
143 static LRESULT ANIMATE_PaintFrame(ANIMATE_INFO* infoPtr, HDC hDC)
145 if (!hDC || !infoPtr->inbih)
146 return TRUE;
147 if (infoPtr->hic)
148 StretchDIBits(hDC, 0, 0, infoPtr->outbih->biWidth, infoPtr->outbih->biHeight,
149 0, 0, infoPtr->outbih->biWidth, infoPtr->outbih->biHeight,
150 infoPtr->outdata, (LPBITMAPINFO)infoPtr->outbih, DIB_RGB_COLORS,
151 SRCCOPY);
152 else
153 StretchDIBits(hDC, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,
154 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,
155 infoPtr->indata, (LPBITMAPINFO)infoPtr->inbih, DIB_RGB_COLORS,
156 SRCCOPY);
158 return TRUE;
161 static LRESULT ANIMATE_DrawFrame(ANIMATE_INFO* infoPtr)
163 HDC hDC;
165 TRACE("Drawing frame %d (loop %d)\n", infoPtr->currFrame, infoPtr->nLoop);
167 EnterCriticalSection(&infoPtr->cs);
169 mmioSeek(infoPtr->hMMio, infoPtr->lpIndex[infoPtr->currFrame], SEEK_SET);
170 mmioRead(infoPtr->hMMio, infoPtr->indata, infoPtr->ash.dwSuggestedBufferSize);
172 if (infoPtr->hic &&
173 (infoPtr->fnICDecompress)(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
174 infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
175 LeaveCriticalSection(&infoPtr->cs);
176 WARN("Decompression error\n");
177 return FALSE;
180 if ((hDC = GetDC(infoPtr->hWnd)) != 0) {
181 ANIMATE_PaintFrame(infoPtr, hDC);
182 ReleaseDC(infoPtr->hWnd, hDC);
185 if (infoPtr->currFrame++ >= infoPtr->nToFrame) {
186 infoPtr->currFrame = infoPtr->nFromFrame;
187 if (infoPtr->nLoop != -1) {
188 if (--infoPtr->nLoop == 0) {
189 ANIMATE_DoStop(infoPtr);
193 LeaveCriticalSection(&infoPtr->cs);
195 return TRUE;
198 static void CALLBACK ANIMATE_ServiceCallback(ULONG_PTR ptr_)
200 ANIMATE_INFO* infoPtr = (ANIMATE_INFO*)ptr_;
202 EnterCriticalSection(&infoPtr->cs);
203 ANIMATE_DrawFrame(infoPtr);
204 LeaveCriticalSection(&infoPtr->cs);
207 static LRESULT ANIMATE_Play(HWND hWnd, WPARAM wParam, LPARAM lParam)
209 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
211 /* nothing opened */
212 if (!infoPtr->hMMio)
213 return FALSE;
215 if (infoPtr->hService || infoPtr->uTimer) {
216 FIXME("Already playing ? what should I do ??\n");
217 ANIMATE_DoStop(infoPtr);
220 infoPtr->nFromFrame = (INT)LOWORD(lParam);
221 infoPtr->nToFrame = (INT)HIWORD(lParam);
222 infoPtr->nLoop = (INT)wParam;
224 if (infoPtr->nToFrame == 0xFFFF)
225 infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1;
227 TRACE("(repeat=%d from=%d to=%d);\n",
228 infoPtr->nLoop, infoPtr->nFromFrame, infoPtr->nToFrame);
230 if (infoPtr->nFromFrame >= infoPtr->nToFrame ||
231 infoPtr->nToFrame >= infoPtr->mah.dwTotalFrames)
232 return FALSE;
234 infoPtr->currFrame = infoPtr->nFromFrame;
236 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TIMER) {
237 TRACE("Using a timer\n");
238 /* create a timer to display AVI */
239 infoPtr->uTimer = SetTimer(hWnd, 1, infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
240 } else {
241 TRACE("Using the service thread\n");
242 /* time is in µs */
243 infoPtr->hService = SERVICE_AddTimer(infoPtr->mah.dwMicroSecPerFrame,
244 ANIMATE_ServiceCallback, (DWORD)infoPtr);
247 ANIMATE_Notify(infoPtr, ACN_START);
249 return TRUE;
253 static BOOL ANIMATE_GetAviInfo(ANIMATE_INFO *infoPtr)
255 MMCKINFO ckMainRIFF;
256 MMCKINFO mmckHead;
257 MMCKINFO mmckList;
258 MMCKINFO mmckInfo;
259 DWORD numFrame;
260 DWORD insize;
262 if (mmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) {
263 WARN("Can't find 'RIFF' chunk\n");
264 return FALSE;
267 if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
268 (ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) {
269 WARN("Can't find 'AVI ' chunk\n");
270 return FALSE;
273 mmckHead.fccType = mmioFOURCC('h', 'd', 'r', 'l');
274 if (mmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
275 WARN("Can't find 'hdrl' list\n");
276 return FALSE;
279 mmckInfo.ckid = mmioFOURCC('a', 'v', 'i', 'h');
280 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
281 WARN("Can't find 'avih' chunk\n");
282 return FALSE;
285 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->mah, sizeof(infoPtr->mah));
286 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr->mah.dwMicroSecPerFrame);
287 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr->mah.dwMaxBytesPerSec);
288 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr->mah.dwPaddingGranularity);
289 TRACE("mah.dwFlags=%ld\n", infoPtr->mah.dwFlags);
290 TRACE("mah.dwTotalFrames=%ld\n", infoPtr->mah.dwTotalFrames);
291 TRACE("mah.dwInitialFrames=%ld\n", infoPtr->mah.dwInitialFrames);
292 TRACE("mah.dwStreams=%ld\n", infoPtr->mah.dwStreams);
293 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr->mah.dwSuggestedBufferSize);
294 TRACE("mah.dwWidth=%ld\n", infoPtr->mah.dwWidth);
295 TRACE("mah.dwHeight=%ld\n", infoPtr->mah.dwHeight);
296 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
298 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
299 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
300 WARN("Can't find 'strl' list\n");
301 return FALSE;
304 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'h');
305 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
306 WARN("Can't find 'strh' chunk\n");
307 return FALSE;
310 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->ash, sizeof(infoPtr->ash));
311 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)),
312 HIBYTE(LOWORD(infoPtr->ash.fccType)),
313 LOBYTE(HIWORD(infoPtr->ash.fccType)),
314 HIBYTE(HIWORD(infoPtr->ash.fccType)));
315 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)),
316 HIBYTE(LOWORD(infoPtr->ash.fccHandler)),
317 LOBYTE(HIWORD(infoPtr->ash.fccHandler)),
318 HIBYTE(HIWORD(infoPtr->ash.fccHandler)));
319 TRACE("ash.dwFlags=%ld\n", infoPtr->ash.dwFlags);
320 TRACE("ash.wPriority=%d\n", infoPtr->ash.wPriority);
321 TRACE("ash.wLanguage=%d\n", infoPtr->ash.wLanguage);
322 TRACE("ash.dwInitialFrames=%ld\n", infoPtr->ash.dwInitialFrames);
323 TRACE("ash.dwScale=%ld\n", infoPtr->ash.dwScale);
324 TRACE("ash.dwRate=%ld\n", infoPtr->ash.dwRate);
325 TRACE("ash.dwStart=%ld\n", infoPtr->ash.dwStart);
326 TRACE("ash.dwLength=%ld\n", infoPtr->ash.dwLength);
327 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr->ash.dwSuggestedBufferSize);
328 TRACE("ash.dwQuality=%ld\n", infoPtr->ash.dwQuality);
329 TRACE("ash.dwSampleSize=%ld\n", infoPtr->ash.dwSampleSize);
330 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left,
331 infoPtr->ash.rcFrame.bottom, infoPtr->ash.rcFrame.right);
332 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
334 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'f');
335 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
336 WARN("Can't find 'strh' chunk\n");
337 return FALSE;
340 infoPtr->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
341 if (!infoPtr->inbih) {
342 WARN("Can't alloc input BIH\n");
343 return FALSE;
346 mmioRead(infoPtr->hMMio, (LPSTR)infoPtr->inbih, mmckInfo.cksize);
347 TRACE("bih.biSize=%ld\n", infoPtr->inbih->biSize);
348 TRACE("bih.biWidth=%ld\n", infoPtr->inbih->biWidth);
349 TRACE("bih.biHeight=%ld\n", infoPtr->inbih->biHeight);
350 TRACE("bih.biPlanes=%d\n", infoPtr->inbih->biPlanes);
351 TRACE("bih.biBitCount=%d\n", infoPtr->inbih->biBitCount);
352 TRACE("bih.biCompression=%ld\n", infoPtr->inbih->biCompression);
353 TRACE("bih.biSizeImage=%ld\n", infoPtr->inbih->biSizeImage);
354 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr->inbih->biXPelsPerMeter);
355 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr->inbih->biYPelsPerMeter);
356 TRACE("bih.biClrUsed=%ld\n", infoPtr->inbih->biClrUsed);
357 TRACE("bih.biClrImportant=%ld\n", infoPtr->inbih->biClrImportant);
358 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
360 mmioAscend(infoPtr->hMMio, &mmckList, 0);
362 #if 0
363 /* an AVI has 0 or 1 video stream, and to be animated should not contain
364 * an audio stream, so only one strl is allowed
366 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
367 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) == 0) {
368 WARN("There should be a single 'strl' list\n");
369 return FALSE;
371 #endif
373 mmioAscend(infoPtr->hMMio, &mmckHead, 0);
375 /* no need to read optional JUNK chunk */
377 mmckList.fccType = mmioFOURCC('m', 'o', 'v', 'i');
378 if (mmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
379 WARN("Can't find 'movi' list\n");
380 return FALSE;
383 /* FIXME: should handle the 'rec ' LIST when present */
385 infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
386 infoPtr->mah.dwTotalFrames * sizeof(DWORD));
387 if (!infoPtr->lpIndex) {
388 WARN("Can't alloc index array\n");
389 return FALSE;
392 numFrame = insize = 0;
393 while (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 &&
394 numFrame < infoPtr->mah.dwTotalFrames) {
395 infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset;
396 if (insize < mmckInfo.cksize)
397 insize = mmckInfo.cksize;
398 numFrame++;
399 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
401 if (numFrame != infoPtr->mah.dwTotalFrames) {
402 WARN("Found %ld frames (/%ld)\n", numFrame, infoPtr->mah.dwTotalFrames);
403 return FALSE;
405 if (insize > infoPtr->ash.dwSuggestedBufferSize) {
406 WARN("insize=%ld suggestedSize=%ld\n", insize, infoPtr->ash.dwSuggestedBufferSize);
407 infoPtr->ash.dwSuggestedBufferSize = insize;
410 infoPtr->indata = HeapAlloc(GetProcessHeap(), 0, infoPtr->ash.dwSuggestedBufferSize);
411 if (!infoPtr->indata) {
412 WARN("Can't alloc input buffer\n");
413 return FALSE;
416 return TRUE;
420 static BOOL ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
422 DWORD outSize;
424 /* check uncompressed AVI */
425 if (infoPtr->ash.fccHandler == mmioFOURCC('D', 'I', 'B', ' ')) {
426 infoPtr->hic = 0;
427 return TRUE;
430 /* try to get a decompressor for that type */
431 infoPtr->hic = (infoPtr->fnICOpen)(ICTYPE_VIDEO,
432 infoPtr->ash.fccHandler,
433 ICMODE_DECOMPRESS);
434 if (!infoPtr->hic) {
435 WARN("Can't load codec for the file\n");
436 return FALSE;
439 outSize = (infoPtr->fnICSendMessage)(infoPtr->hic,
440 ICM_DECOMPRESS_GET_FORMAT,
441 (DWORD)infoPtr->inbih, 0L);
442 infoPtr->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
443 if (!infoPtr->outbih) {
444 WARN("Can't alloc output BIH\n");
445 return FALSE;
448 if ((infoPtr->fnICSendMessage)(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
449 (DWORD)infoPtr->inbih,
450 (DWORD)infoPtr->outbih) != ICERR_OK) {
451 WARN("Can't get output BIH\n");
452 return FALSE;
455 infoPtr->outdata = HeapAlloc(GetProcessHeap(), 0, infoPtr->outbih->biSizeImage);
456 if (!infoPtr->outdata) {
457 WARN("Can't alloc output buffer\n");
458 return FALSE;
461 if ((infoPtr->fnICSendMessage)(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
462 (DWORD)infoPtr->inbih,
463 (DWORD)infoPtr->outbih) != ICERR_OK) {
464 WARN("Can't begin decompression\n");
465 return FALSE;
468 return TRUE;
471 static LRESULT ANIMATE_OpenA(HWND hWnd, WPARAM wParam, LPARAM lParam)
473 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
474 HINSTANCE hInstance = (HINSTANCE)wParam;
476 ANIMATE_Free(infoPtr);
478 if (!lParam) {
479 TRACE("Closing avi!\n");
480 return TRUE;
483 if (!hInstance)
484 hInstance = GetWindowLongA(hWnd, GWL_HINSTANCE);
486 if (HIWORD(lParam)) {
487 TRACE("(\"%s\");\n", (LPSTR)lParam);
489 if (!ANIMATE_LoadResA(infoPtr, hInstance, (LPSTR)lParam)) {
490 TRACE("No AVI resource found!\n");
491 if (!ANIMATE_LoadFileA(infoPtr, (LPSTR)lParam)) {
492 WARN("No AVI file found!\n");
493 return FALSE;
496 } else {
497 TRACE("(%u);\n", (WORD)LOWORD(lParam));
499 if (!ANIMATE_LoadResA(infoPtr, hInstance,
500 MAKEINTRESOURCEA((INT)lParam))) {
501 WARN("No AVI resource found!\n");
502 return FALSE;
506 if (!ANIMATE_GetAviInfo(infoPtr)) {
507 WARN("Can't get AVI information\n");
508 ANIMATE_Free(infoPtr);
509 return FALSE;
512 if (!ANIMATE_GetAviCodec(infoPtr)) {
513 WARN("Can't get AVI Codec\n");
514 ANIMATE_Free(infoPtr);
515 return FALSE;
518 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
519 FIXME("ACS_CENTER: NIY\n");
520 } else {
521 /* MoveWindow(hWnd, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight, FALSE);*/
522 SetWindowPos(hWnd, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
523 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
526 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT) {
527 FIXME("ACS_TRANSPARENT: NIY\n");
530 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_AUTOPLAY) {
531 return ANIMATE_Play(hWnd, -1, (LPARAM)MAKELONG(0, infoPtr->mah.dwTotalFrames-1));
534 return TRUE;
538 /* << ANIMATE_Open32W >> */
540 static LRESULT ANIMATE_Stop(HWND hWnd, WPARAM wParam, LPARAM lParam)
542 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
544 /* nothing opened */
545 if (!infoPtr->hMMio)
546 return FALSE;
548 ANIMATE_DoStop(infoPtr);
549 return TRUE;
553 static LRESULT ANIMATE_Create(HWND hWnd, WPARAM wParam, LPARAM lParam)
555 ANIMATE_INFO* infoPtr;
556 HMODULE hModule = LoadLibraryA("msvfw32.dll");
558 if (!hModule)
559 return FALSE;
561 /* allocate memory for info structure */
562 infoPtr = (ANIMATE_INFO *)COMCTL32_Alloc(sizeof(ANIMATE_INFO));
563 if (!infoPtr) {
564 ERR("could not allocate info memory!\n");
565 return 0;
568 /* Temporary hack until we get dllglue up and running */
569 infoPtr->fnICOpen = (void*)GetProcAddress(hModule, "ICOpen");
570 infoPtr->fnICClose = (void*)GetProcAddress(hModule, "ICClose");
571 infoPtr->fnICSendMessage = (void*)GetProcAddress(hModule, "ICSendMessage");
572 infoPtr->fnICDecompress = (void*)GetProcAddress(hModule, "ICDecompress");
574 TRACE("Animate style=0x%08lx, parent=%08lx\n", GetWindowLongA(hWnd, GWL_STYLE), (DWORD)GetParent(hWnd));
576 /* store crossref hWnd <-> info structure */
577 SetWindowLongA(hWnd, 0, (DWORD)infoPtr);
578 infoPtr->hWnd = hWnd;
580 InitializeCriticalSection(&infoPtr->cs);
582 return 0;
586 static LRESULT ANIMATE_Destroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
588 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
591 /* free avi data */
592 ANIMATE_Free(infoPtr);
594 /* free animate info data */
595 COMCTL32_Free(infoPtr);
597 return 0;
601 static LRESULT ANIMATE_EraseBackground(HWND hWnd, WPARAM wParam, LPARAM lParam)
603 RECT rect;
605 GetClientRect(hWnd, &rect);
606 #if 0
607 HBRUSH hBrush = CreateSolidBrush(infoPtr->clrBk);
609 FillRect((HDC)wParam, &rect, hBrush);
610 DeleteObject(hBrush);
611 #else
612 FillRect((HDC)wParam, &rect, GetSysColorBrush(COLOR_WINDOW));
613 #endif
614 return TRUE;
617 static LRESULT WINAPI ANIMATE_Size(HWND hWnd, WPARAM wParam, LPARAM lParam)
619 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
621 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
622 FIXME("NIY\n");
623 if (infoPtr->hMMio) {
624 /* centers the animation in the control, invalidates the control
627 InvalidateRect(hWnd, NULL, TRUE);
629 return TRUE;
632 static LRESULT WINAPI ANIMATE_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
634 switch (uMsg)
636 case ACM_OPENA:
637 return ANIMATE_OpenA(hWnd, wParam, lParam);
639 /* case ACM_OPEN32W: FIXME!! */
640 /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
642 case ACM_PLAY:
643 return ANIMATE_Play(hWnd, wParam, lParam);
645 case ACM_STOP:
646 return ANIMATE_Stop(hWnd, wParam, lParam);
648 case WM_NCCREATE:
649 ANIMATE_Create(hWnd, wParam, lParam);
650 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
652 case WM_NCHITTEST:
653 return HTTRANSPARENT;
655 case WM_DESTROY:
656 ANIMATE_Destroy(hWnd, wParam, lParam);
657 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
659 case WM_ERASEBKGND:
660 ANIMATE_EraseBackground(hWnd, wParam, lParam);
661 break;
663 /* case WM_STYLECHANGED: FIXME shall we do something ?? */
665 case WM_TIMER:
666 return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd));
668 case WM_CLOSE:
669 ANIMATE_Free(ANIMATE_GetInfoPtr(hWnd));
670 return TRUE;
672 case WM_PAINT:
673 if (wParam) {
674 ANIMATE_PaintFrame(ANIMATE_GetInfoPtr(hWnd), (HDC)wParam);
675 } else {
676 PAINTSTRUCT ps;
677 HDC hDC = BeginPaint(hWnd, &ps);
678 ANIMATE_PaintFrame(ANIMATE_GetInfoPtr(hWnd), hDC);
679 EndPaint(hWnd, &ps);
681 break;
683 case WM_SIZE:
684 ANIMATE_Size(hWnd, wParam, lParam);
685 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
687 default:
688 if (uMsg >= WM_USER)
689 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
691 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
693 return 0;
697 void ANIMATE_Register(void)
699 WNDCLASSA wndClass;
701 if (GlobalFindAtomA(ANIMATE_CLASSA)) return;
703 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
704 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
705 wndClass.lpfnWndProc = (WNDPROC)ANIMATE_WindowProc;
706 wndClass.cbClsExtra = 0;
707 wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
708 wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
709 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
710 wndClass.lpszClassName = ANIMATE_CLASSA;
712 RegisterClassA(&wndClass);
716 void ANIMATE_Unregister(void)
718 if (GlobalFindAtomA(ANIMATE_CLASSA))
719 UnregisterClassA(ANIMATE_CLASSA, (HINSTANCE)NULL);