OSDN Git Service

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