Click here to Skip to main content
Click here to Skip to main content

WTL Extended File Dialogs

, 26 Mar 2002
Rate this:
Please Sign up or sign in to vote.
How to extend WTLs CFileDialog adding Windows ME, 2000 and XP functionality

CSSFileDialog

Introduction

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 GetOpenFileName 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,
	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.

License

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 www.pnotepad.org.

Comments and Discussions

 
GeneralTank you Pinmemberikr22-Mar-05 23:38 
GeneralStarting in THUMBNAILS mode PinmemberAlex Evans14-Nov-04 15:50 
GeneralBug in conversion of '|' and some suggestions Pinsussvarosi2-Apr-03 12:06 
GeneralModeless operations. PinmemberIlushka19-Feb-03 22:46 
GeneralRe: Modeless operations. PinmemberSimon Steele20-Feb-03 0:37 
QuestionHow to change the contens of the location bar? PinmemberRoland Hasenoehrl2-Apr-02 2:20 
GeneralEasier way PinsubeditorMichael Dunn27-Mar-02 16:17 
GeneralRe: Easier way PinmemberSimon Steele27-Mar-02 22:13 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 27 Mar 2002
Article Copyright 2002 by Simon Steele
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid