VCL's glory (1)
A huge treasure is discovered! What is treasure? -V-C-L! VCL component is the essence of dephi, it is the best thing that dephi beauty (I personally think), how exciting things for VCL components for Authorware That is! Let now let everyone realize this dream, huh, huh. I would like to explain the detailed routine, or to make a more practical routine. Our goal is to add a multimedia play control in Authorware to make it a multimedia play platform.
DEPHI components used: PlayForm: Form
MediaPlayer: Media Player
OpenDialog; Open File Dialog
OpenFileBTN: Button to open media files
AboutBTN: Button to open the "About" dialog
as the picture shows:
Set the FORM1's AutoSize property to True
Set the OpenDialog's Filter property to * .mp3 | * .mp3 | * .avi | * .avi | * .mpg | * .mpg | * .dat | * .dat | * .wav | * .wav | * .mid | * .MID
Add the following code to the Open File button Click the event:
Procedure TFORM1.OpenFileBtnClick (Sender: TOBJECT);
Begin
If OpenFiledialog.execute THEN
Begin
MediaPlayer.FileName: = OpenFiledialog.FileName;
MediaPlayer.Open;
END;
Add the following code in the "About" button:
Procedure TFORM1.Aboutbtnclick (Sender: TOBJECT);
Begin
messagebox (getforegroundwindow, 'Authorware media console' chr (13) chr (13) 'OF: Xu Jin' chr (13) 'studio produced immersed oxalyl' chr (13) 'Copr 1998- 2001 ' chr (13) ' email: xujinmax@21cn.com ',' About this Program ', MB_OK or MB_ICONIONFORMATION
END;
Enter the engineering unit
Add the following reference unit in the USES statement:
Uses
......
Messages,
Windows,
......
Type
AWPARAM = Record // AWPARAM structure declaration
......
Establish the following functions:
Function CreateMediaControl (awparam: awparam_ptr): boolean; stdcall;
Begin
Try
Form1: = TFORM1.CREATEPARENTED (AWPARAM.HWND);
/ / The above is a key, incorporate Form1 into the current working window (that is, the Authorware window);
// This way, we use the window created by Dephi to "thieve the thief",
Form1.show;
RESULT: = true;
Except
Result: = FALSE;
END;
END;
Exports // Export function
CreateMediaControl;
Over, we have to build the following resource files:
1 DLL_HEADER LOADONCALL DISCARDABLE
Begin
"CreateMediaControl / 0", "/ 0"
End
CreateMediaControl DLL_Header Loadoncall Discardable
Begin
"/ 0",
"L / 0", (return value type: long)
"A / 0", (Parameter Type: awparam)
"Result: = CreateMediaControl () / r / n",
"Role: Create a media console / r / n",
"Author: Xu Jin / 0"
End
Save the file as Mediarc.rc files and compile into Mediarc.res in engineering units:
......
{$ R Mediarc.RES}
......
Compiling the project into "MediaControl.dll", which is renamed "MediaControl.u32" (in fact no name, as long as the resource file is included, Authorware still can identify it). The final execution effect is shown in the figure (in the IDE environment This DEPHI's form is indeed a sub-window of Authorware. Although this example code is simple, it is very powerful, and can play a file including MP3, but also play VCD, not " The buse is "poor.
In this example, I want to add a note: Translate the MediaPlayer component into the ActiveX control, and then you can also achieve the same effect in Authorware, but it is another thing. Now we can freely use VCL components in Authorware. , But waiting for one, are we satisfied? Some picky readers (also smart readers) may find that the above example does not really realize the connection of VCL and Authorware, because the VCL component is attached to the FORM component (although Form is also VCL components), we are yearning to direct VCL components directly "embed" Authorware on the form of Authorware, not attached to the form of DEPHI,
Quote section:
Uses
......
Windows,
Messages,
MPlayer, // Media Player Source Code Unit, must join
......
Type
AWPARAM = Record
......
VAR
MediaPlayer: TMEDIAPLAYER;
......
Create the following functions: (in order to conflict with other functions, the function name is "X_" starting)
Function X_CreateMediaControl (awparam: awparam_ptr; Visible, x, y: integer; filename: pchar): boolean; stdcall;
// Create a media player
// Parameter description: awparam: implies parameters; Visible: Control is visible (1 or 0); x, y: Place the coordinator of the player; filename: The media file name gived to //
Begin
Try
MediaPlayer: = TMEDIAPLAYER.CREATE (NIL);
MediaPlayer.parentWindow: = awparam.hwnd; // Create MediaPlayer objects first, and give it a parent window
MediaPlayer.FileName: = strpas (filename); // Set media files
MediaPlayer.Open; if visible = 1 THEN
MediaPlayer.Visible: = TRUE
Else
MediaPlayer.visible: = false; // Set visibility
MediaPlayer.top:=x;
Mediaplayer.left: = y; // Set coordinates
RESULT: = true;
Except
Result: = FALSE;
END;
END;
Function X_SetMediafile (filename: pchar): boolean; stdcall;
/ / Change the name of the media file
Begin
Try
MediaPlayer.FileName: = StrPas (filename);
RESULT: = true;
Except
Result: = FALSE;
END;
END;
Function X_Mediaplay: Boolean; stdcall;
// Play the media file
Begin
MediaPlayer.play;
RESULT: = true;
END;
Function x_pauseplay: boolean; stdcall;
// Pause playback
Begin
Try
Mediaplayer.pause;
RESULT: = true;
Except
Result: = FALSE;
END;
END;
Function X_FreemediaPlayer: Boolean; stdcall;
/ / Release the media player (must be released after the object is not available)
Begin
Try
MediaPlayer.Free;
RESULT: = true;
Except
Result: = FALSE;
END;
END;
Exports // Export function
X_createMediaControl,
X_setmediafile,
X_Mediaplay,
X_pauseplay,
X_FreemediaPlayer;
String resource file:
1 DLL_HEADER LOADONCALL DISCARDABLE
Begin
"X_createmediacontrol / 0",
"X_setmediafile / 0",
"X_MediaPlay / 0",
"X_PausePlay / 0",
"X_freemediaplayer / 0",
"/ 0"
End
X_createmediacontrol DLL_Header Loadoncall Discardable
Begin
"/ 0",
"L / 0",
"Aiiis / 0",
"Result: = x_createmediacontrol (Visible, X, Y, FileName) / R / N",
"Role: Create a media console / r / n",
"Author: Xu Jin / 0"
End
X_SetMediafile DLL_Header Loadoncall Discardable
Begin
"/ 0",
"L / 0",
"S / 0",
"Result: = x_setmediafile (filename) / r / n",
"Role: Open a media file / r / n",
"Author: Xu Jin / 0"
End
X_MediaPlay DLL_Header Loadoncall Discardable
Begin
"/ 0",
"L / 0",
"V / 0",
"Result: = X_MEDIAPLAY () / R / N", "Role: Play Media File / R / N",
"Author: Xu Jin / 0"
End
X_pauseplay DLL_HEADER LOADONCALL DISCARDABLE
Begin
"/ 0",
"L / 0",
"V / 0",
"Result: = x_pauseplay () / r / n",
"Role: Suspension Play Media File / R / N",
"Author: Xu Jin / 0"
End
X_freemediaplayer DLL_HEADER LOADONCALL DISCARDABLE
Begin
"/ 0",
"L / 0",
"V / 0",
"Result: = x_freemediaplayer () / r / n",
"Role: Release Media Player / R / N",
"Author: Xu Jin / 0"
End
Finally compiling the effect of authorware running as shown:
It is completely attached to the authorware window, of course, you can also hide it.