OSDN Git Service

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