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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

directory dialog box

Status
Not open for further replies.

Maurader

Technical User
May 8, 2002
59
CA
how do i create a dialog box that will prompt the user to select a directory??
 

you can use SHBrowseForFolder. Here's am example:


char* szResult;
BROWSEINFO bi;
memset((LPVOID)&bi, 0, sizeof(bi));
TCHAR szDisplayName[_MAX_PATH+1];
szDisplayName[0] = '\0';
bi.hwndOwner = this->m_hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = szDisplayName;
bi.lpszTitle = "Find folder";
bi.ulFlags = BIF_RETURNONLYFSDIRS;
LPITEMIDLIST pIIL = ::SHBrowseForFolder(&bi);
BOOL bRetVal = ::SHGetPathFromIDList(pIIL, szResult);
if (!bRetVal)
{
*szResult='\0';

}
LPMALLOC pMalloc;
SHGetMalloc(&pMalloc);
pMalloc->Free(pIIL);
pMalloc->Release();


Hope this helps

CMR
 
I'm getting an access violation when i get to
BOOL bRetVal = ::SHGetPathFromIDList(pIIL, szResult);

any ideas why?
 
Sorry, My mistake.
That code example is taken from an application I wrote some time ago and is actually the body of a function. The complete function looks like this:

BOOL CMyDialog::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 bRetVal = ::SHGetPathFromIDList(pIIL, szResult);
if (!bRetVal)
*szResult='\0';
LPMALLOC pMalloc;
SHGetMalloc(&pMalloc);
pMalloc->Free(pIIL);
pMalloc->Release();
return bRetVal;
}

as you can see, szResult is an output parameter of the function which is called like this:

char szOutputDir[MAX_PATH];
if(BrowseForFolder(_T("Choose file location:"), GetSafeHwnd(), szOutputDir))
{
m_strLocation = szOutputDir;
UpdateData(FALSE);
}

Sorry about that.
hope this sorts out the problem

CMR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top