720a8fb7 |
1 | /* |
2 | * windows.c: Windows front end for my puzzle collection. |
be8d5aa1 |
3 | * |
4 | * TODO: |
5 | * |
6 | * - Figure out what to do if a puzzle requests a size bigger than |
7 | * the screen will take. In principle we could put scrollbars in |
8 | * the window, although that would be pretty horrid. Another |
9 | * option is to detect in advance that this will be a problem - |
10 | * we can probably tell this using midend_size() before actually |
11 | * generating the puzzle - and simply refuse to do it. |
720a8fb7 |
12 | */ |
4e7ef6e6 |
13 | |
14 | #include <windows.h> |
fd1a1a2b |
15 | #include <commctrl.h> |
4e7ef6e6 |
16 | |
17 | #include <stdio.h> |
4efb3868 |
18 | #include <assert.h> |
8b7938e7 |
19 | #include <ctype.h> |
4e7ef6e6 |
20 | #include <stdarg.h> |
21 | #include <stdlib.h> |
22 | #include <time.h> |
23 | |
24 | #include "puzzles.h" |
25 | |
eb2ad6f1 |
26 | #define IDM_NEW 0x0010 |
27 | #define IDM_RESTART 0x0020 |
28 | #define IDM_UNDO 0x0030 |
29 | #define IDM_REDO 0x0040 |
30 | #define IDM_QUIT 0x0050 |
077f3cbe |
31 | #define IDM_CONFIG 0x0060 |
5928817c |
32 | #define IDM_SEED 0x0070 |
e91825f8 |
33 | #define IDM_HELPC 0x0080 |
34 | #define IDM_GAMEHELP 0x0090 |
eb2ad6f1 |
35 | #define IDM_PRESETS 0x0100 |
36 | |
e91825f8 |
37 | #define HELP_FILE_NAME "puzzles.hlp" |
38 | #define HELP_CNT_NAME "puzzles.cnt" |
39 | |
c71454c0 |
40 | #ifdef DEBUG |
41 | static FILE *debug_fp = NULL; |
42 | static HANDLE debug_hdl = INVALID_HANDLE_VALUE; |
43 | static int debug_got_console = 0; |
44 | |
45 | void dputs(char *buf) |
46 | { |
47 | DWORD dw; |
48 | |
49 | if (!debug_got_console) { |
50 | if (AllocConsole()) { |
51 | debug_got_console = 1; |
52 | debug_hdl = GetStdHandle(STD_OUTPUT_HANDLE); |
53 | } |
54 | } |
55 | if (!debug_fp) { |
56 | debug_fp = fopen("debug.log", "w"); |
57 | } |
58 | |
59 | if (debug_hdl != INVALID_HANDLE_VALUE) { |
60 | WriteFile(debug_hdl, buf, strlen(buf), &dw, NULL); |
61 | } |
62 | fputs(buf, debug_fp); |
63 | fflush(debug_fp); |
64 | } |
65 | |
66 | void debug_printf(char *fmt, ...) |
67 | { |
68 | char buf[4096]; |
69 | va_list ap; |
70 | |
71 | va_start(ap, fmt); |
72 | vsprintf(buf, fmt, ap); |
73 | dputs(buf); |
74 | va_end(ap); |
75 | } |
76 | |
77 | #define debug(x) (debug_printf x) |
78 | |
79 | #else |
80 | |
81 | #define debug(x) |
82 | |
83 | #endif |
84 | |
4efb3868 |
85 | struct font { |
86 | HFONT font; |
87 | int type; |
88 | int size; |
89 | }; |
90 | |
077f3cbe |
91 | struct cfg_aux { |
92 | int ctlid; |
93 | }; |
94 | |
4e7ef6e6 |
95 | struct frontend { |
96 | midend_data *me; |
077f3cbe |
97 | HWND hwnd, statusbar, cfgbox; |
98 | HINSTANCE inst; |
4e7ef6e6 |
99 | HBITMAP bitmap, prevbm; |
100 | HDC hdc_bm; |
101 | COLORREF *colours; |
102 | HBRUSH *brushes; |
103 | HPEN *pens; |
4efb3868 |
104 | HRGN clip; |
4e7ef6e6 |
105 | UINT timer; |
8c1fd974 |
106 | DWORD timer_last_tickcount; |
eb2ad6f1 |
107 | int npresets; |
108 | game_params **presets; |
4efb3868 |
109 | struct font *fonts; |
110 | int nfonts, fontsize; |
077f3cbe |
111 | config_item *cfg; |
112 | struct cfg_aux *cfgaux; |
5928817c |
113 | int cfg_which, cfg_done; |
077f3cbe |
114 | HFONT cfgfont; |
e91825f8 |
115 | char *help_path; |
116 | int help_has_contents; |
4e7ef6e6 |
117 | }; |
118 | |
119 | void fatal(char *fmt, ...) |
120 | { |
121 | char buf[2048]; |
122 | va_list ap; |
123 | |
124 | va_start(ap, fmt); |
125 | vsprintf(buf, fmt, ap); |
126 | va_end(ap); |
127 | |
128 | MessageBox(NULL, buf, "Fatal error", MB_ICONEXCLAMATION | MB_OK); |
129 | |
130 | exit(1); |
131 | } |
132 | |
cbb5549e |
133 | void get_random_seed(void **randseed, int *randseedsize) |
134 | { |
135 | time_t *tp = snew(time_t); |
136 | time(tp); |
137 | *randseed = (void *)tp; |
138 | *randseedsize = sizeof(time_t); |
139 | } |
140 | |
fd1a1a2b |
141 | void status_bar(frontend *fe, char *text) |
142 | { |
143 | SetWindowText(fe->statusbar, text); |
144 | } |
145 | |
4e7ef6e6 |
146 | void frontend_default_colour(frontend *fe, float *output) |
147 | { |
148 | DWORD c = GetSysColor(COLOR_MENU); /* ick */ |
149 | |
150 | output[0] = (float)(GetRValue(c) / 255.0); |
151 | output[1] = (float)(GetGValue(c) / 255.0); |
152 | output[2] = (float)(GetBValue(c) / 255.0); |
153 | } |
154 | |
4efb3868 |
155 | void clip(frontend *fe, int x, int y, int w, int h) |
156 | { |
4efb3868 |
157 | IntersectClipRect(fe->hdc_bm, x, y, x+w, y+h); |
158 | } |
159 | |
160 | void unclip(frontend *fe) |
161 | { |
ea25d9da |
162 | SelectClipRgn(fe->hdc_bm, NULL); |
4efb3868 |
163 | } |
164 | |
165 | void draw_text(frontend *fe, int x, int y, int fonttype, int fontsize, |
166 | int align, int colour, char *text) |
167 | { |
168 | int i; |
169 | |
170 | /* |
171 | * Find or create the font. |
172 | */ |
173 | for (i = 0; i < fe->nfonts; i++) |
174 | if (fe->fonts[i].type == fonttype && fe->fonts[i].size == fontsize) |
175 | break; |
176 | |
177 | if (i == fe->nfonts) { |
178 | if (fe->fontsize <= fe->nfonts) { |
179 | fe->fontsize = fe->nfonts + 10; |
180 | fe->fonts = sresize(fe->fonts, fe->fontsize, struct font); |
181 | } |
182 | |
183 | fe->nfonts++; |
184 | |
185 | fe->fonts[i].type = fonttype; |
186 | fe->fonts[i].size = fontsize; |
187 | |
f17b8728 |
188 | fe->fonts[i].font = CreateFont(-fontsize, 0, 0, 0, FW_BOLD, |
4efb3868 |
189 | FALSE, FALSE, FALSE, DEFAULT_CHARSET, |
190 | OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, |
191 | DEFAULT_QUALITY, |
192 | (fonttype == FONT_FIXED ? |
193 | FIXED_PITCH | FF_DONTCARE : |
194 | VARIABLE_PITCH | FF_SWISS), |
195 | NULL); |
196 | } |
197 | |
198 | /* |
199 | * Position and draw the text. |
200 | */ |
201 | { |
202 | HFONT oldfont; |
203 | TEXTMETRIC tm; |
204 | SIZE size; |
205 | |
206 | oldfont = SelectObject(fe->hdc_bm, fe->fonts[i].font); |
207 | if (GetTextMetrics(fe->hdc_bm, &tm)) { |
208 | if (align & ALIGN_VCENTRE) |
209 | y -= (tm.tmAscent+tm.tmDescent)/2; |
210 | else |
211 | y -= tm.tmAscent; |
212 | } |
213 | if (GetTextExtentPoint32(fe->hdc_bm, text, strlen(text), &size)) { |
214 | if (align & ALIGN_HCENTRE) |
215 | x -= size.cx / 2; |
216 | else if (align & ALIGN_HRIGHT) |
217 | x -= size.cx; |
218 | } |
219 | SetBkMode(fe->hdc_bm, TRANSPARENT); |
0572b5d8 |
220 | SetTextColor(fe->hdc_bm, fe->colours[colour]); |
4efb3868 |
221 | TextOut(fe->hdc_bm, x, y, text, strlen(text)); |
222 | SelectObject(fe->hdc_bm, oldfont); |
223 | } |
224 | } |
225 | |
4e7ef6e6 |
226 | void draw_rect(frontend *fe, int x, int y, int w, int h, int colour) |
227 | { |
fbdd7610 |
228 | if (w == 1 && h == 1) { |
229 | /* |
230 | * Rectangle() appears to get uppity if asked to draw a 1x1 |
231 | * rectangle, presumably on the grounds that that's beneath |
232 | * its dignity and you ought to be using SetPixel instead. |
233 | * So I will. |
234 | */ |
235 | SetPixel(fe->hdc_bm, x, y, fe->colours[colour]); |
236 | } else { |
237 | HBRUSH oldbrush = SelectObject(fe->hdc_bm, fe->brushes[colour]); |
238 | HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[colour]); |
239 | Rectangle(fe->hdc_bm, x, y, x+w, y+h); |
240 | SelectObject(fe->hdc_bm, oldbrush); |
241 | SelectObject(fe->hdc_bm, oldpen); |
242 | } |
4e7ef6e6 |
243 | } |
244 | |
245 | void draw_line(frontend *fe, int x1, int y1, int x2, int y2, int colour) |
246 | { |
247 | HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[colour]); |
248 | MoveToEx(fe->hdc_bm, x1, y1, NULL); |
249 | LineTo(fe->hdc_bm, x2, y2); |
250 | SetPixel(fe->hdc_bm, x2, y2, fe->colours[colour]); |
251 | SelectObject(fe->hdc_bm, oldpen); |
252 | } |
253 | |
254 | void draw_polygon(frontend *fe, int *coords, int npoints, |
255 | int fill, int colour) |
256 | { |
257 | POINT *pts = snewn(npoints+1, POINT); |
258 | int i; |
259 | |
260 | for (i = 0; i <= npoints; i++) { |
261 | int j = (i < npoints ? i : 0); |
262 | pts[i].x = coords[j*2]; |
263 | pts[i].y = coords[j*2+1]; |
264 | } |
265 | |
266 | if (fill) { |
267 | HBRUSH oldbrush = SelectObject(fe->hdc_bm, fe->brushes[colour]); |
268 | HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[colour]); |
269 | Polygon(fe->hdc_bm, pts, npoints); |
270 | SelectObject(fe->hdc_bm, oldbrush); |
271 | SelectObject(fe->hdc_bm, oldpen); |
272 | } else { |
273 | HPEN oldpen = SelectObject(fe->hdc_bm, fe->pens[colour]); |
274 | Polyline(fe->hdc_bm, pts, npoints+1); |
275 | SelectObject(fe->hdc_bm, oldpen); |
276 | } |
277 | |
278 | sfree(pts); |
279 | } |
280 | |
281 | void start_draw(frontend *fe) |
282 | { |
283 | HDC hdc_win; |
284 | hdc_win = GetDC(fe->hwnd); |
285 | fe->hdc_bm = CreateCompatibleDC(hdc_win); |
286 | fe->prevbm = SelectObject(fe->hdc_bm, fe->bitmap); |
287 | ReleaseDC(fe->hwnd, hdc_win); |
4efb3868 |
288 | fe->clip = NULL; |
077f3cbe |
289 | SetMapMode(fe->hdc_bm, MM_TEXT); |
4e7ef6e6 |
290 | } |
291 | |
292 | void draw_update(frontend *fe, int x, int y, int w, int h) |
293 | { |
294 | RECT r; |
295 | |
296 | r.left = x; |
297 | r.top = y; |
298 | r.right = x + w; |
299 | r.bottom = y + h; |
300 | |
301 | InvalidateRect(fe->hwnd, &r, FALSE); |
302 | } |
303 | |
304 | void end_draw(frontend *fe) |
305 | { |
306 | SelectObject(fe->hdc_bm, fe->prevbm); |
307 | DeleteDC(fe->hdc_bm); |
4efb3868 |
308 | if (fe->clip) { |
309 | DeleteObject(fe->clip); |
310 | fe->clip = NULL; |
311 | } |
4e7ef6e6 |
312 | } |
313 | |
314 | void deactivate_timer(frontend *fe) |
315 | { |
316 | KillTimer(fe->hwnd, fe->timer); |
317 | fe->timer = 0; |
318 | } |
319 | |
320 | void activate_timer(frontend *fe) |
321 | { |
8c1fd974 |
322 | if (!fe->timer) { |
323 | fe->timer = SetTimer(fe->hwnd, fe->timer, 20, NULL); |
324 | fe->timer_last_tickcount = GetTickCount(); |
325 | } |
4e7ef6e6 |
326 | } |
327 | |
e91825f8 |
328 | /* |
329 | * See if we can find a help file. |
330 | */ |
331 | static void find_help_file(frontend *fe) |
332 | { |
333 | char b[2048], *p, *q, *r; |
334 | FILE *fp; |
335 | if (!fe->help_path) { |
336 | GetModuleFileName(NULL, b, sizeof(b) - 1); |
337 | r = b; |
338 | p = strrchr(b, '\\'); |
339 | if (p && p >= r) r = p+1; |
340 | q = strrchr(b, ':'); |
341 | if (q && q >= r) r = q+1; |
342 | strcpy(r, HELP_FILE_NAME); |
343 | if ( (fp = fopen(b, "r")) != NULL) { |
344 | fe->help_path = dupstr(b); |
345 | fclose(fp); |
346 | } else |
347 | fe->help_path = NULL; |
348 | strcpy(r, HELP_CNT_NAME); |
349 | if ( (fp = fopen(b, "r")) != NULL) { |
350 | fe->help_has_contents = TRUE; |
351 | fclose(fp); |
352 | } else |
353 | fe->help_has_contents = FALSE; |
354 | } |
355 | } |
356 | |
8b7938e7 |
357 | static frontend *new_window(HINSTANCE inst, char *game_id, char **error) |
4e7ef6e6 |
358 | { |
359 | frontend *fe; |
360 | int x, y; |
fd1a1a2b |
361 | RECT r, sr; |
4e7ef6e6 |
362 | HDC hdc; |
363 | |
364 | fe = snew(frontend); |
48d70ca9 |
365 | |
be8d5aa1 |
366 | fe->me = midend_new(fe, &thegame); |
48d70ca9 |
367 | |
8b7938e7 |
368 | if (game_id) { |
369 | *error = midend_game_id(fe->me, game_id, FALSE); |
370 | if (*error) { |
371 | midend_free(fe->me); |
372 | sfree(fe); |
373 | return NULL; |
374 | } |
375 | } |
376 | |
e91825f8 |
377 | fe->help_path = NULL; |
378 | find_help_file(fe); |
379 | |
077f3cbe |
380 | fe->inst = inst; |
5928817c |
381 | midend_new_game(fe->me); |
4e7ef6e6 |
382 | midend_size(fe->me, &x, &y); |
383 | |
384 | fe->timer = 0; |
385 | |
6beae131 |
386 | fe->fonts = NULL; |
387 | fe->nfonts = fe->fontsize = 0; |
388 | |
4e7ef6e6 |
389 | { |
390 | int i, ncolours; |
391 | float *colours; |
392 | |
393 | colours = midend_colours(fe->me, &ncolours); |
394 | |
395 | fe->colours = snewn(ncolours, COLORREF); |
396 | fe->brushes = snewn(ncolours, HBRUSH); |
397 | fe->pens = snewn(ncolours, HPEN); |
398 | |
399 | for (i = 0; i < ncolours; i++) { |
400 | fe->colours[i] = RGB(255 * colours[i*3+0], |
401 | 255 * colours[i*3+1], |
402 | 255 * colours[i*3+2]); |
403 | fe->brushes[i] = CreateSolidBrush(fe->colours[i]); |
4e7ef6e6 |
404 | fe->pens[i] = CreatePen(PS_SOLID, 1, fe->colours[i]); |
405 | } |
406 | } |
407 | |
408 | r.left = r.top = 0; |
409 | r.right = x; |
410 | r.bottom = y; |
411 | AdjustWindowRectEx(&r, WS_OVERLAPPEDWINDOW &~ |
412 | (WS_THICKFRAME | WS_MAXIMIZEBOX | WS_OVERLAPPED), |
eb2ad6f1 |
413 | TRUE, 0); |
4e7ef6e6 |
414 | |
be8d5aa1 |
415 | fe->hwnd = CreateWindowEx(0, thegame.name, thegame.name, |
4e7ef6e6 |
416 | WS_OVERLAPPEDWINDOW &~ |
417 | (WS_THICKFRAME | WS_MAXIMIZEBOX), |
418 | CW_USEDEFAULT, CW_USEDEFAULT, |
419 | r.right - r.left, r.bottom - r.top, |
420 | NULL, NULL, inst, NULL); |
421 | |
eb2ad6f1 |
422 | { |
423 | HMENU bar = CreateMenu(); |
424 | HMENU menu = CreateMenu(); |
425 | |
426 | AppendMenu(bar, MF_ENABLED|MF_POPUP, (UINT)menu, "Game"); |
427 | AppendMenu(menu, MF_ENABLED, IDM_NEW, "New"); |
428 | AppendMenu(menu, MF_ENABLED, IDM_RESTART, "Restart"); |
5928817c |
429 | AppendMenu(menu, MF_ENABLED, IDM_SEED, "Specific..."); |
eb2ad6f1 |
430 | |
077f3cbe |
431 | if ((fe->npresets = midend_num_presets(fe->me)) > 0 || |
be8d5aa1 |
432 | thegame.can_configure) { |
eb2ad6f1 |
433 | HMENU sub = CreateMenu(); |
434 | int i; |
435 | |
077f3cbe |
436 | AppendMenu(bar, MF_ENABLED|MF_POPUP, (UINT)sub, "Type"); |
eb2ad6f1 |
437 | |
438 | fe->presets = snewn(fe->npresets, game_params *); |
439 | |
440 | for (i = 0; i < fe->npresets; i++) { |
441 | char *name; |
442 | |
443 | midend_fetch_preset(fe->me, i, &name, &fe->presets[i]); |
444 | |
445 | /* |
446 | * FIXME: we ought to go through and do something |
447 | * with ampersands here. |
448 | */ |
449 | |
450 | AppendMenu(sub, MF_ENABLED, IDM_PRESETS + 0x10 * i, name); |
451 | } |
077f3cbe |
452 | |
be8d5aa1 |
453 | if (thegame.can_configure) { |
077f3cbe |
454 | AppendMenu(sub, MF_ENABLED, IDM_CONFIG, "Custom..."); |
455 | } |
eb2ad6f1 |
456 | } |
457 | |
458 | AppendMenu(menu, MF_SEPARATOR, 0, 0); |
459 | AppendMenu(menu, MF_ENABLED, IDM_UNDO, "Undo"); |
460 | AppendMenu(menu, MF_ENABLED, IDM_REDO, "Redo"); |
461 | AppendMenu(menu, MF_SEPARATOR, 0, 0); |
462 | AppendMenu(menu, MF_ENABLED, IDM_QUIT, "Exit"); |
e91825f8 |
463 | if (fe->help_path) { |
464 | HMENU hmenu = CreateMenu(); |
465 | AppendMenu(bar, MF_ENABLED|MF_POPUP, (UINT)hmenu, "Help"); |
466 | AppendMenu(hmenu, MF_ENABLED, IDM_HELPC, "Contents"); |
be8d5aa1 |
467 | if (thegame.winhelp_topic) { |
e91825f8 |
468 | char *item; |
be8d5aa1 |
469 | assert(thegame.name); |
470 | item = snewn(9+strlen(thegame.name), char); /*ick*/ |
471 | sprintf(item, "Help on %s", thegame.name); |
e91825f8 |
472 | AppendMenu(hmenu, MF_ENABLED, IDM_GAMEHELP, item); |
473 | sfree(item); |
474 | } |
475 | } |
eb2ad6f1 |
476 | SetMenu(fe->hwnd, bar); |
477 | } |
478 | |
fd1a1a2b |
479 | if (midend_wants_statusbar(fe->me)) { |
480 | fe->statusbar = CreateWindowEx(0, STATUSCLASSNAME, "ooh", |
481 | WS_CHILD | WS_VISIBLE, |
482 | 0, 0, 0, 0, /* status bar does these */ |
483 | fe->hwnd, NULL, inst, NULL); |
484 | GetWindowRect(fe->statusbar, &sr); |
485 | SetWindowPos(fe->hwnd, NULL, 0, 0, |
486 | r.right - r.left, r.bottom - r.top + sr.bottom - sr.top, |
487 | SWP_NOMOVE | SWP_NOZORDER); |
488 | SetWindowPos(fe->statusbar, NULL, 0, y, x, sr.bottom - sr.top, |
489 | SWP_NOZORDER); |
490 | } else { |
491 | fe->statusbar = NULL; |
492 | } |
493 | |
4e7ef6e6 |
494 | hdc = GetDC(fe->hwnd); |
495 | fe->bitmap = CreateCompatibleBitmap(hdc, x, y); |
496 | ReleaseDC(fe->hwnd, hdc); |
497 | |
498 | SetWindowLong(fe->hwnd, GWL_USERDATA, (LONG)fe); |
499 | |
500 | ShowWindow(fe->hwnd, SW_NORMAL); |
501 | SetForegroundWindow(fe->hwnd); |
502 | |
503 | midend_redraw(fe->me); |
504 | |
505 | return fe; |
506 | } |
507 | |
077f3cbe |
508 | static int CALLBACK ConfigDlgProc(HWND hwnd, UINT msg, |
509 | WPARAM wParam, LPARAM lParam) |
510 | { |
511 | frontend *fe = (frontend *)GetWindowLong(hwnd, GWL_USERDATA); |
512 | config_item *i; |
513 | struct cfg_aux *j; |
514 | |
515 | switch (msg) { |
516 | case WM_INITDIALOG: |
517 | return 0; |
518 | |
519 | case WM_COMMAND: |
520 | /* |
521 | * OK and Cancel are special cases. |
522 | */ |
523 | if ((HIWORD(wParam) == BN_CLICKED || |
524 | HIWORD(wParam) == BN_DOUBLECLICKED) && |
525 | (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)) { |
526 | if (LOWORD(wParam) == IDOK) { |
5928817c |
527 | char *err = midend_set_config(fe->me, fe->cfg_which, fe->cfg); |
077f3cbe |
528 | |
529 | if (err) { |
530 | MessageBox(hwnd, err, "Validation error", |
531 | MB_ICONERROR | MB_OK); |
532 | } else { |
533 | fe->cfg_done = 2; |
534 | } |
535 | } else { |
536 | fe->cfg_done = 1; |
537 | } |
538 | return 0; |
539 | } |
540 | |
541 | /* |
542 | * First find the control whose id this is. |
543 | */ |
544 | for (i = fe->cfg, j = fe->cfgaux; i->type != C_END; i++, j++) { |
545 | if (j->ctlid == LOWORD(wParam)) |
546 | break; |
547 | } |
548 | if (i->type == C_END) |
549 | return 0; /* not our problem */ |
550 | |
551 | if (i->type == C_STRING && HIWORD(wParam) == EN_CHANGE) { |
552 | char buffer[4096]; |
553 | GetDlgItemText(fe->cfgbox, j->ctlid, buffer, lenof(buffer)); |
554 | buffer[lenof(buffer)-1] = '\0'; |
555 | sfree(i->sval); |
556 | i->sval = dupstr(buffer); |
557 | } else if (i->type == C_BOOLEAN && |
558 | (HIWORD(wParam) == BN_CLICKED || |
559 | HIWORD(wParam) == BN_DOUBLECLICKED)) { |
560 | i->ival = IsDlgButtonChecked(fe->cfgbox, j->ctlid); |
561 | } else if (i->type == C_CHOICES && |
562 | HIWORD(wParam) == CBN_SELCHANGE) { |
563 | i->ival = SendDlgItemMessage(fe->cfgbox, j->ctlid, |
564 | CB_GETCURSEL, 0, 0); |
565 | } |
566 | |
567 | return 0; |
568 | |
569 | case WM_CLOSE: |
570 | fe->cfg_done = 1; |
571 | return 0; |
572 | } |
573 | |
574 | return 0; |
575 | } |
576 | |
577 | HWND mkctrl(frontend *fe, int x1, int x2, int y1, int y2, |
578 | char *wclass, int wstyle, |
579 | int exstyle, char *wtext, int wid) |
580 | { |
581 | HWND ret; |
582 | ret = CreateWindowEx(exstyle, wclass, wtext, |
583 | wstyle | WS_CHILD | WS_VISIBLE, x1, y1, x2-x1, y2-y1, |
584 | fe->cfgbox, (HMENU) wid, fe->inst, NULL); |
585 | SendMessage(ret, WM_SETFONT, (WPARAM)fe->cfgfont, MAKELPARAM(TRUE, 0)); |
586 | return ret; |
587 | } |
588 | |
5928817c |
589 | static int get_config(frontend *fe, int which) |
077f3cbe |
590 | { |
591 | config_item *i; |
592 | struct cfg_aux *j; |
5928817c |
593 | char *title; |
077f3cbe |
594 | WNDCLASS wc; |
595 | MSG msg; |
596 | TEXTMETRIC tm; |
597 | HDC hdc; |
598 | HFONT oldfont; |
599 | SIZE size; |
600 | HWND ctl; |
601 | int gm, id, nctrls; |
602 | int winwidth, winheight, col1l, col1r, col2l, col2r, y; |
603 | int height, width, maxlabel, maxcheckbox; |
604 | |
605 | wc.style = CS_DBLCLKS | CS_SAVEBITS | CS_BYTEALIGNWINDOW; |
606 | wc.lpfnWndProc = DefDlgProc; |
607 | wc.cbClsExtra = 0; |
608 | wc.cbWndExtra = DLGWINDOWEXTRA + 8; |
609 | wc.hInstance = fe->inst; |
610 | wc.hIcon = NULL; |
611 | wc.hCursor = LoadCursor(NULL, IDC_ARROW); |
612 | wc.hbrBackground = (HBRUSH) (COLOR_BACKGROUND +1); |
613 | wc.lpszMenuName = NULL; |
614 | wc.lpszClassName = "GameConfigBox"; |
615 | RegisterClass(&wc); |
616 | |
617 | hdc = GetDC(fe->hwnd); |
618 | SetMapMode(hdc, MM_TEXT); |
619 | |
620 | fe->cfg_done = FALSE; |
621 | |
622 | fe->cfgfont = CreateFont(-MulDiv(8, GetDeviceCaps(hdc, LOGPIXELSY), 72), |
623 | 0, 0, 0, 0, |
624 | FALSE, FALSE, FALSE, DEFAULT_CHARSET, |
625 | OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, |
626 | DEFAULT_QUALITY, |
627 | FF_SWISS, |
628 | "MS Shell Dlg"); |
629 | |
630 | oldfont = SelectObject(hdc, fe->cfgfont); |
631 | if (GetTextMetrics(hdc, &tm)) { |
632 | height = tm.tmAscent + tm.tmDescent; |
633 | width = tm.tmAveCharWidth; |
634 | } else { |
635 | height = width = 30; |
636 | } |
637 | |
5928817c |
638 | fe->cfg = midend_get_config(fe->me, which, &title); |
639 | fe->cfg_which = which; |
077f3cbe |
640 | |
641 | /* |
642 | * Figure out the layout of the config box by measuring the |
643 | * length of each piece of text. |
644 | */ |
645 | maxlabel = maxcheckbox = 0; |
646 | winheight = height/2; |
647 | |
648 | for (i = fe->cfg; i->type != C_END; i++) { |
649 | switch (i->type) { |
650 | case C_STRING: |
651 | case C_CHOICES: |
652 | /* |
653 | * Both these control types have a label filling only |
654 | * the left-hand column of the box. |
655 | */ |
656 | if (GetTextExtentPoint32(hdc, i->name, strlen(i->name), &size) && |
657 | maxlabel < size.cx) |
658 | maxlabel = size.cx; |
659 | winheight += height * 3 / 2 + (height / 2); |
660 | break; |
661 | |
662 | case C_BOOLEAN: |
663 | /* |
664 | * Checkboxes take up the whole of the box width. |
665 | */ |
666 | if (GetTextExtentPoint32(hdc, i->name, strlen(i->name), &size) && |
667 | maxcheckbox < size.cx) |
668 | maxcheckbox = size.cx; |
669 | winheight += height + (height / 2); |
670 | break; |
671 | } |
672 | } |
673 | |
674 | winheight += height + height * 7 / 4; /* OK / Cancel buttons */ |
675 | |
676 | col1l = 2*width; |
677 | col1r = col1l + maxlabel; |
678 | col2l = col1r + 2*width; |
679 | col2r = col2l + 30*width; |
680 | if (col2r < col1l+2*height+maxcheckbox) |
681 | col2r = col1l+2*height+maxcheckbox; |
682 | winwidth = col2r + 2*width; |
683 | |
684 | ReleaseDC(fe->hwnd, hdc); |
685 | |
686 | /* |
687 | * Create the dialog, now that we know its size. |
688 | */ |
689 | { |
690 | RECT r, r2; |
691 | |
692 | r.left = r.top = 0; |
693 | r.right = winwidth; |
694 | r.bottom = winheight; |
695 | |
696 | AdjustWindowRectEx(&r, (WS_OVERLAPPEDWINDOW /*| |
697 | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | |
698 | WS_CAPTION | WS_SYSMENU*/) &~ |
699 | (WS_MAXIMIZEBOX | WS_OVERLAPPED), |
700 | FALSE, 0); |
701 | |
702 | /* |
703 | * Centre the dialog on its parent window. |
704 | */ |
705 | r.right -= r.left; |
706 | r.bottom -= r.top; |
707 | GetWindowRect(fe->hwnd, &r2); |
708 | r.left = (r2.left + r2.right - r.right) / 2; |
709 | r.top = (r2.top + r2.bottom - r.bottom) / 2; |
710 | r.right += r.left; |
711 | r.bottom += r.top; |
712 | |
5928817c |
713 | fe->cfgbox = CreateWindowEx(0, wc.lpszClassName, title, |
077f3cbe |
714 | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | |
715 | WS_CAPTION | WS_SYSMENU, |
716 | r.left, r.top, |
717 | r.right-r.left, r.bottom-r.top, |
718 | fe->hwnd, NULL, fe->inst, NULL); |
5928817c |
719 | sfree(title); |
077f3cbe |
720 | } |
721 | |
722 | SendMessage(fe->cfgbox, WM_SETFONT, (WPARAM)fe->cfgfont, FALSE); |
723 | |
724 | SetWindowLong(fe->cfgbox, GWL_USERDATA, (LONG)fe); |
725 | SetWindowLong(fe->cfgbox, DWL_DLGPROC, (LONG)ConfigDlgProc); |
726 | |
727 | /* |
728 | * Count the controls so we can allocate cfgaux. |
729 | */ |
730 | for (nctrls = 0, i = fe->cfg; i->type != C_END; i++) |
731 | nctrls++; |
732 | fe->cfgaux = snewn(nctrls, struct cfg_aux); |
733 | |
734 | id = 1000; |
735 | y = height/2; |
736 | for (i = fe->cfg, j = fe->cfgaux; i->type != C_END; i++, j++) { |
737 | switch (i->type) { |
738 | case C_STRING: |
739 | /* |
740 | * Edit box with a label beside it. |
741 | */ |
742 | mkctrl(fe, col1l, col1r, y+height*1/8, y+height*9/8, |
743 | "Static", 0, 0, i->name, id++); |
744 | ctl = mkctrl(fe, col2l, col2r, y, y+height*3/2, |
745 | "EDIT", WS_TABSTOP | ES_AUTOHSCROLL, |
746 | WS_EX_CLIENTEDGE, "", (j->ctlid = id++)); |
747 | SetWindowText(ctl, i->sval); |
748 | y += height*3/2; |
749 | break; |
750 | |
751 | case C_BOOLEAN: |
752 | /* |
753 | * Simple checkbox. |
754 | */ |
755 | mkctrl(fe, col1l, col2r, y, y+height, "BUTTON", |
756 | BS_NOTIFY | BS_AUTOCHECKBOX | WS_TABSTOP, |
757 | 0, i->name, (j->ctlid = id++)); |
42132f2d |
758 | CheckDlgButton(fe->cfgbox, j->ctlid, (i->ival != 0)); |
077f3cbe |
759 | y += height; |
760 | break; |
761 | |
762 | case C_CHOICES: |
763 | /* |
764 | * Drop-down list with a label beside it. |
765 | */ |
766 | mkctrl(fe, col1l, col1r, y+height*1/8, y+height*9/8, |
767 | "STATIC", 0, 0, i->name, id++); |
768 | ctl = mkctrl(fe, col2l, col2r, y, y+height*41/2, |
769 | "COMBOBOX", WS_TABSTOP | |
770 | CBS_DROPDOWNLIST | CBS_HASSTRINGS, |
771 | WS_EX_CLIENTEDGE, "", (j->ctlid = id++)); |
772 | { |
773 | char c, *p, *q, *str; |
774 | |
775 | SendMessage(ctl, CB_RESETCONTENT, 0, 0); |
776 | p = i->sval; |
777 | c = *p++; |
778 | while (*p) { |
779 | q = p; |
780 | while (*q && *q != c) q++; |
781 | str = snewn(q-p+1, char); |
782 | strncpy(str, p, q-p); |
783 | str[q-p] = '\0'; |
784 | SendMessage(ctl, CB_ADDSTRING, 0, (LPARAM)str); |
785 | sfree(str); |
786 | if (*q) q++; |
787 | p = q; |
788 | } |
789 | } |
790 | |
791 | SendMessage(ctl, CB_SETCURSEL, i->ival, 0); |
792 | |
793 | y += height*3/2; |
794 | break; |
795 | } |
796 | |
797 | assert(y < winheight); |
798 | y += height/2; |
799 | } |
800 | |
801 | y += height/2; /* extra space before OK and Cancel */ |
802 | mkctrl(fe, col1l, (col1l+col2r)/2-width, y, y+height*7/4, "BUTTON", |
803 | BS_PUSHBUTTON | BS_NOTIFY | WS_TABSTOP | BS_DEFPUSHBUTTON, 0, |
804 | "OK", IDOK); |
805 | mkctrl(fe, (col1l+col2r)/2+width, col2r, y, y+height*7/4, "BUTTON", |
806 | BS_PUSHBUTTON | BS_NOTIFY | WS_TABSTOP, 0, "Cancel", IDCANCEL); |
807 | |
808 | SendMessage(fe->cfgbox, WM_INITDIALOG, 0, 0); |
809 | |
810 | EnableWindow(fe->hwnd, FALSE); |
811 | ShowWindow(fe->cfgbox, SW_NORMAL); |
812 | while ((gm=GetMessage(&msg, NULL, 0, 0)) > 0) { |
813 | if (!IsDialogMessage(fe->cfgbox, &msg)) |
814 | DispatchMessage(&msg); |
815 | if (fe->cfg_done) |
816 | break; |
817 | } |
818 | EnableWindow(fe->hwnd, TRUE); |
819 | SetForegroundWindow(fe->hwnd); |
820 | DestroyWindow(fe->cfgbox); |
821 | DeleteObject(fe->cfgfont); |
822 | |
823 | free_cfg(fe->cfg); |
824 | sfree(fe->cfgaux); |
825 | |
826 | return (fe->cfg_done == 2); |
827 | } |
828 | |
829 | static void new_game_type(frontend *fe) |
830 | { |
831 | RECT r, sr; |
832 | HDC hdc; |
833 | int x, y; |
834 | |
5928817c |
835 | midend_new_game(fe->me); |
077f3cbe |
836 | midend_size(fe->me, &x, &y); |
837 | |
838 | r.left = r.top = 0; |
839 | r.right = x; |
840 | r.bottom = y; |
841 | AdjustWindowRectEx(&r, WS_OVERLAPPEDWINDOW &~ |
842 | (WS_THICKFRAME | WS_MAXIMIZEBOX | |
843 | WS_OVERLAPPED), |
844 | TRUE, 0); |
845 | |
846 | if (fe->statusbar != NULL) { |
847 | GetWindowRect(fe->statusbar, &sr); |
848 | } else { |
849 | sr.left = sr.right = sr.top = sr.bottom = 0; |
850 | } |
851 | SetWindowPos(fe->hwnd, NULL, 0, 0, |
852 | r.right - r.left, |
853 | r.bottom - r.top + sr.bottom - sr.top, |
854 | SWP_NOMOVE | SWP_NOZORDER); |
855 | if (fe->statusbar != NULL) |
856 | SetWindowPos(fe->statusbar, NULL, 0, y, x, |
857 | sr.bottom - sr.top, SWP_NOZORDER); |
858 | |
859 | DeleteObject(fe->bitmap); |
860 | |
861 | hdc = GetDC(fe->hwnd); |
862 | fe->bitmap = CreateCompatibleBitmap(hdc, x, y); |
863 | ReleaseDC(fe->hwnd, hdc); |
864 | |
865 | midend_redraw(fe->me); |
866 | } |
867 | |
4e7ef6e6 |
868 | static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, |
869 | WPARAM wParam, LPARAM lParam) |
870 | { |
871 | frontend *fe = (frontend *)GetWindowLong(hwnd, GWL_USERDATA); |
872 | |
873 | switch (message) { |
874 | case WM_CLOSE: |
875 | DestroyWindow(hwnd); |
876 | return 0; |
eb2ad6f1 |
877 | case WM_COMMAND: |
878 | switch (wParam & ~0xF) { /* low 4 bits reserved to Windows */ |
879 | case IDM_NEW: |
880 | if (!midend_process_key(fe->me, 0, 0, 'n')) |
881 | PostQuitMessage(0); |
882 | break; |
883 | case IDM_RESTART: |
884 | if (!midend_process_key(fe->me, 0, 0, 'r')) |
885 | PostQuitMessage(0); |
886 | break; |
887 | case IDM_UNDO: |
888 | if (!midend_process_key(fe->me, 0, 0, 'u')) |
889 | PostQuitMessage(0); |
890 | break; |
891 | case IDM_REDO: |
892 | if (!midend_process_key(fe->me, 0, 0, '\x12')) |
893 | PostQuitMessage(0); |
894 | break; |
895 | case IDM_QUIT: |
896 | if (!midend_process_key(fe->me, 0, 0, 'q')) |
897 | PostQuitMessage(0); |
898 | break; |
077f3cbe |
899 | case IDM_CONFIG: |
5928817c |
900 | if (get_config(fe, CFG_SETTINGS)) |
901 | new_game_type(fe); |
902 | break; |
903 | case IDM_SEED: |
904 | if (get_config(fe, CFG_SEED)) |
077f3cbe |
905 | new_game_type(fe); |
906 | break; |
e91825f8 |
907 | case IDM_HELPC: |
908 | assert(fe->help_path); |
909 | WinHelp(hwnd, fe->help_path, |
910 | fe->help_has_contents ? HELP_FINDER : HELP_CONTENTS, 0); |
911 | break; |
912 | case IDM_GAMEHELP: |
913 | assert(fe->help_path); |
be8d5aa1 |
914 | assert(thegame.winhelp_topic); |
e91825f8 |
915 | { |
be8d5aa1 |
916 | char *cmd = snewn(10+strlen(thegame.winhelp_topic), char); |
917 | sprintf(cmd, "JI(`',`%s')", thegame.winhelp_topic); |
e91825f8 |
918 | WinHelp(hwnd, fe->help_path, HELP_COMMAND, (DWORD)cmd); |
919 | sfree(cmd); |
920 | } |
921 | break; |
eb2ad6f1 |
922 | default: |
923 | { |
924 | int p = ((wParam &~ 0xF) - IDM_PRESETS) / 0x10; |
925 | |
926 | if (p >= 0 && p < fe->npresets) { |
eb2ad6f1 |
927 | midend_set_params(fe->me, fe->presets[p]); |
077f3cbe |
928 | new_game_type(fe); |
eb2ad6f1 |
929 | } |
930 | } |
931 | break; |
932 | } |
933 | break; |
4e7ef6e6 |
934 | case WM_DESTROY: |
935 | PostQuitMessage(0); |
936 | return 0; |
937 | case WM_PAINT: |
938 | { |
939 | PAINTSTRUCT p; |
940 | HDC hdc, hdc2; |
941 | HBITMAP prevbm; |
942 | |
943 | hdc = BeginPaint(hwnd, &p); |
944 | hdc2 = CreateCompatibleDC(hdc); |
945 | prevbm = SelectObject(hdc2, fe->bitmap); |
946 | BitBlt(hdc, |
947 | p.rcPaint.left, p.rcPaint.top, |
948 | p.rcPaint.right - p.rcPaint.left, |
949 | p.rcPaint.bottom - p.rcPaint.top, |
950 | hdc2, |
951 | p.rcPaint.left, p.rcPaint.top, |
952 | SRCCOPY); |
953 | SelectObject(hdc2, prevbm); |
954 | DeleteDC(hdc2); |
955 | EndPaint(hwnd, &p); |
956 | } |
957 | return 0; |
958 | case WM_KEYDOWN: |
959 | { |
960 | int key = -1; |
961 | |
962 | switch (wParam) { |
963 | case VK_LEFT: key = CURSOR_LEFT; break; |
964 | case VK_RIGHT: key = CURSOR_RIGHT; break; |
965 | case VK_UP: key = CURSOR_UP; break; |
966 | case VK_DOWN: key = CURSOR_DOWN; break; |
c71454c0 |
967 | /* |
968 | * Diagonal keys on the numeric keypad. |
969 | */ |
970 | case VK_PRIOR: |
971 | if (!(lParam & 0x01000000)) key = CURSOR_UP_RIGHT; |
972 | break; |
973 | case VK_NEXT: |
974 | if (!(lParam & 0x01000000)) key = CURSOR_DOWN_RIGHT; |
975 | break; |
976 | case VK_HOME: |
977 | if (!(lParam & 0x01000000)) key = CURSOR_UP_LEFT; |
978 | break; |
979 | case VK_END: |
980 | if (!(lParam & 0x01000000)) key = CURSOR_DOWN_LEFT; |
981 | break; |
982 | /* |
983 | * Numeric keypad keys with Num Lock on. |
984 | */ |
985 | case VK_NUMPAD4: key = CURSOR_LEFT; break; |
986 | case VK_NUMPAD6: key = CURSOR_RIGHT; break; |
987 | case VK_NUMPAD8: key = CURSOR_UP; break; |
988 | case VK_NUMPAD2: key = CURSOR_DOWN; break; |
989 | case VK_NUMPAD9: key = CURSOR_UP_RIGHT; break; |
990 | case VK_NUMPAD3: key = CURSOR_DOWN_RIGHT; break; |
991 | case VK_NUMPAD7: key = CURSOR_UP_LEFT; break; |
992 | case VK_NUMPAD1: key = CURSOR_DOWN_LEFT; break; |
4e7ef6e6 |
993 | } |
994 | |
995 | if (key != -1) { |
eb2ad6f1 |
996 | if (!midend_process_key(fe->me, 0, 0, key)) |
4e7ef6e6 |
997 | PostQuitMessage(0); |
c71454c0 |
998 | } else { |
999 | MSG m; |
1000 | m.hwnd = hwnd; |
1001 | m.message = WM_KEYDOWN; |
1002 | m.wParam = wParam; |
1003 | m.lParam = lParam & 0xdfff; |
1004 | TranslateMessage(&m); |
4e7ef6e6 |
1005 | } |
1006 | } |
1007 | break; |
1008 | case WM_LBUTTONDOWN: |
1009 | case WM_RBUTTONDOWN: |
1010 | case WM_MBUTTONDOWN: |
b0f06719 |
1011 | { |
1012 | int button; |
1013 | |
1014 | /* |
1015 | * Shift-clicks count as middle-clicks, since otherwise |
1016 | * two-button Windows users won't have any kind of |
1017 | * middle click to use. |
1018 | */ |
1019 | if (message == WM_MBUTTONDOWN || (wParam & MK_SHIFT)) |
1020 | button = MIDDLE_BUTTON; |
1021 | else if (message == WM_LBUTTONDOWN) |
1022 | button = LEFT_BUTTON; |
1023 | else |
1024 | button = RIGHT_BUTTON; |
74a4e547 |
1025 | |
5dda68e8 |
1026 | if (!midend_process_key(fe->me, (signed short)LOWORD(lParam), |
1027 | (signed short)HIWORD(lParam), button)) |
74a4e547 |
1028 | PostQuitMessage(0); |
1029 | |
1030 | SetCapture(hwnd); |
1031 | } |
1032 | break; |
1033 | case WM_LBUTTONUP: |
1034 | case WM_RBUTTONUP: |
1035 | case WM_MBUTTONUP: |
1036 | { |
1037 | int button; |
1038 | |
1039 | /* |
1040 | * Shift-clicks count as middle-clicks, since otherwise |
1041 | * two-button Windows users won't have any kind of |
1042 | * middle click to use. |
1043 | */ |
1044 | if (message == WM_MBUTTONUP || (wParam & MK_SHIFT)) |
1045 | button = MIDDLE_RELEASE; |
1046 | else if (message == WM_LBUTTONUP) |
1047 | button = LEFT_RELEASE; |
1048 | else |
1049 | button = RIGHT_RELEASE; |
1050 | |
5dda68e8 |
1051 | if (!midend_process_key(fe->me, (signed short)LOWORD(lParam), |
1052 | (signed short)HIWORD(lParam), button)) |
74a4e547 |
1053 | PostQuitMessage(0); |
1054 | |
1055 | ReleaseCapture(); |
1056 | } |
1057 | break; |
1058 | case WM_MOUSEMOVE: |
1059 | { |
1060 | int button; |
1061 | |
1062 | if (wParam & (MK_MBUTTON | MK_SHIFT)) |
1063 | button = MIDDLE_DRAG; |
1064 | else if (wParam & MK_LBUTTON) |
1065 | button = LEFT_DRAG; |
1066 | else |
1067 | button = RIGHT_DRAG; |
1068 | |
5dda68e8 |
1069 | if (!midend_process_key(fe->me, (signed short)LOWORD(lParam), |
1070 | (signed short)HIWORD(lParam), button)) |
b0f06719 |
1071 | PostQuitMessage(0); |
1072 | } |
4e7ef6e6 |
1073 | break; |
1074 | case WM_CHAR: |
eb2ad6f1 |
1075 | if (!midend_process_key(fe->me, 0, 0, (unsigned char)wParam)) |
4e7ef6e6 |
1076 | PostQuitMessage(0); |
1077 | return 0; |
1078 | case WM_TIMER: |
8c1fd974 |
1079 | if (fe->timer) { |
1080 | DWORD now = GetTickCount(); |
1081 | float elapsed = (float) (now - fe->timer_last_tickcount) * 0.001F; |
1082 | midend_timer(fe->me, elapsed); |
1083 | fe->timer_last_tickcount = now; |
1084 | } |
4e7ef6e6 |
1085 | return 0; |
1086 | } |
1087 | |
1088 | return DefWindowProc(hwnd, message, wParam, lParam); |
1089 | } |
1090 | |
1091 | int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) |
1092 | { |
1093 | MSG msg; |
8b7938e7 |
1094 | char *error; |
4e7ef6e6 |
1095 | |
fd1a1a2b |
1096 | InitCommonControls(); |
1097 | |
4e7ef6e6 |
1098 | if (!prev) { |
1099 | WNDCLASS wndclass; |
1100 | |
1101 | wndclass.style = 0; |
1102 | wndclass.lpfnWndProc = WndProc; |
1103 | wndclass.cbClsExtra = 0; |
1104 | wndclass.cbWndExtra = 0; |
1105 | wndclass.hInstance = inst; |
1106 | wndclass.hIcon = LoadIcon(inst, IDI_APPLICATION); |
1107 | wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); |
1108 | wndclass.hbrBackground = NULL; |
1109 | wndclass.lpszMenuName = NULL; |
be8d5aa1 |
1110 | wndclass.lpszClassName = thegame.name; |
4e7ef6e6 |
1111 | |
1112 | RegisterClass(&wndclass); |
1113 | } |
1114 | |
8b7938e7 |
1115 | while (*cmdline && isspace(*cmdline)) |
1116 | cmdline++; |
1117 | |
1118 | if (!new_window(inst, *cmdline ? cmdline : NULL, &error)) { |
1119 | char buf[128]; |
be8d5aa1 |
1120 | sprintf(buf, "%.100s Error", thegame.name); |
8b7938e7 |
1121 | MessageBox(NULL, error, buf, MB_OK|MB_ICONERROR); |
1122 | return 1; |
1123 | } |
4e7ef6e6 |
1124 | |
1125 | while (GetMessage(&msg, NULL, 0, 0)) { |
4e7ef6e6 |
1126 | DispatchMessage(&msg); |
1127 | } |
1128 | |
1129 | return msg.wParam; |
1130 | } |