Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
| 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, , and then follow the steps described.
To add Active document support to an existing server
In your project’s stdafx.h, add the following line of code to include document object support:
#include <afxdocob.h>In your CWinApp-derived class, change the parameter to UpdateRegistry from
OAT_INPLACE_SERVERtoOAT_DOC_OBJECT_SERVER:m_server.UpdateRegistry(OAT_DOC_OBJECT_SERVER);In your in-place frame class, change its derived class from
COleIPFrameWndtoCOleDocIPFrameWnd. 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 COleDocIPFrameWndIn the .CPP file, search for
COleIPFrameWndand replace each occurrence withCOleDocIPFrameWnd.
In your item class, change its derived class to
CDocObjectServerItem:class CMyItem : public CDocObjectServerItemIn the .CPP file, search for
COleServerItemand replace each occurrence withCDocObjectServerItem.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_MAPmacro, add macro entries for each of your message-handler functions, and add theEND_OLECMD_MAPmacro. 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_PRINTandID_FILE_PAGE_SETUP. You must have command maps for these functions in your code, for example:ON_COMMAND (ID_FILE_PRINT, OnFilePrint)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); }