关于打开文件对话框(35分)

  • 主题发起人 主题发起人 linuxcrow
  • 开始时间 开始时间
L

linuxcrow

Unregistered / Unconfirmed
GUEST, unregistred user!
请问如何调出一个如winamp中的那样的打开文件对话筐?(就是单击add dir后出来的)<br>只能打开到目录的那一种。
 
你设置对话框的打开类型不就得了?!在它的属性filter里设置
 
在Filer的属性中过滤一下
 
SelectDirectory不就是选目录的.
 
是不是这样:<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; aPath: string;<br>begin<br>&nbsp; aPath := '';<br>&nbsp; if SelectDirectory('选择路径:', '', aPath) then<br>&nbsp; &nbsp; Edti1.Text := AddDirSuffix(aPath);<br>end;
 
把分给我吧[:)]<br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls , CommDlg; //一定要加上 CommDlg<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; &nbsp;ofn: TOpenFileName; // CommDlg must be in uses clause !<br>&nbsp; &nbsp;szFile: array[0..MAX_PATH] of Char;<br>&nbsp; &nbsp;Result: string;<br>begin<br>&nbsp; FillChar(ofn, SizeOf(TOpenFileName), 0);<br>&nbsp; with ofn do<br>&nbsp; begin<br>&nbsp; &nbsp; lStructSize := SizeOf(TOpenFileName);<br>&nbsp; &nbsp; hwndOwner := Handle;<br>&nbsp; &nbsp; lpstrFile := szFile;<br>&nbsp; &nbsp; nMaxFile := SizeOf(szFile);<br>&nbsp; &nbsp; lpstrTitle := PChar('打开文件');<br>&nbsp; &nbsp; lpstrInitialDir := PChar('C:/');<br>&nbsp; &nbsp; lpstrFilter := PChar('所有文件 (*.*)'#0'*.*'#0);<br>&nbsp; &nbsp; Flags := 539140;<br>&nbsp; end;<br>&nbsp; if GetOpenFileName(ofn) then<br>&nbsp; &nbsp; Result := StrPas(ofn.lpstrFile);<br>end;<br><br>end.<br>
 
我的意思是打开一个和winamp打开歌曲目录的那样的对话框<br>就是那种打开目录对话框,一个树型结构显示目录,一选选一个目录<br>不是delphi的opendialog<br>那种打开文件对话框。
 
我这个不对吗? 再不行delphi6中本身就有这种控件.
 
这次满足你的要求了,<br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls, shlobj; //注意这里shlobj<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; &nbsp;lpbi: BROWSEINFO;<br>&nbsp; &nbsp;pidlStart: PItemIDList;<br>&nbsp; &nbsp;pszPath: array[0..MAX_PATH] of Char;<br>&nbsp; &nbsp;pidlResult: PItemIDList;<br>&nbsp; &nbsp;sResult: string;<br>begin<br>&nbsp; SHGetSpecialFolderLocation(Handle, 0, pidlStart);<br>&nbsp; with lpbi do<br>&nbsp; begin<br>&nbsp; &nbsp; hwndOwner := Handle;<br>&nbsp; &nbsp; pszDisplayName := pszPath;<br>&nbsp; &nbsp; lpszTitle := PChar('请选择路径:');<br>&nbsp; &nbsp; ulFlags := BIF_RETURNONLYFSDIRS;<br>&nbsp; &nbsp; pidlRoot := pidlStart;<br>&nbsp; &nbsp; lpfn := nil;<br>&nbsp; end;<br>&nbsp; pidlResult := SHBrowseForFolder(lpbi);<br>&nbsp; if SHGetPathFromIDList(pidlResult, pszPath) then<br>&nbsp; &nbsp; sResult := StrPas(pszPath);<br>end;<br><br>end.<br>
 
谢谢大家捧场!尤其是seaboy和HD_Copy兄,最后采用的是seaboy兄的方法,<br>因为够简单!AddDirSuffix这个API是做什么的忘告之。<br>小弟很菜刚学delphi大家多帮忙吧!!<br>谢谢先!!
 
sorry,AddDirSuffix是个自定义函数用于在取得的目录后加一 '/'字符.
 
后退
顶部