window subclassing另类运用(之二)
你大概已经熟悉通用对话框(打开/保存文件,选择字体/颜色,以及查找和替换)的使用,不过你是否了解如何调用“选择文件夹”对话框呢?如果答案是否的话,你可以先看看一个简单的例子,籍以做个热身。如果你自认为已经了解它的话,可以跳过下面这一段。
要调用“选择文件夹”对话框,和其他通用对话框所使用的方法非常类似:一个结构(browseinfo)加一个函数(shbrowseforfolder)即可。请看代码:
procedure tform1.button2click(sender: tobject);
var
bi : browseinfo;
szdisplay : array[0..max_path] of char;
pidl : pitemidlist;
str : string;
begin
with bi do begin
hwndowner := handle;
pidlroot := nil;
pszdisplayname := szdisplay;
lpsztitle := 'select a directory';
ulflags := bif_returnonlyfsdirs or bif_statustext;
lpfn := @browsecallback;
lparam := 0;
end;
pidl := shbrowseforfolder(bi);
if pidl<>nil then begin
setlength(str, max_path);