An OLE Embedding Container Application

Now that we've got a working mini-server that supports embedding (EX28A), we'll write a container program to run it. We're not going to use the MFC container support, however, because you need to see what's happening at the OLE interface level. We will use the MFC document-view architecture and the MFC interface maps, and we'll also use the MFC data object classes.

MFC Support for OLE Containers

If you did use AppWizard to build an MFC OLE container application, you'd get a class derived from COleDocument and a class derived from COleClientItem. These MFC base classes implement a number of important OLE container interfaces for embedding and in-place activation. The idea is that you have one COleClientItem object for each embedded object in a single container document. Each COleClientItem object defines a site, which is where the component object lives in the window.

The COleDocument class maintains a list of client items, but it's up to you to specify how to select an item and how to synchronize the metafile's position with the in-place frame position. AppWizard generates a basic container application with no support for linking, clipboard processing, or drag and drop. If you want those features, you might be better off looking at the MFC DRAWCLI and OCLIENT samples.

We will use one MFC OLE class in the container—COleInsertDialog. This class wraps the OleUIInsertObject function, which invokes the standard Insert Object dialog box. This Insert Object dialog enables the user to select from a list of registered component programs.

Some Container Limitations

Because our container application is designed for learning, we'll make some simplifications to reduce the bulk of the code. First of all, this container won't support in-place activation—it allows the user to edit embedded objects only in a separate window. Also, the container supports only one embedded item per document, and that means there's no linking support. The container uses a structured storage file to hold the document's embedded item, but it handles the storage directly, bypassing the framework's serialization system. Clipboard support is provided; drag-and-drop support is not. Outside these limitations, however, it's a pretty good container!

Container Features

So, what does the container actually do? Here's a list of features:

  • As an MFC MDI application, it handles multiple documents.

  • Displays the component's metafile in a sizeable, moveable tracker rectangle in the view window.

  • Maintains a temporary storage for each embedded object.

  • Implements the Insert Object menu option, which allows the user to select a registered component. The selected component program starts in its own window.

  • Allows embedded objects to be copied (and cut) to the clipboard and pasted. These objects can be transferred to and from other containers such as Microsoft Word and Microsoft Excel.

  • Allows an embedded object to be deleted.

  • Tracks the component program's loaded-running transitions and hatches the tracker rectangle when the component is running or active.

  • Redraws the embedded object's metafile on receipt of component change notifications.

  • Saves the object in its temporary storage when the component updates the object or exits.

  • Copies the embedded object's temporary storage to and from named storage files in response to Copy To and Paste From commands on the Edit menu.


Programming Visual C++
Advanced 3ds max 5 Modeling & Animating
ISBN: 1572318570
EAN: 2147483647
Year: 1997
Pages: 331
Authors: Boris Kulagin

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net