Export (0) Print
Expand All

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 intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To get samples and instructions for installing them:

To access samples from Visual Studio

  • On the Help menu, click Samples.

    By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.

  • For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.

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.

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.

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

NoteNote

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.

Other Resources

Show:
© 2014 Microsoft