请问用CFileDialog如何选择目录? 请问用CFileDialog能否选择目录?如果可以并返回我选择的目录信息,并可以选择多个目录。如果不能,那么应该用什么类选择多个目录,并得到选择这些目录信息? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参照一下改写的一个类 :)//.h头文件class CFolderDialog : public CFileDialog{ DECLARE_DYNAMIC(CFolderDialog)public: static WNDPROC m_wndProc; virtual void OnInitDone( ); CString* m_pPath; CFolderDialog(CString* pPath);protected: //{{AFX_MSG(CFolderDialog) // NOTE - the ClassWizard will add and remove member functions here. //}}AFX_MSG DECLARE_MESSAGE_MAP()};#include "stdafx.h"#include "folder_dialog.h"#include <DLGS.H>#include <WINUSER.H>#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CFolderDialogIMPLEMENT_DYNAMIC(CFolderDialog, CFileDialog)WNDPROC CFolderDialog::m_wndProc = NULL;// Function name : CFolderDialog::CFolderDialog// Description : Constructor// Return type : // Argument : CString* pPath ; represent string where selected folder wil be savedCFolderDialog::CFolderDialog(CString* pPath) : CFileDialog(TRUE, NULL, _T("*..*")){ m_pPath = pPath;}BEGIN_MESSAGE_MAP(CFolderDialog, CFileDialog) //{{AFX_MSG_MAP(CFolderDialog) // NOTE - the ClassWizard will add and remove mapping macros here. //}}AFX_MSG_MAPEND_MESSAGE_MAP()// Function name : WindowProcNew// Description : Call this function when user navigate into CFileDialog.// Return type : LRESULT// Argument : HWND hwnd// Argument : UINT message// Argument : WPARAM wParam// Argument : LPARAM lParamLRESULT CALLBACK WindowProcNew(HWND hwnd,UINT message, WPARAM wParam, LPARAM lParam){ if (message == WM_COMMAND) if (HIWORD(wParam) == BN_CLICKED) if (LOWORD(wParam) == IDOK) { if (CFileDialog* pDlg = (CFileDialog*)CWnd::FromHandle(hwnd)) { TCHAR path[MAX_PATH]; GetCurrentDirectory(MAX_PATH, path); *((CFolderDialog*)pDlg->GetDlgItem(0))->m_pPath = CString(path); pDlg->EndDialog(IDOK); return NULL; } } return CallWindowProc(CFolderDialog::m_wndProc, hwnd, message, wParam, lParam);}// Function name : CFolderDialog::OnInitDone// Description : For update the wiew of CFileDialog// Return type : void void CFolderDialog::OnInitDone(){ HideControl(edt1); HideControl(stc3); HideControl(cmb1); HideControl(stc2); CWnd* pFD = GetParent(); CRect rectCancel; pFD->GetDlgItem(IDCANCEL)->GetWindowRect(rectCancel); pFD->ScreenToClient(rectCancel); CRect rectOK; pFD->GetDlgItem(IDOK)->GetWindowRect(rectOK); pFD->ScreenToClient(rectOK); pFD->GetDlgItem(IDOK)->SetWindowPos(0,rectCancel.left - rectOK.Width() - 4, rectCancel.top, 0,0, SWP_NOZORDER | SWP_NOSIZE); CRect rectList2; pFD->GetDlgItem(lst1)->GetWindowRect(rectList2); pFD->ScreenToClient(rectList2); pFD->GetDlgItem(lst1)->SetWindowPos(0,0,0,rectList2.Width(), abs(rectList2.top - (rectCancel.top - 4)), SWP_NOMOVE | SWP_NOZORDER); SetControlText(IDOK, _T("Select")); pFD->SetWindowText(_T("Choose folder")); m_wndProc = (WNDPROC)SetWindowLong(pFD->m_hWnd, GWL_WNDPROC, (long)WindowProcNew);}满意记得给分! http://www.vckbase.com/english/code/dialog/folder_dialog.shtml.htm class CFolderDialog 这个类是可以得到选择的目录的父目录,可是得不到我选择的目录呀!并且不支持多项选择,不知道还有没有其他的例程可以得到选择的目录,并可以多项选择? 从模块读数ReadFile? 求一份基于VC6的邮件客户端源代码(有酬) 如何自动添加树形控件消息 怎么查看结果?(很菜的问题) UDP-有点奇怪 小弟最近颇受垃圾邮件骚扰之苦 关于动态的使用.dll增加功能函数模块的问题。高手请进 CString类有Mid函数,可是如果对char*进行类似Mid函数的操作该怎么办? 关与for循环步长问题,请教各位。 XGina看不懂,不知道是在那里处理的logonuser,谁知道呀 Dialog的属性的问题? 怎样编写屏幕保护程序
class CFolderDialog : public CFileDialog
{
DECLARE_DYNAMIC(CFolderDialog)public:
static WNDPROC m_wndProc;
virtual void OnInitDone( );
CString* m_pPath;
CFolderDialog(CString* pPath);protected:
//{{AFX_MSG(CFolderDialog)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#include "stdafx.h"
#include "folder_dialog.h"
#include <DLGS.H>
#include <WINUSER.H>#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CFolderDialogIMPLEMENT_DYNAMIC(CFolderDialog, CFileDialog)WNDPROC CFolderDialog::m_wndProc = NULL;
// Function name : CFolderDialog::CFolderDialog
// Description : Constructor
// Return type :
// Argument : CString* pPath ; represent string where selected folder wil be saved
CFolderDialog::CFolderDialog(CString* pPath) : CFileDialog(TRUE, NULL, _T("*..*"))
{
m_pPath = pPath;
}
BEGIN_MESSAGE_MAP(CFolderDialog, CFileDialog)
//{{AFX_MSG_MAP(CFolderDialog)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()// Function name : WindowProcNew
// Description : Call this function when user navigate into CFileDialog.
// Return type : LRESULT
// Argument : HWND hwnd
// Argument : UINT message
// Argument : WPARAM wParam
// Argument : LPARAM lParam
LRESULT CALLBACK WindowProcNew(HWND hwnd,UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_COMMAND)
if (HIWORD(wParam) == BN_CLICKED)
if (LOWORD(wParam) == IDOK)
{
if (CFileDialog* pDlg = (CFileDialog*)CWnd::FromHandle(hwnd))
{
TCHAR path[MAX_PATH];
GetCurrentDirectory(MAX_PATH, path);
*((CFolderDialog*)pDlg->GetDlgItem(0))->m_pPath = CString(path);
pDlg->EndDialog(IDOK);
return NULL;
}
}
return CallWindowProc(CFolderDialog::m_wndProc, hwnd, message, wParam, lParam);
}// Function name : CFolderDialog::OnInitDone
// Description : For update the wiew of CFileDialog
// Return type : void
void CFolderDialog::OnInitDone()
{
HideControl(edt1);
HideControl(stc3);
HideControl(cmb1);
HideControl(stc2);
CWnd* pFD = GetParent();
CRect rectCancel; pFD->GetDlgItem(IDCANCEL)->GetWindowRect(rectCancel);
pFD->ScreenToClient(rectCancel);
CRect rectOK; pFD->GetDlgItem(IDOK)->GetWindowRect(rectOK);
pFD->ScreenToClient(rectOK);
pFD->GetDlgItem(IDOK)->SetWindowPos(0,rectCancel.left - rectOK.Width() - 4, rectCancel.top, 0,0, SWP_NOZORDER | SWP_NOSIZE);
CRect rectList2; pFD->GetDlgItem(lst1)->GetWindowRect(rectList2);
pFD->ScreenToClient(rectList2);
pFD->GetDlgItem(lst1)->SetWindowPos(0,0,0,rectList2.Width(), abs(rectList2.top - (rectCancel.top - 4)), SWP_NOMOVE | SWP_NOZORDER);
SetControlText(IDOK, _T("Select"));
pFD->SetWindowText(_T("Choose folder"));
m_wndProc = (WNDPROC)SetWindowLong(pFD->m_hWnd, GWL_WNDPROC, (long)WindowProcNew);
}
满意记得给分!