Author: Tomas Rutkauskas
Delphi FLIC component - a starting point
Answer:
I have included two files:
aaplay1.inc - an include file with the interface defs for aaplay.dll
aaplay1.pas - a very skeletal flic-playing component
You need a copy of aaplay.dll from Autodesk.
1 {aaplay1.inc}
2 {Header file containing constant and type definitions for aaplay1.pas}
3 const
4 NULL = 0;
5 NULLPTR = ^0;
6 {Valid flags in wMode: integer; Used in aaLoad, aaReLoad. The low order eight
7 bits of wMode is used in aa_flags.}
8 AA_MEMORYLOAD = $1; { Load into memory }
9 AA_HIDEWINDOW = $2; { Hide the animation window }
10 AA_NOPALETTE = $4; { Prevent palette animation }
11 AA_RESERVEPALETTE = $8; { Reserve entire palette at start }
12 AA_LOOPFRAME = $10; { Loaded with a loop frame }
13 AA_FULLSCREEN = $20; { Use full screen for playing }
14 AA_STOPNOTIFY = $40; { Prevent any notification messages }
15 AA_STOPSTATUS = $80; { Prevent status messages }
16 AA_NOFAIL = $100; { Reduce load type on fail }
17 AA_DONTPAINT = $200; { Don't paByVal animation when loading }
18 AA_BUILDSCRIPT = $400; { lpzFileName is script not name }
19 AA_ALLMODES = $FF; {Valid flags for the sound mode - wMode: integer; Used in
20 aaSound}
21 AA_SNDFREEZE = $1; { Freeze frames until sound begins }
22 AA_SNDDEVICEID = $100; { device is an ID not a name }
23 AA_SNDBUILDALIAS = $200; { create sound device alias }
24 {aaNotify allows an application to be notified at specific frames when an
25 animation is playing.
26 lPosition is the position at which the notification is to take place. The wParam
27 for this message is
28 hAa, and the lParam is copied from this call. Returns TRUE if the notification is
29 set. This value for
30 the loops will cause the animation to end when the sound has finished. If no sound
31 is playing, the
32 animation will loop forever.}
33 AA_LOOPSOUND = $FFFF;
34 {An automatic notify is sent when an animation in a script is reloaded. The lParam
35 of this message is defined below}
36 AA_ANIMATIONLOADED = 0;
37 {The parameter types Used with aaGetParm and aaSetParm.}
38 AA_STATUS = 1; { Get current status }
39 AA_FILETYPE = 2; { Get Type of animation on disk }
40 AA_MODE = 3; { Get/Set Animation Flags }
41 AA_WINDOW = 4; { Set/Get animation window }
42 AA_SPEED = 5; { Set/Get current speed }
43 AA_DESIGNSPEED = 6; { Get design speed }
44 AA_FRAMES = 7; { Get Number of frames }
45 AA_POSITION = 8; { Set/Get current frame position }
46 AA_LOOPS = 9; { Set/Get number of loops }
47 AA_X = 10; { Set/Get Pos of display window }
48 AA_Y = 11; { Set/Get Pos of display window }
49 AA_CX = 12; { Set/Get extents of display window }
50 AA_CY = 13; { Set/Get extents of display window }
51 AA_ORGX = 14; { Set/Get Origin of display window }
52 AA_ORGY = 15; { Set/Get Origin of display window }
53 AA_WIDTH = 16; { Get Width of animation }
54 AA_HEIGHT = 17; { Get Height of animation }
55 AA_RPTSOUND = 18; { Set/Get sound repeats }
56 AA_PAUSE = 19; { Set/Get pause time }
57 AA_DELAYSND = 20; { Set/Get sound delay time }
58 AA_TRANSIN = 21; { Set/Get Transition In type }
59 AA_TRANSOUT = 22; { Set/Get Transition Out type }
60 AA_TIMEIN = 23; { Set/Get Transition In time }
61 AA_TIMEOUT = 24; { Set/Get Transition Out Time }
62 AA_CALLBACK = 25; { Set/Get CallBack window }
63 AA_ANIMWND = 26; { Get Animation Window Handle }
64 AA_MODFLAG = 100; { Set/Get Script is modified flag }
65 AA_SCRIPTNAME = 101; { Set/Get Script name }
66 AA_ANIMATION = 102; { Get/Set Script Animation }
67 AA_ANIMATIONCOUNT = 103; { Get Script Animation Count }
68 AA_SCRIPTCONTENTS = 104; { Get Script Contents }
69 AA_LASTERROR = 1001; { Get last error code }
70 AA_LASTERRORMESSAGE = 1002; { Get/Set last error messsage }
71 {The parameter types Used with aaSetParmIndirect}
72 AA_SETMODE = $1; { Get/Set Animation Flags }
73 AA_SETWINDOW = $2; { Set/Get animation window }
74 AA_SETSPEED = $4; { Set/Get current speed }
75 AA_SETPOSITION = $8; { Set/Get current frame position }
76 AA_SETLOOPS = $10; { Set/Get number of loops }
77 AA_SETX = $20; { Set/Get left of display window }
78 AA_SETY = $40; { Set/Get left of display window }
79 AA_SETCX = $80; { Set/Get top of display window }
80 AA_SETCY = $100; { Set/Get top of display window }
81 AA_SETORGX = $200; { Set/Get width of display window }
82 AA_SETORGY = $400; { Set/Get width of display window }
83 AA_SETRPTSOUND = $800; { Set/Get sound repeats }
84 AA_SETPAUSE = $1000; { Set/Get pause time }
85 AA_SETDELAYSND = $2000; { Set/Get sound delay time }
86 AA_SETTRANSIN = $4000; { Set/Get Transition In type }
87 AA_SETTRANSOUT = $8000; { Set/Get Transition Out type }
88 AA_SETTIMEIN = $10000; { Set/Get Transition In time }
89 AA_SETTIMEOUT = $20000; { Set/Get Transition Out Time }
90 AA_SETCALLBACK = $40000; { Set/Get Callback window }
91 AA_ALL = $FFFFFFFF; { Get/Set all parameters }
92 {Status values for an animation}
93 AA_STOPPED = 1; { Loaded but not playing }
94 AA_QUEUED = 2; { Animation is waiting to play }
95 AA_PLAYING = 3; { Animation is playing }
96 AA_PAUSED = 4; { Animation is paused }
97 AA_DONE = 5; { Animation has ended playing and is awaiting an aaStop call }
98 {File type definitions}
99 AA_FLI = $1; { Autodesk Animator Fli format }
100 AA_DIB = $2; { Windows DIB format }
101 AA_NUMTYPES = $2; { Number of types }
102 AA_SCRIPT = $3; { Script without an animation }
103 {Transition types}
104 AA_CUT = 0; { Just stop one and start another }
105 AA_FADEBLACK = $1; { Fade In/Out from to black }
106 AA_FADEWHITE = $2; { Fade In/Out from to white }
107 {Error codes returned by aaGetParm(xxx, AA_LASTERROR)}
108 AA_ERR_NOERROR = 0; { Unknown error }
109 AA_ERR_NOMEMORY = $100; { 256 - Out of memory error }
110 AA_ERR_BADHANDLE = $101; { 257 - Bad handle }
111 AA_ERR_NOTIMERS = $102; { 258 - Cannot start timer }
112 AA_ERR_BADSOUND = $103; { 259 - Bad sound spec }
113 AA_ERR_NOSCRIPT = $104; { 260 - Requires a script }
114 AA_ERR_WRITEERR = $105; { 261 - Write error for script }
115 AA_ERR_BADANIMATION = $106; { 262 - Cannot open animation }
116 AA_ERR_BADWINDOWHANDLE = $200; { 512 - Bad Window Handle }
117 AA_ERR_WINDOWCREATE = $201; { 513 - Cannot create window }
118 AA_ERR_DLGERROR = $202; { 514 - Dialog error }
119 AA_ERR_INVALIDSTATUS = $300; { 768 - Invalid status }
120 AA_ERR_BADDIBFORMAT = $301; { 769 - Bad dib file }
121 AA_ERR_BADFLIFORMAT = $302; { 770 - Bad fli file }
122 AA_ERR_UNRECOGNIZEDFORMAT = $303; { 771 - Unrecognized format }
123 AA_ERR_NOSOUND = $304; { 772 - Sound not supported }
124 AA_ERR_NOTVALIDFORSCRIPTS = $305; { 773 - Not valid for scripts }
125 AA_ERR_INVALIDFILE = $306; { 774 - Bad file handle }
126 AA_ERR_NOSCRIPTS = $307; { 775 - No Script files }
127 AA_ERR_SPEED = $400; { 1024 - Invalid speed }
128 AA_ERR_LOOPS = $401; { 1025 - invalid loops }
129 AA_ERR_RPTSOUND = $402; { 1026 - invalid repeat sound }
130 AA_ERR_PAUSE = $403; { 1027 - invalid pause }
131 AA_ERR_TRANSIN = $404; { 1028 - invalid transition }
132 AA_ERR_TIMEIN = $405; { 1029 - invalid transition }
133 AA_ERR_TRANSOUT = $406; { 1030 - invalid transition time }
134 AA_ERR_TIMEOUT = $407; { 1031 - invalid transition time }
135 AA_ERR_DELAYSND = $408; { 1032 - invalid sound delay }
136 AA_ERR_INVALIDTYPE = $409; { 1033 - invalid parameter type }
137 AA_ERR_DUPLICATENOTIFY = $500; { 1280 - duplicate notify }
138 AA_ERR_NOSWITCH = $600; { 1536 - no switch in script }
139 AA_ERR_PARSELOOPS = $601; { 1537 - Bad loops in script }
140 AA_ERR_PARSESPEED = $602; { 1538 - Bad speed in script }
141 AA_ERR_BADRPTSOUND = $603; { 1539 - Bad repeat sound in script }
142 AA_ERR_PARSEPAUSE = $604; { 1540 - Bad pause in script }
143 AA_ERR_PARSETRANS = $605; { 1541 - Bad tranisition in script }
144 AA_ERR_PARSEDELAYSND = $606; { 1542 - Bad delay sound in script }
145 AA_ERR_TOOMANYLINKS = $607; { 1543 - Too many links }
146 {dwFlags: integer; can be any of the following Used in aaGetFile.}
147 AA_GETFILE_MUSTEXIST = $1;
148 AA_GETFILE_NOSHOWSPEC = $2;
149 AA_GETFILE_SAVE = $4;
150 AA_GETFILE_OPEN = $8;
151 AA_GETFILE_USEDIR = $10;
152 AA_GETFILE_USEFILE = $20;
153 AA_GETFILE_SOUND = $40;
154 AA_GETFILE_SCRIPT = $80;
155 AA_GETFILE_ANIMATION = $100;
156 {wMode: integer; Values Used in aaSave}
157 AA_SAVE_IFMODIFIED = $1;
158 AA_SAVE_AS = $2;
159 AA_SAVE_CANCEL = $4;
160 {Capabitlities Used in aaGetCaps}
161 AA_CAP_TIMER = 1;
162 AA_CAP_SOUND = 2;
163 AA_CAP_SCRIPT = 3;
164 {Animation status messages Use RegisterWindowMessage to get the real message
165 numbers.}
166 AA_NOTIFY = 'AAPLAY Notify'; { notification message }
167 AA_STOP = 'AAPLAY Stop'; { stop message }
168 {These are sent in the low word of lParam with the AA_ERROR message.
169 They indicate the error that occured}
170 AA_BADPLAY = 1; { Error attempting to play }
171 AA_BADNOTIFY = 2; { Error attempting to notify }
172 AA_BADSCRIPT = 3; { Error attempting to animation in script }
173
174 unit aaplay1;
175
176 interface
177
178 uses
179 SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
180 Forms, Dialogs, MPlayer;
181
182 {$I AAPLAY1.INC}
183
184 const
185 AAPARMS_SIZE = 54;
186
187 type
188 AAHandle = word; { Handle to an animation }
189 AASPEED = word; { Type that holds speed for animation }
190 AATRN = word; { Type that holds transition for animation }
191 dword = longint;
192 {The parameter structure to be used for the animation.}
193 AAPARMS = record
194 AA_STATUS: byte; { Current status of animation }
195 AA_FILETYPE: byte; { Type of file on disk }
196 AA_MODE: byte; { Some flags }
197 AA_bitpix: byte; { bits per pixel }
198 AA_HWnd: HWnd; { Handle of window for status messages }
199 AA_X: integer; { Left of display window }
200 AA_Y: integer; { Top of display window }
201 AA_CX: integer; { Width of display window }
202 AA_CY: integer; { Height of display window }
203 AA_ORGX: integer; { PoByVal in the animation displayed }
204 AA_ORGY: integer; { in the upper left corner }
205 AA_SPEED: AASPEED; { Speed of animation in msec per frame }
206 AA_DESIGNSPEED: AASPEED; { Designed milliseconds per frame }
207 AA_WIDTH: word; { Width of animation in pixels }
208 AA_HEIGHT: word; { Height of animation in pixels }
209 AA_FRAMES: word; { Number of frames in animation }
210 AA_POSITION: dword; { Current frame position }
211 AA_LOOPS: dword; { End of animation position }
212 AA_RPTSOUND: word; { Number of times to repeat sound }
213 AA_PAUSE: word; { Number of milliseconds to hold l:t frame }
214 AA_DELAYSND: longint; { Delay Sound in milliseconds }
215 AA_TRANSIN: byte; { Transition at start of animation }
216 AA_TRANSOUT: byte; { Transition at end of animation }
217 AA_TIMEIN: word; { Length of transition in, milliseconds }
218 AA_TIMEOUT: word; { Length of transition out, milliseconds }
219 AA_CALLBACK: HWnd; { message callback window }
220 AA_ANIMWND: Hwnd; { Animation Window Handle }
221 end;
222 AAPARMSPtr = ^AAPARMS;
223
224 type
225 TAAPlayer = class(TMediaPlayer)
226 procedure OpenAA;
227 private
228 { Private declarations }
229 protected
230 { Protected declarations }
231 public
232 { Public declarations }
233 AAParameters: AAPARMS;
234 FlicHandle: AAHandle;
235 PlayWinHandle: THandle;
236 StatusWinHandle: THandle;
237 CallbackWinHandle: THandle;
238 published
239 { Published declarations }
240 end;
241
242 procedure register;
243
244 { External calls to AAPLAY.DLL }
245 function aaOpen: boolean;
246 procedure aaClose;
247 function aaGetCaps(wType: word): word;
248 function aaLoad(lpzFileName: PChar; WinHnd: HWnd; wMode: word; x, y, wid,
249 hght, orgx, orgy: integer): AAHandle;
250 function aaReLoad(hAa: AAHandle; lpzFileName: PChar; wMode, wMask: word): boolean;
251 function aaUnload(hAa: AAHandle): boolean;
252 function aaPlay(hAa: AAHandle): boolean;
253 function aaNotify(hAa: AAHandle; lPosition, lParam: longint): boolean;
254 function aaCancel(hAa: AAHandle; lLoPos, lHiPos: longint): word;
255 function aaStop(hAa: AAHandle): boolean;
256 function aaPause(hAa: AAHandle): boolean;
257 function aaPrompt(hAa: AAHandle; lpName: PChar): boolean;
258 function aaGetParm(hAa: AAHandle; wType: word): longint;
259 function aaGetParmIndirect(hAa: AAHandle; lpAp: AAPARMSPtr; wSize: word): boolean;
260 function aaSetParm(hAa: AAHandle; wType: word; wValue1, lValue2: longint): AAHandle;
261 function aaSetParmIndirect(hAa: AAHandle; dwType: longint; lpAp: AAPARMSPtr;
262 wMask: word): boolean;
263 function aaShow(hAa: AAHandle; bShow: boolean): boolean;
264 function aaSound(hAa: AAHandle; device, ffile: PChar; wMode: word): boolean;
265 function aaGetFile(dwFlags: word; lpszPath: PChar; wBufLen: word;
266 lpszDriver: PChar; wDrvLen: word): integer;
267 function aaSave(hAa: AAHandle; wMode: word): integer;
268
269 implementation
270
271 procedure register;
272 begin
273 RegisterComponents('Samples', [TAAPlayer]);
274 end;
275
276 procedure TAAPlayer.OpenAA;
277 var
278 FileSuffix, tempstr: string[12];
279 a, b: integer;
280 begin
281 tempstr := ExtractFilename(AAPlayer.Filename);
282 a := StrPos(tempstr, '.');
283 if (a > 0) then
284 begin
285 b := a;
286 while (b <= StrLen(tmpstr)) do
287 begin
288 FileSuffix := FileSuffix + StrUpper(tempstr[b]);
289 b := b + 1;
290 end;
291 if ((FileSuffix = '.FLC') or (FileSuffix = '.FLI')) then
292 begin
293 AutoEnable := False;
294 EnabledButtons := [btRecord, btEject];
295 end;
296 end;
297 end;
298
299 { External calls to 'AAPLAY.DLL' }
300 {$F+}
301
302 function aaOpen: boolean;
303 external 'AAPLAY';
304
305 procedure aaClose;
306 external 'AAPLAY';
307 {AAOpen and AAClose are not really needed, except there is a bug in Windows
308 which prevents Libraries from being freed in the Windows Exit Proc (WEP). So we
309 use AAClose to free the Libraries when the last task closes the AAPlay DLL.}
310
311 function aaGetCaps(wType: word): word;
312 external 'AAPLAY';
313
314 {Get Capabitities}
315 function aaLoad(lpzFileName: PChar; WinHnd: HWnd; wMode: word;
316 x, y, wid, hght, orgx, orgy: integer): AAHandle;
317 external 'AAPLAY';
318 {aaLoad loads an animation. The file name is in lpzFileName and the loading mode is
319 in wMode.}
320
321 function aaReLoad(hAa: AAHandle; lpzFileName: PChar; wMode, wMask: word): boolean;
322 external 'AAPLAY';
323 {aaReLoad will load a new animation file into an old animation handle.
324 Notifications are lost, but the palette and window are retained.}
325
326 function aaUnload(hAa: AAHandle): boolean;
327 external 'AAPLAY';
328 {aaUnload unloads a loaded animation. FALSE is returned if hAa is not the handle
329 of a loaded animation.}
330
331 function aaPlay(hAa: AAHandle): boolean;
332 external 'AAPLAY';
333 {aaPlay plays a loaded animation. TRUE is returned if the animation is not stopped
334 when aaPlay returns.}
335
336 function aaNotify(hAa: AAHandle; lPosition, lParam: longint): boolean;
337 external 'AAPLAY';
338 {aaNotify allows an application to be notified at specific frames when an animation
339 is playing. lPosition is the position at which the notification is to take place.
340 The
341 wParam for this message is hAa, and the lParam is copied from this call. Returns
342 TRUE if the notification is set.}
343
344 function aaCancel(hAa: AAHandle; lLoPos, lHiPos: longint): word;
345 external 'AAPLAY';
346 {aaCancel allows an application to cancel notifications set by aaNotify. lLoPos and
347 lHiPos give lower and upper limits on positions. Returns the number of notifications
348 canceled.}
349
350 function aaStop(hAa: AAHandle): boolean;
351 external 'AAPLAY';
352 {aaStop will stop a playing animation. TRUE is returned if the animation is stopped
353 when aaStop returns.}
354
355 function aaPause(hAa: AAHandle): boolean;
356 external 'AAPLAY';
357 {aaPause will pause an animation. TRUE is returned if the animation is paused when
358 aaPause returns. To resume a paused animation, use aaPlay.}
359
360 function aaPrompt(hAa: AAHandle; lpName: PChar): boolean;
361 external 'AAPLAY';
362 {aaPrompt will produce a dialog to prompt for user input. When input is accepted,
363 the
364 handle is changed to reflect the new parameters. The old handle is not destroyed
365 until
366 the new handle has been created. aaPrompt returns NULL if the new handle cannot be
367 created, otherwise the new handle is returned.}
368
369 function aaGetParm(hAa: AAHandle; wType: word): longint;
370 external 'AAPLAY';
371 {aaGetParm will return information on an animation. Some of the information can be
372 set
373 with aaSetParm, and other information is state information maintained by AAPLAY.}
374
375 function aaGetParmIndirect(hAa: AAHandle; lpAp: AAPARMSPtr; wSize: word): boolean;
376 external 'AAPLAY';
377 {aaGetParmIndirect returns the same information as aaGetParm, in a structure for
378 easy
379 access by Visual Basic applications.}
380
381 function aaSetParm(hAa: AAHandle; wType: word; wValue1, lValue2: longint): AAHandle;
382 external 'AAPLAY';
383 {aaSetParm will set information on an animation}
384
385 function aaSetParmIndirect(hAa: AAHandle; dwType: longint;
386 lpAp: AAPARMSPtr; wMask: word): boolean;
387 external 'AAPLAY';
388 {aaSetParmIndirect will set animation parameters from a structure.}
389
390 function aaShow(hAa: AAHandle; bShow: boolean): boolean;
391 external 'AAPLAY';
392 {aaShow will show a single frame of an animation in a window. The mode determines
393 how the animation is drawn. The window used is set using either aaSetParm or
394 aaSetParmIndirect. aaShow returns TRUE if the animation was successfully drawn.}
395
396 function aaSound(hAa: AAHandle; device, ffile: PChar; wMode: word): boolean;
397 external 'AAPLAY';
398 {aaSound will open or close a sound for the animation. The sound is opened if the
399 file
400 arguement is not null and not blank%, otherwise the sound is closed. If device is
401 null,
402 the format of the file is used to select an appropriate device.}
403
404 function aaGetFile(dwFlags: word; lpszPath: PChar; wBufLen: word;
405 lpszDriver: PChar; wDrvLen: word): integer;
406 external 'AAPLAY';
407 {Opens a dialog box querying the user for a file in the standard windows file open
408 box
409 style. dwFlags determines how the dialog box will appear. It may be the following:
410 AA_GETFILE_MUSTEXIST
411 Selected file must satisfy conditions of OpenFile() flags, else dialog beeps.
412 AA_GETFILE_NOSHOWSPEC
413 Do not show the search spec in the edit box. Default IS to show the spec.
414 AA_GETFILE_SAVE
415 Ok button will show "Save".
416 AA_GETFILE_OPEN
417 Ok button will show "Open".
418 AA_GETFILE_USEFILE
419 Set the filename to the file in lpszPath
420 AA_GETFILE_UDEDIR
421 Change to the directory in lpszPath
422 AA_GETFILE_SOUND
423 Get sound file and driver
424 AA_GETFILE_SCRIPT
425 Get script file
426 AA_GETFILE_ANIMATION
427 Get Animation File (no scripts)
428
429 lpszPath is a LPSTR to a string buffer into which the final fully qualified pathname
430 will be written.
431 wBufLen is the length of this buffer.
432 lpszDriver is a LPSTR to a string buffer into which a sound device selection is
433 placed.
434 wDrvLen is the length of this buffer.
435 Return value is: 0 if cancel was hit, -1 if OpenFile() failed but
436 AA_GETFILE_MUSTEXIST
437 was not specified. DOS file handle of selected file, otherwise. This handle is not
438 open when
439 aaOpenFile returns.}
440
441 function aaSave(hAa: AAHandle; wMode: word): integer;
442 external 'AAPLAY';
443 {Save a script}
444
445 {$F-}
446 { End of external calls to 'AAPLAY.DLL' }
447 end.
|