This example uses the ActiveX® control Shell.Explorer, which is exposed by the Microsoft® Internet Explorer® application, to include an HTML viewer in a MATLAB® figure. The figure's window button down function is then used to select a graphics object when the user clicks the graph and load the object's property documentation into the HTML viewer.
Using Internet Explorer from an ActiveX client program.
Defining a window button down function that displays HTML property documentation for whatever object the user clicks.
Defining a resize function for the figure that also resizes the ActiveX object container.
This example creates a larger than normal figure window that contains an axes object and an HTML viewer on the lower part of the figure window. By default, the viewer displays the URL http://www.mathworks.com. When you issue a plotting command, such as:
the graph displays in the axes.
Click anywhere in the graph to see the property documentation for the selected object.
You can open the file that implements this example in MATLAB Editor or you can run this example with the following links:
This example defines the figure size based on the default figure size and adds space for the ActiveX control. Here is the code to define the figure:
dfpos = get(0,'DefaultFigurePosition'); hfig = figure('Position',dfpos([1 2 3 4]).*[.8 .2 1 1.65],... 'Menu','none','Name','Create a plot and click on an object',... 'ResizeFcn',@reSize,... 'WindowButtonDownFcn',@wbdf,... 'Renderer','Opengl',... 'DeleteFcn',@figDelete);
Note that the figure also defines a resize function and a window button down function by assigning function handles to the ResizeFcn and WindowButtonDownFcn properties. The callback functions reSize and wbdf are defined as nested functions in the same file.
The figure's delete function (called when the figure is closed) provides a mechanism to delete the control.
The actxcontrol function creates the ActiveX control inside the specified figure and returns the control's handle. You need to supply the following information:
Control's programmatic identifier (use actxcontrollist to find it)
Location and size of the control container in the figure (pixels) [left bottom width height]
Handle of the figure that contains the control:
conSize = calcSize; % Calculate the container size hExp = actxcontrol('Shell.Explorer.2',conSize,hfig); % Create the control Navigate(hExp,'http://www.mathworks.com/'); % Specify content of html viewer
The nested function, calcSize calculates the size of the object container based on the current size of the figure. calcSize is also used by the figure resize function, which is described in the next section.
function conSize = calcSize fp = get(hfig,'Position'); % Get current figure size conSize = [0 0 1 .45].*fp([3 4 3 4]); % Calculate container size end % calcSize
In MATLAB, you can change the size of a figure and the axes automatically resize to fit the new size. This example implements similar resizing behavior for the ActiveX object container within the figure using the object's move method. This method enables you to change both size and location of the ActiveX object container (i.e., it is equivalent to setting the figure Position property).
When you resize the figure window, the MATLAB software automatically calls the function assigned to the figure's ResizeFcn property. This example implements the nested function reSize for the figure reSize function.
The resize function first determines if the ActiveX object exists because the MATLAB software calls the figure resize function when the figure is first created. Since the ActiveX object has not been created at this point, the resize function simply returns.
When you change the size of the figure, the resize function executes and does the following:
Calls the calcSize function to calculate a new size for the control container based on the new figure size.
Calls the control's move method to apply the new size to the control.
function reSize(src,evnt) if ~exist('hExp','var') return end conSize = calcSize; move(hExp,conSize); end % reSize
This example uses the figure WindowButtonDownFcn property to define a callback function that handles mouse click events within the figure. When you click the left mouse button while the cursor is over the figure, the MATLAB software executes the WindowButtonDownFcn callback on the mouse down event.
The callback determines which object was clicked by querying the figure CurrentObject property, which contains the handle of the graphics object most recently clicked. Once you have the object's handle, you can determine its type and then load the appropriate HTML page into the Shell.Explorer control.
The nested function wbdf implements the callback. Once it determines the type of the selected object, it uses the control Navigate method to display the documentation for the object type.
function wbdf(src,evnt) cobj = get(hfig,'CurrentObject'); if isempty(cobj) disp('Click somewhere else') return end pth = 'http://www.mathworks.com/help/techdoc/ref/'; typ = get(cobj,'Type'); switch typ case ('figure') Navigate(hExp,[pth,'figure_props.html']); case ('axes') Navigate(hExp,[pth,'axes_props.html']); case ('line') Navigate(hExp,[pth,'line_props.html']); case ('image') Navigate(hExp,[pth,'image_props.html']); case ('patch') Navigate(hExp,[pth,'patch_props.html']); case ('surface') Navigate(hExp,[pth,'surface_props.html']); case ('text') Navigate(hExp,[pth,'text_props.html']); case ('hggroup') Navigate(hExp,[pth,'hggroupproperties.html']); otherwise % Display property browser Navigate(hExp,[pth(1:end-4),'infotool/hgprop/doc_frame.html']); end end % wbdf
This example uses the figure delete function (DeleteFcn property) to delete the ActiveX object before closing the figure. The MATLAB software calls the figure delete function before deleting the figure, which enables the function to perform any clean up needed before closing the figure. The figure delete function calls the control's delete method.
function figDelete(src,evnt) delete(hExp); end