133 int DoModal(LPCTSTR lpszDirectory, LPCTSTR lpszTitle, UINT uFlag = 0, HWND hWnd = NULL)
136 LPMALLOC lpMalloc = NULL;
137 HRESULT hr = ::SHGetMalloc(&lpMalloc);
143 LPTSTR lpBuffer =
static_cast<LPTSTR
>(lpMalloc->Alloc(MAX_PATH));
144 if ( lpBuffer == NULL )
149 HRESULT hCom = ::CoInitialize(NULL);
151 BROWSEINFO bi = { 0 };
154 bi.pszDisplayName = lpBuffer;
155 bi.lpszTitle = lpszTitle;
157 bi.lpfn = ms_BrowseCallbackProc;
159 param.lpszDefaultDir = lpszDirectory;
160 param.piListener = m_piListener;
161 bi.lParam =
reinterpret_cast<LPARAM
>(¶m);
163 LPITEMIDLIST pidlBrowse = ::SHBrowseForFolder(&bi);
164 if ( pidlBrowse != NULL )
167 if ( ::SHGetPathFromIDList(pidlBrowse, lpBuffer) )
170 _tcscpy(m_path, lpBuffer);
174 lpMalloc->Free(pidlBrowse);
177 lpMalloc->Free(lpBuffer);
187 IListener* m_piListener;
188 TCHAR m_path[MAX_PATH];
192 LPCTSTR lpszDefaultDir;
193 IListener* piListener;
202 static int CALLBACK ms_BrowseCallbackProc(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
204 const TParam* P =
reinterpret_cast<const TParam*
>(lpData);
205 if ( uMsg == BFFM_INITIALIZED )
207 ::SendMessage(hWnd, BFFM_SETSELECTION, TRUE,
reinterpret_cast<LPARAM
>(P->lpszDefaultDir));
208 if ( P->piListener != NULL )
210 P->piListener->OnDirectorySelectDlgInitialized(hWnd);
211 bool r = P->piListener->OnDirectorySelectDlgSelectChanged(hWnd, P->lpszDefaultDir);
212 ::SendMessage(hWnd, BFFM_ENABLEOK, 0, r);
215 else if ( uMsg == BFFM_SELCHANGED )
217 if ( P->piListener != NULL )
219 TCHAR path[MAX_PATH];
221 if ( ::SHGetPathFromIDList(
reinterpret_cast<LPCITEMIDLIST
>(lParam), path) )
223 ::SendMessage(hWnd, BFFM_SETSTATUSTEXT, 0,
reinterpret_cast<LPARAM
>(path));
224 r = P->piListener->OnDirectorySelectDlgSelectChanged(hWnd, path);
226 ::SendMessage(hWnd, BFFM_ENABLEOK, 0, r);
229 else if( uMsg == BFFM_VALIDATEFAILED )
CDirectorySelectDlg(void)
コンストラクタ
LPCTSTR GetSelectedPath(void) const
[取得] 選択パス取得.
void SetListener(IListener *I)
[設定] リスナー設定.
int DoModal(LPCTSTR lpszDirectory, LPCTSTR lpszTitle, UINT uFlag=0, HWND hWnd=NULL)
[実行] 選択画面表示.
virtual void OnDirectorySelectDlgInitialized(HWND hWnd)=0
[通知] ダイアログ初期化通知.
virtual ~IListener(void)
デストラクタ
virtual bool OnDirectorySelectDlgSelectChanged(HWND hWnd, LPCTSTR lpszPath) const =0
[通知] 選択変更通知.