Authorware UCD Development Big Secret (7)

xiaoxiao2021-03-06  41

VCL's glory (2)

TGRAPHICCONTROL

In this example, note that the MediaPlayer component is inherited in TWINCONTROL, that is, the component capable of "accommodating" by other windows must be a component having a window handle property, that is, "Parent" attribute.

So is it for Authorware from the components that inherited from TwinControl? But fortunately, Borland has left our back door.

Those familiar with the VCL component architecture know: TwinControl also has a "brother": TgraphicControl and a "son" TCUSTOMCONTROL. The difference between TGraphicControl and TwinControl is that TGRAPHICCONTROL does not have a window handle, while the Canvas property and the PAINT process. The benefits of TCustomControl are: it has all the properties of TwinControl and TgraphicControl. Interesting, the VCL itself does not support multiple inheritance, and the TCUSTOMControl component can be said to be a special case. In fact, most components are inherited from TCUSTomControl (I don't understand why Borland wants to set a TwinControl, it is completely redundant). Ok, now everyone understands what "the back door" is. Our current goal is to change the components from TGRAPHICCONTROL to its "son" TCUSTOMCONTROL, sub-colors industry, just, and CustomControl has TGRAPHICCONTROL all attributes, which is definitely safe. We now set a specific goal: TIMAGE components, this thing is inherited from TGRAPHICCONTROL. It should be said to be a commonly used component, take it trying to test the knife. Borland puts the source code of TIMAGE and other part of the component in the ExtCtrl.PAS file, in the ... / source / vcl directory in the installation directory of the DEPHI. You can also find the declaration of the component in the DEPHI editor and then press Ctrl without placing, or you can link to the source code.

Now find "TIMAGE = Class (TGRAPHICCONTROL", change "TGRAPHICCONTROL" to "TCUSTOMCONTROL" and. save. Is not it simple. After the change, the TIMAGE component has a window handle property, and we can place it on the authorware window.

New DLL project and be sure to add: graphics, extCtrls; these two units;

Set the global object:

VAR

MyImage: TIMAGE;

. . . . . . .

Create such a function: DisplayPicture (awparam: awparam_ptr; bmpfilename: pchar): boolean; stdcall;

VAR

AWHANDLE: THANDLE;

Begin

AwHandle: = awparam.hwnd;

MyImage: = TIMAGE.CREATE (NIL);

MyImage.ParentWindow: = awhandle; // Image component already has a window handle, can be included in the parent window MyImage.Picture.bitmap.LoadFromFile (straps (bmpfilename)); / / Load the picture file

END;

Exports

DisplayPicture; // Export function

This is just a simple function example. If you add x, y two parameters as the coordinate position, then set it wide and higher than the size of the image, but also provide a transparent choice, it is more perfect, interested Friends can add code to make it more perfect. Eventually the implementation is shown in Authorware:

Then, according to this method, all TGRAPHICCONTROL inherited components can be docked with Authorware by changing inheritance base classes.

Read more, Comments (0)

Authorware UCD Development Big Secret (6)

By Admin Posted At Oioj on 2004-4-22 8:14:17 Weather: sunny

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_" start) 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.

转载请注明原文地址:https://www.9cbs.com/read-58409.html

New Post(0)