Question

I am using CFileDialog for displaying the open file dialog. I have set the filter as follows:

static TCHAR BASED_CODE szFilter[] = _T("Chart Files (*.xlc)|*.xlc|")
                                     _T("Worksheet Files (*.xls)|*.xls|Data Files (*.xlc;*.xls)|")
                                     _T("*.xlc; *.xls|All Files (*.*)|*.*||");

I need to set the default file type to be "Worksheet Files" whenever I DoModal the dialog box. I am unable to figure out how to do it. MS Paint is doing, it selects the "All Picture files" when we open the open file dialog.

Please let me know how to do it.

Was it helpful?

Solution

You're looking for the SetDefExt function. This allows you to specify the default file extension for an open/save file dialog box. Remember that the string you specify should not contain a period (.).

Of course, you could also just specify this in the constructor. The second parameter is the default extension (lpszDefExt).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top