1 | /* -*- tab-width: 8; c-basic-offset: 4 -*- */
|
---|
2 | /*
|
---|
3 | * Animation control
|
---|
4 | *
|
---|
5 | * Copyright 1998, 1999 Eric Kohl
|
---|
6 | * 1999 Eric Pouech
|
---|
7 | *
|
---|
8 | * NOTES
|
---|
9 | * I will only improve this control once in a while.
|
---|
10 | * Eric <ekohl@abo.rhein-zeitung.de>
|
---|
11 | *
|
---|
12 | * TODO:
|
---|
13 | * - check for the 'rec ' list in some AVI files
|
---|
14 | * - concurrent access to infoPtr
|
---|
15 | */
|
---|
16 |
|
---|
17 |
|
---|
18 | #include "winbase.h"
|
---|
19 | #include "commctrl.h"
|
---|
20 | #include "vfw.h"
|
---|
21 | #include "mmsystem.h"
|
---|
22 | #include "services.h"
|
---|
23 | #include "debugtools.h"
|
---|
24 |
|
---|
25 | DEFAULT_DEBUG_CHANNEL(animate);
|
---|
26 |
|
---|
27 | typedef struct
|
---|
28 | {
|
---|
29 | /* pointer to msvideo functions. it's easier to put them here.
|
---|
30 | * to be correct, they should be defined on a per process basis, but
|
---|
31 | * this would required a per process storage. We're using a per object
|
---|
32 | * storage instead, which is not efficient on memory usage, but
|
---|
33 | * will lead to less bugs in the future
|
---|
34 | */
|
---|
35 | #ifdef __WIN32OS2__
|
---|
36 | HIC (* WINAPI fnICOpen)(DWORD, DWORD, UINT);
|
---|
37 | LRESULT (* WINAPI fnICClose)(HIC);
|
---|
38 | LRESULT (* WINAPI fnICSendMessage)(HIC, UINT, DWORD, DWORD);
|
---|
39 | DWORD (* WINAPIV fnICDecompress)(HIC,DWORD,LPBITMAPINFOHEADER,LPVOID,LPBITMAPINFOHEADER,LPVOID);
|
---|
40 |
|
---|
41 | HMMIO (* WINAPI fnmmioOpenA)(LPSTR,MMIOINFO*,DWORD);
|
---|
42 | MMRESULT (* WINAPI fnmmioClose)(HMMIO,UINT);
|
---|
43 | UINT (* WINAPI fnmmioAscend)(HMMIO,MMCKINFO*,UINT);
|
---|
44 | UINT (* WINAPI fnmmioDescend)(HMMIO,MMCKINFO*,const MMCKINFO*,UINT);
|
---|
45 | LONG (* WINAPI fnmmioSeek)(HMMIO,LONG,INT);
|
---|
46 | LONG (* WINAPI fnmmioRead)(HMMIO,HPSTR,LONG);
|
---|
47 | #else
|
---|
48 | HIC WINAPI (*fnICOpen)(DWORD, DWORD, UINT);
|
---|
49 | LRESULT WINAPI (*fnICClose)(HIC);
|
---|
50 | LRESULT WINAPI (*fnICSendMessage)(HIC, UINT, DWORD, DWORD);
|
---|
51 | DWORD WINAPIV (*fnICDecompress)(HIC,DWORD,LPBITMAPINFOHEADER,LPVOID,LPBITMAPINFOHEADER,LPVOID);
|
---|
52 |
|
---|
53 | HMMIO WINAPI (*fnmmioOpenA)(LPSTR,MMIOINFO*,DWORD);
|
---|
54 | MMRESULT WINAPI (*fnmmioClose)(HMMIO,UINT);
|
---|
55 | UINT WINAPI (*fnmmioAscend)(HMMIO,MMCKINFO*,UINT);
|
---|
56 | UINT WINAPI (*fnmmioDescend)(HMMIO,MMCKINFO*,const MMCKINFO*,UINT);
|
---|
57 | LONG WINAPI (*fnmmioSeek)(HMMIO,LONG,INT);
|
---|
58 | LONG WINAPI (*fnmmioRead)(HMMIO,HPSTR,LONG);
|
---|
59 | #endif
|
---|
60 |
|
---|
61 | /* reference to input stream (file or resource) */
|
---|
62 | HGLOBAL hRes;
|
---|
63 | HMMIO hMMio; /* handle to mmio stream */
|
---|
64 | HWND hWnd;
|
---|
65 | /* information on the loaded AVI file */
|
---|
66 | MainAVIHeader mah;
|
---|
67 | AVIStreamHeader ash;
|
---|
68 | LPBITMAPINFOHEADER inbih;
|
---|
69 | LPDWORD lpIndex;
|
---|
70 | /* data for the decompressor */
|
---|
71 | HIC hic;
|
---|
72 | LPBITMAPINFOHEADER outbih;
|
---|
73 | LPVOID indata;
|
---|
74 | LPVOID outdata;
|
---|
75 | /* data for the background mechanism */
|
---|
76 | CRITICAL_SECTION cs;
|
---|
77 | HANDLE hThread;
|
---|
78 | UINT uTimer;
|
---|
79 | /* data for playing the file */
|
---|
80 | int nFromFrame;
|
---|
81 | int nToFrame;
|
---|
82 | int nLoop;
|
---|
83 | int currFrame;
|
---|
84 | /* tranparency info*/
|
---|
85 | COLORREF transparentColor;
|
---|
86 | HBRUSH hbrushBG;
|
---|
87 | HBITMAP hbmPrevFrame;
|
---|
88 | } ANIMATE_INFO;
|
---|
89 |
|
---|
90 | #define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongA(hWnd, 0))
|
---|
91 | #define ANIMATE_COLOR_NONE 0xffffffff
|
---|
92 |
|
---|
93 | HMODULE hModWinmm;
|
---|
94 |
|
---|
95 | static void ANIMATE_Notify(ANIMATE_INFO* infoPtr, UINT notif)
|
---|
96 | {
|
---|
97 | SendMessageA(GetParent(infoPtr->hWnd), WM_COMMAND,
|
---|
98 | MAKEWPARAM(GetDlgCtrlID(infoPtr->hWnd), notif),
|
---|
99 | (LPARAM)infoPtr->hWnd);
|
---|
100 | }
|
---|
101 |
|
---|
102 | static BOOL ANIMATE_LoadResA(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
|
---|
103 | {
|
---|
104 | HRSRC hrsrc;
|
---|
105 | MMIOINFO mminfo;
|
---|
106 | LPVOID lpAvi;
|
---|
107 |
|
---|
108 | hrsrc = FindResourceA(hInst, lpName, "AVI");
|
---|
109 | if (!hrsrc)
|
---|
110 | return FALSE;
|
---|
111 |
|
---|
112 | infoPtr->hRes = LoadResource(hInst, hrsrc);
|
---|
113 | if (!infoPtr->hRes)
|
---|
114 | return FALSE;
|
---|
115 |
|
---|
116 | lpAvi = LockResource(infoPtr->hRes);
|
---|
117 | if (!lpAvi)
|
---|
118 | return FALSE;
|
---|
119 |
|
---|
120 | memset(&mminfo, 0, sizeof(mminfo));
|
---|
121 | mminfo.fccIOProc = FOURCC_MEM;
|
---|
122 | mminfo.pchBuffer = (LPSTR)lpAvi;
|
---|
123 | mminfo.cchBuffer = SizeofResource(hInst, hrsrc);
|
---|
124 | infoPtr->hMMio = infoPtr->fnmmioOpenA(NULL, &mminfo, MMIO_READ);
|
---|
125 |
|
---|
126 | if (!infoPtr->hMMio) {
|
---|
127 | GlobalFree((HGLOBAL)lpAvi);
|
---|
128 | return FALSE;
|
---|
129 | }
|
---|
130 |
|
---|
131 | return TRUE;
|
---|
132 | }
|
---|
133 |
|
---|
134 |
|
---|
135 | static BOOL ANIMATE_LoadFileA(ANIMATE_INFO *infoPtr, LPSTR lpName)
|
---|
136 | {
|
---|
137 | infoPtr->hMMio = infoPtr->fnmmioOpenA((LPSTR)lpName, NULL,
|
---|
138 | MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
|
---|
139 |
|
---|
140 | if (!infoPtr->hMMio)
|
---|
141 | return FALSE;
|
---|
142 |
|
---|
143 | return TRUE;
|
---|
144 | }
|
---|
145 |
|
---|
146 |
|
---|
147 | static LRESULT ANIMATE_DoStop(ANIMATE_INFO *infoPtr)
|
---|
148 | {
|
---|
149 | EnterCriticalSection(&infoPtr->cs);
|
---|
150 |
|
---|
151 | /* should stop playing */
|
---|
152 | if (infoPtr->hThread)
|
---|
153 | {
|
---|
154 | if (!TerminateThread(infoPtr->hThread,0))
|
---|
155 | WARN("could not destroy animation thread!\n");
|
---|
156 | infoPtr->hThread = 0;
|
---|
157 | }
|
---|
158 | if (infoPtr->uTimer) {
|
---|
159 | KillTimer(infoPtr->hWnd, infoPtr->uTimer);
|
---|
160 | infoPtr->uTimer = 0;
|
---|
161 | }
|
---|
162 |
|
---|
163 | LeaveCriticalSection(&infoPtr->cs);
|
---|
164 |
|
---|
165 | ANIMATE_Notify(infoPtr, ACN_STOP);
|
---|
166 |
|
---|
167 | return TRUE;
|
---|
168 | }
|
---|
169 |
|
---|
170 |
|
---|
171 | static void ANIMATE_Free(ANIMATE_INFO *infoPtr)
|
---|
172 | {
|
---|
173 | if (infoPtr->hMMio) {
|
---|
174 | ANIMATE_DoStop(infoPtr);
|
---|
175 | infoPtr->fnmmioClose(infoPtr->hMMio, 0);
|
---|
176 | if (infoPtr->hRes) {
|
---|
177 | FreeResource(infoPtr->hRes);
|
---|
178 | infoPtr->hRes = 0;
|
---|
179 | }
|
---|
180 | if (infoPtr->lpIndex) {
|
---|
181 | HeapFree(GetProcessHeap(), 0, infoPtr->lpIndex);
|
---|
182 | infoPtr->lpIndex = NULL;
|
---|
183 | }
|
---|
184 | if (infoPtr->hic) {
|
---|
185 | (infoPtr->fnICClose)(infoPtr->hic);
|
---|
186 | infoPtr->hic = 0;
|
---|
187 | }
|
---|
188 | if (infoPtr->inbih) {
|
---|
189 | HeapFree(GetProcessHeap(), 0, infoPtr->inbih);
|
---|
190 | infoPtr->inbih = NULL;
|
---|
191 | }
|
---|
192 | if (infoPtr->outbih) {
|
---|
193 | HeapFree(GetProcessHeap(), 0, infoPtr->outbih);
|
---|
194 | infoPtr->outbih = NULL;
|
---|
195 | }
|
---|
196 | if( infoPtr->indata )
|
---|
197 | {
|
---|
198 | HeapFree(GetProcessHeap(), 0, infoPtr->indata);
|
---|
199 | infoPtr->indata = NULL;
|
---|
200 | }
|
---|
201 | if( infoPtr->outdata )
|
---|
202 | {
|
---|
203 | HeapFree(GetProcessHeap(), 0, infoPtr->outdata);
|
---|
204 | infoPtr->outdata = NULL;
|
---|
205 | }
|
---|
206 | if( infoPtr->hbmPrevFrame )
|
---|
207 | {
|
---|
208 | DeleteObject(infoPtr->hbmPrevFrame);
|
---|
209 | infoPtr->hbmPrevFrame = 0;
|
---|
210 | }
|
---|
211 | infoPtr->indata = infoPtr->outdata = NULL;
|
---|
212 | infoPtr->hWnd = 0;
|
---|
213 | infoPtr->hMMio = 0;
|
---|
214 |
|
---|
215 | memset(&infoPtr->mah, 0, sizeof(infoPtr->mah));
|
---|
216 | memset(&infoPtr->ash, 0, sizeof(infoPtr->ash));
|
---|
217 | infoPtr->nFromFrame = infoPtr->nToFrame = infoPtr->nLoop = infoPtr->currFrame = 0;
|
---|
218 | }
|
---|
219 | infoPtr->transparentColor = ANIMATE_COLOR_NONE;
|
---|
220 | }
|
---|
221 |
|
---|
222 | static void ANIMATE_TransparentBlt(ANIMATE_INFO* infoPtr, HDC hdcDest, HDC hdcSource)
|
---|
223 | {
|
---|
224 | HDC hdcMask;
|
---|
225 | HBITMAP hbmMask;
|
---|
226 | HBITMAP hbmOld;
|
---|
227 |
|
---|
228 | /* create a transparency mask */
|
---|
229 | hdcMask = CreateCompatibleDC(hdcDest);
|
---|
230 | hbmMask = CreateBitmap(infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 1,1,NULL);
|
---|
231 | hbmOld = SelectObject(hdcMask, hbmMask);
|
---|
232 |
|
---|
233 | SetBkColor(hdcSource,infoPtr->transparentColor);
|
---|
234 | BitBlt(hdcMask,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCCOPY);
|
---|
235 |
|
---|
236 | /* mask the source bitmap */
|
---|
237 | SetBkColor(hdcSource, RGB(0,0,0));
|
---|
238 | SetTextColor(hdcSource, RGB(255,255,255));
|
---|
239 | BitBlt(hdcSource, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
|
---|
240 |
|
---|
241 | /* mask the destination bitmap */
|
---|
242 | SetBkColor(hdcDest, RGB(255,255,255));
|
---|
243 | SetTextColor(hdcDest, RGB(0,0,0));
|
---|
244 | BitBlt(hdcDest, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
|
---|
245 |
|
---|
246 | /* combine source and destination */
|
---|
247 | BitBlt(hdcDest,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCPAINT);
|
---|
248 |
|
---|
249 | SelectObject(hdcMask, hbmOld);
|
---|
250 | DeleteObject(hbmMask);
|
---|
251 | DeleteDC(hdcMask);
|
---|
252 | }
|
---|
253 |
|
---|
254 | static LRESULT ANIMATE_PaintFrame(ANIMATE_INFO* infoPtr, HDC hDC)
|
---|
255 | {
|
---|
256 | void* pBitmapData = NULL;
|
---|
257 | LPBITMAPINFO pBitmapInfo = NULL;
|
---|
258 |
|
---|
259 | HDC hdcMem;
|
---|
260 | HBITMAP hbmOld;
|
---|
261 |
|
---|
262 | int nOffsetX = 0;
|
---|
263 | int nOffsetY = 0;
|
---|
264 |
|
---|
265 | int nWidth;
|
---|
266 | int nHeight;
|
---|
267 |
|
---|
268 | if (!hDC || !infoPtr->inbih)
|
---|
269 | return TRUE;
|
---|
270 |
|
---|
271 | if (infoPtr->hic )
|
---|
272 | {
|
---|
273 | pBitmapData = infoPtr->outdata;
|
---|
274 | pBitmapInfo = (LPBITMAPINFO)infoPtr->outbih;
|
---|
275 |
|
---|
276 | nWidth = infoPtr->outbih->biWidth;
|
---|
277 | nHeight = infoPtr->outbih->biHeight;
|
---|
278 | } else
|
---|
279 | {
|
---|
280 | pBitmapData = infoPtr->indata;
|
---|
281 | pBitmapInfo = (LPBITMAPINFO)infoPtr->inbih;
|
---|
282 |
|
---|
283 | nWidth = infoPtr->inbih->biWidth;
|
---|
284 | nHeight = infoPtr->inbih->biHeight;
|
---|
285 | }
|
---|
286 |
|
---|
287 | if(!infoPtr->hbmPrevFrame)
|
---|
288 | {
|
---|
289 | infoPtr->hbmPrevFrame=CreateCompatibleBitmap(hDC, nWidth,nHeight );
|
---|
290 | }
|
---|
291 |
|
---|
292 | SetDIBits(hDC, infoPtr->hbmPrevFrame, 0, nHeight, pBitmapData, (LPBITMAPINFO)pBitmapInfo, DIB_RGB_COLORS);
|
---|
293 |
|
---|
294 | hdcMem = CreateCompatibleDC(hDC);
|
---|
295 | hbmOld = SelectObject(hdcMem, infoPtr->hbmPrevFrame);
|
---|
296 |
|
---|
297 | /*
|
---|
298 | * we need to get the transparent color even without ACS_TRANSPARENT,
|
---|
299 | * because the style can be changed later on and the color should always
|
---|
300 | * be obtained in the first frame
|
---|
301 | */
|
---|
302 | if(infoPtr->transparentColor == ANIMATE_COLOR_NONE)
|
---|
303 | {
|
---|
304 | infoPtr->transparentColor = GetPixel(hdcMem,0,0);
|
---|
305 | }
|
---|
306 |
|
---|
307 | if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT)
|
---|
308 | {
|
---|
309 | HDC hdcFinal = CreateCompatibleDC(hDC);
|
---|
310 | HBITMAP hbmFinal = CreateCompatibleBitmap(hDC,nWidth, nHeight);
|
---|
311 | HBITMAP hbmOld2 = SelectObject(hdcFinal, hbmFinal);
|
---|
312 | RECT rect;
|
---|
313 |
|
---|
314 | rect.left = 0;
|
---|
315 | rect.top = 0;
|
---|
316 | rect.right = nWidth;
|
---|
317 | rect.bottom = nHeight;
|
---|
318 |
|
---|
319 | if(!infoPtr->hbrushBG)
|
---|
320 | infoPtr->hbrushBG = GetCurrentObject(hDC, OBJ_BRUSH);
|
---|
321 |
|
---|
322 | FillRect(hdcFinal, &rect, infoPtr->hbrushBG);
|
---|
323 | ANIMATE_TransparentBlt(infoPtr, hdcFinal, hdcMem);
|
---|
324 |
|
---|
325 | SelectObject(hdcFinal, hbmOld2);
|
---|
326 | SelectObject(hdcMem, hbmFinal);
|
---|
327 | DeleteDC(hdcFinal);
|
---|
328 | DeleteObject(infoPtr->hbmPrevFrame);
|
---|
329 | infoPtr->hbmPrevFrame = hbmFinal;
|
---|
330 | }
|
---|
331 |
|
---|
332 | if (GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_CENTER)
|
---|
333 | {
|
---|
334 | RECT rect;
|
---|
335 |
|
---|
336 | GetWindowRect(infoPtr->hWnd, &rect);
|
---|
337 | nOffsetX = ((rect.right - rect.left) - nWidth)/2;
|
---|
338 | nOffsetY = ((rect.bottom - rect.top) - nHeight)/2;
|
---|
339 | }
|
---|
340 | BitBlt(hDC, nOffsetX, nOffsetY, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
|
---|
341 |
|
---|
342 | SelectObject(hdcMem, hbmOld);
|
---|
343 | DeleteDC(hdcMem);
|
---|
344 | return TRUE;
|
---|
345 | }
|
---|
346 |
|
---|
347 | static LRESULT ANIMATE_DrawFrame(ANIMATE_INFO* infoPtr)
|
---|
348 | {
|
---|
349 | HDC hDC;
|
---|
350 |
|
---|
351 | TRACE("Drawing frame %d (loop %d)\n", infoPtr->currFrame, infoPtr->nLoop);
|
---|
352 |
|
---|
353 | EnterCriticalSection(&infoPtr->cs);
|
---|
354 |
|
---|
355 | infoPtr->fnmmioSeek(infoPtr->hMMio, infoPtr->lpIndex[infoPtr->currFrame], SEEK_SET);
|
---|
356 | infoPtr->fnmmioRead(infoPtr->hMMio, infoPtr->indata, infoPtr->ash.dwSuggestedBufferSize);
|
---|
357 |
|
---|
358 | if (infoPtr->hic &&
|
---|
359 | (infoPtr->fnICDecompress)(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
|
---|
360 | infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
|
---|
361 | LeaveCriticalSection(&infoPtr->cs);
|
---|
362 | WARN("Decompression error\n");
|
---|
363 | return FALSE;
|
---|
364 | }
|
---|
365 |
|
---|
366 | if ((hDC = GetDC(infoPtr->hWnd)) != 0) {
|
---|
367 | ANIMATE_PaintFrame(infoPtr, hDC);
|
---|
368 | ReleaseDC(infoPtr->hWnd, hDC);
|
---|
369 | }
|
---|
370 |
|
---|
371 | if (infoPtr->currFrame++ >= infoPtr->nToFrame) {
|
---|
372 | infoPtr->currFrame = infoPtr->nFromFrame;
|
---|
373 | if (infoPtr->nLoop != -1) {
|
---|
374 | if (--infoPtr->nLoop == 0) {
|
---|
375 | ANIMATE_DoStop(infoPtr);
|
---|
376 | }
|
---|
377 | }
|
---|
378 | }
|
---|
379 | LeaveCriticalSection(&infoPtr->cs);
|
---|
380 |
|
---|
381 | return TRUE;
|
---|
382 | }
|
---|
383 |
|
---|
384 | static DWORD CALLBACK ANIMATE_AnimationThread(LPVOID ptr_)
|
---|
385 | {
|
---|
386 | ANIMATE_INFO* infoPtr = (ANIMATE_INFO*)ptr_;
|
---|
387 | HDC hDC;
|
---|
388 |
|
---|
389 | if(!infoPtr)
|
---|
390 | {
|
---|
391 | WARN("animation structure undefined!\n");
|
---|
392 | return FALSE;
|
---|
393 | }
|
---|
394 |
|
---|
395 | while(1)
|
---|
396 | {
|
---|
397 | if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT)
|
---|
398 | {
|
---|
399 | hDC = GetDC(infoPtr->hWnd);
|
---|
400 | infoPtr->hbrushBG = SendMessageA(GetParent(infoPtr->hWnd),WM_CTLCOLORSTATIC,hDC, infoPtr->hWnd);
|
---|
401 | ReleaseDC(infoPtr->hWnd,hDC);
|
---|
402 | }
|
---|
403 |
|
---|
404 | EnterCriticalSection(&infoPtr->cs);
|
---|
405 | ANIMATE_DrawFrame(infoPtr);
|
---|
406 | LeaveCriticalSection(&infoPtr->cs);
|
---|
407 |
|
---|
408 | /* time is in microseconds, we should convert it to milliseconds */
|
---|
409 | Sleep((infoPtr->mah.dwMicroSecPerFrame+500)/1000);
|
---|
410 | }
|
---|
411 | return TRUE;
|
---|
412 | }
|
---|
413 |
|
---|
414 | static LRESULT ANIMATE_Play(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
415 | {
|
---|
416 | ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
417 |
|
---|
418 | /* nothing opened */
|
---|
419 | if (!infoPtr->hMMio)
|
---|
420 | return FALSE;
|
---|
421 |
|
---|
422 | if (infoPtr->hThread || infoPtr->uTimer) {
|
---|
423 | FIXME("Already playing ? what should I do ??\n");
|
---|
424 | ANIMATE_DoStop(infoPtr);
|
---|
425 | }
|
---|
426 |
|
---|
427 | infoPtr->nFromFrame = (INT)LOWORD(lParam);
|
---|
428 | infoPtr->nToFrame = (INT)HIWORD(lParam);
|
---|
429 | infoPtr->nLoop = (INT)wParam;
|
---|
430 |
|
---|
431 | if (infoPtr->nToFrame == 0xFFFF)
|
---|
432 | infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1;
|
---|
433 |
|
---|
434 | TRACE("(repeat=%d from=%d to=%d);\n",
|
---|
435 | infoPtr->nLoop, infoPtr->nFromFrame, infoPtr->nToFrame);
|
---|
436 |
|
---|
437 | if (infoPtr->nFromFrame >= infoPtr->nToFrame ||
|
---|
438 | infoPtr->nToFrame >= infoPtr->mah.dwTotalFrames)
|
---|
439 | return FALSE;
|
---|
440 |
|
---|
441 | infoPtr->currFrame = infoPtr->nFromFrame;
|
---|
442 |
|
---|
443 | if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TIMER) {
|
---|
444 | TRACE("Using a timer\n");
|
---|
445 | /* create a timer to display AVI */
|
---|
446 | infoPtr->uTimer = SetTimer(hWnd, 1, infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
|
---|
447 | } else {
|
---|
448 | DWORD threadID;
|
---|
449 |
|
---|
450 | TRACE("Using an animation thread\n");
|
---|
451 | infoPtr->hThread = CreateThread(0,0,ANIMATE_AnimationThread,(LPVOID)infoPtr,0,0 &threadID);
|
---|
452 | if(!infoPtr->hThread)
|
---|
453 | {
|
---|
454 | ERR("Could not create animation thread!\n");
|
---|
455 | return FALSE;
|
---|
456 | }
|
---|
457 |
|
---|
458 | }
|
---|
459 |
|
---|
460 | ANIMATE_Notify(infoPtr, ACN_START);
|
---|
461 |
|
---|
462 | return TRUE;
|
---|
463 | }
|
---|
464 |
|
---|
465 |
|
---|
466 | static BOOL ANIMATE_GetAviInfo(ANIMATE_INFO *infoPtr)
|
---|
467 | {
|
---|
468 | MMCKINFO ckMainRIFF;
|
---|
469 | MMCKINFO mmckHead;
|
---|
470 | MMCKINFO mmckList;
|
---|
471 | MMCKINFO mmckInfo;
|
---|
472 | DWORD numFrame;
|
---|
473 | DWORD insize;
|
---|
474 |
|
---|
475 | if (infoPtr->fnmmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) {
|
---|
476 | WARN("Can't find 'RIFF' chunk\n");
|
---|
477 | return FALSE;
|
---|
478 | }
|
---|
479 |
|
---|
480 | if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
|
---|
481 | (ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) {
|
---|
482 | WARN("Can't find 'AVI ' chunk\n");
|
---|
483 | return FALSE;
|
---|
484 | }
|
---|
485 |
|
---|
486 | mmckHead.fccType = mmioFOURCC('h', 'd', 'r', 'l');
|
---|
487 | if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
|
---|
488 | WARN("Can't find 'hdrl' list\n");
|
---|
489 | return FALSE;
|
---|
490 | }
|
---|
491 |
|
---|
492 | mmckInfo.ckid = mmioFOURCC('a', 'v', 'i', 'h');
|
---|
493 | if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
|
---|
494 | WARN("Can't find 'avih' chunk\n");
|
---|
495 | return FALSE;
|
---|
496 | }
|
---|
497 |
|
---|
498 | infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->mah, sizeof(infoPtr->mah));
|
---|
499 | TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr->mah.dwMicroSecPerFrame);
|
---|
500 | TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr->mah.dwMaxBytesPerSec);
|
---|
501 | TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr->mah.dwPaddingGranularity);
|
---|
502 | TRACE("mah.dwFlags=%ld\n", infoPtr->mah.dwFlags);
|
---|
503 | TRACE("mah.dwTotalFrames=%ld\n", infoPtr->mah.dwTotalFrames);
|
---|
504 | TRACE("mah.dwInitialFrames=%ld\n", infoPtr->mah.dwInitialFrames);
|
---|
505 | TRACE("mah.dwStreams=%ld\n", infoPtr->mah.dwStreams);
|
---|
506 | TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr->mah.dwSuggestedBufferSize);
|
---|
507 | TRACE("mah.dwWidth=%ld\n", infoPtr->mah.dwWidth);
|
---|
508 | TRACE("mah.dwHeight=%ld\n", infoPtr->mah.dwHeight);
|
---|
509 | infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
|
---|
510 |
|
---|
511 | mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
|
---|
512 | if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
|
---|
513 | WARN("Can't find 'strl' list\n");
|
---|
514 | return FALSE;
|
---|
515 | }
|
---|
516 |
|
---|
517 | mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'h');
|
---|
518 | if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
|
---|
519 | WARN("Can't find 'strh' chunk\n");
|
---|
520 | return FALSE;
|
---|
521 | }
|
---|
522 |
|
---|
523 | infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->ash, sizeof(infoPtr->ash));
|
---|
524 | TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)),
|
---|
525 | HIBYTE(LOWORD(infoPtr->ash.fccType)),
|
---|
526 | LOBYTE(HIWORD(infoPtr->ash.fccType)),
|
---|
527 | HIBYTE(HIWORD(infoPtr->ash.fccType)));
|
---|
528 | TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)),
|
---|
529 | HIBYTE(LOWORD(infoPtr->ash.fccHandler)),
|
---|
530 | LOBYTE(HIWORD(infoPtr->ash.fccHandler)),
|
---|
531 | HIBYTE(HIWORD(infoPtr->ash.fccHandler)));
|
---|
532 | TRACE("ash.dwFlags=%ld\n", infoPtr->ash.dwFlags);
|
---|
533 | TRACE("ash.wPriority=%d\n", infoPtr->ash.wPriority);
|
---|
534 | TRACE("ash.wLanguage=%d\n", infoPtr->ash.wLanguage);
|
---|
535 | TRACE("ash.dwInitialFrames=%ld\n", infoPtr->ash.dwInitialFrames);
|
---|
536 | TRACE("ash.dwScale=%ld\n", infoPtr->ash.dwScale);
|
---|
537 | TRACE("ash.dwRate=%ld\n", infoPtr->ash.dwRate);
|
---|
538 | TRACE("ash.dwStart=%ld\n", infoPtr->ash.dwStart);
|
---|
539 | TRACE("ash.dwLength=%ld\n", infoPtr->ash.dwLength);
|
---|
540 | TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr->ash.dwSuggestedBufferSize);
|
---|
541 | TRACE("ash.dwQuality=%ld\n", infoPtr->ash.dwQuality);
|
---|
542 | TRACE("ash.dwSampleSize=%ld\n", infoPtr->ash.dwSampleSize);
|
---|
543 | TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left,
|
---|
544 | infoPtr->ash.rcFrame.bottom, infoPtr->ash.rcFrame.right);
|
---|
545 | infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
|
---|
546 |
|
---|
547 | mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'f');
|
---|
548 | if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
|
---|
549 | WARN("Can't find 'strh' chunk\n");
|
---|
550 | return FALSE;
|
---|
551 | }
|
---|
552 |
|
---|
553 | infoPtr->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
|
---|
554 | if (!infoPtr->inbih) {
|
---|
555 | WARN("Can't alloc input BIH\n");
|
---|
556 | return FALSE;
|
---|
557 | }
|
---|
558 |
|
---|
559 | infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)infoPtr->inbih, mmckInfo.cksize);
|
---|
560 | TRACE("bih.biSize=%ld\n", infoPtr->inbih->biSize);
|
---|
561 | TRACE("bih.biWidth=%ld\n", infoPtr->inbih->biWidth);
|
---|
562 | TRACE("bih.biHeight=%ld\n", infoPtr->inbih->biHeight);
|
---|
563 | TRACE("bih.biPlanes=%d\n", infoPtr->inbih->biPlanes);
|
---|
564 | TRACE("bih.biBitCount=%d\n", infoPtr->inbih->biBitCount);
|
---|
565 | TRACE("bih.biCompression=%ld\n", infoPtr->inbih->biCompression);
|
---|
566 | TRACE("bih.biSizeImage=%ld\n", infoPtr->inbih->biSizeImage);
|
---|
567 | TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr->inbih->biXPelsPerMeter);
|
---|
568 | TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr->inbih->biYPelsPerMeter);
|
---|
569 | TRACE("bih.biClrUsed=%ld\n", infoPtr->inbih->biClrUsed);
|
---|
570 | TRACE("bih.biClrImportant=%ld\n", infoPtr->inbih->biClrImportant);
|
---|
571 | infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
|
---|
572 |
|
---|
573 | infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckList, 0);
|
---|
574 |
|
---|
575 | #if 0
|
---|
576 | /* an AVI has 0 or 1 video stream, and to be animated should not contain
|
---|
577 | * an audio stream, so only one strl is allowed
|
---|
578 | */
|
---|
579 | mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
|
---|
580 | if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) == 0) {
|
---|
581 | WARN("There should be a single 'strl' list\n");
|
---|
582 | return FALSE;
|
---|
583 | }
|
---|
584 | #endif
|
---|
585 |
|
---|
586 | infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckHead, 0);
|
---|
587 |
|
---|
588 | /* no need to read optional JUNK chunk */
|
---|
589 |
|
---|
590 | mmckList.fccType = mmioFOURCC('m', 'o', 'v', 'i');
|
---|
591 | if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
|
---|
592 | WARN("Can't find 'movi' list\n");
|
---|
593 | return FALSE;
|
---|
594 | }
|
---|
595 |
|
---|
596 | /* FIXME: should handle the 'rec ' LIST when present */
|
---|
597 |
|
---|
598 | infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
---|
599 | infoPtr->mah.dwTotalFrames * sizeof(DWORD));
|
---|
600 | if (!infoPtr->lpIndex) {
|
---|
601 | WARN("Can't alloc index array\n");
|
---|
602 | return FALSE;
|
---|
603 | }
|
---|
604 |
|
---|
605 | numFrame = insize = 0;
|
---|
606 | while (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 &&
|
---|
607 | numFrame < infoPtr->mah.dwTotalFrames) {
|
---|
608 | infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset;
|
---|
609 | if (insize < mmckInfo.cksize)
|
---|
610 | insize = mmckInfo.cksize;
|
---|
611 | numFrame++;
|
---|
612 | infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
|
---|
613 | }
|
---|
614 | if (numFrame != infoPtr->mah.dwTotalFrames) {
|
---|
615 | WARN("Found %ld frames (/%ld)\n", numFrame, infoPtr->mah.dwTotalFrames);
|
---|
616 | return FALSE;
|
---|
617 | }
|
---|
618 | if (insize > infoPtr->ash.dwSuggestedBufferSize) {
|
---|
619 | WARN("insize=%ld suggestedSize=%ld\n", insize, infoPtr->ash.dwSuggestedBufferSize);
|
---|
620 | infoPtr->ash.dwSuggestedBufferSize = insize;
|
---|
621 | }
|
---|
622 |
|
---|
623 | infoPtr->indata = HeapAlloc(GetProcessHeap(), 0, infoPtr->ash.dwSuggestedBufferSize);
|
---|
624 | if (!infoPtr->indata) {
|
---|
625 | WARN("Can't alloc input buffer\n");
|
---|
626 | return FALSE;
|
---|
627 | }
|
---|
628 |
|
---|
629 | return TRUE;
|
---|
630 | }
|
---|
631 |
|
---|
632 |
|
---|
633 | static BOOL ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
|
---|
634 | {
|
---|
635 | DWORD outSize;
|
---|
636 |
|
---|
637 | /* check uncompressed AVI */
|
---|
638 | if ((infoPtr->ash.fccHandler == mmioFOURCC('D', 'I', 'B', ' ')) ||
|
---|
639 | (infoPtr->ash.fccHandler == mmioFOURCC('R', 'L', 'E', ' ')))
|
---|
640 | {
|
---|
641 | infoPtr->hic = 0;
|
---|
642 | return TRUE;
|
---|
643 | }
|
---|
644 |
|
---|
645 | /* try to get a decompressor for that type */
|
---|
646 | infoPtr->hic = (infoPtr->fnICOpen)(ICTYPE_VIDEO,
|
---|
647 | infoPtr->ash.fccHandler,
|
---|
648 | ICMODE_DECOMPRESS);
|
---|
649 | if (!infoPtr->hic) {
|
---|
650 | WARN("Can't load codec for the file\n");
|
---|
651 | return FALSE;
|
---|
652 | }
|
---|
653 |
|
---|
654 | outSize = (infoPtr->fnICSendMessage)(infoPtr->hic,
|
---|
655 | ICM_DECOMPRESS_GET_FORMAT,
|
---|
656 | (DWORD)infoPtr->inbih, 0L);
|
---|
657 | infoPtr->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
|
---|
658 | if (!infoPtr->outbih) {
|
---|
659 | WARN("Can't alloc output BIH\n");
|
---|
660 | return FALSE;
|
---|
661 | }
|
---|
662 |
|
---|
663 | if ((infoPtr->fnICSendMessage)(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
|
---|
664 | (DWORD)infoPtr->inbih,
|
---|
665 | (DWORD)infoPtr->outbih) != ICERR_OK) {
|
---|
666 | WARN("Can't get output BIH\n");
|
---|
667 | return FALSE;
|
---|
668 | }
|
---|
669 |
|
---|
670 | infoPtr->outdata = HeapAlloc(GetProcessHeap(), 0, infoPtr->outbih->biSizeImage);
|
---|
671 | if (!infoPtr->outdata) {
|
---|
672 | WARN("Can't alloc output buffer\n");
|
---|
673 | return FALSE;
|
---|
674 | }
|
---|
675 |
|
---|
676 | if ((infoPtr->fnICSendMessage)(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
|
---|
677 | (DWORD)infoPtr->inbih,
|
---|
678 | (DWORD)infoPtr->outbih) != ICERR_OK) {
|
---|
679 | WARN("Can't begin decompression\n");
|
---|
680 | return FALSE;
|
---|
681 | }
|
---|
682 |
|
---|
683 | return TRUE;
|
---|
684 | }
|
---|
685 |
|
---|
686 | static LRESULT ANIMATE_OpenA(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
687 | {
|
---|
688 | ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
689 | HINSTANCE hInstance = (HINSTANCE)wParam;
|
---|
690 |
|
---|
691 | ANIMATE_Free(infoPtr);
|
---|
692 |
|
---|
693 | if (!lParam) {
|
---|
694 | TRACE("Closing avi!\n");
|
---|
695 | return TRUE;
|
---|
696 | }
|
---|
697 |
|
---|
698 | if (!hInstance)
|
---|
699 | hInstance = GetWindowLongA(hWnd, GWL_HINSTANCE);
|
---|
700 |
|
---|
701 | if (HIWORD(lParam)) {
|
---|
702 | TRACE("(\"%s\");\n", (LPSTR)lParam);
|
---|
703 |
|
---|
704 | if (!ANIMATE_LoadResA(infoPtr, hInstance, (LPSTR)lParam)) {
|
---|
705 | TRACE("No AVI resource found!\n");
|
---|
706 | if (!ANIMATE_LoadFileA(infoPtr, (LPSTR)lParam)) {
|
---|
707 | WARN("No AVI file found!\n");
|
---|
708 | return FALSE;
|
---|
709 | }
|
---|
710 | }
|
---|
711 | } else {
|
---|
712 | TRACE("(%u);\n", (WORD)LOWORD(lParam));
|
---|
713 |
|
---|
714 | if (!ANIMATE_LoadResA(infoPtr, hInstance,
|
---|
715 | MAKEINTRESOURCEA((INT)lParam))) {
|
---|
716 | WARN("No AVI resource found!\n");
|
---|
717 | return FALSE;
|
---|
718 | }
|
---|
719 | }
|
---|
720 |
|
---|
721 | if (!ANIMATE_GetAviInfo(infoPtr)) {
|
---|
722 | WARN("Can't get AVI information\n");
|
---|
723 | ANIMATE_Free(infoPtr);
|
---|
724 | return FALSE;
|
---|
725 | }
|
---|
726 |
|
---|
727 | if (!ANIMATE_GetAviCodec(infoPtr)) {
|
---|
728 | WARN("Can't get AVI Codec\n");
|
---|
729 | ANIMATE_Free(infoPtr);
|
---|
730 | return FALSE;
|
---|
731 | }
|
---|
732 |
|
---|
733 | if (!GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
|
---|
734 | SetWindowPos(hWnd, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
|
---|
735 | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
|
---|
736 | }
|
---|
737 |
|
---|
738 | if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_AUTOPLAY) {
|
---|
739 | return ANIMATE_Play(hWnd, -1, (LPARAM)MAKELONG(0, infoPtr->mah.dwTotalFrames-1));
|
---|
740 | }
|
---|
741 |
|
---|
742 | return TRUE;
|
---|
743 | }
|
---|
744 |
|
---|
745 |
|
---|
746 | /* << ANIMATE_Open32W >> */
|
---|
747 |
|
---|
748 | static LRESULT ANIMATE_Stop(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
749 | {
|
---|
750 | ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
751 |
|
---|
752 | /* nothing opened */
|
---|
753 | if (!infoPtr->hMMio)
|
---|
754 | return FALSE;
|
---|
755 |
|
---|
756 | ANIMATE_DoStop(infoPtr);
|
---|
757 | return TRUE;
|
---|
758 | }
|
---|
759 |
|
---|
760 |
|
---|
761 | static LRESULT ANIMATE_Create(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
762 | {
|
---|
763 | ANIMATE_INFO* infoPtr;
|
---|
764 | HMODULE hModule = LoadLibraryA("msvfw32.dll");
|
---|
765 |
|
---|
766 | if (!hModule)
|
---|
767 | return FALSE;
|
---|
768 |
|
---|
769 | /* allocate memory for info structure */
|
---|
770 | infoPtr = (ANIMATE_INFO *)COMCTL32_Alloc(sizeof(ANIMATE_INFO));
|
---|
771 | if (!infoPtr) {
|
---|
772 | ERR("could not allocate info memory!\n");
|
---|
773 | return 0;
|
---|
774 | }
|
---|
775 |
|
---|
776 | /* Temporary hack until we get dllglue up and running */
|
---|
777 | infoPtr->fnICOpen = (void*)GetProcAddress(hModule, "ICOpen");
|
---|
778 | infoPtr->fnICClose = (void*)GetProcAddress(hModule, "ICClose");
|
---|
779 | infoPtr->fnICSendMessage = (void*)GetProcAddress(hModule, "ICSendMessage");
|
---|
780 | infoPtr->fnICDecompress = (void*)GetProcAddress(hModule, "ICDecompress");
|
---|
781 |
|
---|
782 | TRACE("Animate style=0x%08lx, parent=%08lx\n", GetWindowLongA(hWnd, GWL_STYLE), (DWORD)GetParent(hWnd));
|
---|
783 |
|
---|
784 | /* store crossref hWnd <-> info structure */
|
---|
785 | SetWindowLongA(hWnd, 0, (DWORD)infoPtr);
|
---|
786 | infoPtr->hWnd = hWnd;
|
---|
787 | infoPtr->transparentColor = ANIMATE_COLOR_NONE;
|
---|
788 | infoPtr->hbmPrevFrame = 0;
|
---|
789 | hModWinmm = LoadLibraryA("WINMM");
|
---|
790 |
|
---|
791 | infoPtr->fnmmioOpenA = (void*)GetProcAddress(hModWinmm, "mmioOpenA");
|
---|
792 | infoPtr->fnmmioClose = (void*)GetProcAddress(hModWinmm, "mmioClose");
|
---|
793 | infoPtr->fnmmioAscend = (void*)GetProcAddress(hModWinmm, "mmioAscend");
|
---|
794 | infoPtr->fnmmioDescend = (void*)GetProcAddress(hModWinmm, "mmioDescend");
|
---|
795 | infoPtr->fnmmioSeek = (void*)GetProcAddress(hModWinmm, "mmioSeek");
|
---|
796 | infoPtr->fnmmioRead = (void*)GetProcAddress(hModWinmm, "mmioRead");
|
---|
797 |
|
---|
798 | InitializeCriticalSection(&infoPtr->cs);
|
---|
799 |
|
---|
800 | return 0;
|
---|
801 | }
|
---|
802 |
|
---|
803 |
|
---|
804 | static LRESULT ANIMATE_Destroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
805 | {
|
---|
806 | ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
807 |
|
---|
808 |
|
---|
809 | /* free avi data */
|
---|
810 | ANIMATE_Free(infoPtr);
|
---|
811 |
|
---|
812 | /* free animate info data */
|
---|
813 | COMCTL32_Free(infoPtr);
|
---|
814 | SetWindowLongA(hWnd, 0, 0);
|
---|
815 |
|
---|
816 | FreeLibrary(hModWinmm);
|
---|
817 | return 0;
|
---|
818 | }
|
---|
819 |
|
---|
820 |
|
---|
821 | static LRESULT ANIMATE_EraseBackground(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
822 | {
|
---|
823 | RECT rect;
|
---|
824 | HBRUSH hBrush = 0;
|
---|
825 |
|
---|
826 | if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
|
---|
827 | {
|
---|
828 | hBrush = SendMessageA(GetParent(hWnd),WM_CTLCOLORSTATIC,(HDC)wParam, hWnd);
|
---|
829 | }
|
---|
830 |
|
---|
831 | GetClientRect(hWnd, &rect);
|
---|
832 | FillRect((HDC)wParam, &rect, hBrush ? hBrush : GetCurrentObject((HDC)wParam, OBJ_BRUSH));
|
---|
833 |
|
---|
834 | return TRUE;
|
---|
835 | }
|
---|
836 |
|
---|
837 | static LRESULT WINAPI ANIMATE_Size(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
838 | {
|
---|
839 | if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
|
---|
840 | InvalidateRect(hWnd, NULL, TRUE);
|
---|
841 | }
|
---|
842 | return TRUE;
|
---|
843 | }
|
---|
844 |
|
---|
845 | static LRESULT WINAPI ANIMATE_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
---|
846 | {
|
---|
847 | TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hWnd, uMsg, wParam, lParam);
|
---|
848 | if (!ANIMATE_GetInfoPtr(hWnd) && (uMsg != WM_NCCREATE))
|
---|
849 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
850 | switch (uMsg)
|
---|
851 | {
|
---|
852 | case ACM_OPENA:
|
---|
853 | return ANIMATE_OpenA(hWnd, wParam, lParam);
|
---|
854 |
|
---|
855 | /* case ACM_OPEN32W: FIXME!! */
|
---|
856 | /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
|
---|
857 |
|
---|
858 | case ACM_PLAY:
|
---|
859 | return ANIMATE_Play(hWnd, wParam, lParam);
|
---|
860 |
|
---|
861 | case ACM_STOP:
|
---|
862 | return ANIMATE_Stop(hWnd, wParam, lParam);
|
---|
863 |
|
---|
864 | case WM_NCCREATE:
|
---|
865 | ANIMATE_Create(hWnd, wParam, lParam);
|
---|
866 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
867 |
|
---|
868 | case WM_NCHITTEST:
|
---|
869 | return HTTRANSPARENT;
|
---|
870 |
|
---|
871 | case WM_DESTROY:
|
---|
872 | ANIMATE_Destroy(hWnd, wParam, lParam);
|
---|
873 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
874 |
|
---|
875 | case WM_ERASEBKGND:
|
---|
876 | ANIMATE_EraseBackground(hWnd, wParam, lParam);
|
---|
877 | break;
|
---|
878 |
|
---|
879 | /* case WM_STYLECHANGED: FIXME shall we do something ?? */
|
---|
880 |
|
---|
881 | case WM_TIMER:
|
---|
882 | if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
|
---|
883 | {
|
---|
884 | ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
885 | infoPtr->hbrushBG = SendMessageA(GetParent(hWnd),WM_CTLCOLORSTATIC,(HDC)wParam, hWnd);
|
---|
886 | }
|
---|
887 | return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd));
|
---|
888 |
|
---|
889 | case WM_CLOSE:
|
---|
890 | ANIMATE_Free(ANIMATE_GetInfoPtr(hWnd));
|
---|
891 | return TRUE;
|
---|
892 |
|
---|
893 | case WM_PAINT:
|
---|
894 | {
|
---|
895 | ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
896 |
|
---|
897 | /* the animation isn't playing, don't paint */
|
---|
898 | if(!infoPtr->uTimer && !infoPtr->hThread)
|
---|
899 | /* default paint handling */
|
---|
900 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
901 |
|
---|
902 | if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
|
---|
903 | infoPtr->hbrushBG = SendMessageA(GetParent(hWnd), WM_CTLCOLORSTATIC,
|
---|
904 | (HDC)wParam, hWnd);
|
---|
905 |
|
---|
906 | if (wParam)
|
---|
907 | {
|
---|
908 | EnterCriticalSection(&infoPtr->cs);
|
---|
909 | ANIMATE_PaintFrame(infoPtr, (HDC)wParam);
|
---|
910 | LeaveCriticalSection(&infoPtr->cs);
|
---|
911 | }
|
---|
912 | else
|
---|
913 | {
|
---|
914 | PAINTSTRUCT ps;
|
---|
915 | HDC hDC = BeginPaint(hWnd, &ps);
|
---|
916 |
|
---|
917 | EnterCriticalSection(&infoPtr->cs);
|
---|
918 | ANIMATE_PaintFrame(infoPtr, hDC);
|
---|
919 | LeaveCriticalSection(&infoPtr->cs);
|
---|
920 |
|
---|
921 | EndPaint(hWnd, &ps);
|
---|
922 | }
|
---|
923 | }
|
---|
924 | break;
|
---|
925 |
|
---|
926 | case WM_SIZE:
|
---|
927 | ANIMATE_Size(hWnd, wParam, lParam);
|
---|
928 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
929 |
|
---|
930 | default:
|
---|
931 | if (uMsg >= WM_USER)
|
---|
932 | ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
|
---|
933 |
|
---|
934 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
935 | }
|
---|
936 | return 0;
|
---|
937 | }
|
---|
938 |
|
---|
939 |
|
---|
940 | void ANIMATE_Register(void)
|
---|
941 | {
|
---|
942 | WNDCLASSA wndClass;
|
---|
943 |
|
---|
944 | ZeroMemory(&wndClass, sizeof(WNDCLASSA));
|
---|
945 | wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
|
---|
946 | wndClass.lpfnWndProc = (WNDPROC)ANIMATE_WindowProc;
|
---|
947 | wndClass.cbClsExtra = 0;
|
---|
948 | wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
|
---|
949 | wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
|
---|
950 | wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
|
---|
951 | wndClass.lpszClassName = ANIMATE_CLASSA;
|
---|
952 |
|
---|
953 | RegisterClassA(&wndClass);
|
---|
954 | }
|
---|
955 |
|
---|
956 |
|
---|
957 | void ANIMATE_Unregister(void)
|
---|
958 | {
|
---|
959 | UnregisterClassA(ANIMATE_CLASSA, (HINSTANCE)NULL);
|
---|
960 | }
|
---|
961 |
|
---|