Solved

I want to use defualt ext. filter while using CFileDialog

Posted on 2001-06-11
8
540 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 93
notReplace  challenge 53 129
bigDiff challenge 17 106
isEverywhere  challenge 19 75
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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 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.

777 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