How to Select Directory throught File Open dialog
-
Hello Friends, In one of my application I need to let use to select the directory. I am using File Open dialog for that. but that Only let user select File. Is there any Way I can use this to select the Directory This is the code I am using.It Allows me to select *.exe File When Choose EXE in Files of Type in File Open Dialog. but Not able to select the Directoy when Select FOLDER Option.
void FileOpenDlg(WCHAR *Path)
{
OPENFILENAME ofn;ofn.lStructSize = sizeof ( OPENFILENAME) ; ofn.hwndOwner = hDlg ; ofn.hInstance = NULL ; //Not supported **ofn.lpstrFilter =\_T("Application (\*.Exe;\*.avi) \\0 \*.Exe;\*.avi\\0 FOLDER \\0 ") ;** ofn.lpstrCustomFilter = NULL ; //Not Supported ofn.nMaxCustFilter = 0 ; //Not Supported ofn.nFilterIndex = 1 ; ofn.lpstrFile = Path ; // Set in Open and Close functions ofn.nMaxFile = MAX\_PATH ; ofn.lpstrFileTitle = NULL ; // buffer that receives the file name (without path information) ofn.nMaxFileTitle = MAX\_PATH ; ofn.lpstrInitialDir = NULL; ofn.lpstrTitle = NULL ; ofn.Flags = 0 ; // Set in Open and Close functions ofn.nFileOffset = 0 ; ofn.nFileExtension = 0 ; ofn.lpstrDefExt = NULL ; ofn.lCustData = 0L ; ofn.lpfnHook = NULL ; //Not Supported ofn.lpTemplateName = NULL ; //Not Supported GetOpenFileName(&ofn);
}
[ Screen Capture ][ Tool Tip ]
-
Hello Friends, In one of my application I need to let use to select the directory. I am using File Open dialog for that. but that Only let user select File. Is there any Way I can use this to select the Directory This is the code I am using.It Allows me to select *.exe File When Choose EXE in Files of Type in File Open Dialog. but Not able to select the Directoy when Select FOLDER Option.
void FileOpenDlg(WCHAR *Path)
{
OPENFILENAME ofn;ofn.lStructSize = sizeof ( OPENFILENAME) ; ofn.hwndOwner = hDlg ; ofn.hInstance = NULL ; //Not supported **ofn.lpstrFilter =\_T("Application (\*.Exe;\*.avi) \\0 \*.Exe;\*.avi\\0 FOLDER \\0 ") ;** ofn.lpstrCustomFilter = NULL ; //Not Supported ofn.nMaxCustFilter = 0 ; //Not Supported ofn.nFilterIndex = 1 ; ofn.lpstrFile = Path ; // Set in Open and Close functions ofn.nMaxFile = MAX\_PATH ; ofn.lpstrFileTitle = NULL ; // buffer that receives the file name (without path information) ofn.nMaxFileTitle = MAX\_PATH ; ofn.lpstrInitialDir = NULL; ofn.lpstrTitle = NULL ; ofn.Flags = 0 ; // Set in Open and Close functions ofn.nFileOffset = 0 ; ofn.nFileExtension = 0 ; ofn.lpstrDefExt = NULL ; ofn.lCustData = 0L ; ofn.lpfnHook = NULL ; //Not Supported ofn.lpTemplateName = NULL ; //Not Supported GetOpenFileName(&ofn);
}
[ Screen Capture ][ Tool Tip ]
-
Hello Friends, In one of my application I need to let use to select the directory. I am using File Open dialog for that. but that Only let user select File. Is there any Way I can use this to select the Directory This is the code I am using.It Allows me to select *.exe File When Choose EXE in Files of Type in File Open Dialog. but Not able to select the Directoy when Select FOLDER Option.
void FileOpenDlg(WCHAR *Path)
{
OPENFILENAME ofn;ofn.lStructSize = sizeof ( OPENFILENAME) ; ofn.hwndOwner = hDlg ; ofn.hInstance = NULL ; //Not supported **ofn.lpstrFilter =\_T("Application (\*.Exe;\*.avi) \\0 \*.Exe;\*.avi\\0 FOLDER \\0 ") ;** ofn.lpstrCustomFilter = NULL ; //Not Supported ofn.nMaxCustFilter = 0 ; //Not Supported ofn.nFilterIndex = 1 ; ofn.lpstrFile = Path ; // Set in Open and Close functions ofn.nMaxFile = MAX\_PATH ; ofn.lpstrFileTitle = NULL ; // buffer that receives the file name (without path information) ofn.nMaxFileTitle = MAX\_PATH ; ofn.lpstrInitialDir = NULL; ofn.lpstrTitle = NULL ; ofn.Flags = 0 ; // Set in Open and Close functions ofn.nFileOffset = 0 ; ofn.nFileExtension = 0 ; ofn.lpstrDefExt = NULL ; ofn.lCustData = 0L ; ofn.lpfnHook = NULL ; //Not Supported ofn.lpTemplateName = NULL ; //Not Supported GetOpenFileName(&ofn);
}
[ Screen Capture ][ Tool Tip ]
Use the followign code:
CString YourClassName::GetFolderName()
{
BROWSEINFO br;CString title = "Select the folder to convert its files"; char buff\[MAX\_PATH\]; br.hwndOwner = m\_hWnd; br.pidlRoot = NULL; br.lParam = NULL; br.lpfn = NULL; br.lpszTitle =( (LPTSTR) ((LPCTSTR)title)); br.pszDisplayName =(LPTSTR) buff; //br.ulFlags = BIF\_BROWSEINCLUDEFILES; br.ulFlags = BIF\_RETURNONLYFSDIRS; LPITEMIDLIST item; item = ::SHBrowseForFolder ( &br ); ::SHGetPathFromIDList ( item, buff ); return buff;
}
Hoping that it will help you.
Anurag Gandhi. http://www.softgandhi.co.nr Life is a computer program and every one is the programmer of his own life.
-
Use the followign code:
CString YourClassName::GetFolderName()
{
BROWSEINFO br;CString title = "Select the folder to convert its files"; char buff\[MAX\_PATH\]; br.hwndOwner = m\_hWnd; br.pidlRoot = NULL; br.lParam = NULL; br.lpfn = NULL; br.lpszTitle =( (LPTSTR) ((LPCTSTR)title)); br.pszDisplayName =(LPTSTR) buff; //br.ulFlags = BIF\_BROWSEINCLUDEFILES; br.ulFlags = BIF\_RETURNONLYFSDIRS; LPITEMIDLIST item; item = ::SHBrowseForFolder ( &br ); ::SHGetPathFromIDList ( item, buff ); return buff;
}
Hoping that it will help you.
Anurag Gandhi. http://www.softgandhi.co.nr Life is a computer program and every one is the programmer of his own life.
Anurag Gandhi wrote:
LPITEMIDLIST item; item = ::SHBrowseForFolder ( &br ); ::SHGetPathFromIDList ( item, buff ); return buff;
You need to release the memory allocated for
item
after you get the path name. As the documentation for SHBrowseForFolder says: The calling application is responsible for freeing the returned PIDL by using the Shell allocator's IMalloc::Free method. To retrieve a handle to that IMalloc interface, call SHGetMalloc.LPMALLOC pMalloc; SHGetMalloc (&pMalloc); pMalloc->Free (item); pMalloc->Release ();
Judy
-
Hello Friends, In one of my application I need to let use to select the directory. I am using File Open dialog for that. but that Only let user select File. Is there any Way I can use this to select the Directory This is the code I am using.It Allows me to select *.exe File When Choose EXE in Files of Type in File Open Dialog. but Not able to select the Directoy when Select FOLDER Option.
void FileOpenDlg(WCHAR *Path)
{
OPENFILENAME ofn;ofn.lStructSize = sizeof ( OPENFILENAME) ; ofn.hwndOwner = hDlg ; ofn.hInstance = NULL ; //Not supported **ofn.lpstrFilter =\_T("Application (\*.Exe;\*.avi) \\0 \*.Exe;\*.avi\\0 FOLDER \\0 ") ;** ofn.lpstrCustomFilter = NULL ; //Not Supported ofn.nMaxCustFilter = 0 ; //Not Supported ofn.nFilterIndex = 1 ; ofn.lpstrFile = Path ; // Set in Open and Close functions ofn.nMaxFile = MAX\_PATH ; ofn.lpstrFileTitle = NULL ; // buffer that receives the file name (without path information) ofn.nMaxFileTitle = MAX\_PATH ; ofn.lpstrInitialDir = NULL; ofn.lpstrTitle = NULL ; ofn.Flags = 0 ; // Set in Open and Close functions ofn.nFileOffset = 0 ; ofn.nFileExtension = 0 ; ofn.lpstrDefExt = NULL ; ofn.lCustData = 0L ; ofn.lpfnHook = NULL ; //Not Supported ofn.lpTemplateName = NULL ; //Not Supported GetOpenFileName(&ofn);
}
[ Screen Capture ][ Tool Tip ]
-
Anurag Gandhi wrote:
LPITEMIDLIST item; item = ::SHBrowseForFolder ( &br ); ::SHGetPathFromIDList ( item, buff ); return buff;
You need to release the memory allocated for
item
after you get the path name. As the documentation for SHBrowseForFolder says: The calling application is responsible for freeing the returned PIDL by using the Shell allocator's IMalloc::Free method. To retrieve a handle to that IMalloc interface, call SHGetMalloc.LPMALLOC pMalloc; SHGetMalloc (&pMalloc); pMalloc->Free (item); pMalloc->Release ();
Judy
Thanks for the correction Judy. :)
Anurag Gandhi. http://www.softgandhi.co.nr Life is a computer program and every one is the programmer of his own life.