Containers: Implementing a Container

HomeOverviewHow Do ISampleTutorial

Creating an OLE Container in Tutorials describes the implementation of a simple visual editing container, CONTAINER, explaining each step in detail. This article summarizes the tutorial procedure and points you to other articles that provide more detailed explanations about implementing containers. It also lists some optional OLE features you may want to implement and the articles describing these features.

To prepare your CWinApp-derived class

  1. Initialize the OLE libraries by calling AfxOleInit in the InitInstance member function.

  2. Call CDocTemplate::SetContainerInfo in InitInstance to assign the menu and accelerator resources used when an embedded item is activated in-place. For more information on this topic, see the Activation article.

These features are provided for you automatically when you use AppWizard to create a container application. See the article The MFC AppWizard (EXE version): Step-by-Step.

To prepare your view class

  1. Keep track of selected items by maintaining a pointer, or list of pointers if you support multiple selection, to the selected items. Your OnDraw function must draw all OLE items.

  2. Override IsSelected to check whether the item passed to it is currently selected.

  3. Implement an OnInsertObject message handler to display the Insert Object dialog box.

  4. Implement an OnSetFocus message handler to transfer focus from the view to an in-place active OLE embedded item.

  5. Implement an OnSize message handler to inform an OLE embedded item that it needs to change its rectangle to reflect the change in size of its containing view.

Because the implementation of these features varies dramatically from one application to the next, AppWizard provides only a basic implementation. You will likely have to customize these functions to get your application to function properly. For a more detailed explanation and an example of this, see the "Refining Active Container Functionality" section of Creating an OLE Container in Tutorials, and see the MFC Tutorial sample CONTAINER.

To handle embedded and linked items

  1. Derive a class from COleClientItem. Objects of this class represent items that have been embedded in or linked to your OLE document.

  2. Override OnChange, OnChangeItemPosition, and OnGetItemPosition. These functions handle sizing, positioning, and modifying embedded and linked items.

AppWizard will derive the class for you, but you will likely need to override OnChange and the other functions listed with it in step 2 in the preceding procedure. The skeleton implementations need to be customized for most applications, because these functions are implemented differently from one application to the next. For more information about this, see step 2 of the container tutorial (called "Refining Active Container Functionality") in Tutorials and the MFC OLE sample DRAWCLI.

You must add a number of items to the container application’s menu structure to support OLE. For more information on these, see the article Menus and Resources: Container Additions.

You may also want to support some of the following features in your container application:

See Also   Containers: Client Items