[RESOLVED] CFileDialog SaveAs derfault file name problem
Hello,
I cannot define default file name with dot in FileSaveAs dialog.
The document name is "123.45.jpg". User can define different file extension jpg or bmp.
1)
CFileDialog writeDialog2(FALSE, "bmp", "123.45", OFN_EXPLORER|OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_NOREADONLYRETURN| OFN_NOCHANGEDIR,
filter, AfxGetMainWnd());
CFileDialog split .45 from file name and recognize it as extension.
2)
CFileDialog writeDialog2(FALSE, "bmp", "123.45.bmp", OFN_EXPLORER|OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_NOREADONLYRETURN| OFN_NOCHANGEDIR,
filter, AfxGetMainWnd());
When I change extension filter file name isn't changed, file always named as "123.45.bmp".
Re: CFileDialog SaveAs derfault file name problem
Re: CFileDialog SaveAs derfault file name problem
CFileDialog writeDialog2(FALSE, "bmp", "123.45", OFN_EXPLORER|OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_NOREADONLYRETURN| OFN_NOCHANGEDIR,
"BMP (*.bmp)|*.bmp|JPG (*.jpg)|*.jpg|", AfxGetMainWnd());
if(writeDialog2.DoModal() == IDOK)
{
CString extstr = writeDialog2.GetFileExt();
CString ttt2 = writeDialog2.GetPathName();
}
Re: CFileDialog SaveAs derfault file name problem
Quote:
Originally Posted by
Megapixel
Hello,
I cannot define default file name with dot in FileSaveAs dialog.
The document name is "123.45.jpg". User can define different file extension jpg or bmp.
1)
CFileDialog writeDialog2(FALSE, "bmp", "123.45",
OFN_EXPLORER|OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_NOREADONLYRETURN| OFN_NOCHANGEDIR,
filter, AfxGetMainWnd());
CFileDialog split .45 from file name and recognize it as extension.
Well, it works exacly as it is expected to work! In te file name "123.45" "123" is the name and "45" is an extension.
Quote:
Originally Posted by
Megapixel
Code:
CFileDialog writeDialog2(FALSE, "bmp", "123.45",
OFN_EXPLORER|OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_NOREADONLYRETURN| OFN_NOCHANGEDIR,
"BMP (*.bmp)|*.bmp|JPG (*.jpg)|*.jpg|", AfxGetMainWnd());
You forgot to add the second pipe at the end of lpszFilter parameter. It must be:
Code:
"BMP (*.bmp)|*.bmp|JPG (*.jpg)|*.jpg||",
Re: CFileDialog SaveAs default file name problem
How can I define file name as 123.45 and extension as bmp or jpg?
For example if I create file 123.45.txt and open it in MSWord file saveas dilaog show the correct file name 123.45 and user can change file extension from txt to doc.
Re: CFileDialog SaveAs derfault file name problem
I don't know. I never had any problem with default file name /extenstion.
Try to pass in the same extension (as default) that your default file name has:
Code:
CFileDialog writeDialog2(FALSE, "bmp", "123.45.bmp",
Re: CFileDialog SaveAs default file name problem
If I define default file name as "123.45.bmp" and change filter in saveas dialog to *.jpg filename hasn't changed.
Function writeDialog2.GetFileExt return "bmp".
Function writeDialog2.GetPathName return "...fullpath/123.34.bmp"
Re: CFileDialog SaveAs derfault file name problem
Well, I looked at my code again:
Code:
CString strFilter = _T("Microsoft Excel Worksheet (.xls)|*.xls|CSV (Comma Separated Values) (.csv)|*.csv|Text File (.txt)|*.txt|All Files (*.*)|*.*||");
CFileDialog dlg( FALSE,
_T("dat"),
_T("of3.12"),
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
strFilter,
pParent);
After I selected .txt and DoModal returned IDOK the dlg.GetPathName() returns me "fullpath\of3.12.txt" :cool:
BTW, have you alreay fixed your code (as I mentioned in the post#4)?
Re: CFileDialog SaveAs derfault file name problem
I fix bug with filter sting now it's correct "BMP (*.bmp)|*.bmp|JPG (*.jpg)|*.jpg||"
You sample also doesn't work. :-(
I just change pParent to AfxGetMainWnd().
At the dialog I see only "of3" without ".12"
After I selected .txt and DoModal returned IDOK the dlg.GetPathName() returns me "fullpath\of3.12"
1 Attachment(s)
Re: CFileDialog SaveAs derfault file name problem
My code does work!
Try it!
1 Attachment(s)
Re: CFileDialog SaveAs derfault file name problem
please find attach. I compile this sample on vc8.
Maybe difference in configuration of WindowsXP?
1 Attachment(s)
Re: CFileDialog SaveAs derfault file name problem
My results are the same for VC++6.0 and VS2008.
Try to NOT hide extensions for known file types (in Windows Explorer folder options)
Re: CFileDialog SaveAs default file name problem
Excelent,
When I change option "hide extensions for known file types" your sample works correct.
Code:
// keep and set folder option (show/hide) extensions
SHELLFLAGSTATE sfs;
DWORD dwMask = SSF_SHOWEXTENSIONS;
SHGetSettings(&sfs, dwMask);
I1 opt_keep = sfs.fShowExtensions;
SHELLSTATE shellstate = {0};
shellstate.fShowExtensions = -1;
SHGetSetSettings(&shellstate, dwMask, TRUE);
CString strFilter = _T("Microsoft Excel Worksheet (.xls)|*.xls|CSV
(Comma Separated Values) (.csv)|*.csv|Text File (.txt)|*.txt|All Files (*.*)|*.*||");
CFileDialog dlg( FALSE,
_T("dat"),
_T("of3.12"),
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
strFilter,
NULL);
if(dlg.DoModal() == IDOK)
{
CString extstr = dlg.GetFileExt();
CString ttt2 = dlg.GetPathName();
}
// restore folder option (show/hide) extensions
shellstate.fShowExtensions = opt_keep;
SHGetSetSettings(&shellstate, dwMask, TRUE);
thread resolved.
Thanks for help.
Re: [RESOLVED] CFileDialog SaveAs derfault file name problem
Yes, I think it is a serious design mistake made by MS many years ago and haven't fixed till now.
See also this C++ Q&A of Paul DiLascia
Re: [RESOLVED] CFileDialog SaveAs derfault file name problem
Quote:
Originally Posted by
suneelkumar85
CFileDialog writeDialog2(FALSE, "bmp", "123.45", OFN_EXPLORER|OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_NOREADONLYRETURN| OFN_NOCHANGEDIR,
"BMP (*.bmp)|*.bmp|JPG (*.jpg)|*.jpg|", AfxGetMainWnd());
if(writeDialog2.DoModal() == IDOK)
{
CString extstr = writeDialog2.GetFileExt();
CString ttt2 = writeDialog2.GetPathName();
}
And why did you repost this erroneous code? :confused: