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.7 2003/08/17 00:43:49 douglas Exp $ |
6 |
|
|
7 |
|
#include "VTBFileUtil2.h" |
8 |
+ |
#include "Chooser.h" |
9 |
+ |
#include "DiscBrowse.h" |
10 |
+ |
#include "ScanUtility.h" |
11 |
|
|
12 |
|
#include <io.h> |
13 |
|
#include <fcntl.h> |
15 |
|
bool debug = false; |
16 |
|
string program; |
17 |
|
string programName = "Vance Thrift and Biller File Utility 2"; |
18 |
< |
unsigned programVersion = 0x00101000; |
18 |
> |
string programVersion = "2.0alpha"; |
19 |
> |
Gui gui; |
20 |
> |
|
21 |
> |
INT_PTR CALLBACK usage(HWND dialog, UINT msg, WPARAM w, LPARAM l); |
22 |
> |
INT_PTR CALLBACK version(HWND dialog, UINT msg, WPARAM w, LPARAM l); |
23 |
|
|
24 |
|
inline void arguments(vector<string>& args, const string& command) |
25 |
|
{ |
47 |
|
inline void munge(void) |
48 |
|
{ |
49 |
|
AllocConsole(); |
50 |
< |
SetConsoleTitle("Renegade Map Selector"); |
50 |
> |
SetConsoleTitle(programName.c_str()); |
51 |
|
|
52 |
|
int hin = _open_osfhandle(long(GetStdHandle(STD_INPUT_HANDLE)), _O_TEXT); |
53 |
|
int hout = _open_osfhandle(long(GetStdHandle(STD_OUTPUT_HANDLE)), _O_TEXT); |
70 |
|
cerr.sync_with_stdio(); |
71 |
|
} |
72 |
|
|
73 |
+ |
inline void usage(HWND parent) |
74 |
+ |
{ |
75 |
+ |
DialogBox(gui.instance, MAKEINTRESOURCE(IDD_USAGE), parent, usage); |
76 |
+ |
} |
77 |
+ |
|
78 |
+ |
inline void version(HWND parent) |
79 |
+ |
{ |
80 |
+ |
DialogBox(gui.instance, MAKEINTRESOURCE(IDD_VERSION), parent, version); |
81 |
+ |
} |
82 |
+ |
|
83 |
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR |
84 |
|
lpCmdLine, int nShowCmd) |
85 |
|
{ |
86 |
|
vector<string> args; |
87 |
|
|
88 |
+ |
InitCommonControls(); |
89 |
|
arguments(args, GetCommandLine()); |
90 |
|
|
91 |
|
program = args[0]; |
92 |
|
|
93 |
+ |
Mode mode = none; |
94 |
+ |
|
95 |
+ |
gui.instance = hInstance; |
96 |
+ |
gui.icon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_VTB_ICON)); |
97 |
+ |
gui.tips = 0; |
98 |
+ |
|
99 |
|
for (unsigned index = 1; index < args.size(); index++) |
100 |
|
{ |
101 |
|
if (args[index] == "-help") |
110 |
|
} |
111 |
|
else if (args[index] == "-disc") |
112 |
|
{ |
113 |
< |
// |
113 |
> |
mode = disc; |
114 |
|
} |
115 |
|
else if (args[index] == "-scan") |
116 |
|
{ |
117 |
< |
// |
117 |
> |
mode = scan; |
118 |
|
} |
119 |
|
else if (args[index] == "-D") |
120 |
|
{ |
122 |
|
{ |
123 |
|
debug = true; |
124 |
|
|
125 |
< |
munge(); |
125 |
> |
cerr.setf(ios_base::boolalpha); |
126 |
> |
} |
127 |
> |
} |
128 |
> |
else |
129 |
> |
{ |
130 |
> |
string message = "Unknown argument: " + args[index]; |
131 |
> |
|
132 |
> |
MessageBox(NULL, message.c_str(), programName.c_str(), |
133 |
> |
MB_ICONWARNING); |
134 |
> |
} |
135 |
> |
} |
136 |
> |
|
137 |
> |
if (debug) |
138 |
> |
{ |
139 |
> |
munge(); |
140 |
> |
cerr << "mode = "; |
141 |
> |
|
142 |
> |
switch (mode) |
143 |
> |
{ |
144 |
> |
case none: |
145 |
> |
cerr << "none"; |
146 |
> |
break; |
147 |
> |
case disc: |
148 |
> |
cerr << "disc"; |
149 |
> |
break; |
150 |
> |
case scan: |
151 |
> |
cerr << "scan"; |
152 |
> |
break; |
153 |
> |
default: |
154 |
> |
cerr << mode; |
155 |
> |
break; |
156 |
> |
} |
157 |
> |
|
158 |
> |
cerr << "\n"; |
159 |
> |
} |
160 |
> |
|
161 |
> |
if (mode == none) |
162 |
> |
{ |
163 |
> |
Chooser chooser; |
164 |
> |
|
165 |
> |
mode = chooser.choose(); |
166 |
> |
|
167 |
> |
if (debug) |
168 |
> |
{ |
169 |
> |
cerr << "mode = "; |
170 |
> |
|
171 |
> |
switch (mode) |
172 |
> |
{ |
173 |
> |
case none: |
174 |
> |
cerr << "none"; |
175 |
> |
break; |
176 |
> |
case disc: |
177 |
> |
cerr << "disc"; |
178 |
> |
break; |
179 |
> |
case scan: |
180 |
> |
cerr << "scan"; |
181 |
> |
break; |
182 |
> |
default: |
183 |
> |
cerr << mode; |
184 |
> |
break; |
185 |
|
} |
186 |
+ |
|
187 |
+ |
cerr << "\n"; |
188 |
|
} |
189 |
|
} |
190 |
|
|
191 |
+ |
if (mode == disc) |
192 |
+ |
{ |
193 |
+ |
MessageBox(NULL, "Disc Browse mode", programName.c_str(), |
194 |
+ |
MB_ICONINFORMATION); |
195 |
+ |
} |
196 |
+ |
else if (mode == scan) |
197 |
+ |
{ |
198 |
+ |
MessageBox(NULL, "Scan Utility mode", programName.c_str(), |
199 |
+ |
MB_ICONINFORMATION); |
200 |
+ |
} |
201 |
+ |
|
202 |
+ |
if (debug) |
203 |
+ |
{ |
204 |
+ |
cout << "Press enter key to exit . . ."; |
205 |
+ |
cin.get(); |
206 |
+ |
} |
207 |
+ |
|
208 |
|
return 0; |
209 |
|
} |
210 |
|
|
211 |
< |
void usage(void) |
211 |
> |
void tooltip(HWND tool, const string& tip) |
212 |
|
{ |
213 |
< |
// |
213 |
> |
HWND tooltip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP |
214 |
> |
| TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, |
215 |
> |
CW_USEDEFAULT, CW_USEDEFAULT, tool, NULL, gui.instance, NULL); |
216 |
> |
RECT rect; |
217 |
> |
|
218 |
> |
SetWindowPos(tooltip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | |
219 |
> |
SWP_NOACTIVATE); |
220 |
> |
|
221 |
> |
GetClientRect(tool, &rect); |
222 |
> |
|
223 |
> |
TOOLINFO toolinfo; |
224 |
> |
LPTSTR ctip = new CHAR[tip.length()]; |
225 |
> |
|
226 |
> |
sprintf(ctip, "%s", tip.c_str()); |
227 |
> |
|
228 |
> |
if (debug) cerr << "ctip = " << ctip << "\n"; |
229 |
> |
|
230 |
> |
toolinfo.cbSize = sizeof(TOOLINFO); |
231 |
> |
toolinfo.uFlags = TTF_SUBCLASS; |
232 |
> |
toolinfo.hwnd = tool; |
233 |
> |
toolinfo.hinst = gui.instance; |
234 |
> |
toolinfo.uId = gui.tips++; |
235 |
> |
toolinfo.lpszText = ctip; |
236 |
> |
toolinfo.rect.left = rect.left; |
237 |
> |
toolinfo.rect.top = rect.top; |
238 |
> |
toolinfo.rect.right = rect.right; |
239 |
> |
toolinfo.rect.bottom = rect.bottom; |
240 |
> |
|
241 |
> |
SendMessage(tooltip, TTM_ADDTOOL, 0, LPARAM(LPTOOLINFO(&toolinfo))); |
242 |
> |
} |
243 |
> |
|
244 |
> |
INT_PTR CALLBACK usage(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
245 |
> |
{ |
246 |
> |
switch (msg) |
247 |
> |
{ |
248 |
> |
case WM_INITDIALOG: |
249 |
> |
center(dialog); |
250 |
> |
SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(gui.icon)); |
251 |
> |
SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str())); |
252 |
> |
{ |
253 |
> |
ostringstream usage; |
254 |
> |
|
255 |
> |
usage << "Usage: VTBFileUtil [-help | -version | -disc | -scan]\n" |
256 |
> |
<< "\nOptions:\n" |
257 |
> |
<< " -help\t\tDisplay this information\n" |
258 |
> |
<< " -version\tDisplay version information\n" |
259 |
> |
<< " -disc\t\tStart in Disc Browse mode\n" |
260 |
> |
<< " -scan\t\tStart in Scan Utility mode\n"; |
261 |
> |
|
262 |
> |
SendMessage(GetDlgItem(dialog, IDC_USAGE_TEXT), WM_SETTEXT, 0, |
263 |
> |
LPARAM(usage.str().c_str())); |
264 |
> |
} |
265 |
> |
break; |
266 |
> |
case WM_COMMAND: |
267 |
> |
switch (LOWORD(w)) |
268 |
> |
{ |
269 |
> |
case IDOK: |
270 |
> |
case IDCANCEL: |
271 |
> |
EndDialog(dialog, w); |
272 |
> |
return TRUE; |
273 |
> |
default: |
274 |
> |
break; |
275 |
> |
} |
276 |
> |
break; |
277 |
> |
} |
278 |
> |
|
279 |
> |
return FALSE; |
280 |
|
} |
281 |
|
|
282 |
< |
void version(void) |
282 |
> |
INT_PTR CALLBACK version(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
283 |
|
{ |
284 |
< |
// |
284 |
> |
switch (msg) |
285 |
> |
{ |
286 |
> |
case WM_INITDIALOG: |
287 |
> |
center(dialog); |
288 |
> |
SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(gui.icon)); |
289 |
> |
SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str())); |
290 |
> |
{ |
291 |
> |
ostringstream version; |
292 |
> |
|
293 |
> |
version << programName << " (" << programVersion << ")\n\n" |
294 |
> |
<< "Copyright © 2003, Douglas Thrift.\n"; |
295 |
> |
|
296 |
> |
SendMessage(GetDlgItem(dialog, IDC_VERSION_TEXT), WM_SETTEXT, 0, |
297 |
> |
LPARAM(version.str().c_str())); |
298 |
> |
} |
299 |
> |
break; |
300 |
> |
case WM_COMMAND: |
301 |
> |
switch (LOWORD(w)) |
302 |
> |
{ |
303 |
> |
case IDOK: |
304 |
> |
case IDCANCEL: |
305 |
> |
EndDialog(dialog, w); |
306 |
> |
return TRUE; |
307 |
> |
default: |
308 |
> |
break; |
309 |
> |
} |
310 |
> |
break; |
311 |
> |
} |
312 |
> |
|
313 |
> |
return FALSE; |
314 |
|
} |