我建立了两个文档模版
但是在使用
CSMSApp *pApp=(CSMSApp*)AfxGetApp();
pApp->m_pDocManager ->OnFileNew ();
打开时总提示我选择模版,
有没有办法在打开时指定模版参数而不出现提示?
应该很简单,正确就给100分!
但是在使用
CSMSApp *pApp=(CSMSApp*)AfxGetApp();
pApp->m_pDocManager ->OnFileNew ();
打开时总提示我选择模版,
有没有办法在打开时指定模版参数而不出现提示?
应该很简单,正确就给100分!
~~~~~~~~~~~~~~~~~~
用时在相应的位置自己直接调用就可以了ps:记得是这样,不过不太清楚了
在《mfc技术内幕》里有答案
\nYOURAPP\nYOURAPP\n\n\nYOURAPP.Document\nYOURAPP Document
::YOURAPP是你程序的名称,差不多是下面这个样子的:
\nSMS\nSMS\n\n\nSMS.Document\nSMS Document
把它该成:
\nSMS\nSMS\n\nSMS.Document\nSMS Document或者
\nSMS\nSMS\nSMS.Document\nSMS Document或者
\nSMS\nSMS.Document\nSMS Document或者
\nSMS.Document\nSMS Document
看看。如果不行,再改。增加或者减少\n是可以的。
{
if (m_templateList.IsEmpty())
{
TRACE0("Error: no document templates registered with CWinApp.\n");
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
return;
} CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetHead();
if (m_templateList.GetCount() > 1)
{
// more than one document template to choose from
// bring up dialog prompting user
CNewTypeDlg dlg(&m_templateList);
int nID = dlg.DoModal();
if (nID == IDOK)
pTemplate = dlg.m_pSelectedTemplate;
else
return; // none - cancel operation
} ASSERT(pTemplate != NULL);
ASSERT_KINDOF(CDocTemplate, pTemplate); pTemplate->OpenDocumentFile(NULL);
// if returns NULL, the user has already been alerted
}
你看看你调用函数的源代码吧。知道怎么做了吧?
virtual CDocTemplate* GetNextDocTemplate(POSITION& pos) const;
virtual CDocument* OpenDocumentFile(LPCTSTR lpszFileName); // open named file
还有你看看下面的原代码:
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);
}
你从原代码能看到一点端倪你就知道怎么做了。
拐一个弯吧。直接这样调用OnFileNew()没有那么容易的。