External Interfaces/API | ![]() ![]() |
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.
function myclick(varargin) disp('Single click function') function my2click(varargin) disp('Double click function') function mymoused(varargin) disp('You have reached the mouse down function') disp('The X position is: ') varargin(5) disp('The Y position is: ') varargin(6)
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.
h = actxcontrol('SELECTOR.SelectorCtrl.1', [0 0 200 200], f, ... {'Click' 'allevents'; 'DblClick' 'allevents'; ... 'MouseDown' 'allevents'})
function allevents(varargin) if (varargin{2} = -600) disp ('Single Click Event Fired') elseif (varargin{2} = -601) disp ('Double Click Event Fired') elseif (varargin{2} = -605) disp ('Mousedown Event Fired') end
![]() | set | Additional ActiveX Client Information | ![]() |