ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/VTBFileUtil2/ScanUtility.cxx
(Generate patch)

Comparing trunk/VTBFileUtil2/ScanUtility.cxx (file contents):
Revision 260 by douglas, 2003-08-16T02:08:35-07:00 vs.
Revision 277 by douglas, 2003-08-24T00:31:45-07:00

# Line 2 | Line 2
2   //
3   // Douglas Thrift
4   //
5 < // $Id: ScanUtility.cxx,v 1.1 2003/08/16 09:08:35 douglas Exp $
5 > // $Id: ScanUtility.cxx,v 1.8 2003/08/24 07:31:45 douglas Exp $
6  
7   #include "ScanUtility.h"
8 +
9 + 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 +        loadDirs();
17 +
18 +        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 +        
43 +        // start
44 +        wizard[0].dwSize = sizeof(wizard[0]);
45 +        wizard[0].dwFlags = PSP_DEFAULT | PSP_USEHICON | PSP_USETITLE |
46 +                PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
47 +        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 +
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 +
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 +        wizard[2].lParam = number;
79 +        wizard[2].pszHeaderTitle = "Enter";
80 +        wizard[2].pszHeaderSubTitle = "Input the client information.";
81 + }
82 +
83 + ScanUtility::~ScanUtility()
84 + {
85 +        DestroyMenu(popup);
86 +        utilities.erase(number);
87 +        saveDirs();
88 +
89 +        delete [] title;
90 + }
91 +
92 + void ScanUtility::run(void)
93 + {
94 +        PROPSHEETHEADER header;
95 +
96 +        // header
97 +        header.dwSize = sizeof(header);
98 +        header.dwFlags = PSH_DEFAULT | PSH_HEADER | PSH_PROPSHEETPAGE |
99 +                PSH_USEICONID | PSH_WIZARD97;
100 +        header.hwndParent = NULL;
101 +        header.hInstance = gui.instance;
102 +        header.pszIcon = MAKEINTRESOURCE(IDI_VTB_ICON);
103 +        header.nPages = 3;
104 +        header.nStartPage = 0;
105 +        header.ppsp = wizard;
106 +        header.pszbmHeader = MAKEINTRESOURCE(IDB_VTB_BMP);
107 +
108 +        PropertySheet(&header);
109 + }
110 +
111 + unsigned ScanUtility::count = 0;
112 + map<unsigned, ScanUtility*> ScanUtility::utilities;
113 + map<HWND, ScanUtility*> ScanUtility::windows;
114 +
115 + void ScanUtility::loadDirs(void)
116 + {
117 +        HKEY key;
118 +
119 +        if (RegOpenKeyEx(HKEY_CURRENT_USER,
120 +                "Software\\DouglasThrift\\VTBFileUtil2", 0, KEY_QUERY_VALUE, &key) ==
121 +                ERROR_SUCCESS)
122 +        {
123 +                DWORD type;
124 +                char data[MAX_PATH];
125 +                DWORD size = MAX_PATH;
126 +
127 +                if (RegQueryValueEx(key, "ScanDir", NULL, &type, LPBYTE(data), &size)
128 +                        == ERROR_SUCCESS)
129 +                {
130 +                        data[size - 1] = '\0';
131 +
132 +                        switch (type)
133 +                        {
134 +                        case REG_EXPAND_SZ:
135 +                                {
136 +                                        char folder[MAX_PATH];
137 +
138 +                                        ExpandEnvironmentStrings(data, folder, MAX_PATH);
139 +
140 +                                        scanDir = folder;
141 +                                }
142 +                                break;
143 +                        case REG_SZ:
144 +                                scanDir = data;
145 +                                break;
146 +                        default:
147 +                                setScanDir();
148 +                                break;
149 +                        }
150 +                }
151 +                else
152 +                {
153 +                        setScanDir();
154 +                }
155 +
156 +                size = MAX_PATH;
157 +
158 +                if (RegQueryValueEx(key, "SaveDir", NULL, &type, LPBYTE(data), &size)
159 +                        == ERROR_SUCCESS)
160 +                {
161 +                        data[size - 1] = '\0';
162 +
163 +                        switch (type)
164 +                        {
165 +                        case REG_EXPAND_SZ:
166 +                                {
167 +                                        char folder[MAX_PATH];
168 +
169 +                                        ExpandEnvironmentStrings(data, folder, MAX_PATH);
170 +
171 +                                        saveDir = folder;
172 +                                }
173 +                                break;
174 +                        case REG_SZ:
175 +                                saveDir = data;
176 +                                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 +
195 +        if (debug) cerr << "scanDir = " << scanDir << "\n"
196 +                << "saveDir = " << saveDir << "\n";
197 + }
198 +
199 + void ScanUtility::saveDirs(void)
200 + {
201 +        HKEY key;
202 +
203 +        if (RegCreateKeyEx(HKEY_CURRENT_USER,
204 +                "Software\\DouglasThrift\\VTBFileUtil2", 0, NULL,
205 +                REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_SET_VALUE, NULL, &key,
206 +                NULL) == ERROR_SUCCESS)
207 +        {
208 +                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 +                {
215 +                        data[size - 1] = '\0';
216 +                }
217 +                else
218 +                {
219 +                        data[0] = '\0';
220 +                }
221 +
222 +                if (scanDir != data || type != REG_SZ)
223 +                {
224 +                        if (RegSetValueEx(key, "ScanDir", 0, REG_SZ,
225 +                                LPBYTE(scanDir.c_str()), scanDir.length() + 1) !=
226 +                                ERROR_SUCCESS)
227 +                        {
228 +                                error();
229 +                        }
230 +                }
231 +
232 +                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 +                if (saveDir != data || type != REG_SZ)
245 +                {
246 +                        if (RegSetValueEx(key, "SaveDir", 0, REG_SZ,
247 +                                LPBYTE(saveDir.c_str()), saveDir.length() + 1) !=
248 +                                ERROR_SUCCESS)
249 +                        {
250 +                                error();
251 +                        }
252 +                }
253 +
254 +                RegCloseKey(key);
255 +        }
256 +        else
257 +        {
258 +                error();
259 +        }
260 + }
261 +
262 + void ScanUtility::setScanDir(HWND parent)
263 + {
264 +        BROWSEINFO info;
265 +
266 +        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 +
316 +        if (debug) cerr << "scanDir = " << scanDir << "\n";
317 + }
318 +
319 + void ScanUtility::setSaveDir(HWND parent)
320 + {
321 +        BROWSEINFO info;
322 +
323 +        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 +
373 +        if (debug) cerr << "saveDir = " << saveDir << "\n";
374 + }
375 +
376 + 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 +                        item.iItem = 0;
435 +                        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 +
444 +                ListView_SetItemState(GetDlgItem(parent, IDC_SELECT_SCANS), 0,
445 +                        LVIS_SELECTED, LVIS_SELECTED);
446 +        }
447 + }
448 +
449 + 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 + 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 +                SendMessage(dialog, BFFM_SETSELECTION, TRUE, LPARAM(HIWORD(d) ?
479 +                        data->scanDir.c_str() : data->saveDir.c_str()));
480 +                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 + INT_PTR ScanUtility::start(HWND dialog, UINT msg, WPARAM w, LPARAM l)
510 + {
511 +        ScanUtility* data = which(dialog);
512 +
513 +        switch (msg)
514 +        {
515 +        case WM_INITDIALOG:
516 +                center(GetParent(dialog));
517 +                SendMessage(GetParent(dialog), WM_SETICON, ICON_BIG, LPARAM(gui.icon));
518 +                
519 +                data = which(dialog, l);
520 +
521 +                {
522 +                        ostringstream instructions;
523 +
524 +                        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 +
529 +                        SetDlgItemText(dialog, IDC_START_INSTRUCTIONS,
530 +                                instructions.str().c_str());
531 +                }
532 +                break;
533 +        case WM_NOTIFY:
534 +                {
535 +                        LPNMHDR nm = LPNMHDR(l);
536 +
537 +                        switch (nm->code)
538 +                        {
539 +                        case PSN_SETACTIVE:
540 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_NEXT);
541 +                                {
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 +                                break;
550 +                        case PSN_WIZNEXT:
551 +                                SetCurrentDirectory(data->scanDir.c_str());
552 +                                break;
553 +                        }
554 +                }
555 +                break;
556 +        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 +        }
580 +
581 +        return FALSE;
582 + }
583 +
584 + INT_PTR ScanUtility::select(HWND dialog, UINT msg, WPARAM w, LPARAM l)
585 + {
586 +        ScanUtility* data = which(dialog);
587 +
588 +        switch (msg)
589 +        {
590 +        case WM_INITDIALOG:
591 +                data = which(dialog, l);
592 +
593 +                {
594 +                        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 +
601 +                {
602 +                        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 +                        LPNMITEMACTIVATE ni = LPNMITEMACTIVATE(l);
617 +
618 +                        switch (ni->hdr.code)
619 +                        {
620 +                        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 +                                break;
630 +                        }
631 +                }
632 +                else
633 +                {
634 +                        LPNMHDR nm = LPNMHDR(l);
635 +
636 +                        switch (nm->code)
637 +                        {
638 +                        case PSN_SETACTIVE:
639 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
640 +                                        PSWIZB_NEXT);
641 +                                data->populate(dialog);
642 +                                break;
643 +                        case PSN_WIZBACK:
644 +                                ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
645 +                                data->client.setFile("");
646 +                                break;
647 +                        case PSN_WIZNEXT:
648 +                                {
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 +
659 +                                ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
660 +
661 +                                if (debug) cerr << "scan = " << data->scan << "\n";
662 +                                break;
663 +                        }
664 +                }
665 +                break;
666 +        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 +                break;
738 +        }
739 +
740 +        return FALSE;
741 + }
742 +
743 + INT_PTR ScanUtility::enter(HWND dialog, UINT msg, WPARAM w, LPARAM l)
744 + {
745 +        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 +        return FALSE;
855 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines