External Interfaces Reference Previous page   Next Page
actxcontrol

Create ActiveX control in figure window

Syntax

Description

h = actxcontrol('progid') creates an ActiveX control in a figure window. The type of control created is determined by the string progid, the programmatic identifier (ProgID) for the control. (See the documentation provided by the control vendor to get this string.) The returned object, h, represents the default interface for the control.

h = actxcontrol('progid', position) creates an ActiveX control having the location and size specified in the vector, position. The format of this vector is

The first two elements of the vector determine where the control is placed in the figure window, with x and y being offsets, in pixels, from the bottom left corner of the figure window to the same corner of the control. The last two elements, width and height, determine the size of the control itself.

The default position vector is [20 20 60 60].

h = actxcontrol('progid', position, fig_handle) creates an ActiveX control at the specified position in an existing figure window. This window is identified by the Handle Graphics handle, fig_handle.

The default figure handle is gcf.

h = actxcontrol('progid', position, fig_handle, event_handler) creates an ActiveX control that responds to events. Controls respond to events by invoking an M-file function whenever an event (such as clicking a mouse button) is fired. The event_handler argument identifies one or more M-file functions to be used in handling events (see Specifying Event Handlers below).

h = actxcontrol('progid', position, fig_handle, ...
event_handler, 'filename')
creates an ActiveX control with the first four arguments, and sets its initial state to that of a previously saved control. MATLAB loads the initial state from the file specified in the string filename.

If you don't want to specify an event_handler, you can use an empty string ('') as the fourth argument.

The progid argument must match the progid of the saved control.

Specifying Event Handlers

There is more than one valid format for the event_handler argument. Use this argument to specify one of the following:

In the first case, use a cell array for the event_handler argument, with each row of the array specifying an event and handler pair:

event can be either a string containing the event name or a numeric event identifier (see Example 2 below), and eventhandler is a string identifying the M-file function you want the control to use in handling the event. Include only those events that you want enabled.

In the second case, use the same cell array syntax just described, but specify the same eventhandler for each event. Again, include only those events that you want enabled.

In the third case, make event_handler a string (instead of a cell array) that contains the name of the one M-file function that is to handle all events for the control.

There is no limit to the number of event and handler pairs you can specify in the event_handler cell array.

Event handler functions should accept a variable number of arguments.

Strings used in the event_handler argument are not case sensitive.

Remarks

If the control implements any custom interfaces, use the interfaces function to list them, and the invoke function to get a handle to a selected interface.

When you no longer need the control, call release to release the interface and free memory and other resources used by the interface. Note that releasing the interface does not delete the control itself. Use the delete function to do this.

For more information on handling control events, see the section, Writing Event Handlers in the External Interfaces documentation.

For an example event handler, see the file sampev.m in the toolbox\matlab\winfun\comcli directory.

Examples

Example 1 -- Basic Control Methods

Start by creating a figure window to contain the control. Then create a control to run a Microsoft Calendar application in the window. Position the control at a [0 0] x-y offset from the bottom left of the figure window, and make it the same size (600 x 500 pixels) as the figure window.

Call the get method on cal to list all properties of the calendar:

Read just one property to record today's date:

Set the Day property to a new value:

Call invoke with no arguments to list all available methods:

Invoke the NextWeek method to advance the current date by one week:

Call events to list all calendar events that can be triggered:

Example 2 -- Event Handling

The event_handler argument specifies how you want the control to handle any events that occur. The control can handle all events with one common handler function, selected events with a common handler function, or each type of event can be handled by a separate function.

This command creates an mwsamp control that uses one event handler, sampev, to respond to all events:

The next command also uses a common event handler, but will only invoke the handler when selected events, Click and DblClick are fired:

This command assigns a different handler routine to each event. For example, Click is an event, and myclick is the routine that executes whenever a Click event is fired:

The next command does the same thing, but specifies the events using numeric event identifiers:

See the section, Sample Event Handlers in the External Interfaces documentation for examples of event handler functions and how to register them with MATLAB.

See Also

actxserver, release, delete, save, load, interfaces


Previous page  COM Client Functions actxcontrollist Next page

© 1994-2005 The MathWorks, Inc.