Home | Overview | How Do I | FAQ | Details
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, Creating an OLE Server, and then follow the steps described.
To add Active document support to an existing server
#include <afxdocob.h>
OAT_INPLACE_SERVER
to OAT
_DOC_OBJECT
_SERVER
:
m_server.UpdateRegistry(OAT_DOC_OBJECT_SERVER);
COleIPFrameWnd
to COleDocIPFrameWnd
. You will need to make changes in both the .H file and in the .CPP file.
class CInPlaceFrame : public COleDocIPFrameWnd
COleIPFrameWnd
and replace each occurrence with COleDocIPFrameWnd
. CDocObjectServerItem
:
class CMyItem : public CDocObjectServerItem
In the .CPP file, search for COleServerItem
and replace each occurrence with CDocObjectServerItem
.
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)
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);
}