// JP opened flex table

Click to See Complete Forum and Search --> : Select folder dialog???


rambovn
July 8th, 2008, 08:07 AM
Hi all,
I am using CFileDialog for selecting one or multiple files. But now I also want to select a folder. How can I do it?


CFileDialog dlg( true, NULL, NULL, OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY, Filter );
if ( dlg.DoModal() != IDOK )
{
if ( CommDlgExtendedError() == FNERR_BUFFERTOOSMALL )
AfxMessageBox( IDS_TOO_MANY_FILES );
free( pBuf );
return;
}
else
{
}


Thank you very much for any help.
Regards

fred100
July 8th, 2008, 09:24 AM
Why don't you use SHBrowseForFolder() ?!

rambovn
July 8th, 2008, 09:40 AM
Why don't you use SHBrowseForFolder() ?!
Thank you for your answer, I have just tried with SHBrowseForFolder, but it worked only with selecting folder not with selecting file, and in my project, both cases (selecting folder and selecting file) must be done.

macroideal
July 9th, 2008, 03:05 AM
i met this problem last days:
BrowseDlg(CString lpszTitle)
{
ITEMIDLIST *ppidl;
SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP ,&ppidl);
if ( ppidl == NULL)
{
AfxMessageBox(_T("sorry!") ) ;
return _T("error");
}
TCHAR path[255] = _T("");
BROWSEINFO *bi=new BROWSEINFO;
bi->hwndOwner=NULL;
bi->pidlRoot=ppidl;
bi->pszDisplayName=NULL;
bi->lpszTitle=lpszTitle;
bi->lpfn=NULL;
bi->ulFlags=/*BIF_BROWSEINCLUDEFILES|*/BIF_EDITBOX |BIF_RETURNONLYFSDIRS ;
ppidl = SHBrowseForFolder(bi);
if ( !SHGetPathFromIDList(ppidl,path) )
{
delete bi;
return _T("error") ;
}
delete bi;
CString s = path ;
if ( s.Right( 1 ) != _T("\\") )
s+= _T("\\") ;

return s ;
}

//JP added flex table