ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/VTBFileUtil2/ScanUtility.cxx
Revision: 277
Committed: 2003-08-24T00:31:45-07:00 (21 years, 10 months ago) by douglas
File size: 18018 byte(s)
Log Message:
Did work.

File Contents

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