source: trunk/Library/ACLShellUtilityUnit.pas@ 25

Last change on this file since 25 was 17, checked in by RBRi, 19 years ago

+ Library

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1unit ACLShellUtilityUnit;
2
3interface
4
5// Win32 only
6
7uses
8 Forms;
9
10// Retrieves the "My Documents" folder
11function GetPersonalFolder: string;
12
13// Encapsulates Windows shell folder browser.
14// Unlike the Delphi SelectDirectory function, this
15// takes an owner form so that you cannot select the
16// owner form!
17function BrowseForFolder( const Owner: TForm;
18 const Caption: string;
19 const Root: WideString;
20 out Directory: string): Boolean;
21
22// Launch explorer for the specified directory
23procedure Explore( Directory: string;
24 TreeView: boolean = true );
25
26implementation
27
28uses
29 ShlObj, ActiveX, Windows,
30 Dialogs,
31 ACLFileUtility, ACLUtility;
32
33function GetPersonalFolder: string;
34var
35 pIDList: PItemIDList;
36 Path: array[ 0..MAX_PATH ] of char;
37begin
38 SHGetSpecialFolderLocation( HWND_DESKTOP,
39 CSIDL_PERSONAL,
40 pIDList );
41 SHGetPathFromIDList( pIDList, path );
42 Result := path;
43end;
44
45function BrowseForFolder( const Owner: TForm;
46 const Caption: string;
47 const Root: WideString;
48 out Directory: string): Boolean;
49var
50 BrowseInfo: TBrowseInfo;
51 Buffer: PChar;
52 RootItemIDList, ItemIDList: PItemIDList;
53 ShellMalloc: IMalloc;
54 IDesktopFolder: IShellFolder;
55 Eaten, Flags: LongWord;
56begin
57 Result := False;
58 Directory := '';
59 FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);
60 if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc <> nil) then
61 begin
62 Buffer := ShellMalloc.Alloc(MAX_PATH);
63 try
64 SHGetDesktopFolder(IDesktopFolder);
65 IDesktopFolder.ParseDisplayName(Application.Handle, nil,
66 POleStr(Root), Eaten, RootItemIDList, Flags);
67 with BrowseInfo do
68 begin
69 hwndOwner := Owner.Handle;
70 pidlRoot := RootItemIDList;
71 pszDisplayName := Buffer;
72 lpszTitle := PChar(Caption);
73 ulFlags := BIF_RETURNONLYFSDIRS;
74 end;
75 ItemIDList := ShBrowseForFolder(BrowseInfo);
76 Result := ItemIDList <> nil;
77 if Result then
78 begin
79 ShGetPathFromIDList(ItemIDList, Buffer);
80 ShellMalloc.Free(ItemIDList);
81 Directory := Buffer;
82 end;
83 finally
84 ShellMalloc.Free(Buffer);
85 end;
86 end;
87end;
88
89procedure Explore( Directory: string;
90 TreeView: boolean );
91var
92 Parameters: string;
93begin
94 if TreeView then
95 Parameters := '/e,' + Directory
96 else
97 Parameters := Directory;
98
99 if not RunProgram( 'Explorer',
100 Parameters ) then
101 begin
102 ShowMessage( 'Could not run Windows Explorer: '
103 + GetLastAPIErrorString );
104 end;
105end;
106
107end.
Note: See TracBrowser for help on using the repository browser.