Authorware's internal message interface
The first question is that our UCD often needs to create objects in the course of operation, especially for development languages such as Dephi, it is entirely implemented from the process of creating objects during operation to elimination. In a DEPHI program, we don't have to worry about the created objects, because you can't eliminate it, unless you are dynamically created in the running period. When we shut down a program, DEPHI automatically releases the memory space from memory, which will not cause the inch to cause permanent loss. However, if the object is compiled into the DLL program, the object must be dynamically created, and the object must be released before the program exits, otherwise the illegal operation will appear. There is such a problem with the MP3 play function in a famous UCD: The user must be required to perform the function of the release of the object to be properly exited. If the user is exited by using the system menu using the Windows window, illegal operation is inevitable, from another aspect For a good software, it is a basic principle that we can provide them with any problems that may have occurred during the user's operation. The current problem is: How do we know when the user shuts down the program, that is, it is necessary to seize the opportunity to release the object.
Of course, making a system hook function to solve this problem. However, Authorware also gave programmers a chance, which is an object message in Authorware. To enable our object to receive Authorware's internal messages, our first step is to join our object to the list of Authorware's display object. Authorware's display object list is an abstract concept that publishes a message to an object registered in the list, and we can process it according to the specific message. The command to join the object to the display list is implemented by the Windows API function SendMessage, the function describes the following:
ID = SendMessage (PWHANDLE, APWC_POST, 0, LPPOSTPB)
Parameter Description
PWHANDLE Authorware Window Handle
LPPOSTPB points to a far pointer for an APWC_POSTPB parameter block
APWC_POST This message is to tell Authorware I want to join an object. (It is a constant: $ 6000)
return value
> 0: Returns the unique marker of the object.
0: The object process cannot be loaded.
-1 The object process in the DLL is not found.
-2: illegal memory.
-3: Parameter error.
The LPPOSTPB variable structure is described as follows:
Type
APWC_POSTPB = Record
Size: Word; // The length of this structure
DLL_PTR: PCHAR; // Loaded DLL file name
Function_ptr: PCHAR; // Object Process Function Name
RECT: TRECT; // Object Receives the area of the message
Port: integer; // Receive message
Data_ptr: longint; // Object Carry private data structural pointer
Data_size: Word; // Object Carry Private Data Length
Name_ptr: pchar; // Object variable name
END {APWC_POSTPB};
FAR = APWC_POSTPB;
APWC_POSTPB_PTR = ^ APWC_POSTPB;
Description: Where there is no private data, DATA_PTR and DATA_SIZE can be set to zero
Object process function name must be a function exported with Exports
Port can take one of the following three constants:
STATIC_PORT = 0; // Suitable for basic fixed objects, in most cases it
Motion_port = 1; // Suitable for object screen_port = 2 faster update frequencies; // Suitable for direct picture, if the object is an animation, choose it
RECT is a zone defined in Authorware's window, if you need to receive a mouse message?
The message is only available in this area.
Second to create an object process function
After the registration object, Authorware sends a message to the object process defined by my gate. We implemented our object according to the specific message.
Object process function format:
OpjiectProc (AWPARAM: APWN_AB; MSG: NOTIFICATION_MESSAGE): Boolean;
Parameter Description:
AWPARAM: Pointer to the APWN_AB structure defined during the object of the object
The APWN_AB structure is declared as follows:
Type
APWN_AB = Record
Size: Word; // The length of this structure
ID: longint; // Assign the unique marker to the object
Icon_id: integer; // Create the icon where the object is located, usually use the calculation icon //
Display: hwnd; // Authorware main window handle
First parameter of wparam: wparam; // msg
LPARAM: LPARAM; // MSG second parameter
RECT: TRECT; // passed by the APWC_POSTPB parameter
Data_ptr: longint; // is passed by the APWC_POSTPB parameter
DATA_SIZE: WORD; // Transfer by the APWC_POSTPB parameter
Name_ptr: pchar; // is passed by the APWC_POSTPB parameter
END {APWN_AB};
FAR = APWN_AB; // Declaration as a far node call (in fact, there is no need to be in the current 32-bit operation // system, can be deleted)
APWN_AB_PTR = ^ APWN_AB; / / Define Pointer
msg: notification_message is the type of message defined by Authorware
This variable is declared as follows:
Type
NOTIFICATION_MESSAG = Word;
The MSG parameter is the message from Authorware, which is fixed to the following types:
Message name parameter meanings
The APWN_INIT object is being created. 0
WPARAM 0
LPARAM 0
The APWN_DESTROY object is destroy and release the memory 1
WPARAM 0
LPARAM 0
APWN_PAINT object redraws itself on the device description table
WPARAM HDC (Authorware Main Window Device Description Table)
LPARAM 0
APWN_SAVE object saves its own data to overload 3
WPARAM 0
LPARAM 0
APWN_RESTORE object overloads saved private data 4
WPARAM 0
LPARAM 0
Apwn_lbdown mouse left mouse button. 5
WPARAM 0
LPARAM (low byte storage X coordinate, high byte storage y coordinate)
Apwn_lbdblck mouse left button double click. 6
WPARAM 0
LPARAM (low byte storage X coordinate, high byte storage y coordinate)
The APWN_LBUP mouse button is lifted. 7
WPARAM 0
LPARAM (low byte storage X coordinate, high byte storage y coordinate)
APWN_WINDOWOPEN 8
WPARAM 0
LPARAM 0
APWN_WINDOWCLOSE Authorware Main Window Turns 9
WPARAM 0
LPARAM 0
The APWN_SETPROPERTY system uses setProperty () function 10.wParam 0
LPARAM APWN_PROP_PTR (this is another authorware defined structure parameter)
APWN_GETPROPERTY Gets an object value. 11
WPARAM 0 (Not used)
LPARAM APWN_PROP_PTR
APWN_CloseWindow When the system function closewindow () is called, the message is passed 12
WPARAM 0
LPARAM 0
The APWN_MOUSEMOVE mouse moves on the object. 13
WPARAM 0
LPARAM (low byte storage X coordinate, high byte storage y coordinate)
The APWN_HITTEST mouse stays in the object boundary. 14
WPARAM 0
LPARAM (low byte storage X coordinate, high byte storage y coordinate)
APWN_USER Custom Message 10000
Here is the key message that is APWN_WINDOWCLOSE. This message tells us that the Authorware program is about to close, and we can free our object accordingly. Now let's use an instance to explain how to catch this message.
Open the function x_createmediacontrol source code file we did in front, add the following statement after the Uses statement:
......
/
Type
APWC_POSTPB = Record
Size: Word;
DLL_PTR: PCHAR;
Function_ptr: pchar;
RECT: TRECT;
Port: integer;
Data_ptr: longint;
Data_size: Word;
Name_ptr: pchar;
END {APWC_POSTPB};
FAR = APWC_POSTPB;
APWC_POSTPB_PTR = ^ APWC_POSTPB;
///
Type
APWN_AB = Record
Size: Word;
ID: longint;
Icon_id: integer;
Display: hwnd;
WPARAM: WPARAM;
Lparam: lparam;
RECT: TRECT;
Data_ptr: longint;
Data_size: Word;
Name_ptr: pchar;
END {APWN_AB};
APWN_AB_PTR = ^ APWN_AB;
/
Type
APW_NOTIFICATION_MESSAGE = Word;
Const APWN_INIT = 0;
Const APWN_DESTROY = 1;
Const APWN_Paint = 2;
Const Apwn_save = 3;
Const APWN_RESTORE = 4;
Const APWN_LBDOWN = 5;
Const APWN_LBDBLCK = 6
Const APWN_LBUP = 7
Const APWN_WINDOWEN = 8
Const APWN_WINDOWCLOSE = 9
Const APWN_SETPROPERTY = 10
Const APWN_GETPROPERTY = 11
Const Apwn_hittest 11
Const APWN_CLOSEWINDOW = 12.
Const APWN_MOUSEMOVE = 13;
Const APWN_HITTEST = 14;
Const static_port = 0;
Const motion_port = 1;
Const screen_port = 2;
Const APWC_POST = $ 6000; ......
Find Function CreateMediacontrol (AWParam: awparam_ptr): longename: pchar): longint; stdcall; // Note // means that the return value type is changed to Longint, and the declaration part should also be modified accordingly.
//Add to
VAR
PostPB: APWC_POSTPB_PTR;
WPOSTPB: Longint
SZFileName: PCHAR;
Begin
... // The creation process does not change
// in Result =. . . Previously added the following code:
GetMem (SZFileName, 255); // Assign memory to the DLL file name
GetModuleFileName (Hinstance, SzFileName, 255); // Get file name
Postpb.size: = sizeof (postpb); // Set the length of the APWC_POSTPB_PTR parameter
Postpb.dll_ptr: = SZFileName; // Set the APWC_POSTPB_PTR file name
Postpb.function_ptr: = 'newproc'; // Define the object process function
SetRect (PostPb.Rect, 0, 0, 200, 200); // Define the area, it doesn't matter, it can be small
Postpb.port: = static_port; // Define Message Receive Mode
Postpb.name_ptr: = 'myproc'; // Defines the name of the APWC_POSTPB_PTR variable, just give it a good
Postpb.data_ptr: = 0; // Defines APWC_POSTPB_PTR to carry private data
Postpb.data_size: = 0; // Define APWC_POSTPB_PTR Carrying Private Data Length
WPOSTPB: = longint (postPB); / / Define pointers for APWC_POSTPB_PTR
SendMessage (awparam.hwnd, apwc_post, 0, wpostpb); // Send a message to Authorware
......
Next, the write object function process is called, the function named in front is NewProc
The function name needs to be maintained
Function newProc (Apwnptr: APWN_AB_PTR; MSG: Word): longint; stdcall;
Begin
If MSG = APWN_WINDOWCLOSE THEN / / If the message is about to be closed, that is, the user presses the shutdown button or uses the exit // function.
MediaPlayer.Free;
RESULT: = 1;
END;
......
Finally, export NewProc functions in Exports
......
Exports
......
NewProc,
......
Thus when the developer creates a media player using the creation function, there is no need to care for when the user exits because the system passes the message to the NewProc function process, so that the media player can be released in time. .