WEB开发网
开发学院软件开发VC 深入浅出MFC“文档/视图”架构(2)――文档模板 阅读

深入浅出MFC“文档/视图”架构(2)――文档模板

 2009-02-11 20:00:37 来源:WEB开发网   
核心提示: 2.文档模板类CDocTemplate文档模板类CDocTemplate是一个抽象基类(这意味着不能直接用它来定义对象而必须用它的派生类),它定义了文档模板的基本处理函数接口,深入浅出MFC“文档/视图”架构(2)――文档模板(4),对一个单文档界面程序,需使用单文档模板类CSingleD

2.文档模板类CDocTemplate

文档模板类CDocTemplate是一个抽象基类(这意味着不能直接用它来定义对象而必须用它的派生类),它定义了文档模板的基本处理函数接口。对一个单文档界面程序,需使用单文档模板类CSingleDocTemplate,而对于一个多文档界面程序,需使用多文档模板类CMultipleDocTemplate。我们首先来看看CDocTemplate类的声明:

class CDocTemplate : public CCmdTarget
{
    DECLARE_DYNAMIC(CDocTemplate)
  
// Constructors
protected:
    CDocTemplate(UINT nIDResource, CRuntimeClass* pDocClass,
       CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass);
  
public:
    virtual void LoadTemplate();
  
// Attributes
public:
    // setup for OLE containers
    void SetContainerInfo(UINT nIDOleInPlaceContainer);
  
    // setup for OLE servers
    void SetServerInfo(UINT nIDOleEmbedding, UINT nIDOleInPlaceServer = 0,
       CRuntimeClass* pOleFrameClass = NULL, CRuntimeClass* pOleViewClass = NULL);
  
    // iterating over open documents
    virtual POSITION GetFirstDocPosition() const = 0;
    virtual CDocument* GetNextDoc(POSITION& rPos) const = 0;
  
// Operations
public:
    virtual void AddDocument(CDocument* pDoc);   // must override
    virtual void RemoveDocument(CDocument* pDoc);  // must override
  
    enum DocStringIndex
    {
       windowTitle,    // default window title
       docName,      // user visible name for default document
       fileNewName,    // user visible name for FileNew
       // for file based documents:
       filterName,     // user visible name for FileOpen
       filterExt,     // user visible extension for FileOpen
       // for file based documents with Shell open support:
       regFileTypeId,   // REGEDIT visible registered file type identifier
       regFileTypeName,  // Shell visible registered file type name
    };
    virtual BOOL GetDocString(CString& rString,
       enum DocStringIndex index) const; // get one of the info strings
    CFrameWnd* CreateOleFrame(CWnd* pParentWnd, CDocument* pDoc,
       BOOL bCreateView);
  
// Overridables
public:
    enum Confidence
    {
       noAttempt,
       maybeAttemptForeign,
       maybeAttemptNative,
       yesAttemptForeign,
       yesAttemptNative,
       yesAlreadyOpen
    };
    virtual Confidence MatchDocType(LPCTSTR lpszPathName,
                  CDocument*& rpDocMatch);
    virtual CDocument* CreateNewDocument();
    virtual CFrameWnd* CreateNewFrame(CDocument* pDoc, CFrameWnd* pOther);
    virtual void InitialUpdateFrame(CFrameWnd* pFrame, CDocument* pDoc,
       BOOL bMakeVisible = TRUE);
    virtual BOOL SaveAllModified();   // for all documents
    virtual void CloseAllDocuments(BOOL bEndSession);
    virtual CDocument* OpenDocumentFile(
       LPCTSTR lpszPathName, BOOL bMakeVisible = TRUE) = 0;
                  // open named file
                  // if lpszPathName == NULL => create new file with this type
    virtual void SetDefaultTitle(CDocument* pDocument) = 0;
  
// Implementation
public:
    BOOL m_bAutoDelete;
    virtual ~CDocTemplate();
  
    // back pointer to OLE or other server (NULL if none or disabled)
    CObject* m_pAttachedFactory;
  
    // menu & accelerator resources for in-place container
    HMENU m_hMenuInPlace;
    HACCEL m_hAccelInPlace;
  
    // menu & accelerator resource for server editing embedding
    HMENU m_hMenuEmbedding;
    HACCEL m_hAccelEmbedding;
  
    // menu & accelerator resource for server editing in-place
    HMENU m_hMenuInPlaceServer;
    HACCEL m_hAccelInPlaceServer;
  
#ifdef _DEBUG
    virtual void Dump(CDumpContext&) const;
    virtual void AssertValid() const;
#endif
    virtual void OnIdle();       // for all documents
    virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
       AFX_CMDHANDLERINFO* pHandlerInfo);
  
protected:
    UINT m_nIDResource;         // IDR_ for frame/menu/accel as well
    UINT m_nIDServerResource;      // IDR_ for OLE inplace frame/menu/accel
    UINT m_nIDEmbeddingResource;    // IDR_ for OLE open frame/menu/accel
    UINT m_nIDContainerResource;    // IDR_ for container frame/menu/accel
  
    CRuntimeClass* m_pDocClass;     // class for creating new documents
    CRuntimeClass* m_pFrameClass;    // class for creating new frames
    CRuntimeClass* m_pViewClass;    // class for creating new views
    CRuntimeClass* m_pOleFrameClass;  // class for creating in-place frame
    CRuntimeClass* m_pOleViewClass;   // class for creating in-place view
  
    CString m_strDocStrings;  // 'n' separated names
       // The document names sub-strings are represented as _one_ string:
       // windowTitlendocNamen ... (see DocStringIndex enum)
};

上一页  1 2 3 4 5 6 7 8 9  下一页

Tags:深入浅出 MFC 文档

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接