关于MFC的CFileDialog类的问题
CFileDialogdlg(FALSE,NULL,sFileName,0);if(dlg.DoModal()==IDOK){CStringstrFile=dlg.Get...
CFileDialog dlg(FALSE,NULL,sFileName,0);
if(dlg.DoModal() == IDOK)
{
CString strFile = dlg.GetPathName(); // 全路径
int count = 1;
while( count )
{
if( DetectionFileExists(strFile) )//DetectionFileExists()检测某个文件,存在返回TRUE,不存在返回FLASE
{int i = MessageBox("已经有同名文件存在,覆盖原文件?","提示",MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2) ;
if( i == 6 )
{
CFile::Remove(strFile); count = 0; }
if( i == 7 )
{ MessageBox("IDON"); }
}
/////////////////////////////////////////////////////////////////////////////////////////
我做了一个保存文件的对话框,里面有检测保存的文件是否存在的功能。如果文件存在就提示用户是否覆盖文件,问题就出在这里,用户选在了否 if( i == 7 )
{ MessageBox("IDON"); } 这里怎么写才能回到对话框供用户从新选择路径, 展开
if(dlg.DoModal() == IDOK)
{
CString strFile = dlg.GetPathName(); // 全路径
int count = 1;
while( count )
{
if( DetectionFileExists(strFile) )//DetectionFileExists()检测某个文件,存在返回TRUE,不存在返回FLASE
{int i = MessageBox("已经有同名文件存在,覆盖原文件?","提示",MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2) ;
if( i == 6 )
{
CFile::Remove(strFile); count = 0; }
if( i == 7 )
{ MessageBox("IDON"); }
}
/////////////////////////////////////////////////////////////////////////////////////////
我做了一个保存文件的对话框,里面有检测保存的文件是否存在的功能。如果文件存在就提示用户是否覆盖文件,问题就出在这里,用户选在了否 if( i == 7 )
{ MessageBox("IDON"); } 这里怎么写才能回到对话框供用户从新选择路径, 展开
4个回答
展开全部
太复杂,CFileDialog本来就有个文件同名提示选项,
CFileDialog( BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL );
OFN_OVERWRITEPROMPT?
CFileDialog( BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL );
OFN_OVERWRITEPROMPT?
展开全部
问题是什么啊?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
文件存在与否有FindFirstFile之类函数
干嘛用CFileDialog
干嘛用CFileDialog
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
CFileDialog 打开多个文件2006-12-01 17:28从CFileDialog派生一个类MFileDlg: 头文件://///////////////////////////////////////////////////////////////////////////
// MFileDlg dialogclass MFileDlg : public CFileDialog
{
DECLARE_DYNAMIC(MFileDlg)public:
MFileDlg(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
LPCTSTR lpszFilter = NULL,
CWnd* pParentWnd = NULL);
int DoModal();
virtual ~MFileDlg();
protected:
//{{AFX_MSG(MFileDlg)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG TCHAR* m_pszFile;
////////
DECLARE_MESSAGE_MAP()}; 类实现://///////////////////////////////////////////////////////////////////////////
// MFileDlgIMPLEMENT_DYNAMIC(MFileDlg, CFileDialog)MFileDlg::MFileDlg(BOOL bOpenFileDialog, LPCTSTR lpszDefExt, LPCTSTR lpszFileName,
DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) :
CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd)
{
m_pszFile = new TCHAR[2048]; //set a 2K buffer to hold selected files
m_pszFile[0] = '\0'; //initialize pointer;
}
BEGIN_MESSAGE_MAP(MFileDlg, CFileDialog)
//{{AFX_MSG_MAP(MFileDlg)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()MFileDlg::~MFileDlg()
{
if (m_pszFile != NULL)
delete [] m_pszFile; //cleanup
}int MFileDlg::DoModal()
{
ASSERT_VALID(this);
ASSERT(m_ofn.Flags & OFN_ALLOWMULTISELECT); //make sure multiple file selection is on m_ofn.lpstrFile = m_pszFile; //initialize the OPENFILENAME structure
m_ofn.nMaxFile = 2048;
return CFileDialog::DoModal();
} 具体使用: MFileDlg dlg( TRUE,_T("TXT"),_T("*.TXT"),
OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,
_T("文本文件 (*.txt)|*.txt所有文件 (*.*)|*.*|"));
if(dlg.DoModal()!=IDOK) return FALSE; //取消操作 POSITION pos = dlg.GetStartPosition();
while (pos != NULL)
{
CString strPath = dlg.GetNextPathName(pos);
if (strPath.Find(":\\\\") == 1 && strPath.GetLength() > 4)
{
// this means we have an invalid path that looks like this:
// C:\\cda.dgl
// get rid of extra slash
CString temp;
temp = strPath.Left(3);
temp += strPath.Mid(4);
strPath = temp;
}
m_listFileNames.AddTail(strPath); //CStringList m_listFileNames
TRACE(_T("GetOpenFileName returned %s Files\r\n"),strPath);
}
// MFileDlg dialogclass MFileDlg : public CFileDialog
{
DECLARE_DYNAMIC(MFileDlg)public:
MFileDlg(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
LPCTSTR lpszFilter = NULL,
CWnd* pParentWnd = NULL);
int DoModal();
virtual ~MFileDlg();
protected:
//{{AFX_MSG(MFileDlg)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG TCHAR* m_pszFile;
////////
DECLARE_MESSAGE_MAP()}; 类实现://///////////////////////////////////////////////////////////////////////////
// MFileDlgIMPLEMENT_DYNAMIC(MFileDlg, CFileDialog)MFileDlg::MFileDlg(BOOL bOpenFileDialog, LPCTSTR lpszDefExt, LPCTSTR lpszFileName,
DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) :
CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd)
{
m_pszFile = new TCHAR[2048]; //set a 2K buffer to hold selected files
m_pszFile[0] = '\0'; //initialize pointer;
}
BEGIN_MESSAGE_MAP(MFileDlg, CFileDialog)
//{{AFX_MSG_MAP(MFileDlg)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()MFileDlg::~MFileDlg()
{
if (m_pszFile != NULL)
delete [] m_pszFile; //cleanup
}int MFileDlg::DoModal()
{
ASSERT_VALID(this);
ASSERT(m_ofn.Flags & OFN_ALLOWMULTISELECT); //make sure multiple file selection is on m_ofn.lpstrFile = m_pszFile; //initialize the OPENFILENAME structure
m_ofn.nMaxFile = 2048;
return CFileDialog::DoModal();
} 具体使用: MFileDlg dlg( TRUE,_T("TXT"),_T("*.TXT"),
OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,
_T("文本文件 (*.txt)|*.txt所有文件 (*.*)|*.*|"));
if(dlg.DoModal()!=IDOK) return FALSE; //取消操作 POSITION pos = dlg.GetStartPosition();
while (pos != NULL)
{
CString strPath = dlg.GetNextPathName(pos);
if (strPath.Find(":\\\\") == 1 && strPath.GetLength() > 4)
{
// this means we have an invalid path that looks like this:
// C:\\cda.dgl
// get rid of extra slash
CString temp;
temp = strPath.Left(3);
temp += strPath.Mid(4);
strPath = temp;
}
m_listFileNames.AddTail(strPath); //CStringList m_listFileNames
TRACE(_T("GetOpenFileName returned %s Files\r\n"),strPath);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询