Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting a directory 2

Status
Not open for further replies.

SteveD73

Programmer
Jan 5, 2001
109
GB
Hi

I am writting a program which requires the user to select a directory. Does a control exist which displays a dialog that allows the user to select a destination directory?

Thank you
 
try GetOpenFileName and GetSaveFileName. They display a system box save/saveas/open file/directory... Study how to work with structure OPENFILENAME. John Fill
1c.bmp


ivfmd@mail.md
 
I have looked at the above but I see no way of displaying a dialog which only allows the user to select an output directory. For an example of what I require goto Tools->Options->Directories and then try changing the directory. A dialog should be displayed which only shows directories. Do I have to create this dialog manually? If so how would I create a listbox showing all the current directories?

Any help is much appreciated.

Thank you
 
I created this dialog manually using a CTreeView control. Many of the more common Visual C++ books have an example of this (Programming Windows with MFC 2nd Edition - Jeff Prosise). Alternately there is a fairly good example at Regards

Brendan
 
Hi, I had the same problem, it seemed to me that the easiest way was using SHBrowseForFolder() API function. Here I made a more simple function that wraps the API and gives you what you want:

void CParserDlg::BrowseForFolder(char *szTitle, HWND hwndOwner, char *szResult){
BROWSEINFO bi;
memset((LPVOID)&bi, 0, sizeof(bi));
TCHAR szDisplayName[_MAX_PATH+1];
szDisplayName[0] = '\0';
bi.hwndOwner = hwndOwner;
bi.pidlRoot = NULL;
bi.pszDisplayName = szDisplayName;
bi.lpszTitle = szTitle;
bi.ulFlags = BIF_RETURNONLYFSDIRS;

LPITEMIDLIST pIIL = ::SHBrowseForFolder(&bi);


BOOL bRet = ::SHGetPathFromIDList(pIIL, szResult);

if (!bRet)
{
*szResult='\0';

}
LPMALLOC pMalloc;
/*HRESULT hr = */SHGetMalloc(&pMalloc);
pMalloc->Free(pIIL);
pMalloc->Release();

}


And here is an example of how to call it:
BrowseForFolder(_T("Choose the output folder:"),
GetSafeHwnd(), szOutputDir); (you get the full path into the third parameter, note that it must be already allocated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top