本人想实现一个功能,点击一个按钮后马上弹出来一个目录浏览的对话框,可以选择一个路径,(比如点击browse按钮,选择c:\program files目录)好像有一个函数,但是想不起来了,呵呵。

解决方案 »

  1.   

    SelectDirectory()
    SelectDirectory()
      

  2.   

    呵呵,我这个可以用啊
    function SelectDir(ParentHWnd: HWnd; const Caption: string; const Root: WideString; out Directory: string): Boolean;
    var
     BrowseInfo: TBrowseInfo;
     Buffer: PChar;
     RootItemIDList, ItemIDList: PItemIDList;
     ShellMalloc: IMalloc;
     IDesktopFolder: IShellFolder;
     //slFolder    :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
         SHGetDesktopFolder(IDesktopFolder);
         //SHGetDesktopFolder( slFolder );     IDesktopFolder.ParseDisplayName(Application.Handle, nil,
           POleStr(Root), Eaten, RootItemIDList, Flags);
         with BrowseInfo do
         begin
           hwndOwner := ParentHWnd;
           pidlRoot := RootItemIDList;
           pszDisplayName := Buffer;
           lpszTitle := PChar(Caption);
           ulFlags := BIF_RETURNONLYFSDIRS;
         end;
         ItemIDList := ShBrowseForFolder(BrowseInfo);
         Result :=  ItemIDList <> nil;
         if Result then
         begin
           ShGetPathFromIDList(ItemIDList, Buffer);
           ShellMalloc.Free(ItemIDList);
           Directory := Buffer;
         end;
       finally
         ShellMalloc.Free(Buffer);
       end;
     end;
    end;