Creating an Active Document Container Application

HomeOverviewHow Do I

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

  1. From the File menu, choose New.

  2. On the Projects tab, click MFC AppWizard (exe). Name the project MyProj.

  3. In Step 3 of the AppWizard, select the Container or Both container and server button.

  4. Click Finish.

  5. When the AppWizard finishes generating the application, select the FileView tab and open the following files:
  6. In Cntritem.cpp, make the following changes:
  7. In Cntritem.h, make the following changes:
  8. In MyProjview.cpp, make the following changes:

    OnPreparePrinting provides printing support. This code replaces DoPreparePrinting, which is the default print preparation.

    
    

    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.

  9. In MyProjview.h, make the following changes:

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.

  1. Add any implementation of your own and build the application.