Click here to Skip to main content
15,305,480 members
Articles / Desktop Programming / WTL
Posted 26 Mar 2002


21 bookmarked

WTL Extended File Dialogs

Rate me:
Please Sign up or sign in to vote.
4.40/5 (5 votes)
26 Mar 20022 min read
How to extend WTLs CFileDialog adding Windows ME, 2000 and XP functionality



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 OPENFILENAME structure which is passed to GetOpenFileName or GetSaveFileName basically needs to be replaced with a (larger) OPENFILENAMEEX structure. 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 simple CFileDialogImpl implementation from the top of this page. The class overrides the DoModal method and changes the code slightly to fill in an OPENFILENAMEEX structure (the member m_ofnex). It simply copies all of the data from the m_ofn member (which is an OPENFILENAME) and then fills in the extra members. After the call to

or its counterpart, the relevant parts of m_ofnex are copied back into m_ofn.

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 for CSSFileDialog looks like this:

CSSFileDialog(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
	LPCTSTR lpszDefExt = NULL,
	LPCTSTR lpszFileName = NULL,
	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.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Simon Steele
Web Developer
United Kingdom United Kingdom
Simon is the author of Programmer's Notepad. Originally written in Delphi and now entirely in C++ it's a powerful text editor with syntax highlighting etc. See

Comments and Discussions

GeneralTank you Pin
ikr22-Mar-05 23:38
Memberikr22-Mar-05 23:38 
GeneralStarting in THUMBNAILS mode Pin
Alex Evans14-Nov-04 15:50
MemberAlex Evans14-Nov-04 15:50 
GeneralBug in conversion of '|' and some suggestions Pin
varosi2-Apr-03 12:06
Membervarosi2-Apr-03 12:06 
GeneralModeless operations. Pin
Ilushka19-Feb-03 22:46
MemberIlushka19-Feb-03 22:46 
GeneralRe: Modeless operations. Pin
Simon Steele20-Feb-03 0:37
MemberSimon Steele20-Feb-03 0:37 
QuestionHow to change the contens of the location bar? Pin
2-Apr-02 2:20
suss2-Apr-02 2:20 
GeneralEasier way Pin
Michael Dunn27-Mar-02 16:17
sitebuilderMichael Dunn27-Mar-02 16:17 
GeneralRe: Easier way Pin
Simon Steele27-Mar-02 22:13
MemberSimon Steele27-Mar-02 22:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.