From: "John Scalco" Newsgroups: borland.public.delphi.winapi References: <3bb22d66$1_1@dnews> Subject: Re: SHBrowseForFolder - set initial dir ? Date: Wed, 26 Sep 2001 21:50:01 -0400 Lines: 84 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 65.80.148.27 Message-ID: <3bb284ec$1_1@dnews> X-Trace: dnews 1001555180 65.80.148.27 (26 Sep 2001 18:46:20 -0700) Path: dnews Xref: dnews borland.public.delphi.winapi:147686 "Chris Bandy" wrote in message news:3bb22d66$1_1@dnews... > wrote in message news:3b8fb8ae$1_2@dnews... > > > > I want to select a folder using SHBrowseForFolder. > > To select an initial dir I send the > > BFFM_SETSELECTION message to the window, which works > > fine for normal directories > > I've looked through ShlObj.pas but am still having trouble understanding. > How does one send this message to the window? > - Chris, Yeh, this is a little tricky.. at least IMHO. What you need to do is set up a call back... it's not that hard. Check out the code in the ShlObj.pas Search for TBrowseInfo. TBrowseInfo is a record with the following fields: TBrowserInfo = record hwndOwner: HWND; pidlRoot: PItemIDList; pszDisplayName: PAnsiChar; { Return display name of item selected. } lpszTitle: PAnsiChar; { text to go in the banner over the tree. } ulFlags: UINT; { Flags that control the return stuff } lpfn: TFNBFFCallBack; lParam: LPARAM; { extra info that's passed back in callbacks } iImage: Integer; { output var: where to return the Image index. } end; the lpfn field is where you plug in your call back. To do this you need to create a function, which matches the TFNBFFCallbacks prototype. Here is the prototype: BFFCALLBACK = function(Wnd: HWND; uMsg: UINT; lParam, lpData: LPARAM): Integer stdcall; TFNBFFCallBack = type BFFCALLBACK; So, you create a function in your unit function MyBffCallback (Wnd: HWND; uMsg:UINT; lParam, lpData: LPARAM): Integer; stdcall; begin // in here you can send the message ... but you want to handle another Window message like if uMsg = bffm_initialized then begin SendMessage (hwnd, bffm_setselection, ..... ); end; result := 0; end; In your TBrowseInfo you need to 'hook them up' something like var br: TBrowseInfo; begin br.lpfn := MyBffCallBack; .. // other inits SHBrowseForFolder (br); end; Something like that. I hope this gets you heading in the right direction. Sincerely, John Scalco