comparison win/XBrowseForFolder.cpp @ 1617:f8d1da63fb77

Add code to allow building DW.DLL as Unicode on Windows. DWCOMPAT.DLL currently is still built ANSI for now. Will add -DUNICODE and -D_UNICODE to the flags when it is stable.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 27 Mar 2012 08:51:14 +0000
parents 412af8059331
children d39f4f9bed26
comparison
equal deleted inserted replaced
1616:bbef5d25efa0 1617:f8d1da63fb77
31 31
32 /* Make sure we get the right version */ 32 /* Make sure we get the right version */
33 #define _WIN32_IE 0x0500 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 "tchar.h" 37 #include <tchar.h>
38 #endif 38 #endif
39 39
40 #include "Shlobj.h" 40 #include <Shlobj.h>
41 #include "io.h" 41 #include <io.h>
42 #include "XBrowseForFolder.h" 42 #include "XBrowseForFolder.h"
43 43
44 #ifndef __MINGW32__ 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
106 /////////////////////////////////////////////////////////////////////////////// 106 ///////////////////////////////////////////////////////////////////////////////
107 // SizeBrowseDialog - resize dialog, move controls 107 // SizeBrowseDialog - resize dialog, move controls
108 static void SizeBrowseDialog(HWND hWnd, FOLDER_PROPS *fp) 108 static void SizeBrowseDialog(HWND hWnd, FOLDER_PROPS *fp)
109 { 109 {
110 // find the folder tree and make dialog larger 110 // find the folder tree and make dialog larger
111 HWND hwndTree = FindWindowEx(hWnd, NULL, _T("SysTreeView32"), NULL); 111 HWND hwndTree = FindWindowEx(hWnd, NULL, TEXT("SysTreeView32"), NULL);
112 112
113 if (!hwndTree) 113 if (!hwndTree)
114 { 114 {
115 // ... this usually means that BIF_NEWDIALOGSTYLE is enabled. 115 // ... this usually means that BIF_NEWDIALOGSTYLE is enabled.
116 // Then the class name is as used in the code below. 116 // Then the class name is as used in the code below.
117 hwndTree = FindWindowEx(hWnd, NULL, _T("SHBrowseForFolder ShellNameSpace Control"), NULL); 117 hwndTree = FindWindowEx(hWnd, NULL, TEXT("SHBrowseForFolder ShellNameSpace Control"), NULL);
118 } 118 }
119 119
120 CRect rectDlg; 120 CRect rectDlg;
121 121
122 if (hwndTree) 122 if (hwndTree)
123 { 123 {
124 // check if edit box 124 // check if edit box
125 int nEditHeight = 0; 125 int nEditHeight = 0;
126 HWND hwndEdit = FindWindowEx(hWnd, NULL, _T("Edit"), NULL); 126 HWND hwndEdit = FindWindowEx(hWnd, NULL, TEXT("Edit"), NULL);
127 CRect rectEdit; 127 CRect rectEdit;
128 if (hwndEdit && (fp->ulFlags & BIF_EDITBOX)) 128 if (hwndEdit && (fp->ulFlags & BIF_EDITBOX))
129 { 129 {
130 ::GetWindowRect(hwndEdit, &rectEdit); 130 ::GetWindowRect(hwndEdit, &rectEdit);
131 ScreenToClientX(hWnd, &rectEdit); 131 ScreenToClientX(hWnd, &rectEdit);
233 ::SetWindowLong(hWnd, GWL_EXSTYLE, lStyle); 233 ::SetWindowLong(hWnd, GWL_EXSTYLE, lStyle);
234 234
235 FOLDER_PROPS *fp = (FOLDER_PROPS *) lpData; 235 FOLDER_PROPS *fp = (FOLDER_PROPS *) lpData;
236 if (fp) 236 if (fp)
237 { 237 {
238 if (fp->lpszInitialFolder && (fp->lpszInitialFolder[0] != _T('\0'))) 238 if (fp->lpszInitialFolder && fp->lpszInitialFolder[0])
239 { 239 {
240 // set initial directory 240 // set initial directory
241 ::SendMessage(hWnd, BFFM_SETSELECTION, TRUE, (LPARAM)fp->lpszInitialFolder); 241 ::SendMessage(hWnd, BFFM_SETSELECTION, TRUE, (LPARAM)fp->lpszInitialFolder);
242 } 242 }
243 243
244 if (fp->lpszTitle && (fp->lpszTitle[0] != _T('\0'))) 244 if (fp->lpszTitle && fp->lpszTitle[0])
245 { 245 {
246 // set window caption 246 // set window caption
247 ::SetWindowText(hWnd, fp->lpszTitle); 247 ::SetWindowText(hWnd, fp->lpszTitle);
248 } 248 }
249 } 249 }
335 { 335 {
336 if (SUCCEEDED(SHGetSpecialFolderLocation(hWnd, nRootFolder, &pidlRoot))) 336 if (SUCCEEDED(SHGetSpecialFolderLocation(hWnd, nRootFolder, &pidlRoot)))
337 bi.pidlRoot = pidlRoot; 337 bi.pidlRoot = pidlRoot;
338 } 338 }
339 339
340 TCHAR szInitialPath[MAX_PATH*2] = { _T('\0') }; 340 TCHAR szInitialPath[MAX_PATH*2] = { 0 };
341 if (lpszInitialFolder) 341 if (lpszInitialFolder)
342 { 342 {
343 // is this a folder path string or a csidl? 343 // is this a folder path string or a csidl?
344 if (HIWORD(lpszInitialFolder) == 0) 344 if (HIWORD(lpszInitialFolder) == 0)
345 { 345 {
353 _tcsncpy(szInitialPath, lpszInitialFolder, 353 _tcsncpy(szInitialPath, lpszInitialFolder,
354 sizeof(szInitialPath)/sizeof(TCHAR)-2); 354 sizeof(szInitialPath)/sizeof(TCHAR)-2);
355 } 355 }
356 } 356 }
357 357
358 if ((szInitialPath[0] == _T('\0')) && (bi.pidlRoot == NULL)) 358 if (!szInitialPath[0] && !bi.pidlRoot)
359 { 359 {
360 // no initial folder and no root, set to current directory 360 // no initial folder and no root, set to current directory
361 ::GetCurrentDirectory(sizeof(szInitialPath)/sizeof(TCHAR)-2, 361 ::GetCurrentDirectory(sizeof(szInitialPath)/sizeof(TCHAR)-2,
362 szInitialPath); 362 szInitialPath);
363 } 363 }
381 381
382 LPITEMIDLIST pidlFolder = SHBrowseForFolder(&bi); 382 LPITEMIDLIST pidlFolder = SHBrowseForFolder(&bi);
383 383
384 if (pidlFolder) 384 if (pidlFolder)
385 { 385 {
386 TCHAR szBuffer[MAX_PATH*2] = { _T('\0') }; 386 TCHAR szBuffer[MAX_PATH*2] = { 0 };
387 387
388 if (SHGetPathFromIDList(pidlFolder, szBuffer)) 388 if (SHGetPathFromIDList(pidlFolder, szBuffer))
389 { 389 {
390 _tcsncpy(lpszBuf, szBuffer, dwBufSize-1); 390 _tcsncpy(lpszBuf, szBuffer, dwBufSize-1);
391 bRet = TRUE; 391 bRet = TRUE;