User`s manual

7 ActiveX and DDE Support
7-8
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.
h = actxcontrol (progid [, position [, handle ...
[, callback | {event1 eventhandler1; event2 eventhandler2; …}]]])
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:
function event (varargin)
if (str2num(vararg{1}) == -600)
disp ('Click Event Fired');
end
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.