Solved

I want to use defualt ext. filter while using CFileDialog

Posted on 2001-06-11
8
539 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:kobib
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 2

Expert Comment

by:GloriousRain
ID: 6176503
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("");
}
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6176596
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||");
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 50 total points
ID: 6176776
    CFileDialog dlgFile( true);
     dlgFile.m_ofn.lpstrTitle  = "Your dialog title go here...";

     // set directory
     CString strPath = GetPathName();
     int start = strPath.ReverseFind('\\') + 1;
     CString strDir( strPath.Left(start) );
     dlgFile.m_ofn.lpstrInitialDir = strDir;

     // set type
     dlgFile.m_ofn.lpstrDefExt = "tif";

//example of displaying filter with all kind of image files
     dlgFile.m_ofn.lpstrFilter = "Tiff File (*.tif)\0*.tif\0Gif File (*.gif)\0*.gif\0Jpeg File(*.jpg)\0*.jpg\0\0";
     dlgFile.m_ofn.nFilterIndex = 2;

g'day
0
 

Author Comment

by:kobib
ID: 6180347
That was really what I looked for!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6180590
I really don't know what is wrong with GloriousRain answer ?
0
 
LVL 2

Expert Comment

by:GloriousRain
ID: 6180614
forget, MadYugoslav. Sedqwick's sample is clearly than me.
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6180664
OK.
0
 

Author Comment

by:kobib
ID: 6181613
Thank you guys.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now