Click here to Skip to main content
13,195,163 members (69,541 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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 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 30-Jan-13 4:59am
   
Thank you!!it help me so much!!
Kuthuparakkal 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
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.171019.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2017
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