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

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

 2009-02-11 20:00:34 来源:WEB开发网   
核心提示:1.文档类CDocument在“文档/视图”架构的MFC程序中,文档是一个CDocument派生对象,深入浅出MFC“文档/视图”架构(3)――文档,它负责存储应用程序的数据,并把这些信息提供给应用程序的其余部分

1.文档类CDocument

在“文档/视图”架构的MFC程序中,文档是一个CDocument派生对象,它负责存储应用程序的数据,并把这些信息提供给应用程序的其余部分。CDocument类对文档的建立及归档提供支持并提供了应用程序用于控制其数据的接口,类CDocument的声明如下:

/////////////////////////////////////////////////////////////////////////////
// class CDocument is the main document data abstraction
class CDocument : public CCmdTarget
{
    DECLARE_DYNAMIC(CDocument)
  
public:
// Constructors
    CDocument();
  
// Attributes
public:
    const CString& GetTitle() const;
    virtual void SetTitle(LPCTSTR lpszTitle);
    const CString& GetPathName() const;
    virtual void SetPathName(LPCTSTR lpszPathName, BOOL bAddToMRU = TRUE);
  
    CDocTemplate* GetDocTemplate() const;
    virtual BOOL IsModified();
    virtual void SetModifiedFlag(BOOL bModified = TRUE);
  
// Operations
    void AddView(CView* pView);
    void RemoveView(CView* pView);
    virtual POSITION GetFirstViewPosition() const;
    virtual CView* GetNextView(POSITION& rPosition) const;
  
    // Update Views (simple update - DAG only)
    void UpdateAllViews(CView* pSender, LPARAM lHint = 0L,
       CObject* pHint = NULL);
  
// Overridables
    // Special notifications
    virtual void OnChangedViewList(); // after Add or Remove view
    virtual void DeleteContents(); // delete doc items etc
  
    // File helpers
    virtual BOOL OnNewDocument();
    virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
    virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
    virtual void OnCloseDocument();
    virtual void ReportSaveLoadException(LPCTSTR lpszPathName,
              CException* e, BOOL bSaving, UINT nIDPDefault);
    virtual CFile* GetFile(LPCTSTR lpszFileName, UINT nOpenFlags,
       CFileException* pError);
    virtual void ReleaseFile(CFile* pFile, BOOL bAbort);
  
    // advanced overridables, closing down frame/doc, etc.
    virtual BOOL CanCloseFrame(CFrameWnd* pFrame);
    virtual BOOL SaveModified(); // return TRUE if ok to continue
    virtual void PreCloseFrame(CFrameWnd* pFrame);
  
// Implementation
protected:
    // default implementation
    CString m_strTitle;
    CString m_strPathName;
    CDocTemplate* m_pDocTemplate;
    CPtrList m_viewList;        // list of views
    BOOL m_bModified;          // changed since last saved
  
public:
    BOOL m_bAutoDelete;   // TRUE => delete document when no more views
    BOOL m_bEmbedded;    // TRUE => document is being created by OLE
  
#ifdef _DEBUG
    virtual void Dump(CDumpContext&) const;
    virtual void AssertValid() const;
#endif //_DEBUG
    virtual ~CDocument();
  
    // implementation helpers
    virtual BOOL DoSave(LPCTSTR lpszPathName, BOOL bReplace = TRUE);
    virtual BOOL DoFileSave();
    virtual void UpdateFrameCounts();
    void DisconnectViews();
    void SendInitialUpdate();
  
    // overridables for implementation
    virtual HMENU GetDefaultMenu(); // get menu depending on state
    virtual HACCEL GetDefaultAccelerator();
    virtual void OnIdle();
    virtual void OnFinalRelease();
  
    virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
       AFX_CMDHANDLERINFO* pHandlerInfo);
    friend class CDocTemplate;
  
protected:
    // file menu commands
    //{{AFX_MSG(CDocument)
    afx_msg void OnFileClose();
    afx_msg void OnFileSave();
    afx_msg void OnFileSaveAs();
    //}}AFX_MSG
    // mail enabling
    afx_msg void OnFileSendMail();
    afx_msg void OnUpdateFileSendMail(CCmdUI* pCmdUI);
    DECLARE_MESSAGE_MAP()
};

1 2 3 4 5 6  下一页

Tags:深入浅出 MFC 文档

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