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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines