ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/VTBFileUtil2/VTBFileUtil2.cxx
(Generate patch)

Comparing trunk/VTBFileUtil2/VTBFileUtil2.cxx (file contents):
Revision 255 by douglas, 2003-08-15T17:12:57-07:00 vs.
Revision 257 by douglas, 2003-08-15T23:44:42-07:00

# Line 2 | Line 2
2   //
3   // Douglas Thrift
4   //
5 < // $Id: VTBFileUtil2.cxx,v 1.1 2003/08/16 00:12:57 douglas Exp $
5 > // $Id: VTBFileUtil2.cxx,v 1.3 2003/08/16 06:44:42 douglas Exp $
6  
7   #include "VTBFileUtil2.h"
8  
9   #include <io.h>
10   #include <fcntl.h>
11  
12 + #include "resource.h"
13 +
14   bool debug = false;
15   string program;
16   string programName = "Vance Thrift and Biller File Utility 2";
17 < unsigned programVersion = 0x00101000;
17 > string programVersion = "2.0alpha";
18 >
19 > HICON icon;
20 > Mode choiceMode = none;
21 > bool choiceAlways = false;
22 >
23 > INT_PTR CALLBACK usage(HWND dialog, UINT msg, WPARAM w, LPARAM l);
24 > INT_PTR CALLBACK version(HWND dialog, UINT msg, WPARAM w, LPARAM l);
25 > INT_PTR CALLBACK choice(HWND dialog, UINT msg, WPARAM w, LPARAM l);
26  
27   inline void arguments(vector<string>& args, const string& command)
28   {
# Line 63 | Line 73 | inline void munge(void)
73          cerr.sync_with_stdio();
74   }
75  
76 + inline void usage(HINSTANCE instance, HWND parent)
77 + {
78 +        DialogBox(instance, MAKEINTRESOURCE(IDD_USAGE), parent, usage);
79 + }
80 +
81 + inline void version(HINSTANCE instance, HWND parent)
82 + {
83 +        DialogBox(instance, MAKEINTRESOURCE(IDD_VERSION), parent, version);
84 + }
85 +
86 + inline void choice(Mode& mode, HINSTANCE instance, HWND parent)
87 + {
88 +        DialogBox(instance, MAKEINTRESOURCE(IDD_CHOICE), parent, choice);
89 +
90 +        mode = choiceMode;
91 + }
92 +
93   int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
94          lpCmdLine, int nShowCmd)
95   {
96          vector<string> args;
97          
98 +        InitCommonControls();
99          arguments(args, GetCommandLine());
100  
101          program = args[0];
102  
103 +        Mode mode = none;
104 +
105 +        icon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_VTB_ICON));
106 +
107          for (unsigned index = 1; index < args.size(); index++)
108          {
109                  if (args[index] == "-help")
110                  {
111 <                        usage();
111 >                        usage(hInstance);
112                          return 0;
113                  }
114                  else if (args[index] == "-version")
115                  {
116 <                        version();
116 >                        version(hInstance);
117                          return 0;
118                  }
119                  else if (args[index] == "-disc")
120                  {
121 <                        //
121 >                        mode = disc;
122                  }
123                  else if (args[index] == "-scan")
124                  {
125 <                        //
125 >                        mode = scan;
126                  }
127                  else if (args[index] == "-D")
128                  {
# Line 99 | Line 131 | int WINAPI WinMain(HINSTANCE hInstance,
131                                  debug = true;
132  
133                                  munge();
134 +                                cerr.setf(ios_base::boolalpha);
135 +                        }
136 +                }
137 +                else
138 +                {
139 +                        string message = "Unknown argument: " + args[index];
140 +
141 +                        MessageBox(NULL, message.c_str(), programName.c_str(),
142 +                                MB_ICONWARNING);
143 +                }
144 +        }
145 +
146 +        if (debug)
147 +        {
148 +                cerr << "mode = ";
149 +
150 +                switch (mode)
151 +                {
152 +                case none:
153 +                        cerr << "none";
154 +                        break;
155 +                case disc:
156 +                        cerr << "disc";
157 +                        break;
158 +                case scan:
159 +                        cerr << "scan";
160 +                        break;
161 +                default:
162 +                        cerr << mode;
163 +                        break;
164 +                }
165 +
166 +                cerr << "\n";
167 +        }
168 +
169 +        if (mode == none)
170 +        {
171 +                choice(mode, hInstance);
172 +
173 +                if (debug)
174 +                {
175 +                        cerr << "mode = ";
176 +
177 +                        switch (mode)
178 +                        {
179 +                        case none:
180 +                                cerr << "none";
181 +                                break;
182 +                        case disc:
183 +                                cerr << "disc";
184 +                                break;
185 +                        case scan:
186 +                                cerr << "scan";
187 +                                break;
188 +                        default:
189 +                                cerr << mode;
190 +                                break;
191                          }
192 +
193 +                        cerr << "\n";
194                  }
195          }
196  
197 +        if (mode == disc)
198 +        {
199 +                MessageBox(NULL, "Disc Browse mode", programName.c_str(),
200 +                        MB_ICONINFORMATION);
201 +        }
202 +        else if (mode == scan)
203 +        {
204 +                MessageBox(NULL, "Scan Utility mode", programName.c_str(),
205 +                        MB_ICONINFORMATION);
206 +        }
207 +
208 +        if (debug)
209 +        {
210 +                cout << "Press enter key to exit . . .";
211 +                cin.get();
212 +        }
213 +
214          return 0;
215   }
216  
217 < void usage(void)
217 > INT_PTR CALLBACK usage(HWND dialog, UINT msg, WPARAM w, LPARAM l)
218 > {
219 >        switch (msg)
220 >        {
221 >        case WM_INITDIALOG:
222 >                center(dialog);
223 >                SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(icon));
224 >                SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str()));
225 >                {
226 >                        ostringstream usage;
227 >
228 >                        usage << "Usage: VTBFileUtil [-help | -version | -disc | -scan]\n"
229 >                                << "\nOptions:\n"
230 >                                << "  -help\t\tDisplay this information\n"
231 >                                << "  -version\tDisplay version information\n"
232 >                                << "  -disc\t\tStart in Disc Browse mode\n"
233 >                                << "  -scan\t\tStart in Scan Utility mode\n";
234 >
235 >                        SendMessage(GetDlgItem(dialog, IDC_USAGE_TEXT), WM_SETTEXT, 0,
236 >                                LPARAM(usage.str().c_str()));
237 >                }
238 >                break;
239 >        case WM_COMMAND:
240 >                switch (LOWORD(w))
241 >                {
242 >                case IDOK:
243 >                case IDCANCEL:
244 >                        EndDialog(dialog, w);
245 >                        return TRUE;
246 >                default:
247 >                        break;
248 >                }
249 >                break;
250 >        }
251 >
252 >        return FALSE;
253 > }
254 >
255 > INT_PTR CALLBACK version(HWND dialog, UINT msg, WPARAM w, LPARAM l)
256   {
257 <        //
257 >        switch (msg)
258 >        {
259 >        case WM_INITDIALOG:
260 >                center(dialog);
261 >                SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(icon));
262 >                SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str()));
263 >                {
264 >                        ostringstream version;
265 >
266 >                        version << programName << " ( " << programVersion << " )\n\n"
267 >                                << "Copyright © 2003, Douglas Thrift.\n";
268 >
269 >                        SendMessage(GetDlgItem(dialog, IDC_VERSION_TEXT), WM_SETTEXT, 0,
270 >                                LPARAM(version.str().c_str()));
271 >                }
272 >                break;
273 >        case WM_COMMAND:
274 >                switch (LOWORD(w))
275 >                {
276 >                case IDOK:
277 >                case IDCANCEL:
278 >                        EndDialog(dialog, w);
279 >                        return TRUE;
280 >                default:
281 >                        break;
282 >                }
283 >                break;
284 >        }
285 >
286 >        return FALSE;
287   }
288  
289 < void version(void)
289 > INT_PTR CALLBACK choice(HWND dialog, UINT msg, WPARAM w, LPARAM l)
290   {
291 <        //
291 >        switch (msg)
292 >        {
293 >        case WM_INITDIALOG:
294 >                center(dialog);
295 >                SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(icon));
296 >                SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str()));
297 >                break;
298 >        case WM_COMMAND:
299 >                switch (LOWORD(w))
300 >                {
301 >                case IDC_CHOICE_DISC:
302 >                        choiceMode = disc;
303 >                        if (debug) cerr << "choiceMode = disc\n";
304 >                        EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE);
305 >                        EnableWindow(GetDlgItem(dialog, IDOK), TRUE);
306 >                        break;
307 >                case IDC_CHOICE_SCAN:
308 >                        choiceMode = scan;
309 >                        if (debug) cerr << "choiceMode = scan\n";
310 >                        EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE);
311 >                        EnableWindow(GetDlgItem(dialog, IDOK), TRUE);
312 >                        break;
313 >                case IDC_CHOICE_ALWAYS:
314 >                        choiceAlways = !choiceAlways;
315 >                        if (debug) cerr << "choiceAlways = " << choiceAlways << "\n";
316 >                        break;
317 >                case IDCANCEL:
318 >                        choiceMode = none;
319 >                case IDOK:
320 >                        EndDialog(dialog, w);
321 >                        return TRUE;
322 >                default:
323 >                        break;
324 >                }
325 >                break;
326 >        }
327 >
328 >        return FALSE;
329   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines