Solved

I want to use defualt ext. filter while using CFileDialog

Posted on 2001-06-11
8
532 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 88
bigDiff challenge 17 75
fix34  challenge 9 97
Updating statistics with error notification email in SQL server 4 45
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This video discusses moving either the default database or any database to a new volume.

757 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

18 Experts available now in Live!

Get 1:1 Help Now