Udostępnij za pośrednictwem


COleLinkingDoc Class

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

class COleLinkingDoc : public COleDocument

Remarks

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 COleContainerApp : public CWinApp
{
protected:
   COleTemplateServer m_server;
   // remainder of class declaration ommitted

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

// CMyLinkDoc is derived from COleLinkingDoc
   CMultiDocTemplate* pDocTemplate = new CMultiDocTemplate(IDR_LINKDOCTYPE,
      RUNTIME_CLASS(CMyLinkDoc),
      RUNTIME_CLASS(CChildFrame),
      RUNTIME_CLASS(CMyLinkView));
    if (!pDocTemplate)
        return FALSE;
   pDocTemplate->SetContainerInfo(IDR_OLECONTTYPE_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.

Requirements

Header: afxole.h

See Also

Tasks

OCLIENT Sample: Illustrates a Visual Editing Container Application

Reference

COleDocument Class

Hierarchy Chart

CDocTemplate Class

Other Resources

COleLinkingDoc Members