Containers: Implementing a Container
| Overview | How Do I | Sample | Tutorial
in Tutorials describes the implementation of a simple visual editing 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
Initialize the OLE libraries by calling AfxOleInit in the InitInstance member function.
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
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.
Override IsSelected to check whether the item passed to it is currently selected.
Implement an OnInsertObject message handler to display the Insert Object dialog box.
Implement an OnSetFocus message handler to transfer focus from the view to an in-place active OLE embedded item.
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 in Tutorials, and see the MFC Tutorial sample .
To handle embedded and linked items
Derive a class from . Objects of this class represent items that have been embedded in or linked to your OLE document.
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 (called "Refining Active Container Functionality") in Tutorials and the MFC OLE sample .
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:
In-place activation when editing an embedded item.
For more information, see the article Activation.
Creation of OLE items by dragging and dropping a selection from a server application.
For more information, see the article Drag and Drop (OLE).
Links to embedded objects or combination container/server applications.
For more information, see the article Containers: Advanced Features.
See Also Containers: Client Items