OSDN Git Service

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