关于Document Template? 如果一个程序有两个不同的Document Template,那么如何判断当前使用的是哪个? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 新建文档时会提示你选择打开时CDocManager调用MatchDocType来找大匹配的Template.MatchDocType是跟据DocumentTemplete对应的文件后坠判断的。 GetDocTemplate()->GetDocString遍历doctemplate用CWinApp::GetFirstDocTemplatePosition+GetNextDocTemplate 读一下就明白了CDocument* CDocManager::OpenDocumentFile(LPCTSTR lpszFileName){ // find the highest confidence POSITION pos = m_templateList.GetHeadPosition(); CDocTemplate::Confidence bestMatch = CDocTemplate::noAttempt; CDocTemplate* pBestTemplate = NULL; CDocument* pOpenDocument = NULL; TCHAR szPath[_MAX_PATH]; ASSERT(lstrlen(lpszFileName) < _countof(szPath)); TCHAR szTemp[_MAX_PATH]; if (lpszFileName[0] == '\"') ++lpszFileName; lstrcpyn(szTemp, lpszFileName, _MAX_PATH); LPTSTR lpszLast = _tcsrchr(szTemp, '\"'); if (lpszLast != NULL) *lpszLast = 0; AfxFullPath(szPath, szTemp); TCHAR szLinkName[_MAX_PATH]; if (AfxResolveShortcut(AfxGetMainWnd(), szPath, szLinkName, _MAX_PATH)) lstrcpy(szPath, szLinkName); while (pos != NULL) { CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos); ASSERT_KINDOF(CDocTemplate, pTemplate); CDocTemplate::Confidence match; ASSERT(pOpenDocument == NULL); match = pTemplate->MatchDocType(szPath, pOpenDocument); if (match > bestMatch) { bestMatch = match; pBestTemplate = pTemplate; } if (match == CDocTemplate::yesAlreadyOpen) break; // stop here } if (pOpenDocument != NULL) { POSITION pos = pOpenDocument->GetFirstViewPosition(); if (pos != NULL) { CView* pView = pOpenDocument->GetNextView(pos); // get first one ASSERT_VALID(pView); CFrameWnd* pFrame = pView->GetParentFrame(); if (pFrame != NULL) pFrame->ActivateFrame(); else TRACE0("Error: Can not find a frame for document to activate.\n"); CFrameWnd* pAppFrame; if (pFrame != (pAppFrame = (CFrameWnd*)AfxGetApp()->m_pMainWnd)) { ASSERT_KINDOF(CFrameWnd, pAppFrame); pAppFrame->ActivateFrame(); } } else { TRACE0("Error: Can not find a view for document to activate.\n"); } return pOpenDocument; } if (pBestTemplate == NULL) { AfxMessageBox(AFX_IDP_FAILED_TO_OPEN_DOC); return NULL; } return pBestTemplate->OpenDocumentFile(szPath);} POSITION curTemplatePos = GetFirstDocTemplatePosition(); while(curTemplatePos != NULL) { CDocTemplate* curTemplate = GetNextDocTemplate(curTemplatePos); CString str; curTemplate->GetDocString(str, CDocTemplate::docName); if(str == _T("文档名")) { curTemplate->OpenDocumentFile(NULL); return; } }其中文档名对应文档在创建视对应的一个字符串资源当中的文档信息的\n与\n之间的内容 qrlvls(怜松) ( ) 的简单 ActiveX控件,IE第一次加载时提示是否运行? 求助:指针与引用的区别 CFormView相关 还是关于那个"棒子"旋转的问题 入门级的网络编程问题,请帮帮忙 请问如何填充静态文本的背景和EDIT控件的背景颜色? 请问如何实现文件拷贝?? 救救我,文件无法拷贝 VC下的一个小问题。百分。UP者有分。 想设计一个不可视的类,要求能 关于installshield的一个简单的问题:我做一个setup ,仅包括一个exe,其他什么也没有,做好后,去安装,竟然什么东西也没有,就一个unins 请教: 为什么CDaoDatabase.Open() 抛出异常???
打开时CDocManager调用MatchDocType来找大匹配的Template.
MatchDocType是跟据DocumentTemplete对应的文件后坠判断的。
遍历doctemplate用CWinApp::GetFirstDocTemplatePosition+GetNextDocTemplate
CDocument* CDocManager::OpenDocumentFile(LPCTSTR lpszFileName)
{
// find the highest confidence
POSITION pos = m_templateList.GetHeadPosition();
CDocTemplate::Confidence bestMatch = CDocTemplate::noAttempt;
CDocTemplate* pBestTemplate = NULL;
CDocument* pOpenDocument = NULL; TCHAR szPath[_MAX_PATH];
ASSERT(lstrlen(lpszFileName) < _countof(szPath));
TCHAR szTemp[_MAX_PATH];
if (lpszFileName[0] == '\"')
++lpszFileName;
lstrcpyn(szTemp, lpszFileName, _MAX_PATH);
LPTSTR lpszLast = _tcsrchr(szTemp, '\"');
if (lpszLast != NULL)
*lpszLast = 0;
AfxFullPath(szPath, szTemp);
TCHAR szLinkName[_MAX_PATH];
if (AfxResolveShortcut(AfxGetMainWnd(), szPath, szLinkName, _MAX_PATH))
lstrcpy(szPath, szLinkName); while (pos != NULL)
{
CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos);
ASSERT_KINDOF(CDocTemplate, pTemplate); CDocTemplate::Confidence match;
ASSERT(pOpenDocument == NULL);
match = pTemplate->MatchDocType(szPath, pOpenDocument);
if (match > bestMatch)
{
bestMatch = match;
pBestTemplate = pTemplate;
}
if (match == CDocTemplate::yesAlreadyOpen)
break; // stop here
} if (pOpenDocument != NULL)
{
POSITION pos = pOpenDocument->GetFirstViewPosition();
if (pos != NULL)
{
CView* pView = pOpenDocument->GetNextView(pos); // get first one
ASSERT_VALID(pView);
CFrameWnd* pFrame = pView->GetParentFrame();
if (pFrame != NULL)
pFrame->ActivateFrame();
else
TRACE0("Error: Can not find a frame for document to activate.\n");
CFrameWnd* pAppFrame;
if (pFrame != (pAppFrame = (CFrameWnd*)AfxGetApp()->m_pMainWnd))
{
ASSERT_KINDOF(CFrameWnd, pAppFrame);
pAppFrame->ActivateFrame();
}
}
else
{
TRACE0("Error: Can not find a view for document to activate.\n");
}
return pOpenDocument;
} if (pBestTemplate == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_TO_OPEN_DOC);
return NULL;
} return pBestTemplate->OpenDocumentFile(szPath);
}
{
CDocTemplate* curTemplate = GetNextDocTemplate(curTemplatePos);
CString str;
curTemplate->GetDocString(str, CDocTemplate::docName);
if(str == _T("文档名"))
{
curTemplate->OpenDocumentFile(NULL);
return;
}
}其中文档名对应文档在创建视对应的一个字符串资源当中的文档信息的\n与\n之间的内容