Mercurial > dwindows
comparison win/XBrowseForFolder.cpp @ 1362:412af8059331
Attempt to get it building with Mingw again... builds but crashes.
Fix building DLL without HTML widget support... Mingw is missing required headers.
Moved wrapper functions into the main source file so it will export the APIs even if unsupported.
Removed debugging code from XBrowseForFolder.cpp because Mingw does not support it.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 18 Nov 2011 18:56:40 +0000 |
parents | bf3a6d596cd4 |
children | f8d1da63fb77 |
comparison
equal
deleted
inserted
replaced
1361:324812debcc9 | 1362:412af8059331 |
---|---|
27 // I accept no liability for any damage or loss of business that this | 27 // I accept no liability for any damage or loss of business that this |
28 // software may cause. | 28 // software may cause. |
29 // | 29 // |
30 /////////////////////////////////////////////////////////////////////////////// | 30 /////////////////////////////////////////////////////////////////////////////// |
31 | 31 |
32 // if you don't want to use MFC, comment out the following line: | 32 /* Make sure we get the right version */ |
33 //#include "stdafx.h" | 33 #define _WIN32_IE 0x0500 |
34 | 34 |
35 #ifndef __AFX_H__ | 35 #ifndef __AFX_H__ |
36 #include "windows.h" | 36 #include "windows.h" |
37 #include "crtdbg.h" | |
38 #include "tchar.h" | 37 #include "tchar.h" |
39 #endif | 38 #endif |
40 | 39 |
41 #include "Shlobj.h" | 40 #include "Shlobj.h" |
42 #include "io.h" | 41 #include "io.h" |
43 #include "XBrowseForFolder.h" | 42 #include "XBrowseForFolder.h" |
44 | 43 |
44 #ifndef __MINGW32__ | |
45 #pragma warning(disable: 4127) // conditional expression is constant (_ASSERTE) | 45 #pragma warning(disable: 4127) // conditional expression is constant (_ASSERTE) |
46 #pragma warning(disable : 4996) // disable bogus deprecation warning | 46 #pragma warning(disable : 4996) // disable bogus deprecation warning |
47 | |
48 #ifndef __noop | |
49 #if _MSC_VER < 1300 | |
50 #define __noop ((void)0) | |
51 #endif | 47 #endif |
48 | |
49 /* MingW does not have this */ | |
50 #if !defined(BIF_NONEWFOLDERBUTTON) | |
51 # define BIF_NONEWFOLDERBUTTON 0x200 | |
52 #endif | 52 #endif |
53 | |
54 #undef TRACE | |
55 #define TRACE __noop | |
56 | |
57 //============================================================================= | |
58 // if you want to see the TRACE output, uncomment this line: | |
59 //#include "XTrace.h" | |
60 //============================================================================= | |
61 | 53 |
62 //============================================================================= | 54 //============================================================================= |
63 // struct to pass to callback function | 55 // struct to pass to callback function |
64 //============================================================================= | 56 //============================================================================= |
65 struct FOLDER_PROPS | 57 struct FOLDER_PROPS |
97 | 89 |
98 /////////////////////////////////////////////////////////////////////////////// | 90 /////////////////////////////////////////////////////////////////////////////// |
99 // ScreenToClientX - helper function in case non-MFC | 91 // ScreenToClientX - helper function in case non-MFC |
100 static void ScreenToClientX(HWND hWnd, LPRECT lpRect) | 92 static void ScreenToClientX(HWND hWnd, LPRECT lpRect) |
101 { | 93 { |
102 _ASSERTE(::IsWindow(hWnd)); | |
103 ::ScreenToClient(hWnd, (LPPOINT)lpRect); | 94 ::ScreenToClient(hWnd, (LPPOINT)lpRect); |
104 ::ScreenToClient(hWnd, ((LPPOINT)lpRect)+1); | 95 ::ScreenToClient(hWnd, ((LPPOINT)lpRect)+1); |
105 } | 96 } |
106 | 97 |
107 /////////////////////////////////////////////////////////////////////////////// | 98 /////////////////////////////////////////////////////////////////////////////// |
108 // MoveWindowX - helper function in case non-MFC | 99 // MoveWindowX - helper function in case non-MFC |
109 static void MoveWindowX(HWND hWnd, CRect& rect, BOOL bRepaint) | 100 static void MoveWindowX(HWND hWnd, CRect& rect, BOOL bRepaint) |
110 { | 101 { |
111 _ASSERTE(::IsWindow(hWnd)); | |
112 ::MoveWindow(hWnd, rect.left, rect.top, | 102 ::MoveWindow(hWnd, rect.left, rect.top, |
113 rect.Width(), rect.Height(), bRepaint); | 103 rect.Width(), rect.Height(), bRepaint); |
114 } | 104 } |
115 | 105 |
116 /////////////////////////////////////////////////////////////////////////////// | 106 /////////////////////////////////////////////////////////////////////////////// |
117 // SizeBrowseDialog - resize dialog, move controls | 107 // SizeBrowseDialog - resize dialog, move controls |
118 static void SizeBrowseDialog(HWND hWnd, FOLDER_PROPS *fp) | 108 static void SizeBrowseDialog(HWND hWnd, FOLDER_PROPS *fp) |
119 { | 109 { |
120 TRACE(_T("in void SizeBrowseDialog\n")); | |
121 | |
122 // find the folder tree and make dialog larger | 110 // find the folder tree and make dialog larger |
123 HWND hwndTree = FindWindowEx(hWnd, NULL, _T("SysTreeView32"), NULL); | 111 HWND hwndTree = FindWindowEx(hWnd, NULL, _T("SysTreeView32"), NULL); |
124 | 112 |
125 if (!hwndTree) | 113 if (!hwndTree) |
126 { | 114 { |
127 // ... this usually means that BIF_NEWDIALOGSTYLE is enabled. | 115 // ... this usually means that BIF_NEWDIALOGSTYLE is enabled. |
128 // Then the class name is as used in the code below. | 116 // Then the class name is as used in the code below. |
129 hwndTree = FindWindowEx(hWnd, NULL, _T("SHBrowseForFolder ShellNameSpace Control"), NULL); | 117 hwndTree = FindWindowEx(hWnd, NULL, _T("SHBrowseForFolder ShellNameSpace Control"), NULL); |
130 TRACE(_T("SHBrowseForFolder ShellNameSpace Control: hwndTree=%X\n"), hwndTree); | |
131 } | 118 } |
132 | 119 |
133 CRect rectDlg; | 120 CRect rectDlg; |
134 | |
135 _ASSERTE(IsWindow(hwndTree)); | |
136 | 121 |
137 if (hwndTree) | 122 if (hwndTree) |
138 { | 123 { |
139 // check if edit box | 124 // check if edit box |
140 int nEditHeight = 0; | 125 int nEditHeight = 0; |
141 HWND hwndEdit = FindWindowEx(hWnd, NULL, _T("Edit"), NULL); | 126 HWND hwndEdit = FindWindowEx(hWnd, NULL, _T("Edit"), NULL); |
142 TRACE(_T("hwndEdit=%x\n"), hwndEdit); | |
143 CRect rectEdit; | 127 CRect rectEdit; |
144 if (hwndEdit && (fp->ulFlags & BIF_EDITBOX)) | 128 if (hwndEdit && (fp->ulFlags & BIF_EDITBOX)) |
145 { | 129 { |
146 ::GetWindowRect(hwndEdit, &rectEdit); | 130 ::GetWindowRect(hwndEdit, &rectEdit); |
147 ScreenToClientX(hWnd, &rectEdit); | 131 ScreenToClientX(hWnd, &rectEdit); |
183 rectCancel.top = rectCancel.bottom - h; | 167 rectCancel.top = rectCancel.bottom - h; |
184 rectCancel.right = rectDlg.right - hMargin; //(scrollWidth + 2*borderWidth); | 168 rectCancel.right = rectDlg.right - hMargin; //(scrollWidth + 2*borderWidth); |
185 rectCancel.left = rectCancel.right - w; | 169 rectCancel.left = rectCancel.right - w; |
186 if (hwndCancel) | 170 if (hwndCancel) |
187 { | 171 { |
188 //TRACERECT(rectCancel); | |
189 MoveWindowX(hwndCancel, rectCancel, FALSE); | 172 MoveWindowX(hwndCancel, rectCancel, FALSE); |
190 } | 173 } |
191 | 174 |
192 // move the OK button | 175 // move the OK button |
193 CRect rectOK(0, 0, 0, 0); | 176 CRect rectOK(0, 0, 0, 0); |
222 rectTree.top = vMargin; | 205 rectTree.top = vMargin; |
223 } | 206 } |
224 rectTree.left = hMargin; | 207 rectTree.left = hMargin; |
225 rectTree.bottom = rectOK.top - 10;//nMargin; | 208 rectTree.bottom = rectOK.top - 10;//nMargin; |
226 rectTree.right = rectDlg.right - hMargin; | 209 rectTree.right = rectDlg.right - hMargin; |
227 //TRACERECT(rectTree); | |
228 MoveWindowX(hwndTree, rectTree, FALSE); | 210 MoveWindowX(hwndTree, rectTree, FALSE); |
229 } | |
230 else | |
231 { | |
232 TRACE(_T("ERROR - tree control not found.\n")); | |
233 //_ASSERTE(hwndTree); | |
234 } | 211 } |
235 } | 212 } |
236 | 213 |
237 /////////////////////////////////////////////////////////////////////////////// | 214 /////////////////////////////////////////////////////////////////////////////// |
238 // BrowseCallbackProc - SHBrowseForFolder callback function | 215 // BrowseCallbackProc - SHBrowseForFolder callback function |
245 { | 222 { |
246 switch (uMsg) | 223 switch (uMsg) |
247 { | 224 { |
248 case BFFM_INITIALIZED: // sent when the browse dialog box has finished initializing. | 225 case BFFM_INITIALIZED: // sent when the browse dialog box has finished initializing. |
249 { | 226 { |
250 TRACE(_T("hWnd=%X\n"), hWnd); | |
251 | |
252 // remove context help button from dialog caption | 227 // remove context help button from dialog caption |
253 LONG lStyle = ::GetWindowLong(hWnd, GWL_STYLE); | 228 LONG lStyle = ::GetWindowLong(hWnd, GWL_STYLE); |
254 lStyle &= ~DS_CONTEXTHELP; | 229 lStyle &= ~DS_CONTEXTHELP; |
255 ::SetWindowLong(hWnd, GWL_STYLE, lStyle); | 230 ::SetWindowLong(hWnd, GWL_STYLE, lStyle); |
256 lStyle = ::GetWindowLong(hWnd, GWL_EXSTYLE); | 231 lStyle = ::GetWindowLong(hWnd, GWL_EXSTYLE); |
293 else | 268 else |
294 { | 269 { |
295 SHFILEINFO sfi; | 270 SHFILEINFO sfi; |
296 ::SHGetFileInfo((LPCTSTR)lParam, 0, &sfi, sizeof(sfi), | 271 ::SHGetFileInfo((LPCTSTR)lParam, 0, &sfi, sizeof(sfi), |
297 SHGFI_PIDL | SHGFI_ATTRIBUTES); | 272 SHGFI_PIDL | SHGFI_ATTRIBUTES); |
298 TRACE(_T("dwAttributes=0x%08X\n"), sfi.dwAttributes); | |
299 | 273 |
300 // fail if pidl is a link | 274 // fail if pidl is a link |
301 if (sfi.dwAttributes & SFGAO_LINK) | 275 if (sfi.dwAttributes & SFGAO_LINK) |
302 { | 276 { |
303 TRACE(_T("SFGAO_LINK\n")); | |
304 bRet = FALSE; | 277 bRet = FALSE; |
305 } | 278 } |
306 } | 279 } |
307 } | 280 } |
308 | 281 |
309 // if invalid selection, disable the OK button | 282 // if invalid selection, disable the OK button |
310 if (!bRet) | 283 if (!bRet) |
311 { | 284 { |
312 ::EnableWindow(GetDlgItem(hWnd, IDOK), FALSE); | 285 ::EnableWindow(GetDlgItem(hWnd, IDOK), FALSE); |
313 } | 286 } |
314 | |
315 TRACE(_T("szDir=%s\n"), szDir); | |
316 } | 287 } |
317 break; | 288 break; |
318 } | 289 } |
319 | 290 |
320 return 0; | 291 return 0; |
349 LPCTSTR lpszCaption, | 320 LPCTSTR lpszCaption, |
350 LPTSTR lpszBuf, | 321 LPTSTR lpszBuf, |
351 DWORD dwBufSize, | 322 DWORD dwBufSize, |
352 BOOL bEditBox /*= FALSE*/) | 323 BOOL bEditBox /*= FALSE*/) |
353 { | 324 { |
354 _ASSERTE(lpszBuf); | |
355 _ASSERTE(dwBufSize >= MAX_PATH); | |
356 | |
357 if (lpszBuf == NULL || dwBufSize < MAX_PATH) | 325 if (lpszBuf == NULL || dwBufSize < MAX_PATH) |
358 return FALSE; | 326 return FALSE; |
359 | 327 |
360 ZeroMemory(lpszBuf, dwBufSize*sizeof(TCHAR)); | 328 ZeroMemory(lpszBuf, dwBufSize*sizeof(TCHAR)); |
361 | 329 |
375 // is this a folder path string or a csidl? | 343 // is this a folder path string or a csidl? |
376 if (HIWORD(lpszInitialFolder) == 0) | 344 if (HIWORD(lpszInitialFolder) == 0) |
377 { | 345 { |
378 // csidl | 346 // csidl |
379 int nFolder = LOWORD((UINT)(UINT_PTR)lpszInitialFolder); | 347 int nFolder = LOWORD((UINT)(UINT_PTR)lpszInitialFolder); |
380 TRACE(_T("csidl: nFolder=0x%X\n"), nFolder); | |
381 SHGetSpecialFolderPath(hWnd, szInitialPath, nFolder, FALSE); | 348 SHGetSpecialFolderPath(hWnd, szInitialPath, nFolder, FALSE); |
382 } | 349 } |
383 else | 350 else |
384 { | 351 { |
385 // string | 352 // string |
386 _tcsncpy(szInitialPath, lpszInitialFolder, | 353 _tcsncpy(szInitialPath, lpszInitialFolder, |
387 sizeof(szInitialPath)/sizeof(TCHAR)-2); | 354 sizeof(szInitialPath)/sizeof(TCHAR)-2); |
388 } | 355 } |
389 TRACE(_T("szInitialPath=<%s>\n"), szInitialPath); | |
390 } | 356 } |
391 | 357 |
392 if ((szInitialPath[0] == _T('\0')) && (bi.pidlRoot == NULL)) | 358 if ((szInitialPath[0] == _T('\0')) && (bi.pidlRoot == NULL)) |
393 { | 359 { |
394 // no initial folder and no root, set to current directory | 360 // no initial folder and no root, set to current directory |
422 if (SHGetPathFromIDList(pidlFolder, szBuffer)) | 388 if (SHGetPathFromIDList(pidlFolder, szBuffer)) |
423 { | 389 { |
424 _tcsncpy(lpszBuf, szBuffer, dwBufSize-1); | 390 _tcsncpy(lpszBuf, szBuffer, dwBufSize-1); |
425 bRet = TRUE; | 391 bRet = TRUE; |
426 } | 392 } |
427 else | |
428 { | |
429 TRACE(_T("SHGetPathFromIDList failed\n")); | |
430 } | |
431 } | 393 } |
432 | 394 |
433 // free up pidls | 395 // free up pidls |
434 IMalloc *pMalloc = NULL; | 396 IMalloc *pMalloc = NULL; |
435 if (SUCCEEDED(SHGetMalloc(&pMalloc)) && pMalloc) | 397 if (SUCCEEDED(SHGetMalloc(&pMalloc)) && pMalloc) |