记得我们编程的时候,有许多时候需要用到打开一个窗口,来定位目录路径,windows系统中常有这样的操作,我以前是自己做一个from,然后自己在里面加各种控件来调用实现,也可以用delphi提供的dialog对话框来完成,
 我想问的是,我记得在以前看过一个winapi函数,直接提供一个窗口,供你选择目标目录;请教各位,那个函数是什么啊??  它调用后出现一个很简单的对话框式的窗体,一个目录树,然后是确定

解决方案 »

  1.   

    应该是这个(另一个是英文界面,平时也不会用的):extern PACKAGE bool __fastcall SelectDirectory(constAnsiString Caption, const WideString Root, AnsiString &Directory);DescriptionCall SelectDirectory to let the user enter a directory name. Use the first syntax to display the Windows directory browser. The Caption parameter specifies a caption for the dialog. The Root parameter specifies the root directory from which to browse. The selected directory is returned as the Directory parameter. When using this syntax, SelectDirectory does not change the value of the current directory.Warning: You can抰 use the same variable for the Root parameter and the Directory parameter.Use the second syntax to call the Select Directory dialog box. The directory passed to the function with the Directory parameter appears as the currently selected directory when the dialog box appears. The name of the directory the user selects becomes the value of Directory when the function returns.The HelpCtx parameter is the help context ID number.The Options parameter is a set of values. If Options is the empty set, the user can only select a directory that already exists. No edit box is provided for the user to enter a new directory name. If Options is not empty, the included values determine how the dialog responds when the user types a nonexistent directory name.With either syntax, SelectDirectory returns true if the user selected a directory and chose OK, and false if the user chose Cancel or closed the dialog box without selecting a directory.
      

  2.   

    先谢谢楼上那位,我们继续
    对于你刚刚说道的函数我试过了;
    代码如下
    procedure TForm1.Button1Click(Sender: TObject);
    var Dir:String;
    begin
       if SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt],SELDIRHELP) then
        Label1.Caption := Dir;end;出现的窗口是一个有着驱动器选择的COMBOBOX的控件,一个目录树,一个文件显示区及一个文件路径显示编辑框,类似于win31的那种界面, 呵呵;可我还是要找另外的,那个窗口类似于:当你在delphi中配置Environment Options 时,打开library配置页,打开目录浏览后,出现的那个窗口,很简单SelectDirectory不像那么复杂。
      哪位高手还有指教的??
      

  3.   

    function ShowSelectFolder(const Handle:THandle;const FilePosition:TFilePosition;const Title:string;var Path:string):Boolean;
    const
      nFolder:Array[TFilePosition]of Integer = (CSIDL_DRIVES,CSIDL_NETHOOD);
    var
      BrowseInfo    : TBrowseInfo;
      ItemIDList    : PItemIDList;
     // AFolder       : array[0..MAX_PATH-1] of char;
      APath         : array[0..MAX_PATH-1] of char;
    begin
      SHGetSpecialFolderLocation(Handle,nFolder[FilePosition], ItemIdList);
      FillChar(BrowseInfo,SizeOf(TBrowseInfo),0);
      with BrowseInfo do
      begin
        hwndOwner        := Handle;
        pidlRoot         := ItemIDList;
        pszDisplayName   := nil; 
        lpszTitle        := PChar(Title);
        ulFlags          := BIF_RETURNONLYFSDIRS;
      end;
      ItemIDList        := SHBrowseForFolder(BrowseInfo);
      Result             := Assigned(ItemIDList) and  SHGetPathFromIDList(ItemIDList,APath);
      Path               := APath;end;
      

  4.   

    uses
      ShlObj,Windows;
      

  5.   

    unsignedlong SHGetPathFromIDListA 'shell32'
    unsignedlong SHBrowseForFolderA 'shell32'
      

  6.   

    Pb用法:browseinfo lstr_bi
    itemidlist lstr_idl
    unsignedlong ll_pidl
    unsignedlong ll_r
    Integer li_pos
    String ls_Path
    unsignedlong ll_Null
    SetNull( ll_Null )
    lstr_bi.hOwner = Handle( awi_Parent )
    lstr_bi.pidlRoot = 0
    lstr_bi.lpszTitle = as_caption
    lstr_bi.ulFlags = bif_ReturnOnlyFSDirs
    lstr_bi.pszDisplayName = Space( 255 )
    lstr_bi.lpfn = ll_Null
    ll_pidl = SHBrowseForFolderA( lstr_bi )
    ls_Path = Space( 255 )
    ll_R = SHGetPathFromIDListA( ll_pidl, ls_Path )
    CoTaskMemFree( ll_pidl )
    RETURN ls_Path
      

  7.   


    编程中需要得到一个自选择的目录;一般是调用某个对方框窗口控件;或者自己做一个窗体来实现地址传递,但是,我记得微软提供了一个函数,可以直接出现一个选择目录窗口,界面很简单,就是一个目录树和两个确定取消按钮,这个窗口在windows中随处可以遇到,可我就是忘记这个函数是什么了;哪位大侠能告诉我???
    win2000中那目录浏览框中多了个新建目录的按钮;老的没有,不过肯定也是微软的一个函数,在网上邻居中点击右键选择映射一个网络驱动器,然后选择那个  【浏览(b)】按钮;出来的那个窗口就是
      

  8.   

    http://www.yesue.com/question/show.asp?id=787&catalog=Q_Program_General
      

  9.   

    K,就是那个SelectDirectory(),这个函数是Overload的,你注意使用第二个即可!uses filectrl先……
      

  10.   

    嗯;昨天晚上我已经找到了;就是selectDirectory();它有两种用法,可以得到那个框框,谢谢大家了
      

  11.   

    这个是WinAPI???有没有搞错