Solved

I want to use defualt ext. filter while using CFileDialog

Posted on 2001-06-11
8
543 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kobib
ID: 6180347
That was really what I looked for!
0
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating an alias to a directory so I can change the directory 'contents' by changing the alias 5 96
sumHeights  challenge 17 83
Adjust the codes 3 63
Example code 13 43
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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 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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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