我的问题已经搞定,想学习的进来看。(0分)

  • 主题发起人 主题发起人 阿魁
  • 开始时间 开始时间

阿魁

Unregistered / Unconfirmed
GUEST, unregistred user!
原始问题:http://www.delphibbs.com/delphibbs/dispq.asp?lid=665455<br><br>我查了fileCtrl.pas的源代码,找到了他使用的api:SHBrowseForFolder,我想要的就是他!<br><br>我的程序如下:<br>[purple]var<br>&nbsp; pid : PItemIDList;<br>&nbsp; bi : TBrowseInfo;<br>&nbsp; savepath : string;<br>begin<br>&nbsp; setLength(savepath,255);<br>&nbsp; FillChar(bi,sizeof(bi),0);<br>&nbsp; bi.hwndOwner := self.Handle;<br>&nbsp; bi.pidlRoot := nil;<br>&nbsp; bi.pszDisplayName := pchar(savepath); //??????<br>&nbsp; bi.lpszTitle := '选择自动抓取的图像的存放路径:';<br>&nbsp; bi.ulFlags := BIF_RETURNONLYFSDIRS;<br>&nbsp; pid := SHBrowseForFolder(bi);<br>&nbsp; if pid&lt;&gt;nil then<br>&nbsp; begin<br>&nbsp; &nbsp; SHGetPathFromIDList(pid,pchar(savepath));<br>&nbsp; &nbsp; setLength(savepath,strlen(pchar(savepath)));<br>&nbsp; &nbsp; edtSavePath.Text := savepath;<br>&nbsp; end;<br>end;[/purple]<br>==============================================================<br>但还有几个问题:<br>1.我不知如何设置初始目录;<br>2.我不知道 bi.pszDisplayName := pchar(savepath); &nbsp;这一句目的何在。如果不加的话,会出现莫名其妙的问题;<br>3.FillChar(bi,sizeof(bi),0); 这一句有为什么呢?<br><br>题外话:看来大富翁里熟悉 WIN32 SDK的还是太少了。<br>
 
you must use ShlObj unit.
 
uses ShellAPI, ShlObj; <br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; procedure TForm1.Button1Click(Sender: TObject); <br>&nbsp; &nbsp; var <br>&nbsp; &nbsp; &nbsp;TitleName : string; <br>&nbsp; &nbsp; &nbsp;lpItemID : PItemIDList; <br>&nbsp; &nbsp; &nbsp;BrowseInfo : TBrowseInfo; <br>&nbsp; &nbsp; &nbsp;DisplayName : array[0..MAX_PATH] of char; <br>&nbsp; &nbsp; &nbsp;TempPath : array[0..MAX_PATH] of char; <br>&nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp;FillChar(BrowseInfo, sizeof(TBrowseInfo), #0); <br>&nbsp; &nbsp; &nbsp;BrowseInfo.hwndOwner := Form1.Handle; <br>&nbsp; &nbsp; &nbsp;BrowseInfo.pszDisplayName := @DisplayName; <br>&nbsp; &nbsp; &nbsp;TitleName := 'Please specify a directory'; <br>&nbsp; &nbsp; &nbsp;BrowseInfo.lpszTitle := PChar(TitleName); <br>&nbsp; &nbsp; &nbsp;BrowseInfo.ulFlags := BIF_RETURNONLYFSDIRS; <br>&nbsp; &nbsp; &nbsp;lpItemID := SHBrowseForFolder(BrowseInfo); <br>&nbsp; &nbsp; &nbsp;if lpItemId &lt;&gt; nil then begin <br>&nbsp; &nbsp; &nbsp;SHGetPathFromIDList(lpItemID, TempPath); <br>&nbsp; &nbsp; &nbsp;ShowMessage(TempPath); <br>&nbsp; &nbsp; &nbsp;GlobalFreePtr(lpItemID); <br>&nbsp; &nbsp; &nbsp;end; <br>&nbsp; &nbsp; end; <br>
 
to yunzone:<br>谢谢!你的例程更详细了。<br><br>但是,我的那三点疑问不但没得到解决,反而又多了一条:<br>GlobalFreePtr(lpItemID); 这一句是必需的么?不然会发生内存泄漏么?<br><br>请你帮人帮到底,麻烦解释一下吧,谢了!<br>等我有分了,一定重重感谢!
 
xi,到http://eagleboost.myrice.com/issues/Materials/Articles/SelDir.htm<br>来看,早有答案了
 
搞不懂,微软为何不把设置初始路径放在参数里 [:(]
 

Similar threads

A
回复
5
查看
139
awfigsk
A
W
回复
5
查看
207
weisunding
W
回复
20
查看
362
龙石佛
后退
顶部