Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

actxcontrol - Create Microsoft ActiveX control in figure window

Syntax

h = actxcontrol('progid')
h = actxcontrol('progid','param1',value1,...)
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 programmatic identifier (progid) for the control determines the type of control created. (See the documentation provided by the control vendor to get this string.) The returned object, h, represents the default interface for the control.

Note that progid cannot be an ActiveX server because the MATLAB software cannot insert ActiveX servers in a figure. See actxserver for use with ActiveX servers.

h = actxcontrol('progid','param1',value1,...) creates an ActiveX control using the optional parameter name/value pairs. Parameter names include:

One possible format is:

h = actxcontrol('myProgid','newPosition',[0 0 200 200],...
	'myFigHandle',gcf,...
	'myCallback',{'Click' 'myClickHandler';...
	'DblClick' 'myDblClickHandler';...
	'MouseDown' 'myMouseDownHandler'});

The following syntaxes are deprecated and will not become obsolete. They are included for reference, but the above syntaxes are preferred.

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

[x y width height]

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 current figure handle is returned by the gcf command.

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' 'eventhandler'; 'event2' 'eventhandler2'; ...}

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 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.

COM functions are available on Microsoft® Windows® systems only.

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.

f = figure('position', [300 300 600 500]);
cal = actxcontrol('mscal.calendar', [0 0 600 500], f);

Call the get method on cal to list all properties of the calendar, including today's date:

cal.get

For example, MATLAB displays (in part):

        BackColor: 2.1475e+009
              Day: 23
          DayFont: [1x1 Interface.Standard_OLE_Types.Font]
            Value: '8/20/2001'
                 .
                 .
                 .

Read today's date:

date = cal.Value

MATLAB displays a date similar to:

date =
   8/20/2001

Set the Day property to a new value:

cal.Day = 5;
date = cal.Value

MATLAB displays a date similar to:

date =
   8/5/2001

Call invoke to list all available methods:

meth = cal.invoke

MATLAB displays (in part):

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:

cal.NextWeek;
date = cal.Value

MATLAB displays a date similar to:

date =
   8/12/2001

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

cal.events

MATLAB displays:

   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()

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:

h = actxcontrol('mwsamp.mwsampctrl.2', [0 0 200 200], ...
   gcf, 'sampev');

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 software.

See Also

actxserver, release, delete (COM), save (COM), load (COM), interfaces

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS