2 * todo main関数を含むファイルの割に長過ぎる。main-win-utils.cなどといった形で分割したい
4 * @brief Windows版固有実装(メインエントリポイント含む)
6 * @author Hengband Team
10 * Windows98かその前後の頃を起点としたAPI実装。
12 * DirectXといった昨今描画に標準的となったライブラリも用いていない。
13 * タイルの描画処理などについては、現在動作の詳細を検証中。
17 * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
19 * This software may be copied and distributed for educational, research,
20 * and not for profit purposes provided that this copyright and statement
21 * are included in all such copies.
24 * This file helps Angband work with Windows computers.
26 * To use this file, use an appropriate "Makefile" or "Project File",
27 * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
28 * make sure to obtain various extra files as described below.
30 * The official compilation uses the CodeWarrior Pro compiler, which
31 * includes a special project file and precompilable header file.
35 * <del>See also "main-dos.c" and "main-ibm.c".</del>
39 * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
40 * and/or color redefinitions.
44 * The "lib/user/font-win.prf" contains attr/char mappings for use with the
45 * normal "lib/xtra/font/*.fon" font files.
49 * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
50 * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
55 * Compiling this file, and using the resulting executable, requires
56 * several extra files not distributed with the standard Angband code.
57 * In any case, some "*.fon" files (including "8X13.FON" if nothing else)
58 * must be placed into "lib/xtra/font/". All of these extra files can be found
59 * in the "ext-win" archive.
63 * The "term_xtra_win_clear()" function should probably do a low-level
64 * clear of the current window, and redraw the borders and other things,
65 * if only for efficiency.
69 * A simpler method is needed for selecting the "tile size" for windows.
73 * The various "warning" messages assume the existance of the "screen.w"
74 * window, I think, and only a few calls actually check for its existance,
75 * this may be okay since "NULL" means "on top of all windows". (?) The
76 * user must never be allowed to "hide" the main window, or the "menubar"
81 * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
82 * use with the "winhelp.exe" program. These files *may* be available
83 * at the ftp site somewhere, but I have not seen them.
87 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
89 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
91 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
92 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
97 #include "signal-handlers.h"
102 #include "cmd/cmd-dump.h"
103 #include "cmd/cmd-save.h"
104 #include "view-mainwindow.h"
106 #include "floor-events.h"
125 * Extract the "WIN32" flag from the compiler
127 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
134 * Available graphic modes
136 #define GRAPHICS_NONE 0
137 #define GRAPHICS_ORIGINAL 1
138 #define GRAPHICS_ADAM_BOLT 2
139 #define GRAPHICS_HENGBAND 3
142 * Menu constants -- see "ANGBAND.RC"
144 #define IDM_FILE_NEW 100
145 #define IDM_FILE_OPEN 101
146 #define IDM_FILE_SAVE 110
147 #define IDM_FILE_SCORE 120
148 #define IDM_FILE_MOVIE 121
149 #define IDM_FILE_EXIT 130
151 #define IDM_WINDOW_VIS_0 200
152 #define IDM_WINDOW_VIS_1 201
153 #define IDM_WINDOW_VIS_2 202
154 #define IDM_WINDOW_VIS_3 203
155 #define IDM_WINDOW_VIS_4 204
156 #define IDM_WINDOW_VIS_5 205
157 #define IDM_WINDOW_VIS_6 206
158 #define IDM_WINDOW_VIS_7 207
160 #define IDM_WINDOW_FONT_0 210
161 #define IDM_WINDOW_FONT_1 211
162 #define IDM_WINDOW_FONT_2 212
163 #define IDM_WINDOW_FONT_3 213
164 #define IDM_WINDOW_FONT_4 214
165 #define IDM_WINDOW_FONT_5 215
166 #define IDM_WINDOW_FONT_6 216
167 #define IDM_WINDOW_FONT_7 217
169 #define IDM_WINDOW_POS_0 220
170 #define IDM_WINDOW_POS_1 221
171 #define IDM_WINDOW_POS_2 222
172 #define IDM_WINDOW_POS_3 223
173 #define IDM_WINDOW_POS_4 224
174 #define IDM_WINDOW_POS_5 225
175 #define IDM_WINDOW_POS_6 226
176 #define IDM_WINDOW_POS_7 227
178 #define IDM_WINDOW_BIZ_0 230
179 #define IDM_WINDOW_BIZ_1 231
180 #define IDM_WINDOW_BIZ_2 232
181 #define IDM_WINDOW_BIZ_3 233
182 #define IDM_WINDOW_BIZ_4 234
183 #define IDM_WINDOW_BIZ_5 235
184 #define IDM_WINDOW_BIZ_6 236
185 #define IDM_WINDOW_BIZ_7 237
187 #define IDM_WINDOW_I_WID_0 240
188 #define IDM_WINDOW_I_WID_1 241
189 #define IDM_WINDOW_I_WID_2 242
190 #define IDM_WINDOW_I_WID_3 243
191 #define IDM_WINDOW_I_WID_4 244
192 #define IDM_WINDOW_I_WID_5 245
193 #define IDM_WINDOW_I_WID_6 246
194 #define IDM_WINDOW_I_WID_7 247
196 #define IDM_WINDOW_D_WID_0 250
197 #define IDM_WINDOW_D_WID_1 251
198 #define IDM_WINDOW_D_WID_2 252
199 #define IDM_WINDOW_D_WID_3 253
200 #define IDM_WINDOW_D_WID_4 254
201 #define IDM_WINDOW_D_WID_5 255
202 #define IDM_WINDOW_D_WID_6 256
203 #define IDM_WINDOW_D_WID_7 257
205 #define IDM_WINDOW_I_HGT_0 260
206 #define IDM_WINDOW_I_HGT_1 261
207 #define IDM_WINDOW_I_HGT_2 262
208 #define IDM_WINDOW_I_HGT_3 263
209 #define IDM_WINDOW_I_HGT_4 264
210 #define IDM_WINDOW_I_HGT_5 265
211 #define IDM_WINDOW_I_HGT_6 266
212 #define IDM_WINDOW_I_HGT_7 267
214 #define IDM_WINDOW_D_HGT_0 270
215 #define IDM_WINDOW_D_HGT_1 271
216 #define IDM_WINDOW_D_HGT_2 272
217 #define IDM_WINDOW_D_HGT_3 273
218 #define IDM_WINDOW_D_HGT_4 274
219 #define IDM_WINDOW_D_HGT_5 275
220 #define IDM_WINDOW_D_HGT_6 276
221 #define IDM_WINDOW_D_HGT_7 277
223 #define IDM_OPTIONS_NO_GRAPHICS 400
224 #define IDM_OPTIONS_OLD_GRAPHICS 401
225 #define IDM_OPTIONS_NEW_GRAPHICS 402
226 #define IDM_OPTIONS_NEW2_GRAPHICS 403
227 #define IDM_OPTIONS_BIGTILE 409
228 #define IDM_OPTIONS_SOUND 410
229 #define IDM_OPTIONS_MUSIC 411
230 #define IDM_OPTIONS_SAVER 420
231 #define IDM_OPTIONS_MAP 430
232 #define IDM_OPTIONS_BG 440
233 #define IDM_OPTIONS_OPEN_BG 441
235 #define IDM_DUMP_SCREEN_HTML 450
237 #define IDM_HELP_CONTENTS 901
240 * Exclude parts of WINDOWS.H that are not needed
242 #define NOCOMM /* Comm driver APIs and definitions */
243 #define NOLOGERROR /* LogError() and related definitions */
244 #define NOPROFILER /* Profiler APIs */
245 #define NOLFILEIO /* _l* file I/O routines */
246 #define NOOPENFILE /* OpenFile and related definitions */
247 #define NORESOURCE /* Resource management */
248 #define NOATOM /* Atom management */
249 #define NOLANGUAGE /* Character test routines */
250 #define NOLSTRING /* lstr* string management routines */
251 #define NODBCS /* Double-byte character set routines */
252 #define NOKEYBOARDINFO /* Keyboard driver routines */
253 #define NOCOLOR /* COLOR_* color values */
254 #define NODRAWTEXT /* DrawText() and related definitions */
255 #define NOSCALABLEFONT /* Truetype scalable font support */
256 #define NOMETAFILE /* Metafile support */
257 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
258 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
259 #define NOKEYSTATES /* MK_* message key state flags */
260 #define NOWH /* SetWindowsHook and related WH_* definitions */
261 #define NOCLIPBOARD /* Clipboard APIs and definitions */
262 #define NOICONS /* IDI_* icon IDs */
263 #define NOMDI /* MDI support */
264 #define NOHELP /* Help support */
266 /* Not defined since it breaks Borland C++ 5.5 */
267 /* #define NOCTLMGR */ /* Control management and controls */
270 * Exclude parts of WINDOWS.H that are not needed (Win32)
272 #define WIN32_LEAN_AND_MEAN
273 #define NONLS /* All NLS defines and routines */
274 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
275 #define NOKANJI /* Kanji support stuff. */
276 #define NOMCX /* Modem Configuration Extensions */
279 * Include the "windows" support file
284 * Exclude parts of MMSYSTEM.H that are not needed
286 #define MMNODRV /* Installable driver support */
287 #define MMNOWAVE /* Waveform support */
288 #define MMNOMIDI /* MIDI support */
289 #define MMNOAUX /* Auxiliary audio support */
290 #define MMNOTIMER /* Timer support */
291 #define MMNOJOY /* Joystick support */
292 #define MMNOMCI /* MCI support */
293 #define MMNOMMIO /* Multimedia file I/O support */
294 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
297 * Standard sound names
299 const concptr angband_sound_name[SOUND_MAX] =
371 * Standard music names
373 const concptr angband_music_basic_name[MUSIC_BASIC_MAX] =
399 * Include some more files. Note: the Cygnus Cygwin compiler
400 * doesn't use mmsystem.h instead it includes the winmm library
401 * which performs a similar function.
403 #include <mmsystem.h>
407 * Include the support for loading bitmaps
412 * Hack -- Fake declarations from "dos.h"
415 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
417 #define FA_LABEL 0x08 /* Volume label */
418 #define FA_DIREC 0x10 /* Directory */
419 unsigned _cdecl _dos_getfileattr(concptr, unsigned *);
423 * Silliness in WIN32 drawing routine
426 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
430 * Silliness for Windows 95
432 #ifndef WS_EX_TOOLWINDOW
433 # define WS_EX_TOOLWINDOW 0
437 * Foreground color bits (hard-coded by DOS)
439 #define VID_BLACK 0x00
440 #define VID_BLUE 0x01
441 #define VID_GREEN 0x02
442 #define VID_CYAN 0x03
444 #define VID_MAGENTA 0x05
445 #define VID_YELLOW 0x06
446 #define VID_WHITE 0x07
449 * Bright text (hard-coded by DOS)
451 #define VID_BRIGHT 0x08
454 * Background color bits (hard-coded by DOS)
456 #define VUD_BLACK 0x00
457 #define VUD_BLUE 0x10
458 #define VUD_GREEN 0x20
459 #define VUD_CYAN 0x30
461 #define VUD_MAGENTA 0x50
462 #define VUD_YELLOW 0x60
463 #define VUD_WHITE 0x70
466 * Blinking text (hard-coded by DOS)
468 #define VUD_BRIGHT 0x80
474 typedef struct _term_data term_data;
478 * @brief ターム情報構造体 / Extra "term" data
481 * pos_x / pos_y は各タームの左上点座標を指す。
484 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
485 * 1ドットずつ調整するステータスを指す。
486 * また、フォントを変更すると都度自動調整される。
489 * Note the use of "font_want" for the names of the font file requested by
490 * the user, and the use of "font_file" for the currently active font file.
492 * The "font_file" is uppercased, and takes the form "8X13.FON", while
493 * "font_want" can be in almost any form as long as it could be construed
494 * as attempting to represent the name of a font.
506 TERM_LEN rows; /* int -> uint */
509 uint pos_x; //!< タームの左上X座標
510 uint pos_y; //!< タームの左上Y座標
525 int font_wid; //!< フォント横幅
526 int font_hgt; //!< フォント縦幅
527 int tile_wid; //!< タイル横幅
528 int tile_hgt; //!< タイル縦幅
540 #define MAX_TERM_DATA 8 //!< Maximum number of windows
542 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
543 static term_data *my_td; //!< Hack -- global "window creation" pointer
544 POINT normsize; //!< Remember normal size of main window when maxmized
547 * was main window maximized on previous playing
549 bool win_maximized = FALSE;
554 bool game_in_progress = FALSE;
557 * note when "open"/"new" become valid
559 bool initialized = FALSE;
562 * screen paletted, i.e. 256 colors
564 bool paletted = FALSE;
567 * 16 colors screen, don't use RGB()
569 bool colors16 = FALSE;
572 * Saved instance handle
574 static HINSTANCE hInstance;
577 * Yellow brush for the cursor
579 static HBRUSH hbrYellow;
589 static HPALETTE hPal;
592 static HBITMAP hBG = NULL;
593 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
594 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
597 * The screen saver window
599 static HWND hwndSaver;
602 * 現在使用中のタイルID(0ならば未使用)
603 * Flag set once "graphics" has been initialized
605 static byte current_graphics_mode = 0;
610 static DIBINIT infGraph;
613 * The global bitmap mask
615 static DIBINIT infMask;
618 * Flag set once "sound" has been initialized
620 static bool can_use_sound = FALSE;
622 #define SAMPLE_SOUND_MAX 16
624 * An array of sound file names
626 static concptr sound_file[SOUND_MAX][SAMPLE_SOUND_MAX];
628 #define SAMPLE_MUSIC_MAX 16
629 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
630 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
631 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
632 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
633 static bool can_use_music = FALSE;
635 static MCI_OPEN_PARMS mop;
636 static char mci_device_type[256];
638 int current_music_type = 0;
639 int current_music_id = 0;
642 * Full path to ANGBAND.INI
644 static concptr ini_file = NULL;
647 * Name of application
649 static concptr AppName = "ANGBAND";
652 * Name of sub-window type
654 static concptr AngList = "AngList";
659 static concptr ANGBAND_DIR_XTRA_GRAF;
660 static concptr ANGBAND_DIR_XTRA_SOUND;
661 static concptr ANGBAND_DIR_XTRA_MUSIC;
662 static concptr ANGBAND_DIR_XTRA_HELP;
663 static concptr ANGBAND_DIR_XTRA_MUSIC;
666 * The "complex" color values
668 static COLORREF win_clr[256];
672 * Flag for macro trigger with dump ASCII
674 static bool term_no_press = FALSE;
679 static bool mouse_down = FALSE;
680 static bool paint_rect = FALSE;
681 static TERM_LEN mousex = 0, mousey = 0;
682 static TERM_LEN oldx, oldy;
686 * @brief The "simple" color values
688 * See "main-ibm.c" for original table information
689 * The entries below are taken from the "color bits" defined above.
690 * Note that many of the choices below suck, but so do crappy monitors.
692 static BYTE win_pal[256] =
694 VID_BLACK, /* Dark */
695 VID_WHITE, /* White */
696 VID_CYAN, /* Slate XXX */
697 VID_RED | VID_BRIGHT, /* Orange XXX */
699 VID_GREEN, /* Green */
701 VID_YELLOW, /* Umber XXX */
702 VID_BLACK | VID_BRIGHT, /* Light Dark */
703 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
704 VID_MAGENTA, /* Violet XXX */
705 VID_YELLOW | VID_BRIGHT, /* Yellow */
706 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
707 VID_GREEN | VID_BRIGHT, /* Light Green */
708 VID_BLUE | VID_BRIGHT, /* Light Blue */
709 VID_YELLOW /* Light Umber XXX */
714 * Hack -- define which keys are "special"
716 static bool special_key[256];
717 static bool ignore_key[256];
720 * Hack -- initialization list for "special_key"
722 static byte special_key_list[] = {
723 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
724 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
725 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
726 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
727 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
728 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
729 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
730 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
731 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
732 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
733 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
734 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
735 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
736 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
737 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
738 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
739 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
744 static byte ignore_key_list[] = {
745 VK_ESCAPE, VK_TAB, VK_SPACE,
746 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
747 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
748 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
753 /* Function prototype */
755 static bool is_already_running(void);
759 static void delete_bg(void)
768 static int init_bg(void)
770 char * bmfile = bg_bitmap_file;
773 if (use_bg == 0) return 0;
775 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
777 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
785 static void DrawBG(HDC hdc, RECT *r)
790 int x = r->left, y = r->top;
791 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
797 GetObject(hBG, sizeof(bm), &bm);
798 swid = bm.bmWidth; shgt = bm.bmHeight;
800 hdcSrc = CreateCompatibleDC(hdc);
801 hOld = SelectObject(hdcSrc, hBG);
805 cwid = MIN(swid - sx, r->right - nx);
808 chgt = MIN(shgt - sy, r->bottom - ny);
809 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
811 } while (ny < r->bottom);
814 } while (nx < r->right);
816 SelectObject(hdcSrc, hOld);
822 * Check for existance of a file
824 static bool check_file(concptr s)
844 attrib = GetFileAttributes(path);
846 /* Require valid filename */
847 if (attrib == INVALID_FILE_NAME) return FALSE;
849 /* Prohibit directory */
850 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return FALSE;
854 /* Examine and verify */
855 if (_dos_getfileattr(path, &attrib)) return FALSE;
857 /* Prohibit something */
858 if (attrib & FA_LABEL) return FALSE;
860 /* Prohibit directory */
861 if (attrib & FA_DIREC) return FALSE;
871 * Check for existance of a directory
873 static bool check_dir(concptr s)
895 /* Remove trailing backslash */
896 if (i && (path[i - 1] == '\\')) path[--i] = '\0';
901 attrib = GetFileAttributes(path);
903 /* Require valid filename */
904 if (attrib == INVALID_FILE_NAME) return FALSE;
906 /* Require directory */
907 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return FALSE;
911 /* Examine and verify */
912 if (_dos_getfileattr(path, &attrib)) return FALSE;
914 /* Prohibit something */
915 if (attrib & FA_LABEL) return FALSE;
917 /* Require directory */
918 if (!(attrib & FA_DIREC)) return FALSE;
930 static void validate_file(concptr s)
935 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
941 * Validate a directory
943 static void validate_dir(concptr s, bool vital)
948 /* This directory contains needed data */
951 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
953 /* Attempt to create this directory */
956 quit_fmt("Unable to create directory:\n%s", s);
963 * @brief (Windows版固有実装)Get the "size" for a window
965 static void term_getsize(term_data *td)
969 if (td->cols < 1) td->cols = 1;
970 if (td->rows < 1) td->rows = 1;
973 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
974 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
976 /* Fake window size */
978 rc.right = rc.left + wid;
980 rc.bottom = rc.top + hgt;
983 /* rc.bottom += 1; */
986 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
989 td->size_wid = rc.right - rc.left;
990 td->size_hgt = rc.bottom - rc.top;
992 /* See CreateWindowEx */
995 /* Extract actual location */
996 GetWindowRect(td->w, &rc);
998 /* Save the location */
1005 * Write the "prefs" for a single term
1007 static void save_prefs_aux(int i)
1009 term_data *td = &data[i];
1010 GAME_TEXT sec_name[128];
1014 WINDOWPLACEMENT lpwndpl;
1017 /* Make section name */
1018 sprintf(sec_name, "Term-%d", i);
1023 strcpy(buf, td->visible ? "1" : "0");
1024 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1029 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "MS ゴシック");
1031 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "Courier");
1034 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1036 wsprintf(buf, "%d", td->lf.lfWidth);
1037 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1038 wsprintf(buf, "%d", td->lf.lfHeight);
1039 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1040 wsprintf(buf, "%d", td->lf.lfWeight);
1041 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1043 strcpy(buf, td->bizarre ? "1" : "0");
1044 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1047 wsprintf(buf, "%d", td->tile_wid);
1048 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1051 wsprintf(buf, "%d", td->tile_hgt);
1052 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1054 /* Get window placement and dimensions */
1055 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1056 GetWindowPlacement(td->w, &lpwndpl);
1058 /* Acquire position in *normal* mode (not minimized) */
1059 rc = lpwndpl.rcNormalPosition;
1061 /* Window size (x) */
1062 if (i == 0) wsprintf(buf, "%d", normsize.x);
1063 else wsprintf(buf, "%d", td->cols);
1064 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1066 /* Window size (y) */
1067 if (i == 0) wsprintf(buf, "%d", normsize.y);
1068 else wsprintf(buf, "%d", td->rows);
1069 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1071 /* Maxmized (only main window) */
1074 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1075 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1078 /* Acquire position */
1079 GetWindowRect(td->w, &rc);
1081 /* Window position (x) */
1082 wsprintf(buf, "%d", rc.left);
1083 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1085 /* Window position (y) */
1086 wsprintf(buf, "%d", rc.top);
1087 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1089 /* Window Z position */
1092 strcpy(buf, td->posfix ? "1" : "0");
1093 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1100 * We assume that the windows have all been initialized
1102 static void save_prefs(void)
1108 /* Save the "arg_graphics" flag */
1109 sprintf(buf, "%d", arg_graphics);
1110 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1112 /* Save the "arg_bigtile" flag */
1113 strcpy(buf, arg_bigtile ? "1" : "0");
1114 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1116 /* Save the "arg_sound" flag */
1117 strcpy(buf, arg_sound ? "1" : "0");
1118 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1120 /* Save the "arg_sound" flag */
1121 strcpy(buf, arg_music ? "1" : "0");
1122 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1125 strcpy(buf, use_bg ? "1" : "0");
1126 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1127 WritePrivateProfileString("Angband", "BackGroundBitmap",
1128 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1130 /* Save window prefs */
1131 for (i = 0; i < MAX_TERM_DATA; ++i)
1139 * Load the "prefs" for a single term
1141 static void load_prefs_aux(int i)
1143 term_data *td = &data[i];
1144 GAME_TEXT sec_name[128];
1147 int wid, hgt, posx, posy;
1148 int dispx = GetSystemMetrics(SM_CXVIRTUALSCREEN);
1149 int dispy = GetSystemMetrics(SM_CYVIRTUALSCREEN);
1153 /* Make section name */
1154 sprintf(sec_name, "Term-%d", i);
1156 /* Make section name */
1157 sprintf(sec_name, "Term-%d", i);
1162 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1165 /* Desired font, with default */
1167 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1169 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1174 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1176 /* Analyze font, save desired font name */
1177 td->font_want = string_make(tmp);
1179 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1180 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1181 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1184 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1185 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1188 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1189 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1190 normsize.x = td->cols; normsize.y = td->rows;
1195 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
1198 /* Window position */
1199 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1200 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1201 td->pos_x = MIN(MAX(0, posx), dispx - 128);
1202 td->pos_y = MIN(MAX(0, posy), dispy - 128);
1204 /* Window Z position */
1207 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
1215 static void load_prefs(void)
1219 /* Extract the "arg_graphics" flag */
1220 arg_graphics = (byte)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1222 /* Extract the "arg_bigtile" flag */
1223 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
1224 use_bigtile = arg_bigtile;
1226 /* Extract the "arg_sound" flag */
1227 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1229 /* Extract the "arg_sound" flag */
1230 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1233 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1234 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1236 /* Load window prefs */
1237 for (i = 0; i < MAX_TERM_DATA; ++i)
1245 * - Taken from files.c.
1247 * Extract "tokens" from a buffer
1249 * This function uses "whitespace" as delimiters, and treats any amount of
1250 * whitespace as a single delimiter. We will never return any empty tokens.
1251 * When given an empty buffer, or a buffer containing only "whitespace", we
1252 * will return no tokens. We will never extract more than "num" tokens.
1254 * By running a token through the "text_to_ascii()" function, you can allow
1255 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1257 * We save pointers to the tokens in "tokens", and return the number found.
1259 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1269 /* Skip leading whitespace */
1270 for (; *s && iswspace(*s); ++s) /* loop */;
1275 /* Find next whitespace, if any */
1276 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1278 /* Nuke and advance (if necessary) */
1279 if (*t) *t++ = '\0';
1281 /* Save the token */
1293 static void load_sound_prefs(void)
1297 char ini_path[1024];
1298 char wav_path[1024];
1299 char *zz[SAMPLE_SOUND_MAX];
1301 /* Access the sound.cfg */
1303 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1305 for (i = 0; i < SOUND_MAX; i++)
1307 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1309 num = tokenize_whitespace(tmp, SAMPLE_SOUND_MAX, zz);
1311 for (j = 0; j < num; j++)
1313 /* Access the sound */
1314 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1316 /* Save the sound filename, if it exists */
1317 if (check_file(wav_path))
1318 sound_file[i][j] = string_make(zz[j]);
1324 static void load_music_prefs(void)
1328 char ini_path[1024];
1329 char wav_path[1024];
1330 char *zz[SAMPLE_MUSIC_MAX];
1333 /* Access the music.cfg */
1335 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1337 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1339 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1341 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1343 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1345 for (j = 0; j < num; j++)
1347 /* Access the sound */
1348 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1350 /* Save the sound filename, if it exists */
1351 if (check_file(wav_path))
1352 music_file[i][j] = string_make(zz[j]);
1356 for (i = 0; i < current_world_ptr->max_d_idx; i++)
1358 sprintf(key, "dungeon%03d", i);
1359 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1361 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1363 for (j = 0; j < num; j++)
1365 /* Access the sound */
1366 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1368 /* Save the sound filename, if it exists */
1369 if (check_file(wav_path))
1370 dungeon_music_file[i][j] = string_make(zz[j]);
1374 for (i = 0; i < max_q_idx; i++)
1376 sprintf(key, "quest%03d", i);
1377 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1379 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1381 for (j = 0; j < num; j++)
1383 /* Access the sound */
1384 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1386 /* Save the sound filename, if it exists */
1387 if (check_file(wav_path))
1388 quest_music_file[i][j] = string_make(zz[j]);
1392 for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1394 sprintf(key, "town%03d", i);
1395 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1397 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1399 for (j = 0; j < num; j++)
1401 /* Access the sound */
1402 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1404 /* Save the sound filename, if it exists */
1405 if (check_file(wav_path))
1406 town_music_file[i][j] = string_make(zz[j]);
1415 * Create the new global palette based on the bitmap palette
1416 * (if any), and the standard 16 entry palette derived from
1417 * "win_clr[]" which is used for the basic 16 Angband colors.
1419 * This function is never called before all windows are ready.
1421 * This function returns FALSE if the new palette could not be
1422 * prepared, which should normally be a fatal error. XXX XXX
1424 * Note that only some machines actually use a "palette".
1426 static int new_palette(void)
1434 LPLOGPALETTE pLogPal;
1435 LPPALETTEENTRY lppe;
1440 /* This makes no sense */
1441 if (!paletted) return TRUE;
1449 /* Check the bitmap palette */
1450 hBmPal = infGraph.hPalette;
1452 /* Use the bitmap */
1455 lppeSize = 256 * sizeof(PALETTEENTRY);
1456 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1457 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1458 if ((nEntries == 0) || (nEntries > 220))
1461 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1464 rnfree(lppe, lppeSize);
1471 /* Size of palette */
1472 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1474 /* Allocate palette */
1475 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1478 pLogPal->palVersion = 0x300;
1480 /* Make room for bitmap and normal data */
1481 pLogPal->palNumEntries = nEntries + 16;
1483 /* Save the bitmap data */
1484 for (i = 0; i < nEntries; i++)
1486 pLogPal->palPalEntry[i] = lppe[i];
1489 /* Save the normal data */
1490 for (i = 0; i < 16; i++)
1494 /* Access the entry */
1495 p = &(pLogPal->palPalEntry[i + nEntries]);
1497 /* Save the colors */
1498 p->peRed = GetRValue(win_clr[i]);
1499 p->peGreen = GetGValue(win_clr[i]);
1500 p->peBlue = GetBValue(win_clr[i]);
1502 /* Save the flags */
1503 p->peFlags = PC_NOCOLLAPSE;
1506 /* Free something */
1507 if (lppe) rnfree(lppe, lppeSize);
1509 /* Create a new palette, or fail */
1510 hNewPal = CreatePalette(pLogPal);
1511 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1513 /* Free the palette */
1514 rnfree(pLogPal, pLogPalSize);
1519 /* Realize the palette */
1521 SelectPalette(hdc, hNewPal, 0);
1522 i = RealizePalette(hdc);
1523 ReleaseDC(td->w, hdc);
1524 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1528 for (i = 1; i < MAX_TERM_DATA; i++)
1533 SelectPalette(hdc, hNewPal, 0);
1534 ReleaseDC(td->w, hdc);
1537 /* Delete old palette */
1538 if (hPal) DeleteObject(hPal);
1540 /* Save new palette */
1549 * @brief グラフィクスを初期化する / Initialize graphics
1552 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1553 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1556 static bool init_graphics(void)
1558 /* Initialize once */
1560 BYTE wid, hgt, twid, thgt, ox, oy;
1563 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1573 ANGBAND_GRAF = "new";
1575 else if (arg_graphics == GRAPHICS_HENGBAND)
1595 ANGBAND_GRAF = "ne2";
1606 ANGBAND_GRAF = "old";
1609 /* Access the bitmap file */
1610 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1612 /* Load the bitmap or quit */
1613 if (!ReadDIB(data[0].w, buf, &infGraph))
1615 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1619 /* Save the new sizes */
1620 infGraph.CellWidth = wid;
1621 infGraph.CellHeight = hgt;
1622 infGraph.TileWidth = twid;
1623 infGraph.TileHeight = thgt;
1624 infGraph.OffsetX = ox;
1625 infGraph.OffsetY = oy;
1627 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1629 /* Access the mask file */
1630 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1632 /* Load the bitmap or quit */
1633 if (!ReadDIB(data[0].w, buf, &infMask))
1635 plog_fmt("Cannot read bitmap file '%s'", buf);
1639 if (arg_graphics == GRAPHICS_HENGBAND)
1641 /* Access the mask file */
1642 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1644 /* Load the bitmap or quit */
1645 if (!ReadDIB(data[0].w, buf, &infMask))
1647 plog_fmt("Cannot read bitmap file '%s'", buf);
1652 /* Activate a palette */
1657 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1661 /* Graphics available */
1662 current_graphics_mode = arg_graphics;
1663 return (current_graphics_mode);
1670 static bool init_music(void)
1672 /* Initialize once */
1675 /* Load the prefs */
1678 /* Sound available */
1679 can_use_music = TRUE;
1681 return (can_use_music);
1685 * Hack -- Stop a music
1687 static void stop_music(void)
1689 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1690 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1697 static bool init_sound(void)
1699 /* Initialize once */
1702 /* Load the prefs */
1705 /* Sound available */
1706 can_use_sound = TRUE;
1708 return (can_use_sound);
1715 static void term_window_resize(term_data *td)
1717 /* Require window */
1720 /* Resize the window */
1721 SetWindowPos(td->w, 0, 0, 0,
1722 td->size_wid, td->size_hgt,
1723 SWP_NOMOVE | SWP_NOZORDER);
1726 InvalidateRect(td->w, NULL, TRUE);
1731 * Force the use of a new "font file" for a term_data
1733 * This function may be called before the "window" is ready
1735 * This function returns zero only if everything succeeds.
1737 * Note that the "font name" must be capitalized!!!
1739 static errr term_force_font(term_data *td, concptr path)
1743 /* Forget the old font (if needed) */
1744 if (td->font_id) DeleteObject(td->font_id);
1749 /* Create the font (using the 'base' of the font file name!) */
1750 td->font_id = CreateFontIndirect(&(td->lf));
1751 wid = td->lf.lfWidth;
1752 hgt = td->lf.lfHeight;
1753 if (!td->font_id) return 1;
1755 /* Hack -- Unknown size */
1762 /* all this trouble to get the cell size */
1763 hdcDesktop = GetDC(HWND_DESKTOP);
1764 hfOld = SelectObject(hdcDesktop, td->font_id);
1765 GetTextMetrics(hdcDesktop, &tm);
1766 SelectObject(hdcDesktop, hfOld);
1767 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1769 /* Font size info */
1770 wid = tm.tmAveCharWidth;
1774 /* Save the size info */
1785 * Allow the user to change the font for this window.
1787 static void term_change_font(term_data *td)
1791 memset(&cf, 0, sizeof(cf));
1792 cf.lStructSize = sizeof(cf);
1793 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1794 cf.lpLogFont = &(td->lf);
1796 if (ChooseFont(&cf))
1798 /* Force the font */
1799 term_force_font(td, NULL);
1801 /* Assume not bizarre */
1804 /* Reset the tile info */
1805 td->tile_wid = td->font_wid;
1806 td->tile_hgt = td->font_hgt;
1808 /* Analyze the font */
1811 /* Resize the window */
1812 term_window_resize(td);
1818 * Allow the user to lock this window.
1820 static void term_window_pos(term_data *td, HWND hWnd)
1822 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1823 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1826 static void windows_map(player_type *player_ptr);
1829 * Hack -- redraw a term_data
1831 static void term_data_redraw(player_type *player_ptr, term_data *td)
1835 /* Redraw the map */
1836 windows_map(player_ptr);
1840 /* Activate the term */
1841 Term_activate(&td->t);
1843 /* Redraw the contents */
1846 /* Restore the term */
1847 Term_activate(term_screen);
1852 void term_inversed_area(HWND hWnd, int x, int y, int w, int h)
1856 HBRUSH myBrush, oldBrush;
1858 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
1859 int tx = td->size_ow1 + x * td->tile_wid;
1860 int ty = td->size_oh1 + y * td->tile_hgt;
1861 int tw = w * td->tile_wid - 1;
1862 int th = h * td->tile_hgt - 1;
1865 myBrush = CreateSolidBrush(RGB(255, 255, 255));
1866 oldBrush = SelectObject(hdc, myBrush);
1867 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1869 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
1871 SelectObject(hdc, oldBrush);
1872 SelectObject(hdc, oldPen);
1877 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
1879 static errr term_user_win(int n)
1890 * React to global changes
1892 static errr term_xtra_win_react(player_type *player_ptr)
1899 /* Save the default colors */
1900 for (i = 0; i < 256; i++)
1902 /* Simply accept the desired colors */
1903 win_pal[i] = angband_color_table[i][0];
1914 bool change = FALSE;
1916 /* Save the default colors */
1917 for (i = 0; i < 256; i++)
1919 /* Extract desired values */
1920 rv = angband_color_table[i][1];
1921 gv = angband_color_table[i][2];
1922 bv = angband_color_table[i][3];
1924 /* Extract a full color code */
1925 code = PALETTERGB(rv, gv, bv);
1927 /* Activate changes */
1928 if (win_clr[i] != code)
1930 /* Note the change */
1933 /* Apply the desired color */
1938 /* Activate the palette if needed */
1939 if (change) (void)new_palette();
1942 /* Handle "arg_sound" */
1943 if (use_sound != arg_sound)
1945 /* Initialize (if needed) */
1946 if (arg_sound && !init_sound())
1949 plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
1955 /* Change setting */
1956 use_sound = arg_sound;
1959 /* Handle "arg_sound" */
1960 if (use_music != arg_music)
1962 /* Initialize (if needed) */
1963 if (arg_music && !init_music())
1966 plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
1971 /* Change setting */
1972 use_music = arg_music;
1974 if (!arg_music) stop_music();
1975 else select_floor_music(player_ptr);
1979 /* Handle "arg_graphics" */
1980 if (use_graphics != arg_graphics)
1982 /* Initialize (if needed) */
1983 if (arg_graphics && !init_graphics())
1986 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
1989 arg_graphics = GRAPHICS_NONE;
1992 /* Change setting */
1993 use_graphics = arg_graphics;
1996 reset_visuals(player_ptr);
1999 /* Clean up windows */
2000 for (i = 0; i < MAX_TERM_DATA; i++)
2004 term_data *td = &data[i];
2006 /* Update resized windows */
2007 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
2010 Term_activate(&td->t);
2012 /* Hack -- Resize the term */
2013 Term_resize(td->cols, td->rows);
2015 /* Redraw the contents */
2028 * Process at least one event
2030 static errr term_xtra_win_event(int v)
2034 /* Wait for an event */
2038 if (GetMessage(&msg, NULL, 0, 0))
2040 TranslateMessage(&msg);
2041 DispatchMessage(&msg);
2045 /* Check for an event */
2049 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2051 TranslateMessage(&msg);
2052 DispatchMessage(&msg);
2062 * Process all pending events
2064 static errr term_xtra_win_flush(void)
2068 /* Process all pending events */
2069 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2071 TranslateMessage(&msg);
2072 DispatchMessage(&msg);
2081 * Hack -- clear the screen
2083 * Make this more efficient
2085 static errr term_xtra_win_clear(void)
2087 term_data *td = (term_data*)(Term->data);
2092 /* Rectangle to erase */
2093 rc.left = td->size_ow1;
2094 rc.right = rc.left + td->cols * td->tile_wid;
2095 rc.top = td->size_oh1;
2096 rc.bottom = rc.top + td->rows * td->tile_hgt;
2100 SetBkColor(hdc, RGB(0, 0, 0));
2101 SelectObject(hdc, td->font_id);
2102 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2107 rc.left = 0; rc.top = 0;
2110 ReleaseDC(td->w, hdc);
2118 * Hack -- make a noise
2120 static errr term_xtra_win_noise(void)
2122 MessageBeep(MB_ICONASTERISK);
2128 * Hack -- make a sound
2130 static errr term_xtra_win_sound(int v)
2135 /* Sound disabled */
2136 if (!use_sound) return 1;
2139 if ((v < 0) || (v >= SOUND_MAX)) return 1;
2141 /* Count the samples */
2142 for (i = 0; i < SAMPLE_SOUND_MAX; i++)
2144 if (!sound_file[v][i])
2149 if (i == 0) return 1;
2151 /* Build the path */
2152 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2156 /* Play the sound, catch errors */
2157 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2161 /* Play the sound, catch errors */
2162 return (sndPlaySound(buf, SND_ASYNC));
2168 * Hack -- play a music
2170 static errr term_xtra_win_music(int n, int v)
2174 /* Sound disabled */
2175 if (n == TERM_XTRA_MUSIC_MUTE)
2177 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2178 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2181 if (!use_music) return 1;
2184 if (n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return 1;
2185 else if (v < 0 || v >= 1000) return(1); /*!< TODO */
2189 case TERM_XTRA_MUSIC_BASIC:
2190 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!music_file[v][i]) break;
2192 case TERM_XTRA_MUSIC_DUNGEON:
2193 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!dungeon_music_file[v][i]) break;
2195 case TERM_XTRA_MUSIC_QUEST:
2196 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!quest_music_file[v][i]) break;
2198 case TERM_XTRA_MUSIC_TOWN:
2199 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!town_music_file[v][i]) break;
2211 case TERM_XTRA_MUSIC_BASIC:
2212 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2214 case TERM_XTRA_MUSIC_DUNGEON:
2215 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2217 case TERM_XTRA_MUSIC_QUEST:
2218 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2220 case TERM_XTRA_MUSIC_TOWN:
2221 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2225 if (current_music_type == n && current_music_id == v)
2229 current_music_type = n;
2230 current_music_id = v;
2234 mop.lpstrDeviceType = mci_device_type;
2235 mop.lpstrElementName = buf;
2236 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2237 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2238 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2239 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2240 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2248 * Delay for "x" milliseconds
2250 static int term_xtra_win_delay(int v)
2264 t = GetTickCount() + v;
2267 while (GetTickCount() < t)
2269 /* Handle messages */
2270 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2272 TranslateMessage(&msg);
2273 DispatchMessage(&msg);
2285 * todo z-termに影響があるのでplayer_typeの追加は保留
2286 * Do a "special thing"
2288 static errr term_xtra_win(int n, int v)
2290 /* Handle a subset of the legal requests */
2293 /* Make a bell sound */
2294 case TERM_XTRA_NOISE:
2296 return (term_xtra_win_noise());
2300 case TERM_XTRA_MUSIC_BASIC:
2301 case TERM_XTRA_MUSIC_DUNGEON:
2302 case TERM_XTRA_MUSIC_QUEST:
2303 case TERM_XTRA_MUSIC_TOWN:
2305 return (term_xtra_win_music(n, v));
2308 /* Make a special sound */
2309 case TERM_XTRA_SOUND:
2311 return (term_xtra_win_sound(v));
2314 /* Process random events */
2315 case TERM_XTRA_BORED:
2317 return (term_xtra_win_event(0));
2320 /* Process an event */
2321 case TERM_XTRA_EVENT:
2323 return (term_xtra_win_event(v));
2326 /* Flush all events */
2327 case TERM_XTRA_FLUSH:
2329 return (term_xtra_win_flush());
2332 /* Clear the screen */
2333 case TERM_XTRA_CLEAR:
2335 return (term_xtra_win_clear());
2338 /* React to global changes */
2339 case TERM_XTRA_REACT:
2341 return (term_xtra_win_react(p_ptr));
2344 /* Delay for some milliseconds */
2345 case TERM_XTRA_DELAY:
2347 return (term_xtra_win_delay(v));
2357 * Low level graphics (Assumes valid input).
2359 * Draw a "cursor" at (x,y), using a "yellow box".
2361 static errr term_curs_win(int x, int y)
2363 term_data *td = (term_data*)(Term->data);
2368 int tile_wid, tile_hgt;
2372 tile_wid = td->map_tile_wid;
2373 tile_hgt = td->map_tile_hgt;
2377 tile_wid = td->tile_wid;
2378 tile_hgt = td->tile_hgt;
2381 /* Frame the grid */
2382 rc.left = x * tile_wid + td->size_ow1;
2383 rc.right = rc.left + tile_wid;
2384 rc.top = y * tile_hgt + td->size_oh1;
2385 rc.bottom = rc.top + tile_hgt;
2387 /* Cursor is done as a yellow "box" */
2389 FrameRect(hdc, &rc, hbrYellow);
2390 ReleaseDC(td->w, hdc);
2398 * Low level graphics (Assumes valid input).
2400 * Draw a "big cursor" at (x,y), using a "yellow box".
2402 static errr term_bigcurs_win(int x, int y)
2404 term_data *td = (term_data*)(Term->data);
2409 int tile_wid, tile_hgt;
2413 /* Normal cursor in map window */
2414 term_curs_win(x, y);
2419 tile_wid = td->tile_wid;
2420 tile_hgt = td->tile_hgt;
2423 /* Frame the grid */
2424 rc.left = x * tile_wid + td->size_ow1;
2425 rc.right = rc.left + 2 * tile_wid;
2426 rc.top = y * tile_hgt + td->size_oh1;
2427 rc.bottom = rc.top + tile_hgt;
2429 /* Cursor is done as a yellow "box" */
2431 FrameRect(hdc, &rc, hbrYellow);
2432 ReleaseDC(td->w, hdc);
2440 * Low level graphics (Assumes valid input).
2442 * Erase a "block" of "n" characters starting at (x,y).
2444 static errr term_wipe_win(int x, int y, int n)
2446 term_data *td = (term_data*)(Term->data);
2451 /* Rectangle to erase in client coords */
2452 rc.left = x * td->tile_wid + td->size_ow1;
2453 rc.right = rc.left + n * td->tile_wid;
2454 rc.top = y * td->tile_hgt + td->size_oh1;
2455 rc.bottom = rc.top + td->tile_hgt;
2458 SetBkColor(hdc, RGB(0, 0, 0));
2459 SelectObject(hdc, td->font_id);
2464 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2465 ReleaseDC(td->w, hdc);
2473 * Low level graphics. Assumes valid input.
2475 * Draw several ("n") chars, with an attr, at a given location.
2477 * All "graphic" data is handled by "term_pict_win()", below.
2479 * One would think there is a more efficient method for telling a window
2480 * what color it should be using to draw with, but perhaps simply changing
2481 * it every time is not too inefficient.
2483 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
2485 term_data *td = (term_data*)(Term->data);
2489 static HBITMAP WALL;
2490 static HBRUSH myBrush, oldBrush;
2492 static bool init_done = FALSE;
2495 WALL = LoadBitmap(hInstance, AppName);
2496 myBrush = CreatePatternBrush(WALL);
2500 /* Total rectangle */
2501 rc.left = x * td->tile_wid + td->size_ow1;
2502 rc.right = rc.left + n * td->tile_wid;
2503 rc.top = y * td->tile_hgt + td->size_oh1;
2504 rc.bottom = rc.top + td->tile_hgt;
2509 /* Background color */
2510 SetBkColor(hdc, RGB(0, 0, 0));
2512 /* Foreground color */
2515 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2519 SetTextColor(hdc, win_clr[a & 0x0F]);
2523 SetTextColor(hdc, win_clr[a]);
2527 SelectObject(hdc, td->font_id);
2530 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2534 (td->tile_hgt != td->font_hgt) ||
2535 (td->tile_wid != td->font_wid))
2539 /* Erase complete rectangle */
2540 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2543 if (use_bg) DrawBG(hdc, &rc);
2546 rc.left += ((td->tile_wid - td->font_wid) / 2);
2547 rc.right = rc.left + td->font_wid;
2548 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2549 rc.bottom = rc.top + td->font_hgt;
2551 /* Dump each character */
2552 for (i = 0; i < n; i++)
2555 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1])
2557 rc.right += td->font_wid;
2559 oldBrush = SelectObject(hdc, myBrush);
2560 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
2563 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2565 SelectObject(hdc, oldBrush);
2566 SelectObject(hdc, oldPen);
2567 rc.right -= td->font_wid;
2571 rc.left += 2 * td->tile_wid;
2572 rc.right += 2 * td->tile_wid;
2574 else if (iskanji(*(s + i))) /* 2バイト文字 */
2576 rc.right += td->font_wid;
2578 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2580 rc.right -= td->font_wid;
2584 rc.left += 2 * td->tile_wid;
2585 rc.right += 2 * td->tile_wid;
2587 else if (*(s + i) == 127) {
2588 oldBrush = SelectObject(hdc, myBrush);
2589 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
2592 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2594 SelectObject(hdc, oldBrush);
2595 SelectObject(hdc, oldPen);
2598 rc.left += td->tile_wid;
2599 rc.right += td->tile_wid;
2603 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
2606 rc.left += td->tile_wid;
2607 rc.right += td->tile_wid;
2610 if (*(s + i) == 127) {
2611 oldBrush = SelectObject(hdc, myBrush);
2612 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
2615 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2617 SelectObject(hdc, oldBrush);
2618 SelectObject(hdc, oldPen);
2621 rc.left += td->tile_wid;
2622 rc.right += td->tile_wid;
2626 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2630 rc.left += td->tile_wid;
2631 rc.right += td->tile_wid;
2642 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2647 ReleaseDC(td->w, hdc);
2655 * Low level graphics. Assumes valid input.
2657 * Draw an array of "special" attr/char pairs at the given location.
2659 * We use the "term_pict_win()" function for "graphic" data, which are
2660 * encoded by setting the "high-bits" of both the "attr" and the "char"
2661 * data. We use the "attr" to represent the "row" of the main bitmap,
2662 * and the "char" to represent the "col" of the main bitmap. The use
2663 * of this function is induced by the "higher_pict" flag.
2665 * If "graphics" is not available, we simply "wipe" the given grids.
2667 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)
2669 term_data *td = (term_data*)(Term->data);
2671 TERM_LEN x1, y1, w1, h1, tw1, th1;
2672 TERM_LEN x2, y2, w2, h2, tw2 = 0;
2682 /* Erase the grids */
2683 return (term_wipe_win(x, y, n));
2686 /* Size of bitmap cell */
2687 w1 = infGraph.CellWidth;
2688 h1 = infGraph.CellHeight;
2689 tw1 = infGraph.TileWidth;
2690 th1 = infGraph.TileHeight;
2692 /* Size of window cell */
2695 w2 = td->map_tile_wid;
2696 h2 = td->map_tile_hgt;
2705 if (use_bigtile) tw2 *= 2;
2708 /* Location of window cell */
2709 x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
2710 y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
2716 hdcSrc = CreateCompatibleDC(hdc);
2717 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2719 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2721 hdcMask = CreateCompatibleDC(hdc);
2722 SelectObject(hdcMask, infMask.hBitmap);
2725 /* Draw attr/char pairs */
2726 for (i = 0; i < n; i++, x2 += w2)
2728 TERM_COLOR a = ap[i];
2732 /* Extract picture */
2733 int row = (a & 0x7F);
2734 int col = (c & 0x7F);
2736 /* Location of bitmap cell */
2740 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2742 x3 = (tcp[i] & 0x7F) * w1;
2743 y3 = (tap[i] & 0x7F) * h1;
2744 tw2 = tw2 * w1 / tw1;
2748 if ((tw1 == tw2) && (th1 == h2))
2750 /* Copy the terrain picture from the bitmap to the window */
2751 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2753 /* Mask out the tile */
2754 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2757 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2760 /* Need to stretch */
2763 /* Set the correct mode for stretching the tiles */
2764 SetStretchBltMode(hdc, COLORONCOLOR);
2766 /* Copy the terrain picture from the bitmap to the window */
2767 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
2769 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
2771 /* Only draw if terrain and overlay are different */
2772 if ((x1 != x3) || (y1 != y3))
2774 /* Mask out the tile */
2775 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2778 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2785 if ((w1 == tw2) && (h1 == h2))
2787 /* Copy the picture from the bitmap to the window */
2788 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2791 /* Need to stretch */
2794 /* Set the correct mode for stretching the tiles */
2795 SetStretchBltMode(hdc, COLORONCOLOR);
2797 /* Copy the picture from the bitmap to the window */
2798 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2804 SelectObject(hdcSrc, hbmSrcOld);
2807 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2810 SelectObject(hdcMask, hbmSrcOld);
2815 ReleaseDC(td->w, hdc);
2822 static void windows_map(player_type *player_ptr)
2824 term_data *td = &data[0];
2827 TERM_LEN x, min_x, max_x;
2828 TERM_LEN y, min_y, max_y;
2833 /* Only in graphics mode */
2834 if (!use_graphics) return;
2835 term_xtra_win_clear();
2837 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2838 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2839 td->map_active = TRUE;
2844 max_x = player_ptr->current_floor_ptr->width;
2845 max_y = player_ptr->current_floor_ptr->height;
2849 for (x = min_x; x < max_x; x++)
2851 for (y = min_y; y < max_y; y++)
2853 map_info(player_ptr, y, x, &a, (char*)&c, &ta, (char*)&tc);
2855 /* Ignore non-graphics */
2856 if ((a & 0x80) && (c & 0x80))
2858 term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2863 /* Hilite the player */
2864 term_curs_win(player_ptr->x - min_x, player_ptr->y - min_y);
2866 /* Wait for a keypress, flush key buffer */
2867 Term_inkey(&c, TRUE, TRUE);
2870 /* Switch off the map display */
2871 td->map_active = FALSE;
2873 /* Restore screen */
2874 term_xtra_win_clear();
2879 /*** Other routines ***/
2883 * Create and initialize a "term_data" given a title
2885 static void term_data_link(term_data *td)
2889 /* Initialize the term */
2890 term_init(t, td->cols, td->rows, td->keys);
2892 /* Use a "software" cursor */
2893 t->soft_cursor = TRUE;
2895 /* Use "term_pict" for "graphic" data */
2896 t->higher_pict = TRUE;
2898 /* Erase with "white space" */
2899 t->attr_blank = TERM_WHITE;
2900 t->char_blank = ' ';
2902 /* Prepare the template hooks */
2903 t->user_hook = term_user_win;
2904 t->xtra_hook = term_xtra_win;
2905 t->curs_hook = term_curs_win;
2906 t->bigcurs_hook = term_bigcurs_win;
2907 t->wipe_hook = term_wipe_win;
2908 t->text_hook = term_text_win;
2909 t->pict_hook = term_pict_win;
2911 /* Remember where we came from */
2912 t->data = (vptr)(td);
2917 * Create the windows
2919 * First, instantiate the "default" values, then read the "ini_file"
2920 * to over-ride selected values, then create the windows, and fonts.
2922 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2923 * must make active to realize the palette.
2925 static void init_windows(void)
2933 WIPE(td, term_data);
2937 td->s = angband_term_name[0];
2953 for (i = 1; i < MAX_TERM_DATA; i++)
2956 WIPE(td, term_data);
2957 td->s = angband_term_name[i];
2961 td->visible = FALSE;
2966 td->pos_x = (7 - i) * 30;
2967 td->pos_y = (7 - i) * 20;
2975 /* Main window (need these before term_getsize gets called) */
2977 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2978 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2983 /* Sub windows (need these before term_getsize gets called) */
2984 for (i = 1; i < MAX_TERM_DATA; i++)
2987 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2988 td->dwExStyle = (WS_EX_TOOLWINDOW);
2993 for (i = 0; i < MAX_TERM_DATA; i++)
2997 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2998 td->lf.lfCharSet = DEFAULT_CHARSET;
2999 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3000 /* Activate the chosen font */
3001 term_force_font(td, NULL);
3002 if (!td->tile_wid) td->tile_wid = td->font_wid;
3003 if (!td->tile_hgt) td->tile_hgt = td->font_hgt;
3005 /* Analyze the font */
3008 /* Resize the window */
3009 term_window_resize(td);
3013 /* Sub windows (reverse order) */
3014 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3019 td->w = CreateWindowEx(td->dwExStyle, AngList,
3021 td->pos_x, td->pos_y,
3022 td->size_wid, td->size_hgt,
3023 HWND_DESKTOP, NULL, hInstance, NULL);
3025 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3029 td->size_hack = TRUE;
3030 ShowWindow(td->w, SW_SHOW);
3031 td->size_hack = FALSE;
3035 angband_term[i] = &td->t;
3039 /* Activate the window */
3040 SetActiveWindow(td->w);
3045 term_window_pos(&data[i], HWND_TOPMOST);
3049 term_window_pos(&data[i], td->w);
3059 td->w = CreateWindowEx(td->dwExStyle, AppName,
3061 td->pos_x, td->pos_y,
3062 td->size_wid, td->size_hgt,
3063 HWND_DESKTOP, NULL, hInstance, NULL);
3065 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3068 angband_term[0] = &td->t;
3069 normsize.x = td->cols;
3070 normsize.y = td->rows;
3072 /* Activate the main window */
3073 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3074 else ShowWindow(td->w, SW_SHOW);
3076 /* Bring main window back to top */
3077 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3081 (void)new_palette();
3084 /* Create a "brush" for drawing the "cursor" */
3085 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3088 /* Process pending messages */
3089 (void)term_xtra_win_flush();
3097 static void setup_menus(void)
3101 HMENU hm = GetMenu(data[0].w);
3104 /* Menu "File", Disable all */
3105 EnableMenuItem(hm, IDM_FILE_NEW,
3106 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3107 EnableMenuItem(hm, IDM_FILE_OPEN,
3108 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3109 EnableMenuItem(hm, IDM_FILE_SAVE,
3110 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3111 EnableMenuItem(hm, IDM_FILE_EXIT,
3112 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3113 EnableMenuItem(hm, IDM_FILE_SCORE,
3114 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3117 /* No character available */
3118 if (!current_world_ptr->character_generated)
3120 /* Menu "File", Item "New" */
3121 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3123 /* Menu "File", Item "Open" */
3124 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3127 /* A character available */
3128 if (current_world_ptr->character_generated)
3130 /* Menu "File", Item "Save" */
3131 EnableMenuItem(hm, IDM_FILE_SAVE,
3132 MF_BYCOMMAND | MF_ENABLED);
3135 /* Menu "File", Item "Exit" */
3136 EnableMenuItem(hm, IDM_FILE_EXIT,
3137 MF_BYCOMMAND | MF_ENABLED);
3139 EnableMenuItem(hm, IDM_FILE_SCORE,
3140 MF_BYCOMMAND | MF_ENABLED);
3143 /* Menu "Window::Visibility" */
3144 for (i = 0; i < MAX_TERM_DATA; i++)
3146 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3147 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3149 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3150 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3152 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3153 MF_BYCOMMAND | MF_ENABLED);
3156 /* Menu "Window::Font" */
3157 for (i = 0; i < MAX_TERM_DATA; i++)
3159 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3160 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3162 if (data[i].visible)
3164 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3165 MF_BYCOMMAND | MF_ENABLED);
3169 /* Menu "Window::Window Position Fix" */
3170 for (i = 0; i < MAX_TERM_DATA; i++)
3172 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3173 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3175 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3176 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3178 if (data[i].visible)
3180 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3181 MF_BYCOMMAND | MF_ENABLED);
3185 /* Menu "Window::Bizarre Display" */
3186 for (i = 0; i < MAX_TERM_DATA; i++)
3188 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3189 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3191 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3192 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3194 if (data[i].visible)
3196 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3197 MF_BYCOMMAND | MF_ENABLED);
3202 /* Menu "Window::Increase Tile Width" */
3203 for (i = 0; i < MAX_TERM_DATA; i++)
3205 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3206 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3208 if (data[i].visible)
3210 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3211 MF_BYCOMMAND | MF_ENABLED);
3216 /* Menu "Window::Decrease Tile Width" */
3217 for (i = 0; i < MAX_TERM_DATA; i++)
3219 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3220 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3222 if (data[i].visible)
3224 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3225 MF_BYCOMMAND | MF_ENABLED);
3230 /* Menu "Window::Increase Tile Height" */
3231 for (i = 0; i < MAX_TERM_DATA; i++)
3233 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3234 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3236 if (data[i].visible)
3238 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3239 MF_BYCOMMAND | MF_ENABLED);
3244 /* Menu "Window::Decrease Tile Height" */
3245 for (i = 0; i < MAX_TERM_DATA; i++)
3247 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3248 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3250 if (data[i].visible)
3252 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3253 MF_BYCOMMAND | MF_ENABLED);
3258 /* Menu "Options", disable all */
3259 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3260 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3261 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3262 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3263 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3264 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3265 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3266 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3267 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3268 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3272 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3273 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3276 /* Menu "Options", Item "Map" */
3277 if (use_graphics != GRAPHICS_NONE)
3278 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3280 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3281 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3283 /* Menu "Options", update all */
3284 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3285 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3286 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3287 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3288 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3289 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3290 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3291 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3292 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3293 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3294 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3295 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3296 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3297 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3298 CheckMenuItem(hm, IDM_OPTIONS_BG,
3299 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3302 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3303 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3305 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3306 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3307 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3308 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3309 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3310 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3311 MF_BYCOMMAND | MF_ENABLED);
3316 * Check for double clicked (or dragged) savefile
3318 * Apparently, Windows copies the entire filename into the first
3319 * piece of the "command line string". Perhaps we should extract
3320 * the "basename" of that filename and append it to the "save" dir.
3322 static void check_for_save_file(player_type *player_ptr, LPSTR cmd_line)
3332 /* Extract filename */
3333 strcat(savefile, s);
3335 /* Validate the file */
3336 validate_file(savefile);
3338 /* Game in progress */
3339 game_in_progress = TRUE;
3342 play_game(player_ptr, FALSE);
3347 * Process a menu command
3349 static void process_menus(player_type *player_ptr, WORD wCmd)
3359 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3361 else if (game_in_progress)
3363 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3367 game_in_progress = TRUE;
3369 play_game(player_ptr, TRUE);
3378 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3380 else if (game_in_progress)
3382 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3386 memset(&ofn, 0, sizeof(ofn));
3387 ofn.lStructSize = sizeof(ofn);
3388 ofn.hwndOwner = data[0].w;
3389 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3390 ofn.nFilterIndex = 1;
3391 ofn.lpstrFile = savefile;
3392 ofn.nMaxFile = 1024;
3393 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3394 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3396 if (GetOpenFileName(&ofn))
3398 validate_file(savefile);
3399 game_in_progress = TRUE;
3401 play_game(player_ptr, FALSE);
3409 if (game_in_progress && current_world_ptr->character_generated)
3413 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3418 do_cmd_save_game(player_ptr, FALSE);
3422 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3429 if (game_in_progress && current_world_ptr->character_generated)
3433 plog(_("今は終了できません。", "You may not do that right now."));
3438 forget_lite(player_ptr->current_floor_ptr);
3439 forget_view(player_ptr->current_floor_ptr);
3440 clear_mon_lite(player_ptr->current_floor_ptr);
3442 Term_key_push(SPECIAL_KEY_QUIT);
3449 case IDM_FILE_SCORE:
3452 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3453 highscore_fd = fd_open(buf, O_RDONLY);
3454 if (highscore_fd < 0)
3456 msg_print("Score file unavailable.");
3462 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3463 (void)fd_close(highscore_fd);
3471 case IDM_FILE_MOVIE:
3475 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3477 else if (game_in_progress)
3479 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
3483 memset(&ofn, 0, sizeof(ofn));
3484 ofn.lStructSize = sizeof(ofn);
3485 ofn.hwndOwner = data[0].w;
3486 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3487 ofn.nFilterIndex = 1;
3488 ofn.lpstrFile = savefile;
3489 ofn.nMaxFile = 1024;
3490 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3491 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3493 if (GetOpenFileName(&ofn))
3495 prepare_browse_movie_aux(savefile);
3496 play_game(player_ptr, FALSE);
3503 case IDM_WINDOW_VIS_0:
3505 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
3508 case IDM_WINDOW_VIS_1:
3509 case IDM_WINDOW_VIS_2:
3510 case IDM_WINDOW_VIS_3:
3511 case IDM_WINDOW_VIS_4:
3512 case IDM_WINDOW_VIS_5:
3513 case IDM_WINDOW_VIS_6:
3514 case IDM_WINDOW_VIS_7:
3516 int i = wCmd - IDM_WINDOW_VIS_0;
3517 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3524 ShowWindow(td->w, SW_SHOW);
3525 term_data_redraw(player_ptr, td);
3529 td->visible = FALSE;
3531 ShowWindow(td->w, SW_HIDE);
3536 case IDM_WINDOW_FONT_0:
3537 case IDM_WINDOW_FONT_1:
3538 case IDM_WINDOW_FONT_2:
3539 case IDM_WINDOW_FONT_3:
3540 case IDM_WINDOW_FONT_4:
3541 case IDM_WINDOW_FONT_5:
3542 case IDM_WINDOW_FONT_6:
3543 case IDM_WINDOW_FONT_7:
3545 int i = wCmd - IDM_WINDOW_FONT_0;
3546 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3549 term_change_font(td);
3552 case IDM_WINDOW_POS_1:
3553 case IDM_WINDOW_POS_2:
3554 case IDM_WINDOW_POS_3:
3555 case IDM_WINDOW_POS_4:
3556 case IDM_WINDOW_POS_5:
3557 case IDM_WINDOW_POS_6:
3558 case IDM_WINDOW_POS_7:
3560 int i = wCmd - IDM_WINDOW_POS_0;
3561 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3564 if (!td->posfix && td->visible)
3567 term_window_pos(td, HWND_TOPMOST);
3572 term_window_pos(td, data[0].w);
3577 case IDM_WINDOW_BIZ_0:
3578 case IDM_WINDOW_BIZ_1:
3579 case IDM_WINDOW_BIZ_2:
3580 case IDM_WINDOW_BIZ_3:
3581 case IDM_WINDOW_BIZ_4:
3582 case IDM_WINDOW_BIZ_5:
3583 case IDM_WINDOW_BIZ_6:
3584 case IDM_WINDOW_BIZ_7:
3586 int i = wCmd - IDM_WINDOW_BIZ_0;
3587 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3590 td->bizarre = !td->bizarre;
3592 term_window_resize(td);
3595 case IDM_WINDOW_I_WID_0:
3596 case IDM_WINDOW_I_WID_1:
3597 case IDM_WINDOW_I_WID_2:
3598 case IDM_WINDOW_I_WID_3:
3599 case IDM_WINDOW_I_WID_4:
3600 case IDM_WINDOW_I_WID_5:
3601 case IDM_WINDOW_I_WID_6:
3602 case IDM_WINDOW_I_WID_7:
3604 int i = wCmd - IDM_WINDOW_I_WID_0;
3605 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3610 term_window_resize(td);
3613 case IDM_WINDOW_D_WID_0:
3614 case IDM_WINDOW_D_WID_1:
3615 case IDM_WINDOW_D_WID_2:
3616 case IDM_WINDOW_D_WID_3:
3617 case IDM_WINDOW_D_WID_4:
3618 case IDM_WINDOW_D_WID_5:
3619 case IDM_WINDOW_D_WID_6:
3620 case IDM_WINDOW_D_WID_7:
3622 int i = wCmd - IDM_WINDOW_D_WID_0;
3623 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3628 term_window_resize(td);
3631 case IDM_WINDOW_I_HGT_0:
3632 case IDM_WINDOW_I_HGT_1:
3633 case IDM_WINDOW_I_HGT_2:
3634 case IDM_WINDOW_I_HGT_3:
3635 case IDM_WINDOW_I_HGT_4:
3636 case IDM_WINDOW_I_HGT_5:
3637 case IDM_WINDOW_I_HGT_6:
3638 case IDM_WINDOW_I_HGT_7:
3640 int i = wCmd - IDM_WINDOW_I_HGT_0;
3641 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3646 term_window_resize(td);
3649 case IDM_WINDOW_D_HGT_0:
3650 case IDM_WINDOW_D_HGT_1:
3651 case IDM_WINDOW_D_HGT_2:
3652 case IDM_WINDOW_D_HGT_3:
3653 case IDM_WINDOW_D_HGT_4:
3654 case IDM_WINDOW_D_HGT_5:
3655 case IDM_WINDOW_D_HGT_6:
3656 case IDM_WINDOW_D_HGT_7:
3658 int i = wCmd - IDM_WINDOW_D_HGT_0;
3659 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3664 term_window_resize(td);
3667 case IDM_OPTIONS_NO_GRAPHICS:
3671 plog("You may not do that right now.");
3675 if (arg_graphics != GRAPHICS_NONE)
3677 arg_graphics = GRAPHICS_NONE;
3678 term_xtra_win_react(player_ptr);
3679 Term_key_push(KTRL('R'));
3684 case IDM_OPTIONS_OLD_GRAPHICS:
3688 plog("You may not do that right now.");
3692 if (arg_graphics != GRAPHICS_ORIGINAL)
3694 arg_graphics = GRAPHICS_ORIGINAL;
3695 term_xtra_win_react(player_ptr);
3696 Term_key_push(KTRL('R'));
3701 case IDM_OPTIONS_NEW_GRAPHICS:
3705 plog("You may not do that right now.");
3709 if (arg_graphics != GRAPHICS_ADAM_BOLT)
3711 arg_graphics = GRAPHICS_ADAM_BOLT;
3712 term_xtra_win_react(player_ptr);
3713 Term_key_push(KTRL('R'));
3718 case IDM_OPTIONS_NEW2_GRAPHICS:
3722 plog("You may not do that right now.");
3726 if (arg_graphics != GRAPHICS_HENGBAND)
3728 arg_graphics = GRAPHICS_HENGBAND;
3729 term_xtra_win_react(player_ptr);
3730 Term_key_push(KTRL('R'));
3735 case IDM_OPTIONS_BIGTILE:
3740 plog("You may not do that right now.");
3744 arg_bigtile = !arg_bigtile;
3745 Term_activate(&td->t);
3746 Term_resize(td->cols, td->rows);
3747 InvalidateRect(td->w, NULL, TRUE);
3750 case IDM_OPTIONS_MUSIC:
3754 plog("You may not do that right now.");
3758 arg_music = !arg_music;
3759 term_xtra_win_react(player_ptr);
3760 Term_key_push(KTRL('R'));
3763 case IDM_OPTIONS_SOUND:
3767 plog("You may not do that right now.");
3771 arg_sound = !arg_sound;
3772 term_xtra_win_react(player_ptr);
3773 Term_key_push(KTRL('R'));
3776 case IDM_OPTIONS_BG:
3780 plog("You may not do that right now.");
3786 term_xtra_win_react(player_ptr);
3787 Term_key_push(KTRL('R'));
3790 case IDM_OPTIONS_OPEN_BG:
3794 plog("You may not do that right now.");
3799 memset(&ofn, 0, sizeof(ofn));
3800 ofn.lStructSize = sizeof(ofn);
3801 ofn.hwndOwner = data[0].w;
3802 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3803 ofn.nFilterIndex = 1;
3804 ofn.lpstrFile = bg_bitmap_file;
3805 ofn.nMaxFile = 1023;
3806 ofn.lpstrInitialDir = NULL;
3807 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
3808 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3810 if (GetOpenFileName(&ofn))
3816 term_xtra_win_react(player_ptr);
3817 Term_key_push(KTRL('R'));
3822 case IDM_DUMP_SCREEN_HTML:
3824 static char buf[1024] = "";
3825 memset(&ofn, 0, sizeof(ofn));
3826 ofn.lStructSize = sizeof(ofn);
3827 ofn.hwndOwner = data[0].w;
3828 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
3829 ofn.nFilterIndex = 1;
3830 ofn.lpstrFile = buf;
3831 ofn.nMaxFile = 1023;
3832 ofn.lpstrDefExt = "html";
3833 ofn.lpstrInitialDir = NULL;
3834 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
3835 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
3837 if (GetSaveFileName(&ofn))
3839 do_cmd_save_screen_html_aux(buf, 0);
3843 case IDM_OPTIONS_SAVER:
3847 DestroyWindow(hwndSaver);
3852 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
3853 "Angband Screensaver",
3854 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
3855 0, 0, GetSystemMetrics(SM_CXSCREEN),
3856 GetSystemMetrics(SM_CYSCREEN),
3857 NULL, NULL, hInstance, NULL);
3861 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3865 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
3871 case IDM_OPTIONS_MAP:
3873 windows_map(player_ptr);
3877 case IDM_HELP_CONTENTS:
3881 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
3882 if (check_file(tmp))
3884 sprintf(buf, "winhelp.exe %s", tmp);
3885 WinExec(buf, SW_NORMAL);
3889 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
3890 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
3899 static bool process_keydown(WPARAM wParam, LPARAM lParam)
3905 /* Extract the modifiers */
3906 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
3907 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
3908 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
3910 term_no_press = (ma) ? TRUE : FALSE;
3912 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]))
3914 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
3915 bool numpad = FALSE;
3918 if (mc) Term_keypress('C');
3919 if (ms) Term_keypress('S');
3920 if (ma) Term_keypress('A');
3922 int i = LOBYTE(HIWORD(lParam));
3927 term_no_press = TRUE;
3946 term_no_press = TRUE;
3961 if (numpad) Term_keypress('K');
3963 Term_keypress(hexsym[i / 16]);
3964 Term_keypress(hexsym[i % 16]);
3975 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
3977 LRESULT PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3982 td = (term_data *)GetWindowLong(hWnd, 0);
3988 SetWindowLong(hWnd, 0, (LONG)(my_td));
3993 mop.dwCallback = (DWORD)hWnd;
3996 case WM_GETMINMAXINFO:
4001 lpmmi = (MINMAXINFO*)lParam;
4004 rc.left = rc.top = 0;
4005 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4006 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4008 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4010 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4011 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4017 BeginPaint(hWnd, &ps);
4018 if (td) term_data_redraw(p_ptr, td);
4019 EndPaint(hWnd, &ps);
4020 ValidateRect(hWnd, NULL);
4025 if (wParam == MCI_NOTIFY_SUCCESSFUL)
4027 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4028 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4036 if (process_keydown(wParam, lParam))
4042 if (term_no_press) term_no_press = FALSE;
4043 else Term_keypress(wParam);
4046 case WM_LBUTTONDOWN:
4048 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4049 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4059 TERM_LEN dx = abs(oldx - mousex) + 1;
4060 TERM_LEN dy = abs(oldy - mousey) + 1;
4061 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
4062 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
4068 int sz = (dx + 3) * dy;
4070 int sz = (dx + 2) * dy;
4072 hGlobal = GlobalAlloc(GHND, sz + 1);
4073 if (hGlobal == NULL) return 0;
4074 lpStr = (LPSTR)GlobalLock(hGlobal);
4076 for (int i = 0; i < dy; i++)
4080 char **scr = data[0].t.scr->c;
4082 C_MAKE(s, (dx + 1), char);
4083 strncpy(s, &scr[oy + i][ox], dx);
4087 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4090 if (ox + dx < data[0].cols)
4092 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4095 for (int j = 0; j < dx; j++)
4097 if (s[j] == 127) s[j] = '#';
4101 for (int j = 0; j < dx; j++)
4103 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4113 GlobalUnlock(hGlobal);
4114 if (OpenClipboard(hWnd) == 0)
4116 GlobalFree(hGlobal);
4120 SetClipboardData(CF_TEXT, hGlobal);
4132 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4133 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4138 dx = abs(oldx - mousex) + 1;
4139 dy = abs(oldy - mousey) + 1;
4140 ox = (oldx > mousex) ? mousex : oldx;
4141 oy = (oldy > mousey) ? mousey : oldy;
4142 term_inversed_area(hWnd, ox, oy, dx, dy);
4149 dx = abs(cx - mousex) + 1;
4150 dy = abs(cy - mousey) + 1;
4151 ox = (cx > mousex) ? mousex : cx;
4152 oy = (cy > mousey) ? mousey : cy;
4153 term_inversed_area(hWnd, ox, oy, dx, dy);
4168 if (game_in_progress && current_world_ptr->character_generated)
4172 plog(_("今は終了できません。", "You may not do that right now."));
4177 forget_lite(p_ptr->current_floor_ptr);
4178 forget_view(p_ptr->current_floor_ptr);
4179 clear_mon_lite(p_ptr->current_floor_ptr);
4180 Term_key_push(SPECIAL_KEY_QUIT);
4187 case WM_QUERYENDSESSION:
4189 if (game_in_progress && current_world_ptr->character_generated)
4192 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4193 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4195 p_ptr->panic_save = 1;
4196 signals_ignore_tstp();
4197 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4198 (void)save_player(p_ptr);
4211 process_menus(p_ptr, LOWORD(wParam));
4217 if (!td->w) return 1;
4218 if (td->size_hack) return 1;
4222 case SIZE_MINIMIZED:
4224 /* Hide sub-windows */
4225 for (int i = 1; i < MAX_TERM_DATA; i++)
4227 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4232 case SIZE_MAXIMIZED:
4238 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4239 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4240 if ((td->cols != cols) || (td->rows != rows))
4244 if (!IsZoomed(td->w) && !IsIconic(td->w))
4246 normsize.x = td->cols;
4247 normsize.y = td->rows;
4250 Term_activate(&td->t);
4251 Term_resize(td->cols, td->rows);
4252 InvalidateRect(td->w, NULL, TRUE);
4255 td->size_hack = TRUE;
4256 for (int i = 1; i < MAX_TERM_DATA; i++)
4258 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4261 td->size_hack = FALSE;
4269 case WM_PALETTECHANGED:
4271 if ((HWND)wParam == hWnd) return 0;
4273 case WM_QUERYNEWPALETTE:
4275 if (!paletted) return 0;
4278 SelectPalette(hdc, hPal, FALSE);
4279 int i = RealizePalette(hdc);
4280 if (i) InvalidateRect(hWnd, NULL, TRUE);
4282 ReleaseDC(hWnd, hdc);
4287 if (wParam && !HIWORD(lParam))
4289 for (int i = 1; i < MAX_TERM_DATA; i++)
4291 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4300 case WM_ACTIVATEAPP:
4302 if (IsIconic(td->w)) break;
4304 for (int i = 1; i < MAX_TERM_DATA; i++)
4306 if (data[i].visible)
4310 ShowWindow(data[i].w, SW_SHOW);
4314 ShowWindow(data[i].w, SW_HIDE);
4321 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4326 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
4328 LRESULT PASCAL AngbandListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4333 td = (term_data *)GetWindowLong(hWnd, 0);
4339 SetWindowLong(hWnd, 0, (LONG)(my_td));
4346 case WM_GETMINMAXINFO:
4351 lpmmi = (MINMAXINFO*)lParam;
4354 rc.left = rc.top = 0;
4355 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4356 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4358 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4359 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4360 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4367 if (!td->w) return 1;
4368 if (td->size_hack) return 1;
4370 td->size_hack = TRUE;
4372 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4373 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4374 if ((td->cols != cols) || (td->rows != rows))
4376 term *old_term = Term;
4379 Term_activate(&td->t);
4380 Term_resize(td->cols, td->rows);
4381 Term_activate(old_term);
4382 InvalidateRect(td->w, NULL, TRUE);
4383 p_ptr->window = 0xFFFFFFFF;
4384 handle_stuff(p_ptr);
4387 td->size_hack = FALSE;
4393 BeginPaint(hWnd, &ps);
4394 if (td) term_data_redraw(p_ptr, td);
4395 EndPaint(hWnd, &ps);
4401 if (process_keydown(wParam, lParam))
4407 if (term_no_press) term_no_press = FALSE;
4408 else Term_keypress(wParam);
4411 case WM_PALETTECHANGED:
4413 if ((HWND)wParam == hWnd) return FALSE;
4415 case WM_QUERYNEWPALETTE:
4417 if (!paletted) return 0;
4419 SelectPalette(hdc, hPal, FALSE);
4420 int i = RealizePalette(hdc);
4421 if (i) InvalidateRect(hWnd, NULL, TRUE);
4422 ReleaseDC(hWnd, hdc);
4425 case WM_NCLBUTTONDOWN:
4428 if (wParam == HTCLOSE) wParam = HTSYSMENU;
4429 #endif /* HTCLOSE */
4431 if (wParam == HTSYSMENU)
4435 td->visible = FALSE;
4436 ShowWindow(td->w, SW_HIDE);
4446 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4450 #define MOUSE_SENS 40
4452 LRESULT PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4454 static int iMouse = 0;
4455 static WORD xMouse = 0;
4456 static WORD yMouse = 0;
4471 case WM_LBUTTONDOWN:
4472 case WM_MBUTTONDOWN:
4473 case WM_RBUTTONDOWN:
4476 SendMessage(hWnd, WM_CLOSE, 0, 0);
4483 int dx = LOWORD(lParam) - xMouse;
4484 int dy = HIWORD(lParam) - yMouse;
4486 if (dx < 0) dx = -dx;
4487 if (dy < 0) dy = -dy;
4489 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
4491 SendMessage(hWnd, WM_CLOSE, 0, 0);
4496 xMouse = LOWORD(lParam);
4497 yMouse = HIWORD(lParam);
4503 DestroyWindow(hwndSaver);
4509 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4514 * Display warning message (see "z-util.c")
4516 static void hack_plog(concptr str)
4521 MessageBox(NULL, str, "警告!",
4522 MB_ICONEXCLAMATION | MB_OK);
4524 MessageBox(NULL, str, "Warning",
4525 MB_ICONEXCLAMATION | MB_OK);
4533 * Display error message and quit (see "z-util.c")
4535 static void hack_quit(concptr str)
4540 MessageBox(NULL, str, "エラー!",
4541 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4543 MessageBox(NULL, str, "Error",
4544 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4549 UnregisterClass(AppName, hInstance);
4550 if (hIcon) DestroyIcon(hIcon);
4557 * Display warning message (see "z-util.c")
4559 static void hook_plog(concptr str)
4564 MessageBox(data[0].w, str, "警告!",
4565 MB_ICONEXCLAMATION | MB_OK);
4567 MessageBox(data[0].w, str, "Warning",
4568 MB_ICONEXCLAMATION | MB_OK);
4576 * Display error message and quit (see "z-util.c")
4578 static void hook_quit(concptr str)
4583 MessageBox(data[0].w, str, "エラー!",
4584 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4586 MessageBox(data[0].w, str, "Error",
4587 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4592 for (int i = MAX_TERM_DATA - 1; i >= 0; --i)
4594 term_force_font(&data[i], NULL);
4595 if (data[i].font_want) string_free(data[i].font_want);
4596 if (data[i].w) DestroyWindow(data[i].w);
4600 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
4601 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
4602 if (infMask.hPalette) DeleteObject(infMask.hPalette);
4603 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
4605 DeleteObject(hbrYellow);
4608 if (hPal) DeleteObject(hPal);
4610 UnregisterClass(AppName, hInstance);
4611 if (hIcon) DestroyIcon(hIcon);
4620 static void init_stuff(void)
4623 GetModuleFileName(hInstance, path, 512);
4625 strcpy(path + strlen(path) - 4, ".INI");
4626 ini_file = string_make(path);
4627 int i = strlen(path);
4631 if (path[i] == '\\')
4637 strcpy(path + i + 1, "lib\\");
4638 validate_dir(path, TRUE);
4639 init_file_paths(path);
4640 validate_dir(ANGBAND_DIR_APEX, FALSE);
4641 validate_dir(ANGBAND_DIR_BONE, FALSE);
4642 if (!check_dir(ANGBAND_DIR_EDIT))
4644 validate_dir(ANGBAND_DIR_DATA, TRUE);
4648 validate_dir(ANGBAND_DIR_DATA, FALSE);
4651 validate_dir(ANGBAND_DIR_FILE, TRUE);
4652 validate_dir(ANGBAND_DIR_HELP, FALSE);
4653 validate_dir(ANGBAND_DIR_INFO, FALSE);
4654 validate_dir(ANGBAND_DIR_PREF, TRUE);
4655 validate_dir(ANGBAND_DIR_SAVE, FALSE);
4656 validate_dir(ANGBAND_DIR_USER, TRUE);
4657 validate_dir(ANGBAND_DIR_XTRA, TRUE);
4658 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
4660 validate_file(path);
4661 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
4662 ANGBAND_DIR_XTRA_GRAF = string_make(path);
4663 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
4665 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
4666 ANGBAND_DIR_XTRA_SOUND = string_make(path);
4667 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
4669 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
4670 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
4671 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
4673 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
4674 ANGBAND_DIR_XTRA_HELP = string_make(path);
4679 * todo よく見るとhMutexはちゃんと使われていない……?
4680 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
4682 static bool is_already_running(void)
4685 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
4686 if (GetLastError() == ERROR_ALREADY_EXISTS)
4696 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
4698 int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
4704 setlocale(LC_ALL, "ja_JP");
4707 if (is_already_running())
4710 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
4712 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4716 if (hPrevInst == NULL)
4718 wc.style = CS_CLASSDC;
4719 wc.lpfnWndProc = AngbandWndProc;
4722 wc.hInstance = hInst;
4723 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
4724 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
4725 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
4726 wc.lpszMenuName = AppName;
4727 wc.lpszClassName = AppName;
4729 if (!RegisterClass(&wc)) exit(1);
4731 wc.lpfnWndProc = AngbandListProc;
4732 wc.lpszMenuName = NULL;
4733 wc.lpszClassName = AngList;
4735 if (!RegisterClass(&wc)) exit(2);
4737 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
4738 wc.lpfnWndProc = AngbandSaverProc;
4740 wc.lpszMenuName = NULL;
4741 wc.lpszClassName = "WindowsScreenSaverClass";
4743 if (!RegisterClass(&wc)) exit(3);
4746 plog_aux = hack_plog;
4747 quit_aux = hack_quit;
4748 core_aux = hack_quit;
4751 for (int i = 0; special_key_list[i]; ++i)
4753 special_key[special_key_list[i]] = TRUE;
4756 for (int i = 0; ignore_key_list[i]; ++i)
4758 ignore_key[ignore_key_list[i]] = TRUE;
4762 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
4763 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
4764 ReleaseDC(NULL, hdc);
4766 for (int i = 0; i < 256; i++)
4768 byte rv = angband_color_table[i][1];
4769 byte gv = angband_color_table[i][2];
4770 byte bv = angband_color_table[i][3];
4771 win_clr[i] = PALETTERGB(rv, gv, bv);
4772 angband_color_table[i][0] = win_pal[i];
4778 plog_aux = hook_plog;
4779 quit_aux = hook_quit;
4780 core_aux = hook_quit;
4782 ANGBAND_SYS = "win";
4783 if (7 != GetKeyboardType(0))
4784 ANGBAND_KEYBOARD = "0";
4787 /* todo PC-98のサポートは打ち切ったので削除したい */
4788 switch (GetKeyboardType(1))
4790 case 0x0D01: case 0x0D02:
4791 case 0x0D03: case 0x0D04:
4792 case 0x0D05: case 0x0D06:
4794 ANGBAND_KEYBOARD = "NEC98";
4798 ANGBAND_KEYBOARD = "JAPAN";
4803 Term_activate(term_screen);
4804 init_angband(p_ptr);
4807 if (lpCmdLine[0] == '-') {
4808 switch (lpCmdLine[1])
4813 if (!lpCmdLine[2]) break;
4814 chuukei_server = TRUE;
4815 if (connect_chuukei_server(&lpCmdLine[2]) < 0) {
4816 msg_print("connect fail");
4819 msg_print("connect");
4827 if (!lpCmdLine[2]) break;
4828 chuukei_client = TRUE;
4829 connect_chuukei_server(&lpCmdLine[2]);
4830 play_game(player_ptr, FALSE);
4837 if (!lpCmdLine[2]) break;
4838 prepare_browse_movie(&lpCmdLine[2]);
4839 play_game(player_ptr, FALSE);
4848 if (!chuukei_server) check_for_save_file(lpCmdLine);
4850 check_for_save_file(p_ptr, lpCmdLine);
4853 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
4855 while (GetMessage(&msg, NULL, 0, 0))
4857 TranslateMessage(&msg);
4858 DispatchMessage(&msg);
4864 #endif /* WINDOWS */