Delphi本身的那个不能让其位于屏幕中间,可以使用下面的,其实就是调用API来实现具体功能。<br>句柄使用Form的,可以使其显示在所有者中心。能够返回所选择的目录,以及添加的目录,但是功能似乎还不太完善。<br><br>uses shlobj;<br><br>function SelectDirectory1(handle: hwnd; const Caption: string; const Root: WideString; out Directory: string): Boolean;<br>var<br> lpbi: _browseinfo;<br> buf: array[0..MAX_PATH] of char;<br> id: ishellfolder;<br> eaten, att: cardinal;<br> rt: pitemidlist;<br> initdir: pwidechar;<br>begin<br> result := false;<br> lpbi.hwndOwner := handle;<br> lpbi.lpfn := nil;<br> lpbi.lpszTitle := pchar(caption);<br> lpbi.ulFlags := BIF_RETURNONLYFSDIRS + 16;<br> SHGetDesktopFolder(id);<br> initdir := pwchar(root);<br> id.ParseDisplayName(0, nil, initdir, eaten, rt, att);<br> lpbi.pidlRoot := rt;<br> getmem(lpbi.pszDisplayName, MAX_PATH);<br> try<br> result := shgetpathfromidlist(shbrowseforfolder(lpbi), buf);<br> except<br> freemem(lpbi.pszDisplayName);<br> end;<br> if result then directory := buf;<br>end;<br><br>-----------------------------------------------------------------------------------------<br>据说可以设置初始目录,没有具体实验<br>function SelectDirectory(const Caption: string; const Root: WideString;<br> var 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> if not DirectoryExists(Directory) then<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;<br> if Directory <> '' then<br> begin<br>// lpfn := SelectDirCB;<br> lParam := Integer(PChar(Directory));<br> end;<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>