【高分】求比较好用点的目录选择控件,急用。

B2China 2004-12-30 10:29:06
就是一个对话框,在这个对话框中可以象选择一个文件一样选择一个目录,最好能够在这个对话框里面新建目录。
...全文
101 点赞 收藏 20
写回复
20 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
B2China 2004-12-30
bohut(伯虎)
谢了。你这个对话框类实在太简陋了啊,这怎么能拿给别人去用啊?
回复
B2China 2004-12-30
EnochShen(小疯子:真的好菜—知耻而后勇!)

谢谢。

我收到了你的2个文件,怎么不能在对话框中新建文件夹啊?

browse_shell_demo 这个盘符没有选取的,怎么一开始右边都是程序菜单???晕。
回复
bohut 2004-12-30
实现文件:
///////////////////////////////////////////////////////////////////////////
// DirDialog.cpp: implementation of the CDirDialog class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "DirDialog.h"
#include "shlobj.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

// Callback function called by SHBrowseForFolder's browse control
// after initialization and when selection changes
static int __stdcall BrowseCtrlCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
CDirDialog* pDirDialogObj = (CDirDialog*)lpData;

if (uMsg == BFFM_INITIALIZED && !pDirDialogObj->m_strSelDir.IsEmpty())
{
::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)(LPCTSTR)(pDirDialogObj->m_strSelDir));
}
else // uMsg == BFFM_SELCHANGED
{
}

return 0;
}

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CDirDialog::CDirDialog()
{
m_strPath=m_strInitDir=m_strSelDir=m_strTitle="";
}

CDirDialog::~CDirDialog()
{
}

int CDirDialog::DoBrowse()
{
LPMALLOC pMalloc;
if (SHGetMalloc (&pMalloc)!= NOERROR)
{
return 0;
}

BROWSEINFO bInfo;
LPITEMIDLIST pidl;
ZeroMemory ( (PVOID) &bInfo,sizeof (BROWSEINFO));

if (!m_strInitDir.IsEmpty ())
{
OLECHAR olePath[MAX_PATH];
ULONG chEaten;
ULONG dwAttributes;
HRESULT hr;
LPSHELLFOLDER pDesktopFolder;
//
// Get a pointer to the Desktop's IShellFolder interface.
//
if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))
{
//
// IShellFolder::ParseDisplayName requires the file name be in Unicode.
//
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, m_strInitDir.GetBuffer(MAX_PATH), -1,
olePath, MAX_PATH);

m_strInitDir.ReleaseBuffer (-1);
//
// Convert the path to an ITEMIDLIST.
//
hr = pDesktopFolder->ParseDisplayName(NULL,
NULL,
olePath,
&chEaten,
&pidl,
&dwAttributes);
if (FAILED(hr))
{
pMalloc ->Free (pidl);
pMalloc ->Release ();
return 0;
}
bInfo.pidlRoot = pidl;

}
}
bInfo.hwndOwner = NULL;
bInfo.pszDisplayName = m_strPath.GetBuffer (MAX_PATH);
if(m_strTitle.IsEmpty())bInfo.lpszTitle = "Open";
else bInfo.lpszTitle=m_strTitle;

bInfo.ulFlags = BIF_RETURNFSANCESTORS|BIF_RETURNONLYFSDIRS;
bInfo.lpfn = BrowseCtrlCallback; // address of callback function
bInfo.lParam = (LPARAM)this; // pass address of object to callback function

if ((pidl = ::SHBrowseForFolder(&bInfo)) == NULL)
{
return 0;
}
m_strPath.ReleaseBuffer();
m_iImageIndex = bInfo.iImage;

if (::SHGetPathFromIDList(pidl,m_strPath.GetBuffer(MAX_PATH)) == FALSE)
{
pMalloc ->Free(pidl);
pMalloc ->Release();
return 0;
}

m_strPath.ReleaseBuffer();

pMalloc ->Free(pidl);
pMalloc ->Release();

return 1;
}
回复
bohut 2004-12-30
头文件:

////////////////////////////////////////////////////////////////////////
// DirDialog.h: interface for the CDirDialog class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DIRDIALOG_H__62FFAC92_1DEE_11D1_B87A_0060979CDF6D__INCLUDED_)
#define AFX_DIRDIALOG_H__62FFAC92_1DEE_11D1_B87A_0060979CDF6D__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

class CDirDialog
{
public:
CDirDialog();
virtual ~CDirDialog();
int DoBrowse();

CString m_strPath;
CString m_strInitDir;
CString m_strSelDir;
CString m_strTitle;
int m_iImageIndex;
};

#endif // !defined(AFX_DIRDIALOG_H__62FFAC92_1DEE_11D1_B87A_0060979CDF6D__INCLUDED_)

回复
EnochShen 2004-12-30
晕啊~~~septhawk@yahoo.com.cn发了
回复
CuteSword 2004-12-30
EnochShen(小疯子:真的好菜—知耻而后勇!)
不好意思,邮件地址是错了,应该是:septhawk@yahoo.com.cn

想学习一下嘛,楼主不用那么急吧。
回复
B2China 2004-12-30
我的邮件: Tu_80c@sohu.com 可是对的哦,我刚才已经给你发了一封确认的邮件了。

先发给我吧,看CuteSword(灵剑)和我抢。呵呵
回复
EnochShen 2004-12-30
Tu_80c@sohu.com发了
回复
EnochShen 2004-12-30
2楼,你的邮箱对吗?flyhawk@yahoo.com.cn?
This is the Postfix program at host qs5.qq.com.

I'm sorry to have to inform you that the message returned
below could not be delivered to one or more destinations.

For further assistance, please send mail to <postmaster>

If you do so, please include this problem report. You can
delete your own text from the message returned below.

The Postfix program

<flyhawk@yahoo.com.cn>: host mta-v1.mail.vip.cnb.yahoo.com[202.43.216.28] said:
554 delivery error: dd This user doesn't have a yahoo.com.cn account
(flyhawk@yahoo.com.cn) [-5] - mta101.mail.cnb.yahoo.com (in reply to end of
DATA command)

连续两次都被退回来了,我在试试~~
回复
B2China 2004-12-30
不对,是3楼的: CuteSword(灵剑) ,晕哦。
回复
B2China 2004-12-30
考,2楼怎么抢在我前面了?

我的邮件: Tu_80c@sohu.com

呵呵。
回复
EnochShen 2004-12-30
flyhawk@yahoo.com.cn已发送
回复
EnochShen 2004-12-30
呵呵,可以可以~~~^O^
回复
CuteSword 2004-12-30
也给我一份,好吗?
回复
CuteSword 2004-12-30
我的邮件: flyhawk@yahoo.com.cn

谢谢。
回复
EnochShen 2004-12-30
给我发邮件EnochShen@QQ.com
回复
B2China 2004-12-30
呵呵,我已经在网上找到了比较好的例子了。
回复
bobob 2004-12-30
选择一个目录
char szDir[MAX_PATH];
BROWSEINFO bi;
ITEMIDLIST *pidl;

bi.hwndOwner = this->m_hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = szDir;
bi.lpszTitle = "请选择目录";
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
bi.iImage = 0;

pidl = SHBrowseForFolder(&bi);
if(pidl == NULL)
return;
if(!SHGetPathFromIDList(pidl, szDir))
return;
回复
EnochShen 2004-12-30
那个函数根据参数,设置根目录的,上次改了,忘记改回来~~
回复
EnochShen 2004-12-30
browse_shell_demo 这个盘符没有选取的,怎么一开始右边都是程序菜单???

呵呵,那是个测试,在CTreeExampleDlg::OnInitiDialog里面把那个,PopaluteTree(22);的参数就是22删掉
回复
相关推荐
发帖
界面
创建于2007-09-28

1.5w+

社区成员

VC/MFC 界面
申请成为版主
帖子事件
创建了帖子
2004-12-30 10:29
社区公告
暂无公告