🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: SHBrowseForFolder

#9796
From: Gary Setter
Date: Tue, 08 Jun 2004 13:11
60 lines
2692 bytes
"Hans Galema" <dontusethis@dontusethis.nl> wrote in message
news:40c5a181$1@newsgroups.borland.com...
> JD wrote:
>
> > It'a all sorted. One needs to use the callback to set the
> > initial directory.
>
> You are the first one here, who succeeds setting the initial
> directory, as far as I know. Compliments.
>
> Now are you willing to post a complete example ?
>
> I would put it in my code then and put big comments
> around it that state that you did it. <g>
>
> Hans.

FWIW, this is what I use

#include <shlobj.h> //SHBrowseForFolder

// Callback for the BrowseForFolder, which purpose is to set the initial
folder
int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM /*lParam*/,
LPARAM lpData)
{
 switch (uMsg) {
    case BFFM_INITIALIZED:
      ::SendMessage(hwnd, BFFM_SETSELECTION, (WPARAM)TRUE, lpData);
      break;
  }

  return 0;
}

void MyClass::CmBrowseForFolder()
{
 std::auto_ptr<char> dir(new char[_MAX_PATH]);
 GetCurrentDirectory(MAX_PATH,dir.get());
 BROWSEINFO info;
 memset(&info,0,sizeof(info));
 info.hwndOwner = GetHandle();
 info.lpszTitle = "Select the source directory";
 info.lpfn = BrowseCallbackProc;
 info.lParam = (LPARAM)dir.get();
   //info.ulFlags = BIF_NEWDIALOGSTYLE;
 LPITEMIDLIST items = SHBrowseForFolder(&info);
   if (items) {
  if (SHGetPathFromIDList(items, dir.get()))
   SetDlgItemText(IDC_DIR,dir.get());
      LPMALLOC ppMalloc;
      HRESULT result = SHGetMalloc(&ppMalloc);
      if (SUCCEEDED(result) && ppMalloc) {
       ppMalloc->Free(items);
      }
   }
}

I'm not sure about how I free memory. Suggestions would be wellcome.
Technical Details
Message-ID: <40c5bb67@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!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: "Gary Setter" <setterg@worldnet.att.net>
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 08:11:48 -0500
Lines: 61
MIME-Version: 1.0
Content-Type: text/plain;
 charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
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: 12.74.20.54
Message-ID: <40c5bb67@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1086700391 12.74.20.54 (8 Jun 2004 06:13:11 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail