|
-
August 28th, 2009, 01:12 AM
#1
Can CFileDialog (FALSE) detect an existing file?
I have overridden OnFileSave and used CFileDialog to implement the process. It would be useful if the dialog would warn the user if a file of that name already exists, offering an option to replace it. But my overridden implementation doesnt do that. It will simply overwrite the file if it exists. (very unprofessional).
Is there a flag or something that can be set using CFileDialog that will warn if file exists?
Here's the code I've been using:
Code:
void myDlg::OnFileSaveas()
{
const char fileDialogFilter[] =
"Data Files (*.dat)|*.dat||";
const char fileDialogExt[] = "dat";
CFileDialog fileDialog(FALSE,
fileDialogExt, m_csFilename,
OFN_FILEMUSTEXIST, fileDialogFilter);
if (fileDialog.DoModal() == IDOK)
{
CWaitCursor wait;
if(fileDialog.GetFileExt()=="dat")
{
m_csPathname = fileDialog.GetPathName();
m_csFilename = fileDialog.GetFileName();
//.. do the save
}
}
}
mpliam
-
August 28th, 2009, 01:32 AM
#2
Re: Can CFileDialog (FALSE) detect an existing file?
OFN_OVERWRITEPROMPT should prompt the user for overwriting.
You can find all the flags here: http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx.
-
August 28th, 2009, 01:40 AM
#3
Re: Can CFileDialog (FALSE) detect an existing file?
Other way: use
Code:
BOOL PathFileExists(
LPCTSTR pszPath
);
to know if the file exists.
Regards!
-
August 28th, 2009, 09:28 AM
#4
Re: Can CFileDialog (FALSE) detect an existing file?
OFN_OVERWRITEPROMPT works. thanks. I should have looked up the flags myself.
mpliam
-
August 30th, 2009, 01:33 AM
#5
Re: Can CFileDialog (FALSE) detect an existing file?
OFN_FILEMUSTEXIST is not needed for Save dialog. It is ignored.
What would it mean if you require that file must exist before saving?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|