Creating an Active Document Container Application
The simplest and most recommended way to create an active document container application is to create an MFC EXE container application using the MFC Application Wizard, then modify the application to support active document containment.
To create an active document container application
From the File menu, click Projectfrom the New submenu.
From the left pane, click Visual C++ project type.
Select MFC Application from the right pane.
Name the project MyProj, click OK.
Select the Compound Document Support page.
Select the Container or Container/Full-server option.
Select the Active document container check box.
Click Finish.
When the MFC Application Wizard finishes generating the application, open the following files using Solution Explorer:
- MyProjview.cpp
In MyProjview.cpp, make the following changes:
In
CMyProjView::OnPreparePrinting
, replace the function contents with the following code:if (!CView::OnPreparePrinting(pInfo)) return FALSE; if (!COleDocObjectItem::OnPreparePrinting(this, pInfo)) return FALSE; return TRUE;
OnPreparePrinting
provides printing support. This code replacesDoPreparePrinting
, which is the default print preparation.Active document containment provides an improved printing scheme:
You can first call the active document through its
IPrint
interface and tell it to print itself. This is different from previous OLE containment, in which the container had to render an image of the contained item onto the printerCDC
object.If that fails, tell the contained item to print itself through its
IOleCommandTarget
interfaceIf that fails, make your own rendering of the item.
The static member functions
COleDocObjectItem::OnPrint
andCOleDocObjectItem::OnPreparePrinting
, as implemented in the previous code, handle this improved printing scheme.Add any implementation of your own and build the application.