Click here to Skip to main content
11,633,454 members (79,726 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC VC++
I design one application in which Browse button event should select the .bin files,but I write that event select all files;I copy my code below,please give my problem solution.
CFileDialog CFiledlg(TRUE,_T(".bin"));
    if(CFiledlg.DoModal()==IDOK)
    {
        m_Input_File_Path=CFiledlg.GetPathName();
        char *file_path=new char[m_Input_File_Path.GetLength()+1];
        wcstombs(file_path,m_Input_File_Path,m_Input_File_Path.GetLength()+1);
        UpdateData(FALSE);
delete[] file_path
    }
Posted 28-Jan-13 21:59pm
Comments
Jochen Arndt at 29-Jan-13 5:14am
   
The question is not very clear. Did you want the file dialog to show only files with .bin extension rather than all files?

Then you must pass a filter string as 5th parameter to the CFileDialog constructor (like "Binary files (*.bin)|*.bin|All files (*.*)|*.*||")

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

   // szFilters is a text string that includes two file name filters:
   // "*.bin" for "Binary Files" and "*.*' for "All Files."
   char CChildFrame::szFilters[]=
      "Binary Files (*.bin)|*.bin";
 
   // Create an Open dialog; the default file name extension is ".bin".
   CFileDialog CFiledlg (TRUE, "bin", "*.bin",
      OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);
   
   // Display the file dialog. When user clicks OK, fileDlg.DoModal() 
   // returns IDOK
   if( fileDlg.DoModal ()==IDOK )
   {
        m_Input_File_Path=CFiledlg.GetPathName();
        char *file_path=new char[m_Input_File_Path.GetLength()+1];
        wcstombs(file_path,m_Input_File_Path,m_Input_File_Path.GetLength()+1);
        UpdateData(FALSE);
        delete[] file_path
   }
  Permalink  
v2
Comments
Sameer_awana at 30-Jan-13 4:59am
   
Thank you!!it help me so much!!
Kuthuparakkal at 30-Jan-13 5:42am
   
Mark answer if it helps!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 625
1 Mika Wendelius 415
2 Sergey Alexandrovich Kryukov 310
3 CPallini 160
4 Richard MacCutchan 150
0 OriginalGriff 8,658
1 Sergey Alexandrovich Kryukov 8,204
2 Mika Wendelius 6,645
3 F-ES Sitecore 2,321
4 Suvendu Shekhar Giri 2,095


Advertise | Privacy | Mobile
Web01 | 2.8.150728.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100