My intention is to setup an scecific file extension on CFileDialog ... For that, I derived a class from CFileDialog, named CFileDialogExt. I have 5 different file types, like this:
Code:
LPTSTR szFilter = _T("Bitmap Files (*.bmp)|*.bmp|Gif Files (*.gif)|*.gif|Jpeg Files (*.jpg)|*.jpg|Png Files (*.png)|*.png|Tiff Files (*.tiff)|*.tiff||");
and the call is simple:
Code:
CFileDialogExt dlg(FALSE, NULL, NULL, OFN_FILEMUSTEXIST, szFilter); // <-- Saving operation
Ok, in order to catch file type changing, I override CFileDialogExt::OnTypeChange(), just ike that:
Code:
void CFileDialogExt::OnTypeChange()
{
// TODO: Add your specialized code here and/or call the base class
CFileDialog::OnTypeChange();
CString sExt(GetFileExt());
switch(GetOFN().nFilterIndex)
{
case 1:
sExt.Format(_T("bmp"));
break;
case 2:
sExt.Format(_T("gif"));
break;
case 3:
sExt.Format(_T("jpg"));
break;
case 4:
sExt.Format(_T("png"));
break;
case 5:
sExt.Format(_T("tiff"));
break;
}
SetDefExt((LPCSTR)(LPCTSTR)sExt);
}
but the SetDefExt does work delayed with one step ... here is the behavior:
I type "test" as file name. I chose "gif" extension. Nothing happen, the file name is the same.
I chose "jpg". The file name is changing as "test.gif".
I chose "png". The file name is changing as "test.jpg".
Do you know what I mean ? The file name is changing by the previous file extension choose.
I attach a test project to have a sample of what I wrote here ... Is there a solution to setup the right file name at the user file type choosing ?
Thank you.
TestFD.zip