Article View: borland.public.cppbuilder.nativeapi
Article #2629Re: SHBrowseForFolder and filtering
From: Remy Lebeau (TeamB)
Date: Wed, 07 Feb 2007 18:27
Date: Wed, 07 Feb 2007 18:27
80 lines
3550 bytes
3550 bytes
"Mike Collins" <its@TheBottomOfThePost.com> wrote in message
news:45c9eb0a@newsgroups.borland.com...
> I want to limit the users display to only removale drives, CD / DVD
> drives and folders within these drives.
SHBrowseForFolder() does not support that. You can use the pidlRoot
member of the BROWSEINFO structure to limit the dialog to drive
letters only by setting it to the ITEMIDLIST returned by
SHGetSpecialFolderLocation(CSIDL_DRIVES). But you cannot filter out
which individual drives are actually displayed. The only thing you
can do is use the callback function to prevent the dialog from being
closed if the user tries to select an incorrect drive/folder.
> I've coded a custome callback for the browser but i'm not sure what
> messages to look for and how to process then.
For example:
int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM
lParam, LPARAM lpData)
{
if( uMsg == BFFM_SELCHANGED )
{
LPITEMIDLIST pidl = (LPITEMIDLIST) lpData;
TCHAR path[MAX_PATH+1] = {0};
if( SHGetPathFromIDList(pidl, path) )
{
if( path[1] == TEXT(':') )
{
path[2] = 0;
UINT type = GetDriveType(path);
if( (type == DRIVE_REMOVABLE) || (type ==
DRIVE_CDROM) )
{
SendMessage(hwnd, BFFM_ENABLEOK, TRUE, 0);
SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0,
(LPARAM) TEXT(""));
return 0;
}
}
SendMessage(hwnd, BFFM_ENABLEOK, FALSE, 0);
SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)
TEXT("Select a removable drive/folder only!"));
}
return 0;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TCHAR buffer[MAX_PATH+1];
LPITEMIDLIST pidlRoot = NULL;
SHGetSpecialFolderLocation(Handle, CSIDL_DRIVES, &pidlRoot);
BROWSEINFO bi = {0};
bi.hwndOwner = Handle;
bi.pidlRoot = pidlRoot;
bi.pszDisplayName = buffer;
bi.lpszTitle = TEXT("Select a removalbe drive/folder");
bi.ulFlags = BIF_STATUSTEXT | BIF_RETURNONLYFSDIRS;
bi.lpfn = &BrowseCallbackProc;
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
if( pidlRoot ) CoTaskMemFree(pidlRoot);
if( pidl )
{
//...
CoTaskMemFree(pidl);
}
}
Gambit
Technical Details
Message-ID:
<45ca1a14$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<45c9eb0a@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,44855005298c82e X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <45c9eb0a@newsgroups.borland.com> Subject: Re: SHBrowseForFolder and filtering Date: Wed, 7 Feb 2007 10:27:16 -0800 Lines: 82 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 75.83.34.171 Message-ID: <45ca1a14$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1170872852 75.83.34.171 (7 Feb 2007 10:27:32 -0800) Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail