External Interfaces/API    

Writing Event Handlers

ActiveX events are invoked when a control wants to notify its container that something of interest has occurred. For example, many controls trigger an event when the user single-clicks on the control. In MATLAB, when a control is created, you may optionally supply a callback (also known as an event handler function) as the last argument to the actxcontrol command or a cell array that contains the event handlers.

The event handler function (callback) is called whenever the control triggers any event. The event handler function must be an M-function that accepts a variable number of arguments of the following form:

All arguments passed to this function are MATLAB strings. The first argument to the event handler is a string that represents the number of the event that caused the event handler to be called. The remaining arguments are the values passed by the control with the event. These values will vary with the particular event and control being used. The list of events that control invocations and their corresponding event numbers and parameters must be obtained from the control's documentation. In order to use events with MATLAB, you will need to find out the numerical values that the control uses for each event so that you can use these in the event handler.

The event handlers that are used in the cell array style are slightly different than those used in the callback style. The first argument in the cell array style is a reference to the object itself. The second argument is the event number, which, unlike the callback style, is not a string that represents the number. (Subsequent arguments vary depending on the event.)

These sample event handlers, myclick.m, my2click.m, and mymoused.m correspond to the actxcontrol example.

You can use the same event handler for all the events you want to monitor using the cell array pairs. Response time will be better than using the callback style.

For instance

and allevents.m is


 set Additional ActiveX Client Information