如何向 MFC CFolderDialog(“浏览文件夹”对话框)添加编辑框?

发布于 2024-07-25 09:30:39 字数 1824 浏览 8 评论 0原文

我目前有一个 CFolderDialog 类,在我的 CDocManagerEx 类中用于处理文件操作,如下所示:

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

我不知道是否需要显示此类的方法实现(我从发布的项目中找到了这个这里),但这里是类定义,如果它帮助:

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;
};

我这个问题的目标是在选择目录的工作区正下方的窗口中添加一个编辑控件。 实现这一目标的最简单方法是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海少女心 2024-08-01 09:30:39

如果您只想要一个允许用户输入目录条目名称的编辑控件,这是可能的。 您使用的 C++ 类是 Win32 SHBrowseForFolder() 方法的包装器,该方法通过在 BROWSEINFO 结构的 ulFlags 成员中设置 BIF_EDITBOX(或更好的是 BIF_USENEWUI)来支持编辑框。

查看 C++ 类,实现此目的的最简单方法似乎是将 BIF_USENEWUI 作为构造函数调用中的 dwFlags 成员传递。 (尽管我很想直接调用 SHBrowseForFolder,而不用操心 C++ 类。)

不过,请注意 MSDN 中有关此标志的警告:在打开对话框之前必须调用 OleInitialize() 或 CoInitialize()这面旗帜。

更一般地说,如果您想要一个可用于自己目的的编辑控件,允许用户输入任何内容,那就更成问题了:无法使用自定义控件扩展 SHBrowseForFolder() 使用的对话框。 如果您想这样做,您最终将不得不重新实现整个对话框,这不是一个好主意。

另外,最后一点,如果您可以将自己限制在 Vista(及更高版本)中,那么还有另一种方法可以提供目录选择对话框:使用带有 FOS_PICKFOLDERS 标志的新 IFileDialog COM 接口。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文