OSDN Git Service

833d5f9bc85e31901eedc027f57ee596e3371c50
[hengband/hengband.git] / src / main-win.c
1 /* File: main-win.c */
2
3 /*
4  * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
5  *
6  * This software may be copied and distributed for educational, research,
7  * and not for profit purposes provided that this copyright and statement
8  * are included in all such copies.
9  */
10
11
12 /*
13  * This file helps Angband work with Windows computers.
14  *
15  * To use this file, use an appropriate "Makefile" or "Project File",
16  * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
17  * make sure to obtain various extra files as described below.
18  *
19  * The official compilation uses the CodeWarrior Pro compiler, which
20  * includes a special project file and precompilable header file.
21  *
22  *
23  * See also "main-dos.c" and "main-ibm.c".
24  *
25  *
26  * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
27  * and/or color redefinitions.
28  *
29  * The "lib/user/font-win.prf" contains attr/char mappings for use with the
30  * normal "lib/xtra/font/*.fon" font files.
31  *
32  * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
33  * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
34  * item.
35  *
36  *
37  * Compiling this file, and using the resulting executable, requires
38  * several extra files not distributed with the standard Angband code.
39  * If "USE_GRAPHICS" is defined, then "readdib.h" and "readdib.c" must
40  * be placed into "src/", and the "8X8.BMP" bitmap file must be placed
41  * into "lib/xtra/graf".  In any case, some "*.fon" files (including
42  * "8X13.FON" if nothing else) must be placed into "lib/xtra/font/".
43  * If "USE_SOUND" is defined, then some special library (for example,
44  * "winmm.lib") may need to be linked in, and desired "*.WAV" sound
45  * files must be placed into "lib/xtra/sound/".  All of these extra
46  * files can be found in the "ext-win" archive.
47  *
48  *
49  * The "Term_xtra_win_clear()" function should probably do a low-level
50  * clear of the current window, and redraw the borders and other things,
51  * if only for efficiency.  XXX XXX XXX
52  *
53  * A simpler method is needed for selecting the "tile size" for windows.
54  * XXX XXX XXX
55  *
56  * The various "warning" messages assume the existance of the "screen.w"
57  * window, I think, and only a few calls actually check for its existance,
58  * this may be okay since "NULL" means "on top of all windows". (?)  The
59  * user must never be allowed to "hide" the main window, or the "menubar"
60  * will disappear.  XXX XXX XXX
61  *
62  * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
63  * use with the "winhelp.exe" program.  These files *may* be available
64  * at the ftp site somewhere, but I have not seen them.  XXX XXX XXX
65  *
66  *
67  * Initial framework (and most code) by Ben Harrison (benh@phial.com).
68  *
69  * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
70  *
71  * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
72  * and Chris R. Martin (crm7479@tam2000.tamu.edu).
73  */
74
75 #include "angband.h"
76
77
78 #ifdef WINDOWS
79
80 #include <direct.h>
81
82 /*
83  * Extract the "WIN32" flag from the compiler
84  */
85 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
86 # ifndef WIN32
87 #  define WIN32
88 # endif
89 #endif
90
91
92 /*
93  * Hack -- allow use of "screen saver" mode
94  */
95 #define USE_SAVER
96
97
98 /*
99  * Menu constants -- see "ANGBAND.RC"
100  */
101
102 #define IDM_FILE_NEW                    100
103 #define IDM_FILE_OPEN                   101
104 #define IDM_FILE_SAVE                   110
105 #define IDM_FILE_SCORE                  120
106 #define IDM_FILE_EXIT                   130
107
108 #define IDM_WINDOW_VIS_0                200
109 #define IDM_WINDOW_VIS_1                201
110 #define IDM_WINDOW_VIS_2                202
111 #define IDM_WINDOW_VIS_3                203
112 #define IDM_WINDOW_VIS_4                204
113 #define IDM_WINDOW_VIS_5                205
114 #define IDM_WINDOW_VIS_6                206
115 #define IDM_WINDOW_VIS_7                207
116
117 #define IDM_WINDOW_FONT_0               210
118 #define IDM_WINDOW_FONT_1               211
119 #define IDM_WINDOW_FONT_2               212
120 #define IDM_WINDOW_FONT_3               213
121 #define IDM_WINDOW_FONT_4               214
122 #define IDM_WINDOW_FONT_5               215
123 #define IDM_WINDOW_FONT_6               216
124 #define IDM_WINDOW_FONT_7               217
125
126 #define IDM_WINDOW_POS_0                220
127 #define IDM_WINDOW_POS_1                221
128 #define IDM_WINDOW_POS_2                222
129 #define IDM_WINDOW_POS_3                223
130 #define IDM_WINDOW_POS_4                224
131 #define IDM_WINDOW_POS_5                225
132 #define IDM_WINDOW_POS_6                226
133 #define IDM_WINDOW_POS_7                227
134
135 #define IDM_WINDOW_BIZ_0                230
136 #define IDM_WINDOW_BIZ_1                231
137 #define IDM_WINDOW_BIZ_2                232
138 #define IDM_WINDOW_BIZ_3                233
139 #define IDM_WINDOW_BIZ_4                234
140 #define IDM_WINDOW_BIZ_5                235
141 #define IDM_WINDOW_BIZ_6                236
142 #define IDM_WINDOW_BIZ_7                237
143
144 #define IDM_WINDOW_I_WID_0              240
145 #define IDM_WINDOW_I_WID_1              241
146 #define IDM_WINDOW_I_WID_2              242
147 #define IDM_WINDOW_I_WID_3              243
148 #define IDM_WINDOW_I_WID_4              244
149 #define IDM_WINDOW_I_WID_5              245
150 #define IDM_WINDOW_I_WID_6              246
151 #define IDM_WINDOW_I_WID_7              247
152
153 #define IDM_WINDOW_D_WID_0              250
154 #define IDM_WINDOW_D_WID_1              251
155 #define IDM_WINDOW_D_WID_2              252
156 #define IDM_WINDOW_D_WID_3              253
157 #define IDM_WINDOW_D_WID_4              254
158 #define IDM_WINDOW_D_WID_5              255
159 #define IDM_WINDOW_D_WID_6              256
160 #define IDM_WINDOW_D_WID_7              257
161
162 #define IDM_WINDOW_I_HGT_0              260
163 #define IDM_WINDOW_I_HGT_1              261
164 #define IDM_WINDOW_I_HGT_2              262
165 #define IDM_WINDOW_I_HGT_3              263
166 #define IDM_WINDOW_I_HGT_4              264
167 #define IDM_WINDOW_I_HGT_5              265
168 #define IDM_WINDOW_I_HGT_6              266
169 #define IDM_WINDOW_I_HGT_7              267
170
171 #define IDM_WINDOW_D_HGT_0              270
172 #define IDM_WINDOW_D_HGT_1              271
173 #define IDM_WINDOW_D_HGT_2              272
174 #define IDM_WINDOW_D_HGT_3              273
175 #define IDM_WINDOW_D_HGT_4              274
176 #define IDM_WINDOW_D_HGT_5              275
177 #define IDM_WINDOW_D_HGT_6              276
178 #define IDM_WINDOW_D_HGT_7              277
179
180 #define IDM_OPTIONS_NO_GRAPHICS  400
181 #define IDM_OPTIONS_OLD_GRAPHICS 401
182 #define IDM_OPTIONS_NEW_GRAPHICS 402
183 #define IDM_OPTIONS_BIGTILE             409
184 #define IDM_OPTIONS_SOUND               410
185 #define IDM_OPTIONS_SAVER               420
186 #define IDM_OPTIONS_MAP                 430
187 #define IDM_OPTIONS_BG                  440
188 #define IDM_OPTIONS_OPEN_BG             441
189
190 #define IDM_DUMP_SCREEN_HTML    450
191
192 #define IDM_HELP_CONTENTS       901
193
194
195
196 /*
197  * This may need to be removed for some compilers XXX XXX XXX
198  */
199 #define STRICT
200
201 /*
202  * Exclude parts of WINDOWS.H that are not needed
203  */
204 #define NOCOMM            /* Comm driver APIs and definitions */
205 #define NOLOGERROR        /* LogError() and related definitions */
206 #define NOPROFILER        /* Profiler APIs */
207 #define NOLFILEIO         /* _l* file I/O routines */
208 #define NOOPENFILE        /* OpenFile and related definitions */
209 #define NORESOURCE        /* Resource management */
210 #define NOATOM            /* Atom management */
211 #define NOLANGUAGE        /* Character test routines */
212 #define NOLSTRING         /* lstr* string management routines */
213 #define NODBCS            /* Double-byte character set routines */
214 #define NOKEYBOARDINFO    /* Keyboard driver routines */
215 #define NOCOLOR           /* COLOR_* color values */
216 #define NODRAWTEXT        /* DrawText() and related definitions */
217 #define NOSCALABLEFONT    /* Truetype scalable font support */
218 #define NOMETAFILE        /* Metafile support */
219 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
220 #define NODEFERWINDOWPOS  /* DeferWindowPos and related definitions */
221 #define NOKEYSTATES       /* MK_* message key state flags */
222 #define NOWH              /* SetWindowsHook and related WH_* definitions */
223 #define NOCLIPBOARD       /* Clipboard APIs and definitions */
224 #define NOICONS           /* IDI_* icon IDs */
225 #define NOMDI             /* MDI support */
226 #define NOHELP            /* Help support */
227
228 /* Not defined since it breaks Borland C++ 5.5 */
229 /* #define NOCTLMGR */    /* Control management and controls */
230
231 /*
232  * Exclude parts of WINDOWS.H that are not needed (Win32)
233  */
234 #define WIN32_LEAN_AND_MEAN
235 #define NONLS             /* All NLS defines and routines */
236 #define NOSERVICE         /* All Service Controller routines, SERVICE_ equates, etc. */
237 #define NOKANJI           /* Kanji support stuff. */
238 #define NOMCX             /* Modem Configuration Extensions */
239
240 /*
241  * Include the "windows" support file
242  */
243 #include <windows.h>
244
245 /*
246  * Exclude parts of MMSYSTEM.H that are not needed
247  */
248 #define MMNODRV          /* Installable driver support */
249 #define MMNOWAVE         /* Waveform support */
250 #define MMNOMIDI         /* MIDI support */
251 #define MMNOAUX          /* Auxiliary audio support */
252 #define MMNOTIMER        /* Timer support */
253 #define MMNOJOY          /* Joystick support */
254 #define MMNOMCI          /* MCI support */
255 #define MMNOMMIO         /* Multimedia file I/O support */
256 #define MMNOMMSYSTEM     /* General MMSYSTEM functions */
257
258 /*
259  * Include some more files. Note: the Cygnus Cygwin compiler
260  * doesn't use mmsystem.h instead it includes the winmm library
261  * which performs a similar function.
262  */
263 #include <mmsystem.h>
264 #include <commdlg.h>
265
266 /*
267  * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
268  * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
269  */
270 /* #define HTML_HELP */
271
272 #ifdef HTML_HELP
273 #include <htmlhelp.h>
274 #endif /* HTML_HELP */
275
276 /*
277  * Include the support for loading bitmaps
278  */
279 #ifdef USE_GRAPHICS
280 # include "readdib.h"
281 #endif
282
283 /*
284  * Hack -- Fake declarations from "dos.h" XXX XXX XXX
285  */
286 #ifdef WIN32
287 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
288 #else /* WIN32 */
289 #define FA_LABEL    0x08        /* Volume label */
290 #define FA_DIREC    0x10        /* Directory */
291 unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
292 #endif /* WIN32 */
293
294 /*
295  * Silliness in WIN32 drawing routine
296  */
297 #ifdef WIN32
298 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
299 #endif /* WIN32 */
300
301 /*
302  * Silliness for Windows 95
303  */
304 #ifndef WS_EX_TOOLWINDOW
305 # define WS_EX_TOOLWINDOW 0
306 #endif
307
308 /*
309  * Foreground color bits (hard-coded by DOS)
310  */
311 #define VID_BLACK       0x00
312 #define VID_BLUE        0x01
313 #define VID_GREEN       0x02
314 #define VID_CYAN        0x03
315 #define VID_RED         0x04
316 #define VID_MAGENTA     0x05
317 #define VID_YELLOW      0x06
318 #define VID_WHITE       0x07
319
320 /*
321  * Bright text (hard-coded by DOS)
322  */
323 #define VID_BRIGHT      0x08
324
325 /*
326  * Background color bits (hard-coded by DOS)
327  */
328 #define VUD_BLACK       0x00
329 #define VUD_BLUE        0x10
330 #define VUD_GREEN       0x20
331 #define VUD_CYAN        0x30
332 #define VUD_RED         0x40
333 #define VUD_MAGENTA     0x50
334 #define VUD_YELLOW      0x60
335 #define VUD_WHITE       0x70
336
337 /*
338  * Blinking text (hard-coded by DOS)
339  */
340 #define VUD_BRIGHT      0x80
341
342
343 /*
344  * Forward declare
345  */
346 typedef struct _term_data term_data;
347
348 /*
349  * Extra "term" data
350  *
351  * Note the use of "font_want" for the names of the font file requested by
352  * the user, and the use of "font_file" for the currently active font file.
353  *
354  * The "font_file" is uppercased, and takes the form "8X13.FON", while
355  * "font_want" can be in almost any form as long as it could be construed
356  * as attempting to represent the name of a font.
357  */
358 struct _term_data
359 {
360         term t;
361
362         cptr s;
363
364         HWND w;
365
366         DWORD dwStyle;
367         DWORD dwExStyle;
368
369         uint keys;
370
371         uint rows;      /* int -> uint */
372         uint cols;
373
374         uint pos_x;
375         uint pos_y;
376         uint size_wid;
377         uint size_hgt;
378         uint size_ow1;
379         uint size_oh1;
380         uint size_ow2;
381         uint size_oh2;
382
383         bool size_hack;
384
385         bool xtra_hack;
386
387         bool visible;
388
389         bool bizarre;
390
391         cptr font_want;
392
393         cptr font_file;
394
395         HFONT font_id;
396
397         uint font_wid;
398         uint font_hgt;
399
400         uint tile_wid;
401         uint tile_hgt;
402
403         uint map_tile_wid;
404         uint map_tile_hgt;
405
406         bool map_active;
407 #ifdef JP
408         LOGFONT lf;
409 #endif
410
411         bool posfix;
412
413 /* bg */
414 #if 0
415         char *bgfile;
416         int use_bg;
417 #endif
418 };
419
420
421 /*
422  * Maximum number of windows XXX XXX XXX
423  */
424 #define MAX_TERM_DATA 8
425
426 /*
427  * An array of term_data's
428  */
429 static term_data data[MAX_TERM_DATA];
430
431 /*
432  * Hack -- global "window creation" pointer
433  */
434 static term_data *my_td;
435
436 /*
437  * game in progress
438  */
439 bool game_in_progress = FALSE;
440
441 /*
442  * note when "open"/"new" become valid
443  */
444 bool initialized = FALSE;
445
446 /*
447  * screen paletted, i.e. 256 colors
448  */
449 bool paletted = FALSE;
450
451 /*
452  * 16 colors screen, don't use RGB()
453  */
454 bool colors16 = FALSE;
455
456 /*
457  * Saved instance handle
458  */
459 static HINSTANCE hInstance;
460
461 /*
462  * Yellow brush for the cursor
463  */
464 static HBRUSH hbrYellow;
465
466 /*
467  * An icon
468  */
469 static HICON hIcon;
470
471 /*
472  * A palette
473  */
474 static HPALETTE hPal;
475
476 /* bg */
477 static HBITMAP hBG = NULL;
478 static int use_bg = 0;
479 static char bg_bitmap_file[1024] = "bg.bmp";
480
481 #ifdef USE_SAVER
482
483 /*
484  * The screen saver window
485  */
486 static HWND hwndSaver;
487
488 #endif /* USE_SAVER */
489
490
491 #ifdef USE_GRAPHICS
492
493 /*
494  * Flag set once "graphics" has been initialized
495  */
496 static bool can_use_graphics = FALSE;
497
498 /*
499  * The global bitmap
500  */
501 static DIBINIT infGraph;
502
503 #ifdef USE_TRANSPARENCY
504
505 /*
506  * The global bitmap mask
507  */
508 static DIBINIT infMask;
509
510 #endif /* USE_TRANSPARENCY */
511
512 #endif /* USE_GRAPHICS */
513
514
515 #ifdef USE_SOUND
516
517 /*
518  * Flag set once "sound" has been initialized
519  */
520 static bool can_use_sound = FALSE;
521
522 #define SAMPLE_MAX 8
523
524 /*
525  * An array of sound file names
526  */
527 static cptr sound_file[SOUND_MAX][SAMPLE_MAX];
528
529 #endif /* USE_SOUND */
530
531
532 /*
533  * Full path to ANGBAND.INI
534  */
535 static cptr ini_file = NULL;
536
537 /*
538  * Name of application
539  */
540 static cptr AppName = "ANGBAND";
541
542 /*
543  * Name of sub-window type
544  */
545 static cptr AngList = "AngList";
546
547 /*
548  * Directory names
549  */
550 static cptr ANGBAND_DIR_XTRA_GRAF;
551 static cptr ANGBAND_DIR_XTRA_SOUND;
552 static cptr ANGBAND_DIR_XTRA_HELP;
553 #ifndef JP
554 static cptr ANGBAND_DIR_XTRA_FONT;
555 #endif
556 #ifdef USE_MUSIC
557 static cptr ANGBAND_DIR_XTRA_MUSIC;
558 #endif
559
560
561 /*
562  * The "complex" color values
563  */
564 static COLORREF win_clr[256];
565
566
567 /*
568  * The "simple" color values
569  *
570  * See "main-ibm.c" for original table information
571  *
572  * The entries below are taken from the "color bits" defined above.
573  *
574  * Note that many of the choices below suck, but so do crappy monitors.
575  */
576 static BYTE win_pal[256] =
577 {
578         VID_BLACK,                                      /* Dark */
579         VID_WHITE,                                      /* White */
580         VID_CYAN,                                       /* Slate XXX */
581         VID_RED | VID_BRIGHT,           /* Orange XXX */
582         VID_RED,                                        /* Red */
583         VID_GREEN,                                      /* Green */
584         VID_BLUE,                                       /* Blue */
585         VID_YELLOW,                                     /* Umber XXX */
586         VID_BLACK | VID_BRIGHT,         /* Light Dark */
587         VID_CYAN | VID_BRIGHT,          /* Light Slate XXX */
588         VID_MAGENTA,                            /* Violet XXX */
589         VID_YELLOW | VID_BRIGHT,        /* Yellow */
590         VID_MAGENTA | VID_BRIGHT,       /* Light Red XXX */
591         VID_GREEN | VID_BRIGHT,         /* Light Green */
592         VID_BLUE | VID_BRIGHT,          /* Light Blue */
593         VID_YELLOW                                      /* Light Umber XXX */
594 };
595
596
597 /*
598  * Hack -- define which keys are "special"
599  */
600 static bool special_key[256];
601 static bool ignore_key[256];
602
603 #if 1
604 /*
605  * Hack -- initialization list for "special_key"
606  */
607 static byte special_key_list[] = {
608 VK_CLEAR,VK_PAUSE,VK_CAPITAL,VK_KANA,VK_JUNJA,VK_FINAL,VK_KANJI,
609 VK_CONVERT,VK_NONCONVERT,VK_ACCEPT,VK_MODECHANGE,
610 VK_PRIOR,VK_NEXT,VK_END,VK_HOME,VK_LEFT,VK_UP,VK_RIGHT,VK_DOWN,
611 VK_SELECT,VK_PRINT,VK_EXECUTE,VK_SNAPSHOT,VK_INSERT,VK_DELETE,
612 VK_HELP,VK_APPS,
613 VK_F1,VK_F2,VK_F3,VK_F4,VK_F5,VK_F6,VK_F7,VK_F8,VK_F9,VK_F10,
614 VK_F11,VK_F12,VK_F13,VK_F14,VK_F15,VK_F16,VK_F17,VK_F18,VK_F19,VK_F20,
615 VK_F21,VK_F22,VK_F23,VK_F24,VK_NUMLOCK,VK_SCROLL,
616 VK_ATTN,VK_CRSEL,VK_EXSEL,VK_EREOF,VK_PLAY,VK_ZOOM,VK_NONAME,
617 VK_PA1,0
618 };
619
620 static byte ignore_key_list[] = {
621 VK_ESCAPE,VK_TAB,VK_SPACE,
622 'F','W','O','H', /* these are menu characters.*/
623 VK_SHIFT,VK_CONTROL,VK_MENU,VK_LWIN,VK_RWIN,
624 VK_LSHIFT,VK_RSHIFT,VK_LCONTROL,VK_RCONTROL,VK_LMENU,VK_RMENU,0
625 };
626
627 #else
628 /*
629  * Hack -- initialization list for "special_key"
630  *
631  * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
632  * and the normal keys (escape, tab, return, letters, numbers, etc), but we
633  * catch the keypad keys (with and without numlock set, including keypad 5),
634  * the function keys (including the "menu" key which maps to F10), and the
635  * "pause" key (between scroll lock and numlock).  We also catch a few odd
636  * keys which I do not recognize, but which are listed among keys which we
637  * do catch, so they should be harmless to catch.
638  */
639 static byte special_key_list[] =
640 {
641         VK_CLEAR,               /* 0x0C (KP<5>) */
642
643         VK_PAUSE,               /* 0x13 (pause) */
644
645         VK_PRIOR,               /* 0x21 (KP<9>) */
646         VK_NEXT,                /* 0x22 (KP<3>) */
647         VK_END,                 /* 0x23 (KP<1>) */
648         VK_HOME,                /* 0x24 (KP<7>) */
649         VK_LEFT,                /* 0x25 (KP<4>) */
650         VK_UP,                  /* 0x26 (KP<8>) */
651         VK_RIGHT,               /* 0x27 (KP<6>) */
652         VK_DOWN,                /* 0x28 (KP<2>) */
653         VK_SELECT,              /* 0x29 (?????) */
654         VK_PRINT,               /* 0x2A (?????) */
655         VK_EXECUTE,             /* 0x2B (?????) */
656         VK_SNAPSHOT,    /* 0x2C (?????) */
657         VK_INSERT,              /* 0x2D (KP<0>) */
658         VK_DELETE,              /* 0x2E (KP<.>) */
659         VK_HELP,                /* 0x2F (?????) */
660
661 #if 0
662         VK_NUMPAD0,             /* 0x60 (KP<0>) */
663         VK_NUMPAD1,             /* 0x61 (KP<1>) */
664         VK_NUMPAD2,             /* 0x62 (KP<2>) */
665         VK_NUMPAD3,             /* 0x63 (KP<3>) */
666         VK_NUMPAD4,             /* 0x64 (KP<4>) */
667         VK_NUMPAD5,             /* 0x65 (KP<5>) */
668         VK_NUMPAD6,             /* 0x66 (KP<6>) */
669         VK_NUMPAD7,             /* 0x67 (KP<7>) */
670         VK_NUMPAD8,             /* 0x68 (KP<8>) */
671         VK_NUMPAD9,             /* 0x69 (KP<9>) */
672         VK_MULTIPLY,    /* 0x6A (KP<*>) */
673         VK_ADD,                 /* 0x6B (KP<+>) */
674         VK_SEPARATOR,   /* 0x6C (?????) */
675         VK_SUBTRACT,    /* 0x6D (KP<->) */
676         VK_DECIMAL,             /* 0x6E (KP<.>) */
677         VK_DIVIDE,              /* 0x6F (KP</>) */
678 #endif
679
680         VK_F1,                  /* 0x70 */
681         VK_F2,                  /* 0x71 */
682         VK_F3,                  /* 0x72 */
683         VK_F4,                  /* 0x73 */
684         VK_F5,                  /* 0x74 */
685         VK_F6,                  /* 0x75 */
686         VK_F7,                  /* 0x76 */
687         VK_F8,                  /* 0x77 */
688         VK_F9,                  /* 0x78 */
689         VK_F10,                 /* 0x79 */
690         VK_F11,                 /* 0x7A */
691         VK_F12,                 /* 0x7B */
692         VK_F13,                 /* 0x7C */
693         VK_F14,                 /* 0x7D */
694         VK_F15,                 /* 0x7E */
695         VK_F16,                 /* 0x7F */
696         VK_F17,                 /* 0x80 */
697         VK_F18,                 /* 0x81 */
698         VK_F19,                 /* 0x82 */
699         VK_F20,                 /* 0x83 */
700         VK_F21,                 /* 0x84 */
701         VK_F22,                 /* 0x85 */
702         VK_F23,                 /* 0x86 */
703         VK_F24,                 /* 0x87 */
704
705         0
706 };
707 #endif
708
709 /* bg */
710 static void delete_bg(void)
711 {
712         if (hBG != NULL)
713         {
714                 DeleteObject(hBG);
715                 hBG = NULL;
716         }
717 }
718
719 static int init_bg(void)
720 {
721         char * bmfile = bg_bitmap_file;
722
723         delete_bg();
724         if (use_bg == 0) return 0;
725
726         hBG = LoadImage(NULL, bmfile,  IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
727         if (!hBG) {
728                 plog_fmt("ÊÉ»æÍѥӥåȥޥåנ'%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
729                 use_bg = 0;
730                 return 0;
731         }
732 #if 0 /* gomi */
733         HDC wnddc, dcimage, dcbg;
734         HBITMAP bmimage, bmimage_old, bmbg_old;
735         int i, j;
736
737         delete_bg();
738
739         wnddc = GetDC(hwnd);
740         dcimage = CreateCompatibleDC(wnddc);
741         dcbg = CreateCompatibleDC(wnddc);
742
743         bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
744         if (!bmimage) quit("bg.bmp¤¬Æɤߤ³¤á¤Ê¤¤¡ª");
745         bmimage_old = SelectObject(dcimage, bmimage);
746
747         CreateCompatibleBitmap();
748
749         ReleaseDC(hwnd, wnddc);
750 #endif
751         use_bg = 1;
752         return 1;
753 }
754
755 static void DrawBG(HDC hdc, RECT *r)
756 {
757         HDC hdcSrc;
758         HBITMAP hOld;
759         BITMAP bm;
760         int x = r->left, y = r->top;
761         int nx, ny, sx, sy, swid, shgt, cwid, chgt;
762         
763         if (!use_bg || !hBG)
764                 return;
765
766         nx = x; ny = y;
767         GetObject(hBG, sizeof(bm), &bm);
768         swid = bm.bmWidth; shgt = bm.bmHeight;
769
770         hdcSrc = CreateCompatibleDC(hdc);
771         hOld = SelectObject(hdcSrc, hBG);
772
773         do {
774                 sx = nx % swid;
775                 cwid = MIN(swid - sx, r->right - nx);
776                 do {
777                         sy = ny % shgt;
778                         chgt = MIN(shgt - sy, r->bottom - ny);
779                                 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
780                         ny += chgt;
781                 } while (ny < r->bottom);
782                 ny = y;
783                 nx += cwid;
784         } while (nx < r->right);
785         
786         SelectObject(hdcSrc, hOld);
787         DeleteDC(hdcSrc);
788 }
789
790 #if 0
791 /*
792  * Hack -- given a pathname, point at the filename
793  */
794 static cptr extract_file_name(cptr s)
795 {
796         cptr p;
797
798         /* Start at the end */
799         p = s + strlen(s) - 1;
800
801         /* Back up to divider */
802         while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
803
804         /* Return file name */
805         return (p+1);
806 }
807 #endif
808
809
810 /*
811  * Hack -- given a simple filename, extract the "font size" info
812  *
813  * Return a pointer to a static buffer holding the capitalized base name.
814  */
815 #ifndef JP
816 static char *analyze_font(char *path, int *wp, int *hp)
817 {
818         int wid, hgt;
819
820         char *s, *p;
821
822         /* Start at the end */
823         p = path + strlen(path) - 1;
824
825         /* Back up to divider */
826         while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
827
828         /* Advance to file name */
829         ++p;
830
831         /* Capitalize */
832         for (s = p; *s; ++s)
833         {
834                 /* Capitalize (be paranoid) */
835                 if (islower(*s)) *s = toupper(*s);
836         }
837
838         /* Find first 'X' */
839         s = strchr(p, 'X');
840
841         /* Extract font width */
842         wid = atoi(p);
843
844         /* Extract height */
845         hgt = s ? atoi(s+1) : 0;
846
847         /* Save results */
848         (*wp) = wid;
849         (*hp) = hgt;
850
851         /* Result */
852         return (p);
853 }
854 #endif
855
856
857 /*
858  * Check for existance of a file
859  */
860 static bool check_file(cptr s)
861 {
862         char path[1024];
863
864 #ifdef WIN32
865
866         DWORD attrib;
867
868 #else /* WIN32 */
869
870         unsigned int attrib;
871
872 #endif /* WIN32 */
873
874         /* Copy it */
875         strcpy(path, s);
876
877 #ifdef WIN32
878
879         /* Examine */
880         attrib = GetFileAttributes(path);
881
882         /* Require valid filename */
883         if (attrib == INVALID_FILE_NAME) return (FALSE);
884
885         /* Prohibit directory */
886         if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
887
888 #else /* WIN32 */
889
890         /* Examine and verify */
891         if (_dos_getfileattr(path, &attrib)) return (FALSE);
892
893         /* Prohibit something */
894         if (attrib & FA_LABEL) return (FALSE);
895
896         /* Prohibit directory */
897         if (attrib & FA_DIREC) return (FALSE);
898
899 #endif /* WIN32 */
900
901         /* Success */
902         return (TRUE);
903 }
904
905
906 /*
907  * Check for existance of a directory
908  */
909 static bool check_dir(cptr s)
910 {
911         int i;
912
913         char path[1024];
914
915 #ifdef WIN32
916
917         DWORD attrib;
918
919 #else /* WIN32 */
920
921         unsigned int attrib;
922
923 #endif /* WIN32 */
924
925         /* Copy it */
926         strcpy(path, s);
927
928         /* Check length */
929         i = strlen(path);
930
931         /* Remove trailing backslash */
932         if (i && (path[i-1] == '\\')) path[--i] = '\0';
933
934 #ifdef WIN32
935
936         /* Examine */
937         attrib = GetFileAttributes(path);
938
939         /* Require valid filename */
940         if (attrib == INVALID_FILE_NAME) return (FALSE);
941
942         /* Require directory */
943         if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
944
945 #else /* WIN32 */
946
947         /* Examine and verify */
948         if (_dos_getfileattr(path, &attrib)) return (FALSE);
949
950         /* Prohibit something */
951         if (attrib & FA_LABEL) return (FALSE);
952
953         /* Require directory */
954         if (!(attrib & FA_DIREC)) return (FALSE);
955
956 #endif /* WIN32 */
957
958         /* Success */
959         return (TRUE);
960 }
961
962
963 /*
964  * Validate a file
965  */
966 static void validate_file(cptr s)
967 {
968         /* Verify or fail */
969         if (!check_file(s))
970         {
971 #ifdef JP
972                 quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
973 #else
974                 quit_fmt("Cannot find required file:\n%s", s);
975 #endif
976
977         }
978 }
979
980
981 /*
982  * Validate a directory
983  */
984 static void validate_dir(cptr s, bool vital)
985 {
986         /* Verify or fail */
987         if (!check_dir(s))
988         {
989                 /* This directory contains needed data */
990                 if (vital)
991                 {
992 #ifdef JP
993                 quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
994 #else
995                         quit_fmt("Cannot find required directory:\n%s", s);
996 #endif
997
998                 }
999                 /* Attempt to create this directory */
1000                 else if (mkdir(s))
1001                 {
1002                         quit_fmt("Unable to create directory:\n%s", s);
1003                 }
1004         }
1005 }
1006
1007
1008 /*
1009  * Get the "size" for a window
1010  */
1011 static void term_getsize(term_data *td)
1012 {
1013         RECT rc;
1014
1015         int wid, hgt;
1016
1017         /* Paranoia */
1018         if (td->cols < 1) td->cols = 1;
1019         if (td->rows < 1) td->rows = 1;
1020
1021         /* Window sizes */
1022         wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1023         hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1024
1025         /* Fake window size */
1026         rc.left = 0;
1027         rc.right = rc.left + wid;
1028         rc.top = 0;
1029         rc.bottom = rc.top + hgt;
1030
1031         /* XXX XXX XXX */
1032         /* rc.right += 1; */
1033         /* rc.bottom += 1; */
1034
1035         /* Adjust */
1036         AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1037
1038         /* Total size */
1039         td->size_wid = rc.right - rc.left;
1040         td->size_hgt = rc.bottom - rc.top;
1041
1042         /* See CreateWindowEx */
1043         if (!td->w) return;
1044
1045         /* Extract actual location */
1046         GetWindowRect(td->w, &rc);
1047
1048         /* Save the location */
1049         td->pos_x = rc.left;
1050         td->pos_y = rc.top;
1051 }
1052
1053
1054 /*
1055  * Write the "prefs" for a single term
1056  */
1057 static void save_prefs_aux(term_data *td, cptr sec_name)
1058 {
1059         char buf[1024];
1060
1061         RECT rc;
1062
1063         /* Paranoia */
1064         if (!td->w) return;
1065
1066         /* Visible */
1067         strcpy(buf, td->visible ? "1" : "0");
1068         WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1069
1070         /* Font */
1071 #ifdef JP
1072         strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1073 #else
1074         strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1075 #endif
1076
1077         WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1078
1079 #ifdef JP
1080         wsprintf(buf, "%d", td->lf.lfWidth);
1081         WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1082         wsprintf(buf, "%d", td->lf.lfHeight);
1083         WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1084         wsprintf(buf, "%d", td->lf.lfWeight);
1085         WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1086 #endif
1087         /* Bizarre */
1088         strcpy(buf, td->bizarre ? "1" : "0");
1089         WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1090
1091         /* Tile size (x) */
1092         wsprintf(buf, "%d", td->tile_wid);
1093         WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1094
1095         /* Tile size (y) */
1096         wsprintf(buf, "%d", td->tile_hgt);
1097         WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1098
1099         /* Window size (x) */
1100         wsprintf(buf, "%d", td->cols);
1101         WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1102
1103         /* Window size (y) */
1104         wsprintf(buf, "%d", td->rows);
1105         WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1106
1107         /* Acquire position */
1108         GetWindowRect(td->w, &rc);
1109
1110         /* Window position (x) */
1111         wsprintf(buf, "%d", rc.left);
1112         WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1113
1114         /* Window position (y) */
1115         wsprintf(buf, "%d", rc.top);
1116         WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1117
1118         /* Window Z position */
1119         strcpy(buf, td->posfix ? "1" : "0");
1120         WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1121 }
1122
1123
1124 /*
1125  * Write the "prefs"
1126  *
1127  * We assume that the windows have all been initialized
1128  */
1129 static void save_prefs(void)
1130 {
1131         int i;
1132
1133         char buf[128];
1134
1135         /* Save the "arg_graphics" flag */
1136         sprintf(buf, "%d", arg_graphics);
1137         WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1138
1139         /* Save the "arg_bigtile" flag */
1140         strcpy(buf, arg_bigtile ? "1" : "0");
1141         WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1142
1143         /* Save the "arg_sound" flag */
1144         strcpy(buf, arg_sound ? "1" : "0");
1145         WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1146
1147         /* bg */
1148         strcpy(buf, use_bg ? "1" : "0");
1149         WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1150         WritePrivateProfileString("Angband", "BackGroundBitmap", 
1151                 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1152
1153         /* Save window prefs */
1154         for (i = 0; i < MAX_TERM_DATA; ++i)
1155         {
1156                 term_data *td = &data[i];
1157
1158                 sprintf(buf, "Term-%d", i);
1159
1160                 save_prefs_aux(td, buf);
1161         }
1162 }
1163
1164
1165 /*
1166  * Load the "prefs" for a single term
1167  */
1168 static void load_prefs_aux(term_data *td, cptr sec_name)
1169 {
1170         char tmp[1024];
1171
1172         int wid, hgt;
1173
1174         /* Visible */
1175         td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1176
1177         /* Desired font, with default */
1178 #ifdef JP
1179         GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1180 #else
1181         GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1182 #endif
1183
1184
1185         /* Bizarre */
1186         td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1187
1188         /* Analyze font, save desired font name */
1189 #ifdef JP
1190         td->font_want = string_make(tmp);
1191         hgt = 15; wid = 0;
1192         td->lf.lfWidth  = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1193         td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1194         td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1195 #else
1196         td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1197 #endif
1198
1199
1200         /* Tile size */
1201 #ifdef JP
1202         td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1203         td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1204 #else
1205         td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1206         td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1207 #endif
1208
1209
1210         /* Window size */
1211         td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1212         td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1213
1214         /* Window position */
1215         td->pos_x = GetPrivateProfileInt(sec_name, "PositionX", td->pos_x, ini_file);
1216         td->pos_y = GetPrivateProfileInt(sec_name, "PositionY", td->pos_y, ini_file);
1217
1218         /* Window Z position */
1219         td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1220 }
1221
1222
1223 /*
1224  * Load the "prefs"
1225  */
1226 static void load_prefs(void)
1227 {
1228         int i;
1229
1230         char buf[1024];
1231
1232         /* Extract the "arg_graphics" flag */
1233         arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1234
1235         /* Extract the "arg_bigtile" flag */
1236         arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1237         use_bigtile = arg_bigtile;
1238
1239         /* Extract the "arg_sound" flag */
1240         arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1241
1242         /* bg */
1243         use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1244         GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1245
1246         /* Load window prefs */
1247         for (i = 0; i < MAX_TERM_DATA; ++i)
1248         {
1249                 term_data *td = &data[i];
1250
1251                 sprintf(buf, "Term-%d", i);
1252
1253                 load_prefs_aux(td, buf);
1254         }
1255 }
1256
1257 #ifdef USE_SOUND
1258
1259 /*
1260  * XXX XXX XXX - Taken from files.c.
1261  *
1262  * Extract "tokens" from a buffer
1263  *
1264  * This function uses "whitespace" as delimiters, and treats any amount of
1265  * whitespace as a single delimiter.  We will never return any empty tokens.
1266  * When given an empty buffer, or a buffer containing only "whitespace", we
1267  * will return no tokens.  We will never extract more than "num" tokens.
1268  *
1269  * By running a token through the "text_to_ascii()" function, you can allow
1270  * that token to include (encoded) whitespace, using "\s" to encode spaces.
1271  *
1272  * We save pointers to the tokens in "tokens", and return the number found.
1273  */
1274 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1275 {
1276         int k = 0;
1277
1278         char *s = buf;
1279
1280
1281         /* Process */
1282         while (k < num)
1283         {
1284                 char *t;
1285
1286                 /* Skip leading whitespace */
1287                 for ( ; *s && isspace(*s); ++s) /* loop */;
1288
1289                 /* All done */
1290                 if (!*s) break;
1291
1292                 /* Find next whitespace, if any */
1293                 for (t = s; *t && !isspace(*t); ++t) /* loop */;
1294
1295                 /* Nuke and advance (if necessary) */
1296                 if (*t) *t++ = '\0';
1297
1298                 /* Save the token */
1299                 tokens[k++] = s;
1300
1301                 /* Advance */
1302                 s = t;
1303         }
1304
1305         /* Count */
1306         return (k);
1307 }
1308
1309 static void load_sound_prefs(void)
1310 {
1311         int i, j, num;
1312         char tmp[1024];
1313         char ini_path[1024];
1314         char wav_path[1024];
1315         char *zz[SAMPLE_MAX];
1316
1317         /* Access the sound.cfg */
1318         path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1319
1320         for (i = 0; i < SOUND_MAX; i++)
1321         {
1322                 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1323
1324                 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1325
1326                 for (j = 0; j < num; j++)
1327                 {
1328                         /* Access the sound */
1329                         path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1330
1331                         /* Save the sound filename, if it exists */
1332                         if (check_file(wav_path))
1333                                 sound_file[i][j] = string_make(zz[j]);
1334                 }
1335         }
1336 }
1337
1338 #endif /* USE_SOUND */
1339
1340 /*
1341  * Create the new global palette based on the bitmap palette
1342  * (if any), and the standard 16 entry palette derived from
1343  * "win_clr[]" which is used for the basic 16 Angband colors.
1344  *
1345  * This function is never called before all windows are ready.
1346  *
1347  * This function returns FALSE if the new palette could not be
1348  * prepared, which should normally be a fatal error.  XXX XXX
1349  *
1350  * Note that only some machines actually use a "palette".
1351  */
1352 static int new_palette(void)
1353 {
1354         HPALETTE hBmPal;
1355         HPALETTE hNewPal;
1356         HDC hdc;
1357         int i, nEntries;
1358         int pLogPalSize;
1359         int lppeSize;
1360         LPLOGPALETTE pLogPal;
1361         LPPALETTEENTRY lppe;
1362
1363         term_data *td;
1364
1365
1366         /* This makes no sense */
1367         if (!paletted) return (TRUE);
1368
1369
1370         /* No bitmap */
1371         lppeSize = 0;
1372         lppe = NULL;
1373         nEntries = 0;
1374
1375 #ifdef USE_GRAPHICS
1376
1377         /* Check the bitmap palette */
1378         hBmPal = infGraph.hPalette;
1379
1380         /* Use the bitmap */
1381         if (hBmPal)
1382         {
1383                 lppeSize = 256 * sizeof(PALETTEENTRY);
1384                 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1385                 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1386                 if ((nEntries == 0) || (nEntries > 220))
1387                 {
1388                         /* Warn the user */
1389 #ifdef JP
1390                         plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1391 #else
1392                         plog("Please switch to high- or true-color mode.");
1393 #endif
1394
1395
1396                         /* Cleanup */
1397                         rnfree(lppe, lppeSize);
1398
1399                         /* Fail */
1400                         return (FALSE);
1401                 }
1402         }
1403
1404 #endif /* USE_GRAPHICS */
1405
1406         /* Size of palette */
1407         pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1408
1409         /* Allocate palette */
1410         pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1411
1412         /* Version */
1413         pLogPal->palVersion = 0x300;
1414
1415         /* Make room for bitmap and normal data */
1416         pLogPal->palNumEntries = nEntries + 16;
1417
1418         /* Save the bitmap data */
1419         for (i = 0; i < nEntries; i++)
1420         {
1421                 pLogPal->palPalEntry[i] = lppe[i];
1422         }
1423
1424         /* Save the normal data */
1425         for (i = 0; i < 16; i++)
1426         {
1427                 LPPALETTEENTRY p;
1428
1429                 /* Access the entry */
1430                 p = &(pLogPal->palPalEntry[i+nEntries]);
1431
1432                 /* Save the colors */
1433                 p->peRed = GetRValue(win_clr[i]);
1434                 p->peGreen = GetGValue(win_clr[i]);
1435                 p->peBlue = GetBValue(win_clr[i]);
1436
1437                 /* Save the flags */
1438                 p->peFlags = PC_NOCOLLAPSE;
1439         }
1440
1441         /* Free something */
1442         if (lppe) rnfree(lppe, lppeSize);
1443
1444         /* Create a new palette, or fail */
1445         hNewPal = CreatePalette(pLogPal);
1446 #ifdef JP
1447         if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¡ª");
1448 #else
1449         if (!hNewPal) quit("Cannot create palette!");
1450 #endif
1451
1452
1453         /* Free the palette */
1454         rnfree(pLogPal, pLogPalSize);
1455
1456         /* Main window */
1457         td = &data[0];
1458
1459         /* Realize the palette */
1460         hdc = GetDC(td->w);
1461         SelectPalette(hdc, hNewPal, 0);
1462         i = RealizePalette(hdc);
1463         ReleaseDC(td->w, hdc);
1464 #ifdef JP
1465         if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤­¤Þ¤»¤ó¡ª");
1466 #else
1467         if (i == 0) quit("Cannot realize palette!");
1468 #endif
1469
1470
1471         /* Sub-windows */
1472         for (i = 1; i < MAX_TERM_DATA; i++)
1473         {
1474                 td = &data[i];
1475
1476                 hdc = GetDC(td->w);
1477                 SelectPalette(hdc, hNewPal, 0);
1478                 ReleaseDC(td->w, hdc);
1479         }
1480
1481         /* Delete old palette */
1482         if (hPal) DeleteObject(hPal);
1483
1484         /* Save new palette */
1485         hPal = hNewPal;
1486
1487         /* Success */
1488         return (TRUE);
1489 }
1490
1491
1492 #ifdef USE_GRAPHICS
1493 /*
1494  * Initialize graphics
1495  */
1496 static bool init_graphics(void)
1497 {
1498         /* Initialize once */
1499         /* if (can_use_graphics != arg_graphics) */
1500         {
1501                 char buf[1024];
1502                 int wid, hgt;
1503                 cptr name;
1504
1505                 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1506                 {
1507                         wid = 16;
1508                         hgt = 16;
1509
1510                         name = "16X16.BMP";
1511
1512                         ANGBAND_GRAF = "new";
1513                 }
1514                 else
1515                 {
1516                         wid = 8;
1517                         hgt = 8;
1518
1519                         name = "8X8.BMP";
1520                         ANGBAND_GRAF = "old";
1521                 }
1522
1523                 /* Access the bitmap file */
1524                 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1525
1526                 /* Load the bitmap or quit */
1527                 if (!ReadDIB(data[0].w, buf, &infGraph))
1528                 {
1529 #ifdef JP
1530                         plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1531 #else
1532                         plog_fmt("Cannot read bitmap file '%s'", name);
1533 #endif
1534
1535                         return (FALSE);
1536                 }
1537
1538                 /* Save the new sizes */
1539                 infGraph.CellWidth = wid;
1540                 infGraph.CellHeight = hgt;
1541
1542 #ifdef USE_TRANSPARENCY
1543
1544                 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1545                 {
1546                         /* Access the mask file */
1547                         path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1548
1549                         /* Load the bitmap or quit */
1550                         if (!ReadDIB(data[0].w, buf, &infMask))
1551                         {
1552                                 plog_fmt("Cannot read bitmap file '%s'", buf);
1553                                 return (FALSE);
1554                         }
1555                 }
1556
1557 #endif /* USE_TRANSPARENCY */
1558
1559                 /* Activate a palette */
1560                 if (!new_palette())
1561                 {
1562                         /* Free bitmap XXX XXX XXX */
1563
1564                         /* Oops */
1565 #ifdef JP
1566                         plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤­¤Þ¤»¤ó¡ª");
1567 #else
1568                         plog("Cannot activate palette!");
1569 #endif
1570
1571                         return (FALSE);
1572                 }
1573
1574                 /* Graphics available */
1575                 can_use_graphics = arg_graphics;
1576         }
1577
1578         /* Result */
1579         return (can_use_graphics);
1580 }
1581 #endif /* USE_GRAPHICS */
1582
1583
1584 #ifdef USE_SOUND
1585 /*
1586  * Initialize sound
1587  */
1588 static bool init_sound(void)
1589 {
1590         /* Initialize once */
1591         if (!can_use_sound)
1592         {
1593                 /* Load the prefs */
1594                 load_sound_prefs();
1595
1596                 /* Sound available */
1597                 can_use_sound = TRUE;
1598         }
1599
1600         /* Result */
1601         return (can_use_sound);
1602 }
1603 #endif /* USE_SOUND */
1604
1605
1606 /*
1607  * Resize a window
1608  */
1609 static void term_window_resize(term_data *td)
1610 {
1611         /* Require window */
1612         if (!td->w) return;
1613
1614         /* Resize the window */
1615         SetWindowPos(td->w, 0, 0, 0,
1616                      td->size_wid, td->size_hgt,
1617                      SWP_NOMOVE | SWP_NOZORDER);
1618
1619         /* Redraw later */
1620         InvalidateRect(td->w, NULL, TRUE);
1621 }
1622
1623
1624 /*
1625  * Force the use of a new "font file" for a term_data
1626  *
1627  * This function may be called before the "window" is ready
1628  *
1629  * This function returns zero only if everything succeeds.
1630  *
1631  * Note that the "font name" must be capitalized!!!
1632  */
1633 static errr term_force_font(term_data *td, cptr path)
1634 {
1635         int wid, hgt;
1636
1637 #ifndef JP
1638         int i;
1639         char *base;
1640         char buf[1024];
1641 #endif
1642
1643         /* Forget the old font (if needed) */
1644         if (td->font_id) DeleteObject(td->font_id);
1645
1646 #ifndef JP
1647         /* Forget old font */
1648         if (td->font_file)
1649         {
1650                 bool used = FALSE;
1651
1652                 /* Scan windows */
1653                 for (i = 0; i < MAX_TERM_DATA; i++)
1654                 {
1655                         /* Don't check when closing the application */
1656                         if (!path) break;
1657
1658                         /* Check "screen" */
1659                         if ((td != &data[i]) &&
1660                             (data[i].font_file) &&
1661                             (streq(data[i].font_file, td->font_file)))
1662                         {
1663                                 used = TRUE;
1664                         }
1665                 }
1666
1667                 /* Remove unused font resources */
1668                 if (!used) RemoveFontResource(td->font_file);
1669
1670                 /* Free the old name */
1671                 string_free(td->font_file);
1672
1673                 /* Forget it */
1674                 td->font_file = NULL;
1675         }
1676
1677
1678         /* No path given */
1679         if (!path) return (1);
1680
1681
1682         /* Local copy */
1683         strcpy(buf, path);
1684
1685         /* Analyze font path */
1686         base = analyze_font(buf, &wid, &hgt);
1687
1688         /* Verify suffix */
1689         if (!suffix(base, ".FON")) return (1);
1690
1691         /* Verify file */
1692         if (!check_file(buf)) return (1);
1693
1694         /* Load the new font */
1695         if (!AddFontResource(buf)) return (1);
1696
1697         /* Save new font name */
1698         td->font_file = string_make(base);
1699
1700         /* Remove the "suffix" */
1701         base[strlen(base)-4] = '\0';
1702 #endif
1703
1704         /* Create the font (using the 'base' of the font file name!) */
1705 #ifdef JP
1706         td->font_id = CreateFontIndirect(&(td->lf));
1707         wid = td->lf.lfWidth;
1708         hgt = td->lf.lfHeight;
1709         if (!td->font_id) return (1);
1710 #else
1711         td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1712                                  ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1713                                  CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1714                                  FIXED_PITCH | FF_DONTCARE, base);
1715 #endif
1716
1717
1718         /* Hack -- Unknown size */
1719         if (!wid || !hgt)
1720         {
1721                 HDC hdcDesktop;
1722                 HFONT hfOld;
1723                 TEXTMETRIC tm;
1724
1725                 /* all this trouble to get the cell size */
1726                 hdcDesktop = GetDC(HWND_DESKTOP);
1727                 hfOld = SelectObject(hdcDesktop, td->font_id);
1728                 GetTextMetrics(hdcDesktop, &tm);
1729                 SelectObject(hdcDesktop, hfOld);
1730                 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1731
1732                 /* Font size info */
1733                 wid = tm.tmAveCharWidth;
1734                 hgt = tm.tmHeight;
1735         }
1736
1737         /* Save the size info */
1738         td->font_wid = wid;
1739         td->font_hgt = hgt;
1740
1741         /* Success */
1742         return (0);
1743 }
1744
1745
1746
1747 /*
1748  * Allow the user to change the font for this window.
1749  */
1750 static void term_change_font(term_data *td)
1751 {
1752 #ifdef JP
1753         CHOOSEFONT cf;
1754
1755         memset(&cf, 0, sizeof(cf));
1756         cf.lStructSize = sizeof(cf);
1757     cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1758     cf.lpLogFont = &(td->lf);
1759
1760         if (ChooseFont(&cf))
1761         {
1762                 /* Force the font */
1763                 term_force_font(td, NULL);
1764
1765                 /* Assume not bizarre */
1766                 td->bizarre = TRUE;
1767
1768                 /* Reset the tile info */
1769                 td->tile_wid = td->font_wid;
1770                 td->tile_hgt = td->font_hgt;
1771
1772                 /* Analyze the font */
1773                 term_getsize(td);
1774
1775                 /* Resize the window */
1776                 term_window_resize(td);
1777         }
1778
1779 #else
1780         OPENFILENAME ofn;
1781
1782         char tmp[1024] = "";
1783
1784         /* Extract a default if possible */
1785         if (td->font_file) strcpy(tmp, td->font_file);
1786
1787         /* Ask for a choice */
1788         memset(&ofn, 0, sizeof(ofn));
1789         ofn.lStructSize = sizeof(ofn);
1790         ofn.hwndOwner = data[0].w;
1791         ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1792         ofn.nFilterIndex = 1;
1793         ofn.lpstrFile = tmp;
1794         ofn.nMaxFile = 128;
1795         ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1796         ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1797         ofn.lpstrDefExt = "fon";
1798
1799         /* Force choice if legal */
1800         if (GetOpenFileName(&ofn))
1801         {
1802                 /* Force the font */
1803                 if (term_force_font(td, tmp))
1804                 {
1805                         /* Access the standard font file */
1806                         path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1807
1808                         /* Force the use of that font */
1809                         (void)term_force_font(td, tmp);
1810                 }
1811
1812                 /* Assume not bizarre */
1813                 td->bizarre = FALSE;
1814
1815                 /* Reset the tile info */
1816                 td->tile_wid = td->font_wid;
1817                 td->tile_hgt = td->font_hgt;
1818
1819                 /* Analyze the font */
1820                 term_getsize(td);
1821
1822                 /* Resize the window */
1823                 term_window_resize(td);
1824         }
1825 #endif
1826
1827 }
1828
1829 /*
1830  * Allow the user to lock this window.
1831  */
1832 static void term_window_pos(term_data *td, HWND hWnd)
1833 {
1834         SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1835                         SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1836 }
1837
1838 static void windows_map(void);
1839
1840 /*
1841  * Hack -- redraw a term_data
1842  */
1843 static void term_data_redraw(term_data *td)
1844 {
1845         if (td->map_active)
1846         {
1847                 /* Redraw the map */
1848                 windows_map();
1849         }
1850         else
1851         {
1852                 /* Activate the term */
1853                 Term_activate(&td->t);
1854
1855                 /* Redraw the contents */
1856                 Term_redraw();
1857
1858                 /* Restore the term */
1859                 Term_activate(term_screen);
1860         }
1861 }
1862
1863
1864
1865
1866
1867 /*** Function hooks needed by "Term" ***/
1868
1869
1870 #if 0
1871
1872 /*
1873  * Initialize a new Term
1874  */
1875 static void Term_init_win(term *t)
1876 {
1877         /* XXX Unused */
1878 }
1879
1880
1881 /*
1882  * Nuke an old Term
1883  */
1884 static void Term_nuke_win(term *t)
1885 {
1886         /* XXX Unused */
1887 }
1888
1889 #endif
1890
1891
1892 /*
1893  * Interact with the User
1894  */
1895 static errr Term_user_win(int n)
1896 {
1897         /* Success */
1898         return (0);
1899 }
1900
1901
1902 /*
1903  * React to global changes
1904  */
1905 static errr Term_xtra_win_react(void)
1906 {
1907         int i;
1908
1909
1910         /* Simple color */
1911         if (colors16)
1912         {
1913                 /* Save the default colors */
1914                 for (i = 0; i < 256; i++)
1915                 {
1916                         /* Simply accept the desired colors */
1917                         win_pal[i] = angband_color_table[i][0];
1918                 }
1919         }
1920
1921         /* Complex color */
1922         else
1923         {
1924                 COLORREF code;
1925
1926                 byte rv, gv, bv;
1927
1928                 bool change = FALSE;
1929
1930                 /* Save the default colors */
1931                 for (i = 0; i < 256; i++)
1932                 {
1933                         /* Extract desired values */
1934                         rv = angband_color_table[i][1];
1935                         gv = angband_color_table[i][2];
1936                         bv = angband_color_table[i][3];
1937
1938                         /* Extract a full color code */
1939                         code = PALETTERGB(rv, gv, bv);
1940
1941                         /* Activate changes */
1942                         if (win_clr[i] != code)
1943                         {
1944                                 /* Note the change */
1945                                 change = TRUE;
1946
1947                                 /* Apply the desired color */
1948                                 win_clr[i] = code;
1949                         }
1950                 }
1951
1952                 /* Activate the palette if needed */
1953                 if (change) (void)new_palette();
1954         }
1955
1956
1957 #ifdef USE_SOUND
1958
1959         /* Handle "arg_sound" */
1960         if (use_sound != arg_sound)
1961         {
1962                 /* Initialize (if needed) */
1963                 if (arg_sound && !init_sound())
1964                 {
1965                         /* Warning */
1966 #ifdef JP
1967                         plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤­¤Þ¤»¤ó¡ª");
1968 #else
1969                         plog("Cannot initialize sound!");
1970 #endif
1971
1972
1973                         /* Cannot enable */
1974                         arg_sound = FALSE;
1975                 }
1976
1977                 /* Change setting */
1978                 use_sound = arg_sound;
1979         }
1980
1981 #endif
1982
1983
1984 #ifdef USE_GRAPHICS
1985
1986         /* Handle "arg_graphics" */
1987         if (use_graphics != arg_graphics)
1988         {
1989                 /* Initialize (if needed) */
1990                 if (arg_graphics && !init_graphics())
1991                 {
1992                         /* Warning */
1993 #ifdef JP
1994                         plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤­¤Þ¤»¤ó!");
1995 #else
1996                         plog("Cannot initialize graphics!");
1997 #endif
1998
1999
2000                         /* Cannot enable */
2001                         arg_graphics = GRAPHICS_NONE;
2002                 }
2003
2004                 /* Change setting */
2005                 use_graphics = arg_graphics;
2006
2007                 /* Reset visuals */
2008 #ifdef ANGBAND_2_8_1
2009                 reset_visuals();
2010 #else /* ANGBAND_2_8_1 */
2011                 reset_visuals(TRUE);
2012 #endif /* ANGBAND_2_8_1 */
2013         }
2014
2015 #endif /* USE_GRAPHICS */
2016
2017
2018         /* Clean up windows */
2019         for (i = 0; i < MAX_TERM_DATA; i++)
2020         {
2021                 term *old = Term;
2022
2023                 term_data *td = &data[i];
2024
2025                 /* Update resized windows */
2026                 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2027                 {
2028                         /* Activate */
2029                         Term_activate(&td->t);
2030
2031                         /* Hack -- Resize the term */
2032                         Term_resize(td->cols, td->rows);
2033
2034                         /* Redraw the contents */
2035                         Term_redraw();
2036
2037                         /* Restore */
2038                         Term_activate(old);
2039                 }
2040         }
2041
2042
2043         /* Success */
2044         return (0);
2045 }
2046
2047
2048 /*
2049  * Process at least one event
2050  */
2051 static errr Term_xtra_win_event(int v)
2052 {
2053         MSG msg;
2054
2055         /* Wait for an event */
2056         if (v)
2057         {
2058                 /* Block */
2059                 if (GetMessage(&msg, NULL, 0, 0))
2060                 {
2061                         TranslateMessage(&msg);
2062                         DispatchMessage(&msg);
2063                 }
2064         }
2065
2066         /* Check for an event */
2067         else
2068         {
2069                 /* Check */
2070                 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2071                 {
2072                         TranslateMessage(&msg);
2073                         DispatchMessage(&msg);
2074                 }
2075         }
2076
2077         /* Success */
2078         return 0;
2079 }
2080
2081
2082 /*
2083  * Process all pending events
2084  */
2085 static errr Term_xtra_win_flush(void)
2086 {
2087         MSG msg;
2088
2089         /* Process all pending events */
2090         while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2091         {
2092                 TranslateMessage(&msg);
2093                 DispatchMessage(&msg);
2094         }
2095
2096         /* Success */
2097         return (0);
2098 }
2099
2100
2101 /*
2102  * Hack -- clear the screen
2103  *
2104  * Make this more efficient XXX XXX XXX
2105  */
2106 static errr Term_xtra_win_clear(void)
2107 {
2108         term_data *td = (term_data*)(Term->data);
2109
2110         HDC hdc;
2111         RECT rc;
2112
2113         /* Rectangle to erase */
2114         rc.left = td->size_ow1;
2115         rc.right = rc.left + td->cols * td->tile_wid;
2116         rc.top = td->size_oh1;
2117         rc.bottom = rc.top + td->rows * td->tile_hgt;
2118
2119         /* Erase it */
2120         hdc = GetDC(td->w);
2121         SetBkColor(hdc, RGB(0, 0, 0));
2122         SelectObject(hdc, td->font_id);
2123         ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2124
2125         /* bg */
2126         if (use_bg)
2127         {
2128                 rc.left = 0; rc.top = 0;
2129                 DrawBG(hdc, &rc);
2130         }
2131         ReleaseDC(td->w, hdc);
2132
2133         /* Success */
2134         return 0;
2135 }
2136
2137
2138 /*
2139  * Hack -- make a noise
2140  */
2141 static errr Term_xtra_win_noise(void)
2142 {
2143         MessageBeep(MB_ICONASTERISK);
2144         return (0);
2145 }
2146
2147
2148 /*
2149  * Hack -- make a sound
2150  */
2151 static errr Term_xtra_win_sound(int v)
2152 {
2153 #ifdef USE_SOUND
2154         int i;
2155         char buf[1024];
2156 #endif /* USE_SOUND */
2157
2158         /* Sound disabled */
2159         if (!use_sound) return (1);
2160
2161         /* Illegal sound */
2162         if ((v < 0) || (v >= SOUND_MAX)) return (1);
2163
2164 #ifdef USE_SOUND
2165
2166         /* Count the samples */
2167         for (i = 0; i < SAMPLE_MAX; i++)
2168         {
2169                 if (!sound_file[v][i])
2170                         break;
2171         }
2172
2173         /* No sample */
2174         if (i == 0) return (1);
2175
2176         /* Build the path */
2177         path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_simple(i)]);
2178
2179 #ifdef WIN32
2180
2181         /* Play the sound, catch errors */
2182         return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2183
2184 #else /* WIN32 */
2185
2186         /* Play the sound, catch errors */
2187         return (sndPlaySound(buf, SND_ASYNC));
2188
2189 #endif /* WIN32 */
2190
2191 #else /* USE_SOUND */
2192
2193         /* Oops */
2194         return (1);
2195
2196 #endif /* USE_SOUND */
2197 }
2198
2199
2200 /*
2201  * Delay for "x" milliseconds
2202  */
2203 static int Term_xtra_win_delay(int v)
2204 {
2205
2206 #ifdef WIN32
2207
2208         /* Sleep */
2209         Sleep(v);
2210
2211 #else /* WIN32 */
2212
2213         DWORD t;
2214         MSG msg;
2215
2216         /* Final count */
2217         t = GetTickCount() + v;
2218
2219         /* Wait for it */
2220         while (GetTickCount() < t)
2221         {
2222                 /* Handle messages */
2223                 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2224                 {
2225                         TranslateMessage(&msg);
2226                         DispatchMessage(&msg);
2227                 }
2228         }
2229
2230 #endif /* WIN32 */
2231
2232         /* Success */
2233         return (0);
2234 }
2235
2236
2237 /*
2238  * Do a "special thing"
2239  */
2240 static errr Term_xtra_win(int n, int v)
2241 {
2242         /* Handle a subset of the legal requests */
2243         switch (n)
2244         {
2245                 /* Make a bell sound */
2246                 case TERM_XTRA_NOISE:
2247                 {
2248                         return (Term_xtra_win_noise());
2249                 }
2250
2251                 /* Make a special sound */
2252                 case TERM_XTRA_SOUND:
2253                 {
2254                         return (Term_xtra_win_sound(v));
2255                 }
2256
2257                 /* Process random events */
2258                 case TERM_XTRA_BORED:
2259                 {
2260                         return (Term_xtra_win_event(0));
2261                 }
2262
2263                 /* Process an event */
2264                 case TERM_XTRA_EVENT:
2265                 {
2266                         return (Term_xtra_win_event(v));
2267                 }
2268
2269                 /* Flush all events */
2270                 case TERM_XTRA_FLUSH:
2271                 {
2272                         return (Term_xtra_win_flush());
2273                 }
2274
2275                 /* Clear the screen */
2276                 case TERM_XTRA_CLEAR:
2277                 {
2278                         return (Term_xtra_win_clear());
2279                 }
2280
2281                 /* React to global changes */
2282                 case TERM_XTRA_REACT:
2283                 {
2284                         return (Term_xtra_win_react());
2285                 }
2286
2287                 /* Delay for some milliseconds */
2288                 case TERM_XTRA_DELAY:
2289                 {
2290                         return (Term_xtra_win_delay(v));
2291                 }
2292         }
2293
2294         /* Oops */
2295         return 1;
2296 }
2297
2298
2299
2300 /*
2301  * Low level graphics (Assumes valid input).
2302  *
2303  * Draw a "cursor" at (x,y), using a "yellow box".
2304  */
2305 static errr Term_curs_win(int x, int y)
2306 {
2307         term_data *td = (term_data*)(Term->data);
2308
2309         RECT rc;
2310         HDC hdc;
2311
2312         int tile_wid, tile_hgt;
2313
2314         if (td->map_active)
2315         {
2316                 tile_wid = td->map_tile_wid;
2317                 tile_hgt = td->map_tile_hgt;
2318         }
2319         else
2320         {
2321                 tile_wid = td->tile_wid;
2322                 tile_hgt = td->tile_hgt;
2323         }
2324
2325         /* Frame the grid */
2326         rc.left = x * tile_wid + td->size_ow1;
2327         rc.right = rc.left + tile_wid;
2328         rc.top = y * tile_hgt + td->size_oh1;
2329         rc.bottom = rc.top + tile_hgt;
2330
2331         /* Cursor is done as a yellow "box" */
2332         hdc = GetDC(td->w);
2333         FrameRect(hdc, &rc, hbrYellow);
2334         ReleaseDC(td->w, hdc);
2335
2336         /* Success */
2337         return 0;
2338 }
2339
2340
2341 /*
2342  * Low level graphics (Assumes valid input).
2343  *
2344  * Draw a "big cursor" at (x,y), using a "yellow box".
2345  */
2346 static errr Term_bigcurs_win(int x, int y)
2347 {
2348         term_data *td = (term_data*)(Term->data);
2349
2350         RECT rc;
2351         HDC hdc;
2352
2353         int tile_wid, tile_hgt;
2354
2355         if (td->map_active)
2356         {
2357                 /* Normal cursor in map window */
2358                 Term_curs_win(x, y);
2359                 return 0;
2360         }
2361         else
2362         {
2363                 tile_wid = td->tile_wid;
2364                 tile_hgt = td->tile_hgt;
2365         }
2366
2367         /* Frame the grid */
2368         rc.left = x * tile_wid + td->size_ow1;
2369         rc.right = rc.left + 2 * tile_wid;
2370         rc.top = y * tile_hgt + td->size_oh1;
2371         rc.bottom = rc.top + tile_hgt;
2372
2373         /* Cursor is done as a yellow "box" */
2374         hdc = GetDC(td->w);
2375         FrameRect(hdc, &rc, hbrYellow);
2376         ReleaseDC(td->w, hdc);
2377
2378         /* Success */
2379         return 0;
2380 }
2381
2382
2383 /*
2384  * Low level graphics (Assumes valid input).
2385  *
2386  * Erase a "block" of "n" characters starting at (x,y).
2387  */
2388 static errr Term_wipe_win(int x, int y, int n)
2389 {
2390         term_data *td = (term_data*)(Term->data);
2391
2392         HDC hdc;
2393         RECT rc;
2394
2395         /* Rectangle to erase in client coords */
2396         rc.left = x * td->tile_wid + td->size_ow1;
2397         rc.right = rc.left + n * td->tile_wid;
2398         rc.top = y * td->tile_hgt + td->size_oh1;
2399         rc.bottom = rc.top + td->tile_hgt;
2400
2401         hdc = GetDC(td->w);
2402         SetBkColor(hdc, RGB(0, 0, 0));
2403         SelectObject(hdc, td->font_id);
2404         /* bg */
2405         if (use_bg)
2406                 DrawBG(hdc, &rc);
2407         else
2408                 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2409         ReleaseDC(td->w, hdc);
2410
2411         /* Success */
2412         return 0;
2413 }
2414
2415
2416 /*
2417  * Low level graphics.  Assumes valid input.
2418  *
2419  * Draw several ("n") chars, with an attr, at a given location.
2420  *
2421  * All "graphic" data is handled by "Term_pict_win()", below.
2422  *
2423  * One would think there is a more efficient method for telling a window
2424  * what color it should be using to draw with, but perhaps simply changing
2425  * it every time is not too inefficient.  XXX XXX XXX
2426  */
2427 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2428 {
2429         term_data *td = (term_data*)(Term->data);
2430         RECT rc;
2431         HDC hdc;
2432
2433
2434 #ifdef JP
2435         static HBITMAP  WALL;
2436         static HBRUSH   myBrush, oldBrush;
2437         static HPEN     oldPen;
2438         static bool init_done = FALSE;
2439
2440         if (!init_done){
2441                 WALL = LoadBitmap(hInstance, AppName);
2442                 myBrush = CreatePatternBrush(WALL);
2443                 init_done = TRUE;
2444         }
2445 #endif
2446
2447         /* Total rectangle */
2448         rc.left = x * td->tile_wid + td->size_ow1;
2449         rc.right = rc.left + n * td->tile_wid;
2450         rc.top = y * td->tile_hgt + td->size_oh1;
2451         rc.bottom = rc.top + td->tile_hgt;
2452
2453         /* Acquire DC */
2454         hdc = GetDC(td->w);
2455
2456         /* Background color */
2457         SetBkColor(hdc, RGB(0, 0, 0));
2458
2459         /* Foreground color */
2460         if (colors16)
2461         {
2462                 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2463         }
2464         else if (paletted)
2465         {
2466                 SetTextColor(hdc, win_clr[a&0x0F]);
2467         }
2468         else
2469         {
2470                 SetTextColor(hdc, win_clr[a]);
2471         }
2472
2473         /* Use the font */
2474         SelectObject(hdc, td->font_id);
2475         
2476         /* bg */
2477         if (use_bg) SetBkMode(hdc, TRANSPARENT);
2478
2479         /* Bizarre size */
2480         if (td->bizarre ||
2481             (td->tile_hgt != td->font_hgt) ||
2482             (td->tile_wid != td->font_wid))
2483         {
2484                 int i;
2485
2486                 /* Erase complete rectangle */
2487                 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2488                 
2489                 /* bg */
2490                 if (use_bg) DrawBG(hdc, &rc);
2491
2492                 /* New rectangle */
2493                 rc.left += ((td->tile_wid - td->font_wid) / 2);
2494                 rc.right = rc.left + td->font_wid;
2495                 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2496                 rc.bottom = rc.top + td->font_hgt;
2497
2498                 /* Dump each character */
2499                 for (i = 0; i < n; i++)
2500                 {
2501 #ifdef JP
2502                         if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2503                         {
2504                                 rc.right += td->font_wid;
2505
2506                                 oldBrush = SelectObject(hdc, myBrush);
2507                                 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2508
2509                                 /* Dump the wall */
2510                                 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2511
2512                                 SelectObject(hdc, oldBrush);
2513                                 SelectObject(hdc, oldPen);
2514                                 rc.right -= td->font_wid;
2515
2516                                 /* Advance */
2517                                 i++;
2518                                 rc.left += 2 * td->tile_wid;
2519                                 rc.right += 2 * td->tile_wid;
2520                         }
2521                         else if ( iskanji(*(s+i)) )  /*  £²¥Ð¥¤¥Èʸ»ú  */
2522                         {
2523                                 rc.right += td->font_wid;
2524                                 /* Dump the text */
2525                                 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2526                                        s+i, 2, NULL);
2527                                 rc.right -= td->font_wid;
2528
2529                                 /* Advance */
2530                                 i++;
2531                                 rc.left += 2 * td->tile_wid;
2532                                 rc.right += 2 * td->tile_wid;
2533                         } else if (*(s+i)==127){
2534                                 oldBrush = SelectObject(hdc, myBrush);
2535                                 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2536
2537                                 /* Dump the wall */
2538                                 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2539
2540                                 SelectObject(hdc, oldBrush);
2541                                 SelectObject(hdc, oldPen);
2542
2543                                 /* Advance */
2544                                 rc.left += td->tile_wid;
2545                                 rc.right += td->tile_wid;
2546                         } else {
2547                                 /* Dump the text */
2548                                 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2549                                        s+i, 1, NULL);
2550
2551                                 /* Advance */
2552                                 rc.left += td->tile_wid;
2553                                 rc.right += td->tile_wid;
2554                         }
2555 #else
2556                         /* Dump the text */
2557                         ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2558                                    s+i, 1, NULL);
2559
2560                         /* Advance */
2561                         rc.left += td->tile_wid;
2562                         rc.right += td->tile_wid;
2563 #endif
2564
2565                 }
2566         }
2567
2568         /* Normal size */
2569         else
2570         {
2571                 /* Dump the text */
2572                 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2573                            s, n, NULL);
2574         }
2575
2576         /* Release DC */
2577         ReleaseDC(td->w, hdc);
2578
2579         /* Success */
2580         return 0;
2581 }
2582
2583
2584 /*
2585  * Low level graphics.  Assumes valid input.
2586  *
2587  * Draw an array of "special" attr/char pairs at the given location.
2588  *
2589  * We use the "Term_pict_win()" function for "graphic" data, which are
2590  * encoded by setting the "high-bits" of both the "attr" and the "char"
2591  * data.  We use the "attr" to represent the "row" of the main bitmap,
2592  * and the "char" to represent the "col" of the main bitmap.  The use
2593  * of this function is induced by the "higher_pict" flag.
2594  *
2595  * If "graphics" is not available, we simply "wipe" the given grids.
2596  */
2597 # ifdef USE_TRANSPARENCY
2598 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2599 # else /* USE_TRANSPARENCY */
2600 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp)
2601 # endif /* USE_TRANSPARENCY */
2602 {
2603         term_data *td = (term_data*)(Term->data);
2604
2605 #ifdef USE_GRAPHICS
2606
2607         int i;
2608         int x1, y1, w1, h1;
2609         int x2, y2, w2, h2, tw2;
2610
2611 # ifdef USE_TRANSPARENCY
2612
2613         int x3, y3;
2614
2615         HDC hdcMask;
2616
2617 # endif /* USE_TRANSPARENCY */
2618
2619         HDC hdc;
2620         HDC hdcSrc;
2621         HBITMAP hbmSrcOld;
2622
2623         /* Paranoia */
2624         if (!use_graphics)
2625         {
2626                 /* Erase the grids */
2627                 return (Term_wipe_win(x, y, n));
2628         }
2629
2630         /* Size of bitmap cell */
2631         w1 = infGraph.CellWidth;
2632         h1 = infGraph.CellHeight;
2633
2634         /* Size of window cell */
2635         if (td->map_active)
2636         {
2637                 w2 = td->map_tile_wid;
2638                 h2 = td->map_tile_hgt;
2639         }
2640         else
2641         {
2642                 w2 = td->tile_wid;
2643                 h2 = td->tile_hgt;
2644                 tw2 = w2;
2645
2646                 /* big tile mode */
2647                 if (use_bigtile) tw2 *= 2;
2648         }
2649
2650         /* Location of window cell */
2651         x2 = x * w2 + td->size_ow1;
2652         y2 = y * h2 + td->size_oh1;
2653
2654         /* Info */
2655         hdc = GetDC(td->w);
2656
2657         /* More info */
2658         hdcSrc = CreateCompatibleDC(hdc);
2659         hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2660
2661 # ifdef USE_TRANSPARENCY
2662
2663         if (arg_graphics == GRAPHICS_ADAM_BOLT)
2664         {
2665                 hdcMask = CreateCompatibleDC(hdc);
2666                 SelectObject(hdcMask, infMask.hBitmap);
2667         }
2668
2669 # endif /* USE_TRANSPARENCY */
2670
2671         /* Draw attr/char pairs */
2672         for (i = 0; i < n; i++, x2 += w2)
2673         {
2674                 byte a = ap[i];
2675                 char c = cp[i];
2676
2677                 /* Extract picture */
2678                 int row = (a & 0x7F);
2679                 int col = (c & 0x7F);
2680
2681                 /* Location of bitmap cell */
2682                 x1 = col * w1;
2683                 y1 = row * h1;
2684
2685 # ifdef USE_TRANSPARENCY
2686
2687                 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2688                 {
2689                         x3 = (tcp[i] & 0x7F) * w1;
2690                         y3 = (tap[i] & 0x7F) * h1;
2691
2692                         /* Perfect size */
2693                         if ((w1 == tw2) && (h1 == h2))
2694                         {
2695                                 /* Copy the terrain picture from the bitmap to the window */
2696                                 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2697
2698                                 /* Mask out the tile */
2699                                 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2700
2701                                 /* Draw the tile */
2702                                 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2703                         }
2704
2705                         /* Need to stretch */
2706                         else
2707                         {
2708                                 /* Set the correct mode for stretching the tiles */
2709                                 SetStretchBltMode(hdc, COLORONCOLOR);
2710
2711                                 /* Copy the terrain picture from the bitmap to the window */
2712                                 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
2713
2714                                 /* Only draw if terrain and overlay are different */
2715                                 if ((x1 != x3) || (y1 != y3))
2716                                 {
2717                                         /* Mask out the tile */
2718                                         StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2719
2720                                         /* Draw the tile */
2721                                         StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2722                                 }
2723                         }
2724                 }
2725                 else
2726
2727 # endif /* USE_TRANSPARENCY */
2728
2729                 {
2730                         /* Perfect size */
2731                         if ((w1 == tw2) && (h1 == h2))
2732                         {
2733                                 /* Copy the picture from the bitmap to the window */
2734                                 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2735                         }
2736
2737                         /* Need to stretch */
2738                         else
2739                         {
2740                                 /* Set the correct mode for stretching the tiles */
2741                                 SetStretchBltMode(hdc, COLORONCOLOR);
2742
2743                                 /* Copy the picture from the bitmap to the window */
2744                                 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2745                         }
2746                 }
2747         }
2748
2749         /* Release */
2750         SelectObject(hdcSrc, hbmSrcOld);
2751         DeleteDC(hdcSrc);
2752
2753 # ifdef USE_TRANSPARENCY
2754
2755         if (arg_graphics == GRAPHICS_ADAM_BOLT)
2756         {
2757                 /* Release */
2758                 SelectObject(hdcMask, hbmSrcOld);
2759                 DeleteDC(hdcMask);
2760         }
2761
2762 # endif /* USE_TRANSPARENCY */
2763
2764         /* Release */
2765         ReleaseDC(td->w, hdc);
2766
2767 #else /* USE_GRAPHICS */
2768
2769         /* Just erase this grid */
2770         return (Term_wipe_win(x, y, n));
2771
2772 #endif /* USE_GRAPHICS */
2773
2774         /* Success */
2775         return 0;
2776 }
2777
2778
2779 static void windows_map(void)
2780 {
2781         term_data *td = &data[0];
2782         byte a, c;
2783         int x, min_x, max_x;
2784         int y, min_y, max_y;
2785
2786 #ifdef USE_TRANSPARENCY
2787         byte ta, tc;
2788 #endif
2789
2790         /* Only in graphics mode */
2791         if (!use_graphics) return;
2792
2793         /* Clear screen */
2794         Term_xtra_win_clear();
2795
2796         td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2797         td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2798         td->map_active = TRUE;
2799
2800         {
2801                 min_x = 0;
2802                 min_y = 0;
2803                 max_x = cur_wid;
2804                 max_y = cur_hgt;
2805         }
2806
2807         /* Draw the map */
2808         for (x = min_x; x < max_x; x++)
2809         {
2810                 for (y = min_y; y < max_y; y++)
2811                 {
2812 #ifdef USE_TRANSPARENCY
2813                         map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
2814 #else /* USE_TRANSPARENCY */
2815                         map_info(y, x, &a, (char*)&c);
2816 #endif /* USE_TRANSPARENCY */
2817
2818                         /* Ignore non-graphics */
2819                         if ((a & 0x80) && (c & 0x80))
2820                         {
2821 #ifdef USE_TRANSPARENCY
2822                                 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2823 #else /* USE_TRANSPARENCY */
2824                                 Term_pict_win(x - min_x, y - min_y, 1, &a, &c);
2825 #endif /* USE_TRANSPARENCY */
2826                         }
2827                 }
2828         }
2829
2830         /* Hilite the player */
2831         Term_curs_win(px - min_x, py - min_y);
2832
2833         /* Wait for a keypress, flush key buffer */
2834         Term_inkey(&c, TRUE, TRUE);
2835         Term_flush();
2836
2837         /* Switch off the map display */
2838         td->map_active = FALSE;
2839
2840         /* Restore screen */
2841         Term_xtra_win_clear();
2842         Term_redraw();
2843 }
2844
2845
2846 /*** Other routines ***/
2847
2848
2849 /*
2850  * Create and initialize a "term_data" given a title
2851  */
2852 static void term_data_link(term_data *td)
2853 {
2854         term *t = &td->t;
2855
2856         /* Initialize the term */
2857         term_init(t, td->cols, td->rows, td->keys);
2858
2859         /* Use a "software" cursor */
2860         t->soft_cursor = TRUE;
2861
2862         /* Use "Term_pict" for "graphic" data */
2863         t->higher_pict = TRUE;
2864
2865         /* Erase with "white space" */
2866         t->attr_blank = TERM_WHITE;
2867         t->char_blank = ' ';
2868
2869 #if 0
2870         /* Prepare the init/nuke hooks */
2871         t->init_hook = Term_init_win;
2872         t->nuke_hook = Term_nuke_win;
2873 #endif
2874
2875         /* Prepare the template hooks */
2876         t->user_hook = Term_user_win;
2877         t->xtra_hook = Term_xtra_win;
2878         t->curs_hook = Term_curs_win;
2879         t->bigcurs_hook = Term_bigcurs_win;
2880         t->wipe_hook = Term_wipe_win;
2881         t->text_hook = Term_text_win;
2882         t->pict_hook = Term_pict_win;
2883
2884         /* Remember where we came from */
2885         t->data = (vptr)(td);
2886 }
2887
2888
2889 /*
2890  * Create the windows
2891  *
2892  * First, instantiate the "default" values, then read the "ini_file"
2893  * to over-ride selected values, then create the windows, and fonts.
2894  *
2895  * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2896  * must make active to realize the palette.  XXX XXX XXX
2897  */
2898 static void init_windows(void)
2899 {
2900         int i;
2901
2902         term_data *td;
2903
2904 #ifndef JP
2905         char buf[1024];
2906 #endif
2907
2908         /* Main window */
2909         td = &data[0];
2910         WIPE(td, term_data);
2911 #ifdef JP
2912         td->s = "ÊѶòÈÚÅÜ";
2913 #else
2914         td->s = angband_term_name[0];
2915 #endif
2916
2917         td->keys = 1024;
2918         td->rows = 24;
2919         td->cols = 80;
2920         td->visible = TRUE;
2921         td->size_ow1 = 2;
2922         td->size_ow2 = 2;
2923         td->size_oh1 = 2;
2924         td->size_oh2 = 2;
2925         td->pos_x = 7 * 30;
2926         td->pos_y = 7 * 20;
2927         td->posfix = FALSE;
2928
2929 #ifdef JP
2930         td->bizarre = TRUE;
2931 #endif
2932         /* Sub windows */
2933         for (i = 1; i < MAX_TERM_DATA; i++)
2934         {
2935                 td = &data[i];
2936                 WIPE(td, term_data);
2937                 td->s = angband_term_name[i];
2938                 td->keys = 16;
2939                 td->rows = 24;
2940                 td->cols = 80;
2941                 td->visible = FALSE;
2942                 td->size_ow1 = 1;
2943                 td->size_ow2 = 1;
2944                 td->size_oh1 = 1;
2945                 td->size_oh2 = 1;
2946                 td->pos_x = (7 - i) * 30;
2947                 td->pos_y = (7 - i) * 20;
2948                 td->posfix = FALSE;
2949 #ifdef JP
2950                         td->bizarre = TRUE;
2951 #endif
2952         }
2953
2954
2955         /* Load prefs */
2956         load_prefs();
2957
2958
2959         /* Main window (need these before term_getsize gets called) */
2960         td = &data[0];
2961         td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2962                        WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2963                        WS_VISIBLE);
2964         td->dwExStyle = 0;
2965         td->visible = TRUE;
2966
2967         /* Sub windows (need these before term_getsize gets called) */
2968         for (i = 1; i < MAX_TERM_DATA; i++)
2969         {
2970                 td = &data[i];
2971                 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2972                 td->dwExStyle = (WS_EX_TOOLWINDOW);
2973         }
2974
2975
2976         /* All windows */
2977         for (i = 0; i < MAX_TERM_DATA; i++)
2978         {
2979                 td = &data[i];
2980
2981 #ifdef JP
2982                 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2983                 td->lf.lfCharSet = SHIFTJIS_CHARSET;
2984                 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2985                 /* Activate the chosen font */
2986                 term_force_font(td, NULL);
2987                 td->tile_wid = td->font_wid;
2988                 td->tile_hgt = td->font_hgt;
2989 #else
2990                 /* Access the standard font file */
2991                 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
2992
2993                 /* Activate the chosen font */
2994                 if (term_force_font(td, buf))
2995                 {
2996                         /* Access the standard font file */
2997                         path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2998
2999                         /* Force the use of that font */
3000                         (void)term_force_font(td, buf);
3001
3002                         /* Oops */
3003                         td->tile_wid = 8;
3004                         td->tile_hgt = 13;
3005
3006                         /* Assume not bizarre */
3007                         td->bizarre = FALSE;
3008                 }
3009 #endif
3010
3011
3012                 /* Analyze the font */
3013                 term_getsize(td);
3014
3015                 /* Resize the window */
3016                 term_window_resize(td);
3017         }
3018
3019
3020         /* Sub windows (reverse order) */
3021         for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3022         {
3023                 td = &data[i];
3024
3025                 my_td = td;
3026                 td->w = CreateWindowEx(td->dwExStyle, AngList,
3027                                        td->s, td->dwStyle,
3028                                        td->pos_x, td->pos_y,
3029                                        td->size_wid, td->size_hgt,
3030                                        HWND_DESKTOP, NULL, hInstance, NULL);
3031                 my_td = NULL;
3032 #ifdef JP
3033                 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3034 #else
3035                 if (!td->w) quit("Failed to create sub-window");
3036 #endif
3037
3038
3039                 if (td->visible)
3040                 {
3041                         td->size_hack = TRUE;
3042                         ShowWindow(td->w, SW_SHOW);
3043                         td->size_hack = FALSE;
3044                 }
3045
3046                 term_data_link(td);
3047                 angband_term[i] = &td->t;
3048
3049                 if (td->visible)
3050                 {
3051                         /* Activate the window */
3052                         SetActiveWindow(td->w);
3053                 }
3054
3055                 if (data[i].posfix)
3056                 {
3057                         term_window_pos(&data[i], HWND_TOPMOST);
3058                 }
3059                 else
3060                 {
3061                         term_window_pos(&data[i], td->w);
3062                 }
3063         }
3064
3065
3066         /* Main window */
3067         td = &data[0];
3068
3069         /* Main window */
3070         my_td = td;
3071         td->w = CreateWindowEx(td->dwExStyle, AppName,
3072                                td->s, td->dwStyle,
3073                                td->pos_x, td->pos_y,
3074                                td->size_wid, td->size_hgt,
3075                                HWND_DESKTOP, NULL, hInstance, NULL);
3076         my_td = NULL;
3077 #ifdef JP
3078         if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3079 #else
3080         if (!td->w) quit("Failed to create Angband window");
3081 #endif
3082
3083
3084         term_data_link(td);
3085         angband_term[0] = &td->t;
3086
3087         /* Activate the main window */
3088         SetActiveWindow(td->w);
3089
3090         /* Bring main window back to top */
3091         SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3092
3093
3094         /* New palette XXX XXX XXX */
3095         (void)new_palette();
3096
3097
3098         /* Create a "brush" for drawing the "cursor" */
3099         hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3100
3101
3102         /* Process pending messages */
3103         (void)Term_xtra_win_flush();
3104 }
3105
3106
3107
3108 /*
3109  * Prepare the menus
3110  */
3111 static void setup_menus(void)
3112 {
3113         int i;
3114
3115         HMENU hm = GetMenu(data[0].w);
3116
3117
3118         /* Menu "File", Disable all */
3119         EnableMenuItem(hm, IDM_FILE_NEW,
3120                        MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3121         EnableMenuItem(hm, IDM_FILE_OPEN,
3122                        MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3123         EnableMenuItem(hm, IDM_FILE_SAVE,
3124                        MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3125         EnableMenuItem(hm, IDM_FILE_EXIT,
3126                        MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3127         EnableMenuItem(hm, IDM_FILE_SCORE,
3128                        MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3129
3130
3131         /* No character available */
3132         if (!character_generated)
3133         {
3134                 /* Menu "File", Item "New" */
3135                 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3136
3137                 /* Menu "File", Item "Open" */
3138                 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3139         }
3140
3141         /* A character available */
3142         if (character_generated)
3143         {
3144                 /* Menu "File", Item "Save" */
3145                 EnableMenuItem(hm, IDM_FILE_SAVE,
3146                            MF_BYCOMMAND | MF_ENABLED);
3147         }
3148
3149         /* Menu "File", Item "Exit" */
3150         EnableMenuItem(hm, IDM_FILE_EXIT,
3151                        MF_BYCOMMAND | MF_ENABLED);
3152
3153         EnableMenuItem(hm, IDM_FILE_SCORE,
3154                        MF_BYCOMMAND | MF_ENABLED);
3155
3156
3157         /* Menu "Window::Visibility" */
3158         for (i = 0; i < MAX_TERM_DATA; i++)
3159         {
3160                 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3161                                MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3162
3163                 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3164                               (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3165
3166                 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3167                                MF_BYCOMMAND | MF_ENABLED);
3168         }
3169
3170         /* Menu "Window::Font" */
3171         for (i = 0; i < MAX_TERM_DATA; i++)
3172         {
3173                 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3174                                MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3175
3176                 if (data[i].visible)
3177                 {
3178                         EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3179                                        MF_BYCOMMAND | MF_ENABLED);
3180                 }
3181         }
3182
3183         /* Menu "Window::Window Position Fix" */
3184         for (i = 0; i < MAX_TERM_DATA; i++)
3185         {
3186                 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3187                                MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3188
3189                 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3190                               (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3191
3192                 if (data[i].visible)
3193                 {
3194                         EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3195                                        MF_BYCOMMAND | MF_ENABLED);
3196                 }
3197         }
3198
3199         /* Menu "Window::Bizarre Display" */
3200         for (i = 0; i < MAX_TERM_DATA; i++)
3201         {
3202                 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3203                                MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3204
3205                 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3206                               (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3207
3208                 if (data[i].visible)
3209                 {
3210                         EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3211                                    MF_BYCOMMAND | MF_ENABLED);
3212
3213                 }
3214         }
3215
3216         /* Menu "Window::Increase Tile Width" */
3217         for (i = 0; i < MAX_TERM_DATA; i++)
3218         {
3219                 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3220                                MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3221
3222                 if (data[i].visible)
3223                 {
3224                         EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3225                                    MF_BYCOMMAND | MF_ENABLED);
3226
3227                 }
3228         }
3229
3230         /* Menu "Window::Decrease Tile Width" */
3231         for (i = 0; i < MAX_TERM_DATA; i++)
3232         {
3233                 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3234                                MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3235
3236                 if (data[i].visible)
3237                 {
3238                         EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3239                                    MF_BYCOMMAND | MF_ENABLED);
3240
3241                 }
3242         }
3243
3244         /* Menu "Window::Increase Tile Height" */
3245         for (i = 0; i < MAX_TERM_DATA; i++)
3246         {
3247                 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3248                                MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3249
3250                 if (data[i].visible)
3251                 {
3252                         EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3253                                    MF_BYCOMMAND | MF_ENABLED);
3254
3255                 }
3256         }
3257
3258         /* Menu "Window::Decrease Tile Height" */
3259         for (i = 0; i < MAX_TERM_DATA; i++)
3260         {
3261                 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3262                                MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3263
3264                 if (data[i].visible)
3265                 {
3266                         EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3267                                    MF_BYCOMMAND | MF_ENABLED);
3268
3269                 }
3270         }
3271
3272         /* Menu "Options", disable all */
3273         EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3274                        MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3275         EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3276                        MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3277         EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3278                        MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3279         EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3280                        MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3281         EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3282                        MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3283 #ifndef JP
3284         EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3285                        MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3286 #endif
3287
3288         /* Menu "Options", Item "Map" */
3289         if (use_graphics != GRAPHICS_NONE)
3290                 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3291         else
3292                 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3293                                MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3294
3295         /* Menu "Options", update all */
3296         CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3297                       (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3298         CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3299                       (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3300         CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3301                       (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3302         CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3303                       (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3304         CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3305                       (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3306         CheckMenuItem(hm, IDM_OPTIONS_BG,
3307                       (use_bg ? MF_CHECKED : MF_UNCHECKED));
3308 #ifndef JP
3309         CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3310                       (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3311 #endif
3312
3313 #ifdef USE_GRAPHICS
3314         /* Menu "Options", Item "Graphics" */
3315         EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3316         /* Menu "Options", Item "Graphics" */
3317         EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3318         /* Menu "Options", Item "Graphics" */
3319         EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3320         /* Menu "Options", Item "Graphics" */
3321         EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3322 #endif /* USE_GRAPHICS */
3323
3324 #ifdef USE_SOUND
3325         /* Menu "Options", Item "Sound" */
3326         EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3327 #endif /* USE_SOUND */
3328
3329 #ifdef USE_SAVER
3330         /* Menu "Options", Item "ScreenSaver" */
3331         EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3332                        MF_BYCOMMAND | MF_ENABLED);
3333 #endif /* USE_SAVER */
3334 }
3335
3336
3337 /*
3338  * Check for double clicked (or dragged) savefile
3339  *
3340  * Apparently, Windows copies the entire filename into the first
3341  * piece of the "command line string".  Perhaps we should extract
3342  * the "basename" of that filename and append it to the "save" dir.
3343  */
3344 static void check_for_save_file(LPSTR cmd_line)
3345 {
3346         char *s;
3347
3348         /* First arg */
3349         s = cmd_line;
3350
3351         /* No args */
3352         if (!*s) return;
3353
3354         /* Extract filename */
3355         strcat(savefile, s);
3356
3357         /* Validate the file */
3358         validate_file(savefile);
3359
3360         /* Game in progress */
3361         game_in_progress = TRUE;
3362
3363         /* Play game */
3364         play_game(FALSE);
3365 }
3366
3367
3368 /*
3369  * Process a menu command
3370  */
3371 static void process_menus(WORD wCmd)
3372 {
3373         int i;
3374
3375         term_data *td;
3376
3377         OPENFILENAME ofn;
3378
3379         /* Analyze */
3380         switch (wCmd)
3381         {
3382                 /* New game */
3383                 case IDM_FILE_NEW:
3384                 {
3385                         if (!initialized)
3386                         {
3387 #ifdef JP
3388                                 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3389 #else
3390                                 plog("You cannot do that yet...");
3391 #endif
3392
3393                         }
3394                         else if (game_in_progress)
3395                         {
3396 #ifdef JP
3397                                 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤­¤Þ¤»¤ó¡ª");
3398 #else
3399                                 plog("You can't start a new game while you're still playing!");
3400 #endif
3401
3402                         }
3403                         else
3404                         {
3405                                 game_in_progress = TRUE;
3406                                 Term_flush();
3407                                 play_game(TRUE);
3408                                 quit(NULL);
3409                         }
3410                         break;
3411                 }
3412
3413                 /* Open game */
3414                 case IDM_FILE_OPEN:
3415                 {
3416                         if (!initialized)
3417                         {
3418 #ifdef JP
3419                                 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3420 #else
3421                                 plog("You cannot do that yet...");
3422 #endif
3423
3424                         }
3425                         else if (game_in_progress)
3426                         {
3427 #ifdef JP
3428                                 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤»¤ó¡ª");
3429 #else
3430                                 plog("You can't open a new game while you're still playing!");
3431 #endif
3432
3433                         }
3434                         else
3435                         {
3436                                 memset(&ofn, 0, sizeof(ofn));
3437                                 ofn.lStructSize = sizeof(ofn);
3438                                 ofn.hwndOwner = data[0].w;
3439                                 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3440                                 ofn.nFilterIndex = 1;
3441                                 ofn.lpstrFile = savefile;
3442                                 ofn.nMaxFile = 1024;
3443                                 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3444                                 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3445
3446                                 if (GetOpenFileName(&ofn))
3447                                 {
3448                                         /* Load 'savefile' */
3449                                         validate_file(savefile);
3450                                         game_in_progress = TRUE;
3451                                         Term_flush();
3452                                         play_game(FALSE);
3453                                         quit(NULL);
3454                                 }
3455                         }
3456                         break;
3457                 }
3458
3459                 /* Save game */
3460                 case IDM_FILE_SAVE:
3461                 {
3462                         if (game_in_progress && character_generated)
3463                         {
3464                                 /* Paranoia */
3465                                 if (!can_save)
3466                                 {
3467 #ifdef JP
3468                                         plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3469 #else
3470                                         plog("You may not do that right now.");
3471 #endif
3472
3473                                         break;
3474                                 }
3475
3476                                 /* Hack -- Forget messages */
3477                                 msg_flag = FALSE;
3478
3479                                 /* Save the game */
3480 #ifdef ZANGBAND
3481                                 do_cmd_save_game(FALSE);
3482 #else /* ZANGBAND */
3483                                 do_cmd_save_game();
3484 #endif /* ZANGBAND */
3485                         }
3486                         else
3487                         {
3488 #ifdef JP
3489                                 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3490 #else
3491                                 plog("You may not do that right now.");
3492 #endif
3493
3494                         }
3495                         break;
3496                 }
3497
3498                 /* Exit */
3499                 case IDM_FILE_EXIT:
3500                 {
3501                         if (game_in_progress && character_generated)
3502                         {
3503                                 /* Paranoia */
3504                                 if (!can_save)
3505                                 {
3506 #ifdef JP
3507                                         plog("º£¤Ï½ªÎ»¤Ç¤­¤Þ¤»¤ó¡£");
3508 #else
3509                                         plog("You may not do that right now.");
3510 #endif
3511
3512                                         break;
3513                                 }
3514
3515                                 /* Hack -- Forget messages */
3516                                 msg_flag = FALSE;
3517
3518                                 forget_lite();
3519                                 forget_view();
3520                                 clear_mon_lite();
3521
3522                                 /* Save the game */
3523 #ifdef ZANGBAND
3524                                 /* do_cmd_save_game(FALSE); */
3525 #else /* ZANGBAND */
3526                                 /* do_cmd_save_game(); */
3527 #endif /* ZANGBAND */
3528                                 Term_key_push(SPECIAL_KEY_QUIT);
3529                                 break;
3530                         }
3531                         quit(NULL);
3532                         break;
3533                 }
3534
3535                 /* Show scores */
3536                 case IDM_FILE_SCORE:
3537                 {
3538                         char buf[1024];
3539
3540                         /* Build the filename */
3541                         path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3542
3543                         /* Open the binary high score file, for reading */
3544                         highscore_fd = fd_open(buf, O_RDONLY);
3545
3546                         /* Paranoia -- No score file */
3547                         if (highscore_fd < 0)
3548                         {
3549                                 msg_print("Score file unavailable.");
3550                         }
3551                         else
3552                         {
3553                                 /* Save Screen */
3554                                 screen_save();
3555
3556                                 /* Clear screen */
3557                                 Term_clear();
3558
3559                                 /* Display the scores */
3560                                 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3561
3562                                 /* Shut the high score file */
3563                                 (void)fd_close(highscore_fd);
3564
3565                                 /* Forget the high score fd */
3566                                 highscore_fd = -1;
3567
3568                                 /* Load screen */
3569                                 screen_load();
3570
3571                                 /* Hack - Flush it */
3572                                 Term_fresh();
3573                         }
3574
3575                         break;
3576                 }
3577
3578
3579                 case IDM_WINDOW_VIS_0:
3580                 {
3581 #ifdef JP
3582                         plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤­¤Þ¤»¤ó¡ª");
3583 #else
3584                         plog("You are not allowed to do that!");
3585 #endif
3586
3587
3588                         break;
3589                 }
3590
3591                 /* Window visibility */
3592                 case IDM_WINDOW_VIS_1:
3593                 case IDM_WINDOW_VIS_2:
3594                 case IDM_WINDOW_VIS_3:
3595                 case IDM_WINDOW_VIS_4:
3596                 case IDM_WINDOW_VIS_5:
3597                 case IDM_WINDOW_VIS_6:
3598                 case IDM_WINDOW_VIS_7:
3599                 {
3600                         i = wCmd - IDM_WINDOW_VIS_0;
3601
3602                         if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3603
3604                         td = &data[i];
3605
3606                         if (!td->visible)
3607                         {
3608                                 td->visible = TRUE;
3609                                 ShowWindow(td->w, SW_SHOW);
3610                                 term_data_redraw(td);
3611                         }
3612                         else
3613                         {
3614                                 td->visible = FALSE;
3615                                 td->posfix = FALSE;
3616                                 ShowWindow(td->w, SW_HIDE);
3617                         }
3618
3619                         break;
3620                 }
3621
3622                 /* Window fonts */
3623                 case IDM_WINDOW_FONT_0:
3624                 case IDM_WINDOW_FONT_1:
3625                 case IDM_WINDOW_FONT_2:
3626                 case IDM_WINDOW_FONT_3:
3627                 case IDM_WINDOW_FONT_4:
3628                 case IDM_WINDOW_FONT_5:
3629                 case IDM_WINDOW_FONT_6:
3630                 case IDM_WINDOW_FONT_7:
3631                 {
3632                         i = wCmd - IDM_WINDOW_FONT_0;
3633
3634                         if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3635
3636                         td = &data[i];
3637
3638                         term_change_font(td);
3639
3640                         break;
3641                 }
3642
3643                 /* Window Z Position */
3644                 case IDM_WINDOW_POS_1:
3645                 case IDM_WINDOW_POS_2:
3646                 case IDM_WINDOW_POS_3:
3647                 case IDM_WINDOW_POS_4:
3648                 case IDM_WINDOW_POS_5:
3649                 case IDM_WINDOW_POS_6:
3650                 case IDM_WINDOW_POS_7:
3651                 {
3652                         i = wCmd - IDM_WINDOW_POS_0;
3653
3654                         if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3655
3656                         td = &data[i];
3657
3658                         if (!td->posfix && td->visible)
3659                         {
3660                                 td->posfix = TRUE;
3661                                 term_window_pos(td, HWND_TOPMOST);
3662                         }
3663                         else
3664                         {
3665                                 td->posfix = FALSE;
3666                                 term_window_pos(td, data[0].w);
3667                         }
3668
3669                         break;
3670                 }
3671
3672                 /* Bizarre Display */
3673                 case IDM_WINDOW_BIZ_0:
3674                 case IDM_WINDOW_BIZ_1:
3675                 case IDM_WINDOW_BIZ_2:
3676                 case IDM_WINDOW_BIZ_3:
3677                 case IDM_WINDOW_BIZ_4:
3678                 case IDM_WINDOW_BIZ_5:
3679                 case IDM_WINDOW_BIZ_6:
3680                 case IDM_WINDOW_BIZ_7:
3681                 {
3682                         i = wCmd - IDM_WINDOW_BIZ_0;
3683
3684                         if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3685
3686                         td = &data[i];
3687
3688                         td->bizarre = !td->bizarre;
3689
3690                         term_getsize(td);
3691
3692                         term_window_resize(td);
3693
3694                         break;
3695                 }
3696
3697                 /* Increase Tile Width */
3698                 case IDM_WINDOW_I_WID_0:
3699                 case IDM_WINDOW_I_WID_1:
3700                 case IDM_WINDOW_I_WID_2:
3701                 case IDM_WINDOW_I_WID_3:
3702                 case IDM_WINDOW_I_WID_4:
3703                 case IDM_WINDOW_I_WID_5:
3704                 case IDM_WINDOW_I_WID_6:
3705                 case IDM_WINDOW_I_WID_7:
3706                 {
3707                         i = wCmd - IDM_WINDOW_I_WID_0;
3708
3709                         if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3710
3711                         td = &data[i];
3712
3713                         td->tile_wid += 1;
3714
3715                         term_getsize(td);
3716
3717                         term_window_resize(td);
3718
3719                         break;
3720                 }
3721
3722                 /* Decrease Tile Height */
3723                 case IDM_WINDOW_D_WID_0:
3724                 case IDM_WINDOW_D_WID_1:
3725                 case IDM_WINDOW_D_WID_2:
3726                 case IDM_WINDOW_D_WID_3:
3727                 case IDM_WINDOW_D_WID_4:
3728                 case IDM_WINDOW_D_WID_5:
3729                 case IDM_WINDOW_D_WID_6:
3730                 case IDM_WINDOW_D_WID_7:
3731                 {
3732                         i = wCmd - IDM_WINDOW_D_WID_0;
3733
3734                         if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3735
3736                         td = &data[i];
3737
3738                         td->tile_wid -= 1;
3739
3740                         term_getsize(td);
3741
3742                         term_window_resize(td);
3743
3744                         break;
3745                 }
3746
3747                 /* Increase Tile Height */
3748                 case IDM_WINDOW_I_HGT_0:
3749                 case IDM_WINDOW_I_HGT_1:
3750                 case IDM_WINDOW_I_HGT_2:
3751                 case IDM_WINDOW_I_HGT_3:
3752                 case IDM_WINDOW_I_HGT_4:
3753                 case IDM_WINDOW_I_HGT_5:
3754                 case IDM_WINDOW_I_HGT_6:
3755                 case IDM_WINDOW_I_HGT_7:
3756                 {
3757                         i = wCmd - IDM_WINDOW_I_HGT_0;
3758
3759                         if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3760
3761                         td = &data[i];
3762
3763                         td->tile_hgt += 1;
3764
3765                         term_getsize(td);
3766
3767                         term_window_resize(td);
3768
3769                         break;
3770                 }
3771
3772                 /* Decrease Tile Height */
3773                 case IDM_WINDOW_D_HGT_0:
3774                 case IDM_WINDOW_D_HGT_1:
3775                 case IDM_WINDOW_D_HGT_2:
3776                 case IDM_WINDOW_D_HGT_3:
3777                 case IDM_WINDOW_D_HGT_4:
3778                 case IDM_WINDOW_D_HGT_5:
3779                 case IDM_WINDOW_D_HGT_6:
3780                 case IDM_WINDOW_D_HGT_7:
3781                 {
3782                         i = wCmd - IDM_WINDOW_D_HGT_0;
3783
3784                         if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3785
3786                         td = &data[i];
3787
3788                         td->tile_hgt -= 1;
3789
3790                         term_getsize(td);
3791
3792                         term_window_resize(td);
3793
3794                         break;
3795                 }
3796
3797                 case IDM_OPTIONS_NO_GRAPHICS:
3798                 {
3799                         /* Paranoia */
3800                         if (!inkey_flag)
3801                         {
3802                                 plog("You may not do that right now.");
3803                                 break;
3804                         }
3805
3806                         /* Toggle "arg_graphics" */
3807                         if (arg_graphics != GRAPHICS_NONE)
3808                         {
3809                                 arg_graphics = GRAPHICS_NONE;
3810
3811                                 /* React to changes */
3812                                 Term_xtra_win_react();
3813
3814                                 /* Hack -- Force redraw */
3815                                 Term_key_push(KTRL('R'));
3816                         }
3817
3818                         break;
3819                 }
3820
3821                 case IDM_OPTIONS_OLD_GRAPHICS:
3822                 {
3823                         /* Paranoia */
3824                         if (!inkey_flag)
3825                         {
3826                                 plog("You may not do that right now.");
3827                                 break;
3828                         }
3829
3830                         /* Toggle "arg_graphics" */
3831                         if (arg_graphics != GRAPHICS_ORIGINAL)
3832                         {
3833                                 arg_graphics = GRAPHICS_ORIGINAL;
3834
3835                                 /* React to changes */
3836                                 Term_xtra_win_react();
3837
3838                                 /* Hack -- Force redraw */
3839                                 Term_key_push(KTRL('R'));
3840                         }
3841
3842                         break;
3843                 }
3844
3845                 case IDM_OPTIONS_NEW_GRAPHICS:
3846                 {
3847                         /* Paranoia */
3848                         if (!inkey_flag)
3849                         {
3850                                 plog("You may not do that right now.");
3851                                 break;
3852                         }
3853
3854                         /* Toggle "arg_graphics" */
3855                         if (arg_graphics != GRAPHICS_ADAM_BOLT)
3856                         {
3857                                 arg_graphics = GRAPHICS_ADAM_BOLT;
3858
3859                                 /* React to changes */
3860                                 Term_xtra_win_react();
3861
3862                                 /* Hack -- Force redraw */
3863                                 Term_key_push(KTRL('R'));
3864                         }
3865
3866                         break;
3867                 }
3868
3869                 case IDM_OPTIONS_BIGTILE:
3870                 {
3871                         term_data *td = &data[0];
3872
3873                         /* Paranoia */
3874                         if (!inkey_flag)
3875                         {
3876                                 plog("You may not do that right now.");
3877                                 break;
3878                         }
3879
3880                         /* Toggle "arg_sound" */
3881                         arg_bigtile = !arg_bigtile;
3882
3883                         /* Activate */
3884                         Term_activate(&td->t);
3885
3886                         /* Resize the term */
3887                         Term_resize(td->cols, td->rows);
3888
3889                         /* Redraw later */
3890                         InvalidateRect(td->w, NULL, TRUE);
3891
3892                         break;
3893                 }
3894
3895                 case IDM_OPTIONS_SOUND:
3896                 {
3897                         /* Paranoia */
3898                         if (!inkey_flag)
3899                         {
3900                                 plog("You may not do that right now.");
3901                                 break;
3902                         }
3903
3904                         /* Toggle "arg_sound" */
3905                         arg_sound = !arg_sound;
3906
3907                         /* React to changes */
3908                         Term_xtra_win_react();
3909
3910                         /* Hack -- Force redraw */
3911                         Term_key_push(KTRL('R'));
3912
3913                         break;
3914                 }
3915
3916                 /* bg */
3917                 case IDM_OPTIONS_BG:
3918                 {
3919                         /* Paranoia */
3920                         if (!inkey_flag)
3921                         {
3922                                 plog("You may not do that right now.");
3923                                 break;
3924                         }
3925
3926                         /* Toggle "use_bg" */
3927                         use_bg = !use_bg;
3928
3929                         init_bg();
3930
3931                         /* React to changes */
3932                         Term_xtra_win_react();
3933
3934                         /* Hack -- Force redraw */
3935                         Term_key_push(KTRL('R'));
3936
3937                         break;
3938                 }
3939
3940                 /* bg */
3941                 case IDM_OPTIONS_OPEN_BG:
3942                 {
3943                         /* Paranoia */
3944                         if (!inkey_flag)
3945                         {
3946                                 plog("You may not do that right now.");
3947                                 break;
3948                         }
3949                         else
3950                         {
3951                                 memset(&ofn, 0, sizeof(ofn));
3952                                 ofn.lStructSize = sizeof(ofn);
3953                                 ofn.hwndOwner = data[0].w;
3954                                 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3955                                 ofn.nFilterIndex = 1;
3956                                 ofn.lpstrFile = bg_bitmap_file;
3957                                 ofn.nMaxFile = 1023;
3958                                 ofn.lpstrInitialDir = NULL;
3959 #ifdef JP
3960                                 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
3961 #else
3962                                 ofn.lpstrTitle = "Choose wall paper.";
3963 #endif
3964                                 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3965
3966                                 if (GetOpenFileName(&ofn))
3967                                 {
3968                                         /* Load 'savefile' */
3969                                         use_bg = 1;
3970                                         init_bg();
3971                                 }
3972
3973                                 /* React to changes */
3974                                 Term_xtra_win_react();
3975
3976                                 /* Hack -- Force redraw */
3977                                 Term_key_push(KTRL('R'));
3978                         }
3979                         break;
3980                 }
3981
3982                 case IDM_DUMP_SCREEN_HTML:
3983                 {
3984                         static char buf[1024] = "";
3985                         memset(&ofn, 0, sizeof(ofn));
3986                         ofn.lStructSize = sizeof(ofn);
3987                         ofn.hwndOwner = data[0].w;
3988                         ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
3989                         ofn.nFilterIndex = 1;
3990                         ofn.lpstrFile = buf;
3991                         ofn.nMaxFile = 1023;
3992                         ofn.lpstrDefExt = "html";
3993                         ofn.lpstrInitialDir = NULL;
3994 #ifdef JP
3995                         ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
3996 #else
3997                         ofn.lpstrTitle = "Save screen dump as HTML.";
3998 #endif
3999                         ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4000
4001                         if (GetSaveFileName(&ofn))
4002                         {
4003                                 do_cmd_save_screen_html_aux(buf, 0);
4004                         }
4005                         break;
4006                 }
4007
4008 #ifdef USE_SAVER
4009
4010                 case IDM_OPTIONS_SAVER:
4011                 {
4012                         if (hwndSaver)
4013                         {
4014                                 DestroyWindow(hwndSaver);
4015                                 hwndSaver = NULL;
4016                         }
4017                         else
4018                         {
4019                                 /* Create a screen scaver window */
4020                                 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4021                                                            "Angband Screensaver",
4022                                                            WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4023                                                            0, 0, GetSystemMetrics(SM_CXSCREEN),
4024                                                            GetSystemMetrics(SM_CYSCREEN),
4025                                                            NULL, NULL, hInstance, NULL);
4026
4027                                 if (hwndSaver)
4028                                 {
4029                                         /* Push the window to the bottom XXX XXX XXX */
4030                                         SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4031                                 }
4032                                 else
4033                                 {
4034 #ifdef JP
4035                                         plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
4036 #else
4037                                         plog("Failed to create saver window");
4038 #endif
4039
4040                                 }
4041                         }
4042                         break;
4043                 }
4044
4045 #endif
4046
4047                 case IDM_OPTIONS_MAP:
4048                 {
4049                         windows_map();
4050                         break;
4051                 }
4052
4053                 case IDM_HELP_CONTENTS:
4054                 {
4055 #ifdef HTML_HELP
4056                         char tmp[1024];
4057                         path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4058                         if (check_file(tmp))
4059                         {
4060                                 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4061                         }
4062                         else
4063                         {
4064 #ifdef JP
4065                                 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4066                                 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4067 #else
4068                                 plog_fmt("Cannot find help file: %s", tmp);
4069                                 plog("Use the online help files instead.");
4070 #endif
4071
4072                         }
4073                         break;
4074 #else /* HTML_HELP */
4075                         char buf[1024];
4076                         char tmp[1024];
4077                         path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4078                         if (check_file(tmp))
4079                         {
4080                                 sprintf(buf, "winhelp.exe %s", tmp);
4081                                 WinExec(buf, SW_NORMAL);
4082                         }
4083                         else
4084                         {
4085 #ifdef JP
4086                                 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4087                                 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4088 #else
4089                                 plog_fmt("Cannot find help file: %s", tmp);
4090                                 plog("Use the online help files instead.");
4091 #endif
4092
4093                         }
4094                         break;
4095 #endif /* HTML_HELP */
4096                 }
4097         }
4098 }
4099
4100
4101
4102 #ifdef __MWERKS__
4103 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4104                                   WPARAM wParam, LPARAM lParam);
4105 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4106                                   WPARAM wParam, LPARAM lParam)
4107 #else /* __MWERKS__ */
4108 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4109                                           WPARAM wParam, LPARAM lParam)
4110 #endif /* __MWERKS__ */
4111 {
4112         PAINTSTRUCT ps;
4113         HDC hdc;
4114         term_data *td;
4115 #if 0
4116         MINMAXINFO FAR *lpmmi;
4117         RECT rc;
4118 #endif
4119         int i;
4120
4121
4122         /* Acquire proper "term_data" info */
4123         td = (term_data *)GetWindowLong(hWnd, 0);
4124
4125         /* Handle message */
4126         switch (uMsg)
4127         {
4128                 /* XXX XXX XXX */
4129                 case WM_NCCREATE:
4130                 {
4131                         SetWindowLong(hWnd, 0, (LONG)(my_td));
4132                         break;
4133                 }
4134
4135                 /* XXX XXX XXX */
4136                 case WM_CREATE:
4137                 {
4138                         return 0;
4139                 }
4140
4141                 case WM_GETMINMAXINFO:
4142                 {
4143                         MINMAXINFO FAR *lpmmi;
4144                         RECT rc;
4145
4146                         lpmmi = (MINMAXINFO FAR *)lParam;
4147
4148                         /* this message was sent before WM_NCCREATE */
4149                         if (!td) return 1;
4150
4151                         /* Minimum window size is 80x24 */
4152                         rc.left = rc.top = 0;
4153                         rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4154                         rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4155
4156                         /* Adjust */
4157                         AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4158
4159                         /* Save minimum size */
4160                         lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4161                         lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4162
4163                         return 0;
4164                 }
4165
4166                 case WM_PAINT:
4167                 {
4168                         BeginPaint(hWnd, &ps);
4169                         if (td) term_data_redraw(td);
4170                         EndPaint(hWnd, &ps);
4171                         ValidateRect(hWnd, NULL);
4172                         return 0;
4173                 }
4174
4175                 case WM_SYSKEYDOWN:
4176                 case WM_KEYDOWN:
4177                 {
4178                         bool mc = FALSE;
4179                         bool ms = FALSE;
4180                         bool ma = FALSE;
4181
4182                         /* Extract the modifiers */
4183                         if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4184                         if (GetKeyState(VK_SHIFT)   & 0x8000) ms = TRUE;
4185                         if (GetKeyState(VK_MENU)    & 0x8000) ma = TRUE;
4186
4187                         /* Handle "special" keys */
4188                         if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4189                         {
4190                                 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4191                                 bool numpad = FALSE;
4192
4193                                 /* Begin the macro trigger */
4194                                 Term_keypress(31);
4195
4196                                 /* Send the modifiers */
4197                                 if (mc) Term_keypress('C');
4198                                 if (ms) Term_keypress('S');
4199                                 if (ma) Term_keypress('A');
4200
4201                                 /* Extract "scan code" */
4202                                 i = LOBYTE(HIWORD(lParam));
4203
4204                                 /* Introduce the scan code */
4205                                 Term_keypress('x');
4206
4207                                 /* Extended key bit */
4208                                 switch (i)
4209                                 {
4210                                 case VK_ENTER:
4211                                 case '/':
4212                                         /* Numpad Enter and '/' are extended key */
4213                                         numpad = ext_key;
4214                                 default:
4215                                         /* Other extended keys are on full keyboard */
4216                                         numpad = !ext_key;
4217                                 }
4218
4219                                 /* Special modifiers for keypad keys */
4220                                 if (numpad) Term_keypress('K');
4221
4222                                 /* Encode the hexidecimal scan code */
4223                                 Term_keypress(hexsym[i/16]);
4224                                 Term_keypress(hexsym[i%16]);
4225
4226                                 /* End the macro trigger */
4227                                 Term_keypress(13);
4228
4229                                 return 0;
4230                         }
4231
4232                         break;
4233                 }
4234
4235                 case WM_CHAR:
4236                 {
4237                         Term_keypress(wParam);
4238                         return 0;
4239                 }
4240
4241                 case WM_INITMENU:
4242                 {
4243                         setup_menus();
4244                         return 0;
4245                 }
4246
4247                 case WM_CLOSE:
4248                 {
4249                         if (game_in_progress && character_generated)
4250                         {
4251                                 if (!can_save)
4252                                 {
4253 #ifdef JP
4254                                         plog("º£¤Ï½ªÎ»¤Ç¤­¤Þ¤»¤ó¡£");
4255 #else
4256                                         plog("You may not do that right now.");
4257 #endif
4258                                         return 0;
4259                                 }
4260
4261                                 /* Hack -- Forget messages */
4262                                 msg_flag = FALSE;
4263
4264                                 forget_lite();
4265                                 forget_view();
4266                                 clear_mon_lite();
4267
4268                                 /* Save the game */
4269 #ifdef ZANGBAND
4270                                 /* do_cmd_save_game(FALSE); */
4271 #else /* ZANGBAND */
4272                                 /* do_cmd_save_game(); */
4273 #endif /* ZANGBAND */
4274                                 Term_key_push(252);
4275                                 return 0;
4276                         }
4277                         quit(NULL);
4278                         return 0;
4279                 }
4280
4281                 case WM_QUIT:
4282                 {
4283                         quit(NULL);
4284                         return 0;
4285                 }
4286
4287                 case WM_COMMAND:
4288                 {
4289                         process_menus(LOWORD(wParam));
4290                         return 0;
4291                 }
4292
4293                 case WM_SIZE:
4294                 {
4295                         /* this message was sent before WM_NCCREATE */
4296                         if (!td) return 1;
4297
4298                         /* it was sent from inside CreateWindowEx */
4299                         if (!td->w) return 1;
4300
4301                         /* was sent from WM_SIZE */
4302                         if (td->size_hack) return 1;
4303
4304                         switch (wParam)
4305                         {
4306                                 case SIZE_MINIMIZED:
4307                                 {
4308                                         /* Hide sub-windows */
4309                                         for (i = 1; i < MAX_TERM_DATA; i++)
4310                                         {
4311                                                 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4312                                         }
4313                                         return 0;
4314                                 }
4315
4316                                 case SIZE_MAXIMIZED:
4317                                 {
4318                                         /* fall through XXX XXX XXX */
4319                                 }
4320
4321                                 case SIZE_RESTORED:
4322                                 {
4323                                         uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4324                                         uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4325
4326                                         /* New size */
4327                                         if ((td->cols != cols) || (td->rows != rows))
4328                                         {
4329                                                 /* Save the new size */
4330                                                 td->cols = cols;
4331                                                 td->rows = rows;
4332
4333                                                 /* Activate */
4334                                                 Term_activate(&td->t);
4335
4336                                                 /* Resize the term */
4337                                                 Term_resize(td->cols, td->rows);
4338
4339                                                 /* Redraw later */
4340                                                 InvalidateRect(td->w, NULL, TRUE);
4341                                         }
4342
4343                                         td->size_hack = TRUE;
4344
4345                                         /* Show sub-windows */
4346                                         for (i = 1; i < MAX_TERM_DATA; i++)
4347                                         {
4348                                                 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4349                                         }
4350
4351                                         td->size_hack = FALSE;
4352
4353                                         return 0;
4354                                 }
4355                         }
4356                         break;
4357                 }
4358
4359                 case WM_PALETTECHANGED:
4360                 {
4361                         /* Ignore if palette change caused by itself */
4362                         if ((HWND)wParam == hWnd) return 0;
4363
4364                         /* Fall through... */
4365                 }
4366
4367                 case WM_QUERYNEWPALETTE:
4368                 {
4369                         if (!paletted) return 0;
4370
4371                         hdc = GetDC(hWnd);
4372
4373                         SelectPalette(hdc, hPal, FALSE);
4374
4375                         i = RealizePalette(hdc);
4376
4377                         /* if any palette entries changed, repaint the window. */
4378                         if (i) InvalidateRect(hWnd, NULL, TRUE);
4379
4380                         ReleaseDC(hWnd, hdc);
4381
4382                         return 0;
4383                 }
4384
4385                 case WM_ACTIVATE:
4386                 {
4387                         if (wParam && !HIWORD(lParam))
4388                         {
4389                                 /* Do something to sub-windows */
4390                                 for (i = 1; i < MAX_TERM_DATA; i++)
4391                                 {
4392                                         if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4393                                 }
4394
4395                                 /* Focus on main window */
4396                                 SetFocus(hWnd);
4397
4398                                 return 0;
4399                         }
4400
4401                         break;
4402                 }
4403
4404                 case WM_ACTIVATEAPP:
4405                 {
4406                         for (i = 1; i < MAX_TERM_DATA; i++)
4407                         {
4408                                 if(data[i].visible)
4409                                 {
4410                                         if (wParam == TRUE)
4411                                         {
4412                                                 ShowWindow(data[i].w, SW_SHOW);
4413                                         }
4414                                         else
4415                                         {
4416                                                 ShowWindow(data[i].w, SW_HIDE);
4417                                         }
4418                                 }
4419                         }
4420                 }
4421         }
4422
4423         return DefWindowProc(hWnd, uMsg, wParam, lParam);
4424 }
4425
4426
4427 #ifdef __MWERKS__
4428 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4429                                            WPARAM wParam, LPARAM lParam);
4430 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4431                                            WPARAM wParam, LPARAM lParam)
4432 #else /* __MWERKS__ */
4433 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4434                                            WPARAM wParam, LPARAM lParam)
4435 #endif /* __MWERKS__ */
4436 {
4437         term_data *td;
4438 #if 0
4439         MINMAXINFO FAR *lpmmi;
4440         RECT rc;
4441 #endif
4442         PAINTSTRUCT ps;
4443         HDC hdc;
4444         int i;
4445
4446
4447         /* Acquire proper "term_data" info */
4448         td = (term_data *)GetWindowLong(hWnd, 0);
4449
4450         /* Process message */
4451         switch (uMsg)
4452         {
4453                 /* XXX XXX XXX */
4454                 case WM_NCCREATE:
4455                 {
4456                         SetWindowLong(hWnd, 0, (LONG)(my_td));
4457                         break;
4458                 }
4459
4460                 /* XXX XXX XXX */
4461                 case WM_CREATE:
4462                 {
4463                         return 0;
4464                 }
4465
4466                 case WM_GETMINMAXINFO:
4467                 {
4468                         MINMAXINFO FAR *lpmmi;
4469                         RECT rc;
4470
4471                         lpmmi = (MINMAXINFO FAR *)lParam;
4472
4473                         /* this message was sent before WM_NCCREATE */
4474                         if (!td) return 1;
4475
4476                         /* Minimum window size is 80x24 */
4477                         rc.left = rc.top = 0;
4478                         rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4479                         rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4480
4481                         /* Adjust */
4482                         AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4483
4484                         /* Save minimum size */
4485                         lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4486                         lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4487
4488                         return 0;
4489                 }
4490
4491                 case WM_SIZE:
4492                 {
4493                         uint cols;
4494                         uint rows;
4495                         
4496                         /* this message was sent before WM_NCCREATE */
4497                         if (!td) return 1;
4498
4499                         /* it was sent from inside CreateWindowEx */
4500                         if (!td->w) return 1;
4501
4502                         /* was sent from inside WM_SIZE */
4503                         if (td->size_hack) return 1;
4504
4505                         td->size_hack = TRUE;
4506
4507                         cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4508                         rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4509
4510                         /* New size */
4511                         if ((td->cols != cols) || (td->rows != rows))
4512                         {
4513                                 /* Save old term */
4514                                 term *old_term = Term;
4515
4516                                 /* Save the new size */
4517                                 td->cols = cols;
4518                                 td->rows = rows;
4519
4520                                 /* Activate */
4521                                 Term_activate(&td->t);
4522
4523                                 /* Resize the term */
4524                                 Term_resize(td->cols, td->rows);
4525
4526                                 /* Activate */
4527                                 Term_activate(old_term);
4528
4529                                 /* Redraw later */
4530                                 InvalidateRect(td->w, NULL, TRUE);
4531
4532                                 /* HACK - Redraw all windows */
4533                                 p_ptr->window = 0xFFFFFFFF;
4534                                 window_stuff();
4535                         }
4536
4537                         td->size_hack = FALSE;
4538
4539                         return 0;
4540                 }
4541
4542                 case WM_PAINT:
4543                 {
4544                         BeginPaint(hWnd, &ps);
4545                         if (td) term_data_redraw(td);
4546                         EndPaint(hWnd, &ps);
4547                         return 0;
4548                 }
4549
4550                 case WM_SYSKEYDOWN:
4551                 case WM_KEYDOWN:
4552                 {
4553                         bool mc = FALSE;
4554                         bool ms = FALSE;
4555                         bool ma = FALSE;
4556
4557                         /* Extract the modifiers */
4558                         if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4559                         if (GetKeyState(VK_SHIFT)   & 0x8000) ms = TRUE;
4560                         if (GetKeyState(VK_MENU)    & 0x8000) ma = TRUE;
4561
4562                         /* Handle "special" keys */
4563                         if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4564                         {
4565                                 /* Begin the macro trigger */
4566                                 Term_keypress(31);
4567
4568                                 /* Send the modifiers */
4569                                 if (mc) Term_keypress('C');
4570                                 if (ms) Term_keypress('S');
4571                                 if (ma) Term_keypress('A');
4572
4573                                 /* Extract "scan code" */
4574                                 i = LOBYTE(HIWORD(lParam));
4575
4576                                 /* Introduce the scan code */
4577                                 Term_keypress('x');
4578
4579                                 /* Encode the hexidecimal scan code */
4580                                 Term_keypress(hexsym[i/16]);
4581                                 Term_keypress(hexsym[i%16]);
4582
4583                                 /* End the macro trigger */
4584                                 Term_keypress(13);
4585
4586                                 return 0;
4587                         }
4588
4589                         break;
4590                 }
4591
4592                 case WM_CHAR:
4593                 {
4594                         Term_keypress(wParam);
4595                         return 0;
4596                 }
4597
4598                 case WM_PALETTECHANGED:
4599                 {
4600                         /* ignore if palette change caused by itself */
4601                         if ((HWND)wParam == hWnd) return FALSE;
4602                         /* otherwise, fall through!!! */
4603                 }
4604
4605                 case WM_QUERYNEWPALETTE:
4606                 {
4607                         if (!paletted) return 0;
4608                         hdc = GetDC(hWnd);
4609                         SelectPalette(hdc, hPal, FALSE);
4610                         i = RealizePalette(hdc);
4611                         /* if any palette entries changed, repaint the window. */
4612                         if (i) InvalidateRect(hWnd, NULL, TRUE);
4613                         ReleaseDC(hWnd, hdc);
4614                         return 0;
4615                 }
4616
4617                 case WM_NCLBUTTONDOWN:
4618                 {
4619
4620 #ifdef HTCLOSE
4621                         if (wParam == HTCLOSE) wParam = HTSYSMENU;
4622 #endif /* HTCLOSE */
4623
4624                         if (wParam == HTSYSMENU)
4625                         {
4626                                 if (td->visible)
4627                                 {
4628                                         td->visible = FALSE;
4629                                         ShowWindow(td->w, SW_HIDE);
4630                                 }
4631
4632                                 return 0;
4633                         }
4634
4635                         break;
4636                 }
4637         }
4638
4639         return DefWindowProc(hWnd, uMsg, wParam, lParam);
4640 }
4641
4642
4643 #ifdef USE_SAVER
4644
4645 #define MOUSE_SENS 40
4646
4647 #ifdef __MWERKS__
4648 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4649                                     WPARAM wParam, LPARAM lParam);
4650 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4651                                     WPARAM wParam, LPARAM lParam)
4652 #else /* __MWERKS__ */
4653 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4654                                             WPARAM wParam, LPARAM lParam)
4655 #endif /* __MWERKS__ */
4656 {
4657         static int iMouse = 0;
4658         static WORD xMouse = 0;
4659         static WORD yMouse = 0;
4660
4661         int dx, dy;
4662
4663
4664         /* Process */
4665         switch (uMsg)
4666         {
4667                 /* XXX XXX XXX */
4668                 case WM_NCCREATE:
4669                 {
4670                         break;
4671                 }
4672
4673                 case WM_SETCURSOR:
4674                 {
4675                         SetCursor(NULL);
4676                         return 0;
4677                 }
4678
4679 #if 0
4680                 case WM_ACTIVATE:
4681                 {
4682                         if (LOWORD(wParam) == WA_INACTIVE) break;
4683
4684                         /* else fall through */
4685                 }
4686 #endif
4687
4688                 case WM_LBUTTONDOWN:
4689                 case WM_MBUTTONDOWN:
4690                 case WM_RBUTTONDOWN:
4691                 case WM_KEYDOWN:
4692                 {
4693                         SendMessage(hWnd, WM_CLOSE, 0, 0);
4694                         return 0;
4695                 }
4696
4697                 case WM_MOUSEMOVE:
4698                 {
4699                         if (iMouse)
4700                         {
4701                                 dx = LOWORD(lParam) - xMouse;
4702                                 dy = HIWORD(lParam) - yMouse;
4703
4704                                 if (dx < 0) dx = -dx;
4705                                 if (dy < 0) dy = -dy;
4706
4707                                 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
4708                                 {
4709                                         SendMessage(hWnd, WM_CLOSE, 0, 0);
4710                                 }
4711                         }
4712
4713                         /* Save last location */
4714                         iMouse = 1;
4715                         xMouse = LOWORD(lParam);
4716                         yMouse = HIWORD(lParam);
4717
4718                         return 0;
4719                 }
4720
4721                 case WM_CLOSE:
4722                 {
4723                         DestroyWindow(hwndSaver);
4724                         hwndSaver = NULL;
4725                         return 0;
4726                 }
4727         }
4728
4729         /* Oops */
4730         return DefWindowProc(hWnd, uMsg, wParam, lParam);
4731 }
4732
4733 #endif /* USE_SAVER */
4734
4735
4736
4737
4738
4739 /*** Temporary Hooks ***/
4740
4741
4742 /*
4743  * Display warning message (see "z-util.c")
4744  */
4745 static void hack_plog(cptr str)
4746 {
4747         /* Give a warning */
4748         if (str)
4749         {
4750 #ifdef JP
4751                 MessageBox(NULL, str, "·Ù¹ð¡ª",
4752                            MB_ICONEXCLAMATION | MB_OK);
4753 #else
4754                 MessageBox(NULL, str, "Warning",
4755                            MB_ICONEXCLAMATION | MB_OK);
4756 #endif
4757
4758         }
4759 }
4760
4761
4762 /*
4763  * Display error message and quit (see "z-util.c")
4764  */
4765 static void hack_quit(cptr str)
4766 {
4767         /* Give a warning */
4768         if (str)
4769         {
4770 #ifdef JP
4771                 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
4772                            MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4773 #else
4774                 MessageBox(NULL, str, "Error",
4775                            MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4776 #endif
4777
4778         }
4779
4780         /* Unregister the classes */
4781         UnregisterClass(AppName, hInstance);
4782
4783         /* Destroy the icon */
4784         if (hIcon) DestroyIcon(hIcon);
4785
4786         /* Exit */
4787         exit(0);
4788 }
4789
4790
4791
4792 /*** Various hooks ***/
4793
4794
4795 /*
4796  * Display warning message (see "z-util.c")
4797  */
4798 static void hook_plog(cptr str)
4799 {
4800         /* Warning */
4801         if (str)
4802         {
4803 #ifdef JP
4804                 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
4805                            MB_ICONEXCLAMATION | MB_OK);
4806 #else
4807                 MessageBox(data[0].w, str, "Warning",
4808                            MB_ICONEXCLAMATION | MB_OK);
4809 #endif
4810
4811         }
4812 }
4813
4814
4815 /*
4816  * Display error message and quit (see "z-util.c")
4817  */
4818 static void hook_quit(cptr str)
4819 {
4820         int i;
4821
4822
4823         /* Give a warning */
4824         if (str)
4825         {
4826 #ifdef JP
4827                 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
4828                            MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4829 #else
4830                 MessageBox(data[0].w, str, "Error",
4831                            MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4832 #endif
4833
4834         }
4835
4836
4837         /* Save the preferences */
4838         save_prefs();
4839
4840
4841         /*** Could use 'Term_nuke_win()' XXX XXX XXX */
4842
4843         /* Destroy all windows */
4844         for (i = MAX_TERM_DATA - 1; i >= 0; --i)
4845         {
4846                 term_force_font(&data[i], NULL);
4847                 if (data[i].font_want) string_free(data[i].font_want);
4848                 if (data[i].w) DestroyWindow(data[i].w);
4849                 data[i].w = 0;
4850         }
4851
4852         /* Free the bitmap stuff */
4853 #ifdef USE_GRAPHICS
4854         if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
4855         if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
4856
4857 #ifdef USE_TRANSPARENCY
4858         if (infMask.hPalette) DeleteObject(infMask.hPalette);
4859         if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
4860 #endif /* USE_TRANSPARENCY */
4861
4862 #endif /* USE_GRAPHICS */
4863
4864         /*** Free some other stuff ***/
4865
4866         DeleteObject(hbrYellow);
4867
4868         /* bg */
4869         delete_bg();
4870
4871         if (hPal) DeleteObject(hPal);
4872
4873         UnregisterClass(AppName, hInstance);
4874
4875         if (hIcon) DestroyIcon(hIcon);
4876
4877         exit(0);
4878 }
4879
4880
4881
4882 /*** Initialize ***/
4883
4884
4885 /*
4886  * Init some stuff
4887  */
4888 static void init_stuff(void)
4889 {
4890         int i;
4891
4892         char path[1024];
4893
4894
4895         /* Get program name with full path */
4896         GetModuleFileName(hInstance, path, 512);
4897
4898         /* Save the "program name" XXX XXX XXX */
4899         argv0 = path;
4900
4901         /* Get the name of the "*.ini" file */
4902         strcpy(path + strlen(path) - 4, ".INI");
4903
4904         /* Save the the name of the ini-file */
4905         ini_file = string_make(path);
4906
4907         /* Analyze the path */
4908         i = strlen(path);
4909
4910         /* Get the path */
4911         for (; i > 0; i--)
4912         {
4913                 if (path[i] == '\\')
4914                 {
4915                         /* End of path */
4916                         break;
4917                 }
4918         }
4919
4920         /* Add "lib" to the path */
4921         strcpy(path + i + 1, "lib\\");
4922
4923         /* Validate the path */
4924         validate_dir(path, TRUE);
4925
4926         /* Init the file paths */
4927         init_file_paths(path);
4928
4929         /* Hack -- Validate the paths */
4930         validate_dir(ANGBAND_DIR_APEX, FALSE);
4931         validate_dir(ANGBAND_DIR_BONE, FALSE);
4932
4933         /* Allow missing 'edit' directory */
4934         if (!check_dir(ANGBAND_DIR_EDIT))
4935         {
4936                 /* Must have 'data'! */
4937                 validate_dir(ANGBAND_DIR_DATA, TRUE);
4938         }
4939         else
4940         {
4941                 /* Don't need 'data' */
4942                 validate_dir(ANGBAND_DIR_DATA, FALSE);
4943         }
4944
4945         validate_dir(ANGBAND_DIR_FILE, TRUE);
4946         validate_dir(ANGBAND_DIR_HELP, FALSE);
4947         validate_dir(ANGBAND_DIR_INFO, FALSE);
4948         validate_dir(ANGBAND_DIR_PREF, TRUE);
4949         validate_dir(ANGBAND_DIR_SAVE, FALSE);
4950         validate_dir(ANGBAND_DIR_USER, TRUE);
4951         validate_dir(ANGBAND_DIR_XTRA, TRUE);
4952
4953         /* Build the filename */
4954 #ifdef JP
4955         path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
4956 #else
4957         path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
4958 #endif
4959
4960
4961         /* Hack -- Validate the "news.txt" file */
4962         validate_file(path);
4963
4964
4965 #ifndef JP
4966         /* Build the "font" path */
4967         path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
4968
4969         /* Allocate the path */
4970         ANGBAND_DIR_XTRA_FONT = string_make(path);
4971
4972         /* Validate the "font" directory */
4973         validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
4974
4975         /* Build the filename */
4976         path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
4977
4978         /* Hack -- Validate the basic font */
4979         validate_file(path);
4980 #endif
4981
4982
4983 #ifdef USE_GRAPHICS
4984
4985         /* Build the "graf" path */
4986         path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
4987
4988         /* Allocate the path */
4989         ANGBAND_DIR_XTRA_GRAF = string_make(path);
4990
4991         /* Validate the "graf" directory */
4992         validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
4993
4994 #endif /* USE_GRAPHICS */
4995
4996
4997 #ifdef USE_SOUND
4998
4999         /* Build the "sound" path */
5000         path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5001
5002         /* Allocate the path */
5003         ANGBAND_DIR_XTRA_SOUND = string_make(path);
5004
5005         /* Validate the "sound" directory */
5006         validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5007
5008 #endif /* USE_SOUND */
5009
5010 #ifdef USE_MUSIC
5011
5012         /* Build the "music" path */
5013         path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5014
5015         /* Allocate the path */
5016         ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5017
5018         /* Validate the "music" directory */
5019         validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5020
5021 #endif /* USE_MUSIC */
5022
5023         /* Build the "help" path */
5024         path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5025
5026         /* Allocate the path */
5027         ANGBAND_DIR_XTRA_HELP = string_make(path);
5028
5029         /* Validate the "help" directory */
5030         /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5031 }
5032
5033
5034 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5035                        LPSTR lpCmdLine, int nCmdShow)
5036 {
5037         int i;
5038
5039         WNDCLASS wc;
5040         HDC hdc;
5041         MSG msg;
5042
5043         /* Save globally */
5044         hInstance = hInst;
5045
5046         /* Initialize */
5047         if (hPrevInst == NULL)
5048         {
5049                 wc.style         = CS_CLASSDC;
5050                 wc.lpfnWndProc   = AngbandWndProc;
5051                 wc.cbClsExtra    = 0;
5052                 wc.cbWndExtra    = 4; /* one long pointer to term_data */
5053                 wc.hInstance     = hInst;
5054                 wc.hIcon         = hIcon = LoadIcon(hInst, AppName);
5055                 wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
5056                 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5057                 wc.lpszMenuName  = AppName;
5058                 wc.lpszClassName = AppName;
5059
5060                 if (!RegisterClass(&wc)) exit(1);
5061
5062                 wc.lpfnWndProc   = AngbandListProc;
5063                 wc.lpszMenuName  = NULL;
5064                 wc.lpszClassName = AngList;
5065
5066                 if (!RegisterClass(&wc)) exit(2);
5067
5068 #ifdef USE_SAVER
5069
5070                 wc.style          = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5071                 wc.lpfnWndProc    = AngbandSaverProc;
5072                 wc.hCursor        = NULL;
5073                 wc.lpszMenuName   = NULL;
5074                 wc.lpszClassName  = "WindowsScreenSaverClass";
5075
5076                 if (!RegisterClass(&wc)) exit(3);
5077
5078 #endif
5079
5080         }
5081
5082         /* Temporary hooks */
5083         plog_aux = hack_plog;
5084         quit_aux = hack_quit;
5085         core_aux = hack_quit;
5086
5087         /* Prepare the filepaths */
5088         init_stuff();
5089
5090         /* Initialize the keypress analyzer */
5091         for (i = 0; special_key_list[i]; ++i)
5092         {
5093                 special_key[special_key_list[i]] = TRUE;
5094         }
5095         /* Initialize the keypress analyzer */
5096         for (i = 0; ignore_key_list[i]; ++i)
5097         {
5098                 ignore_key[ignore_key_list[i]] = TRUE;
5099         }
5100
5101         /* Determine if display is 16/256/true color */
5102         hdc = GetDC(NULL);
5103         colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5104         paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5105         ReleaseDC(NULL, hdc);
5106
5107         /* Initialize the colors */
5108         for (i = 0; i < 256; i++)
5109         {
5110                 byte rv, gv, bv;
5111
5112                 /* Extract desired values */
5113                 rv = angband_color_table[i][1];
5114                 gv = angband_color_table[i][2];
5115                 bv = angband_color_table[i][3];
5116
5117                 /* Extract the "complex" code */
5118                 win_clr[i] = PALETTERGB(rv, gv, bv);
5119
5120                 /* Save the "simple" code */
5121                 angband_color_table[i][0] = win_pal[i];
5122         }
5123
5124         /* Prepare the windows */
5125         init_windows();
5126
5127         /* bg */
5128         init_bg();
5129
5130         /* Activate hooks */
5131         plog_aux = hook_plog;
5132         quit_aux = hook_quit;
5133         core_aux = hook_quit;
5134
5135         /* Set the system suffix */
5136         ANGBAND_SYS = "win";
5137
5138         /* Set the keyboard suffix */
5139         if (7 != GetKeyboardType(0))
5140                 ANGBAND_KEYBOARD = "0";
5141         else
5142         {
5143                 /* Japanese keyboard */
5144                 switch (GetKeyboardType(1))
5145                 {
5146                 case 0x0D01: case 0x0D02:
5147                 case 0x0D03: case 0x0D04:
5148                 case 0x0D05: case 0x0D06:
5149                         /* NEC PC-98x1 */
5150                         ANGBAND_KEYBOARD = "NEC98";
5151                         break;
5152                 default:
5153                         /* PC/AT */
5154                         ANGBAND_KEYBOARD = "JAPAN";
5155                 }
5156         }
5157
5158
5159         /* Initialize */
5160         init_angband();
5161
5162         /* We are now initialized */
5163         initialized = TRUE;
5164
5165 #ifdef CHUUKEI
5166         if(lpCmdLine[0] == '-'){
5167           switch(lpCmdLine[1])
5168           {
5169           case 'p':
5170           case 'P':
5171             {
5172               if (!lpCmdLine[2]) break;
5173               chuukei_server = TRUE;
5174               if(connect_chuukei_server(&lpCmdLine[2])<0){
5175                 msg_print("connect fail");
5176                 return 0;
5177               }
5178               msg_print("connect");
5179               msg_print(NULL);
5180               break;
5181             }
5182
5183           case 'c':
5184           case 'C':
5185             {
5186               if (!lpCmdLine[2]) break;
5187               chuukei_client = TRUE;
5188               connect_chuukei_server(&lpCmdLine[2]);
5189               play_game(FALSE);
5190               quit(NULL);
5191               return 0;
5192             }
5193           }
5194         }
5195 #endif
5196
5197 #ifdef CHUUKEI
5198         /* Did the user double click on a save file? */
5199         if(!chuukei_server) check_for_save_file(lpCmdLine);
5200 #else
5201         /* Did the user double click on a save file? */
5202         check_for_save_file(lpCmdLine);
5203 #endif
5204
5205         /* Prompt the user */
5206 #ifdef JP
5207         prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5208 #else
5209         prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5210 #endif
5211
5212         Term_fresh();
5213
5214         /* Process messages forever */
5215         while (GetMessage(&msg, NULL, 0, 0))
5216         {
5217                 TranslateMessage(&msg);
5218                 DispatchMessage(&msg);
5219         }
5220
5221         /* Paranoia */
5222         quit(NULL);
5223
5224         /* Paranoia */
5225         return (0);
5226 }
5227
5228
5229 #endif /* WINDOWS */
5230