The simplest and most recommended way to create an Active document container application is to create an MFC EXE container application using the MFC AppWizard, then modify the application to support active document containment.
To create an active document container application
The OnActivate code is not needed because the code in a normal container is used to guarantee that the item being activated is the only active item. Therefore, if there is another active item, it is deactivated first. A basic OLE container lets you have multiple embedded objects in a single document, so it needs this code. The default AppWizard-generated active document container is only set up to allow one Active document in the container at a time, so this code is unnecessary. Once you insert an object in your active document container, you cannot insert other objects.
if (!CView::OnPreparePrinting(pInfo))
return FALSE;
if (!COleDocObjectItem::OnPreparePrinting(this, pInfo))
return FALSE;
return TRUE;
OnPreparePrinting provides printing support. This code replaces DoPreparePrinting, which is the default print preparation.
void CMyProjView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: add code to print the controls
if(pInfo->m_bDocObject)
COleDocObjectItem::OnPrint(this, pInfo, TRUE);
}
Active document containment provides an improved printing scheme:
The static member functions COleDocObjectItem::OnPrint and COleDocObjectItem::OnPreparePrinting, as implemented in the previous code, handle this improved printing scheme.
virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
Note In some functions, you do not need to change COleClientItem to COleDocObjectItem. Because a COleDocObjectItem object is a COleClientItem object, functions that do not specifically implement active document containment functionality (such as OnDestroy, OnCancelEditCntr, OnSetFocus, and OnSize) can implement functionality provided by COM client item objects.
Note also that COleDocument maintains a list of COleClientItem objects, not COleDocObjectItem objects.