3 * @brief Windows版固有実装(メインエントリポイント含む)
5 * @author Hengband Team
9 * Windows98かその前後の頃を起点としたAPI実装。
11 * DirectXといった昨今描画に標準的となったライブラリも用いていない。
12 * タイルの描画処理などについては、現在動作の詳細を検証中。
16 * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
18 * This software may be copied and distributed for educational, research,
19 * and not for profit purposes provided that this copyright and statement
20 * are included in all such copies.
23 * This file helps Angband work with Windows computers.
25 * To use this file, use an appropriate "Makefile" or "Project File",
26 * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
27 * make sure to obtain various extra files as described below.
29 * The official compilation uses the CodeWarrior Pro compiler, which
30 * includes a special project file and precompilable header file.
34 * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
35 * and/or color redefinitions.
39 * The "lib/user/font-win.prf" contains attr/char mappings for wall.bmp.
43 * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
44 * special bitmap files in "lib/xtra/graf", which are activated by a menu
49 * Compiling this file, and using the resulting executable, requires
50 * several extra files not distributed with the standard Angband code.
51 * All of these extra files can be found in the "ext-win" archive.
55 * The "term_xtra_win_clear()" function should probably do a low-level
56 * clear of the current window, and redraw the borders and other things,
57 * if only for efficiency.
61 * A simpler method is needed for selecting the "tile size" for windows.
65 * The various "warning" messages assume the existance of the "screen.w"
66 * window, I think, and only a few calls actually check for its existance,
67 * this may be okay since "NULL" means "on top of all windows". (?) The
68 * user must never be allowed to "hide" the main window, or the "menubar"
73 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
75 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
77 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
78 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
84 #include "cmd-io/cmd-save.h"
85 #include "cmd-visual/cmd-draw.h"
86 #include "core/game-play.h"
87 #include "core/player-processor.h"
88 #include "core/score-util.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/commandline-win.h"
102 #include "main-win/graphics-win.h"
103 #include "main-win/main-win-bg.h"
104 #include "main-win/main-win-file-utils.h"
105 #include "main-win/main-win-mci.h"
106 #include "main-win/main-win-menuitem.h"
107 #include "main-win/main-win-music.h"
108 #include "main-win/main-win-sound.h"
109 #include "main-win/main-win-utils.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.h"
115 #include "system/player-type-definition.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 "view/display-scores.h"
125 #include "wizard/spoiler-util.h"
126 #include "wizard/wizard-spoiler.h"
127 #include "world/world.h"
139 LPCWSTR win_term_name[] = { L"Hengband", L"Term-1", L"Term-2", L"Term-3", L"Term-4", L"Term-5", L"Term-6", L"Term-7" };
143 * @brief ターム情報構造体 / Extra "term" data
146 * pos_x / pos_y は各タームの左上点座標を指す。
149 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
150 * 1ドットずつ調整するステータスを指す。
151 * また、フォントを変更すると都度自動調整される。
154 * Note the use of "font_want" for the names of the font file requested by
165 TERM_LEN rows; /* int -> uint */
168 uint pos_x; //!< タームの左上X座標
169 uint pos_y; //!< タームの左上Y座標
181 int font_wid; //!< フォント横幅
182 int font_hgt; //!< フォント縦幅
183 int tile_wid; //!< タイル横幅
184 int tile_hgt; //!< タイル縦幅
191 #define MAX_TERM_DATA 8 //!< Maximum number of windows
193 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
194 static term_data *my_td; //!< Hack -- global "window creation" pointer
195 POINT normsize; //!< Remember normal size of main window when maxmized
198 * was main window maximized on previous playing
200 bool win_maximized = FALSE;
205 bool game_in_progress = false;
210 bool movie_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;
233 bg_mode current_bg_mode = bg_mode::BG_NONE;
234 #define DEFAULT_BG_FILENAME "bg.bmp"
235 char wallpaper_file[MAIN_WIN_MAX_PATH] = ""; //!< 壁紙ファイル名。
238 * Show sub-windows even when Hengband is not in focus
240 static bool keep_subwindows = TRUE;
243 * Full path to ANGBAND.INI
245 static concptr ini_file = NULL;
248 * Name of application
250 static LPCWSTR AppName = L"ANGBAND";
253 * Name of sub-window type
255 static LPCWSTR AngList = L"AngList";
258 * The "complex" color values
260 static COLORREF win_clr[256];
263 * Flag for macro trigger with dump ASCII
265 static bool term_no_press = FALSE;
270 static bool mouse_down = FALSE;
271 static bool paint_rect = FALSE;
272 static TERM_LEN mousex = 0, mousey = 0;
273 static TERM_LEN oldx, oldy;
276 * Hack -- define which keys are "special"
278 static bool special_key[256];
279 static bool ignore_key[256];
282 * Hack -- initialization list for "special_key"
284 static byte special_key_list[] = {
285 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,
286 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,
287 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,
288 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,
289 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,
293 static byte ignore_key_list[] = {
294 VK_ESCAPE, VK_TAB, VK_SPACE, 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
295 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 */
299 * @brief Validate a file
301 static void validate_file(concptr s)
306 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
310 * @brief Validate a directory
312 static void validate_dir(concptr s, bool vital)
318 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
319 } else if (mkdir(s)) {
320 quit_fmt("Unable to create directory:\n%s", s);
325 * @brief (Windows版固有実装)Get the "size" for a window
327 static void term_getsize(term_data *td)
334 TERM_LEN wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
335 TERM_LEN hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
339 GetWindowRect(td->w, &rw);
340 GetClientRect(td->w, &rc);
342 td->size_wid = (rw.right - rw.left) - (rc.right - rc.left) + wid;
343 td->size_hgt = (rw.bottom - rw.top) - (rc.bottom - rc.top) + hgt;
348 /* Tempolary calculation */
353 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
354 td->size_wid = rc.right - rc.left;
355 td->size_hgt = rc.bottom - rc.top;
360 * @brief Write the "prefs" for a single term
362 static void save_prefs_aux(int i)
364 term_data *td = &data[i];
365 GAME_TEXT sec_name[128];
371 wsprintfA(sec_name, "Term-%d", i);
374 strcpy(buf, td->visible ? "1" : "0");
375 WritePrivateProfileStringA(sec_name, "Visible", buf, ini_file);
378 auto pwchar = td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : _(L"MS ゴシック", L"Courier");
379 WritePrivateProfileStringA(sec_name, "Font", to_multibyte(pwchar).c_str(), ini_file);
381 wsprintfA(buf, "%d", td->lf.lfWidth);
382 WritePrivateProfileStringA(sec_name, "FontWid", buf, ini_file);
383 wsprintfA(buf, "%d", td->lf.lfHeight);
384 WritePrivateProfileStringA(sec_name, "FontHgt", buf, ini_file);
385 wsprintfA(buf, "%d", td->lf.lfWeight);
386 WritePrivateProfileStringA(sec_name, "FontWgt", buf, ini_file);
388 wsprintfA(buf, "%d", td->tile_wid);
389 WritePrivateProfileStringA(sec_name, "TileWid", buf, ini_file);
391 wsprintfA(buf, "%d", td->tile_hgt);
392 WritePrivateProfileStringA(sec_name, "TileHgt", buf, ini_file);
394 WINDOWPLACEMENT lpwndpl;
395 lpwndpl.length = sizeof(WINDOWPLACEMENT);
396 GetWindowPlacement(td->w, &lpwndpl);
398 RECT rc = lpwndpl.rcNormalPosition;
400 wsprintfA(buf, "%d", normsize.x);
402 wsprintfA(buf, "%d", td->cols);
404 WritePrivateProfileStringA(sec_name, "NumCols", buf, ini_file);
407 wsprintfA(buf, "%d", normsize.y);
409 wsprintfA(buf, "%d", td->rows);
411 WritePrivateProfileStringA(sec_name, "NumRows", buf, ini_file);
413 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
414 WritePrivateProfileStringA(sec_name, "Maximized", buf, ini_file);
417 GetWindowRect(td->w, &rc);
418 wsprintfA(buf, "%d", rc.left);
419 WritePrivateProfileStringA(sec_name, "PositionX", buf, ini_file);
421 wsprintfA(buf, "%d", rc.top);
422 WritePrivateProfileStringA(sec_name, "PositionY", buf, ini_file);
424 strcpy(buf, td->posfix ? "1" : "0");
425 WritePrivateProfileStringA(sec_name, "PositionFix", buf, ini_file);
430 * @brief Write the "prefs"
431 * We assume that the windows have all been initialized
433 static void save_prefs(void)
436 wsprintfA(buf, "%d", arg_graphics);
437 WritePrivateProfileStringA("Angband", "Graphics", buf, ini_file);
439 strcpy(buf, arg_bigtile ? "1" : "0");
440 WritePrivateProfileStringA("Angband", "Bigtile", buf, ini_file);
442 strcpy(buf, arg_sound ? "1" : "0");
443 WritePrivateProfileStringA("Angband", "Sound", buf, ini_file);
445 strcpy(buf, arg_music ? "1" : "0");
446 WritePrivateProfileStringA("Angband", "Music", buf, ini_file);
447 strcpy(buf, use_pause_music_inactive ? "1" : "0");
448 WritePrivateProfileStringA("Angband", "MusicPauseInactive", buf, ini_file);
450 wsprintfA(buf, "%d", current_bg_mode);
451 WritePrivateProfileStringA("Angband", "BackGround", buf, ini_file);
452 WritePrivateProfileStringA("Angband", "BackGroundBitmap", wallpaper_file[0] != '\0' ? wallpaper_file : DEFAULT_BG_FILENAME, ini_file);
454 int path_length = strlen(ANGBAND_DIR) - 4; /* \libの4文字分を削除 */
456 strncat(tmp, ANGBAND_DIR, path_length);
458 int n = strncmp(tmp, savefile, path_length);
460 char relative_path[1024] = "";
461 snprintf(relative_path, sizeof(relative_path), ".\\%s", (savefile + path_length));
462 WritePrivateProfileStringA("Angband", "SaveFile", relative_path, ini_file);
464 WritePrivateProfileStringA("Angband", "SaveFile", savefile, ini_file);
467 strcpy(buf, keep_subwindows ? "1" : "0");
468 WritePrivateProfileStringA("Angband", "KeepSubwindows", buf, ini_file);
470 for (int i = 0; i < MAX_TERM_DATA; ++i) {
476 * @brief callback for EnumDisplayMonitors API
478 BOOL CALLBACK monitorenumproc([[maybe_unused]] HMONITOR hMon, [[maybe_unused]] HDC hdcMon, [[maybe_unused]] LPRECT lpMon, LPARAM dwDate)
480 bool *result = (bool *)dwDate;
486 * @brief Load the "prefs" for a single term
488 static void load_prefs_aux(int i)
490 term_data *td = &data[i];
491 GAME_TEXT sec_name[128];
494 wsprintfA(sec_name, "Term-%d", i);
496 td->visible = (GetPrivateProfileIntA(sec_name, "Visible", td->visible, ini_file) != 0);
499 GetPrivateProfileStringA(sec_name, "Font", _("MS ゴシック", "Courier"), tmp, 127, ini_file);
501 td->font_want = string_make(tmp);
504 td->lf.lfWidth = GetPrivateProfileIntA(sec_name, "FontWid", wid, ini_file);
505 td->lf.lfHeight = GetPrivateProfileIntA(sec_name, "FontHgt", hgt, ini_file);
506 td->lf.lfWeight = GetPrivateProfileIntA(sec_name, "FontWgt", 0, ini_file);
508 td->tile_wid = GetPrivateProfileIntA(sec_name, "TileWid", td->lf.lfWidth, ini_file);
509 td->tile_hgt = GetPrivateProfileIntA(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
511 td->cols = GetPrivateProfileIntA(sec_name, "NumCols", td->cols, ini_file);
512 td->rows = GetPrivateProfileIntA(sec_name, "NumRows", td->rows, ini_file);
513 normsize.x = td->cols;
514 normsize.y = td->rows;
517 win_maximized = (GetPrivateProfileIntA(sec_name, "Maximized", win_maximized, ini_file) != 0);
520 int posx = GetPrivateProfileIntA(sec_name, "PositionX", 0, ini_file);
521 int posy = GetPrivateProfileIntA(sec_name, "PositionY", 0, ini_file);
522 // 保存座標がモニタ内の領域にあるかチェック
523 RECT rect = { posx, posy, posx + 128, posy + 128 };
524 bool in_any_monitor = false;
525 ::EnumDisplayMonitors(NULL, &rect, monitorenumproc, (LPARAM)&in_any_monitor);
526 if (in_any_monitor) {
527 // いずれかのモニタに表示可能、ウインドウ位置を復元
533 td->posfix = (GetPrivateProfileIntA(sec_name, "PositionFix", td->posfix, ini_file) != 0);
538 * @brief Load the "prefs"
540 static void load_prefs(void)
542 arg_graphics = (byte)GetPrivateProfileIntA("Angband", "Graphics", static_cast<byte>(graphics_mode::GRAPHICS_NONE), ini_file);
543 arg_bigtile = (GetPrivateProfileIntA("Angband", "Bigtile", FALSE, ini_file) != 0);
544 use_bigtile = arg_bigtile;
545 arg_sound = (GetPrivateProfileIntA("Angband", "Sound", 0, ini_file) != 0);
546 arg_music = (GetPrivateProfileIntA("Angband", "Music", 0, ini_file) != 0);
547 use_pause_music_inactive = (GetPrivateProfileIntA("Angband", "MusicPauseInactive", 0, ini_file) != 0);
548 current_bg_mode = static_cast<bg_mode>(GetPrivateProfileIntA("Angband", "BackGround", 0, ini_file));
549 GetPrivateProfileStringA("Angband", "BackGroundBitmap", DEFAULT_BG_FILENAME, wallpaper_file, 1023, ini_file);
550 GetPrivateProfileStringA("Angband", "SaveFile", "", savefile, 1023, ini_file);
552 int n = strncmp(".\\", savefile, 2);
554 int path_length = strlen(ANGBAND_DIR) - 4; /* \libの4文字分を削除 */
556 strncat(tmp, ANGBAND_DIR, path_length);
557 strncat(tmp, savefile + 2, strlen(savefile) - 2 + path_length);
558 strncpy(savefile, tmp, strlen(tmp));
561 keep_subwindows = (GetPrivateProfileIntA("Angband", "KeepSubwindows", 0, ini_file) != 0);
562 for (int i = 0; i < MAX_TERM_DATA; ++i) {
568 * @brief Initialize music
570 static void init_music(void)
572 // Flag set once "music" has been initialized
573 static bool can_use_music = FALSE;
575 if (!can_use_music) {
576 main_win_music::load_music_prefs();
577 can_use_music = TRUE;
582 * @brief Initialize sound
584 static void init_sound(void)
586 // Flag set once "sound" has been initialized
587 static bool can_use_sound = FALSE;
589 if (!can_use_sound) {
591 can_use_sound = TRUE;
596 * @brief Change sound mode
597 * @param new_mode bool
599 static void change_sound_mode(bool new_mode)
601 use_sound = new_mode;
608 * @brief Initialize background
610 static void init_background(void)
612 // Flag set once "background" has been initialized
613 static bool can_use_background = FALSE;
615 if (!can_use_background) {
617 can_use_background = TRUE;
622 * @brief Change background mode
623 * @param new_mode bg_mode
624 * @param show_error trueに設定した場合のみ、エラーダイアログを表示する
625 * @param force_redraw trueの場合、モード変更に関わらずウインドウを再描画する
626 * @retval true success
627 * @retval false failed
629 static bool change_bg_mode(bg_mode new_mode, bool show_error = false, bool force_redraw = false)
631 bg_mode old_bg_mode = current_bg_mode;
632 current_bg_mode = new_mode;
633 if (current_bg_mode != bg_mode::BG_NONE) {
635 if (!load_bg(wallpaper_file)) {
636 current_bg_mode = bg_mode::BG_NONE;
638 plog_fmt(_("壁紙用ファイル '%s' を読み込めません。", "Can't load the image file '%s'."), wallpaper_file);
644 const bool mode_changed = (current_bg_mode != old_bg_mode);
645 if (mode_changed || force_redraw) {
647 for (int i = 0; i < MAX_TERM_DATA; i++) {
648 term_data *td = &data[i];
650 InvalidateRect(td->w, NULL, FALSE);
654 return (current_bg_mode == new_mode);
658 * @brief Resize a window
660 static void term_window_resize(term_data *td)
665 SetWindowPos(td->w, 0, 0, 0, td->size_wid, td->size_hgt, SWP_NOMOVE | SWP_NOZORDER);
666 InvalidateRect(td->w, NULL, TRUE);
670 * @brief Force the use of a new font for a term_data.
671 * This function may be called before the "window" is ready.
672 * This function returns zero only if everything succeeds.
673 * @note that the "font name" must be capitalized!!!
675 static errr term_force_font(term_data *td)
678 DeleteObject(td->font_id);
680 td->font_id = CreateFontIndirectW(&(td->lf));
681 int wid = td->lf.lfWidth;
682 int hgt = td->lf.lfHeight;
691 hdcDesktop = GetDC(HWND_DESKTOP);
692 hfOld = static_cast<HFONT>(SelectObject(hdcDesktop, td->font_id));
693 GetTextMetrics(hdcDesktop, &tm);
694 SelectObject(hdcDesktop, hfOld);
695 ReleaseDC(HWND_DESKTOP, hdcDesktop);
697 wid = tm.tmAveCharWidth;
708 * @brief Allow the user to change the font for this window.
710 static void term_change_font(term_data *td)
713 memset(&cf, 0, sizeof(cf));
714 cf.lStructSize = sizeof(cf);
715 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
716 cf.lpLogFont = &(td->lf);
718 if (!ChooseFontW(&cf))
722 td->tile_wid = td->font_wid;
723 td->tile_hgt = td->font_hgt;
725 term_window_resize(td);
729 * @brief Allow the user to lock this window.
731 static void term_window_pos(term_data *td, HWND hWnd)
733 SetWindowPos(td->w, hWnd, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
737 * @brief Hack -- redraw a term_data
739 static void term_data_redraw(term_data *td)
741 term_activate(&td->t);
743 term_activate(term_screen);
749 void term_inversed_area(HWND hWnd, int x, int y, int w, int h)
751 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
752 int tx = td->size_ow1 + x * td->tile_wid;
753 int ty = td->size_oh1 + y * td->tile_hgt;
754 int tw = w * td->tile_wid - 1;
755 int th = h * td->tile_hgt - 1;
757 HDC hdc = GetDC(hWnd);
758 HBRUSH myBrush = CreateSolidBrush(RGB(255, 255, 255));
759 HBRUSH oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
760 HPEN oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
762 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
764 SelectObject(hdc, oldBrush);
765 SelectObject(hdc, oldPen);
769 * @brief Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
771 static errr term_user_win(int n)
780 static void refresh_color_table()
782 for (int i = 0; i < 256; i++) {
783 byte rv = angband_color_table[i][1];
784 byte gv = angband_color_table[i][2];
785 byte bv = angband_color_table[i][3];
786 win_clr[i] = PALETTERGB(rv, gv, bv);
791 * @brief グラフィクスのモード変更
793 static void change_graphics_mode(graphics_mode mode)
795 graphics_mode ret = graphic.change_graphics(mode);
797 plog(_("グラフィクスを初期化できません!", "Cannot initialize graphics!"));
799 arg_graphics = static_cast<byte>(ret);
800 use_graphics = (arg_graphics > 0);
804 * @brief React to global changes
806 static errr term_xtra_win_react(player_type *player_ptr)
808 refresh_color_table();
810 const byte current_mode = static_cast<byte>(graphic.get_mode());
811 if (current_mode != arg_graphics) {
812 change_graphics_mode(static_cast<graphics_mode>(arg_graphics));
813 reset_visuals(player_ptr);
816 for (int i = 0; i < MAX_TERM_DATA; i++) {
817 term_type *old = Term;
818 term_data *td = &data[i];
819 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt)) {
820 term_activate(&td->t);
821 term_resize(td->cols, td->rows);
831 * @brief Process at least one event
833 static errr term_xtra_win_event(int v)
837 if (GetMessage(&msg, NULL, 0, 0)) {
838 TranslateMessage(&msg);
839 DispatchMessage(&msg);
842 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
843 TranslateMessage(&msg);
844 DispatchMessage(&msg);
852 * @brief Process all pending events
854 static errr term_xtra_win_flush(void)
857 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
858 TranslateMessage(&msg);
859 DispatchMessage(&msg);
866 * @brief Hack -- clear the screen
868 * Make this more efficient
870 static errr term_xtra_win_clear(void)
872 term_data *td = (term_data *)(Term->data);
875 GetClientRect(td->w, &rc);
877 HDC hdc = GetDC(td->w);
878 SetBkColor(hdc, RGB(0, 0, 0));
879 SelectObject(hdc, td->font_id);
880 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
882 if (current_bg_mode != bg_mode::BG_NONE) {
888 ReleaseDC(td->w, hdc);
893 * @brief Hack -- make a noise
895 static errr term_xtra_win_noise(void)
897 MessageBeep(MB_ICONASTERISK);
902 * @brief Hack -- make a sound
904 static errr term_xtra_win_sound(int v)
908 return play_sound(v);
912 * @brief Hack -- play a music
914 static errr term_xtra_win_music(int n, int v)
920 return main_win_music::play_music(n, v);
924 * @brief Hack -- play a music matches a situation
926 static errr term_xtra_win_scene(int v)
933 return main_win_music::play_music_scene(v);
937 * @brief Delay for "x" milliseconds
939 static int term_xtra_win_delay(int v)
946 * @brief Do a "special thing"
947 * @todo z-termに影響があるのでplayer_typeの追加は保留
949 static errr term_xtra_win(int n, int v)
952 case TERM_XTRA_NOISE: {
953 return (term_xtra_win_noise());
955 case TERM_XTRA_MUSIC_BASIC:
956 case TERM_XTRA_MUSIC_DUNGEON:
957 case TERM_XTRA_MUSIC_QUEST:
958 case TERM_XTRA_MUSIC_TOWN:
959 case TERM_XTRA_MUSIC_MONSTER: {
960 return term_xtra_win_music(n, v);
962 case TERM_XTRA_MUSIC_MUTE: {
963 return main_win_music::stop_music();
965 case TERM_XTRA_SCENE: {
966 return term_xtra_win_scene(v);
968 case TERM_XTRA_SOUND: {
969 return (term_xtra_win_sound(v));
971 case TERM_XTRA_BORED: {
972 return (term_xtra_win_event(0));
974 case TERM_XTRA_EVENT: {
975 return (term_xtra_win_event(v));
977 case TERM_XTRA_FLUSH: {
978 return (term_xtra_win_flush());
980 case TERM_XTRA_CLEAR: {
981 return (term_xtra_win_clear());
983 case TERM_XTRA_REACT: {
984 return (term_xtra_win_react(p_ptr));
986 case TERM_XTRA_DELAY: {
987 return (term_xtra_win_delay(v));
995 * @brief Low level graphics (Assumes valid input).
997 * Draw a "cursor" at (x,y), using a "yellow box".
999 static errr term_curs_win(int x, int y)
1001 term_data *td = (term_data *)(Term->data);
1002 int tile_wid, tile_hgt;
1003 tile_wid = td->tile_wid;
1004 tile_hgt = td->tile_hgt;
1007 rc.left = x * tile_wid + td->size_ow1;
1008 rc.right = rc.left + tile_wid;
1009 rc.top = y * tile_hgt + td->size_oh1;
1010 rc.bottom = rc.top + tile_hgt;
1012 HDC hdc = GetDC(td->w);
1013 FrameRect(hdc, &rc, hbrYellow);
1014 ReleaseDC(td->w, hdc);
1019 * @brief Low level graphics (Assumes valid input).
1021 * Draw a "big cursor" at (x,y), using a "yellow box".
1023 static errr term_bigcurs_win(int x, int y)
1025 term_data *td = (term_data *)(Term->data);
1026 int tile_wid, tile_hgt;
1027 tile_wid = td->tile_wid;
1028 tile_hgt = td->tile_hgt;
1031 rc.left = x * tile_wid + td->size_ow1;
1032 rc.right = rc.left + 2 * tile_wid;
1033 rc.top = y * tile_hgt + td->size_oh1;
1034 rc.bottom = rc.top + tile_hgt;
1036 HDC hdc = GetDC(td->w);
1037 FrameRect(hdc, &rc, hbrYellow);
1038 ReleaseDC(td->w, hdc);
1043 * @brief Low level graphics (Assumes valid input).
1045 * Erase a "block" of "n" characters starting at (x,y).
1047 static errr term_wipe_win(int x, int y, int n)
1049 term_data *td = (term_data *)(Term->data);
1051 rc.left = x * td->tile_wid + td->size_ow1;
1052 rc.right = rc.left + n * td->tile_wid;
1053 rc.top = y * td->tile_hgt + td->size_oh1;
1054 rc.bottom = rc.top + td->tile_hgt;
1056 HDC hdc = GetDC(td->w);
1057 SetBkColor(hdc, RGB(0, 0, 0));
1058 SelectObject(hdc, td->font_id);
1059 if (current_bg_mode != bg_mode::BG_NONE)
1062 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1064 ReleaseDC(td->w, hdc);
1069 * @brief Low level graphics. Assumes valid input.
1071 * Draw several ("n") chars, with an attr, at a given location.
1073 * All "graphic" data is handled by "term_pict_win()", below.
1075 * One would think there is a more efficient method for telling a window
1076 * what color it should be using to draw with, but perhaps simply changing
1077 * it every time is not too inefficient.
1079 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
1081 term_data *td = (term_data *)(Term->data);
1082 static HBITMAP WALL;
1083 static HBRUSH myBrush, oldBrush;
1085 static bool init_done = FALSE;
1088 WALL = LoadBitmapW(hInstance, AppName);
1089 myBrush = CreatePatternBrush(WALL);
1093 RECT rc{ static_cast<LONG>(x * td->tile_wid + td->size_ow1), static_cast<LONG>(y * td->tile_hgt + td->size_oh1),
1094 static_cast<LONG>(rc.left + n * td->tile_wid), static_cast<LONG>(rc.top + td->tile_hgt) };
1096 HDC hdc = GetDC(td->w);
1097 SetBkColor(hdc, RGB(0, 0, 0));
1098 SetTextColor(hdc, win_clr[a]);
1100 SelectObject(hdc, td->font_id);
1101 if (current_bg_mode != bg_mode::BG_NONE)
1102 SetBkMode(hdc, TRANSPARENT);
1104 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1105 if (current_bg_mode != bg_mode::BG_NONE)
1108 rc.left += ((td->tile_wid - td->font_wid) / 2);
1109 rc.right = rc.left + td->font_wid;
1110 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
1111 rc.bottom = rc.top + td->font_hgt;
1113 for (int i = 0; i < n; i++) {
1115 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1]) {
1116 rc.right += td->font_wid;
1117 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1118 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1119 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1120 SelectObject(hdc, oldBrush);
1121 SelectObject(hdc, oldPen);
1122 rc.right -= td->font_wid;
1124 rc.left += 2 * td->tile_wid;
1125 rc.right += 2 * td->tile_wid;
1126 } else if (iskanji(*(s + i))) /* 2バイト文字 */
1128 const auto *buf = to_wchar(s + i).wc_str();
1129 rc.right += td->font_wid;
1131 ExtTextOutA(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 2, NULL);
1133 ExtTextOutW(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, buf, wcslen(buf), NULL);
1134 rc.right -= td->font_wid;
1136 rc.left += 2 * td->tile_wid;
1137 rc.right += 2 * td->tile_wid;
1138 } else if (*(s + i) == 127) {
1139 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1140 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1141 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1142 SelectObject(hdc, oldBrush);
1143 SelectObject(hdc, oldPen);
1144 rc.left += td->tile_wid;
1145 rc.right += td->tile_wid;
1147 ExtTextOutA(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1148 rc.left += td->tile_wid;
1149 rc.right += td->tile_wid;
1152 if (*(s + i) == 127) {
1153 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1154 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1155 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1156 SelectObject(hdc, oldBrush);
1157 SelectObject(hdc, oldPen);
1158 rc.left += td->tile_wid;
1159 rc.right += td->tile_wid;
1161 ExtTextOutA(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1162 rc.left += td->tile_wid;
1163 rc.right += td->tile_wid;
1168 ReleaseDC(td->w, hdc);
1173 * @brief Low level graphics. Assumes valid input.
1175 * Draw an array of "special" attr/char pairs at the given location.
1177 * We use the "term_pict_win()" function for "graphic" data, which are
1178 * encoded by setting the "high-bits" of both the "attr" and the "char"
1179 * data. We use the "attr" to represent the "row" of the main bitmap,
1180 * and the "char" to represent the "col" of the main bitmap. The use
1181 * of this function is induced by the "higher_pict" flag.
1183 * If "graphics" is not available, we simply "wipe" the given grids.
1185 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)
1187 term_data *td = (term_data *)(Term->data);
1190 if (!use_graphics) {
1191 return (term_wipe_win(x, y, n));
1194 const tile_info &infGraph = graphic.get_tile_info();
1195 const bool has_mask = (infGraph.hBitmapMask != NULL);
1196 TERM_LEN w1 = infGraph.CellWidth;
1197 TERM_LEN h1 = infGraph.CellHeight;
1198 TERM_LEN tw1 = infGraph.TileWidth;
1199 TERM_LEN th1 = infGraph.TileHeight;
1200 TERM_LEN w2, h2, tw2 = 0;
1207 TERM_LEN x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
1208 TERM_LEN y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
1209 HDC hdc = GetDC(td->w);
1210 HDC hdcSrc = CreateCompatibleDC(hdc);
1211 HBITMAP hbmSrcOld = static_cast<HBITMAP>(SelectObject(hdcSrc, infGraph.hBitmap));
1214 hdcMask = CreateCompatibleDC(hdc);
1215 SelectObject(hdcMask, infGraph.hBitmapMask);
1218 for (i = 0; i < n; i++, x2 += w2) {
1219 TERM_COLOR a = ap[i];
1221 int row = (a & 0x7F);
1222 int col = (c & 0x7F);
1223 TERM_LEN x1 = col * w1;
1224 TERM_LEN y1 = row * h1;
1227 TERM_LEN x3 = (tcp[i] & 0x7F) * w1;
1228 TERM_LEN y3 = (tap[i] & 0x7F) * h1;
1229 tw2 = tw2 * w1 / tw1;
1231 if ((tw1 == tw2) && (th1 == h2)) {
1232 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
1233 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
1234 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
1238 SetStretchBltMode(hdc, COLORONCOLOR);
1239 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
1240 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
1241 if ((x1 != x3) || (y1 != y3)) {
1242 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
1243 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
1249 if ((w1 == tw2) && (h1 == h2)) {
1250 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
1254 SetStretchBltMode(hdc, COLORONCOLOR);
1255 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
1258 SelectObject(hdcSrc, hbmSrcOld);
1261 SelectObject(hdcMask, hbmSrcOld);
1265 ReleaseDC(td->w, hdc);
1270 * @brief Create and initialize a "term_data" given a title
1272 static void term_data_link(term_data *td)
1274 term_type *t = &td->t;
1275 term_init(t, td->cols, td->rows, FILE_READ_BUFF_SIZE);
1276 t->soft_cursor = TRUE;
1277 t->higher_pict = TRUE;
1278 t->attr_blank = TERM_WHITE;
1279 t->char_blank = ' ';
1280 t->user_hook = term_user_win;
1281 t->xtra_hook = term_xtra_win;
1282 t->curs_hook = term_curs_win;
1283 t->bigcurs_hook = term_bigcurs_win;
1284 t->wipe_hook = term_wipe_win;
1285 t->text_hook = term_text_win;
1286 t->pict_hook = term_pict_win;
1287 t->data = (vptr)(td);
1291 * @brief Create the windows
1293 * First, instantiate the "default" values, then read the "ini_file"
1294 * to over-ride selected values, then create the windows, and fonts.
1296 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
1297 * must make active to realize the palette.
1299 static void init_windows(void)
1303 WIPE(td, term_data);
1304 td->name = win_term_name[0];
1317 for (int i = 1; i < MAX_TERM_DATA; i++) {
1319 WIPE(td, term_data);
1320 td->name = win_term_name[i];
1323 td->visible = FALSE;
1328 td->pos_x = (7 - i) * 30;
1329 td->pos_y = (7 - i) * 20;
1335 /* Atrributes of main window */
1337 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_VISIBLE);
1341 /* Attributes of sub windows */
1342 for (int i = 1; i < MAX_TERM_DATA; i++) {
1344 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
1345 td->dwExStyle = (WS_EX_TOOLWINDOW);
1348 /* Font of each window */
1349 for (int i = 0; i < MAX_TERM_DATA; i++) {
1351 wcsncpy(td->lf.lfFaceName, to_wchar(td->font_want).wc_str(), LF_FACESIZE);
1352 td->lf.lfCharSet = _(SHIFTJIS_CHARSET, DEFAULT_CHARSET);
1353 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
1354 term_force_font(td);
1356 td->tile_wid = td->font_wid;
1358 td->tile_hgt = td->font_hgt;
1360 term_window_resize(td);
1363 /* Create sub windows */
1364 for (int i = MAX_TERM_DATA - 1; i >= 1; --i) {
1368 td->w = CreateWindowExW(
1369 td->dwExStyle, AngList, td->name, td->dwStyle, td->pos_x, td->pos_y, td->size_wid, td->size_hgt, HWND_DESKTOP, NULL, hInstance, NULL);
1373 quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
1375 td->size_hack = TRUE;
1377 term_window_resize(td);
1380 ShowWindow(td->w, SW_SHOW);
1382 td->size_hack = FALSE;
1385 angband_term[i] = &td->t;
1388 /* Activate the window */
1389 SetActiveWindow(td->w);
1393 term_window_pos(td, HWND_TOPMOST);
1395 term_window_pos(td, td->w);
1399 /* Create main window */
1402 td->w = CreateWindowExW(
1403 td->dwExStyle, AppName, _(L"変愚蛮怒", td->name), td->dwStyle, td->pos_x, td->pos_y, td->size_wid, td->size_hgt, HWND_DESKTOP, NULL, hInstance, NULL);
1407 quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
1410 td->size_hack = TRUE;
1412 term_window_resize(td);
1413 td->size_hack = FALSE;
1416 angband_term[0] = &td->t;
1417 normsize.x = td->cols;
1418 normsize.y = td->rows;
1421 ShowWindow(td->w, SW_SHOWMAXIMIZED);
1423 ShowWindow(td->w, SW_SHOW);
1425 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
1426 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
1427 (void)term_xtra_win_flush();
1431 * @brief Prepare the menus
1433 static void setup_menus(void)
1435 HMENU hm = GetMenu(data[0].w);
1437 if (current_world_ptr->character_generated) {
1438 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1439 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1440 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_ENABLED);
1442 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
1443 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
1444 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1447 for (int i = 0; i < MAX_TERM_DATA; i++) {
1448 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1449 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i, (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
1450 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_ENABLED);
1453 for (int i = 0; i < MAX_TERM_DATA; i++) {
1454 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1456 if (data[i].visible) {
1457 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1461 for (int i = 0; i < MAX_TERM_DATA; i++) {
1462 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1463 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i, (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
1464 if (data[i].visible) {
1465 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_ENABLED);
1469 for (int i = 0; i < MAX_TERM_DATA; i++) {
1470 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1471 if (data[i].visible) {
1472 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
1476 for (int i = 0; i < MAX_TERM_DATA; i++) {
1477 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1478 if (data[i].visible) {
1479 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
1483 for (int i = 0; i < MAX_TERM_DATA; i++) {
1484 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1485 if (data[i].visible) {
1486 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1490 for (int i = 0; i < MAX_TERM_DATA; i++) {
1491 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1493 if (data[i].visible) {
1494 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1497 CheckMenuItem(hm, IDM_WINDOW_KEEP_SUBWINDOWS, (keep_subwindows ? MF_CHECKED : MF_UNCHECKED));
1499 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, (arg_graphics == static_cast<byte>(graphics_mode::GRAPHICS_NONE) ? MF_CHECKED : MF_UNCHECKED));
1500 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, (arg_graphics == static_cast<byte>(graphics_mode::GRAPHICS_ORIGINAL) ? MF_CHECKED : MF_UNCHECKED));
1501 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, (arg_graphics == static_cast<byte>(graphics_mode::GRAPHICS_ADAM_BOLT) ? MF_CHECKED : MF_UNCHECKED));
1502 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS, (arg_graphics == static_cast<byte>(graphics_mode::GRAPHICS_HENGBAND) ? MF_CHECKED : MF_UNCHECKED));
1503 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE, (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
1504 CheckMenuItem(hm, IDM_OPTIONS_MUSIC, (arg_music ? MF_CHECKED : MF_UNCHECKED));
1505 CheckMenuItem(hm, IDM_OPTIONS_MUSIC_PAUSE_INACTIVE, (use_pause_music_inactive ? MF_CHECKED : MF_UNCHECKED));
1506 CheckMenuItem(hm, IDM_OPTIONS_SOUND, (arg_sound ? MF_CHECKED : MF_UNCHECKED));
1507 CheckMenuItem(hm, IDM_OPTIONS_NO_BG, ((current_bg_mode == bg_mode::BG_NONE) ? MF_CHECKED : MF_UNCHECKED));
1508 CheckMenuItem(hm, IDM_OPTIONS_BG, ((current_bg_mode == bg_mode::BG_ONE) ? MF_CHECKED : MF_UNCHECKED));
1509 CheckMenuItem(hm, IDM_OPTIONS_PRESET_BG, ((current_bg_mode == bg_mode::BG_PRESET) ? MF_CHECKED : MF_UNCHECKED));
1510 // TODO IDM_OPTIONS_PRESET_BG を有効にする
1511 EnableMenuItem(hm, IDM_OPTIONS_PRESET_BG, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1515 * @brief Check for double clicked (or dragged) savefile
1517 * Apparently, Windows copies the entire filename into the first
1518 * piece of the "command line string". Perhaps we should extract
1519 * the "basename" of that filename and append it to the "save" dir.
1520 * @param savefile_option savefile path
1522 static void check_for_save_file(const std::string &savefile_option)
1524 if (savefile_option.empty())
1527 strcpy(savefile, savefile_option.c_str());
1528 validate_file(savefile);
1529 game_in_progress = true;
1533 * @brief Process a menu command
1535 static void process_menus(player_type *player_ptr, WORD wCmd)
1538 plog(_("まだ初期化中です...", "You cannot do that yet..."));
1545 case IDM_FILE_NEW: {
1546 if (game_in_progress || movie_in_progress) {
1547 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
1549 game_in_progress = true;
1555 case IDM_FILE_OPEN: {
1556 if (game_in_progress || movie_in_progress) {
1557 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
1559 memset(&ofn, 0, sizeof(ofn));
1560 ofn.lStructSize = sizeof(ofn);
1561 ofn.hwndOwner = data[0].w;
1562 ofn.lpstrFilter = L"Save Files (*.)\0*\0";
1563 ofn.nFilterIndex = 1;
1564 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
1566 if (get_open_filename(&ofn, ANGBAND_DIR_SAVE, savefile, MAIN_WIN_MAX_PATH)) {
1567 validate_file(savefile);
1568 game_in_progress = true;
1574 case IDM_FILE_SAVE: {
1575 if (game_in_progress && current_world_ptr->character_generated) {
1577 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
1582 do_cmd_save_game(player_ptr, FALSE);
1584 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
1589 case IDM_FILE_EXIT: {
1590 if (game_in_progress && current_world_ptr->character_generated) {
1592 plog(_("今は終了できません。", "You may not do that right now."));
1597 forget_lite(player_ptr->current_floor_ptr);
1598 forget_view(player_ptr->current_floor_ptr);
1599 clear_mon_lite(player_ptr->current_floor_ptr);
1601 term_key_push(SPECIAL_KEY_QUIT);
1608 case IDM_FILE_SCORE: {
1610 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
1611 highscore_fd = fd_open(buf, O_RDONLY);
1612 if (highscore_fd < 0) {
1613 msg_print("Score file unavailable.");
1617 display_scores(0, MAX_HISCORES, -1, NULL);
1618 (void)fd_close(highscore_fd);
1626 case IDM_FILE_MOVIE: {
1627 if (game_in_progress || movie_in_progress) {
1628 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
1630 memset(&ofn, 0, sizeof(ofn));
1631 ofn.lStructSize = sizeof(ofn);
1632 ofn.hwndOwner = data[0].w;
1633 ofn.lpstrFilter = L"Angband Movie Files (*.amv)\0*.amv\0";
1634 ofn.nFilterIndex = 1;
1635 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1637 if (get_open_filename(&ofn, ANGBAND_DIR_USER, savefile, MAIN_WIN_MAX_PATH)) {
1638 prepare_browse_movie_without_path_build(savefile);
1639 movie_in_progress = true;
1645 case IDM_WINDOW_VIS_0: {
1646 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
1649 case IDM_WINDOW_VIS_1:
1650 case IDM_WINDOW_VIS_2:
1651 case IDM_WINDOW_VIS_3:
1652 case IDM_WINDOW_VIS_4:
1653 case IDM_WINDOW_VIS_5:
1654 case IDM_WINDOW_VIS_6:
1655 case IDM_WINDOW_VIS_7: {
1656 int i = wCmd - IDM_WINDOW_VIS_0;
1657 if ((i < 0) || (i >= MAX_TERM_DATA))
1663 ShowWindow(td->w, SW_SHOW);
1664 term_data_redraw(td);
1666 td->visible = FALSE;
1668 ShowWindow(td->w, SW_HIDE);
1673 case IDM_WINDOW_FONT_0:
1674 case IDM_WINDOW_FONT_1:
1675 case IDM_WINDOW_FONT_2:
1676 case IDM_WINDOW_FONT_3:
1677 case IDM_WINDOW_FONT_4:
1678 case IDM_WINDOW_FONT_5:
1679 case IDM_WINDOW_FONT_6:
1680 case IDM_WINDOW_FONT_7: {
1681 int i = wCmd - IDM_WINDOW_FONT_0;
1682 if ((i < 0) || (i >= MAX_TERM_DATA))
1686 term_change_font(td);
1689 case IDM_WINDOW_POS_1:
1690 case IDM_WINDOW_POS_2:
1691 case IDM_WINDOW_POS_3:
1692 case IDM_WINDOW_POS_4:
1693 case IDM_WINDOW_POS_5:
1694 case IDM_WINDOW_POS_6:
1695 case IDM_WINDOW_POS_7: {
1696 int i = wCmd - IDM_WINDOW_POS_0;
1697 if ((i < 0) || (i >= MAX_TERM_DATA))
1701 if (!td->posfix && td->visible) {
1703 term_window_pos(td, HWND_TOPMOST);
1706 term_window_pos(td, data[0].w);
1711 case IDM_WINDOW_I_WID_0:
1712 case IDM_WINDOW_I_WID_1:
1713 case IDM_WINDOW_I_WID_2:
1714 case IDM_WINDOW_I_WID_3:
1715 case IDM_WINDOW_I_WID_4:
1716 case IDM_WINDOW_I_WID_5:
1717 case IDM_WINDOW_I_WID_6:
1718 case IDM_WINDOW_I_WID_7: {
1719 int i = wCmd - IDM_WINDOW_I_WID_0;
1720 if ((i < 0) || (i >= MAX_TERM_DATA))
1726 term_window_resize(td);
1729 case IDM_WINDOW_D_WID_0:
1730 case IDM_WINDOW_D_WID_1:
1731 case IDM_WINDOW_D_WID_2:
1732 case IDM_WINDOW_D_WID_3:
1733 case IDM_WINDOW_D_WID_4:
1734 case IDM_WINDOW_D_WID_5:
1735 case IDM_WINDOW_D_WID_6:
1736 case IDM_WINDOW_D_WID_7: {
1737 int i = wCmd - IDM_WINDOW_D_WID_0;
1738 if ((i < 0) || (i >= MAX_TERM_DATA))
1744 term_window_resize(td);
1747 case IDM_WINDOW_I_HGT_0:
1748 case IDM_WINDOW_I_HGT_1:
1749 case IDM_WINDOW_I_HGT_2:
1750 case IDM_WINDOW_I_HGT_3:
1751 case IDM_WINDOW_I_HGT_4:
1752 case IDM_WINDOW_I_HGT_5:
1753 case IDM_WINDOW_I_HGT_6:
1754 case IDM_WINDOW_I_HGT_7: {
1755 int i = wCmd - IDM_WINDOW_I_HGT_0;
1756 if ((i < 0) || (i >= MAX_TERM_DATA))
1762 term_window_resize(td);
1765 case IDM_WINDOW_D_HGT_0:
1766 case IDM_WINDOW_D_HGT_1:
1767 case IDM_WINDOW_D_HGT_2:
1768 case IDM_WINDOW_D_HGT_3:
1769 case IDM_WINDOW_D_HGT_4:
1770 case IDM_WINDOW_D_HGT_5:
1771 case IDM_WINDOW_D_HGT_6:
1772 case IDM_WINDOW_D_HGT_7: {
1773 int i = wCmd - IDM_WINDOW_D_HGT_0;
1774 if ((i < 0) || (i >= MAX_TERM_DATA))
1780 term_window_resize(td);
1783 case IDM_WINDOW_KEEP_SUBWINDOWS: {
1784 keep_subwindows = !keep_subwindows;
1787 case IDM_OPTIONS_NO_GRAPHICS: {
1788 if (arg_graphics != static_cast<byte>(graphics_mode::GRAPHICS_NONE)) {
1789 arg_graphics = static_cast<byte>(graphics_mode::GRAPHICS_NONE);
1790 if (game_in_progress)
1791 do_cmd_redraw(player_ptr);
1795 case IDM_OPTIONS_OLD_GRAPHICS: {
1796 if (arg_graphics != static_cast<byte>(graphics_mode::GRAPHICS_ORIGINAL)) {
1797 arg_graphics = static_cast<byte>(graphics_mode::GRAPHICS_ORIGINAL);
1798 if (game_in_progress)
1799 do_cmd_redraw(player_ptr);
1804 case IDM_OPTIONS_NEW_GRAPHICS: {
1805 if (arg_graphics != static_cast<byte>(graphics_mode::GRAPHICS_ADAM_BOLT)) {
1806 arg_graphics = static_cast<byte>(graphics_mode::GRAPHICS_ADAM_BOLT);
1807 if (game_in_progress)
1808 do_cmd_redraw(player_ptr);
1813 case IDM_OPTIONS_NEW2_GRAPHICS: {
1814 if (arg_graphics != static_cast<byte>(graphics_mode::GRAPHICS_HENGBAND)) {
1815 arg_graphics = static_cast<byte>(graphics_mode::GRAPHICS_HENGBAND);
1816 if (game_in_progress)
1817 do_cmd_redraw(player_ptr);
1822 case IDM_OPTIONS_BIGTILE: {
1824 arg_bigtile = !arg_bigtile;
1825 term_activate(&td->t);
1826 term_resize(td->cols, td->rows);
1827 InvalidateRect(td->w, NULL, TRUE);
1830 case IDM_OPTIONS_MUSIC: {
1831 arg_music = !arg_music;
1832 use_music = arg_music;
1835 if (game_in_progress)
1836 select_floor_music(player_ptr);
1838 main_win_music::stop_music();
1842 case IDM_OPTIONS_MUSIC_PAUSE_INACTIVE: {
1843 use_pause_music_inactive = !use_pause_music_inactive;
1846 case IDM_OPTIONS_OPEN_MUSIC_DIR: {
1847 std::vector<char> buf(MAIN_WIN_MAX_PATH);
1848 path_build(&buf[0], MAIN_WIN_MAX_PATH, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1849 open_dir_in_explorer(&buf[0]);
1852 case IDM_OPTIONS_SOUND: {
1853 arg_sound = !arg_sound;
1854 change_sound_mode(arg_sound);
1857 case IDM_OPTIONS_OPEN_SOUND_DIR: {
1858 std::vector<char> buf(MAIN_WIN_MAX_PATH);
1859 path_build(&buf[0], MAIN_WIN_MAX_PATH, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1860 open_dir_in_explorer(&buf[0]);
1863 case IDM_OPTIONS_NO_BG: {
1864 change_bg_mode(bg_mode::BG_NONE);
1867 case IDM_OPTIONS_PRESET_BG: {
1868 change_bg_mode(bg_mode::BG_PRESET);
1871 case IDM_OPTIONS_BG: {
1872 if (change_bg_mode(bg_mode::BG_ONE))
1874 // 壁紙の設定に失敗した(ファイルが存在しない等)場合、壁紙に使うファイルを選択させる
1876 [[fallthrough]]; /* Fall through */
1877 case IDM_OPTIONS_OPEN_BG: {
1878 memset(&ofn, 0, sizeof(ofn));
1879 ofn.lStructSize = sizeof(ofn);
1880 ofn.hwndOwner = data[0].w;
1881 ofn.lpstrFilter = L"Image Files (*.bmp;*.png;*.jpg;*.jpeg;)\0*.bmp;*.png;*.jpg;*.jpeg;\0";
1882 ofn.nFilterIndex = 1;
1883 ofn.lpstrTitle = _(L"壁紙を選んでね。", L"Choose wall paper.");
1884 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
1886 if (get_open_filename(&ofn, NULL, wallpaper_file, MAIN_WIN_MAX_PATH)) {
1887 change_bg_mode(bg_mode::BG_ONE, true, true);
1891 case IDM_DUMP_SCREEN_HTML: {
1892 save_screen_as_html(data[0].w);
1899 * @brief Add a keypress to the "queue"
1901 static errr term_keypress(int k)
1903 /* Refuse to enqueue non-keys */
1907 /* Store the char, advance the queue */
1908 Term->key_queue[Term->key_head++] = (char)k;
1910 /* Circular queue, handle wrap */
1911 if (Term->key_head == Term->key_size)
1914 if (Term->key_head != Term->key_tail)
1921 * @brief Add a keypress to the "queue"
1922 * @details マルチバイト文字をkey_queueに追加する。
1923 * @param str マルチバイト文字列
1925 static void term_keypress(char *str)
1930 term_keypress(*psrc);
1939 static bool process_keydown(WPARAM wParam, LPARAM lParam)
1945 if (GetKeyState(VK_CONTROL) & 0x8000)
1947 if (GetKeyState(VK_SHIFT) & 0x8000)
1949 if (GetKeyState(VK_MENU) & 0x8000)
1952 term_no_press = (ma) ? TRUE : FALSE;
1953 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)])) {
1954 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
1955 bool numpad = FALSE;
1965 int i = LOBYTE(HIWORD(lParam));
1969 term_no_press = TRUE;
1970 [[fallthrough]]; /* Fall through */
1989 term_no_press = TRUE;
1990 [[fallthrough]]; /* Fall through */
2008 term_keypress(hexsym[i / 16]);
2009 term_keypress(hexsym[i % 16]);
2019 * @brief ウィンドウのアクティブ/非アクティブのハンドラ
2021 static void handle_app_active(HWND hWnd, UINT uMsg, WPARAM wParam, [[maybe_unused]] LPARAM lParam)
2024 case WM_ACTIVATEAPP: {
2026 if (use_pause_music_inactive)
2027 main_win_music::resume_music();
2029 if (use_pause_music_inactive)
2030 main_win_music::pause_music();
2034 case WM_WINDOWPOSCHANGING: {
2035 if (!IsIconic(hWnd))
2036 if (use_pause_music_inactive)
2037 main_win_music::resume_music();
2044 * @brief メインウインドウ用ウインドウプロシージャ
2046 LRESULT PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2050 td = (term_data *)GetWindowLong(hWnd, 0);
2052 handle_app_active(hWnd, uMsg, wParam, lParam);
2056 SetWindowLong(hWnd, 0, (LONG)(my_td));
2063 case WM_GETMINMAXINFO: {
2067 lpmmi = (MINMAXINFO *)lParam;
2071 rc.left = rc.top = 0;
2072 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
2073 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
2075 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
2077 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
2078 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
2082 case WM_ERASEBKGND: {
2086 BeginPaint(hWnd, &ps);
2088 term_data_redraw(td);
2089 EndPaint(hWnd, &ps);
2090 ValidateRect(hWnd, NULL);
2093 case MM_MCINOTIFY: {
2094 main_win_music::on_mci_notify(wParam, lParam);
2100 if (process_keydown(wParam, lParam))
2105 // wParam is WCHAR because using RegisterClassW
2107 term_no_press = FALSE;
2109 WCHAR wc[2] = { (WCHAR)wParam, '\0' };
2110 term_keypress(to_multibyte(wc).c_str());
2114 case WM_LBUTTONDOWN: {
2115 if (macro_running())
2117 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
2118 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
2124 case WM_LBUTTONUP: {
2129 TERM_LEN dx = abs(oldx - mousex) + 1;
2130 TERM_LEN dy = abs(oldy - mousey) + 1;
2131 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
2132 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
2138 int sz = (dx + 3) * dy;
2140 int sz = (dx + 2) * dy;
2142 hGlobal = GlobalAlloc(GHND, sz + 1);
2143 if (hGlobal == NULL)
2145 lpStr = (LPSTR)GlobalLock(hGlobal);
2147 for (int i = 0; i < dy; i++) {
2150 const auto &scr = data[0].t.scr->c;
2152 C_MAKE(s, (dx + 1), char);
2153 strncpy(s, &scr[oy + i][ox], dx);
2156 if (iskanji(scr[oy + i][ox - 1]))
2160 if (ox + dx < data[0].cols) {
2161 if (iskanji(scr[oy + i][ox + dx - 1]))
2165 for (int j = 0; j < dx; j++) {
2171 for (int j = 0; j < dx; j++) {
2172 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
2181 GlobalUnlock(hGlobal);
2182 if (OpenClipboard(hWnd) == 0) {
2183 GlobalFree(hGlobal);
2188 SetClipboardData(CF_TEXT, hGlobal);
2193 case WM_MOUSEMOVE: {
2198 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
2199 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
2203 dx = abs(oldx - mousex) + 1;
2204 dy = abs(oldy - mousey) + 1;
2205 ox = (oldx > mousex) ? mousex : oldx;
2206 oy = (oldy > mousey) ? mousey : oldy;
2207 term_inversed_area(hWnd, ox, oy, dx, dy);
2212 dx = abs(cx - mousex) + 1;
2213 dy = abs(cy - mousey) + 1;
2214 ox = (cx > mousex) ? mousex : cx;
2215 oy = (cy > mousey) ? mousey : cy;
2216 term_inversed_area(hWnd, ox, oy, dx, dy);
2227 if (!game_in_progress || !current_world_ptr->character_generated) {
2233 plog(_("今は終了できません。", "You may not do that right now."));
2238 forget_lite(p_ptr->current_floor_ptr);
2239 forget_view(p_ptr->current_floor_ptr);
2240 clear_mon_lite(p_ptr->current_floor_ptr);
2241 term_key_push(SPECIAL_KEY_QUIT);
2244 case WM_QUERYENDSESSION: {
2245 if (!game_in_progress || !current_world_ptr->character_generated) {
2252 p_ptr->is_dead = FALSE;
2253 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
2255 p_ptr->panic_save = 1;
2256 signals_ignore_tstp();
2257 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
2258 (void)save_player(p_ptr, SAVE_TYPE_CLOSE_GAME);
2267 process_menus(p_ptr, LOWORD(wParam));
2278 //!< @todo 二重のswitch文。後で分割する.
2280 case SIZE_MINIMIZED: {
2281 for (int i = 1; i < MAX_TERM_DATA; i++) {
2282 if (data[i].visible)
2283 ShowWindow(data[i].w, SW_HIDE);
2288 case SIZE_MAXIMIZED:
2289 case SIZE_RESTORED: {
2290 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1 - td->size_ow2) / td->tile_wid;
2291 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1 - td->size_oh2) / td->tile_hgt;
2292 if ((td->cols != cols) || (td->rows != rows)) {
2295 if (!IsZoomed(td->w) && !IsIconic(td->w)) {
2296 normsize.x = td->cols;
2297 normsize.y = td->rows;
2300 term_activate(&td->t);
2301 term_resize(td->cols, td->rows);
2302 InvalidateRect(td->w, NULL, TRUE);
2305 td->size_hack = TRUE;
2306 for (int i = 1; i < MAX_TERM_DATA; i++) {
2307 if (data[i].visible)
2308 ShowWindow(data[i].w, SW_SHOWNA);
2311 td->size_hack = FALSE;
2320 if (!wParam || HIWORD(lParam))
2323 for (int i = 1; i < MAX_TERM_DATA; i++) {
2324 if (!data[i].posfix)
2325 term_window_pos(&data[i], hWnd);
2331 case WM_ACTIVATEAPP: {
2332 if (IsIconic(td->w))
2335 for (int i = 1; i < MAX_TERM_DATA; i++) {
2336 if (data[i].visible) {
2337 if (wParam == TRUE) {
2338 ShowWindow(data[i].w, SW_SHOWNA);
2340 ShowWindow(data[i].w, SW_HIDE);
2345 [[fallthrough]]; /* Fall through */
2347 if (wParam == FALSE && keep_subwindows) {
2348 for (int i = 1; i < MAX_TERM_DATA; i++) {
2349 if (data[i].visible) {
2350 ShowWindow(data[i].w, SW_SHOWNA);
2357 return DefWindowProc(hWnd, uMsg, wParam, lParam);
2361 * @brief サブウインドウ用ウインドウプロシージャ
2363 LRESULT PASCAL AngbandListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2367 td = (term_data *)GetWindowLong(hWnd, 0);
2371 SetWindowLong(hWnd, 0, (LONG)(my_td));
2377 case WM_GETMINMAXINFO: {
2381 lpmmi = (MINMAXINFO *)lParam;
2385 rc.left = rc.top = 0;
2386 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
2387 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
2389 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
2390 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
2391 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
2402 td->size_hack = TRUE;
2404 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1 - td->size_ow2) / td->tile_wid;
2405 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1 - td->size_oh2) / td->tile_hgt;
2406 if ((td->cols != cols) || (td->rows != rows)) {
2407 term_type *old_term = Term;
2410 term_activate(&td->t);
2411 term_resize(td->cols, td->rows);
2412 term_activate(old_term);
2413 InvalidateRect(td->w, NULL, TRUE);
2414 p_ptr->window_flags = 0xFFFFFFFF;
2415 handle_stuff(p_ptr);
2418 td->size_hack = FALSE;
2421 case WM_ERASEBKGND: {
2425 BeginPaint(hWnd, &ps);
2427 term_data_redraw(td);
2428 EndPaint(hWnd, &ps);
2433 if (process_keydown(wParam, lParam))
2439 // wParam is WCHAR because using RegisterClassW
2441 term_no_press = FALSE;
2443 WCHAR wc[2] = { (WCHAR)wParam, '\0' };
2444 term_keypress(to_multibyte(wc).c_str());
2448 case WM_NCLBUTTONDOWN: {
2449 if (wParam == HTCLOSE)
2452 if (wParam == HTSYSMENU) {
2454 td->visible = FALSE;
2455 ShowWindow(td->w, SW_HIDE);
2465 return DefWindowProc(hWnd, uMsg, wParam, lParam);
2469 * @brief Display warning message (see "z-util.c")
2471 static void hook_plog(concptr str)
2474 MessageBoxW(data[0].w, to_wchar(str).wc_str(), _(L"警告!", L"Warning"), MB_ICONEXCLAMATION | MB_OK);
2479 * @brief Display error message and quit (see "z-util.c")
2481 static void hook_quit(concptr str)
2484 MessageBoxW(data[0].w, to_wchar(str).wc_str(), _(L"エラー!", L"Error"), MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2488 for (int i = MAX_TERM_DATA - 1; i >= 0; --i) {
2489 term_force_font(&data[i]);
2490 if (data[i].font_want)
2491 string_free(data[i].font_want);
2493 DestroyWindow(data[i].w);
2497 DeleteObject(hbrYellow);
2501 UnregisterClassW(AppName, hInstance);
2509 * @brief Init some stuff
2511 static void init_stuff(void)
2513 char path[MAIN_WIN_MAX_PATH];
2514 DWORD path_len = GetModuleFileNameA(hInstance, path, MAIN_WIN_MAX_PATH);
2515 strcpy(path + path_len - 4, ".INI");
2516 ini_file = string_make(path);
2519 for (; i > 0; i--) {
2520 if (path[i] == '\\') {
2525 strcpy(path + i + 1, "lib\\");
2526 validate_dir(path, TRUE);
2527 init_file_paths(path, path);
2528 validate_dir(ANGBAND_DIR_APEX, FALSE);
2529 validate_dir(ANGBAND_DIR_BONE, FALSE);
2530 if (!check_dir(ANGBAND_DIR_EDIT)) {
2531 validate_dir(ANGBAND_DIR_DATA, TRUE);
2533 validate_dir(ANGBAND_DIR_DATA, FALSE);
2536 validate_dir(ANGBAND_DIR_FILE, TRUE);
2537 validate_dir(ANGBAND_DIR_HELP, FALSE);
2538 validate_dir(ANGBAND_DIR_INFO, FALSE);
2539 validate_dir(ANGBAND_DIR_PREF, TRUE);
2540 validate_dir(ANGBAND_DIR_SAVE, FALSE);
2541 validate_dir(ANGBAND_DIR_DEBUG_SAVE, FALSE);
2542 validate_dir(ANGBAND_DIR_USER, TRUE);
2543 validate_dir(ANGBAND_DIR_XTRA, TRUE);
2544 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
2546 validate_file(path);
2547 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
2548 ANGBAND_DIR_XTRA_GRAF = string_make(path);
2549 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
2551 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
2552 ANGBAND_DIR_XTRA_SOUND = string_make(path);
2553 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
2555 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
2556 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
2557 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
2559 for (i = 0; special_key_list[i]; ++i) {
2560 special_key[special_key_list[i]] = TRUE;
2563 for (i = 0; ignore_key_list[i]; ++i) {
2564 ignore_key[ignore_key_list[i]] = TRUE;
2567 ANGBAND_SYS = "win";
2568 if (7 != GetKeyboardType(0))
2569 ANGBAND_KEYBOARD = "0";
2571 switch (GetKeyboardType(1)) {
2579 ANGBAND_KEYBOARD = "NEC98";
2583 ANGBAND_KEYBOARD = "JAPAN";
2589 * @brief 全スポイラー出力を行う
2590 * Create Spoiler files
2591 * @details スポイラー出力処理の成功、失敗に関わらずプロセスを終了する。
2593 void create_debug_spoiler(void)
2596 init_angband(p_ptr, TRUE);
2598 switch (output_all_spoilers()) {
2599 case spoiler_output_status::SPOILER_OUTPUT_SUCCESS:
2600 fprintf(stdout, "Successfully created a spoiler file.");
2601 case spoiler_output_status::SPOILER_OUTPUT_FAIL_FOPEN:
2602 fprintf(stderr, "Cannot create spoiler file.");
2603 case spoiler_output_status::SPOILER_OUTPUT_FAIL_FCLOSE:
2604 fprintf(stderr, "Cannot close spoiler file.");
2613 * @brief メインウインドウ、サブウインドウのウインドウクラス登録
2615 static void register_wndclass(void)
2618 wc.style = CS_CLASSDC;
2619 wc.lpfnWndProc = AngbandWndProc;
2622 wc.hInstance = hInstance;
2623 wc.hIcon = hIcon = LoadIconW(hInstance, AppName);
2624 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
2625 wc.hbrBackground = NULL;
2626 wc.lpszMenuName = AppName;
2627 wc.lpszClassName = AppName;
2629 if (!RegisterClassW(&wc))
2632 wc.lpfnWndProc = AngbandListProc;
2633 wc.lpszMenuName = NULL;
2634 wc.lpszClassName = AngList;
2636 if (!RegisterClassW(&wc))
2641 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
2644 _In_ HINSTANCE hInst, [[maybe_unused]] _In_opt_ HINSTANCE hPrevInst, [[maybe_unused]] _In_ LPSTR lpCmdLine, [[maybe_unused]] _In_ int nCmdShow)
2646 setlocale(LC_ALL, "ja_JP");
2648 if (is_already_running()) {
2650 NULL, _(L"変愚蛮怒はすでに起動しています。", L"Hengband is already running."), _(L"エラー!", L"Error"), MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2654 command_line.handle();
2655 register_wndclass();
2657 // before term_data initialize
2658 plog_aux = [](concptr str) {
2660 MessageBoxW(NULL, to_wchar(str).wc_str(), _(L"警告!", L"Warning"), MB_ICONEXCLAMATION | MB_OK);
2662 quit_aux = [](concptr str) {
2664 MessageBoxW(NULL, to_wchar(str).wc_str(), _(L"エラー!", L"Error"), MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2667 UnregisterClassW(AppName, hInstance);
2673 core_aux = quit_aux;
2677 HDC hdc = GetDC(NULL);
2678 if (GetDeviceCaps(hdc, BITSPIXEL) <= 8) {
2679 quit(_("画面を16ビット以上のカラーモードにして下さい。", "Please switch to High Color (16-bit) or higher color mode."));
2681 ReleaseDC(NULL, hdc);
2683 refresh_color_table();
2685 change_graphics_mode(static_cast<graphics_mode>(arg_graphics));
2686 change_bg_mode(current_bg_mode, true);
2688 // after term_data initialize
2689 plog_aux = hook_plog;
2690 quit_aux = hook_quit;
2691 core_aux = hook_quit;
2694 term_activate(term_screen);
2695 init_angband(p_ptr, FALSE);
2698 check_for_save_file(command_line.get_savefile_option());
2699 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
2702 change_sound_mode(arg_sound);
2703 use_music = arg_music;
2708 // ユーザーがゲーム開始を選択するまで待つループ
2710 while (GetMessage(&msg, NULL, 0, 0)) {
2711 TranslateMessage(&msg);
2712 DispatchMessage(&msg);
2713 if (game_in_progress || movie_in_progress)
2718 if (movie_in_progress) {
2720 play_game(p_ptr, FALSE, TRUE);
2721 } else if (savefile[0] == '\0') {
2723 play_game(p_ptr, TRUE, FALSE);
2726 // selected savefile
2727 play_game(p_ptr, FALSE, FALSE);
2733 #endif /* WINDOWS */