2004. október 29., péntek
Delphi FLIC component - a starting point
Problem/Question/Abstract:
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.
{aaplay1.inc}
{Header file containing constant and type definitions for aaplay1.pas}
const
NULL = 0;
NULLPTR = ^0;
{Valid flags in wMode: integer; Used in aaLoad, aaReLoad. The low order eight bits of wMode is used in aa_flags.}
AA_MEMORYLOAD = $1; { Load into memory }
AA_HIDEWINDOW = $2; { Hide the animation window }
AA_NOPALETTE = $4; { Prevent palette animation }
AA_RESERVEPALETTE = $8; { Reserve entire palette at start }
AA_LOOPFRAME = $10; { Loaded with a loop frame }
AA_FULLSCREEN = $20; { Use full screen for playing }
AA_STOPNOTIFY = $40; { Prevent any notification messages }
AA_STOPSTATUS = $80; { Prevent status messages }
AA_NOFAIL = $100; { Reduce load type on fail }
AA_DONTPAINT = $200; { Don't paByVal animation when loading }
AA_BUILDSCRIPT = $400; { lpzFileName is script not name }
AA_ALLMODES = $FF; {Valid flags for the sound mode - wMode: integer; Used in aaSound}
AA_SNDFREEZE = $1; { Freeze frames until sound begins }
AA_SNDDEVICEID = $100; { device is an ID not a name }
AA_SNDBUILDALIAS = $200; { create sound device alias }
{aaNotify allows an application to be notified at specific frames when an animation is playing.
lPosition is the position at which the notification is to take place. The wParam for this message is
hAa, and the lParam is copied from this call. Returns TRUE if the notification is set. This value for
the loops will cause the animation to end when the sound has finished. If no sound is playing, the
animation will loop forever.}
AA_LOOPSOUND = $FFFF;
{An automatic notify is sent when an animation in a script is reloaded. The lParam
of this message is defined below}
AA_ANIMATIONLOADED = 0;
{The parameter types Used with aaGetParm and aaSetParm.}
AA_STATUS = 1; { Get current status }
AA_FILETYPE = 2; { Get Type of animation on disk }
AA_MODE = 3; { Get/Set Animation Flags }
AA_WINDOW = 4; { Set/Get animation window }
AA_SPEED = 5; { Set/Get current speed }
AA_DESIGNSPEED = 6; { Get design speed }
AA_FRAMES = 7; { Get Number of frames }
AA_POSITION = 8; { Set/Get current frame position }
AA_LOOPS = 9; { Set/Get number of loops }
AA_X = 10; { Set/Get Pos of display window }
AA_Y = 11; { Set/Get Pos of display window }
AA_CX = 12; { Set/Get extents of display window }
AA_CY = 13; { Set/Get extents of display window }
AA_ORGX = 14; { Set/Get Origin of display window }
AA_ORGY = 15; { Set/Get Origin of display window }
AA_WIDTH = 16; { Get Width of animation }
AA_HEIGHT = 17; { Get Height of animation }
AA_RPTSOUND = 18; { Set/Get sound repeats }
AA_PAUSE = 19; { Set/Get pause time }
AA_DELAYSND = 20; { Set/Get sound delay time }
AA_TRANSIN = 21; { Set/Get Transition In type }
AA_TRANSOUT = 22; { Set/Get Transition Out type }
AA_TIMEIN = 23; { Set/Get Transition In time }
AA_TIMEOUT = 24; { Set/Get Transition Out Time }
AA_CALLBACK = 25; { Set/Get CallBack window }
AA_ANIMWND = 26; { Get Animation Window Handle }
AA_MODFLAG = 100; { Set/Get Script is modified flag }
AA_SCRIPTNAME = 101; { Set/Get Script name }
AA_ANIMATION = 102; { Get/Set Script Animation }
AA_ANIMATIONCOUNT = 103; { Get Script Animation Count }
AA_SCRIPTCONTENTS = 104; { Get Script Contents }
AA_LASTERROR = 1001; { Get last error code }
AA_LASTERRORMESSAGE = 1002; { Get/Set last error messsage }
{The parameter types Used with aaSetParmIndirect}
AA_SETMODE = $1; { Get/Set Animation Flags }
AA_SETWINDOW = $2; { Set/Get animation window }
AA_SETSPEED = $4; { Set/Get current speed }
AA_SETPOSITION = $8; { Set/Get current frame position }
AA_SETLOOPS = $10; { Set/Get number of loops }
AA_SETX = $20; { Set/Get left of display window }
AA_SETY = $40; { Set/Get left of display window }
AA_SETCX = $80; { Set/Get top of display window }
AA_SETCY = $100; { Set/Get top of display window }
AA_SETORGX = $200; { Set/Get width of display window }
AA_SETORGY = $400; { Set/Get width of display window }
AA_SETRPTSOUND = $800; { Set/Get sound repeats }
AA_SETPAUSE = $1000; { Set/Get pause time }
AA_SETDELAYSND = $2000; { Set/Get sound delay time }
AA_SETTRANSIN = $4000; { Set/Get Transition In type }
AA_SETTRANSOUT = $8000; { Set/Get Transition Out type }
AA_SETTIMEIN = $10000; { Set/Get Transition In time }
AA_SETTIMEOUT = $20000; { Set/Get Transition Out Time }
AA_SETCALLBACK = $40000; { Set/Get Callback window }
AA_ALL = $FFFFFFFF; { Get/Set all parameters }
{Status values for an animation}
AA_STOPPED = 1; { Loaded but not playing }
AA_QUEUED = 2; { Animation is waiting to play }
AA_PLAYING = 3; { Animation is playing }
AA_PAUSED = 4; { Animation is paused }
AA_DONE = 5; { Animation has ended playing and is awaiting an aaStop call }
{File type definitions}
AA_FLI = $1; { Autodesk Animator Fli format }
AA_DIB = $2; { Windows DIB format }
AA_NUMTYPES = $2; { Number of types }
AA_SCRIPT = $3; { Script without an animation }
{Transition types}
AA_CUT = 0; { Just stop one and start another }
AA_FADEBLACK = $1; { Fade In/Out from to black }
AA_FADEWHITE = $2; { Fade In/Out from to white }
{Error codes returned by aaGetParm(xxx, AA_LASTERROR)}
AA_ERR_NOERROR = 0; { Unknown error }
AA_ERR_NOMEMORY = $100; { 256 - Out of memory error }
AA_ERR_BADHANDLE = $101; { 257 - Bad handle }
AA_ERR_NOTIMERS = $102; { 258 - Cannot start timer }
AA_ERR_BADSOUND = $103; { 259 - Bad sound spec }
AA_ERR_NOSCRIPT = $104; { 260 - Requires a script }
AA_ERR_WRITEERR = $105; { 261 - Write error for script }
AA_ERR_BADANIMATION = $106; { 262 - Cannot open animation }
AA_ERR_BADWINDOWHANDLE = $200; { 512 - Bad Window Handle }
AA_ERR_WINDOWCREATE = $201; { 513 - Cannot create window }
AA_ERR_DLGERROR = $202; { 514 - Dialog error }
AA_ERR_INVALIDSTATUS = $300; { 768 - Invalid status }
AA_ERR_BADDIBFORMAT = $301; { 769 - Bad dib file }
AA_ERR_BADFLIFORMAT = $302; { 770 - Bad fli file }
AA_ERR_UNRECOGNIZEDFORMAT = $303; { 771 - Unrecognized format }
AA_ERR_NOSOUND = $304; { 772 - Sound not supported }
AA_ERR_NOTVALIDFORSCRIPTS = $305; { 773 - Not valid for scripts }
AA_ERR_INVALIDFILE = $306; { 774 - Bad file handle }
AA_ERR_NOSCRIPTS = $307; { 775 - No Script files }
AA_ERR_SPEED = $400; { 1024 - Invalid speed }
AA_ERR_LOOPS = $401; { 1025 - invalid loops }
AA_ERR_RPTSOUND = $402; { 1026 - invalid repeat sound }
AA_ERR_PAUSE = $403; { 1027 - invalid pause }
AA_ERR_TRANSIN = $404; { 1028 - invalid transition }
AA_ERR_TIMEIN = $405; { 1029 - invalid transition }
AA_ERR_TRANSOUT = $406; { 1030 - invalid transition time }
AA_ERR_TIMEOUT = $407; { 1031 - invalid transition time }
AA_ERR_DELAYSND = $408; { 1032 - invalid sound delay }
AA_ERR_INVALIDTYPE = $409; { 1033 - invalid parameter type }
AA_ERR_DUPLICATENOTIFY = $500; { 1280 - duplicate notify }
AA_ERR_NOSWITCH = $600; { 1536 - no switch in script }
AA_ERR_PARSELOOPS = $601; { 1537 - Bad loops in script }
AA_ERR_PARSESPEED = $602; { 1538 - Bad speed in script }
AA_ERR_BADRPTSOUND = $603; { 1539 - Bad repeat sound in script }
AA_ERR_PARSEPAUSE = $604; { 1540 - Bad pause in script }
AA_ERR_PARSETRANS = $605; { 1541 - Bad tranisition in script }
AA_ERR_PARSEDELAYSND = $606; { 1542 - Bad delay sound in script }
AA_ERR_TOOMANYLINKS = $607; { 1543 - Too many links }
{dwFlags: integer; can be any of the following Used in aaGetFile.}
AA_GETFILE_MUSTEXIST = $1;
AA_GETFILE_NOSHOWSPEC = $2;
AA_GETFILE_SAVE = $4;
AA_GETFILE_OPEN = $8;
AA_GETFILE_USEDIR = $10;
AA_GETFILE_USEFILE = $20;
AA_GETFILE_SOUND = $40;
AA_GETFILE_SCRIPT = $80;
AA_GETFILE_ANIMATION = $100;
{wMode: integer; Values Used in aaSave}
AA_SAVE_IFMODIFIED = $1;
AA_SAVE_AS = $2;
AA_SAVE_CANCEL = $4;
{Capabitlities Used in aaGetCaps}
AA_CAP_TIMER = 1;
AA_CAP_SOUND = 2;
AA_CAP_SCRIPT = 3;
{Animation status messages Use RegisterWindowMessage to get the real message numbers.}
AA_NOTIFY = 'AAPLAY Notify'; { notification message }
AA_STOP = 'AAPLAY Stop'; { stop message }
{These are sent in the low word of lParam with the AA_ERROR message.
They indicate the error that occured}
AA_BADPLAY = 1; { Error attempting to play }
AA_BADNOTIFY = 2; { Error attempting to notify }
AA_BADSCRIPT = 3; { Error attempting to animation in script }
unit aaplay1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, MPlayer;
{$I AAPLAY1.INC}
const
AAPARMS_SIZE = 54;
type
AAHandle = word; { Handle to an animation }
AASPEED = word; { Type that holds speed for animation }
AATRN = word; { Type that holds transition for animation }
dword = longint;
{The parameter structure to be used for the animation.}
AAPARMS = record
AA_STATUS: byte; { Current status of animation }
AA_FILETYPE: byte; { Type of file on disk }
AA_MODE: byte; { Some flags }
AA_bitpix: byte; { bits per pixel }
AA_HWnd: HWnd; { Handle of window for status messages }
AA_X: integer; { Left of display window }
AA_Y: integer; { Top of display window }
AA_CX: integer; { Width of display window }
AA_CY: integer; { Height of display window }
AA_ORGX: integer; { PoByVal in the animation displayed }
AA_ORGY: integer; { in the upper left corner }
AA_SPEED: AASPEED; { Speed of animation in msec per frame }
AA_DESIGNSPEED: AASPEED; { Designed milliseconds per frame }
AA_WIDTH: word; { Width of animation in pixels }
AA_HEIGHT: word; { Height of animation in pixels }
AA_FRAMES: word; { Number of frames in animation }
AA_POSITION: dword; { Current frame position }
AA_LOOPS: dword; { End of animation position }
AA_RPTSOUND: word; { Number of times to repeat sound }
AA_PAUSE: word; { Number of milliseconds to hold l:t frame }
AA_DELAYSND: longint; { Delay Sound in milliseconds }
AA_TRANSIN: byte; { Transition at start of animation }
AA_TRANSOUT: byte; { Transition at end of animation }
AA_TIMEIN: word; { Length of transition in, milliseconds }
AA_TIMEOUT: word; { Length of transition out, milliseconds }
AA_CALLBACK: HWnd; { message callback window }
AA_ANIMWND: Hwnd; { Animation Window Handle }
end;
AAPARMSPtr = ^AAPARMS;
type
TAAPlayer = class(TMediaPlayer)
procedure OpenAA;
private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
AAParameters: AAPARMS;
FlicHandle: AAHandle;
PlayWinHandle: THandle;
StatusWinHandle: THandle;
CallbackWinHandle: THandle;
published
{ Published declarations }
end;
procedure Register;
{ External calls to AAPLAY.DLL }
function aaOpen: boolean;
procedure aaClose;
function aaGetCaps(wType: word): word;
function aaLoad(lpzFileName: PChar; WinHnd: HWnd; wMode: word; x, y, wid,
hght, orgx, orgy: integer): AAHandle;
function aaReLoad(hAa: AAHandle; lpzFileName: PChar; wMode, wMask: word): boolean;
function aaUnload(hAa: AAHandle): boolean;
function aaPlay(hAa: AAHandle): boolean;
function aaNotify(hAa: AAHandle; lPosition, lParam: longint): boolean;
function aaCancel(hAa: AAHandle; lLoPos, lHiPos: longint): word;
function aaStop(hAa: AAHandle): boolean;
function aaPause(hAa: AAHandle): boolean;
function aaPrompt(hAa: AAHandle; lpName: PChar): boolean;
function aaGetParm(hAa: AAHandle; wType: word): longint;
function aaGetParmIndirect(hAa: AAHandle; lpAp: AAPARMSPtr; wSize: word): boolean;
function aaSetParm(hAa: AAHandle; wType: word; wValue1, lValue2: longint): AAHandle;
function aaSetParmIndirect(hAa: AAHandle; dwType: longint; lpAp: AAPARMSPtr;
wMask: word): boolean;
function aaShow(hAa: AAHandle; bShow: boolean): boolean;
function aaSound(hAa: AAHandle; device, ffile: PChar; wMode: word): boolean;
function aaGetFile(dwFlags: word; lpszPath: PChar; wBufLen: word;
lpszDriver: PChar; wDrvLen: word): integer;
function aaSave(hAa: AAHandle; wMode: word): integer;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TAAPlayer]);
end;
procedure TAAPlayer.OpenAA;
var
FileSuffix, tempstr: string[12];
a, b: integer;
begin
tempstr := ExtractFilename(AAPlayer.Filename);
a := StrPos(tempstr, '.');
if (a > 0) then
begin
b := a;
while (b <= StrLen(tmpstr)) do
begin
FileSuffix := FileSuffix + StrUpper(tempstr[b]);
b := b + 1;
end;
if ((FileSuffix = '.FLC') or (FileSuffix = '.FLI')) then
begin
AutoEnable := False;
EnabledButtons := [btRecord, btEject];
end;
end;
end;
{ External calls to 'AAPLAY.DLL' }
{$F+}
function aaOpen: boolean;
external 'AAPLAY';
procedure aaClose;
external 'AAPLAY';
{AAOpen and AAClose are not really needed, except there is a bug in Windows
which prevents Libraries from being freed in the Windows Exit Proc (WEP). So we
use AAClose to free the Libraries when the last task closes the AAPlay DLL.}
function aaGetCaps(wType: word): word;
external 'AAPLAY';
{Get Capabitities}
function aaLoad(lpzFileName: PChar; WinHnd: HWnd; wMode: word;
x, y, wid, hght, orgx, orgy: integer): AAHandle;
external 'AAPLAY';
{aaLoad loads an animation. The file name is in lpzFileName and the loading mode is in wMode.}
function aaReLoad(hAa: AAHandle; lpzFileName: PChar; wMode, wMask: word): boolean;
external 'AAPLAY';
{aaReLoad will load a new animation file into an old animation handle.
Notifications are lost, but the palette and window are retained.}
function aaUnload(hAa: AAHandle): boolean;
external 'AAPLAY';
{aaUnload unloads a loaded animation. FALSE is returned if hAa is not the handle
of a loaded animation.}
function aaPlay(hAa: AAHandle): boolean;
external 'AAPLAY';
{aaPlay plays a loaded animation. TRUE is returned if the animation is not stopped
when aaPlay returns.}
function aaNotify(hAa: AAHandle; lPosition, lParam: longint): boolean;
external 'AAPLAY';
{aaNotify allows an application to be notified at specific frames when an animation
is playing. lPosition is the position at which the notification is to take place. The
wParam for this message is hAa, and the lParam is copied from this call. Returns
TRUE if the notification is set.}
function aaCancel(hAa: AAHandle; lLoPos, lHiPos: longint): word;
external 'AAPLAY';
{aaCancel allows an application to cancel notifications set by aaNotify. lLoPos and
lHiPos give lower and upper limits on positions. Returns the number of notifications
canceled.}
function aaStop(hAa: AAHandle): boolean;
external 'AAPLAY';
{aaStop will stop a playing animation. TRUE is returned if the animation is stopped
when aaStop returns.}
function aaPause(hAa: AAHandle): boolean;
external 'AAPLAY';
{aaPause will pause an animation. TRUE is returned if the animation is paused when
aaPause returns. To resume a paused animation, use aaPlay.}
function aaPrompt(hAa: AAHandle; lpName: PChar): boolean;
external 'AAPLAY';
{aaPrompt will produce a dialog to prompt for user input. When input is accepted, the
handle is changed to reflect the new parameters. The old handle is not destroyed until
the new handle has been created. aaPrompt returns NULL if the new handle cannot be
created, otherwise the new handle is returned.}
function aaGetParm(hAa: AAHandle; wType: word): longint;
external 'AAPLAY';
{aaGetParm will return information on an animation. Some of the information can be set
with aaSetParm, and other information is state information maintained by AAPLAY.}
function aaGetParmIndirect(hAa: AAHandle; lpAp: AAPARMSPtr; wSize: word): boolean;
external 'AAPLAY';
{aaGetParmIndirect returns the same information as aaGetParm, in a structure for easy
access by Visual Basic applications.}
function aaSetParm(hAa: AAHandle; wType: word; wValue1, lValue2: longint): AAHandle;
external 'AAPLAY';
{aaSetParm will set information on an animation}
function aaSetParmIndirect(hAa: AAHandle; dwType: longint;
lpAp: AAPARMSPtr; wMask: word): boolean;
external 'AAPLAY';
{aaSetParmIndirect will set animation parameters from a structure.}
function aaShow(hAa: AAHandle; bShow: boolean): boolean;
external 'AAPLAY';
{aaShow will show a single frame of an animation in a window. The mode determines
how the animation is drawn. The window used is set using either aaSetParm or
aaSetParmIndirect. aaShow returns TRUE if the animation was successfully drawn.}
function aaSound(hAa: AAHandle; device, ffile: PChar; wMode: word): boolean;
external 'AAPLAY';
{aaSound will open or close a sound for the animation. The sound is opened if the file
arguement is not null and not blank%, otherwise the sound is closed. If device is null,
the format of the file is used to select an appropriate device.}
function aaGetFile(dwFlags: word; lpszPath: PChar; wBufLen: word;
lpszDriver: PChar; wDrvLen: word): integer;
external 'AAPLAY';
{Opens a dialog box querying the user for a file in the standard windows file open box
style. dwFlags determines how the dialog box will appear. It may be the following:
AA_GETFILE_MUSTEXIST
Selected file must satisfy conditions of OpenFile() flags, else dialog beeps.
AA_GETFILE_NOSHOWSPEC
Do not show the search spec in the edit box. Default IS to show the spec.
AA_GETFILE_SAVE
Ok button will show "Save".
AA_GETFILE_OPEN
Ok button will show "Open".
AA_GETFILE_USEFILE
Set the filename to the file in lpszPath
AA_GETFILE_UDEDIR
Change to the directory in lpszPath
AA_GETFILE_SOUND
Get sound file and driver
AA_GETFILE_SCRIPT
Get script file
AA_GETFILE_ANIMATION
Get Animation File (no scripts)
lpszPath is a LPSTR to a string buffer into which the final fully qualified pathname
will be written.
wBufLen is the length of this buffer.
lpszDriver is a LPSTR to a string buffer into which a sound device selection is placed.
wDrvLen is the length of this buffer.
Return value is: 0 if cancel was hit, -1 if OpenFile() failed but AA_GETFILE_MUSTEXIST
was not specified. DOS file handle of selected file, otherwise. This handle is not open when
aaOpenFile returns.}
function aaSave(hAa: AAHandle; wMode: word): integer;
external 'AAPLAY';
{Save a script}
{$F-}
{ End of external calls to 'AAPLAY.DLL' }
end.
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése