MFCBIND Sample: Active Document Container

The MFCBIND sample shows how to create an Active document (formerly known as a DocObject) container using the Active document container support classes in MFC. The MFC Binder sample is an SDI application that uses the COleDocObjectItem class to represent an embedded Active document in an MFC document. MFCBIND works much like the Office Binder application, which ships with Microsoft Office.

Security noteSecurity Note:

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To get samples and instructions for installing them:

  • On the Visual Studio Help menu, click Samples.

    For more information, see Visual Studio Samples.

  • The most recent version and complete list of samples is available online from the Visual Studio 2008 Samples page.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied into a folder under \Program Files\Visual Studio 9.0\Samples\. For Express editions of Visual Studio, all samples are located online.

Building and Running the Sample

To build and run the MFCBIND sample

  1. Open the solution mfcbind.sln.

  2. On the Build menu, click Build.

  3. Start the application and click the Add menu item from the Section menu to add to the binder as many sections as you want.

    Image, Word, and Excel documents are examples of sections. When you add a section to the binder, you can edit it directly from within the MFC Binder application as though you were working in the section's native application.

  4. When you finish editing the sections in the binder, save the binder by clicking Save on the File menu. Save saves the sections in the binder to a single file. When you reopen the binder later, the sections are available in their previously saved state.

Active Documents in MFC

In MFC, Active documents are handled much the same way regular in-place editable embeddings are handled. The COleDocument-derived class still maintains a list of the currently embedded items. The COleClientItem object, which is replaced by the COleClientItem-derived COleDocObjectItem class, represents the embedded item in the COleDocument. It is these COleDocObjectItem-derived items that are maintained in a list by the COleDocument-derived class. Active documents, however, take up the entire client area of the view when they are in-place active. An Active document container also has full control of the Help menu, unlike the older in-place embeddings. The Help menu contains menu items for both the Active document container and server. Because the Active document container owns the Help menu, it is responsible for forwarding messages for the server's part of the Help menu to the server. The help menu merging and message forwarding functionality is completely handled by the MFC framework.

Keywords

This sample demonstrates the following keywords:

COleClientItem::FinishCreate, COleClientItem::GetIconFromRegistry, IOleObject::GetUserClassID, COleClientItem::OnChange, COleClientItem::OnChangeItemPosition, COleClientItem::OnGetItemPosition, COleClientItem::OnActivate, COleDocument::GetInPlaceActiveItem, COleClientItem::Deactivate, COleClientItem::CreateNewItem, COleClientItem::DoVerb, COleDocObjectItem::COleDocObjectItem, COleClientItem::CreateFromFile, COleClientItem::Activate, COleDocObjectItem::OnPreparePrintin, COleDocObjectItem::OnPrint, SystemParametersInfo, MeasureItem, DrawItem, GetSystemMetrics, SelectObject

Note

Some samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.

See Also

Other Resources

MFC Samples