1 |
// Vance Thrift and Biller File Utility 2 |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id: DiscBrowse.cxx,v 1.9 2003/09/05 08:57:00 douglas Exp $ |
6 |
|
7 |
#include "DiscBrowse.h" |
8 |
|
9 |
DiscBrowse::DiscBrowse() |
10 |
{ |
11 |
number = count++; |
12 |
|
13 |
browsers.insert(pair<unsigned, DiscBrowse*>(number, this)); |
14 |
|
15 |
title = programName + " - Disc Browse"; |
16 |
popup = CreatePopupMenu(); |
17 |
|
18 |
MENUITEMINFO open, separator, properties; |
19 |
|
20 |
open.cbSize = sizeof(open); |
21 |
open.fMask = MIIM_ID | MIIM_STATE | MIIM_TYPE; |
22 |
open.fType = MFT_STRING; |
23 |
open.fState = MFS_DEFAULT; |
24 |
open.wID = 1; |
25 |
open.dwTypeData = "&Open"; |
26 |
open.cch = 5; |
27 |
separator.cbSize = sizeof(open); |
28 |
separator.fMask = MIIM_TYPE; |
29 |
separator.fType = MFT_SEPARATOR; |
30 |
properties.cbSize = sizeof(open); |
31 |
properties.fMask = MIIM_ID | MIIM_TYPE; |
32 |
properties.fType = MFT_STRING; |
33 |
properties.wID = 2; |
34 |
properties.dwTypeData = "P&roperties"; |
35 |
properties.cch = 11; |
36 |
|
37 |
InsertMenuItem(popup, 0, TRUE, &open); |
38 |
InsertMenuItem(popup, 1, TRUE, &separator); |
39 |
InsertMenuItem(popup, 2, TRUE, &properties); |
40 |
|
41 |
// start |
42 |
wizard[0].dwSize = sizeof(wizard[0]); |
43 |
wizard[0].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE | |
44 |
PSP_USEHEADERSUBTITLE; |
45 |
wizard[0].hInstance = gui.instance; |
46 |
wizard[0].pszTemplate = MAKEINTRESOURCE(IDD_BEGIN); |
47 |
wizard[0].pszTitle = title.c_str(); |
48 |
wizard[0].pfnDlgProc = start; |
49 |
wizard[0].lParam = number; |
50 |
wizard[0].pszHeaderTitle = "Start"; |
51 |
wizard[0].pszHeaderSubTitle = "Change any settings before browsing."; |
52 |
|
53 |
// browse |
54 |
wizard[1].dwSize = sizeof(wizard[1]); |
55 |
wizard[1].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE | |
56 |
PSP_USEHEADERSUBTITLE; |
57 |
wizard[1].hInstance = gui.instance; |
58 |
wizard[1].pszTemplate = MAKEINTRESOURCE(IDD_BROWSE); |
59 |
wizard[1].pszTitle = title.c_str(); |
60 |
wizard[1].pfnDlgProc = browse; |
61 |
wizard[1].lParam = number; |
62 |
wizard[1].pszHeaderTitle = "Browse"; |
63 |
wizard[1].pszHeaderSubTitle = "View documents on the disc."; |
64 |
} |
65 |
|
66 |
DiscBrowse::~DiscBrowse() |
67 |
{ |
68 |
DestroyMenu(popup); |
69 |
browsers.erase(number); |
70 |
} |
71 |
|
72 |
void DiscBrowse::run(void) |
73 |
{ |
74 |
loadDir(); |
75 |
|
76 |
PROPSHEETHEADER header; |
77 |
|
78 |
// header |
79 |
header.dwSize = sizeof(header); |
80 |
header.dwFlags = PSH_DEFAULT | PSH_HEADER | PSH_PROPSHEETPAGE | |
81 |
PSH_USEICONID | PSH_WIZARD97 | PSH_WIZARDHASFINISH; |
82 |
header.hwndParent = NULL; |
83 |
header.hInstance = gui.instance; |
84 |
header.pszIcon = MAKEINTRESOURCE(IDI_VTB_ICON); |
85 |
header.nPages = 2; |
86 |
header.nStartPage = 0; |
87 |
header.ppsp = wizard; |
88 |
header.pszbmHeader = MAKEINTRESOURCE(IDB_VTB_BMP); |
89 |
|
90 |
PropertySheet(&header); |
91 |
saveDir(); |
92 |
} |
93 |
|
94 |
unsigned DiscBrowse::count = 0; |
95 |
map<unsigned, DiscBrowse*> DiscBrowse::browsers; |
96 |
|
97 |
map<HWND, DiscBrowse*> DiscBrowse::windows; |
98 |
|
99 |
void DiscBrowse::loadDir(void) |
100 |
{ |
101 |
HKEY key; |
102 |
|
103 |
if (RegOpenKeyEx(HKEY_CURRENT_USER, |
104 |
"Software\\DouglasThrift\\VTBFileUtil2", 0, KEY_QUERY_VALUE, &key) == |
105 |
ERROR_SUCCESS) |
106 |
{ |
107 |
DWORD type; |
108 |
char data[MAX_PATH]; |
109 |
DWORD size = MAX_PATH; |
110 |
|
111 |
if (RegQueryValueEx(key, "DiscDir", NULL, &type, LPBYTE(data), &size) |
112 |
== ERROR_SUCCESS) |
113 |
{ |
114 |
data[size - 1] = '\0'; |
115 |
|
116 |
switch (type) |
117 |
{ |
118 |
case REG_EXPAND_SZ: |
119 |
{ |
120 |
char folder[MAX_PATH]; |
121 |
|
122 |
ExpandEnvironmentStrings(data, folder, MAX_PATH); |
123 |
|
124 |
discDir = tail(folder); |
125 |
} |
126 |
break; |
127 |
case REG_SZ: |
128 |
discDir = tail(data); |
129 |
break; |
130 |
default: |
131 |
setDiscDir(); |
132 |
break; |
133 |
} |
134 |
} |
135 |
else |
136 |
{ |
137 |
setDiscDir(); |
138 |
} |
139 |
|
140 |
RegCloseKey(key); |
141 |
} |
142 |
else |
143 |
{ |
144 |
setDiscDir(); |
145 |
} |
146 |
|
147 |
if (debug) cerr << "discDir = " << discDir << "\n"; |
148 |
} |
149 |
|
150 |
void DiscBrowse::saveDir(void) |
151 |
{ |
152 |
HKEY key; |
153 |
|
154 |
if (LONG code = RegCreateKeyEx(HKEY_CURRENT_USER, |
155 |
"Software\\DouglasThrift\\VTBFileUtil2", 0, NULL, |
156 |
REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_SET_VALUE, NULL, &key, |
157 |
NULL) == ERROR_SUCCESS) |
158 |
{ |
159 |
DWORD type; |
160 |
char data[MAX_PATH]; |
161 |
DWORD size = MAX_PATH; |
162 |
|
163 |
if (RegQueryValueEx(key, "DiscDir", NULL, &type, LPBYTE(data), &size) |
164 |
== ERROR_SUCCESS) |
165 |
{ |
166 |
data[size - 1] = '\0'; |
167 |
} |
168 |
else |
169 |
{ |
170 |
data[0] = '\0'; |
171 |
} |
172 |
|
173 |
if (discDir != data || type != REG_SZ) |
174 |
{ |
175 |
if (code = RegSetValueEx(key, "DiscDir", 0, REG_SZ, |
176 |
LPBYTE(discDir.c_str()), discDir.length() + 1) != |
177 |
ERROR_SUCCESS) |
178 |
{ |
179 |
error(NULL, code); |
180 |
} |
181 |
} |
182 |
|
183 |
RegCloseKey(key); |
184 |
} |
185 |
else |
186 |
{ |
187 |
error(NULL, code); |
188 |
} |
189 |
} |
190 |
|
191 |
void DiscBrowse::setDiscDir(HWND parent) |
192 |
{ |
193 |
BROWSEINFO info; |
194 |
|
195 |
info.hwndOwner = parent; |
196 |
info.pidlRoot = NULL; |
197 |
info.pszDisplayName = NULL; |
198 |
info.lpszTitle = "Select the Disc"; |
199 |
info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT; |
200 |
info.lpfn = browse; |
201 |
info.lParam = MAKELPARAM(number, true); |
202 |
info.iImage = 0; |
203 |
|
204 |
do |
205 |
{ |
206 |
LPITEMIDLIST id = SHBrowseForFolder(&info); |
207 |
|
208 |
if (id != NULL) |
209 |
{ |
210 |
char folder[MAX_PATH]; |
211 |
|
212 |
if (SHGetPathFromIDList(id, folder)) discDir = tail(folder); |
213 |
|
214 |
LPMALLOC destruct; |
215 |
|
216 |
SHGetMalloc(&destruct); |
217 |
destruct->Free(id); |
218 |
destruct->Release(); |
219 |
} |
220 |
|
221 |
if (discDir == "") |
222 |
{ |
223 |
switch (MessageBox(parent, "Disc needs to be selected.", |
224 |
title.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR)) |
225 |
{ |
226 |
case IDABORT: |
227 |
exit(1); |
228 |
break; |
229 |
case IDRETRY: |
230 |
break; |
231 |
case IDIGNORE: |
232 |
Beep(2200, 250); |
233 |
Beep(1100, 500); |
234 |
Beep(3300, 250); |
235 |
exit(2); |
236 |
break; |
237 |
} |
238 |
} |
239 |
} |
240 |
while (discDir == ""); |
241 |
|
242 |
if (debug) cerr << "discDir = " << discDir << "\n"; |
243 |
} |
244 |
|
245 |
void DiscBrowse::populate(HWND parent) |
246 |
{ |
247 |
set<IndividualClient> clients; |
248 |
|
249 |
do |
250 |
{ |
251 |
string client = discDir + "*_*." + IndividualClient::getExtension(); |
252 |
WIN32_FIND_DATA found; |
253 |
HANDLE finder = FindFirstFile(client.c_str(), &found); |
254 |
|
255 |
if (finder != INVALID_HANDLE_VALUE) |
256 |
{ |
257 |
do |
258 |
{ |
259 |
clients.insert(IndividualClient(found.cFileName)); |
260 |
} |
261 |
while (FindNextFile(finder, &found)); |
262 |
|
263 |
FindClose(finder); |
264 |
} |
265 |
|
266 |
if (clients.empty()) |
267 |
{ |
268 |
if (MessageBox(parent, "No client documents found.", |
269 |
title.c_str(), MB_RETRYCANCEL | MB_ICONQUESTION) == IDCANCEL) |
270 |
break; |
271 |
} |
272 |
} |
273 |
while (clients.empty()); |
274 |
|
275 |
if (!clients.empty()) |
276 |
{ |
277 |
SHFILEINFO info; |
278 |
HIMAGELIST icons = |
279 |
HIMAGELIST(SHGetFileInfo((*clients.begin()).getFile().c_str(), |
280 |
0, &info, sizeof(info), SHGFI_SMALLICON | SHGFI_SYSICONINDEX)); |
281 |
|
282 |
ListView_SetImageList(GetDlgItem(parent, IDC_BROWSE_DISC), icons, |
283 |
LVSIL_SMALL); |
284 |
|
285 |
if (debug) cerr << "clients = {\n"; |
286 |
|
287 |
for (set<IndividualClient>::iterator itor = clients.begin(); itor != |
288 |
clients.end(); itor++) |
289 |
{ |
290 |
IndividualClient client = *itor; |
291 |
|
292 |
if (debug) cerr << " {\n" |
293 |
<< " number = " << client.getNumber() << "\n" |
294 |
<< " name = " << client.getName() << "\n" |
295 |
<< " file = " << client.getFile() << "\n" |
296 |
<< " }\n"; |
297 |
|
298 |
char clientFile[MAX_PATH], clientNumber[MAX_PATH], |
299 |
clientName[MAX_PATH], clientSize[MAX_PATH]; |
300 |
HANDLE fileSize = CreateFile(client.getFile().c_str(), |
301 |
GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, |
302 |
FILE_ATTRIBUTE_NORMAL, NULL); |
303 |
DWORD bytes = GetFileSize(fileSize, NULL); |
304 |
|
305 |
CloseHandle(fileSize); |
306 |
sprintf(clientFile, "%s", client.getFile().c_str()); |
307 |
sprintf(clientNumber, "%u", client.getNumber()); |
308 |
sprintf(clientName, "%s", client.getName().c_str()); |
309 |
sprintf(clientSize, "%.2f MB", FLOAT(bytes) / FLOAT(1024 * 1024)); |
310 |
|
311 |
LVITEM number, name, file, size; |
312 |
|
313 |
file.mask = LVIF_IMAGE | LVIF_PARAM | LVIF_TEXT; |
314 |
file.iItem = 0; |
315 |
file.iSubItem = 0; |
316 |
file.pszText = clientFile; |
317 |
file.iImage = info.iIcon; |
318 |
file.lParam = bytes; |
319 |
|
320 |
int item = ListView_InsertItem(GetDlgItem(parent, IDC_BROWSE_DISC), |
321 |
&file); |
322 |
|
323 |
number.mask = LVIF_TEXT; |
324 |
number.iItem = item; |
325 |
number.iSubItem = 1; |
326 |
number.pszText = clientNumber; |
327 |
name.mask = LVIF_TEXT; |
328 |
name.iItem = item; |
329 |
name.iSubItem = 2; |
330 |
name.pszText = clientName; |
331 |
size.mask = LVIF_TEXT; |
332 |
size.iItem = item; |
333 |
size.iSubItem = 3; |
334 |
size.pszText = clientSize; |
335 |
|
336 |
ListView_SetItem(GetDlgItem(parent, IDC_BROWSE_DISC), &number); |
337 |
ListView_SetItem(GetDlgItem(parent, IDC_BROWSE_DISC), &name); |
338 |
ListView_SetItem(GetDlgItem(parent, IDC_BROWSE_DISC), &size); |
339 |
} |
340 |
|
341 |
if (debug) cerr << "}\n"; |
342 |
|
343 |
Thing thing; |
344 |
|
345 |
sortFile = true, sortNumber = true, sortName = true, sortSize = true; |
346 |
thing.index = 1; |
347 |
thing.order = sortNumber; |
348 |
thing.list = GetDlgItem(parent, IDC_BROWSE_DISC); |
349 |
sortNumber = !sortNumber; |
350 |
|
351 |
ListView_SortItemsEx(thing.list, sort, &thing); |
352 |
} |
353 |
} |
354 |
|
355 |
DiscBrowse* DiscBrowse::which(HWND window) |
356 |
{ |
357 |
map<HWND, DiscBrowse*>::iterator itor = windows.find(window); |
358 |
|
359 |
return itor->second; |
360 |
} |
361 |
|
362 |
DiscBrowse* DiscBrowse::which(HWND window, LPARAM l) |
363 |
{ |
364 |
LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l); |
365 |
map<unsigned, DiscBrowse*>::iterator itor = browsers.find(page->lParam); |
366 |
|
367 |
windows.insert(pair<HWND, DiscBrowse*>(window, itor->second)); |
368 |
|
369 |
return itor->second; |
370 |
} |
371 |
|
372 |
int DiscBrowse::browse(HWND dialog, UINT msg, LPARAM l, LPARAM d) |
373 |
{ |
374 |
map<unsigned, DiscBrowse*>::iterator itor = browsers.find(LOWORD(d)); |
375 |
DiscBrowse* data = itor->second; |
376 |
|
377 |
switch (msg) |
378 |
{ |
379 |
case BFFM_INITIALIZED: |
380 |
center(dialog); |
381 |
SendMessage(dialog, BFFM_SETOKTEXT, 0, |
382 |
LPARAM(toWide("&Select").c_str())); |
383 |
SendMessage(dialog, BFFM_SETEXPANDED, FALSE, CSIDL_DRIVES); |
384 |
|
385 |
if (data->discDir != "") |
386 |
{ |
387 |
IShellFolder* desktop; |
388 |
LPWSTR path = new WCHAR[data->discDir.length() + 1]; |
389 |
LPITEMIDLIST id; |
390 |
|
391 |
wsprintfW(path, toWide(data->discDir).c_str()); |
392 |
|
393 |
if (debug) cerr << "path = " << toAnsi(path) << "\n"; |
394 |
|
395 |
SHGetDesktopFolder(&desktop); |
396 |
desktop->ParseDisplayName(dialog, NULL, path, NULL, &id, NULL); |
397 |
|
398 |
if (id != NULL) |
399 |
{ |
400 |
SendMessage(dialog, BFFM_SETSELECTION, FALSE, LPARAM(id)); |
401 |
|
402 |
LPMALLOC destruct; |
403 |
|
404 |
SHGetMalloc(&destruct); |
405 |
destruct->Free(id); |
406 |
destruct->Release(); |
407 |
} |
408 |
|
409 |
desktop->Release(); |
410 |
} |
411 |
break; |
412 |
case BFFM_SELCHANGED: |
413 |
{ |
414 |
SHFILEINFO info; |
415 |
|
416 |
SHGetFileInfo(LPCSTR(l), 0, &info, sizeof(info), SHGFI_DISPLAYNAME |
417 |
| SHGFI_PIDL); |
418 |
SendMessage(dialog, BFFM_SETSTATUSTEXT, 0, |
419 |
LPARAM(info.szDisplayName)); |
420 |
|
421 |
char folder[MAX_PATH]; |
422 |
|
423 |
if (!SHGetPathFromIDList(LPCITEMIDLIST(l), folder)) |
424 |
{ |
425 |
SendMessage(dialog, BFFM_ENABLEOK, 0, 0); |
426 |
} |
427 |
} |
428 |
break; |
429 |
} |
430 |
|
431 |
return 0; |
432 |
} |
433 |
|
434 |
int DiscBrowse::sort(LPARAM first, LPARAM second, LPARAM l) |
435 |
{ |
436 |
Thing* thing = (Thing*)(l); |
437 |
|
438 |
switch (thing->index) |
439 |
{ |
440 |
case 0: |
441 |
{ |
442 |
char one[MAX_PATH], two[MAX_PATH]; |
443 |
|
444 |
ListView_GetItemText(thing->list, first, 0, one, MAX_PATH); |
445 |
ListView_GetItemText(thing->list, second, 0, two, MAX_PATH); |
446 |
|
447 |
string first = one, second = two; |
448 |
|
449 |
if (first < second) |
450 |
{ |
451 |
return thing->order ? -1 : 1; |
452 |
} |
453 |
else if (first > second) |
454 |
{ |
455 |
return thing->order ? 1 : -1; |
456 |
} |
457 |
} |
458 |
break; |
459 |
case 1: |
460 |
{ |
461 |
char one[MAX_PATH], two[MAX_PATH]; |
462 |
|
463 |
ListView_GetItemText(thing->list, first, 0, one, MAX_PATH); |
464 |
ListView_GetItemText(thing->list, second, 0, two, MAX_PATH); |
465 |
|
466 |
IndividualClient first(one), second(two); |
467 |
|
468 |
if (first < second) |
469 |
{ |
470 |
return thing->order ? -1 : 1; |
471 |
} |
472 |
else if (first > second) |
473 |
{ |
474 |
return thing->order ? 1 : -1; |
475 |
} |
476 |
} |
477 |
break; |
478 |
case 2: |
479 |
{ |
480 |
char one[MAX_PATH], two[MAX_PATH]; |
481 |
|
482 |
ListView_GetItemText(thing->list, first, 2, one, MAX_PATH); |
483 |
ListView_GetItemText(thing->list, second, 2, two, MAX_PATH); |
484 |
|
485 |
if (mcLess(one, two)) |
486 |
{ |
487 |
return thing->order ? -1 : 1; |
488 |
} |
489 |
else if (mcGreater(one, two)) |
490 |
{ |
491 |
return thing->order ? 1 : -1; |
492 |
} |
493 |
} |
494 |
break; |
495 |
case 3: |
496 |
if (first < second) |
497 |
{ |
498 |
return thing->order ? -1 : 1; |
499 |
} |
500 |
else if (first > second) |
501 |
{ |
502 |
return thing->order ? 1 : -1; |
503 |
} |
504 |
break; |
505 |
} |
506 |
|
507 |
return 0; |
508 |
} |
509 |
|
510 |
INT_PTR DiscBrowse::start(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
511 |
{ |
512 |
DiscBrowse* data = which(dialog); |
513 |
|
514 |
switch (msg) |
515 |
{ |
516 |
case WM_INITDIALOG: |
517 |
center(GetParent(dialog)); |
518 |
SendMessage(GetParent(dialog), WM_SETICON, ICON_BIG, LPARAM(gui.icon)); |
519 |
|
520 |
data = which(dialog, l); |
521 |
break; |
522 |
case WM_NOTIFY: |
523 |
{ |
524 |
LPNMHDR nm = LPNMHDR(l); |
525 |
|
526 |
switch (nm->code) |
527 |
{ |
528 |
case PSN_SETACTIVE: |
529 |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_FINISH | |
530 |
PSWIZB_NEXT); |
531 |
|
532 |
{ |
533 |
SHFILEINFO info; |
534 |
|
535 |
SHGetFileInfo(data->discDir.c_str(), 0, &info, |
536 |
sizeof(info), SHGFI_ICONLOCATION); |
537 |
|
538 |
HICON icon = ExtractIcon(gui.instance, info.szDisplayName, |
539 |
info.iIcon); |
540 |
|
541 |
SendDlgItemMessage(dialog, IDC_BEGIN_ICON, STM_SETIMAGE, |
542 |
IMAGE_ICON, LPARAM(icon)); |
543 |
} |
544 |
|
545 |
{ |
546 |
SHFILEINFO info; |
547 |
|
548 |
SHGetFileInfo(data->discDir.c_str(), 0, &info, |
549 |
sizeof(info), SHGFI_DISPLAYNAME); |
550 |
|
551 |
SetDlgItemText(dialog, IDC_BEGIN_TEXT, info.szDisplayName); |
552 |
} |
553 |
break; |
554 |
case PSN_WIZNEXT: |
555 |
SetCurrentDirectory(data->discDir.c_str()); |
556 |
break; |
557 |
} |
558 |
} |
559 |
break; |
560 |
case WM_COMMAND: |
561 |
switch (LOWORD(w)) |
562 |
{ |
563 |
case IDC_BEGIN_BROWSE: |
564 |
data->setDiscDir(dialog); |
565 |
|
566 |
{ |
567 |
SHFILEINFO info; |
568 |
|
569 |
SHGetFileInfo(data->discDir.c_str(), 0, &info, sizeof(info), |
570 |
SHGFI_ICONLOCATION); |
571 |
|
572 |
HICON icon = ExtractIcon(gui.instance, info.szDisplayName, |
573 |
info.iIcon); |
574 |
|
575 |
SendDlgItemMessage(dialog, IDC_BEGIN_ICON, STM_SETIMAGE, |
576 |
IMAGE_ICON, LPARAM(icon)); |
577 |
} |
578 |
|
579 |
{ |
580 |
SHFILEINFO info; |
581 |
|
582 |
SHGetFileInfo(data->discDir.c_str(), 0, &info, |
583 |
sizeof(info), SHGFI_DISPLAYNAME); |
584 |
|
585 |
SetDlgItemText(dialog, IDC_BEGIN_TEXT, info.szDisplayName); |
586 |
} |
587 |
break; |
588 |
} |
589 |
} |
590 |
|
591 |
return FALSE; |
592 |
} |
593 |
|
594 |
INT_PTR DiscBrowse::browse(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
595 |
{ |
596 |
DiscBrowse* data = which(dialog); |
597 |
int previous = -1; |
598 |
|
599 |
switch (msg) |
600 |
{ |
601 |
case WM_INITDIALOG: |
602 |
data = which(dialog, l); |
603 |
|
604 |
ListView_SetExtendedListViewStyleEx(GetDlgItem(dialog, |
605 |
IDC_BROWSE_DISC), LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP | |
606 |
LVS_EX_LABELTIP, LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP | |
607 |
LVS_EX_LABELTIP); |
608 |
|
609 |
{ |
610 |
LVCOLUMN file, number, name, size; |
611 |
|
612 |
file.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH; |
613 |
file.fmt = LVCFMT_IMAGE; |
614 |
file.cx = 224; |
615 |
file.pszText = "File Name"; |
616 |
number.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; |
617 |
number.cx = 56; |
618 |
number.pszText = "Number"; |
619 |
number.iSubItem = 1; |
620 |
name.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; |
621 |
name.cx = 152; |
622 |
name.pszText = "Client Name"; |
623 |
name.iSubItem = 2; |
624 |
size.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; |
625 |
size.cx = 68; |
626 |
size.pszText = "Size"; |
627 |
size.iSubItem = 3; |
628 |
|
629 |
ListView_InsertColumn(GetDlgItem(dialog, IDC_BROWSE_DISC), 0, |
630 |
&file); |
631 |
ListView_InsertColumn(GetDlgItem(dialog, IDC_BROWSE_DISC), 1, |
632 |
&number); |
633 |
ListView_InsertColumn(GetDlgItem(dialog, IDC_BROWSE_DISC), 2, |
634 |
&name); |
635 |
ListView_InsertColumn(GetDlgItem(dialog, IDC_BROWSE_DISC), 3, |
636 |
&size); |
637 |
} |
638 |
|
639 |
{ |
640 |
int columns[4]; |
641 |
|
642 |
columns[0] = 1; |
643 |
columns[1] = 2; |
644 |
columns[2] = 0; |
645 |
columns[3] = 3; |
646 |
|
647 |
ListView_SetColumnOrderArray(GetDlgItem(dialog, IDC_BROWSE_DISC), |
648 |
4, columns); |
649 |
} |
650 |
break; |
651 |
case WM_NOTIFY: |
652 |
if (w == IDC_BROWSE_DISC) |
653 |
{ |
654 |
LPNMITEMACTIVATE ni = LPNMITEMACTIVATE(l); |
655 |
|
656 |
switch (ni->hdr.code) |
657 |
{ |
658 |
case LVN_COLUMNCLICK: |
659 |
{ |
660 |
Thing thing; |
661 |
|
662 |
thing.index = ni->iSubItem; |
663 |
|
664 |
switch (thing.index) |
665 |
{ |
666 |
case 0: |
667 |
thing.order = data->sortFile; |
668 |
data->sortFile = !data->sortFile; |
669 |
break; |
670 |
case 1: |
671 |
thing.order = data->sortNumber; |
672 |
data->sortNumber = !data->sortNumber; |
673 |
break; |
674 |
case 2: |
675 |
thing.order = data->sortName; |
676 |
data->sortName = !data->sortName; |
677 |
break; |
678 |
case 3: |
679 |
thing.order = data->sortSize; |
680 |
data->sortSize = !data->sortSize; |
681 |
break; |
682 |
} |
683 |
|
684 |
thing.list = GetDlgItem(dialog, IDC_BROWSE_DISC); |
685 |
|
686 |
if (ni->iSubItem == 3) |
687 |
{ |
688 |
ListView_SortItems(thing.list, sort, &thing); |
689 |
} |
690 |
else |
691 |
{ |
692 |
ListView_SortItemsEx(thing.list, sort, &thing); |
693 |
} |
694 |
} |
695 |
break; |
696 |
case LVN_ITEMCHANGED: |
697 |
if (ListView_GetNextItem(GetDlgItem(dialog, IDC_BROWSE_DISC), |
698 |
-1, LVNI_SELECTED) != -1) |
699 |
{ |
700 |
EnableWindow(GetDlgItem(dialog, IDC_BROWSE_OPEN), TRUE); |
701 |
EnableWindow(GetDlgItem(dialog, IDC_BROWSE_PROP), TRUE); |
702 |
} |
703 |
else |
704 |
{ |
705 |
EnableWindow(GetDlgItem(dialog, IDC_BROWSE_OPEN), FALSE); |
706 |
EnableWindow(GetDlgItem(dialog, IDC_BROWSE_PROP), FALSE); |
707 |
} |
708 |
break; |
709 |
case NM_DBLCLK: |
710 |
if (ni->iItem != -1) |
711 |
{ |
712 |
char scan[MAX_PATH]; |
713 |
|
714 |
ListView_GetItemText(GetDlgItem(dialog, IDC_BROWSE_DISC), |
715 |
ni->iItem, 0, scan, MAX_PATH); |
716 |
ShellExecute(dialog, NULL, scan, NULL, NULL, |
717 |
SW_SHOWDEFAULT); |
718 |
} |
719 |
break; |
720 |
} |
721 |
} |
722 |
else |
723 |
{ |
724 |
LPNMHDR nm = LPNMHDR(l); |
725 |
|
726 |
switch (nm->code) |
727 |
{ |
728 |
case PSN_SETACTIVE: |
729 |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
730 |
PSWIZB_FINISH); |
731 |
data->populate(dialog); |
732 |
|
733 |
{ |
734 |
SHFILEINFO info; |
735 |
|
736 |
SHGetFileInfo(data->discDir.c_str(), 0, &info, |
737 |
sizeof(info), SHGFI_ICONLOCATION); |
738 |
|
739 |
HICON icon = ExtractIcon(gui.instance, info.szDisplayName, |
740 |
info.iIcon); |
741 |
|
742 |
SendDlgItemMessage(dialog, IDC_BROWSE_ICON, STM_SETIMAGE, |
743 |
IMAGE_ICON, LPARAM(icon)); |
744 |
} |
745 |
|
746 |
{ |
747 |
SHFILEINFO info; |
748 |
|
749 |
SHGetFileInfo(data->discDir.c_str(), 0, &info, |
750 |
sizeof(info), SHGFI_DISPLAYNAME); |
751 |
|
752 |
SetDlgItemText(dialog, IDC_BROWSE_TEXT, |
753 |
info.szDisplayName); |
754 |
} |
755 |
break; |
756 |
case PSN_WIZBACK: |
757 |
EnableWindow(GetDlgItem(dialog, IDC_BROWSE_OPEN), FALSE); |
758 |
EnableWindow(GetDlgItem(dialog, IDC_BROWSE_PROP), FALSE); |
759 |
ListView_DeleteAllItems(GetDlgItem(dialog, IDC_BROWSE_DISC)); |
760 |
break; |
761 |
} |
762 |
} |
763 |
break; |
764 |
case WM_COMMAND: |
765 |
switch (LOWORD(w)) |
766 |
{ |
767 |
case IDC_BROWSE_REFRESH: |
768 |
EnableWindow(GetDlgItem(dialog, IDC_BROWSE_OPEN), FALSE); |
769 |
EnableWindow(GetDlgItem(dialog, IDC_BROWSE_PROP), FALSE); |
770 |
ListView_DeleteAllItems(GetDlgItem(dialog, IDC_BROWSE_DISC)); |
771 |
data->populate(dialog); |
772 |
break; |
773 |
case IDC_BROWSE_OPEN: |
774 |
do |
775 |
{ |
776 |
char scan[MAX_PATH]; |
777 |
int index = ListView_GetNextItem(GetDlgItem(dialog, |
778 |
IDC_BROWSE_DISC), previous, LVNI_SELECTED); |
779 |
|
780 |
previous = index; |
781 |
|
782 |
if (previous == -1) continue; |
783 |
|
784 |
ListView_GetItemText(GetDlgItem(dialog, IDC_BROWSE_DISC), |
785 |
index, 0, scan, MAX_PATH); |
786 |
ShellExecute(dialog, NULL, scan, NULL, NULL, SW_SHOWDEFAULT); |
787 |
} |
788 |
while (previous != -1); |
789 |
break; |
790 |
case IDC_BROWSE_PROP: |
791 |
do |
792 |
{ |
793 |
char scan[MAX_PATH]; |
794 |
int index = ListView_GetNextItem(GetDlgItem(dialog, |
795 |
IDC_BROWSE_DISC), previous, LVNI_SELECTED); |
796 |
|
797 |
previous = index; |
798 |
|
799 |
if (previous == -1) continue; |
800 |
|
801 |
ListView_GetItemText(GetDlgItem(dialog, IDC_BROWSE_DISC), |
802 |
index, 0, scan, MAX_PATH); |
803 |
|
804 |
SHELLEXECUTEINFO info; |
805 |
|
806 |
info.cbSize = sizeof(info); |
807 |
info.fMask = SEE_MASK_INVOKEIDLIST; |
808 |
info.hwnd = dialog; |
809 |
info.lpVerb = "properties"; |
810 |
info.lpFile = scan; |
811 |
info.lpParameters = NULL; |
812 |
info.lpDirectory = NULL; |
813 |
info.nShow = SW_SHOWDEFAULT; |
814 |
info.lpIDList = NULL; |
815 |
|
816 |
ShellExecuteEx(&info); |
817 |
} |
818 |
while (previous != -1); |
819 |
break; |
820 |
} |
821 |
break; |
822 |
case WM_CONTEXTMENU: |
823 |
if (ListView_GetNextItem(GetDlgItem(dialog, IDC_BROWSE_DISC), -1, |
824 |
LVNI_SELECTED) != -1) |
825 |
{ |
826 |
// char scan[MAX_PATH]; |
827 |
POINT spot; |
828 |
LVHITTESTINFO test; |
829 |
|
830 |
test.pt.x = GET_X_LPARAM(l); |
831 |
test.pt.y = GET_Y_LPARAM(l); |
832 |
|
833 |
ScreenToClient(GetDlgItem(dialog, IDC_BROWSE_DISC), &test.pt); |
834 |
ListView_HitTest(GetDlgItem(dialog, IDC_BROWSE_DISC), &test); |
835 |
|
836 |
if (test.iItem != -1) |
837 |
{ |
838 |
// ListView_GetItemText(GetDlgItem(dialog, IDC_BROWSE_DISC), |
839 |
// test.iItem, 0, scan, MAX_PATH); |
840 |
|
841 |
spot.x = test.pt.x; |
842 |
spot.y = test.pt.y; |
843 |
} |
844 |
else if (GET_X_LPARAM(l) == -1 && GET_Y_LPARAM(l) == -1) |
845 |
{ |
846 |
int index = ListView_GetNextItem(GetDlgItem(dialog, |
847 |
IDC_BROWSE_DISC), -1, LVNI_SELECTED); |
848 |
RECT rect; |
849 |
|
850 |
// ListView_GetItemText(GetDlgItem(dialog, IDC_BROWSE_DISC), |
851 |
// index, 0, scan, MAX_PATH); |
852 |
ListView_EnsureVisible(GetDlgItem(dialog, IDC_BROWSE_DISC), |
853 |
index, FALSE); |
854 |
ListView_GetItemRect(GetDlgItem(dialog, IDC_BROWSE_DISC), |
855 |
index, &rect, LVIR_SELECTBOUNDS); |
856 |
|
857 |
spot.x = rect.left; |
858 |
spot.y = rect.top; |
859 |
} |
860 |
|
861 |
ClientToScreen(GetDlgItem(dialog, IDC_BROWSE_DISC), &spot); |
862 |
|
863 |
int code = TrackPopupMenuEx(data->popup, TPM_LEFTALIGN | |
864 |
TPM_TOPALIGN | TPM_NONOTIFY | TPM_RETURNCMD | TPM_RIGHTBUTTON, |
865 |
spot.x, spot.y, GetDlgItem(dialog, IDC_BROWSE_DISC), NULL); |
866 |
|
867 |
switch (code) |
868 |
{ |
869 |
case 1: |
870 |
do |
871 |
{ |
872 |
char scan[MAX_PATH]; |
873 |
int index = ListView_GetNextItem(GetDlgItem(dialog, |
874 |
IDC_BROWSE_DISC), previous, LVNI_SELECTED); |
875 |
|
876 |
previous = index; |
877 |
|
878 |
if (previous == -1) continue; |
879 |
|
880 |
ListView_GetItemText(GetDlgItem(dialog, IDC_BROWSE_DISC), |
881 |
index, 0, scan, MAX_PATH); |
882 |
ShellExecute(dialog, NULL, scan, NULL, NULL, |
883 |
SW_SHOWDEFAULT); |
884 |
} |
885 |
while (previous != -1); |
886 |
break; |
887 |
case 2: |
888 |
do |
889 |
{ |
890 |
char scan[MAX_PATH]; |
891 |
int index = ListView_GetNextItem(GetDlgItem(dialog, |
892 |
IDC_BROWSE_DISC), previous, LVNI_SELECTED); |
893 |
|
894 |
previous = index; |
895 |
|
896 |
if (previous == -1) continue; |
897 |
|
898 |
ListView_GetItemText(GetDlgItem(dialog, IDC_BROWSE_DISC), |
899 |
index, 0, scan, MAX_PATH); |
900 |
|
901 |
SHELLEXECUTEINFO info; |
902 |
|
903 |
info.cbSize = sizeof(info); |
904 |
info.fMask = SEE_MASK_INVOKEIDLIST; |
905 |
info.hwnd = dialog; |
906 |
info.lpVerb = "properties"; |
907 |
info.lpFile = scan; |
908 |
info.lpParameters = NULL; |
909 |
info.lpDirectory = NULL; |
910 |
info.nShow = SW_SHOWDEFAULT; |
911 |
info.lpIDList = NULL; |
912 |
|
913 |
ShellExecuteEx(&info); |
914 |
} |
915 |
while (previous != -1); |
916 |
break; |
917 |
} |
918 |
} |
919 |
break; |
920 |
} |
921 |
|
922 |
return FALSE; |
923 |
} |