CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Aug 2009
    Posts
    7

    [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".

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: CFileDialog SaveAs derfault file name problem

    Code?

  3. #3
    Join Date
    Aug 2009
    Posts
    7

    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();
    }

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: CFileDialog SaveAs derfault file name problem

    Quote Originally Posted by Megapixel View Post
    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 View Post
    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||",
    Victor Nijegorodov

  5. #5
    Join Date
    Aug 2009
    Posts
    7

    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.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    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",
    Victor Nijegorodov

  7. #7
    Join Date
    Aug 2009
    Posts
    7

    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"

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    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"

    BTW, have you alreay fixed your code (as I mentioned in the post#4)?
    Victor Nijegorodov

  9. #9
    Join Date
    Aug 2009
    Posts
    7

    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"

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: CFileDialog SaveAs derfault file name problem

    My code does work!
    Try it!
    Attached Files Attached Files
    Victor Nijegorodov

  11. #11
    Join Date
    Aug 2009
    Posts
    7

    Re: CFileDialog SaveAs derfault file name problem

    please find attach. I compile this sample on vc8.
    Maybe difference in configuration of WindowsXP?
    Attached Images Attached Images

  12. #12
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    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)
    Attached Images Attached Images
    Victor Nijegorodov

  13. #13
    Join Date
    Aug 2009
    Posts
    7

    Thumbs up 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.

  14. #14
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    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
    Victor Nijegorodov

  15. #15
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: [RESOLVED] CFileDialog SaveAs derfault file name problem

    Quote Originally Posted by suneelkumar85 View Post
    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?
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured