opendialog savedialog 这些控件可以选择文件,怎么选文件夹呀
谢谢!焦急等待中

解决方案 »

  1.   

    uses 
      shlobj,ActiveX; 
      var
       Form1: TForm1; 
       Path: string;   //起始路径implementation {$R *.DFM} function BrowseCallbackProc(hwnd: HWND;uMsg: UINT;lParam: Cardinal;lpData: Cardinal): integer; stdcall; 
    begin 
      if uMsg=BFFM_INITIALIZED then 
        result :=SendMessage(Hwnd,BFFM_SETSELECTION,Ord(TRUE),Longint(PChar(Path))) 
      else 
        result :=1 
    end; function SelDir(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; 
            lpfn :=@BrowseCallbackProc; 
            lParam :=BFFM_INITIALIZED; 
          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; procedure TForm1.SpeedButton1Click(Sender: TObject); 
    var 
      Path1: string; 
    begin 
      Path :=Edit1.Text; 
      SelDir('SelectDirectory Sample','d:\temp',Path1); 
      Edit1.Text :=Path1 
    end; 
      

  2.   

    直接用SelectDirectory函数不就的了,有这样的控件,但SelectDirectory函数功能和他一样啊
      

  3.   

    >>有没有控件可以选择文件夹? 
    控件面板 win3.1 下的
    DirectoryListBox1
      

  4.   

    rxlib  www.51delphi.com下载
      

  5.   

    ljmanage(过客) ( ) 信誉:113  2004-7-29 10:26:13  得分: 0   
       
    直接用SelectDirectory函数不就的了,有这样的控件,但SelectDirectory函数功能和他一样啊
    UnitFileCtrlCategorydialog and message routinesfunction SelectDirectory(const Caption: string; const Root: WideString; out Directory: string): Boolean; overload;
    function SelectDirectory(var Directory: string; Options: TSelectDirOpts; HelpCtx: Longint): Boolean; overload;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.
      

  6.   

    SelectDirectory ExampleThis example uses a button and a label on a form. When the user clicks the button, a Select Directory dialog box appears. The current directory displayed in the dialog box is C:\MYDIR. The user can select a directory from the directory list, or enter a new directory in the edit box. If the user enters a new directory, a message box asks the user if the directory should be created. If the user chooses Yes, the directory is created. If the user chooses No, the message box goes away without creating the directory. The name of the directory the user selects appears as the caption of the label:uses FileCtrl;const
      SELDIRHELP = 1000;
    procedure TForm1.Button1Click(Sender: TObject);
    var
      Dir: string;
    begin
      Dir := 'C:\MYDIR';
      if SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt],SELDIRHELP) then
        Label1.Caption := Dir;
    end;
      

  7.   

    用DirectoryListBox应该可以解决问题
      

  8.   

    SelectDirectory函数,有两种形式,建议用第二种
      

  9.   

    严重建议用,selectDirectory函数,简单又实用。
      

  10.   

    对,用 SelectDirectory,很方便。
      

  11.   

    SelectDirectory delphi封装好的
      

  12.   

    SelectDirectory就OK,需要这么麻烦?想强大就ShellControlPack的那个,很多功能的
      

  13.   

    找Sample面板,里面有,自己选