galneweinhaw
asked on
How to open a File Browse Dialog
How can I create a File browsing dialog that returns the directory chosen?
I tried this:
http://www.codeproject.com/dialog/cfolderdialog.asp?df=100&forumid=3533&select=957565
but can't get it to work (errors are posted at the bottom of that page)
thanks!
I tried this:
http://www.codeproject.com/dialog/cfolderdialog.asp?df=100&forumid=3533&select=957565
but can't get it to work (errors are posted at the bottom of that page)
thanks!
ASKER
That works great!
is there any way for me to specify the folder the browse window starts in? (without restricting the browsing by using a root)
thanks
is there any way for me to specify the folder the browse window starts in? (without restricting the browsing by using a root)
thanks
http://www.codeproject.com/dialog/folderbrowser.asp ("How to show a dialog to let users browse for and select a folder") describes that issu epretty well, and better than I could do.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried the codeproject thing but it's giving me this error...
Compiling...
UpdateIESDlg.cpp
O:\ENGINEERING\SHARED\PHOT OMET\PROGR AMS\OTHER PROGRAMS\UPDATEIES\UpdateI ES\UpdateI ESDlg.cpp( 302) : error C2440: '=' : cannot convert from 'int (__stdcall CUpdateIESDlg::*)(struct HWND__ *,unsigned int,long,long)' to 'int (__stdcall *)(struct HWND__
*,unsigned int,long,long)'
There is no context in which this conversion is possible
O:\ENGINEERING\SHARED\PHOT OMET\PROGR AMS\OTHER PROGRAMS\UPDATEIES\UpdateI ES\UpdateI ESDlg.cpp( 312) : warning C4390: ';' : empty controlled statement found; is this the intent?
Error executing cl.exe.
Creating browse info file...
UpdateIES.exe - 1 error(s), 1 warning(s)
The first occurs here:
bi.lpfn = BrowseCallbackProc;
The warning here:
if(SUCCEEDED(SHGetMalloc(& pMalloc)) && pMalloc);
pMalloc->Free(pidl);
pMalloc->Release();
thanks for the help.
Compiling...
UpdateIESDlg.cpp
O:\ENGINEERING\SHARED\PHOT
*,unsigned int,long,long)'
There is no context in which this conversion is possible
O:\ENGINEERING\SHARED\PHOT
Error executing cl.exe.
Creating browse info file...
UpdateIES.exe - 1 error(s), 1 warning(s)
The first occurs here:
bi.lpfn = BrowseCallbackProc;
The warning here:
if(SUCCEEDED(SHGetMalloc(&
pMalloc->Free(pidl);
pMalloc->Release();
thanks for the help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to both of you for the help
unfortunately I am still getting this error using the code above:
error C2440: '=' : cannot convert from 'int (__stdcall CUpdateIESDlg::*)(struct HWND__ *,unsigned int,long,long)' to 'int (__stdcall *)(struct HWND__ *,unsigned int,long,long)' There is no context in which this conversion is possible
It is occuring at this line:
bi.lpfn = BrowseCallbackProc;
Also getting the error:
error C2660: 'SendMessageA' : function does not take 4 parameters
from lines:
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)szDir);
//and
SendMessage(hwnd,BFFM_SETS TATUSTEXT, 0,(LPARAM) szDir);
thanks again.
unfortunately I am still getting this error using the code above:
error C2440: '=' : cannot convert from 'int (__stdcall CUpdateIESDlg::*)(struct HWND__ *,unsigned int,long,long)' to 'int (__stdcall *)(struct HWND__ *,unsigned int,long,long)' There is no context in which this conversion is possible
It is occuring at this line:
bi.lpfn = BrowseCallbackProc;
Also getting the error:
error C2660: 'SendMessageA' : function does not take 4 parameters
from lines:
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)szDir);
//and
SendMessage(hwnd,BFFM_SETS
thanks again.
>>error C2440: '=' : cannot convert from
The browse callback cannot be a non-static member of CUpdateIESDlg - either make that not a member function or declare it as 'static'.
>>error C2660: 'SendMessageA' : function does not take 4 parameters
The compiler thinks you are referring to CWnd::SendMessage() - use
::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)szDir);
//and
::SendMessage(hwnd,BFFM_SE TSTATUSTEX T,0,(LPARA M)szDir);
to resolve this ambiguity.
The browse callback cannot be a non-static member of CUpdateIESDlg - either make that not a member function or declare it as 'static'.
>>error C2660: 'SendMessageA' : function does not take 4 parameters
The compiler thinks you are referring to CWnd::SendMessage() - use
::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)szDir);
//and
::SendMessage(hwnd,BFFM_SE
to resolve this ambiguity.
ASKER
Thanks jkr,
working great.
How do I post a follow-up question?
My directory name is so long it is wrapping and getting hidden behind the tree-view.
working great.
How do I post a follow-up question?
My directory name is so long it is wrapping and getting hidden behind the tree-view.
#include <shlobj.h>
void PickFolder ( CString& strFolder)
{
LPMALLOC pMalloc; /* Gets the Shell's default allocator */
if ( ::SHGetMalloc ( &pMalloc) == NOERROR)
{
BROWSEINFO bi;
char pszBuffer [ MAX_PATH];
LPITEMIDLIST pidl;
// Get help on BROWSEINFO struct - it's got all the bit settings.
bi.hwndOwner = GetSafeHwnd();
bi.pidlRoot = NULL;
bi.pszDisplayName = pszBuffer;
bi.lpszTitle = _T("Select a Folder");
bi.ulFlags = 0;
bi.lpfn = NULL;
bi.lParam = 0;
// This next call issues the dialog box.
if ( pidl = ::SHBrowseForFolder ( &bi))
{
if ( ::SHGetPathFromIDList ( pidl, pszBuffer))
{
// At this point pszBuffer contains the selected folder */
strFolder = pszBuffer;
}
// Free the PIDL allocated by SHBrowseForFolder.
pMalloc->Free ( pidl);
}
// Release the shell's allocator.
pMalloc->Release();
}
}