Defines
core/vgui/impl/mfc/vgui_dir_dialog.cxx File Reference

creates a directory browsing dialog, it allows to choose both directories and files More...

#include "stdafx.h"
#include <Dlgs.h>
#include <imagehlp.h>
#include "vgui_dir_dialog.h"
#include <vcl_cstring.h>
#include <vcl_cctype.h>

Go to the source code of this file.

Defines

#define IDC_DIR   181
#define IDC_OPEN   182

Detailed Description

creates a directory browsing dialog, it allows to choose both directories and files

Author:
Gamze Tunali, LEMS, Brown University
Date:
16 Nov 2007

The CDirDialog class implements a directory selection dialog by deriving from the file selection dialog class (CFileDialog). This dialog has the advantages of the standard file open dialog (resizeable, ability to create/delete directories etc) but is customized for the selection of a directory rather than a file.

USER INTERFACE --------------

For example, the user can double click on a directory name or type it into the edit control to open it in the directory listing display. To say that this is the directory they want the user must click the "Open" button. When the user enters a backslash (\) as the last character in the edit control the display is changed to show the contents of the directory if it exists. The same is done if the user presses the Enter key except that if the directory does not exist the user is asked if they want to create it.

When the user enters other characters and the contents don't end in a backslash then automatic directory name completion is attempted. If the contents of the edit box are the first character(s) of one unique existing directory then the rest of the directory name is added to the end of the edit box. These characters are selected so that the user can type something else and it they will be ignored.

When selecting a directory you would normally not want to see files, but you may on occasion. The normal "Files of Type:" drop down list is available but it has an extra entry "Show Folders Only" that is selected by default. When files are displayed double clicking of them is ignored (unlike the normal File Open dialog). Double-clicking a directory name changes to that directory as normal.

PROGRAMMER INTERFACE --------------------

Add DirDialog.cpp and DirDialog.h to your project. Include DirDialog.h in the source file(s) where you want to use the CDirDialog class.

Create a CDirDialog object using the constructor described below. If necessary you may then modify values in the m_ofn member of the CFileDialog base class (see the Win32 documentation for OPENFILENAME). For example, to change the text that appears in the title bar of the dialog use m_ofn.lpstrTitle.

Call DoModal() to activate the dialog. If DoModal() return IDOK you can then call GetPath() to obtain the name of the directory that the user selected.

CDirDialog::CDirDialog(LPCTSTR lpstrInitialDir = NULL, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL);

lpstrInitialDir The initial directory. If NULL then the current directory is used. See lpstrInitialDir in the Win32 documentation for OPENFILENAME for more info.

lpszFilter The string pairs that specify the file filters to use. See lpszFilter in the documentation for the CFileDialog constructor for more info. Note that an extra entry is always added that allows the user to hide the display of all files. If NULL is used (the default) then only the "no files" entry and an "all files" entry are provided.

pParentWnd A pointer to the dialog parent window.

virtual int CDirDialog::DoModal()

see CFileDialog::DoModal().

CString CDirDialog::GetPath()

return value The full path name chosen by the user.

Example:

// Called when the Browse button is clicked in CMyDialog void CMyDialog::OnBrowseDir() { if (!UpdateData(TRUE)) // Update current value of m_dir from control return;

CDirDialog dlg(m_dir, "JPEG Files (*.jpg; *.jpeg)|*.jpg;*.jpeg|All Files (*.*)|*.*||", this); dlg.m_ofn.lpstrTitle = "Select Folder to Store Images";

if (dlg.DoModal() == IDOK) { m_dir = dlg.GetPath(); // Store selected directory name back into the control UpdateData(FALSE); } }

INTERNAL DESIGN ---------------

The following changes are made to the controls in the standard file open dialog:

The "Open" button is hidden and replaced with another button (IDC_OPEN). The normal edit control (edt1) where the file name is entered is hidden and replaced by a "subclassed" edit control (IDC_DIR) of class CDirEdit (derived from CEdit). By hiding and replacing these controls we can manipulate the behaviour of the dialog in ways not provided for in any other way. For example, by changing the contents of the hidden edit control (edt1) and simulating a click of the hidden Open button (IDOK) we can force the contents of a directory to be displayed.

An extra entry is added to the file types drop down combo called "Show Folders Only" that causes no files to be displayed. (If no filters are supplied at all by using the default value of NULL, then an "All Files" filter type is also added.) The filter string is a single dot (full-stop) which will match no files.

The new edit control (IDC_DIR) is subclassed so that the contents are monitored and the some keys can be intercepted. When the contents are changed and they end with a backslash the current display is changed to point to the directory entered (if it exists). When return is pressed the directory is also changed, but if it doesn't exist then the user is asked if he wants to create it. The way the directory is changed (ie. the files of that directory are shown in the display) is by putting the directory name into the original edit control (edt1) and simulating a click of the original Open button (IDOK). Directory name completion is also performed as the user types in a directory name.

The IDC_OPEN button is used as a replacement for the IDOK button while still allowing the hidden IDOK button to be used to change the displayed directory.

The CDirDialog class is derived from CFileDialog. The following base class members are overridden:

Definition in file vgui_dir_dialog.cxx.


Define Documentation

#define IDC_DIR   181

Definition at line 159 of file vgui_dir_dialog.cxx.

#define IDC_OPEN   182

Definition at line 160 of file vgui_dir_dialog.cxx.