日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

MFC 多文档源码分析1

發布時間:2023/12/10 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MFC 多文档源码分析1 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
添加模板

在復寫的CWinApp::InitInstance()函數中添加下面代碼

CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate(IDR_SMARTTTYPE,RUNTIME_CLASS(CCosiWorksDoc),RUNTIME_CLASS(CChildFrame), // custom MDI child frameRUNTIME_CLASS(CCosiWorksView)); AddDocTemplate(pDocTemplate);new一個CMultiDocTemplate,并用doc,frame,view的CRuntimeClass類初始化CMultiDocTemplate

然后調用AddDocTemplate,往CWinApp的成員m_pDocManager變量,文檔管理器中添加模板

void CWinApp::AddDocTemplate(CDocTemplate* pTemplate) {if (m_pDocManager == NULL)m_pDocManager = new CDocManager;m_pDocManager->AddDocTemplate(pTemplate); }打開文檔
CDocument* CWinApp::OpenDocumentFile(LPCTSTR lpszFileName) {ENSURE_VALID(m_pDocManager);return m_pDocManager->OpenDocumentFile(lpszFileName); }CDocument* CDocManager::OpenDocumentFile(LPCTSTR lpszFileName) {POSITION pos = m_templateList.GetHeadPosition();CDocTemplate* pBestTemplate = NULL;while (pos != NULL){CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos);CDocTemplate::Confidence match;match = pTemplate->MatchDocType(szPath, pOpenDocument);if (match > bestMatch){bestMatch = match;pBestTemplate = pTemplate;}if (match == CDocTemplate::yesAlreadyOpen)break; // stop here}return pBestTemplate->OpenDocumentFile(szPath);}CDocument* CMultiDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName,BOOL bMakeVisible) {CDocument* pDocument = CreateNewDocument(); }CDocument* CDocTemplate::CreateNewDocument() {CDocument* pDocument = (CDocument*)m_pDocClass->CreateObject();return pDocument; }void CMultiDocTemplate::AddDocument(CDocument* pDoc) {ASSERT_VALID(pDoc);CDocTemplate::AddDocument(pDoc);ASSERT(m_docList.Find(pDoc, NULL) == NULL); // must not be in listm_docList.AddTail(pDoc); }CDocument* CMultiDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName,BOOL bMakeVisible) {CDocument* pDocument = CreateNewDocument();CFrameWnd* pFrame = CreateNewFrame(pDocument, NULL); }CFrameWnd* CDocTemplate::CreateNewFrame(CDocument* pDoc, CFrameWnd* pOther) {CFrameWnd* pFrame = (CFrameWnd*)m_pFrameClass->CreateObject(); }CDocument* CMultiDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName,BOOL bMakeVisible) {CDocument* pDocument = CreateNewDocument();CFrameWnd* pFrame = CreateNewFrame(pDocument, NULL);pDocument->OnOpenDocument(lpszPathName); }到這里調用到了CMultiDocTemplate中實際的文檔里,就是RUNTIME_CLASS(CCosiWorksDoc)

總結

以上是生活随笔為你收集整理的MFC 多文档源码分析1的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。