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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
|
// For licensing and usage information, read docs/winui_license.txt
// MASTER
//****************************************************************************
/***************************************************************************
directories.c
***************************************************************************/
// standard windows headers
#include <windows.h>
#include <windowsx.h>
// standard C headers
#include <sys/stat.h> // S_IFDIR
#include <tchar.h>
// MAME/MAMEUI headers
#include "directories.h"
#include "resource.h"
#include "mui_util.h"
// SHELL DIR header
#include <shlobj.h>
#define MAX_DIRS 256
/***************************************************************************
Internal structures
***************************************************************************/
typedef struct
{
TCHAR m_Directories[MAX_DIRS][MAX_PATH];
int m_NumDirectories;
BOOL m_bModified;
} tPath;
typedef struct
{
tPath *m_Path;
TCHAR *m_tDirectory;
} tDirInfo;
/***************************************************************************
Function prototypes
***************************************************************************/
static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData);
BOOL BrowseForDirectory(HWND hwnd, LPCTSTR pStartDir, TCHAR* pResult);
static void DirInfo_SetDir(tDirInfo *pInfo, int nType, int nItem, LPCTSTR pText);
static TCHAR* DirInfo_Dir(tDirInfo *pInfo, int nType);
static TCHAR* DirInfo_Path(tDirInfo *pInfo, int nType, int nItem);
static void DirInfo_SetModified(tDirInfo *pInfo, int nType, BOOL bModified);
static BOOL DirInfo_Modified(tDirInfo *pInfo, int nType);
static TCHAR* FixSlash(TCHAR *s);
static void UpdateDirectoryList(HWND hDlg);
static void Directories_OnSelChange(HWND hDlg);
static BOOL Directories_OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lParam);
static void Directories_OnDestroy(HWND hDlg);
static void Directories_OnClose(HWND hDlg);
static void Directories_OnOk(HWND hDlg);
static void Directories_OnCancel(HWND hDlg);
static void Directories_OnInsert(HWND hDlg);
static void Directories_OnBrowse(HWND hDlg);
static void Directories_OnDelete(HWND hDlg);
static BOOL Directories_OnBeginLabelEdit(HWND hDlg, NMHDR* pNMHDR);
static BOOL Directories_OnEndLabelEdit(HWND hDlg, NMHDR* pNMHDR);
static void Directories_OnCommand(HWND hDlg, int id, HWND hwndCtl, UINT codeNotify);
static BOOL Directories_OnNotify(HWND hDlg, int id, NMHDR* pNMHDR);
/***************************************************************************
External variables
***************************************************************************/
/***************************************************************************
Internal variables
***************************************************************************/
static tDirInfo *g_pDirInfo;
/***************************************************************************
External function definitions
***************************************************************************/
INT_PTR CALLBACK DirectoriesDialogProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
BOOL bReturn = false;
switch (Msg)
{
case WM_INITDIALOG:
return (BOOL)HANDLE_WM_INITDIALOG(hDlg, wParam, lParam, Directories_OnInitDialog);
case WM_COMMAND:
HANDLE_WM_COMMAND(hDlg, wParam, lParam, Directories_OnCommand);
bReturn = true;
break;
case WM_NOTIFY:
return (BOOL)HANDLE_WM_NOTIFY(hDlg, wParam, lParam, Directories_OnNotify);
case WM_CLOSE:
HANDLE_WM_CLOSE(hDlg, wParam, lParam, Directories_OnClose);
break;
case WM_DESTROY:
HANDLE_WM_DESTROY(hDlg, wParam, lParam, Directories_OnDestroy);
break;
default:
break;
}
return bReturn;
}
/***************************************************************************
Internal function definitions
***************************************************************************/
static BOOL IsMultiDir(int nType)
{
return g_directoryInfo[nType].bMulti;
}
static void DirInfo_SetDir(tDirInfo *pInfo, int nType, int nItem, LPCTSTR pText)
{
TCHAR *t_s;
TCHAR *t_pOldText;
if (IsMultiDir(nType))
{
assert(nItem >= 0);
_tcscpy(DirInfo_Path(pInfo, nType, nItem), pText);
DirInfo_SetModified(pInfo, nType, TRUE);
}
else
{
t_s = win_tstring_strdup(pText);
if (!t_s)
return;
t_pOldText = pInfo[nType].m_tDirectory;
if (t_pOldText)
free(t_pOldText);
pInfo[nType].m_tDirectory = t_s; // don't free t_s else directory name is corrupted
}
}
static TCHAR* DirInfo_Dir(tDirInfo *pInfo, int nType)
{
// if a multipath exists in a single-path-only area then truncate it
return _tcstok(pInfo[nType].m_tDirectory, TEXT(";"));
}
static TCHAR* DirInfo_Path(tDirInfo *pInfo, int nType, int nItem)
{
return pInfo[nType].m_Path->m_Directories[nItem];
}
static void DirInfo_SetModified(tDirInfo *pInfo, int nType, BOOL bModified)
{
//assert(IsMultiDir(nType));
pInfo[nType].m_Path->m_bModified = bModified;
}
static BOOL DirInfo_Modified(tDirInfo *pInfo, int nType)
{
//assert(IsMultiDir(nType));
return pInfo[nType].m_Path->m_bModified;
}
#define DirInfo_NumDir(pInfo, path) \
((pInfo)[(path)].m_Path->m_NumDirectories)
/* lop off trailing backslash if it exists */
static TCHAR * FixSlash(TCHAR *s)
{
int len = 0;
if (s)
len = _tcslen(s);
if (len>3 && s[len - 1] == '\\')
s[len - 1] = '\0';
return s;
}
static void UpdateDirectoryList(HWND hDlg)
{
HWND hList = GetDlgItem(hDlg, IDC_DIR_LIST);
HWND hCombo = GetDlgItem(hDlg, IDC_DIR_COMBO);
/* Remove previous */
BOOL b_res = ListView_DeleteAllItems(hList);
/* Update list */
LV_ITEM Item;
memset(&Item, 0, sizeof(LV_ITEM));
Item.mask = LVIF_TEXT;
int nType = ComboBox_GetCurSel(hCombo);
if (IsMultiDir(nType))
{
Item.pszText = (TCHAR*) TEXT(DIRLIST_NEWENTRYTEXT); // puts the < > empty entry in
(void)ListView_InsertItem(hList, &Item);
int t = DirInfo_NumDir(g_pDirInfo, nType);
// directories are inserted in reverse order
for (int i = t; 0 < i; i--)
{
Item.pszText = DirInfo_Path(g_pDirInfo, nType, i-1);
(void)ListView_InsertItem(hList, &Item);
}
}
else
{
Item.pszText = DirInfo_Dir(g_pDirInfo, nType);
(void)ListView_InsertItem(hList, &Item);
}
/* select first one */
ListView_SetItemState(hList, 0, LVIS_SELECTED, LVIS_SELECTED);
b_res++;
}
static void Directories_OnSelChange(HWND hDlg)
{
UpdateDirectoryList(hDlg);
HWND hCombo = GetDlgItem(hDlg, IDC_DIR_COMBO);
int nType = ComboBox_GetCurSel(hCombo);
if (IsMultiDir(nType))
{
EnableWindow(GetDlgItem(hDlg, IDC_DIR_DELETE), TRUE);
EnableWindow(GetDlgItem(hDlg, IDC_DIR_INSERT), TRUE);
}
else
{
EnableWindow(GetDlgItem(hDlg, IDC_DIR_DELETE), FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_DIR_INSERT), FALSE);
}
}
static BOOL Directories_OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lParam)
{
RECT rectClient;
LVCOLUMN LVCol;
int i = 0;
std::string s;
TCHAR *token;
TCHAR buf[MAX_PATH * MAX_DIRS];
TCHAR* t_s = NULL;
HRESULT res = 0;
/* count how many dirinfos there are */
int nDirInfoCount = 0;
while(g_directoryInfo[nDirInfoCount].lpName)
nDirInfoCount++;
g_pDirInfo = (tDirInfo *) malloc(sizeof(tDirInfo) * nDirInfoCount);
if (!g_pDirInfo) /* bummer */
goto error;
memset(g_pDirInfo, 0, sizeof(tDirInfo) * nDirInfoCount);
for (i = nDirInfoCount - 1; i >= 0; i--)
{
t_s = ui_wstring_from_utf8(g_directoryInfo[i].lpName);
if( !t_s )
return FALSE;
(void)ComboBox_InsertString(GetDlgItem(hDlg, IDC_DIR_COMBO), 0, win_tstring_strdup(t_s));
free(t_s);
t_s = NULL;
}
(void)ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO), 0);
GetClientRect(GetDlgItem(hDlg, IDC_DIR_LIST), &rectClient);
memset(&LVCol, 0, sizeof(LVCOLUMN));
LVCol.mask = LVCF_WIDTH;
LVCol.cx = rectClient.right - rectClient.left - GetSystemMetrics(SM_CXHSCROLL);
res = ListView_InsertColumn(GetDlgItem(hDlg, IDC_DIR_LIST), 0, &LVCol);
res++;
/* Keep a temporary copy of the directory strings in g_pDirInfo. */
for (i = 0; i < nDirInfoCount; i++)
{
s = g_directoryInfo[i].pfnGetTheseDirs();
t_s = ui_wstring_from_utf8(s.c_str());
if( !t_s )
return false;
/* Copy the string to our own buffer so that we can mutilate it */
_tcscpy(buf, t_s);
if (IsMultiDir(i))
{
g_pDirInfo[i].m_Path = (tPath*)malloc(sizeof(tPath));
if (!g_pDirInfo[i].m_Path)
goto error;
g_pDirInfo[i].m_Path->m_NumDirectories = 0;
token = _tcstok(buf, TEXT(";"));
while ((DirInfo_NumDir(g_pDirInfo, i) < MAX_DIRS) && token)
{
_tcscpy(DirInfo_Path(g_pDirInfo, i, DirInfo_NumDir(g_pDirInfo, i)), token);
DirInfo_NumDir(g_pDirInfo, i)++;
token = _tcstok(NULL, TEXT(";"));
}
DirInfo_SetModified(g_pDirInfo, i, FALSE);
}
else
{
// multi not supported so get first directory only
token = _tcstok(buf, TEXT(";"));
if (token)
DirInfo_SetDir(g_pDirInfo, i, -1, token);
else
DirInfo_SetDir(g_pDirInfo, i, -1, t_s);
}
free(t_s);
t_s = NULL;
}
UpdateDirectoryList(hDlg);
return true;
error:
if( t_s )
free(t_s);
Directories_OnDestroy(hDlg);
EndDialog(hDlg, -1);
return false;
}
static void Directories_OnDestroy(HWND hDlg)
{
if (g_pDirInfo)
{
/* count how many dirinfos there are */
int nDirInfoCount = 0;
while(g_directoryInfo[nDirInfoCount].lpName)
nDirInfoCount++;
for (int i = 0; i < nDirInfoCount; i++)
{
if (g_pDirInfo[i].m_Path)
free(g_pDirInfo[i].m_Path);
if (g_pDirInfo[i].m_tDirectory)
free(g_pDirInfo[i].m_tDirectory);
}
free(g_pDirInfo);
g_pDirInfo = NULL;
}
}
static void Directories_OnClose(HWND hDlg)
{
EndDialog(hDlg, IDCANCEL);
}
static int RetrieveDirList(int nDir, int nFlagResult, void (*SetTheseDirs)(const char *s))
{
int nResult = 0;
if (DirInfo_Modified(g_pDirInfo, nDir))
{
TCHAR buf[MAX_PATH * MAX_DIRS];
memset(buf, 0, sizeof(buf));
int nPaths = DirInfo_NumDir(g_pDirInfo, nDir);
for (int i = 0; i < nPaths; i++)
{
_tcscat(buf, FixSlash(DirInfo_Path(g_pDirInfo, nDir, i)));
if (i < nPaths - 1)
_tcscat(buf, TEXT(";"));
}
char* utf8_buf = ui_utf8_from_wstring(buf);
SetTheseDirs(utf8_buf);
free(utf8_buf);
nResult |= nFlagResult;
}
return nResult;
}
static void Directories_OnOk(HWND hDlg)
{
int nResult = 0;
for (int i = 0; g_directoryInfo[i].lpName; i++)
{
if (IsMultiDir(i))
nResult |= RetrieveDirList(i, g_directoryInfo[i].nDirDlgFlags, g_directoryInfo[i].pfnSetTheseDirs);
else
{
LPTSTR s = FixSlash(DirInfo_Dir(g_pDirInfo, i));
char* utf8_s = ui_utf8_from_wstring(s);
g_directoryInfo[i].pfnSetTheseDirs(utf8_s);
free(utf8_s);
}
}
EndDialog(hDlg, nResult);
}
static void Directories_OnCancel(HWND hDlg)
{
EndDialog(hDlg, IDCANCEL);
}
static void Directories_OnInsert(HWND hDlg)
{
HWND hList = GetDlgItem(hDlg, IDC_DIR_LIST);
int nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED);
TCHAR buf[MAX_PATH];
if (BrowseForDirectory(hDlg, NULL, buf) == true)
{
/* list was empty */
if (nItem == -1)
nItem = 0;
int nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO));
if (IsMultiDir(nType))
{
if (MAX_DIRS <= DirInfo_NumDir(g_pDirInfo, nType))
return;
for (int i = DirInfo_NumDir(g_pDirInfo, nType); nItem < i; i--)
_tcscpy(DirInfo_Path(g_pDirInfo, nType, i), DirInfo_Path(g_pDirInfo, nType, i - 1));
_tcscpy(DirInfo_Path(g_pDirInfo, nType, nItem), buf);
DirInfo_NumDir(g_pDirInfo, nType)++;
DirInfo_SetModified(g_pDirInfo, nType, true);
}
UpdateDirectoryList(hDlg);
ListView_SetItemState(hList, nItem, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
}
}
static void Directories_OnBrowse(HWND hDlg)
{
HWND hList = GetDlgItem(hDlg, IDC_DIR_LIST);
int nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED);
if (nItem == -1)
return;
int nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO));
if (IsMultiDir(nType))
{
/* Last item is placeholder for append */
if (nItem == ListView_GetItemCount(hList) - 1)
{
Directories_OnInsert(hDlg);
return;
}
}
TCHAR inbuf[MAX_PATH], outbuf[MAX_PATH];
ListView_GetItemText(hList, nItem, 0, inbuf, MAX_PATH);
if (BrowseForDirectory(hDlg, inbuf, outbuf) == true)
{
nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO));
DirInfo_SetDir(g_pDirInfo, nType, nItem, outbuf);
UpdateDirectoryList(hDlg);
}
}
static void Directories_OnDelete(HWND hDlg)
{
HWND hList = GetDlgItem(hDlg, IDC_DIR_LIST);
int nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED | LVNI_ALL);
if (nItem == -1)
return;
/* Don't delete "Append" placeholder. */
if (nItem == ListView_GetItemCount(hList) - 1)
return;
int nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO));
if (IsMultiDir(nType))
{
for (int i = nItem; i < DirInfo_NumDir(g_pDirInfo, nType) - 1; i++)
_tcscpy(DirInfo_Path(g_pDirInfo, nType, i), DirInfo_Path(g_pDirInfo, nType, i + 1));
_tcscpy(DirInfo_Path(g_pDirInfo, nType, DirInfo_NumDir(g_pDirInfo, nType) - 1), TEXT(""));
DirInfo_NumDir(g_pDirInfo, nType)--;
DirInfo_SetModified(g_pDirInfo, nType, TRUE);
}
UpdateDirectoryList(hDlg);
int nCount = ListView_GetItemCount(hList);
if (nCount <= 1)
return;
/* If the last item was removed, select the item above. */
int nSelect;
if (nItem == nCount - 1)
nSelect = nCount - 2;
else
nSelect = nItem;
ListView_SetItemState(hList, nSelect, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
}
static BOOL Directories_OnBeginLabelEdit(HWND hDlg, NMHDR* pNMHDR)
{
BOOL bResult = false;
NMLVDISPINFO* pDispInfo = (NMLVDISPINFO*)pNMHDR;
LVITEM* pItem = &pDispInfo->item;
int nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO));
if (IsMultiDir(nType))
{
/* Last item is placeholder for append */
if (pItem->iItem == ListView_GetItemCount(GetDlgItem(hDlg, IDC_DIR_LIST)) - 1)
{
if (MAX_DIRS <= DirInfo_NumDir(g_pDirInfo, nType))
return true; /* don't edit */
HWND hEdit = (HWND)(LRESULT)(int)SendDlgItemMessage(hDlg, IDC_DIR_LIST, LVM_GETEDITCONTROL, 0, 0);
Edit_SetText(hEdit, TEXT(""));
}
}
return bResult;
}
static BOOL Directories_OnEndLabelEdit(HWND hDlg, NMHDR* pNMHDR)
{
BOOL bResult = false;
NMLVDISPINFO* pDispInfo = (NMLVDISPINFO*)pNMHDR;
LVITEM* pItem = &pDispInfo->item;
if (pItem->pszText)
{
struct _stat file_stat;
/* Don't allow empty entries. */
if (!_tcscmp(pItem->pszText, TEXT("")))
return false;
/* Check validity of edited directory. */
if (_tstat(pItem->pszText, &file_stat) == 0
&& (file_stat.st_mode & S_IFDIR))
bResult = true;
else
if (MessageBox(NULL, TEXT("Directory does not exist, continue anyway?"), TEXT(MAMEUINAME), MB_OKCANCEL) == IDOK)
bResult = true;
}
if (bResult == true)
{
int nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO));
if (IsMultiDir(nType))
{
/* Last item is placeholder for append */
if (pItem->iItem == ListView_GetItemCount(GetDlgItem(hDlg, IDC_DIR_LIST)) - 1)
{
if (MAX_DIRS <= DirInfo_NumDir(g_pDirInfo, nType))
return false;
for (int i = DirInfo_NumDir(g_pDirInfo, nType); pItem->iItem < i; i--)
_tcscpy(DirInfo_Path(g_pDirInfo, nType, i), DirInfo_Path(g_pDirInfo, nType, i - 1));
_tcscpy(DirInfo_Path(g_pDirInfo, nType, pItem->iItem), pItem->pszText);
DirInfo_SetModified(g_pDirInfo, nType, true);
DirInfo_NumDir(g_pDirInfo, nType)++;
}
else
DirInfo_SetDir(g_pDirInfo, nType, pItem->iItem, pItem->pszText);
}
else
DirInfo_SetDir(g_pDirInfo, nType, pItem->iItem, pItem->pszText);
UpdateDirectoryList(hDlg);
ListView_SetItemState(GetDlgItem(hDlg, IDC_DIR_LIST), pItem->iItem, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
}
return bResult;
}
static void Directories_OnCommand(HWND hDlg, int id, HWND hwndCtl, UINT codeNotify)
{
switch (id)
{
case IDOK:
if (codeNotify == BN_CLICKED)
Directories_OnOk(hDlg);
break;
case IDCANCEL:
if (codeNotify == BN_CLICKED)
Directories_OnCancel(hDlg);
break;
case IDC_DIR_BROWSE:
if (codeNotify == BN_CLICKED)
Directories_OnBrowse(hDlg);
break;
case IDC_DIR_INSERT:
if (codeNotify == BN_CLICKED)
Directories_OnInsert(hDlg);
break;
case IDC_DIR_DELETE:
if (codeNotify == BN_CLICKED)
Directories_OnDelete(hDlg);
break;
case IDC_DIR_COMBO:
switch (codeNotify)
{
case CBN_SELCHANGE:
Directories_OnSelChange(hDlg);
break;
}
break;
}
}
static BOOL Directories_OnNotify(HWND hDlg, int id, NMHDR* pNMHDR)
{
switch (id)
{
case IDC_DIR_LIST:
switch (pNMHDR->code)
{
case LVN_ENDLABELEDIT:
return Directories_OnEndLabelEdit(hDlg, pNMHDR);
case LVN_BEGINLABELEDIT:
return Directories_OnBeginLabelEdit(hDlg, pNMHDR);
}
}
return FALSE;
}
/**************************************************************************
Use the shell to select a Directory.
**************************************************************************/
static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
/*
Called just after the dialog is initialized
Select the dir passed in BROWSEINFO.lParam
*/
if (uMsg == BFFM_INITIALIZED)
{
if ((const char*)lpData)
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
}
return 0;
}
BOOL BrowseForDirectory(HWND hwnd, LPCTSTR pStartDir, TCHAR* pResult)
{
BOOL bResult = false;
TCHAR buf[MAX_PATH];
BROWSEINFO Info;
Info.hwndOwner = hwnd;
Info.pidlRoot = NULL;
Info.pszDisplayName = buf;
Info.lpszTitle = TEXT("Select a directory:");
Info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI;
Info.lpfn = BrowseCallbackProc;
Info.lParam = (LPARAM)pStartDir;
LPITEMIDLIST pItemIDList = SHBrowseForFolder(&Info);
if (pItemIDList)
{
if (SHGetPathFromIDList(pItemIDList, buf) == true)
{
_sntprintf(pResult, MAX_PATH, TEXT("%s"), buf);
bResult = true;
}
}
else
bResult = false;
return bResult;
}
|