-
Notifications
You must be signed in to change notification settings - Fork 29
/
AlsFolderBrowser.cpp
106 lines (78 loc) · 1.88 KB
/
AlsFolderBrowser.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
Free Download Manager Copyright (c) 2003-2016 FreeDownloadManager.ORG
*/
#include "StdAfx.h"
#include "AlsFolderBrowser.h"
#include <tchar.h>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
AlsFolderBrowser::AlsFolderBrowser()
{
}
AlsFolderBrowser::~AlsFolderBrowser()
{
}
LPCTSTR AlsFolderBrowser::GetPath()
{
return m_pszFullPath;
}
INT CALLBACK AlsFolderBrowser::_BrowserCallback(HWND hWnd, UINT uMsg, LPARAM lp, LPARAM lpData)
{
switch (uMsg)
{
case BFFM_INITIALIZED:
if (lpData)
SendMessage (hWnd, BFFM_SETSELECTION, TRUE, lpData);
break;
case BFFM_SELCHANGED:
break;
}
return 0;
}
BOOL AlsFolderBrowser::Create(LPCTSTR pszTitle, LPCTSTR pszPath, LPCTSTR pszRoot, HWND hWndParent)
{
LPMALLOC pMalloc;
BOOL bResult = FALSE;
if (SHGetMalloc (&pMalloc) != NOERROR)
return FALSE;
BROWSEINFO bi;
ZeroMemory (&bi, sizeof (bi));
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_EDITBOX | BIF_VALIDATE | 0x40;
bi.hwndOwner = hWndParent;
bi.lpszTitle = pszTitle;
bi.lpfn = _BrowserCallback;
bi.lParam = (LPARAM) pszPath;
if (pszRoot != NULL)
{
IShellFolder *pFolder;
if (SHGetDesktopFolder (&pFolder) == NOERROR)
{
LPITEMIDLIST pIdl = NULL;
ULONG chEaten;
ULONG dwAttributes;
wchar_t str [MAX_PATH];
#ifdef UNICODE
wcscpy(str, pszRoot);
#else
mbtowc (str, pszRoot, _tcslen (pszRoot));
#endif
pFolder->ParseDisplayName (NULL, NULL, str, &chEaten, &pIdl, &dwAttributes);
pFolder->Release ();
bi.pidlRoot = pIdl;
}
}
LPITEMIDLIST pIdl = SHBrowseForFolder (&bi);
if (pIdl != NULL)
{
if (SHGetPathFromIDList (pIdl, m_pszFullPath))
bResult = TRUE;
pMalloc->Free (pIdl);
}
if (bi.pidlRoot)
pMalloc->Free ((void*)bi.pidlRoot);
pMalloc->Release ();
return bResult;
}