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

Comparing trunk/VTBFileUtil2/ScanUtility.cxx (file contents):
Revision 271 by douglas, 2003-08-19T22:49:34-07:00 vs.
Revision 281 by douglas, 2003-08-25T14:56:30-07:00

# Line 2 | Line 2
2   //
3   // Douglas Thrift
4   //
5 < // $Id: ScanUtility.cxx,v 1.5 2003/08/20 05:49:34 douglas Exp $
5 > // $Id: ScanUtility.cxx,v 1.10 2003/08/25 21:56:30 douglas Exp $
6  
7   #include "ScanUtility.h"
8  
# Line 14 | Line 14 | ScanUtility::ScanUtility()
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]);
# Line 27 | Line 52 | ScanUtility::ScanUtility()
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 +        // confirm
83 +        wizard[3].dwSize = sizeof(wizard[3]);
84 +        wizard[3].dwFlags = PSP_DEFAULT | PSP_USEHICON | PSP_USETITLE |
85 +                PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
86 +        wizard[3].hInstance = gui.instance;
87 +        wizard[3].pszTemplate = MAKEINTRESOURCE(IDD_CONFIRM);
88 +        wizard[3].hIcon = gui.icon;
89 +        wizard[3].pszTitle = title;
90 +        wizard[3].pfnDlgProc = confirm;
91 +        wizard[3].lParam = number;
92 +        wizard[3].pszHeaderTitle = "Confirm";
93 +        wizard[3].pszHeaderSubTitle = "Make sure the file information is correct.";
94 +
95 +        // complete
96 +        wizard[4].dwSize = sizeof(wizard[3]);
97 +        wizard[4].dwFlags = PSP_DEFAULT | PSP_USEHICON | PSP_USETITLE |
98 +                PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
99 +        wizard[4].hInstance = gui.instance;
100 +        wizard[4].pszTemplate = MAKEINTRESOURCE(IDD_DONE);
101 +        wizard[4].hIcon = gui.icon;
102 +        wizard[4].pszTitle = title;
103 +        wizard[4].pfnDlgProc = done;
104 +        wizard[4].lParam = number;
105 +        wizard[4].pszHeaderTitle = "Done";
106 +        wizard[4].pszHeaderSubTitle = "Exit or start over for another scan.";
107   }
108  
109   ScanUtility::~ScanUtility()
110   {
111 +        DestroyMenu(popup);
112          utilities.erase(number);
113          saveDirs();
114  
# Line 44 | Line 122 | void ScanUtility::run(void)
122          // header
123          header.dwSize = sizeof(header);
124          header.dwFlags = PSH_DEFAULT | PSH_HEADER | PSH_PROPSHEETPAGE |
125 <                PSH_USEICONID | PSH_WIZARD97;
125 >                PSH_USEICONID | PSH_WIZARD97 | PSH_WIZARDHASFINISH;
126          header.hwndParent = NULL;
127          header.hInstance = gui.instance;
128          header.pszIcon = MAKEINTRESOURCE(IDI_VTB_ICON);
129 <        header.nPages = 1;
129 >        header.nPages = 5;
130          header.nStartPage = 0;
131          header.ppsp = wizard;
132          header.pszbmHeader = MAKEINTRESOURCE(IDB_VTB_BMP);
# Line 80 | Line 158 | void ScanUtility::loadDirs(void)
158                          switch (type)
159                          {
160                          case REG_EXPAND_SZ:
161 <                                scanDir = data;
162 <                                scanEnv = true;
161 >                                {
162 >                                        char folder[MAX_PATH];
163 >
164 >                                        ExpandEnvironmentStrings(data, folder, MAX_PATH);
165 >
166 >                                        scanDir = folder;
167 >                                }
168                                  break;
169                          case REG_SZ:
170                                  scanDir = data;
88                                scanEnv = false;
171                                  break;
172                          default:
173                                  setScanDir();
# Line 107 | Line 189 | void ScanUtility::loadDirs(void)
189                          switch (type)
190                          {
191                          case REG_EXPAND_SZ:
192 <                                saveDir = data;
193 <                                saveEnv = true;
192 >                                {
193 >                                        char folder[MAX_PATH];
194 >
195 >                                        ExpandEnvironmentStrings(data, folder, MAX_PATH);
196 >
197 >                                        saveDir = folder;
198 >                                }
199                                  break;
200                          case REG_SZ:
201                                  saveDir = data;
115                                saveEnv = false;
202                                  break;
203                          default:
204                                  setSaveDir();
# Line 133 | Line 219 | void ScanUtility::loadDirs(void)
219          }
220  
221          if (debug) cerr << "scanDir = " << scanDir << "\n"
222 <                << "scanEnv = " << scanEnv << "\n"
137 <                << "saveDir = " << saveDir << "\n"
138 <                << "saveEnv = " << saveEnv << "\n";
222 >                << "saveDir = " << saveDir << "\n";
223   }
224  
225   void ScanUtility::saveDirs(void)
# Line 161 | Line 245 | void ScanUtility::saveDirs(void)
245                          data[0] = '\0';
246                  }
247  
248 <                if (scanDir != data || type != (scanEnv ? REG_EXPAND_SZ : REG_SZ))
248 >                if (scanDir != data || type != REG_SZ)
249                  {
250 <                        if (RegSetValueEx(key, "ScanDir", 0, scanEnv ? REG_EXPAND_SZ :
251 <                                REG_SZ, LPBYTE(scanDir.c_str()), scanDir.length() + 1) !=
250 >                        if (RegSetValueEx(key, "ScanDir", 0, REG_SZ,
251 >                                LPBYTE(scanDir.c_str()), scanDir.length() + 1) !=
252                                  ERROR_SUCCESS)
253                          {
254                                  error();
# Line 183 | Line 267 | void ScanUtility::saveDirs(void)
267                          data[0] = '\0';
268                  }
269  
270 <                if (saveDir != data || type != (saveEnv ? REG_EXPAND_SZ : REG_SZ))
270 >                if (saveDir != data || type != REG_SZ)
271                  {
272 <                        if (RegSetValueEx(key, "SaveDir", 0, saveEnv ? REG_EXPAND_SZ :
273 <                                REG_SZ, LPBYTE(saveDir.c_str()), saveDir.length() + 1) !=
272 >                        if (RegSetValueEx(key, "SaveDir", 0, REG_SZ,
273 >                                LPBYTE(saveDir.c_str()), saveDir.length() + 1) !=
274                                  ERROR_SUCCESS)
275                          {
276                                  error();
# Line 225 | Line 309 | void ScanUtility::setScanDir(HWND parent
309                          if (SHGetPathFromIDList(id, folder))
310                          {
311                                  scanDir = folder;
228                                scanEnv = false;
312                          }
313                  }
314  
# Line 255 | Line 338 | void ScanUtility::setScanDir(HWND parent
338                  }
339          }
340          while (scanDir == "");
341 +
342 +        if (debug) cerr << "scanDir = " << scanDir << "\n";
343   }
344  
345   void ScanUtility::setSaveDir(HWND parent)
# Line 281 | Line 366 | void ScanUtility::setSaveDir(HWND parent
366                          if (SHGetPathFromIDList(id, folder))
367                          {
368                                  saveDir = folder;
284                                saveEnv = false;
369                          }
370                  }
371  
# Line 311 | Line 395 | void ScanUtility::setSaveDir(HWND parent
395                  }
396          }
397          while (saveDir == "");
398 +
399 +        if (debug) cerr << "saveDir = " << saveDir << "\n";
400 + }
401 +
402 + void ScanUtility::populate(HWND parent)
403 + {
404 +        set<string> scans;
405 +
406 +        do
407 +        {
408 +                string scan = scanDir + "\\SCAN????_000." +
409 +                        IndividualClient::getExtension();
410 +                WIN32_FIND_DATA found;
411 +                HANDLE finder = FindFirstFile(scan.c_str(), &found);
412 +
413 +                if (finder != INVALID_HANDLE_VALUE)
414 +                {
415 +                        do
416 +                        {
417 +                                scans.insert(found.cFileName);
418 +                        }
419 +                        while (FindNextFile(finder, &found));
420 +
421 +                        FindClose(finder);
422 +                }
423 +
424 +                if (scans.empty())
425 +                {
426 +                        if (MessageBox(parent, "No scanned documents found.",
427 +                                programName.c_str(), MB_RETRYCANCEL | MB_ICONQUESTION) ==
428 +                                IDCANCEL) break;
429 +                }
430 +        }
431 +        while (scans.empty());
432 +
433 +        if (scans.empty())
434 +        {
435 +                PropSheet_PressButton(GetParent(parent), PSBTN_BACK);
436 +        }
437 +        else
438 +        {
439 +                SHFILEINFO info;
440 +                HIMAGELIST icons = HIMAGELIST(SHGetFileInfo((*scans.begin()).c_str(),
441 +                        0, &info, sizeof(info), SHGFI_SMALLICON | SHGFI_SYSICONINDEX));
442 +
443 +                ListView_SetImageList(GetDlgItem(parent, IDC_SELECT_SCANS), icons,
444 +                        LVSIL_SMALL);
445 +
446 +                if (debug) cerr << "scans = {\n";
447 +
448 +                for (set<string>::iterator itor = scans.begin(); itor != scans.end();
449 +                        itor++)
450 +                {
451 +                        if (debug) cerr << "   " << *itor << "\n";
452 +
453 +                        char scan[MAX_PATH];
454 +
455 +                        sprintf(scan, "%s", (*itor).c_str());
456 +
457 +                        LVITEM item;
458 +
459 +                        item.mask = LVIF_IMAGE | LVIF_TEXT;
460 +                        item.iItem = 0;
461 +                        item.iSubItem = 0;
462 +                        item.pszText = scan;
463 +                        item.iImage = info.iIcon;
464 +
465 +                        ListView_InsertItem(GetDlgItem(parent, IDC_SELECT_SCANS), &item);
466 +                }
467 +
468 +                if (debug) cerr << "}\n";
469 +
470 +                ListView_SetItemState(GetDlgItem(parent, IDC_SELECT_SCANS), 0,
471 +                        LVIS_SELECTED, LVIS_SELECTED);
472 +        }
473 + }
474 +
475 + ScanUtility* ScanUtility::which(HWND window)
476 + {
477 +        map<HWND, ScanUtility*>::iterator itor = windows.find(window);
478 +
479 +        return itor->second;
480 + }
481 +
482 + ScanUtility* ScanUtility::which(HWND window, LPARAM l)
483 + {
484 +        LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l);
485 +        map<unsigned, ScanUtility*>::iterator itor = utilities.find(page->lParam);
486 +
487 +        windows.insert(pair<HWND, ScanUtility*>(window, itor->second));
488 +
489 +        return itor->second;
490   }
491  
492   int ScanUtility::browse(HWND dialog, UINT msg, LPARAM l, LPARAM d)
# Line 325 | Line 501 | int ScanUtility::browse(HWND dialog, UIN
501                  SendMessage(dialog, BFFM_SETOKTEXT, 0,
502                          LPARAM(toWide("&Select").c_str()));
503                  SendMessage(dialog, BFFM_SETEXPANDED, FALSE, CSIDL_DRIVES);
504 <                if (HIWORD(d) ? data->scanEnv : data->saveEnv)
505 <                {
330 <                        char folder[MAX_PATH];
331 <
332 <                        ExpandEnvironmentStrings(HIWORD(d) ? data->scanDir.c_str() :
333 <                                data->saveDir.c_str(), folder, MAX_PATH);
334 <                        SendMessage(dialog, BFFM_SETSELECTION, TRUE, LPARAM(folder));
335 <                }
336 <                else
337 <                {
338 <                        SendMessage(dialog, BFFM_SETSELECTION, TRUE, LPARAM(HIWORD(d) ?
339 <                                data->scanDir.c_str() : data->saveDir.c_str()));
340 <                }
504 >                SendMessage(dialog, BFFM_SETSELECTION, TRUE, LPARAM(HIWORD(d) ?
505 >                        data->scanDir.c_str() : data->saveDir.c_str()));
506                  break;
507          case BFFM_SELCHANGED:
508                  {
# Line 369 | Line 534 | int ScanUtility::browse(HWND dialog, UIN
534  
535   INT_PTR ScanUtility::start(HWND dialog, UINT msg, WPARAM w, LPARAM l)
536   {
537 <        map<HWND, ScanUtility*>::iterator itor = windows.find(dialog);
373 <        ScanUtility* data = itor->second;
537 >        ScanUtility* data = which(dialog);
538  
539          switch (msg)
540          {
541          case WM_INITDIALOG:
542                  center(GetParent(dialog));
543 +                SendMessage(GetParent(dialog), WM_SETICON, ICON_BIG, LPARAM(gui.icon));
544 +                
545 +                data = which(dialog, l);
546 +
547                  {
548 <                        LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l);
549 <                        map<unsigned, ScanUtility*>::iterator itor =
550 <                                utilities.find(page->lParam);
548 >                        ostringstream instructions;
549 >
550 >                        instructions << "1. If you need instructions, you should not be ru"
551 >                                << "nning this program in Scan Utility mode.\n"
552 >                                << "2. Otherwise, go forth and scan.\n"
553 >                                << "3. Then come back and click Next.\n";
554  
555 <                        windows.insert(pair<HWND, ScanUtility*>(dialog, itor->second));
555 >                        SetDlgItemText(dialog, IDC_START_INSTRUCTIONS,
556 >                                instructions.str().c_str());
557                  }
558                  break;
559          case WM_NOTIFY:
560                  {
561 <                        LPNMHDR nm = (LPNMHDR) l;
561 >                        LPNMHDR nm = LPNMHDR(l);
562  
563                          switch (nm->code)
564                          {
565                          case PSN_SETACTIVE:
566 <                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_NEXT);
566 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_FINISH |
567 >                                        PSWIZB_NEXT);
568 >
569                                  {
570                                          char folder[44];
571  
# Line 401 | Line 575 | INT_PTR ScanUtility::start(HWND dialog,
575                                          SetDlgItemText(dialog, IDC_START_SAVE_TEXT, folder);
576                                  }
577                                  break;
578 +                        case PSN_WIZNEXT:
579 +                                SetCurrentDirectory(data->scanDir.c_str());
580 +                                break;
581                          }
582                  }
583                  break;
# Line 428 | Line 605 | INT_PTR ScanUtility::start(HWND dialog,
605                  }
606                  break;
607          }
608 +
609 +        return FALSE;
610 + }
611 +
612 + INT_PTR ScanUtility::select(HWND dialog, UINT msg, WPARAM w, LPARAM l)
613 + {
614 +        ScanUtility* data = which(dialog);
615 +
616 +        switch (msg)
617 +        {
618 +        case WM_INITDIALOG:
619 +                data = which(dialog, l);
620 +
621 +                {
622 +                        ostringstream select;
623 +
624 +                        select << "Select the scanned document that you need to be save.";
625 +
626 +                        SetDlgItemText(dialog, IDC_SELECT_TEXT, select.str().c_str());
627 +                }
628 +
629 +                {
630 +                        LVCOLUMN column;
631 +
632 +                        column.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
633 +                        column.fmt = LVCFMT_IMAGE;
634 +                        column.cx = 120;
635 +                        column.pszText = "Scanned Documents";
636 +
637 +                        ListView_InsertColumn(GetDlgItem(dialog, IDC_SELECT_SCANS), 0,
638 +                                &column);
639 +                }
640 +                break;
641 +        case WM_NOTIFY:
642 +                if (w == IDC_SELECT_SCANS)
643 +                {
644 +                        LPNMITEMACTIVATE ni = LPNMITEMACTIVATE(l);
645 +
646 +                        switch (ni->hdr.code)
647 +                        {
648 +                        case NM_DBLCLK:
649 +                                {
650 +                                        char scan[MAX_PATH];
651 +
652 +                                        ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS),
653 +                                                ni->iItem, 0, scan, MAX_PATH);
654 +                                        ShellExecute(dialog, NULL, scan, NULL, NULL,
655 +                                                SW_SHOWDEFAULT);
656 +                                }
657 +                                break;
658 +                        }
659 +                }
660 +                else
661 +                {
662 +                        LPNMHDR nm = LPNMHDR(l);
663 +
664 +                        switch (nm->code)
665 +                        {
666 +                        case PSN_SETACTIVE:
667 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
668 +                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
669 +                                data->populate(dialog);
670 +                                break;
671 +                        case PSN_WIZBACK:
672 +                                ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
673 +                                data->client.setFile("");
674 +                                break;
675 +                        case PSN_WIZNEXT:
676 +                                {
677 +                                        int index = ListView_GetNextItem(GetDlgItem(dialog,
678 +                                                IDC_SELECT_SCANS), -1, LVNI_SELECTED);
679 +                                        char scan[MAX_PATH];
680 +
681 +                                        ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS),
682 +                                                index, 0, scan, MAX_PATH);
683 +
684 +                                        data->scan = scan;
685 +                                }
686 +
687 +                                ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
688 +
689 +                                if (debug) cerr << "scan = " << data->scan << "\n";
690 +                                break;
691 +                        }
692 +                }
693 +                break;
694 +        case WM_CONTEXTMENU:
695 +                {
696 +                        char scan[MAX_PATH];
697 +                        POINT spot;
698 +                        LVHITTESTINFO test;
699 +
700 +                        test.pt.x = GET_X_LPARAM(l);
701 +                        test.pt.y = GET_Y_LPARAM(l);
702 +
703 +                        ScreenToClient(GetDlgItem(dialog, IDC_SELECT_SCANS), &test.pt);
704 +                        ListView_HitTest(GetDlgItem(dialog, IDC_SELECT_SCANS), &test);
705 +
706 +                        if (test.iItem != -1)
707 +                        {
708 +                                ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS),
709 +                                        test.iItem, 0, scan, MAX_PATH);
710 +                                
711 +                                spot.x = test.pt.x;
712 +                                spot.y = test.pt.y;
713 +                        }
714 +                        else if (GET_X_LPARAM(l) == -1 && GET_Y_LPARAM(l) == -1)
715 +                        {
716 +                                int index = ListView_GetNextItem(GetDlgItem(dialog,
717 +                                        IDC_SELECT_SCANS), -1, LVNI_SELECTED);
718 +                                RECT rect;
719 +
720 +                                ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS),
721 +                                        index, 0, scan, MAX_PATH);
722 +                                ListView_EnsureVisible(GetDlgItem(dialog, IDC_SELECT_SCANS),
723 +                                        index, FALSE);
724 +                                ListView_GetItemRect(GetDlgItem(dialog, IDC_SELECT_SCANS),
725 +                                        index, &rect, LVIR_SELECTBOUNDS);
726 +
727 +                                spot.x = rect.left;
728 +                                spot.y = rect.top;
729 +                        }
730 +                        else
731 +                        {
732 +                                break;
733 +                        }
734 +
735 +                        ClientToScreen(GetDlgItem(dialog, IDC_SELECT_SCANS), &spot);
736 +
737 +                        int code = TrackPopupMenuEx(data->popup, TPM_LEFTALIGN |
738 +                                TPM_TOPALIGN | TPM_NONOTIFY | TPM_RETURNCMD | TPM_RIGHTBUTTON,
739 +                                spot.x, spot.y, GetDlgItem(dialog, IDC_SELECT_SCANS), NULL);
740 +
741 +                        switch (code)
742 +                        {
743 +                        case 1:
744 +                                ShellExecute(dialog, NULL, scan, NULL, NULL, SW_SHOWDEFAULT);
745 +                                break;
746 +                        case 2:
747 +                                {
748 +                                        SHELLEXECUTEINFO info;
749 +
750 +                                        info.cbSize = sizeof(info);
751 +                                        info.fMask = SEE_MASK_INVOKEIDLIST;
752 +                                        info.hwnd = dialog;
753 +                                        info.lpVerb = "properties";
754 +                                        info.lpFile = scan;
755 +                                        info.lpParameters = NULL;
756 +                                        info.lpDirectory = NULL;
757 +                                        info.nShow = SW_SHOWDEFAULT;
758 +                                        info.lpIDList = NULL;
759 +
760 +                                        ShellExecuteEx(&info);
761 +                                }
762 +                                break;
763 +                        }
764 +                }
765 +                break;
766 +        }
767 +
768 +        return FALSE;
769 + }
770 +
771 + INT_PTR ScanUtility::enter(HWND dialog, UINT msg, WPARAM w, LPARAM l)
772 + {
773 +        ScanUtility* data = which(dialog);
774 +
775 +        switch (msg)
776 +        {
777 +        case WM_INITDIALOG:
778 +                data = which(dialog, l);
779 +
780 +                {
781 +                        ostringstream enter;
782 +
783 +                        enter << "Enter the client name and number.";
784 +
785 +                        SetDlgItemText(dialog, IDC_ENTER_TEXT, enter.str().c_str());
786 +                }
787 +                break;
788 +        case WM_NOTIFY:
789 +                {
790 +                        LPNMHDR nm = LPNMHDR(l);
791 +
792 +                        switch (nm->code)
793 +                        {
794 +                        case PSN_SETACTIVE:
795 +                                if (data->client.getName() != "" && data->client.getNumber() !=
796 +                                        0)
797 +                                {
798 +                                        PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
799 +                                                PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
800 +                                }
801 +                                else
802 +                                {
803 +                                        PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
804 +                                                PSWIZB_DISABLEDFINISH);
805 +                                }
806 +
807 +                                SetDlgItemText(dialog, IDC_ENTER_NAME,
808 +                                        data->client.getName().c_str());
809 +
810 +                                if (data->client.getNumber() != 0)
811 +                                {
812 +                                        SetDlgItemInt(dialog, IDC_ENTER_NUM,
813 +                                                data->client.getNumber(), FALSE);
814 +                                }
815 +                                else
816 +                                {
817 +                                        SetDlgItemText(dialog, IDC_ENTER_NUM, "");
818 +                                }
819 +                                break;
820 +                        case PSN_WIZBACK:
821 +                                break;
822 +                        case PSN_WIZNEXT:
823 +                                if (debug)
824 +                                {
825 +                                        cerr << "client = {\n"
826 +                                                << "   name = " << data->client.getName() << "\n"
827 +                                                << "   number = " << data->client.getNumber() << "\n"
828 +                                                << "   file = " << data->client.getFile() << "\n"
829 +                                                << "}\n";
830 +                                }
831 +
832 +                                data->save = data->saveDir + '\\' + data->client.getFile();
833 +
834 +                                if (debug) cerr << "save = " << data->save << "\n";
835 +                                
836 +                                break;
837 +                        }
838 +                }
839 +                break;
840 +        case WM_COMMAND:
841 +                switch (LOWORD(w))
842 +                {
843 +                case IDC_ENTER_NAME:
844 +                        {
845 +                                char name[BUFSIZ];
846 +
847 +                                GetDlgItemText(dialog, IDC_ENTER_NAME, name, BUFSIZ);
848 +
849 +                                if (name != data->client.getName())
850 +                                {
851 +                                        data->client.setName(name);
852 +                                }
853 +                        }
854 +
855 +                        if (data->client.getName() != "" && data->client.getNumber() != 0)
856 +                        {
857 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
858 +                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
859 +                        }
860 +                        else
861 +                        {
862 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
863 +                                        PSWIZB_DISABLEDFINISH);
864 +                        }
865 +                        break;
866 +                case IDC_ENTER_NUM:
867 +                        {
868 +                                unsigned number = GetDlgItemInt(dialog, IDC_ENTER_NUM, NULL,
869 +                                        FALSE);
870 +
871 +                                if (number != data->client.getNumber())
872 +                                {
873 +                                        data->client.setNumber(number);
874 +                                }
875 +                        }
876 +
877 +                        if (data->client.getName() != "" && data->client.getNumber() != 0)
878 +                        {
879 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
880 +                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
881 +                        }
882 +                        else
883 +                        {
884 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
885 +                                        PSWIZB_DISABLEDFINISH);
886 +                        }
887 +                        break;
888 +                }
889 +                break;
890 +        }
891 +
892 +        return FALSE;
893 + }
894 +
895 + INT_PTR ScanUtility::confirm(HWND dialog, UINT msg, WPARAM w, LPARAM l)
896 + {
897 +        ScanUtility* data = which(dialog);
898 +
899 +        switch (msg)
900 +        {
901 +        case WM_INITDIALOG:
902 +                data = which(dialog, l);
903 +
904 +                {
905 +                        ostringstream confirm;
906 +
907 +                        confirm << "Confirm the client file\'s name and size.";
908 +
909 +                        SetDlgItemText(dialog, IDC_CONFIRM_TEXT, confirm.str().c_str());
910 +                }
911 +                break;
912 +        case WM_NOTIFY:
913 +                {
914 +                        LPNMHDR nm = LPNMHDR(l);
915 +
916 +                        switch (nm->code)
917 +                        {
918 +                        case PSN_SETACTIVE:
919 +                                CheckDlgButton(dialog, IDC_CONFIRM_GOOD, BST_UNCHECKED);
920 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
921 +                                        PSWIZB_DISABLEDFINISH);
922 +                                SetDlgItemText(dialog, IDC_CONFIRM_FILE,
923 +                                        data->client.getFile().c_str());
924 +
925 +                                {
926 +                                        HANDLE scan = CreateFile(data->scan.c_str(), GENERIC_READ,
927 +                                                FILE_SHARE_READ, NULL, OPEN_EXISTING,
928 +                                                FILE_ATTRIBUTE_NORMAL, NULL);
929 +                                        DWORD bytes = GetFileSize(scan, NULL);
930 +
931 +                                        CloseHandle(scan);
932 +
933 +                                        ostringstream size;
934 +
935 +                                        size << format(bytes);
936 +
937 +                                        size.setf(ios_base::fixed, ios_base::floatfield);
938 +                                        size.precision(2);
939 +                                        
940 +                                        FLOAT megabytes = FLOAT(bytes) / FLOAT(1024 * 1024);
941 +
942 +                                        size << " bytes (" << megabytes << " MB)";
943 +
944 +                                        SetDlgItemText(dialog, IDC_CONFIRM_SIZE,
945 +                                                size.str().c_str());
946 +                                }
947 +                                break;
948 +                        case PSN_WIZBACK:
949 +                                break;
950 +                        case PSN_WIZNEXT:
951 +                                if (MoveFile(data->scan.c_str(), data->save.c_str()) == 0)
952 +                                {
953 +                                        do
954 +                                        {
955 +                                                LPVOID message;
956 +                                                
957 +                                                FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
958 +                                                        FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
959 +                                                        LPTSTR(&message), 0, NULL);
960 +
961 +                                                int code = MessageBox(dialog, LPCTSTR(message),
962 +                                                        programName.c_str(), MB_RETRYCANCEL |
963 +                                                        MB_ICONEXCLAMATION);
964 +
965 +                                                LocalFree(message);
966 +
967 +                                                if (code == IDCANCEL)
968 +                                                {
969 +                                                        PropSheet_PressButton(GetParent(dialog),
970 +                                                                PSBTN_BACK);
971 +                                                        break;
972 +                                                }
973 +                                        }
974 +                                        while (MoveFileEx(data->scan.c_str(), data->save.c_str(),
975 +                                                MOVEFILE_REPLACE_EXISTING) == 0);
976 +                                }
977 +                                break;
978 +                        }
979 +                }
980 +                break;
981 +        case WM_COMMAND:
982 +                switch (LOWORD(w))
983 +                {
984 +                case IDC_CONFIRM_GOOD:
985 +                        if (IsDlgButtonChecked(dialog, IDC_CONFIRM_GOOD) == BST_CHECKED)
986 +                        {
987 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
988 +                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
989 +                        }
990 +                        else
991 +                        {
992 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
993 +                                        PSWIZB_DISABLEDFINISH);
994 +                        }
995 +                        break;
996 +                }
997 +                break;
998 +        }
999 +
1000 +        return FALSE;
1001 + }
1002 +
1003 + INT_PTR ScanUtility::done(HWND dialog, UINT msg, WPARAM w, LPARAM l)
1004 + {
1005 +        ScanUtility* data = which(dialog);
1006 +
1007 +        switch (msg)
1008 +        {
1009 +        case WM_INITDIALOG:
1010 +                data = which(dialog, l);
1011 +
1012 +                {
1013 +                        ostringstream done;
1014 +
1015 +                        done << "You are done saving the scanned document. Click Finish to"
1016 +                                << " exit or click Back to return to the beginning.";
1017 +
1018 +                        SetDlgItemText(dialog, IDC_DONE_TEXT, done.str().c_str());
1019 +                }
1020 +                break;
1021 +        case WM_NOTIFY:
1022 +                {
1023 +                        LPNMHDR nm = LPNMHDR(l);
1024 +
1025 +                        switch (nm->code)
1026 +                        {
1027 +                        case PSN_SETACTIVE:
1028 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
1029 +                                        PSWIZB_FINISH);
1030 +                                break;
1031 +                        case PSN_WIZBACK:
1032 +                                data->client.setFile("");
1033 +                                PropSheet_SetCurSelByID(GetParent(dialog), IDD_START);
1034 +                                break;
1035 +                        case PSN_WIZFINISH:
1036 +                                break;
1037 +                        }
1038 +                }
1039 +                break;
1040 +        }
1041  
1042          return FALSE;
1043   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines