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 260 by douglas, 2003-08-16T02:08:35-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.5 2003/08/16 09:08:35 douglas Exp $
6  
7   #include "VTBFileUtil2.h"
8 + #include "DiscBrowse.h"
9 + #include "ScanUtility.h"
10  
11   #include <io.h>
12   #include <fcntl.h>
13  
14 + #include "resource.h"
15 +
16   bool debug = false;
17   string program;
18   string programName = "Vance Thrift and Biller File Utility 2";
19 < unsigned programVersion = 0x00101000;
19 > string programVersion = "2.0alpha";
20 >
21 > HINSTANCE instance;
22 > HICON icon;
23 > Mode choiceMode = none;
24 > bool choiceAlways = false;
25 > UINT_PTR tips = 0;
26 >
27 > INT_PTR CALLBACK usage(HWND dialog, UINT msg, WPARAM w, LPARAM l);
28 > INT_PTR CALLBACK version(HWND dialog, UINT msg, WPARAM w, LPARAM l);
29 > INT_PTR CALLBACK choice(HWND dialog, UINT msg, WPARAM w, LPARAM l);
30  
31   inline void arguments(vector<string>& args, const string& command)
32   {
# Line 40 | Line 54 | inline void arguments(vector<string>& ar
54   inline void munge(void)
55   {
56          AllocConsole();
57 <        SetConsoleTitle("Renegade Map Selector");
57 >        SetConsoleTitle(programName.c_str());
58  
59          int hin = _open_osfhandle(long(GetStdHandle(STD_INPUT_HANDLE)), _O_TEXT);
60          int hout = _open_osfhandle(long(GetStdHandle(STD_OUTPUT_HANDLE)), _O_TEXT);
# Line 63 | Line 77 | inline void munge(void)
77          cerr.sync_with_stdio();
78   }
79  
80 + inline void usage(HWND parent)
81 + {
82 +        DialogBox(instance, MAKEINTRESOURCE(IDD_USAGE), parent, usage);
83 + }
84 +
85 + inline void version(HWND parent)
86 + {
87 +        DialogBox(instance, MAKEINTRESOURCE(IDD_VERSION), parent, version);
88 + }
89 +
90 + inline void choice(Mode& mode, HWND parent)
91 + {
92 +        DialogBox(instance, MAKEINTRESOURCE(IDD_CHOICE), parent, choice);
93 +
94 +        mode = choiceMode;
95 + }
96 +
97   int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
98          lpCmdLine, int nShowCmd)
99   {
100          vector<string> args;
101          
102 +        InitCommonControls();
103          arguments(args, GetCommandLine());
104  
105 +        instance = hInstance;
106          program = args[0];
107  
108 +        Mode mode = none;
109 +
110 +        icon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_VTB_ICON));
111 +
112          for (unsigned index = 1; index < args.size(); index++)
113          {
114                  if (args[index] == "-help")
# Line 86 | Line 123 | int WINAPI WinMain(HINSTANCE hInstance,
123                  }
124                  else if (args[index] == "-disc")
125                  {
126 <                        //
126 >                        mode = disc;
127                  }
128                  else if (args[index] == "-scan")
129                  {
130 <                        //
130 >                        mode = scan;
131                  }
132                  else if (args[index] == "-D")
133                  {
# Line 99 | Line 136 | int WINAPI WinMain(HINSTANCE hInstance,
136                                  debug = true;
137  
138                                  munge();
139 +                                cerr.setf(ios_base::boolalpha);
140 +                        }
141 +                }
142 +                else
143 +                {
144 +                        string message = "Unknown argument: " + args[index];
145 +
146 +                        MessageBox(NULL, message.c_str(), programName.c_str(),
147 +                                MB_ICONWARNING);
148 +                }
149 +        }
150 +
151 +        if (debug)
152 +        {
153 +                cerr << "mode = ";
154 +
155 +                switch (mode)
156 +                {
157 +                case none:
158 +                        cerr << "none";
159 +                        break;
160 +                case disc:
161 +                        cerr << "disc";
162 +                        break;
163 +                case scan:
164 +                        cerr << "scan";
165 +                        break;
166 +                default:
167 +                        cerr << mode;
168 +                        break;
169 +                }
170 +
171 +                cerr << "\n";
172 +        }
173 +
174 +        if (mode == none)
175 +        {
176 +                choice(mode);
177 +
178 +                if (debug)
179 +                {
180 +                        cerr << "mode = ";
181 +
182 +                        switch (mode)
183 +                        {
184 +                        case none:
185 +                                cerr << "none";
186 +                                break;
187 +                        case disc:
188 +                                cerr << "disc";
189 +                                break;
190 +                        case scan:
191 +                                cerr << "scan";
192 +                                break;
193 +                        default:
194 +                                cerr << mode;
195 +                                break;
196                          }
197 +
198 +                        cerr << "\n";
199                  }
200          }
201  
202 +        if (mode == disc)
203 +        {
204 +                MessageBox(NULL, "Disc Browse mode", programName.c_str(),
205 +                        MB_ICONINFORMATION);
206 +        }
207 +        else if (mode == scan)
208 +        {
209 +                MessageBox(NULL, "Scan Utility mode", programName.c_str(),
210 +                        MB_ICONINFORMATION);
211 +        }
212 +
213 +        if (debug)
214 +        {
215 +                cout << "Press enter key to exit . . .";
216 +                cin.get();
217 +        }
218 +
219          return 0;
220   }
221  
222 < void usage(void)
222 > void tooltip(HWND tool, const string& tip)
223 > {
224 >        HWND tooltip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP
225 >                | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT,
226 >                CW_USEDEFAULT, CW_USEDEFAULT, tool, NULL, instance, NULL);
227 >        RECT rect;
228 >
229 >        SetWindowPos(tooltip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
230 >                SWP_NOACTIVATE);
231 >
232 >        GetClientRect(tool, &rect);
233 >
234 >        TOOLINFO toolinfo;
235 >        char* ctip = new char[tip.length()];
236 >
237 >        sprintf(ctip, "%s", tip.c_str());
238 >
239 >        if (debug) cerr << "ctip = " << ctip << "\n";
240 >
241 >        toolinfo.cbSize = sizeof(TOOLINFO);
242 >        toolinfo.uFlags = TTF_SUBCLASS;
243 >        toolinfo.hwnd = tool;
244 >        toolinfo.hinst = instance;
245 >        toolinfo.uId = tips++;
246 >        toolinfo.lpszText = ctip;
247 >        toolinfo.rect.left = rect.left;
248 >        toolinfo.rect.top = rect.top;
249 >        toolinfo.rect.right = rect.right;
250 >        toolinfo.rect.bottom = rect.bottom;
251 >
252 >        SendMessage(tooltip, TTM_ADDTOOL, 0, LPARAM(LPTOOLINFO(&toolinfo)));
253 > }
254 >
255 > INT_PTR CALLBACK usage(HWND dialog, UINT msg, WPARAM w, LPARAM l)
256 > {
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 usage;
265 >
266 >                        usage << "Usage: VTBFileUtil [-help | -version | -disc | -scan]\n"
267 >                                << "\nOptions:\n"
268 >                                << "  -help\t\tDisplay this information\n"
269 >                                << "  -version\tDisplay version information\n"
270 >                                << "  -disc\t\tStart in Disc Browse mode\n"
271 >                                << "  -scan\t\tStart in Scan Utility mode\n";
272 >
273 >                        SendMessage(GetDlgItem(dialog, IDC_USAGE_TEXT), WM_SETTEXT, 0,
274 >                                LPARAM(usage.str().c_str()));
275 >                }
276 >                break;
277 >        case WM_COMMAND:
278 >                switch (LOWORD(w))
279 >                {
280 >                case IDOK:
281 >                case IDCANCEL:
282 >                        EndDialog(dialog, w);
283 >                        return TRUE;
284 >                default:
285 >                        break;
286 >                }
287 >                break;
288 >        }
289 >
290 >        return FALSE;
291 > }
292 >
293 > INT_PTR CALLBACK version(HWND dialog, UINT msg, WPARAM w, LPARAM l)
294   {
295 <        //
295 >        switch (msg)
296 >        {
297 >        case WM_INITDIALOG:
298 >                center(dialog);
299 >                SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(icon));
300 >                SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str()));
301 >                {
302 >                        ostringstream version;
303 >
304 >                        version << programName << " ( " << programVersion << " )\n\n"
305 >                                << "Copyright © 2003, Douglas Thrift.\n";
306 >
307 >                        SendMessage(GetDlgItem(dialog, IDC_VERSION_TEXT), WM_SETTEXT, 0,
308 >                                LPARAM(version.str().c_str()));
309 >                }
310 >                break;
311 >        case WM_COMMAND:
312 >                switch (LOWORD(w))
313 >                {
314 >                case IDOK:
315 >                case IDCANCEL:
316 >                        EndDialog(dialog, w);
317 >                        return TRUE;
318 >                default:
319 >                        break;
320 >                }
321 >                break;
322 >        }
323 >
324 >        return FALSE;
325   }
326  
327 < void version(void)
327 > INT_PTR CALLBACK choice(HWND dialog, UINT msg, WPARAM w, LPARAM l)
328   {
329 <        //
329 >        switch (msg)
330 >        {
331 >        case WM_INITDIALOG:
332 >                center(dialog);
333 >                SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(icon));
334 >                SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str()));
335 >                break;
336 >        case WM_COMMAND:
337 >                switch (LOWORD(w))
338 >                {
339 >                case IDC_CHOICE_DISC:
340 >                        choiceMode = disc;
341 >                        if (debug) cerr << "choiceMode = disc\n";
342 >                        EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE);
343 >                        EnableWindow(GetDlgItem(dialog, IDOK), TRUE);
344 >                        break;
345 >                case IDC_CHOICE_SCAN:
346 >                        choiceMode = scan;
347 >                        if (debug) cerr << "choiceMode = scan\n";
348 >                        EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE);
349 >                        EnableWindow(GetDlgItem(dialog, IDOK), TRUE);
350 >                        break;
351 >                case IDC_CHOICE_ALWAYS:
352 >                        choiceAlways = !choiceAlways;
353 >                        if (debug) cerr << "choiceAlways = " << choiceAlways << "\n";
354 >                        break;
355 >                case IDCANCEL:
356 >                        choiceMode = none;
357 >                case IDOK:
358 >                        EndDialog(dialog, w);
359 >                        return TRUE;
360 >                default:
361 >                        break;
362 >                }
363 >                break;
364 >        }
365 >
366 >        return FALSE;
367   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines