DoPromptFileName(newName,bReplace?AFX_IDS_SAVEFILE:AFX_IDS_SAVEFILECOPY,OFN_HIDEREADONLY|OFN_PATHMUSTEXIST,FLASE,pTemplate)
我查了MSDN 没有查到
请问这个函数的作用是什么?
我大概知道是打开一个对话框让你输入(选择)路径名 然后猜测大概是:
1 把路径赋值给newName
2 创造一个空的文件(等待后面的OnSaveDocument函数写入数据)
请问是这样吗 还请高手帮忙
另外再问2个小问题:
1 这个AFX_IDS_SAVEFILE 和 AFX_IDS_SAVEFILECOPY分别让对话框有什么不一样的地方呢?
2 这个函数是谁的成员函数?CWinAPP? CDocument?
3 个解决方案
#1
LZ可真辛苦啊,没有分了 ,我实在是于心不忍。
#2
LS的 多谢关注啊 实在没分啊 我技术菜 也回答不了别人的问题去赚分啊
#3
解释这个问题的最好回答就是直接看MFC源代码就好了:
BOOL CDocument::DoSave(LPCTSTR lpszPathName, BOOL bReplace)
{
CString newName = lpszPathName;
if (newName.IsEmpty())
{
.......
if (!AfxGetApp()->DoPromptFileName(newName,
bReplace ? AFX_IDS_SAVEFILE : AFX_IDS_SAVEFILECOPY,
OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, FALSE, pTemplate))
return FALSE; // don't even attempt to save
}
......
}
=======================================================>
// prompt for file name - used for open and save as
BOOL CWinApp::DoPromptFileName(CString& fileName, UINT nIDSTitle, DWORD lFlags,
BOOL bOpenFileDialog, CDocTemplate* pTemplate)
// if pTemplate==NULL => all document templates
{
ASSERT(m_pDocManager != NULL);
return m_pDocManager->DoPromptFileName(fileName, nIDSTitle, lFlags,
bOpenFileDialog, pTemplate);
}
=======================================================>
BOOL CDocManager::DoPromptFileName(CString& fileName, UINT nIDSTitle, DWORD lFlags, BOOL bOpenFileDialog, CDocTemplate* pTemplate)
{
CFileDialog dlgFile(bOpenFileDialog);
CString title;
VERIFY(title.LoadString(nIDSTitle));
dlgFile.m_ofn.Flags |= lFlags;
CString strFilter;
CString strDefault;
if (pTemplate != NULL)
{
ASSERT_VALID(pTemplate);
_AfxAppendFilterSuffix(strFilter, dlgFile.m_ofn, pTemplate, &strDefault);
}
else
{
// do for all doc template
POSITION pos = m_templateList.GetHeadPosition();
BOOL bFirst = TRUE;
while (pos != NULL)
{
CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos);
_AfxAppendFilterSuffix(strFilter, dlgFile.m_ofn, pTemplate,
bFirst ? &strDefault : NULL);
bFirst = FALSE;
}
}
// append the "*.*" all files filter
CString allFilter;
VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER));
strFilter += allFilter;
strFilter += (TCHAR)'\0'; // next string please
strFilter += _T("*.*");
strFilter += (TCHAR)'\0'; // last string
dlgFile.m_ofn.nMaxCustFilter++;
dlgFile.m_ofn.lpstrFilter = strFilter;
dlgFile.m_ofn.lpstrTitle = title;
dlgFile.m_ofn.lpstrFile = fileName.GetBuffer(_MAX_PATH);
int nResult = dlgFile.DoModal();
fileName.ReleaseBuffer();
return nResult == IDOK;
}
// 看出来了吧,其实还是调用了CFileDialog。
BOOL CDocument::DoSave(LPCTSTR lpszPathName, BOOL bReplace)
{
CString newName = lpszPathName;
if (newName.IsEmpty())
{
.......
if (!AfxGetApp()->DoPromptFileName(newName,
bReplace ? AFX_IDS_SAVEFILE : AFX_IDS_SAVEFILECOPY,
OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, FALSE, pTemplate))
return FALSE; // don't even attempt to save
}
......
}
=======================================================>
// prompt for file name - used for open and save as
BOOL CWinApp::DoPromptFileName(CString& fileName, UINT nIDSTitle, DWORD lFlags,
BOOL bOpenFileDialog, CDocTemplate* pTemplate)
// if pTemplate==NULL => all document templates
{
ASSERT(m_pDocManager != NULL);
return m_pDocManager->DoPromptFileName(fileName, nIDSTitle, lFlags,
bOpenFileDialog, pTemplate);
}
=======================================================>
BOOL CDocManager::DoPromptFileName(CString& fileName, UINT nIDSTitle, DWORD lFlags, BOOL bOpenFileDialog, CDocTemplate* pTemplate)
{
CFileDialog dlgFile(bOpenFileDialog);
CString title;
VERIFY(title.LoadString(nIDSTitle));
dlgFile.m_ofn.Flags |= lFlags;
CString strFilter;
CString strDefault;
if (pTemplate != NULL)
{
ASSERT_VALID(pTemplate);
_AfxAppendFilterSuffix(strFilter, dlgFile.m_ofn, pTemplate, &strDefault);
}
else
{
// do for all doc template
POSITION pos = m_templateList.GetHeadPosition();
BOOL bFirst = TRUE;
while (pos != NULL)
{
CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos);
_AfxAppendFilterSuffix(strFilter, dlgFile.m_ofn, pTemplate,
bFirst ? &strDefault : NULL);
bFirst = FALSE;
}
}
// append the "*.*" all files filter
CString allFilter;
VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER));
strFilter += allFilter;
strFilter += (TCHAR)'\0'; // next string please
strFilter += _T("*.*");
strFilter += (TCHAR)'\0'; // last string
dlgFile.m_ofn.nMaxCustFilter++;
dlgFile.m_ofn.lpstrFilter = strFilter;
dlgFile.m_ofn.lpstrTitle = title;
dlgFile.m_ofn.lpstrFile = fileName.GetBuffer(_MAX_PATH);
int nResult = dlgFile.DoModal();
fileName.ReleaseBuffer();
return nResult == IDOK;
}
// 看出来了吧,其实还是调用了CFileDialog。
#1
LZ可真辛苦啊,没有分了 ,我实在是于心不忍。
#2
LS的 多谢关注啊 实在没分啊 我技术菜 也回答不了别人的问题去赚分啊
#3
解释这个问题的最好回答就是直接看MFC源代码就好了:
BOOL CDocument::DoSave(LPCTSTR lpszPathName, BOOL bReplace)
{
CString newName = lpszPathName;
if (newName.IsEmpty())
{
.......
if (!AfxGetApp()->DoPromptFileName(newName,
bReplace ? AFX_IDS_SAVEFILE : AFX_IDS_SAVEFILECOPY,
OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, FALSE, pTemplate))
return FALSE; // don't even attempt to save
}
......
}
=======================================================>
// prompt for file name - used for open and save as
BOOL CWinApp::DoPromptFileName(CString& fileName, UINT nIDSTitle, DWORD lFlags,
BOOL bOpenFileDialog, CDocTemplate* pTemplate)
// if pTemplate==NULL => all document templates
{
ASSERT(m_pDocManager != NULL);
return m_pDocManager->DoPromptFileName(fileName, nIDSTitle, lFlags,
bOpenFileDialog, pTemplate);
}
=======================================================>
BOOL CDocManager::DoPromptFileName(CString& fileName, UINT nIDSTitle, DWORD lFlags, BOOL bOpenFileDialog, CDocTemplate* pTemplate)
{
CFileDialog dlgFile(bOpenFileDialog);
CString title;
VERIFY(title.LoadString(nIDSTitle));
dlgFile.m_ofn.Flags |= lFlags;
CString strFilter;
CString strDefault;
if (pTemplate != NULL)
{
ASSERT_VALID(pTemplate);
_AfxAppendFilterSuffix(strFilter, dlgFile.m_ofn, pTemplate, &strDefault);
}
else
{
// do for all doc template
POSITION pos = m_templateList.GetHeadPosition();
BOOL bFirst = TRUE;
while (pos != NULL)
{
CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos);
_AfxAppendFilterSuffix(strFilter, dlgFile.m_ofn, pTemplate,
bFirst ? &strDefault : NULL);
bFirst = FALSE;
}
}
// append the "*.*" all files filter
CString allFilter;
VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER));
strFilter += allFilter;
strFilter += (TCHAR)'\0'; // next string please
strFilter += _T("*.*");
strFilter += (TCHAR)'\0'; // last string
dlgFile.m_ofn.nMaxCustFilter++;
dlgFile.m_ofn.lpstrFilter = strFilter;
dlgFile.m_ofn.lpstrTitle = title;
dlgFile.m_ofn.lpstrFile = fileName.GetBuffer(_MAX_PATH);
int nResult = dlgFile.DoModal();
fileName.ReleaseBuffer();
return nResult == IDOK;
}
// 看出来了吧,其实还是调用了CFileDialog。
BOOL CDocument::DoSave(LPCTSTR lpszPathName, BOOL bReplace)
{
CString newName = lpszPathName;
if (newName.IsEmpty())
{
.......
if (!AfxGetApp()->DoPromptFileName(newName,
bReplace ? AFX_IDS_SAVEFILE : AFX_IDS_SAVEFILECOPY,
OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, FALSE, pTemplate))
return FALSE; // don't even attempt to save
}
......
}
=======================================================>
// prompt for file name - used for open and save as
BOOL CWinApp::DoPromptFileName(CString& fileName, UINT nIDSTitle, DWORD lFlags,
BOOL bOpenFileDialog, CDocTemplate* pTemplate)
// if pTemplate==NULL => all document templates
{
ASSERT(m_pDocManager != NULL);
return m_pDocManager->DoPromptFileName(fileName, nIDSTitle, lFlags,
bOpenFileDialog, pTemplate);
}
=======================================================>
BOOL CDocManager::DoPromptFileName(CString& fileName, UINT nIDSTitle, DWORD lFlags, BOOL bOpenFileDialog, CDocTemplate* pTemplate)
{
CFileDialog dlgFile(bOpenFileDialog);
CString title;
VERIFY(title.LoadString(nIDSTitle));
dlgFile.m_ofn.Flags |= lFlags;
CString strFilter;
CString strDefault;
if (pTemplate != NULL)
{
ASSERT_VALID(pTemplate);
_AfxAppendFilterSuffix(strFilter, dlgFile.m_ofn, pTemplate, &strDefault);
}
else
{
// do for all doc template
POSITION pos = m_templateList.GetHeadPosition();
BOOL bFirst = TRUE;
while (pos != NULL)
{
CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos);
_AfxAppendFilterSuffix(strFilter, dlgFile.m_ofn, pTemplate,
bFirst ? &strDefault : NULL);
bFirst = FALSE;
}
}
// append the "*.*" all files filter
CString allFilter;
VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER));
strFilter += allFilter;
strFilter += (TCHAR)'\0'; // next string please
strFilter += _T("*.*");
strFilter += (TCHAR)'\0'; // last string
dlgFile.m_ofn.nMaxCustFilter++;
dlgFile.m_ofn.lpstrFilter = strFilter;
dlgFile.m_ofn.lpstrTitle = title;
dlgFile.m_ofn.lpstrFile = fileName.GetBuffer(_MAX_PATH);
int nResult = dlgFile.DoModal();
fileName.ReleaseBuffer();
return nResult == IDOK;
}
// 看出来了吧,其实还是调用了CFileDialog。