WTL includes a
CFileDialog class to (almost) match the one available in MFC.
As anyone who has worked with either class will know, these classes do not show the "location" bar
found on the left-hand side of the Windows 2000 and XP common file dialogs.
The changes required to enable this location bar are very small, the
which is passed to
basically needs to be replaced with a (larger)
This structure has a
FlagsEx member which needs to be set to 0 to enable the location bar.
Earlier versions of windows will not work well with the new structure, so we need to ensure that
this structure is only used when Windows 2000, XP or ME are being used. To do this we check that if
we are using NT, the version is at least 5, and if we are using a 9x range operating system that the version
is at least 4.90.
You can download my
CSSFileDialog class which implements these ideas in a
CFileDialogImpl implementation from the top of this page. The class overrides the
DoModal method and changes the code slightly to fill in an
structure (the member
m_ofnex). It simply copies all of the data from the
(which is an
OPENFILENAME) and then fills in the extra members. After the call to
GetOpenFileName or its counterpart, the relevant parts of
m_ofnex are copied back into
I also re-implemented the MFC use of the pipe character '|' as a filter separator instead of using the NULL
character. This can be disabled with the last parameter of the constructor, by specifying false. The constructor
CSSFileDialog looks like this:
CSSFileDialog(BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
LPCTSTR lpszFilter = NULL,
HWND hWndParent = NULL,
bool bUsePipeChar = true)
So to show the common file open dialog, you can now do this:
CSSFileDialog dlgOpen(TRUE, NULL, NULL, OFN_HIDEREADONLY, "All Files (*.*)|*.*", m_hWnd);
If you want to disable the places bar, simply set the
m_bShowPlacesBar member to false.
I hope someone finds this useful! I've been using an MFC equivalent of this (which I wrote) for some
time now, and it doesn't seem to have any problems. I simply wanted a lightweight implementation of the modern
file dialogs and couldn't find one anywhere, so I wrote one.