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 277 by douglas, 2003-08-24T00:31:45-07:00 vs.
Revision 291 by douglas, 2003-09-05T01:57:00-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.16 2003/09/05 08:57:00 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 200 | Line 193 | void ScanUtility::saveDirs(void)
193   {
194          HKEY key;
195  
196 <        if (RegCreateKeyEx(HKEY_CURRENT_USER,
196 >        if (LONG code = RegCreateKeyEx(HKEY_CURRENT_USER,
197                  "Software\\DouglasThrift\\VTBFileUtil2", 0, NULL,
198                  REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_SET_VALUE, NULL, &key,
199                  NULL) == ERROR_SUCCESS)
# Line 225 | Line 218 | void ScanUtility::saveDirs(void)
218                                  LPBYTE(scanDir.c_str()), scanDir.length() + 1) !=
219                                  ERROR_SUCCESS)
220                          {
221 <                                error();
221 >                                error(NULL, code);
222                          }
223                  }
224  
# Line 247 | Line 240 | void ScanUtility::saveDirs(void)
240                                  LPBYTE(saveDir.c_str()), saveDir.length() + 1) !=
241                                  ERROR_SUCCESS)
242                          {
243 <                                error();
243 >                                error(NULL, code);
244                          }
245                  }
246  
# Line 255 | Line 248 | void ScanUtility::saveDirs(void)
248          }
249          else
250          {
251 <                error();
251 >                error(NULL, code);
252          }
253   }
254  
# 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 398 | Line 385 | void ScanUtility::populate(HWND parent)
385                  if (scans.empty())
386                  {
387                          if (MessageBox(parent, "No scanned documents found.",
388 <                                programName.c_str(), MB_RETRYCANCEL | MB_ICONQUESTION) ==
389 <                                IDCANCEL) break;
388 >                                title.c_str(), MB_RETRYCANCEL | MB_ICONQUESTION) == IDCANCEL)
389 >                                break;
390                  }
391          }
392          while (scans.empty());
# Line 475 | Line 462 | int ScanUtility::browse(HWND dialog, UIN
462                  SendMessage(dialog, BFFM_SETOKTEXT, 0,
463                          LPARAM(toWide("&Select").c_str()));
464                  SendMessage(dialog, BFFM_SETEXPANDED, FALSE, CSIDL_DRIVES);
465 <                SendMessage(dialog, BFFM_SETSELECTION, TRUE, LPARAM(HIWORD(d) ?
466 <                        data->scanDir.c_str() : data->saveDir.c_str()));
465 >
466 >                if ((HIWORD(d) ? data->scanDir : data->saveDir) != "")
467 >                {
468 >                        IShellFolder* desktop;
469 >                        LPWSTR path = new WCHAR[(HIWORD(d) ? data->scanDir.length() :
470 >                                data->saveDir.length()) + 1];
471 >                        LPITEMIDLIST id;
472 >
473 >                        wsprintfW(path, toWide(HIWORD(d) ? data->scanDir :
474 >                                data->saveDir).c_str());
475 >
476 >                        if (debug) cerr << "path = " << toAnsi(path) << "\n";
477 >
478 >                        SHGetDesktopFolder(&desktop);
479 >                        desktop->ParseDisplayName(dialog, NULL, path, NULL, &id, NULL);
480 >
481 >                        if (id != NULL)
482 >                        {
483 >                                SendMessage(dialog, BFFM_SETSELECTION, FALSE, LPARAM(id));
484 >
485 >                                LPMALLOC destruct;
486 >
487 >                                SHGetMalloc(&destruct);
488 >                                destruct->Free(id);
489 >                                destruct->Release();
490 >                        }
491 >
492 >                        desktop->Release();
493 >                }
494                  break;
495          case BFFM_SELCHANGED:
496                  {
497 <                        IShellFolder* object;
497 >                        SHFILEINFO info;
498  
499 <                        SHGetDesktopFolder(&object);
499 >                        SHGetFileInfo(LPCSTR(l), 0, &info, sizeof(info), SHGFI_DISPLAYNAME
500 >                                | SHGFI_PIDL);
501 >                        SendMessage(dialog, BFFM_SETSTATUSTEXT, 0,
502 >                                LPARAM(info.szDisplayName));
503  
504 <                        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));
504 >                        char folder[MAX_PATH];
505  
506 <                        if (PathIsUNCServer(folder))
506 >                        if (!SHGetPathFromIDList(LPCITEMIDLIST(l), folder))
507                          {
508                                  SendMessage(dialog, BFFM_ENABLEOK, 0, 0);
509                          }
510 <
511 <                        CoTaskMemFree(folder);
512 <                        object->Release();
510 >                        else
511 >                        {
512 >                                SendMessage(dialog, BFFM_SETSTATUSTEXT, 0, LPARAM(folder));
513 >                        }
514                  }
515                  break;
516          }
# Line 537 | Line 549 | INT_PTR ScanUtility::start(HWND dialog,
549                          switch (nm->code)
550                          {
551                          case PSN_SETACTIVE:
552 <                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_NEXT);
552 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_FINISH |
553 >                                        PSWIZB_NEXT);
554 >
555 >                                {
556 >                                        SHFILEINFO info;
557 >
558 >                                        SHGetFileInfo(data->scanDir.c_str(), 0, &info,
559 >                                                sizeof(info), SHGFI_ICONLOCATION);
560 >
561 >                                        HICON icon = ExtractIcon(gui.instance, info.szDisplayName,
562 >                                                info.iIcon);
563 >
564 >                                        SendDlgItemMessage(dialog, IDC_START_SCAN_ICON,
565 >                                                STM_SETIMAGE, IMAGE_ICON, LPARAM(icon));
566 >                                        SHGetFileInfo(data->saveDir.c_str(), 0, &info,
567 >                                                sizeof(info), SHGFI_ICONLOCATION);
568 >
569 >                                        icon = ExtractIcon(gui.instance, info.szDisplayName,
570 >                                                info.iIcon);
571 >
572 >                                        SendDlgItemMessage(dialog, IDC_START_SAVE_ICON,
573 >                                                STM_SETIMAGE, IMAGE_ICON, LPARAM(icon));
574 >                                }
575 >
576                                  {
577 <                                        char folder[44];
577 >                                        char folder[38];
578  
579 <                                        PathCompactPathEx(folder, data->scanDir.c_str(), 44, 0);
579 >                                        PathCompactPathEx(folder, data->scanDir.substr(0,
580 >                                                data->scanDir.length() - 1).c_str(), 38, 0);
581                                          SetDlgItemText(dialog, IDC_START_SCAN_TEXT, folder);
582 <                                        PathCompactPathEx(folder, data->saveDir.c_str(), 44, 0);
582 >                                        PathCompactPathEx(folder, data->saveDir.substr(0,
583 >                                                data->saveDir.length() - 1).c_str(), 38, 0);
584                                          SetDlgItemText(dialog, IDC_START_SAVE_TEXT, folder);
585                                  }
586                                  break;
# Line 558 | Line 595 | INT_PTR ScanUtility::start(HWND dialog,
595                  {
596                  case IDC_START_SCAN_BROWSE:
597                          data->setScanDir(dialog);
598 +
599                          {
600 <                                char folder[44];
600 >                                SHFILEINFO info;
601 >
602 >                                SHGetFileInfo(data->scanDir.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_SCAN_ICON, STM_SETIMAGE,
609 >                                        IMAGE_ICON, LPARAM(icon));
610 >                        }
611  
612 <                                PathCompactPathEx(folder, data->scanDir.c_str(), 44, 0);
612 >                        {
613 >                                char folder[38];
614 >
615 >                                PathCompactPathEx(folder, data->scanDir.substr(0,
616 >                                        data->scanDir.length() - 1).c_str(), 38, 0);
617                                  SetDlgItemText(dialog, IDC_START_SCAN_TEXT, folder);
618                          }
619                          break;
620                  case IDC_START_SAVE_BROWSE:
621                          data->setSaveDir(dialog);
622 +
623                          {
624 <                                char folder[44];
624 >                                SHFILEINFO info;
625 >
626 >                                SHGetFileInfo(data->saveDir.c_str(), 0, &info, sizeof(info),
627 >                                        SHGFI_ICONLOCATION);
628 >
629 >                                HICON icon = ExtractIcon(gui.instance, info.szDisplayName,
630 >                                        info.iIcon);
631  
632 <                                PathCompactPathEx(folder, data->saveDir.c_str(), 44, 0);
632 >                                SendDlgItemMessage(dialog, IDC_START_SAVE_ICON, STM_SETIMAGE,
633 >                                        IMAGE_ICON, LPARAM(icon));
634 >                        }
635 >
636 >                        {
637 >                                char folder[38];
638 >
639 >                                PathCompactPathEx(folder, data->saveDir.substr(0,
640 >                                        data->saveDir.length() - 1).c_str(), 38, 0);
641                                  SetDlgItemText(dialog, IDC_START_SAVE_TEXT, folder);
642                          }
643                          break;
# Line 593 | Line 660 | INT_PTR ScanUtility::select(HWND dialog,
660                  {
661                          ostringstream select;
662  
663 <                        select << "Select the scanned document that you need to be save.";
663 >                        select << "Select the scanned document that you need to save.";
664  
665                          SetDlgItemText(dialog, IDC_SELECT_TEXT, select.str().c_str());
666                  }
# Line 618 | Line 685 | INT_PTR ScanUtility::select(HWND dialog,
685                          switch (ni->hdr.code)
686                          {
687                          case NM_DBLCLK:
688 +                                if (ni->iItem != -1)
689                                  {
690                                          char scan[MAX_PATH];
691  
# Line 637 | Line 705 | INT_PTR ScanUtility::select(HWND dialog,
705                          {
706                          case PSN_SETACTIVE:
707                                  PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
708 <                                        PSWIZB_NEXT);
708 >                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
709                                  data->populate(dialog);
710                                  break;
711                          case PSN_WIZBACK:
# Line 650 | Line 718 | INT_PTR ScanUtility::select(HWND dialog,
718                                                  IDC_SELECT_SCANS), -1, LVNI_SELECTED);
719                                          char scan[MAX_PATH];
720  
721 <                                        ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS),
722 <                                                index, 0, scan, MAX_PATH);
721 >                                        if (index != -1)
722 >                                        {
723 >                                                ListView_GetItemText(GetDlgItem(dialog,
724 >                                                        IDC_SELECT_SCANS), index, 0, scan, MAX_PATH);
725 >                                        }
726 >                                        else
727 >                                        {
728 >                                                ListView_GetItemText(GetDlgItem(dialog,
729 >                                                        IDC_SELECT_SCANS), 0, 0, scan, MAX_PATH);
730 >                                        }
731  
732                                          data->scan = scan;
733                                  }
734  
659                                ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
660
735                                  if (debug) cerr << "scan = " << data->scan << "\n";
736 +
737 +                                ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
738                                  break;
739                          }
740                  }
741                  break;
742          case WM_CONTEXTMENU:
743 +                if (ListView_GetNextItem(GetDlgItem(dialog, IDC_SELECT_SCANS), -1,
744 +                        LVNI_SELECTED) != -1)
745                  {
746                          char scan[MAX_PATH];
747                          POINT spot;
# Line 699 | Line 777 | INT_PTR ScanUtility::select(HWND dialog,
777                                  spot.x = rect.left;
778                                  spot.y = rect.top;
779                          }
702                        else
703                        {
704                                break;
705                        }
780  
781                          ClientToScreen(GetDlgItem(dialog, IDC_SELECT_SCANS), &spot);
782  
# Line 748 | Line 822 | INT_PTR ScanUtility::enter(HWND dialog,
822          {
823          case WM_INITDIALOG:
824                  data = which(dialog, l);
825 +
826                  {
827                          ostringstream enter;
828  
# Line 767 | Line 842 | INT_PTR ScanUtility::enter(HWND dialog,
842                                          0)
843                                  {
844                                          PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
845 <                                                PSWIZB_NEXT);
845 >                                                PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
846                                  }
847                                  else
848                                  {
849 <                                        PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK);
849 >                                        PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
850 >                                                PSWIZB_DISABLEDFINISH);
851                                  }
852  
853                                  SetDlgItemText(dialog, IDC_ENTER_NAME,
# Line 795 | Line 871 | INT_PTR ScanUtility::enter(HWND dialog,
871                                          cerr << "client = {\n"
872                                                  << "   name = " << data->client.getName() << "\n"
873                                                  << "   number = " << data->client.getNumber() << "\n"
874 +                                                << "   file = " << data->client.getFile() << "\n"
875                                                  << "}\n";
876                                  }
877 +
878 +                                data->save = data->saveDir + '\\' + data->client.getFile();
879 +
880 +                                if (debug) cerr << "save = " << data->save << "\n";
881 +                                
882                                  break;
883                          }
884                  }
# Line 819 | Line 901 | INT_PTR ScanUtility::enter(HWND dialog,
901                          if (data->client.getName() != "" && data->client.getNumber() != 0)
902                          {
903                                  PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
904 <                                        PSWIZB_NEXT);
904 >                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
905                          }
906                          else
907                          {
908 <                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK);
908 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
909 >                                        PSWIZB_DISABLEDFINISH);
910                          }
911                          break;
912                  case IDC_ENTER_NUM:
# Line 840 | Line 923 | INT_PTR ScanUtility::enter(HWND dialog,
923                          if (data->client.getName() != "" && data->client.getNumber() != 0)
924                          {
925                                  PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
926 <                                        PSWIZB_NEXT);
926 >                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
927                          }
928                          else
929                          {
930 <                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK);
930 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
931 >                                        PSWIZB_DISABLEDFINISH);
932                          }
933                          break;
934                  }
935                  break;
936          }
937 +
938 +        return FALSE;
939 + }
940 +
941 + INT_PTR ScanUtility::confirm(HWND dialog, UINT msg, WPARAM w, LPARAM l)
942 + {
943 +        ScanUtility* data = which(dialog);
944 +
945 +        switch (msg)
946 +        {
947 +        case WM_INITDIALOG:
948 +                data = which(dialog, l);
949 +
950 +                {
951 +                        ostringstream confirm;
952 +
953 +                        confirm << "Confirm the client file\'s name and size.";
954 +
955 +                        SetDlgItemText(dialog, IDC_CONFIRM_TEXT, confirm.str().c_str());
956 +                }
957 +                break;
958 +        case WM_NOTIFY:
959 +                {
960 +                        LPNMHDR nm = LPNMHDR(l);
961 +
962 +                        switch (nm->code)
963 +                        {
964 +                        case PSN_SETACTIVE:
965 +                                CheckDlgButton(dialog, IDC_CONFIRM_GOOD, BST_UNCHECKED);
966 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
967 +                                        PSWIZB_DISABLEDFINISH);
968 +                                SetDlgItemText(dialog, IDC_CONFIRM_FILE,
969 +                                        data->client.getFile().c_str());
970 +
971 +                                {
972 +                                        HANDLE scan = CreateFile(data->scan.c_str(), GENERIC_READ,
973 +                                                FILE_SHARE_READ, NULL, OPEN_EXISTING,
974 +                                                FILE_ATTRIBUTE_NORMAL, NULL);
975 +                                        DWORD bytes = GetFileSize(scan, NULL);
976 +
977 +                                        CloseHandle(scan);
978 +
979 +                                        ostringstream size;
980 +
981 +                                        size << format(bytes);
982 +
983 +                                        size.setf(ios_base::fixed, ios_base::floatfield);
984 +                                        size.precision(2);
985 +                                        
986 +                                        FLOAT megabytes = FLOAT(bytes) / FLOAT(1024 * 1024);
987 +
988 +                                        size << " bytes (" << megabytes << " MB)";
989 +
990 +                                        SetDlgItemText(dialog, IDC_CONFIRM_SIZE,
991 +                                                size.str().c_str());
992 +                                }
993 +                                break;
994 +                        case PSN_WIZBACK:
995 +                                break;
996 +                        case PSN_WIZNEXT:
997 +                                if (MoveFile(data->scan.c_str(), data->save.c_str()) == 0)
998 +                                {
999 +                                        do
1000 +                                        {
1001 +                                                LPVOID message;
1002 +                                                
1003 +                                                FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
1004 +                                                        FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
1005 +                                                        0, LPTSTR(&message), 0, NULL);
1006 +
1007 +                                                int code = MessageBox(dialog, LPCTSTR(message),
1008 +                                                        data->title.c_str(), MB_RETRYCANCEL |
1009 +                                                        MB_ICONEXCLAMATION);
1010 +
1011 +                                                LocalFree(message);
1012 +
1013 +                                                if (code == IDCANCEL)
1014 +                                                {
1015 +                                                        PropSheet_PressButton(GetParent(dialog),
1016 +                                                                PSBTN_BACK);
1017 +                                                        break;
1018 +                                                }
1019 +                                        }
1020 +                                        while (MoveFileEx(data->scan.c_str(), data->save.c_str(),
1021 +                                                MOVEFILE_REPLACE_EXISTING) == 0);
1022 +                                }
1023 +                                break;
1024 +                        }
1025 +                }
1026 +                break;
1027 +        case WM_COMMAND:
1028 +                switch (LOWORD(w))
1029 +                {
1030 +                case IDC_CONFIRM_GOOD:
1031 +                        if (IsDlgButtonChecked(dialog, IDC_CONFIRM_GOOD) == BST_CHECKED)
1032 +                        {
1033 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
1034 +                                        PSWIZB_DISABLEDFINISH | PSWIZB_NEXT);
1035 +                        }
1036 +                        else
1037 +                        {
1038 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
1039 +                                        PSWIZB_DISABLEDFINISH);
1040 +                        }
1041 +                        break;
1042 +                }
1043 +                break;
1044 +        }
1045 +
1046 +        return FALSE;
1047 + }
1048 +
1049 + INT_PTR ScanUtility::done(HWND dialog, UINT msg, WPARAM w, LPARAM l)
1050 + {
1051 +        ScanUtility* data = which(dialog);
1052 +
1053 +        switch (msg)
1054 +        {
1055 +        case WM_INITDIALOG:
1056 +                data = which(dialog, l);
1057 +
1058 +                {
1059 +                        ostringstream done;
1060 +
1061 +                        done << "You are done saving the scanned document. Click Finish to"
1062 +                                << " exit or click Back to return to the beginning.";
1063 +
1064 +                        SetDlgItemText(dialog, IDC_DONE_TEXT, done.str().c_str());
1065 +                }
1066 +                break;
1067 +        case WM_NOTIFY:
1068 +                {
1069 +                        LPNMHDR nm = LPNMHDR(l);
1070 +
1071 +                        switch (nm->code)
1072 +                        {
1073 +                        case PSN_SETACTIVE:
1074 +                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
1075 +                                        PSWIZB_FINISH);
1076 +                                break;
1077 +                        case PSN_WIZBACK:
1078 +                                data->client.setFile("");
1079 +                                PropSheet_SetCurSelByID(GetParent(dialog), IDD_START);
1080 +                                break;
1081 +                        case PSN_WIZFINISH:
1082 +                                break;
1083 +                        }
1084 +                }
1085 +                break;
1086 +        }
1087  
1088          return FALSE;
1089   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines