CFileDialog OnTypeChange issue
-
I derived a class from
CFileDialog
, namedCFileDialogExt
. Here, I have the following filters: 1.bmp 2.gif 3.jpg 4.png 5.tiff In order to setup the right extension for file name, I override OnTypeChange, just like this:void CFileDialogExt::OnTypeChange()
{
// TODO: Add your specialized code here and/or call the base classswitch(GetOFN().nFilterIndex) { case 1: SetDefExt(\_T("bmp")); break; case 2: SetDefExt(\_T("gif")); break; case 3: SetDefExt(\_T("jpg")); break; case 4: SetDefExt(\_T("png")); break; case 5: SetDefExt(\_T("tiff")); break; } CFileDialog::OnTypeChange();
}
Default type is bmp. So, I type "aaa" as file name. Then, I change the type (from combo type), as gif. The file name is still "aaa". Then, I change again as jpg, the file name is changed as "aaa.gif" !! Is delayed by one changing ... strange ... why ? Furthermore, I change extension as tiff, the file name is "aaa.jpg", not "aaa.tiff" .... I have done something wrong here ?
-
I derived a class from
CFileDialog
, namedCFileDialogExt
. Here, I have the following filters: 1.bmp 2.gif 3.jpg 4.png 5.tiff In order to setup the right extension for file name, I override OnTypeChange, just like this:void CFileDialogExt::OnTypeChange()
{
// TODO: Add your specialized code here and/or call the base classswitch(GetOFN().nFilterIndex) { case 1: SetDefExt(\_T("bmp")); break; case 2: SetDefExt(\_T("gif")); break; case 3: SetDefExt(\_T("jpg")); break; case 4: SetDefExt(\_T("png")); break; case 5: SetDefExt(\_T("tiff")); break; } CFileDialog::OnTypeChange();
}
Default type is bmp. So, I type "aaa" as file name. Then, I change the type (from combo type), as gif. The file name is still "aaa". Then, I change again as jpg, the file name is changed as "aaa.gif" !! Is delayed by one changing ... strange ... why ? Furthermore, I change extension as tiff, the file name is "aaa.jpg", not "aaa.tiff" .... I have done something wrong here ?
Maybe if I could get a pointer to
CComboBox
fromCFileDialog
, I can find more about this problem ... but I can not ... I tried this:void CFileDialogExt::OnTypeChange()
{
// TODO: Add your specialized code here and/or call the base classCString sTemp; CComboBox\* pCombo = (CComboBox\*)GetDlgItem(cmb1); if(NULL != pCombo->GetSafeHwnd()) { int nIndex = pCombo->GetCurSel(); if(CB\_ERR != nIndex) pCombo->GetLBText(nIndex, sTemp); }
TRACE(">>>%s\n", sTemp);
switch(GetOFN().nFilterIndex)
{
case 1:
SetDefExt(_T("bmp"));
break;
case 2:
SetDefExt(_T("gif"));
break;
case 3:
SetDefExt(_T("jpg"));
break;
case 4:
SetDefExt(_T("png"));
break;
case 5:
SetDefExt(_T("tiff"));
break;
case 6:
SetDefExt(_T("dcm"));
break;
}CFileDialog::OnTypeChange();
}
but
pCombo
seem to be null ... -
I derived a class from
CFileDialog
, namedCFileDialogExt
. Here, I have the following filters: 1.bmp 2.gif 3.jpg 4.png 5.tiff In order to setup the right extension for file name, I override OnTypeChange, just like this:void CFileDialogExt::OnTypeChange()
{
// TODO: Add your specialized code here and/or call the base classswitch(GetOFN().nFilterIndex) { case 1: SetDefExt(\_T("bmp")); break; case 2: SetDefExt(\_T("gif")); break; case 3: SetDefExt(\_T("jpg")); break; case 4: SetDefExt(\_T("png")); break; case 5: SetDefExt(\_T("tiff")); break; } CFileDialog::OnTypeChange();
}
Default type is bmp. So, I type "aaa" as file name. Then, I change the type (from combo type), as gif. The file name is still "aaa". Then, I change again as jpg, the file name is changed as "aaa.gif" !! Is delayed by one changing ... strange ... why ? Furthermore, I change extension as tiff, the file name is "aaa.jpg", not "aaa.tiff" .... I have done something wrong here ?
We do something similar. In the OnTypeChange virtual method: We have a external list of extension (external to the file dialog) We get the selected filter extension (m_ofn.nFilterIndex). We get the current filename (GetFileName()) Extract the filename without extension and replace with the new extension and call this :
// This only works is the bVistaStyle flag is set to false in the CFileDialog constructor.
SetControlText(edt1, fileNameNoExtension ); // edt1 is undocumented.This will change the name of the file in the file dialog editbox. Good luck.
I'd rather be phishing!
-
We do something similar. In the OnTypeChange virtual method: We have a external list of extension (external to the file dialog) We get the selected filter extension (m_ofn.nFilterIndex). We get the current filename (GetFileName()) Extract the filename without extension and replace with the new extension and call this :
// This only works is the bVistaStyle flag is set to false in the CFileDialog constructor.
SetControlText(edt1, fileNameNoExtension ); // edt1 is undocumented.This will change the name of the file in the file dialog editbox. Good luck.
I'd rather be phishing!