🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Shbrowseforfolder edit box problems

#2352
From: Remy Lebeau (TeamB)
Date: Mon, 05 Mar 2007 18:40
68 lines
2858 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:45ec6a71@newsgroups.borland.com...

> You don't.  That box is not for your code to use at all.  It is only
> for the user to use.

I stand corrected.  Bob's approach is the key.  It just needs some
cleaning up.  The following code works fine for me:

    int CALLBACK mjBrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM
lParam, LPARAM lpData)
    {
        switch( uMsg )
        {
            case BFFM_INITIALIZED:
            {
                LPTSTR ptr = reinterpret_cast<LPTSTR>(lpData);
                if( ptr[0] != 0 )
                {
                    SendMessage(hwnd, BFFM_SETSELECTION, TRUE,
lpData);
                    ptr[0] = 0;
                }
                break;
            }

            case BFFM_VALIDATEFAILED:
            {
                lstrcpyn(reinterpret_cast<LPTSTR>(lpData),
reinterpret_cast<LPTSTR>(lParam), MAX_PATH);
                break;
            }
        }

        return 0;
    }

    void __fastcall Tmjgrabstr::xbtnClick(TObject *Sender)
    {
        AnsiString Dir = Edit1->Text;
        if( !DirectoryExists(Dir) )
            Dir = GetCurrentDir();

        TCHAR rcvdir[MAX_PATH+1] = {0};
        lstrcpy(rcvdir, Dir.c_str(), MAX_PATH);

        BROWSEINFO mjbi = {0};
        mjbi.hwndOwner = Application->Handle;
        mjbi.lpszTitle = TEXT("Choose a Directory :-");
        mjbi.ulFlags = BIF_EDITBOX | BIF_VALIDATE;
        mjbi.lpfn = mjBrowseCallbackProc;
        mjbi.lParam = reinterpret_cast<LPARAM>(rcvdir);

        LPITEMIDLIST mjites = SHBrowseForFolder(&mjbi);
        if( mjites )
        {
            rcvdir[0] = 0;
            SHGetPathFromIDList(mjites, rcvdir);
            CoTaskMemFree(mjites);
        }

        if( rcvdir[0] != 0 )
            Edit1->Text = rcvdir;
    }


Gambit
Technical Details
Message-ID: <45ec71a5$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <45ec10db$1@newsgroups.borland.com> <45ec6a71@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,149a673c2d92f69f
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: <45ec10db$1@newsgroups.borland.com> <45ec6a71@newsgroups.borland.com>
Subject: Re: Shbrowseforfolder edit box problems
Date: Mon, 5 Mar 2007 10:40:30 -0800
Lines: 70
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: <45ec71a5$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1173123493 75.83.34.171 (5 Mar 2007 11:38:13 -0800)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail