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 277 by douglas, 2003-08-24T00:31:45-07:00 vs.
Revision 288 by douglas, 2003-09-03T15:58:38-07:00

# Line 2 | Line 2
2   //
3   // Douglas Thrift
4   //
5 < // $Id: ScanUtility.cxx,v 1.8 2003/08/24 07:31:45 douglas Exp $
5 > // $Id: ScanUtility.cxx,v 1.14 2003/09/03 22:58:38 douglas Exp $
6  
7   #include "ScanUtility.h"
8  
9 < ScanUtility::ScanUtility()
9 > ScanUtility::ScanUtility() : DiscBrowse()
10   {
11          number = count++;
12        utilities.insert(pair<unsigned, ScanUtility*>(number, this));
13        title = new char[programName.length() + 16];
14
15        sprintf(title, "%s - Scan Utility", programName.c_str());
16        loadDirs();
12  
13 <        popup = CreatePopupMenu();
13 >        utilities.insert(pair<unsigned, ScanUtility*>(number, this));
14  
15 <        MENUITEMINFO open, separator, properties;
15 >        title = programName + " - Scan Utility";
16  
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        
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;
50 <        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 55 | 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;
63 <        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 68 | 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;
76 <        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   {
85        DestroyMenu(popup);
80          utilities.erase(number);
87        saveDirs();
88
89        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  
111 unsigned ScanUtility::count = 0;
105   map<unsigned, ScanUtility*> ScanUtility::utilities;
106   map<HWND, ScanUtility*> ScanUtility::windows;
107  
# Line 137 | Line 130 | void ScanUtility::loadDirs(void)
130  
131                                          ExpandEnvironmentStrings(data, folder, MAX_PATH);
132  
133 <                                        scanDir = folder;
133 >                                        scanDir = tail(folder);
134                                  }
135                                  break;
136                          case REG_SZ:
137 <                                scanDir = data;
137 >                                scanDir = tail(data);
138                                  break;
139                          default:
140                                  setScanDir();
# Line 168 | Line 161 | void ScanUtility::loadDirs(void)
161  
162                                          ExpandEnvironmentStrings(data, folder, MAX_PATH);
163  
164 <                                        saveDir = folder;
164 >                                        saveDir = tail(folder);
165                                  }
166                                  break;
167                          case REG_SZ:
168 <                                saveDir = data;
168 >                                saveDir = tail(data);
169                                  break;
170                          default:
171                                  setSaveDir();
# Line 280 | Line 273 | void ScanUtility::setScanDir(HWND parent
273                  {
274                          char folder[MAX_PATH];
275  
276 <                        if (SHGetPathFromIDList(id, folder))
284 <                        {
285 <                                scanDir = folder;
286 <                        }
276 >                        if (SHGetPathFromIDList(id, folder)) scanDir = tail(folder);
277                  }
278  
279                  LPMALLOC destruct;
# Line 295 | Line 285 | void ScanUtility::setScanDir(HWND parent
285                  if (scanDir == "")
286                  {
287                          switch (MessageBox(parent, "Scan Directory needs to be selected.",
288 <                                programName.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR))
288 >                                title.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR))
289                          {
290                          case IDABORT:
291                                  exit(1);
# Line 337 | Line 327 | void ScanUtility::setSaveDir(HWND parent
327                  {
328                          char folder[MAX_PATH];
329  
330 <                        if (SHGetPathFromIDList(id, folder))
341 <                        {
342 <                                saveDir = folder;
343 <                        }
330 >                        if (SHGetPathFromIDList(id, folder)) saveDir = tail(folder);
331                  }
332  
333                  LPMALLOC destruct;
# Line 352 | Line 339 | void ScanUtility::setSaveDir(HWND parent
339                  if (saveDir == "")
340                  {
341                          switch (MessageBox(parent, "Scan Directory needs to be selected.",
342 <                                programName.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR))
342 >                                title.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR))
343                          {
344                          case IDABORT:
345                                  exit(1);
# Line 379 | Line 366 | void ScanUtility::populate(HWND parent)
366  
367          do
368          {
369 <                string scan = scanDir + "\\SCAN????_000." +
369 >                string scan = scanDir + "SCAN????_000." +
370                          IndividualClient::getExtension();
371                  WIN32_FIND_DATA found;
372                  HANDLE finder = FindFirstFile(scan.c_str(), &found);
# Line 394 | Line 381 | void ScanUtility::populate(HWND parent)
381  
382                          FindClose(finder);
383                  }
384 +                else
385 +                {
386 +                        error(parent);
387 +                }
388  
389                  if (scans.empty())
390                  {
391                          if (MessageBox(parent, "No scanned documents found.",
392 <                                programName.c_str(), MB_RETRYCANCEL | MB_ICONQUESTION) ==
393 <                                IDCANCEL) break;
392 >                                title.c_str(), MB_RETRYCANCEL | MB_ICONQUESTION) == IDCANCEL)
393 >                                break;
394                  }
395          }
396          while (scans.empty());
# Line 480 | Line 471 | int ScanUtility::browse(HWND dialog, UIN
471                  break;
472          case BFFM_SELCHANGED:
473                  {
474 <                        IShellFolder* object;
474 >                        SHFILEINFO info;
475  
476 <                        SHGetDesktopFolder(&object);
476 >                        SHGetFileInfo(LPCSTR(l), 0, &info, sizeof(info), SHGFI_DISPLAYNAME
477 >                                | SHGFI_PIDL);
478 >                        SendMessage(dialog, BFFM_SETSTATUSTEXT, 0,
479 >                                LPARAM(info.szDisplayName));
480  
481 <                        STRRET thing;
488 <                        char* folder;
489 <
490 <                        object->GetDisplayNameOf(LPCITEMIDLIST(l), SHGDN_FORPARSING,
491 <                                &thing);
492 <                        StrRetToStr(&thing, LPCITEMIDLIST(l), &folder);
493 <                        SendMessage(dialog, BFFM_SETSTATUSTEXT, 0, LPARAM(folder));
481 >                        char folder[MAX_PATH];
482  
483 <                        if (PathIsUNCServer(folder))
483 >                        if (!SHGetPathFromIDList(LPCITEMIDLIST(l), folder))
484                          {
485                                  SendMessage(dialog, BFFM_ENABLEOK, 0, 0);
486                          }
487 <
488 <                        CoTaskMemFree(folder);
489 <                        object->Release();
487 >                        else
488 >                        {
489 >                                SendMessage(dialog, BFFM_SETSTATUSTEXT, 0, LPARAM(folder));
490 >                        }
491                  }
492                  break;
493          }
# Line 537 | Line 526 | INT_PTR ScanUtility::start(HWND dialog,
526                          switch (nm->code)
527                          {
528                          case PSN_SETACTIVE:
529 <                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_NEXT);
529 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_FINISH |
530 >                                        PSWIZB_NEXT);
531 >
532 >                                {
533 >                                        SHFILEINFO info;
534 >
535 >                                        SHGetFileInfo(data->scanDir.c_str(), 0, &info,
536 >                                                sizeof(info), SHGFI_ICONLOCATION);
537 >
538 >                                        HICON icon = ExtractIcon(gui.instance, info.szDisplayName,
539 >                                                info.iIcon);
540 >
541 >                                        SendDlgItemMessage(dialog, IDC_START_SCAN_ICON,
542 >                                                STM_SETIMAGE, IMAGE_ICON, LPARAM(icon));
543 >                                        SHGetFileInfo(data->saveDir.c_str(), 0, &info,
544 >                                                sizeof(info), SHGFI_ICONLOCATION);
545 >
546 >                                        icon = ExtractIcon(gui.instance, info.szDisplayName,
547 >                                                info.iIcon);
548 >
549 >                                        SendDlgItemMessage(dialog, IDC_START_SAVE_ICON,
550 >                                                STM_SETIMAGE, IMAGE_ICON, LPARAM(icon));
551 >                                }
552 >
553                                  {
554 <                                        char folder[44];
554 >                                        char folder[38];
555  
556 <                                        PathCompactPathEx(folder, data->scanDir.c_str(), 44, 0);
556 >                                        PathCompactPathEx(folder, data->scanDir.substr(0,
557 >                                                data->scanDir.length() - 1).c_str(), 38, 0);
558                                          SetDlgItemText(dialog, IDC_START_SCAN_TEXT, folder);
559 <                                        PathCompactPathEx(folder, data->saveDir.c_str(), 44, 0);
559 >                                        PathCompactPathEx(folder, data->saveDir.substr(0,
560 >                                                data->saveDir.length() - 1).c_str(), 38, 0);
561                                          SetDlgItemText(dialog, IDC_START_SAVE_TEXT, folder);
562                                  }
563                                  break;
# Line 558 | 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 <                                PathCompactPathEx(folder, data->scanDir.c_str(), 44, 0);
579 >                                SHGetFileInfo(data->scanDir.c_str(), 0, &info, sizeof(info),
580 >                                        SHGFI_ICONLOCATION);
581 >
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.substr(0,
593 >                                        data->scanDir.length() - 1).c_str(), 38, 0);
594                                  SetDlgItemText(dialog, IDC_START_SCAN_TEXT, folder);
595                          }
596                          break;
597                  case IDC_START_SAVE_BROWSE:
598                          data->setSaveDir(dialog);
599 +
600 +                        {
601 +                                SHFILEINFO info;
602 +
603 +                                SHGetFileInfo(data->saveDir.c_str(), 0, &info, sizeof(info),
604 +                                        SHGFI_ICONLOCATION);
605 +
606 +                                HICON icon = ExtractIcon(gui.instance, info.szDisplayName,
607 +                                        info.iIcon);
608 +
609 +                                SendDlgItemMessage(dialog, IDC_START_SAVE_ICON, STM_SETIMAGE,
610 +                                        IMAGE_ICON, LPARAM(icon));
611 +                        }
612 +
613                          {
614 <                                char folder[44];
614 >                                char folder[38];
615  
616 <                                PathCompactPathEx(folder, data->saveDir.c_str(), 44, 0);
616 >                                PathCompactPathEx(folder, data->saveDir.substr(0,
617 >                                        data->saveDir.length() - 1).c_str(), 38, 0);
618                                  SetDlgItemText(dialog, IDC_START_SAVE_TEXT, folder);
619                          }
620                          break;
# Line 593 | Line 637 | INT_PTR ScanUtility::select(HWND dialog,
637                  {
638                          ostringstream select;
639  
640 <                        select << "Select the scanned document that you need to be save.";
640 >                        select << "Select the scanned document that you need to save.";
641  
642                          SetDlgItemText(dialog, IDC_SELECT_TEXT, select.str().c_str());
643                  }
# Line 618 | Line 662 | INT_PTR ScanUtility::select(HWND dialog,
662                          switch (ni->hdr.code)
663                          {
664                          case NM_DBLCLK:
665 +                                if (ni->iItem != -1)
666                                  {
667                                          char scan[MAX_PATH];
668  
# Line 637 | Line 682 | INT_PTR ScanUtility::select(HWND dialog,
682                          {
683                          case PSN_SETACTIVE:
684                                  PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
685 <                                        PSWIZB_NEXT);
685 >                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
686                                  data->populate(dialog);
687                                  break;
688                          case PSN_WIZBACK:
# Line 650 | Line 695 | INT_PTR ScanUtility::select(HWND dialog,
695                                                  IDC_SELECT_SCANS), -1, LVNI_SELECTED);
696                                          char scan[MAX_PATH];
697  
698 <                                        ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS),
699 <                                                index, 0, scan, MAX_PATH);
698 >                                        if (index != -1)
699 >                                        {
700 >                                                ListView_GetItemText(GetDlgItem(dialog,
701 >                                                        IDC_SELECT_SCANS), index, 0, scan, MAX_PATH);
702 >                                        }
703 >                                        else
704 >                                        {
705 >                                                ListView_GetItemText(GetDlgItem(dialog,
706 >                                                        IDC_SELECT_SCANS), 0, 0, scan, MAX_PATH);
707 >                                        }
708  
709                                          data->scan = scan;
710                                  }
711  
659                                ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
660
712                                  if (debug) cerr << "scan = " << data->scan << "\n";
713 +
714 +                                ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
715                                  break;
716                          }
717                  }
718                  break;
719          case WM_CONTEXTMENU:
720 +                if (ListView_GetNextItem(GetDlgItem(dialog, IDC_SELECT_SCANS), -1,
721 +                        LVNI_SELECTED) != -1)
722                  {
723                          char scan[MAX_PATH];
724                          POINT spot;
# Line 699 | Line 754 | INT_PTR ScanUtility::select(HWND dialog,
754                                  spot.x = rect.left;
755                                  spot.y = rect.top;
756                          }
702                        else
703                        {
704                                break;
705                        }
757  
758                          ClientToScreen(GetDlgItem(dialog, IDC_SELECT_SCANS), &spot);
759  
# Line 748 | Line 799 | INT_PTR ScanUtility::enter(HWND dialog,
799          {
800          case WM_INITDIALOG:
801                  data = which(dialog, l);
802 +
803                  {
804                          ostringstream enter;
805  
# Line 767 | Line 819 | INT_PTR ScanUtility::enter(HWND dialog,
819                                          0)
820                                  {
821                                          PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
822 <                                                PSWIZB_NEXT);
822 >                                                PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
823                                  }
824                                  else
825                                  {
826 <                                        PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK);
826 >                                        PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
827 >                                                PSWIZB_DISABLEDFINISH);
828                                  }
829  
830                                  SetDlgItemText(dialog, IDC_ENTER_NAME,
# Line 795 | Line 848 | INT_PTR ScanUtility::enter(HWND dialog,
848                                          cerr << "client = {\n"
849                                                  << "   name = " << data->client.getName() << "\n"
850                                                  << "   number = " << data->client.getNumber() << "\n"
851 +                                                << "   file = " << data->client.getFile() << "\n"
852                                                  << "}\n";
853                                  }
854 +
855 +                                data->save = data->saveDir + '\\' + data->client.getFile();
856 +
857 +                                if (debug) cerr << "save = " << data->save << "\n";
858 +                                
859                                  break;
860                          }
861                  }
# Line 819 | Line 878 | INT_PTR ScanUtility::enter(HWND dialog,
878                          if (data->client.getName() != "" && data->client.getNumber() != 0)
879                          {
880                                  PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
881 <                                        PSWIZB_NEXT);
881 >                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
882                          }
883                          else
884                          {
885 <                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK);
885 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
886 >                                        PSWIZB_DISABLEDFINISH);
887                          }
888                          break;
889                  case IDC_ENTER_NUM:
# Line 840 | Line 900 | INT_PTR ScanUtility::enter(HWND dialog,
900                          if (data->client.getName() != "" && data->client.getNumber() != 0)
901                          {
902                                  PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
903 <                                        PSWIZB_NEXT);
903 >                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
904 >                        }
905 >                        else
906 >                        {
907 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
908 >                                        PSWIZB_DISABLEDFINISH);
909 >                        }
910 >                        break;
911 >                }
912 >                break;
913 >        }
914 >
915 >        return FALSE;
916 > }
917 >
918 > INT_PTR ScanUtility::confirm(HWND dialog, UINT msg, WPARAM w, LPARAM l)
919 > {
920 >        ScanUtility* data = which(dialog);
921 >
922 >        switch (msg)
923 >        {
924 >        case WM_INITDIALOG:
925 >                data = which(dialog, l);
926 >
927 >                {
928 >                        ostringstream confirm;
929 >
930 >                        confirm << "Confirm the client file\'s name and size.";
931 >
932 >                        SetDlgItemText(dialog, IDC_CONFIRM_TEXT, confirm.str().c_str());
933 >                }
934 >                break;
935 >        case WM_NOTIFY:
936 >                {
937 >                        LPNMHDR nm = LPNMHDR(l);
938 >
939 >                        switch (nm->code)
940 >                        {
941 >                        case PSN_SETACTIVE:
942 >                                CheckDlgButton(dialog, IDC_CONFIRM_GOOD, BST_UNCHECKED);
943 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
944 >                                        PSWIZB_DISABLEDFINISH);
945 >                                SetDlgItemText(dialog, IDC_CONFIRM_FILE,
946 >                                        data->client.getFile().c_str());
947 >
948 >                                {
949 >                                        HANDLE scan = CreateFile(data->scan.c_str(), GENERIC_READ,
950 >                                                FILE_SHARE_READ, NULL, OPEN_EXISTING,
951 >                                                FILE_ATTRIBUTE_NORMAL, NULL);
952 >                                        DWORD bytes = GetFileSize(scan, NULL);
953 >
954 >                                        CloseHandle(scan);
955 >
956 >                                        ostringstream size;
957 >
958 >                                        size << format(bytes);
959 >
960 >                                        size.setf(ios_base::fixed, ios_base::floatfield);
961 >                                        size.precision(2);
962 >                                        
963 >                                        FLOAT megabytes = FLOAT(bytes) / FLOAT(1024 * 1024);
964 >
965 >                                        size << " bytes (" << megabytes << " MB)";
966 >
967 >                                        SetDlgItemText(dialog, IDC_CONFIRM_SIZE,
968 >                                                size.str().c_str());
969 >                                }
970 >                                break;
971 >                        case PSN_WIZBACK:
972 >                                break;
973 >                        case PSN_WIZNEXT:
974 >                                if (MoveFile(data->scan.c_str(), data->save.c_str()) == 0)
975 >                                {
976 >                                        do
977 >                                        {
978 >                                                LPVOID message;
979 >                                                
980 >                                                FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
981 >                                                        FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
982 >                                                        0, LPTSTR(&message), 0, NULL);
983 >
984 >                                                int code = MessageBox(dialog, LPCTSTR(message),
985 >                                                        data->title.c_str(), MB_RETRYCANCEL |
986 >                                                        MB_ICONEXCLAMATION);
987 >
988 >                                                LocalFree(message);
989 >
990 >                                                if (code == IDCANCEL)
991 >                                                {
992 >                                                        PropSheet_PressButton(GetParent(dialog),
993 >                                                                PSBTN_BACK);
994 >                                                        break;
995 >                                                }
996 >                                        }
997 >                                        while (MoveFileEx(data->scan.c_str(), data->save.c_str(),
998 >                                                MOVEFILE_REPLACE_EXISTING) == 0);
999 >                                }
1000 >                                break;
1001 >                        }
1002 >                }
1003 >                break;
1004 >        case WM_COMMAND:
1005 >                switch (LOWORD(w))
1006 >                {
1007 >                case IDC_CONFIRM_GOOD:
1008 >                        if (IsDlgButtonChecked(dialog, IDC_CONFIRM_GOOD) == BST_CHECKED)
1009 >                        {
1010 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
1011 >                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
1012                          }
1013                          else
1014                          {
1015 <                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK);
1015 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
1016 >                                        PSWIZB_DISABLEDFINISH);
1017                          }
1018                          break;
1019                  }
1020                  break;
1021          }
1022 +
1023 +        return FALSE;
1024 + }
1025 +
1026 + INT_PTR ScanUtility::done(HWND dialog, UINT msg, WPARAM w, LPARAM l)
1027 + {
1028 +        ScanUtility* data = which(dialog);
1029 +
1030 +        switch (msg)
1031 +        {
1032 +        case WM_INITDIALOG:
1033 +                data = which(dialog, l);
1034 +
1035 +                {
1036 +                        ostringstream done;
1037 +
1038 +                        done << "You are done saving the scanned document. Click Finish to"
1039 +                                << " exit or click Back to return to the beginning.";
1040 +
1041 +                        SetDlgItemText(dialog, IDC_DONE_TEXT, done.str().c_str());
1042 +                }
1043 +                break;
1044 +        case WM_NOTIFY:
1045 +                {
1046 +                        LPNMHDR nm = LPNMHDR(l);
1047 +
1048 +                        switch (nm->code)
1049 +                        {
1050 +                        case PSN_SETACTIVE:
1051 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
1052 +                                        PSWIZB_FINISH);
1053 +                                break;
1054 +                        case PSN_WIZBACK:
1055 +                                data->client.setFile("");
1056 +                                PropSheet_SetCurSelByID(GetParent(dialog), IDD_START);
1057 +                                break;
1058 +                        case PSN_WIZFINISH:
1059 +                                break;
1060 +                        }
1061 +                }
1062 +                break;
1063 +        }
1064  
1065          return FALSE;
1066   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines