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 273 by douglas, 2003-08-20T23:29:24-07:00 vs.
Revision 282 by douglas, 2003-08-25T23:41:12-07:00

# Line 2 | Line 2
2   //
3   // Douglas Thrift
4   //
5 < // $Id: ScanUtility.cxx,v 1.6 2003/08/21 06:29:24 douglas Exp $
5 > // $Id: ScanUtility.cxx,v 1.11 2003/08/26 06:41:12 douglas Exp $
6  
7   #include "ScanUtility.h"
8  
9 < ScanUtility::ScanUtility()
9 > ScanUtility::ScanUtility() : DiscBrowse()
10   {
11          number = count++;
12 +
13          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 <        
15 >        title = programName + " - Scan Utility";
16 >
17          // start
18          wizard[0].dwSize = sizeof(wizard[0]);
19 <        wizard[0].dwFlags = PSP_DEFAULT | PSP_USEHICON | PSP_USETITLE |
20 <                PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
19 >        wizard[0].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE |
20 >                PSP_USEHEADERSUBTITLE;
21          wizard[0].hInstance = gui.instance;
22          wizard[0].pszTemplate = MAKEINTRESOURCE(IDD_START);
23 <        wizard[0].hIcon = gui.icon;
25 <        wizard[0].pszTitle = title;
23 >        wizard[0].pszTitle = title.c_str();
24          wizard[0].pfnDlgProc = start;
25          wizard[0].lParam = number;
26          wizard[0].pszHeaderTitle = "Start";
# Line 30 | Line 28 | ScanUtility::ScanUtility()
28  
29          // select
30          wizard[1].dwSize = sizeof(wizard[1]);
31 <        wizard[1].dwFlags = PSP_DEFAULT | PSP_USEHICON | PSP_USETITLE |
32 <                PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
31 >        wizard[1].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE |
32 >                PSP_USEHEADERSUBTITLE;
33          wizard[1].hInstance = gui.instance;
34          wizard[1].pszTemplate = MAKEINTRESOURCE(IDD_SELECT);
35 <        wizard[1].hIcon = gui.icon;
38 <        wizard[1].pszTitle = title;
35 >        wizard[1].pszTitle = title.c_str();
36          wizard[1].pfnDlgProc = select;
37          wizard[1].lParam = number;
38          wizard[1].pszHeaderTitle = "Select";
39          wizard[1].pszHeaderSubTitle = "Choose the scanned document to save.";
40 +
41 +        // enter
42 +        wizard[2].dwSize = sizeof(wizard[2]);
43 +        wizard[2].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE |
44 +                PSP_USEHEADERSUBTITLE;
45 +        wizard[2].hInstance = gui.instance;
46 +        wizard[2].pszTemplate = MAKEINTRESOURCE(IDD_ENTER);
47 +        wizard[2].pszTitle = title.c_str();
48 +        wizard[2].pfnDlgProc = enter;
49 +        wizard[2].lParam = number;
50 +        wizard[2].pszHeaderTitle = "Enter";
51 +        wizard[2].pszHeaderSubTitle = "Input the client information.";
52 +
53 +        // confirm
54 +        wizard[3].dwSize = sizeof(wizard[3]);
55 +        wizard[3].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE |
56 +                PSP_USEHEADERSUBTITLE;
57 +        wizard[3].hInstance = gui.instance;
58 +        wizard[3].pszTemplate = MAKEINTRESOURCE(IDD_CONFIRM);
59 +        wizard[3].pszTitle = title.c_str();
60 +        wizard[3].pfnDlgProc = confirm;
61 +        wizard[3].lParam = number;
62 +        wizard[3].pszHeaderTitle = "Confirm";
63 +        wizard[3].pszHeaderSubTitle = "Make sure the file information is correct.";
64 +
65 +        // complete
66 +        wizard[4].dwSize = sizeof(wizard[3]);
67 +        wizard[4].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE |
68 +                PSP_USEHEADERSUBTITLE;
69 +        wizard[4].hInstance = gui.instance;
70 +        wizard[4].pszTemplate = MAKEINTRESOURCE(IDD_DONE);
71 +        wizard[4].pszTitle = title.c_str();
72 +        wizard[4].pfnDlgProc = done;
73 +        wizard[4].lParam = number;
74 +        wizard[4].pszHeaderTitle = "Done";
75 +        wizard[4].pszHeaderSubTitle = "Exit or start over for another scan.";
76   }
77  
78   ScanUtility::~ScanUtility()
79   {
80          utilities.erase(number);
48        saveDirs();
49
50        delete [] title;
81   }
82  
83   void ScanUtility::run(void)
84   {
85 +        loadDirs();
86 +
87          PROPSHEETHEADER header;
88  
89          // header
90          header.dwSize = sizeof(header);
91          header.dwFlags = PSH_DEFAULT | PSH_HEADER | PSH_PROPSHEETPAGE |
92 <                PSH_USEICONID | PSH_WIZARD97;
92 >                PSH_USEICONID | PSH_WIZARD97 | PSH_WIZARDHASFINISH;
93          header.hwndParent = NULL;
94          header.hInstance = gui.instance;
95          header.pszIcon = MAKEINTRESOURCE(IDI_VTB_ICON);
96 <        header.nPages = 2;
96 >        header.nPages = 5;
97          header.nStartPage = 0;
98          header.ppsp = wizard;
99          header.pszbmHeader = MAKEINTRESOURCE(IDB_VTB_BMP);
100  
101          PropertySheet(&header);
102 +        saveDirs();
103   }
104  
72 unsigned ScanUtility::count = 0;
105   map<unsigned, ScanUtility*> ScanUtility::utilities;
106   map<HWND, ScanUtility*> ScanUtility::windows;
107  
# Line 256 | Line 288 | void ScanUtility::setScanDir(HWND parent
288                  if (scanDir == "")
289                  {
290                          switch (MessageBox(parent, "Scan Directory needs to be selected.",
291 <                                programName.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR))
291 >                                title.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR))
292                          {
293                          case IDABORT:
294                                  exit(1);
# Line 313 | Line 345 | void ScanUtility::setSaveDir(HWND parent
345                  if (saveDir == "")
346                  {
347                          switch (MessageBox(parent, "Scan Directory needs to be selected.",
348 <                                programName.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR))
348 >                                title.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR))
349                          {
350                          case IDABORT:
351                                  exit(1);
# Line 359 | Line 391 | void ScanUtility::populate(HWND parent)
391                  if (scans.empty())
392                  {
393                          if (MessageBox(parent, "No scanned documents found.",
394 <                                programName.c_str(), MB_RETRYCANCEL | MB_ICONQUESTION) ==
395 <                                IDCANCEL) break;
394 >                                title.c_str(), MB_RETRYCANCEL | MB_ICONQUESTION) == IDCANCEL)
395 >                                break;
396                  }
397          }
398          while (scans.empty());
# Line 378 | Line 410 | void ScanUtility::populate(HWND parent)
410                  ListView_SetImageList(GetDlgItem(parent, IDC_SELECT_SCANS), icons,
411                          LVSIL_SMALL);
412  
381                int index = 0;
382
413                  if (debug) cerr << "scans = {\n";
414  
415                  for (set<string>::iterator itor = scans.begin(); itor != scans.end();
# Line 394 | Line 424 | void ScanUtility::populate(HWND parent)
424                          LVITEM item;
425  
426                          item.mask = LVIF_IMAGE | LVIF_TEXT;
427 <                        item.iItem = index++;
427 >                        item.iItem = 0;
428                          item.iSubItem = 0;
399                        item.state = LVIS_SELECTED;
400                        item.stateMask = LVIS_SELECTED;
429                          item.pszText = scan;
430                          item.iImage = info.iIcon;
431  
# Line 405 | Line 433 | void ScanUtility::populate(HWND parent)
433                  }
434  
435                  if (debug) cerr << "}\n";
436 +
437 +                ListView_SetItemState(GetDlgItem(parent, IDC_SELECT_SCANS), 0,
438 +                        LVIS_SELECTED, LVIS_SELECTED);
439          }
440   }
441  
442 + ScanUtility* ScanUtility::which(HWND window)
443 + {
444 +        map<HWND, ScanUtility*>::iterator itor = windows.find(window);
445 +
446 +        return itor->second;
447 + }
448 +
449 + ScanUtility* ScanUtility::which(HWND window, LPARAM l)
450 + {
451 +        LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l);
452 +        map<unsigned, ScanUtility*>::iterator itor = utilities.find(page->lParam);
453 +
454 +        windows.insert(pair<HWND, ScanUtility*>(window, itor->second));
455 +
456 +        return itor->second;
457 + }
458 +
459   int ScanUtility::browse(HWND dialog, UINT msg, LPARAM l, LPARAM d)
460   {
461          map<unsigned, ScanUtility*>::iterator itor = utilities.find(LOWORD(d));
# Line 453 | Line 501 | int ScanUtility::browse(HWND dialog, UIN
501  
502   INT_PTR ScanUtility::start(HWND dialog, UINT msg, WPARAM w, LPARAM l)
503   {
504 <        map<HWND, ScanUtility*>::iterator itor = windows.find(dialog);
457 <        ScanUtility* data = itor->second;
504 >        ScanUtility* data = which(dialog);
505  
506          switch (msg)
507          {
508          case WM_INITDIALOG:
509                  center(GetParent(dialog));
510 <                {
511 <                        LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l);
512 <                        map<unsigned, ScanUtility*>::iterator itor =
466 <                                utilities.find(page->lParam);
510 >                SendMessage(GetParent(dialog), WM_SETICON, ICON_BIG, LPARAM(gui.icon));
511 >                
512 >                data = which(dialog, l);
513  
468                        windows.insert(pair<HWND, ScanUtility*>(dialog, itor->second));
469                }
514                  {
515                          ostringstream instructions;
516  
517 <                        instructions << "1.\tIf you need instructions, you should not be r"
518 <                                << "unning this program\n\tin Scan Utility mode.\n"
519 <                                << "2.\tOtherwise, go forth and scan.\n"
520 <                                << "3.\tThen come back and click Next.\n";
517 >                        instructions << "1. If you need instructions, you should not be ru"
518 >                                << "nning this program in Scan Utility mode.\n"
519 >                                << "2. Otherwise, go forth and scan.\n"
520 >                                << "3. Then come back and click Next.\n";
521  
522                          SetDlgItemText(dialog, IDC_START_INSTRUCTIONS,
523                                  instructions.str().c_str());
# Line 486 | Line 530 | INT_PTR ScanUtility::start(HWND dialog,
530                          switch (nm->code)
531                          {
532                          case PSN_SETACTIVE:
533 <                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_NEXT);
533 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_FINISH |
534 >                                        PSWIZB_NEXT);
535 >
536                                  {
537                                          char folder[44];
538  
# Line 532 | Line 578 | INT_PTR ScanUtility::start(HWND dialog,
578  
579   INT_PTR ScanUtility::select(HWND dialog, UINT msg, WPARAM w, LPARAM l)
580   {
581 <        map<HWND, ScanUtility*>::iterator itor = windows.find(dialog);
536 <        ScanUtility* data = itor->second;
581 >        ScanUtility* data = which(dialog);
582  
583          switch (msg)
584          {
585          case WM_INITDIALOG:
586 +                data = which(dialog, l);
587 +
588                  {
589 <                        LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l);
590 <                        map<unsigned, ScanUtility*>::iterator itor =
591 <                                utilities.find(page->lParam);
589 >                        ostringstream select;
590 >
591 >                        select << "Select the scanned document that you need to save.";
592  
593 <                        windows.insert(pair<HWND, ScanUtility*>(dialog, itor->second));
593 >                        SetDlgItemText(dialog, IDC_SELECT_TEXT, select.str().c_str());
594                  }
595 +
596                  {
597                          LVCOLUMN column;
598  
# Line 560 | Line 608 | INT_PTR ScanUtility::select(HWND dialog,
608          case WM_NOTIFY:
609                  if (w == IDC_SELECT_SCANS)
610                  {
611 <                        switch (ListView_GetSelectedCount(GetDlgItem(dialog,
612 <                                IDC_SELECT_SCANS)))
611 >                        LPNMITEMACTIVATE ni = LPNMITEMACTIVATE(l);
612 >
613 >                        switch (ni->hdr.code)
614                          {
615 <                        case 1:
616 <                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
617 <                                        PSWIZB_NEXT);
618 <                                break;
619 <                        default:
620 <                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK);
615 >                        case NM_DBLCLK:
616 >                                {
617 >                                        char scan[MAX_PATH];
618 >
619 >                                        ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS),
620 >                                                ni->iItem, 0, scan, MAX_PATH);
621 >                                        ShellExecute(dialog, NULL, scan, NULL, NULL,
622 >                                                SW_SHOWDEFAULT);
623 >                                }
624                                  break;
625                          }
626                  }
# Line 579 | Line 631 | INT_PTR ScanUtility::select(HWND dialog,
631                          switch (nm->code)
632                          {
633                          case PSN_SETACTIVE:
634 <                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK);
634 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
635 >                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
636                                  data->populate(dialog);
637                                  break;
638                          case PSN_WIZBACK:
639                                  ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
640 +                                data->client.setFile("");
641                                  break;
642                          case PSN_WIZNEXT:
643 <                                //
643 >                                {
644 >                                        int index = ListView_GetNextItem(GetDlgItem(dialog,
645 >                                                IDC_SELECT_SCANS), -1, LVNI_SELECTED);
646 >                                        char scan[MAX_PATH];
647 >
648 >                                        ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS),
649 >                                                index, 0, scan, MAX_PATH);
650 >
651 >                                        data->scan = scan;
652 >                                }
653 >
654                                  ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
655 +
656 +                                if (debug) cerr << "scan = " << data->scan << "\n";
657 +                                break;
658 +                        }
659 +                }
660 +                break;
661 +        case WM_CONTEXTMENU:
662 +                {
663 +                        char scan[MAX_PATH];
664 +                        POINT spot;
665 +                        LVHITTESTINFO test;
666 +
667 +                        test.pt.x = GET_X_LPARAM(l);
668 +                        test.pt.y = GET_Y_LPARAM(l);
669 +
670 +                        ScreenToClient(GetDlgItem(dialog, IDC_SELECT_SCANS), &test.pt);
671 +                        ListView_HitTest(GetDlgItem(dialog, IDC_SELECT_SCANS), &test);
672 +
673 +                        if (test.iItem != -1)
674 +                        {
675 +                                ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS),
676 +                                        test.iItem, 0, scan, MAX_PATH);
677 +                                
678 +                                spot.x = test.pt.x;
679 +                                spot.y = test.pt.y;
680 +                        }
681 +                        else if (GET_X_LPARAM(l) == -1 && GET_Y_LPARAM(l) == -1)
682 +                        {
683 +                                int index = ListView_GetNextItem(GetDlgItem(dialog,
684 +                                        IDC_SELECT_SCANS), -1, LVNI_SELECTED);
685 +                                RECT rect;
686 +
687 +                                ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS),
688 +                                        index, 0, scan, MAX_PATH);
689 +                                ListView_EnsureVisible(GetDlgItem(dialog, IDC_SELECT_SCANS),
690 +                                        index, FALSE);
691 +                                ListView_GetItemRect(GetDlgItem(dialog, IDC_SELECT_SCANS),
692 +                                        index, &rect, LVIR_SELECTBOUNDS);
693 +
694 +                                spot.x = rect.left;
695 +                                spot.y = rect.top;
696 +                        }
697 +                        else
698 +                        {
699 +                                break;
700 +                        }
701 +
702 +                        ClientToScreen(GetDlgItem(dialog, IDC_SELECT_SCANS), &spot);
703 +
704 +                        int code = TrackPopupMenuEx(data->popup, TPM_LEFTALIGN |
705 +                                TPM_TOPALIGN | TPM_NONOTIFY | TPM_RETURNCMD | TPM_RIGHTBUTTON,
706 +                                spot.x, spot.y, GetDlgItem(dialog, IDC_SELECT_SCANS), NULL);
707 +
708 +                        switch (code)
709 +                        {
710 +                        case 1:
711 +                                ShellExecute(dialog, NULL, scan, NULL, NULL, SW_SHOWDEFAULT);
712 +                                break;
713 +                        case 2:
714 +                                {
715 +                                        SHELLEXECUTEINFO info;
716 +
717 +                                        info.cbSize = sizeof(info);
718 +                                        info.fMask = SEE_MASK_INVOKEIDLIST;
719 +                                        info.hwnd = dialog;
720 +                                        info.lpVerb = "properties";
721 +                                        info.lpFile = scan;
722 +                                        info.lpParameters = NULL;
723 +                                        info.lpDirectory = NULL;
724 +                                        info.nShow = SW_SHOWDEFAULT;
725 +                                        info.lpIDList = NULL;
726 +
727 +                                        ShellExecuteEx(&info);
728 +                                }
729 +                                break;
730 +                        }
731 +                }
732 +                break;
733 +        }
734 +
735 +        return FALSE;
736 + }
737 +
738 + INT_PTR ScanUtility::enter(HWND dialog, UINT msg, WPARAM w, LPARAM l)
739 + {
740 +        ScanUtility* data = which(dialog);
741 +
742 +        switch (msg)
743 +        {
744 +        case WM_INITDIALOG:
745 +                data = which(dialog, l);
746 +
747 +                {
748 +                        ostringstream enter;
749 +
750 +                        enter << "Enter the client name and number.";
751 +
752 +                        SetDlgItemText(dialog, IDC_ENTER_TEXT, enter.str().c_str());
753 +                }
754 +                break;
755 +        case WM_NOTIFY:
756 +                {
757 +                        LPNMHDR nm = LPNMHDR(l);
758 +
759 +                        switch (nm->code)
760 +                        {
761 +                        case PSN_SETACTIVE:
762 +                                if (data->client.getName() != "" && data->client.getNumber() !=
763 +                                        0)
764 +                                {
765 +                                        PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
766 +                                                PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
767 +                                }
768 +                                else
769 +                                {
770 +                                        PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
771 +                                                PSWIZB_DISABLEDFINISH);
772 +                                }
773 +
774 +                                SetDlgItemText(dialog, IDC_ENTER_NAME,
775 +                                        data->client.getName().c_str());
776 +
777 +                                if (data->client.getNumber() != 0)
778 +                                {
779 +                                        SetDlgItemInt(dialog, IDC_ENTER_NUM,
780 +                                                data->client.getNumber(), FALSE);
781 +                                }
782 +                                else
783 +                                {
784 +                                        SetDlgItemText(dialog, IDC_ENTER_NUM, "");
785 +                                }
786 +                                break;
787 +                        case PSN_WIZBACK:
788 +                                break;
789 +                        case PSN_WIZNEXT:
790 +                                if (debug)
791 +                                {
792 +                                        cerr << "client = {\n"
793 +                                                << "   name = " << data->client.getName() << "\n"
794 +                                                << "   number = " << data->client.getNumber() << "\n"
795 +                                                << "   file = " << data->client.getFile() << "\n"
796 +                                                << "}\n";
797 +                                }
798 +
799 +                                data->save = data->saveDir + '\\' + data->client.getFile();
800 +
801 +                                if (debug) cerr << "save = " << data->save << "\n";
802 +                                
803                                  break;
804                          }
805                  }
806                  break;
807          case WM_COMMAND:
808 +                switch (LOWORD(w))
809 +                {
810 +                case IDC_ENTER_NAME:
811 +                        {
812 +                                char name[BUFSIZ];
813 +
814 +                                GetDlgItemText(dialog, IDC_ENTER_NAME, name, BUFSIZ);
815 +
816 +                                if (name != data->client.getName())
817 +                                {
818 +                                        data->client.setName(name);
819 +                                }
820 +                        }
821 +
822 +                        if (data->client.getName() != "" && data->client.getNumber() != 0)
823 +                        {
824 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
825 +                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
826 +                        }
827 +                        else
828 +                        {
829 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
830 +                                        PSWIZB_DISABLEDFINISH);
831 +                        }
832 +                        break;
833 +                case IDC_ENTER_NUM:
834 +                        {
835 +                                unsigned number = GetDlgItemInt(dialog, IDC_ENTER_NUM, NULL,
836 +                                        FALSE);
837 +
838 +                                if (number != data->client.getNumber())
839 +                                {
840 +                                        data->client.setNumber(number);
841 +                                }
842 +                        }
843 +
844 +                        if (data->client.getName() != "" && data->client.getNumber() != 0)
845 +                        {
846 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
847 +                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
848 +                        }
849 +                        else
850 +                        {
851 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
852 +                                        PSWIZB_DISABLEDFINISH);
853 +                        }
854 +                        break;
855 +                }
856 +                break;
857 +        }
858 +
859 +        return FALSE;
860 + }
861 +
862 + INT_PTR ScanUtility::confirm(HWND dialog, UINT msg, WPARAM w, LPARAM l)
863 + {
864 +        ScanUtility* data = which(dialog);
865 +
866 +        switch (msg)
867 +        {
868 +        case WM_INITDIALOG:
869 +                data = which(dialog, l);
870 +
871 +                {
872 +                        ostringstream confirm;
873 +
874 +                        confirm << "Confirm the client file\'s name and size.";
875 +
876 +                        SetDlgItemText(dialog, IDC_CONFIRM_TEXT, confirm.str().c_str());
877 +                }
878 +                break;
879 +        case WM_NOTIFY:
880 +                {
881 +                        LPNMHDR nm = LPNMHDR(l);
882 +
883 +                        switch (nm->code)
884 +                        {
885 +                        case PSN_SETACTIVE:
886 +                                CheckDlgButton(dialog, IDC_CONFIRM_GOOD, BST_UNCHECKED);
887 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
888 +                                        PSWIZB_DISABLEDFINISH);
889 +                                SetDlgItemText(dialog, IDC_CONFIRM_FILE,
890 +                                        data->client.getFile().c_str());
891 +
892 +                                {
893 +                                        HANDLE scan = CreateFile(data->scan.c_str(), GENERIC_READ,
894 +                                                FILE_SHARE_READ, NULL, OPEN_EXISTING,
895 +                                                FILE_ATTRIBUTE_NORMAL, NULL);
896 +                                        DWORD bytes = GetFileSize(scan, NULL);
897 +
898 +                                        CloseHandle(scan);
899 +
900 +                                        ostringstream size;
901 +
902 +                                        size << format(bytes);
903 +
904 +                                        size.setf(ios_base::fixed, ios_base::floatfield);
905 +                                        size.precision(2);
906 +                                        
907 +                                        FLOAT megabytes = FLOAT(bytes) / FLOAT(1024 * 1024);
908 +
909 +                                        size << " bytes (" << megabytes << " MB)";
910 +
911 +                                        SetDlgItemText(dialog, IDC_CONFIRM_SIZE,
912 +                                                size.str().c_str());
913 +                                }
914 +                                break;
915 +                        case PSN_WIZBACK:
916 +                                break;
917 +                        case PSN_WIZNEXT:
918 +                                if (MoveFile(data->scan.c_str(), data->save.c_str()) == 0)
919 +                                {
920 +                                        do
921 +                                        {
922 +                                                LPVOID message;
923 +                                                
924 +                                                FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
925 +                                                        FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
926 +                                                        0, LPTSTR(&message), 0, NULL);
927 +
928 +                                                int code = MessageBox(dialog, LPCTSTR(message),
929 +                                                        data->title.c_str(), MB_RETRYCANCEL |
930 +                                                        MB_ICONEXCLAMATION);
931 +
932 +                                                LocalFree(message);
933 +
934 +                                                if (code == IDCANCEL)
935 +                                                {
936 +                                                        PropSheet_PressButton(GetParent(dialog),
937 +                                                                PSBTN_BACK);
938 +                                                        break;
939 +                                                }
940 +                                        }
941 +                                        while (MoveFileEx(data->scan.c_str(), data->save.c_str(),
942 +                                                MOVEFILE_REPLACE_EXISTING) == 0);
943 +                                }
944 +                                break;
945 +                        }
946 +                }
947 +                break;
948 +        case WM_COMMAND:
949 +                switch (LOWORD(w))
950 +                {
951 +                case IDC_CONFIRM_GOOD:
952 +                        if (IsDlgButtonChecked(dialog, IDC_CONFIRM_GOOD) == BST_CHECKED)
953 +                        {
954 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
955 +                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
956 +                        }
957 +                        else
958 +                        {
959 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
960 +                                        PSWIZB_DISABLEDFINISH);
961 +                        }
962 +                        break;
963 +                }
964 +                break;
965 +        }
966 +
967 +        return FALSE;
968 + }
969 +
970 + INT_PTR ScanUtility::done(HWND dialog, UINT msg, WPARAM w, LPARAM l)
971 + {
972 +        ScanUtility* data = which(dialog);
973 +
974 +        switch (msg)
975 +        {
976 +        case WM_INITDIALOG:
977 +                data = which(dialog, l);
978 +
979 +                {
980 +                        ostringstream done;
981 +
982 +                        done << "You are done saving the scanned document. Click Finish to"
983 +                                << " exit or click Back to return to the beginning.";
984 +
985 +                        SetDlgItemText(dialog, IDC_DONE_TEXT, done.str().c_str());
986 +                }
987 +                break;
988 +        case WM_NOTIFY:
989 +                {
990 +                        LPNMHDR nm = LPNMHDR(l);
991 +
992 +                        switch (nm->code)
993 +                        {
994 +                        case PSN_SETACTIVE:
995 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
996 +                                        PSWIZB_FINISH);
997 +                                break;
998 +                        case PSN_WIZBACK:
999 +                                data->client.setFile("");
1000 +                                PropSheet_SetCurSelByID(GetParent(dialog), IDD_START);
1001 +                                break;
1002 +                        case PSN_WIZFINISH:
1003 +                                break;
1004 +                        }
1005 +                }
1006                  break;
1007          }
1008  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines