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 计算农历的单元

Delphi在目录中搜索文件

Delphi tparallel并行性能测试

Delphi 数据集转换json对象

Delphi idhttp组件+idhttpserver组件实现文件下载服务

Delphi tms web core messagedlg对话框 yes no

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



打赏

取消

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

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

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

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

评论

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