-
January 22nd, 2013, 06:46 PM
#1
How to set a starting root directory for this code that selects a folder name?
The following code is useful to allow a user to select a particular folder in the disk directory.
Code:
void OpenFolder()
{
LPMALLOC pMalloc; //,pMalloc2;
CString strDirectory;
BROWSEINFO bi;
// Gets the Shell's default allocator
wchar_t pszBuffer[MAX_PATH];
LPITEMIDLIST pidl;
// Get help on BROWSEINFO struct - it's got all the bit settings.
bi.hwndOwner = ::GetDesktopWindow();
bi.pidlRoot = NULL;
bi.pszDisplayName = pszBuffer;
bi.lpszTitle = _T("Select A Directory");
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS | BIF_NEWDIA********;
bi.lpfn = NULL;
bi.lParam = 0;
if (::SHGetMalloc(&pMalloc) == NOERROR)
{
if ((pidl = ::SHBrowseForFolder(&bi)) != NULL)
{
if (::SHGetPathFromIDList(pidl, pszBuffer))
{
strDirectory = pszBuffer;
}
pMalloc->Free(pidl);
}
pMalloc->Release();
}
TRACE0("strDirectory =: ");
OutputDebugString(strDirectory); TRACE0("\n");
}
However, if one uses this code over and over, one quickly becomes tired of threading one's way all the way from root directory C:\. There is undoubtedly some way to designate a starting directory. The most obvious candidate to set such a target is the:
Code:
bi.pidlRoot = NULL;
But attempting to set bi.pidlRoot to a CString (directory address) errors because 'no suiitable conversion from CString to LPCITEMIDLIST exists'
How can I set the code to open at a designated address in the directory tree?
mpliam
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|