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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(animate
);
53 HIC (WINAPI
*fnICOpen
)(DWORD
, DWORD
, UINT
);
54 LRESULT (WINAPI
*fnICClose
)(HIC
);
55 LRESULT (WINAPI
*fnICSendMessage
)(HIC
, UINT
, DWORD_PTR
, DWORD_PTR
);
56 DWORD (WINAPIV
*fnICDecompress
)(HIC
,DWORD
,LPBITMAPINFOHEADER
,LPVOID
,LPBITMAPINFOHEADER
,LPVOID
);
61 /* reference to input stream (file or resource) */
63 HMMIO hMMio
; /* handle to mmio stream */
67 /* information on the loaded AVI file */
70 LPBITMAPINFOHEADER inbih
;
72 /* data for the decompressor */
74 LPBITMAPINFOHEADER outbih
;
77 /* data for the background mechanism */
83 /* data for playing the file */
89 COLORREF transparentColor
;
94 #define ANIMATE_COLOR_NONE 0xffffffff
96 static void ANIMATE_Notify(const ANIMATE_INFO
*infoPtr
, UINT notif
)
98 SendMessageW(infoPtr
->hwndNotify
, WM_COMMAND
,
99 MAKEWPARAM(GetDlgCtrlID(infoPtr
->hwndSelf
), notif
),
100 (LPARAM
)infoPtr
->hwndSelf
);
103 static BOOL
ANIMATE_LoadResW(ANIMATE_INFO
*infoPtr
, HINSTANCE hInst
, LPCWSTR lpName
)
105 static const WCHAR aviW
[] = { 'A', 'V', 'I', 0 };
110 hrsrc
= FindResourceW(hInst
, lpName
, aviW
);
114 infoPtr
->hRes
= LoadResource(hInst
, hrsrc
);
118 lpAvi
= LockResource(infoPtr
->hRes
);
122 memset(&mminfo
, 0, sizeof(mminfo
));
123 mminfo
.fccIOProc
= FOURCC_MEM
;
124 mminfo
.pchBuffer
= (LPSTR
)lpAvi
;
125 mminfo
.cchBuffer
= SizeofResource(hInst
, hrsrc
);
126 infoPtr
->hMMio
= mmioOpenW(NULL
, &mminfo
, MMIO_READ
);
129 FreeResource(infoPtr
->hRes
);
137 static BOOL
ANIMATE_LoadFileW(ANIMATE_INFO
*infoPtr
, LPWSTR lpName
)
139 infoPtr
->hMMio
= mmioOpenW(lpName
, 0, MMIO_ALLOCBUF
| MMIO_READ
| MMIO_DENYWRITE
);
141 if(!infoPtr
->hMMio
) return FALSE
;
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 Free (infoPtr
->lpIndex
);
194 infoPtr
->lpIndex
= NULL
;
196 fnIC
.fnICClose(infoPtr
->hic
);
199 Free (infoPtr
->inbih
);
200 infoPtr
->inbih
= NULL
;
201 Free (infoPtr
->outbih
);
202 infoPtr
->outbih
= NULL
;
203 Free (infoPtr
->indata
);
204 infoPtr
->indata
= NULL
;
205 Free (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
const *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 const *pBitmapData
;
255 BITMAPINFO
const *pBitmapInfo
;
263 if (!hDC
|| !infoPtr
->inbih
)
268 pBitmapData
= infoPtr
->outdata
;
269 pBitmapInfo
= (LPBITMAPINFO
)infoPtr
->outbih
;
271 nWidth
= infoPtr
->outbih
->biWidth
;
272 nHeight
= infoPtr
->outbih
->biHeight
;
276 pBitmapData
= infoPtr
->indata
;
277 pBitmapInfo
= (LPBITMAPINFO
)infoPtr
->inbih
;
279 nWidth
= infoPtr
->inbih
->biWidth
;
280 nHeight
= infoPtr
->inbih
->biHeight
;
283 if(!infoPtr
->hbmPrevFrame
)
285 infoPtr
->hbmPrevFrame
=CreateCompatibleBitmap(hDC
, nWidth
,nHeight
);
288 hdcMem
= CreateCompatibleDC(hDC
);
289 hbmOld
= SelectObject(hdcMem
, infoPtr
->hbmPrevFrame
);
291 SetDIBits(hdcMem
, infoPtr
->hbmPrevFrame
, 0, nHeight
, pBitmapData
, pBitmapInfo
, DIB_RGB_COLORS
);
294 * we need to get the transparent color even without ACS_TRANSPARENT,
295 * because the style can be changed later on and the color should always
296 * be obtained in the first frame
298 if(infoPtr
->transparentColor
== ANIMATE_COLOR_NONE
)
300 infoPtr
->transparentColor
= GetPixel(hdcMem
,0,0);
303 if(infoPtr
->dwStyle
& ACS_TRANSPARENT
)
305 HDC hdcFinal
= CreateCompatibleDC(hDC
);
306 HBITMAP hbmFinal
= CreateCompatibleBitmap(hDC
,nWidth
, nHeight
);
307 HBITMAP hbmOld2
= SelectObject(hdcFinal
, hbmFinal
);
313 rect
.bottom
= nHeight
;
315 if(!infoPtr
->hbrushBG
)
316 infoPtr
->hbrushBG
= GetCurrentObject(hDC
, OBJ_BRUSH
);
318 FillRect(hdcFinal
, &rect
, infoPtr
->hbrushBG
);
319 ANIMATE_TransparentBlt(infoPtr
, hdcFinal
, hdcMem
);
321 SelectObject(hdcFinal
, hbmOld2
);
322 SelectObject(hdcMem
, hbmFinal
);
324 DeleteObject(infoPtr
->hbmPrevFrame
);
325 infoPtr
->hbmPrevFrame
= hbmFinal
;
328 if (infoPtr
->dwStyle
& ACS_CENTER
)
332 GetWindowRect(infoPtr
->hwndSelf
, &rect
);
333 nOffsetX
= ((rect
.right
- rect
.left
) - nWidth
)/2;
334 nOffsetY
= ((rect
.bottom
- rect
.top
) - nHeight
)/2;
336 BitBlt(hDC
, nOffsetX
, nOffsetY
, nWidth
, nHeight
, hdcMem
, 0, 0, SRCCOPY
);
338 SelectObject(hdcMem
, hbmOld
);
343 static BOOL
ANIMATE_DrawFrame(ANIMATE_INFO
*infoPtr
)
347 TRACE("Drawing frame %d (loop %d)\n", infoPtr
->currFrame
, infoPtr
->nLoop
);
349 mmioSeek(infoPtr
->hMMio
, infoPtr
->lpIndex
[infoPtr
->currFrame
], SEEK_SET
);
350 mmioRead(infoPtr
->hMMio
, infoPtr
->indata
, infoPtr
->ash
.dwSuggestedBufferSize
);
353 fnIC
.fnICDecompress(infoPtr
->hic
, 0, infoPtr
->inbih
, infoPtr
->indata
,
354 infoPtr
->outbih
, infoPtr
->outdata
) != ICERR_OK
) {
355 WARN("Decompression error\n");
359 if ((hDC
= GetDC(infoPtr
->hwndSelf
)) != 0) {
360 ANIMATE_PaintFrame(infoPtr
, hDC
);
361 ReleaseDC(infoPtr
->hwndSelf
, hDC
);
364 if (infoPtr
->currFrame
++ >= infoPtr
->nToFrame
) {
365 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
366 if (infoPtr
->nLoop
!= -1) {
367 if (--infoPtr
->nLoop
== 0) {
368 ANIMATE_DoStop(infoPtr
);
376 static LRESULT
ANIMATE_Timer(ANIMATE_INFO
*infoPtr
)
378 /* FIXME: we should pass the hDC instead of 0 to WM_CTLCOLORSTATIC */
379 if (infoPtr
->dwStyle
& ACS_TRANSPARENT
)
380 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
,
382 0, (LPARAM
)infoPtr
->hwndSelf
);
383 EnterCriticalSection(&infoPtr
->cs
);
384 ANIMATE_DrawFrame(infoPtr
);
385 LeaveCriticalSection(&infoPtr
->cs
);
390 static DWORD CALLBACK
ANIMATE_AnimationThread(LPVOID ptr_
)
392 ANIMATE_INFO
*infoPtr
= (ANIMATE_INFO
*)ptr_
;
398 EnterCriticalSection(&infoPtr
->cs
);
399 ANIMATE_DrawFrame(infoPtr
);
400 timeout
= infoPtr
->mah
.dwMicroSecPerFrame
;
401 event
= infoPtr
->hStopEvent
;
402 LeaveCriticalSection(&infoPtr
->cs
);
404 /* time is in microseconds, we should convert it to milliseconds */
405 if ((event
== 0) || WaitForSingleObject( event
, (timeout
+500)/1000) == WAIT_OBJECT_0
)
411 static LRESULT
ANIMATE_Play(ANIMATE_INFO
*infoPtr
, UINT cRepeat
, WORD wFrom
, WORD wTo
)
417 if (infoPtr
->hThread
|| infoPtr
->uTimer
) {
418 TRACE("Already playing\n");
422 infoPtr
->nFromFrame
= wFrom
;
423 infoPtr
->nToFrame
= wTo
;
424 infoPtr
->nLoop
= cRepeat
;
426 if (infoPtr
->nToFrame
== 0xFFFF)
427 infoPtr
->nToFrame
= infoPtr
->mah
.dwTotalFrames
- 1;
429 TRACE("(repeat=%d from=%d to=%d);\n",
430 infoPtr
->nLoop
, infoPtr
->nFromFrame
, infoPtr
->nToFrame
);
432 if (infoPtr
->nFromFrame
>= infoPtr
->nToFrame
||
433 infoPtr
->nToFrame
>= infoPtr
->mah
.dwTotalFrames
)
436 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
438 if (infoPtr
->dwStyle
& ACS_TIMER
)
440 TRACE("Using a timer\n");
441 /* create a timer to display AVI */
442 infoPtr
->uTimer
= SetTimer(infoPtr
->hwndSelf
, 1,
443 infoPtr
->mah
.dwMicroSecPerFrame
/ 1000, NULL
);
447 if(infoPtr
->dwStyle
& ACS_TRANSPARENT
)
448 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
,
449 WM_CTLCOLORSTATIC
, 0,
450 (LPARAM
)infoPtr
->hwndSelf
);
452 TRACE("Using an animation thread\n");
453 infoPtr
->hStopEvent
= CreateEventW( NULL
, TRUE
, FALSE
, NULL
);
454 infoPtr
->hThread
= CreateThread(0, 0, ANIMATE_AnimationThread
,
455 (LPVOID
)infoPtr
, 0, &infoPtr
->threadId
);
456 if(!infoPtr
->hThread
) return FALSE
;
460 ANIMATE_Notify(infoPtr
, ACN_START
);
466 static BOOL
ANIMATE_GetAviInfo(ANIMATE_INFO
*infoPtr
)
475 if (mmioDescend(infoPtr
->hMMio
, &ckMainRIFF
, NULL
, 0) != 0) {
476 WARN("Can't find 'RIFF' chunk\n");
480 if ((ckMainRIFF
.ckid
!= FOURCC_RIFF
) ||
481 (ckMainRIFF
.fccType
!= mmioFOURCC('A', 'V', 'I', ' '))) {
482 WARN("Can't find 'AVI ' chunk\n");
486 mmckHead
.fccType
= mmioFOURCC('h', 'd', 'r', 'l');
487 if (mmioDescend(infoPtr
->hMMio
, &mmckHead
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
488 WARN("Can't find 'hdrl' list\n");
492 mmckInfo
.ckid
= mmioFOURCC('a', 'v', 'i', 'h');
493 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckHead
, MMIO_FINDCHUNK
) != 0) {
494 WARN("Can't find 'avih' chunk\n");
498 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->mah
, sizeof(infoPtr
->mah
));
500 TRACE("mah.dwMicroSecPerFrame=%d\n", infoPtr
->mah
.dwMicroSecPerFrame
);
501 TRACE("mah.dwMaxBytesPerSec=%d\n", infoPtr
->mah
.dwMaxBytesPerSec
);
502 TRACE("mah.dwPaddingGranularity=%d\n", infoPtr
->mah
.dwPaddingGranularity
);
503 TRACE("mah.dwFlags=%d\n", infoPtr
->mah
.dwFlags
);
504 TRACE("mah.dwTotalFrames=%d\n", infoPtr
->mah
.dwTotalFrames
);
505 TRACE("mah.dwInitialFrames=%d\n", infoPtr
->mah
.dwInitialFrames
);
506 TRACE("mah.dwStreams=%d\n", infoPtr
->mah
.dwStreams
);
507 TRACE("mah.dwSuggestedBufferSize=%d\n", infoPtr
->mah
.dwSuggestedBufferSize
);
508 TRACE("mah.dwWidth=%d\n", infoPtr
->mah
.dwWidth
);
509 TRACE("mah.dwHeight=%d\n", infoPtr
->mah
.dwHeight
);
511 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
513 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
514 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) != 0) {
515 WARN("Can't find 'strl' list\n");
519 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'h');
520 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
521 WARN("Can't find 'strh' chunk\n");
525 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->ash
, sizeof(infoPtr
->ash
));
527 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccType
)),
528 HIBYTE(LOWORD(infoPtr
->ash
.fccType
)),
529 LOBYTE(HIWORD(infoPtr
->ash
.fccType
)),
530 HIBYTE(HIWORD(infoPtr
->ash
.fccType
)));
531 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
532 HIBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
533 LOBYTE(HIWORD(infoPtr
->ash
.fccHandler
)),
534 HIBYTE(HIWORD(infoPtr
->ash
.fccHandler
)));
535 TRACE("ash.dwFlags=%d\n", infoPtr
->ash
.dwFlags
);
536 TRACE("ash.wPriority=%d\n", infoPtr
->ash
.wPriority
);
537 TRACE("ash.wLanguage=%d\n", infoPtr
->ash
.wLanguage
);
538 TRACE("ash.dwInitialFrames=%d\n", infoPtr
->ash
.dwInitialFrames
);
539 TRACE("ash.dwScale=%d\n", infoPtr
->ash
.dwScale
);
540 TRACE("ash.dwRate=%d\n", infoPtr
->ash
.dwRate
);
541 TRACE("ash.dwStart=%d\n", infoPtr
->ash
.dwStart
);
542 TRACE("ash.dwLength=%d\n", infoPtr
->ash
.dwLength
);
543 TRACE("ash.dwSuggestedBufferSize=%d\n", infoPtr
->ash
.dwSuggestedBufferSize
);
544 TRACE("ash.dwQuality=%d\n", infoPtr
->ash
.dwQuality
);
545 TRACE("ash.dwSampleSize=%d\n", infoPtr
->ash
.dwSampleSize
);
546 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr
->ash
.rcFrame
.top
, infoPtr
->ash
.rcFrame
.left
,
547 infoPtr
->ash
.rcFrame
.bottom
, infoPtr
->ash
.rcFrame
.right
);
549 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
551 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'f');
552 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
553 WARN("Can't find 'strh' chunk\n");
557 infoPtr
->inbih
= Alloc(mmckInfo
.cksize
);
558 if (!infoPtr
->inbih
) {
559 WARN("Can't alloc input BIH\n");
563 mmioRead(infoPtr
->hMMio
, (LPSTR
)infoPtr
->inbih
, mmckInfo
.cksize
);
565 TRACE("bih.biSize=%d\n", infoPtr
->inbih
->biSize
);
566 TRACE("bih.biWidth=%d\n", infoPtr
->inbih
->biWidth
);
567 TRACE("bih.biHeight=%d\n", infoPtr
->inbih
->biHeight
);
568 TRACE("bih.biPlanes=%d\n", infoPtr
->inbih
->biPlanes
);
569 TRACE("bih.biBitCount=%d\n", infoPtr
->inbih
->biBitCount
);
570 TRACE("bih.biCompression=%d\n", infoPtr
->inbih
->biCompression
);
571 TRACE("bih.biSizeImage=%d\n", infoPtr
->inbih
->biSizeImage
);
572 TRACE("bih.biXPelsPerMeter=%d\n", infoPtr
->inbih
->biXPelsPerMeter
);
573 TRACE("bih.biYPelsPerMeter=%d\n", infoPtr
->inbih
->biYPelsPerMeter
);
574 TRACE("bih.biClrUsed=%d\n", infoPtr
->inbih
->biClrUsed
);
575 TRACE("bih.biClrImportant=%d\n", infoPtr
->inbih
->biClrImportant
);
577 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
579 mmioAscend(infoPtr
->hMMio
, &mmckList
, 0);
582 /* an AVI has 0 or 1 video stream, and to be animated should not contain
583 * an audio stream, so only one strl is allowed
585 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
586 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) == 0) {
587 WARN("There should be a single 'strl' list\n");
592 mmioAscend(infoPtr
->hMMio
, &mmckHead
, 0);
594 /* no need to read optional JUNK chunk */
596 mmckList
.fccType
= mmioFOURCC('m', 'o', 'v', 'i');
597 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
598 WARN("Can't find 'movi' list\n");
602 /* FIXME: should handle the 'rec ' LIST when present */
604 infoPtr
->lpIndex
= Alloc(infoPtr
->mah
.dwTotalFrames
* sizeof(DWORD
));
605 if (!infoPtr
->lpIndex
)
608 numFrame
= insize
= 0;
609 while (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, 0) == 0 &&
610 numFrame
< infoPtr
->mah
.dwTotalFrames
) {
611 infoPtr
->lpIndex
[numFrame
] = mmckInfo
.dwDataOffset
;
612 if (insize
< mmckInfo
.cksize
)
613 insize
= mmckInfo
.cksize
;
615 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
617 if (numFrame
!= infoPtr
->mah
.dwTotalFrames
) {
618 WARN("Found %d frames (/%d)\n", numFrame
, infoPtr
->mah
.dwTotalFrames
);
621 if (insize
> infoPtr
->ash
.dwSuggestedBufferSize
) {
622 WARN("insize=%d suggestedSize=%d\n", insize
, infoPtr
->ash
.dwSuggestedBufferSize
);
623 infoPtr
->ash
.dwSuggestedBufferSize
= insize
;
626 infoPtr
->indata
= Alloc(infoPtr
->ash
.dwSuggestedBufferSize
);
627 if (!infoPtr
->indata
)
634 static BOOL
ANIMATE_GetAviCodec(ANIMATE_INFO
*infoPtr
)
638 /* check uncompressed AVI */
639 if ((infoPtr
->ash
.fccHandler
== mmioFOURCC('D', 'I', 'B', ' ')) ||
640 (infoPtr
->ash
.fccHandler
== mmioFOURCC('R', 'L', 'E', ' ')) ||
641 (infoPtr
->ash
.fccHandler
== mmioFOURCC(0, 0, 0, 0)))
647 /* try to get a decompressor for that type */
648 infoPtr
->hic
= fnIC
.fnICOpen(ICTYPE_VIDEO
, infoPtr
->ash
.fccHandler
, ICMODE_DECOMPRESS
);
650 WARN("Can't load codec for the file\n");
654 outSize
= fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
655 (DWORD_PTR
)infoPtr
->inbih
, 0L);
657 infoPtr
->outbih
= Alloc(outSize
);
658 if (!infoPtr
->outbih
)
661 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
662 (DWORD_PTR
)infoPtr
->inbih
, (DWORD_PTR
)infoPtr
->outbih
) != ICERR_OK
)
664 WARN("Can't get output BIH\n");
668 infoPtr
->outdata
= Alloc(infoPtr
->outbih
->biSizeImage
);
669 if (!infoPtr
->outdata
)
672 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_BEGIN
,
673 (DWORD_PTR
)infoPtr
->inbih
, (DWORD_PTR
)infoPtr
->outbih
) != ICERR_OK
) {
674 WARN("Can't begin decompression\n");
682 static BOOL
ANIMATE_OpenW(ANIMATE_INFO
*infoPtr
, HINSTANCE hInstance
, LPWSTR lpszName
)
684 ANIMATE_Free(infoPtr
);
688 TRACE("Closing avi!\n");
689 /* installer of thebat! v1.62 requires FALSE here */
690 return (infoPtr
->hMMio
!= 0);
694 hInstance
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
696 TRACE("(%s)\n", debugstr_w(lpszName
));
698 if (HIWORD(lpszName
))
700 if (!ANIMATE_LoadResW(infoPtr
, hInstance
, lpszName
))
702 TRACE("No AVI resource found!\n");
703 if (!ANIMATE_LoadFileW(infoPtr
, lpszName
))
705 WARN("No AVI file found!\n");
712 if (!ANIMATE_LoadResW(infoPtr
, hInstance
, lpszName
))
714 WARN("No AVI resource found!\n");
719 if (!ANIMATE_GetAviInfo(infoPtr
))
721 WARN("Can't get AVI information\n");
722 ANIMATE_Free(infoPtr
);
726 if (!ANIMATE_GetAviCodec(infoPtr
))
728 WARN("Can't get AVI Codec\n");
729 ANIMATE_Free(infoPtr
);
733 if (!(infoPtr
->dwStyle
& ACS_CENTER
))
734 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, infoPtr
->mah
.dwWidth
, infoPtr
->mah
.dwHeight
,
735 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
737 if (infoPtr
->dwStyle
& ACS_AUTOPLAY
)
738 return ANIMATE_Play(infoPtr
, -1, 0, infoPtr
->mah
.dwTotalFrames
- 1);
744 static BOOL
ANIMATE_OpenA(ANIMATE_INFO
*infoPtr
, HINSTANCE hInstance
, LPSTR lpszName
)
750 if (!HIWORD(lpszName
))
751 return ANIMATE_OpenW(infoPtr
, hInstance
, (LPWSTR
)lpszName
);
753 len
= MultiByteToWideChar(CP_ACP
, 0, lpszName
, -1, NULL
, 0);
754 lpwszName
= Alloc(len
* sizeof(WCHAR
));
755 if (!lpwszName
) return FALSE
;
756 MultiByteToWideChar(CP_ACP
, 0, lpszName
, -1, lpwszName
, len
);
758 result
= ANIMATE_OpenW(infoPtr
, hInstance
, lpwszName
);
764 static BOOL
ANIMATE_Stop(ANIMATE_INFO
*infoPtr
)
770 ANIMATE_DoStop(infoPtr
);
775 static BOOL
ANIMATE_Create(HWND hWnd
, const CREATESTRUCTW
*lpcs
)
777 static const WCHAR msvfw32W
[] = { 'm', 's', 'v', 'f', 'w', '3', '2', '.', 'd', 'l', 'l', 0 };
778 ANIMATE_INFO
*infoPtr
;
782 fnIC
.hModule
= LoadLibraryW(msvfw32W
);
783 if (!fnIC
.hModule
) return FALSE
;
785 fnIC
.fnICOpen
= (void*)GetProcAddress(fnIC
.hModule
, "ICOpen");
786 fnIC
.fnICClose
= (void*)GetProcAddress(fnIC
.hModule
, "ICClose");
787 fnIC
.fnICSendMessage
= (void*)GetProcAddress(fnIC
.hModule
, "ICSendMessage");
788 fnIC
.fnICDecompress
= (void*)GetProcAddress(fnIC
.hModule
, "ICDecompress");
791 /* allocate memory for info structure */
792 infoPtr
= (ANIMATE_INFO
*)Alloc(sizeof(ANIMATE_INFO
));
793 if (!infoPtr
) return FALSE
;
795 /* store crossref hWnd <-> info structure */
796 SetWindowLongPtrW(hWnd
, 0, (DWORD_PTR
)infoPtr
);
797 infoPtr
->hwndSelf
= hWnd
;
798 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
799 infoPtr
->transparentColor
= ANIMATE_COLOR_NONE
;
800 infoPtr
->hbmPrevFrame
= 0;
801 infoPtr
->dwStyle
= lpcs
->style
;
803 TRACE("Animate style=0x%08x, parent=%p\n", infoPtr
->dwStyle
, infoPtr
->hwndNotify
);
805 InitializeCriticalSection(&infoPtr
->cs
);
806 infoPtr
->cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": ANIMATE_INFO*->cs");
812 static LRESULT
ANIMATE_Destroy(ANIMATE_INFO
*infoPtr
)
815 ANIMATE_Free(infoPtr
);
817 /* free animate info data */
818 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
820 infoPtr
->cs
.DebugInfo
->Spare
[0] = 0;
821 DeleteCriticalSection(&infoPtr
->cs
);
828 static BOOL
ANIMATE_EraseBackground(ANIMATE_INFO
const *infoPtr
, HDC hdc
)
833 if(infoPtr
->dwStyle
& ACS_TRANSPARENT
)
835 hBrush
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLORSTATIC
,
836 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
839 GetClientRect(infoPtr
->hwndSelf
, &rect
);
840 FillRect(hdc
, &rect
, hBrush
? hBrush
: GetCurrentObject(hdc
, OBJ_BRUSH
));
846 static LRESULT
ANIMATE_StyleChanged(ANIMATE_INFO
*infoPtr
, WPARAM wStyleType
, const STYLESTRUCT
*lpss
)
848 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
849 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
851 if (wStyleType
!= GWL_STYLE
) return 0;
853 infoPtr
->dwStyle
= lpss
->styleNew
;
855 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
860 static LRESULT WINAPI
ANIMATE_WindowProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
862 ANIMATE_INFO
*infoPtr
= (ANIMATE_INFO
*)GetWindowLongPtrW(hWnd
, 0);
864 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hWnd
, uMsg
, wParam
, lParam
);
865 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
866 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
870 return ANIMATE_OpenA(infoPtr
, (HINSTANCE
)wParam
, (LPSTR
)lParam
);
873 return ANIMATE_OpenW(infoPtr
, (HINSTANCE
)wParam
, (LPWSTR
)lParam
);
876 return ANIMATE_Play(infoPtr
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
879 return ANIMATE_Stop(infoPtr
);
882 ANIMATE_Free(infoPtr
);
886 return ANIMATE_Create(hWnd
, (LPCREATESTRUCTW
)lParam
);
889 return HTTRANSPARENT
;
892 return ANIMATE_Destroy(infoPtr
);
895 return ANIMATE_EraseBackground(infoPtr
, (HDC
)wParam
);
897 case WM_STYLECHANGED
:
898 return ANIMATE_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
901 return ANIMATE_Timer(infoPtr
);
906 /* the animation isn't playing, or has not decompressed
907 * (and displayed) the first frame yet, don't paint
909 if ((!infoPtr
->uTimer
&& !infoPtr
->hThread
) ||
910 !infoPtr
->hbmPrevFrame
)
912 /* default paint handling */
913 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
916 if (infoPtr
->dwStyle
& ACS_TRANSPARENT
)
917 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
,
919 wParam
, (LPARAM
)infoPtr
->hwndSelf
);
923 EnterCriticalSection(&infoPtr
->cs
);
924 ANIMATE_PaintFrame(infoPtr
, (HDC
)wParam
);
925 LeaveCriticalSection(&infoPtr
->cs
);
930 HDC hDC
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
932 EnterCriticalSection(&infoPtr
->cs
);
933 ANIMATE_PaintFrame(infoPtr
, hDC
);
934 LeaveCriticalSection(&infoPtr
->cs
);
936 EndPaint(infoPtr
->hwndSelf
, &ps
);
942 if (infoPtr
->dwStyle
& ACS_CENTER
)
943 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
944 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
947 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
948 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
950 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
955 void ANIMATE_Register(void)
959 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
960 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
961 wndClass
.lpfnWndProc
= ANIMATE_WindowProc
;
962 wndClass
.cbClsExtra
= 0;
963 wndClass
.cbWndExtra
= sizeof(ANIMATE_INFO
*);
964 wndClass
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
965 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
966 wndClass
.lpszClassName
= ANIMATE_CLASSW
;
968 RegisterClassW(&wndClass
);
972 void ANIMATE_Unregister(void)
974 UnregisterClassW(ANIMATE_CLASSW
, NULL
);