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 269 by douglas, 2003-08-19T01:19:24-07:00 vs.
Revision 273 by douglas, 2003-08-20T23:29:24-07:00

# Line 2 | Line 2
2   //
3   // Douglas Thrift
4   //
5 < // $Id: ScanUtility.cxx,v 1.4 2003/08/19 08:19:24 douglas Exp $
5 > // $Id: ScanUtility.cxx,v 1.6 2003/08/21 06:29:24 douglas Exp $
6  
7   #include "ScanUtility.h"
8  
# Line 15 | Line 15 | ScanUtility::ScanUtility()
15          sprintf(title, "%s - Scan Utility", programName.c_str());
16          loadDirs();
17          
18        PROPSHEETPAGE page;
19
18          // start
19 <        page.dwSize = sizeof(page);
20 <        page.dwFlags = PSP_DEFAULT | PSP_USEHICON | PSP_USETITLE |
19 >        wizard[0].dwSize = sizeof(wizard[0]);
20 >        wizard[0].dwFlags = PSP_DEFAULT | PSP_USEHICON | PSP_USETITLE |
21                  PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
22 <        page.hInstance = gui.instance;
23 <        page.pszTemplate = MAKEINTRESOURCE(IDD_SCAN_START);
24 <        page.hIcon = gui.icon;
25 <        page.pszTitle = title;
26 <        page.pfnDlgProc = start;
27 <        page.lParam = number;
28 <        page.pszHeaderTitle = "Start";
29 <        page.pszHeaderSubTitle = "Change any settings before scanning.";
30 <
31 <        wizard[0] = CreatePropertySheetPage(&page);
22 >        wizard[0].hInstance = gui.instance;
23 >        wizard[0].pszTemplate = MAKEINTRESOURCE(IDD_START);
24 >        wizard[0].hIcon = gui.icon;
25 >        wizard[0].pszTitle = title;
26 >        wizard[0].pfnDlgProc = start;
27 >        wizard[0].lParam = number;
28 >        wizard[0].pszHeaderTitle = "Start";
29 >        wizard[0].pszHeaderSubTitle = "Change any settings before scanning.";
30 >
31 >        // select
32 >        wizard[1].dwSize = sizeof(wizard[1]);
33 >        wizard[1].dwFlags = PSP_DEFAULT | PSP_USEHICON | PSP_USETITLE |
34 >                PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
35 >        wizard[1].hInstance = gui.instance;
36 >        wizard[1].pszTemplate = MAKEINTRESOURCE(IDD_SELECT);
37 >        wizard[1].hIcon = gui.icon;
38 >        wizard[1].pszTitle = title;
39 >        wizard[1].pfnDlgProc = select;
40 >        wizard[1].lParam = number;
41 >        wizard[1].pszHeaderTitle = "Select";
42 >        wizard[1].pszHeaderSubTitle = "Choose the scanned document to save.";
43   }
44  
45   ScanUtility::~ScanUtility()
# Line 47 | Line 56 | void ScanUtility::run(void)
56  
57          // header
58          header.dwSize = sizeof(header);
59 <        header.dwFlags = PSH_DEFAULT | PSH_HEADER | PSH_USEICONID | PSH_WIZARD97;
59 >        header.dwFlags = PSH_DEFAULT | PSH_HEADER | PSH_PROPSHEETPAGE |
60 >                PSH_USEICONID | PSH_WIZARD97;
61          header.hwndParent = NULL;
62          header.hInstance = gui.instance;
63          header.pszIcon = MAKEINTRESOURCE(IDI_VTB_ICON);
64 <        header.nPages = 1;
64 >        header.nPages = 2;
65          header.nStartPage = 0;
66 <        header.phpage = wizard;
66 >        header.ppsp = wizard;
67          header.pszbmHeader = MAKEINTRESOURCE(IDB_VTB_BMP);
68  
69          PropertySheet(&header);
# Line 68 | Line 78 | void ScanUtility::loadDirs(void)
78          HKEY key;
79  
80          if (RegOpenKeyEx(HKEY_CURRENT_USER,
81 <                "Software\\DouglasThrift\\VTBFileUtil2", 0, KEY_READ, &key) ==
81 >                "Software\\DouglasThrift\\VTBFileUtil2", 0, KEY_QUERY_VALUE, &key) ==
82                  ERROR_SUCCESS)
83          {
84                  DWORD type;
85 <                BYTE data[MAX_PATH];
85 >                char data[MAX_PATH];
86                  DWORD size = MAX_PATH;
87  
88 <                if (RegQueryValueEx(key, "ScanDir", NULL, &type, data, &size) ==
89 <                        ERROR_SUCCESS)
88 >                if (RegQueryValueEx(key, "ScanDir", NULL, &type, LPBYTE(data), &size)
89 >                        == ERROR_SUCCESS)
90                  {
81                        char* buffer = new char[size];
82
91                          data[size - 1] = '\0';
92  
93                          switch (type)
94                          {
95                          case REG_EXPAND_SZ:
96 <                                sprintf(buffer, "%s", data);
97 <                                ExpandEnvironmentStrings(buffer, scanDir, MAX_PATH);
98 <                                cerr << "scanDir = " << scanDir << "\n";
96 >                                {
97 >                                        char folder[MAX_PATH];
98 >
99 >                                        ExpandEnvironmentStrings(data, folder, MAX_PATH);
100 >
101 >                                        scanDir = folder;
102 >                                }
103                                  break;
104                          case REG_SZ:
105 <                                sprintf(scanDir, "%s", data);
94 <                                cerr << "scanDir = " << scanDir << "\n";
105 >                                scanDir = data;
106                                  break;
107                          default:
108                                  setScanDir();
109                                  break;
110                          }
100
101                        delete [] buffer;
111                  }
112                  else
113                  {
# Line 107 | Line 116 | void ScanUtility::loadDirs(void)
116  
117                  size = MAX_PATH;
118  
119 <                if (RegQueryValueEx(key, "SaveDir", NULL, &type, data, &size) ==
120 <                        ERROR_SUCCESS)
119 >                if (RegQueryValueEx(key, "SaveDir", NULL, &type, LPBYTE(data), &size)
120 >                        == ERROR_SUCCESS)
121                  {
113                        char* buffer = new char[size];
114                        
122                          data[size - 1] = '\0';
123  
124                          switch (type)
125                          {
126                          case REG_EXPAND_SZ:
127 <                                sprintf(buffer, "%s", data);
128 <                                ExpandEnvironmentStrings(buffer, saveDir, MAX_PATH);
129 <                                cerr << "saveDir = " << saveDir << "\n";
127 >                                {
128 >                                        char folder[MAX_PATH];
129 >
130 >                                        ExpandEnvironmentStrings(data, folder, MAX_PATH);
131 >
132 >                                        saveDir = folder;
133 >                                }
134                                  break;
135                          case REG_SZ:
136 <                                sprintf(saveDir, "%s", data);
126 <                                cerr << "saveDir = " << saveDir << "\n";
136 >                                saveDir = data;
137                                  break;
138                          default:
139                                  setSaveDir();
140                                  break;
141                          }
132
133                        delete [] buffer;
142                  }
143                  else
144                  {
# Line 144 | Line 152 | void ScanUtility::loadDirs(void)
152                  setScanDir();
153                  setSaveDir();
154          }
155 +
156 +        if (debug) cerr << "scanDir = " << scanDir << "\n"
157 +                << "saveDir = " << saveDir << "\n";
158   }
159  
160   void ScanUtility::saveDirs(void)
# Line 152 | Line 163 | void ScanUtility::saveDirs(void)
163  
164          if (RegCreateKeyEx(HKEY_CURRENT_USER,
165                  "Software\\DouglasThrift\\VTBFileUtil2", 0, NULL,
166 <                REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS)
166 >                REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_SET_VALUE, NULL, &key,
167 >                NULL) == ERROR_SUCCESS)
168          {
169 <                if (RegSetValueEx(key, "ScanDir", 0, REG_SZ, LPBYTE(scanDir),
170 <                        strlen(scanDir) + 1) != ERROR_SUCCESS)
169 >                DWORD type;
170 >                char data[MAX_PATH];
171 >                DWORD size = MAX_PATH;
172 >
173 >                if (RegQueryValueEx(key, "ScanDir", NULL, &type, LPBYTE(data), &size)
174 >                        == ERROR_SUCCESS)
175 >                {
176 >                        data[size - 1] = '\0';
177 >                }
178 >                else
179 >                {
180 >                        data[0] = '\0';
181 >                }
182 >
183 >                if (scanDir != data || type != REG_SZ)
184 >                {
185 >                        if (RegSetValueEx(key, "ScanDir", 0, REG_SZ,
186 >                                LPBYTE(scanDir.c_str()), scanDir.length() + 1) !=
187 >                                ERROR_SUCCESS)
188 >                        {
189 >                                error();
190 >                        }
191 >                }
192 >
193 >                size = MAX_PATH;
194 >
195 >                if (RegQueryValueEx(key, "SaveDir", NULL, &type, LPBYTE(data), &size)
196 >                        == ERROR_SUCCESS)
197 >                {
198 >                        data[size - 1] = '\0';
199 >                }
200 >                else
201                  {
202 <                        error();
202 >                        data[0] = '\0';
203                  }
204  
205 <                if (RegSetValueEx(key, "SaveDir", 0, REG_SZ, LPBYTE(saveDir),
164 <                        strlen(saveDir) + 1) != ERROR_SUCCESS)
205 >                if (saveDir != data || type != REG_SZ)
206                  {
207 <                        error();
207 >                        if (RegSetValueEx(key, "SaveDir", 0, REG_SZ,
208 >                                LPBYTE(saveDir.c_str()), saveDir.length() + 1) !=
209 >                                ERROR_SUCCESS)
210 >                        {
211 >                                error();
212 >                        }
213                  }
214  
215                  RegCloseKey(key);
# Line 176 | Line 222 | void ScanUtility::saveDirs(void)
222  
223   void ScanUtility::setScanDir(HWND parent)
224   {
225 <        sprintf(scanDir, "C:\\ScannedFiles\\");
225 >        BROWSEINFO info;
226 >
227 >        info.hwndOwner = parent;
228 >        info.pidlRoot = NULL;
229 >        info.pszDisplayName = NULL;
230 >        info.lpszTitle = "Select the Scan Directory";
231 >        info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
232 >        info.lpfn = browse;
233 >        info.lParam = MAKELPARAM(number, true);
234 >        info.iImage = 0;
235 >
236 >        do
237 >        {
238 >                LPITEMIDLIST id = SHBrowseForFolder(&info);
239 >
240 >                if (id != NULL)
241 >                {
242 >                        char folder[MAX_PATH];
243 >
244 >                        if (SHGetPathFromIDList(id, folder))
245 >                        {
246 >                                scanDir = folder;
247 >                        }
248 >                }
249 >
250 >                LPMALLOC destruct;
251 >
252 >                SHGetMalloc(&destruct);
253 >                destruct->Free(id);
254 >                destruct->Release();
255 >
256 >                if (scanDir == "")
257 >                {
258 >                        switch (MessageBox(parent, "Scan Directory needs to be selected.",
259 >                                programName.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR))
260 >                        {
261 >                        case IDABORT:
262 >                                exit(1);
263 >                                break;
264 >                        case IDRETRY:
265 >                                break;
266 >                        case IDIGNORE:
267 >                                Beep(2200, 250);
268 >                                Beep(1100, 500);
269 >                                Beep(3300, 250);
270 >                                exit(2);
271 >                                break;
272 >                        }
273 >                }
274 >        }
275 >        while (scanDir == "");
276  
277 <        //
277 >        if (debug) cerr << "scanDir = " << scanDir << "\n";
278   }
279  
280   void ScanUtility::setSaveDir(HWND parent)
281   {
282 <        sprintf(saveDir, "C:\\ScannedFiles\\Individual2003\\");
282 >        BROWSEINFO info;
283 >
284 >        info.hwndOwner = parent;
285 >        info.pidlRoot = NULL;
286 >        info.pszDisplayName = NULL;
287 >        info.lpszTitle = "Select the Save Directory";
288 >        info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
289 >        info.lpfn = browse;
290 >        info.lParam = MAKELPARAM(number, false);
291 >        info.iImage = 0;
292 >
293 >        do
294 >        {
295 >                LPITEMIDLIST id = SHBrowseForFolder(&info);
296 >
297 >                if (id != NULL)
298 >                {
299 >                        char folder[MAX_PATH];
300 >
301 >                        if (SHGetPathFromIDList(id, folder))
302 >                        {
303 >                                saveDir = folder;
304 >                        }
305 >                }
306 >
307 >                LPMALLOC destruct;
308 >
309 >                SHGetMalloc(&destruct);
310 >                destruct->Free(id);
311 >                destruct->Release();
312 >
313 >                if (saveDir == "")
314 >                {
315 >                        switch (MessageBox(parent, "Scan Directory needs to be selected.",
316 >                                programName.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR))
317 >                        {
318 >                        case IDABORT:
319 >                                exit(1);
320 >                                break;
321 >                        case IDRETRY:
322 >                                break;
323 >                        case IDIGNORE:
324 >                                Beep(2200, 250);
325 >                                Beep(1100, 500);
326 >                                Beep(3300, 250);
327 >                                exit(2);
328 >                                break;
329 >                        }
330 >                }
331 >        }
332 >        while (saveDir == "");
333  
334 <        //
334 >        if (debug) cerr << "saveDir = " << saveDir << "\n";
335 > }
336 >
337 > void ScanUtility::populate(HWND parent)
338 > {
339 >        set<string> scans;
340 >
341 >        do
342 >        {
343 >                string scan = scanDir + "\\SCAN????_000." +
344 >                        IndividualClient::getExtension();
345 >                WIN32_FIND_DATA found;
346 >                HANDLE finder = FindFirstFile(scan.c_str(), &found);
347 >
348 >                if (finder != INVALID_HANDLE_VALUE)
349 >                {
350 >                        do
351 >                        {
352 >                                scans.insert(found.cFileName);
353 >                        }
354 >                        while (FindNextFile(finder, &found));
355 >
356 >                        FindClose(finder);
357 >                }
358 >
359 >                if (scans.empty())
360 >                {
361 >                        if (MessageBox(parent, "No scanned documents found.",
362 >                                programName.c_str(), MB_RETRYCANCEL | MB_ICONQUESTION) ==
363 >                                IDCANCEL) break;
364 >                }
365 >        }
366 >        while (scans.empty());
367 >
368 >        if (scans.empty())
369 >        {
370 >                PropSheet_PressButton(GetParent(parent), PSBTN_BACK);
371 >        }
372 >        else
373 >        {
374 >                SHFILEINFO info;
375 >                HIMAGELIST icons = HIMAGELIST(SHGetFileInfo((*scans.begin()).c_str(),
376 >                        0, &info, sizeof(info), SHGFI_SMALLICON | SHGFI_SYSICONINDEX));
377 >
378 >                ListView_SetImageList(GetDlgItem(parent, IDC_SELECT_SCANS), icons,
379 >                        LVSIL_SMALL);
380 >
381 >                int index = 0;
382 >
383 >                if (debug) cerr << "scans = {\n";
384 >
385 >                for (set<string>::iterator itor = scans.begin(); itor != scans.end();
386 >                        itor++)
387 >                {
388 >                        if (debug) cerr << "   " << *itor << "\n";
389 >
390 >                        char scan[MAX_PATH];
391 >
392 >                        sprintf(scan, "%s", (*itor).c_str());
393 >
394 >                        LVITEM item;
395 >
396 >                        item.mask = LVIF_IMAGE | LVIF_TEXT;
397 >                        item.iItem = index++;
398 >                        item.iSubItem = 0;
399 >                        item.state = LVIS_SELECTED;
400 >                        item.stateMask = LVIS_SELECTED;
401 >                        item.pszText = scan;
402 >                        item.iImage = info.iIcon;
403 >
404 >                        ListView_InsertItem(GetDlgItem(parent, IDC_SELECT_SCANS), &item);
405 >                }
406 >
407 >                if (debug) cerr << "}\n";
408 >        }
409 > }
410 >
411 > int ScanUtility::browse(HWND dialog, UINT msg, LPARAM l, LPARAM d)
412 > {
413 >        map<unsigned, ScanUtility*>::iterator itor = utilities.find(LOWORD(d));
414 >        ScanUtility* data = itor->second;
415 >
416 >        switch (msg)
417 >        {
418 >        case BFFM_INITIALIZED:
419 >                center(dialog);
420 >                SendMessage(dialog, BFFM_SETOKTEXT, 0,
421 >                        LPARAM(toWide("&Select").c_str()));
422 >                SendMessage(dialog, BFFM_SETEXPANDED, FALSE, CSIDL_DRIVES);
423 >                SendMessage(dialog, BFFM_SETSELECTION, TRUE, LPARAM(HIWORD(d) ?
424 >                        data->scanDir.c_str() : data->saveDir.c_str()));
425 >                break;
426 >        case BFFM_SELCHANGED:
427 >                {
428 >                        IShellFolder* object;
429 >
430 >                        SHGetDesktopFolder(&object);
431 >
432 >                        STRRET thing;
433 >                        char* folder;
434 >
435 >                        object->GetDisplayNameOf(LPCITEMIDLIST(l), SHGDN_FORPARSING,
436 >                                &thing);
437 >                        StrRetToStr(&thing, LPCITEMIDLIST(l), &folder);
438 >                        SendMessage(dialog, BFFM_SETSTATUSTEXT, 0, LPARAM(folder));
439 >
440 >                        if (PathIsUNCServer(folder))
441 >                        {
442 >                                SendMessage(dialog, BFFM_ENABLEOK, 0, 0);
443 >                        }
444 >
445 >                        CoTaskMemFree(folder);
446 >                        object->Release();
447 >                }
448 >                break;
449 >        }
450 >
451 >        return 0;
452   }
453  
454   INT_PTR ScanUtility::start(HWND dialog, UINT msg, WPARAM w, LPARAM l)
# Line 198 | Line 461 | INT_PTR ScanUtility::start(HWND dialog,
461          case WM_INITDIALOG:
462                  center(GetParent(dialog));
463                  {
464 <                        map<unsigned, ScanUtility*>::iterator itor = utilities.find(l);
464 >                        LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l);
465 >                        map<unsigned, ScanUtility*>::iterator itor =
466 >                                utilities.find(page->lParam);
467  
468                          windows.insert(pair<HWND, ScanUtility*>(dialog, itor->second));
469                  }
470 +                {
471 +                        ostringstream instructions;
472 +
473 +                        instructions << "1.\tIf you need instructions, you should not be r"
474 +                                << "unning this program\n\tin Scan Utility mode.\n"
475 +                                << "2.\tOtherwise, go forth and scan.\n"
476 +                                << "3.\tThen come back and click Next.\n";
477 +
478 +                        SetDlgItemText(dialog, IDC_START_INSTRUCTIONS,
479 +                                instructions.str().c_str());
480 +                }
481                  break;
482          case WM_NOTIFY:
483                  {
484 <                        LPNMHDR nm = (LPNMHDR) l;
484 >                        LPNMHDR nm = LPNMHDR(l);
485  
486                          switch (nm->code)
487                          {
488                          case PSN_SETACTIVE:
489                                  PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_NEXT);
490 +                                {
491 +                                        char folder[44];
492 +
493 +                                        PathCompactPathEx(folder, data->scanDir.c_str(), 44, 0);
494 +                                        SetDlgItemText(dialog, IDC_START_SCAN_TEXT, folder);
495 +                                        PathCompactPathEx(folder, data->saveDir.c_str(), 44, 0);
496 +                                        SetDlgItemText(dialog, IDC_START_SAVE_TEXT, folder);
497 +                                }
498 +                                break;
499 +                        case PSN_WIZNEXT:
500 +                                SetCurrentDirectory(data->scanDir.c_str());
501                                  break;
502                          }
503                  }
504 <        case WM_DESTROY:
505 <                windows.erase(dialog);
504 >                break;
505 >        case WM_COMMAND:
506 >                switch (LOWORD(w))
507 >                {
508 >                case IDC_START_SCAN_BROWSE:
509 >                        data->setScanDir(dialog);
510 >                        {
511 >                                char folder[44];
512 >
513 >                                PathCompactPathEx(folder, data->scanDir.c_str(), 44, 0);
514 >                                SetDlgItemText(dialog, IDC_START_SCAN_TEXT, folder);
515 >                        }
516 >                        break;
517 >                case IDC_START_SAVE_BROWSE:
518 >                        data->setSaveDir(dialog);
519 >                        {
520 >                                char folder[44];
521 >
522 >                                PathCompactPathEx(folder, data->saveDir.c_str(), 44, 0);
523 >                                SetDlgItemText(dialog, IDC_START_SAVE_TEXT, folder);
524 >                        }
525 >                        break;
526 >                }
527 >                break;
528 >        }
529 >
530 >        return FALSE;
531 > }
532 >
533 > INT_PTR ScanUtility::select(HWND dialog, UINT msg, WPARAM w, LPARAM l)
534 > {
535 >        map<HWND, ScanUtility*>::iterator itor = windows.find(dialog);
536 >        ScanUtility* data = itor->second;
537 >
538 >        switch (msg)
539 >        {
540 >        case WM_INITDIALOG:
541 >                {
542 >                        LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l);
543 >                        map<unsigned, ScanUtility*>::iterator itor =
544 >                                utilities.find(page->lParam);
545 >
546 >                        windows.insert(pair<HWND, ScanUtility*>(dialog, itor->second));
547 >                }
548 >                {
549 >                        LVCOLUMN column;
550 >
551 >                        column.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
552 >                        column.fmt = LVCFMT_IMAGE;
553 >                        column.cx = 120;
554 >                        column.pszText = "Scanned Documents";
555 >
556 >                        ListView_InsertColumn(GetDlgItem(dialog, IDC_SELECT_SCANS), 0,
557 >                                &column);
558 >                }
559 >                break;
560 >        case WM_NOTIFY:
561 >                if (w == IDC_SELECT_SCANS)
562 >                {
563 >                        switch (ListView_GetSelectedCount(GetDlgItem(dialog,
564 >                                IDC_SELECT_SCANS)))
565 >                        {
566 >                        case 1:
567 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
568 >                                        PSWIZB_NEXT);
569 >                                break;
570 >                        default:
571 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK);
572 >                                break;
573 >                        }
574 >                }
575 >                else
576 >                {
577 >                        LPNMHDR nm = LPNMHDR(l);
578 >
579 >                        switch (nm->code)
580 >                        {
581 >                        case PSN_SETACTIVE:
582 >                                PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK);
583 >                                data->populate(dialog);
584 >                                break;
585 >                        case PSN_WIZBACK:
586 >                                ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
587 >                                break;
588 >                        case PSN_WIZNEXT:
589 >                                //
590 >                                ListView_DeleteAllItems(GetDlgItem(dialog, IDC_SELECT_SCANS));
591 >                                break;
592 >                        }
593 >                }
594 >                break;
595 >        case WM_COMMAND:
596                  break;
597          }
598  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines