Delphi 选择文件夹对话框 (有新建文件夹按钮)修正版


本文整理自网络,侵删。

 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 类的声明

Delphi实现文件的拖放功能

Delphi 数据异或校验

Delphi strlenwide 汇编统计字符串长度

Delphi tlistview按指定列排序

Delphi 根据邮箱地址分离出@前的内容

Delphi 过滤字符串首位特殊符号

Delphi injectmemexe

Delphi 根据进程id获取程序ico图标

Delphi 不管什么datetime日期格式时间格式转换都不会错了

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...