-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathUntUtils.pas
65 lines (47 loc) · 1.64 KB
/
UntUtils.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{
JPL : @DarkCoderSc
}
unit UntUtils;
interface
uses Windows, ShlObj;
function BrowseForFolder(const ADialogTitle : String; const AInitialFolder : String = ''; ACanCreateFolder: Boolean = False) : String;
implementation
{-------------------------------------------------------------------------------
Show native Windows Dialog to select an existing folder.
-------------------------------------------------------------------------------}
function BrowseForFolderCallBack(hwnd : HWND; uMsg: UINT; lParam, lpData: LPARAM): Integer stdcall;
begin
if (uMsg = BFFM_INITIALIZED) then begin
SendMessage(hwnd, BFFM_SETSELECTION, 1, lpData);
end;
///
result := 0;
end;
function BrowseForFolder(const ADialogTitle : String; const AInitialFolder : String = ''; ACanCreateFolder: Boolean = False) : String;
var ABrowseInfo : TBrowseInfo;
AFolder : array[0..MAX_PATH-1] of Char;
pItem : PItemIDList;
begin
ZeroMemory(@ABrowseInfo, SizeOf(TBrowseInfo));
///
ABrowseInfo.pszDisplayName := @AFolder[0];
ABrowseInfo.lpszTitle := PChar(ADialogTitle);
ABrowseInfo.ulFlags := BIF_RETURNONLYFSDIRS or BIF_NEWDIALOGSTYLE;
if NOT ACanCreateFolder then
ABrowseInfo.ulFlags := ABrowseInfo.ulFlags or BIF_NONEWFOLDERBUTTON;
ABrowseInfo.hwndOwner := 0;
if AInitialFolder <> '' then begin
ABrowseInfo.lpfn := BrowseForFolderCallBack;
ABrowseInfo.lParam := NativeUInt(@AInitialFolder[1]);
end;
pItem := SHBrowseForFolder(ABrowseInfo);
if Assigned(pItem) then begin
if SHGetPathFromIDList(pItem, AFolder) then
result := AFolder
else
result := '';
GlobalFreePtr(pItem);
end else
result := '';
end;
end.