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 274 by douglas, 2003-08-21T23:30:14-07:00 vs.
Revision 284 by douglas, 2003-09-01T23:05:56-07:00

# Line 2 | Line 2
2   //
3   // Douglas Thrift
4   //
5 < // $Id: ScanUtility.cxx,v 1.7 2003/08/22 06:30:14 douglas Exp $
5 > // $Id: ScanUtility.cxx,v 1.13 2003/09/02 06:05:56 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();
15 >        title = programName + " - Scan Utility";
16  
18        menu = LoadMenu(gui.instance, MAKEINTRESOURCE(IDR_SELECT));
19        popup = GetSubMenu(menu, 0);
20        
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;
28 <        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 33 | 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;
41 <        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";
# Line 46 | Line 40 | ScanUtility::ScanUtility()
40  
41          // enter
42          wizard[2].dwSize = sizeof(wizard[2]);
43 <        wizard[2].dwFlags = PSP_DEFAULT | PSP_USEHICON | PSP_USETITLE |
44 <                PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
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].hIcon = gui.icon;
54 <        wizard[2].pszTitle = title;
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   {
62        DestroyMenu(popup);
63        DestroyMenu(menu);
80          utilities.erase(number);
65        saveDirs();
66
67        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 = 3;
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  
89 unsigned ScanUtility::count = 0;
105   map<unsigned, ScanUtility*> ScanUtility::utilities;
106   map<HWND, ScanUtility*> ScanUtility::windows;
107  
# Line 273 | 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 330 | 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 376 | 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 424 | Line 439 | void ScanUtility::populate(HWND parent)
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 441 | Line 473 | int ScanUtility::browse(HWND dialog, UIN
473                  break;
474          case BFFM_SELCHANGED:
475                  {
476 <                        IShellFolder* object;
445 <
446 <                        SHGetDesktopFolder(&object);
476 >                        SHFILEINFO info;
477  
478 <                        STRRET thing;
479 <                        char* folder;
478 >                        SHGetFileInfo(LPCSTR(l), 0, &info, sizeof(info), SHGFI_DISPLAYNAME
479 >                                | SHGFI_PIDL);
480 >                        SendMessage(dialog, BFFM_SETSTATUSTEXT, 0,
481 >                                LPARAM(info.szDisplayName));
482  
483 <                        object->GetDisplayNameOf(LPCITEMIDLIST(l), SHGDN_FORPARSING,
452 <                                &thing);
453 <                        StrRetToStr(&thing, LPCITEMIDLIST(l), &folder);
454 <                        SendMessage(dialog, BFFM_SETSTATUSTEXT, 0, LPARAM(folder));
483 >                        char folder[MAX_PATH];
484  
485 <                        if (PathIsUNCServer(folder))
485 >                        if (!SHGetPathFromIDList(LPCITEMIDLIST(l), folder))
486                          {
487                                  SendMessage(dialog, BFFM_ENABLEOK, 0, 0);
488                          }
489 <
490 <                        CoTaskMemFree(folder);
491 <                        object->Release();
489 >                        else
490 >                        {
491 >                                SendMessage(dialog, BFFM_SETSTATUSTEXT, 0, LPARAM(folder));
492 >                        }
493                  }
494                  break;
495          }
# Line 469 | Line 499 | int ScanUtility::browse(HWND dialog, UIN
499  
500   INT_PTR ScanUtility::start(HWND dialog, UINT msg, WPARAM w, LPARAM l)
501   {
502 <        map<HWND, ScanUtility*>::iterator itor = windows.find(dialog);
473 <        ScanUtility* data = itor->second;
502 >        ScanUtility* data = which(dialog);
503  
504          switch (msg)
505          {
506          case WM_INITDIALOG:
507                  center(GetParent(dialog));
508                  SendMessage(GetParent(dialog), WM_SETICON, ICON_BIG, LPARAM(gui.icon));
509 <                {
510 <                        LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l);
482 <                        map<unsigned, ScanUtility*>::iterator itor =
483 <                                utilities.find(page->lParam);
509 >                
510 >                data = which(dialog, l);
511  
485                        windows.insert(pair<HWND, ScanUtility*>(dialog, itor->second));
486                }
512                  {
513                          ostringstream instructions;
514  
# Line 503 | Line 528 | INT_PTR ScanUtility::start(HWND dialog,
528                          switch (nm->code)
529                          {
530                          case PSN_SETACTIVE:
531 <                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_NEXT);
531 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_FINISH |
532 >                                        PSWIZB_NEXT);
533 >
534 >                                {
535 >                                        SHFILEINFO info;
536 >
537 >                                        SHGetFileInfo(data->scanDir.c_str(), 0, &info,
538 >                                                sizeof(info), SHGFI_ICONLOCATION);
539 >
540 >                                        HICON icon = ExtractIcon(gui.instance, info.szDisplayName,
541 >                                                info.iIcon);
542 >
543 >                                        SendDlgItemMessage(dialog, IDC_START_SCAN_ICON,
544 >                                                STM_SETIMAGE, IMAGE_ICON, LPARAM(icon));
545 >                                        SHGetFileInfo(data->saveDir.c_str(), 0, &info,
546 >                                                sizeof(info), SHGFI_ICONLOCATION);
547 >
548 >                                        icon = ExtractIcon(gui.instance, info.szDisplayName,
549 >                                                info.iIcon);
550 >
551 >                                        SendDlgItemMessage(dialog, IDC_START_SAVE_ICON,
552 >                                                STM_SETIMAGE, IMAGE_ICON, LPARAM(icon));
553 >                                }
554 >
555                                  {
556 <                                        char folder[44];
556 >                                        char folder[38];
557  
558 <                                        PathCompactPathEx(folder, data->scanDir.c_str(), 44, 0);
558 >                                        PathCompactPathEx(folder, data->scanDir.c_str(), 38, 0);
559                                          SetDlgItemText(dialog, IDC_START_SCAN_TEXT, folder);
560 <                                        PathCompactPathEx(folder, data->saveDir.c_str(), 44, 0);
560 >                                        PathCompactPathEx(folder, data->saveDir.c_str(), 38, 0);
561                                          SetDlgItemText(dialog, IDC_START_SAVE_TEXT, folder);
562                                  }
563                                  break;
# Line 524 | Line 572 | INT_PTR ScanUtility::start(HWND dialog,
572                  {
573                  case IDC_START_SCAN_BROWSE:
574                          data->setScanDir(dialog);
575 +
576                          {
577 <                                char folder[44];
577 >                                SHFILEINFO info;
578 >
579 >                                SHGetFileInfo(data->scanDir.c_str(), 0, &info, sizeof(info),
580 >                                        SHGFI_ICONLOCATION);
581  
582 <                                PathCompactPathEx(folder, data->scanDir.c_str(), 44, 0);
582 >                                HICON icon = ExtractIcon(gui.instance, info.szDisplayName,
583 >                                        info.iIcon);
584 >
585 >                                SendDlgItemMessage(dialog, IDC_START_SCAN_ICON, STM_SETIMAGE,
586 >                                        IMAGE_ICON, LPARAM(icon));
587 >                        }
588 >
589 >                        {
590 >                                char folder[38];
591 >
592 >                                PathCompactPathEx(folder, data->scanDir.c_str(), 38, 0);
593                                  SetDlgItemText(dialog, IDC_START_SCAN_TEXT, folder);
594                          }
595                          break;
596                  case IDC_START_SAVE_BROWSE:
597                          data->setSaveDir(dialog);
598 +
599 +                        {
600 +                                SHFILEINFO info;
601 +
602 +                                SHGetFileInfo(data->saveDir.c_str(), 0, &info, sizeof(info),
603 +                                        SHGFI_ICONLOCATION);
604 +
605 +                                HICON icon = ExtractIcon(gui.instance, info.szDisplayName,
606 +                                        info.iIcon);
607 +
608 +                                SendDlgItemMessage(dialog, IDC_START_SAVE_ICON, STM_SETIMAGE,
609 +                                        IMAGE_ICON, LPARAM(icon));
610 +                        }
611 +
612                          {
613 <                                char folder[44];
613 >                                char folder[38];
614  
615 <                                PathCompactPathEx(folder, data->saveDir.c_str(), 44, 0);
615 >                                PathCompactPathEx(folder, data->saveDir.c_str(), 38, 0);
616                                  SetDlgItemText(dialog, IDC_START_SAVE_TEXT, folder);
617                          }
618                          break;
# Line 549 | Line 625 | INT_PTR ScanUtility::start(HWND dialog,
625  
626   INT_PTR ScanUtility::select(HWND dialog, UINT msg, WPARAM w, LPARAM l)
627   {
628 <        map<HWND, ScanUtility*>::iterator itor = windows.find(dialog);
553 <        ScanUtility* data = itor->second;
628 >        ScanUtility* data = which(dialog);
629  
630          switch (msg)
631          {
632          case WM_INITDIALOG:
633 <                {
559 <                        LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l);
560 <                        map<unsigned, ScanUtility*>::iterator itor =
561 <                                utilities.find(page->lParam);
633 >                data = which(dialog, l);
634  
563                        windows.insert(pair<HWND, ScanUtility*>(dialog, itor->second));
564                }
635                  {
636                          ostringstream select;
637  
638 <                        select << "Select the scanned document that you need to be save.";
638 >                        select << "Select the scanned document that you need to save.";
639  
640                          SetDlgItemText(dialog, IDC_SELECT_TEXT, select.str().c_str());
641                  }
642 +
643                  {
644                          LVCOLUMN column;
645  
# Line 588 | Line 659 | INT_PTR ScanUtility::select(HWND dialog,
659  
660                          switch (ni->hdr.code)
661                          {
662 <                        case NM_RCLICK:
662 >                        case NM_DBLCLK:
663 >                                if (ni->iItem != -1)
664                                  {
665                                          char scan[MAX_PATH];
666  
667                                          ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS),
668                                                  ni->iItem, 0, scan, MAX_PATH);
669 +                                        ShellExecute(dialog, NULL, scan, NULL, NULL,
670 +                                                SW_SHOWDEFAULT);
671 +                                }
672 +                                break;
673 +                        }
674 +                }
675 +                else
676 +                {
677 +                        LPNMHDR nm = LPNMHDR(l);
678 +
679 +                        switch (nm->code)
680 +                        {
681 +                        case PSN_SETACTIVE:
682 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
683 +                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
684 +                                data->populate(dialog);
685 +                                break;
686 +                        case PSN_WIZBACK:
687 +                                ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
688 +                                data->client.setFile("");
689 +                                break;
690 +                        case PSN_WIZNEXT:
691 +                                {
692 +                                        int index = ListView_GetNextItem(GetDlgItem(dialog,
693 +                                                IDC_SELECT_SCANS), -1, LVNI_SELECTED);
694 +                                        char scan[MAX_PATH];
695 +
696 +                                        if (index != -1)
697 +                                        {
698 +                                                ListView_GetItemText(GetDlgItem(dialog,
699 +                                                        IDC_SELECT_SCANS), index, 0, scan, MAX_PATH);
700 +                                        }
701 +                                        else
702 +                                        {
703 +                                                ListView_GetItemText(GetDlgItem(dialog,
704 +                                                        IDC_SELECT_SCANS), 0, 0, scan, MAX_PATH);
705 +                                        }
706 +
707 +                                        data->scan = scan;
708 +                                }
709 +
710 +                                if (debug) cerr << "scan = " << data->scan << "\n";
711 +
712 +                                ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
713 +                                break;
714 +                        }
715 +                }
716 +                break;
717 +        case WM_CONTEXTMENU:
718 +                if (ListView_GetNextItem(GetDlgItem(dialog, IDC_SELECT_SCANS), -1,
719 +                        LVNI_SELECTED) != -1)
720 +                {
721 +                        char scan[MAX_PATH];
722 +                        POINT spot;
723 +                        LVHITTESTINFO test;
724 +
725 +                        test.pt.x = GET_X_LPARAM(l);
726 +                        test.pt.y = GET_Y_LPARAM(l);
727 +
728 +                        ScreenToClient(GetDlgItem(dialog, IDC_SELECT_SCANS), &test.pt);
729 +                        ListView_HitTest(GetDlgItem(dialog, IDC_SELECT_SCANS), &test);
730 +
731 +                        if (test.iItem != -1)
732 +                        {
733 +                                ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS),
734 +                                        test.iItem, 0, scan, MAX_PATH);
735 +                                
736 +                                spot.x = test.pt.x;
737 +                                spot.y = test.pt.y;
738 +                        }
739 +                        else if (GET_X_LPARAM(l) == -1 && GET_Y_LPARAM(l) == -1)
740 +                        {
741 +                                int index = ListView_GetNextItem(GetDlgItem(dialog,
742 +                                        IDC_SELECT_SCANS), -1, LVNI_SELECTED);
743 +                                RECT rect;
744 +
745 +                                ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS),
746 +                                        index, 0, scan, MAX_PATH);
747 +                                ListView_EnsureVisible(GetDlgItem(dialog, IDC_SELECT_SCANS),
748 +                                        index, FALSE);
749 +                                ListView_GetItemRect(GetDlgItem(dialog, IDC_SELECT_SCANS),
750 +                                        index, &rect, LVIR_SELECTBOUNDS);
751  
752 +                                spot.x = rect.left;
753 +                                spot.y = rect.top;
754 +                        }
755 +
756 +                        ClientToScreen(GetDlgItem(dialog, IDC_SELECT_SCANS), &spot);
757 +
758 +                        int code = TrackPopupMenuEx(data->popup, TPM_LEFTALIGN |
759 +                                TPM_TOPALIGN | TPM_NONOTIFY | TPM_RETURNCMD | TPM_RIGHTBUTTON,
760 +                                spot.x, spot.y, GetDlgItem(dialog, IDC_SELECT_SCANS), NULL);
761 +
762 +                        switch (code)
763 +                        {
764 +                        case 1:
765 +                                ShellExecute(dialog, NULL, scan, NULL, NULL, SW_SHOWDEFAULT);
766 +                                break;
767 +                        case 2:
768 +                                {
769                                          SHELLEXECUTEINFO info;
770  
771                                          info.cbSize = sizeof(info);
# Line 610 | Line 781 | INT_PTR ScanUtility::select(HWND dialog,
781                                          ShellExecuteEx(&info);
782                                  }
783                                  break;
784 <                        case NM_DBLCLK:
784 >                        }
785 >                }
786 >                break;
787 >        }
788 >
789 >        return FALSE;
790 > }
791 >
792 > INT_PTR ScanUtility::enter(HWND dialog, UINT msg, WPARAM w, LPARAM l)
793 > {
794 >        ScanUtility* data = which(dialog);
795 >
796 >        switch (msg)
797 >        {
798 >        case WM_INITDIALOG:
799 >                data = which(dialog, l);
800 >
801 >                {
802 >                        ostringstream enter;
803 >
804 >                        enter << "Enter the client name and number.";
805 >
806 >                        SetDlgItemText(dialog, IDC_ENTER_TEXT, enter.str().c_str());
807 >                }
808 >                break;
809 >        case WM_NOTIFY:
810 >                {
811 >                        LPNMHDR nm = LPNMHDR(l);
812 >
813 >                        switch (nm->code)
814 >                        {
815 >                        case PSN_SETACTIVE:
816 >                                if (data->client.getName() != "" && data->client.getNumber() !=
817 >                                        0)
818                                  {
819 <                                        char scan[MAX_PATH];
819 >                                        PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
820 >                                                PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
821 >                                }
822 >                                else
823 >                                {
824 >                                        PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
825 >                                                PSWIZB_DISABLEDFINISH);
826 >                                }
827  
828 <                                        ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS),
829 <                                                ni->iItem, 0, scan, MAX_PATH);
830 <                                        ShellExecute(dialog, NULL, scan, NULL, NULL,
831 <                                                SW_SHOWDEFAULT);
828 >                                SetDlgItemText(dialog, IDC_ENTER_NAME,
829 >                                        data->client.getName().c_str());
830 >
831 >                                if (data->client.getNumber() != 0)
832 >                                {
833 >                                        SetDlgItemInt(dialog, IDC_ENTER_NUM,
834 >                                                data->client.getNumber(), FALSE);
835 >                                }
836 >                                else
837 >                                {
838 >                                        SetDlgItemText(dialog, IDC_ENTER_NUM, "");
839                                  }
840                                  break;
841 +                        case PSN_WIZBACK:
842 +                                break;
843 +                        case PSN_WIZNEXT:
844 +                                if (debug)
845 +                                {
846 +                                        cerr << "client = {\n"
847 +                                                << "   name = " << data->client.getName() << "\n"
848 +                                                << "   number = " << data->client.getNumber() << "\n"
849 +                                                << "   file = " << data->client.getFile() << "\n"
850 +                                                << "}\n";
851 +                                }
852 +
853 +                                data->save = data->saveDir + '\\' + data->client.getFile();
854 +
855 +                                if (debug) cerr << "save = " << data->save << "\n";
856 +                                
857 +                                break;
858                          }
859                  }
860 <                else
860 >                break;
861 >        case WM_COMMAND:
862 >                switch (LOWORD(w))
863 >                {
864 >                case IDC_ENTER_NAME:
865 >                        {
866 >                                char name[BUFSIZ];
867 >
868 >                                GetDlgItemText(dialog, IDC_ENTER_NAME, name, BUFSIZ);
869 >
870 >                                if (name != data->client.getName())
871 >                                {
872 >                                        data->client.setName(name);
873 >                                }
874 >                        }
875 >
876 >                        if (data->client.getName() != "" && data->client.getNumber() != 0)
877 >                        {
878 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
879 >                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
880 >                        }
881 >                        else
882 >                        {
883 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
884 >                                        PSWIZB_DISABLEDFINISH);
885 >                        }
886 >                        break;
887 >                case IDC_ENTER_NUM:
888 >                        {
889 >                                unsigned number = GetDlgItemInt(dialog, IDC_ENTER_NUM, NULL,
890 >                                        FALSE);
891 >
892 >                                if (number != data->client.getNumber())
893 >                                {
894 >                                        data->client.setNumber(number);
895 >                                }
896 >                        }
897 >
898 >                        if (data->client.getName() != "" && data->client.getNumber() != 0)
899 >                        {
900 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
901 >                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
902 >                        }
903 >                        else
904 >                        {
905 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
906 >                                        PSWIZB_DISABLEDFINISH);
907 >                        }
908 >                        break;
909 >                }
910 >                break;
911 >        }
912 >
913 >        return FALSE;
914 > }
915 >
916 > INT_PTR ScanUtility::confirm(HWND dialog, UINT msg, WPARAM w, LPARAM l)
917 > {
918 >        ScanUtility* data = which(dialog);
919 >
920 >        switch (msg)
921 >        {
922 >        case WM_INITDIALOG:
923 >                data = which(dialog, l);
924 >
925 >                {
926 >                        ostringstream confirm;
927 >
928 >                        confirm << "Confirm the client file\'s name and size.";
929 >
930 >                        SetDlgItemText(dialog, IDC_CONFIRM_TEXT, confirm.str().c_str());
931 >                }
932 >                break;
933 >        case WM_NOTIFY:
934                  {
935                          LPNMHDR nm = LPNMHDR(l);
936  
937                          switch (nm->code)
938                          {
939                          case PSN_SETACTIVE:
940 +                                CheckDlgButton(dialog, IDC_CONFIRM_GOOD, BST_UNCHECKED);
941                                  PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
942 <                                        PSWIZB_NEXT);
943 <                                data->populate(dialog);
942 >                                        PSWIZB_DISABLEDFINISH);
943 >                                SetDlgItemText(dialog, IDC_CONFIRM_FILE,
944 >                                        data->client.getFile().c_str());
945 >
946 >                                {
947 >                                        HANDLE scan = CreateFile(data->scan.c_str(), GENERIC_READ,
948 >                                                FILE_SHARE_READ, NULL, OPEN_EXISTING,
949 >                                                FILE_ATTRIBUTE_NORMAL, NULL);
950 >                                        DWORD bytes = GetFileSize(scan, NULL);
951 >
952 >                                        CloseHandle(scan);
953 >
954 >                                        ostringstream size;
955 >
956 >                                        size << format(bytes);
957 >
958 >                                        size.setf(ios_base::fixed, ios_base::floatfield);
959 >                                        size.precision(2);
960 >                                        
961 >                                        FLOAT megabytes = FLOAT(bytes) / FLOAT(1024 * 1024);
962 >
963 >                                        size << " bytes (" << megabytes << " MB)";
964 >
965 >                                        SetDlgItemText(dialog, IDC_CONFIRM_SIZE,
966 >                                                size.str().c_str());
967 >                                }
968                                  break;
969                          case PSN_WIZBACK:
637                                ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
970                                  break;
971                          case PSN_WIZNEXT:
972 +                                if (MoveFile(data->scan.c_str(), data->save.c_str()) == 0)
973                                  {
974 <                                        int index = ListView_GetNextItem(GetDlgItem(dialog,
975 <                                                IDC_SELECT_SCANS), -1, LVNI_SELECTED);
976 <                                        char scan[MAX_PATH];
977 <
978 <                                        ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS),
979 <                                                index, 0, scan, MAX_PATH);
980 <
981 <                                        data->scan = scan;
974 >                                        do
975 >                                        {
976 >                                                LPVOID message;
977 >                                                
978 >                                                FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
979 >                                                        FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
980 >                                                        0, LPTSTR(&message), 0, NULL);
981 >
982 >                                                int code = MessageBox(dialog, LPCTSTR(message),
983 >                                                        data->title.c_str(), MB_RETRYCANCEL |
984 >                                                        MB_ICONEXCLAMATION);
985 >
986 >                                                LocalFree(message);
987 >
988 >                                                if (code == IDCANCEL)
989 >                                                {
990 >                                                        PropSheet_PressButton(GetParent(dialog),
991 >                                                                PSBTN_BACK);
992 >                                                        break;
993 >                                                }
994 >                                        }
995 >                                        while (MoveFileEx(data->scan.c_str(), data->save.c_str(),
996 >                                                MOVEFILE_REPLACE_EXISTING) == 0);
997                                  }
650                                ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
651                                if (debug) cerr << "scan = " << data->scan << "\n";
652                                ShellExecute(dialog, NULL, data->scan.c_str(), NULL, NULL,
653                                        SW_SHOWDEFAULT);
998                                  break;
999                          }
1000                  }
1001                  break;
1002          case WM_COMMAND:
1003 +                switch (LOWORD(w))
1004 +                {
1005 +                case IDC_CONFIRM_GOOD:
1006 +                        if (IsDlgButtonChecked(dialog, IDC_CONFIRM_GOOD) == BST_CHECKED)
1007 +                        {
1008 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
1009 +                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
1010 +                        }
1011 +                        else
1012 +                        {
1013 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
1014 +                                        PSWIZB_DISABLEDFINISH);
1015 +                        }
1016 +                        break;
1017 +                }
1018                  break;
1019          }
1020  
1021          return FALSE;
1022   }
1023  
1024 < INT_PTR ScanUtility::enter(HWND dialog, UINT msg, WPARAM w, LPARAM l)
1024 > INT_PTR ScanUtility::done(HWND dialog, UINT msg, WPARAM w, LPARAM l)
1025   {
1026 +        ScanUtility* data = which(dialog);
1027 +
1028 +        switch (msg)
1029 +        {
1030 +        case WM_INITDIALOG:
1031 +                data = which(dialog, l);
1032 +
1033 +                {
1034 +                        ostringstream done;
1035 +
1036 +                        done << "You are done saving the scanned document. Click Finish to"
1037 +                                << " exit or click Back to return to the beginning.";
1038 +
1039 +                        SetDlgItemText(dialog, IDC_DONE_TEXT, done.str().c_str());
1040 +                }
1041 +                break;
1042 +        case WM_NOTIFY:
1043 +                {
1044 +                        LPNMHDR nm = LPNMHDR(l);
1045 +
1046 +                        switch (nm->code)
1047 +                        {
1048 +                        case PSN_SETACTIVE:
1049 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
1050 +                                        PSWIZB_FINISH);
1051 +                                break;
1052 +                        case PSN_WIZBACK:
1053 +                                data->client.setFile("");
1054 +                                PropSheet_SetCurSelByID(GetParent(dialog), IDD_START);
1055 +                                break;
1056 +                        case PSN_WIZFINISH:
1057 +                                break;
1058 +                        }
1059 +                }
1060 +                break;
1061 +        }
1062 +
1063          return FALSE;
1064   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines