This documentation is archived and is not being maintained.

ACTIVEDOC Sample: Implements an Active Document Server

The ACTIVEDOC sample demonstrates how to implement an Active Document Server. The sample demonstrates the following:

  • How to implement the interfaces IOleDocument and IOleDocumentView.

  • How to perform menu merging with the container.

  • How to implement a toolbar in your object.

  • How to override the IPersistStreamInit methods Load and Save to perform custom saving and loading.

  • How to use CDialogImpl to implement an About dialog box.

  • How to subclass the Rich Text Edit Control.

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.

To build the sample

  1. Open the solution ActiveDoc.sln.

  2. From the Build menu, click Build Solution.

To run the sample using Internet Explorer

  1. Open ActiveDoc.htm or the ActiveDoc.AAA generated file in Internet Explorer (to open ActiveDoc.AAA, click the Open button when prompted to open this file).

  2. Use the Format menu that has been merged into Internet Explorer's menu bar, or just click the toolbar colors to change the color of the typed text.

To run the sample using Microsoft Office Binder

  1. Run Microsoft Office Binder and from the Section menu click Add.

  2. Select the icon labeled "ActiveDoc Class" and click OK.

    You should see the object embedded in Office Binder. Notice that the menus have been merged and the ActiveDoc's toolbar is shown. You can enter text and use the menu and toolbar buttons to change the color of the text that is typed.

The sample includes the following main files:

  • ActiveCtl.h

  • ActiveCtl.cpp — implements CActiveDoc, which represents the overall ActiveDoc object.

  • OleDocument.h — contains the implementation of the IOleDocument and IOleDocumentView interfaces.

  • Toolbar.h — contains CToolbar, which helps with the implementation of the toolbar.

This sample uses the following keywords:

ActiveXDocActivate; ALT_MSG_MAP; ATLASSERT; ATLTRACE; BEGIN_COM_MAP; BEGIN_MSG_MAP; BEGIN_OBJECT_MAP; BEGIN_PROPERTY_MAP; BEGIN_TOOLBAR_MAP; CAboutDlg::DoModal; CanInPlaceActivate; CComCoClass; CComControl; CComModule::GetClassObject; CComModule::GetLockCount; CComModule::Init; CComModule::RegisterServer; CComModule::Term; CComModule::UnregisterServer; CComObjectRoot; CComObjectRootEx::InternalQueryInterface; CComPtr; CHARFORMAT; CMenu; COM_INTERFACE_ENTRY; COM_INTERFACE_ENTRY_IMPL; COMMAND_ID_HANDLER; COMMAND_RANGE_HANDLER; CreateMenu; CreateRTFWindow; CreateToolbar; CreateWindowEx; CToolbar; CWindow::DestroyWindow; CWindow::ModifyStyle; CWindow::SetFocus; CWindow::SetParent; CWindow::SetWindowPos; DECLARE_REGISTRY_RESOURCEID; DestroyMenu; DestroyToolbar; DisableThreadLibraryCalls; DllMain; DoesVerbUIActivate; EDITSTREAM::dwCookie; EDITSTREAM::dwError; EDITSTREAM::pfnCallback; Ellipse; END_COM_MAP; END_MSG_MAP; END_OBJECT_MAP; END_PROPERTY_MAP; END_TOOLBAR_MAP; EndDialog; ExtTextOut; FreeLibrary; GetMenuItemCount; GetMenuItemID; GetMenuState; GetMenuString; GetResourceInstance; GetStockObject; GetSubMenu; GetTextMetrics; GetWindow; GetWindowContext; GetWindowRect; HDC; IDataObjectImpl; IDispatchImpl; InitCommonControls; InlineIsEqualGUID; InPlaceDeactivate; InPlaceMenuCreate; InPlaceMenuDestroy; InsertMenu; InterfaceSupportsErrorInfo; InternalQueryInterface; IOleControlImpl; IOleDocument::GetDocMiscStatus; IOleDocumentImpl; IOleDocumentView::ApplyViewState; IOleDocumentView::SetInPlaceSite; IOleDocumentViewImpl; IOleInPlaceActiveObjectImpl; IOleInPlaceFrame; IOleInPlaceFrame::InsertMenus; IOleInPlaceFrame::Release; IOleInPlaceFrame::SetMenu; IOleInPlaceObjectWindowlessImpl; IOLEInPlaceSite::GetWindowContext; IOleObjectImpl; IPersistStorageImpl; IPersistStreamInitImpl; IProvideClassInfo2Impl; IQuickActivateImpl; ISupportErrorImpl; IViewObjectExImpl; LoadLibrary; LoadMenu; LoadString; MAKEINTRESOURCE; MergeMenus; MESSAGE_HANDLER; NOTIFY_CODE_HANDLER; OBJECT_ENTRY; OleCreateMenuDescriptor; OLEINPLACEFRAMEINFO; OnInPlaceActivate; OnUIActivate; prcBounds; RECT; RemoveMenu; SelectObject; SendMessage; SetActiveObject; SetBkMode; SetBorderSpace; SetControlFocus; SetFocus; SetInPlaceSite; SetMenu; SetObjectRects; SetTextColor; ShowObject; ShowWindow; UIActivate; UIDeactivate; UnmergeMenus; ZeroMemory

Other Resources