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 wall.bmp.
44 * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
45 * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
50 * Compiling this file, and using the resulting executable, requires
51 * several extra files not distributed with the standard Angband code.
52 * All of these extra files can be found in the "ext-win" archive.
56 * The "term_xtra_win_clear()" function should probably do a low-level
57 * clear of the current window, and redraw the borders and other things,
58 * if only for efficiency.
62 * A simpler method is needed for selecting the "tile size" for windows.
66 * The various "warning" messages assume the existance of the "screen.w"
67 * window, I think, and only a few calls actually check for its existance,
68 * this may be okay since "NULL" means "on top of all windows". (?) The
69 * user must never be allowed to "hide" the main window, or the "menubar"
74 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
76 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
78 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
79 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
85 #include "cmd-io/cmd-process-screen.h"
86 #include "cmd-io/cmd-save.h"
87 #include "core/game-play.h"
88 #include "core/player-processor.h"
89 #include "core/scores.h"
90 #include "core/special-internal-keys.h"
91 #include "core/stuff-handler.h"
92 #include "core/visuals-reseter.h"
93 #include "floor/floor-events.h"
94 #include "game-option/runtime-arguments.h"
95 #include "game-option/special-options.h"
96 #include "io/files-util.h"
97 #include "io/input-key-acceptor.h"
98 #include "io/record-play-movie.h"
99 #include "io/signal-handlers.h"
100 #include "io/write-diary.h"
101 #include "main-win/main-win-bg.h"
102 #include "main-win/main-win-file-utils.h"
103 #include "main-win/main-win-mci.h"
104 #include "main-win/main-win-menuitem.h"
105 #include "main-win/main-win-music.h"
106 #include "main-win/main-win-sound.h"
107 #include "main-win/read-graphics.h"
108 #include "main-win/string-win.h"
109 #include "main-win/tile-info.h"
110 #include "main/angband-initializer.h"
111 #include "main/sound-of-music.h"
112 #include "monster-floor/monster-lite.h"
113 #include "save/save.h"
114 #include "system/angband-version.h"
115 #include "system/angband.h"
116 #include "system/system-variables.h"
117 #include "term/gameterm.h"
118 #include "term/screen-processor.h"
119 #include "term/term-color-types.h"
120 #include "util/angband-files.h"
121 #include "util/int-char-converter.h"
122 #include "util/string-processor.h"
123 #include "view/display-messages.h"
124 #include "wizard/spoiler-util.h"
125 #include "wizard/wizard-spoiler.h"
126 #include "world/world.h"
135 * Available graphic modes
139 GRAPHICS_ORIGINAL = 1,
140 GRAPHICS_ADAM_BOLT = 2,
141 GRAPHICS_HENGBAND = 3,
146 * @brief ターム情報構造体 / Extra "term" data
149 * pos_x / pos_y は各タームの左上点座標を指す。
152 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
153 * 1ドットずつ調整するステータスを指す。
154 * また、フォントを変更すると都度自動調整される。
157 * Note the use of "font_want" for the names of the font file requested by
169 TERM_LEN rows; /* int -> uint */
172 uint pos_x; //!< タームの左上X座標
173 uint pos_y; //!< タームの左上Y座標
186 int font_wid; //!< フォント横幅
187 int font_hgt; //!< フォント縦幅
188 int tile_wid; //!< タイル横幅
189 int tile_hgt; //!< タイル縦幅
196 #define MAX_TERM_DATA 8 //!< Maximum number of windows
198 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
199 static term_data *my_td; //!< Hack -- global "window creation" pointer
200 POINT normsize; //!< Remember normal size of main window when maxmized
203 * was main window maximized on previous playing
205 bool win_maximized = FALSE;
210 bool game_in_progress = FALSE;
213 * note when "open"/"new" become valid
215 bool initialized = FALSE;
218 * Saved instance handle
220 static HINSTANCE hInstance;
223 * Yellow brush for the cursor
225 static HBRUSH hbrYellow;
238 bg_mode current_bg_mode = bg_mode::BG_NONE;
239 #define DEFAULT_BG_FILENAME "bg.bmp"
240 char wallpaper_file[MAIN_WIN_MAX_PATH] = ""; //!< 壁紙ファイル名。
243 * 現在使用中のタイルID(0ならば未使用)
244 * Flag set once "graphics" has been initialized
246 static byte current_graphics_mode = 0;
251 static tile_info infGraph;
254 * The global tile mask
256 static tile_info infMask;
259 * Show sub-windows even when Hengband is not in focus
261 static bool keep_subwindows = TRUE;
264 * Full path to ANGBAND.INI
266 static concptr ini_file = NULL;
269 * Name of application
271 static concptr AppName = "ANGBAND";
274 * Name of sub-window type
276 static concptr AngList = "AngList";
281 static concptr ANGBAND_DIR_XTRA_GRAF;
284 * The "complex" color values
286 static COLORREF win_clr[256];
289 * Flag for macro trigger with dump ASCII
291 static bool term_no_press = FALSE;
296 static bool mouse_down = FALSE;
297 static bool paint_rect = FALSE;
298 static TERM_LEN mousex = 0, mousey = 0;
299 static TERM_LEN oldx, oldy;
302 * Hack -- define which keys are "special"
304 static bool special_key[256];
305 static bool ignore_key[256];
308 * Hack -- initialization list for "special_key"
310 static byte special_key_list[] = {
311 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,
312 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,
313 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,
314 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,
315 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,
319 static byte ignore_key_list[] = {
320 VK_ESCAPE, VK_TAB, VK_SPACE, 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
321 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 */
327 static void validate_file(concptr s)
332 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
336 * Validate a directory
338 static void validate_dir(concptr s, bool vital)
344 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
345 } else if (mkdir(s)) {
346 quit_fmt("Unable to create directory:\n%s", s);
351 * @brief (Windows版固有実装)Get the "size" for a window
353 static void term_getsize(term_data *td)
360 TERM_LEN wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
361 TERM_LEN hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
365 GetWindowRect(td->w, &rw);
366 GetClientRect(td->w, &rc);
368 td->size_wid = (rw.right - rw.left) - (rc.right - rc.left) + wid;
369 td->size_hgt = (rw.bottom - rw.top) - (rc.bottom - rc.top) + hgt;
374 /* Tempolary calculation */
379 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
380 td->size_wid = rc.right - rc.left;
381 td->size_hgt = rc.bottom - rc.top;
386 * Write the "prefs" for a single term
388 static void save_prefs_aux(int i)
390 term_data *td = &data[i];
391 GAME_TEXT sec_name[128];
397 sprintf(sec_name, "Term-%d", i);
400 strcpy(buf, td->visible ? "1" : "0");
401 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
405 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "MS ゴシック");
407 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "Courier");
410 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
412 wsprintf(buf, "%d", td->lf.lfWidth);
413 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
414 wsprintf(buf, "%d", td->lf.lfHeight);
415 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
416 wsprintf(buf, "%d", td->lf.lfWeight);
417 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
419 wsprintf(buf, "%d", td->tile_wid);
420 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
422 wsprintf(buf, "%d", td->tile_hgt);
423 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
425 WINDOWPLACEMENT lpwndpl;
426 lpwndpl.length = sizeof(WINDOWPLACEMENT);
427 GetWindowPlacement(td->w, &lpwndpl);
429 RECT rc = lpwndpl.rcNormalPosition;
431 wsprintf(buf, "%d", normsize.x);
433 wsprintf(buf, "%d", td->cols);
435 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
438 wsprintf(buf, "%d", normsize.y);
440 wsprintf(buf, "%d", td->rows);
442 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
444 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
445 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
448 GetWindowRect(td->w, &rc);
449 wsprintf(buf, "%d", rc.left);
450 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
452 wsprintf(buf, "%d", rc.top);
453 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
455 strcpy(buf, td->posfix ? "1" : "0");
456 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
462 * We assume that the windows have all been initialized
464 static void save_prefs(void)
467 sprintf(buf, "%d", arg_graphics);
468 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
470 strcpy(buf, arg_bigtile ? "1" : "0");
471 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
473 strcpy(buf, arg_sound ? "1" : "0");
474 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
476 strcpy(buf, arg_music ? "1" : "0");
477 WritePrivateProfileString("Angband", "Music", buf, ini_file);
478 strcpy(buf, use_pause_music_inactive ? "1" : "0");
479 WritePrivateProfileString("Angband", "MusicPauseInactive", buf, ini_file);
481 sprintf(buf, "%d", current_bg_mode);
482 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
483 WritePrivateProfileString("Angband", "BackGroundBitmap", wallpaper_file[0] != '\0' ? wallpaper_file : DEFAULT_BG_FILENAME, ini_file);
485 int path_length = strlen(ANGBAND_DIR) - 4; /* \libの4文字分を削除 */
487 strncat(tmp, ANGBAND_DIR, path_length);
489 int n = strncmp(tmp, savefile, path_length);
491 char relative_path[1024] = "";
492 snprintf(relative_path, sizeof(relative_path), ".\\%s", (savefile + path_length));
493 WritePrivateProfileString("Angband", "SaveFile", relative_path, ini_file);
495 WritePrivateProfileString("Angband", "SaveFile", savefile, ini_file);
498 strcpy(buf, keep_subwindows ? "1" : "0");
499 WritePrivateProfileString("Angband", "KeepSubwindows", buf, ini_file);
501 for (int i = 0; i < MAX_TERM_DATA; ++i) {
507 * callback for EnumDisplayMonitors API
509 BOOL CALLBACK monitorenumproc([[maybe_unused]] HMONITOR hMon, [[maybe_unused]] HDC hdcMon, [[maybe_unused]] LPRECT lpMon, LPARAM dwDate)
511 bool *result = (bool *)dwDate;
517 * Load the "prefs" for a single term
519 static void load_prefs_aux(int i)
521 term_data *td = &data[i];
522 GAME_TEXT sec_name[128];
525 sprintf(sec_name, "Term-%d", i);
526 sprintf(sec_name, "Term-%d", i);
528 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
532 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
534 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
537 td->font_want = string_make(tmp);
540 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
541 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
542 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
544 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
545 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
547 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
548 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
549 normsize.x = td->cols;
550 normsize.y = td->rows;
553 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
556 int posx = GetPrivateProfileInt(sec_name, "PositionX", 0, ini_file);
557 int posy = GetPrivateProfileInt(sec_name, "PositionY", 0, ini_file);
558 // 保存座標がモニタ内の領域にあるかチェック
559 RECT rect = { posx, posy, posx + 128, posy + 128 };
560 bool in_any_monitor = false;
561 ::EnumDisplayMonitors(NULL, &rect, monitorenumproc, (LPARAM)&in_any_monitor);
562 if (in_any_monitor) {
563 // いずれかのモニタに表示可能、ウインドウ位置を復元
569 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
576 static void load_prefs(void)
578 arg_graphics = (byte)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
579 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
580 use_bigtile = arg_bigtile;
581 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
582 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
583 use_pause_music_inactive = (GetPrivateProfileInt("Angband", "MusicPauseInactive", 0, ini_file) != 0);
584 current_bg_mode = static_cast<bg_mode>(GetPrivateProfileInt("Angband", "BackGround", 0, ini_file));
585 GetPrivateProfileString("Angband", "BackGroundBitmap", DEFAULT_BG_FILENAME, wallpaper_file, 1023, ini_file);
586 GetPrivateProfileString("Angband", "SaveFile", "", savefile, 1023, ini_file);
588 int n = strncmp(".\\", savefile, 2);
590 int path_length = strlen(ANGBAND_DIR) - 4; /* \libの4文字分を削除 */
592 strncat(tmp, ANGBAND_DIR, path_length);
593 strncat(tmp, savefile + 2, strlen(savefile) - 2 + path_length);
594 strncpy(savefile, tmp, strlen(tmp));
597 keep_subwindows = (GetPrivateProfileInt("Angband", "KeepSubwindows", 0, ini_file) != 0);
598 for (int i = 0; i < MAX_TERM_DATA; ++i) {
604 * @brief グラフィクスを初期化する / Initialize graphics
607 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
608 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
611 static bool init_graphics(void)
613 char buf[MAIN_WIN_MAX_PATH];
614 BYTE wid, hgt, twid, thgt, ox, oy;
616 concptr name_mask = NULL;
618 infGraph.delete_bitmap();
619 infMask.delete_bitmap();
621 if (arg_graphics == GRAPHICS_ADAM_BOLT) {
629 name_mask = "mask.bmp";
631 ANGBAND_GRAF = "new";
632 } else if (arg_graphics == GRAPHICS_HENGBAND) {
640 name_mask = "mask32.bmp";
642 ANGBAND_GRAF = "ne2";
651 ANGBAND_GRAF = "old";
654 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
655 infGraph.hBitmap = read_graphic(buf);
656 if (!infGraph.hBitmap) {
657 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
661 infGraph.CellWidth = wid;
662 infGraph.CellHeight = hgt;
663 infGraph.TileWidth = twid;
664 infGraph.TileHeight = thgt;
665 infGraph.OffsetX = ox;
666 infGraph.OffsetY = oy;
669 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name_mask);
670 infMask.hBitmap = read_graphic(buf);
671 if (!infMask.hBitmap) {
672 plog_fmt("Cannot read bitmap file '%s'", buf);
677 current_graphics_mode = arg_graphics;
678 return (current_graphics_mode != GRAPHICS_NONE);
684 static void init_music(void)
686 // Flag set once "music" has been initialized
687 static bool can_use_music = FALSE;
689 if (!can_use_music) {
690 main_win_music::load_music_prefs();
691 can_use_music = TRUE;
698 static void init_sound(void)
700 // Flag set once "sound" has been initialized
701 static bool can_use_sound = FALSE;
703 if (!can_use_sound) {
705 can_use_sound = TRUE;
710 * Initialize background
712 static void init_background(void)
714 // Flag set once "background" has been initialized
715 static bool can_use_background = FALSE;
717 if (!can_use_background) {
719 can_use_background = TRUE;
724 * @brief Change background mode
725 * @param new_mode bg_mode
726 * @param show_error trueに設定した場合のみ、エラーダイアログを表示する
727 * @retval true success
728 * @retval false failed
730 static bool change_bg_mode(bg_mode new_mode, bool show_error = false)
732 current_bg_mode = new_mode;
733 if (current_bg_mode != bg_mode::BG_NONE) {
735 if (!load_bg(wallpaper_file)) {
736 current_bg_mode = bg_mode::BG_NONE;
738 plog_fmt(_("壁紙用ファイル '%s' を読み込めません。", "Can't load the image file '%s'."), wallpaper_file);
744 return (current_bg_mode == new_mode);
748 * @brief Resize a window
750 static void term_window_resize(term_data *td)
755 SetWindowPos(td->w, 0, 0, 0, td->size_wid, td->size_hgt, SWP_NOMOVE | SWP_NOZORDER);
756 InvalidateRect(td->w, NULL, TRUE);
760 * @brief Force the use of a new font for a term_data.
761 * This function may be called before the "window" is ready.
762 * This function returns zero only if everything succeeds.
763 * @note that the "font name" must be capitalized!!!
765 static errr term_force_font(term_data *td)
768 DeleteObject(td->font_id);
770 td->font_id = CreateFontIndirect(&(td->lf));
771 int wid = td->lf.lfWidth;
772 int hgt = td->lf.lfHeight;
781 hdcDesktop = GetDC(HWND_DESKTOP);
782 hfOld = static_cast<HFONT>(SelectObject(hdcDesktop, td->font_id));
783 GetTextMetrics(hdcDesktop, &tm);
784 SelectObject(hdcDesktop, hfOld);
785 ReleaseDC(HWND_DESKTOP, hdcDesktop);
787 wid = tm.tmAveCharWidth;
798 * Allow the user to change the font for this window.
800 static void term_change_font(term_data *td)
803 memset(&cf, 0, sizeof(cf));
804 cf.lStructSize = sizeof(cf);
805 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
806 cf.lpLogFont = &(td->lf);
808 if (!ChooseFont(&cf))
812 td->tile_wid = td->font_wid;
813 td->tile_hgt = td->font_hgt;
815 term_window_resize(td);
819 * Allow the user to lock this window.
821 static void term_window_pos(term_data *td, HWND hWnd)
823 SetWindowPos(td->w, hWnd, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
827 * Hack -- redraw a term_data
829 static void term_data_redraw(term_data *td)
831 term_activate(&td->t);
833 term_activate(term_screen);
836 void term_inversed_area(HWND hWnd, int x, int y, int w, int h)
838 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
839 int tx = td->size_ow1 + x * td->tile_wid;
840 int ty = td->size_oh1 + y * td->tile_hgt;
841 int tw = w * td->tile_wid - 1;
842 int th = h * td->tile_hgt - 1;
844 HDC hdc = GetDC(hWnd);
845 HBRUSH myBrush = CreateSolidBrush(RGB(255, 255, 255));
846 HBRUSH oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
847 HPEN oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
849 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
851 SelectObject(hdc, oldBrush);
852 SelectObject(hdc, oldPen);
856 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
858 static errr term_user_win(int n)
864 static void refresh_color_table()
866 for (int i = 0; i < 256; i++) {
867 byte rv = angband_color_table[i][1];
868 byte gv = angband_color_table[i][2];
869 byte bv = angband_color_table[i][3];
870 win_clr[i] = PALETTERGB(rv, gv, bv);
875 * React to global changes
877 static errr term_xtra_win_react(player_type *player_ptr)
879 refresh_color_table();
881 use_sound = arg_sound;
886 if (use_graphics != (arg_graphics > 0)) {
887 if (arg_graphics && !init_graphics()) {
888 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
889 arg_graphics = GRAPHICS_NONE;
892 use_graphics = (arg_graphics > 0);
893 reset_visuals(player_ptr);
896 for (int i = 0; i < MAX_TERM_DATA; i++) {
897 term_type *old = Term;
898 term_data *td = &data[i];
899 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt)) {
900 term_activate(&td->t);
901 term_resize(td->cols, td->rows);
911 * Process at least one event
913 static errr term_xtra_win_event(int v)
917 if (GetMessage(&msg, NULL, 0, 0)) {
918 TranslateMessage(&msg);
919 DispatchMessage(&msg);
922 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
923 TranslateMessage(&msg);
924 DispatchMessage(&msg);
932 * Process all pending events
934 static errr term_xtra_win_flush(void)
937 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
938 TranslateMessage(&msg);
939 DispatchMessage(&msg);
946 * Hack -- clear the screen
948 * Make this more efficient
950 static errr term_xtra_win_clear(void)
952 term_data *td = (term_data *)(Term->data);
955 rc.left = td->size_ow1;
956 rc.right = rc.left + td->cols * td->tile_wid;
957 rc.top = td->size_oh1;
958 rc.bottom = rc.top + td->rows * td->tile_hgt;
960 HDC hdc = GetDC(td->w);
961 SetBkColor(hdc, RGB(0, 0, 0));
962 SelectObject(hdc, td->font_id);
963 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
965 if (current_bg_mode != bg_mode::BG_NONE) {
971 ReleaseDC(td->w, hdc);
976 * Hack -- make a noise
978 static errr term_xtra_win_noise(void)
980 MessageBeep(MB_ICONASTERISK);
985 * Hack -- make a sound
987 static errr term_xtra_win_sound(int v)
991 return play_sound(v);
995 * Hack -- play a music
997 static errr term_xtra_win_music(int n, int v)
1003 return main_win_music::play_music(n, v);
1007 * Hack -- play a music matches a situation
1009 static errr term_xtra_win_scene(int v)
1011 // TODO 場面に合った壁紙変更対応
1016 return main_win_music::play_music_scene(v);
1020 * Delay for "x" milliseconds
1022 static int term_xtra_win_delay(int v)
1029 * @brief Do a "special thing"
1030 * @todo z-termに影響があるのでplayer_typeの追加は保留
1032 static errr term_xtra_win(int n, int v)
1035 case TERM_XTRA_NOISE: {
1036 return (term_xtra_win_noise());
1038 case TERM_XTRA_MUSIC_BASIC:
1039 case TERM_XTRA_MUSIC_DUNGEON:
1040 case TERM_XTRA_MUSIC_QUEST:
1041 case TERM_XTRA_MUSIC_TOWN:
1042 case TERM_XTRA_MUSIC_MONSTER: {
1043 return term_xtra_win_music(n, v);
1045 case TERM_XTRA_MUSIC_MUTE: {
1046 return main_win_music::stop_music();
1048 case TERM_XTRA_SCENE: {
1049 return term_xtra_win_scene(v);
1051 case TERM_XTRA_SOUND: {
1052 return (term_xtra_win_sound(v));
1054 case TERM_XTRA_BORED: {
1055 return (term_xtra_win_event(0));
1057 case TERM_XTRA_EVENT: {
1058 return (term_xtra_win_event(v));
1060 case TERM_XTRA_FLUSH: {
1061 return (term_xtra_win_flush());
1063 case TERM_XTRA_CLEAR: {
1064 return (term_xtra_win_clear());
1066 case TERM_XTRA_REACT: {
1067 return (term_xtra_win_react(p_ptr));
1069 case TERM_XTRA_DELAY: {
1070 return (term_xtra_win_delay(v));
1078 * Low level graphics (Assumes valid input).
1080 * Draw a "cursor" at (x,y), using a "yellow box".
1082 static errr term_curs_win(int x, int y)
1084 term_data *td = (term_data *)(Term->data);
1085 int tile_wid, tile_hgt;
1086 tile_wid = td->tile_wid;
1087 tile_hgt = td->tile_hgt;
1090 rc.left = x * tile_wid + td->size_ow1;
1091 rc.right = rc.left + tile_wid;
1092 rc.top = y * tile_hgt + td->size_oh1;
1093 rc.bottom = rc.top + tile_hgt;
1095 HDC hdc = GetDC(td->w);
1096 FrameRect(hdc, &rc, hbrYellow);
1097 ReleaseDC(td->w, hdc);
1102 * Low level graphics (Assumes valid input).
1104 * Draw a "big cursor" at (x,y), using a "yellow box".
1106 static errr term_bigcurs_win(int x, int y)
1108 term_data *td = (term_data *)(Term->data);
1109 int tile_wid, tile_hgt;
1110 tile_wid = td->tile_wid;
1111 tile_hgt = td->tile_hgt;
1114 rc.left = x * tile_wid + td->size_ow1;
1115 rc.right = rc.left + 2 * tile_wid;
1116 rc.top = y * tile_hgt + td->size_oh1;
1117 rc.bottom = rc.top + tile_hgt;
1119 HDC hdc = GetDC(td->w);
1120 FrameRect(hdc, &rc, hbrYellow);
1121 ReleaseDC(td->w, hdc);
1126 * Low level graphics (Assumes valid input).
1128 * Erase a "block" of "n" characters starting at (x,y).
1130 static errr term_wipe_win(int x, int y, int n)
1132 term_data *td = (term_data *)(Term->data);
1134 rc.left = x * td->tile_wid + td->size_ow1;
1135 rc.right = rc.left + n * td->tile_wid;
1136 rc.top = y * td->tile_hgt + td->size_oh1;
1137 rc.bottom = rc.top + td->tile_hgt;
1139 HDC hdc = GetDC(td->w);
1140 SetBkColor(hdc, RGB(0, 0, 0));
1141 SelectObject(hdc, td->font_id);
1142 if (current_bg_mode != bg_mode::BG_NONE)
1145 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1147 ReleaseDC(td->w, hdc);
1152 * Low level graphics. Assumes valid input.
1154 * Draw several ("n") chars, with an attr, at a given location.
1156 * All "graphic" data is handled by "term_pict_win()", below.
1158 * One would think there is a more efficient method for telling a window
1159 * what color it should be using to draw with, but perhaps simply changing
1160 * it every time is not too inefficient.
1162 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
1164 term_data *td = (term_data *)(Term->data);
1165 static HBITMAP WALL;
1166 static HBRUSH myBrush, oldBrush;
1168 static bool init_done = FALSE;
1171 WALL = LoadBitmap(hInstance, AppName);
1172 myBrush = CreatePatternBrush(WALL);
1176 RECT rc{ static_cast<LONG>(x * td->tile_wid + td->size_ow1), static_cast<LONG>(y * td->tile_hgt + td->size_oh1),
1177 static_cast<LONG>(rc.left + n * td->tile_wid), static_cast<LONG>(rc.top + td->tile_hgt) };
1179 HDC hdc = GetDC(td->w);
1180 SetBkColor(hdc, RGB(0, 0, 0));
1181 SetTextColor(hdc, win_clr[a]);
1183 SelectObject(hdc, td->font_id);
1184 if (current_bg_mode != bg_mode::BG_NONE)
1185 SetBkMode(hdc, TRANSPARENT);
1187 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1188 if (current_bg_mode != bg_mode::BG_NONE)
1191 rc.left += ((td->tile_wid - td->font_wid) / 2);
1192 rc.right = rc.left + td->font_wid;
1193 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
1194 rc.bottom = rc.top + td->font_hgt;
1196 for (int i = 0; i < n; i++) {
1198 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1]) {
1199 rc.right += td->font_wid;
1200 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1201 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1202 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1203 SelectObject(hdc, oldBrush);
1204 SelectObject(hdc, oldPen);
1205 rc.right -= td->font_wid;
1207 rc.left += 2 * td->tile_wid;
1208 rc.right += 2 * td->tile_wid;
1209 } else if (iskanji(*(s + i))) /* 2バイト文字 */
1211 rc.right += td->font_wid;
1212 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 2, NULL);
1213 rc.right -= td->font_wid;
1215 rc.left += 2 * td->tile_wid;
1216 rc.right += 2 * td->tile_wid;
1217 } else if (*(s + i) == 127) {
1218 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1219 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1220 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1221 SelectObject(hdc, oldBrush);
1222 SelectObject(hdc, oldPen);
1223 rc.left += td->tile_wid;
1224 rc.right += td->tile_wid;
1226 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1227 rc.left += td->tile_wid;
1228 rc.right += td->tile_wid;
1231 if (*(s + i) == 127) {
1232 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1233 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1234 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1235 SelectObject(hdc, oldBrush);
1236 SelectObject(hdc, oldPen);
1237 rc.left += td->tile_wid;
1238 rc.right += td->tile_wid;
1240 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1241 rc.left += td->tile_wid;
1242 rc.right += td->tile_wid;
1247 ReleaseDC(td->w, hdc);
1252 * Low level graphics. Assumes valid input.
1254 * Draw an array of "special" attr/char pairs at the given location.
1256 * We use the "term_pict_win()" function for "graphic" data, which are
1257 * encoded by setting the "high-bits" of both the "attr" and the "char"
1258 * data. We use the "attr" to represent the "row" of the main bitmap,
1259 * and the "char" to represent the "col" of the main bitmap. The use
1260 * of this function is induced by the "higher_pict" flag.
1262 * If "graphics" is not available, we simply "wipe" the given grids.
1264 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)
1266 term_data *td = (term_data *)(Term->data);
1269 if (!use_graphics) {
1270 return (term_wipe_win(x, y, n));
1273 TERM_LEN w1 = infGraph.CellWidth;
1274 TERM_LEN h1 = infGraph.CellHeight;
1275 TERM_LEN tw1 = infGraph.TileWidth;
1276 TERM_LEN th1 = infGraph.TileHeight;
1277 TERM_LEN w2, h2, tw2 = 0;
1284 TERM_LEN x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
1285 TERM_LEN y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
1286 HDC hdc = GetDC(td->w);
1287 HDC hdcSrc = CreateCompatibleDC(hdc);
1288 HBITMAP hbmSrcOld = static_cast<HBITMAP>(SelectObject(hdcSrc, infGraph.hBitmap));
1290 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1291 hdcMask = CreateCompatibleDC(hdc);
1292 SelectObject(hdcMask, infMask.hBitmap);
1295 for (i = 0; i < n; i++, x2 += w2) {
1296 TERM_COLOR a = ap[i];
1298 int row = (a & 0x7F);
1299 int col = (c & 0x7F);
1300 TERM_LEN x1 = col * w1;
1301 TERM_LEN y1 = row * h1;
1303 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1304 TERM_LEN x3 = (tcp[i] & 0x7F) * w1;
1305 TERM_LEN y3 = (tap[i] & 0x7F) * h1;
1306 tw2 = tw2 * w1 / tw1;
1308 if ((tw1 == tw2) && (th1 == h2)) {
1309 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
1310 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
1311 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
1315 SetStretchBltMode(hdc, COLORONCOLOR);
1316 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
1317 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
1318 if ((x1 != x3) || (y1 != y3)) {
1319 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
1320 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
1326 if ((w1 == tw2) && (h1 == h2)) {
1327 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
1331 SetStretchBltMode(hdc, COLORONCOLOR);
1332 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
1335 SelectObject(hdcSrc, hbmSrcOld);
1337 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1338 SelectObject(hdcMask, hbmSrcOld);
1342 ReleaseDC(td->w, hdc);
1347 * Create and initialize a "term_data" given a title
1349 static void term_data_link(term_data *td)
1351 term_type *t = &td->t;
1352 term_init(t, td->cols, td->rows, FILE_READ_BUFF_SIZE);
1353 t->soft_cursor = TRUE;
1354 t->higher_pict = TRUE;
1355 t->attr_blank = TERM_WHITE;
1356 t->char_blank = ' ';
1357 t->user_hook = term_user_win;
1358 t->xtra_hook = term_xtra_win;
1359 t->curs_hook = term_curs_win;
1360 t->bigcurs_hook = term_bigcurs_win;
1361 t->wipe_hook = term_wipe_win;
1362 t->text_hook = term_text_win;
1363 t->pict_hook = term_pict_win;
1364 t->data = (vptr)(td);
1368 * Create the windows
1370 * First, instantiate the "default" values, then read the "ini_file"
1371 * to over-ride selected values, then create the windows, and fonts.
1373 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
1374 * must make active to realize the palette.
1376 static void init_windows(void)
1380 WIPE(td, term_data);
1384 td->s = angband_term_name[0];
1399 for (int i = 1; i < MAX_TERM_DATA; i++) {
1401 WIPE(td, term_data);
1402 td->s = angband_term_name[i];
1406 td->visible = FALSE;
1411 td->pos_x = (7 - i) * 30;
1412 td->pos_y = (7 - i) * 20;
1418 /* Atrributes of main window */
1420 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_VISIBLE);
1424 /* Attributes of sub windows */
1425 for (int i = 1; i < MAX_TERM_DATA; i++) {
1427 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
1428 td->dwExStyle = (WS_EX_TOOLWINDOW);
1431 /* Font of each window */
1432 for (int i = 0; i < MAX_TERM_DATA; i++) {
1434 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
1435 td->lf.lfCharSet = DEFAULT_CHARSET;
1436 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
1437 term_force_font(td);
1439 td->tile_wid = td->font_wid;
1441 td->tile_hgt = td->font_hgt;
1443 term_window_resize(td);
1446 /* Create sub windows */
1447 for (int i = MAX_TERM_DATA - 1; i >= 1; --i) {
1452 = 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);
1456 quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
1458 td->size_hack = TRUE;
1460 term_window_resize(td);
1463 ShowWindow(td->w, SW_SHOW);
1465 td->size_hack = FALSE;
1468 angband_term[i] = &td->t;
1471 /* Activate the window */
1472 SetActiveWindow(td->w);
1476 term_window_pos(td, HWND_TOPMOST);
1478 term_window_pos(td, td->w);
1482 /* Create main window */
1485 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);
1489 quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
1492 td->size_hack = TRUE;
1494 term_window_resize(td);
1495 td->size_hack = FALSE;
1498 angband_term[0] = &td->t;
1499 normsize.x = td->cols;
1500 normsize.y = td->rows;
1503 ShowWindow(td->w, SW_SHOWMAXIMIZED);
1505 ShowWindow(td->w, SW_SHOW);
1507 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
1508 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
1509 (void)term_xtra_win_flush();
1515 static void setup_menus(void)
1517 HMENU hm = GetMenu(data[0].w);
1519 if (current_world_ptr->character_generated) {
1520 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1521 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1522 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_ENABLED);
1524 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
1525 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
1526 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1529 for (int i = 0; i < MAX_TERM_DATA; i++) {
1530 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1531 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i, (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
1532 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_ENABLED);
1535 for (int i = 0; i < MAX_TERM_DATA; i++) {
1536 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1538 if (data[i].visible) {
1539 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1543 for (int i = 0; i < MAX_TERM_DATA; i++) {
1544 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1545 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i, (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
1546 if (data[i].visible) {
1547 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_ENABLED);
1551 for (int i = 0; i < MAX_TERM_DATA; i++) {
1552 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1553 if (data[i].visible) {
1554 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
1558 for (int i = 0; i < MAX_TERM_DATA; i++) {
1559 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1560 if (data[i].visible) {
1561 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
1565 for (int i = 0; i < MAX_TERM_DATA; i++) {
1566 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1567 if (data[i].visible) {
1568 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1572 for (int i = 0; i < MAX_TERM_DATA; i++) {
1573 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1575 if (data[i].visible) {
1576 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1579 CheckMenuItem(hm, IDM_WINDOW_KEEP_SUBWINDOWS, (keep_subwindows ? MF_CHECKED : MF_UNCHECKED));
1581 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
1582 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
1583 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
1584 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS, (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
1585 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE, (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
1586 CheckMenuItem(hm, IDM_OPTIONS_MUSIC, (arg_music ? MF_CHECKED : MF_UNCHECKED));
1587 CheckMenuItem(hm, IDM_OPTIONS_MUSIC_PAUSE_INACTIVE, (use_pause_music_inactive ? MF_CHECKED : MF_UNCHECKED));
1588 CheckMenuItem(hm, IDM_OPTIONS_SOUND, (arg_sound ? MF_CHECKED : MF_UNCHECKED));
1589 CheckMenuItem(hm, IDM_OPTIONS_NO_BG, ((current_bg_mode == bg_mode::BG_NONE) ? MF_CHECKED : MF_UNCHECKED));
1590 CheckMenuItem(hm, IDM_OPTIONS_BG, ((current_bg_mode == bg_mode::BG_ONE) ? MF_CHECKED : MF_UNCHECKED));
1591 CheckMenuItem(hm, IDM_OPTIONS_PRESET_BG, ((current_bg_mode == bg_mode::BG_PRESET) ? MF_CHECKED : MF_UNCHECKED));
1592 // TODO IDM_OPTIONS_PRESET_BG を有効にする
1593 EnableMenuItem(hm, IDM_OPTIONS_PRESET_BG, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1597 * Check for double clicked (or dragged) savefile
1599 * Apparently, Windows copies the entire filename into the first
1600 * piece of the "command line string". Perhaps we should extract
1601 * the "basename" of that filename and append it to the "save" dir.
1603 static void check_for_save_file(player_type *player_ptr, LPSTR cmd_line)
1610 strcpy(savefile, s);
1611 validate_file(savefile);
1612 game_in_progress = TRUE;
1613 play_game(player_ptr, FALSE, FALSE);
1617 * Process a menu command
1619 static void process_menus(player_type *player_ptr, WORD wCmd)
1622 plog(_("まだ初期化中です...", "You cannot do that yet..."));
1629 case IDM_FILE_NEW: {
1630 if (game_in_progress) {
1631 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
1633 game_in_progress = TRUE;
1635 strcpy(savefile, "");
1636 play_game(player_ptr, TRUE, FALSE);
1642 case IDM_FILE_OPEN: {
1643 if (game_in_progress) {
1644 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
1646 memset(&ofn, 0, sizeof(ofn));
1647 ofn.lStructSize = sizeof(ofn);
1648 ofn.hwndOwner = data[0].w;
1649 ofn.lpstrFilter = "Save Files (*.)\0*\0";
1650 ofn.nFilterIndex = 1;
1651 ofn.lpstrFile = savefile;
1652 ofn.nMaxFile = 1024;
1653 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
1654 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
1656 if (GetOpenFileName(&ofn)) {
1657 validate_file(savefile);
1658 game_in_progress = TRUE;
1660 play_game(player_ptr, FALSE, FALSE);
1667 case IDM_FILE_SAVE: {
1668 if (game_in_progress && current_world_ptr->character_generated) {
1670 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
1675 do_cmd_save_game(player_ptr, FALSE);
1677 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
1682 case IDM_FILE_EXIT: {
1683 if (game_in_progress && current_world_ptr->character_generated) {
1685 plog(_("今は終了できません。", "You may not do that right now."));
1690 forget_lite(player_ptr->current_floor_ptr);
1691 forget_view(player_ptr->current_floor_ptr);
1692 clear_mon_lite(player_ptr->current_floor_ptr);
1694 term_key_push(SPECIAL_KEY_QUIT);
1701 case IDM_FILE_SCORE: {
1703 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
1704 highscore_fd = fd_open(buf, O_RDONLY);
1705 if (highscore_fd < 0) {
1706 msg_print("Score file unavailable.");
1710 display_scores_aux(0, MAX_HISCORES, -1, NULL);
1711 (void)fd_close(highscore_fd);
1719 case IDM_FILE_MOVIE: {
1720 if (game_in_progress) {
1721 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
1723 memset(&ofn, 0, sizeof(ofn));
1724 ofn.lStructSize = sizeof(ofn);
1725 ofn.hwndOwner = data[0].w;
1726 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
1727 ofn.nFilterIndex = 1;
1728 ofn.lpstrFile = savefile;
1729 ofn.nMaxFile = 1024;
1730 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
1731 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1733 if (GetOpenFileName(&ofn)) {
1734 prepare_browse_movie_without_path_build(savefile);
1735 play_game(player_ptr, FALSE, TRUE);
1743 case IDM_WINDOW_VIS_0: {
1744 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
1747 case IDM_WINDOW_VIS_1:
1748 case IDM_WINDOW_VIS_2:
1749 case IDM_WINDOW_VIS_3:
1750 case IDM_WINDOW_VIS_4:
1751 case IDM_WINDOW_VIS_5:
1752 case IDM_WINDOW_VIS_6:
1753 case IDM_WINDOW_VIS_7: {
1754 int i = wCmd - IDM_WINDOW_VIS_0;
1755 if ((i < 0) || (i >= MAX_TERM_DATA))
1761 ShowWindow(td->w, SW_SHOW);
1762 term_data_redraw(td);
1764 td->visible = FALSE;
1766 ShowWindow(td->w, SW_HIDE);
1771 case IDM_WINDOW_FONT_0:
1772 case IDM_WINDOW_FONT_1:
1773 case IDM_WINDOW_FONT_2:
1774 case IDM_WINDOW_FONT_3:
1775 case IDM_WINDOW_FONT_4:
1776 case IDM_WINDOW_FONT_5:
1777 case IDM_WINDOW_FONT_6:
1778 case IDM_WINDOW_FONT_7: {
1779 int i = wCmd - IDM_WINDOW_FONT_0;
1780 if ((i < 0) || (i >= MAX_TERM_DATA))
1784 term_change_font(td);
1787 case IDM_WINDOW_POS_1:
1788 case IDM_WINDOW_POS_2:
1789 case IDM_WINDOW_POS_3:
1790 case IDM_WINDOW_POS_4:
1791 case IDM_WINDOW_POS_5:
1792 case IDM_WINDOW_POS_6:
1793 case IDM_WINDOW_POS_7: {
1794 int i = wCmd - IDM_WINDOW_POS_0;
1795 if ((i < 0) || (i >= MAX_TERM_DATA))
1799 if (!td->posfix && td->visible) {
1801 term_window_pos(td, HWND_TOPMOST);
1804 term_window_pos(td, data[0].w);
1809 case IDM_WINDOW_I_WID_0:
1810 case IDM_WINDOW_I_WID_1:
1811 case IDM_WINDOW_I_WID_2:
1812 case IDM_WINDOW_I_WID_3:
1813 case IDM_WINDOW_I_WID_4:
1814 case IDM_WINDOW_I_WID_5:
1815 case IDM_WINDOW_I_WID_6:
1816 case IDM_WINDOW_I_WID_7: {
1817 int i = wCmd - IDM_WINDOW_I_WID_0;
1818 if ((i < 0) || (i >= MAX_TERM_DATA))
1824 term_window_resize(td);
1827 case IDM_WINDOW_D_WID_0:
1828 case IDM_WINDOW_D_WID_1:
1829 case IDM_WINDOW_D_WID_2:
1830 case IDM_WINDOW_D_WID_3:
1831 case IDM_WINDOW_D_WID_4:
1832 case IDM_WINDOW_D_WID_5:
1833 case IDM_WINDOW_D_WID_6:
1834 case IDM_WINDOW_D_WID_7: {
1835 int i = wCmd - IDM_WINDOW_D_WID_0;
1836 if ((i < 0) || (i >= MAX_TERM_DATA))
1842 term_window_resize(td);
1845 case IDM_WINDOW_I_HGT_0:
1846 case IDM_WINDOW_I_HGT_1:
1847 case IDM_WINDOW_I_HGT_2:
1848 case IDM_WINDOW_I_HGT_3:
1849 case IDM_WINDOW_I_HGT_4:
1850 case IDM_WINDOW_I_HGT_5:
1851 case IDM_WINDOW_I_HGT_6:
1852 case IDM_WINDOW_I_HGT_7: {
1853 int i = wCmd - IDM_WINDOW_I_HGT_0;
1854 if ((i < 0) || (i >= MAX_TERM_DATA))
1860 term_window_resize(td);
1863 case IDM_WINDOW_D_HGT_0:
1864 case IDM_WINDOW_D_HGT_1:
1865 case IDM_WINDOW_D_HGT_2:
1866 case IDM_WINDOW_D_HGT_3:
1867 case IDM_WINDOW_D_HGT_4:
1868 case IDM_WINDOW_D_HGT_5:
1869 case IDM_WINDOW_D_HGT_6:
1870 case IDM_WINDOW_D_HGT_7: {
1871 int i = wCmd - IDM_WINDOW_D_HGT_0;
1872 if ((i < 0) || (i >= MAX_TERM_DATA))
1878 term_window_resize(td);
1881 case IDM_WINDOW_KEEP_SUBWINDOWS: {
1882 keep_subwindows = !keep_subwindows;
1885 case IDM_OPTIONS_NO_GRAPHICS: {
1886 if (arg_graphics != GRAPHICS_NONE) {
1887 arg_graphics = GRAPHICS_NONE;
1890 term_xtra_win_react(player_ptr);
1891 term_key_push(KTRL('R'));
1896 case IDM_OPTIONS_OLD_GRAPHICS: {
1897 if (arg_graphics != GRAPHICS_ORIGINAL) {
1898 arg_graphics = GRAPHICS_ORIGINAL;
1901 term_xtra_win_react(player_ptr);
1902 term_key_push(KTRL('R'));
1903 } else if (!init_graphics()) {
1904 arg_graphics = GRAPHICS_NONE;
1910 case IDM_OPTIONS_NEW_GRAPHICS: {
1911 if (arg_graphics != GRAPHICS_ADAM_BOLT) {
1912 arg_graphics = GRAPHICS_ADAM_BOLT;
1915 term_xtra_win_react(player_ptr);
1916 term_key_push(KTRL('R'));
1917 } else if (!init_graphics()) {
1918 arg_graphics = GRAPHICS_NONE;
1924 case IDM_OPTIONS_NEW2_GRAPHICS: {
1925 if (arg_graphics != GRAPHICS_HENGBAND) {
1926 arg_graphics = GRAPHICS_HENGBAND;
1929 term_xtra_win_react(player_ptr);
1930 term_key_push(KTRL('R'));
1931 } else if (!init_graphics()) {
1932 arg_graphics = GRAPHICS_NONE;
1938 case IDM_OPTIONS_BIGTILE: {
1940 arg_bigtile = !arg_bigtile;
1941 term_activate(&td->t);
1942 term_resize(td->cols, td->rows);
1943 InvalidateRect(td->w, NULL, TRUE);
1946 case IDM_OPTIONS_MUSIC: {
1947 arg_music = !arg_music;
1948 use_music = arg_music;
1951 if (game_in_progress)
1952 select_floor_music(player_ptr);
1954 main_win_music::stop_music();
1958 case IDM_OPTIONS_MUSIC_PAUSE_INACTIVE: {
1959 use_pause_music_inactive = !use_pause_music_inactive;
1962 case IDM_OPTIONS_SOUND: {
1963 arg_sound = !arg_sound;
1965 term_xtra_win_react(player_ptr);
1968 case IDM_OPTIONS_NO_BG: {
1969 change_bg_mode(bg_mode::BG_NONE);
1971 InvalidateRect(td->w, NULL, TRUE);
1974 case IDM_OPTIONS_PRESET_BG: {
1975 change_bg_mode(bg_mode::BG_PRESET);
1977 InvalidateRect(td->w, NULL, TRUE);
1980 case IDM_OPTIONS_BG: {
1981 bool ret = change_bg_mode(bg_mode::BG_ONE);
1984 InvalidateRect(td->w, NULL, TRUE);
1987 // 壁紙の設定に失敗した(ファイルが存在しない等)場合、壁紙に使うファイルを選択させる
1989 [[fallthrough]]; /* Fall through */
1990 case IDM_OPTIONS_OPEN_BG: {
1991 memset(&ofn, 0, sizeof(ofn));
1992 ofn.lStructSize = sizeof(ofn);
1993 ofn.hwndOwner = data[0].w;
1994 ofn.lpstrFilter = "Image Files (*.bmp;*.png;*.jpg;*.jpeg;)\0*.bmp;*.png;*.jpg;*.jpeg;\0";
1995 ofn.nFilterIndex = 1;
1996 ofn.lpstrFile = wallpaper_file;
1997 ofn.nMaxFile = 1023;
1998 ofn.lpstrInitialDir = NULL;
1999 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
2000 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
2002 if (GetOpenFileName(&ofn)) {
2003 change_bg_mode(bg_mode::BG_ONE, true);
2005 InvalidateRect(td->w, NULL, TRUE);
2009 case IDM_DUMP_SCREEN_HTML: {
2011 std::vector<WCHAR> buf(MAIN_WIN_MAX_PATH + 1);
2012 memset(&ofnw, 0, sizeof(ofnw));
2013 ofnw.lStructSize = sizeof(ofnw);
2014 ofnw.hwndOwner = data[0].w;
2015 ofnw.lpstrFilter = L"HTML Files (*.html)\0*.html\0";
2016 ofnw.nFilterIndex = 1;
2017 ofnw.lpstrFile = &buf[0];
2018 ofnw.nMaxFile = MAIN_WIN_MAX_PATH;
2019 ofnw.lpstrDefExt = L"html";
2020 ofnw.lpstrInitialDir = NULL;
2021 ofnw.lpstrTitle = _(L"HTMLでスクリーンダンプを保存", L"Save screen dump as HTML.");
2022 ofnw.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
2024 if (GetSaveFileNameW(&ofnw)) {
2025 do_cmd_save_screen_html_aux(to_multibyte(&buf[0]).c_str(), 0);
2034 * Add a keypress to the "queue"
2036 static errr term_keypress(int k)
2038 /* Refuse to enqueue non-keys */
2042 /* Store the char, advance the queue */
2043 Term->key_queue[Term->key_head++] = (char)k;
2045 /* Circular queue, handle wrap */
2046 if (Term->key_head == Term->key_size)
2049 if (Term->key_head != Term->key_tail)
2055 static bool process_keydown(WPARAM wParam, LPARAM lParam)
2061 if (GetKeyState(VK_CONTROL) & 0x8000)
2063 if (GetKeyState(VK_SHIFT) & 0x8000)
2065 if (GetKeyState(VK_MENU) & 0x8000)
2068 term_no_press = (ma) ? TRUE : FALSE;
2069 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)])) {
2070 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
2071 bool numpad = FALSE;
2081 int i = LOBYTE(HIWORD(lParam));
2085 term_no_press = TRUE;
2086 [[fallthrough]]; /* Fall through */
2105 term_no_press = TRUE;
2106 [[fallthrough]]; /* Fall through */
2124 term_keypress(hexsym[i / 16]);
2125 term_keypress(hexsym[i % 16]);
2134 static void handle_app_active(HWND hWnd, UINT uMsg, WPARAM wParam, [[maybe_unused]] LPARAM lParam)
2137 case WM_ACTIVATEAPP: {
2139 if (use_pause_music_inactive)
2140 main_win_music::resume_music();
2142 if (use_pause_music_inactive)
2143 main_win_music::pause_music();
2147 case WM_WINDOWPOSCHANGING: {
2148 if (!IsIconic(hWnd))
2149 if (use_pause_music_inactive)
2150 main_win_music::resume_music();
2157 * @todo WNDCLASSに影響があるのでplayer_type*の追加は保留
2159 LRESULT PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2163 td = (term_data *)GetWindowLong(hWnd, 0);
2165 handle_app_active(hWnd, uMsg, wParam, lParam);
2169 SetWindowLong(hWnd, 0, (LONG)(my_td));
2176 case WM_GETMINMAXINFO: {
2180 lpmmi = (MINMAXINFO *)lParam;
2184 rc.left = rc.top = 0;
2185 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
2186 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
2188 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
2190 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
2191 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
2196 BeginPaint(hWnd, &ps);
2198 term_data_redraw(td);
2199 EndPaint(hWnd, &ps);
2200 ValidateRect(hWnd, NULL);
2203 case MM_MCINOTIFY: {
2204 main_win_music::on_mci_notify(wParam, lParam);
2210 if (process_keydown(wParam, lParam))
2216 term_no_press = FALSE;
2218 term_keypress(wParam);
2221 case WM_LBUTTONDOWN: {
2222 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
2223 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
2229 case WM_LBUTTONUP: {
2232 TERM_LEN dx = abs(oldx - mousex) + 1;
2233 TERM_LEN dy = abs(oldy - mousey) + 1;
2234 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
2235 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
2241 int sz = (dx + 3) * dy;
2243 int sz = (dx + 2) * dy;
2245 hGlobal = GlobalAlloc(GHND, sz + 1);
2246 if (hGlobal == NULL)
2248 lpStr = (LPSTR)GlobalLock(hGlobal);
2250 for (int i = 0; i < dy; i++) {
2253 const auto &scr = data[0].t.scr->c;
2255 C_MAKE(s, (dx + 1), char);
2256 strncpy(s, &scr[oy + i][ox], dx);
2259 if (iskanji(scr[oy + i][ox - 1]))
2263 if (ox + dx < data[0].cols) {
2264 if (iskanji(scr[oy + i][ox + dx - 1]))
2268 for (int j = 0; j < dx; j++) {
2274 for (int j = 0; j < dx; j++) {
2275 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
2284 GlobalUnlock(hGlobal);
2285 if (OpenClipboard(hWnd) == 0) {
2286 GlobalFree(hGlobal);
2291 SetClipboardData(CF_TEXT, hGlobal);
2296 case WM_MOUSEMOVE: {
2301 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
2302 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
2306 dx = abs(oldx - mousex) + 1;
2307 dy = abs(oldy - mousey) + 1;
2308 ox = (oldx > mousex) ? mousex : oldx;
2309 oy = (oldy > mousey) ? mousey : oldy;
2310 term_inversed_area(hWnd, ox, oy, dx, dy);
2315 dx = abs(cx - mousex) + 1;
2316 dy = abs(cy - mousey) + 1;
2317 ox = (cx > mousex) ? mousex : cx;
2318 oy = (cy > mousey) ? mousey : cy;
2319 term_inversed_area(hWnd, ox, oy, dx, dy);
2330 if (!game_in_progress || !current_world_ptr->character_generated) {
2336 plog(_("今は終了できません。", "You may not do that right now."));
2341 forget_lite(p_ptr->current_floor_ptr);
2342 forget_view(p_ptr->current_floor_ptr);
2343 clear_mon_lite(p_ptr->current_floor_ptr);
2344 term_key_push(SPECIAL_KEY_QUIT);
2347 case WM_QUERYENDSESSION: {
2348 if (!game_in_progress || !current_world_ptr->character_generated) {
2355 p_ptr->is_dead = FALSE;
2356 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
2358 p_ptr->panic_save = 1;
2359 signals_ignore_tstp();
2360 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
2361 (void)save_player(p_ptr, SAVE_TYPE_CLOSE_GAME);
2370 process_menus(p_ptr, LOWORD(wParam));
2381 //!< @todo 二重のswitch文。後で分割する.
2383 case SIZE_MINIMIZED: {
2384 for (int i = 1; i < MAX_TERM_DATA; i++) {
2385 if (data[i].visible)
2386 ShowWindow(data[i].w, SW_HIDE);
2391 case SIZE_MAXIMIZED:
2392 case SIZE_RESTORED: {
2393 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
2394 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
2395 if ((td->cols != cols) || (td->rows != rows)) {
2398 if (!IsZoomed(td->w) && !IsIconic(td->w)) {
2399 normsize.x = td->cols;
2400 normsize.y = td->rows;
2403 term_activate(&td->t);
2404 term_resize(td->cols, td->rows);
2405 InvalidateRect(td->w, NULL, TRUE);
2408 td->size_hack = TRUE;
2409 for (int i = 1; i < MAX_TERM_DATA; i++) {
2410 if (data[i].visible)
2411 ShowWindow(data[i].w, SW_SHOW);
2414 td->size_hack = FALSE;
2423 if (!wParam || HIWORD(lParam))
2426 for (int i = 1; i < MAX_TERM_DATA; i++) {
2427 if (!data[i].posfix)
2428 term_window_pos(&data[i], hWnd);
2434 case WM_ACTIVATEAPP: {
2435 if (IsIconic(td->w))
2438 for (int i = 1; i < MAX_TERM_DATA; i++) {
2439 if (data[i].visible) {
2440 if (wParam == TRUE) {
2441 ShowWindow(data[i].w, SW_SHOW);
2443 ShowWindow(data[i].w, SW_HIDE);
2448 [[fallthrough]]; /* Fall through */
2450 if (wParam == FALSE && keep_subwindows) {
2451 for (int i = 0; i < MAX_TERM_DATA; i++) {
2452 if (data[i].visible) {
2453 ShowWindow(data[i].w, SW_SHOW);
2460 return DefWindowProc(hWnd, uMsg, wParam, lParam);
2464 * @todo WNDCLASSに影響があるのでplayer_type*の追加は保留
2466 LRESULT PASCAL AngbandListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2470 td = (term_data *)GetWindowLong(hWnd, 0);
2474 SetWindowLong(hWnd, 0, (LONG)(my_td));
2480 case WM_GETMINMAXINFO: {
2484 lpmmi = (MINMAXINFO *)lParam;
2488 rc.left = rc.top = 0;
2489 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
2490 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
2492 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
2493 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
2494 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
2505 td->size_hack = TRUE;
2507 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
2508 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
2509 if ((td->cols != cols) || (td->rows != rows)) {
2510 term_type *old_term = Term;
2513 term_activate(&td->t);
2514 term_resize(td->cols, td->rows);
2515 term_activate(old_term);
2516 InvalidateRect(td->w, NULL, TRUE);
2517 p_ptr->window_flags = 0xFFFFFFFF;
2518 handle_stuff(p_ptr);
2521 td->size_hack = FALSE;
2525 BeginPaint(hWnd, &ps);
2527 term_data_redraw(td);
2528 EndPaint(hWnd, &ps);
2533 if (process_keydown(wParam, lParam))
2540 term_no_press = FALSE;
2542 term_keypress(wParam);
2545 case WM_NCLBUTTONDOWN: {
2546 if (wParam == HTCLOSE)
2549 if (wParam == HTSYSMENU) {
2551 td->visible = FALSE;
2552 ShowWindow(td->w, SW_HIDE);
2562 return DefWindowProc(hWnd, uMsg, wParam, lParam);
2566 * Display warning message (see "z-util.c")
2568 static void hack_plog(concptr str)
2571 MessageBoxW(NULL, to_wchar(str).wc_str(), _(L"警告!", L"Warning"), MB_ICONEXCLAMATION | MB_OK);
2576 * Display error message and quit (see "z-util.c")
2578 static void hack_quit(concptr str)
2581 MessageBoxW(NULL, to_wchar(str).wc_str(), _(L"エラー!", L"Error"), MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2584 UnregisterClass(AppName, hInstance);
2592 * Display warning message (see "z-util.c")
2594 static void hook_plog(concptr str)
2597 MessageBoxW(data[0].w, to_wchar(str).wc_str(), _(L"警告!", L"Warning"), MB_ICONEXCLAMATION | MB_OK);
2602 * Display error message and quit (see "z-util.c")
2604 static void hook_quit(concptr str)
2607 MessageBoxW(data[0].w, to_wchar(str).wc_str(), _(L"エラー!", L"Error"), MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2611 for (int i = MAX_TERM_DATA - 1; i >= 0; --i) {
2612 term_force_font(&data[i]);
2613 if (data[i].font_want)
2614 string_free(data[i].font_want);
2616 DestroyWindow(data[i].w);
2620 infGraph.delete_bitmap();
2621 infMask.delete_bitmap();
2623 DeleteObject(hbrYellow);
2625 finalize_graphics();
2627 UnregisterClass(AppName, hInstance);
2637 static void init_stuff(void)
2640 GetModuleFileName(hInstance, path, 512);
2642 strcpy(path + strlen(path) - 4, ".INI");
2643 ini_file = string_make(path);
2644 int i = strlen(path);
2646 for (; i > 0; i--) {
2647 if (path[i] == '\\') {
2652 strcpy(path + i + 1, "lib\\");
2653 validate_dir(path, TRUE);
2654 init_file_paths(path, path);
2655 validate_dir(ANGBAND_DIR_APEX, FALSE);
2656 validate_dir(ANGBAND_DIR_BONE, FALSE);
2657 if (!check_dir(ANGBAND_DIR_EDIT)) {
2658 validate_dir(ANGBAND_DIR_DATA, TRUE);
2660 validate_dir(ANGBAND_DIR_DATA, FALSE);
2663 validate_dir(ANGBAND_DIR_FILE, TRUE);
2664 validate_dir(ANGBAND_DIR_HELP, FALSE);
2665 validate_dir(ANGBAND_DIR_INFO, FALSE);
2666 validate_dir(ANGBAND_DIR_PREF, TRUE);
2667 validate_dir(ANGBAND_DIR_SAVE, FALSE);
2668 validate_dir(ANGBAND_DIR_DEBUG_SAVE, FALSE);
2669 validate_dir(ANGBAND_DIR_USER, TRUE);
2670 validate_dir(ANGBAND_DIR_XTRA, TRUE);
2671 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
2673 validate_file(path);
2674 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
2675 ANGBAND_DIR_XTRA_GRAF = string_make(path);
2676 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
2678 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
2679 ANGBAND_DIR_XTRA_SOUND = string_make(path);
2680 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
2682 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
2683 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
2684 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
2688 * @brief コマンドラインから全スポイラー出力を行う
2689 * Create Spoiler files from Command Line
2690 * @return spoiler_output_status
2692 static spoiler_output_status create_debug_spoiler(LPSTR cmd_line)
2698 return SPOILER_OUTPUT_CANCEL;
2699 option = "--output-spoilers";
2701 if (strncmp(s, option, strlen(option)) != 0)
2702 return SPOILER_OUTPUT_CANCEL;
2705 init_angband(p_ptr, TRUE);
2707 return output_all_spoilers();
2711 * @todo よく見るとhMutexはちゃんと使われていない……?
2712 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
2714 static bool is_already_running(void)
2717 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
2718 if (GetLastError() == ERROR_ALREADY_EXISTS) {
2726 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
2728 int WINAPI WinMain(_In_ HINSTANCE hInst, _In_opt_ HINSTANCE hPrevInst, _In_ LPSTR lpCmdLine, [[maybe_unused]] _In_ int nCmdShow)
2730 setlocale(LC_ALL, "ja_JP");
2732 if (is_already_running()) {
2734 NULL, _(L"変愚蛮怒はすでに起動しています。", L"Hengband is already running."), _(L"エラー!", L"Error"), MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2738 switch (create_debug_spoiler(lpCmdLine)) {
2739 case SPOILER_OUTPUT_SUCCESS:
2740 fprintf(stdout, "Successfully created a spoiler file.");
2743 case SPOILER_OUTPUT_FAIL_FOPEN:
2744 fprintf(stderr, "Cannot create spoiler file.");
2747 case SPOILER_OUTPUT_FAIL_FCLOSE:
2748 fprintf(stderr, "Cannot close spoiler file.");
2755 if (hPrevInst == NULL) {
2757 wc.style = CS_CLASSDC;
2758 wc.lpfnWndProc = AngbandWndProc;
2761 wc.hInstance = hInst;
2762 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
2763 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
2764 wc.hbrBackground = static_cast<HBRUSH>(GetStockObject(BLACK_BRUSH));
2765 wc.lpszMenuName = AppName;
2766 wc.lpszClassName = AppName;
2768 if (!RegisterClass(&wc))
2771 wc.lpfnWndProc = AngbandListProc;
2772 wc.lpszMenuName = NULL;
2773 wc.lpszClassName = AngList;
2775 if (!RegisterClass(&wc))
2779 plog_aux = hack_plog;
2780 quit_aux = hack_quit;
2781 core_aux = hack_quit;
2784 for (int i = 0; special_key_list[i]; ++i) {
2785 special_key[special_key_list[i]] = TRUE;
2788 for (int i = 0; ignore_key_list[i]; ++i) {
2789 ignore_key[ignore_key_list[i]] = TRUE;
2792 HDC hdc = GetDC(NULL);
2793 if (GetDeviceCaps(hdc, BITSPIXEL) <= 8) {
2794 quit(_("画面を16ビット以上のカラーモードにして下さい。", "Please switch to High Color (16-bit) or higher color mode."));
2796 ReleaseDC(NULL, hdc);
2798 refresh_color_table();
2800 change_bg_mode(current_bg_mode, true);
2802 plog_aux = hook_plog;
2803 quit_aux = hook_quit;
2804 core_aux = hook_quit;
2806 ANGBAND_SYS = "win";
2807 if (7 != GetKeyboardType(0))
2808 ANGBAND_KEYBOARD = "0";
2810 switch (GetKeyboardType(1)) {
2818 ANGBAND_KEYBOARD = "NEC98";
2822 ANGBAND_KEYBOARD = "JAPAN";
2827 term_activate(term_screen);
2828 init_angband(p_ptr, FALSE);
2830 check_for_save_file(p_ptr, lpCmdLine);
2831 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
2834 use_music = arg_music;
2840 while (GetMessage(&msg, NULL, 0, 0)) {
2841 TranslateMessage(&msg);
2842 DispatchMessage(&msg);
2848 #endif /* WINDOWS */