3 * @brief Windows版固有実装(メインエントリポイント含む)
5 * @author Hengband Team
6 * @todo main関数を含むファイルの割に長過ぎる。main-win-utils.cなどといった形で分割したい
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 * All of these extra files can be found in the "ext-win" archive.
57 * The "term_xtra_win_clear()" function should probably do a low-level
58 * clear of the current window, and redraw the borders and other things,
59 * if only for efficiency.
63 * A simpler method is needed for selecting the "tile size" for windows.
67 * The various "warning" messages assume the existance of the "screen.w"
68 * window, I think, and only a few calls actually check for its existance,
69 * this may be okay since "NULL" means "on top of all windows". (?) The
70 * user must never be allowed to "hide" the main window, or the "menubar"
75 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
77 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
79 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
80 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
86 #include "cmd-io/cmd-process-screen.h"
87 #include "cmd-io/cmd-save.h"
88 #include "core/game-play.h"
89 #include "core/player-processor.h"
90 #include "core/scores.h"
91 #include "core/special-internal-keys.h"
92 #include "core/stuff-handler.h"
93 #include "core/visuals-reseter.h"
94 #include "floor/floor-events.h"
95 #include "game-option/runtime-arguments.h"
96 #include "game-option/special-options.h"
97 #include "io/files-util.h"
98 #include "io/input-key-acceptor.h"
99 #include "io/record-play-movie.h"
100 #include "io/signal-handlers.h"
101 #include "io/write-diary.h"
102 #include "main-win/main-win-bg.h"
103 #include "main-win/main-win-file-utils.h"
104 #include "main-win/main-win-mci.h"
105 #include "main-win/main-win-menuitem.h"
106 #include "main-win/main-win-music.h"
107 #include "main-win/main-win-sound.h"
108 #include "main/angband-initializer.h"
109 #include "main/sound-of-music.h"
110 #include "monster-floor/monster-lite.h"
111 #include "save/save.h"
112 #include "system/angband-version.h"
113 #include "system/angband.h"
114 #include "system/system-variables.h"
115 #include "term/gameterm.h"
116 #include "term/screen-processor.h"
117 #include "term/term-color-types.h"
118 #include "util/angband-files.h"
119 #include "util/int-char-converter.h"
120 #include "util/string-processor.h"
121 #include "view/display-messages.h"
122 #include "wizard/spoiler-util.h"
123 #include "wizard/wizard-spoiler.h"
124 #include "world/world.h"
133 * Include the support for loading bitmaps
135 #include "term/readdib.h"
138 * Available graphic modes
140 #define GRAPHICS_NONE 0
141 #define GRAPHICS_ORIGINAL 1
142 #define GRAPHICS_ADAM_BOLT 2
143 #define GRAPHICS_HENGBAND 3
146 * Foreground color bits
148 #define VID_BLACK 0x00
149 #define VID_BLUE 0x01
150 #define VID_GREEN 0x02
151 #define VID_CYAN 0x03
153 #define VID_MAGENTA 0x05
154 #define VID_YELLOW 0x06
155 #define VID_WHITE 0x07
160 #define VID_BRIGHT 0x08
164 * @brief ターム情報構造体 / Extra "term" data
167 * pos_x / pos_y は各タームの左上点座標を指す。
170 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
171 * 1ドットずつ調整するステータスを指す。
172 * また、フォントを変更すると都度自動調整される。
175 * Note the use of "font_want" for the names of the font file requested by
187 TERM_LEN rows; /* int -> uint */
190 uint pos_x; //!< タームの左上X座標
191 uint pos_y; //!< タームの左上Y座標
204 int font_wid; //!< フォント横幅
205 int font_hgt; //!< フォント縦幅
206 int tile_wid; //!< タイル横幅
207 int tile_hgt; //!< タイル縦幅
214 #define MAX_TERM_DATA 8 //!< Maximum number of windows
216 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
217 static term_data *my_td; //!< Hack -- global "window creation" pointer
218 POINT normsize; //!< Remember normal size of main window when maxmized
221 * was main window maximized on previous playing
223 bool win_maximized = FALSE;
228 bool game_in_progress = FALSE;
231 * note when "open"/"new" become valid
233 bool initialized = FALSE;
236 * screen paletted, i.e. 256 colors
238 bool paletted = FALSE;
241 * 16 colors screen, don't use RGB()
243 bool colors16 = FALSE;
246 * Saved instance handle
248 static HINSTANCE hInstance;
251 * Yellow brush for the cursor
253 static HBRUSH hbrYellow;
263 static HPALETTE hPal;
266 static int use_bg = 0; //!< 背景使用フラグ、1なら使用。
267 #define DEFAULT_BG_FILENAME "bg.bmp"
270 * 現在使用中のタイルID(0ならば未使用)
271 * Flag set once "graphics" has been initialized
273 static byte current_graphics_mode = 0;
278 static DIBINIT infGraph;
281 * The global bitmap mask
283 static DIBINIT infMask;
286 * Show sub-windows even when Hengband is not in focus
288 static bool keep_subwindows = TRUE;
291 * Full path to ANGBAND.INI
293 static concptr ini_file = NULL;
296 * Name of application
298 static concptr AppName = "ANGBAND";
301 * Name of sub-window type
303 static concptr AngList = "AngList";
308 static concptr ANGBAND_DIR_XTRA_GRAF;
311 * The "complex" color values
313 static COLORREF win_clr[256];
316 * Flag for macro trigger with dump ASCII
318 static bool term_no_press = FALSE;
323 static bool mouse_down = FALSE;
324 static bool paint_rect = FALSE;
325 static TERM_LEN mousex = 0, mousey = 0;
326 static TERM_LEN oldx, oldy;
329 * @brief The "simple" color values
331 * See "main-ibm.c" for original table information
332 * The entries below are taken from the "color bits" defined above.
333 * Note that many of the choices below suck, but so do crappy monitors.
335 static BYTE win_pal[256] = {
336 VID_BLACK, /* Dark */
337 VID_WHITE, /* White */
338 VID_CYAN, /* Slate XXX */
339 VID_RED | VID_BRIGHT, /* Orange XXX */
341 VID_GREEN, /* Green */
343 VID_YELLOW, /* Umber XXX */
344 VID_BLACK | VID_BRIGHT, /* Light Dark */
345 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
346 VID_MAGENTA, /* Violet XXX */
347 VID_YELLOW | VID_BRIGHT, /* Yellow */
348 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
349 VID_GREEN | VID_BRIGHT, /* Light Green */
350 VID_BLUE | VID_BRIGHT, /* Light Blue */
351 VID_YELLOW /* Light Umber XXX */
355 * Hack -- define which keys are "special"
357 static bool special_key[256];
358 static bool ignore_key[256];
361 * Hack -- initialization list for "special_key"
363 static byte special_key_list[] = {
364 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,
365 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,
366 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,
367 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,
368 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,
372 static byte ignore_key_list[] = {
373 VK_ESCAPE, VK_TAB, VK_SPACE, 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
374 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 */
380 static void validate_file(concptr s)
385 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
389 * Validate a directory
391 static void validate_dir(concptr s, bool vital)
397 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
398 } else if (mkdir(s)) {
399 quit_fmt("Unable to create directory:\n%s", s);
404 * @brief (Windows版固有実装)Get the "size" for a window
406 static void term_getsize(term_data *td)
413 TERM_LEN wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
414 TERM_LEN hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
418 GetWindowRect(td->w, &rw);
419 GetClientRect(td->w, &rc);
421 td->size_wid = (rw.right - rw.left) - (rc.right - rc.left) + wid;
422 td->size_hgt = (rw.bottom - rw.top) - (rc.bottom - rc.top) + hgt;
427 /* Tempolary calculation */
432 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
433 td->size_wid = rc.right - rc.left;
434 td->size_hgt = rc.bottom - rc.top;
439 * Write the "prefs" for a single term
441 static void save_prefs_aux(int i)
443 term_data *td = &data[i];
444 GAME_TEXT sec_name[128];
450 sprintf(sec_name, "Term-%d", i);
453 strcpy(buf, td->visible ? "1" : "0");
454 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
458 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "MS ゴシック");
460 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "Courier");
463 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
465 wsprintf(buf, "%d", td->lf.lfWidth);
466 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
467 wsprintf(buf, "%d", td->lf.lfHeight);
468 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
469 wsprintf(buf, "%d", td->lf.lfWeight);
470 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
472 wsprintf(buf, "%d", td->tile_wid);
473 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
475 wsprintf(buf, "%d", td->tile_hgt);
476 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
478 WINDOWPLACEMENT lpwndpl;
479 lpwndpl.length = sizeof(WINDOWPLACEMENT);
480 GetWindowPlacement(td->w, &lpwndpl);
482 RECT rc = lpwndpl.rcNormalPosition;
484 wsprintf(buf, "%d", normsize.x);
486 wsprintf(buf, "%d", td->cols);
488 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
491 wsprintf(buf, "%d", normsize.y);
493 wsprintf(buf, "%d", td->rows);
495 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
497 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
498 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
501 GetWindowRect(td->w, &rc);
502 wsprintf(buf, "%d", rc.left);
503 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
505 wsprintf(buf, "%d", rc.top);
506 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
508 strcpy(buf, td->posfix ? "1" : "0");
509 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
515 * We assume that the windows have all been initialized
517 static void save_prefs(void)
520 sprintf(buf, "%d", arg_graphics);
521 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
523 strcpy(buf, arg_bigtile ? "1" : "0");
524 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
526 strcpy(buf, arg_sound ? "1" : "0");
527 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
529 strcpy(buf, arg_music ? "1" : "0");
530 WritePrivateProfileString("Angband", "Music", buf, ini_file);
531 strcpy(buf, use_pause_music_inactive ? "1" : "0");
532 WritePrivateProfileString("Angband", "MusicPauseInactive", buf, ini_file);
534 strcpy(buf, use_bg ? "1" : "0");
535 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
536 WritePrivateProfileString("Angband", "BackGroundBitmap", bg_bitmap_file[0] != '\0' ? bg_bitmap_file : DEFAULT_BG_FILENAME, ini_file);
538 int path_length = strlen(ANGBAND_DIR) - 4; /* \libの4文字分を削除 */
540 strncat(tmp, ANGBAND_DIR, path_length);
542 int n = strncmp(tmp, savefile, path_length);
544 char relative_path[1024] = "";
545 snprintf(relative_path, sizeof(relative_path), ".\\%s", (savefile + path_length));
546 WritePrivateProfileString("Angband", "SaveFile", relative_path, ini_file);
548 WritePrivateProfileString("Angband", "SaveFile", savefile, ini_file);
551 strcpy(buf, keep_subwindows ? "1" : "0");
552 WritePrivateProfileString("Angband", "KeepSubwindows", buf, ini_file);
554 for (int i = 0; i < MAX_TERM_DATA; ++i) {
560 * callback for EnumDisplayMonitors API
562 BOOL CALLBACK monitorenumproc([[maybe_unused]] HMONITOR hMon, [[maybe_unused]] HDC hdcMon, [[maybe_unused]] LPRECT lpMon, LPARAM dwDate)
564 bool *result = (bool *)dwDate;
570 * Load the "prefs" for a single term
572 static void load_prefs_aux(int i)
574 term_data *td = &data[i];
575 GAME_TEXT sec_name[128];
578 sprintf(sec_name, "Term-%d", i);
579 sprintf(sec_name, "Term-%d", i);
581 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
585 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
587 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
590 td->font_want = string_make(tmp);
593 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
594 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
595 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
597 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
598 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
600 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
601 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
602 normsize.x = td->cols;
603 normsize.y = td->rows;
606 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
609 int posx = GetPrivateProfileInt(sec_name, "PositionX", 0, ini_file);
610 int posy = GetPrivateProfileInt(sec_name, "PositionY", 0, ini_file);
611 // 保存座標がモニタ内の領域にあるかチェック
612 RECT rect = { posx, posy, posx + 128, posy + 128 };
613 bool in_any_monitor = false;
614 ::EnumDisplayMonitors(NULL, &rect, monitorenumproc, (LPARAM)&in_any_monitor);
615 if (in_any_monitor) {
616 // いずれかのモニタに表示可能、ウインドウ位置を復元
622 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
629 static void load_prefs(void)
631 arg_graphics = (byte)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
632 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
633 use_bigtile = arg_bigtile;
634 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
635 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
636 use_pause_music_inactive = (GetPrivateProfileInt("Angband", "MusicPauseInactive", 0, ini_file) != 0);
637 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
638 GetPrivateProfileString("Angband", "BackGroundBitmap", DEFAULT_BG_FILENAME, bg_bitmap_file, 1023, ini_file);
639 GetPrivateProfileString("Angband", "SaveFile", "", savefile, 1023, ini_file);
641 int n = strncmp(".\\", savefile, 2);
643 int path_length = strlen(ANGBAND_DIR) - 4; /* \libの4文字分を削除 */
645 strncat(tmp, ANGBAND_DIR, path_length);
646 strncat(tmp, savefile + 2, strlen(savefile) - 2 + path_length);
647 strncpy(savefile, tmp, strlen(tmp));
650 keep_subwindows = (GetPrivateProfileInt("Angband", "KeepSubwindows", 0, ini_file) != 0);
651 for (int i = 0; i < MAX_TERM_DATA; ++i) {
657 * Create the new global palette based on the bitmap palette
658 * (if any), and the standard 16 entry palette derived from
659 * "win_clr[]" which is used for the basic 16 Angband colors.
661 * This function is never called before all windows are ready.
663 * This function returns FALSE if the new palette could not be
664 * prepared, which should normally be a fatal error. XXX XXX
666 * Note that only some machines actually use a "palette".
668 static int new_palette(void)
673 LPLOGPALETTE pLogPal;
683 HPALETTE hBmPal = static_cast<HPALETTE>(infGraph.hPalette);
685 lppeSize = 256 * sizeof(PALETTEENTRY);
686 lppe = (LPPALETTEENTRY)std::malloc(lppeSize);
687 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
688 if ((nEntries == 0) || (nEntries > 220)) {
689 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
695 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
696 pLogPal = (LPLOGPALETTE)std::malloc(pLogPalSize);
697 pLogPal->palVersion = 0x300;
698 pLogPal->palNumEntries = nEntries + 16;
699 for (i = 0; i < nEntries; i++) {
700 pLogPal->palPalEntry[i] = lppe[i];
703 for (i = 0; i < 16; i++) {
705 p = &(pLogPal->palPalEntry[i + nEntries]);
706 p->peRed = GetRValue(win_clr[i]);
707 p->peGreen = GetGValue(win_clr[i]);
708 p->peBlue = GetBValue(win_clr[i]);
709 p->peFlags = PC_NOCOLLAPSE;
715 HPALETTE hNewPal = CreatePalette(pLogPal);
717 quit(_("パレットを作成できません!", "Cannot create palette!"));
721 HDC hdc = GetDC(td->w);
722 SelectPalette(hdc, hNewPal, 0);
723 i = RealizePalette(hdc);
724 ReleaseDC(td->w, hdc);
726 quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
728 for (i = 1; i < MAX_TERM_DATA; i++) {
731 SelectPalette(hdc, hNewPal, 0);
732 ReleaseDC(td->w, hdc);
743 * @brief グラフィクスを初期化する / Initialize graphics
746 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
747 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
750 static bool init_graphics(void)
753 BYTE wid, hgt, twid, thgt, ox, oy;
756 if (arg_graphics == GRAPHICS_ADAM_BOLT) {
765 ANGBAND_GRAF = "new";
766 } else if (arg_graphics == GRAPHICS_HENGBAND) {
775 ANGBAND_GRAF = "ne2";
784 ANGBAND_GRAF = "old";
787 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
788 if (!ReadDIB(data[0].w, buf, &infGraph)) {
789 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
793 infGraph.CellWidth = wid;
794 infGraph.CellHeight = hgt;
795 infGraph.TileWidth = twid;
796 infGraph.TileHeight = thgt;
797 infGraph.OffsetX = ox;
798 infGraph.OffsetY = oy;
800 if (arg_graphics == GRAPHICS_ADAM_BOLT) {
801 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
802 if (!ReadDIB(data[0].w, buf, &infMask)) {
803 plog_fmt("Cannot read bitmap file '%s'", buf);
808 if (arg_graphics == GRAPHICS_HENGBAND) {
809 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
810 if (!ReadDIB(data[0].w, buf, &infMask)) {
811 plog_fmt("Cannot read bitmap file '%s'", buf);
816 if (!new_palette()) {
817 plog(_("パレットを実現できません!", "Cannot activate palette!"));
821 current_graphics_mode = arg_graphics;
822 return current_graphics_mode != 0;
828 static void init_music(void)
830 // Flag set once "music" has been initialized
831 static bool can_use_music = FALSE;
833 if (!can_use_music) {
834 main_win_music::load_music_prefs();
835 can_use_music = TRUE;
842 static void init_sound(void)
844 // Flag set once "sound" has been initialized
845 static bool can_use_sound = FALSE;
847 if (!can_use_sound) {
849 can_use_sound = TRUE;
854 * Initialize background
856 static void init_background(void)
858 // Flag set once "background" has been initialized
859 static bool can_use_background = FALSE;
861 if (!can_use_background) {
863 can_use_background = TRUE;
868 * @brief Resize a window
870 static void term_window_resize(term_data *td)
875 SetWindowPos(td->w, 0, 0, 0, td->size_wid, td->size_hgt, SWP_NOMOVE | SWP_NOZORDER);
876 InvalidateRect(td->w, NULL, TRUE);
880 * @brief Force the use of a new font for a term_data.
881 * This function may be called before the "window" is ready.
882 * This function returns zero only if everything succeeds.
883 * @note that the "font name" must be capitalized!!!
885 static errr term_force_font(term_data *td)
888 DeleteObject(td->font_id);
890 td->font_id = CreateFontIndirect(&(td->lf));
891 int wid = td->lf.lfWidth;
892 int hgt = td->lf.lfHeight;
901 hdcDesktop = GetDC(HWND_DESKTOP);
902 hfOld = static_cast<HFONT>(SelectObject(hdcDesktop, td->font_id));
903 GetTextMetrics(hdcDesktop, &tm);
904 SelectObject(hdcDesktop, hfOld);
905 ReleaseDC(HWND_DESKTOP, hdcDesktop);
907 wid = tm.tmAveCharWidth;
918 * Allow the user to change the font for this window.
920 static void term_change_font(term_data *td)
923 memset(&cf, 0, sizeof(cf));
924 cf.lStructSize = sizeof(cf);
925 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
926 cf.lpLogFont = &(td->lf);
928 if (!ChooseFont(&cf))
932 td->tile_wid = td->font_wid;
933 td->tile_hgt = td->font_hgt;
935 term_window_resize(td);
939 * Allow the user to lock this window.
941 static void term_window_pos(term_data *td, HWND hWnd)
943 SetWindowPos(td->w, hWnd, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
947 * Hack -- redraw a term_data
949 static void term_data_redraw(term_data *td)
951 term_activate(&td->t);
953 term_activate(term_screen);
956 void term_inversed_area(HWND hWnd, int x, int y, int w, int h)
958 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
959 int tx = td->size_ow1 + x * td->tile_wid;
960 int ty = td->size_oh1 + y * td->tile_hgt;
961 int tw = w * td->tile_wid - 1;
962 int th = h * td->tile_hgt - 1;
964 HDC hdc = GetDC(hWnd);
965 HBRUSH myBrush = CreateSolidBrush(RGB(255, 255, 255));
966 HBRUSH oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
967 HPEN oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
969 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
971 SelectObject(hdc, oldBrush);
972 SelectObject(hdc, oldPen);
976 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
978 static errr term_user_win(int n)
985 * React to global changes
987 static errr term_xtra_win_react(player_type *player_ptr)
990 for (int i = 0; i < 256; i++) {
991 win_pal[i] = angband_color_table[i][0];
997 for (int i = 0; i < 256; i++) {
998 rv = angband_color_table[i][1];
999 gv = angband_color_table[i][2];
1000 bv = angband_color_table[i][3];
1001 code = PALETTERGB(rv, gv, bv);
1002 if (win_clr[i] != code) {
1009 (void)new_palette();
1012 use_sound = arg_sound;
1017 if (use_graphics != (arg_graphics > 0)) {
1018 if (arg_graphics && !init_graphics()) {
1019 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
1020 arg_graphics = GRAPHICS_NONE;
1023 use_graphics = (arg_graphics > 0);
1024 reset_visuals(player_ptr);
1027 for (int i = 0; i < MAX_TERM_DATA; i++) {
1028 term_type *old = Term;
1029 term_data *td = &data[i];
1030 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt)) {
1031 term_activate(&td->t);
1032 term_resize(td->cols, td->rows);
1042 * Process at least one event
1044 static errr term_xtra_win_event(int v)
1048 if (GetMessage(&msg, NULL, 0, 0)) {
1049 TranslateMessage(&msg);
1050 DispatchMessage(&msg);
1053 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
1054 TranslateMessage(&msg);
1055 DispatchMessage(&msg);
1063 * Process all pending events
1065 static errr term_xtra_win_flush(void)
1068 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
1069 TranslateMessage(&msg);
1070 DispatchMessage(&msg);
1077 * Hack -- clear the screen
1079 * Make this more efficient
1081 static errr term_xtra_win_clear(void)
1083 term_data *td = (term_data *)(Term->data);
1086 rc.left = td->size_ow1;
1087 rc.right = rc.left + td->cols * td->tile_wid;
1088 rc.top = td->size_oh1;
1089 rc.bottom = rc.top + td->rows * td->tile_hgt;
1091 HDC hdc = GetDC(td->w);
1092 SetBkColor(hdc, RGB(0, 0, 0));
1093 SelectObject(hdc, td->font_id);
1094 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1102 ReleaseDC(td->w, hdc);
1107 * Hack -- make a noise
1109 static errr term_xtra_win_noise(void)
1111 MessageBeep(MB_ICONASTERISK);
1116 * Hack -- make a sound
1118 static errr term_xtra_win_sound(int v)
1122 return play_sound(v);
1126 * Hack -- play a music
1128 static errr term_xtra_win_music(int n, int v)
1134 return main_win_music::play_music(n, v);
1138 * Hack -- play a music matches a situation
1140 static errr term_xtra_win_scene(int v)
1142 // TODO 場面に合った壁紙変更対応
1147 return main_win_music::play_music_scene(v);
1151 * Delay for "x" milliseconds
1153 static int term_xtra_win_delay(int v)
1160 * @brief Do a "special thing"
1161 * @todo z-termに影響があるのでplayer_typeの追加は保留
1163 static errr term_xtra_win(int n, int v)
1166 case TERM_XTRA_NOISE: {
1167 return (term_xtra_win_noise());
1169 case TERM_XTRA_MUSIC_BASIC:
1170 case TERM_XTRA_MUSIC_DUNGEON:
1171 case TERM_XTRA_MUSIC_QUEST:
1172 case TERM_XTRA_MUSIC_TOWN:
1173 case TERM_XTRA_MUSIC_MONSTER: {
1174 return term_xtra_win_music(n, v);
1176 case TERM_XTRA_MUSIC_MUTE: {
1177 return main_win_music::stop_music();
1179 case TERM_XTRA_SCENE: {
1180 return term_xtra_win_scene(v);
1182 case TERM_XTRA_SOUND: {
1183 return (term_xtra_win_sound(v));
1185 case TERM_XTRA_BORED: {
1186 return (term_xtra_win_event(0));
1188 case TERM_XTRA_EVENT: {
1189 return (term_xtra_win_event(v));
1191 case TERM_XTRA_FLUSH: {
1192 return (term_xtra_win_flush());
1194 case TERM_XTRA_CLEAR: {
1195 return (term_xtra_win_clear());
1197 case TERM_XTRA_REACT: {
1198 return (term_xtra_win_react(p_ptr));
1200 case TERM_XTRA_DELAY: {
1201 return (term_xtra_win_delay(v));
1209 * Low level graphics (Assumes valid input).
1211 * Draw a "cursor" at (x,y), using a "yellow box".
1213 static errr term_curs_win(int x, int y)
1215 term_data *td = (term_data *)(Term->data);
1216 int tile_wid, tile_hgt;
1217 tile_wid = td->tile_wid;
1218 tile_hgt = td->tile_hgt;
1221 rc.left = x * tile_wid + td->size_ow1;
1222 rc.right = rc.left + tile_wid;
1223 rc.top = y * tile_hgt + td->size_oh1;
1224 rc.bottom = rc.top + tile_hgt;
1226 HDC hdc = GetDC(td->w);
1227 FrameRect(hdc, &rc, hbrYellow);
1228 ReleaseDC(td->w, hdc);
1233 * Low level graphics (Assumes valid input).
1235 * Draw a "big cursor" at (x,y), using a "yellow box".
1237 static errr term_bigcurs_win(int x, int y)
1239 term_data *td = (term_data *)(Term->data);
1240 int tile_wid, tile_hgt;
1241 tile_wid = td->tile_wid;
1242 tile_hgt = td->tile_hgt;
1245 rc.left = x * tile_wid + td->size_ow1;
1246 rc.right = rc.left + 2 * tile_wid;
1247 rc.top = y * tile_hgt + td->size_oh1;
1248 rc.bottom = rc.top + tile_hgt;
1250 HDC hdc = GetDC(td->w);
1251 FrameRect(hdc, &rc, hbrYellow);
1252 ReleaseDC(td->w, hdc);
1257 * Low level graphics (Assumes valid input).
1259 * Erase a "block" of "n" characters starting at (x,y).
1261 static errr term_wipe_win(int x, int y, int n)
1263 term_data *td = (term_data *)(Term->data);
1265 rc.left = x * td->tile_wid + td->size_ow1;
1266 rc.right = rc.left + n * td->tile_wid;
1267 rc.top = y * td->tile_hgt + td->size_oh1;
1268 rc.bottom = rc.top + td->tile_hgt;
1270 HDC hdc = GetDC(td->w);
1271 SetBkColor(hdc, RGB(0, 0, 0));
1272 SelectObject(hdc, td->font_id);
1276 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1278 ReleaseDC(td->w, hdc);
1283 * Low level graphics. Assumes valid input.
1285 * Draw several ("n") chars, with an attr, at a given location.
1287 * All "graphic" data is handled by "term_pict_win()", below.
1289 * One would think there is a more efficient method for telling a window
1290 * what color it should be using to draw with, but perhaps simply changing
1291 * it every time is not too inefficient.
1293 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
1295 term_data *td = (term_data *)(Term->data);
1296 static HBITMAP WALL;
1297 static HBRUSH myBrush, oldBrush;
1299 static bool init_done = FALSE;
1302 WALL = LoadBitmap(hInstance, AppName);
1303 myBrush = CreatePatternBrush(WALL);
1308 rc.left = x * td->tile_wid + td->size_ow1;
1309 rc.right = rc.left + n * td->tile_wid;
1310 rc.top = y * td->tile_hgt + td->size_oh1;
1311 rc.bottom = rc.top + td->tile_hgt;
1313 HDC hdc = GetDC(td->w);
1314 SetBkColor(hdc, RGB(0, 0, 0));
1316 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
1317 } else if (paletted) {
1318 SetTextColor(hdc, win_clr[a & 0x0F]);
1320 SetTextColor(hdc, win_clr[a]);
1323 SelectObject(hdc, td->font_id);
1325 SetBkMode(hdc, TRANSPARENT);
1327 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1331 rc.left += ((td->tile_wid - td->font_wid) / 2);
1332 rc.right = rc.left + td->font_wid;
1333 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
1334 rc.bottom = rc.top + td->font_hgt;
1336 for (int i = 0; i < n; i++) {
1338 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1]) {
1339 rc.right += td->font_wid;
1340 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1341 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1342 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1343 SelectObject(hdc, oldBrush);
1344 SelectObject(hdc, oldPen);
1345 rc.right -= td->font_wid;
1347 rc.left += 2 * td->tile_wid;
1348 rc.right += 2 * td->tile_wid;
1349 } else if (iskanji(*(s + i))) /* 2バイト文字 */
1351 rc.right += td->font_wid;
1352 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 2, NULL);
1353 rc.right -= td->font_wid;
1355 rc.left += 2 * td->tile_wid;
1356 rc.right += 2 * td->tile_wid;
1357 } else if (*(s + i) == 127) {
1358 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1359 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1360 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1361 SelectObject(hdc, oldBrush);
1362 SelectObject(hdc, oldPen);
1363 rc.left += td->tile_wid;
1364 rc.right += td->tile_wid;
1366 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1367 rc.left += td->tile_wid;
1368 rc.right += td->tile_wid;
1371 if (*(s + i) == 127) {
1372 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1373 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1374 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1375 SelectObject(hdc, oldBrush);
1376 SelectObject(hdc, oldPen);
1377 rc.left += td->tile_wid;
1378 rc.right += td->tile_wid;
1380 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1381 rc.left += td->tile_wid;
1382 rc.right += td->tile_wid;
1387 ReleaseDC(td->w, hdc);
1392 * Low level graphics. Assumes valid input.
1394 * Draw an array of "special" attr/char pairs at the given location.
1396 * We use the "term_pict_win()" function for "graphic" data, which are
1397 * encoded by setting the "high-bits" of both the "attr" and the "char"
1398 * data. We use the "attr" to represent the "row" of the main bitmap,
1399 * and the "char" to represent the "col" of the main bitmap. The use
1400 * of this function is induced by the "higher_pict" flag.
1402 * If "graphics" is not available, we simply "wipe" the given grids.
1404 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)
1406 term_data *td = (term_data *)(Term->data);
1409 if (!use_graphics) {
1410 return (term_wipe_win(x, y, n));
1413 TERM_LEN w1 = infGraph.CellWidth;
1414 TERM_LEN h1 = infGraph.CellHeight;
1415 TERM_LEN tw1 = infGraph.TileWidth;
1416 TERM_LEN th1 = infGraph.TileHeight;
1417 TERM_LEN w2, h2, tw2 = 0;
1424 TERM_LEN x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
1425 TERM_LEN y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
1426 HDC hdc = GetDC(td->w);
1427 HDC hdcSrc = CreateCompatibleDC(hdc);
1428 HBITMAP hbmSrcOld = static_cast<HBITMAP>(SelectObject(hdcSrc, infGraph.hBitmap));
1430 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1431 hdcMask = CreateCompatibleDC(hdc);
1432 SelectObject(hdcMask, infMask.hBitmap);
1435 for (i = 0; i < n; i++, x2 += w2) {
1436 TERM_COLOR a = ap[i];
1438 int row = (a & 0x7F);
1439 int col = (c & 0x7F);
1440 TERM_LEN x1 = col * w1;
1441 TERM_LEN y1 = row * h1;
1443 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1444 TERM_LEN x3 = (tcp[i] & 0x7F) * w1;
1445 TERM_LEN y3 = (tap[i] & 0x7F) * h1;
1446 tw2 = tw2 * w1 / tw1;
1448 if ((tw1 == tw2) && (th1 == h2)) {
1449 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
1450 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
1451 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
1455 SetStretchBltMode(hdc, COLORONCOLOR);
1456 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
1457 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
1458 if ((x1 != x3) || (y1 != y3)) {
1459 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
1460 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
1466 if ((w1 == tw2) && (h1 == h2)) {
1467 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
1471 SetStretchBltMode(hdc, COLORONCOLOR);
1472 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
1475 SelectObject(hdcSrc, hbmSrcOld);
1477 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1478 SelectObject(hdcMask, hbmSrcOld);
1482 ReleaseDC(td->w, hdc);
1487 * Create and initialize a "term_data" given a title
1489 static void term_data_link(term_data *td)
1491 term_type *t = &td->t;
1492 term_init(t, td->cols, td->rows, FILE_READ_BUFF_SIZE);
1493 t->soft_cursor = TRUE;
1494 t->higher_pict = TRUE;
1495 t->attr_blank = TERM_WHITE;
1496 t->char_blank = ' ';
1497 t->user_hook = term_user_win;
1498 t->xtra_hook = term_xtra_win;
1499 t->curs_hook = term_curs_win;
1500 t->bigcurs_hook = term_bigcurs_win;
1501 t->wipe_hook = term_wipe_win;
1502 t->text_hook = term_text_win;
1503 t->pict_hook = term_pict_win;
1504 t->data = (vptr)(td);
1508 * Create the windows
1510 * First, instantiate the "default" values, then read the "ini_file"
1511 * to over-ride selected values, then create the windows, and fonts.
1513 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
1514 * must make active to realize the palette.
1516 static void init_windows(void)
1520 WIPE(td, term_data);
1524 td->s = angband_term_name[0];
1539 for (int i = 1; i < MAX_TERM_DATA; i++) {
1541 WIPE(td, term_data);
1542 td->s = angband_term_name[i];
1546 td->visible = FALSE;
1551 td->pos_x = (7 - i) * 30;
1552 td->pos_y = (7 - i) * 20;
1558 /* Atrributes of main window */
1560 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_VISIBLE);
1564 /* Attributes of sub windows */
1565 for (int i = 1; i < MAX_TERM_DATA; i++) {
1567 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
1568 td->dwExStyle = (WS_EX_TOOLWINDOW);
1571 /* Font of each window */
1572 for (int i = 0; i < MAX_TERM_DATA; i++) {
1574 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
1575 td->lf.lfCharSet = DEFAULT_CHARSET;
1576 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
1577 term_force_font(td);
1579 td->tile_wid = td->font_wid;
1581 td->tile_hgt = td->font_hgt;
1583 term_window_resize(td);
1586 /* Create sub windows */
1587 for (int i = MAX_TERM_DATA - 1; i >= 1; --i) {
1592 = 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);
1596 quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
1598 td->size_hack = TRUE;
1600 term_window_resize(td);
1603 ShowWindow(td->w, SW_SHOW);
1605 td->size_hack = FALSE;
1608 angband_term[i] = &td->t;
1611 /* Activate the window */
1612 SetActiveWindow(td->w);
1616 term_window_pos(td, HWND_TOPMOST);
1618 term_window_pos(td, td->w);
1622 /* Create main window */
1625 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);
1629 quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
1632 td->size_hack = TRUE;
1634 term_window_resize(td);
1635 td->size_hack = FALSE;
1638 angband_term[0] = &td->t;
1639 normsize.x = td->cols;
1640 normsize.y = td->rows;
1643 ShowWindow(td->w, SW_SHOWMAXIMIZED);
1645 ShowWindow(td->w, SW_SHOW);
1647 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
1648 (void)new_palette();
1649 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
1650 (void)term_xtra_win_flush();
1656 static void setup_menus(void)
1658 HMENU hm = GetMenu(data[0].w);
1660 if (current_world_ptr->character_generated) {
1661 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1662 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1663 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_ENABLED);
1665 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
1666 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
1667 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1670 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_ENABLED);
1671 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_ENABLED);
1673 for (int i = 0; i < MAX_TERM_DATA; i++) {
1674 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1675 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i, (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
1676 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_ENABLED);
1679 for (int i = 0; i < MAX_TERM_DATA; i++) {
1680 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1682 if (data[i].visible) {
1683 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1687 for (int i = 0; i < MAX_TERM_DATA; i++) {
1688 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1689 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i, (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
1690 if (data[i].visible) {
1691 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_ENABLED);
1695 for (int i = 0; i < MAX_TERM_DATA; i++) {
1696 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1697 if (data[i].visible) {
1698 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
1702 for (int i = 0; i < MAX_TERM_DATA; i++) {
1703 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1704 if (data[i].visible) {
1705 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
1709 for (int i = 0; i < MAX_TERM_DATA; i++) {
1710 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1711 if (data[i].visible) {
1712 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1716 for (int i = 0; i < MAX_TERM_DATA; i++) {
1717 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1719 if (data[i].visible) {
1720 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1723 EnableMenuItem(hm, IDM_WINDOW_KEEP_SUBWINDOWS, MF_BYCOMMAND | MF_ENABLED);
1724 CheckMenuItem(hm, IDM_WINDOW_KEEP_SUBWINDOWS, (keep_subwindows ? MF_CHECKED : MF_UNCHECKED));
1726 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1727 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1728 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1729 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1730 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1732 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
1733 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
1734 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
1735 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS, (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
1736 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE, (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
1737 CheckMenuItem(hm, IDM_OPTIONS_MUSIC, (arg_music ? MF_CHECKED : MF_UNCHECKED));
1738 CheckMenuItem(hm, IDM_OPTIONS_MUSIC_PAUSE_INACTIVE, (use_pause_music_inactive ? MF_CHECKED : MF_UNCHECKED));
1739 CheckMenuItem(hm, IDM_OPTIONS_SOUND, (arg_sound ? MF_CHECKED : MF_UNCHECKED));
1740 CheckMenuItem(hm, IDM_OPTIONS_BG, (use_bg ? MF_CHECKED : MF_UNCHECKED));
1742 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
1743 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
1744 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
1745 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
1746 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
1750 * Check for double clicked (or dragged) savefile
1752 * Apparently, Windows copies the entire filename into the first
1753 * piece of the "command line string". Perhaps we should extract
1754 * the "basename" of that filename and append it to the "save" dir.
1756 static void check_for_save_file(player_type *player_ptr, LPSTR cmd_line)
1763 strcpy(savefile, s);
1764 validate_file(savefile);
1765 game_in_progress = TRUE;
1766 play_game(player_ptr, FALSE, FALSE);
1770 * Process a menu command
1772 static void process_menus(player_type *player_ptr, WORD wCmd)
1775 plog(_("まだ初期化中です...", "You cannot do that yet..."));
1782 case IDM_FILE_NEW: {
1783 if (game_in_progress) {
1784 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
1786 game_in_progress = TRUE;
1788 strcpy(savefile, "");
1789 play_game(player_ptr, TRUE, FALSE);
1795 case IDM_FILE_OPEN: {
1796 if (game_in_progress) {
1797 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
1799 memset(&ofn, 0, sizeof(ofn));
1800 ofn.lStructSize = sizeof(ofn);
1801 ofn.hwndOwner = data[0].w;
1802 ofn.lpstrFilter = "Save Files (*.)\0*\0";
1803 ofn.nFilterIndex = 1;
1804 ofn.lpstrFile = savefile;
1805 ofn.nMaxFile = 1024;
1806 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
1807 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
1809 if (GetOpenFileName(&ofn)) {
1810 validate_file(savefile);
1811 game_in_progress = TRUE;
1813 play_game(player_ptr, FALSE, FALSE);
1820 case IDM_FILE_SAVE: {
1821 if (game_in_progress && current_world_ptr->character_generated) {
1823 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
1828 do_cmd_save_game(player_ptr, FALSE);
1830 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
1835 case IDM_FILE_EXIT: {
1836 if (game_in_progress && current_world_ptr->character_generated) {
1838 plog(_("今は終了できません。", "You may not do that right now."));
1843 forget_lite(player_ptr->current_floor_ptr);
1844 forget_view(player_ptr->current_floor_ptr);
1845 clear_mon_lite(player_ptr->current_floor_ptr);
1847 term_key_push(SPECIAL_KEY_QUIT);
1854 case IDM_FILE_SCORE: {
1856 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
1857 highscore_fd = fd_open(buf, O_RDONLY);
1858 if (highscore_fd < 0) {
1859 msg_print("Score file unavailable.");
1863 display_scores_aux(0, MAX_HISCORES, -1, NULL);
1864 (void)fd_close(highscore_fd);
1872 case IDM_FILE_MOVIE: {
1873 if (game_in_progress) {
1874 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
1876 memset(&ofn, 0, sizeof(ofn));
1877 ofn.lStructSize = sizeof(ofn);
1878 ofn.hwndOwner = data[0].w;
1879 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
1880 ofn.nFilterIndex = 1;
1881 ofn.lpstrFile = savefile;
1882 ofn.nMaxFile = 1024;
1883 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
1884 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1886 if (GetOpenFileName(&ofn)) {
1887 prepare_browse_movie_without_path_build(savefile);
1888 play_game(player_ptr, FALSE, TRUE);
1896 case IDM_WINDOW_VIS_0: {
1897 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
1900 case IDM_WINDOW_VIS_1:
1901 case IDM_WINDOW_VIS_2:
1902 case IDM_WINDOW_VIS_3:
1903 case IDM_WINDOW_VIS_4:
1904 case IDM_WINDOW_VIS_5:
1905 case IDM_WINDOW_VIS_6:
1906 case IDM_WINDOW_VIS_7: {
1907 int i = wCmd - IDM_WINDOW_VIS_0;
1908 if ((i < 0) || (i >= MAX_TERM_DATA))
1914 ShowWindow(td->w, SW_SHOW);
1915 term_data_redraw(td);
1917 td->visible = FALSE;
1919 ShowWindow(td->w, SW_HIDE);
1924 case IDM_WINDOW_FONT_0:
1925 case IDM_WINDOW_FONT_1:
1926 case IDM_WINDOW_FONT_2:
1927 case IDM_WINDOW_FONT_3:
1928 case IDM_WINDOW_FONT_4:
1929 case IDM_WINDOW_FONT_5:
1930 case IDM_WINDOW_FONT_6:
1931 case IDM_WINDOW_FONT_7: {
1932 int i = wCmd - IDM_WINDOW_FONT_0;
1933 if ((i < 0) || (i >= MAX_TERM_DATA))
1937 term_change_font(td);
1940 case IDM_WINDOW_POS_1:
1941 case IDM_WINDOW_POS_2:
1942 case IDM_WINDOW_POS_3:
1943 case IDM_WINDOW_POS_4:
1944 case IDM_WINDOW_POS_5:
1945 case IDM_WINDOW_POS_6:
1946 case IDM_WINDOW_POS_7: {
1947 int i = wCmd - IDM_WINDOW_POS_0;
1948 if ((i < 0) || (i >= MAX_TERM_DATA))
1952 if (!td->posfix && td->visible) {
1954 term_window_pos(td, HWND_TOPMOST);
1957 term_window_pos(td, data[0].w);
1962 case IDM_WINDOW_I_WID_0:
1963 case IDM_WINDOW_I_WID_1:
1964 case IDM_WINDOW_I_WID_2:
1965 case IDM_WINDOW_I_WID_3:
1966 case IDM_WINDOW_I_WID_4:
1967 case IDM_WINDOW_I_WID_5:
1968 case IDM_WINDOW_I_WID_6:
1969 case IDM_WINDOW_I_WID_7: {
1970 int i = wCmd - IDM_WINDOW_I_WID_0;
1971 if ((i < 0) || (i >= MAX_TERM_DATA))
1977 term_window_resize(td);
1980 case IDM_WINDOW_D_WID_0:
1981 case IDM_WINDOW_D_WID_1:
1982 case IDM_WINDOW_D_WID_2:
1983 case IDM_WINDOW_D_WID_3:
1984 case IDM_WINDOW_D_WID_4:
1985 case IDM_WINDOW_D_WID_5:
1986 case IDM_WINDOW_D_WID_6:
1987 case IDM_WINDOW_D_WID_7: {
1988 int i = wCmd - IDM_WINDOW_D_WID_0;
1989 if ((i < 0) || (i >= MAX_TERM_DATA))
1995 term_window_resize(td);
1998 case IDM_WINDOW_I_HGT_0:
1999 case IDM_WINDOW_I_HGT_1:
2000 case IDM_WINDOW_I_HGT_2:
2001 case IDM_WINDOW_I_HGT_3:
2002 case IDM_WINDOW_I_HGT_4:
2003 case IDM_WINDOW_I_HGT_5:
2004 case IDM_WINDOW_I_HGT_6:
2005 case IDM_WINDOW_I_HGT_7: {
2006 int i = wCmd - IDM_WINDOW_I_HGT_0;
2007 if ((i < 0) || (i >= MAX_TERM_DATA))
2013 term_window_resize(td);
2016 case IDM_WINDOW_D_HGT_0:
2017 case IDM_WINDOW_D_HGT_1:
2018 case IDM_WINDOW_D_HGT_2:
2019 case IDM_WINDOW_D_HGT_3:
2020 case IDM_WINDOW_D_HGT_4:
2021 case IDM_WINDOW_D_HGT_5:
2022 case IDM_WINDOW_D_HGT_6:
2023 case IDM_WINDOW_D_HGT_7: {
2024 int i = wCmd - IDM_WINDOW_D_HGT_0;
2025 if ((i < 0) || (i >= MAX_TERM_DATA))
2031 term_window_resize(td);
2034 case IDM_WINDOW_KEEP_SUBWINDOWS: {
2035 keep_subwindows = !keep_subwindows;
2038 case IDM_OPTIONS_NO_GRAPHICS: {
2039 if (arg_graphics != GRAPHICS_NONE) {
2040 arg_graphics = GRAPHICS_NONE;
2043 term_xtra_win_react(player_ptr);
2044 term_key_push(KTRL('R'));
2049 case IDM_OPTIONS_OLD_GRAPHICS: {
2050 if (arg_graphics != GRAPHICS_ORIGINAL) {
2051 arg_graphics = GRAPHICS_ORIGINAL;
2054 term_xtra_win_react(player_ptr);
2055 term_key_push(KTRL('R'));
2056 } else if (!init_graphics()) {
2057 arg_graphics = GRAPHICS_NONE;
2063 case IDM_OPTIONS_NEW_GRAPHICS: {
2064 if (arg_graphics != GRAPHICS_ADAM_BOLT) {
2065 arg_graphics = GRAPHICS_ADAM_BOLT;
2068 term_xtra_win_react(player_ptr);
2069 term_key_push(KTRL('R'));
2070 } else if (!init_graphics()) {
2071 arg_graphics = GRAPHICS_NONE;
2077 case IDM_OPTIONS_NEW2_GRAPHICS: {
2078 if (arg_graphics != GRAPHICS_HENGBAND) {
2079 arg_graphics = GRAPHICS_HENGBAND;
2082 term_xtra_win_react(player_ptr);
2083 term_key_push(KTRL('R'));
2084 } else if (!init_graphics()) {
2085 arg_graphics = GRAPHICS_NONE;
2091 case IDM_OPTIONS_BIGTILE: {
2093 arg_bigtile = !arg_bigtile;
2094 term_activate(&td->t);
2095 term_resize(td->cols, td->rows);
2096 InvalidateRect(td->w, NULL, TRUE);
2099 case IDM_OPTIONS_MUSIC: {
2100 arg_music = !arg_music;
2101 use_music = arg_music;
2104 if (game_in_progress)
2105 select_floor_music(player_ptr);
2107 main_win_music::stop_music();
2111 case IDM_OPTIONS_MUSIC_PAUSE_INACTIVE: {
2112 use_pause_music_inactive = !use_pause_music_inactive;
2115 case IDM_OPTIONS_SOUND: {
2116 arg_sound = !arg_sound;
2118 term_xtra_win_react(player_ptr);
2121 case IDM_OPTIONS_BG: {
2122 use_bg = !(use_bg > 0);
2131 InvalidateRect(td->w, NULL, TRUE);
2134 case IDM_OPTIONS_OPEN_BG: {
2135 memset(&ofn, 0, sizeof(ofn));
2136 ofn.lStructSize = sizeof(ofn);
2137 ofn.hwndOwner = data[0].w;
2138 ofn.lpstrFilter = "Image Files (*.bmp;*.png;*.jpg;*.jpeg;)\0*.bmp;*.png;*.jpg;*.jpeg;\0";
2139 ofn.nFilterIndex = 1;
2140 ofn.lpstrFile = bg_bitmap_file;
2141 ofn.nMaxFile = 1023;
2142 ofn.lpstrInitialDir = NULL;
2143 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
2144 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
2146 if (GetOpenFileName(&ofn)) {
2151 InvalidateRect(td->w, NULL, TRUE);
2155 case IDM_DUMP_SCREEN_HTML: {
2156 static char buf[1024] = "";
2157 memset(&ofn, 0, sizeof(ofn));
2158 ofn.lStructSize = sizeof(ofn);
2159 ofn.hwndOwner = data[0].w;
2160 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
2161 ofn.nFilterIndex = 1;
2162 ofn.lpstrFile = buf;
2163 ofn.nMaxFile = 1023;
2164 ofn.lpstrDefExt = "html";
2165 ofn.lpstrInitialDir = NULL;
2166 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
2167 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
2169 if (GetSaveFileName(&ofn)) {
2170 do_cmd_save_screen_html_aux(buf, 0);
2179 * Add a keypress to the "queue"
2181 static errr term_keypress(int k)
2183 /* Refuse to enqueue non-keys */
2187 /* Store the char, advance the queue */
2188 Term->key_queue[Term->key_head++] = (char)k;
2190 /* Circular queue, handle wrap */
2191 if (Term->key_head == Term->key_size)
2194 if (Term->key_head != Term->key_tail)
2200 static bool process_keydown(WPARAM wParam, LPARAM lParam)
2206 if (GetKeyState(VK_CONTROL) & 0x8000)
2208 if (GetKeyState(VK_SHIFT) & 0x8000)
2210 if (GetKeyState(VK_MENU) & 0x8000)
2213 term_no_press = (ma) ? TRUE : FALSE;
2214 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)])) {
2215 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
2216 bool numpad = FALSE;
2226 int i = LOBYTE(HIWORD(lParam));
2230 term_no_press = TRUE;
2231 [[fallthrough]]; /* Fall through */
2250 term_no_press = TRUE;
2251 [[fallthrough]]; /* Fall through */
2269 term_keypress(hexsym[i / 16]);
2270 term_keypress(hexsym[i % 16]);
2279 static void handle_app_active(HWND hWnd, UINT uMsg, WPARAM wParam, [[maybe_unused]] LPARAM lParam)
2282 case WM_ACTIVATEAPP: {
2284 if (use_pause_music_inactive)
2285 main_win_music::resume_music();
2287 if (use_pause_music_inactive)
2288 main_win_music::pause_music();
2292 case WM_WINDOWPOSCHANGING: {
2293 if (!IsIconic(hWnd))
2294 if (use_pause_music_inactive)
2295 main_win_music::resume_music();
2302 * @todo WNDCLASSに影響があるのでplayer_type*の追加は保留
2304 LRESULT PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2308 td = (term_data *)GetWindowLong(hWnd, 0);
2310 handle_app_active(hWnd, uMsg, wParam, lParam);
2314 SetWindowLong(hWnd, 0, (LONG)(my_td));
2321 case WM_GETMINMAXINFO: {
2325 lpmmi = (MINMAXINFO *)lParam;
2329 rc.left = rc.top = 0;
2330 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
2331 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
2333 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
2335 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
2336 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
2341 BeginPaint(hWnd, &ps);
2343 term_data_redraw(td);
2344 EndPaint(hWnd, &ps);
2345 ValidateRect(hWnd, NULL);
2348 case MM_MCINOTIFY: {
2349 main_win_music::on_mci_notify(wParam, lParam);
2355 if (process_keydown(wParam, lParam))
2361 term_no_press = FALSE;
2363 term_keypress(wParam);
2366 case WM_LBUTTONDOWN: {
2367 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
2368 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
2374 case WM_LBUTTONUP: {
2377 TERM_LEN dx = abs(oldx - mousex) + 1;
2378 TERM_LEN dy = abs(oldy - mousey) + 1;
2379 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
2380 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
2386 int sz = (dx + 3) * dy;
2388 int sz = (dx + 2) * dy;
2390 hGlobal = GlobalAlloc(GHND, sz + 1);
2391 if (hGlobal == NULL)
2393 lpStr = (LPSTR)GlobalLock(hGlobal);
2395 for (int i = 0; i < dy; i++) {
2398 char **scr = data[0].t.scr->c;
2400 C_MAKE(s, (dx + 1), char);
2401 strncpy(s, &scr[oy + i][ox], dx);
2404 if (iskanji(scr[oy + i][ox - 1]))
2408 if (ox + dx < data[0].cols) {
2409 if (iskanji(scr[oy + i][ox + dx - 1]))
2413 for (int j = 0; j < dx; j++) {
2419 for (int j = 0; j < dx; j++) {
2420 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
2429 GlobalUnlock(hGlobal);
2430 if (OpenClipboard(hWnd) == 0) {
2431 GlobalFree(hGlobal);
2436 SetClipboardData(CF_TEXT, hGlobal);
2441 case WM_MOUSEMOVE: {
2446 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
2447 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
2451 dx = abs(oldx - mousex) + 1;
2452 dy = abs(oldy - mousey) + 1;
2453 ox = (oldx > mousex) ? mousex : oldx;
2454 oy = (oldy > mousey) ? mousey : oldy;
2455 term_inversed_area(hWnd, ox, oy, dx, dy);
2460 dx = abs(cx - mousex) + 1;
2461 dy = abs(cy - mousey) + 1;
2462 ox = (cx > mousex) ? mousex : cx;
2463 oy = (cy > mousey) ? mousey : cy;
2464 term_inversed_area(hWnd, ox, oy, dx, dy);
2475 if (!game_in_progress || !current_world_ptr->character_generated) {
2481 plog(_("今は終了できません。", "You may not do that right now."));
2486 forget_lite(p_ptr->current_floor_ptr);
2487 forget_view(p_ptr->current_floor_ptr);
2488 clear_mon_lite(p_ptr->current_floor_ptr);
2489 term_key_push(SPECIAL_KEY_QUIT);
2492 case WM_QUERYENDSESSION: {
2493 if (!game_in_progress || !current_world_ptr->character_generated) {
2500 p_ptr->is_dead = FALSE;
2501 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
2503 p_ptr->panic_save = 1;
2504 signals_ignore_tstp();
2505 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
2506 (void)save_player(p_ptr, SAVE_TYPE_CLOSE_GAME);
2515 process_menus(p_ptr, LOWORD(wParam));
2526 //!< @todo 二重のswitch文。後で分割する.
2528 case SIZE_MINIMIZED: {
2529 for (int i = 1; i < MAX_TERM_DATA; i++) {
2530 if (data[i].visible)
2531 ShowWindow(data[i].w, SW_HIDE);
2536 case SIZE_MAXIMIZED:
2537 case SIZE_RESTORED: {
2538 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
2539 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
2540 if ((td->cols != cols) || (td->rows != rows)) {
2543 if (!IsZoomed(td->w) && !IsIconic(td->w)) {
2544 normsize.x = td->cols;
2545 normsize.y = td->rows;
2548 term_activate(&td->t);
2549 term_resize(td->cols, td->rows);
2550 InvalidateRect(td->w, NULL, TRUE);
2553 td->size_hack = TRUE;
2554 for (int i = 1; i < MAX_TERM_DATA; i++) {
2555 if (data[i].visible)
2556 ShowWindow(data[i].w, SW_SHOW);
2559 td->size_hack = FALSE;
2567 case WM_PALETTECHANGED: {
2568 if ((HWND)wParam == hWnd)
2571 [[fallthrough]]; /* Fall through */
2572 case WM_QUERYNEWPALETTE: {
2576 HDC hdc = GetDC(hWnd);
2577 SelectPalette(hdc, hPal, FALSE);
2578 int i = RealizePalette(hdc);
2580 InvalidateRect(hWnd, NULL, TRUE);
2582 ReleaseDC(hWnd, hdc);
2586 if (!wParam || HIWORD(lParam))
2589 for (int i = 1; i < MAX_TERM_DATA; i++) {
2590 if (!data[i].posfix)
2591 term_window_pos(&data[i], hWnd);
2597 case WM_ACTIVATEAPP: {
2598 if (IsIconic(td->w))
2601 for (int i = 1; i < MAX_TERM_DATA; i++) {
2602 if (data[i].visible) {
2603 if (wParam == TRUE) {
2604 ShowWindow(data[i].w, SW_SHOW);
2606 ShowWindow(data[i].w, SW_HIDE);
2611 [[fallthrough]]; /* Fall through */
2613 if (wParam == FALSE && keep_subwindows) {
2614 for (int i = 0; i < MAX_TERM_DATA; i++) {
2615 if (data[i].visible) {
2616 ShowWindow(data[i].w, SW_SHOW);
2623 return DefWindowProc(hWnd, uMsg, wParam, lParam);
2627 * @todo WNDCLASSに影響があるのでplayer_type*の追加は保留
2629 LRESULT PASCAL AngbandListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2633 td = (term_data *)GetWindowLong(hWnd, 0);
2637 SetWindowLong(hWnd, 0, (LONG)(my_td));
2643 case WM_GETMINMAXINFO: {
2647 lpmmi = (MINMAXINFO *)lParam;
2651 rc.left = rc.top = 0;
2652 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
2653 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
2655 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
2656 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
2657 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
2668 td->size_hack = TRUE;
2670 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
2671 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
2672 if ((td->cols != cols) || (td->rows != rows)) {
2673 term_type *old_term = Term;
2676 term_activate(&td->t);
2677 term_resize(td->cols, td->rows);
2678 term_activate(old_term);
2679 InvalidateRect(td->w, NULL, TRUE);
2680 p_ptr->window_flags = 0xFFFFFFFF;
2681 handle_stuff(p_ptr);
2684 td->size_hack = FALSE;
2688 BeginPaint(hWnd, &ps);
2690 term_data_redraw(td);
2691 EndPaint(hWnd, &ps);
2696 if (process_keydown(wParam, lParam))
2703 term_no_press = FALSE;
2705 term_keypress(wParam);
2708 case WM_PALETTECHANGED: {
2709 if ((HWND)wParam == hWnd)
2712 [[fallthrough]]; /* Fall through */
2713 case WM_QUERYNEWPALETTE: {
2717 HDC hdc = GetDC(hWnd);
2718 SelectPalette(hdc, hPal, FALSE);
2719 int i = RealizePalette(hdc);
2721 InvalidateRect(hWnd, NULL, TRUE);
2723 ReleaseDC(hWnd, hdc);
2726 case WM_NCLBUTTONDOWN: {
2727 if (wParam == HTCLOSE)
2730 if (wParam == HTSYSMENU) {
2732 td->visible = FALSE;
2733 ShowWindow(td->w, SW_HIDE);
2743 return DefWindowProc(hWnd, uMsg, wParam, lParam);
2747 * Display warning message (see "z-util.c")
2749 static void hack_plog(concptr str)
2753 MessageBox(NULL, str, "警告!", MB_ICONEXCLAMATION | MB_OK);
2755 MessageBox(NULL, str, "Warning", MB_ICONEXCLAMATION | MB_OK);
2761 * Display error message and quit (see "z-util.c")
2763 static void hack_quit(concptr str)
2767 MessageBox(NULL, str, "エラー!", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2769 MessageBox(NULL, str, "Error", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2773 UnregisterClass(AppName, hInstance);
2781 * Display warning message (see "z-util.c")
2783 static void hook_plog(concptr str)
2787 MessageBox(data[0].w, str, "警告!", MB_ICONEXCLAMATION | MB_OK);
2789 MessageBox(data[0].w, str, "Warning", MB_ICONEXCLAMATION | MB_OK);
2795 * Display error message and quit (see "z-util.c")
2797 static void hook_quit(concptr str)
2801 MessageBox(data[0].w, str, "エラー!", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2803 MessageBox(data[0].w, str, "Error", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2808 for (int i = MAX_TERM_DATA - 1; i >= 0; --i) {
2809 term_force_font(&data[i]);
2810 if (data[i].font_want)
2811 string_free(data[i].font_want);
2813 DestroyWindow(data[i].w);
2817 if (infGraph.hPalette)
2818 DeleteObject(infGraph.hPalette);
2819 if (infGraph.hBitmap)
2820 DeleteObject(infGraph.hBitmap);
2821 if (infMask.hPalette)
2822 DeleteObject(infMask.hPalette);
2823 if (infMask.hBitmap)
2824 DeleteObject(infMask.hBitmap);
2826 DeleteObject(hbrYellow);
2832 UnregisterClass(AppName, hInstance);
2842 static void init_stuff(void)
2845 GetModuleFileName(hInstance, path, 512);
2847 strcpy(path + strlen(path) - 4, ".INI");
2848 ini_file = string_make(path);
2849 int i = strlen(path);
2851 for (; i > 0; i--) {
2852 if (path[i] == '\\') {
2857 strcpy(path + i + 1, "lib\\");
2858 validate_dir(path, TRUE);
2859 init_file_paths(path, path);
2860 validate_dir(ANGBAND_DIR_APEX, FALSE);
2861 validate_dir(ANGBAND_DIR_BONE, FALSE);
2862 if (!check_dir(ANGBAND_DIR_EDIT)) {
2863 validate_dir(ANGBAND_DIR_DATA, TRUE);
2865 validate_dir(ANGBAND_DIR_DATA, FALSE);
2868 validate_dir(ANGBAND_DIR_FILE, TRUE);
2869 validate_dir(ANGBAND_DIR_HELP, FALSE);
2870 validate_dir(ANGBAND_DIR_INFO, FALSE);
2871 validate_dir(ANGBAND_DIR_PREF, TRUE);
2872 validate_dir(ANGBAND_DIR_SAVE, FALSE);
2873 validate_dir(ANGBAND_DIR_DEBUG_SAVE, FALSE);
2874 validate_dir(ANGBAND_DIR_USER, TRUE);
2875 validate_dir(ANGBAND_DIR_XTRA, TRUE);
2876 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
2878 validate_file(path);
2879 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
2880 ANGBAND_DIR_XTRA_GRAF = string_make(path);
2881 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
2883 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
2884 ANGBAND_DIR_XTRA_SOUND = string_make(path);
2885 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
2887 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
2888 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
2889 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
2893 * @brief コマンドラインから全スポイラー出力を行う
2894 * Create Spoiler files from Command Line
2895 * @return spoiler_output_status
2897 static spoiler_output_status create_debug_spoiler(LPSTR cmd_line)
2903 return SPOILER_OUTPUT_CANCEL;
2904 option = "--output-spoilers";
2906 if (strncmp(s, option, strlen(option)) != 0)
2907 return SPOILER_OUTPUT_CANCEL;
2910 init_angband(p_ptr, TRUE);
2912 return output_all_spoilers();
2916 * @todo よく見るとhMutexはちゃんと使われていない……?
2917 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
2919 static bool is_already_running(void)
2922 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
2923 if (GetLastError() == ERROR_ALREADY_EXISTS) {
2931 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
2933 int WINAPI WinMain(_In_ HINSTANCE hInst, _In_opt_ HINSTANCE hPrevInst, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
2939 setlocale(LC_ALL, "ja_JP");
2942 if (is_already_running()) {
2944 NULL, _("変愚蛮怒はすでに起動しています。", "Hengband is already running."), _("エラー!", "Error"), MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2948 switch (create_debug_spoiler(lpCmdLine)) {
2949 case SPOILER_OUTPUT_SUCCESS:
2950 fprintf(stdout, "Successfully created a spoiler file.");
2953 case SPOILER_OUTPUT_FAIL_FOPEN:
2954 fprintf(stderr, "Cannot create spoiler file.");
2957 case SPOILER_OUTPUT_FAIL_FCLOSE:
2958 fprintf(stderr, "Cannot close spoiler file.");
2965 if (hPrevInst == NULL) {
2966 wc.style = CS_CLASSDC;
2967 wc.lpfnWndProc = AngbandWndProc;
2970 wc.hInstance = hInst;
2971 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
2972 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
2973 wc.hbrBackground = static_cast<HBRUSH>(GetStockObject(BLACK_BRUSH));
2974 wc.lpszMenuName = AppName;
2975 wc.lpszClassName = AppName;
2977 if (!RegisterClass(&wc))
2980 wc.lpfnWndProc = AngbandListProc;
2981 wc.lpszMenuName = NULL;
2982 wc.lpszClassName = AngList;
2984 if (!RegisterClass(&wc))
2988 plog_aux = hack_plog;
2989 quit_aux = hack_quit;
2990 core_aux = hack_quit;
2993 for (int i = 0; special_key_list[i]; ++i) {
2994 special_key[special_key_list[i]] = TRUE;
2997 for (int i = 0; ignore_key_list[i]; ++i) {
2998 ignore_key[ignore_key_list[i]] = TRUE;
3002 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
3003 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
3004 ReleaseDC(NULL, hdc);
3006 for (int i = 0; i < 256; i++) {
3007 byte rv = angband_color_table[i][1];
3008 byte gv = angband_color_table[i][2];
3009 byte bv = angband_color_table[i][3];
3010 win_clr[i] = PALETTERGB(rv, gv, bv);
3011 angband_color_table[i][0] = win_pal[i];
3020 use_music = arg_music;
3025 plog_aux = hook_plog;
3026 quit_aux = hook_quit;
3027 core_aux = hook_quit;
3029 ANGBAND_SYS = "win";
3030 if (7 != GetKeyboardType(0))
3031 ANGBAND_KEYBOARD = "0";
3033 switch (GetKeyboardType(1)) {
3041 ANGBAND_KEYBOARD = "NEC98";
3045 ANGBAND_KEYBOARD = "JAPAN";
3050 term_activate(term_screen);
3051 init_angband(p_ptr, FALSE);
3053 check_for_save_file(p_ptr, lpCmdLine);
3054 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
3056 while (GetMessage(&msg, NULL, 0, 0)) {
3057 TranslateMessage(&msg);
3058 DispatchMessage(&msg);
3064 #endif /* WINDOWS */