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 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.

Building and Running the Sample

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.

Sample Files

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.

Keywords

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; hdcDraw;; 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;RECT; RemoveMenu; SelectObject; SendMessage; SetActiveObject; SetBkMode; SetBorderSpace; SetControlFocus; SetFocus; SetInPlaceSite; SetMenu; SetObjectRects; SetTextColor; ShowObject; ShowWindow; UIActivate; UIDeactivate; UnmergeMenus; ZeroMemory

See Also

Other Resources

ATL Samples