怎样限制OpenDialog只能选择文件夹

解决方案 »

  1.   

    不能。你用SelectDirectory
    这个函数但是这个函数表现不好,在极少数的电脑中会产生问题。有些电脑用了一些主题会导致这个函数异常,异常地部位是Screen取得屏幕分辨率的地方,他用了一个自写的Form对话框,所以需要取得屏幕分辨率来调整按扭位置。你有空自己改一下就好了。
      

  2.   

    procedure TdataSaveForm.SpeedButton1Click(Sender: TObject);
    var
     TitleName : string;
     lpItemID : PItemIDList;
     BrowseInfo : TBrowseInfo;
     DisplayName : array[0..MAX_PATH] of char;
     TempPath : array[0..MAX_PATH] of char;
    begin
     FillChar(BrowseInfo, sizeof(TBrowseInfo), #0);
     BrowseInfo.hwndOwner := datasaveform.Handle;
     BrowseInfo.pszDisplayName := @DisplayName;
     TitleName := '请选择目录';
     BrowseInfo.lpszTitle := PChar(TitleName);
     BrowseInfo.ulFlags := BIF_RETURNONLYFSDIRS;
     lpItemID := SHBrowseForFolder(BrowseInfo);
     if lpItemId <> nil then
     begin
     SHGetPathFromIDList(lpItemID, TempPath);
     edit1.Text:= TempPath;//选择的目录
     GlobalFreePtr(lpItemID);
     end;
    end;
      

  3.   

    SelectDirectoryBrings up a dialog to allow the user to enter a directory name.
     
    Namespace 
    Borland.Vcl.FileCtrl 
    Syntax function SelectDirectory(var Directory: string, Options: TSelectDirOpts, HelpCtx: Integer): Boolean;
     function SelectDirectory(const Caption: string, const Root: string, var Directory: string, Options: TSelectDirExtOpts): Boolean;
     Description 
    Call 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: Warning:You can’t 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.
      

  4.   

    向 happyggy 学习 能不能添加点注释?
      

  5.   

    delphi中有专门选择文件夹的控件,自己做个窗口就行了.