delphi如何调用window的folderBrowserDialog函数
delphi如何调用window的folderBrowserDialog函数,选择文件目录. 问题点数:20、回复次数:2Top
1 楼Kshape(C/C++初学者~~~~)回复于 2005-04-03 22:30:18 得分 20
给个C#的代码吧
System.Windows.Forms.FolderBrowserDialog dlg = new FolderBrowserDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(dlg.SelectedPath);
}Top
2 楼cnhgj(戏子) (没时间练太极)回复于 2005-04-03 23:00:33 得分 0
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants,shlobj, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function SelectDirectory(handle:hwnd;const Caption: string; const Root: WideString;out Directory: string): Boolean;
var
lpbi:_browseinfo;
buf:array [0..MAX_PATH] of char;
id:ishellfolder;
eaten,att:cardinal;
rt:pitemidlist;
initdir:pwidechar;
begin
result:=false;
lpbi.hwndOwner:=handle;
lpbi.lpfn:=nil;
lpbi.lpszTitle:=pchar(caption);
lpbi.ulFlags:=BIF_RETURNONLYFSDIRS+BIF_EDITBOX;
SHGetDesktopFolder(id);
initdir:=pwchar(root);
id.ParseDisplayName(0,nil,initdir,eaten,rt,att);
lpbi.pidlRoot:=rt;
getmem(lpbi.pszDisplayName,MAX_PATH);
try
result:=shgetpathfromidlist(shbrowseforfolder(lpbi),buf);
except
freemem(lpbi.pszDisplayName);
end;
if result then
begin
directory:=buf;
if length(directory)<>3 then directory:=directory+'\';
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var dir:string;
begin
if selectdirectory(handle,'请选择文件夹','',dir) then showmessage(dir);
end;
end.
Top




