External Interfaces Reference |
Create ActiveX control in figure window
Syntax
h = actxcontrol('progid') h = actxcontrol('progid', position) h = actxcontrol('progid', position, fig_handle) h = actxcontrol('progid', position, fig_handle, event_handler) h = actxcontrol('progid', position, fig_handle, ... event_handler, 'filename')
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
.
Note
If the figure window designated by fig_handle is invisible, the control will be invisible. If you want the control you are creating to be invisible, use the handle of an invisible figure window.
|
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, ...
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
event_handler, 'filename')
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.
Note Although using a single handler for all events may be easier in some cases, specifying an individual handler for each event creates more efficient code that results in better performance. |
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.
Note If you encounter problems creating Microsoft Forms 2.0 controls in MATLAB or other non-VBA container applications, see Using Microsoft Forms 2.0 Controls in the External Interfaces documentation. |
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.
f = figure('position', [300 300 600 500]); cal = actxcontrol('mscal.calendar', [0 0 600 500], f) cal = COM.mscal.calendar
Call the get
method on cal
to list all properties of the calendar:
cal.get BackColor: 2.1475e+009 Day: 23 DayFont: [1x1 Interface.Standard_OLE_Types.Font] Value: '8/20/2001' . .
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:
meth = cal.invoke meth = NextDay: 'HRESULT NextDay(handle)' NextMonth: 'HRESULT NextMonth(handle)' NextWeek: 'HRESULT NextWeek(handle)' NextYear: 'HRESULT NextYear(handle)' . .
Invoke the NextWeek
method to advance the current date by one week:
Call events
to list all calendar events that can be triggered:
cal.events ans = Click = void Click() DblClick = void DblClick() KeyDown = void KeyDown(int16 KeyCode, int16 Shift) KeyPress = void KeyPress(int16 KeyAscii) KeyUp = void KeyUp(int16 KeyCode, int16 Shift) BeforeUpdate = void BeforeUpdate(int16 Cancel) AfterUpdate = void AfterUpdate() NewMonth = void NewMonth() NewYear = void NewYear()
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:
h = actxcontrol('mwsamp.mwsampctrl.2', [0 0 200 200], ... gcf, {'Click' 'sampev'; 'DblClick' 'sampev'})
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:
h = actxcontrol('mwsamp.mwsampctrl.2', [0 0 200 200], ... gcf, {'Click', 'myclick'; 'DblClick' 'my2click'; ... 'MouseDown' 'mymoused'});
The next command does the same thing, but specifies the events using numeric event identifiers:
h = actxcontrol('mwsamp.mwsampctrl.2', [0 0 200 200], ... gcf, {-600, 'myclick'; -601 'my2click'; -605 'mymoused'});
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
COM Client Functions | actxcontrollist |
© 1994-2005 The MathWorks, Inc.