简单的可以用一个窗口加directorylist实现!

解决方案 »

  1.   

    { uses FileCtrl; }procedure TForm1.Button1Click(Sender: TObject);
    var
      vDirectory: string;
    begin
      if SelectDirectory('测试', '', vDirectory) then
        Caption := vDirectory;
    end;
      

  2.   

    我用过SelectDirectory,但是对话框关闭之后,我的应用程序会失去焦点.
      

  3.   

    我明白了,原来我引用的是QDialog,而非FileCtrl
      

  4.   

    但为什么编译时会出现提示:[Warning] OptionSet.pas(7): Unit 'FileCtrl' is specific to a platform
      

  5.   

    {$WARNINGS OFF}
    uses FileCtrl;
    {$WARNINGS ON}你不喜欢它就用
      

  6.   

    function SelectDirectory(const Caption: string; const Root: WideString; out Directory: string): Boolean; overload;
      

  7.   

    呵呵,伴水的选择目录框是Delphi自己带的,看我的这个:function SelectDirectory(const Caption: string; const Root: WideString;
      out Directory: string): Boolean;
    var //选择一个目录的函数
      WindowList: Pointer;
      BrowseInfo: TBrowseInfo;
      Buffer: PChar;
      RootItemIDList, ItemIDList: PItemIDList;
      ShellMalloc: IMalloc;
      IDesktopFolder: 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
          RootItemIDList := nil;
          if Root <> '' then
          begin
            SHGetDesktopFolder(IDesktopFolder);
            IDesktopFolder.ParseDisplayName(Application.Handle, nil,
              POleStr(Root), Eaten, RootItemIDList, Flags);
          end;
          with BrowseInfo do
          begin
            hwndOwner := Application.Handle;
            pidlRoot := RootItemIDList;
            pszDisplayName := Buffer;
            lpszTitle := PChar(Caption);
            ulFlags := BIF_RETURNONLYFSDIRS;
          end;
          WindowList := DisableTaskWindows(0);
          try
            ItemIDList := ShBrowseForFolder(BrowseInfo);
          finally
            EnableTaskWindows(WindowList);
          end;
          Result := ItemIDList <> nil;
          if Result then
          begin
            ShGetPathFromIDList(ItemIDList, Buffer);
            ShellMalloc.Free(ItemIDList);
            Directory := Buffer;
          end;
        finally
          ShellMalloc.Free(Buffer);
        end;
      end;
    end;嘻嘻嘻嘻嘻嘻嘻嘻嘻
    嘻嘻嘻怎么样嘻嘻嘻
    嘻嘻嘻嘻嘻嘻嘻嘻嘻
      

  8.   

    呵呵,伴水的选择目录框是Delphi自己带的,看我的这个:function SelectDirectory(const Caption: string; const Root: WideString;
      out Directory: string): Boolean;
    var //选择一个目录的函数
      WindowList: Pointer;
      BrowseInfo: TBrowseInfo;
      Buffer: PChar;
      RootItemIDList, ItemIDList: PItemIDList;
      ShellMalloc: IMalloc;
      IDesktopFolder: 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
          RootItemIDList := nil;
          if Root <> '' then
          begin
            SHGetDesktopFolder(IDesktopFolder);
            IDesktopFolder.ParseDisplayName(Application.Handle, nil,
              POleStr(Root), Eaten, RootItemIDList, Flags);
          end;
          with BrowseInfo do
          begin
            hwndOwner := Application.Handle;
            pidlRoot := RootItemIDList;
            pszDisplayName := Buffer;
            lpszTitle := PChar(Caption);
            ulFlags := BIF_RETURNONLYFSDIRS;
          end;
          WindowList := DisableTaskWindows(0);
          try
            ItemIDList := ShBrowseForFolder(BrowseInfo);
          finally
            EnableTaskWindows(WindowList);
          end;
          Result := ItemIDList <> nil;
          if Result then
          begin
            ShGetPathFromIDList(ItemIDList, Buffer);
            ShellMalloc.Free(ItemIDList);
            Directory := Buffer;
          end;
        finally
          ShellMalloc.Free(Buffer);
        end;
      end;
    end;嘻嘻嘻嘻嘻嘻嘻嘻嘻
    嘻嘻嘻怎么样嘻嘻嘻
    嘻嘻嘻嘻嘻嘻嘻嘻嘻
      

  9.   

    伴水调用的是Delphi自己的目录选择框,看我这个:function SelectDirectory(const Caption: string; const Root: WideString;
      out Directory: string): Boolean;
    var //选择一个目录的函数
      WindowList: Pointer;
      BrowseInfo: TBrowseInfo;
      Buffer: PChar;
      RootItemIDList, ItemIDList: PItemIDList;
      ShellMalloc: IMalloc;
      IDesktopFolder: 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
          RootItemIDList := nil;
          if Root <> '' then
          begin
            SHGetDesktopFolder(IDesktopFolder);
            IDesktopFolder.ParseDisplayName(Application.Handle, nil,
              POleStr(Root), Eaten, RootItemIDList, Flags);
          end;
          with BrowseInfo do
          begin
            hwndOwner := Application.Handle;
            pidlRoot := RootItemIDList;
            pszDisplayName := Buffer;
            lpszTitle := PChar(Caption);
            ulFlags := BIF_RETURNONLYFSDIRS;
          end;
          WindowList := DisableTaskWindows(0);
          try
            ItemIDList := ShBrowseForFolder(BrowseInfo);
          finally
            EnableTaskWindows(WindowList);
          end;
          Result := ItemIDList <> nil;
          if Result then
          begin
            ShGetPathFromIDList(ItemIDList, Buffer);
            ShellMalloc.Free(ItemIDList);
            Directory := Buffer;
          end;
        finally
          ShellMalloc.Free(Buffer);
        end;
      end;
    end;