Question

I currently have a CFolderDialog class that is used in my CDocManagerEx class for handling file operations as follows:

alt text http://img268.yfrog.com/img268/9271/filedialog.png

I don't know if I need to show the method implementation of this class (I found this from a project posted here), but here is the class definition if it helps:

class CFolderDialog  
{
    friend static int CALLBACK BrowseDirectoryCallback(
        HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData);

public:
    CFolderDialog(  LPCTSTR lpszFolderName = NULL, 
        DWORD dwFlags = NULL/*BIF_RETURNONLYFSDIRS*/, 
        CWnd* pParentWnd = NULL);
    virtual ~CFolderDialog();
    virtual int DoModal();
    CString GetPathName() const;

protected:
    virtual void OnInitDialog();
    virtual void OnSelChanged(ITEMIDLIST* pIdl);
    virtual void CallbackFunction(HWND hWnd, UINT uMsg, LPARAM lParam);

    void EnableOK(BOOL bEnable = TRUE);
    void SetSelection(LPCTSTR pszSelection);
    void SetSelection(ITEMIDLIST* pIdl);
    void SetStatusText(LPCTSTR pszStatusText);
    CString ShortName(const CString& strName);

public:
    BROWSEINFO m_bi;

protected:
    CString m_strInitialFolderName;
    CString m_strFinalFolderName;

    TCHAR m_szDisplayName[MAX_PATH];
    TCHAR m_szPath[MAX_PATH];

    HWND m_hDialogBox;
};

class CMyFolderDialog : public CFolderDialog  
{
public:
    CMyFolderDialog(LPCTSTR lpszFolderName = NULL, 
        DWORD dwFlags = NULL, 
        CWnd* pParentWnd = NULL,
        LPCTSTR pszFileFilter = NULL);
    virtual ~CMyFolderDialog();
protected:
    virtual void OnSelChanged(ITEMIDLIST* pIdl);

protected:
    CString m_strFileFilter;
};

My goal of this question is adding an edit control to the window just below the workspace where the directory is selected. What would be the easiest way to accomplish this?

Was it helpful?

Solution

If you just want an edit control that allows the user to type in the name of a directory entry, that is possible. The C++ class you're using is a wrapper round the Win32 SHBrowseForFolder() method, and that method supports having an edit box by setting the BIF_EDITBOX (or better, BIF_USENEWUI) in the ulFlags member of the BROWSEINFO structure.

Looking at the C++ class, it looks like the simplest way to achieve this will be to pass BIF_USENEWUI as the dwFlags member in the constructor call. (Though I'd be tempted to just call SHBrowseForFolder directly and not bother with the C++ class.)

Do note the warning about this flag in MSDN, though: OleInitialize() or CoInitialize() must have been called before bringing up the dialog with this flag.

More generally, if you want an edit control that you can use for your own purposes, allowing the user to enter anything, that's more of a problem: there's no way to extend the dialog used by SHBrowseForFolder() with custom controls. If you want to do that, you'd end up having to re-implement the whole dialog, which isn't a good idea.

Also, as a final note, if you can limit yourself to Vista (and beyond) then there's another way to have a directory selection dialog: use the new IFileDialog COM interface, with the FOS_PICKFOLDERS flag.

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