Message-ID: <3ACF1F38.F8DEC45B@hotmael.com> Date: Sat, 07 Apr 2001 16:07:52 +0200 From: -The Delphi Expert- <"-The Delphi Expert-"@hotmael.com> X-Mailer: Mozilla 4.73 [en] (Win95; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: borland.public.delphi.winapi Subject: Re: How to browse for a Folder? References: <3ace3b45$1_2@dnews> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 213.17.86.136 X-Trace: dnews 986652263 213.17.86.136 (7 Apr 2001 07:04:23 -0700) Lines: 68 Path: dnews Xref: dnews borland.public.delphi.winapi:129135 > I got to thinking that there may be an API call that I could > make that would give me access to this Windows dialog directly. Just put this function in your code: function SelectDirectory(const Caption: string; const Root: WideString; out Directory: string): Boolean; var WindowList: Pointer; BrowseInfo: TBrowseInfo; Buffer: PChar; RootItemIDList, ItemIDList: PItemIDList; ShellMalloc: IMalloc; IDesktopFolder: IShellFolder; Eaten, Flags: LongWord; begin Result := False; Directory := ''; FillChar(BrowseInfo, SizeOf(BrowseInfo), 0); if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc <> nil) then begin Buffer := ShellMalloc.Alloc(MAX_PATH); try RootItemIDList := nil; if Root <> '' then begin SHGetDesktopFolder(IDesktopFolder); IDesktopFolder.ParseDisplayName(Application.Handle, nil, POleStr(Root), Eaten, RootItemIDList, Flags); end; with BrowseInfo do begin hwndOwner := Application.Handle; pidlRoot := RootItemIDList; pszDisplayName := Buffer; lpszTitle := PChar(Caption); ulFlags := BIF_RETURNONLYFSDIRS; end; WindowList := DisableTaskWindows(0); try ItemIDList := ShBrowseForFolder(BrowseInfo); finally EnableTaskWindows(WindowList); end; Result := ItemIDList <> nil; if Result then begin ShGetPathFromIDList(ItemIDList, Buffer); ShellMalloc.Free(ItemIDList); Directory := Buffer; end; finally ShellMalloc.Free(Buffer); end; end; end; ------------- example: var OutputDirectory: string; begin SelectDirectory('Caption','',OutputDirectory); ShowMessage(OutputDirectory); end;