Share via


Upgrade to an Active Document Server

OverviewHow Do IFAQDetails

If your application was created with a version of Visual C++ prior to version 4.2 and is already an in-place server, you can add Active document support by following the procedure below. If your application is not already an in-place server, you must first add this support as described in the tutorial, , and then follow the steps described.

To add Active document support to an existing server

  1. In your project’s stdafx.h, add the following line of code to include document object support:

    #include <afxdocob.h>
    
  2. In your CWinApp-derived class, change the parameter to UpdateRegistry from OAT_INPLACE_SERVER to OAT_DOC_OBJECT_SERVER:

    m_server.UpdateRegistry(OAT_DOC_OBJECT_SERVER);
    
  3. In your in-place frame class, change its derived class from COleIPFrameWnd to COleDocIPFrameWnd. You will need to make changes in both the .H file and in the .CPP file.

    • In the header file, derive your in-place frame class from COleDocIPFrameWnd:

      class CInPlaceFrame : public COleDocIPFrameWnd
      
    • In the .CPP file, search for COleIPFrameWnd and replace each occurrence with COleDocIPFrameWnd.

  4. In your item class, change its derived class to CDocObjectServerItem:

    class CMyItem : public CDocObjectServerItem
    

    In the .CPP file, search for COleServerItem and replace each occurrence with CDocObjectServerItem.

  5. In your document class header file, insert the following line to add a parse map to route OLE menu commands such as Print between the container and your server. (Add the line in the message map function section, after the line DECLARE_MESSAGE_MAP.)

    DECLARE_OLECMD_MAP()
    

    In the document class .CPP file, use the BEGIN_OLECMD_MAP macro, add macro entries for each of your message-handler functions, and add the END_OLECMD_MAP macro. An AppWizard-generated application contains the following map:

    BEGIN_OLECMD_MAP(CMyDoc, COleServerDoc)
    ON_OLECMD_PAGESETUP()
    ON_OLECMD_PRINT()
    END_OLECMD_MAP()
    

    This OLE command map routes the Print and Page Setup commands to their handler functions using standard IDs ID_FILE_PRINT and ID_FILE_PAGE_SETUP. You must have command maps for these functions in your code, for example:

    ON_COMMAND (ID_FILE_PRINT, OnFilePrint)
    
  6. In your document class header file, add a function declaration in the public section of your document class:

    CDocObjectServer* GetDocObjectServer(LPOLEDOCUMENTSITE pSite);
    

    In your document class header file, implement the function as follows:

    CDocObjectServer* CMyDoc::GetDocObjectServer(LPOLEDOCUMENTSITE pSite)
    {
    return new CDocObjectServer(this, pSite);
    }