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 * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
36 * and/or color redefinitions.
40 * The "lib/user/font-win.prf" contains attr/char mappings for use with the
41 * normal "lib/xtra/font/*.fon" font files.
45 * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
46 * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
51 * Compiling this file, and using the resulting executable, requires
52 * several extra files not distributed with the standard Angband code.
53 * In any case, some "*.fon" files (including "8X13.FON" if nothing else)
54 * must be placed into "lib/xtra/font/". All of these extra files can be found
55 * in the "ext-win" archive.
59 * The "term_xtra_win_clear()" function should probably do a low-level
60 * clear of the current window, and redraw the borders and other things,
61 * if only for efficiency.
65 * A simpler method is needed for selecting the "tile size" for windows.
69 * The various "warning" messages assume the existance of the "screen.w"
70 * window, I think, and only a few calls actually check for its existance,
71 * this may be okay since "NULL" means "on top of all windows". (?) The
72 * user must never be allowed to "hide" the main window, or the "menubar"
77 * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
78 * use with the "winhelp.exe" program. These files *may* be available
79 * at the ftp site somewhere, but I have not seen them.
83 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
85 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
87 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
88 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
92 #include "autopick/autopick-pref-processor.h"
93 #include "cmd-io/cmd-process-screen.h"
94 #include "cmd-io/cmd-save.h"
95 #include "core/game-play.h"
96 #include "core/player-processor.h"
97 #include "core/scores.h"
98 #include "core/special-internal-keys.h"
99 #include "core/stuff-handler.h"
100 #include "core/visuals-reseter.h"
101 #include "dungeon/quest.h"
102 #include "floor/floor-base-definitions.h"
103 #include "floor/floor-events.h"
104 #include "game-option/game-play-options.h"
105 #include "game-option/runtime-arguments.h"
106 #include "game-option/special-options.h"
107 #include "io/files-util.h"
109 #include "io/input-key-acceptor.h"
110 #include "io/record-play-movie.h"
111 #include "io/signal-handlers.h"
112 #include "io/write-diary.h"
113 #include "main/angband-initializer.h"
114 #include "main/music-definitions-table.h"
115 #include "main/sound-definitions-table.h"
116 #include "main/sound-of-music.h"
117 #include "monster-floor/monster-lite.h"
118 #include "system/angband-version.h"
119 #include "system/angband.h"
120 #include "system/floor-type-definition.h"
121 #include "system/system-variables.h"
122 #include "term/gameterm.h"
123 #include "term/screen-processor.h"
124 #include "term/term-color-types.h"
125 #include "util/angband-files.h"
126 #include "util/int-char-converter.h"
127 #include "util/string-processor.h"
128 #include "view/display-map.h"
129 #include "view/display-messages.h"
130 #include "wizard/spoiler-util.h"
131 #include "wizard/wizard-spoiler.h"
132 #include "world/world.h"
135 #include "dungeon/dungeon.h"
136 #include "save/save.h"
142 * Available graphic modes
144 #define GRAPHICS_NONE 0
145 #define GRAPHICS_ORIGINAL 1
146 #define GRAPHICS_ADAM_BOLT 2
147 #define GRAPHICS_HENGBAND 3
150 * Menu constants -- see "ANGBAND.RC"
152 #define IDM_FILE_NEW 100
153 #define IDM_FILE_OPEN 101
154 #define IDM_FILE_SAVE 110
155 #define IDM_FILE_SCORE 120
156 #define IDM_FILE_MOVIE 121
157 #define IDM_FILE_EXIT 130
159 #define IDM_WINDOW_VIS_0 200
160 #define IDM_WINDOW_VIS_1 201
161 #define IDM_WINDOW_VIS_2 202
162 #define IDM_WINDOW_VIS_3 203
163 #define IDM_WINDOW_VIS_4 204
164 #define IDM_WINDOW_VIS_5 205
165 #define IDM_WINDOW_VIS_6 206
166 #define IDM_WINDOW_VIS_7 207
168 #define IDM_WINDOW_FONT_0 210
169 #define IDM_WINDOW_FONT_1 211
170 #define IDM_WINDOW_FONT_2 212
171 #define IDM_WINDOW_FONT_3 213
172 #define IDM_WINDOW_FONT_4 214
173 #define IDM_WINDOW_FONT_5 215
174 #define IDM_WINDOW_FONT_6 216
175 #define IDM_WINDOW_FONT_7 217
177 #define IDM_WINDOW_POS_0 220
178 #define IDM_WINDOW_POS_1 221
179 #define IDM_WINDOW_POS_2 222
180 #define IDM_WINDOW_POS_3 223
181 #define IDM_WINDOW_POS_4 224
182 #define IDM_WINDOW_POS_5 225
183 #define IDM_WINDOW_POS_6 226
184 #define IDM_WINDOW_POS_7 227
186 #define IDM_WINDOW_BIZ_0 230
187 #define IDM_WINDOW_BIZ_1 231
188 #define IDM_WINDOW_BIZ_2 232
189 #define IDM_WINDOW_BIZ_3 233
190 #define IDM_WINDOW_BIZ_4 234
191 #define IDM_WINDOW_BIZ_5 235
192 #define IDM_WINDOW_BIZ_6 236
193 #define IDM_WINDOW_BIZ_7 237
195 #define IDM_WINDOW_I_WID_0 240
196 #define IDM_WINDOW_I_WID_1 241
197 #define IDM_WINDOW_I_WID_2 242
198 #define IDM_WINDOW_I_WID_3 243
199 #define IDM_WINDOW_I_WID_4 244
200 #define IDM_WINDOW_I_WID_5 245
201 #define IDM_WINDOW_I_WID_6 246
202 #define IDM_WINDOW_I_WID_7 247
204 #define IDM_WINDOW_D_WID_0 250
205 #define IDM_WINDOW_D_WID_1 251
206 #define IDM_WINDOW_D_WID_2 252
207 #define IDM_WINDOW_D_WID_3 253
208 #define IDM_WINDOW_D_WID_4 254
209 #define IDM_WINDOW_D_WID_5 255
210 #define IDM_WINDOW_D_WID_6 256
211 #define IDM_WINDOW_D_WID_7 257
213 #define IDM_WINDOW_I_HGT_0 260
214 #define IDM_WINDOW_I_HGT_1 261
215 #define IDM_WINDOW_I_HGT_2 262
216 #define IDM_WINDOW_I_HGT_3 263
217 #define IDM_WINDOW_I_HGT_4 264
218 #define IDM_WINDOW_I_HGT_5 265
219 #define IDM_WINDOW_I_HGT_6 266
220 #define IDM_WINDOW_I_HGT_7 267
222 #define IDM_WINDOW_D_HGT_0 270
223 #define IDM_WINDOW_D_HGT_1 271
224 #define IDM_WINDOW_D_HGT_2 272
225 #define IDM_WINDOW_D_HGT_3 273
226 #define IDM_WINDOW_D_HGT_4 274
227 #define IDM_WINDOW_D_HGT_5 275
228 #define IDM_WINDOW_D_HGT_6 276
229 #define IDM_WINDOW_D_HGT_7 277
231 #define IDM_WINDOW_KEEP_SUBWINDOWS 280
233 #define IDM_OPTIONS_NO_GRAPHICS 400
234 #define IDM_OPTIONS_OLD_GRAPHICS 401
235 #define IDM_OPTIONS_NEW_GRAPHICS 402
236 #define IDM_OPTIONS_NEW2_GRAPHICS 403
237 #define IDM_OPTIONS_BIGTILE 409
238 #define IDM_OPTIONS_SOUND 410
239 #define IDM_OPTIONS_MUSIC 411
240 #define IDM_OPTIONS_SAVER 420
241 #define IDM_OPTIONS_MAP 430
242 #define IDM_OPTIONS_BG 440
243 #define IDM_OPTIONS_OPEN_BG 441
245 #define IDM_DUMP_SCREEN_HTML 450
247 #define IDM_HELP_CONTENTS 901
250 * Exclude parts of WINDOWS.H that are not needed (Win32)
252 #define WIN32_LEAN_AND_MEAN
253 #define NONLS /* All NLS defines and routines */
254 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
255 #define NOMCX /* Modem Configuration Extensions */
258 * Include the "windows" support file
263 * Exclude parts of MMSYSTEM.H that are not needed
265 #define MMNODRV /* Installable driver support */
266 #define MMNOWAVE /* Waveform support */
267 #define MMNOMIDI /* MIDI support */
268 #define MMNOAUX /* Auxiliary audio support */
269 #define MMNOTIMER /* Timer support */
270 #define MMNOJOY /* Joystick support */
271 #define MMNOMCI /* MCI support */
272 #define MMNOMMIO /* Multimedia file I/O support */
274 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
275 #define MOUSE_SENS 40
278 * Include some more files. Note: the Cygnus Cygwin compiler
279 * doesn't use mmsystem.h instead it includes the winmm library
280 * which performs a similar function.
283 #include <mmsystem.h>
286 * Include the support for loading bitmaps
288 #include "term/readdib.h"
290 #define MoveTo(H, X, Y) MoveToEx(H, X, Y, NULL)
293 * Foreground color bits
295 #define VID_BLACK 0x00
296 #define VID_BLUE 0x01
297 #define VID_GREEN 0x02
298 #define VID_CYAN 0x03
300 #define VID_MAGENTA 0x05
301 #define VID_YELLOW 0x06
302 #define VID_WHITE 0x07
307 #define VID_BRIGHT 0x08
311 * @brief ターム情報構造体 / Extra "term" data
314 * pos_x / pos_y は各タームの左上点座標を指す。
317 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
318 * 1ドットずつ調整するステータスを指す。
319 * また、フォントを変更すると都度自動調整される。
322 * Note the use of "font_want" for the names of the font file requested by
323 * the user, and the use of "font_file" for the currently active font file.
325 * The "font_file" is uppercased, and takes the form "8X13.FON", while
326 * "font_want" can be in almost any form as long as it could be construed
327 * as attempting to represent the name of a font.
338 TERM_LEN rows; /* int -> uint */
341 uint pos_x; //!< タームの左上X座標
342 uint pos_y; //!< タームの左上Y座標
357 int font_wid; //!< フォント横幅
358 int font_hgt; //!< フォント縦幅
359 int tile_wid; //!< タイル横幅
360 int tile_hgt; //!< タイル縦幅
371 #define MAX_TERM_DATA 8 //!< Maximum number of windows
373 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
374 static term_data *my_td; //!< Hack -- global "window creation" pointer
375 POINT normsize; //!< Remember normal size of main window when maxmized
378 * was main window maximized on previous playing
380 bool win_maximized = FALSE;
385 bool game_in_progress = FALSE;
388 * note when "open"/"new" become valid
390 bool initialized = FALSE;
393 * screen paletted, i.e. 256 colors
395 bool paletted = FALSE;
398 * 16 colors screen, don't use RGB()
400 bool colors16 = FALSE;
403 * Saved instance handle
405 static HINSTANCE hInstance;
408 * Yellow brush for the cursor
410 static HBRUSH hbrYellow;
420 static HPALETTE hPal;
423 static HBITMAP hBG = NULL;
424 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
425 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
428 * The screen saver window
430 static HWND hwndSaver;
433 * 現在使用中のタイルID(0ならば未使用)
434 * Flag set once "graphics" has been initialized
436 static byte current_graphics_mode = 0;
441 static DIBINIT infGraph;
444 * The global bitmap mask
446 static DIBINIT infMask;
449 * Flag set once "sound" has been initialized
451 static bool can_use_sound = FALSE;
454 * Show sub-windows even when Hengband is not in focus
456 static bool keep_subwindows = TRUE;
458 #define SAMPLE_SOUND_MAX 16
460 * An array of sound file names
462 static concptr sound_file[SOUND_MAX][SAMPLE_SOUND_MAX];
464 #define SAMPLE_MUSIC_MAX 16
465 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
466 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
467 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
468 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
469 static bool can_use_music = FALSE;
471 static MCI_OPEN_PARMS mop;
472 static char mci_device_type[256];
474 static int current_music_type = TERM_XTRA_MUSIC_MUTE;
475 static int current_music_id = 0;
476 static char current_music_path[1024];
479 * Full path to ANGBAND.INI
481 static concptr ini_file = NULL;
484 * Name of application
486 static concptr AppName = "ANGBAND";
489 * Name of sub-window type
491 static concptr AngList = "AngList";
496 static concptr ANGBAND_DIR_XTRA_GRAF;
497 static concptr ANGBAND_DIR_XTRA_SOUND;
498 static concptr ANGBAND_DIR_XTRA_HELP;
499 static concptr ANGBAND_DIR_XTRA_MUSIC;
502 * The "complex" color values
504 static COLORREF win_clr[256];
507 * Flag for macro trigger with dump ASCII
509 static bool term_no_press = FALSE;
514 static bool mouse_down = FALSE;
515 static bool paint_rect = FALSE;
516 static TERM_LEN mousex = 0, mousey = 0;
517 static TERM_LEN oldx, oldy;
520 * @brief The "simple" color values
522 * See "main-ibm.c" for original table information
523 * The entries below are taken from the "color bits" defined above.
524 * Note that many of the choices below suck, but so do crappy monitors.
526 static BYTE win_pal[256] = {
527 VID_BLACK, /* Dark */
528 VID_WHITE, /* White */
529 VID_CYAN, /* Slate XXX */
530 VID_RED | VID_BRIGHT, /* Orange XXX */
532 VID_GREEN, /* Green */
534 VID_YELLOW, /* Umber XXX */
535 VID_BLACK | VID_BRIGHT, /* Light Dark */
536 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
537 VID_MAGENTA, /* Violet XXX */
538 VID_YELLOW | VID_BRIGHT, /* Yellow */
539 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
540 VID_GREEN | VID_BRIGHT, /* Light Green */
541 VID_BLUE | VID_BRIGHT, /* Light Blue */
542 VID_YELLOW /* Light Umber XXX */
546 * Hack -- define which keys are "special"
548 static bool special_key[256];
549 static bool ignore_key[256];
552 * Hack -- initialization list for "special_key"
554 static byte special_key_list[] = {
555 VK_CLEAR, VK_PAUSE, VK_CAPITAL, VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI, VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE, VK_PRIOR, VK_NEXT, VK_END,
556 VK_HOME, VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN, VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT, VK_INSERT, VK_DELETE, VK_HELP, VK_APPS, VK_NUMPAD0, VK_NUMPAD1,
557 VK_NUMPAD2, VK_NUMPAD3, VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7, VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD, VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL,
558 VK_DIVIDE, VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6, VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12, VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18, VK_F19,
559 VK_F20, VK_F21, VK_F22, VK_F23, VK_F24, VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL, VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM, VK_NONAME, VK_PA1,
563 static byte ignore_key_list[] = {
564 VK_ESCAPE, VK_TAB, VK_SPACE, 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
565 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN, VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL, VK_LMENU, VK_RMENU, 0 /* End of List */
568 /* Function prototype */
570 static bool is_already_running(void);
573 static void delete_bg(void)
581 static int init_bg(void)
583 char *bmfile = bg_bitmap_file;
588 hBG = static_cast<HBITMAP>(LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE));
590 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
599 static void DrawBG(HDC hdc, RECT *r)
604 int x = r->left, y = r->top;
608 GetObject(hBG, sizeof(bm), &bm);
609 int swid = bm.bmWidth;
610 int shgt = bm.bmHeight;
612 HDC hdcSrc = CreateCompatibleDC(hdc);
613 HBITMAP hOld = static_cast<HBITMAP>(SelectObject(hdcSrc, hBG));
617 int cwid = MIN(swid - sx, r->right - nx);
620 int chgt = MIN(shgt - sy, r->bottom - ny);
621 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
623 } while (ny < r->bottom);
627 } while (nx < r->right);
629 SelectObject(hdcSrc, hOld);
634 * Check for existance of a file
636 static bool check_file(concptr s)
640 DWORD attrib = GetFileAttributes(path);
641 if (attrib == INVALID_FILE_NAME)
643 if (attrib & FILE_ATTRIBUTE_DIRECTORY)
650 * Check for existance of a directory
652 static bool check_dir(concptr s)
656 int i = strlen(path);
657 if (i && (path[i - 1] == '\\'))
660 DWORD attrib = GetFileAttributes(path);
661 if (attrib == INVALID_FILE_NAME)
663 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY))
672 static void validate_file(concptr s)
677 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
681 * Validate a directory
683 static void validate_dir(concptr s, bool vital)
689 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
690 } else if (mkdir(s)) {
691 quit_fmt("Unable to create directory:\n%s", s);
696 * @brief (Windows版固有実装)Get the "size" for a window
698 static void term_getsize(term_data *td)
705 TERM_LEN wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
706 TERM_LEN hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
710 GetWindowRect(td->w, &rw);
711 GetClientRect(td->w, &rc);
713 td->size_wid = (rw.right - rw.left) - (rc.right - rc.left) + wid;
714 td->size_hgt = (rw.bottom - rw.top) - (rc.bottom - rc.top) + hgt;
719 /* Tempolary calculation */
724 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
725 td->size_wid = rc.right - rc.left;
726 td->size_hgt = rc.bottom - rc.top;
731 * Write the "prefs" for a single term
733 static void save_prefs_aux(int i)
735 term_data *td = &data[i];
736 GAME_TEXT sec_name[128];
742 sprintf(sec_name, "Term-%d", i);
745 strcpy(buf, td->visible ? "1" : "0");
746 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
750 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "MS ゴシック");
752 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "Courier");
755 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
757 wsprintf(buf, "%d", td->lf.lfWidth);
758 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
759 wsprintf(buf, "%d", td->lf.lfHeight);
760 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
761 wsprintf(buf, "%d", td->lf.lfWeight);
762 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
764 strcpy(buf, td->bizarre ? "1" : "0");
765 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
767 wsprintf(buf, "%d", td->tile_wid);
768 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
770 wsprintf(buf, "%d", td->tile_hgt);
771 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
773 WINDOWPLACEMENT lpwndpl;
774 lpwndpl.length = sizeof(WINDOWPLACEMENT);
775 GetWindowPlacement(td->w, &lpwndpl);
777 RECT rc = lpwndpl.rcNormalPosition;
779 wsprintf(buf, "%d", normsize.x);
781 wsprintf(buf, "%d", td->cols);
783 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
786 wsprintf(buf, "%d", normsize.y);
788 wsprintf(buf, "%d", td->rows);
790 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
792 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
793 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
796 GetWindowRect(td->w, &rc);
797 wsprintf(buf, "%d", rc.left);
798 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
800 wsprintf(buf, "%d", rc.top);
801 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
803 strcpy(buf, td->posfix ? "1" : "0");
804 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
810 * We assume that the windows have all been initialized
812 static void save_prefs(void)
815 sprintf(buf, "%d", arg_graphics);
816 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
818 strcpy(buf, arg_bigtile ? "1" : "0");
819 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
821 strcpy(buf, arg_sound ? "1" : "0");
822 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
824 strcpy(buf, arg_music ? "1" : "0");
825 WritePrivateProfileString("Angband", "Music", buf, ini_file);
827 strcpy(buf, use_bg ? "1" : "0");
828 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
829 WritePrivateProfileString("Angband", "BackGroundBitmap", bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
831 int path_length = strlen(ANGBAND_DIR) - 4; /* \libの4文字分を削除 */
833 strncat(tmp, ANGBAND_DIR, path_length);
835 int n = strncmp(tmp, savefile, path_length);
837 char relative_path[1024] = "";
838 snprintf(relative_path, sizeof(relative_path), ".\\%s", (savefile + path_length));
839 WritePrivateProfileString("Angband", "SaveFile", relative_path, ini_file);
841 WritePrivateProfileString("Angband", "SaveFile", savefile, ini_file);
844 strcpy(buf, keep_subwindows ? "1" : "0");
845 WritePrivateProfileString("Angband", "KeepSubwindows", buf, ini_file);
847 for (int i = 0; i < MAX_TERM_DATA; ++i) {
853 * Load the "prefs" for a single term
855 static void load_prefs_aux(int i)
857 term_data *td = &data[i];
858 GAME_TEXT sec_name[128];
861 int dispx = GetSystemMetrics(SM_CXVIRTUALSCREEN);
862 int dispy = GetSystemMetrics(SM_CYVIRTUALSCREEN);
866 sprintf(sec_name, "Term-%d", i);
867 sprintf(sec_name, "Term-%d", i);
869 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
873 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
875 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
878 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
880 td->font_want = string_make(tmp);
883 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
884 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
885 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
887 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
888 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
890 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
891 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
892 normsize.x = td->cols;
893 normsize.y = td->rows;
896 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
899 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
900 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
901 td->pos_x = MIN(MAX(0, posx), dispx - 128);
902 td->pos_y = MIN(MAX(0, posy), dispy - 128);
905 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
912 static void load_prefs(void)
914 arg_graphics = (byte)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
915 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
916 use_bigtile = arg_bigtile;
917 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
918 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
919 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
920 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
921 GetPrivateProfileString("Angband", "SaveFile", "", savefile, 1023, ini_file);
923 int n = strncmp(".\\", savefile, 2);
925 int path_length = strlen(ANGBAND_DIR) - 4; /* \libの4文字分を削除 */
927 strncat(tmp, ANGBAND_DIR, path_length);
928 strncat(tmp, savefile + 2, strlen(savefile) - 2 + path_length);
929 strncpy(savefile, tmp, strlen(tmp));
932 keep_subwindows = (GetPrivateProfileInt("Angband", "KeepSubwindows", 0, ini_file) != 0);
933 for (int i = 0; i < MAX_TERM_DATA; ++i) {
939 * - Taken from files.c.
941 * Extract "tokens" from a buffer
943 * This function uses "whitespace" as delimiters, and treats any amount of
944 * whitespace as a single delimiter. We will never return any empty tokens.
945 * When given an empty buffer, or a buffer containing only "whitespace", we
946 * will return no tokens. We will never extract more than "num" tokens.
948 * By running a token through the "text_to_ascii()" function, you can allow
949 * that token to include (encoded) whitespace, using "\s" to encode spaces.
951 * We save pointers to the tokens in "tokens", and return the number found.
953 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
960 for (; *s && iswspace(*s); ++s) /* loop */
966 for (t = s; *t && !iswspace(*t); ++t) /* loop */
979 static void load_sound_prefs(void)
984 char *zz[SAMPLE_SOUND_MAX];
986 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound_debug.cfg");
987 if (GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path) == 0) {
988 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
989 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
992 for (int i = 0; i < SOUND_MAX; i++) {
993 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
994 int num = tokenize_whitespace(tmp, SAMPLE_SOUND_MAX, zz);
995 for (int j = 0; j < num; j++) {
996 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
997 if (check_file(wav_path))
998 sound_file[i][j] = string_make(zz[j]);
1003 static void load_music_prefs(void)
1006 char ini_path[1024];
1007 char wav_path[1024];
1008 char *zz[SAMPLE_MUSIC_MAX];
1011 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music_debug.cfg");
1012 if (GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path) == 0) {
1013 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1014 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1017 for (int i = 0; i < MUSIC_BASIC_MAX; i++) {
1018 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1019 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1020 for (int j = 0; j < num; j++) {
1021 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1022 if (check_file(wav_path))
1023 music_file[i][j] = string_make(zz[j]);
1027 for (int i = 0; i < current_world_ptr->max_d_idx; i++) {
1028 sprintf(key, "dungeon%03d", i);
1029 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1030 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1031 for (int j = 0; j < num; j++) {
1032 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1033 if (check_file(wav_path))
1034 dungeon_music_file[i][j] = string_make(zz[j]);
1038 for (int i = 0; i < max_q_idx; i++) {
1039 sprintf(key, "quest%03d", i);
1040 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1041 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1042 for (int j = 0; j < num; j++) {
1043 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1044 if (check_file(wav_path))
1045 quest_music_file[i][j] = string_make(zz[j]);
1049 for (int i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1051 sprintf(key, "town%03d", i);
1052 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1053 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1054 for (int j = 0; j < num; j++) {
1055 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1056 if (check_file(wav_path))
1057 town_music_file[i][j] = string_make(zz[j]);
1063 * Create the new global palette based on the bitmap palette
1064 * (if any), and the standard 16 entry palette derived from
1065 * "win_clr[]" which is used for the basic 16 Angband colors.
1067 * This function is never called before all windows are ready.
1069 * This function returns FALSE if the new palette could not be
1070 * prepared, which should normally be a fatal error. XXX XXX
1072 * Note that only some machines actually use a "palette".
1074 static int new_palette(void)
1079 LPLOGPALETTE pLogPal;
1080 LPPALETTEENTRY lppe;
1089 HPALETTE hBmPal = static_cast<HPALETTE>(infGraph.hPalette);
1091 lppeSize = 256 * sizeof(PALETTEENTRY);
1092 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1093 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1094 if ((nEntries == 0) || (nEntries > 220)) {
1095 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1096 rnfree(lppe, lppeSize);
1101 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1102 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1103 pLogPal->palVersion = 0x300;
1104 pLogPal->palNumEntries = nEntries + 16;
1105 for (i = 0; i < nEntries; i++) {
1106 pLogPal->palPalEntry[i] = lppe[i];
1109 for (i = 0; i < 16; i++) {
1111 p = &(pLogPal->palPalEntry[i + nEntries]);
1112 p->peRed = GetRValue(win_clr[i]);
1113 p->peGreen = GetGValue(win_clr[i]);
1114 p->peBlue = GetBValue(win_clr[i]);
1115 p->peFlags = PC_NOCOLLAPSE;
1119 rnfree(lppe, lppeSize);
1121 HPALETTE hNewPal = CreatePalette(pLogPal);
1123 quit(_("パレットを作成できません!", "Cannot create palette!"));
1125 rnfree(pLogPal, pLogPalSize);
1127 HDC hdc = GetDC(td->w);
1128 SelectPalette(hdc, hNewPal, 0);
1129 i = RealizePalette(hdc);
1130 ReleaseDC(td->w, hdc);
1132 quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1134 for (i = 1; i < MAX_TERM_DATA; i++) {
1137 SelectPalette(hdc, hNewPal, 0);
1138 ReleaseDC(td->w, hdc);
1149 * @brief グラフィクスを初期化する / Initialize graphics
1152 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1153 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1156 static bool init_graphics(void)
1159 BYTE wid, hgt, twid, thgt, ox, oy;
1162 if (arg_graphics == GRAPHICS_ADAM_BOLT) {
1171 ANGBAND_GRAF = "new";
1172 } else if (arg_graphics == GRAPHICS_HENGBAND) {
1181 ANGBAND_GRAF = "ne2";
1190 ANGBAND_GRAF = "old";
1193 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1194 if (!ReadDIB(data[0].w, buf, &infGraph)) {
1195 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1199 infGraph.CellWidth = wid;
1200 infGraph.CellHeight = hgt;
1201 infGraph.TileWidth = twid;
1202 infGraph.TileHeight = thgt;
1203 infGraph.OffsetX = ox;
1204 infGraph.OffsetY = oy;
1206 if (arg_graphics == GRAPHICS_ADAM_BOLT) {
1207 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1208 if (!ReadDIB(data[0].w, buf, &infMask)) {
1209 plog_fmt("Cannot read bitmap file '%s'", buf);
1214 if (arg_graphics == GRAPHICS_HENGBAND) {
1215 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1216 if (!ReadDIB(data[0].w, buf, &infMask)) {
1217 plog_fmt("Cannot read bitmap file '%s'", buf);
1222 if (!new_palette()) {
1223 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1227 current_graphics_mode = arg_graphics;
1228 return current_graphics_mode != 0;
1234 static void init_music(void)
1236 if (!can_use_music) {
1238 can_use_music = TRUE;
1243 * Hack -- Stop a music
1245 static void stop_music(void)
1247 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1248 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1249 current_music_type = TERM_XTRA_MUSIC_MUTE;
1250 current_music_id = 0;
1251 strcpy(current_music_path, "\0");
1257 static void init_sound(void)
1259 if (!can_use_sound) {
1261 can_use_sound = TRUE;
1268 static void term_window_resize(term_data *td)
1273 SetWindowPos(td->w, 0, 0, 0, td->size_wid, td->size_hgt, SWP_NOMOVE | SWP_NOZORDER);
1274 InvalidateRect(td->w, NULL, TRUE);
1279 * Force the use of a new "font file" for a term_data.
1280 * This function may be called before the "window" is ready.
1281 * This function returns zero only if everything succeeds.
1282 * Note that the "font name" must be capitalized!!!
1284 static errr term_force_font(term_data *td, concptr path)
1287 DeleteObject(td->font_id);
1290 td->font_id = CreateFontIndirect(&(td->lf));
1291 int wid = td->lf.lfWidth;
1292 int hgt = td->lf.lfHeight;
1301 hdcDesktop = GetDC(HWND_DESKTOP);
1302 hfOld = static_cast<HFONT>(SelectObject(hdcDesktop, td->font_id));
1303 GetTextMetrics(hdcDesktop, &tm);
1304 SelectObject(hdcDesktop, hfOld);
1305 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1307 wid = tm.tmAveCharWidth;
1318 * Allow the user to change the font for this window.
1320 static void term_change_font(term_data *td)
1323 memset(&cf, 0, sizeof(cf));
1324 cf.lStructSize = sizeof(cf);
1325 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1326 cf.lpLogFont = &(td->lf);
1328 if (!ChooseFont(&cf))
1331 term_force_font(td, NULL);
1333 td->tile_wid = td->font_wid;
1334 td->tile_hgt = td->font_hgt;
1336 term_window_resize(td);
1340 * Allow the user to lock this window.
1342 static void term_window_pos(term_data *td, HWND hWnd)
1344 SetWindowPos(td->w, hWnd, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1347 static void windows_map(player_type *player_ptr);
1350 * Hack -- redraw a term_data
1352 static void term_data_redraw(player_type *player_ptr, term_data *td)
1354 if (td->map_active) {
1355 windows_map(player_ptr);
1359 term_activate(&td->t);
1361 term_activate(term_screen);
1364 void term_inversed_area(HWND hWnd, int x, int y, int w, int h)
1366 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
1367 int tx = td->size_ow1 + x * td->tile_wid;
1368 int ty = td->size_oh1 + y * td->tile_hgt;
1369 int tw = w * td->tile_wid - 1;
1370 int th = h * td->tile_hgt - 1;
1372 HDC hdc = GetDC(hWnd);
1373 HBRUSH myBrush = CreateSolidBrush(RGB(255, 255, 255));
1374 HBRUSH oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1375 HPEN oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1377 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
1379 SelectObject(hdc, oldBrush);
1380 SelectObject(hdc, oldPen);
1384 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
1386 static errr term_user_win(int n)
1393 * React to global changes
1395 static errr term_xtra_win_react(player_type *player_ptr)
1398 for (int i = 0; i < 256; i++) {
1399 win_pal[i] = angband_color_table[i][0];
1404 bool change = FALSE;
1405 for (int i = 0; i < 256; i++) {
1406 rv = angband_color_table[i][1];
1407 gv = angband_color_table[i][2];
1408 bv = angband_color_table[i][3];
1409 code = PALETTERGB(rv, gv, bv);
1410 if (win_clr[i] != code) {
1417 (void)new_palette();
1420 if (use_sound != arg_sound) {
1422 use_sound = arg_sound;
1425 if (use_music != arg_music) {
1427 use_music = arg_music;
1431 select_floor_music(player_ptr);
1434 if (use_graphics != (arg_graphics > 0)) {
1435 if (arg_graphics && !init_graphics()) {
1436 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
1437 arg_graphics = GRAPHICS_NONE;
1440 use_graphics = (arg_graphics > 0);
1441 reset_visuals(player_ptr, process_autopick_file_command);
1444 for (int i = 0; i < MAX_TERM_DATA; i++) {
1445 term_type *old = Term;
1446 term_data *td = &data[i];
1447 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt)) {
1448 term_activate(&td->t);
1449 term_resize(td->cols, td->rows);
1459 * Process at least one event
1461 static errr term_xtra_win_event(int v)
1465 if (GetMessage(&msg, NULL, 0, 0)) {
1466 TranslateMessage(&msg);
1467 DispatchMessage(&msg);
1470 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
1471 TranslateMessage(&msg);
1472 DispatchMessage(&msg);
1480 * Process all pending events
1482 static errr term_xtra_win_flush(void)
1485 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
1486 TranslateMessage(&msg);
1487 DispatchMessage(&msg);
1494 * Hack -- clear the screen
1496 * Make this more efficient
1498 static errr term_xtra_win_clear(void)
1500 term_data *td = (term_data *)(Term->data);
1503 rc.left = td->size_ow1;
1504 rc.right = rc.left + td->cols * td->tile_wid;
1505 rc.top = td->size_oh1;
1506 rc.bottom = rc.top + td->rows * td->tile_hgt;
1508 HDC hdc = GetDC(td->w);
1509 SetBkColor(hdc, RGB(0, 0, 0));
1510 SelectObject(hdc, td->font_id);
1511 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1519 ReleaseDC(td->w, hdc);
1524 * Hack -- make a noise
1526 static errr term_xtra_win_noise(void)
1528 MessageBeep(MB_ICONASTERISK);
1533 * Hack -- make a sound
1535 static errr term_xtra_win_sound(int v)
1540 if ((v < 0) || (v >= SOUND_MAX))
1544 for (i = 0; i < SAMPLE_SOUND_MAX; i++) {
1545 if (!sound_file[v][i])
1552 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
1553 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
1557 * Hack -- play a music
1559 static errr term_xtra_win_music(int n, int v)
1564 if (n == TERM_XTRA_MUSIC_MUTE)
1571 if (n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX)))
1573 else if (v < 0 || v >= 1000)
1574 return (1); /*!< TODO */
1577 case TERM_XTRA_MUSIC_BASIC:
1578 for (i = 0; i < SAMPLE_MUSIC_MAX; i++)
1579 if (!music_file[v][i])
1582 case TERM_XTRA_MUSIC_DUNGEON:
1583 for (i = 0; i < SAMPLE_MUSIC_MAX; i++)
1584 if (!dungeon_music_file[v][i])
1587 case TERM_XTRA_MUSIC_QUEST:
1588 for (i = 0; i < SAMPLE_MUSIC_MAX; i++)
1589 if (!quest_music_file[v][i])
1592 case TERM_XTRA_MUSIC_TOWN:
1593 for (i = 0; i < SAMPLE_MUSIC_MAX; i++)
1594 if (!town_music_file[v][i])
1604 case TERM_XTRA_MUSIC_BASIC:
1605 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
1607 case TERM_XTRA_MUSIC_DUNGEON:
1608 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
1610 case TERM_XTRA_MUSIC_QUEST:
1611 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
1613 case TERM_XTRA_MUSIC_TOWN:
1614 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
1618 if (current_music_type == n && current_music_id == v)
1621 if (current_music_type != TERM_XTRA_MUSIC_MUTE && n != TERM_XTRA_MUSIC_MUTE)
1622 if (0 == strcmp(current_music_path, buf))
1625 current_music_type = n;
1626 current_music_id = v;
1627 strcpy(current_music_path, buf);
1629 mop.lpstrDeviceType = mci_device_type;
1630 mop.lpstrElementName = buf;
1631 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1632 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1633 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
1634 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
1635 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
1640 * Delay for "x" milliseconds
1642 static int term_xtra_win_delay(int v)
1649 * todo z-termに影響があるのでplayer_typeの追加は保留
1650 * Do a "special thing"
1652 static errr term_xtra_win(int n, int v)
1655 case TERM_XTRA_NOISE: {
1656 return (term_xtra_win_noise());
1658 case TERM_XTRA_MUSIC_BASIC:
1659 case TERM_XTRA_MUSIC_DUNGEON:
1660 case TERM_XTRA_MUSIC_QUEST:
1661 case TERM_XTRA_MUSIC_TOWN:
1662 case TERM_XTRA_MUSIC_MUTE: {
1663 return (term_xtra_win_music(n, v));
1665 case TERM_XTRA_SOUND: {
1666 return (term_xtra_win_sound(v));
1668 case TERM_XTRA_BORED: {
1669 return (term_xtra_win_event(0));
1671 case TERM_XTRA_EVENT: {
1672 return (term_xtra_win_event(v));
1674 case TERM_XTRA_FLUSH: {
1675 return (term_xtra_win_flush());
1677 case TERM_XTRA_CLEAR: {
1678 return (term_xtra_win_clear());
1680 case TERM_XTRA_REACT: {
1681 return (term_xtra_win_react(p_ptr));
1683 case TERM_XTRA_DELAY: {
1684 return (term_xtra_win_delay(v));
1692 * Low level graphics (Assumes valid input).
1694 * Draw a "cursor" at (x,y), using a "yellow box".
1696 static errr term_curs_win(int x, int y)
1698 term_data *td = (term_data *)(Term->data);
1699 int tile_wid, tile_hgt;
1700 if (td->map_active) {
1701 tile_wid = td->map_tile_wid;
1702 tile_hgt = td->map_tile_hgt;
1704 tile_wid = td->tile_wid;
1705 tile_hgt = td->tile_hgt;
1709 rc.left = x * tile_wid + td->size_ow1;
1710 rc.right = rc.left + tile_wid;
1711 rc.top = y * tile_hgt + td->size_oh1;
1712 rc.bottom = rc.top + tile_hgt;
1714 HDC hdc = GetDC(td->w);
1715 FrameRect(hdc, &rc, hbrYellow);
1716 ReleaseDC(td->w, hdc);
1721 * Low level graphics (Assumes valid input).
1723 * Draw a "big cursor" at (x,y), using a "yellow box".
1725 static errr term_bigcurs_win(int x, int y)
1727 term_data *td = (term_data *)(Term->data);
1728 int tile_wid, tile_hgt;
1729 if (td->map_active) {
1730 term_curs_win(x, y);
1733 tile_wid = td->tile_wid;
1734 tile_hgt = td->tile_hgt;
1738 rc.left = x * tile_wid + td->size_ow1;
1739 rc.right = rc.left + 2 * tile_wid;
1740 rc.top = y * tile_hgt + td->size_oh1;
1741 rc.bottom = rc.top + tile_hgt;
1743 HDC hdc = GetDC(td->w);
1744 FrameRect(hdc, &rc, hbrYellow);
1745 ReleaseDC(td->w, hdc);
1750 * Low level graphics (Assumes valid input).
1752 * Erase a "block" of "n" characters starting at (x,y).
1754 static errr term_wipe_win(int x, int y, int n)
1756 term_data *td = (term_data *)(Term->data);
1758 rc.left = x * td->tile_wid + td->size_ow1;
1759 rc.right = rc.left + n * td->tile_wid;
1760 rc.top = y * td->tile_hgt + td->size_oh1;
1761 rc.bottom = rc.top + td->tile_hgt;
1763 HDC hdc = GetDC(td->w);
1764 SetBkColor(hdc, RGB(0, 0, 0));
1765 SelectObject(hdc, td->font_id);
1769 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1771 ReleaseDC(td->w, hdc);
1776 * Low level graphics. Assumes valid input.
1778 * Draw several ("n") chars, with an attr, at a given location.
1780 * All "graphic" data is handled by "term_pict_win()", below.
1782 * One would think there is a more efficient method for telling a window
1783 * what color it should be using to draw with, but perhaps simply changing
1784 * it every time is not too inefficient.
1786 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
1788 term_data *td = (term_data *)(Term->data);
1789 static HBITMAP WALL;
1790 static HBRUSH myBrush, oldBrush;
1792 static bool init_done = FALSE;
1795 WALL = LoadBitmap(hInstance, AppName);
1796 myBrush = CreatePatternBrush(WALL);
1801 rc.left = x * td->tile_wid + td->size_ow1;
1802 rc.right = rc.left + n * td->tile_wid;
1803 rc.top = y * td->tile_hgt + td->size_oh1;
1804 rc.bottom = rc.top + td->tile_hgt;
1806 HDC hdc = GetDC(td->w);
1807 SetBkColor(hdc, RGB(0, 0, 0));
1809 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
1810 } else if (paletted) {
1811 SetTextColor(hdc, win_clr[a & 0x0F]);
1813 SetTextColor(hdc, win_clr[a]);
1816 SelectObject(hdc, td->font_id);
1818 SetBkMode(hdc, TRANSPARENT);
1820 if (td->bizarre || (td->tile_hgt != td->font_hgt) || (td->tile_wid != td->font_wid)) {
1821 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1825 rc.left += ((td->tile_wid - td->font_wid) / 2);
1826 rc.right = rc.left + td->font_wid;
1827 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
1828 rc.bottom = rc.top + td->font_hgt;
1830 for (int i = 0; i < n; i++) {
1832 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1]) {
1833 rc.right += td->font_wid;
1834 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1835 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1836 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1837 SelectObject(hdc, oldBrush);
1838 SelectObject(hdc, oldPen);
1839 rc.right -= td->font_wid;
1841 rc.left += 2 * td->tile_wid;
1842 rc.right += 2 * td->tile_wid;
1843 } else if (iskanji(*(s + i))) /* 2バイト文字 */
1845 rc.right += td->font_wid;
1846 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 2, NULL);
1847 rc.right -= td->font_wid;
1849 rc.left += 2 * td->tile_wid;
1850 rc.right += 2 * td->tile_wid;
1851 } else if (*(s + i) == 127) {
1852 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1853 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1854 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1855 SelectObject(hdc, oldBrush);
1856 SelectObject(hdc, oldPen);
1857 rc.left += td->tile_wid;
1858 rc.right += td->tile_wid;
1860 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1861 rc.left += td->tile_wid;
1862 rc.right += td->tile_wid;
1865 if (*(s + i) == 127) {
1866 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1867 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1868 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1869 SelectObject(hdc, oldBrush);
1870 SelectObject(hdc, oldPen);
1871 rc.left += td->tile_wid;
1872 rc.right += td->tile_wid;
1874 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1875 rc.left += td->tile_wid;
1876 rc.right += td->tile_wid;
1881 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc, s, n, NULL);
1884 ReleaseDC(td->w, hdc);
1889 * Low level graphics. Assumes valid input.
1891 * Draw an array of "special" attr/char pairs at the given location.
1893 * We use the "term_pict_win()" function for "graphic" data, which are
1894 * encoded by setting the "high-bits" of both the "attr" and the "char"
1895 * data. We use the "attr" to represent the "row" of the main bitmap,
1896 * and the "char" to represent the "col" of the main bitmap. The use
1897 * of this function is induced by the "higher_pict" flag.
1899 * If "graphics" is not available, we simply "wipe" the given grids.
1901 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)
1903 term_data *td = (term_data *)(Term->data);
1906 if (!use_graphics) {
1907 return (term_wipe_win(x, y, n));
1910 TERM_LEN w1 = infGraph.CellWidth;
1911 TERM_LEN h1 = infGraph.CellHeight;
1912 TERM_LEN tw1 = infGraph.TileWidth;
1913 TERM_LEN th1 = infGraph.TileHeight;
1914 TERM_LEN w2, h2, tw2 = 0;
1915 if (td->map_active) {
1916 w2 = td->map_tile_wid;
1917 h2 = td->map_tile_hgt;
1926 TERM_LEN x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
1927 TERM_LEN y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
1928 HDC hdc = GetDC(td->w);
1929 HDC hdcSrc = CreateCompatibleDC(hdc);
1930 HBITMAP hbmSrcOld = static_cast<HBITMAP>(SelectObject(hdcSrc, infGraph.hBitmap));
1932 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1933 hdcMask = CreateCompatibleDC(hdc);
1934 SelectObject(hdcMask, infMask.hBitmap);
1937 for (i = 0; i < n; i++, x2 += w2) {
1938 TERM_COLOR a = ap[i];
1940 int row = (a & 0x7F);
1941 int col = (c & 0x7F);
1942 TERM_LEN x1 = col * w1;
1943 TERM_LEN y1 = row * h1;
1945 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1946 TERM_LEN x3 = (tcp[i] & 0x7F) * w1;
1947 TERM_LEN y3 = (tap[i] & 0x7F) * h1;
1948 tw2 = tw2 * w1 / tw1;
1950 if ((tw1 == tw2) && (th1 == h2)) {
1951 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
1952 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
1953 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
1957 SetStretchBltMode(hdc, COLORONCOLOR);
1958 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
1959 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
1960 if ((x1 != x3) || (y1 != y3)) {
1961 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
1962 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
1968 if ((w1 == tw2) && (h1 == h2)) {
1969 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
1973 SetStretchBltMode(hdc, COLORONCOLOR);
1974 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
1977 SelectObject(hdcSrc, hbmSrcOld);
1979 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1980 SelectObject(hdcMask, hbmSrcOld);
1984 ReleaseDC(td->w, hdc);
1988 static void windows_map(player_type *player_ptr)
1990 term_data *td = &data[0];
1995 term_xtra_win_clear();
1996 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
1997 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
1998 td->map_active = TRUE;
2002 TERM_LEN max_x = player_ptr->current_floor_ptr->width;
2003 TERM_LEN max_y = player_ptr->current_floor_ptr->height;
2006 for (TERM_LEN x = min_x; x < max_x; x++) {
2007 for (TERM_LEN y = min_y; y < max_y; y++) {
2010 map_info(player_ptr, y, x, &a, (char *)&c, &ta, (char *)&tc);
2011 if ((a & 0x80) && (c & 0x80)) {
2012 term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2017 term_curs_win(player_ptr->x - min_x, player_ptr->y - min_y);
2018 term_inkey(&c, TRUE, TRUE);
2020 td->map_active = FALSE;
2021 term_xtra_win_clear();
2026 * Create and initialize a "term_data" given a title
2028 static void term_data_link(term_data *td)
2030 term_type *t = &td->t;
2031 term_init(t, td->cols, td->rows, FILE_READ_BUFF_SIZE);
2032 t->soft_cursor = TRUE;
2033 t->higher_pict = TRUE;
2034 t->attr_blank = TERM_WHITE;
2035 t->char_blank = ' ';
2036 t->user_hook = term_user_win;
2037 t->xtra_hook = term_xtra_win;
2038 t->curs_hook = term_curs_win;
2039 t->bigcurs_hook = term_bigcurs_win;
2040 t->wipe_hook = term_wipe_win;
2041 t->text_hook = term_text_win;
2042 t->pict_hook = term_pict_win;
2043 t->data = (vptr)(td);
2047 * Create the windows
2049 * First, instantiate the "default" values, then read the "ini_file"
2050 * to over-ride selected values, then create the windows, and fonts.
2052 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2053 * must make active to realize the palette.
2055 static void init_windows(void)
2059 WIPE(td, term_data);
2063 td->s = angband_term_name[0];
2079 for (int i = 1; i < MAX_TERM_DATA; i++) {
2081 WIPE(td, term_data);
2082 td->s = angband_term_name[i];
2086 td->visible = FALSE;
2091 td->pos_x = (7 - i) * 30;
2092 td->pos_y = (7 - i) * 20;
2099 /* Atrributes of main window */
2101 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_VISIBLE);
2105 /* Attributes of sub windows */
2106 for (int i = 1; i < MAX_TERM_DATA; i++) {
2108 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2109 td->dwExStyle = (WS_EX_TOOLWINDOW);
2112 /* Font of each window */
2113 for (int i = 0; i < MAX_TERM_DATA; i++) {
2115 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2116 td->lf.lfCharSet = DEFAULT_CHARSET;
2117 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2118 term_force_font(td, NULL);
2120 td->tile_wid = td->font_wid;
2122 td->tile_hgt = td->font_hgt;
2124 term_window_resize(td);
2127 /* Create sub windows */
2128 for (int i = MAX_TERM_DATA - 1; i >= 1; --i) {
2133 = CreateWindowEx(td->dwExStyle, AngList, td->s, td->dwStyle, td->pos_x, td->pos_y, td->size_wid, td->size_hgt, HWND_DESKTOP, NULL, hInstance, NULL);
2137 quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
2139 td->size_hack = TRUE;
2141 term_window_resize(td);
2144 ShowWindow(td->w, SW_SHOW);
2146 td->size_hack = FALSE;
2149 angband_term[i] = &td->t;
2152 /* Activate the window */
2153 SetActiveWindow(td->w);
2157 term_window_pos(td, HWND_TOPMOST);
2159 term_window_pos(td, td->w);
2163 /* Create main window */
2166 td->w = CreateWindowEx(td->dwExStyle, AppName, td->s, td->dwStyle, td->pos_x, td->pos_y, td->size_wid, td->size_hgt, HWND_DESKTOP, NULL, hInstance, NULL);
2170 quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
2173 td->size_hack = TRUE;
2175 term_window_resize(td);
2176 td->size_hack = FALSE;
2179 angband_term[0] = &td->t;
2180 normsize.x = td->cols;
2181 normsize.y = td->rows;
2184 ShowWindow(td->w, SW_SHOWMAXIMIZED);
2186 ShowWindow(td->w, SW_SHOW);
2188 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2189 (void)new_palette();
2190 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
2191 (void)term_xtra_win_flush();
2197 static void setup_menus(void)
2199 HMENU hm = GetMenu(data[0].w);
2200 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2201 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2202 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2203 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2204 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2206 if (!current_world_ptr->character_generated) {
2207 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
2208 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
2211 if (current_world_ptr->character_generated) {
2212 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_ENABLED);
2215 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_ENABLED);
2216 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_ENABLED);
2218 for (int i = 0; i < MAX_TERM_DATA; i++) {
2219 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2220 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i, (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
2221 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_ENABLED);
2224 for (int i = 0; i < MAX_TERM_DATA; i++) {
2225 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2227 if (data[i].visible) {
2228 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2232 for (int i = 0; i < MAX_TERM_DATA; i++) {
2233 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2234 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i, (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
2235 if (data[i].visible) {
2236 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_ENABLED);
2240 for (int i = 0; i < MAX_TERM_DATA; i++) {
2241 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2242 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i, (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
2243 if (data[i].visible) {
2244 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_ENABLED);
2248 for (int i = 0; i < MAX_TERM_DATA; i++) {
2249 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2250 if (data[i].visible) {
2251 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
2255 for (int i = 0; i < MAX_TERM_DATA; i++) {
2256 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2257 if (data[i].visible) {
2258 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
2262 for (int i = 0; i < MAX_TERM_DATA; i++) {
2263 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2264 if (data[i].visible) {
2265 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2269 for (int i = 0; i < MAX_TERM_DATA; i++) {
2270 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2272 if (data[i].visible) {
2273 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2276 EnableMenuItem(hm, IDM_WINDOW_KEEP_SUBWINDOWS, MF_BYCOMMAND | MF_ENABLED);
2277 CheckMenuItem(hm, IDM_WINDOW_KEEP_SUBWINDOWS, (keep_subwindows ? MF_CHECKED : MF_UNCHECKED));
2279 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2280 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2281 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2282 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2283 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2286 EnableMenuItem(hm, IDM_OPTIONS_SAVER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2289 if (use_graphics != GRAPHICS_NONE)
2290 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
2292 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2294 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
2295 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
2296 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
2297 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS, (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
2298 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE, (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
2299 CheckMenuItem(hm, IDM_OPTIONS_MUSIC, (arg_music ? MF_CHECKED : MF_UNCHECKED));
2300 CheckMenuItem(hm, IDM_OPTIONS_SOUND, (arg_sound ? MF_CHECKED : MF_UNCHECKED));
2301 CheckMenuItem(hm, IDM_OPTIONS_BG, (use_bg ? MF_CHECKED : MF_UNCHECKED));
2304 CheckMenuItem(hm, IDM_OPTIONS_SAVER, (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
2306 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
2307 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
2308 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
2309 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
2310 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
2311 EnableMenuItem(hm, IDM_OPTIONS_SAVER, MF_BYCOMMAND | MF_ENABLED);
2315 * Check for double clicked (or dragged) savefile
2317 * Apparently, Windows copies the entire filename into the first
2318 * piece of the "command line string". Perhaps we should extract
2319 * the "basename" of that filename and append it to the "save" dir.
2321 static void check_for_save_file(player_type *player_ptr, LPSTR cmd_line)
2328 strcpy(savefile, s);
2329 validate_file(savefile);
2330 game_in_progress = TRUE;
2331 play_game(player_ptr, FALSE, FALSE);
2335 * Process a menu command
2337 static void process_menus(player_type *player_ptr, WORD wCmd)
2342 case IDM_FILE_NEW: {
2344 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2345 } else if (game_in_progress) {
2346 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
2348 game_in_progress = TRUE;
2350 strcpy(savefile, "");
2351 play_game(player_ptr, TRUE, FALSE);
2357 case IDM_FILE_OPEN: {
2359 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2360 } else if (game_in_progress) {
2361 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
2363 memset(&ofn, 0, sizeof(ofn));
2364 ofn.lStructSize = sizeof(ofn);
2365 ofn.hwndOwner = data[0].w;
2366 ofn.lpstrFilter = "Save Files (*.)\0*\0";
2367 ofn.nFilterIndex = 1;
2368 ofn.lpstrFile = savefile;
2369 ofn.nMaxFile = 1024;
2370 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
2371 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
2373 if (GetOpenFileName(&ofn)) {
2374 validate_file(savefile);
2375 game_in_progress = TRUE;
2377 play_game(player_ptr, FALSE, FALSE);
2384 case IDM_FILE_SAVE: {
2385 if (game_in_progress && current_world_ptr->character_generated) {
2387 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
2392 do_cmd_save_game(player_ptr, FALSE);
2394 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
2399 case IDM_FILE_EXIT: {
2400 if (game_in_progress && current_world_ptr->character_generated) {
2402 plog(_("今は終了できません。", "You may not do that right now."));
2407 forget_lite(player_ptr->current_floor_ptr);
2408 forget_view(player_ptr->current_floor_ptr);
2409 clear_mon_lite(player_ptr->current_floor_ptr);
2411 term_key_push(SPECIAL_KEY_QUIT);
2418 case IDM_FILE_SCORE: {
2420 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
2421 highscore_fd = fd_open(buf, O_RDONLY);
2422 if (highscore_fd < 0) {
2423 msg_print("Score file unavailable.");
2427 display_scores_aux(0, MAX_HISCORES, -1, NULL);
2428 (void)fd_close(highscore_fd);
2436 case IDM_FILE_MOVIE: {
2438 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2439 } else if (game_in_progress) {
2440 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
2442 memset(&ofn, 0, sizeof(ofn));
2443 ofn.lStructSize = sizeof(ofn);
2444 ofn.hwndOwner = data[0].w;
2445 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
2446 ofn.nFilterIndex = 1;
2447 ofn.lpstrFile = savefile;
2448 ofn.nMaxFile = 1024;
2449 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
2450 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2452 if (GetOpenFileName(&ofn)) {
2453 prepare_browse_movie_without_path_build(savefile);
2454 play_game(player_ptr, FALSE, TRUE);
2462 case IDM_WINDOW_VIS_0: {
2463 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
2466 case IDM_WINDOW_VIS_1:
2467 case IDM_WINDOW_VIS_2:
2468 case IDM_WINDOW_VIS_3:
2469 case IDM_WINDOW_VIS_4:
2470 case IDM_WINDOW_VIS_5:
2471 case IDM_WINDOW_VIS_6:
2472 case IDM_WINDOW_VIS_7: {
2473 int i = wCmd - IDM_WINDOW_VIS_0;
2474 if ((i < 0) || (i >= MAX_TERM_DATA))
2480 ShowWindow(td->w, SW_SHOW);
2481 term_data_redraw(player_ptr, td);
2483 td->visible = FALSE;
2485 ShowWindow(td->w, SW_HIDE);
2490 case IDM_WINDOW_FONT_0:
2491 case IDM_WINDOW_FONT_1:
2492 case IDM_WINDOW_FONT_2:
2493 case IDM_WINDOW_FONT_3:
2494 case IDM_WINDOW_FONT_4:
2495 case IDM_WINDOW_FONT_5:
2496 case IDM_WINDOW_FONT_6:
2497 case IDM_WINDOW_FONT_7: {
2498 int i = wCmd - IDM_WINDOW_FONT_0;
2499 if ((i < 0) || (i >= MAX_TERM_DATA))
2503 term_change_font(td);
2506 case IDM_WINDOW_POS_1:
2507 case IDM_WINDOW_POS_2:
2508 case IDM_WINDOW_POS_3:
2509 case IDM_WINDOW_POS_4:
2510 case IDM_WINDOW_POS_5:
2511 case IDM_WINDOW_POS_6:
2512 case IDM_WINDOW_POS_7: {
2513 int i = wCmd - IDM_WINDOW_POS_0;
2514 if ((i < 0) || (i >= MAX_TERM_DATA))
2518 if (!td->posfix && td->visible) {
2520 term_window_pos(td, HWND_TOPMOST);
2523 term_window_pos(td, data[0].w);
2528 case IDM_WINDOW_BIZ_0:
2529 case IDM_WINDOW_BIZ_1:
2530 case IDM_WINDOW_BIZ_2:
2531 case IDM_WINDOW_BIZ_3:
2532 case IDM_WINDOW_BIZ_4:
2533 case IDM_WINDOW_BIZ_5:
2534 case IDM_WINDOW_BIZ_6:
2535 case IDM_WINDOW_BIZ_7: {
2536 int i = wCmd - IDM_WINDOW_BIZ_0;
2537 if ((i < 0) || (i >= MAX_TERM_DATA))
2541 td->bizarre = !td->bizarre;
2543 term_window_resize(td);
2546 case IDM_WINDOW_I_WID_0:
2547 case IDM_WINDOW_I_WID_1:
2548 case IDM_WINDOW_I_WID_2:
2549 case IDM_WINDOW_I_WID_3:
2550 case IDM_WINDOW_I_WID_4:
2551 case IDM_WINDOW_I_WID_5:
2552 case IDM_WINDOW_I_WID_6:
2553 case IDM_WINDOW_I_WID_7: {
2554 int i = wCmd - IDM_WINDOW_I_WID_0;
2555 if ((i < 0) || (i >= MAX_TERM_DATA))
2561 term_window_resize(td);
2564 case IDM_WINDOW_D_WID_0:
2565 case IDM_WINDOW_D_WID_1:
2566 case IDM_WINDOW_D_WID_2:
2567 case IDM_WINDOW_D_WID_3:
2568 case IDM_WINDOW_D_WID_4:
2569 case IDM_WINDOW_D_WID_5:
2570 case IDM_WINDOW_D_WID_6:
2571 case IDM_WINDOW_D_WID_7: {
2572 int i = wCmd - IDM_WINDOW_D_WID_0;
2573 if ((i < 0) || (i >= MAX_TERM_DATA))
2579 term_window_resize(td);
2582 case IDM_WINDOW_I_HGT_0:
2583 case IDM_WINDOW_I_HGT_1:
2584 case IDM_WINDOW_I_HGT_2:
2585 case IDM_WINDOW_I_HGT_3:
2586 case IDM_WINDOW_I_HGT_4:
2587 case IDM_WINDOW_I_HGT_5:
2588 case IDM_WINDOW_I_HGT_6:
2589 case IDM_WINDOW_I_HGT_7: {
2590 int i = wCmd - IDM_WINDOW_I_HGT_0;
2591 if ((i < 0) || (i >= MAX_TERM_DATA))
2597 term_window_resize(td);
2600 case IDM_WINDOW_D_HGT_0:
2601 case IDM_WINDOW_D_HGT_1:
2602 case IDM_WINDOW_D_HGT_2:
2603 case IDM_WINDOW_D_HGT_3:
2604 case IDM_WINDOW_D_HGT_4:
2605 case IDM_WINDOW_D_HGT_5:
2606 case IDM_WINDOW_D_HGT_6:
2607 case IDM_WINDOW_D_HGT_7: {
2608 int i = wCmd - IDM_WINDOW_D_HGT_0;
2609 if ((i < 0) || (i >= MAX_TERM_DATA))
2615 term_window_resize(td);
2618 case IDM_WINDOW_KEEP_SUBWINDOWS: {
2619 keep_subwindows = !keep_subwindows;
2622 case IDM_OPTIONS_NO_GRAPHICS: {
2624 plog("You may not do that right now.");
2628 if (arg_graphics != GRAPHICS_NONE) {
2629 arg_graphics = GRAPHICS_NONE;
2630 term_xtra_win_react(player_ptr);
2631 term_key_push(KTRL('R'));
2636 case IDM_OPTIONS_OLD_GRAPHICS: {
2638 plog("You may not do that right now.");
2642 if (arg_graphics != GRAPHICS_ORIGINAL) {
2643 arg_graphics = GRAPHICS_ORIGINAL;
2644 term_xtra_win_react(player_ptr);
2645 term_key_push(KTRL('R'));
2650 case IDM_OPTIONS_NEW_GRAPHICS: {
2652 plog("You may not do that right now.");
2656 if (arg_graphics != GRAPHICS_ADAM_BOLT) {
2657 arg_graphics = GRAPHICS_ADAM_BOLT;
2658 term_xtra_win_react(player_ptr);
2659 term_key_push(KTRL('R'));
2664 case IDM_OPTIONS_NEW2_GRAPHICS: {
2666 plog("You may not do that right now.");
2670 if (arg_graphics != GRAPHICS_HENGBAND) {
2671 arg_graphics = GRAPHICS_HENGBAND;
2672 term_xtra_win_react(player_ptr);
2673 term_key_push(KTRL('R'));
2678 case IDM_OPTIONS_BIGTILE: {
2681 plog("You may not do that right now.");
2685 arg_bigtile = !arg_bigtile;
2686 term_activate(&td->t);
2687 term_resize(td->cols, td->rows);
2688 InvalidateRect(td->w, NULL, TRUE);
2691 case IDM_OPTIONS_MUSIC: {
2693 plog("You may not do that right now.");
2697 arg_music = !arg_music;
2698 term_xtra_win_react(player_ptr);
2699 term_key_push(KTRL('R'));
2702 case IDM_OPTIONS_SOUND: {
2704 plog("You may not do that right now.");
2708 arg_sound = !arg_sound;
2709 term_xtra_win_react(player_ptr);
2710 term_key_push(KTRL('R'));
2713 case IDM_OPTIONS_BG: {
2715 plog("You may not do that right now.");
2721 term_xtra_win_react(player_ptr);
2722 term_key_push(KTRL('R'));
2725 case IDM_OPTIONS_OPEN_BG: {
2727 plog("You may not do that right now.");
2731 memset(&ofn, 0, sizeof(ofn));
2732 ofn.lStructSize = sizeof(ofn);
2733 ofn.hwndOwner = data[0].w;
2734 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
2735 ofn.nFilterIndex = 1;
2736 ofn.lpstrFile = bg_bitmap_file;
2737 ofn.nMaxFile = 1023;
2738 ofn.lpstrInitialDir = NULL;
2739 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
2740 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
2742 if (GetOpenFileName(&ofn)) {
2747 term_xtra_win_react(player_ptr);
2748 term_key_push(KTRL('R'));
2751 case IDM_DUMP_SCREEN_HTML: {
2752 static char buf[1024] = "";
2753 memset(&ofn, 0, sizeof(ofn));
2754 ofn.lStructSize = sizeof(ofn);
2755 ofn.hwndOwner = data[0].w;
2756 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
2757 ofn.nFilterIndex = 1;
2758 ofn.lpstrFile = buf;
2759 ofn.nMaxFile = 1023;
2760 ofn.lpstrDefExt = "html";
2761 ofn.lpstrInitialDir = NULL;
2762 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
2763 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
2765 if (GetSaveFileName(&ofn)) {
2766 do_cmd_save_screen_html_aux(buf, 0);
2771 case IDM_OPTIONS_SAVER: {
2773 DestroyWindow(hwndSaver);
2778 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass", "Angband Screensaver", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE, 0, 0,
2779 GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL);
2782 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2784 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
2789 case IDM_OPTIONS_MAP: {
2790 windows_map(player_ptr);
2794 case IDM_HELP_CONTENTS: {
2797 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
2798 if (check_file(tmp)) {
2799 sprintf(buf, "winhelp.exe %s", tmp);
2800 WinExec(buf, SW_NORMAL);
2804 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
2805 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
2812 * Add a keypress to the "queue"
2814 static errr term_keypress(int k)
2816 /* Refuse to enqueue non-keys */
2820 /* Store the char, advance the queue */
2821 Term->key_queue[Term->key_head++] = (char)k;
2823 /* Circular queue, handle wrap */
2824 if (Term->key_head == Term->key_size)
2827 if (Term->key_head != Term->key_tail)
2833 static bool process_keydown(WPARAM wParam, LPARAM lParam)
2839 if (GetKeyState(VK_CONTROL) & 0x8000)
2841 if (GetKeyState(VK_SHIFT) & 0x8000)
2843 if (GetKeyState(VK_MENU) & 0x8000)
2846 term_no_press = (ma) ? TRUE : FALSE;
2847 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)])) {
2848 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
2849 bool numpad = FALSE;
2859 int i = LOBYTE(HIWORD(lParam));
2863 term_no_press = TRUE;
2864 [[fallthrough]]; /* Fall through */
2883 term_no_press = TRUE;
2884 [[fallthrough]]; /* Fall through */
2902 term_keypress(hexsym[i / 16]);
2903 term_keypress(hexsym[i % 16]);
2913 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
2915 LRESULT PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2919 td = (term_data *)GetWindowLong(hWnd, 0);
2923 SetWindowLong(hWnd, 0, (LONG)(my_td));
2927 mop.dwCallback = (DWORD)hWnd;
2930 case WM_GETMINMAXINFO: {
2934 lpmmi = (MINMAXINFO *)lParam;
2938 rc.left = rc.top = 0;
2939 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
2940 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
2942 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
2944 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
2945 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
2950 BeginPaint(hWnd, &ps);
2952 term_data_redraw(p_ptr, td);
2953 EndPaint(hWnd, &ps);
2954 ValidateRect(hWnd, NULL);
2957 case MM_MCINOTIFY: {
2958 if (wParam == MCI_NOTIFY_SUCCESSFUL) {
2959 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2960 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2967 if (process_keydown(wParam, lParam))
2973 term_no_press = FALSE;
2975 term_keypress(wParam);
2978 case WM_LBUTTONDOWN: {
2979 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
2980 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
2986 case WM_LBUTTONUP: {
2989 TERM_LEN dx = abs(oldx - mousex) + 1;
2990 TERM_LEN dy = abs(oldy - mousey) + 1;
2991 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
2992 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
2998 int sz = (dx + 3) * dy;
3000 int sz = (dx + 2) * dy;
3002 hGlobal = GlobalAlloc(GHND, sz + 1);
3003 if (hGlobal == NULL)
3005 lpStr = (LPSTR)GlobalLock(hGlobal);
3007 for (int i = 0; i < dy; i++) {
3010 char **scr = data[0].t.scr->c;
3012 C_MAKE(s, (dx + 1), char);
3013 strncpy(s, &scr[oy + i][ox], dx);
3016 if (iskanji(scr[oy + i][ox - 1]))
3020 if (ox + dx < data[0].cols) {
3021 if (iskanji(scr[oy + i][ox + dx - 1]))
3025 for (int j = 0; j < dx; j++) {
3031 for (int j = 0; j < dx; j++) {
3032 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
3041 GlobalUnlock(hGlobal);
3042 if (OpenClipboard(hWnd) == 0) {
3043 GlobalFree(hGlobal);
3048 SetClipboardData(CF_TEXT, hGlobal);
3053 case WM_MOUSEMOVE: {
3058 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
3059 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
3063 dx = abs(oldx - mousex) + 1;
3064 dy = abs(oldy - mousey) + 1;
3065 ox = (oldx > mousex) ? mousex : oldx;
3066 oy = (oldy > mousey) ? mousey : oldy;
3067 term_inversed_area(hWnd, ox, oy, dx, dy);
3072 dx = abs(cx - mousex) + 1;
3073 dy = abs(cy - mousey) + 1;
3074 ox = (cx > mousex) ? mousex : cx;
3075 oy = (cy > mousey) ? mousey : cy;
3076 term_inversed_area(hWnd, ox, oy, dx, dy);
3087 if (!game_in_progress || !current_world_ptr->character_generated) {
3093 plog(_("今は終了できません。", "You may not do that right now."));
3098 forget_lite(p_ptr->current_floor_ptr);
3099 forget_view(p_ptr->current_floor_ptr);
3100 clear_mon_lite(p_ptr->current_floor_ptr);
3101 term_key_push(SPECIAL_KEY_QUIT);
3104 case WM_QUERYENDSESSION: {
3105 if (!game_in_progress || !current_world_ptr->character_generated) {
3112 p_ptr->is_dead = FALSE;
3113 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
3115 p_ptr->panic_save = 1;
3116 signals_ignore_tstp();
3117 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
3118 (void)save_player(p_ptr, SAVE_TYPE_CLOSE_GAME);
3127 process_menus(p_ptr, LOWORD(wParam));
3138 // todo 二重のswitch文。後で分割する.
3140 case SIZE_MINIMIZED: {
3141 for (int i = 1; i < MAX_TERM_DATA; i++) {
3142 if (data[i].visible)
3143 ShowWindow(data[i].w, SW_HIDE);
3148 case SIZE_MAXIMIZED:
3149 case SIZE_RESTORED: {
3150 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
3151 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
3152 if ((td->cols != cols) || (td->rows != rows)) {
3155 if (!IsZoomed(td->w) && !IsIconic(td->w)) {
3156 normsize.x = td->cols;
3157 normsize.y = td->rows;
3160 term_activate(&td->t);
3161 term_resize(td->cols, td->rows);
3162 InvalidateRect(td->w, NULL, TRUE);
3165 td->size_hack = TRUE;
3166 for (int i = 1; i < MAX_TERM_DATA; i++) {
3167 if (data[i].visible)
3168 ShowWindow(data[i].w, SW_SHOW);
3171 td->size_hack = FALSE;
3179 case WM_PALETTECHANGED: {
3180 if ((HWND)wParam == hWnd)
3183 [[fallthrough]]; /* Fall through */
3184 case WM_QUERYNEWPALETTE: {
3188 HDC hdc = GetDC(hWnd);
3189 SelectPalette(hdc, hPal, FALSE);
3190 int i = RealizePalette(hdc);
3192 InvalidateRect(hWnd, NULL, TRUE);
3194 ReleaseDC(hWnd, hdc);
3198 if (!wParam || HIWORD(lParam))
3201 for (int i = 1; i < MAX_TERM_DATA; i++) {
3202 if (!data[i].posfix)
3203 term_window_pos(&data[i], hWnd);
3209 case WM_ACTIVATEAPP: {
3210 if (IsIconic(td->w))
3213 for (int i = 1; i < MAX_TERM_DATA; i++) {
3214 if (data[i].visible) {
3215 if (wParam == TRUE) {
3216 ShowWindow(data[i].w, SW_SHOW);
3218 ShowWindow(data[i].w, SW_HIDE);
3223 [[fallthrough]]; /* Fall through */
3225 if (wParam == FALSE && keep_subwindows) {
3226 for (int i = 0; i < MAX_TERM_DATA; i++) {
3227 if (data[i].visible) {
3228 ShowWindow(data[i].w, SW_SHOW);
3235 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3239 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
3241 LRESULT PASCAL AngbandListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3245 td = (term_data *)GetWindowLong(hWnd, 0);
3249 SetWindowLong(hWnd, 0, (LONG)(my_td));
3255 case WM_GETMINMAXINFO: {
3259 lpmmi = (MINMAXINFO *)lParam;
3263 rc.left = rc.top = 0;
3264 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
3265 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
3267 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3268 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
3269 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
3280 td->size_hack = TRUE;
3282 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
3283 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
3284 if ((td->cols != cols) || (td->rows != rows)) {
3285 term_type *old_term = Term;
3288 term_activate(&td->t);
3289 term_resize(td->cols, td->rows);
3290 term_activate(old_term);
3291 InvalidateRect(td->w, NULL, TRUE);
3292 p_ptr->window_flags = 0xFFFFFFFF;
3293 handle_stuff(p_ptr);
3296 td->size_hack = FALSE;
3300 BeginPaint(hWnd, &ps);
3302 term_data_redraw(p_ptr, td);
3303 EndPaint(hWnd, &ps);
3308 if (process_keydown(wParam, lParam))
3315 term_no_press = FALSE;
3317 term_keypress(wParam);
3320 case WM_PALETTECHANGED: {
3321 if ((HWND)wParam == hWnd)
3324 [[fallthrough]]; /* Fall through */
3325 case WM_QUERYNEWPALETTE: {
3329 HDC hdc = GetDC(hWnd);
3330 SelectPalette(hdc, hPal, FALSE);
3331 int i = RealizePalette(hdc);
3333 InvalidateRect(hWnd, NULL, TRUE);
3335 ReleaseDC(hWnd, hdc);
3338 case WM_NCLBUTTONDOWN: {
3339 if (wParam == HTCLOSE)
3342 if (wParam == HTSYSMENU) {
3344 td->visible = FALSE;
3345 ShowWindow(td->w, SW_HIDE);
3355 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3358 LRESULT PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3360 static int iMouse = 0;
3361 static WORD xMouse = 0;
3362 static WORD yMouse = 0;
3369 case WM_SETCURSOR: {
3374 case WM_LBUTTONDOWN:
3375 case WM_MBUTTONDOWN:
3376 case WM_RBUTTONDOWN:
3378 SendMessage(hWnd, WM_CLOSE, 0, 0);
3381 case WM_MOUSEMOVE: {
3383 int dx = LOWORD(lParam) - xMouse;
3384 int dy = HIWORD(lParam) - yMouse;
3391 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS)) {
3392 SendMessage(hWnd, WM_CLOSE, 0, 0);
3397 xMouse = LOWORD(lParam);
3398 yMouse = HIWORD(lParam);
3403 DestroyWindow(hwndSaver);
3409 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3413 * Display warning message (see "z-util.c")
3415 static void hack_plog(concptr str)
3419 MessageBox(NULL, str, "警告!", MB_ICONEXCLAMATION | MB_OK);
3421 MessageBox(NULL, str, "Warning", MB_ICONEXCLAMATION | MB_OK);
3427 * Display error message and quit (see "z-util.c")
3429 static void hack_quit(concptr str)
3433 MessageBox(NULL, str, "エラー!", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3435 MessageBox(NULL, str, "Error", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3439 UnregisterClass(AppName, hInstance);
3447 * Display warning message (see "z-util.c")
3449 static void hook_plog(concptr str)
3453 MessageBox(data[0].w, str, "警告!", MB_ICONEXCLAMATION | MB_OK);
3455 MessageBox(data[0].w, str, "Warning", MB_ICONEXCLAMATION | MB_OK);
3461 * Display error message and quit (see "z-util.c")
3463 static void hook_quit(concptr str)
3467 MessageBox(data[0].w, str, "エラー!", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3469 MessageBox(data[0].w, str, "Error", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3474 for (int i = MAX_TERM_DATA - 1; i >= 0; --i) {
3475 term_force_font(&data[i], NULL);
3476 if (data[i].font_want)
3477 string_free(data[i].font_want);
3479 DestroyWindow(data[i].w);
3483 if (infGraph.hPalette)
3484 DeleteObject(infGraph.hPalette);
3485 if (infGraph.hBitmap)
3486 DeleteObject(infGraph.hBitmap);
3487 if (infMask.hPalette)
3488 DeleteObject(infMask.hPalette);
3489 if (infMask.hBitmap)
3490 DeleteObject(infMask.hBitmap);
3492 DeleteObject(hbrYellow);
3498 UnregisterClass(AppName, hInstance);
3508 static void init_stuff(void)
3511 GetModuleFileName(hInstance, path, 512);
3513 strcpy(path + strlen(path) - 4, ".INI");
3514 ini_file = string_make(path);
3515 int i = strlen(path);
3517 for (; i > 0; i--) {
3518 if (path[i] == '\\') {
3523 strcpy(path + i + 1, "lib\\");
3524 validate_dir(path, TRUE);
3525 init_file_paths(path, path);
3526 validate_dir(ANGBAND_DIR_APEX, FALSE);
3527 validate_dir(ANGBAND_DIR_BONE, FALSE);
3528 if (!check_dir(ANGBAND_DIR_EDIT)) {
3529 validate_dir(ANGBAND_DIR_DATA, TRUE);
3531 validate_dir(ANGBAND_DIR_DATA, FALSE);
3534 validate_dir(ANGBAND_DIR_FILE, TRUE);
3535 validate_dir(ANGBAND_DIR_HELP, FALSE);
3536 validate_dir(ANGBAND_DIR_INFO, FALSE);
3537 validate_dir(ANGBAND_DIR_PREF, TRUE);
3538 validate_dir(ANGBAND_DIR_SAVE, FALSE);
3539 validate_dir(ANGBAND_DIR_DEBUG_SAVE, FALSE);
3540 validate_dir(ANGBAND_DIR_USER, TRUE);
3541 validate_dir(ANGBAND_DIR_XTRA, TRUE);
3542 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
3544 validate_file(path);
3545 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
3546 ANGBAND_DIR_XTRA_GRAF = string_make(path);
3547 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
3549 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
3550 ANGBAND_DIR_XTRA_SOUND = string_make(path);
3551 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
3553 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
3554 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
3555 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
3557 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
3558 ANGBAND_DIR_XTRA_HELP = string_make(path);
3562 * @brief コマンドラインから全スポイラー出力を行う
3563 * Create Spoiler files from Command Line
3564 * @return spoiler_output_status
3566 static spoiler_output_status create_debug_spoiler(LPSTR cmd_line)
3572 return SPOILER_OUTPUT_CANCEL;
3573 option = "--output-spoilers";
3575 if (strncmp(s, option, strlen(option)) != 0)
3576 return SPOILER_OUTPUT_CANCEL;
3579 init_angband(p_ptr, process_autopick_file_command, TRUE);
3581 return output_all_spoilers();
3585 * todo よく見るとhMutexはちゃんと使われていない……?
3586 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
3588 static bool is_already_running(void)
3591 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
3592 if (GetLastError() == ERROR_ALREADY_EXISTS) {
3600 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
3602 int WINAPI WinMain(_In_ HINSTANCE hInst, _In_opt_ HINSTANCE hPrevInst, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
3608 setlocale(LC_ALL, "ja_JP");
3611 if (is_already_running()) {
3613 NULL, _("変愚蛮怒はすでに起動しています。", "Hengband is already running."), _("エラー!", "Error"), MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3617 switch (create_debug_spoiler(lpCmdLine)) {
3618 case SPOILER_OUTPUT_SUCCESS:
3619 fprintf(stdout, "Successfully created a spoiler file.");
3622 case SPOILER_OUTPUT_FAIL_FOPEN:
3623 fprintf(stderr, "Cannot create spoiler file.");
3626 case SPOILER_OUTPUT_FAIL_FCLOSE:
3627 fprintf(stderr, "Cannot close spoiler file.");
3634 if (hPrevInst == NULL) {
3635 wc.style = CS_CLASSDC;
3636 wc.lpfnWndProc = AngbandWndProc;
3639 wc.hInstance = hInst;
3640 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
3641 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
3642 wc.hbrBackground = static_cast<HBRUSH>(GetStockObject(BLACK_BRUSH));
3643 wc.lpszMenuName = AppName;
3644 wc.lpszClassName = AppName;
3646 if (!RegisterClass(&wc))
3649 wc.lpfnWndProc = AngbandListProc;
3650 wc.lpszMenuName = NULL;
3651 wc.lpszClassName = AngList;
3653 if (!RegisterClass(&wc))
3656 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
3657 wc.lpfnWndProc = AngbandSaverProc;
3659 wc.lpszMenuName = NULL;
3660 wc.lpszClassName = "WindowsScreenSaverClass";
3662 if (!RegisterClass(&wc))
3666 plog_aux = hack_plog;
3667 quit_aux = hack_quit;
3668 core_aux = hack_quit;
3671 for (int i = 0; special_key_list[i]; ++i) {
3672 special_key[special_key_list[i]] = TRUE;
3675 for (int i = 0; ignore_key_list[i]; ++i) {
3676 ignore_key[ignore_key_list[i]] = TRUE;
3680 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
3681 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
3682 ReleaseDC(NULL, hdc);
3684 for (int i = 0; i < 256; i++) {
3685 byte rv = angband_color_table[i][1];
3686 byte gv = angband_color_table[i][2];
3687 byte bv = angband_color_table[i][3];
3688 win_clr[i] = PALETTERGB(rv, gv, bv);
3689 angband_color_table[i][0] = win_pal[i];
3695 plog_aux = hook_plog;
3696 quit_aux = hook_quit;
3697 core_aux = hook_quit;
3699 ANGBAND_SYS = "win";
3700 if (7 != GetKeyboardType(0))
3701 ANGBAND_KEYBOARD = "0";
3703 switch (GetKeyboardType(1)) {
3711 ANGBAND_KEYBOARD = "NEC98";
3715 ANGBAND_KEYBOARD = "JAPAN";
3720 term_activate(term_screen);
3721 init_angband(p_ptr, process_autopick_file_command, FALSE);
3723 check_for_save_file(p_ptr, lpCmdLine);
3724 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
3726 while (GetMessage(&msg, NULL, 0, 0)) {
3727 TranslateMessage(&msg);
3728 DispatchMessage(&msg);
3734 #endif /* WINDOWS */