Setting the CMFCEditBrowseCtrl filter index

ChuckieAJ 86 Reputation points
2020-10-18T21:00:57.223+00:00

I know how to assign file types to my CMFCEditBrowseCtrl object:

    m_browseImagePath.EnableFileBrowseButton(_T("jpg"),
        _T("GIF image (*.gif)|*.gif|")
        _T("JPEG image (*.jpg, *.jpeg)|*.jpg;*.jpeg|")
        _T("PNG image (*.png)|*.png|")
        _T("TIFF image (*.tif, *.tiff)|*.tif;*.tiff|")
        _T("Windows BMP image (*.bmp)|*.bmp||"));

But I have two questions:

  1. How can I default the filter index to the second entry (JPEG Image)? Since the default extension is "jpg" it makes sense the filter index matches.
  2. How do I set the filter index to match the file type of the existing file? Eg. I am pressing Browse button for the second time and I had a PNG, so the filter index should be set to PNG.

At the moment, it has no knowledge what the current file name means. The filters always default to item 0 (GIF Image).

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,546 questions
{count} votes

Accepted answer
  1. RLWA32 40,856 Reputation points
    2020-10-19T12:02:22.397+00:00

    The CMFCEditBrowseCtrl class does not expose most of the functionality of the temporary CFileDialog object that it creates every time the browse button is clicked.

    So to provide more control and specialization you can derive your own class from CMFCEditBrowseCtrl and override the OnBrowse() function. Then you can create and customize a CFileDialog object to display the file browser in whatever manner you desire.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful