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"
138 * @brief ターム情報構造体 / Extra "term" data
141 * pos_x / pos_y は各タームの左上点座標を指す。
144 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
145 * 1ドットずつ調整するステータスを指す。
146 * また、フォントを変更すると都度自動調整される。
149 * Note the use of "font_want" for the names of the font file requested by
161 TERM_LEN rows; /* int -> uint */
164 uint pos_x; //!< タームの左上X座標
165 uint pos_y; //!< タームの左上Y座標
178 int font_wid; //!< フォント横幅
179 int font_hgt; //!< フォント縦幅
180 int tile_wid; //!< タイル横幅
181 int tile_hgt; //!< タイル縦幅
188 #define MAX_TERM_DATA 8 //!< Maximum number of windows
190 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
191 static term_data *my_td; //!< Hack -- global "window creation" pointer
192 POINT normsize; //!< Remember normal size of main window when maxmized
195 * was main window maximized on previous playing
197 bool win_maximized = FALSE;
202 bool game_in_progress = FALSE;
205 * note when "open"/"new" become valid
207 bool initialized = FALSE;
210 * Saved instance handle
212 static HINSTANCE hInstance;
215 * Yellow brush for the cursor
217 static HBRUSH hbrYellow;
225 bg_mode current_bg_mode = bg_mode::BG_NONE;
226 #define DEFAULT_BG_FILENAME "bg.bmp"
227 char wallpaper_file[MAIN_WIN_MAX_PATH] = ""; //!< 壁紙ファイル名。
230 * Show sub-windows even when Hengband is not in focus
232 static bool keep_subwindows = TRUE;
235 * Full path to ANGBAND.INI
237 static concptr ini_file = NULL;
240 * Name of application
242 static concptr AppName = "ANGBAND";
245 * Name of sub-window type
247 static concptr AngList = "AngList";
250 * The "complex" color values
252 static COLORREF win_clr[256];
255 * Flag for macro trigger with dump ASCII
257 static bool term_no_press = FALSE;
262 static bool mouse_down = FALSE;
263 static bool paint_rect = FALSE;
264 static TERM_LEN mousex = 0, mousey = 0;
265 static TERM_LEN oldx, oldy;
268 * Hack -- define which keys are "special"
270 static bool special_key[256];
271 static bool ignore_key[256];
274 * Hack -- initialization list for "special_key"
276 static byte special_key_list[] = {
277 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,
278 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,
279 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,
280 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,
281 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,
285 static byte ignore_key_list[] = {
286 VK_ESCAPE, VK_TAB, VK_SPACE, 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
287 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 */
291 * @brief Validate a file
293 static void validate_file(concptr s)
298 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
302 * @brief Validate a directory
304 static void validate_dir(concptr s, bool vital)
310 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
311 } else if (mkdir(s)) {
312 quit_fmt("Unable to create directory:\n%s", s);
317 * @brief (Windows版固有実装)Get the "size" for a window
319 static void term_getsize(term_data *td)
326 TERM_LEN wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
327 TERM_LEN hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
331 GetWindowRect(td->w, &rw);
332 GetClientRect(td->w, &rc);
334 td->size_wid = (rw.right - rw.left) - (rc.right - rc.left) + wid;
335 td->size_hgt = (rw.bottom - rw.top) - (rc.bottom - rc.top) + hgt;
340 /* Tempolary calculation */
345 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
346 td->size_wid = rc.right - rc.left;
347 td->size_hgt = rc.bottom - rc.top;
352 * @brief Write the "prefs" for a single term
354 static void save_prefs_aux(int i)
356 term_data *td = &data[i];
357 GAME_TEXT sec_name[128];
363 sprintf(sec_name, "Term-%d", i);
366 strcpy(buf, td->visible ? "1" : "0");
367 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
370 auto pwchar = td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : _(L"MS ゴシック", L"Courier");
371 WritePrivateProfileString(sec_name, "Font", to_multibyte(pwchar).c_str(), ini_file);
373 wsprintf(buf, "%d", td->lf.lfWidth);
374 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
375 wsprintf(buf, "%d", td->lf.lfHeight);
376 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
377 wsprintf(buf, "%d", td->lf.lfWeight);
378 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
380 wsprintf(buf, "%d", td->tile_wid);
381 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
383 wsprintf(buf, "%d", td->tile_hgt);
384 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
386 WINDOWPLACEMENT lpwndpl;
387 lpwndpl.length = sizeof(WINDOWPLACEMENT);
388 GetWindowPlacement(td->w, &lpwndpl);
390 RECT rc = lpwndpl.rcNormalPosition;
392 wsprintf(buf, "%d", normsize.x);
394 wsprintf(buf, "%d", td->cols);
396 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
399 wsprintf(buf, "%d", normsize.y);
401 wsprintf(buf, "%d", td->rows);
403 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
405 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
406 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
409 GetWindowRect(td->w, &rc);
410 wsprintf(buf, "%d", rc.left);
411 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
413 wsprintf(buf, "%d", rc.top);
414 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
416 strcpy(buf, td->posfix ? "1" : "0");
417 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
422 * @brief Write the "prefs"
423 * We assume that the windows have all been initialized
425 static void save_prefs(void)
428 sprintf(buf, "%d", arg_graphics);
429 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
431 strcpy(buf, arg_bigtile ? "1" : "0");
432 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
434 strcpy(buf, arg_sound ? "1" : "0");
435 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
437 strcpy(buf, arg_music ? "1" : "0");
438 WritePrivateProfileString("Angband", "Music", buf, ini_file);
439 strcpy(buf, use_pause_music_inactive ? "1" : "0");
440 WritePrivateProfileString("Angband", "MusicPauseInactive", buf, ini_file);
442 sprintf(buf, "%d", current_bg_mode);
443 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
444 WritePrivateProfileString("Angband", "BackGroundBitmap", wallpaper_file[0] != '\0' ? wallpaper_file : DEFAULT_BG_FILENAME, ini_file);
446 int path_length = strlen(ANGBAND_DIR) - 4; /* \libの4文字分を削除 */
448 strncat(tmp, ANGBAND_DIR, path_length);
450 int n = strncmp(tmp, savefile, path_length);
452 char relative_path[1024] = "";
453 snprintf(relative_path, sizeof(relative_path), ".\\%s", (savefile + path_length));
454 WritePrivateProfileString("Angband", "SaveFile", relative_path, ini_file);
456 WritePrivateProfileString("Angband", "SaveFile", savefile, ini_file);
459 strcpy(buf, keep_subwindows ? "1" : "0");
460 WritePrivateProfileString("Angband", "KeepSubwindows", buf, ini_file);
462 for (int i = 0; i < MAX_TERM_DATA; ++i) {
468 * @brief callback for EnumDisplayMonitors API
470 BOOL CALLBACK monitorenumproc([[maybe_unused]] HMONITOR hMon, [[maybe_unused]] HDC hdcMon, [[maybe_unused]] LPRECT lpMon, LPARAM dwDate)
472 bool *result = (bool *)dwDate;
478 * @brief Load the "prefs" for a single term
480 static void load_prefs_aux(int i)
482 term_data *td = &data[i];
483 GAME_TEXT sec_name[128];
486 sprintf(sec_name, "Term-%d", i);
488 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
491 GetPrivateProfileString(sec_name, "Font", _("MS ゴシック", "Courier"), tmp, 127, ini_file);
493 td->font_want = string_make(tmp);
496 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
497 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
498 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
500 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
501 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
503 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
504 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
505 normsize.x = td->cols;
506 normsize.y = td->rows;
509 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
512 int posx = GetPrivateProfileInt(sec_name, "PositionX", 0, ini_file);
513 int posy = GetPrivateProfileInt(sec_name, "PositionY", 0, ini_file);
514 // 保存座標がモニタ内の領域にあるかチェック
515 RECT rect = { posx, posy, posx + 128, posy + 128 };
516 bool in_any_monitor = false;
517 ::EnumDisplayMonitors(NULL, &rect, monitorenumproc, (LPARAM)&in_any_monitor);
518 if (in_any_monitor) {
519 // いずれかのモニタに表示可能、ウインドウ位置を復元
525 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
530 * @brief Load the "prefs"
532 static void load_prefs(void)
534 arg_graphics = (byte)GetPrivateProfileInt("Angband", "Graphics", static_cast<byte>(graphics_mode::GRAPHICS_NONE), ini_file);
535 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
536 use_bigtile = arg_bigtile;
537 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
538 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
539 use_pause_music_inactive = (GetPrivateProfileInt("Angband", "MusicPauseInactive", 0, ini_file) != 0);
540 current_bg_mode = static_cast<bg_mode>(GetPrivateProfileInt("Angband", "BackGround", 0, ini_file));
541 GetPrivateProfileString("Angband", "BackGroundBitmap", DEFAULT_BG_FILENAME, wallpaper_file, 1023, ini_file);
542 GetPrivateProfileString("Angband", "SaveFile", "", savefile, 1023, ini_file);
544 int n = strncmp(".\\", savefile, 2);
546 int path_length = strlen(ANGBAND_DIR) - 4; /* \libの4文字分を削除 */
548 strncat(tmp, ANGBAND_DIR, path_length);
549 strncat(tmp, savefile + 2, strlen(savefile) - 2 + path_length);
550 strncpy(savefile, tmp, strlen(tmp));
553 keep_subwindows = (GetPrivateProfileInt("Angband", "KeepSubwindows", 0, ini_file) != 0);
554 for (int i = 0; i < MAX_TERM_DATA; ++i) {
560 * @brief Initialize music
562 static void init_music(void)
564 // Flag set once "music" has been initialized
565 static bool can_use_music = FALSE;
567 if (!can_use_music) {
568 main_win_music::load_music_prefs();
569 can_use_music = TRUE;
574 * @brief Initialize sound
576 static void init_sound(void)
578 // Flag set once "sound" has been initialized
579 static bool can_use_sound = FALSE;
581 if (!can_use_sound) {
583 can_use_sound = TRUE;
588 * @brief Change sound mode
589 * @param new_mode bool
591 static void change_sound_mode(bool new_mode)
593 use_sound = new_mode;
600 * @brief Initialize background
602 static void init_background(void)
604 // Flag set once "background" has been initialized
605 static bool can_use_background = FALSE;
607 if (!can_use_background) {
609 can_use_background = TRUE;
614 * @brief Change background mode
615 * @param new_mode bg_mode
616 * @param show_error trueに設定した場合のみ、エラーダイアログを表示する
617 * @param force_redraw trueの場合、モード変更に関わらずウインドウを再描画する
618 * @retval true success
619 * @retval false failed
621 static bool change_bg_mode(bg_mode new_mode, bool show_error = false, bool force_redraw = false)
623 bg_mode old_bg_mode = current_bg_mode;
624 current_bg_mode = new_mode;
625 if (current_bg_mode != bg_mode::BG_NONE) {
627 if (!load_bg(wallpaper_file)) {
628 current_bg_mode = bg_mode::BG_NONE;
630 plog_fmt(_("壁紙用ファイル '%s' を読み込めません。", "Can't load the image file '%s'."), wallpaper_file);
636 const bool mode_changed = (current_bg_mode != old_bg_mode);
637 if (mode_changed || force_redraw) {
639 for (int i = 0; i < MAX_TERM_DATA; i++) {
640 term_data *td = &data[i];
642 InvalidateRect(td->w, NULL, FALSE);
646 return (current_bg_mode == new_mode);
650 * @brief Resize a window
652 static void term_window_resize(term_data *td)
657 SetWindowPos(td->w, 0, 0, 0, td->size_wid, td->size_hgt, SWP_NOMOVE | SWP_NOZORDER);
658 InvalidateRect(td->w, NULL, TRUE);
662 * @brief Force the use of a new font for a term_data.
663 * This function may be called before the "window" is ready.
664 * This function returns zero only if everything succeeds.
665 * @note that the "font name" must be capitalized!!!
667 static errr term_force_font(term_data *td)
670 DeleteObject(td->font_id);
672 td->font_id = CreateFontIndirectW(&(td->lf));
673 int wid = td->lf.lfWidth;
674 int hgt = td->lf.lfHeight;
683 hdcDesktop = GetDC(HWND_DESKTOP);
684 hfOld = static_cast<HFONT>(SelectObject(hdcDesktop, td->font_id));
685 GetTextMetrics(hdcDesktop, &tm);
686 SelectObject(hdcDesktop, hfOld);
687 ReleaseDC(HWND_DESKTOP, hdcDesktop);
689 wid = tm.tmAveCharWidth;
700 * @brief Allow the user to change the font for this window.
702 static void term_change_font(term_data *td)
705 memset(&cf, 0, sizeof(cf));
706 cf.lStructSize = sizeof(cf);
707 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
708 cf.lpLogFont = &(td->lf);
710 if (!ChooseFontW(&cf))
714 td->tile_wid = td->font_wid;
715 td->tile_hgt = td->font_hgt;
717 term_window_resize(td);
721 * @brief Allow the user to lock this window.
723 static void term_window_pos(term_data *td, HWND hWnd)
725 SetWindowPos(td->w, hWnd, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
729 * @brief Hack -- redraw a term_data
731 static void term_data_redraw(term_data *td)
733 term_activate(&td->t);
735 term_activate(term_screen);
741 void term_inversed_area(HWND hWnd, int x, int y, int w, int h)
743 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
744 int tx = td->size_ow1 + x * td->tile_wid;
745 int ty = td->size_oh1 + y * td->tile_hgt;
746 int tw = w * td->tile_wid - 1;
747 int th = h * td->tile_hgt - 1;
749 HDC hdc = GetDC(hWnd);
750 HBRUSH myBrush = CreateSolidBrush(RGB(255, 255, 255));
751 HBRUSH oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
752 HPEN oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
754 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
756 SelectObject(hdc, oldBrush);
757 SelectObject(hdc, oldPen);
761 * @brief Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
763 static errr term_user_win(int n)
773 static void refresh_color_table()
775 for (int i = 0; i < 256; i++) {
776 byte rv = angband_color_table[i][1];
777 byte gv = angband_color_table[i][2];
778 byte bv = angband_color_table[i][3];
779 win_clr[i] = PALETTERGB(rv, gv, bv);
784 * @brief React to global changes
786 static errr term_xtra_win_react(player_type *player_ptr)
788 refresh_color_table();
790 const byte current_mode = static_cast<byte>(graphic.get_mode());
791 if (current_mode != arg_graphics) {
792 const byte old_graphics = arg_graphics;
793 arg_graphics = static_cast<byte>(graphic.change_graphics(static_cast<graphics_mode>(arg_graphics)));
794 if (old_graphics != arg_graphics) {
795 plog(_("グラフィクスを初期化できません!", "Cannot initialize graphics!"));
797 use_graphics = (arg_graphics > 0);
798 reset_visuals(player_ptr);
801 for (int i = 0; i < MAX_TERM_DATA; i++) {
802 term_type *old = Term;
803 term_data *td = &data[i];
804 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt)) {
805 term_activate(&td->t);
806 term_resize(td->cols, td->rows);
816 * @brief Process at least one event
818 static errr term_xtra_win_event(int v)
822 if (GetMessage(&msg, NULL, 0, 0)) {
823 TranslateMessage(&msg);
824 DispatchMessage(&msg);
827 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
828 TranslateMessage(&msg);
829 DispatchMessage(&msg);
837 * @brief Process all pending events
839 static errr term_xtra_win_flush(void)
842 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
843 TranslateMessage(&msg);
844 DispatchMessage(&msg);
851 * @brief Hack -- clear the screen
853 * Make this more efficient
855 static errr term_xtra_win_clear(void)
857 term_data *td = (term_data *)(Term->data);
860 GetClientRect(td->w, &rc);
862 HDC hdc = GetDC(td->w);
863 SetBkColor(hdc, RGB(0, 0, 0));
864 SelectObject(hdc, td->font_id);
865 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
867 if (current_bg_mode != bg_mode::BG_NONE) {
873 ReleaseDC(td->w, hdc);
878 * @brief Hack -- make a noise
880 static errr term_xtra_win_noise(void)
882 MessageBeep(MB_ICONASTERISK);
887 * @brief Hack -- make a sound
889 static errr term_xtra_win_sound(int v)
893 return play_sound(v);
897 * @brief Hack -- play a music
899 static errr term_xtra_win_music(int n, int v)
905 return main_win_music::play_music(n, v);
909 * @brief Hack -- play a music matches a situation
911 static errr term_xtra_win_scene(int v)
918 return main_win_music::play_music_scene(v);
922 * @brief Delay for "x" milliseconds
924 static int term_xtra_win_delay(int v)
931 * @brief Do a "special thing"
932 * @todo z-termに影響があるのでplayer_typeの追加は保留
934 static errr term_xtra_win(int n, int v)
937 case TERM_XTRA_NOISE: {
938 return (term_xtra_win_noise());
940 case TERM_XTRA_MUSIC_BASIC:
941 case TERM_XTRA_MUSIC_DUNGEON:
942 case TERM_XTRA_MUSIC_QUEST:
943 case TERM_XTRA_MUSIC_TOWN:
944 case TERM_XTRA_MUSIC_MONSTER: {
945 return term_xtra_win_music(n, v);
947 case TERM_XTRA_MUSIC_MUTE: {
948 return main_win_music::stop_music();
950 case TERM_XTRA_SCENE: {
951 return term_xtra_win_scene(v);
953 case TERM_XTRA_SOUND: {
954 return (term_xtra_win_sound(v));
956 case TERM_XTRA_BORED: {
957 return (term_xtra_win_event(0));
959 case TERM_XTRA_EVENT: {
960 return (term_xtra_win_event(v));
962 case TERM_XTRA_FLUSH: {
963 return (term_xtra_win_flush());
965 case TERM_XTRA_CLEAR: {
966 return (term_xtra_win_clear());
968 case TERM_XTRA_REACT: {
969 return (term_xtra_win_react(p_ptr));
971 case TERM_XTRA_DELAY: {
972 return (term_xtra_win_delay(v));
980 * @brief Low level graphics (Assumes valid input).
982 * Draw a "cursor" at (x,y), using a "yellow box".
984 static errr term_curs_win(int x, int y)
986 term_data *td = (term_data *)(Term->data);
987 int tile_wid, tile_hgt;
988 tile_wid = td->tile_wid;
989 tile_hgt = td->tile_hgt;
992 rc.left = x * tile_wid + td->size_ow1;
993 rc.right = rc.left + tile_wid;
994 rc.top = y * tile_hgt + td->size_oh1;
995 rc.bottom = rc.top + tile_hgt;
997 HDC hdc = GetDC(td->w);
998 FrameRect(hdc, &rc, hbrYellow);
999 ReleaseDC(td->w, hdc);
1004 * @brief Low level graphics (Assumes valid input).
1006 * Draw a "big cursor" at (x,y), using a "yellow box".
1008 static errr term_bigcurs_win(int x, int y)
1010 term_data *td = (term_data *)(Term->data);
1011 int tile_wid, tile_hgt;
1012 tile_wid = td->tile_wid;
1013 tile_hgt = td->tile_hgt;
1016 rc.left = x * tile_wid + td->size_ow1;
1017 rc.right = rc.left + 2 * tile_wid;
1018 rc.top = y * tile_hgt + td->size_oh1;
1019 rc.bottom = rc.top + tile_hgt;
1021 HDC hdc = GetDC(td->w);
1022 FrameRect(hdc, &rc, hbrYellow);
1023 ReleaseDC(td->w, hdc);
1028 * @brief Low level graphics (Assumes valid input).
1030 * Erase a "block" of "n" characters starting at (x,y).
1032 static errr term_wipe_win(int x, int y, int n)
1034 term_data *td = (term_data *)(Term->data);
1036 rc.left = x * td->tile_wid + td->size_ow1;
1037 rc.right = rc.left + n * td->tile_wid;
1038 rc.top = y * td->tile_hgt + td->size_oh1;
1039 rc.bottom = rc.top + td->tile_hgt;
1041 HDC hdc = GetDC(td->w);
1042 SetBkColor(hdc, RGB(0, 0, 0));
1043 SelectObject(hdc, td->font_id);
1044 if (current_bg_mode != bg_mode::BG_NONE)
1047 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1049 ReleaseDC(td->w, hdc);
1054 * @brief Low level graphics. Assumes valid input.
1056 * Draw several ("n") chars, with an attr, at a given location.
1058 * All "graphic" data is handled by "term_pict_win()", below.
1060 * One would think there is a more efficient method for telling a window
1061 * what color it should be using to draw with, but perhaps simply changing
1062 * it every time is not too inefficient.
1064 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
1066 term_data *td = (term_data *)(Term->data);
1067 static HBITMAP WALL;
1068 static HBRUSH myBrush, oldBrush;
1070 static bool init_done = FALSE;
1073 WALL = LoadBitmap(hInstance, AppName);
1074 myBrush = CreatePatternBrush(WALL);
1078 RECT rc{ static_cast<LONG>(x * td->tile_wid + td->size_ow1), static_cast<LONG>(y * td->tile_hgt + td->size_oh1),
1079 static_cast<LONG>(rc.left + n * td->tile_wid), static_cast<LONG>(rc.top + td->tile_hgt) };
1081 HDC hdc = GetDC(td->w);
1082 SetBkColor(hdc, RGB(0, 0, 0));
1083 SetTextColor(hdc, win_clr[a]);
1085 SelectObject(hdc, td->font_id);
1086 if (current_bg_mode != bg_mode::BG_NONE)
1087 SetBkMode(hdc, TRANSPARENT);
1089 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1090 if (current_bg_mode != bg_mode::BG_NONE)
1093 rc.left += ((td->tile_wid - td->font_wid) / 2);
1094 rc.right = rc.left + td->font_wid;
1095 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
1096 rc.bottom = rc.top + td->font_hgt;
1098 for (int i = 0; i < n; i++) {
1100 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1]) {
1101 rc.right += td->font_wid;
1102 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1103 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1104 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1105 SelectObject(hdc, oldBrush);
1106 SelectObject(hdc, oldPen);
1107 rc.right -= td->font_wid;
1109 rc.left += 2 * td->tile_wid;
1110 rc.right += 2 * td->tile_wid;
1111 } else if (iskanji(*(s + i))) /* 2バイト文字 */
1113 rc.right += td->font_wid;
1114 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 2, NULL);
1115 rc.right -= td->font_wid;
1117 rc.left += 2 * td->tile_wid;
1118 rc.right += 2 * td->tile_wid;
1119 } else if (*(s + i) == 127) {
1120 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1121 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1122 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1123 SelectObject(hdc, oldBrush);
1124 SelectObject(hdc, oldPen);
1125 rc.left += td->tile_wid;
1126 rc.right += td->tile_wid;
1128 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1129 rc.left += td->tile_wid;
1130 rc.right += td->tile_wid;
1133 if (*(s + i) == 127) {
1134 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1135 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1136 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1137 SelectObject(hdc, oldBrush);
1138 SelectObject(hdc, oldPen);
1139 rc.left += td->tile_wid;
1140 rc.right += td->tile_wid;
1142 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1143 rc.left += td->tile_wid;
1144 rc.right += td->tile_wid;
1149 ReleaseDC(td->w, hdc);
1154 * @brief Low level graphics. Assumes valid input.
1156 * Draw an array of "special" attr/char pairs at the given location.
1158 * We use the "term_pict_win()" function for "graphic" data, which are
1159 * encoded by setting the "high-bits" of both the "attr" and the "char"
1160 * data. We use the "attr" to represent the "row" of the main bitmap,
1161 * and the "char" to represent the "col" of the main bitmap. The use
1162 * of this function is induced by the "higher_pict" flag.
1164 * If "graphics" is not available, we simply "wipe" the given grids.
1166 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)
1168 term_data *td = (term_data *)(Term->data);
1171 if (!use_graphics) {
1172 return (term_wipe_win(x, y, n));
1175 const tile_info &infGraph = graphic.get_tile_info();
1176 const bool has_mask = (infGraph.hBitmapMask != NULL);
1177 TERM_LEN w1 = infGraph.CellWidth;
1178 TERM_LEN h1 = infGraph.CellHeight;
1179 TERM_LEN tw1 = infGraph.TileWidth;
1180 TERM_LEN th1 = infGraph.TileHeight;
1181 TERM_LEN w2, h2, tw2 = 0;
1188 TERM_LEN x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
1189 TERM_LEN y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
1190 HDC hdc = GetDC(td->w);
1191 HDC hdcSrc = CreateCompatibleDC(hdc);
1192 HBITMAP hbmSrcOld = static_cast<HBITMAP>(SelectObject(hdcSrc, infGraph.hBitmap));
1195 hdcMask = CreateCompatibleDC(hdc);
1196 SelectObject(hdcMask, infGraph.hBitmapMask);
1199 for (i = 0; i < n; i++, x2 += w2) {
1200 TERM_COLOR a = ap[i];
1202 int row = (a & 0x7F);
1203 int col = (c & 0x7F);
1204 TERM_LEN x1 = col * w1;
1205 TERM_LEN y1 = row * h1;
1208 TERM_LEN x3 = (tcp[i] & 0x7F) * w1;
1209 TERM_LEN y3 = (tap[i] & 0x7F) * h1;
1210 tw2 = tw2 * w1 / tw1;
1212 if ((tw1 == tw2) && (th1 == h2)) {
1213 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
1214 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
1215 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
1219 SetStretchBltMode(hdc, COLORONCOLOR);
1220 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
1221 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
1222 if ((x1 != x3) || (y1 != y3)) {
1223 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
1224 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
1230 if ((w1 == tw2) && (h1 == h2)) {
1231 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
1235 SetStretchBltMode(hdc, COLORONCOLOR);
1236 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
1239 SelectObject(hdcSrc, hbmSrcOld);
1242 SelectObject(hdcMask, hbmSrcOld);
1246 ReleaseDC(td->w, hdc);
1251 * @brief Create and initialize a "term_data" given a title
1253 static void term_data_link(term_data *td)
1255 term_type *t = &td->t;
1256 term_init(t, td->cols, td->rows, FILE_READ_BUFF_SIZE);
1257 t->soft_cursor = TRUE;
1258 t->higher_pict = TRUE;
1259 t->attr_blank = TERM_WHITE;
1260 t->char_blank = ' ';
1261 t->user_hook = term_user_win;
1262 t->xtra_hook = term_xtra_win;
1263 t->curs_hook = term_curs_win;
1264 t->bigcurs_hook = term_bigcurs_win;
1265 t->wipe_hook = term_wipe_win;
1266 t->text_hook = term_text_win;
1267 t->pict_hook = term_pict_win;
1268 t->data = (vptr)(td);
1272 * @brief Create the windows
1274 * First, instantiate the "default" values, then read the "ini_file"
1275 * to over-ride selected values, then create the windows, and fonts.
1277 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
1278 * must make active to realize the palette.
1280 static void init_windows(void)
1284 WIPE(td, term_data);
1288 td->s = angband_term_name[0];
1303 for (int i = 1; i < MAX_TERM_DATA; i++) {
1305 WIPE(td, term_data);
1306 td->s = angband_term_name[i];
1310 td->visible = FALSE;
1315 td->pos_x = (7 - i) * 30;
1316 td->pos_y = (7 - i) * 20;
1322 /* Atrributes of main window */
1324 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_VISIBLE);
1328 /* Attributes of sub windows */
1329 for (int i = 1; i < MAX_TERM_DATA; i++) {
1331 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
1332 td->dwExStyle = (WS_EX_TOOLWINDOW);
1335 /* Font of each window */
1336 for (int i = 0; i < MAX_TERM_DATA; i++) {
1338 wcsncpy(td->lf.lfFaceName, to_wchar(td->font_want).wc_str(), LF_FACESIZE);
1339 td->lf.lfCharSet = _(SHIFTJIS_CHARSET, DEFAULT_CHARSET);
1340 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
1341 term_force_font(td);
1343 td->tile_wid = td->font_wid;
1345 td->tile_hgt = td->font_hgt;
1347 term_window_resize(td);
1350 /* Create sub windows */
1351 for (int i = MAX_TERM_DATA - 1; i >= 1; --i) {
1356 = CreateWindowEx(td->dwExStyle, AngList, td->s, td->dwStyle, td->pos_x, td->pos_y, td->size_wid, td->size_hgt, HWND_DESKTOP, NULL, hInstance, NULL);
1360 quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
1362 td->size_hack = TRUE;
1364 term_window_resize(td);
1367 ShowWindow(td->w, SW_SHOW);
1369 td->size_hack = FALSE;
1372 angband_term[i] = &td->t;
1375 /* Activate the window */
1376 SetActiveWindow(td->w);
1380 term_window_pos(td, HWND_TOPMOST);
1382 term_window_pos(td, td->w);
1386 /* Create main window */
1389 td->w = CreateWindowEx(td->dwExStyle, AppName, td->s, td->dwStyle, td->pos_x, td->pos_y, td->size_wid, td->size_hgt, HWND_DESKTOP, NULL, hInstance, NULL);
1393 quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
1396 td->size_hack = TRUE;
1398 term_window_resize(td);
1399 td->size_hack = FALSE;
1402 angband_term[0] = &td->t;
1403 normsize.x = td->cols;
1404 normsize.y = td->rows;
1407 ShowWindow(td->w, SW_SHOWMAXIMIZED);
1409 ShowWindow(td->w, SW_SHOW);
1411 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
1412 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
1413 (void)term_xtra_win_flush();
1417 * @brief Prepare the menus
1419 static void setup_menus(void)
1421 HMENU hm = GetMenu(data[0].w);
1423 if (current_world_ptr->character_generated) {
1424 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1425 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1426 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_ENABLED);
1428 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
1429 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
1430 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1433 for (int i = 0; i < MAX_TERM_DATA; i++) {
1434 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1435 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i, (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
1436 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_ENABLED);
1439 for (int i = 0; i < MAX_TERM_DATA; i++) {
1440 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1442 if (data[i].visible) {
1443 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1447 for (int i = 0; i < MAX_TERM_DATA; i++) {
1448 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1449 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i, (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
1450 if (data[i].visible) {
1451 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_ENABLED);
1455 for (int i = 0; i < MAX_TERM_DATA; i++) {
1456 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1457 if (data[i].visible) {
1458 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
1462 for (int i = 0; i < MAX_TERM_DATA; i++) {
1463 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1464 if (data[i].visible) {
1465 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
1469 for (int i = 0; i < MAX_TERM_DATA; i++) {
1470 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1471 if (data[i].visible) {
1472 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1476 for (int i = 0; i < MAX_TERM_DATA; i++) {
1477 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1479 if (data[i].visible) {
1480 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1483 CheckMenuItem(hm, IDM_WINDOW_KEEP_SUBWINDOWS, (keep_subwindows ? MF_CHECKED : MF_UNCHECKED));
1485 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, (arg_graphics == static_cast<byte>(graphics_mode::GRAPHICS_NONE) ? MF_CHECKED : MF_UNCHECKED));
1486 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, (arg_graphics == static_cast<byte>(graphics_mode::GRAPHICS_ORIGINAL) ? MF_CHECKED : MF_UNCHECKED));
1487 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, (arg_graphics == static_cast<byte>(graphics_mode::GRAPHICS_ADAM_BOLT) ? MF_CHECKED : MF_UNCHECKED));
1488 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS, (arg_graphics == static_cast<byte>(graphics_mode::GRAPHICS_HENGBAND) ? MF_CHECKED : MF_UNCHECKED));
1489 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE, (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
1490 CheckMenuItem(hm, IDM_OPTIONS_MUSIC, (arg_music ? MF_CHECKED : MF_UNCHECKED));
1491 CheckMenuItem(hm, IDM_OPTIONS_MUSIC_PAUSE_INACTIVE, (use_pause_music_inactive ? MF_CHECKED : MF_UNCHECKED));
1492 CheckMenuItem(hm, IDM_OPTIONS_SOUND, (arg_sound ? MF_CHECKED : MF_UNCHECKED));
1493 CheckMenuItem(hm, IDM_OPTIONS_NO_BG, ((current_bg_mode == bg_mode::BG_NONE) ? MF_CHECKED : MF_UNCHECKED));
1494 CheckMenuItem(hm, IDM_OPTIONS_BG, ((current_bg_mode == bg_mode::BG_ONE) ? MF_CHECKED : MF_UNCHECKED));
1495 CheckMenuItem(hm, IDM_OPTIONS_PRESET_BG, ((current_bg_mode == bg_mode::BG_PRESET) ? MF_CHECKED : MF_UNCHECKED));
1496 // TODO IDM_OPTIONS_PRESET_BG を有効にする
1497 EnableMenuItem(hm, IDM_OPTIONS_PRESET_BG, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1501 * @brief Check for double clicked (or dragged) savefile
1503 * Apparently, Windows copies the entire filename into the first
1504 * piece of the "command line string". Perhaps we should extract
1505 * the "basename" of that filename and append it to the "save" dir.
1506 * @param player_ptr pointer of player_type
1507 * @param savefile_option savefile path
1509 static void check_for_save_file(player_type *player_ptr, const std::string &savefile_option)
1511 if (savefile_option.empty())
1514 strcpy(savefile, savefile_option.c_str());
1515 validate_file(savefile);
1516 game_in_progress = TRUE;
1517 play_game(player_ptr, FALSE, FALSE);
1521 * @brief Process a menu command
1523 static void process_menus(player_type *player_ptr, WORD wCmd)
1526 plog(_("まだ初期化中です...", "You cannot do that yet..."));
1533 case IDM_FILE_NEW: {
1534 if (game_in_progress) {
1535 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
1537 game_in_progress = TRUE;
1539 strcpy(savefile, "");
1540 play_game(player_ptr, TRUE, FALSE);
1546 case IDM_FILE_OPEN: {
1547 if (game_in_progress) {
1548 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
1550 memset(&ofn, 0, sizeof(ofn));
1551 ofn.lStructSize = sizeof(ofn);
1552 ofn.hwndOwner = data[0].w;
1553 ofn.lpstrFilter = L"Save Files (*.)\0*\0";
1554 ofn.nFilterIndex = 1;
1555 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
1557 if (get_open_filename(&ofn, ANGBAND_DIR_SAVE, savefile, MAIN_WIN_MAX_PATH)) {
1558 validate_file(savefile);
1559 game_in_progress = TRUE;
1561 play_game(player_ptr, FALSE, FALSE);
1568 case IDM_FILE_SAVE: {
1569 if (game_in_progress && current_world_ptr->character_generated) {
1571 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
1576 do_cmd_save_game(player_ptr, FALSE);
1578 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
1583 case IDM_FILE_EXIT: {
1584 if (game_in_progress && current_world_ptr->character_generated) {
1586 plog(_("今は終了できません。", "You may not do that right now."));
1591 forget_lite(player_ptr->current_floor_ptr);
1592 forget_view(player_ptr->current_floor_ptr);
1593 clear_mon_lite(player_ptr->current_floor_ptr);
1595 term_key_push(SPECIAL_KEY_QUIT);
1602 case IDM_FILE_SCORE: {
1604 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
1605 highscore_fd = fd_open(buf, O_RDONLY);
1606 if (highscore_fd < 0) {
1607 msg_print("Score file unavailable.");
1611 display_scores(0, MAX_HISCORES, -1, NULL);
1612 (void)fd_close(highscore_fd);
1620 case IDM_FILE_MOVIE: {
1621 if (game_in_progress) {
1622 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
1624 memset(&ofn, 0, sizeof(ofn));
1625 ofn.lStructSize = sizeof(ofn);
1626 ofn.hwndOwner = data[0].w;
1627 ofn.lpstrFilter = L"Angband Movie Files (*.amv)\0*.amv\0";
1628 ofn.nFilterIndex = 1;
1629 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1631 if (get_open_filename(&ofn, ANGBAND_DIR_USER, savefile, MAIN_WIN_MAX_PATH)) {
1632 prepare_browse_movie_without_path_build(savefile);
1633 play_game(player_ptr, FALSE, TRUE);
1641 case IDM_WINDOW_VIS_0: {
1642 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
1645 case IDM_WINDOW_VIS_1:
1646 case IDM_WINDOW_VIS_2:
1647 case IDM_WINDOW_VIS_3:
1648 case IDM_WINDOW_VIS_4:
1649 case IDM_WINDOW_VIS_5:
1650 case IDM_WINDOW_VIS_6:
1651 case IDM_WINDOW_VIS_7: {
1652 int i = wCmd - IDM_WINDOW_VIS_0;
1653 if ((i < 0) || (i >= MAX_TERM_DATA))
1659 ShowWindow(td->w, SW_SHOW);
1660 term_data_redraw(td);
1662 td->visible = FALSE;
1664 ShowWindow(td->w, SW_HIDE);
1669 case IDM_WINDOW_FONT_0:
1670 case IDM_WINDOW_FONT_1:
1671 case IDM_WINDOW_FONT_2:
1672 case IDM_WINDOW_FONT_3:
1673 case IDM_WINDOW_FONT_4:
1674 case IDM_WINDOW_FONT_5:
1675 case IDM_WINDOW_FONT_6:
1676 case IDM_WINDOW_FONT_7: {
1677 int i = wCmd - IDM_WINDOW_FONT_0;
1678 if ((i < 0) || (i >= MAX_TERM_DATA))
1682 term_change_font(td);
1685 case IDM_WINDOW_POS_1:
1686 case IDM_WINDOW_POS_2:
1687 case IDM_WINDOW_POS_3:
1688 case IDM_WINDOW_POS_4:
1689 case IDM_WINDOW_POS_5:
1690 case IDM_WINDOW_POS_6:
1691 case IDM_WINDOW_POS_7: {
1692 int i = wCmd - IDM_WINDOW_POS_0;
1693 if ((i < 0) || (i >= MAX_TERM_DATA))
1697 if (!td->posfix && td->visible) {
1699 term_window_pos(td, HWND_TOPMOST);
1702 term_window_pos(td, data[0].w);
1707 case IDM_WINDOW_I_WID_0:
1708 case IDM_WINDOW_I_WID_1:
1709 case IDM_WINDOW_I_WID_2:
1710 case IDM_WINDOW_I_WID_3:
1711 case IDM_WINDOW_I_WID_4:
1712 case IDM_WINDOW_I_WID_5:
1713 case IDM_WINDOW_I_WID_6:
1714 case IDM_WINDOW_I_WID_7: {
1715 int i = wCmd - IDM_WINDOW_I_WID_0;
1716 if ((i < 0) || (i >= MAX_TERM_DATA))
1722 term_window_resize(td);
1725 case IDM_WINDOW_D_WID_0:
1726 case IDM_WINDOW_D_WID_1:
1727 case IDM_WINDOW_D_WID_2:
1728 case IDM_WINDOW_D_WID_3:
1729 case IDM_WINDOW_D_WID_4:
1730 case IDM_WINDOW_D_WID_5:
1731 case IDM_WINDOW_D_WID_6:
1732 case IDM_WINDOW_D_WID_7: {
1733 int i = wCmd - IDM_WINDOW_D_WID_0;
1734 if ((i < 0) || (i >= MAX_TERM_DATA))
1740 term_window_resize(td);
1743 case IDM_WINDOW_I_HGT_0:
1744 case IDM_WINDOW_I_HGT_1:
1745 case IDM_WINDOW_I_HGT_2:
1746 case IDM_WINDOW_I_HGT_3:
1747 case IDM_WINDOW_I_HGT_4:
1748 case IDM_WINDOW_I_HGT_5:
1749 case IDM_WINDOW_I_HGT_6:
1750 case IDM_WINDOW_I_HGT_7: {
1751 int i = wCmd - IDM_WINDOW_I_HGT_0;
1752 if ((i < 0) || (i >= MAX_TERM_DATA))
1758 term_window_resize(td);
1761 case IDM_WINDOW_D_HGT_0:
1762 case IDM_WINDOW_D_HGT_1:
1763 case IDM_WINDOW_D_HGT_2:
1764 case IDM_WINDOW_D_HGT_3:
1765 case IDM_WINDOW_D_HGT_4:
1766 case IDM_WINDOW_D_HGT_5:
1767 case IDM_WINDOW_D_HGT_6:
1768 case IDM_WINDOW_D_HGT_7: {
1769 int i = wCmd - IDM_WINDOW_D_HGT_0;
1770 if ((i < 0) || (i >= MAX_TERM_DATA))
1776 term_window_resize(td);
1779 case IDM_WINDOW_KEEP_SUBWINDOWS: {
1780 keep_subwindows = !keep_subwindows;
1783 case IDM_OPTIONS_NO_GRAPHICS: {
1784 if (arg_graphics != static_cast<byte>(graphics_mode::GRAPHICS_NONE)) {
1785 arg_graphics = static_cast<byte>(graphics_mode::GRAPHICS_NONE);
1786 if (game_in_progress)
1787 do_cmd_redraw(player_ptr);
1791 case IDM_OPTIONS_OLD_GRAPHICS: {
1792 if (arg_graphics != static_cast<byte>(graphics_mode::GRAPHICS_ORIGINAL)) {
1793 arg_graphics = static_cast<byte>(graphics_mode::GRAPHICS_ORIGINAL);
1794 if (game_in_progress)
1795 do_cmd_redraw(player_ptr);
1800 case IDM_OPTIONS_NEW_GRAPHICS: {
1801 if (arg_graphics != static_cast<byte>(graphics_mode::GRAPHICS_ADAM_BOLT)) {
1802 arg_graphics = static_cast<byte>(graphics_mode::GRAPHICS_ADAM_BOLT);
1803 if (game_in_progress)
1804 do_cmd_redraw(player_ptr);
1809 case IDM_OPTIONS_NEW2_GRAPHICS: {
1810 if (arg_graphics != static_cast<byte>(graphics_mode::GRAPHICS_HENGBAND)) {
1811 arg_graphics = static_cast<byte>(graphics_mode::GRAPHICS_HENGBAND);
1812 if (game_in_progress)
1813 do_cmd_redraw(player_ptr);
1818 case IDM_OPTIONS_BIGTILE: {
1820 arg_bigtile = !arg_bigtile;
1821 term_activate(&td->t);
1822 term_resize(td->cols, td->rows);
1823 InvalidateRect(td->w, NULL, TRUE);
1826 case IDM_OPTIONS_MUSIC: {
1827 arg_music = !arg_music;
1828 use_music = arg_music;
1831 if (game_in_progress)
1832 select_floor_music(player_ptr);
1834 main_win_music::stop_music();
1838 case IDM_OPTIONS_MUSIC_PAUSE_INACTIVE: {
1839 use_pause_music_inactive = !use_pause_music_inactive;
1842 case IDM_OPTIONS_OPEN_MUSIC_DIR: {
1843 std::vector<char> buf(MAIN_WIN_MAX_PATH);
1844 path_build(&buf[0], MAIN_WIN_MAX_PATH, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1845 open_dir_in_explorer(&buf[0]);
1848 case IDM_OPTIONS_SOUND: {
1849 arg_sound = !arg_sound;
1850 change_sound_mode(arg_sound);
1853 case IDM_OPTIONS_OPEN_SOUND_DIR: {
1854 std::vector<char> buf(MAIN_WIN_MAX_PATH);
1855 path_build(&buf[0], MAIN_WIN_MAX_PATH, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1856 open_dir_in_explorer(&buf[0]);
1859 case IDM_OPTIONS_NO_BG: {
1860 change_bg_mode(bg_mode::BG_NONE);
1863 case IDM_OPTIONS_PRESET_BG: {
1864 change_bg_mode(bg_mode::BG_PRESET);
1867 case IDM_OPTIONS_BG: {
1868 if (change_bg_mode(bg_mode::BG_ONE))
1870 // 壁紙の設定に失敗した(ファイルが存在しない等)場合、壁紙に使うファイルを選択させる
1872 [[fallthrough]]; /* Fall through */
1873 case IDM_OPTIONS_OPEN_BG: {
1874 memset(&ofn, 0, sizeof(ofn));
1875 ofn.lStructSize = sizeof(ofn);
1876 ofn.hwndOwner = data[0].w;
1877 ofn.lpstrFilter = L"Image Files (*.bmp;*.png;*.jpg;*.jpeg;)\0*.bmp;*.png;*.jpg;*.jpeg;\0";
1878 ofn.nFilterIndex = 1;
1879 ofn.lpstrTitle = _(L"壁紙を選んでね。", L"Choose wall paper.");
1880 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
1882 if (get_open_filename(&ofn, NULL, wallpaper_file, MAIN_WIN_MAX_PATH)) {
1883 change_bg_mode(bg_mode::BG_ONE, true, true);
1887 case IDM_DUMP_SCREEN_HTML: {
1888 save_screen_as_html(data[0].w);
1895 * @brief Add a keypress to the "queue"
1897 static errr term_keypress(int k)
1899 /* Refuse to enqueue non-keys */
1903 /* Store the char, advance the queue */
1904 Term->key_queue[Term->key_head++] = (char)k;
1906 /* Circular queue, handle wrap */
1907 if (Term->key_head == Term->key_size)
1910 if (Term->key_head != Term->key_tail)
1919 static bool process_keydown(WPARAM wParam, LPARAM lParam)
1925 if (GetKeyState(VK_CONTROL) & 0x8000)
1927 if (GetKeyState(VK_SHIFT) & 0x8000)
1929 if (GetKeyState(VK_MENU) & 0x8000)
1932 term_no_press = (ma) ? TRUE : FALSE;
1933 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)])) {
1934 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
1935 bool numpad = FALSE;
1945 int i = LOBYTE(HIWORD(lParam));
1949 term_no_press = TRUE;
1950 [[fallthrough]]; /* Fall through */
1969 term_no_press = TRUE;
1970 [[fallthrough]]; /* Fall through */
1988 term_keypress(hexsym[i / 16]);
1989 term_keypress(hexsym[i % 16]);
1999 * @brief ウィンドウのアクティブ/非アクティブのハンドラ
2001 static void handle_app_active(HWND hWnd, UINT uMsg, WPARAM wParam, [[maybe_unused]] LPARAM lParam)
2004 case WM_ACTIVATEAPP: {
2006 if (use_pause_music_inactive)
2007 main_win_music::resume_music();
2009 if (use_pause_music_inactive)
2010 main_win_music::pause_music();
2014 case WM_WINDOWPOSCHANGING: {
2015 if (!IsIconic(hWnd))
2016 if (use_pause_music_inactive)
2017 main_win_music::resume_music();
2024 * @brief メインウインドウ用ウインドウプロシージャ
2026 LRESULT PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2030 td = (term_data *)GetWindowLong(hWnd, 0);
2032 handle_app_active(hWnd, uMsg, wParam, lParam);
2036 SetWindowLong(hWnd, 0, (LONG)(my_td));
2043 case WM_GETMINMAXINFO: {
2047 lpmmi = (MINMAXINFO *)lParam;
2051 rc.left = rc.top = 0;
2052 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
2053 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
2055 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
2057 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
2058 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
2062 case WM_ERASEBKGND: {
2066 BeginPaint(hWnd, &ps);
2068 term_data_redraw(td);
2069 EndPaint(hWnd, &ps);
2070 ValidateRect(hWnd, NULL);
2073 case MM_MCINOTIFY: {
2074 main_win_music::on_mci_notify(wParam, lParam);
2080 if (process_keydown(wParam, lParam))
2086 term_no_press = FALSE;
2088 term_keypress(wParam);
2091 case WM_LBUTTONDOWN: {
2092 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
2093 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
2099 case WM_LBUTTONUP: {
2102 TERM_LEN dx = abs(oldx - mousex) + 1;
2103 TERM_LEN dy = abs(oldy - mousey) + 1;
2104 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
2105 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
2111 int sz = (dx + 3) * dy;
2113 int sz = (dx + 2) * dy;
2115 hGlobal = GlobalAlloc(GHND, sz + 1);
2116 if (hGlobal == NULL)
2118 lpStr = (LPSTR)GlobalLock(hGlobal);
2120 for (int i = 0; i < dy; i++) {
2123 const auto &scr = data[0].t.scr->c;
2125 C_MAKE(s, (dx + 1), char);
2126 strncpy(s, &scr[oy + i][ox], dx);
2129 if (iskanji(scr[oy + i][ox - 1]))
2133 if (ox + dx < data[0].cols) {
2134 if (iskanji(scr[oy + i][ox + dx - 1]))
2138 for (int j = 0; j < dx; j++) {
2144 for (int j = 0; j < dx; j++) {
2145 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
2154 GlobalUnlock(hGlobal);
2155 if (OpenClipboard(hWnd) == 0) {
2156 GlobalFree(hGlobal);
2161 SetClipboardData(CF_TEXT, hGlobal);
2166 case WM_MOUSEMOVE: {
2171 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
2172 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
2176 dx = abs(oldx - mousex) + 1;
2177 dy = abs(oldy - mousey) + 1;
2178 ox = (oldx > mousex) ? mousex : oldx;
2179 oy = (oldy > mousey) ? mousey : oldy;
2180 term_inversed_area(hWnd, ox, oy, dx, dy);
2185 dx = abs(cx - mousex) + 1;
2186 dy = abs(cy - mousey) + 1;
2187 ox = (cx > mousex) ? mousex : cx;
2188 oy = (cy > mousey) ? mousey : cy;
2189 term_inversed_area(hWnd, ox, oy, dx, dy);
2200 if (!game_in_progress || !current_world_ptr->character_generated) {
2206 plog(_("今は終了できません。", "You may not do that right now."));
2211 forget_lite(p_ptr->current_floor_ptr);
2212 forget_view(p_ptr->current_floor_ptr);
2213 clear_mon_lite(p_ptr->current_floor_ptr);
2214 term_key_push(SPECIAL_KEY_QUIT);
2217 case WM_QUERYENDSESSION: {
2218 if (!game_in_progress || !current_world_ptr->character_generated) {
2225 p_ptr->is_dead = FALSE;
2226 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
2228 p_ptr->panic_save = 1;
2229 signals_ignore_tstp();
2230 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
2231 (void)save_player(p_ptr, SAVE_TYPE_CLOSE_GAME);
2240 process_menus(p_ptr, LOWORD(wParam));
2251 //!< @todo 二重のswitch文。後で分割する.
2253 case SIZE_MINIMIZED: {
2254 for (int i = 1; i < MAX_TERM_DATA; i++) {
2255 if (data[i].visible)
2256 ShowWindow(data[i].w, SW_HIDE);
2261 case SIZE_MAXIMIZED:
2262 case SIZE_RESTORED: {
2263 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1 - td->size_ow2) / td->tile_wid;
2264 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1 - td->size_oh2) / td->tile_hgt;
2265 if ((td->cols != cols) || (td->rows != rows)) {
2268 if (!IsZoomed(td->w) && !IsIconic(td->w)) {
2269 normsize.x = td->cols;
2270 normsize.y = td->rows;
2273 term_activate(&td->t);
2274 term_resize(td->cols, td->rows);
2275 InvalidateRect(td->w, NULL, TRUE);
2278 td->size_hack = TRUE;
2279 for (int i = 1; i < MAX_TERM_DATA; i++) {
2280 if (data[i].visible)
2281 ShowWindow(data[i].w, SW_SHOWNA);
2284 td->size_hack = FALSE;
2293 if (!wParam || HIWORD(lParam))
2296 for (int i = 1; i < MAX_TERM_DATA; i++) {
2297 if (!data[i].posfix)
2298 term_window_pos(&data[i], hWnd);
2304 case WM_ACTIVATEAPP: {
2305 if (IsIconic(td->w))
2308 for (int i = 1; i < MAX_TERM_DATA; i++) {
2309 if (data[i].visible) {
2310 if (wParam == TRUE) {
2311 ShowWindow(data[i].w, SW_SHOWNA);
2313 ShowWindow(data[i].w, SW_HIDE);
2318 [[fallthrough]]; /* Fall through */
2320 if (wParam == FALSE && keep_subwindows) {
2321 for (int i = 1; i < MAX_TERM_DATA; i++) {
2322 if (data[i].visible) {
2323 ShowWindow(data[i].w, SW_SHOWNA);
2330 return DefWindowProc(hWnd, uMsg, wParam, lParam);
2334 * @brief サブウインドウ用ウインドウプロシージャ
2336 LRESULT PASCAL AngbandListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2340 td = (term_data *)GetWindowLong(hWnd, 0);
2344 SetWindowLong(hWnd, 0, (LONG)(my_td));
2350 case WM_GETMINMAXINFO: {
2354 lpmmi = (MINMAXINFO *)lParam;
2358 rc.left = rc.top = 0;
2359 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
2360 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
2362 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
2363 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
2364 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
2375 td->size_hack = TRUE;
2377 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1 - td->size_ow2) / td->tile_wid;
2378 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1 - td->size_oh2) / td->tile_hgt;
2379 if ((td->cols != cols) || (td->rows != rows)) {
2380 term_type *old_term = Term;
2383 term_activate(&td->t);
2384 term_resize(td->cols, td->rows);
2385 term_activate(old_term);
2386 InvalidateRect(td->w, NULL, TRUE);
2387 p_ptr->window_flags = 0xFFFFFFFF;
2388 handle_stuff(p_ptr);
2391 td->size_hack = FALSE;
2394 case WM_ERASEBKGND: {
2398 BeginPaint(hWnd, &ps);
2400 term_data_redraw(td);
2401 EndPaint(hWnd, &ps);
2406 if (process_keydown(wParam, lParam))
2413 term_no_press = FALSE;
2415 term_keypress(wParam);
2418 case WM_NCLBUTTONDOWN: {
2419 if (wParam == HTCLOSE)
2422 if (wParam == HTSYSMENU) {
2424 td->visible = FALSE;
2425 ShowWindow(td->w, SW_HIDE);
2435 return DefWindowProc(hWnd, uMsg, wParam, lParam);
2439 * @brief Display warning message (see "z-util.c")
2441 static void hook_plog(concptr str)
2444 MessageBoxW(data[0].w, to_wchar(str).wc_str(), _(L"警告!", L"Warning"), MB_ICONEXCLAMATION | MB_OK);
2449 * @brief Display error message and quit (see "z-util.c")
2451 static void hook_quit(concptr str)
2454 MessageBoxW(data[0].w, to_wchar(str).wc_str(), _(L"エラー!", L"Error"), MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2458 for (int i = MAX_TERM_DATA - 1; i >= 0; --i) {
2459 term_force_font(&data[i]);
2460 if (data[i].font_want)
2461 string_free(data[i].font_want);
2463 DestroyWindow(data[i].w);
2467 DeleteObject(hbrYellow);
2471 UnregisterClass(AppName, hInstance);
2479 * @brief Init some stuff
2481 static void init_stuff(void)
2483 char path[MAIN_WIN_MAX_PATH];
2484 DWORD path_len = GetModuleFileName(hInstance, path, MAIN_WIN_MAX_PATH);
2485 strcpy(path + path_len - 4, ".INI");
2486 ini_file = string_make(path);
2489 for (; i > 0; i--) {
2490 if (path[i] == '\\') {
2495 strcpy(path + i + 1, "lib\\");
2496 validate_dir(path, TRUE);
2497 init_file_paths(path, path);
2498 validate_dir(ANGBAND_DIR_APEX, FALSE);
2499 validate_dir(ANGBAND_DIR_BONE, FALSE);
2500 if (!check_dir(ANGBAND_DIR_EDIT)) {
2501 validate_dir(ANGBAND_DIR_DATA, TRUE);
2503 validate_dir(ANGBAND_DIR_DATA, FALSE);
2506 validate_dir(ANGBAND_DIR_FILE, TRUE);
2507 validate_dir(ANGBAND_DIR_HELP, FALSE);
2508 validate_dir(ANGBAND_DIR_INFO, FALSE);
2509 validate_dir(ANGBAND_DIR_PREF, TRUE);
2510 validate_dir(ANGBAND_DIR_SAVE, FALSE);
2511 validate_dir(ANGBAND_DIR_DEBUG_SAVE, FALSE);
2512 validate_dir(ANGBAND_DIR_USER, TRUE);
2513 validate_dir(ANGBAND_DIR_XTRA, TRUE);
2514 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
2516 validate_file(path);
2517 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
2518 ANGBAND_DIR_XTRA_GRAF = string_make(path);
2519 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
2521 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
2522 ANGBAND_DIR_XTRA_SOUND = string_make(path);
2523 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
2525 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
2526 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
2527 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
2529 for (i = 0; special_key_list[i]; ++i) {
2530 special_key[special_key_list[i]] = TRUE;
2533 for (i = 0; ignore_key_list[i]; ++i) {
2534 ignore_key[ignore_key_list[i]] = TRUE;
2537 ANGBAND_SYS = "win";
2538 if (7 != GetKeyboardType(0))
2539 ANGBAND_KEYBOARD = "0";
2541 switch (GetKeyboardType(1)) {
2549 ANGBAND_KEYBOARD = "NEC98";
2553 ANGBAND_KEYBOARD = "JAPAN";
2559 * @brief 全スポイラー出力を行う
2560 * Create Spoiler files
2561 * @details スポイラー出力処理の成功、失敗に関わらずプロセスを終了する。
2563 void create_debug_spoiler(void)
2566 init_angband(p_ptr, TRUE);
2568 switch (output_all_spoilers()) {
2569 case spoiler_output_status::SPOILER_OUTPUT_SUCCESS:
2570 fprintf(stdout, "Successfully created a spoiler file.");
2571 case spoiler_output_status::SPOILER_OUTPUT_FAIL_FOPEN:
2572 fprintf(stderr, "Cannot create spoiler file.");
2573 case spoiler_output_status::SPOILER_OUTPUT_FAIL_FCLOSE:
2574 fprintf(stderr, "Cannot close spoiler file.");
2583 * @brief メインウインドウ、サブウインドウのウインドウクラス登録
2585 static void register_wndclass(void)
2588 wc.style = CS_CLASSDC;
2589 wc.lpfnWndProc = AngbandWndProc;
2592 wc.hInstance = hInstance;
2593 wc.hIcon = hIcon = LoadIcon(hInstance, AppName);
2594 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
2595 wc.hbrBackground = NULL;
2596 wc.lpszMenuName = AppName;
2597 wc.lpszClassName = AppName;
2599 if (!RegisterClass(&wc))
2602 wc.lpfnWndProc = AngbandListProc;
2603 wc.lpszMenuName = NULL;
2604 wc.lpszClassName = AngList;
2606 if (!RegisterClass(&wc))
2611 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
2614 _In_ HINSTANCE hInst, [[maybe_unused]] _In_opt_ HINSTANCE hPrevInst, [[maybe_unused]] _In_ LPSTR lpCmdLine, [[maybe_unused]] _In_ int nCmdShow)
2616 setlocale(LC_ALL, "ja_JP");
2618 if (is_already_running()) {
2620 NULL, _(L"変愚蛮怒はすでに起動しています。", L"Hengband is already running."), _(L"エラー!", L"Error"), MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2624 command_line.handle();
2625 register_wndclass();
2627 // before term_data initialize
2628 plog_aux = [](concptr str) {
2630 MessageBoxW(NULL, to_wchar(str).wc_str(), _(L"警告!", L"Warning"), MB_ICONEXCLAMATION | MB_OK);
2632 quit_aux = [](concptr str) {
2634 MessageBoxW(NULL, to_wchar(str).wc_str(), _(L"エラー!", L"Error"), MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2637 UnregisterClass(AppName, hInstance);
2643 core_aux = quit_aux;
2647 HDC hdc = GetDC(NULL);
2648 if (GetDeviceCaps(hdc, BITSPIXEL) <= 8) {
2649 quit(_("画面を16ビット以上のカラーモードにして下さい。", "Please switch to High Color (16-bit) or higher color mode."));
2651 ReleaseDC(NULL, hdc);
2653 refresh_color_table();
2655 change_bg_mode(current_bg_mode, true);
2657 // after term_data initialize
2658 plog_aux = hook_plog;
2659 quit_aux = hook_quit;
2660 core_aux = hook_quit;
2663 term_activate(term_screen);
2664 init_angband(p_ptr, FALSE);
2666 check_for_save_file(p_ptr, command_line.get_savefile_option());
2667 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
2670 change_sound_mode(arg_sound);
2671 use_music = arg_music;
2677 while (GetMessage(&msg, NULL, 0, 0)) {
2678 TranslateMessage(&msg);
2679 DispatchMessage(&msg);
2685 #endif /* WINDOWS */