Export (0) Print
Expand All

COleLinkingDoc Class 

The base class for OLE container documents that support linking to the embedded items they contain.


class COleLinkingDoc : public COleDocument

A container application that supports linking to embedded items is called a "link container." The OCLIENT sample application is an example of a link container.

When a linked item's source is an embedded item in another document, that containing document must be loaded in order for the embedded item to be edited. For this reason, a link container must be able to be launched by another container application when the user wants to edit the source of a linked item. Your application must also use the COleTemplateServer class so that it can create documents when launched programmatically.

To make your container a link container, derive your document class from COleLinkingDoc instead of COleDocument. As with any other OLE container, you must design your class for storing the application's native data as well as embedded or linked items. Also, you must design data structures for storing your native data. If you define a CDocItem-derived class for your application's native data, you can use the interface defined by COleDocument to store your native data as well as your OLE data.

To allow your application to be launched programmatically by another container, declare a COleTemplateServer object as a member of your application's CWinApp-derived class:

class COleClientApp : public CWinApp
{
// ...
protected:
   COleTemplateServer m_server;
// ...
};

In the InitInstance member function of your CWinApp-derived class, create a document template and specify your COleLinkingDoc-derived class as the document class:

// CMainDoc is derived from COleLinkingDoc
CMultiDocTemplate* pDocTemplate = new CMultiDocTemplate(IDR_OCLIENTTYPE,
   RUNTIME_CLASS(CMainDoc),
   RUNTIME_CLASS(CSplitFrame),
   RUNTIME_CLASS(CMainView));
pDocTemplate->SetContainerInfo(
   IDR_OCLIENTTYPE_CNTR_IP);
AddDocTemplate(pDocTemplate);

Connect your COleTemplateServer object to your document templates by calling the object's ConnectTemplate member function, and register all class objects with the OLE system by calling COleTemplateServer::RegisterAll:

m_server.ConnectTemplate(clsid, pDocTemplate, FALSE);
COleTemplateServer::RegisterAll();

For a sample CWinApp-derived class definition and InitInstance function, see OCLIENT.H and OCLIENT.CPP in the MFC sample OCLIENT.

For more information on using COleLinkingDoc, see the articles Containers: Implementing a Container and Containers: Advanced Features.

Header: afxole.h

This class is not supported in Smart Device projects.

Community Additions

ADD
Show:
© 2014 Microsoft