uses ShlObj;
function SelectFolderDialog(const Handle: integer; const Caption: string;
const InitFolder: WideString; var SelectedFolder: string): boolean;
var
BInfo: _browseinfo;
Buffer: array[0..MAX_PATH] of Char;
ID: IShellFolder;
Eaten, Attribute: Cardinal;
ItemID: PItemidlist;
begin
Result := False;
BInfo.HwndOwner := Handle;
BInfo.lpfn := nil;
BInfo.lpszTitle := Pchar(Caption);
BInfo.ulFlags := BIF_RETURNONLYFSDIRS + BIF_NEWDIALOGSTYLE;
SHGetDesktopFolder(ID);
ID.ParseDisplayName(0, nil, PWideChar(InitFolder), Eaten, ItemID, Attribute);
BInfo.pidlRoot := ItemID;
GetMem(BInfo.pszDisplayName, MAX_PATH);
try
if SHGetPathFromIDList(SHBrowseForFolder(BInfo), Buffer) then
begin
SelectedFolder := Buffer;
if Length(SelectedFolder) <> 3 then
SelectedFolder := SelectedFolder + '\';
result := True;
end
else
begin
SelectedFolder := '';
Result := False;
end;
finally
FreeMem(BInfo.pszDisplayName);
end;
end;
procedure TFrmMain.EdtDirPathButtonClick(Sender: TObject);
var
NewDir: string;
begin
if SelectFolderDialog(Handle, '选择', '', NewDir) then
EdtDirPath.Text := NewDir;
end;
Delphi 选择文件夹对话框 (有新建文件夹按钮)修正版
最新推荐文章于 2022-03-01 17:55:43 发布
本文介绍了一个使用Delphi实现的文件夹选择对话框功能。该对话框允许用户从桌面环境中选择文件夹,并返回所选文件夹的路径。通过调用Windows API函数和shell对象,实现了初始化文件夹的选择、新对话框样式等功能。
1万+

被折叠的 条评论
为什么被折叠?



