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 * - concurrent access to infoPtr
22 #include "debugtools.h"
24 DEFAULT_DEBUG_CHANNEL(animate);
28 /* reference to input stream (file or resource) */
30 HMMIO hMMio; /* handle to mmio stream */
32 /* information on the loaded AVI file */
35 LPBITMAPINFOHEADER inbih;
37 /* data for the decompressor */
39 LPBITMAPINFOHEADER outbih;
42 /* data for the background mechanism */
46 /* data for playing the file */
52 COLORREF transparentColor;
57 #define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongA(hWnd, 0))
58 #define ANIMATE_COLOR_NONE 0xffffffff
60 static void ANIMATE_Notify(ANIMATE_INFO* infoPtr, UINT notif)
62 SendMessageA(GetParent(infoPtr->hWnd), WM_COMMAND,
63 MAKEWPARAM(GetDlgCtrlID(infoPtr->hWnd), notif),
64 (LPARAM)infoPtr->hWnd);
67 static BOOL ANIMATE_LoadResA(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
73 hrsrc = FindResourceA(hInst, lpName, "AVI");
77 infoPtr->hRes = LoadResource(hInst, hrsrc);
81 lpAvi = LockResource(infoPtr->hRes);
85 memset(&mminfo, 0, sizeof(mminfo));
86 mminfo.fccIOProc = FOURCC_MEM;
87 mminfo.pchBuffer = (LPSTR)lpAvi;
88 mminfo.cchBuffer = SizeofResource(hInst, hrsrc);
89 infoPtr->hMMio = mmioOpenA(NULL, &mminfo, MMIO_READ);
90 if (!infoPtr->hMMio) {
91 GlobalFree((HGLOBAL)lpAvi);
99 static BOOL ANIMATE_LoadFileA(ANIMATE_INFO *infoPtr, LPSTR lpName)
101 infoPtr->hMMio = mmioOpenA((LPSTR)lpName, NULL,
102 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
111 static LRESULT ANIMATE_DoStop(ANIMATE_INFO *infoPtr)
113 EnterCriticalSection(&infoPtr->cs);
115 /* should stop playing */
116 if (infoPtr->hThread)
118 if (!TerminateThread(infoPtr->hThread,0))
119 WARN("could not destroy animation thread!\n");
120 infoPtr->hThread = 0;
122 if (infoPtr->uTimer) {
123 KillTimer(infoPtr->hWnd, infoPtr->uTimer);
127 LeaveCriticalSection(&infoPtr->cs);
129 ANIMATE_Notify(infoPtr, ACN_STOP);
135 static void ANIMATE_Free(ANIMATE_INFO *infoPtr)
137 if (infoPtr->hMMio) {
138 ANIMATE_DoStop(infoPtr);
139 mmioClose(infoPtr->hMMio, 0);
141 FreeResource(infoPtr->hRes);
144 if (infoPtr->lpIndex) {
145 HeapFree(GetProcessHeap(), 0, infoPtr->lpIndex);
146 infoPtr->lpIndex = NULL;
149 ICClose(infoPtr->hic);
152 if (infoPtr->inbih) {
153 HeapFree(GetProcessHeap(), 0, infoPtr->inbih);
154 infoPtr->inbih = NULL;
156 if (infoPtr->outbih) {
157 HeapFree(GetProcessHeap(), 0, infoPtr->outbih);
158 infoPtr->outbih = NULL;
160 if( infoPtr->indata )
162 HeapFree(GetProcessHeap(), 0, infoPtr->indata);
163 infoPtr->indata = NULL;
165 if( infoPtr->outdata )
167 HeapFree(GetProcessHeap(), 0, infoPtr->outdata);
168 infoPtr->outdata = NULL;
170 if( infoPtr->hbmPrevFrame )
172 DeleteObject(infoPtr->hbmPrevFrame);
173 infoPtr->hbmPrevFrame = 0;
175 infoPtr->indata = infoPtr->outdata = NULL;
179 memset(&infoPtr->mah, 0, sizeof(infoPtr->mah));
180 memset(&infoPtr->ash, 0, sizeof(infoPtr->ash));
181 infoPtr->nFromFrame = infoPtr->nToFrame = infoPtr->nLoop = infoPtr->currFrame = 0;
183 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
186 static void ANIMATE_TransparentBlt(ANIMATE_INFO* infoPtr, HDC hdcDest, HDC hdcSource)
192 /* create a transparency mask */
193 hdcMask = CreateCompatibleDC(hdcDest);
194 hbmMask = CreateBitmap(infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 1,1,NULL);
195 hbmOld = SelectObject(hdcMask, hbmMask);
197 SetBkColor(hdcSource,infoPtr->transparentColor);
198 BitBlt(hdcMask,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCCOPY);
200 /* mask the source bitmap */
201 SetBkColor(hdcSource, RGB(0,0,0));
202 SetTextColor(hdcSource, RGB(255,255,255));
203 BitBlt(hdcSource, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
205 /* mask the destination bitmap */
206 SetBkColor(hdcDest, RGB(255,255,255));
207 SetTextColor(hdcDest, RGB(0,0,0));
208 BitBlt(hdcDest, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
210 /* combine source and destination */
211 BitBlt(hdcDest,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCPAINT);
213 SelectObject(hdcMask, hbmOld);
214 DeleteObject(hbmMask);
218 static LRESULT ANIMATE_PaintFrame(ANIMATE_INFO* infoPtr, HDC hDC)
220 void* pBitmapData = NULL;
221 LPBITMAPINFO pBitmapInfo = NULL;
232 if (!hDC || !infoPtr->inbih)
237 pBitmapData = infoPtr->outdata;
238 pBitmapInfo = (LPBITMAPINFO)infoPtr->outbih;
240 nWidth = infoPtr->outbih->biWidth;
241 nHeight = infoPtr->outbih->biHeight;
244 pBitmapData = infoPtr->indata;
245 pBitmapInfo = (LPBITMAPINFO)infoPtr->inbih;
247 nWidth = infoPtr->inbih->biWidth;
248 nHeight = infoPtr->inbih->biHeight;
251 if(!infoPtr->hbmPrevFrame)
253 infoPtr->hbmPrevFrame=CreateCompatibleBitmap(hDC, nWidth,nHeight );
256 SetDIBits(hDC, infoPtr->hbmPrevFrame, 0, nHeight, pBitmapData, (LPBITMAPINFO)pBitmapInfo, DIB_RGB_COLORS);
258 hdcMem = CreateCompatibleDC(hDC);
259 hbmOld = SelectObject(hdcMem, infoPtr->hbmPrevFrame);
262 * we need to get the transparent color even without ACS_TRANSPARENT,
263 * because the style can be changed later on and the color should always
264 * be obtained in the first frame
266 if(infoPtr->transparentColor == ANIMATE_COLOR_NONE)
268 infoPtr->transparentColor = GetPixel(hdcMem,0,0);
271 if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT)
273 HDC hdcFinal = CreateCompatibleDC(hDC);
274 HBITMAP hbmFinal = CreateCompatibleBitmap(hDC,nWidth, nHeight);
275 HBITMAP hbmOld2 = SelectObject(hdcFinal, hbmFinal);
281 rect.bottom = nHeight;
283 if(!infoPtr->hbrushBG)
284 infoPtr->hbrushBG = GetCurrentObject(hDC, OBJ_BRUSH);
286 FillRect(hdcFinal, &rect, infoPtr->hbrushBG);
287 ANIMATE_TransparentBlt(infoPtr, hdcFinal, hdcMem);
289 SelectObject(hdcFinal, hbmOld2);
290 SelectObject(hdcMem, hbmFinal);
292 DeleteObject(infoPtr->hbmPrevFrame);
293 infoPtr->hbmPrevFrame = hbmFinal;
296 if (GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_CENTER)
300 GetWindowRect(infoPtr->hWnd, &rect);
301 nOffsetX = ((rect.right - rect.left) - nWidth)/2;
302 nOffsetY = ((rect.bottom - rect.top) - nHeight)/2;
304 BitBlt(hDC, nOffsetX, nOffsetY, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
306 SelectObject(hdcMem, hbmOld);
311 static LRESULT ANIMATE_DrawFrame(ANIMATE_INFO* infoPtr)
315 TRACE("Drawing frame %d (loop %d)\n", infoPtr->currFrame, infoPtr->nLoop);
317 EnterCriticalSection(&infoPtr->cs);
319 mmioSeek(infoPtr->hMMio, infoPtr->lpIndex[infoPtr->currFrame], SEEK_SET);
320 mmioRead(infoPtr->hMMio, infoPtr->indata, infoPtr->ash.dwSuggestedBufferSize);
323 ICDecompress(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
324 infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
325 LeaveCriticalSection(&infoPtr->cs);
326 WARN("Decompression error\n");
330 if ((hDC = GetDC(infoPtr->hWnd)) != 0) {
331 ANIMATE_PaintFrame(infoPtr, hDC);
332 ReleaseDC(infoPtr->hWnd, hDC);
335 if (infoPtr->currFrame++ >= infoPtr->nToFrame) {
336 infoPtr->currFrame = infoPtr->nFromFrame;
337 if (infoPtr->nLoop != -1) {
338 if (--infoPtr->nLoop == 0) {
339 ANIMATE_DoStop(infoPtr);
343 LeaveCriticalSection(&infoPtr->cs);
348 static DWORD CALLBACK ANIMATE_AnimationThread(LPVOID ptr_)
350 ANIMATE_INFO* infoPtr = (ANIMATE_INFO*)ptr_;
355 WARN("animation structure undefined!\n");
361 if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT)
363 hDC = GetDC(infoPtr->hWnd);
364 /* sometimes the animation window will be destroyed in between
365 * by the main program, so a ReleaseDC() error msg is possible */
366 infoPtr->hbrushBG = SendMessageA(GetParent(infoPtr->hWnd),WM_CTLCOLORSTATIC,hDC, infoPtr->hWnd);
367 ReleaseDC(infoPtr->hWnd,hDC);
370 EnterCriticalSection(&infoPtr->cs);
371 ANIMATE_DrawFrame(infoPtr);
372 LeaveCriticalSection(&infoPtr->cs);
374 /* time is in microseconds, we should convert it to milliseconds */
375 Sleep((infoPtr->mah.dwMicroSecPerFrame+500)/1000);
380 static LRESULT ANIMATE_Play(HWND hWnd, WPARAM wParam, LPARAM lParam)
382 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
388 if (infoPtr->hThread || infoPtr->uTimer) {
389 FIXME("Already playing ? what should I do ??\n");
390 ANIMATE_DoStop(infoPtr);
393 infoPtr->nFromFrame = (INT)LOWORD(lParam);
394 infoPtr->nToFrame = (INT)HIWORD(lParam);
395 infoPtr->nLoop = (INT)wParam;
397 if (infoPtr->nToFrame == 0xFFFF)
398 infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1;
400 TRACE("(repeat=%d from=%d to=%d);\n",
401 infoPtr->nLoop, infoPtr->nFromFrame, infoPtr->nToFrame);
403 if (infoPtr->nFromFrame >= infoPtr->nToFrame ||
404 infoPtr->nToFrame >= infoPtr->mah.dwTotalFrames)
407 infoPtr->currFrame = infoPtr->nFromFrame;
409 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TIMER) {
410 TRACE("Using a timer\n");
411 /* create a timer to display AVI */
412 infoPtr->uTimer = SetTimer(hWnd, 1, infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
416 TRACE("Using an animation thread\n");
417 infoPtr->hThread = CreateThread(0,0,ANIMATE_AnimationThread,(LPVOID)infoPtr,0,0 &threadID);
418 if(!infoPtr->hThread)
420 ERR("Could not create animation thread!\n");
426 ANIMATE_Notify(infoPtr, ACN_START);
432 static BOOL ANIMATE_GetAviInfo(ANIMATE_INFO *infoPtr)
441 if (mmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) {
442 WARN("Can't find 'RIFF' chunk\n");
446 if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
447 (ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) {
448 WARN("Can't find 'AVI ' chunk\n");
452 mmckHead.fccType = mmioFOURCC('h', 'd', 'r', 'l');
453 if (mmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
454 WARN("Can't find 'hdrl' list\n");
458 mmckInfo.ckid = mmioFOURCC('a', 'v', 'i', 'h');
459 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
460 WARN("Can't find 'avih' chunk\n");
464 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->mah, sizeof(infoPtr->mah));
466 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr->mah.dwMicroSecPerFrame);
467 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr->mah.dwMaxBytesPerSec);
468 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr->mah.dwPaddingGranularity);
469 TRACE("mah.dwFlags=%ld\n", infoPtr->mah.dwFlags);
470 TRACE("mah.dwTotalFrames=%ld\n", infoPtr->mah.dwTotalFrames);
471 TRACE("mah.dwInitialFrames=%ld\n", infoPtr->mah.dwInitialFrames);
472 TRACE("mah.dwStreams=%ld\n", infoPtr->mah.dwStreams);
473 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr->mah.dwSuggestedBufferSize);
474 TRACE("mah.dwWidth=%ld\n", infoPtr->mah.dwWidth);
475 TRACE("mah.dwHeight=%ld\n", infoPtr->mah.dwHeight);
477 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
479 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
480 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
481 WARN("Can't find 'strl' list\n");
485 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'h');
486 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
487 WARN("Can't find 'strh' chunk\n");
491 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->ash, sizeof(infoPtr->ash));
493 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)),
494 HIBYTE(LOWORD(infoPtr->ash.fccType)),
495 LOBYTE(HIWORD(infoPtr->ash.fccType)),
496 HIBYTE(HIWORD(infoPtr->ash.fccType)));
497 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)),
498 HIBYTE(LOWORD(infoPtr->ash.fccHandler)),
499 LOBYTE(HIWORD(infoPtr->ash.fccHandler)),
500 HIBYTE(HIWORD(infoPtr->ash.fccHandler)));
501 TRACE("ash.dwFlags=%ld\n", infoPtr->ash.dwFlags);
502 TRACE("ash.wPriority=%d\n", infoPtr->ash.wPriority);
503 TRACE("ash.wLanguage=%d\n", infoPtr->ash.wLanguage);
504 TRACE("ash.dwInitialFrames=%ld\n", infoPtr->ash.dwInitialFrames);
505 TRACE("ash.dwScale=%ld\n", infoPtr->ash.dwScale);
506 TRACE("ash.dwRate=%ld\n", infoPtr->ash.dwRate);
507 TRACE("ash.dwStart=%ld\n", infoPtr->ash.dwStart);
508 TRACE("ash.dwLength=%ld\n", infoPtr->ash.dwLength);
509 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr->ash.dwSuggestedBufferSize);
510 TRACE("ash.dwQuality=%ld\n", infoPtr->ash.dwQuality);
511 TRACE("ash.dwSampleSize=%ld\n", infoPtr->ash.dwSampleSize);
512 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left,
513 infoPtr->ash.rcFrame.bottom, infoPtr->ash.rcFrame.right);
515 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
517 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'f');
518 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
519 WARN("Can't find 'strh' chunk\n");
523 infoPtr->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
524 if (!infoPtr->inbih) {
525 WARN("Can't alloc input BIH\n");
529 mmioRead(infoPtr->hMMio, (LPSTR)infoPtr->inbih, mmckInfo.cksize);
531 TRACE("bih.biSize=%ld\n", infoPtr->inbih->biSize);
532 TRACE("bih.biWidth=%ld\n", infoPtr->inbih->biWidth);
533 TRACE("bih.biHeight=%ld\n", infoPtr->inbih->biHeight);
534 TRACE("bih.biPlanes=%d\n", infoPtr->inbih->biPlanes);
535 TRACE("bih.biBitCount=%d\n", infoPtr->inbih->biBitCount);
536 TRACE("bih.biCompression=%ld\n", infoPtr->inbih->biCompression);
537 TRACE("bih.biSizeImage=%ld\n", infoPtr->inbih->biSizeImage);
538 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr->inbih->biXPelsPerMeter);
539 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr->inbih->biYPelsPerMeter);
540 TRACE("bih.biClrUsed=%ld\n", infoPtr->inbih->biClrUsed);
541 TRACE("bih.biClrImportant=%ld\n", infoPtr->inbih->biClrImportant);
543 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
545 mmioAscend(infoPtr->hMMio, &mmckList, 0);
548 /* an AVI has 0 or 1 video stream, and to be animated should not contain
549 * an audio stream, so only one strl is allowed
551 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
552 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) == 0) {
553 WARN("There should be a single 'strl' list\n");
558 mmioAscend(infoPtr->hMMio, &mmckHead, 0);
560 /* no need to read optional JUNK chunk */
562 mmckList.fccType = mmioFOURCC('m', 'o', 'v', 'i');
563 if (mmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
564 WARN("Can't find 'movi' list\n");
568 /* FIXME: should handle the 'rec ' LIST when present */
570 infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
571 infoPtr->mah.dwTotalFrames * sizeof(DWORD));
572 if (!infoPtr->lpIndex) {
573 WARN("Can't alloc index array\n");
577 numFrame = insize = 0;
578 while (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 &&
579 numFrame < infoPtr->mah.dwTotalFrames) {
580 infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset;
581 if (insize < mmckInfo.cksize)
582 insize = mmckInfo.cksize;
584 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
586 if (numFrame != infoPtr->mah.dwTotalFrames) {
587 WARN("Found %ld frames (/%ld)\n", numFrame, infoPtr->mah.dwTotalFrames);
590 if (insize > infoPtr->ash.dwSuggestedBufferSize) {
591 WARN("insize=%ld suggestedSize=%ld\n", insize, infoPtr->ash.dwSuggestedBufferSize);
592 infoPtr->ash.dwSuggestedBufferSize = insize;
595 infoPtr->indata = HeapAlloc(GetProcessHeap(), 0, infoPtr->ash.dwSuggestedBufferSize);
596 if (!infoPtr->indata) {
597 WARN("Can't alloc input buffer\n");
605 static BOOL ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
609 /* check uncompressed AVI */
610 if ((infoPtr->ash.fccHandler == mmioFOURCC('D', 'I', 'B', ' ')) ||
611 (infoPtr->ash.fccHandler == mmioFOURCC('R', 'L', 'E', ' ')))
617 /* try to get a decompressor for that type */
618 infoPtr->hic = ICOpen(ICTYPE_VIDEO, infoPtr->ash.fccHandler, ICMODE_DECOMPRESS);
620 WARN("Can't load codec for the file\n");
624 outSize = ICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
625 (DWORD)infoPtr->inbih, 0L);
627 infoPtr->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
628 if (!infoPtr->outbih) {
629 WARN("Can't alloc output BIH\n");
633 if (ICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
634 (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != ICERR_OK) {
635 WARN("Can't get output BIH\n");
639 infoPtr->outdata = HeapAlloc(GetProcessHeap(), 0, infoPtr->outbih->biSizeImage);
640 if (!infoPtr->outdata) {
641 WARN("Can't alloc output buffer\n");
645 if (ICSendMessage(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
646 (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != ICERR_OK) {
647 WARN("Can't begin decompression\n");
654 static LRESULT ANIMATE_OpenA(HWND hWnd, WPARAM wParam, LPARAM lParam)
656 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
657 HINSTANCE hInstance = (HINSTANCE)wParam;
659 ANIMATE_Free(infoPtr);
662 TRACE("Closing avi!\n");
667 hInstance = GetWindowLongA(hWnd, GWL_HINSTANCE);
669 if (HIWORD(lParam)) {
670 TRACE("(\"%s\");\n", (LPSTR)lParam);
672 if (!ANIMATE_LoadResA(infoPtr, hInstance, (LPSTR)lParam)) {
673 TRACE("No AVI resource found!\n");
674 if (!ANIMATE_LoadFileA(infoPtr, (LPSTR)lParam)) {
675 WARN("No AVI file found!\n");
680 TRACE("(%u);\n", (WORD)LOWORD(lParam));
682 if (!ANIMATE_LoadResA(infoPtr, hInstance,
683 MAKEINTRESOURCEA((INT)lParam))) {
684 WARN("No AVI resource found!\n");
689 if (!ANIMATE_GetAviInfo(infoPtr)) {
690 WARN("Can't get AVI information\n");
691 ANIMATE_Free(infoPtr);
695 if (!ANIMATE_GetAviCodec(infoPtr)) {
696 WARN("Can't get AVI Codec\n");
697 ANIMATE_Free(infoPtr);
701 if (!GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
702 SetWindowPos(hWnd, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
703 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
706 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_AUTOPLAY) {
707 return ANIMATE_Play(hWnd, -1, (LPARAM)MAKELONG(0, infoPtr->mah.dwTotalFrames-1));
714 /* << ANIMATE_Open32W >> */
716 static LRESULT ANIMATE_Stop(HWND hWnd, WPARAM wParam, LPARAM lParam)
718 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
724 ANIMATE_DoStop(infoPtr);
729 static LRESULT ANIMATE_Create(HWND hWnd, WPARAM wParam, LPARAM lParam)
731 ANIMATE_INFO* infoPtr;
733 /* allocate memory for info structure */
734 infoPtr = (ANIMATE_INFO *)COMCTL32_Alloc(sizeof(ANIMATE_INFO));
736 ERR("could not allocate info memory!\n");
740 TRACE("Animate style=0x%08lx, parent=%08lx\n", GetWindowLongA(hWnd, GWL_STYLE), (DWORD)GetParent(hWnd));
742 /* store crossref hWnd <-> info structure */
743 SetWindowLongA(hWnd, 0, (DWORD)infoPtr);
744 infoPtr->hWnd = hWnd;
745 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
746 infoPtr->hbmPrevFrame = 0;
748 InitializeCriticalSection(&infoPtr->cs);
754 static LRESULT ANIMATE_Destroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
756 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
760 ANIMATE_Free(infoPtr);
762 /* free animate info data */
763 COMCTL32_Free(infoPtr);
764 SetWindowLongA(hWnd, 0, 0);
770 static LRESULT ANIMATE_EraseBackground(HWND hWnd, WPARAM wParam, LPARAM lParam)
775 if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
777 hBrush = SendMessageA(GetParent(hWnd),WM_CTLCOLORSTATIC,(HDC)wParam, hWnd);
780 GetClientRect(hWnd, &rect);
781 FillRect((HDC)wParam, &rect, hBrush ? hBrush : GetCurrentObject((HDC)wParam, OBJ_BRUSH));
786 static LRESULT WINAPI ANIMATE_Size(HWND hWnd, WPARAM wParam, LPARAM lParam)
788 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
789 InvalidateRect(hWnd, NULL, TRUE);
794 static LRESULT WINAPI ANIMATE_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
796 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hWnd, uMsg, wParam, lParam);
797 if (!ANIMATE_GetInfoPtr(hWnd) && (uMsg != WM_NCCREATE))
798 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
802 return ANIMATE_OpenA(hWnd, wParam, lParam);
804 /* case ACM_OPEN32W: FIXME!! */
805 /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
808 return ANIMATE_Play(hWnd, wParam, lParam);
811 return ANIMATE_Stop(hWnd, wParam, lParam);
814 ANIMATE_Create(hWnd, wParam, lParam);
815 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
818 return HTTRANSPARENT;
821 ANIMATE_Destroy(hWnd, wParam, lParam);
822 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
825 ANIMATE_EraseBackground(hWnd, wParam, lParam);
828 /* case WM_STYLECHANGED: FIXME shall we do something ?? */
831 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
833 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
834 infoPtr->hbrushBG = SendMessageA(GetParent(hWnd),WM_CTLCOLORSTATIC,(HDC)wParam, hWnd);
836 return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd));
839 ANIMATE_Free(ANIMATE_GetInfoPtr(hWnd));
844 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
846 /* the animation isn't playing, don't paint */
847 if(!infoPtr->uTimer && !infoPtr->hThread)
848 /* default paint handling */
849 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
851 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
852 infoPtr->hbrushBG = SendMessageA(GetParent(hWnd), WM_CTLCOLORSTATIC,
857 EnterCriticalSection(&infoPtr->cs);
858 ANIMATE_PaintFrame(infoPtr, (HDC)wParam);
859 LeaveCriticalSection(&infoPtr->cs);
864 HDC hDC = BeginPaint(hWnd, &ps);
866 EnterCriticalSection(&infoPtr->cs);
867 ANIMATE_PaintFrame(infoPtr, hDC);
868 LeaveCriticalSection(&infoPtr->cs);
876 ANIMATE_Size(hWnd, wParam, lParam);
877 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
881 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
883 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
889 void ANIMATE_Register(void)
893 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
894 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
895 wndClass.lpfnWndProc = (WNDPROC)ANIMATE_WindowProc;
896 wndClass.cbClsExtra = 0;
897 wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
898 wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
899 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
900 wndClass.lpszClassName = ANIMATE_CLASSA;
902 RegisterClassA(&wndClass);
906 void ANIMATE_Unregister(void)
908 UnregisterClassA(ANIMATE_CLASSA, (HINSTANCE)NULL);