1 |
douglas |
260 |
// Vance Thrift and Biller File Utility 2 |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
douglas |
295 |
// $Id: ScanUtility.cxx,v 1.18 2003/09/12 04:26:54 douglas Exp $ |
6 |
douglas |
260 |
|
7 |
|
|
#include "ScanUtility.h" |
8 |
douglas |
265 |
|
9 |
douglas |
282 |
ScanUtility::ScanUtility() : DiscBrowse() |
10 |
douglas |
268 |
{ |
11 |
|
|
number = count++; |
12 |
douglas |
282 |
|
13 |
douglas |
268 |
utilities.insert(pair<unsigned, ScanUtility*>(number, this)); |
14 |
|
|
|
15 |
douglas |
282 |
title = programName + " - Scan Utility"; |
16 |
douglas |
274 |
|
17 |
douglas |
268 |
// start |
18 |
douglas |
271 |
wizard[0].dwSize = sizeof(wizard[0]); |
19 |
douglas |
282 |
wizard[0].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE | |
20 |
|
|
PSP_USEHEADERSUBTITLE; |
21 |
douglas |
271 |
wizard[0].hInstance = gui.instance; |
22 |
|
|
wizard[0].pszTemplate = MAKEINTRESOURCE(IDD_START); |
23 |
douglas |
282 |
wizard[0].pszTitle = title.c_str(); |
24 |
douglas |
271 |
wizard[0].pfnDlgProc = start; |
25 |
|
|
wizard[0].lParam = number; |
26 |
|
|
wizard[0].pszHeaderTitle = "Start"; |
27 |
|
|
wizard[0].pszHeaderSubTitle = "Change any settings before scanning."; |
28 |
douglas |
273 |
|
29 |
|
|
// select |
30 |
|
|
wizard[1].dwSize = sizeof(wizard[1]); |
31 |
douglas |
282 |
wizard[1].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE | |
32 |
|
|
PSP_USEHEADERSUBTITLE; |
33 |
douglas |
273 |
wizard[1].hInstance = gui.instance; |
34 |
|
|
wizard[1].pszTemplate = MAKEINTRESOURCE(IDD_SELECT); |
35 |
douglas |
282 |
wizard[1].pszTitle = title.c_str(); |
36 |
douglas |
273 |
wizard[1].pfnDlgProc = select; |
37 |
|
|
wizard[1].lParam = number; |
38 |
|
|
wizard[1].pszHeaderTitle = "Select"; |
39 |
|
|
wizard[1].pszHeaderSubTitle = "Choose the scanned document to save."; |
40 |
douglas |
274 |
|
41 |
|
|
// enter |
42 |
|
|
wizard[2].dwSize = sizeof(wizard[2]); |
43 |
douglas |
282 |
wizard[2].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE | |
44 |
|
|
PSP_USEHEADERSUBTITLE; |
45 |
douglas |
274 |
wizard[2].hInstance = gui.instance; |
46 |
|
|
wizard[2].pszTemplate = MAKEINTRESOURCE(IDD_ENTER); |
47 |
douglas |
282 |
wizard[2].pszTitle = title.c_str(); |
48 |
douglas |
274 |
wizard[2].pfnDlgProc = enter; |
49 |
douglas |
277 |
wizard[2].lParam = number; |
50 |
douglas |
274 |
wizard[2].pszHeaderTitle = "Enter"; |
51 |
|
|
wizard[2].pszHeaderSubTitle = "Input the client information."; |
52 |
douglas |
278 |
|
53 |
|
|
// confirm |
54 |
|
|
wizard[3].dwSize = sizeof(wizard[3]); |
55 |
douglas |
282 |
wizard[3].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE | |
56 |
|
|
PSP_USEHEADERSUBTITLE; |
57 |
douglas |
278 |
wizard[3].hInstance = gui.instance; |
58 |
|
|
wizard[3].pszTemplate = MAKEINTRESOURCE(IDD_CONFIRM); |
59 |
douglas |
282 |
wizard[3].pszTitle = title.c_str(); |
60 |
douglas |
278 |
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 |
douglas |
282 |
wizard[4].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE | |
68 |
|
|
PSP_USEHEADERSUBTITLE; |
69 |
douglas |
278 |
wizard[4].hInstance = gui.instance; |
70 |
|
|
wizard[4].pszTemplate = MAKEINTRESOURCE(IDD_DONE); |
71 |
douglas |
282 |
wizard[4].pszTitle = title.c_str(); |
72 |
douglas |
278 |
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 |
douglas |
268 |
} |
77 |
|
|
|
78 |
|
|
ScanUtility::~ScanUtility() |
79 |
|
|
{ |
80 |
|
|
utilities.erase(number); |
81 |
|
|
} |
82 |
|
|
|
83 |
douglas |
265 |
void ScanUtility::run(void) |
84 |
|
|
{ |
85 |
douglas |
282 |
loadDirs(); |
86 |
|
|
|
87 |
douglas |
268 |
PROPSHEETHEADER header; |
88 |
douglas |
265 |
|
89 |
douglas |
268 |
// header |
90 |
|
|
header.dwSize = sizeof(header); |
91 |
douglas |
271 |
header.dwFlags = PSH_DEFAULT | PSH_HEADER | PSH_PROPSHEETPAGE | |
92 |
douglas |
278 |
PSH_USEICONID | PSH_WIZARD97 | PSH_WIZARDHASFINISH; |
93 |
douglas |
268 |
header.hwndParent = NULL; |
94 |
|
|
header.hInstance = gui.instance; |
95 |
|
|
header.pszIcon = MAKEINTRESOURCE(IDI_VTB_ICON); |
96 |
douglas |
278 |
header.nPages = 5; |
97 |
douglas |
268 |
header.nStartPage = 0; |
98 |
douglas |
271 |
header.ppsp = wizard; |
99 |
douglas |
269 |
header.pszbmHeader = MAKEINTRESOURCE(IDB_VTB_BMP); |
100 |
douglas |
265 |
|
101 |
douglas |
268 |
PropertySheet(&header); |
102 |
douglas |
282 |
saveDirs(); |
103 |
douglas |
268 |
} |
104 |
|
|
|
105 |
|
|
map<unsigned, ScanUtility*> ScanUtility::utilities; |
106 |
|
|
map<HWND, ScanUtility*> ScanUtility::windows; |
107 |
|
|
|
108 |
douglas |
269 |
void ScanUtility::loadDirs(void) |
109 |
|
|
{ |
110 |
|
|
HKEY key; |
111 |
|
|
|
112 |
|
|
if (RegOpenKeyEx(HKEY_CURRENT_USER, |
113 |
douglas |
271 |
"Software\\DouglasThrift\\VTBFileUtil2", 0, KEY_QUERY_VALUE, &key) == |
114 |
douglas |
269 |
ERROR_SUCCESS) |
115 |
|
|
{ |
116 |
|
|
DWORD type; |
117 |
douglas |
271 |
char data[MAX_PATH]; |
118 |
douglas |
269 |
DWORD size = MAX_PATH; |
119 |
|
|
|
120 |
douglas |
271 |
if (RegQueryValueEx(key, "ScanDir", NULL, &type, LPBYTE(data), &size) |
121 |
|
|
== ERROR_SUCCESS) |
122 |
douglas |
269 |
{ |
123 |
|
|
data[size - 1] = '\0'; |
124 |
|
|
|
125 |
|
|
switch (type) |
126 |
|
|
{ |
127 |
|
|
case REG_EXPAND_SZ: |
128 |
douglas |
273 |
{ |
129 |
|
|
char folder[MAX_PATH]; |
130 |
|
|
|
131 |
|
|
ExpandEnvironmentStrings(data, folder, MAX_PATH); |
132 |
|
|
|
133 |
douglas |
288 |
scanDir = tail(folder); |
134 |
douglas |
273 |
} |
135 |
douglas |
269 |
break; |
136 |
|
|
case REG_SZ: |
137 |
douglas |
288 |
scanDir = tail(data); |
138 |
douglas |
269 |
break; |
139 |
|
|
default: |
140 |
|
|
setScanDir(); |
141 |
|
|
break; |
142 |
|
|
} |
143 |
|
|
} |
144 |
|
|
else |
145 |
|
|
{ |
146 |
|
|
setScanDir(); |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
size = MAX_PATH; |
150 |
|
|
|
151 |
douglas |
271 |
if (RegQueryValueEx(key, "SaveDir", NULL, &type, LPBYTE(data), &size) |
152 |
|
|
== ERROR_SUCCESS) |
153 |
douglas |
269 |
{ |
154 |
|
|
data[size - 1] = '\0'; |
155 |
|
|
|
156 |
|
|
switch (type) |
157 |
|
|
{ |
158 |
|
|
case REG_EXPAND_SZ: |
159 |
douglas |
273 |
{ |
160 |
|
|
char folder[MAX_PATH]; |
161 |
|
|
|
162 |
|
|
ExpandEnvironmentStrings(data, folder, MAX_PATH); |
163 |
|
|
|
164 |
douglas |
288 |
saveDir = tail(folder); |
165 |
douglas |
273 |
} |
166 |
douglas |
269 |
break; |
167 |
|
|
case REG_SZ: |
168 |
douglas |
288 |
saveDir = tail(data); |
169 |
douglas |
269 |
break; |
170 |
|
|
default: |
171 |
|
|
setSaveDir(); |
172 |
|
|
break; |
173 |
|
|
} |
174 |
|
|
} |
175 |
|
|
else |
176 |
|
|
{ |
177 |
|
|
setSaveDir(); |
178 |
|
|
} |
179 |
|
|
|
180 |
|
|
RegCloseKey(key); |
181 |
|
|
} |
182 |
|
|
else |
183 |
|
|
{ |
184 |
|
|
setScanDir(); |
185 |
|
|
setSaveDir(); |
186 |
|
|
} |
187 |
douglas |
271 |
|
188 |
|
|
if (debug) cerr << "scanDir = " << scanDir << "\n" |
189 |
douglas |
273 |
<< "saveDir = " << saveDir << "\n"; |
190 |
douglas |
269 |
} |
191 |
|
|
|
192 |
|
|
void ScanUtility::saveDirs(void) |
193 |
|
|
{ |
194 |
|
|
HKEY key; |
195 |
|
|
|
196 |
douglas |
291 |
if (LONG code = RegCreateKeyEx(HKEY_CURRENT_USER, |
197 |
douglas |
269 |
"Software\\DouglasThrift\\VTBFileUtil2", 0, NULL, |
198 |
douglas |
271 |
REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_SET_VALUE, NULL, &key, |
199 |
|
|
NULL) == ERROR_SUCCESS) |
200 |
douglas |
269 |
{ |
201 |
douglas |
271 |
DWORD type; |
202 |
|
|
char data[MAX_PATH]; |
203 |
|
|
DWORD size = MAX_PATH; |
204 |
|
|
|
205 |
|
|
if (RegQueryValueEx(key, "ScanDir", NULL, &type, LPBYTE(data), &size) |
206 |
|
|
== ERROR_SUCCESS) |
207 |
douglas |
269 |
{ |
208 |
douglas |
271 |
data[size - 1] = '\0'; |
209 |
douglas |
269 |
} |
210 |
douglas |
271 |
else |
211 |
|
|
{ |
212 |
|
|
data[0] = '\0'; |
213 |
|
|
} |
214 |
douglas |
269 |
|
215 |
douglas |
273 |
if (scanDir != data || type != REG_SZ) |
216 |
douglas |
269 |
{ |
217 |
douglas |
273 |
if (RegSetValueEx(key, "ScanDir", 0, REG_SZ, |
218 |
|
|
LPBYTE(scanDir.c_str()), scanDir.length() + 1) != |
219 |
douglas |
271 |
ERROR_SUCCESS) |
220 |
|
|
{ |
221 |
douglas |
291 |
error(NULL, code); |
222 |
douglas |
271 |
} |
223 |
douglas |
269 |
} |
224 |
|
|
|
225 |
douglas |
271 |
size = MAX_PATH; |
226 |
|
|
|
227 |
|
|
if (RegQueryValueEx(key, "SaveDir", NULL, &type, LPBYTE(data), &size) |
228 |
|
|
== ERROR_SUCCESS) |
229 |
|
|
{ |
230 |
|
|
data[size - 1] = '\0'; |
231 |
|
|
} |
232 |
|
|
else |
233 |
|
|
{ |
234 |
|
|
data[0] = '\0'; |
235 |
|
|
} |
236 |
|
|
|
237 |
douglas |
273 |
if (saveDir != data || type != REG_SZ) |
238 |
douglas |
271 |
{ |
239 |
douglas |
273 |
if (RegSetValueEx(key, "SaveDir", 0, REG_SZ, |
240 |
|
|
LPBYTE(saveDir.c_str()), saveDir.length() + 1) != |
241 |
douglas |
271 |
ERROR_SUCCESS) |
242 |
|
|
{ |
243 |
douglas |
291 |
error(NULL, code); |
244 |
douglas |
271 |
} |
245 |
|
|
} |
246 |
|
|
|
247 |
douglas |
269 |
RegCloseKey(key); |
248 |
|
|
} |
249 |
|
|
else |
250 |
|
|
{ |
251 |
douglas |
291 |
error(NULL, code); |
252 |
douglas |
269 |
} |
253 |
|
|
} |
254 |
|
|
|
255 |
|
|
void ScanUtility::setScanDir(HWND parent) |
256 |
|
|
{ |
257 |
douglas |
292 |
char buffer[MAX_PATH]; |
258 |
|
|
|
259 |
|
|
SHGetFolderPath(parent, CSIDL_FLAG_CREATE | CSIDL_DESKTOPDIRECTORY, NULL, |
260 |
|
|
0, buffer); |
261 |
|
|
|
262 |
douglas |
271 |
BROWSEINFO info; |
263 |
douglas |
269 |
|
264 |
douglas |
271 |
info.hwndOwner = parent; |
265 |
|
|
info.pidlRoot = NULL; |
266 |
|
|
info.pszDisplayName = NULL; |
267 |
|
|
info.lpszTitle = "Select the Scan Directory"; |
268 |
|
|
info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT; |
269 |
|
|
info.lpfn = browse; |
270 |
|
|
info.lParam = MAKELPARAM(number, true); |
271 |
|
|
info.iImage = 0; |
272 |
|
|
|
273 |
|
|
do |
274 |
|
|
{ |
275 |
|
|
LPITEMIDLIST id = SHBrowseForFolder(&info); |
276 |
|
|
|
277 |
|
|
if (id != NULL) |
278 |
|
|
{ |
279 |
|
|
char folder[MAX_PATH]; |
280 |
|
|
|
281 |
douglas |
288 |
if (SHGetPathFromIDList(id, folder)) scanDir = tail(folder); |
282 |
douglas |
271 |
} |
283 |
|
|
|
284 |
|
|
LPMALLOC destruct; |
285 |
|
|
|
286 |
|
|
SHGetMalloc(&destruct); |
287 |
|
|
destruct->Free(id); |
288 |
|
|
destruct->Release(); |
289 |
|
|
|
290 |
|
|
if (scanDir == "") |
291 |
|
|
{ |
292 |
|
|
switch (MessageBox(parent, "Scan Directory needs to be selected.", |
293 |
douglas |
282 |
title.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR)) |
294 |
douglas |
271 |
{ |
295 |
|
|
case IDABORT: |
296 |
|
|
exit(1); |
297 |
|
|
break; |
298 |
|
|
case IDRETRY: |
299 |
|
|
break; |
300 |
|
|
case IDIGNORE: |
301 |
|
|
Beep(2200, 250); |
302 |
|
|
Beep(1100, 500); |
303 |
|
|
Beep(3300, 250); |
304 |
|
|
exit(2); |
305 |
|
|
break; |
306 |
|
|
} |
307 |
|
|
} |
308 |
|
|
} |
309 |
|
|
while (scanDir == ""); |
310 |
douglas |
273 |
|
311 |
|
|
if (debug) cerr << "scanDir = " << scanDir << "\n"; |
312 |
douglas |
269 |
} |
313 |
|
|
|
314 |
|
|
void ScanUtility::setSaveDir(HWND parent) |
315 |
|
|
{ |
316 |
douglas |
292 |
char buffer[MAX_PATH]; |
317 |
|
|
|
318 |
|
|
SHGetFolderPath(parent, CSIDL_FLAG_CREATE | CSIDL_DESKTOPDIRECTORY, NULL, |
319 |
|
|
0, buffer); |
320 |
|
|
|
321 |
douglas |
271 |
BROWSEINFO info; |
322 |
douglas |
269 |
|
323 |
douglas |
271 |
info.hwndOwner = parent; |
324 |
|
|
info.pidlRoot = NULL; |
325 |
|
|
info.pszDisplayName = NULL; |
326 |
|
|
info.lpszTitle = "Select the Save Directory"; |
327 |
|
|
info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT; |
328 |
|
|
info.lpfn = browse; |
329 |
|
|
info.lParam = MAKELPARAM(number, false); |
330 |
|
|
info.iImage = 0; |
331 |
|
|
|
332 |
|
|
do |
333 |
|
|
{ |
334 |
|
|
LPITEMIDLIST id = SHBrowseForFolder(&info); |
335 |
|
|
|
336 |
|
|
if (id != NULL) |
337 |
|
|
{ |
338 |
|
|
char folder[MAX_PATH]; |
339 |
|
|
|
340 |
douglas |
288 |
if (SHGetPathFromIDList(id, folder)) saveDir = tail(folder); |
341 |
douglas |
271 |
} |
342 |
|
|
|
343 |
|
|
LPMALLOC destruct; |
344 |
|
|
|
345 |
|
|
SHGetMalloc(&destruct); |
346 |
|
|
destruct->Free(id); |
347 |
|
|
destruct->Release(); |
348 |
|
|
|
349 |
|
|
if (saveDir == "") |
350 |
|
|
{ |
351 |
|
|
switch (MessageBox(parent, "Scan Directory needs to be selected.", |
352 |
douglas |
282 |
title.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR)) |
353 |
douglas |
271 |
{ |
354 |
|
|
case IDABORT: |
355 |
|
|
exit(1); |
356 |
|
|
break; |
357 |
|
|
case IDRETRY: |
358 |
|
|
break; |
359 |
|
|
case IDIGNORE: |
360 |
|
|
Beep(2200, 250); |
361 |
|
|
Beep(1100, 500); |
362 |
|
|
Beep(3300, 250); |
363 |
|
|
exit(2); |
364 |
|
|
break; |
365 |
|
|
} |
366 |
|
|
} |
367 |
|
|
} |
368 |
|
|
while (saveDir == ""); |
369 |
douglas |
273 |
|
370 |
|
|
if (debug) cerr << "saveDir = " << saveDir << "\n"; |
371 |
douglas |
269 |
} |
372 |
|
|
|
373 |
douglas |
273 |
void ScanUtility::populate(HWND parent) |
374 |
|
|
{ |
375 |
|
|
set<string> scans; |
376 |
|
|
|
377 |
|
|
do |
378 |
|
|
{ |
379 |
douglas |
288 |
string scan = scanDir + "SCAN????_000." + |
380 |
douglas |
273 |
IndividualClient::getExtension(); |
381 |
|
|
WIN32_FIND_DATA found; |
382 |
|
|
HANDLE finder = FindFirstFile(scan.c_str(), &found); |
383 |
|
|
|
384 |
|
|
if (finder != INVALID_HANDLE_VALUE) |
385 |
|
|
{ |
386 |
|
|
do |
387 |
|
|
{ |
388 |
|
|
scans.insert(found.cFileName); |
389 |
|
|
} |
390 |
|
|
while (FindNextFile(finder, &found)); |
391 |
|
|
|
392 |
|
|
FindClose(finder); |
393 |
|
|
} |
394 |
|
|
|
395 |
|
|
if (scans.empty()) |
396 |
|
|
{ |
397 |
|
|
if (MessageBox(parent, "No scanned documents found.", |
398 |
douglas |
282 |
title.c_str(), MB_RETRYCANCEL | MB_ICONQUESTION) == IDCANCEL) |
399 |
|
|
break; |
400 |
douglas |
273 |
} |
401 |
|
|
} |
402 |
|
|
while (scans.empty()); |
403 |
|
|
|
404 |
|
|
if (scans.empty()) |
405 |
|
|
{ |
406 |
|
|
PropSheet_PressButton(GetParent(parent), PSBTN_BACK); |
407 |
|
|
} |
408 |
|
|
else |
409 |
|
|
{ |
410 |
|
|
SHFILEINFO info; |
411 |
|
|
HIMAGELIST icons = HIMAGELIST(SHGetFileInfo((*scans.begin()).c_str(), |
412 |
|
|
0, &info, sizeof(info), SHGFI_SMALLICON | SHGFI_SYSICONINDEX)); |
413 |
|
|
|
414 |
|
|
ListView_SetImageList(GetDlgItem(parent, IDC_SELECT_SCANS), icons, |
415 |
|
|
LVSIL_SMALL); |
416 |
|
|
|
417 |
|
|
if (debug) cerr << "scans = {\n"; |
418 |
|
|
|
419 |
|
|
for (set<string>::iterator itor = scans.begin(); itor != scans.end(); |
420 |
|
|
itor++) |
421 |
|
|
{ |
422 |
|
|
if (debug) cerr << " " << *itor << "\n"; |
423 |
|
|
|
424 |
|
|
char scan[MAX_PATH]; |
425 |
|
|
|
426 |
douglas |
295 |
StringCchPrintf(scan, MAX_PATH, "%s", (*itor).c_str()); |
427 |
douglas |
273 |
|
428 |
|
|
LVITEM item; |
429 |
|
|
|
430 |
|
|
item.mask = LVIF_IMAGE | LVIF_TEXT; |
431 |
douglas |
274 |
item.iItem = 0; |
432 |
douglas |
273 |
item.iSubItem = 0; |
433 |
|
|
item.pszText = scan; |
434 |
|
|
item.iImage = info.iIcon; |
435 |
|
|
|
436 |
|
|
ListView_InsertItem(GetDlgItem(parent, IDC_SELECT_SCANS), &item); |
437 |
|
|
} |
438 |
|
|
|
439 |
|
|
if (debug) cerr << "}\n"; |
440 |
douglas |
274 |
|
441 |
|
|
ListView_SetItemState(GetDlgItem(parent, IDC_SELECT_SCANS), 0, |
442 |
|
|
LVIS_SELECTED, LVIS_SELECTED); |
443 |
douglas |
273 |
} |
444 |
|
|
} |
445 |
|
|
|
446 |
douglas |
277 |
ScanUtility* ScanUtility::which(HWND window) |
447 |
|
|
{ |
448 |
|
|
map<HWND, ScanUtility*>::iterator itor = windows.find(window); |
449 |
|
|
|
450 |
|
|
return itor->second; |
451 |
|
|
} |
452 |
|
|
|
453 |
|
|
ScanUtility* ScanUtility::which(HWND window, LPARAM l) |
454 |
|
|
{ |
455 |
|
|
LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l); |
456 |
|
|
map<unsigned, ScanUtility*>::iterator itor = utilities.find(page->lParam); |
457 |
|
|
|
458 |
|
|
windows.insert(pair<HWND, ScanUtility*>(window, itor->second)); |
459 |
|
|
|
460 |
|
|
return itor->second; |
461 |
|
|
} |
462 |
|
|
|
463 |
douglas |
271 |
int ScanUtility::browse(HWND dialog, UINT msg, LPARAM l, LPARAM d) |
464 |
|
|
{ |
465 |
|
|
map<unsigned, ScanUtility*>::iterator itor = utilities.find(LOWORD(d)); |
466 |
|
|
ScanUtility* data = itor->second; |
467 |
|
|
|
468 |
|
|
switch (msg) |
469 |
|
|
{ |
470 |
|
|
case BFFM_INITIALIZED: |
471 |
|
|
center(dialog); |
472 |
|
|
SendMessage(dialog, BFFM_SETOKTEXT, 0, |
473 |
|
|
LPARAM(toWide("&Select").c_str())); |
474 |
|
|
SendMessage(dialog, BFFM_SETEXPANDED, FALSE, CSIDL_DRIVES); |
475 |
douglas |
290 |
|
476 |
|
|
if ((HIWORD(d) ? data->scanDir : data->saveDir) != "") |
477 |
|
|
{ |
478 |
|
|
IShellFolder* desktop; |
479 |
|
|
LPWSTR path = new WCHAR[(HIWORD(d) ? data->scanDir.length() : |
480 |
|
|
data->saveDir.length()) + 1]; |
481 |
|
|
LPITEMIDLIST id; |
482 |
|
|
|
483 |
douglas |
295 |
StringCchPrintfW(path, (HIWORD(d) ? data->scanDir.length() : |
484 |
|
|
data->saveDir.length()) + 1, toWide(HIWORD(d) ? data->scanDir : |
485 |
douglas |
290 |
data->saveDir).c_str()); |
486 |
|
|
|
487 |
|
|
if (debug) cerr << "path = " << toAnsi(path) << "\n"; |
488 |
|
|
|
489 |
|
|
SHGetDesktopFolder(&desktop); |
490 |
|
|
desktop->ParseDisplayName(dialog, NULL, path, NULL, &id, NULL); |
491 |
|
|
|
492 |
|
|
if (id != NULL) |
493 |
|
|
{ |
494 |
|
|
SendMessage(dialog, BFFM_SETSELECTION, FALSE, LPARAM(id)); |
495 |
|
|
|
496 |
|
|
LPMALLOC destruct; |
497 |
|
|
|
498 |
|
|
SHGetMalloc(&destruct); |
499 |
|
|
destruct->Free(id); |
500 |
|
|
destruct->Release(); |
501 |
|
|
} |
502 |
|
|
|
503 |
|
|
desktop->Release(); |
504 |
|
|
} |
505 |
douglas |
271 |
break; |
506 |
|
|
case BFFM_SELCHANGED: |
507 |
|
|
{ |
508 |
douglas |
284 |
SHFILEINFO info; |
509 |
douglas |
271 |
|
510 |
douglas |
284 |
SHGetFileInfo(LPCSTR(l), 0, &info, sizeof(info), SHGFI_DISPLAYNAME |
511 |
|
|
| SHGFI_PIDL); |
512 |
|
|
SendMessage(dialog, BFFM_SETSTATUSTEXT, 0, |
513 |
|
|
LPARAM(info.szDisplayName)); |
514 |
douglas |
271 |
|
515 |
douglas |
284 |
char folder[MAX_PATH]; |
516 |
douglas |
271 |
|
517 |
douglas |
284 |
if (!SHGetPathFromIDList(LPCITEMIDLIST(l), folder)) |
518 |
douglas |
271 |
{ |
519 |
|
|
SendMessage(dialog, BFFM_ENABLEOK, 0, 0); |
520 |
|
|
} |
521 |
douglas |
284 |
else |
522 |
|
|
{ |
523 |
|
|
SendMessage(dialog, BFFM_SETSTATUSTEXT, 0, LPARAM(folder)); |
524 |
|
|
} |
525 |
douglas |
271 |
} |
526 |
|
|
break; |
527 |
|
|
} |
528 |
|
|
|
529 |
|
|
return 0; |
530 |
|
|
} |
531 |
|
|
|
532 |
douglas |
268 |
INT_PTR ScanUtility::start(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
533 |
|
|
{ |
534 |
douglas |
277 |
ScanUtility* data = which(dialog); |
535 |
douglas |
268 |
|
536 |
|
|
switch (msg) |
537 |
douglas |
265 |
{ |
538 |
douglas |
268 |
case WM_INITDIALOG: |
539 |
douglas |
269 |
center(GetParent(dialog)); |
540 |
douglas |
274 |
SendMessage(GetParent(dialog), WM_SETICON, ICON_BIG, LPARAM(gui.icon)); |
541 |
douglas |
277 |
|
542 |
|
|
data = which(dialog, l); |
543 |
douglas |
265 |
|
544 |
douglas |
273 |
{ |
545 |
|
|
ostringstream instructions; |
546 |
|
|
|
547 |
douglas |
274 |
instructions << "1. If you need instructions, you should not be ru" |
548 |
|
|
<< "nning this program in Scan Utility mode.\n" |
549 |
|
|
<< "2. Otherwise, go forth and scan.\n" |
550 |
|
|
<< "3. Then come back and click Next.\n"; |
551 |
douglas |
273 |
|
552 |
|
|
SetDlgItemText(dialog, IDC_START_INSTRUCTIONS, |
553 |
|
|
instructions.str().c_str()); |
554 |
|
|
} |
555 |
douglas |
268 |
break; |
556 |
douglas |
269 |
case WM_NOTIFY: |
557 |
|
|
{ |
558 |
douglas |
273 |
LPNMHDR nm = LPNMHDR(l); |
559 |
douglas |
269 |
|
560 |
|
|
switch (nm->code) |
561 |
|
|
{ |
562 |
|
|
case PSN_SETACTIVE: |
563 |
douglas |
278 |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_FINISH | |
564 |
|
|
PSWIZB_NEXT); |
565 |
|
|
|
566 |
douglas |
271 |
{ |
567 |
douglas |
283 |
SHFILEINFO info; |
568 |
douglas |
271 |
|
569 |
douglas |
283 |
SHGetFileInfo(data->scanDir.c_str(), 0, &info, |
570 |
|
|
sizeof(info), SHGFI_ICONLOCATION); |
571 |
|
|
|
572 |
douglas |
284 |
HICON icon = ExtractIcon(gui.instance, info.szDisplayName, |
573 |
|
|
info.iIcon); |
574 |
douglas |
283 |
|
575 |
|
|
SendDlgItemMessage(dialog, IDC_START_SCAN_ICON, |
576 |
|
|
STM_SETIMAGE, IMAGE_ICON, LPARAM(icon)); |
577 |
|
|
SHGetFileInfo(data->saveDir.c_str(), 0, &info, |
578 |
|
|
sizeof(info), SHGFI_ICONLOCATION); |
579 |
|
|
|
580 |
douglas |
284 |
icon = ExtractIcon(gui.instance, info.szDisplayName, |
581 |
|
|
info.iIcon); |
582 |
douglas |
283 |
|
583 |
|
|
SendDlgItemMessage(dialog, IDC_START_SAVE_ICON, |
584 |
|
|
STM_SETIMAGE, IMAGE_ICON, LPARAM(icon)); |
585 |
|
|
} |
586 |
|
|
|
587 |
|
|
{ |
588 |
|
|
char folder[38]; |
589 |
|
|
|
590 |
douglas |
288 |
PathCompactPathEx(folder, data->scanDir.substr(0, |
591 |
|
|
data->scanDir.length() - 1).c_str(), 38, 0); |
592 |
douglas |
271 |
SetDlgItemText(dialog, IDC_START_SCAN_TEXT, folder); |
593 |
douglas |
288 |
PathCompactPathEx(folder, data->saveDir.substr(0, |
594 |
|
|
data->saveDir.length() - 1).c_str(), 38, 0); |
595 |
douglas |
271 |
SetDlgItemText(dialog, IDC_START_SAVE_TEXT, folder); |
596 |
|
|
} |
597 |
douglas |
269 |
break; |
598 |
douglas |
273 |
case PSN_WIZNEXT: |
599 |
|
|
SetCurrentDirectory(data->scanDir.c_str()); |
600 |
|
|
break; |
601 |
douglas |
269 |
} |
602 |
|
|
} |
603 |
|
|
break; |
604 |
douglas |
271 |
case WM_COMMAND: |
605 |
|
|
switch (LOWORD(w)) |
606 |
|
|
{ |
607 |
|
|
case IDC_START_SCAN_BROWSE: |
608 |
|
|
data->setScanDir(dialog); |
609 |
douglas |
283 |
|
610 |
douglas |
271 |
{ |
611 |
douglas |
283 |
SHFILEINFO info; |
612 |
douglas |
271 |
|
613 |
douglas |
283 |
SHGetFileInfo(data->scanDir.c_str(), 0, &info, sizeof(info), |
614 |
|
|
SHGFI_ICONLOCATION); |
615 |
|
|
|
616 |
douglas |
284 |
HICON icon = ExtractIcon(gui.instance, info.szDisplayName, |
617 |
|
|
info.iIcon); |
618 |
douglas |
283 |
|
619 |
|
|
SendDlgItemMessage(dialog, IDC_START_SCAN_ICON, STM_SETIMAGE, |
620 |
|
|
IMAGE_ICON, LPARAM(icon)); |
621 |
|
|
} |
622 |
|
|
|
623 |
|
|
{ |
624 |
|
|
char folder[38]; |
625 |
|
|
|
626 |
douglas |
288 |
PathCompactPathEx(folder, data->scanDir.substr(0, |
627 |
|
|
data->scanDir.length() - 1).c_str(), 38, 0); |
628 |
douglas |
271 |
SetDlgItemText(dialog, IDC_START_SCAN_TEXT, folder); |
629 |
|
|
} |
630 |
|
|
break; |
631 |
|
|
case IDC_START_SAVE_BROWSE: |
632 |
|
|
data->setSaveDir(dialog); |
633 |
douglas |
283 |
|
634 |
douglas |
271 |
{ |
635 |
douglas |
283 |
SHFILEINFO info; |
636 |
douglas |
271 |
|
637 |
douglas |
283 |
SHGetFileInfo(data->saveDir.c_str(), 0, &info, sizeof(info), |
638 |
|
|
SHGFI_ICONLOCATION); |
639 |
|
|
|
640 |
douglas |
284 |
HICON icon = ExtractIcon(gui.instance, info.szDisplayName, |
641 |
|
|
info.iIcon); |
642 |
douglas |
283 |
|
643 |
|
|
SendDlgItemMessage(dialog, IDC_START_SAVE_ICON, STM_SETIMAGE, |
644 |
|
|
IMAGE_ICON, LPARAM(icon)); |
645 |
|
|
} |
646 |
|
|
|
647 |
|
|
{ |
648 |
|
|
char folder[38]; |
649 |
|
|
|
650 |
douglas |
288 |
PathCompactPathEx(folder, data->saveDir.substr(0, |
651 |
|
|
data->saveDir.length() - 1).c_str(), 38, 0); |
652 |
douglas |
271 |
SetDlgItemText(dialog, IDC_START_SAVE_TEXT, folder); |
653 |
|
|
} |
654 |
|
|
break; |
655 |
|
|
} |
656 |
|
|
break; |
657 |
douglas |
268 |
} |
658 |
douglas |
265 |
|
659 |
douglas |
268 |
return FALSE; |
660 |
douglas |
265 |
} |
661 |
douglas |
273 |
|
662 |
|
|
INT_PTR ScanUtility::select(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
663 |
|
|
{ |
664 |
douglas |
277 |
ScanUtility* data = which(dialog); |
665 |
douglas |
273 |
|
666 |
|
|
switch (msg) |
667 |
|
|
{ |
668 |
|
|
case WM_INITDIALOG: |
669 |
douglas |
277 |
data = which(dialog, l); |
670 |
douglas |
273 |
|
671 |
|
|
{ |
672 |
douglas |
274 |
ostringstream select; |
673 |
|
|
|
674 |
douglas |
282 |
select << "Select the scanned document that you need to save."; |
675 |
douglas |
274 |
|
676 |
|
|
SetDlgItemText(dialog, IDC_SELECT_TEXT, select.str().c_str()); |
677 |
|
|
} |
678 |
douglas |
277 |
|
679 |
douglas |
274 |
{ |
680 |
douglas |
273 |
LVCOLUMN column; |
681 |
|
|
|
682 |
|
|
column.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH; |
683 |
|
|
column.fmt = LVCFMT_IMAGE; |
684 |
|
|
column.cx = 120; |
685 |
|
|
column.pszText = "Scanned Documents"; |
686 |
|
|
|
687 |
|
|
ListView_InsertColumn(GetDlgItem(dialog, IDC_SELECT_SCANS), 0, |
688 |
|
|
&column); |
689 |
|
|
} |
690 |
|
|
break; |
691 |
|
|
case WM_NOTIFY: |
692 |
|
|
if (w == IDC_SELECT_SCANS) |
693 |
|
|
{ |
694 |
douglas |
274 |
LPNMITEMACTIVATE ni = LPNMITEMACTIVATE(l); |
695 |
|
|
|
696 |
|
|
switch (ni->hdr.code) |
697 |
douglas |
273 |
{ |
698 |
douglas |
274 |
case NM_DBLCLK: |
699 |
douglas |
284 |
if (ni->iItem != -1) |
700 |
douglas |
274 |
{ |
701 |
|
|
char scan[MAX_PATH]; |
702 |
|
|
|
703 |
|
|
ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS), |
704 |
|
|
ni->iItem, 0, scan, MAX_PATH); |
705 |
|
|
ShellExecute(dialog, NULL, scan, NULL, NULL, |
706 |
|
|
SW_SHOWDEFAULT); |
707 |
|
|
} |
708 |
douglas |
273 |
break; |
709 |
|
|
} |
710 |
|
|
} |
711 |
|
|
else |
712 |
|
|
{ |
713 |
|
|
LPNMHDR nm = LPNMHDR(l); |
714 |
|
|
|
715 |
|
|
switch (nm->code) |
716 |
|
|
{ |
717 |
|
|
case PSN_SETACTIVE: |
718 |
douglas |
274 |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
719 |
douglas |
278 |
PSWIZB_DISABLEDFINISH | PSWIZB_NEXT); |
720 |
douglas |
273 |
data->populate(dialog); |
721 |
|
|
break; |
722 |
|
|
case PSN_WIZBACK: |
723 |
|
|
ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS)); |
724 |
douglas |
277 |
data->client.setFile(""); |
725 |
douglas |
273 |
break; |
726 |
|
|
case PSN_WIZNEXT: |
727 |
douglas |
274 |
{ |
728 |
|
|
int index = ListView_GetNextItem(GetDlgItem(dialog, |
729 |
|
|
IDC_SELECT_SCANS), -1, LVNI_SELECTED); |
730 |
|
|
char scan[MAX_PATH]; |
731 |
|
|
|
732 |
douglas |
284 |
if (index != -1) |
733 |
|
|
{ |
734 |
|
|
ListView_GetItemText(GetDlgItem(dialog, |
735 |
|
|
IDC_SELECT_SCANS), index, 0, scan, MAX_PATH); |
736 |
|
|
} |
737 |
|
|
else |
738 |
|
|
{ |
739 |
|
|
ListView_GetItemText(GetDlgItem(dialog, |
740 |
|
|
IDC_SELECT_SCANS), 0, 0, scan, MAX_PATH); |
741 |
|
|
} |
742 |
douglas |
274 |
|
743 |
|
|
data->scan = scan; |
744 |
|
|
} |
745 |
douglas |
277 |
|
746 |
douglas |
284 |
if (debug) cerr << "scan = " << data->scan << "\n"; |
747 |
|
|
|
748 |
douglas |
273 |
ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS)); |
749 |
|
|
break; |
750 |
|
|
} |
751 |
|
|
} |
752 |
|
|
break; |
753 |
douglas |
277 |
case WM_CONTEXTMENU: |
754 |
douglas |
284 |
if (ListView_GetNextItem(GetDlgItem(dialog, IDC_SELECT_SCANS), -1, |
755 |
|
|
LVNI_SELECTED) != -1) |
756 |
douglas |
277 |
{ |
757 |
|
|
char scan[MAX_PATH]; |
758 |
|
|
POINT spot; |
759 |
|
|
LVHITTESTINFO test; |
760 |
|
|
|
761 |
|
|
test.pt.x = GET_X_LPARAM(l); |
762 |
|
|
test.pt.y = GET_Y_LPARAM(l); |
763 |
|
|
|
764 |
|
|
ScreenToClient(GetDlgItem(dialog, IDC_SELECT_SCANS), &test.pt); |
765 |
|
|
ListView_HitTest(GetDlgItem(dialog, IDC_SELECT_SCANS), &test); |
766 |
|
|
|
767 |
|
|
if (test.iItem != -1) |
768 |
|
|
{ |
769 |
|
|
ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS), |
770 |
|
|
test.iItem, 0, scan, MAX_PATH); |
771 |
|
|
|
772 |
|
|
spot.x = test.pt.x; |
773 |
|
|
spot.y = test.pt.y; |
774 |
|
|
} |
775 |
|
|
else if (GET_X_LPARAM(l) == -1 && GET_Y_LPARAM(l) == -1) |
776 |
|
|
{ |
777 |
|
|
int index = ListView_GetNextItem(GetDlgItem(dialog, |
778 |
|
|
IDC_SELECT_SCANS), -1, LVNI_SELECTED); |
779 |
|
|
RECT rect; |
780 |
|
|
|
781 |
|
|
ListView_GetItemText(GetDlgItem(dialog, IDC_SELECT_SCANS), |
782 |
|
|
index, 0, scan, MAX_PATH); |
783 |
|
|
ListView_EnsureVisible(GetDlgItem(dialog, IDC_SELECT_SCANS), |
784 |
|
|
index, FALSE); |
785 |
|
|
ListView_GetItemRect(GetDlgItem(dialog, IDC_SELECT_SCANS), |
786 |
|
|
index, &rect, LVIR_SELECTBOUNDS); |
787 |
|
|
|
788 |
|
|
spot.x = rect.left; |
789 |
|
|
spot.y = rect.top; |
790 |
|
|
} |
791 |
|
|
|
792 |
|
|
ClientToScreen(GetDlgItem(dialog, IDC_SELECT_SCANS), &spot); |
793 |
|
|
|
794 |
|
|
int code = TrackPopupMenuEx(data->popup, TPM_LEFTALIGN | |
795 |
|
|
TPM_TOPALIGN | TPM_NONOTIFY | TPM_RETURNCMD | TPM_RIGHTBUTTON, |
796 |
|
|
spot.x, spot.y, GetDlgItem(dialog, IDC_SELECT_SCANS), NULL); |
797 |
|
|
|
798 |
|
|
switch (code) |
799 |
|
|
{ |
800 |
|
|
case 1: |
801 |
|
|
ShellExecute(dialog, NULL, scan, NULL, NULL, SW_SHOWDEFAULT); |
802 |
|
|
break; |
803 |
|
|
case 2: |
804 |
|
|
{ |
805 |
|
|
SHELLEXECUTEINFO info; |
806 |
|
|
|
807 |
|
|
info.cbSize = sizeof(info); |
808 |
|
|
info.fMask = SEE_MASK_INVOKEIDLIST; |
809 |
|
|
info.hwnd = dialog; |
810 |
|
|
info.lpVerb = "properties"; |
811 |
|
|
info.lpFile = scan; |
812 |
|
|
info.lpParameters = NULL; |
813 |
|
|
info.lpDirectory = NULL; |
814 |
|
|
info.nShow = SW_SHOWDEFAULT; |
815 |
|
|
info.lpIDList = NULL; |
816 |
|
|
|
817 |
|
|
ShellExecuteEx(&info); |
818 |
|
|
} |
819 |
|
|
break; |
820 |
|
|
} |
821 |
|
|
} |
822 |
douglas |
273 |
break; |
823 |
|
|
} |
824 |
|
|
|
825 |
|
|
return FALSE; |
826 |
|
|
} |
827 |
douglas |
274 |
|
828 |
|
|
INT_PTR ScanUtility::enter(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
829 |
|
|
{ |
830 |
douglas |
277 |
ScanUtility* data = which(dialog); |
831 |
|
|
|
832 |
|
|
switch (msg) |
833 |
|
|
{ |
834 |
|
|
case WM_INITDIALOG: |
835 |
|
|
data = which(dialog, l); |
836 |
douglas |
278 |
|
837 |
douglas |
277 |
{ |
838 |
|
|
ostringstream enter; |
839 |
|
|
|
840 |
|
|
enter << "Enter the client name and number."; |
841 |
|
|
|
842 |
|
|
SetDlgItemText(dialog, IDC_ENTER_TEXT, enter.str().c_str()); |
843 |
|
|
} |
844 |
|
|
break; |
845 |
|
|
case WM_NOTIFY: |
846 |
|
|
{ |
847 |
|
|
LPNMHDR nm = LPNMHDR(l); |
848 |
|
|
|
849 |
|
|
switch (nm->code) |
850 |
|
|
{ |
851 |
|
|
case PSN_SETACTIVE: |
852 |
|
|
if (data->client.getName() != "" && data->client.getNumber() != |
853 |
|
|
0) |
854 |
|
|
{ |
855 |
|
|
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
856 |
douglas |
278 |
PSWIZB_DISABLEDFINISH | PSWIZB_NEXT); |
857 |
douglas |
277 |
} |
858 |
|
|
else |
859 |
|
|
{ |
860 |
douglas |
278 |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
861 |
|
|
PSWIZB_DISABLEDFINISH); |
862 |
douglas |
277 |
} |
863 |
|
|
|
864 |
|
|
SetDlgItemText(dialog, IDC_ENTER_NAME, |
865 |
|
|
data->client.getName().c_str()); |
866 |
|
|
|
867 |
|
|
if (data->client.getNumber() != 0) |
868 |
|
|
{ |
869 |
|
|
SetDlgItemInt(dialog, IDC_ENTER_NUM, |
870 |
|
|
data->client.getNumber(), FALSE); |
871 |
|
|
} |
872 |
|
|
else |
873 |
|
|
{ |
874 |
|
|
SetDlgItemText(dialog, IDC_ENTER_NUM, ""); |
875 |
|
|
} |
876 |
|
|
break; |
877 |
|
|
case PSN_WIZBACK: |
878 |
|
|
break; |
879 |
|
|
case PSN_WIZNEXT: |
880 |
|
|
if (debug) |
881 |
|
|
{ |
882 |
|
|
cerr << "client = {\n" |
883 |
|
|
<< " name = " << data->client.getName() << "\n" |
884 |
|
|
<< " number = " << data->client.getNumber() << "\n" |
885 |
douglas |
278 |
<< " file = " << data->client.getFile() << "\n" |
886 |
douglas |
277 |
<< "}\n"; |
887 |
|
|
} |
888 |
douglas |
278 |
|
889 |
douglas |
292 |
data->save = data->saveDir + data->client.getFile(); |
890 |
douglas |
278 |
|
891 |
|
|
if (debug) cerr << "save = " << data->save << "\n"; |
892 |
|
|
|
893 |
douglas |
277 |
break; |
894 |
|
|
} |
895 |
|
|
} |
896 |
|
|
break; |
897 |
|
|
case WM_COMMAND: |
898 |
|
|
switch (LOWORD(w)) |
899 |
|
|
{ |
900 |
|
|
case IDC_ENTER_NAME: |
901 |
|
|
{ |
902 |
|
|
char name[BUFSIZ]; |
903 |
|
|
|
904 |
|
|
GetDlgItemText(dialog, IDC_ENTER_NAME, name, BUFSIZ); |
905 |
|
|
|
906 |
|
|
if (name != data->client.getName()) |
907 |
|
|
{ |
908 |
|
|
data->client.setName(name); |
909 |
|
|
} |
910 |
|
|
} |
911 |
|
|
|
912 |
|
|
if (data->client.getName() != "" && data->client.getNumber() != 0) |
913 |
|
|
{ |
914 |
|
|
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
915 |
douglas |
278 |
PSWIZB_DISABLEDFINISH | PSWIZB_NEXT); |
916 |
douglas |
277 |
} |
917 |
|
|
else |
918 |
|
|
{ |
919 |
douglas |
278 |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
920 |
|
|
PSWIZB_DISABLEDFINISH); |
921 |
douglas |
277 |
} |
922 |
|
|
break; |
923 |
|
|
case IDC_ENTER_NUM: |
924 |
|
|
{ |
925 |
|
|
unsigned number = GetDlgItemInt(dialog, IDC_ENTER_NUM, NULL, |
926 |
|
|
FALSE); |
927 |
|
|
|
928 |
|
|
if (number != data->client.getNumber()) |
929 |
|
|
{ |
930 |
|
|
data->client.setNumber(number); |
931 |
|
|
} |
932 |
|
|
} |
933 |
|
|
|
934 |
|
|
if (data->client.getName() != "" && data->client.getNumber() != 0) |
935 |
|
|
{ |
936 |
|
|
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
937 |
douglas |
278 |
PSWIZB_DISABLEDFINISH | PSWIZB_NEXT); |
938 |
douglas |
277 |
} |
939 |
|
|
else |
940 |
|
|
{ |
941 |
douglas |
278 |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
942 |
|
|
PSWIZB_DISABLEDFINISH); |
943 |
douglas |
277 |
} |
944 |
|
|
break; |
945 |
|
|
} |
946 |
|
|
break; |
947 |
|
|
} |
948 |
|
|
|
949 |
douglas |
274 |
return FALSE; |
950 |
|
|
} |
951 |
douglas |
278 |
|
952 |
|
|
INT_PTR ScanUtility::confirm(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
953 |
|
|
{ |
954 |
|
|
ScanUtility* data = which(dialog); |
955 |
|
|
|
956 |
|
|
switch (msg) |
957 |
|
|
{ |
958 |
|
|
case WM_INITDIALOG: |
959 |
|
|
data = which(dialog, l); |
960 |
|
|
|
961 |
|
|
{ |
962 |
|
|
ostringstream confirm; |
963 |
|
|
|
964 |
|
|
confirm << "Confirm the client file\'s name and size."; |
965 |
|
|
|
966 |
|
|
SetDlgItemText(dialog, IDC_CONFIRM_TEXT, confirm.str().c_str()); |
967 |
|
|
} |
968 |
|
|
break; |
969 |
|
|
case WM_NOTIFY: |
970 |
|
|
{ |
971 |
|
|
LPNMHDR nm = LPNMHDR(l); |
972 |
|
|
|
973 |
|
|
switch (nm->code) |
974 |
|
|
{ |
975 |
|
|
case PSN_SETACTIVE: |
976 |
|
|
CheckDlgButton(dialog, IDC_CONFIRM_GOOD, BST_UNCHECKED); |
977 |
|
|
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
978 |
|
|
PSWIZB_DISABLEDFINISH); |
979 |
|
|
SetDlgItemText(dialog, IDC_CONFIRM_FILE, |
980 |
|
|
data->client.getFile().c_str()); |
981 |
|
|
|
982 |
|
|
{ |
983 |
|
|
HANDLE scan = CreateFile(data->scan.c_str(), GENERIC_READ, |
984 |
|
|
FILE_SHARE_READ, NULL, OPEN_EXISTING, |
985 |
|
|
FILE_ATTRIBUTE_NORMAL, NULL); |
986 |
|
|
DWORD bytes = GetFileSize(scan, NULL); |
987 |
|
|
|
988 |
|
|
CloseHandle(scan); |
989 |
|
|
|
990 |
|
|
ostringstream size; |
991 |
|
|
|
992 |
|
|
size << format(bytes); |
993 |
|
|
|
994 |
|
|
size.setf(ios_base::fixed, ios_base::floatfield); |
995 |
|
|
size.precision(2); |
996 |
|
|
|
997 |
|
|
FLOAT megabytes = FLOAT(bytes) / FLOAT(1024 * 1024); |
998 |
|
|
|
999 |
|
|
size << " bytes (" << megabytes << " MB)"; |
1000 |
|
|
|
1001 |
|
|
SetDlgItemText(dialog, IDC_CONFIRM_SIZE, |
1002 |
|
|
size.str().c_str()); |
1003 |
|
|
} |
1004 |
|
|
break; |
1005 |
|
|
case PSN_WIZBACK: |
1006 |
|
|
break; |
1007 |
|
|
case PSN_WIZNEXT: |
1008 |
|
|
if (MoveFile(data->scan.c_str(), data->save.c_str()) == 0) |
1009 |
|
|
{ |
1010 |
|
|
do |
1011 |
|
|
{ |
1012 |
|
|
LPVOID message; |
1013 |
|
|
|
1014 |
|
|
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
1015 |
douglas |
282 |
FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), |
1016 |
|
|
0, LPTSTR(&message), 0, NULL); |
1017 |
douglas |
278 |
|
1018 |
|
|
int code = MessageBox(dialog, LPCTSTR(message), |
1019 |
douglas |
282 |
data->title.c_str(), MB_RETRYCANCEL | |
1020 |
douglas |
278 |
MB_ICONEXCLAMATION); |
1021 |
|
|
|
1022 |
|
|
LocalFree(message); |
1023 |
|
|
|
1024 |
|
|
if (code == IDCANCEL) |
1025 |
|
|
{ |
1026 |
|
|
PropSheet_PressButton(GetParent(dialog), |
1027 |
|
|
PSBTN_BACK); |
1028 |
|
|
break; |
1029 |
|
|
} |
1030 |
|
|
} |
1031 |
|
|
while (MoveFileEx(data->scan.c_str(), data->save.c_str(), |
1032 |
|
|
MOVEFILE_REPLACE_EXISTING) == 0); |
1033 |
|
|
} |
1034 |
|
|
break; |
1035 |
|
|
} |
1036 |
|
|
} |
1037 |
|
|
break; |
1038 |
|
|
case WM_COMMAND: |
1039 |
|
|
switch (LOWORD(w)) |
1040 |
|
|
{ |
1041 |
|
|
case IDC_CONFIRM_GOOD: |
1042 |
|
|
if (IsDlgButtonChecked(dialog, IDC_CONFIRM_GOOD) == BST_CHECKED) |
1043 |
|
|
{ |
1044 |
|
|
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
1045 |
|
|
PSWIZB_DISABLEDFINISH | PSWIZB_NEXT); |
1046 |
|
|
} |
1047 |
|
|
else |
1048 |
|
|
{ |
1049 |
|
|
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
1050 |
|
|
PSWIZB_DISABLEDFINISH); |
1051 |
|
|
} |
1052 |
|
|
break; |
1053 |
|
|
} |
1054 |
|
|
break; |
1055 |
|
|
} |
1056 |
|
|
|
1057 |
|
|
return FALSE; |
1058 |
|
|
} |
1059 |
|
|
|
1060 |
|
|
INT_PTR ScanUtility::done(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
1061 |
|
|
{ |
1062 |
|
|
ScanUtility* data = which(dialog); |
1063 |
|
|
|
1064 |
|
|
switch (msg) |
1065 |
|
|
{ |
1066 |
|
|
case WM_INITDIALOG: |
1067 |
|
|
data = which(dialog, l); |
1068 |
douglas |
281 |
|
1069 |
|
|
{ |
1070 |
|
|
ostringstream done; |
1071 |
|
|
|
1072 |
|
|
done << "You are done saving the scanned document. Click Finish to" |
1073 |
|
|
<< " exit or click Back to return to the beginning."; |
1074 |
|
|
|
1075 |
|
|
SetDlgItemText(dialog, IDC_DONE_TEXT, done.str().c_str()); |
1076 |
|
|
} |
1077 |
douglas |
278 |
break; |
1078 |
|
|
case WM_NOTIFY: |
1079 |
|
|
{ |
1080 |
|
|
LPNMHDR nm = LPNMHDR(l); |
1081 |
|
|
|
1082 |
|
|
switch (nm->code) |
1083 |
|
|
{ |
1084 |
|
|
case PSN_SETACTIVE: |
1085 |
|
|
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
1086 |
|
|
PSWIZB_FINISH); |
1087 |
|
|
break; |
1088 |
|
|
case PSN_WIZBACK: |
1089 |
|
|
data->client.setFile(""); |
1090 |
|
|
PropSheet_SetCurSelByID(GetParent(dialog), IDD_START); |
1091 |
|
|
break; |
1092 |
|
|
case PSN_WIZFINISH: |
1093 |
|
|
break; |
1094 |
|
|
} |
1095 |
|
|
} |
1096 |
|
|
break; |
1097 |
|
|
} |
1098 |
|
|
|
1099 |
|
|
return FALSE; |
1100 |
|
|
} |