浏览文件夹的对话框怎么写。(50分)

  • 主题发起人 主题发起人 server
  • 开始时间 开始时间
S

server

Unregistered / Unconfirmed
GUEST, unregistred user!
&nbsp;浏览文件夹的对话框怎么写。<br>就象windows中查找文件框中点<br>击浏览后出现的对话框。
 
uses shlobj;<br>中ShBrowseForFolder
 
首先在你的Form上放一个OpenDialog 控件OpenDialog1<br>&nbsp; 然后:OpenDialog1.execute 即可.<br>
 
&nbsp;尊敬的hubdog:<br>请问具体怎么调用,请写个简单的例子给我行吗?<br>
 
uses shlobj,activex;<br>procedure TForm1.Button2Click(Sender: TObject);<br>var<br>&nbsp; &nbsp; BrowseInfo: TBrowseInfo;<br>&nbsp; &nbsp; &nbsp; ShellMalloc: IMalloc;<br>&nbsp;RootIDList,ItemIDList: PItemIDList;<br>begin<br>&nbsp; FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);<br>&nbsp; if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc &lt;&gt; nil) then<br>&nbsp; &nbsp; SHGetSpecialFolderLocation(Application.Handle,CSIDL_FONTS , RootIDList);//起始是字体目录,可改成CSIDL_DESKTOP等其他<br>&nbsp; with BrowseInfo do<br>&nbsp; begin<br>&nbsp; &nbsp; hwndOwner := Application.Handle;<br>&nbsp; &nbsp; pidlRoot := RootIDList;//can be nil<br>&nbsp; &nbsp; pszDisplayName := '浏览';<br>&nbsp; &nbsp; lpszTitle := '浏览';<br>&nbsp; &nbsp; ulFlags := BIF_BROWSEFORCOMPUTER;<br>&nbsp; &nbsp; lpfn:=nil;<br>&nbsp; &nbsp; lparam:=0;<br>&nbsp; end;<br>&nbsp; ItemIDList := ShBrowseForFolder(BrowseInfo);<br>&nbsp; ShellMalloc.Free(RootIDList);<br>end;
 
&nbsp;不懂怎样判断用户按了确定还是取消,<br>在对话框返回时得到选定的路径怎样获取.<br>
 
procedure TForm1.Button2Click(Sender: TObject);<br>var<br>&nbsp;BrowseInfo: TBrowseInfo;<br>&nbsp;ShellMalloc: IMalloc;<br>&nbsp;RootIDList,ItemIDList: PItemIDList;<br>&nbsp;SelectBuffer:array [0..Max_Path] of char;//PChar;<br>&nbsp;Directory,displayname:string; <br>begin<br>&nbsp; FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);<br>&nbsp; if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc &lt;&gt; nil) then<br>&nbsp; &nbsp; SHGetSpecialFolderLocation(Application.Handle,CSIDL_FONTS , RootIDList);//起始是字体目录,可改成CSIDL_DESKTOP等其他<br>&nbsp; with BrowseInfo do<br>&nbsp; begin<br>&nbsp; &nbsp; hwndOwner := Application.Handle;<br>&nbsp; &nbsp; pidlRoot := RootIDList;//can be nil<br>&nbsp; &nbsp; pszDisplayName := '浏览';<br>&nbsp; &nbsp; lpszTitle := '浏览';<br>&nbsp; &nbsp; ulFlags := BIF_BROWSEFORCOMPUTER;<br>&nbsp; &nbsp; lpfn:=nil;<br>&nbsp; &nbsp; lparam:=0;<br>&nbsp; end;<br>&nbsp; ItemIDList := ShBrowseForFolder(BrowseInfo);<br>&nbsp; if ItemIDList &lt;&gt; nil then<br>&nbsp; begin<br>&nbsp; &nbsp; ShGetPathFromIDList(ItemIDList, SelectBuffer);<br>&nbsp; &nbsp; ShellMalloc.Free(ItemIDList);<br>&nbsp; &nbsp; Directory := String(SelectBuffer);//选的目录名<br>&nbsp; &nbsp; DisplayName:=string(BrowseInfo.pszDisplayName);<br>&nbsp; end;<br>&nbsp; ShellMalloc.Free(RootIDList);<br>end;
 
好麻烦,<br>如果是选择目录呢,<br>uses FileCtrl;<br>function SelectDirectory(var Directory: string; Options: TSelectDirOpts; HelpCtx: Longint): Boolean; overload;<br>如果是选择文件呢,就用FileOpenDialog好了
 
蚯蚓说的对.<br>这个问题已经讨论多次了!
 
&nbsp;hubdog:<br>&nbsp; &nbsp; 我所有的问题中这个问题得到了最快最好的回答.<br>&nbsp; 真是感激不尽!!<br>&nbsp;
 
K! 不可理喻!
 
dialog里有的
 
题外话,选择目录的时候,怎么让他出现<br>Window95模式的选择Dialog?而不是用<br>Drive,Directory和File三个选择框组合而<br>成的那种?
 
hubdog做的很好呀,delphi自带的那个对话框太土了,感觉是回到了<br>win32的年代,难道hubdog的做法有不妥么?
 
hubdog应该注意一下自己的笔误.<br>
 
接受答案了.
 
hubdog的代码实现结果和delphi自己的函数SelectDirectory效果一样!<br>你们大概不会用SelectDirectory函数吧? 看看它的帮助,有两种用法!
 
&lt;p style={font-size:20pt}&gt;<br>我不服!!!!!!!!<br>&lt;/p&gt;<br>&lt;p style={font-size:10pt}&gt;<br>SelectDirectory函数是overload的,我不过Copy错了而已。。。。<br><br>Win95系统的那个如下:<br><br>源代码:<br>unit FileCtrl;<br>...<br>function SelectDirectory(const Caption: string; const Root: WideString;<br>&nbsp; out Directory: string): Boolean;<br>var<br>&nbsp; WindowList: Pointer;<br>&nbsp; BrowseInfo: TBrowseInfo;<br>&nbsp; Buffer: PChar;<br>&nbsp; RootItemIDList, ItemIDList: PItemIDList;<br>&nbsp; ShellMalloc: IMalloc;<br>&nbsp; IDesktopFolder: IShellFolder;<br>&nbsp; Eaten, Flags: LongWord;<br>begin<br>&nbsp; Result := False;<br>&nbsp; Directory := '';<br>&nbsp; FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);<br>&nbsp; if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc &lt;&gt; nil) then<br>&nbsp; begin<br>&nbsp; &nbsp; Buffer := ShellMalloc.Alloc(MAX_PATH);<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; RootItemIDList := nil;<br>&nbsp; &nbsp; &nbsp; if Root &lt;&gt; '' then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; SHGetDesktopFolder(IDesktopFolder);<br>&nbsp; &nbsp; &nbsp; &nbsp; IDesktopFolder.ParseDisplayName(Application.Handle, nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; POleStr(Root), Eaten, RootItemIDList, Flags);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; with BrowseInfo do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; hwndOwner := Application.Handle;<br>&nbsp; &nbsp; &nbsp; &nbsp; pidlRoot := RootItemIDList;<br>&nbsp; &nbsp; &nbsp; &nbsp; pszDisplayName := Buffer;<br>&nbsp; &nbsp; &nbsp; &nbsp; lpszTitle := PChar(Caption);<br>&nbsp; &nbsp; &nbsp; &nbsp; ulFlags := BIF_RETURNONLYFSDIRS;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; WindowList := DisableTaskWindows(0);<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; ItemIDList := ShBrowseForFolder(BrowseInfo);<br>&nbsp; &nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; &nbsp; EnableTaskWindows(WindowList);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; Result := &nbsp;ItemIDList &lt;&gt; nil;<br>&nbsp; &nbsp; &nbsp; if Result then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ShGetPathFromIDList(ItemIDList, Buffer);<br>&nbsp; &nbsp; &nbsp; &nbsp; ShellMalloc.Free(ItemIDList);<br>&nbsp; &nbsp; &nbsp; &nbsp; Directory := Buffer;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; ShellMalloc.Free(Buffer);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>你自己说,哪个是"最快最好的回答"!!!!!!!!<br>&lt;/p&gt;<br>
 
后退
顶部