扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:宋宝华 来源:天极开发 2007年10月16日
关键字:
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: // windowTitle\ndocName\n ... (see DocStringIndex enum) }; |
CDocTemplate::CDocTemplate(UINT nIDResource, CRuntimeClass* pDocClass, CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass) { ASSERT_VALID_IDR(nIDResource); ASSERT(pDocClass == NULL || pDocClass->IsDerivedFrom(RUNTIME_CLASS(CDocument))); ASSERT(pFrameClass == NULL ||pFrameClass->IsDerivedFrom(RUNTIME_CLASS(CFrameWnd))); ASSERT(pViewClass == NULL || pViewClass->IsDerivedFrom(RUNTIME_CLASS(CView))); m_nIDResource = nIDResource; m_nIDServerResource = NULL; m_nIDEmbeddingResource = NULL; m_nIDContainerResource = NULL; m_pDocClass = pDocClass; m_pFrameClass = pFrameClass; m_pViewClass = pViewClass; m_pOleFrameClass = NULL; m_pOleViewClass = NULL; m_pAttachedFactory = NULL; m_hMenuInPlace = NULL; m_hAccelInPlace = NULL; m_hMenuEmbedding = NULL; m_hAccelEmbedding = NULL; m_hMenuInPlaceServer = NULL; m_hAccelInPlaceServer = NULL; // add to pStaticList if constructed as static instead of on heap if (CDocManager::bStaticInit) { m_bAutoDelete = FALSE; if (CDocManager::pStaticList == NULL) CDocManager::pStaticList = new CPtrList; if (CDocManager::pStaticDocManager == NULL) CDocManager::pStaticDocManager = new CDocManager; CDocManager::pStaticList->AddTail(this); } else { m_bAutoDelete = TRUE; // usually allocated on the heap LoadTemplate(); } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者