The CDocument class implements standard document behavior in a stand-alone application. When the application runs as an OLE in-place editing server, however, the document must do extra work on behalf of OLE. The framework implements the bulk of this OLE document support in class COleServerDoc. The remaining work you have to do is:
CScribbleDoc
from CDocument to COleServerDoc.To change the base class of CScribbleDoc
CScribbleDoc
and change:class CScribbleDoc : public CDocument
to:
class CScribbleDoc : public COleServerDoc
This changes the base class reference of CScribbleDoc
from CDocument to COleServerDoc.
The COleServerItem object represents the Scribble document when the document is embedded in a container. To create a COleServerItem for a given document, AppWizard provides an override of GetEmbeddedItem in the COleServerDoc-derived class. The return type of OnGetEmbeddedItem is a pointer to a COleServerItem.
Note A COleServerItem object can also represent an OLE link item, but Scribble doesn’t illustrate that. The sample HIERSVR illustrates this link item.
In the following procedure, you’ll fill in some of the code that AppWizard would have generated had you originally chosen the Full-server option.
To implement the document’s support for embedded items
CScribbleItem
immediately before the line class CScribbleDoc : public COleServerDoc
:class CScribbleItem;
#include "scribbleDoc.h"
:#include "ScribbleItem.h"
Note The short filename for this header file is ScribItm.h. If you’re starting from the sample source files from Scribble Step 6 to complete this tutorial step, you must use this short filename. Otherwise, you will not be able to compile your project.
Now you’ll add the OnGetEmbeddedItem
function override. (AppWizard provided this code in the Scratch version of Scribble you generated with Full-server support.)
CScribbleDoc
class icon.COleServerItem*
.OnGetEmbeddedItem()
.// OnGetEmbeddedItem is called by the framework to get the COleServerItem
// that is associated with the document. It is only called when necessary.
CScribbleItem* pItem = new CScribbleItem(this);
ASSERT_VALID(pItem);
return pItem;
CScribbleItem* GetEmbeddedItem()
{ return (CScribbleItem*)COleServerDoc::GetEmbeddedItem(); }
Note AppWizard provided this code in the \Scratch\Scribble project, but you must insert it manually in the Scribble project.
This code provides a type-safe function to return a pointer to the specific COleServerItem-derived class, CScribbleItem.