1 | /*
|
---|
2 | * Animation control
|
---|
3 | *
|
---|
4 | * Copyright 1998, 1999 Eric Kohl
|
---|
5 | *
|
---|
6 | * NOTES
|
---|
7 | * This is just a dummy control. An author is needed! Any volunteers?
|
---|
8 | * I will only improve this control once in a while.
|
---|
9 | * Eric <ekohl@abo.rhein-zeitung.de>
|
---|
10 | *
|
---|
11 | * TODO:
|
---|
12 | * - All messages.
|
---|
13 | * - All notifications.
|
---|
14 | */
|
---|
15 |
|
---|
16 |
|
---|
17 | #include "winbase.h"
|
---|
18 | #include "commctrl.h"
|
---|
19 | #include "comctl32.h"
|
---|
20 | #include "animate.h"
|
---|
21 |
|
---|
22 |
|
---|
23 | #define ANIMATE_GetInfoPtr(hwnd) ((ANIMATE_INFO *)GetWindowLongA (hwnd, 0))
|
---|
24 |
|
---|
25 |
|
---|
26 | static BOOL
|
---|
27 | ANIMATE_LoadResA (ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
|
---|
28 | {
|
---|
29 | HRSRC hrsrc;
|
---|
30 | HGLOBAL handle;
|
---|
31 |
|
---|
32 | hrsrc = FindResourceA (hInst, lpName, "AVI");
|
---|
33 | if (!hrsrc)
|
---|
34 | return FALSE;
|
---|
35 |
|
---|
36 | handle = LoadResource (hInst, hrsrc);
|
---|
37 | if (!handle)
|
---|
38 | return FALSE;
|
---|
39 |
|
---|
40 | infoPtr->lpAvi = LockResource (handle);
|
---|
41 | if (!infoPtr->lpAvi)
|
---|
42 | return FALSE;
|
---|
43 |
|
---|
44 | return TRUE;
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | static BOOL
|
---|
49 | ANIMATE_LoadFileA (ANIMATE_INFO *infoPtr, LPSTR lpName)
|
---|
50 | {
|
---|
51 | HANDLE handle;
|
---|
52 |
|
---|
53 | infoPtr->hFile =
|
---|
54 | CreateFileA (lpName, GENERIC_READ, 0, NULL, OPEN_EXISTING,
|
---|
55 | FILE_ATTRIBUTE_NORMAL, 0);
|
---|
56 | if (!infoPtr->hFile)
|
---|
57 | return FALSE;
|
---|
58 |
|
---|
59 | handle =
|
---|
60 | CreateFileMappingA (infoPtr->hFile, NULL, PAGE_READONLY | SEC_COMMIT,
|
---|
61 | 0, 0, NULL);
|
---|
62 | if (!handle) {
|
---|
63 | CloseHandle (infoPtr->hFile);
|
---|
64 | infoPtr->hFile = 0;
|
---|
65 | return FALSE;
|
---|
66 | }
|
---|
67 |
|
---|
68 | infoPtr->lpAvi = MapViewOfFile (handle, FILE_MAP_READ, 0, 0, 0);
|
---|
69 | if (!infoPtr->lpAvi) {
|
---|
70 | CloseHandle (infoPtr->hFile);
|
---|
71 | infoPtr->hFile = 0;
|
---|
72 | return FALSE;
|
---|
73 | }
|
---|
74 |
|
---|
75 | return TRUE;
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | static VOID
|
---|
80 | ANIMATE_Free (ANIMATE_INFO *infoPtr)
|
---|
81 | {
|
---|
82 | if (infoPtr->hFile) {
|
---|
83 | UnmapViewOfFile (infoPtr->lpAvi);
|
---|
84 | CloseHandle (infoPtr->hFile);
|
---|
85 | infoPtr->lpAvi = NULL;
|
---|
86 | }
|
---|
87 | else {
|
---|
88 | GlobalFree ((HGLOBAL)infoPtr->lpAvi);
|
---|
89 | infoPtr->lpAvi = NULL;
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | static VOID
|
---|
95 | ANIMATE_GetAviInfo (infoPtr)
|
---|
96 | {
|
---|
97 |
|
---|
98 |
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | static LRESULT
|
---|
103 | ANIMATE_OpenA (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
104 | {
|
---|
105 | ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd);
|
---|
106 | HINSTANCE hInstance = (HINSTANCE)wParam;
|
---|
107 |
|
---|
108 | ANIMATE_Free (infoPtr);
|
---|
109 |
|
---|
110 | if (!lParam) {
|
---|
111 | // TRACE (animate, "closing avi!\n");
|
---|
112 | return TRUE;
|
---|
113 | }
|
---|
114 |
|
---|
115 | if (HIWORD(lParam)) {
|
---|
116 | // FIXME (animate, "(\"%s\") empty stub!\n", (LPSTR)lParam);
|
---|
117 |
|
---|
118 | if (ANIMATE_LoadResA (infoPtr, hInstance, (LPSTR)lParam)) {
|
---|
119 |
|
---|
120 | // FIXME (animate, "AVI resource found!\n");
|
---|
121 |
|
---|
122 | }
|
---|
123 | else {
|
---|
124 | // FIXME (animate, "No AVI resource found!\n");
|
---|
125 | if (ANIMATE_LoadFileA (infoPtr, (LPSTR)lParam)) {
|
---|
126 | // FIXME (animate, "AVI file found!\n");
|
---|
127 | }
|
---|
128 | else {
|
---|
129 | // FIXME (animate, "No AVI file found!\n");
|
---|
130 | return FALSE;
|
---|
131 | }
|
---|
132 | }
|
---|
133 | }
|
---|
134 | else {
|
---|
135 | // FIXME (animate, "(%u) empty stub!\n", (WORD)LOWORD(lParam));
|
---|
136 |
|
---|
137 | if (ANIMATE_LoadResA (infoPtr, hInstance,
|
---|
138 | MAKEINTRESOURCEA((INT)lParam))) {
|
---|
139 | // FIXME (animate, "AVI resource found!\n");
|
---|
140 | }
|
---|
141 | else {
|
---|
142 | // FIXME (animate, "No AVI resource found!\n");
|
---|
143 | return FALSE;
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 | ANIMATE_GetAviInfo (infoPtr);
|
---|
148 |
|
---|
149 | return TRUE;
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | /* << ANIMATE_Open32W >> */
|
---|
154 |
|
---|
155 |
|
---|
156 | static LRESULT
|
---|
157 | ANIMATE_Play (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
158 | {
|
---|
159 | /* ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); */
|
---|
160 | INT nFrom = (INT)LOWORD(lParam);
|
---|
161 | INT nTo = (INT)HIWORD(lParam);
|
---|
162 | INT nRepeat = (INT)wParam;
|
---|
163 |
|
---|
164 | #if 0
|
---|
165 | /* nothing opened */
|
---|
166 | if (...)
|
---|
167 | return FALSE;
|
---|
168 | #endif
|
---|
169 |
|
---|
170 | if (nRepeat == -1) {
|
---|
171 |
|
---|
172 | // FIXME (animate, "(loop from=%d to=%d) empty stub!\n",
|
---|
173 | // nFrom, nTo);
|
---|
174 |
|
---|
175 | }
|
---|
176 | else {
|
---|
177 |
|
---|
178 | // FIXME (animate, "(repeat=%d from=%d to=%d) empty stub!\n",
|
---|
179 | // nRepeat, nFrom, nTo);
|
---|
180 |
|
---|
181 | }
|
---|
182 |
|
---|
183 |
|
---|
184 | return TRUE;
|
---|
185 | }
|
---|
186 |
|
---|
187 |
|
---|
188 | static LRESULT
|
---|
189 | ANIMATE_Stop (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
190 | {
|
---|
191 | /* ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); */
|
---|
192 |
|
---|
193 | #if 0
|
---|
194 | /* nothing opened */
|
---|
195 | if (...)
|
---|
196 | return FALSE;
|
---|
197 | #endif
|
---|
198 |
|
---|
199 | return TRUE;
|
---|
200 | }
|
---|
201 |
|
---|
202 |
|
---|
203 |
|
---|
204 | static LRESULT
|
---|
205 | ANIMATE_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
206 | {
|
---|
207 | ANIMATE_INFO *infoPtr;
|
---|
208 |
|
---|
209 | /* allocate memory for info structure */
|
---|
210 | infoPtr = (ANIMATE_INFO *)COMCTL32_Alloc (sizeof(ANIMATE_INFO));
|
---|
211 | if (!infoPtr) {
|
---|
212 | // ERR (animate, "could not allocate info memory!\n");
|
---|
213 | return 0;
|
---|
214 | }
|
---|
215 |
|
---|
216 | /* store pointer to info structure */
|
---|
217 | SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
|
---|
218 |
|
---|
219 |
|
---|
220 | /* set default settings */
|
---|
221 |
|
---|
222 |
|
---|
223 | return 0;
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 | static LRESULT
|
---|
228 | ANIMATE_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
229 | {
|
---|
230 | ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd);
|
---|
231 |
|
---|
232 |
|
---|
233 | /* free avi data */
|
---|
234 | ANIMATE_Free (infoPtr);
|
---|
235 |
|
---|
236 | /* free animate info data */
|
---|
237 | COMCTL32_Free (infoPtr);
|
---|
238 |
|
---|
239 | return 0;
|
---|
240 | }
|
---|
241 |
|
---|
242 |
|
---|
243 | #if 0
|
---|
244 | static LRESULT
|
---|
245 | ANIMATE_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
246 | {
|
---|
247 | ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd);
|
---|
248 | /*
|
---|
249 | HBRUSH32 hBrush = CreateSolidBrush32 (infoPtr->clrBk);
|
---|
250 | RECT32 rect;
|
---|
251 |
|
---|
252 | GetClientRect32 (wndPtr->hwndSelf, &rect);
|
---|
253 | FillRect32 ((HDC32)wParam, &rect, hBrush);
|
---|
254 | DeleteObject32 (hBrush);
|
---|
255 | */
|
---|
256 | return TRUE;
|
---|
257 | }
|
---|
258 | #endif
|
---|
259 |
|
---|
260 |
|
---|
261 |
|
---|
262 | LRESULT WINAPI
|
---|
263 | ANIMATE_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
---|
264 | {
|
---|
265 | switch (uMsg)
|
---|
266 | {
|
---|
267 | case ACM_OPENA:
|
---|
268 | return ANIMATE_OpenA (hwnd, wParam, lParam);
|
---|
269 |
|
---|
270 | /* case ACM_OPEN32W: */
|
---|
271 | /* return ANIMATE_Open32W (hwnd, wParam, lParam); */
|
---|
272 |
|
---|
273 | case ACM_PLAY:
|
---|
274 | return ANIMATE_Play (hwnd, wParam, lParam);
|
---|
275 |
|
---|
276 | case ACM_STOP:
|
---|
277 | return ANIMATE_Stop (hwnd, wParam, lParam);
|
---|
278 |
|
---|
279 |
|
---|
280 | case WM_CREATE:
|
---|
281 | return ANIMATE_Create (hwnd, wParam, lParam);
|
---|
282 |
|
---|
283 | case WM_DESTROY:
|
---|
284 | return ANIMATE_Destroy (hwnd, wParam, lParam);
|
---|
285 |
|
---|
286 | /* case WM_ERASEBKGND: */
|
---|
287 | /* return ANIMATE_EraseBackground (hwnd, wParam, lParam); */
|
---|
288 |
|
---|
289 | /* case WM_NCCREATE: */
|
---|
290 | /* case WM_NCHITTEST: */
|
---|
291 | /* case WM_PAINT: */
|
---|
292 | /* case WM_SIZE: */
|
---|
293 | /* case WM_STYLECHANGED: */
|
---|
294 | /* case WM_TIMER: */
|
---|
295 |
|
---|
296 | default:
|
---|
297 | // if (uMsg >= WM_USER)
|
---|
298 | // ERR (animate, "unknown msg %04x wp=%08x lp=%08lx\n",
|
---|
299 | // uMsg, wParam, lParam);
|
---|
300 | return DefWindowProcA (hwnd, uMsg, wParam, lParam);
|
---|
301 | }
|
---|
302 | return 0;
|
---|
303 | }
|
---|
304 |
|
---|
305 |
|
---|
306 | VOID
|
---|
307 | ANIMATE_Register (VOID)
|
---|
308 | {
|
---|
309 | WNDCLASSA wndClass;
|
---|
310 |
|
---|
311 | if (GlobalFindAtomA (ANIMATE_CLASSA)) return;
|
---|
312 |
|
---|
313 | ZeroMemory (&wndClass, sizeof(WNDCLASSA));
|
---|
314 | wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
|
---|
315 | wndClass.lpfnWndProc = (WNDPROC)ANIMATE_WindowProc;
|
---|
316 | wndClass.cbClsExtra = 0;
|
---|
317 | wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
|
---|
318 | wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
|
---|
319 | wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
|
---|
320 | wndClass.lpszClassName = ANIMATE_CLASSA;
|
---|
321 |
|
---|
322 | RegisterClassA (&wndClass);
|
---|
323 | }
|
---|
324 |
|
---|
325 |
|
---|
326 | VOID
|
---|
327 | ANIMATE_Unregister (VOID)
|
---|
328 | {
|
---|
329 | if (GlobalFindAtomA (ANIMATE_CLASSA))
|
---|
330 | UnregisterClassA (ANIMATE_CLASSA, (HINSTANCE)NULL);
|
---|
331 | }
|
---|
332 |
|
---|