大漠孤烟

导航

打开文件夹对话框

 1 function SelectFolderDialog(const Handle: integer; const Caption: string;const InitFolder: WideString; var SelectedFolder: string): boolean;
 2 var
 3   BInfo: _browseinfo;
 4   Buffer: array[0..MAX_PATH] of Char;
 5   ID: IShellFolder;
 6   Eaten, Attribute: Cardinal;
 7   ItemID: PItemidlist;
 8 begin
 9   Result := False;
10   BInfo.HwndOwner := Handle;
11   BInfo.lpfn := nil;
12   BInfo.lpszTitle := Pchar(Caption);
13   BInfo.ulFlags := BIF_RETURNONLYFSDIRS + BIF_NEWDIALOGSTYLE;
14   SHGetDesktopFolder(ID);
15   ID.ParseDisplayName(0, nil, PWideChar(InitFolder), Eaten, ItemID, Attribute);
16   BInfo.pidlRoot := ItemID;
17   GetMem(BInfo.pszDisplayName, MAX_PATH);
18   try
19     if SHGetPathFromIDList(SHBrowseForFolder(BInfo), Buffer) then
20     begin
21       SelectedFolder := Buffer;
22       if Length(SelectedFolder) <> 3 then
23       SelectedFolder := SelectedFolder + '\';
24       result := True;
25     end
26     else
27     begin
28       SelectedFolder := '';
29       Result := False;
30     end;
31   finally
32    FreeMem(BInfo.pszDisplayName);
33   end;
34 end;

 

posted on 2012-07-15 14:54  jnmcok  阅读(106)  评论(0编辑  收藏  举报