1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
5 * Copyright 1998, 1999 Eric Kohl
9 * I will only improve this control once in a while.
10 * Eric <ekohl@abo.rhein-zeitung.de>
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
25 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(animate);
31 /* pointer to msvideo functions. it's easier to put them here.
32 * to be correct, they should be defined on a per process basis, but
33 * this would required a per process storage. We're using a per object
34 * storage instead, which is not efficient on memory usage, but
35 * will lead to less bugs in the future
37 HIC WINAPI (*fnICOpen)(DWORD, DWORD, UINT);
38 LRESULT WINAPI (*fnICClose)(HIC);
39 LRESULT WINAPI (*fnICSendMessage)(HIC, UINT, DWORD, DWORD);
40 DWORD WINAPIV (*fnICDecompress)(HIC,DWORD,LPBITMAPINFOHEADER,LPVOID,LPBITMAPINFOHEADER,LPVOID);
42 HMMIO WINAPI (*fnmmioOpenA)(LPSTR,MMIOINFO*,DWORD);
43 MMRESULT WINAPI (*fnmmioClose)(HMMIO,UINT);
44 UINT WINAPI (*fnmmioAscend)(HMMIO,MMCKINFO*,UINT);
45 UINT WINAPI (*fnmmioDescend)(HMMIO,MMCKINFO*,const MMCKINFO*,UINT);
46 LONG WINAPI (*fnmmioSeek)(HMMIO,LONG,INT);
47 LONG WINAPI (*fnmmioRead)(HMMIO,HPSTR,LONG);
49 /* reference to input stream (file or resource) */
51 HMMIO hMMio; /* handle to mmio stream */
53 /* information on the loaded AVI file */
56 LPBITMAPINFOHEADER inbih;
58 /* data for the decompressor */
60 LPBITMAPINFOHEADER outbih;
63 /* data for the background mechanism */
67 /* data for playing the file */
74 #define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongA(hWnd, 0))
78 static void ANIMATE_Notify(ANIMATE_INFO* infoPtr, UINT notif)
80 SendMessageA(GetParent(infoPtr->hWnd), WM_COMMAND,
81 MAKEWPARAM(GetDlgCtrlID(infoPtr->hWnd), notif),
82 (LPARAM)infoPtr->hWnd);
85 static BOOL ANIMATE_LoadResA(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
91 hrsrc = FindResourceA(hInst, lpName, "AVI");
95 infoPtr->hRes = LoadResource(hInst, hrsrc);
99 lpAvi = LockResource(infoPtr->hRes);
103 memset(&mminfo, 0, sizeof(mminfo));
104 mminfo.fccIOProc = FOURCC_MEM;
105 mminfo.pchBuffer = (LPSTR)lpAvi;
106 mminfo.cchBuffer = SizeofResource(hInst, hrsrc);
107 infoPtr->hMMio = infoPtr->fnmmioOpenA(NULL, &mminfo, MMIO_READ);
109 if (!infoPtr->hMMio) {
110 GlobalFree((HGLOBAL)lpAvi);
118 static BOOL ANIMATE_LoadFileA(ANIMATE_INFO *infoPtr, LPSTR lpName)
120 infoPtr->hMMio = infoPtr->fnmmioOpenA((LPSTR)lpName, NULL,
121 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
130 static LRESULT ANIMATE_DoStop(ANIMATE_INFO *infoPtr)
132 EnterCriticalSection(&infoPtr->cs);
134 /* should stop playing */
135 if (infoPtr->hService) {
136 SERVICE_Delete(infoPtr->hService);
137 infoPtr->hService = 0;
139 if (infoPtr->uTimer) {
140 KillTimer(infoPtr->hWnd, infoPtr->uTimer);
144 LeaveCriticalSection(&infoPtr->cs);
146 ANIMATE_Notify(infoPtr, ACN_STOP);
152 static void ANIMATE_Free(ANIMATE_INFO *infoPtr)
154 if (infoPtr->hMMio) {
155 ANIMATE_DoStop(infoPtr);
156 infoPtr->fnmmioClose(infoPtr->hMMio, 0);
158 FreeResource(infoPtr->hRes);
161 if (infoPtr->lpIndex) {
162 HeapFree(GetProcessHeap(), 0, infoPtr->lpIndex);
163 infoPtr->lpIndex = NULL;
166 (infoPtr->fnICClose)(infoPtr->hic);
169 if (infoPtr->inbih) {
170 HeapFree(GetProcessHeap(), 0, infoPtr->inbih);
171 infoPtr->inbih = NULL;
173 if (infoPtr->outbih) {
174 HeapFree(GetProcessHeap(), 0, infoPtr->outbih);
175 infoPtr->outbih = NULL;
177 HeapFree(GetProcessHeap(), 0, infoPtr->indata);
178 HeapFree(GetProcessHeap(), 0, infoPtr->outdata);
179 infoPtr->indata = infoPtr->outdata = NULL;
182 memset(&infoPtr->mah, 0, sizeof(infoPtr->mah));
183 memset(&infoPtr->ash, 0, sizeof(infoPtr->ash));
184 infoPtr->nFromFrame = infoPtr->nToFrame = infoPtr->nLoop = infoPtr->currFrame = 0;
189 static LRESULT ANIMATE_PaintFrame(ANIMATE_INFO* infoPtr, HDC hDC)
191 if (!hDC || !infoPtr->inbih)
194 StretchDIBits(hDC, 0, 0, infoPtr->outbih->biWidth, infoPtr->outbih->biHeight,
195 0, 0, infoPtr->outbih->biWidth, infoPtr->outbih->biHeight,
196 infoPtr->outdata, (LPBITMAPINFO)infoPtr->outbih, DIB_RGB_COLORS,
199 StretchDIBits(hDC, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,
200 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,
201 infoPtr->indata, (LPBITMAPINFO)infoPtr->inbih, DIB_RGB_COLORS,
207 static LRESULT ANIMATE_DrawFrame(ANIMATE_INFO* infoPtr)
211 TRACE("Drawing frame %d (loop %d)\n", infoPtr->currFrame, infoPtr->nLoop);
213 EnterCriticalSection(&infoPtr->cs);
215 infoPtr->fnmmioSeek(infoPtr->hMMio, infoPtr->lpIndex[infoPtr->currFrame], SEEK_SET);
216 infoPtr->fnmmioRead(infoPtr->hMMio, infoPtr->indata, infoPtr->ash.dwSuggestedBufferSize);
219 (infoPtr->fnICDecompress)(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
220 infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
221 LeaveCriticalSection(&infoPtr->cs);
222 WARN("Decompression error\n");
226 if ((hDC = GetDC(infoPtr->hWnd)) != 0) {
227 ANIMATE_PaintFrame(infoPtr, hDC);
228 ReleaseDC(infoPtr->hWnd, hDC);
231 if (infoPtr->currFrame++ >= infoPtr->nToFrame) {
232 infoPtr->currFrame = infoPtr->nFromFrame;
233 if (infoPtr->nLoop != -1) {
234 if (--infoPtr->nLoop == 0) {
235 ANIMATE_DoStop(infoPtr);
239 LeaveCriticalSection(&infoPtr->cs);
244 static void CALLBACK ANIMATE_ServiceCallback(ULONG_PTR ptr_)
246 ANIMATE_INFO* infoPtr = (ANIMATE_INFO*)ptr_;
248 EnterCriticalSection(&infoPtr->cs);
249 ANIMATE_DrawFrame(infoPtr);
250 LeaveCriticalSection(&infoPtr->cs);
253 static LRESULT ANIMATE_Play(HWND hWnd, WPARAM wParam, LPARAM lParam)
255 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
261 if (infoPtr->hService || infoPtr->uTimer) {
262 FIXME("Already playing ? what should I do ??\n");
263 ANIMATE_DoStop(infoPtr);
266 infoPtr->nFromFrame = (INT)LOWORD(lParam);
267 infoPtr->nToFrame = (INT)HIWORD(lParam);
268 infoPtr->nLoop = (INT)wParam;
270 if (infoPtr->nToFrame == 0xFFFF)
271 infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1;
273 TRACE("(repeat=%d from=%d to=%d);\n",
274 infoPtr->nLoop, infoPtr->nFromFrame, infoPtr->nToFrame);
276 if (infoPtr->nFromFrame >= infoPtr->nToFrame ||
277 infoPtr->nToFrame >= infoPtr->mah.dwTotalFrames)
280 infoPtr->currFrame = infoPtr->nFromFrame;
282 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TIMER) {
283 TRACE("Using a timer\n");
284 /* create a timer to display AVI */
285 infoPtr->uTimer = SetTimer(hWnd, 1, infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
287 TRACE("Using the service thread\n");
289 infoPtr->hService = SERVICE_AddTimer(infoPtr->mah.dwMicroSecPerFrame / 1000,
290 ANIMATE_ServiceCallback, (DWORD)infoPtr);
293 ANIMATE_Notify(infoPtr, ACN_START);
299 static BOOL ANIMATE_GetAviInfo(ANIMATE_INFO *infoPtr)
308 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) {
309 WARN("Can't find 'RIFF' chunk\n");
313 if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
314 (ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) {
315 WARN("Can't find 'AVI ' chunk\n");
319 mmckHead.fccType = mmioFOURCC('h', 'd', 'r', 'l');
320 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
321 WARN("Can't find 'hdrl' list\n");
325 mmckInfo.ckid = mmioFOURCC('a', 'v', 'i', 'h');
326 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
327 WARN("Can't find 'avih' chunk\n");
331 infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->mah, sizeof(infoPtr->mah));
332 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr->mah.dwMicroSecPerFrame);
333 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr->mah.dwMaxBytesPerSec);
334 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr->mah.dwPaddingGranularity);
335 TRACE("mah.dwFlags=%ld\n", infoPtr->mah.dwFlags);
336 TRACE("mah.dwTotalFrames=%ld\n", infoPtr->mah.dwTotalFrames);
337 TRACE("mah.dwInitialFrames=%ld\n", infoPtr->mah.dwInitialFrames);
338 TRACE("mah.dwStreams=%ld\n", infoPtr->mah.dwStreams);
339 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr->mah.dwSuggestedBufferSize);
340 TRACE("mah.dwWidth=%ld\n", infoPtr->mah.dwWidth);
341 TRACE("mah.dwHeight=%ld\n", infoPtr->mah.dwHeight);
342 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
344 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
345 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
346 WARN("Can't find 'strl' list\n");
350 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'h');
351 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
352 WARN("Can't find 'strh' chunk\n");
356 infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->ash, sizeof(infoPtr->ash));
357 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)),
358 HIBYTE(LOWORD(infoPtr->ash.fccType)),
359 LOBYTE(HIWORD(infoPtr->ash.fccType)),
360 HIBYTE(HIWORD(infoPtr->ash.fccType)));
361 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)),
362 HIBYTE(LOWORD(infoPtr->ash.fccHandler)),
363 LOBYTE(HIWORD(infoPtr->ash.fccHandler)),
364 HIBYTE(HIWORD(infoPtr->ash.fccHandler)));
365 TRACE("ash.dwFlags=%ld\n", infoPtr->ash.dwFlags);
366 TRACE("ash.wPriority=%d\n", infoPtr->ash.wPriority);
367 TRACE("ash.wLanguage=%d\n", infoPtr->ash.wLanguage);
368 TRACE("ash.dwInitialFrames=%ld\n", infoPtr->ash.dwInitialFrames);
369 TRACE("ash.dwScale=%ld\n", infoPtr->ash.dwScale);
370 TRACE("ash.dwRate=%ld\n", infoPtr->ash.dwRate);
371 TRACE("ash.dwStart=%ld\n", infoPtr->ash.dwStart);
372 TRACE("ash.dwLength=%ld\n", infoPtr->ash.dwLength);
373 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr->ash.dwSuggestedBufferSize);
374 TRACE("ash.dwQuality=%ld\n", infoPtr->ash.dwQuality);
375 TRACE("ash.dwSampleSize=%ld\n", infoPtr->ash.dwSampleSize);
376 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left,
377 infoPtr->ash.rcFrame.bottom, infoPtr->ash.rcFrame.right);
378 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
380 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'f');
381 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
382 WARN("Can't find 'strh' chunk\n");
386 infoPtr->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
387 if (!infoPtr->inbih) {
388 WARN("Can't alloc input BIH\n");
392 infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)infoPtr->inbih, mmckInfo.cksize);
393 TRACE("bih.biSize=%ld\n", infoPtr->inbih->biSize);
394 TRACE("bih.biWidth=%ld\n", infoPtr->inbih->biWidth);
395 TRACE("bih.biHeight=%ld\n", infoPtr->inbih->biHeight);
396 TRACE("bih.biPlanes=%d\n", infoPtr->inbih->biPlanes);
397 TRACE("bih.biBitCount=%d\n", infoPtr->inbih->biBitCount);
398 TRACE("bih.biCompression=%ld\n", infoPtr->inbih->biCompression);
399 TRACE("bih.biSizeImage=%ld\n", infoPtr->inbih->biSizeImage);
400 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr->inbih->biXPelsPerMeter);
401 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr->inbih->biYPelsPerMeter);
402 TRACE("bih.biClrUsed=%ld\n", infoPtr->inbih->biClrUsed);
403 TRACE("bih.biClrImportant=%ld\n", infoPtr->inbih->biClrImportant);
404 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
406 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckList, 0);
409 /* an AVI has 0 or 1 video stream, and to be animated should not contain
410 * an audio stream, so only one strl is allowed
412 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
413 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) == 0) {
414 WARN("There should be a single 'strl' list\n");
419 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckHead, 0);
421 /* no need to read optional JUNK chunk */
423 mmckList.fccType = mmioFOURCC('m', 'o', 'v', 'i');
424 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
425 WARN("Can't find 'movi' list\n");
429 /* FIXME: should handle the 'rec ' LIST when present */
431 infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
432 infoPtr->mah.dwTotalFrames * sizeof(DWORD));
433 if (!infoPtr->lpIndex) {
434 WARN("Can't alloc index array\n");
438 numFrame = insize = 0;
439 while (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 &&
440 numFrame < infoPtr->mah.dwTotalFrames) {
441 infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset;
442 if (insize < mmckInfo.cksize)
443 insize = mmckInfo.cksize;
445 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
447 if (numFrame != infoPtr->mah.dwTotalFrames) {
448 WARN("Found %ld frames (/%ld)\n", numFrame, infoPtr->mah.dwTotalFrames);
451 if (insize > infoPtr->ash.dwSuggestedBufferSize) {
452 WARN("insize=%ld suggestedSize=%ld\n", insize, infoPtr->ash.dwSuggestedBufferSize);
453 infoPtr->ash.dwSuggestedBufferSize = insize;
456 infoPtr->indata = HeapAlloc(GetProcessHeap(), 0, infoPtr->ash.dwSuggestedBufferSize);
457 if (!infoPtr->indata) {
458 WARN("Can't alloc input buffer\n");
466 static BOOL ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
470 /* check uncompressed AVI */
471 if (infoPtr->ash.fccHandler == mmioFOURCC('D', 'I', 'B', ' ') ||
472 infoPtr->ash.fccHandler == mmioFOURCC('R', 'L', 'E', ' ')) {
477 /* try to get a decompressor for that type */
478 infoPtr->hic = (infoPtr->fnICOpen)(ICTYPE_VIDEO,
479 infoPtr->ash.fccHandler,
482 WARN("Can't load codec for the file\n");
486 outSize = (infoPtr->fnICSendMessage)(infoPtr->hic,
487 ICM_DECOMPRESS_GET_FORMAT,
488 (DWORD)infoPtr->inbih, 0L);
489 infoPtr->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
490 if (!infoPtr->outbih) {
491 WARN("Can't alloc output BIH\n");
495 if ((infoPtr->fnICSendMessage)(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
496 (DWORD)infoPtr->inbih,
497 (DWORD)infoPtr->outbih) != ICERR_OK) {
498 WARN("Can't get output BIH\n");
502 infoPtr->outdata = HeapAlloc(GetProcessHeap(), 0, infoPtr->outbih->biSizeImage);
503 if (!infoPtr->outdata) {
504 WARN("Can't alloc output buffer\n");
508 if ((infoPtr->fnICSendMessage)(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
509 (DWORD)infoPtr->inbih,
510 (DWORD)infoPtr->outbih) != ICERR_OK) {
511 WARN("Can't begin decompression\n");
518 static LRESULT ANIMATE_OpenA(HWND hWnd, WPARAM wParam, LPARAM lParam)
520 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
521 HINSTANCE hInstance = (HINSTANCE)wParam;
523 ANIMATE_Free(infoPtr);
526 TRACE("Closing avi!\n");
531 hInstance = GetWindowLongA(hWnd, GWL_HINSTANCE);
533 if (HIWORD(lParam)) {
534 TRACE("(\"%s\");\n", (LPSTR)lParam);
536 if (!ANIMATE_LoadResA(infoPtr, hInstance, (LPSTR)lParam)) {
537 TRACE("No AVI resource found!\n");
538 if (!ANIMATE_LoadFileA(infoPtr, (LPSTR)lParam)) {
539 WARN("No AVI file found!\n");
544 TRACE("(%u);\n", (WORD)LOWORD(lParam));
546 if (!ANIMATE_LoadResA(infoPtr, hInstance,
547 MAKEINTRESOURCEA((INT)lParam))) {
548 WARN("No AVI resource found!\n");
553 if (!ANIMATE_GetAviInfo(infoPtr)) {
554 WARN("Can't get AVI information\n");
555 ANIMATE_Free(infoPtr);
559 if (!ANIMATE_GetAviCodec(infoPtr)) {
560 WARN("Can't get AVI Codec\n");
561 ANIMATE_Free(infoPtr);
565 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
566 FIXME("ACS_CENTER: NIY\n");
568 /* MoveWindow(hWnd, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight, FALSE);*/
569 SetWindowPos(hWnd, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
570 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
573 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT) {
574 FIXME("ACS_TRANSPARENT: NIY\n");
577 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_AUTOPLAY) {
578 return ANIMATE_Play(hWnd, -1, (LPARAM)MAKELONG(0, infoPtr->mah.dwTotalFrames-1));
585 /* << ANIMATE_Open32W >> */
587 static LRESULT ANIMATE_Stop(HWND hWnd, WPARAM wParam, LPARAM lParam)
589 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
595 ANIMATE_DoStop(infoPtr);
600 static LRESULT ANIMATE_Create(HWND hWnd, WPARAM wParam, LPARAM lParam)
602 ANIMATE_INFO* infoPtr;
603 HMODULE hModule = LoadLibraryA("msvfw32.dll");
608 /* allocate memory for info structure */
609 infoPtr = (ANIMATE_INFO *)COMCTL32_Alloc(sizeof(ANIMATE_INFO));
611 ERR("could not allocate info memory!\n");
615 /* Temporary hack until we get dllglue up and running */
616 infoPtr->fnICOpen = (void*)GetProcAddress(hModule, "ICOpen");
617 infoPtr->fnICClose = (void*)GetProcAddress(hModule, "ICClose");
618 infoPtr->fnICSendMessage = (void*)GetProcAddress(hModule, "ICSendMessage");
619 infoPtr->fnICDecompress = (void*)GetProcAddress(hModule, "ICDecompress");
621 TRACE("Animate style=0x%08lx, parent=%08lx\n", GetWindowLongA(hWnd, GWL_STYLE), (DWORD)GetParent(hWnd));
623 /* store crossref hWnd <-> info structure */
624 SetWindowLongA(hWnd, 0, (DWORD)infoPtr);
625 infoPtr->hWnd = hWnd;
627 hModWinmm = LoadLibraryA("WINMM");
629 infoPtr->fnmmioOpenA = (void*)GetProcAddress(hModWinmm, "mmioOpenA");
630 infoPtr->fnmmioClose = (void*)GetProcAddress(hModWinmm, "mmioClose");
631 infoPtr->fnmmioAscend = (void*)GetProcAddress(hModWinmm, "mmioAscend");
632 infoPtr->fnmmioDescend = (void*)GetProcAddress(hModWinmm, "mmioDescend");
633 infoPtr->fnmmioSeek = (void*)GetProcAddress(hModWinmm, "mmioSeek");
634 infoPtr->fnmmioRead = (void*)GetProcAddress(hModWinmm, "mmioRead");
636 InitializeCriticalSection(&infoPtr->cs);
642 static LRESULT ANIMATE_Destroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
644 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
648 ANIMATE_Free(infoPtr);
650 /* free animate info data */
651 COMCTL32_Free(infoPtr);
652 SetWindowLongA(hWnd, 0, 0);
654 FreeLibrary(hModWinmm);
659 static LRESULT ANIMATE_EraseBackground(HWND hWnd, WPARAM wParam, LPARAM lParam)
663 GetClientRect(hWnd, &rect);
665 HBRUSH hBrush = CreateSolidBrush(infoPtr->clrBk);
667 FillRect((HDC)wParam, &rect, hBrush);
668 DeleteObject(hBrush);
670 FillRect((HDC)wParam, &rect, GetSysColorBrush(COLOR_WINDOW));
675 static LRESULT WINAPI ANIMATE_Size(HWND hWnd, WPARAM wParam, LPARAM lParam)
677 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
679 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
681 if (infoPtr->hMMio) {
682 /* centers the animation in the control, invalidates the control
685 InvalidateRect(hWnd, NULL, TRUE);
690 static LRESULT WINAPI ANIMATE_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
692 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hWnd, uMsg, wParam, lParam);
693 if (!ANIMATE_GetInfoPtr(hWnd) && (uMsg != WM_NCCREATE))
694 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
698 return ANIMATE_OpenA(hWnd, wParam, lParam);
700 /* case ACM_OPEN32W: FIXME!! */
701 /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
704 return ANIMATE_Play(hWnd, wParam, lParam);
707 return ANIMATE_Stop(hWnd, wParam, lParam);
710 ANIMATE_Create(hWnd, wParam, lParam);
711 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
714 return HTTRANSPARENT;
717 ANIMATE_Destroy(hWnd, wParam, lParam);
718 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
721 ANIMATE_EraseBackground(hWnd, wParam, lParam);
724 /* case WM_STYLECHANGED: FIXME shall we do something ?? */
727 return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd));
730 ANIMATE_Free(ANIMATE_GetInfoPtr(hWnd));
735 ANIMATE_PaintFrame(ANIMATE_GetInfoPtr(hWnd), (HDC)wParam);
738 HDC hDC = BeginPaint(hWnd, &ps);
739 ANIMATE_PaintFrame(ANIMATE_GetInfoPtr(hWnd), hDC);
745 ANIMATE_Size(hWnd, wParam, lParam);
746 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
750 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
752 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
758 void ANIMATE_Register(void)
762 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
763 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
764 wndClass.lpfnWndProc = (WNDPROC)ANIMATE_WindowProc;
765 wndClass.cbClsExtra = 0;
766 wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
767 wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
768 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
769 wndClass.lpszClassName = ANIMATE_CLASSA;
771 RegisterClassA(&wndClass);
775 void ANIMATE_Unregister(void)
777 UnregisterClassA(ANIMATE_CLASSA, (HINSTANCE)NULL);