1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
5 * Copyright 1998, 1999 Eric Kohl
6 * Copyright 1999 Eric Pouech
7 * Copyright 2005 Dimitrie O. Paun
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * This code was audited for completeness against the documented features
26 * of Comctl32.dll version 6.0 on Mar. 15, 2005, by Dimitrie O. Paun.
28 * Unless otherwise noted, we believe this code to be complete, as per
29 * the specification mentioned above.
30 * If you discover missing features, or bugs, please note them below.
33 * - check for the 'rec ' list in some AVI files
36 #define COM_NO_WINDOWS_H
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(animate);
54 HIC (WINAPI *fnICOpen)(DWORD, DWORD, UINT);
55 LRESULT (WINAPI *fnICClose)(HIC);
56 LRESULT (WINAPI *fnICSendMessage)(HIC, UINT, DWORD, DWORD);
57 DWORD (WINAPIV *fnICDecompress)(HIC,DWORD,LPBITMAPINFOHEADER,LPVOID,LPBITMAPINFOHEADER,LPVOID);
62 /* reference to input stream (file or resource) */
64 HMMIO hMMio; /* handle to mmio stream */
68 /* information on the loaded AVI file */
71 LPBITMAPINFOHEADER inbih;
73 /* data for the decompressor */
75 LPBITMAPINFOHEADER outbih;
78 /* data for the background mechanism */
84 /* data for playing the file */
90 COLORREF transparentColor;
95 #define ANIMATE_COLOR_NONE 0xffffffff
97 static void ANIMATE_Notify(ANIMATE_INFO *infoPtr, UINT notif)
99 SendMessageW(infoPtr->hwndNotify, WM_COMMAND,
100 MAKEWPARAM(GetDlgCtrlID(infoPtr->hwndSelf), notif),
101 (LPARAM)infoPtr->hwndSelf);
104 static BOOL ANIMATE_LoadResW(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPWSTR lpName)
106 static const WCHAR aviW[] = { 'A', 'V', 'I', 0 };
111 hrsrc = FindResourceW(hInst, lpName, aviW);
115 infoPtr->hRes = LoadResource(hInst, hrsrc);
119 lpAvi = LockResource(infoPtr->hRes);
123 memset(&mminfo, 0, sizeof(mminfo));
124 mminfo.fccIOProc = FOURCC_MEM;
125 mminfo.pchBuffer = (LPSTR)lpAvi;
126 mminfo.cchBuffer = SizeofResource(hInst, hrsrc);
127 infoPtr->hMMio = mmioOpenW(NULL, &mminfo, MMIO_READ);
130 FreeResource(infoPtr->hRes);
138 static BOOL ANIMATE_LoadFileW(ANIMATE_INFO *infoPtr, LPWSTR lpName)
140 infoPtr->hMMio = mmioOpenW(lpName, 0, MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
142 return (BOOL)infoPtr->hMMio;
146 static BOOL ANIMATE_DoStop(ANIMATE_INFO *infoPtr)
148 EnterCriticalSection(&infoPtr->cs);
150 /* should stop playing */
151 if (infoPtr->hThread)
153 HANDLE handle = infoPtr->hThread;
155 TRACE("stopping animation thread\n");
156 infoPtr->hThread = 0;
157 SetEvent( infoPtr->hStopEvent );
159 if (infoPtr->threadId != GetCurrentThreadId())
161 LeaveCriticalSection(&infoPtr->cs); /* leave it a chance to run */
162 WaitForSingleObject( handle, INFINITE );
163 TRACE("animation thread stopped\n");
164 EnterCriticalSection(&infoPtr->cs);
167 CloseHandle( handle );
168 CloseHandle( infoPtr->hStopEvent );
169 infoPtr->hStopEvent = 0;
171 if (infoPtr->uTimer) {
172 KillTimer(infoPtr->hwndSelf, infoPtr->uTimer);
176 LeaveCriticalSection(&infoPtr->cs);
178 ANIMATE_Notify(infoPtr, ACN_STOP);
184 static void ANIMATE_Free(ANIMATE_INFO *infoPtr)
186 if (infoPtr->hMMio) {
187 ANIMATE_DoStop(infoPtr);
188 mmioClose(infoPtr->hMMio, 0);
190 FreeResource(infoPtr->hRes);
193 HeapFree(GetProcessHeap(), 0, infoPtr->lpIndex);
194 infoPtr->lpIndex = NULL;
196 fnIC.fnICClose(infoPtr->hic);
199 HeapFree(GetProcessHeap(), 0, infoPtr->inbih);
200 infoPtr->inbih = NULL;
201 HeapFree(GetProcessHeap(), 0, infoPtr->outbih);
202 infoPtr->outbih = NULL;
203 HeapFree(GetProcessHeap(), 0, infoPtr->indata);
204 infoPtr->indata = NULL;
205 HeapFree(GetProcessHeap(), 0, infoPtr->outdata);
206 infoPtr->outdata = NULL;
207 if( infoPtr->hbmPrevFrame )
209 DeleteObject(infoPtr->hbmPrevFrame);
210 infoPtr->hbmPrevFrame = 0;
213 memset(&infoPtr->mah, 0, sizeof(infoPtr->mah));
214 memset(&infoPtr->ash, 0, sizeof(infoPtr->ash));
215 infoPtr->nFromFrame = infoPtr->nToFrame = infoPtr->nLoop = infoPtr->currFrame = 0;
217 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
220 static void ANIMATE_TransparentBlt(ANIMATE_INFO *infoPtr, HDC hdcDest, HDC hdcSource)
226 /* create a transparency mask */
227 hdcMask = CreateCompatibleDC(hdcDest);
228 hbmMask = CreateBitmap(infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 1,1,NULL);
229 hbmOld = SelectObject(hdcMask, hbmMask);
231 SetBkColor(hdcSource,infoPtr->transparentColor);
232 BitBlt(hdcMask,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCCOPY);
234 /* mask the source bitmap */
235 SetBkColor(hdcSource, RGB(0,0,0));
236 SetTextColor(hdcSource, RGB(255,255,255));
237 BitBlt(hdcSource, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
239 /* mask the destination bitmap */
240 SetBkColor(hdcDest, RGB(255,255,255));
241 SetTextColor(hdcDest, RGB(0,0,0));
242 BitBlt(hdcDest, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
244 /* combine source and destination */
245 BitBlt(hdcDest,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCPAINT);
247 SelectObject(hdcMask, hbmOld);
248 DeleteObject(hbmMask);
252 static BOOL ANIMATE_PaintFrame(ANIMATE_INFO* infoPtr, HDC hDC)
254 void* pBitmapData = NULL;
255 LPBITMAPINFO pBitmapInfo = NULL;
266 if (!hDC || !infoPtr->inbih)
269 if (infoPtr->dwStyle & ACS_TRANSPARENT)
270 infoPtr->hbrushBG = (HBRUSH)SendMessageW(infoPtr->hwndNotify, WM_CTLCOLORSTATIC,
271 (WPARAM)hDC, (LPARAM)infoPtr->hwndSelf);
275 pBitmapData = infoPtr->outdata;
276 pBitmapInfo = (LPBITMAPINFO)infoPtr->outbih;
278 nWidth = infoPtr->outbih->biWidth;
279 nHeight = infoPtr->outbih->biHeight;
283 pBitmapData = infoPtr->indata;
284 pBitmapInfo = (LPBITMAPINFO)infoPtr->inbih;
286 nWidth = infoPtr->inbih->biWidth;
287 nHeight = infoPtr->inbih->biHeight;
290 if(!infoPtr->hbmPrevFrame)
292 infoPtr->hbmPrevFrame=CreateCompatibleBitmap(hDC, nWidth,nHeight );
295 SetDIBits(hDC, infoPtr->hbmPrevFrame, 0, nHeight, pBitmapData, (LPBITMAPINFO)pBitmapInfo, DIB_RGB_COLORS);
297 hdcMem = CreateCompatibleDC(hDC);
298 hbmOld = SelectObject(hdcMem, infoPtr->hbmPrevFrame);
301 * we need to get the transparent color even without ACS_TRANSPARENT,
302 * because the style can be changed later on and the color should always
303 * be obtained in the first frame
305 if(infoPtr->transparentColor == ANIMATE_COLOR_NONE)
307 infoPtr->transparentColor = GetPixel(hdcMem,0,0);
310 if(infoPtr->dwStyle & ACS_TRANSPARENT)
312 HDC hdcFinal = CreateCompatibleDC(hDC);
313 HBITMAP hbmFinal = CreateCompatibleBitmap(hDC,nWidth, nHeight);
314 HBITMAP hbmOld2 = SelectObject(hdcFinal, hbmFinal);
320 rect.bottom = nHeight;
322 if(!infoPtr->hbrushBG)
323 infoPtr->hbrushBG = GetCurrentObject(hDC, OBJ_BRUSH);
325 FillRect(hdcFinal, &rect, infoPtr->hbrushBG);
326 ANIMATE_TransparentBlt(infoPtr, hdcFinal, hdcMem);
328 SelectObject(hdcFinal, hbmOld2);
329 SelectObject(hdcMem, hbmFinal);
331 DeleteObject(infoPtr->hbmPrevFrame);
332 infoPtr->hbmPrevFrame = hbmFinal;
335 if (infoPtr->dwStyle & ACS_CENTER)
339 GetWindowRect(infoPtr->hwndSelf, &rect);
340 nOffsetX = ((rect.right - rect.left) - nWidth)/2;
341 nOffsetY = ((rect.bottom - rect.top) - nHeight)/2;
343 BitBlt(hDC, nOffsetX, nOffsetY, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
345 SelectObject(hdcMem, hbmOld);
350 static BOOL ANIMATE_DrawFrame(ANIMATE_INFO *infoPtr)
354 TRACE("Drawing frame %d (loop %d)\n", infoPtr->currFrame, infoPtr->nLoop);
356 EnterCriticalSection(&infoPtr->cs);
358 mmioSeek(infoPtr->hMMio, infoPtr->lpIndex[infoPtr->currFrame], SEEK_SET);
359 mmioRead(infoPtr->hMMio, infoPtr->indata, infoPtr->ash.dwSuggestedBufferSize);
362 fnIC.fnICDecompress(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
363 infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
364 LeaveCriticalSection(&infoPtr->cs);
365 WARN("Decompression error\n");
369 if ((hDC = GetDC(infoPtr->hwndSelf)) != 0) {
370 ANIMATE_PaintFrame(infoPtr, hDC);
371 ReleaseDC(infoPtr->hwndSelf, hDC);
374 if (infoPtr->currFrame++ >= infoPtr->nToFrame) {
375 infoPtr->currFrame = infoPtr->nFromFrame;
376 if (infoPtr->nLoop != -1) {
377 if (--infoPtr->nLoop == 0) {
378 ANIMATE_DoStop(infoPtr);
382 LeaveCriticalSection(&infoPtr->cs);
387 static LRESULT ANIMATE_Paint(ANIMATE_INFO *infoPtr, HDC hdc)
392 if (!hdc) hDC = BeginPaint(infoPtr->hwndSelf, &ps);
394 EnterCriticalSection(&infoPtr->cs);
395 ANIMATE_PaintFrame(infoPtr, hDC);
396 LeaveCriticalSection(&infoPtr->cs);
398 if (!hdc) EndPaint(infoPtr->hwndSelf, &ps);
403 static DWORD CALLBACK ANIMATE_AnimationThread(LPVOID ptr_)
405 ANIMATE_INFO *infoPtr = (ANIMATE_INFO *)ptr_;
411 EnterCriticalSection(&infoPtr->cs);
412 ANIMATE_DrawFrame(infoPtr);
413 timeout = infoPtr->mah.dwMicroSecPerFrame;
414 event = infoPtr->hStopEvent;
415 LeaveCriticalSection(&infoPtr->cs);
417 /* time is in microseconds, we should convert it to milliseconds */
418 if ((event == 0) || WaitForSingleObject( event, (timeout+500)/1000) == WAIT_OBJECT_0)
424 static LRESULT ANIMATE_Play(ANIMATE_INFO *infoPtr, UINT cRepeat, WORD wFrom, WORD wTo)
430 if (infoPtr->hThread || infoPtr->uTimer) {
431 TRACE("Already playing\n");
435 infoPtr->nFromFrame = wFrom;
436 infoPtr->nToFrame = wTo;
437 infoPtr->nLoop = cRepeat;
439 if (infoPtr->nToFrame == 0xFFFF)
440 infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1;
442 TRACE("(repeat=%d from=%d to=%d);\n",
443 infoPtr->nLoop, infoPtr->nFromFrame, infoPtr->nToFrame);
445 if (infoPtr->nFromFrame >= infoPtr->nToFrame ||
446 infoPtr->nToFrame >= infoPtr->mah.dwTotalFrames)
449 infoPtr->currFrame = infoPtr->nFromFrame;
451 if (infoPtr->dwStyle & ACS_TIMER)
453 TRACE("Using a timer\n");
454 /* create a timer to display AVI */
455 infoPtr->uTimer = SetTimer(infoPtr->hwndSelf, 1,
456 infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
460 TRACE("Using an animation thread\n");
461 infoPtr->hStopEvent = CreateEventW( NULL, TRUE, FALSE, NULL );
462 infoPtr->hThread = CreateThread(0, 0, ANIMATE_AnimationThread,
463 (LPVOID)infoPtr, 0, &infoPtr->threadId);
464 if(!infoPtr->hThread) return FALSE;
468 ANIMATE_Notify(infoPtr, ACN_START);
474 static BOOL ANIMATE_GetAviInfo(ANIMATE_INFO *infoPtr)
483 if (mmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) {
484 WARN("Can't find 'RIFF' chunk\n");
488 if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
489 (ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) {
490 WARN("Can't find 'AVI ' chunk\n");
494 mmckHead.fccType = mmioFOURCC('h', 'd', 'r', 'l');
495 if (mmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
496 WARN("Can't find 'hdrl' list\n");
500 mmckInfo.ckid = mmioFOURCC('a', 'v', 'i', 'h');
501 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
502 WARN("Can't find 'avih' chunk\n");
506 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->mah, sizeof(infoPtr->mah));
508 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr->mah.dwMicroSecPerFrame);
509 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr->mah.dwMaxBytesPerSec);
510 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr->mah.dwPaddingGranularity);
511 TRACE("mah.dwFlags=%ld\n", infoPtr->mah.dwFlags);
512 TRACE("mah.dwTotalFrames=%ld\n", infoPtr->mah.dwTotalFrames);
513 TRACE("mah.dwInitialFrames=%ld\n", infoPtr->mah.dwInitialFrames);
514 TRACE("mah.dwStreams=%ld\n", infoPtr->mah.dwStreams);
515 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr->mah.dwSuggestedBufferSize);
516 TRACE("mah.dwWidth=%ld\n", infoPtr->mah.dwWidth);
517 TRACE("mah.dwHeight=%ld\n", infoPtr->mah.dwHeight);
519 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
521 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
522 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
523 WARN("Can't find 'strl' list\n");
527 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'h');
528 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
529 WARN("Can't find 'strh' chunk\n");
533 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->ash, sizeof(infoPtr->ash));
535 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)),
536 HIBYTE(LOWORD(infoPtr->ash.fccType)),
537 LOBYTE(HIWORD(infoPtr->ash.fccType)),
538 HIBYTE(HIWORD(infoPtr->ash.fccType)));
539 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)),
540 HIBYTE(LOWORD(infoPtr->ash.fccHandler)),
541 LOBYTE(HIWORD(infoPtr->ash.fccHandler)),
542 HIBYTE(HIWORD(infoPtr->ash.fccHandler)));
543 TRACE("ash.dwFlags=%ld\n", infoPtr->ash.dwFlags);
544 TRACE("ash.wPriority=%d\n", infoPtr->ash.wPriority);
545 TRACE("ash.wLanguage=%d\n", infoPtr->ash.wLanguage);
546 TRACE("ash.dwInitialFrames=%ld\n", infoPtr->ash.dwInitialFrames);
547 TRACE("ash.dwScale=%ld\n", infoPtr->ash.dwScale);
548 TRACE("ash.dwRate=%ld\n", infoPtr->ash.dwRate);
549 TRACE("ash.dwStart=%ld\n", infoPtr->ash.dwStart);
550 TRACE("ash.dwLength=%ld\n", infoPtr->ash.dwLength);
551 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr->ash.dwSuggestedBufferSize);
552 TRACE("ash.dwQuality=%ld\n", infoPtr->ash.dwQuality);
553 TRACE("ash.dwSampleSize=%ld\n", infoPtr->ash.dwSampleSize);
554 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left,
555 infoPtr->ash.rcFrame.bottom, infoPtr->ash.rcFrame.right);
557 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
559 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'f');
560 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
561 WARN("Can't find 'strh' chunk\n");
565 infoPtr->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
566 if (!infoPtr->inbih) {
567 WARN("Can't alloc input BIH\n");
571 mmioRead(infoPtr->hMMio, (LPSTR)infoPtr->inbih, mmckInfo.cksize);
573 TRACE("bih.biSize=%ld\n", infoPtr->inbih->biSize);
574 TRACE("bih.biWidth=%ld\n", infoPtr->inbih->biWidth);
575 TRACE("bih.biHeight=%ld\n", infoPtr->inbih->biHeight);
576 TRACE("bih.biPlanes=%d\n", infoPtr->inbih->biPlanes);
577 TRACE("bih.biBitCount=%d\n", infoPtr->inbih->biBitCount);
578 TRACE("bih.biCompression=%ld\n", infoPtr->inbih->biCompression);
579 TRACE("bih.biSizeImage=%ld\n", infoPtr->inbih->biSizeImage);
580 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr->inbih->biXPelsPerMeter);
581 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr->inbih->biYPelsPerMeter);
582 TRACE("bih.biClrUsed=%ld\n", infoPtr->inbih->biClrUsed);
583 TRACE("bih.biClrImportant=%ld\n", infoPtr->inbih->biClrImportant);
585 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
587 mmioAscend(infoPtr->hMMio, &mmckList, 0);
590 /* an AVI has 0 or 1 video stream, and to be animated should not contain
591 * an audio stream, so only one strl is allowed
593 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
594 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) == 0) {
595 WARN("There should be a single 'strl' list\n");
600 mmioAscend(infoPtr->hMMio, &mmckHead, 0);
602 /* no need to read optional JUNK chunk */
604 mmckList.fccType = mmioFOURCC('m', 'o', 'v', 'i');
605 if (mmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
606 WARN("Can't find 'movi' list\n");
610 /* FIXME: should handle the 'rec ' LIST when present */
612 infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
613 infoPtr->mah.dwTotalFrames * sizeof(DWORD));
614 if (!infoPtr->lpIndex)
617 numFrame = insize = 0;
618 while (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 &&
619 numFrame < infoPtr->mah.dwTotalFrames) {
620 infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset;
621 if (insize < mmckInfo.cksize)
622 insize = mmckInfo.cksize;
624 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
626 if (numFrame != infoPtr->mah.dwTotalFrames) {
627 WARN("Found %ld frames (/%ld)\n", numFrame, infoPtr->mah.dwTotalFrames);
630 if (insize > infoPtr->ash.dwSuggestedBufferSize) {
631 WARN("insize=%ld suggestedSize=%ld\n", insize, infoPtr->ash.dwSuggestedBufferSize);
632 infoPtr->ash.dwSuggestedBufferSize = insize;
635 infoPtr->indata = HeapAlloc(GetProcessHeap(), 0, infoPtr->ash.dwSuggestedBufferSize);
636 if (!infoPtr->indata)
643 static BOOL ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
647 /* check uncompressed AVI */
648 if ((infoPtr->ash.fccHandler == mmioFOURCC('D', 'I', 'B', ' ')) ||
649 (infoPtr->ash.fccHandler == mmioFOURCC('R', 'L', 'E', ' ')) ||
650 (infoPtr->ash.fccHandler == mmioFOURCC(0, 0, 0, 0)))
656 /* try to get a decompressor for that type */
657 infoPtr->hic = fnIC.fnICOpen(ICTYPE_VIDEO, infoPtr->ash.fccHandler, ICMODE_DECOMPRESS);
659 WARN("Can't load codec for the file\n");
663 outSize = fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
664 (DWORD)infoPtr->inbih, 0L);
666 infoPtr->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
667 if (!infoPtr->outbih)
670 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
671 (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != outSize)
673 WARN("Can't get output BIH\n");
677 infoPtr->outdata = HeapAlloc(GetProcessHeap(), 0, infoPtr->outbih->biSizeImage);
678 if (!infoPtr->outdata)
681 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
682 (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != ICERR_OK) {
683 WARN("Can't begin decompression\n");
691 static BOOL ANIMATE_OpenW(ANIMATE_INFO *infoPtr, HINSTANCE hInstance, LPWSTR lpszName)
693 ANIMATE_Free(infoPtr);
697 TRACE("Closing avi!\n");
698 /* installer of thebat! v1.62 requires FALSE here */
699 return (infoPtr->hMMio != 0);
703 hInstance = (HINSTANCE)GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_HINSTANCE);
705 if (HIWORD(lpszName))
707 TRACE("(\"%s\");\n", debugstr_w(lpszName));
709 if (!ANIMATE_LoadResW(infoPtr, hInstance, lpszName))
711 TRACE("No AVI resource found!\n");
712 if (!ANIMATE_LoadFileW(infoPtr, lpszName))
714 WARN("No AVI file found!\n");
721 TRACE("(%u);\n", (WORD)(DWORD)lpszName);
723 if (!ANIMATE_LoadResW(infoPtr, hInstance, MAKEINTRESOURCEW((INT)lpszName)))
725 WARN("No AVI resource found!\n");
730 if (!ANIMATE_GetAviInfo(infoPtr))
732 WARN("Can't get AVI information\n");
733 ANIMATE_Free(infoPtr);
737 if (!ANIMATE_GetAviCodec(infoPtr))
739 WARN("Can't get AVI Codec\n");
740 ANIMATE_Free(infoPtr);
744 if (!(infoPtr->dwStyle & ACS_CENTER))
745 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
746 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
748 if (infoPtr->dwStyle & ACS_AUTOPLAY)
749 return ANIMATE_Play(infoPtr, -1, 0, infoPtr->mah.dwTotalFrames - 1);
755 static BOOL ANIMATE_OpenA(ANIMATE_INFO *infoPtr, HINSTANCE hInstance, LPSTR lpszName)
761 if (!HIWORD(lpszName))
762 return ANIMATE_OpenW(infoPtr, hInstance, (LPWSTR)lpszName);
764 len = MultiByteToWideChar(CP_ACP, 0, lpszName, -1, NULL, 0);
765 lpwszName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
766 if (!lpwszName) return FALSE;
767 MultiByteToWideChar(CP_ACP, 0, lpszName, -1, lpwszName, len);
769 result = ANIMATE_OpenW(infoPtr, hInstance, lpwszName);
770 HeapFree(GetProcessHeap(), 0, lpwszName);
775 static BOOL ANIMATE_Stop(ANIMATE_INFO *infoPtr)
781 ANIMATE_DoStop(infoPtr);
786 static BOOL ANIMATE_Create(HWND hWnd, LPCREATESTRUCTW lpcs)
788 static const WCHAR msvfw32W[] = { 'm', 's', 'v', 'f', 'w', '3', '2', '.', 'd', 'l', 'l', 0 };
789 ANIMATE_INFO *infoPtr;
793 fnIC.hModule = LoadLibraryW(msvfw32W);
794 if (!fnIC.hModule) return FALSE;
796 fnIC.fnICOpen = (void*)GetProcAddress(fnIC.hModule, "ICOpen");
797 fnIC.fnICClose = (void*)GetProcAddress(fnIC.hModule, "ICClose");
798 fnIC.fnICSendMessage = (void*)GetProcAddress(fnIC.hModule, "ICSendMessage");
799 fnIC.fnICDecompress = (void*)GetProcAddress(fnIC.hModule, "ICDecompress");
802 /* allocate memory for info structure */
803 infoPtr = (ANIMATE_INFO *)Alloc(sizeof(ANIMATE_INFO));
804 if (!infoPtr) return FALSE;
806 /* store crossref hWnd <-> info structure */
807 SetWindowLongPtrW(hWnd, 0, (DWORD_PTR)infoPtr);
808 infoPtr->hwndSelf = hWnd;
809 infoPtr->hwndNotify = lpcs->hwndParent;
810 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
811 infoPtr->hbmPrevFrame = 0;
812 infoPtr->dwStyle = lpcs->style;
814 TRACE("Animate style=0x%08lx, parent=%p\n", infoPtr->dwStyle, infoPtr->hwndNotify);
816 InitializeCriticalSection(&infoPtr->cs);
822 static LRESULT ANIMATE_Destroy(ANIMATE_INFO *infoPtr)
825 ANIMATE_Free(infoPtr);
827 /* free animate info data */
828 SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
835 static BOOL ANIMATE_EraseBackground(ANIMATE_INFO *infoPtr, HDC hdc)
840 if(infoPtr->dwStyle & ACS_TRANSPARENT)
842 hBrush = (HBRUSH)SendMessageW(infoPtr->hwndNotify, WM_CTLCOLORSTATIC,
843 (WPARAM)hdc, (LPARAM)infoPtr->hwndSelf);
846 GetClientRect(infoPtr->hwndSelf, &rect);
847 FillRect(hdc, &rect, hBrush ? hBrush : GetCurrentObject(hdc, OBJ_BRUSH));
853 static LRESULT ANIMATE_StyleChanged(ANIMATE_INFO *infoPtr, WPARAM wStyleType, LPSTYLESTRUCT lpss)
855 TRACE("(styletype=%x, styleOld=0x%08lx, styleNew=0x%08lx)\n",
856 wStyleType, lpss->styleOld, lpss->styleNew);
858 if (wStyleType != GWL_STYLE) return 0;
860 infoPtr->dwStyle = lpss->styleNew;
862 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
867 static LRESULT WINAPI ANIMATE_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
869 ANIMATE_INFO *infoPtr = (ANIMATE_INFO *)GetWindowLongPtrW(hWnd, 0);
871 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hWnd, uMsg, wParam, lParam);
872 if (!infoPtr && (uMsg != WM_NCCREATE))
873 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
877 return ANIMATE_OpenA(infoPtr, (HINSTANCE)wParam, (LPSTR)lParam);
880 return ANIMATE_OpenW(infoPtr, (HINSTANCE)wParam, (LPWSTR)lParam);
883 return ANIMATE_Play(infoPtr, (INT)wParam, LOWORD(lParam), HIWORD(lParam));
886 return ANIMATE_Stop(infoPtr);
889 ANIMATE_Free(infoPtr);
893 return ANIMATE_Create(hWnd, (LPCREATESTRUCTW)lParam);
896 return HTTRANSPARENT;
899 return ANIMATE_Destroy(infoPtr);
902 return ANIMATE_EraseBackground(infoPtr, (HDC)wParam);
904 case WM_STYLECHANGED:
905 return ANIMATE_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
908 return ANIMATE_DrawFrame(infoPtr);
911 /* the animation isn't playing, or has not decompressed
912 * (and displayed) the first frame yet, do default painting
914 if ((!infoPtr->uTimer && !infoPtr->hThread) || !infoPtr->hbmPrevFrame)
915 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
917 return ANIMATE_Paint(infoPtr, (HDC)wParam);
920 if (infoPtr->dwStyle & ACS_CENTER)
921 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
922 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
925 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
926 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
928 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
933 void ANIMATE_Register(void)
937 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
938 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
939 wndClass.lpfnWndProc = ANIMATE_WindowProc;
940 wndClass.cbClsExtra = 0;
941 wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
942 wndClass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
943 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
944 wndClass.lpszClassName = ANIMATE_CLASSW;
946 RegisterClassW(&wndClass);
950 void ANIMATE_Unregister(void)
952 UnregisterClassW(ANIMATE_CLASSW, NULL);