这样子:<br> <br>function BrowseCallbackProc(Handle: HWND;<br> uMsg: UINT; lParam: Cardinal;<br> lpData: Cardinal): integer; stdcall;<br>var<br> dirbuf: array[0..Max_Path-1] of Char;<br>begin<br> Result := 0;<br> if uMsg = BFFM_INITIALIZED then<br> begin<br> if GetCurrentDirectory(Max_path,@dirbuf) > 0 then<br> // WParam is TRUE since you are passing a path.<br> // It would be FALSE if you were passing a pidl.<br> SendMessage(Handle,BFFM_SETSELECTION,1,LongInt(@Dirbuf));<br> end<br> else if uMsg = BFFM_SELCHANGED then<br> begin<br><br> // Set the status window to the currently selected path.<br> if SHGetPathFromIDList(PItemIDList(lParam) ,@Dirbuf) then<br> SendMessage(Handle,BFFM_SETSTATUSTEXT,0,LongInt(@Dirbuf));<br> end;<br>end;<br><br>function SelectDirectoryEx(const Caption: string; const Root: WideString;<br> out Directory: string): Boolean;<br>var<br> WindowList: Pointer;<br> BrowseInfo: TBrowseInfo;<br> Buffer: PChar;<br> RootItemIDList, ItemIDList: PItemIDList;<br> ShellMalloc: IMalloc;<br> IDesktopFolder: IShellFolder;<br> Eaten, Flags: LongWord;<br>begin<br> Result := False;<br> Directory := '';<br> FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);<br> if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc <> nil) then<br> begin<br> Buffer := ShellMalloc.Alloc(MAX_PATH);<br> try<br> RootItemIDList := nil;<br> if Root <> '' then<br> begin<br> SHGetDesktopFolder(IDesktopFolder);<br> IDesktopFolder.ParseDisplayName(Application.Handle, nil,<br> POleStr(Root), Eaten, RootItemIDList, Flags);<br> end;<br> with BrowseInfo do<br> begin<br> hwndOwner := Application.Handle;<br> pidlRoot := RootItemIDList;<br> pszDisplayName := Buffer;<br> lpszTitle := PChar(Caption);<br> ulFlags := BIF_RETURNONLYFSDIRS or BIF_STATUSTEXT;//包含 BIF_STATUSTEXT<br> lpfn := @BrowseCallbackProc; //回调函数<br> end;<br> WindowList := DisableTaskWindows(0);<br> try<br> ItemIDList := ShBrowseForFolder(BrowseInfo);<br> finally<br> EnableTaskWindows(WindowList);<br> end;<br> Result := ItemIDList <> nil;<br> if Result then<br> begin<br> ShGetPathFromIDList(ItemIDList, Buffer);<br> ShellMalloc.Free(ItemIDList);<br> Directory := Buffer;<br> end;<br> finally<br> ShellMalloc.Free(Buffer);<br> end;<br> end;<br>end;<br><br>SelectDirectoryEx 这个函数主要是从 FileCtrl.pas 中拷过来的,只作了些修改。其它<br>的参考了 MSDN。运行测试过了。