🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #9809

Re: SHBrowseForFolder

#9809
From: Remy Lebeau (TeamB)
Date: Tue, 08 Jun 2004 17:55
72 lines
3129 bytes
"Hans Galema" <dontusethis@dontusethis.nl> wrote in message
news:40c5a181$1@newsgroups.borland.com...

> You are the first one here, who succeeds setting the
> initial directory, as far as I know. Compliments.

Here is the code that I have been using for several years now:

    #include <shlobj.h>

    int __stdcall BrowseProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM
lpData)
    {
        if( uMsg == BFFM_INITIALIZED )
        {
            AnsiString *asTemp = reinterpret_cast<AnsiString*>(lpData);
            if( (asTemp) && (!asTemp->IsEmpty()) )
            {
                // the browse dialog will not correctly set the desired
                // path if there's a trailing '\' at the end of it when it's
                // not a root path

                if( asTemp->Length() > 3 )
                {
                    while( asTemp->IsPathDelimiter(asTemp->Length()) )
                        asTemp->Delete(asTemp->Length(), 1);
                }

                SendMessage(hwnd, BFFM_SETSELECTION, TRUE,
reinterpret_cast<LPARAM>(asTemp->c_str()));
            }
        }
        return 0;
    }


    AnsiString asCurrentDataDir;

    void __fastcall TEventLogSettingsForm::Button1Click(TObject *Sender)
    {
        LPITEMIDLIST pRoot = NULL;
        SHGetSpecialFolderLocation(Handle, CSIDL_DRIVES, &pRoot);

        BROWSEINFO bi = {0};
        bi.lpszTitle = "Pick a folder:";
        bi.hwndOwner = Handle;
        bi.pidlRoot = pRoot;
        bi.ulFlags = BIF_STATUSTEXT | BIF_RETURNONLYFSDIRS | BIF_EDITBOX;
        bi.lpfn = (BFFCALLBACK)BrowseProc;
        bi.lParam = reinterpret_cast<LPARAM>(&asCurrentDataDir);

        this->Enabled = false;
        Application->ProcessMessages();

        LPITEMIDLIST lpItemList = SHBrowseForFolder(&bi);
        if( lpItemList != NULL )
        {
            char buffer[MAX_PATH] = {0};
            //...
            asCurrentDataDir = buffer;
            CoTaskMemFree(lpItemList);
        }

        this->Enabled = true;

        if( pRoot )
            CoTaskMemFree(pRoot);
    }


Gambit
Technical Details
Message-ID: <40c5fe8e$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <40c56f71$1@newsgroups.borland.com> <40c576e3$1@newsgroups.borland.com> <40c5975f@newsgroups.borland.com> <40c5a181$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,179ca2994416d9ea
X-Google-Attributes: gid10cc67,public
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <40c56f71$1@newsgroups.borland.com> <40c576e3$1@newsgroups.borland.com> <40c5975f@newsgroups.borland.com> <40c5a181$1@newsgroups.borland.com>
Subject: Re: SHBrowseForFolder
Date: Tue, 8 Jun 2004 10:55:35 -0700
Lines: 74
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: 68.169.168.124
Message-ID: <40c5fe8e$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1086717582 68.169.168.124 (8 Jun 2004 10:59:42 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail