-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFolderBrowser.pas
60 lines (51 loc) · 1.67 KB
/
FolderBrowser.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
unit FolderBrowser;
interface
uses Windows, SysUtils, ShlObj;
function GetFolderDialog(Handle: integer; Caption: string; var strFolder: string): boolean;
implementation
function BrowseCallbackProc(hwnd: HWND; uMsg: UINT; lParam: LPARAM; lpData: LPARAM): integer; stdcall;
begin
if (uMsg = BFFM_INITIALIZED) then
SendMessage(hwnd, BFFM_SETSELECTION, 1, lpData);
BrowseCallbackProc:= 0;
end;
function GetFolderDialog(Handle: integer; Caption: string; var strFolder: string): boolean;
const
BIF_STATUSTEXT = $0004;
BIF_EDITBOX = $0010;
BIF_NEWDIALOGSTYLE = $0040;
BIF_RETURNONLYFSDIRS = $0080;
BIF_SHAREABLE = $0100;
BIF_NONEWFOLDERBUTTON = $0200;
BIF_USENEWUI = BIF_EDITBOX or BIF_NEWDIALOGSTYLE;
var
BrowseInfo: TBrowseInfo;
ItemIDList: PItemIDList;
JtemIDList: PItemIDList;
Path: PAnsiChar;
begin
result:= False;
Path:= StrAlloc(MAX_PATH);
SHGetSpecialFolderLocation(Handle, CSIDL_DRIVES, JtemIDList);
with BrowseInfo do
begin
hwndOwner:= GetActiveWindow;
pidlRoot:= JtemIDList;
SHGetSpecialFolderLocation(hwndOwner, CSIDL_DRIVES, JtemIDList);
pszDisplayName:= StrAlloc(MAX_PATH);
lpszTitle:= pchar(Caption);
lpfn:= @BrowseCallbackProc;
lParam:= LongInt(pchar(strFolder));
ulflags :=
BIF_STATUSTEXT or BIF_NEWDIALOGSTYLE or BIF_RETURNONLYFSDIRS or
BIF_SHAREABLE or BIF_NONEWFOLDERBUTTON;
end;
ItemIDList:= SHBrowseForFolder(BrowseInfo);
if (ItemIDList <> nil) then
if SHGetPathFromIDList(ItemIDList, Path) then
begin
strFolder:= Path;
result:= True;
end;
end;
end.