目录选择对话框

来源:互联网 发布:mysql数据库恢复命令 编辑:程序博客网 时间:2024/06/05 17:52

Delphi中可以使用三种方式创建目录选择对话框,其中两种在FileCtrl单元中。分别是:

function SelectDirectory(var Directory: string;

  Options:TselectDirOpts; HelpCtx: Longint): Boolean;

function SelectDirectory(const Caption: string;const Root: WideString;

  varDirectory: string): Boolean;

第一种是Win32模式的目录选择对话框,样式老旧。使用Delphi元件封装的类。

第二种是Win95模式目录选择对话框,但是没有新建文件夹按钮。这个函数是Delphi封装了Windows的组件。

另外一种是使用下面函数封装

Uses ShlObj

function SelectDirectoryDlg: string;

var

  Buffer:string;

  IdList:PItemIDList;

  Info:TbrowseInfo;

begin

  result :=‘’;

 SetLength(Buffer, Max_Path);

  with Infodo

  begin

    hwndOwner:= Application.Handle;

    pidlRoot:= nil;

   pszDisplayName := Pchar(Buffer);

    lpszTitle:= Pchar(sSelectDirectory);

    ulFlags:= BIF_RETURNONLYFSDIRS or BIF_NEWDIALOGSTYLE;

    lpfn :=nil;

    lParam :=0;

    iImage :=0;

  end;

  idList :=SHBrowseForFolder(Info);

  if idList<> nil then

  begin

   SHGetPathFromIDList(idList, Pchar(Buffer));

   SetLength(Buffer, StrLen(Pchar(Buffer)));

    result :=Buffer;

  end;

end;

这种方式和上面的第二种是相同的封装形式。关键点是ulFlag参数,可以详细查看ShlObj中的声明。

原创粉丝点击