Discussion:
SHBrowseForFolder returns wrong info when BIF_USENEWUI | BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT | BIF_VALIDATE is used
(too old to reply)
j***@gmail.com
2014-04-15 01:11:07 UTC
Permalink
The following is my code. According to MSDN, when user types in some garbage string in the edit box, the OK button is supposed to be disabled. I am expecting to receive the garbage string and so I can bail out by reminding user. However, it looks like Microsoft is trying to make itself look nice: it is always returning the current selected item in the tree control. This will lead to some unwanted behavior in my application.

Is there some way to force it to disable the OK button or return the garbage string and so I can do some validation by myself? Thanks in advance.

wchar_t outPath[MAX_PATH];
BROWSEINFO bInfo;
::ZeroMemory(&bInfo, sizeof(BROWSEINFO));
bInfo.hwndOwner = parentHWND;
bInfo.pidlRoot = NULL;
bInfo.pszDisplayName = outPath;
bInfo.lpszTitle = (LPCWSTR)caption;
bInfo.ulFlags = BIF_USENEWUI | BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT | BIF_VALIDATE;
bInfo.lpfn = NULL;
bInfo.lParam = 0;

LPITEMIDLIST lpItem = ::SHBrowseForFolder(&bInfo);
David Lowndes
2014-04-15 10:24:25 UTC
Permalink
Post by j***@gmail.com
According to MSDN, when user types in some garbage string in the edit box, the OK button is supposed to be disabled.
Can you tell us where this is documented?

As far as I can see, the MSDN documentation for BIF_VALIDATE says:

" If the user types an invalid name into the edit box, the browse
dialog box calls the application's BrowseCallbackProc with the
BFFM_VALIDATEFAILED message"

and for BIF_RETURNONLYFSDIRS it says:

"If the user selects folders that are not part of the file system, the
OK button is grayed"

Dave

Loading...