Click here to Skip to main content
15,895,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
C#
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
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

C++
// 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
}
 
Share this answer
 
v2
Comments
Venkat Raghvan 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900