Link to home
Start Free TrialLog in
Avatar of kobib
kobib

asked on

I want to use defualt ext. filter while using CFileDialog

Hello friends.

I creat a CFileDialog object for browse a file.
I try to use a filter in order to focus on some file type.
Has any body have an idea?

my code look like:

        CFileDialog m_ldFile(TRUE);

     m_ldFile.m_ofn.lpstrFilter = "*.hex";     m_ldFile.m_ofn.lpstrCustomFilter ;

     if (m_ldFile.DoModal() == IDOK)
     {
          m_sResults = m_ldFile.GetFileName();    
          UpdateData(FALSE);
     }


But it doesn't work. It shows all the files on the director and not just the "hex" files.

Thanks for your help,

Kobi.
Avatar of GloriousRain
GloriousRain

This sample to get filename with ext is .hex
CPatcherView::GetFileName()
{
     TCHAR szFilters[] = _T("Patch Files (*.hex)|*.hex|");
    CFileDialog dlg( TRUE, _T("hex"), NULL, OFN_FILEMUSTEXIST |
                         OFN_HIDEREADONLY, szFilters, this);        
     CString strTitle(_T(""));
     dlg.m_ofn.lpstrTitle =  "Select File Name";    
     if(dlg.DoModal()==IDOK)
     {          
          CString     strConfigFileName(_T(""));              
          strConfigFileName=dlg.GetPathName();
          UpdateData(FALSE);          
          strConfigFileName.MakeUpper();
          return     strConfigFileName;
     }
     else
          return     _T("");
}
Just to correct GloriousRain !

To complete list of filters in szFilters You need to terminate string with two | characters:

TCHAR szFilters[] = _T("Patch Files (*.hex)|*.hex||");
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kobib

ASKER

That was really what I looked for!
I really don't know what is wrong with GloriousRain answer ?
forget, MadYugoslav. Sedqwick's sample is clearly than me.
Avatar of kobib

ASKER

Thank you guys.