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 React to global changes
793 static errr term_xtra_win_react(player_type *player_ptr)
795 refresh_color_table();
797 const byte current_mode = static_cast<byte>(graphic.get_mode());
798 if (current_mode != arg_graphics) {
799 const byte old_graphics = arg_graphics;
800 arg_graphics = static_cast<byte>(graphic.change_graphics(static_cast<graphics_mode>(arg_graphics)));
801 if (old_graphics != arg_graphics) {
802 plog(_("グラフィクスを初期化できません!", "Cannot initialize graphics!"));
804 use_graphics = (arg_graphics > 0);
805 reset_visuals(player_ptr);
808 for (int i = 0; i < MAX_TERM_DATA; i++) {
809 term_type *old = Term;
810 term_data *td = &data[i];
811 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt)) {
812 term_activate(&td->t);
813 term_resize(td->cols, td->rows);
823 * @brief Process at least one event
825 static errr term_xtra_win_event(int v)
829 if (GetMessage(&msg, NULL, 0, 0)) {
830 TranslateMessage(&msg);
831 DispatchMessage(&msg);
834 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
835 TranslateMessage(&msg);
836 DispatchMessage(&msg);
844 * @brief Process all pending events
846 static errr term_xtra_win_flush(void)
849 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
850 TranslateMessage(&msg);
851 DispatchMessage(&msg);
858 * @brief Hack -- clear the screen
860 * Make this more efficient
862 static errr term_xtra_win_clear(void)
864 term_data *td = (term_data *)(Term->data);
867 GetClientRect(td->w, &rc);
869 HDC hdc = GetDC(td->w);
870 SetBkColor(hdc, RGB(0, 0, 0));
871 SelectObject(hdc, td->font_id);
872 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
874 if (current_bg_mode != bg_mode::BG_NONE) {
880 ReleaseDC(td->w, hdc);
885 * @brief Hack -- make a noise
887 static errr term_xtra_win_noise(void)
889 MessageBeep(MB_ICONASTERISK);
894 * @brief Hack -- make a sound
896 static errr term_xtra_win_sound(int v)
900 return play_sound(v);
904 * @brief Hack -- play a music
906 static errr term_xtra_win_music(int n, int v)
912 return main_win_music::play_music(n, v);
916 * @brief Hack -- play a music matches a situation
918 static errr term_xtra_win_scene(int v)
925 return main_win_music::play_music_scene(v);
929 * @brief Delay for "x" milliseconds
931 static int term_xtra_win_delay(int v)
938 * @brief Do a "special thing"
939 * @todo z-termに影響があるのでplayer_typeの追加は保留
941 static errr term_xtra_win(int n, int v)
944 case TERM_XTRA_NOISE: {
945 return (term_xtra_win_noise());
947 case TERM_XTRA_MUSIC_BASIC:
948 case TERM_XTRA_MUSIC_DUNGEON:
949 case TERM_XTRA_MUSIC_QUEST:
950 case TERM_XTRA_MUSIC_TOWN:
951 case TERM_XTRA_MUSIC_MONSTER: {
952 return term_xtra_win_music(n, v);
954 case TERM_XTRA_MUSIC_MUTE: {
955 return main_win_music::stop_music();
957 case TERM_XTRA_SCENE: {
958 return term_xtra_win_scene(v);
960 case TERM_XTRA_SOUND: {
961 return (term_xtra_win_sound(v));
963 case TERM_XTRA_BORED: {
964 return (term_xtra_win_event(0));
966 case TERM_XTRA_EVENT: {
967 return (term_xtra_win_event(v));
969 case TERM_XTRA_FLUSH: {
970 return (term_xtra_win_flush());
972 case TERM_XTRA_CLEAR: {
973 return (term_xtra_win_clear());
975 case TERM_XTRA_REACT: {
976 return (term_xtra_win_react(p_ptr));
978 case TERM_XTRA_DELAY: {
979 return (term_xtra_win_delay(v));
987 * @brief Low level graphics (Assumes valid input).
989 * Draw a "cursor" at (x,y), using a "yellow box".
991 static errr term_curs_win(int x, int y)
993 term_data *td = (term_data *)(Term->data);
994 int tile_wid, tile_hgt;
995 tile_wid = td->tile_wid;
996 tile_hgt = td->tile_hgt;
999 rc.left = x * tile_wid + td->size_ow1;
1000 rc.right = rc.left + tile_wid;
1001 rc.top = y * tile_hgt + td->size_oh1;
1002 rc.bottom = rc.top + tile_hgt;
1004 HDC hdc = GetDC(td->w);
1005 FrameRect(hdc, &rc, hbrYellow);
1006 ReleaseDC(td->w, hdc);
1011 * @brief Low level graphics (Assumes valid input).
1013 * Draw a "big cursor" at (x,y), using a "yellow box".
1015 static errr term_bigcurs_win(int x, int y)
1017 term_data *td = (term_data *)(Term->data);
1018 int tile_wid, tile_hgt;
1019 tile_wid = td->tile_wid;
1020 tile_hgt = td->tile_hgt;
1023 rc.left = x * tile_wid + td->size_ow1;
1024 rc.right = rc.left + 2 * tile_wid;
1025 rc.top = y * tile_hgt + td->size_oh1;
1026 rc.bottom = rc.top + tile_hgt;
1028 HDC hdc = GetDC(td->w);
1029 FrameRect(hdc, &rc, hbrYellow);
1030 ReleaseDC(td->w, hdc);
1035 * @brief Low level graphics (Assumes valid input).
1037 * Erase a "block" of "n" characters starting at (x,y).
1039 static errr term_wipe_win(int x, int y, int n)
1041 term_data *td = (term_data *)(Term->data);
1043 rc.left = x * td->tile_wid + td->size_ow1;
1044 rc.right = rc.left + n * td->tile_wid;
1045 rc.top = y * td->tile_hgt + td->size_oh1;
1046 rc.bottom = rc.top + td->tile_hgt;
1048 HDC hdc = GetDC(td->w);
1049 SetBkColor(hdc, RGB(0, 0, 0));
1050 SelectObject(hdc, td->font_id);
1051 if (current_bg_mode != bg_mode::BG_NONE)
1054 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1056 ReleaseDC(td->w, hdc);
1061 * @brief Low level graphics. Assumes valid input.
1063 * Draw several ("n") chars, with an attr, at a given location.
1065 * All "graphic" data is handled by "term_pict_win()", below.
1067 * One would think there is a more efficient method for telling a window
1068 * what color it should be using to draw with, but perhaps simply changing
1069 * it every time is not too inefficient.
1071 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
1073 term_data *td = (term_data *)(Term->data);
1074 static HBITMAP WALL;
1075 static HBRUSH myBrush, oldBrush;
1077 static bool init_done = FALSE;
1080 WALL = LoadBitmapW(hInstance, AppName);
1081 myBrush = CreatePatternBrush(WALL);
1085 RECT rc{ static_cast<LONG>(x * td->tile_wid + td->size_ow1), static_cast<LONG>(y * td->tile_hgt + td->size_oh1),
1086 static_cast<LONG>(rc.left + n * td->tile_wid), static_cast<LONG>(rc.top + td->tile_hgt) };
1088 HDC hdc = GetDC(td->w);
1089 SetBkColor(hdc, RGB(0, 0, 0));
1090 SetTextColor(hdc, win_clr[a]);
1092 SelectObject(hdc, td->font_id);
1093 if (current_bg_mode != bg_mode::BG_NONE)
1094 SetBkMode(hdc, TRANSPARENT);
1096 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1097 if (current_bg_mode != bg_mode::BG_NONE)
1100 rc.left += ((td->tile_wid - td->font_wid) / 2);
1101 rc.right = rc.left + td->font_wid;
1102 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
1103 rc.bottom = rc.top + td->font_hgt;
1105 for (int i = 0; i < n; i++) {
1107 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1]) {
1108 rc.right += td->font_wid;
1109 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1110 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1111 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1112 SelectObject(hdc, oldBrush);
1113 SelectObject(hdc, oldPen);
1114 rc.right -= td->font_wid;
1116 rc.left += 2 * td->tile_wid;
1117 rc.right += 2 * td->tile_wid;
1118 } else if (iskanji(*(s + i))) /* 2バイト文字 */
1120 const auto *buf = to_wchar(s + i).wc_str();
1121 rc.right += td->font_wid;
1123 ExtTextOutA(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 2, NULL);
1125 ExtTextOutW(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, buf, wcslen(buf), NULL);
1126 rc.right -= td->font_wid;
1128 rc.left += 2 * td->tile_wid;
1129 rc.right += 2 * td->tile_wid;
1130 } else if (*(s + i) == 127) {
1131 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1132 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1133 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1134 SelectObject(hdc, oldBrush);
1135 SelectObject(hdc, oldPen);
1136 rc.left += td->tile_wid;
1137 rc.right += td->tile_wid;
1139 ExtTextOutA(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1140 rc.left += td->tile_wid;
1141 rc.right += td->tile_wid;
1144 if (*(s + i) == 127) {
1145 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1146 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1147 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1148 SelectObject(hdc, oldBrush);
1149 SelectObject(hdc, oldPen);
1150 rc.left += td->tile_wid;
1151 rc.right += td->tile_wid;
1153 ExtTextOutA(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1154 rc.left += td->tile_wid;
1155 rc.right += td->tile_wid;
1160 ReleaseDC(td->w, hdc);
1165 * @brief Low level graphics. Assumes valid input.
1167 * Draw an array of "special" attr/char pairs at the given location.
1169 * We use the "term_pict_win()" function for "graphic" data, which are
1170 * encoded by setting the "high-bits" of both the "attr" and the "char"
1171 * data. We use the "attr" to represent the "row" of the main bitmap,
1172 * and the "char" to represent the "col" of the main bitmap. The use
1173 * of this function is induced by the "higher_pict" flag.
1175 * If "graphics" is not available, we simply "wipe" the given grids.
1177 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)
1179 term_data *td = (term_data *)(Term->data);
1182 if (!use_graphics) {
1183 return (term_wipe_win(x, y, n));
1186 const tile_info &infGraph = graphic.get_tile_info();
1187 const bool has_mask = (infGraph.hBitmapMask != NULL);
1188 TERM_LEN w1 = infGraph.CellWidth;
1189 TERM_LEN h1 = infGraph.CellHeight;
1190 TERM_LEN tw1 = infGraph.TileWidth;
1191 TERM_LEN th1 = infGraph.TileHeight;
1192 TERM_LEN w2, h2, tw2 = 0;
1199 TERM_LEN x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
1200 TERM_LEN y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
1201 HDC hdc = GetDC(td->w);
1202 HDC hdcSrc = CreateCompatibleDC(hdc);
1203 HBITMAP hbmSrcOld = static_cast<HBITMAP>(SelectObject(hdcSrc, infGraph.hBitmap));
1206 hdcMask = CreateCompatibleDC(hdc);
1207 SelectObject(hdcMask, infGraph.hBitmapMask);
1210 for (i = 0; i < n; i++, x2 += w2) {
1211 TERM_COLOR a = ap[i];
1213 int row = (a & 0x7F);
1214 int col = (c & 0x7F);
1215 TERM_LEN x1 = col * w1;
1216 TERM_LEN y1 = row * h1;
1219 TERM_LEN x3 = (tcp[i] & 0x7F) * w1;
1220 TERM_LEN y3 = (tap[i] & 0x7F) * h1;
1221 tw2 = tw2 * w1 / tw1;
1223 if ((tw1 == tw2) && (th1 == h2)) {
1224 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
1225 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
1226 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
1230 SetStretchBltMode(hdc, COLORONCOLOR);
1231 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
1232 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
1233 if ((x1 != x3) || (y1 != y3)) {
1234 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
1235 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
1241 if ((w1 == tw2) && (h1 == h2)) {
1242 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
1246 SetStretchBltMode(hdc, COLORONCOLOR);
1247 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
1250 SelectObject(hdcSrc, hbmSrcOld);
1253 SelectObject(hdcMask, hbmSrcOld);
1257 ReleaseDC(td->w, hdc);
1262 * @brief Create and initialize a "term_data" given a title
1264 static void term_data_link(term_data *td)
1266 term_type *t = &td->t;
1267 term_init(t, td->cols, td->rows, FILE_READ_BUFF_SIZE);
1268 t->soft_cursor = TRUE;
1269 t->higher_pict = TRUE;
1270 t->attr_blank = TERM_WHITE;
1271 t->char_blank = ' ';
1272 t->user_hook = term_user_win;
1273 t->xtra_hook = term_xtra_win;
1274 t->curs_hook = term_curs_win;
1275 t->bigcurs_hook = term_bigcurs_win;
1276 t->wipe_hook = term_wipe_win;
1277 t->text_hook = term_text_win;
1278 t->pict_hook = term_pict_win;
1279 t->data = (vptr)(td);
1283 * @brief Create the windows
1285 * First, instantiate the "default" values, then read the "ini_file"
1286 * to over-ride selected values, then create the windows, and fonts.
1288 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
1289 * must make active to realize the palette.
1291 static void init_windows(void)
1295 WIPE(td, term_data);
1296 td->name = win_term_name[0];
1309 for (int i = 1; i < MAX_TERM_DATA; i++) {
1311 WIPE(td, term_data);
1312 td->name = win_term_name[i];
1315 td->visible = FALSE;
1320 td->pos_x = (7 - i) * 30;
1321 td->pos_y = (7 - i) * 20;
1327 /* Atrributes of main window */
1329 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_VISIBLE);
1333 /* Attributes of sub windows */
1334 for (int i = 1; i < MAX_TERM_DATA; i++) {
1336 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
1337 td->dwExStyle = (WS_EX_TOOLWINDOW);
1340 /* Font of each window */
1341 for (int i = 0; i < MAX_TERM_DATA; i++) {
1343 wcsncpy(td->lf.lfFaceName, to_wchar(td->font_want).wc_str(), LF_FACESIZE);
1344 td->lf.lfCharSet = _(SHIFTJIS_CHARSET, DEFAULT_CHARSET);
1345 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
1346 term_force_font(td);
1348 td->tile_wid = td->font_wid;
1350 td->tile_hgt = td->font_hgt;
1352 term_window_resize(td);
1355 /* Create sub windows */
1356 for (int i = MAX_TERM_DATA - 1; i >= 1; --i) {
1360 td->w = CreateWindowExW(
1361 td->dwExStyle, AngList, td->name, td->dwStyle, td->pos_x, td->pos_y, td->size_wid, td->size_hgt, HWND_DESKTOP, NULL, hInstance, NULL);
1365 quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
1367 td->size_hack = TRUE;
1369 term_window_resize(td);
1372 ShowWindow(td->w, SW_SHOW);
1374 td->size_hack = FALSE;
1377 angband_term[i] = &td->t;
1380 /* Activate the window */
1381 SetActiveWindow(td->w);
1385 term_window_pos(td, HWND_TOPMOST);
1387 term_window_pos(td, td->w);
1391 /* Create main window */
1394 td->w = CreateWindowExW(
1395 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);
1399 quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
1402 td->size_hack = TRUE;
1404 term_window_resize(td);
1405 td->size_hack = FALSE;
1408 angband_term[0] = &td->t;
1409 normsize.x = td->cols;
1410 normsize.y = td->rows;
1413 ShowWindow(td->w, SW_SHOWMAXIMIZED);
1415 ShowWindow(td->w, SW_SHOW);
1417 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
1418 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
1419 (void)term_xtra_win_flush();
1423 * @brief Prepare the menus
1425 static void setup_menus(void)
1427 HMENU hm = GetMenu(data[0].w);
1429 if (current_world_ptr->character_generated) {
1430 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1431 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1432 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_ENABLED);
1434 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
1435 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
1436 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1439 for (int i = 0; i < MAX_TERM_DATA; i++) {
1440 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1441 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i, (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
1442 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_ENABLED);
1445 for (int i = 0; i < MAX_TERM_DATA; i++) {
1446 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1448 if (data[i].visible) {
1449 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1453 for (int i = 0; i < MAX_TERM_DATA; i++) {
1454 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1455 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i, (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
1456 if (data[i].visible) {
1457 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_ENABLED);
1461 for (int i = 0; i < MAX_TERM_DATA; i++) {
1462 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1463 if (data[i].visible) {
1464 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
1468 for (int i = 0; i < MAX_TERM_DATA; i++) {
1469 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1470 if (data[i].visible) {
1471 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
1475 for (int i = 0; i < MAX_TERM_DATA; i++) {
1476 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1477 if (data[i].visible) {
1478 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1482 for (int i = 0; i < MAX_TERM_DATA; i++) {
1483 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1485 if (data[i].visible) {
1486 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1489 CheckMenuItem(hm, IDM_WINDOW_KEEP_SUBWINDOWS, (keep_subwindows ? MF_CHECKED : MF_UNCHECKED));
1491 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, (arg_graphics == static_cast<byte>(graphics_mode::GRAPHICS_NONE) ? MF_CHECKED : MF_UNCHECKED));
1492 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, (arg_graphics == static_cast<byte>(graphics_mode::GRAPHICS_ORIGINAL) ? MF_CHECKED : MF_UNCHECKED));
1493 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, (arg_graphics == static_cast<byte>(graphics_mode::GRAPHICS_ADAM_BOLT) ? MF_CHECKED : MF_UNCHECKED));
1494 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS, (arg_graphics == static_cast<byte>(graphics_mode::GRAPHICS_HENGBAND) ? MF_CHECKED : MF_UNCHECKED));
1495 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE, (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
1496 CheckMenuItem(hm, IDM_OPTIONS_MUSIC, (arg_music ? MF_CHECKED : MF_UNCHECKED));
1497 CheckMenuItem(hm, IDM_OPTIONS_MUSIC_PAUSE_INACTIVE, (use_pause_music_inactive ? MF_CHECKED : MF_UNCHECKED));
1498 CheckMenuItem(hm, IDM_OPTIONS_SOUND, (arg_sound ? MF_CHECKED : MF_UNCHECKED));
1499 CheckMenuItem(hm, IDM_OPTIONS_NO_BG, ((current_bg_mode == bg_mode::BG_NONE) ? MF_CHECKED : MF_UNCHECKED));
1500 CheckMenuItem(hm, IDM_OPTIONS_BG, ((current_bg_mode == bg_mode::BG_ONE) ? MF_CHECKED : MF_UNCHECKED));
1501 CheckMenuItem(hm, IDM_OPTIONS_PRESET_BG, ((current_bg_mode == bg_mode::BG_PRESET) ? MF_CHECKED : MF_UNCHECKED));
1502 // TODO IDM_OPTIONS_PRESET_BG を有効にする
1503 EnableMenuItem(hm, IDM_OPTIONS_PRESET_BG, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1507 * @brief Check for double clicked (or dragged) savefile
1509 * Apparently, Windows copies the entire filename into the first
1510 * piece of the "command line string". Perhaps we should extract
1511 * the "basename" of that filename and append it to the "save" dir.
1512 * @param savefile_option savefile path
1514 static void check_for_save_file(const std::string &savefile_option)
1516 if (savefile_option.empty())
1519 strcpy(savefile, savefile_option.c_str());
1520 validate_file(savefile);
1521 game_in_progress = true;
1525 * @brief Process a menu command
1527 static void process_menus(player_type *player_ptr, WORD wCmd)
1530 plog(_("まだ初期化中です...", "You cannot do that yet..."));
1537 case IDM_FILE_NEW: {
1538 if (game_in_progress || movie_in_progress) {
1539 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
1541 game_in_progress = true;
1547 case IDM_FILE_OPEN: {
1548 if (game_in_progress || movie_in_progress) {
1549 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
1551 memset(&ofn, 0, sizeof(ofn));
1552 ofn.lStructSize = sizeof(ofn);
1553 ofn.hwndOwner = data[0].w;
1554 ofn.lpstrFilter = L"Save Files (*.)\0*\0";
1555 ofn.nFilterIndex = 1;
1556 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
1558 if (get_open_filename(&ofn, ANGBAND_DIR_SAVE, savefile, MAIN_WIN_MAX_PATH)) {
1559 validate_file(savefile);
1560 game_in_progress = true;
1566 case IDM_FILE_SAVE: {
1567 if (game_in_progress && current_world_ptr->character_generated) {
1569 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
1574 do_cmd_save_game(player_ptr, FALSE);
1576 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
1581 case IDM_FILE_EXIT: {
1582 if (game_in_progress && current_world_ptr->character_generated) {
1584 plog(_("今は終了できません。", "You may not do that right now."));
1589 forget_lite(player_ptr->current_floor_ptr);
1590 forget_view(player_ptr->current_floor_ptr);
1591 clear_mon_lite(player_ptr->current_floor_ptr);
1593 term_key_push(SPECIAL_KEY_QUIT);
1600 case IDM_FILE_SCORE: {
1602 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
1603 highscore_fd = fd_open(buf, O_RDONLY);
1604 if (highscore_fd < 0) {
1605 msg_print("Score file unavailable.");
1609 display_scores(0, MAX_HISCORES, -1, NULL);
1610 (void)fd_close(highscore_fd);
1618 case IDM_FILE_MOVIE: {
1619 if (game_in_progress || movie_in_progress) {
1620 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
1622 memset(&ofn, 0, sizeof(ofn));
1623 ofn.lStructSize = sizeof(ofn);
1624 ofn.hwndOwner = data[0].w;
1625 ofn.lpstrFilter = L"Angband Movie Files (*.amv)\0*.amv\0";
1626 ofn.nFilterIndex = 1;
1627 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1629 if (get_open_filename(&ofn, ANGBAND_DIR_USER, savefile, MAIN_WIN_MAX_PATH)) {
1630 prepare_browse_movie_without_path_build(savefile);
1631 movie_in_progress = true;
1637 case IDM_WINDOW_VIS_0: {
1638 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
1641 case IDM_WINDOW_VIS_1:
1642 case IDM_WINDOW_VIS_2:
1643 case IDM_WINDOW_VIS_3:
1644 case IDM_WINDOW_VIS_4:
1645 case IDM_WINDOW_VIS_5:
1646 case IDM_WINDOW_VIS_6:
1647 case IDM_WINDOW_VIS_7: {
1648 int i = wCmd - IDM_WINDOW_VIS_0;
1649 if ((i < 0) || (i >= MAX_TERM_DATA))
1655 ShowWindow(td->w, SW_SHOW);
1656 term_data_redraw(td);
1658 td->visible = FALSE;
1660 ShowWindow(td->w, SW_HIDE);
1665 case IDM_WINDOW_FONT_0:
1666 case IDM_WINDOW_FONT_1:
1667 case IDM_WINDOW_FONT_2:
1668 case IDM_WINDOW_FONT_3:
1669 case IDM_WINDOW_FONT_4:
1670 case IDM_WINDOW_FONT_5:
1671 case IDM_WINDOW_FONT_6:
1672 case IDM_WINDOW_FONT_7: {
1673 int i = wCmd - IDM_WINDOW_FONT_0;
1674 if ((i < 0) || (i >= MAX_TERM_DATA))
1678 term_change_font(td);
1681 case IDM_WINDOW_POS_1:
1682 case IDM_WINDOW_POS_2:
1683 case IDM_WINDOW_POS_3:
1684 case IDM_WINDOW_POS_4:
1685 case IDM_WINDOW_POS_5:
1686 case IDM_WINDOW_POS_6:
1687 case IDM_WINDOW_POS_7: {
1688 int i = wCmd - IDM_WINDOW_POS_0;
1689 if ((i < 0) || (i >= MAX_TERM_DATA))
1693 if (!td->posfix && td->visible) {
1695 term_window_pos(td, HWND_TOPMOST);
1698 term_window_pos(td, data[0].w);
1703 case IDM_WINDOW_I_WID_0:
1704 case IDM_WINDOW_I_WID_1:
1705 case IDM_WINDOW_I_WID_2:
1706 case IDM_WINDOW_I_WID_3:
1707 case IDM_WINDOW_I_WID_4:
1708 case IDM_WINDOW_I_WID_5:
1709 case IDM_WINDOW_I_WID_6:
1710 case IDM_WINDOW_I_WID_7: {
1711 int i = wCmd - IDM_WINDOW_I_WID_0;
1712 if ((i < 0) || (i >= MAX_TERM_DATA))
1718 term_window_resize(td);
1721 case IDM_WINDOW_D_WID_0:
1722 case IDM_WINDOW_D_WID_1:
1723 case IDM_WINDOW_D_WID_2:
1724 case IDM_WINDOW_D_WID_3:
1725 case IDM_WINDOW_D_WID_4:
1726 case IDM_WINDOW_D_WID_5:
1727 case IDM_WINDOW_D_WID_6:
1728 case IDM_WINDOW_D_WID_7: {
1729 int i = wCmd - IDM_WINDOW_D_WID_0;
1730 if ((i < 0) || (i >= MAX_TERM_DATA))
1736 term_window_resize(td);
1739 case IDM_WINDOW_I_HGT_0:
1740 case IDM_WINDOW_I_HGT_1:
1741 case IDM_WINDOW_I_HGT_2:
1742 case IDM_WINDOW_I_HGT_3:
1743 case IDM_WINDOW_I_HGT_4:
1744 case IDM_WINDOW_I_HGT_5:
1745 case IDM_WINDOW_I_HGT_6:
1746 case IDM_WINDOW_I_HGT_7: {
1747 int i = wCmd - IDM_WINDOW_I_HGT_0;
1748 if ((i < 0) || (i >= MAX_TERM_DATA))
1754 term_window_resize(td);
1757 case IDM_WINDOW_D_HGT_0:
1758 case IDM_WINDOW_D_HGT_1:
1759 case IDM_WINDOW_D_HGT_2:
1760 case IDM_WINDOW_D_HGT_3:
1761 case IDM_WINDOW_D_HGT_4:
1762 case IDM_WINDOW_D_HGT_5:
1763 case IDM_WINDOW_D_HGT_6:
1764 case IDM_WINDOW_D_HGT_7: {
1765 int i = wCmd - IDM_WINDOW_D_HGT_0;
1766 if ((i < 0) || (i >= MAX_TERM_DATA))
1772 term_window_resize(td);
1775 case IDM_WINDOW_KEEP_SUBWINDOWS: {
1776 keep_subwindows = !keep_subwindows;
1779 case IDM_OPTIONS_NO_GRAPHICS: {
1780 if (arg_graphics != static_cast<byte>(graphics_mode::GRAPHICS_NONE)) {
1781 arg_graphics = static_cast<byte>(graphics_mode::GRAPHICS_NONE);
1782 if (game_in_progress)
1783 do_cmd_redraw(player_ptr);
1787 case IDM_OPTIONS_OLD_GRAPHICS: {
1788 if (arg_graphics != static_cast<byte>(graphics_mode::GRAPHICS_ORIGINAL)) {
1789 arg_graphics = static_cast<byte>(graphics_mode::GRAPHICS_ORIGINAL);
1790 if (game_in_progress)
1791 do_cmd_redraw(player_ptr);
1796 case IDM_OPTIONS_NEW_GRAPHICS: {
1797 if (arg_graphics != static_cast<byte>(graphics_mode::GRAPHICS_ADAM_BOLT)) {
1798 arg_graphics = static_cast<byte>(graphics_mode::GRAPHICS_ADAM_BOLT);
1799 if (game_in_progress)
1800 do_cmd_redraw(player_ptr);
1805 case IDM_OPTIONS_NEW2_GRAPHICS: {
1806 if (arg_graphics != static_cast<byte>(graphics_mode::GRAPHICS_HENGBAND)) {
1807 arg_graphics = static_cast<byte>(graphics_mode::GRAPHICS_HENGBAND);
1808 if (game_in_progress)
1809 do_cmd_redraw(player_ptr);
1814 case IDM_OPTIONS_BIGTILE: {
1816 arg_bigtile = !arg_bigtile;
1817 term_activate(&td->t);
1818 term_resize(td->cols, td->rows);
1819 InvalidateRect(td->w, NULL, TRUE);
1822 case IDM_OPTIONS_MUSIC: {
1823 arg_music = !arg_music;
1824 use_music = arg_music;
1827 if (game_in_progress)
1828 select_floor_music(player_ptr);
1830 main_win_music::stop_music();
1834 case IDM_OPTIONS_MUSIC_PAUSE_INACTIVE: {
1835 use_pause_music_inactive = !use_pause_music_inactive;
1838 case IDM_OPTIONS_OPEN_MUSIC_DIR: {
1839 std::vector<char> buf(MAIN_WIN_MAX_PATH);
1840 path_build(&buf[0], MAIN_WIN_MAX_PATH, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1841 open_dir_in_explorer(&buf[0]);
1844 case IDM_OPTIONS_SOUND: {
1845 arg_sound = !arg_sound;
1846 change_sound_mode(arg_sound);
1849 case IDM_OPTIONS_OPEN_SOUND_DIR: {
1850 std::vector<char> buf(MAIN_WIN_MAX_PATH);
1851 path_build(&buf[0], MAIN_WIN_MAX_PATH, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1852 open_dir_in_explorer(&buf[0]);
1855 case IDM_OPTIONS_NO_BG: {
1856 change_bg_mode(bg_mode::BG_NONE);
1859 case IDM_OPTIONS_PRESET_BG: {
1860 change_bg_mode(bg_mode::BG_PRESET);
1863 case IDM_OPTIONS_BG: {
1864 if (change_bg_mode(bg_mode::BG_ONE))
1866 // 壁紙の設定に失敗した(ファイルが存在しない等)場合、壁紙に使うファイルを選択させる
1868 [[fallthrough]]; /* Fall through */
1869 case IDM_OPTIONS_OPEN_BG: {
1870 memset(&ofn, 0, sizeof(ofn));
1871 ofn.lStructSize = sizeof(ofn);
1872 ofn.hwndOwner = data[0].w;
1873 ofn.lpstrFilter = L"Image Files (*.bmp;*.png;*.jpg;*.jpeg;)\0*.bmp;*.png;*.jpg;*.jpeg;\0";
1874 ofn.nFilterIndex = 1;
1875 ofn.lpstrTitle = _(L"壁紙を選んでね。", L"Choose wall paper.");
1876 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
1878 if (get_open_filename(&ofn, NULL, wallpaper_file, MAIN_WIN_MAX_PATH)) {
1879 change_bg_mode(bg_mode::BG_ONE, true, true);
1883 case IDM_DUMP_SCREEN_HTML: {
1884 save_screen_as_html(data[0].w);
1891 * @brief Add a keypress to the "queue"
1893 static errr term_keypress(int k)
1895 /* Refuse to enqueue non-keys */
1899 /* Store the char, advance the queue */
1900 Term->key_queue[Term->key_head++] = (char)k;
1902 /* Circular queue, handle wrap */
1903 if (Term->key_head == Term->key_size)
1906 if (Term->key_head != Term->key_tail)
1913 * @brief Add a keypress to the "queue"
1914 * @details マルチバイト文字をkey_queueに追加する。
1915 * @param str マルチバイト文字列
1917 static void term_keypress(char *str)
1922 term_keypress(*psrc);
1931 static bool process_keydown(WPARAM wParam, LPARAM lParam)
1937 if (GetKeyState(VK_CONTROL) & 0x8000)
1939 if (GetKeyState(VK_SHIFT) & 0x8000)
1941 if (GetKeyState(VK_MENU) & 0x8000)
1944 term_no_press = (ma) ? TRUE : FALSE;
1945 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)])) {
1946 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
1947 bool numpad = FALSE;
1957 int i = LOBYTE(HIWORD(lParam));
1961 term_no_press = TRUE;
1962 [[fallthrough]]; /* Fall through */
1981 term_no_press = TRUE;
1982 [[fallthrough]]; /* Fall through */
2000 term_keypress(hexsym[i / 16]);
2001 term_keypress(hexsym[i % 16]);
2011 * @brief ウィンドウのアクティブ/非アクティブのハンドラ
2013 static void handle_app_active(HWND hWnd, UINT uMsg, WPARAM wParam, [[maybe_unused]] LPARAM lParam)
2016 case WM_ACTIVATEAPP: {
2018 if (use_pause_music_inactive)
2019 main_win_music::resume_music();
2021 if (use_pause_music_inactive)
2022 main_win_music::pause_music();
2026 case WM_WINDOWPOSCHANGING: {
2027 if (!IsIconic(hWnd))
2028 if (use_pause_music_inactive)
2029 main_win_music::resume_music();
2036 * @brief メインウインドウ用ウインドウプロシージャ
2038 LRESULT PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2042 td = (term_data *)GetWindowLong(hWnd, 0);
2044 handle_app_active(hWnd, uMsg, wParam, lParam);
2048 SetWindowLong(hWnd, 0, (LONG)(my_td));
2055 case WM_GETMINMAXINFO: {
2059 lpmmi = (MINMAXINFO *)lParam;
2063 rc.left = rc.top = 0;
2064 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
2065 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
2067 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
2069 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
2070 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
2074 case WM_ERASEBKGND: {
2078 BeginPaint(hWnd, &ps);
2080 term_data_redraw(td);
2081 EndPaint(hWnd, &ps);
2082 ValidateRect(hWnd, NULL);
2085 case MM_MCINOTIFY: {
2086 main_win_music::on_mci_notify(wParam, lParam);
2092 if (process_keydown(wParam, lParam))
2097 // wParam is WCHAR because using RegisterClassW
2099 term_no_press = FALSE;
2101 WCHAR wc[2] = { (WCHAR)wParam, '\0' };
2102 term_keypress(to_multibyte(wc).c_str());
2106 case WM_LBUTTONDOWN: {
2107 if (macro_running())
2109 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
2110 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
2116 case WM_LBUTTONUP: {
2121 TERM_LEN dx = abs(oldx - mousex) + 1;
2122 TERM_LEN dy = abs(oldy - mousey) + 1;
2123 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
2124 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
2130 int sz = (dx + 3) * dy;
2132 int sz = (dx + 2) * dy;
2134 hGlobal = GlobalAlloc(GHND, sz + 1);
2135 if (hGlobal == NULL)
2137 lpStr = (LPSTR)GlobalLock(hGlobal);
2139 for (int i = 0; i < dy; i++) {
2142 const auto &scr = data[0].t.scr->c;
2144 C_MAKE(s, (dx + 1), char);
2145 strncpy(s, &scr[oy + i][ox], dx);
2148 if (iskanji(scr[oy + i][ox - 1]))
2152 if (ox + dx < data[0].cols) {
2153 if (iskanji(scr[oy + i][ox + dx - 1]))
2157 for (int j = 0; j < dx; j++) {
2163 for (int j = 0; j < dx; j++) {
2164 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
2173 GlobalUnlock(hGlobal);
2174 if (OpenClipboard(hWnd) == 0) {
2175 GlobalFree(hGlobal);
2180 SetClipboardData(CF_TEXT, hGlobal);
2185 case WM_MOUSEMOVE: {
2190 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
2191 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
2195 dx = abs(oldx - mousex) + 1;
2196 dy = abs(oldy - mousey) + 1;
2197 ox = (oldx > mousex) ? mousex : oldx;
2198 oy = (oldy > mousey) ? mousey : oldy;
2199 term_inversed_area(hWnd, ox, oy, dx, dy);
2204 dx = abs(cx - mousex) + 1;
2205 dy = abs(cy - mousey) + 1;
2206 ox = (cx > mousex) ? mousex : cx;
2207 oy = (cy > mousey) ? mousey : cy;
2208 term_inversed_area(hWnd, ox, oy, dx, dy);
2219 if (!game_in_progress || !current_world_ptr->character_generated) {
2225 plog(_("今は終了できません。", "You may not do that right now."));
2230 forget_lite(p_ptr->current_floor_ptr);
2231 forget_view(p_ptr->current_floor_ptr);
2232 clear_mon_lite(p_ptr->current_floor_ptr);
2233 term_key_push(SPECIAL_KEY_QUIT);
2236 case WM_QUERYENDSESSION: {
2237 if (!game_in_progress || !current_world_ptr->character_generated) {
2244 p_ptr->is_dead = FALSE;
2245 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
2247 p_ptr->panic_save = 1;
2248 signals_ignore_tstp();
2249 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
2250 (void)save_player(p_ptr, SAVE_TYPE_CLOSE_GAME);
2259 process_menus(p_ptr, LOWORD(wParam));
2270 //!< @todo 二重のswitch文。後で分割する.
2272 case SIZE_MINIMIZED: {
2273 for (int i = 1; i < MAX_TERM_DATA; i++) {
2274 if (data[i].visible)
2275 ShowWindow(data[i].w, SW_HIDE);
2280 case SIZE_MAXIMIZED:
2281 case SIZE_RESTORED: {
2282 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1 - td->size_ow2) / td->tile_wid;
2283 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1 - td->size_oh2) / td->tile_hgt;
2284 if ((td->cols != cols) || (td->rows != rows)) {
2287 if (!IsZoomed(td->w) && !IsIconic(td->w)) {
2288 normsize.x = td->cols;
2289 normsize.y = td->rows;
2292 term_activate(&td->t);
2293 term_resize(td->cols, td->rows);
2294 InvalidateRect(td->w, NULL, TRUE);
2297 td->size_hack = TRUE;
2298 for (int i = 1; i < MAX_TERM_DATA; i++) {
2299 if (data[i].visible)
2300 ShowWindow(data[i].w, SW_SHOWNA);
2303 td->size_hack = FALSE;
2312 if (!wParam || HIWORD(lParam))
2315 for (int i = 1; i < MAX_TERM_DATA; i++) {
2316 if (!data[i].posfix)
2317 term_window_pos(&data[i], hWnd);
2323 case WM_ACTIVATEAPP: {
2324 if (IsIconic(td->w))
2327 for (int i = 1; i < MAX_TERM_DATA; i++) {
2328 if (data[i].visible) {
2329 if (wParam == TRUE) {
2330 ShowWindow(data[i].w, SW_SHOWNA);
2332 ShowWindow(data[i].w, SW_HIDE);
2337 [[fallthrough]]; /* Fall through */
2339 if (wParam == FALSE && keep_subwindows) {
2340 for (int i = 1; i < MAX_TERM_DATA; i++) {
2341 if (data[i].visible) {
2342 ShowWindow(data[i].w, SW_SHOWNA);
2349 return DefWindowProc(hWnd, uMsg, wParam, lParam);
2353 * @brief サブウインドウ用ウインドウプロシージャ
2355 LRESULT PASCAL AngbandListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2359 td = (term_data *)GetWindowLong(hWnd, 0);
2363 SetWindowLong(hWnd, 0, (LONG)(my_td));
2369 case WM_GETMINMAXINFO: {
2373 lpmmi = (MINMAXINFO *)lParam;
2377 rc.left = rc.top = 0;
2378 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
2379 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
2381 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
2382 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
2383 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
2394 td->size_hack = TRUE;
2396 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1 - td->size_ow2) / td->tile_wid;
2397 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1 - td->size_oh2) / td->tile_hgt;
2398 if ((td->cols != cols) || (td->rows != rows)) {
2399 term_type *old_term = Term;
2402 term_activate(&td->t);
2403 term_resize(td->cols, td->rows);
2404 term_activate(old_term);
2405 InvalidateRect(td->w, NULL, TRUE);
2406 p_ptr->window_flags = 0xFFFFFFFF;
2407 handle_stuff(p_ptr);
2410 td->size_hack = FALSE;
2413 case WM_ERASEBKGND: {
2417 BeginPaint(hWnd, &ps);
2419 term_data_redraw(td);
2420 EndPaint(hWnd, &ps);
2425 if (process_keydown(wParam, lParam))
2431 // wParam is WCHAR because using RegisterClassW
2433 term_no_press = FALSE;
2435 WCHAR wc[2] = { (WCHAR)wParam, '\0' };
2436 term_keypress(to_multibyte(wc).c_str());
2440 case WM_NCLBUTTONDOWN: {
2441 if (wParam == HTCLOSE)
2444 if (wParam == HTSYSMENU) {
2446 td->visible = FALSE;
2447 ShowWindow(td->w, SW_HIDE);
2457 return DefWindowProc(hWnd, uMsg, wParam, lParam);
2461 * @brief Display warning message (see "z-util.c")
2463 static void hook_plog(concptr str)
2466 MessageBoxW(data[0].w, to_wchar(str).wc_str(), _(L"警告!", L"Warning"), MB_ICONEXCLAMATION | MB_OK);
2471 * @brief Display error message and quit (see "z-util.c")
2473 static void hook_quit(concptr str)
2476 MessageBoxW(data[0].w, to_wchar(str).wc_str(), _(L"エラー!", L"Error"), MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2480 for (int i = MAX_TERM_DATA - 1; i >= 0; --i) {
2481 term_force_font(&data[i]);
2482 if (data[i].font_want)
2483 string_free(data[i].font_want);
2485 DestroyWindow(data[i].w);
2489 DeleteObject(hbrYellow);
2493 UnregisterClassW(AppName, hInstance);
2501 * @brief Init some stuff
2503 static void init_stuff(void)
2505 char path[MAIN_WIN_MAX_PATH];
2506 DWORD path_len = GetModuleFileNameA(hInstance, path, MAIN_WIN_MAX_PATH);
2507 strcpy(path + path_len - 4, ".INI");
2508 ini_file = string_make(path);
2511 for (; i > 0; i--) {
2512 if (path[i] == '\\') {
2517 strcpy(path + i + 1, "lib\\");
2518 validate_dir(path, TRUE);
2519 init_file_paths(path, path);
2520 validate_dir(ANGBAND_DIR_APEX, FALSE);
2521 validate_dir(ANGBAND_DIR_BONE, FALSE);
2522 if (!check_dir(ANGBAND_DIR_EDIT)) {
2523 validate_dir(ANGBAND_DIR_DATA, TRUE);
2525 validate_dir(ANGBAND_DIR_DATA, FALSE);
2528 validate_dir(ANGBAND_DIR_FILE, TRUE);
2529 validate_dir(ANGBAND_DIR_HELP, FALSE);
2530 validate_dir(ANGBAND_DIR_INFO, FALSE);
2531 validate_dir(ANGBAND_DIR_PREF, TRUE);
2532 validate_dir(ANGBAND_DIR_SAVE, FALSE);
2533 validate_dir(ANGBAND_DIR_DEBUG_SAVE, FALSE);
2534 validate_dir(ANGBAND_DIR_USER, TRUE);
2535 validate_dir(ANGBAND_DIR_XTRA, TRUE);
2536 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
2538 validate_file(path);
2539 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
2540 ANGBAND_DIR_XTRA_GRAF = string_make(path);
2541 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
2543 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
2544 ANGBAND_DIR_XTRA_SOUND = string_make(path);
2545 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
2547 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
2548 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
2549 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
2551 for (i = 0; special_key_list[i]; ++i) {
2552 special_key[special_key_list[i]] = TRUE;
2555 for (i = 0; ignore_key_list[i]; ++i) {
2556 ignore_key[ignore_key_list[i]] = TRUE;
2559 ANGBAND_SYS = "win";
2560 if (7 != GetKeyboardType(0))
2561 ANGBAND_KEYBOARD = "0";
2563 switch (GetKeyboardType(1)) {
2571 ANGBAND_KEYBOARD = "NEC98";
2575 ANGBAND_KEYBOARD = "JAPAN";
2581 * @brief 全スポイラー出力を行う
2582 * Create Spoiler files
2583 * @details スポイラー出力処理の成功、失敗に関わらずプロセスを終了する。
2585 void create_debug_spoiler(void)
2588 init_angband(p_ptr, TRUE);
2590 switch (output_all_spoilers()) {
2591 case spoiler_output_status::SPOILER_OUTPUT_SUCCESS:
2592 fprintf(stdout, "Successfully created a spoiler file.");
2593 case spoiler_output_status::SPOILER_OUTPUT_FAIL_FOPEN:
2594 fprintf(stderr, "Cannot create spoiler file.");
2595 case spoiler_output_status::SPOILER_OUTPUT_FAIL_FCLOSE:
2596 fprintf(stderr, "Cannot close spoiler file.");
2605 * @brief メインウインドウ、サブウインドウのウインドウクラス登録
2607 static void register_wndclass(void)
2610 wc.style = CS_CLASSDC;
2611 wc.lpfnWndProc = AngbandWndProc;
2614 wc.hInstance = hInstance;
2615 wc.hIcon = hIcon = LoadIconW(hInstance, AppName);
2616 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
2617 wc.hbrBackground = NULL;
2618 wc.lpszMenuName = AppName;
2619 wc.lpszClassName = AppName;
2621 if (!RegisterClassW(&wc))
2624 wc.lpfnWndProc = AngbandListProc;
2625 wc.lpszMenuName = NULL;
2626 wc.lpszClassName = AngList;
2628 if (!RegisterClassW(&wc))
2633 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
2636 _In_ HINSTANCE hInst, [[maybe_unused]] _In_opt_ HINSTANCE hPrevInst, [[maybe_unused]] _In_ LPSTR lpCmdLine, [[maybe_unused]] _In_ int nCmdShow)
2638 setlocale(LC_ALL, "ja_JP");
2640 if (is_already_running()) {
2642 NULL, _(L"変愚蛮怒はすでに起動しています。", L"Hengband is already running."), _(L"エラー!", L"Error"), MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2646 command_line.handle();
2647 register_wndclass();
2649 // before term_data initialize
2650 plog_aux = [](concptr str) {
2652 MessageBoxW(NULL, to_wchar(str).wc_str(), _(L"警告!", L"Warning"), MB_ICONEXCLAMATION | MB_OK);
2654 quit_aux = [](concptr str) {
2656 MessageBoxW(NULL, to_wchar(str).wc_str(), _(L"エラー!", L"Error"), MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2659 UnregisterClassW(AppName, hInstance);
2665 core_aux = quit_aux;
2669 HDC hdc = GetDC(NULL);
2670 if (GetDeviceCaps(hdc, BITSPIXEL) <= 8) {
2671 quit(_("画面を16ビット以上のカラーモードにして下さい。", "Please switch to High Color (16-bit) or higher color mode."));
2673 ReleaseDC(NULL, hdc);
2675 refresh_color_table();
2677 change_bg_mode(current_bg_mode, true);
2679 // after term_data initialize
2680 plog_aux = hook_plog;
2681 quit_aux = hook_quit;
2682 core_aux = hook_quit;
2685 term_activate(term_screen);
2686 init_angband(p_ptr, FALSE);
2689 check_for_save_file(command_line.get_savefile_option());
2690 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
2693 change_sound_mode(arg_sound);
2694 use_music = arg_music;
2699 // ユーザーがゲーム開始を選択するまで待つループ
2701 while (GetMessage(&msg, NULL, 0, 0)) {
2702 TranslateMessage(&msg);
2703 DispatchMessage(&msg);
2704 if (game_in_progress || movie_in_progress)
2709 if (movie_in_progress) {
2711 play_game(p_ptr, FALSE, TRUE);
2712 } else if (savefile[0] == '\0') {
2714 play_game(p_ptr, TRUE, FALSE);
2717 // selected savefile
2718 play_game(p_ptr, FALSE, FALSE);
2724 #endif /* WINDOWS */