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.11 2003/08/26 06:41:12 douglas Exp $ |
6 |
|
|
7 |
|
#include "ScanUtility.h" |
8 |
|
|
9 |
< |
ScanUtility::ScanUtility() |
9 |
> |
ScanUtility::ScanUtility() : DiscBrowse() |
10 |
|
{ |
11 |
|
number = count++; |
12 |
– |
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"; |
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"; |
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 |
|
|
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); |
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); |
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()); |
530 |
|
switch (nm->code) |
531 |
|
{ |
532 |
|
case PSN_SETACTIVE: |
533 |
< |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_NEXT); |
533 |
> |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_FINISH | |
534 |
> |
PSWIZB_NEXT); |
535 |
> |
|
536 |
|
{ |
537 |
|
char folder[44]; |
538 |
|
|
588 |
|
{ |
589 |
|
ostringstream select; |
590 |
|
|
591 |
< |
select << "Select the scanned document that you need to be save."; |
591 |
> |
select << "Select the scanned document that you need to save."; |
592 |
|
|
593 |
|
SetDlgItemText(dialog, IDC_SELECT_TEXT, select.str().c_str()); |
594 |
|
} |
632 |
|
{ |
633 |
|
case PSN_SETACTIVE: |
634 |
|
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
635 |
< |
PSWIZB_NEXT); |
635 |
> |
PSWIZB_DISABLEDFINISH | PSWIZB_NEXT); |
636 |
|
data->populate(dialog); |
637 |
|
break; |
638 |
|
case PSN_WIZBACK: |
743 |
|
{ |
744 |
|
case WM_INITDIALOG: |
745 |
|
data = which(dialog, l); |
746 |
+ |
|
747 |
|
{ |
748 |
|
ostringstream enter; |
749 |
|
|
763 |
|
0) |
764 |
|
{ |
765 |
|
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
766 |
< |
PSWIZB_NEXT); |
766 |
> |
PSWIZB_DISABLEDFINISH | PSWIZB_NEXT); |
767 |
|
} |
768 |
|
else |
769 |
|
{ |
770 |
< |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK); |
770 |
> |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
771 |
> |
PSWIZB_DISABLEDFINISH); |
772 |
|
} |
773 |
|
|
774 |
|
SetDlgItemText(dialog, IDC_ENTER_NAME, |
792 |
|
cerr << "client = {\n" |
793 |
|
<< " name = " << data->client.getName() << "\n" |
794 |
|
<< " number = " << data->client.getNumber() << "\n" |
795 |
+ |
<< " file = " << data->client.getFile() << "\n" |
796 |
|
<< "}\n"; |
797 |
|
} |
798 |
+ |
|
799 |
+ |
data->save = data->saveDir + '\\' + data->client.getFile(); |
800 |
+ |
|
801 |
+ |
if (debug) cerr << "save = " << data->save << "\n"; |
802 |
+ |
|
803 |
|
break; |
804 |
|
} |
805 |
|
} |
822 |
|
if (data->client.getName() != "" && data->client.getNumber() != 0) |
823 |
|
{ |
824 |
|
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
825 |
< |
PSWIZB_NEXT); |
825 |
> |
PSWIZB_DISABLEDFINISH | PSWIZB_NEXT); |
826 |
|
} |
827 |
|
else |
828 |
|
{ |
829 |
< |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK); |
829 |
> |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
830 |
> |
PSWIZB_DISABLEDFINISH); |
831 |
|
} |
832 |
|
break; |
833 |
|
case IDC_ENTER_NUM: |
844 |
|
if (data->client.getName() != "" && data->client.getNumber() != 0) |
845 |
|
{ |
846 |
|
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
847 |
< |
PSWIZB_NEXT); |
847 |
> |
PSWIZB_DISABLEDFINISH | PSWIZB_NEXT); |
848 |
> |
} |
849 |
> |
else |
850 |
> |
{ |
851 |
> |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
852 |
> |
PSWIZB_DISABLEDFINISH); |
853 |
> |
} |
854 |
> |
break; |
855 |
> |
} |
856 |
> |
break; |
857 |
> |
} |
858 |
> |
|
859 |
> |
return FALSE; |
860 |
> |
} |
861 |
> |
|
862 |
> |
INT_PTR ScanUtility::confirm(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
863 |
> |
{ |
864 |
> |
ScanUtility* data = which(dialog); |
865 |
> |
|
866 |
> |
switch (msg) |
867 |
> |
{ |
868 |
> |
case WM_INITDIALOG: |
869 |
> |
data = which(dialog, l); |
870 |
> |
|
871 |
> |
{ |
872 |
> |
ostringstream confirm; |
873 |
> |
|
874 |
> |
confirm << "Confirm the client file\'s name and size."; |
875 |
> |
|
876 |
> |
SetDlgItemText(dialog, IDC_CONFIRM_TEXT, confirm.str().c_str()); |
877 |
> |
} |
878 |
> |
break; |
879 |
> |
case WM_NOTIFY: |
880 |
> |
{ |
881 |
> |
LPNMHDR nm = LPNMHDR(l); |
882 |
> |
|
883 |
> |
switch (nm->code) |
884 |
> |
{ |
885 |
> |
case PSN_SETACTIVE: |
886 |
> |
CheckDlgButton(dialog, IDC_CONFIRM_GOOD, BST_UNCHECKED); |
887 |
> |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
888 |
> |
PSWIZB_DISABLEDFINISH); |
889 |
> |
SetDlgItemText(dialog, IDC_CONFIRM_FILE, |
890 |
> |
data->client.getFile().c_str()); |
891 |
> |
|
892 |
> |
{ |
893 |
> |
HANDLE scan = CreateFile(data->scan.c_str(), GENERIC_READ, |
894 |
> |
FILE_SHARE_READ, NULL, OPEN_EXISTING, |
895 |
> |
FILE_ATTRIBUTE_NORMAL, NULL); |
896 |
> |
DWORD bytes = GetFileSize(scan, NULL); |
897 |
> |
|
898 |
> |
CloseHandle(scan); |
899 |
> |
|
900 |
> |
ostringstream size; |
901 |
> |
|
902 |
> |
size << format(bytes); |
903 |
> |
|
904 |
> |
size.setf(ios_base::fixed, ios_base::floatfield); |
905 |
> |
size.precision(2); |
906 |
> |
|
907 |
> |
FLOAT megabytes = FLOAT(bytes) / FLOAT(1024 * 1024); |
908 |
> |
|
909 |
> |
size << " bytes (" << megabytes << " MB)"; |
910 |
> |
|
911 |
> |
SetDlgItemText(dialog, IDC_CONFIRM_SIZE, |
912 |
> |
size.str().c_str()); |
913 |
> |
} |
914 |
> |
break; |
915 |
> |
case PSN_WIZBACK: |
916 |
> |
break; |
917 |
> |
case PSN_WIZNEXT: |
918 |
> |
if (MoveFile(data->scan.c_str(), data->save.c_str()) == 0) |
919 |
> |
{ |
920 |
> |
do |
921 |
> |
{ |
922 |
> |
LPVOID message; |
923 |
> |
|
924 |
> |
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
925 |
> |
FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), |
926 |
> |
0, LPTSTR(&message), 0, NULL); |
927 |
> |
|
928 |
> |
int code = MessageBox(dialog, LPCTSTR(message), |
929 |
> |
data->title.c_str(), MB_RETRYCANCEL | |
930 |
> |
MB_ICONEXCLAMATION); |
931 |
> |
|
932 |
> |
LocalFree(message); |
933 |
> |
|
934 |
> |
if (code == IDCANCEL) |
935 |
> |
{ |
936 |
> |
PropSheet_PressButton(GetParent(dialog), |
937 |
> |
PSBTN_BACK); |
938 |
> |
break; |
939 |
> |
} |
940 |
> |
} |
941 |
> |
while (MoveFileEx(data->scan.c_str(), data->save.c_str(), |
942 |
> |
MOVEFILE_REPLACE_EXISTING) == 0); |
943 |
> |
} |
944 |
> |
break; |
945 |
> |
} |
946 |
> |
} |
947 |
> |
break; |
948 |
> |
case WM_COMMAND: |
949 |
> |
switch (LOWORD(w)) |
950 |
> |
{ |
951 |
> |
case IDC_CONFIRM_GOOD: |
952 |
> |
if (IsDlgButtonChecked(dialog, IDC_CONFIRM_GOOD) == BST_CHECKED) |
953 |
> |
{ |
954 |
> |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
955 |
> |
PSWIZB_DISABLEDFINISH | PSWIZB_NEXT); |
956 |
|
} |
957 |
|
else |
958 |
|
{ |
959 |
< |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK); |
959 |
> |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
960 |
> |
PSWIZB_DISABLEDFINISH); |
961 |
|
} |
962 |
|
break; |
963 |
|
} |
964 |
|
break; |
965 |
|
} |
966 |
+ |
|
967 |
+ |
return FALSE; |
968 |
+ |
} |
969 |
+ |
|
970 |
+ |
INT_PTR ScanUtility::done(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
971 |
+ |
{ |
972 |
+ |
ScanUtility* data = which(dialog); |
973 |
+ |
|
974 |
+ |
switch (msg) |
975 |
+ |
{ |
976 |
+ |
case WM_INITDIALOG: |
977 |
+ |
data = which(dialog, l); |
978 |
+ |
|
979 |
+ |
{ |
980 |
+ |
ostringstream done; |
981 |
+ |
|
982 |
+ |
done << "You are done saving the scanned document. Click Finish to" |
983 |
+ |
<< " exit or click Back to return to the beginning."; |
984 |
+ |
|
985 |
+ |
SetDlgItemText(dialog, IDC_DONE_TEXT, done.str().c_str()); |
986 |
+ |
} |
987 |
+ |
break; |
988 |
+ |
case WM_NOTIFY: |
989 |
+ |
{ |
990 |
+ |
LPNMHDR nm = LPNMHDR(l); |
991 |
+ |
|
992 |
+ |
switch (nm->code) |
993 |
+ |
{ |
994 |
+ |
case PSN_SETACTIVE: |
995 |
+ |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
996 |
+ |
PSWIZB_FINISH); |
997 |
+ |
break; |
998 |
+ |
case PSN_WIZBACK: |
999 |
+ |
data->client.setFile(""); |
1000 |
+ |
PropSheet_SetCurSelByID(GetParent(dialog), IDD_START); |
1001 |
+ |
break; |
1002 |
+ |
case PSN_WIZFINISH: |
1003 |
+ |
break; |
1004 |
+ |
} |
1005 |
+ |
} |
1006 |
+ |
break; |
1007 |
+ |
} |
1008 |
|
|
1009 |
|
return FALSE; |
1010 |
|
} |