3 * @brief Windows版固有実装(メインエントリポイント含む)
5 * @author Hengband Team
6 * @todo main関数を含むファイルの割に長過ぎる。main-win-utils.cなどといった形で分割したい
10 * Windows98かその前後の頃を起点としたAPI実装。
12 * DirectXといった昨今描画に標準的となったライブラリも用いていない。
13 * タイルの描画処理などについては、現在動作の詳細を検証中。
17 * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
19 * This software may be copied and distributed for educational, research,
20 * and not for profit purposes provided that this copyright and statement
21 * are included in all such copies.
24 * This file helps Angband work with Windows computers.
26 * To use this file, use an appropriate "Makefile" or "Project File",
27 * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
28 * make sure to obtain various extra files as described below.
30 * The official compilation uses the CodeWarrior Pro compiler, which
31 * includes a special project file and precompilable header file.
35 * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
36 * and/or color redefinitions.
40 * The "lib/user/font-win.prf" contains attr/char mappings for use with the
41 * normal "lib/xtra/font/*.fon" font files.
45 * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
46 * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
51 * Compiling this file, and using the resulting executable, requires
52 * several extra files not distributed with the standard Angband code.
53 * In any case, some "*.fon" files (including "8X13.FON" if nothing else)
54 * must be placed into "lib/xtra/font/". All of these extra files can be found
55 * in the "ext-win" archive.
59 * The "term_xtra_win_clear()" function should probably do a low-level
60 * clear of the current window, and redraw the borders and other things,
61 * if only for efficiency.
65 * A simpler method is needed for selecting the "tile size" for windows.
69 * The various "warning" messages assume the existance of the "screen.w"
70 * window, I think, and only a few calls actually check for its existance,
71 * this may be okay since "NULL" means "on top of all windows". (?) The
72 * user must never be allowed to "hide" the main window, or the "menubar"
77 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
79 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
81 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
82 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
88 #include "autopick/autopick-pref-processor.h"
89 #include "cmd-io/cmd-process-screen.h"
90 #include "cmd-io/cmd-save.h"
91 #include "core/game-play.h"
92 #include "core/player-processor.h"
93 #include "core/scores.h"
94 #include "core/special-internal-keys.h"
95 #include "core/stuff-handler.h"
96 #include "core/visuals-reseter.h"
97 #include "floor/floor-base-definitions.h"
98 #include "floor/floor-events.h"
99 #include "game-option/runtime-arguments.h"
100 #include "game-option/special-options.h"
101 #include "io/files-util.h"
102 #include "io/input-key-acceptor.h"
103 #include "io/record-play-movie.h"
104 #include "io/signal-handlers.h"
105 #include "io/write-diary.h"
106 #include "main-win/main-win-bg.h"
107 #include "main-win/main-win-file-utils.h"
108 #include "main-win/main-win-mci.h"
109 #include "main-win/main-win-menuitem.h"
110 #include "main-win/main-win-music.h"
111 #include "main-win/main-win-sound.h"
112 #include "main/angband-initializer.h"
113 #include "main/sound-of-music.h"
114 #include "monster-floor/monster-lite.h"
115 #include "save/save.h"
116 #include "system/angband-version.h"
117 #include "system/angband.h"
118 #include "system/floor-type-definition.h"
119 #include "system/system-variables.h"
120 #include "term/gameterm.h"
121 #include "term/screen-processor.h"
122 #include "term/term-color-types.h"
123 #include "util/angband-files.h"
124 #include "util/int-char-converter.h"
125 #include "util/string-processor.h"
126 #include "view/display-map.h"
127 #include "view/display-messages.h"
128 #include "wizard/spoiler-util.h"
129 #include "wizard/wizard-spoiler.h"
130 #include "world/world.h"
139 * Include the support for loading bitmaps
141 #include "term/readdib.h"
144 * Available graphic modes
146 #define GRAPHICS_NONE 0
147 #define GRAPHICS_ORIGINAL 1
148 #define GRAPHICS_ADAM_BOLT 2
149 #define GRAPHICS_HENGBAND 3
152 * Foreground color bits
154 #define VID_BLACK 0x00
155 #define VID_BLUE 0x01
156 #define VID_GREEN 0x02
157 #define VID_CYAN 0x03
159 #define VID_MAGENTA 0x05
160 #define VID_YELLOW 0x06
161 #define VID_WHITE 0x07
166 #define VID_BRIGHT 0x08
170 * @brief ターム情報構造体 / Extra "term" data
173 * pos_x / pos_y は各タームの左上点座標を指す。
176 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
177 * 1ドットずつ調整するステータスを指す。
178 * また、フォントを変更すると都度自動調整される。
181 * Note the use of "font_want" for the names of the font file requested by
182 * the user, and the use of "font_file" for the currently active font file.
184 * The "font_file" is uppercased, and takes the form "8X13.FON", while
185 * "font_want" can be in almost any form as long as it could be construed
186 * as attempting to represent the name of a font.
197 TERM_LEN rows; /* int -> uint */
200 uint pos_x; //!< タームの左上X座標
201 uint pos_y; //!< タームの左上Y座標
216 int font_wid; //!< フォント横幅
217 int font_hgt; //!< フォント縦幅
218 int tile_wid; //!< タイル横幅
219 int tile_hgt; //!< タイル縦幅
226 #define MAX_TERM_DATA 8 //!< Maximum number of windows
228 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
229 static term_data *my_td; //!< Hack -- global "window creation" pointer
230 POINT normsize; //!< Remember normal size of main window when maxmized
233 * was main window maximized on previous playing
235 bool win_maximized = FALSE;
240 bool game_in_progress = FALSE;
243 * note when "open"/"new" become valid
245 bool initialized = FALSE;
248 * screen paletted, i.e. 256 colors
250 bool paletted = FALSE;
253 * 16 colors screen, don't use RGB()
255 bool colors16 = FALSE;
258 * Saved instance handle
260 static HINSTANCE hInstance;
263 * Yellow brush for the cursor
265 static HBRUSH hbrYellow;
275 static HPALETTE hPal;
278 static int use_bg = 0; //!< 背景使用フラグ、1なら使用。
279 #define DEFAULT_BG_FILENAME "bg.bmp"
282 * 現在使用中のタイルID(0ならば未使用)
283 * Flag set once "graphics" has been initialized
285 static byte current_graphics_mode = 0;
290 static DIBINIT infGraph;
293 * The global bitmap mask
295 static DIBINIT infMask;
298 * Show sub-windows even when Hengband is not in focus
300 static bool keep_subwindows = TRUE;
303 * Full path to ANGBAND.INI
305 static concptr ini_file = NULL;
308 * Name of application
310 static concptr AppName = "ANGBAND";
313 * Name of sub-window type
315 static concptr AngList = "AngList";
320 static concptr ANGBAND_DIR_XTRA_GRAF;
323 * The "complex" color values
325 static COLORREF win_clr[256];
328 * Flag for macro trigger with dump ASCII
330 static bool term_no_press = FALSE;
335 static bool mouse_down = FALSE;
336 static bool paint_rect = FALSE;
337 static TERM_LEN mousex = 0, mousey = 0;
338 static TERM_LEN oldx, oldy;
341 * @brief The "simple" color values
343 * See "main-ibm.c" for original table information
344 * The entries below are taken from the "color bits" defined above.
345 * Note that many of the choices below suck, but so do crappy monitors.
347 static BYTE win_pal[256] = {
348 VID_BLACK, /* Dark */
349 VID_WHITE, /* White */
350 VID_CYAN, /* Slate XXX */
351 VID_RED | VID_BRIGHT, /* Orange XXX */
353 VID_GREEN, /* Green */
355 VID_YELLOW, /* Umber XXX */
356 VID_BLACK | VID_BRIGHT, /* Light Dark */
357 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
358 VID_MAGENTA, /* Violet XXX */
359 VID_YELLOW | VID_BRIGHT, /* Yellow */
360 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
361 VID_GREEN | VID_BRIGHT, /* Light Green */
362 VID_BLUE | VID_BRIGHT, /* Light Blue */
363 VID_YELLOW /* Light Umber XXX */
367 * Hack -- define which keys are "special"
369 static bool special_key[256];
370 static bool ignore_key[256];
373 * Hack -- initialization list for "special_key"
375 static byte special_key_list[] = {
376 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,
377 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,
378 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,
379 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,
380 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,
384 static byte ignore_key_list[] = {
385 VK_ESCAPE, VK_TAB, VK_SPACE, 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
386 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 */
392 static void validate_file(concptr s)
397 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
401 * Validate a directory
403 static void validate_dir(concptr s, bool vital)
409 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
410 } else if (mkdir(s)) {
411 quit_fmt("Unable to create directory:\n%s", s);
416 * @brief (Windows版固有実装)Get the "size" for a window
418 static void term_getsize(term_data *td)
425 TERM_LEN wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
426 TERM_LEN hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
430 GetWindowRect(td->w, &rw);
431 GetClientRect(td->w, &rc);
433 td->size_wid = (rw.right - rw.left) - (rc.right - rc.left) + wid;
434 td->size_hgt = (rw.bottom - rw.top) - (rc.bottom - rc.top) + hgt;
439 /* Tempolary calculation */
444 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
445 td->size_wid = rc.right - rc.left;
446 td->size_hgt = rc.bottom - rc.top;
451 * Write the "prefs" for a single term
453 static void save_prefs_aux(int i)
455 term_data *td = &data[i];
456 GAME_TEXT sec_name[128];
462 sprintf(sec_name, "Term-%d", i);
465 strcpy(buf, td->visible ? "1" : "0");
466 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
470 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "MS ゴシック");
472 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "Courier");
475 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
477 wsprintf(buf, "%d", td->lf.lfWidth);
478 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
479 wsprintf(buf, "%d", td->lf.lfHeight);
480 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
481 wsprintf(buf, "%d", td->lf.lfWeight);
482 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
484 strcpy(buf, td->bizarre ? "1" : "0");
485 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
487 wsprintf(buf, "%d", td->tile_wid);
488 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
490 wsprintf(buf, "%d", td->tile_hgt);
491 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
493 WINDOWPLACEMENT lpwndpl;
494 lpwndpl.length = sizeof(WINDOWPLACEMENT);
495 GetWindowPlacement(td->w, &lpwndpl);
497 RECT rc = lpwndpl.rcNormalPosition;
499 wsprintf(buf, "%d", normsize.x);
501 wsprintf(buf, "%d", td->cols);
503 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
506 wsprintf(buf, "%d", normsize.y);
508 wsprintf(buf, "%d", td->rows);
510 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
512 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
513 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
516 GetWindowRect(td->w, &rc);
517 wsprintf(buf, "%d", rc.left);
518 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
520 wsprintf(buf, "%d", rc.top);
521 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
523 strcpy(buf, td->posfix ? "1" : "0");
524 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
530 * We assume that the windows have all been initialized
532 static void save_prefs(void)
535 sprintf(buf, "%d", arg_graphics);
536 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
538 strcpy(buf, arg_bigtile ? "1" : "0");
539 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
541 strcpy(buf, arg_sound ? "1" : "0");
542 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
544 strcpy(buf, arg_music ? "1" : "0");
545 WritePrivateProfileString("Angband", "Music", buf, ini_file);
547 strcpy(buf, use_bg ? "1" : "0");
548 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
549 WritePrivateProfileString("Angband", "BackGroundBitmap", bg_bitmap_file[0] != '\0' ? bg_bitmap_file : DEFAULT_BG_FILENAME, ini_file);
551 int path_length = strlen(ANGBAND_DIR) - 4; /* \libの4文字分を削除 */
553 strncat(tmp, ANGBAND_DIR, path_length);
555 int n = strncmp(tmp, savefile, path_length);
557 char relative_path[1024] = "";
558 snprintf(relative_path, sizeof(relative_path), ".\\%s", (savefile + path_length));
559 WritePrivateProfileString("Angband", "SaveFile", relative_path, ini_file);
561 WritePrivateProfileString("Angband", "SaveFile", savefile, ini_file);
564 strcpy(buf, keep_subwindows ? "1" : "0");
565 WritePrivateProfileString("Angband", "KeepSubwindows", buf, ini_file);
567 for (int i = 0; i < MAX_TERM_DATA; ++i) {
573 * Load the "prefs" for a single term
575 static void load_prefs_aux(int i)
577 term_data *td = &data[i];
578 GAME_TEXT sec_name[128];
581 int dispx = GetSystemMetrics(SM_CXVIRTUALSCREEN);
582 int dispy = GetSystemMetrics(SM_CYVIRTUALSCREEN);
586 sprintf(sec_name, "Term-%d", i);
587 sprintf(sec_name, "Term-%d", i);
589 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
593 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
595 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
598 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
600 td->font_want = string_make(tmp);
603 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
604 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
605 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
607 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
608 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
610 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
611 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
612 normsize.x = td->cols;
613 normsize.y = td->rows;
616 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
619 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
620 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
621 td->pos_x = MIN(MAX(0, posx), dispx - 128);
622 td->pos_y = MIN(MAX(0, posy), dispy - 128);
625 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
632 static void load_prefs(void)
634 arg_graphics = (byte)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
635 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
636 use_bigtile = arg_bigtile;
637 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
638 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
639 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
640 GetPrivateProfileString("Angband", "BackGroundBitmap", DEFAULT_BG_FILENAME, bg_bitmap_file, 1023, ini_file);
641 GetPrivateProfileString("Angband", "SaveFile", "", savefile, 1023, ini_file);
643 int n = strncmp(".\\", savefile, 2);
645 int path_length = strlen(ANGBAND_DIR) - 4; /* \libの4文字分を削除 */
647 strncat(tmp, ANGBAND_DIR, path_length);
648 strncat(tmp, savefile + 2, strlen(savefile) - 2 + path_length);
649 strncpy(savefile, tmp, strlen(tmp));
652 keep_subwindows = (GetPrivateProfileInt("Angband", "KeepSubwindows", 0, ini_file) != 0);
653 for (int i = 0; i < MAX_TERM_DATA; ++i) {
659 * Create the new global palette based on the bitmap palette
660 * (if any), and the standard 16 entry palette derived from
661 * "win_clr[]" which is used for the basic 16 Angband colors.
663 * This function is never called before all windows are ready.
665 * This function returns FALSE if the new palette could not be
666 * prepared, which should normally be a fatal error. XXX XXX
668 * Note that only some machines actually use a "palette".
670 static int new_palette(void)
675 LPLOGPALETTE pLogPal;
685 HPALETTE hBmPal = static_cast<HPALETTE>(infGraph.hPalette);
687 lppeSize = 256 * sizeof(PALETTEENTRY);
688 lppe = (LPPALETTEENTRY)std::malloc(lppeSize);
689 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
690 if ((nEntries == 0) || (nEntries > 220)) {
691 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
697 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
698 pLogPal = (LPLOGPALETTE)std::malloc(pLogPalSize);
699 pLogPal->palVersion = 0x300;
700 pLogPal->palNumEntries = nEntries + 16;
701 for (i = 0; i < nEntries; i++) {
702 pLogPal->palPalEntry[i] = lppe[i];
705 for (i = 0; i < 16; i++) {
707 p = &(pLogPal->palPalEntry[i + nEntries]);
708 p->peRed = GetRValue(win_clr[i]);
709 p->peGreen = GetGValue(win_clr[i]);
710 p->peBlue = GetBValue(win_clr[i]);
711 p->peFlags = PC_NOCOLLAPSE;
717 HPALETTE hNewPal = CreatePalette(pLogPal);
719 quit(_("パレットを作成できません!", "Cannot create palette!"));
723 HDC hdc = GetDC(td->w);
724 SelectPalette(hdc, hNewPal, 0);
725 i = RealizePalette(hdc);
726 ReleaseDC(td->w, hdc);
728 quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
730 for (i = 1; i < MAX_TERM_DATA; i++) {
733 SelectPalette(hdc, hNewPal, 0);
734 ReleaseDC(td->w, hdc);
745 * @brief グラフィクスを初期化する / Initialize graphics
748 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
749 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
752 static bool init_graphics(void)
755 BYTE wid, hgt, twid, thgt, ox, oy;
758 if (arg_graphics == GRAPHICS_ADAM_BOLT) {
767 ANGBAND_GRAF = "new";
768 } else if (arg_graphics == GRAPHICS_HENGBAND) {
777 ANGBAND_GRAF = "ne2";
786 ANGBAND_GRAF = "old";
789 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
790 if (!ReadDIB(data[0].w, buf, &infGraph)) {
791 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
795 infGraph.CellWidth = wid;
796 infGraph.CellHeight = hgt;
797 infGraph.TileWidth = twid;
798 infGraph.TileHeight = thgt;
799 infGraph.OffsetX = ox;
800 infGraph.OffsetY = oy;
802 if (arg_graphics == GRAPHICS_ADAM_BOLT) {
803 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
804 if (!ReadDIB(data[0].w, buf, &infMask)) {
805 plog_fmt("Cannot read bitmap file '%s'", buf);
810 if (arg_graphics == GRAPHICS_HENGBAND) {
811 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
812 if (!ReadDIB(data[0].w, buf, &infMask)) {
813 plog_fmt("Cannot read bitmap file '%s'", buf);
818 if (!new_palette()) {
819 plog(_("パレットを実現できません!", "Cannot activate palette!"));
823 current_graphics_mode = arg_graphics;
824 return current_graphics_mode != 0;
830 static void init_music(void)
832 // Flag set once "music" has been initialized
833 static bool can_use_music = FALSE;
835 if (!can_use_music) {
836 main_win_music::load_music_prefs();
837 can_use_music = TRUE;
844 static void init_sound(void)
846 // Flag set once "sound" has been initialized
847 static bool can_use_sound = FALSE;
849 if (!can_use_sound) {
851 can_use_sound = TRUE;
856 * Initialize background
858 static void init_background(void)
860 // Flag set once "background" has been initialized
861 static bool can_use_background = FALSE;
863 if (!can_use_background) {
865 can_use_background = TRUE;
870 * @brief Resize a window
872 static void term_window_resize(term_data *td)
877 SetWindowPos(td->w, 0, 0, 0, td->size_wid, td->size_hgt, SWP_NOMOVE | SWP_NOZORDER);
878 InvalidateRect(td->w, NULL, TRUE);
882 * @brief Force the use of a new "font file" for a term_data.
883 * This function may be called before the "window" is ready.
884 * This function returns zero only if everything succeeds.
885 * @note that the "font name" must be capitalized!!!
888 static errr term_force_font(term_data *td, concptr path)
891 DeleteObject(td->font_id);
894 td->font_id = CreateFontIndirect(&(td->lf));
895 int wid = td->lf.lfWidth;
896 int hgt = td->lf.lfHeight;
905 hdcDesktop = GetDC(HWND_DESKTOP);
906 hfOld = static_cast<HFONT>(SelectObject(hdcDesktop, td->font_id));
907 GetTextMetrics(hdcDesktop, &tm);
908 SelectObject(hdcDesktop, hfOld);
909 ReleaseDC(HWND_DESKTOP, hdcDesktop);
911 wid = tm.tmAveCharWidth;
922 * Allow the user to change the font for this window.
924 static void term_change_font(term_data *td)
927 memset(&cf, 0, sizeof(cf));
928 cf.lStructSize = sizeof(cf);
929 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
930 cf.lpLogFont = &(td->lf);
932 if (!ChooseFont(&cf))
935 term_force_font(td, NULL);
937 td->tile_wid = td->font_wid;
938 td->tile_hgt = td->font_hgt;
940 term_window_resize(td);
944 * Allow the user to lock this window.
946 static void term_window_pos(term_data *td, HWND hWnd)
948 SetWindowPos(td->w, hWnd, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
952 * Hack -- redraw a term_data
954 static void term_data_redraw(term_data *td)
956 term_activate(&td->t);
958 term_activate(term_screen);
961 void term_inversed_area(HWND hWnd, int x, int y, int w, int h)
963 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
964 int tx = td->size_ow1 + x * td->tile_wid;
965 int ty = td->size_oh1 + y * td->tile_hgt;
966 int tw = w * td->tile_wid - 1;
967 int th = h * td->tile_hgt - 1;
969 HDC hdc = GetDC(hWnd);
970 HBRUSH myBrush = CreateSolidBrush(RGB(255, 255, 255));
971 HBRUSH oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
972 HPEN oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
974 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
976 SelectObject(hdc, oldBrush);
977 SelectObject(hdc, oldPen);
981 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
983 static errr term_user_win(int n)
990 * React to global changes
992 static errr term_xtra_win_react(player_type *player_ptr)
995 for (int i = 0; i < 256; i++) {
996 win_pal[i] = angband_color_table[i][0];
1001 bool change = FALSE;
1002 for (int i = 0; i < 256; i++) {
1003 rv = angband_color_table[i][1];
1004 gv = angband_color_table[i][2];
1005 bv = angband_color_table[i][3];
1006 code = PALETTERGB(rv, gv, bv);
1007 if (win_clr[i] != code) {
1014 (void)new_palette();
1017 if (use_sound != arg_sound) {
1019 use_sound = arg_sound;
1022 if (use_music != arg_music) {
1024 use_music = arg_music;
1026 main_win_music::stop_music();
1028 select_floor_music(player_ptr);
1031 if (use_graphics != (arg_graphics > 0)) {
1032 if (arg_graphics && !init_graphics()) {
1033 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
1034 arg_graphics = GRAPHICS_NONE;
1037 use_graphics = (arg_graphics > 0);
1038 reset_visuals(player_ptr, process_autopick_file_command);
1041 for (int i = 0; i < MAX_TERM_DATA; i++) {
1042 term_type *old = Term;
1043 term_data *td = &data[i];
1044 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt)) {
1045 term_activate(&td->t);
1046 term_resize(td->cols, td->rows);
1056 * Process at least one event
1058 static errr term_xtra_win_event(int v)
1062 if (GetMessage(&msg, NULL, 0, 0)) {
1063 TranslateMessage(&msg);
1064 DispatchMessage(&msg);
1067 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
1068 TranslateMessage(&msg);
1069 DispatchMessage(&msg);
1077 * Process all pending events
1079 static errr term_xtra_win_flush(void)
1082 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
1083 TranslateMessage(&msg);
1084 DispatchMessage(&msg);
1091 * Hack -- clear the screen
1093 * Make this more efficient
1095 static errr term_xtra_win_clear(void)
1097 term_data *td = (term_data *)(Term->data);
1100 rc.left = td->size_ow1;
1101 rc.right = rc.left + td->cols * td->tile_wid;
1102 rc.top = td->size_oh1;
1103 rc.bottom = rc.top + td->rows * td->tile_hgt;
1105 HDC hdc = GetDC(td->w);
1106 SetBkColor(hdc, RGB(0, 0, 0));
1107 SelectObject(hdc, td->font_id);
1108 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1116 ReleaseDC(td->w, hdc);
1121 * Hack -- make a noise
1123 static errr term_xtra_win_noise(void)
1125 MessageBeep(MB_ICONASTERISK);
1130 * Hack -- make a sound
1132 static errr term_xtra_win_sound(int v)
1136 return play_sound(v);
1140 * Hack -- play a music
1142 static errr term_xtra_win_music(int n, int v)
1148 return main_win_music::play_music(n, v);
1152 * Hack -- play a music matches a situation
1154 static errr term_xtra_win_scene(int v)
1156 // TODO 場面に合った壁紙変更対応
1161 return main_win_music::play_music_scene(v);
1165 * Delay for "x" milliseconds
1167 static int term_xtra_win_delay(int v)
1174 * @brief Do a "special thing"
1175 * @todo z-termに影響があるのでplayer_typeの追加は保留
1177 static errr term_xtra_win(int n, int v)
1180 case TERM_XTRA_NOISE: {
1181 return (term_xtra_win_noise());
1183 case TERM_XTRA_MUSIC_BASIC:
1184 case TERM_XTRA_MUSIC_DUNGEON:
1185 case TERM_XTRA_MUSIC_QUEST:
1186 case TERM_XTRA_MUSIC_TOWN:
1187 case TERM_XTRA_MUSIC_MONSTER: {
1188 return term_xtra_win_music(n, v);
1190 case TERM_XTRA_MUSIC_MUTE: {
1191 return main_win_music::stop_music();
1193 case TERM_XTRA_SCENE: {
1194 return term_xtra_win_scene(v);
1196 case TERM_XTRA_SOUND: {
1197 return (term_xtra_win_sound(v));
1199 case TERM_XTRA_BORED: {
1200 return (term_xtra_win_event(0));
1202 case TERM_XTRA_EVENT: {
1203 return (term_xtra_win_event(v));
1205 case TERM_XTRA_FLUSH: {
1206 return (term_xtra_win_flush());
1208 case TERM_XTRA_CLEAR: {
1209 return (term_xtra_win_clear());
1211 case TERM_XTRA_REACT: {
1212 return (term_xtra_win_react(p_ptr));
1214 case TERM_XTRA_DELAY: {
1215 return (term_xtra_win_delay(v));
1223 * Low level graphics (Assumes valid input).
1225 * Draw a "cursor" at (x,y), using a "yellow box".
1227 static errr term_curs_win(int x, int y)
1229 term_data *td = (term_data *)(Term->data);
1230 int tile_wid, tile_hgt;
1231 tile_wid = td->tile_wid;
1232 tile_hgt = td->tile_hgt;
1235 rc.left = x * tile_wid + td->size_ow1;
1236 rc.right = rc.left + tile_wid;
1237 rc.top = y * tile_hgt + td->size_oh1;
1238 rc.bottom = rc.top + tile_hgt;
1240 HDC hdc = GetDC(td->w);
1241 FrameRect(hdc, &rc, hbrYellow);
1242 ReleaseDC(td->w, hdc);
1247 * Low level graphics (Assumes valid input).
1249 * Draw a "big cursor" at (x,y), using a "yellow box".
1251 static errr term_bigcurs_win(int x, int y)
1253 term_data *td = (term_data *)(Term->data);
1254 int tile_wid, tile_hgt;
1255 tile_wid = td->tile_wid;
1256 tile_hgt = td->tile_hgt;
1259 rc.left = x * tile_wid + td->size_ow1;
1260 rc.right = rc.left + 2 * tile_wid;
1261 rc.top = y * tile_hgt + td->size_oh1;
1262 rc.bottom = rc.top + tile_hgt;
1264 HDC hdc = GetDC(td->w);
1265 FrameRect(hdc, &rc, hbrYellow);
1266 ReleaseDC(td->w, hdc);
1271 * Low level graphics (Assumes valid input).
1273 * Erase a "block" of "n" characters starting at (x,y).
1275 static errr term_wipe_win(int x, int y, int n)
1277 term_data *td = (term_data *)(Term->data);
1279 rc.left = x * td->tile_wid + td->size_ow1;
1280 rc.right = rc.left + n * td->tile_wid;
1281 rc.top = y * td->tile_hgt + td->size_oh1;
1282 rc.bottom = rc.top + td->tile_hgt;
1284 HDC hdc = GetDC(td->w);
1285 SetBkColor(hdc, RGB(0, 0, 0));
1286 SelectObject(hdc, td->font_id);
1290 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1292 ReleaseDC(td->w, hdc);
1297 * Low level graphics. Assumes valid input.
1299 * Draw several ("n") chars, with an attr, at a given location.
1301 * All "graphic" data is handled by "term_pict_win()", below.
1303 * One would think there is a more efficient method for telling a window
1304 * what color it should be using to draw with, but perhaps simply changing
1305 * it every time is not too inefficient.
1307 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
1309 term_data *td = (term_data *)(Term->data);
1310 static HBITMAP WALL;
1311 static HBRUSH myBrush, oldBrush;
1313 static bool init_done = FALSE;
1316 WALL = LoadBitmap(hInstance, AppName);
1317 myBrush = CreatePatternBrush(WALL);
1322 rc.left = x * td->tile_wid + td->size_ow1;
1323 rc.right = rc.left + n * td->tile_wid;
1324 rc.top = y * td->tile_hgt + td->size_oh1;
1325 rc.bottom = rc.top + td->tile_hgt;
1327 HDC hdc = GetDC(td->w);
1328 SetBkColor(hdc, RGB(0, 0, 0));
1330 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
1331 } else if (paletted) {
1332 SetTextColor(hdc, win_clr[a & 0x0F]);
1334 SetTextColor(hdc, win_clr[a]);
1337 SelectObject(hdc, td->font_id);
1339 SetBkMode(hdc, TRANSPARENT);
1341 if (td->bizarre || (td->tile_hgt != td->font_hgt) || (td->tile_wid != td->font_wid)) {
1342 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1346 rc.left += ((td->tile_wid - td->font_wid) / 2);
1347 rc.right = rc.left + td->font_wid;
1348 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
1349 rc.bottom = rc.top + td->font_hgt;
1351 for (int i = 0; i < n; i++) {
1353 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1]) {
1354 rc.right += td->font_wid;
1355 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1356 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1357 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1358 SelectObject(hdc, oldBrush);
1359 SelectObject(hdc, oldPen);
1360 rc.right -= td->font_wid;
1362 rc.left += 2 * td->tile_wid;
1363 rc.right += 2 * td->tile_wid;
1364 } else if (iskanji(*(s + i))) /* 2バイト文字 */
1366 rc.right += td->font_wid;
1367 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 2, NULL);
1368 rc.right -= td->font_wid;
1370 rc.left += 2 * td->tile_wid;
1371 rc.right += 2 * td->tile_wid;
1372 } else if (*(s + i) == 127) {
1373 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1374 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1375 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1376 SelectObject(hdc, oldBrush);
1377 SelectObject(hdc, oldPen);
1378 rc.left += td->tile_wid;
1379 rc.right += td->tile_wid;
1381 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1382 rc.left += td->tile_wid;
1383 rc.right += td->tile_wid;
1386 if (*(s + i) == 127) {
1387 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1388 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1389 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1390 SelectObject(hdc, oldBrush);
1391 SelectObject(hdc, oldPen);
1392 rc.left += td->tile_wid;
1393 rc.right += td->tile_wid;
1395 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1396 rc.left += td->tile_wid;
1397 rc.right += td->tile_wid;
1402 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc, s, n, NULL);
1405 ReleaseDC(td->w, hdc);
1410 * Low level graphics. Assumes valid input.
1412 * Draw an array of "special" attr/char pairs at the given location.
1414 * We use the "term_pict_win()" function for "graphic" data, which are
1415 * encoded by setting the "high-bits" of both the "attr" and the "char"
1416 * data. We use the "attr" to represent the "row" of the main bitmap,
1417 * and the "char" to represent the "col" of the main bitmap. The use
1418 * of this function is induced by the "higher_pict" flag.
1420 * If "graphics" is not available, we simply "wipe" the given grids.
1422 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)
1424 term_data *td = (term_data *)(Term->data);
1427 if (!use_graphics) {
1428 return (term_wipe_win(x, y, n));
1431 TERM_LEN w1 = infGraph.CellWidth;
1432 TERM_LEN h1 = infGraph.CellHeight;
1433 TERM_LEN tw1 = infGraph.TileWidth;
1434 TERM_LEN th1 = infGraph.TileHeight;
1435 TERM_LEN w2, h2, tw2 = 0;
1442 TERM_LEN x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
1443 TERM_LEN y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
1444 HDC hdc = GetDC(td->w);
1445 HDC hdcSrc = CreateCompatibleDC(hdc);
1446 HBITMAP hbmSrcOld = static_cast<HBITMAP>(SelectObject(hdcSrc, infGraph.hBitmap));
1448 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1449 hdcMask = CreateCompatibleDC(hdc);
1450 SelectObject(hdcMask, infMask.hBitmap);
1453 for (i = 0; i < n; i++, x2 += w2) {
1454 TERM_COLOR a = ap[i];
1456 int row = (a & 0x7F);
1457 int col = (c & 0x7F);
1458 TERM_LEN x1 = col * w1;
1459 TERM_LEN y1 = row * h1;
1461 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1462 TERM_LEN x3 = (tcp[i] & 0x7F) * w1;
1463 TERM_LEN y3 = (tap[i] & 0x7F) * h1;
1464 tw2 = tw2 * w1 / tw1;
1466 if ((tw1 == tw2) && (th1 == h2)) {
1467 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
1468 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
1469 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
1473 SetStretchBltMode(hdc, COLORONCOLOR);
1474 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
1475 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
1476 if ((x1 != x3) || (y1 != y3)) {
1477 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
1478 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
1484 if ((w1 == tw2) && (h1 == h2)) {
1485 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
1489 SetStretchBltMode(hdc, COLORONCOLOR);
1490 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
1493 SelectObject(hdcSrc, hbmSrcOld);
1495 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1496 SelectObject(hdcMask, hbmSrcOld);
1500 ReleaseDC(td->w, hdc);
1505 * Create and initialize a "term_data" given a title
1507 static void term_data_link(term_data *td)
1509 term_type *t = &td->t;
1510 term_init(t, td->cols, td->rows, FILE_READ_BUFF_SIZE);
1511 t->soft_cursor = TRUE;
1512 t->higher_pict = TRUE;
1513 t->attr_blank = TERM_WHITE;
1514 t->char_blank = ' ';
1515 t->user_hook = term_user_win;
1516 t->xtra_hook = term_xtra_win;
1517 t->curs_hook = term_curs_win;
1518 t->bigcurs_hook = term_bigcurs_win;
1519 t->wipe_hook = term_wipe_win;
1520 t->text_hook = term_text_win;
1521 t->pict_hook = term_pict_win;
1522 t->data = (vptr)(td);
1526 * Create the windows
1528 * First, instantiate the "default" values, then read the "ini_file"
1529 * to over-ride selected values, then create the windows, and fonts.
1531 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
1532 * must make active to realize the palette.
1534 static void init_windows(void)
1538 WIPE(td, term_data);
1542 td->s = angband_term_name[0];
1558 for (int i = 1; i < MAX_TERM_DATA; i++) {
1560 WIPE(td, term_data);
1561 td->s = angband_term_name[i];
1565 td->visible = FALSE;
1570 td->pos_x = (7 - i) * 30;
1571 td->pos_y = (7 - i) * 20;
1578 /* Atrributes of main window */
1580 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_VISIBLE);
1584 /* Attributes of sub windows */
1585 for (int i = 1; i < MAX_TERM_DATA; i++) {
1587 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
1588 td->dwExStyle = (WS_EX_TOOLWINDOW);
1591 /* Font of each window */
1592 for (int i = 0; i < MAX_TERM_DATA; i++) {
1594 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
1595 td->lf.lfCharSet = DEFAULT_CHARSET;
1596 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
1597 term_force_font(td, NULL);
1599 td->tile_wid = td->font_wid;
1601 td->tile_hgt = td->font_hgt;
1603 term_window_resize(td);
1606 /* Create sub windows */
1607 for (int i = MAX_TERM_DATA - 1; i >= 1; --i) {
1612 = 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);
1616 quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
1618 td->size_hack = TRUE;
1620 term_window_resize(td);
1623 ShowWindow(td->w, SW_SHOW);
1625 td->size_hack = FALSE;
1628 angband_term[i] = &td->t;
1631 /* Activate the window */
1632 SetActiveWindow(td->w);
1636 term_window_pos(td, HWND_TOPMOST);
1638 term_window_pos(td, td->w);
1642 /* Create main window */
1645 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);
1649 quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
1652 td->size_hack = TRUE;
1654 term_window_resize(td);
1655 td->size_hack = FALSE;
1658 angband_term[0] = &td->t;
1659 normsize.x = td->cols;
1660 normsize.y = td->rows;
1663 ShowWindow(td->w, SW_SHOWMAXIMIZED);
1665 ShowWindow(td->w, SW_SHOW);
1667 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
1668 (void)new_palette();
1669 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
1670 (void)term_xtra_win_flush();
1676 static void setup_menus(void)
1678 HMENU hm = GetMenu(data[0].w);
1680 if (current_world_ptr->character_generated) {
1681 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1682 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1683 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_ENABLED);
1685 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
1686 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
1687 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1690 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_ENABLED);
1691 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_ENABLED);
1693 for (int i = 0; i < MAX_TERM_DATA; i++) {
1694 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1695 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i, (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
1696 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_ENABLED);
1699 for (int i = 0; i < MAX_TERM_DATA; i++) {
1700 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1702 if (data[i].visible) {
1703 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1707 for (int i = 0; i < MAX_TERM_DATA; i++) {
1708 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1709 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i, (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
1710 if (data[i].visible) {
1711 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_ENABLED);
1715 for (int i = 0; i < MAX_TERM_DATA; i++) {
1716 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1717 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i, (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
1718 if (data[i].visible) {
1719 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_ENABLED);
1723 for (int i = 0; i < MAX_TERM_DATA; i++) {
1724 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1725 if (data[i].visible) {
1726 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
1730 for (int i = 0; i < MAX_TERM_DATA; i++) {
1731 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1732 if (data[i].visible) {
1733 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
1737 for (int i = 0; i < MAX_TERM_DATA; i++) {
1738 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1739 if (data[i].visible) {
1740 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1744 for (int i = 0; i < MAX_TERM_DATA; i++) {
1745 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1747 if (data[i].visible) {
1748 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
1751 EnableMenuItem(hm, IDM_WINDOW_KEEP_SUBWINDOWS, MF_BYCOMMAND | MF_ENABLED);
1752 CheckMenuItem(hm, IDM_WINDOW_KEEP_SUBWINDOWS, (keep_subwindows ? MF_CHECKED : MF_UNCHECKED));
1754 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1755 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1756 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1757 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1758 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
1760 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
1761 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
1762 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
1763 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS, (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
1764 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE, (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
1765 CheckMenuItem(hm, IDM_OPTIONS_MUSIC, (arg_music ? MF_CHECKED : MF_UNCHECKED));
1766 CheckMenuItem(hm, IDM_OPTIONS_SOUND, (arg_sound ? MF_CHECKED : MF_UNCHECKED));
1767 CheckMenuItem(hm, IDM_OPTIONS_BG, (use_bg ? MF_CHECKED : MF_UNCHECKED));
1769 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
1770 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
1771 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
1772 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
1773 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
1777 * Check for double clicked (or dragged) savefile
1779 * Apparently, Windows copies the entire filename into the first
1780 * piece of the "command line string". Perhaps we should extract
1781 * the "basename" of that filename and append it to the "save" dir.
1783 static void check_for_save_file(player_type *player_ptr, LPSTR cmd_line)
1790 strcpy(savefile, s);
1791 validate_file(savefile);
1792 game_in_progress = TRUE;
1793 play_game(player_ptr, FALSE, FALSE);
1797 * Process a menu command
1799 static void process_menus(player_type *player_ptr, WORD wCmd)
1804 case IDM_FILE_NEW: {
1806 plog(_("まだ初期化中です...", "You cannot do that yet..."));
1807 } else if (game_in_progress) {
1808 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
1810 game_in_progress = TRUE;
1812 strcpy(savefile, "");
1813 play_game(player_ptr, TRUE, FALSE);
1819 case IDM_FILE_OPEN: {
1821 plog(_("まだ初期化中です...", "You cannot do that yet..."));
1822 } else if (game_in_progress) {
1823 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
1825 memset(&ofn, 0, sizeof(ofn));
1826 ofn.lStructSize = sizeof(ofn);
1827 ofn.hwndOwner = data[0].w;
1828 ofn.lpstrFilter = "Save Files (*.)\0*\0";
1829 ofn.nFilterIndex = 1;
1830 ofn.lpstrFile = savefile;
1831 ofn.nMaxFile = 1024;
1832 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
1833 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
1835 if (GetOpenFileName(&ofn)) {
1836 validate_file(savefile);
1837 game_in_progress = TRUE;
1839 play_game(player_ptr, FALSE, FALSE);
1846 case IDM_FILE_SAVE: {
1847 if (game_in_progress && current_world_ptr->character_generated) {
1849 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
1854 do_cmd_save_game(player_ptr, FALSE);
1856 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
1861 case IDM_FILE_EXIT: {
1862 if (game_in_progress && current_world_ptr->character_generated) {
1864 plog(_("今は終了できません。", "You may not do that right now."));
1869 forget_lite(player_ptr->current_floor_ptr);
1870 forget_view(player_ptr->current_floor_ptr);
1871 clear_mon_lite(player_ptr->current_floor_ptr);
1873 term_key_push(SPECIAL_KEY_QUIT);
1880 case IDM_FILE_SCORE: {
1882 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
1883 highscore_fd = fd_open(buf, O_RDONLY);
1884 if (highscore_fd < 0) {
1885 msg_print("Score file unavailable.");
1889 display_scores_aux(0, MAX_HISCORES, -1, NULL);
1890 (void)fd_close(highscore_fd);
1898 case IDM_FILE_MOVIE: {
1900 plog(_("まだ初期化中です...", "You cannot do that yet..."));
1901 } else if (game_in_progress) {
1902 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
1904 memset(&ofn, 0, sizeof(ofn));
1905 ofn.lStructSize = sizeof(ofn);
1906 ofn.hwndOwner = data[0].w;
1907 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
1908 ofn.nFilterIndex = 1;
1909 ofn.lpstrFile = savefile;
1910 ofn.nMaxFile = 1024;
1911 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
1912 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1914 if (GetOpenFileName(&ofn)) {
1915 prepare_browse_movie_without_path_build(savefile);
1916 play_game(player_ptr, FALSE, TRUE);
1924 case IDM_WINDOW_VIS_0: {
1925 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
1928 case IDM_WINDOW_VIS_1:
1929 case IDM_WINDOW_VIS_2:
1930 case IDM_WINDOW_VIS_3:
1931 case IDM_WINDOW_VIS_4:
1932 case IDM_WINDOW_VIS_5:
1933 case IDM_WINDOW_VIS_6:
1934 case IDM_WINDOW_VIS_7: {
1935 int i = wCmd - IDM_WINDOW_VIS_0;
1936 if ((i < 0) || (i >= MAX_TERM_DATA))
1942 ShowWindow(td->w, SW_SHOW);
1943 term_data_redraw(td);
1945 td->visible = FALSE;
1947 ShowWindow(td->w, SW_HIDE);
1952 case IDM_WINDOW_FONT_0:
1953 case IDM_WINDOW_FONT_1:
1954 case IDM_WINDOW_FONT_2:
1955 case IDM_WINDOW_FONT_3:
1956 case IDM_WINDOW_FONT_4:
1957 case IDM_WINDOW_FONT_5:
1958 case IDM_WINDOW_FONT_6:
1959 case IDM_WINDOW_FONT_7: {
1960 int i = wCmd - IDM_WINDOW_FONT_0;
1961 if ((i < 0) || (i >= MAX_TERM_DATA))
1965 term_change_font(td);
1968 case IDM_WINDOW_POS_1:
1969 case IDM_WINDOW_POS_2:
1970 case IDM_WINDOW_POS_3:
1971 case IDM_WINDOW_POS_4:
1972 case IDM_WINDOW_POS_5:
1973 case IDM_WINDOW_POS_6:
1974 case IDM_WINDOW_POS_7: {
1975 int i = wCmd - IDM_WINDOW_POS_0;
1976 if ((i < 0) || (i >= MAX_TERM_DATA))
1980 if (!td->posfix && td->visible) {
1982 term_window_pos(td, HWND_TOPMOST);
1985 term_window_pos(td, data[0].w);
1990 case IDM_WINDOW_BIZ_0:
1991 case IDM_WINDOW_BIZ_1:
1992 case IDM_WINDOW_BIZ_2:
1993 case IDM_WINDOW_BIZ_3:
1994 case IDM_WINDOW_BIZ_4:
1995 case IDM_WINDOW_BIZ_5:
1996 case IDM_WINDOW_BIZ_6:
1997 case IDM_WINDOW_BIZ_7: {
1998 int i = wCmd - IDM_WINDOW_BIZ_0;
1999 if ((i < 0) || (i >= MAX_TERM_DATA))
2003 td->bizarre = !td->bizarre;
2005 term_window_resize(td);
2008 case IDM_WINDOW_I_WID_0:
2009 case IDM_WINDOW_I_WID_1:
2010 case IDM_WINDOW_I_WID_2:
2011 case IDM_WINDOW_I_WID_3:
2012 case IDM_WINDOW_I_WID_4:
2013 case IDM_WINDOW_I_WID_5:
2014 case IDM_WINDOW_I_WID_6:
2015 case IDM_WINDOW_I_WID_7: {
2016 int i = wCmd - IDM_WINDOW_I_WID_0;
2017 if ((i < 0) || (i >= MAX_TERM_DATA))
2023 term_window_resize(td);
2026 case IDM_WINDOW_D_WID_0:
2027 case IDM_WINDOW_D_WID_1:
2028 case IDM_WINDOW_D_WID_2:
2029 case IDM_WINDOW_D_WID_3:
2030 case IDM_WINDOW_D_WID_4:
2031 case IDM_WINDOW_D_WID_5:
2032 case IDM_WINDOW_D_WID_6:
2033 case IDM_WINDOW_D_WID_7: {
2034 int i = wCmd - IDM_WINDOW_D_WID_0;
2035 if ((i < 0) || (i >= MAX_TERM_DATA))
2041 term_window_resize(td);
2044 case IDM_WINDOW_I_HGT_0:
2045 case IDM_WINDOW_I_HGT_1:
2046 case IDM_WINDOW_I_HGT_2:
2047 case IDM_WINDOW_I_HGT_3:
2048 case IDM_WINDOW_I_HGT_4:
2049 case IDM_WINDOW_I_HGT_5:
2050 case IDM_WINDOW_I_HGT_6:
2051 case IDM_WINDOW_I_HGT_7: {
2052 int i = wCmd - IDM_WINDOW_I_HGT_0;
2053 if ((i < 0) || (i >= MAX_TERM_DATA))
2059 term_window_resize(td);
2062 case IDM_WINDOW_D_HGT_0:
2063 case IDM_WINDOW_D_HGT_1:
2064 case IDM_WINDOW_D_HGT_2:
2065 case IDM_WINDOW_D_HGT_3:
2066 case IDM_WINDOW_D_HGT_4:
2067 case IDM_WINDOW_D_HGT_5:
2068 case IDM_WINDOW_D_HGT_6:
2069 case IDM_WINDOW_D_HGT_7: {
2070 int i = wCmd - IDM_WINDOW_D_HGT_0;
2071 if ((i < 0) || (i >= MAX_TERM_DATA))
2077 term_window_resize(td);
2080 case IDM_WINDOW_KEEP_SUBWINDOWS: {
2081 keep_subwindows = !keep_subwindows;
2084 case IDM_OPTIONS_NO_GRAPHICS: {
2086 plog("You may not do that right now.");
2090 if (arg_graphics != GRAPHICS_NONE) {
2091 arg_graphics = GRAPHICS_NONE;
2092 term_xtra_win_react(player_ptr);
2093 term_key_push(KTRL('R'));
2098 case IDM_OPTIONS_OLD_GRAPHICS: {
2100 plog("You may not do that right now.");
2104 if (arg_graphics != GRAPHICS_ORIGINAL) {
2105 arg_graphics = GRAPHICS_ORIGINAL;
2106 term_xtra_win_react(player_ptr);
2107 term_key_push(KTRL('R'));
2112 case IDM_OPTIONS_NEW_GRAPHICS: {
2114 plog("You may not do that right now.");
2118 if (arg_graphics != GRAPHICS_ADAM_BOLT) {
2119 arg_graphics = GRAPHICS_ADAM_BOLT;
2120 term_xtra_win_react(player_ptr);
2121 term_key_push(KTRL('R'));
2126 case IDM_OPTIONS_NEW2_GRAPHICS: {
2128 plog("You may not do that right now.");
2132 if (arg_graphics != GRAPHICS_HENGBAND) {
2133 arg_graphics = GRAPHICS_HENGBAND;
2134 term_xtra_win_react(player_ptr);
2135 term_key_push(KTRL('R'));
2140 case IDM_OPTIONS_BIGTILE: {
2143 plog("You may not do that right now.");
2147 arg_bigtile = !arg_bigtile;
2148 term_activate(&td->t);
2149 term_resize(td->cols, td->rows);
2150 InvalidateRect(td->w, NULL, TRUE);
2153 case IDM_OPTIONS_MUSIC: {
2155 plog("You may not do that right now.");
2159 arg_music = !arg_music;
2160 term_xtra_win_react(player_ptr);
2161 term_key_push(KTRL('R'));
2164 case IDM_OPTIONS_SOUND: {
2166 plog("You may not do that right now.");
2170 arg_sound = !arg_sound;
2171 term_xtra_win_react(player_ptr);
2172 term_key_push(KTRL('R'));
2175 case IDM_OPTIONS_BG: {
2177 plog("You may not do that right now.");
2189 term_xtra_win_react(player_ptr);
2190 term_key_push(KTRL('R'));
2193 case IDM_OPTIONS_OPEN_BG: {
2195 plog("You may not do that right now.");
2199 memset(&ofn, 0, sizeof(ofn));
2200 ofn.lStructSize = sizeof(ofn);
2201 ofn.hwndOwner = data[0].w;
2202 ofn.lpstrFilter = "Image Files (*.bmp;*.png;*.jpg;*.jpeg;)\0*.bmp;*.png;*.jpg;*.jpeg;\0";
2203 ofn.nFilterIndex = 1;
2204 ofn.lpstrFile = bg_bitmap_file;
2205 ofn.nMaxFile = 1023;
2206 ofn.lpstrInitialDir = NULL;
2207 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
2208 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
2210 if (GetOpenFileName(&ofn)) {
2215 term_xtra_win_react(player_ptr);
2216 term_key_push(KTRL('R'));
2219 case IDM_DUMP_SCREEN_HTML: {
2220 static char buf[1024] = "";
2221 memset(&ofn, 0, sizeof(ofn));
2222 ofn.lStructSize = sizeof(ofn);
2223 ofn.hwndOwner = data[0].w;
2224 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
2225 ofn.nFilterIndex = 1;
2226 ofn.lpstrFile = buf;
2227 ofn.nMaxFile = 1023;
2228 ofn.lpstrDefExt = "html";
2229 ofn.lpstrInitialDir = NULL;
2230 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
2231 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
2233 if (GetSaveFileName(&ofn)) {
2234 do_cmd_save_screen_html_aux(buf, 0);
2243 * Add a keypress to the "queue"
2245 static errr term_keypress(int k)
2247 /* Refuse to enqueue non-keys */
2251 /* Store the char, advance the queue */
2252 Term->key_queue[Term->key_head++] = (char)k;
2254 /* Circular queue, handle wrap */
2255 if (Term->key_head == Term->key_size)
2258 if (Term->key_head != Term->key_tail)
2264 static bool process_keydown(WPARAM wParam, LPARAM lParam)
2270 if (GetKeyState(VK_CONTROL) & 0x8000)
2272 if (GetKeyState(VK_SHIFT) & 0x8000)
2274 if (GetKeyState(VK_MENU) & 0x8000)
2277 term_no_press = (ma) ? TRUE : FALSE;
2278 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)])) {
2279 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
2280 bool numpad = FALSE;
2290 int i = LOBYTE(HIWORD(lParam));
2294 term_no_press = TRUE;
2295 [[fallthrough]]; /* Fall through */
2314 term_no_press = TRUE;
2315 [[fallthrough]]; /* Fall through */
2333 term_keypress(hexsym[i / 16]);
2334 term_keypress(hexsym[i % 16]);
2344 * @todo WNDCLASSに影響があるのでplayer_type*の追加は保留
2346 LRESULT PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2350 td = (term_data *)GetWindowLong(hWnd, 0);
2354 SetWindowLong(hWnd, 0, (LONG)(my_td));
2361 case WM_GETMINMAXINFO: {
2365 lpmmi = (MINMAXINFO *)lParam;
2369 rc.left = rc.top = 0;
2370 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
2371 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
2373 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
2375 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
2376 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
2381 BeginPaint(hWnd, &ps);
2383 term_data_redraw(td);
2384 EndPaint(hWnd, &ps);
2385 ValidateRect(hWnd, NULL);
2388 case MM_MCINOTIFY: {
2389 main_win_music::on_mci_notify(wParam, lParam);
2395 if (process_keydown(wParam, lParam))
2401 term_no_press = FALSE;
2403 term_keypress(wParam);
2406 case WM_LBUTTONDOWN: {
2407 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
2408 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
2414 case WM_LBUTTONUP: {
2417 TERM_LEN dx = abs(oldx - mousex) + 1;
2418 TERM_LEN dy = abs(oldy - mousey) + 1;
2419 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
2420 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
2426 int sz = (dx + 3) * dy;
2428 int sz = (dx + 2) * dy;
2430 hGlobal = GlobalAlloc(GHND, sz + 1);
2431 if (hGlobal == NULL)
2433 lpStr = (LPSTR)GlobalLock(hGlobal);
2435 for (int i = 0; i < dy; i++) {
2438 char **scr = data[0].t.scr->c;
2440 C_MAKE(s, (dx + 1), char);
2441 strncpy(s, &scr[oy + i][ox], dx);
2444 if (iskanji(scr[oy + i][ox - 1]))
2448 if (ox + dx < data[0].cols) {
2449 if (iskanji(scr[oy + i][ox + dx - 1]))
2453 for (int j = 0; j < dx; j++) {
2459 for (int j = 0; j < dx; j++) {
2460 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
2469 GlobalUnlock(hGlobal);
2470 if (OpenClipboard(hWnd) == 0) {
2471 GlobalFree(hGlobal);
2476 SetClipboardData(CF_TEXT, hGlobal);
2481 case WM_MOUSEMOVE: {
2486 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
2487 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
2491 dx = abs(oldx - mousex) + 1;
2492 dy = abs(oldy - mousey) + 1;
2493 ox = (oldx > mousex) ? mousex : oldx;
2494 oy = (oldy > mousey) ? mousey : oldy;
2495 term_inversed_area(hWnd, ox, oy, dx, dy);
2500 dx = abs(cx - mousex) + 1;
2501 dy = abs(cy - mousey) + 1;
2502 ox = (cx > mousex) ? mousex : cx;
2503 oy = (cy > mousey) ? mousey : cy;
2504 term_inversed_area(hWnd, ox, oy, dx, dy);
2515 if (!game_in_progress || !current_world_ptr->character_generated) {
2521 plog(_("今は終了できません。", "You may not do that right now."));
2526 forget_lite(p_ptr->current_floor_ptr);
2527 forget_view(p_ptr->current_floor_ptr);
2528 clear_mon_lite(p_ptr->current_floor_ptr);
2529 term_key_push(SPECIAL_KEY_QUIT);
2532 case WM_QUERYENDSESSION: {
2533 if (!game_in_progress || !current_world_ptr->character_generated) {
2540 p_ptr->is_dead = FALSE;
2541 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
2543 p_ptr->panic_save = 1;
2544 signals_ignore_tstp();
2545 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
2546 (void)save_player(p_ptr, SAVE_TYPE_CLOSE_GAME);
2555 process_menus(p_ptr, LOWORD(wParam));
2566 //!< @todo 二重のswitch文。後で分割する.
2568 case SIZE_MINIMIZED: {
2569 for (int i = 1; i < MAX_TERM_DATA; i++) {
2570 if (data[i].visible)
2571 ShowWindow(data[i].w, SW_HIDE);
2576 case SIZE_MAXIMIZED:
2577 case SIZE_RESTORED: {
2578 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
2579 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
2580 if ((td->cols != cols) || (td->rows != rows)) {
2583 if (!IsZoomed(td->w) && !IsIconic(td->w)) {
2584 normsize.x = td->cols;
2585 normsize.y = td->rows;
2588 term_activate(&td->t);
2589 term_resize(td->cols, td->rows);
2590 InvalidateRect(td->w, NULL, TRUE);
2593 td->size_hack = TRUE;
2594 for (int i = 1; i < MAX_TERM_DATA; i++) {
2595 if (data[i].visible)
2596 ShowWindow(data[i].w, SW_SHOW);
2599 td->size_hack = FALSE;
2607 case WM_PALETTECHANGED: {
2608 if ((HWND)wParam == hWnd)
2611 [[fallthrough]]; /* Fall through */
2612 case WM_QUERYNEWPALETTE: {
2616 HDC hdc = GetDC(hWnd);
2617 SelectPalette(hdc, hPal, FALSE);
2618 int i = RealizePalette(hdc);
2620 InvalidateRect(hWnd, NULL, TRUE);
2622 ReleaseDC(hWnd, hdc);
2626 if (!wParam || HIWORD(lParam))
2629 for (int i = 1; i < MAX_TERM_DATA; i++) {
2630 if (!data[i].posfix)
2631 term_window_pos(&data[i], hWnd);
2637 case WM_ACTIVATEAPP: {
2638 if (IsIconic(td->w))
2641 for (int i = 1; i < MAX_TERM_DATA; i++) {
2642 if (data[i].visible) {
2643 if (wParam == TRUE) {
2644 ShowWindow(data[i].w, SW_SHOW);
2646 ShowWindow(data[i].w, SW_HIDE);
2651 [[fallthrough]]; /* Fall through */
2653 if (wParam == FALSE && keep_subwindows) {
2654 for (int i = 0; i < MAX_TERM_DATA; i++) {
2655 if (data[i].visible) {
2656 ShowWindow(data[i].w, SW_SHOW);
2663 return DefWindowProc(hWnd, uMsg, wParam, lParam);
2667 * @todo WNDCLASSに影響があるのでplayer_type*の追加は保留
2669 LRESULT PASCAL AngbandListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2673 td = (term_data *)GetWindowLong(hWnd, 0);
2677 SetWindowLong(hWnd, 0, (LONG)(my_td));
2683 case WM_GETMINMAXINFO: {
2687 lpmmi = (MINMAXINFO *)lParam;
2691 rc.left = rc.top = 0;
2692 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
2693 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
2695 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
2696 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
2697 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
2708 td->size_hack = TRUE;
2710 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
2711 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
2712 if ((td->cols != cols) || (td->rows != rows)) {
2713 term_type *old_term = Term;
2716 term_activate(&td->t);
2717 term_resize(td->cols, td->rows);
2718 term_activate(old_term);
2719 InvalidateRect(td->w, NULL, TRUE);
2720 p_ptr->window_flags = 0xFFFFFFFF;
2721 handle_stuff(p_ptr);
2724 td->size_hack = FALSE;
2728 BeginPaint(hWnd, &ps);
2730 term_data_redraw(td);
2731 EndPaint(hWnd, &ps);
2736 if (process_keydown(wParam, lParam))
2743 term_no_press = FALSE;
2745 term_keypress(wParam);
2748 case WM_PALETTECHANGED: {
2749 if ((HWND)wParam == hWnd)
2752 [[fallthrough]]; /* Fall through */
2753 case WM_QUERYNEWPALETTE: {
2757 HDC hdc = GetDC(hWnd);
2758 SelectPalette(hdc, hPal, FALSE);
2759 int i = RealizePalette(hdc);
2761 InvalidateRect(hWnd, NULL, TRUE);
2763 ReleaseDC(hWnd, hdc);
2766 case WM_NCLBUTTONDOWN: {
2767 if (wParam == HTCLOSE)
2770 if (wParam == HTSYSMENU) {
2772 td->visible = FALSE;
2773 ShowWindow(td->w, SW_HIDE);
2783 return DefWindowProc(hWnd, uMsg, wParam, lParam);
2787 * Display warning message (see "z-util.c")
2789 static void hack_plog(concptr str)
2793 MessageBox(NULL, str, "警告!", MB_ICONEXCLAMATION | MB_OK);
2795 MessageBox(NULL, str, "Warning", MB_ICONEXCLAMATION | MB_OK);
2801 * Display error message and quit (see "z-util.c")
2803 static void hack_quit(concptr str)
2807 MessageBox(NULL, str, "エラー!", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2809 MessageBox(NULL, str, "Error", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2813 UnregisterClass(AppName, hInstance);
2821 * Display warning message (see "z-util.c")
2823 static void hook_plog(concptr str)
2827 MessageBox(data[0].w, str, "警告!", MB_ICONEXCLAMATION | MB_OK);
2829 MessageBox(data[0].w, str, "Warning", MB_ICONEXCLAMATION | MB_OK);
2835 * Display error message and quit (see "z-util.c")
2837 static void hook_quit(concptr str)
2841 MessageBox(data[0].w, str, "エラー!", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2843 MessageBox(data[0].w, str, "Error", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2848 for (int i = MAX_TERM_DATA - 1; i >= 0; --i) {
2849 term_force_font(&data[i], NULL);
2850 if (data[i].font_want)
2851 string_free(data[i].font_want);
2853 DestroyWindow(data[i].w);
2857 if (infGraph.hPalette)
2858 DeleteObject(infGraph.hPalette);
2859 if (infGraph.hBitmap)
2860 DeleteObject(infGraph.hBitmap);
2861 if (infMask.hPalette)
2862 DeleteObject(infMask.hPalette);
2863 if (infMask.hBitmap)
2864 DeleteObject(infMask.hBitmap);
2866 DeleteObject(hbrYellow);
2872 UnregisterClass(AppName, hInstance);
2882 static void init_stuff(void)
2885 GetModuleFileName(hInstance, path, 512);
2887 strcpy(path + strlen(path) - 4, ".INI");
2888 ini_file = string_make(path);
2889 int i = strlen(path);
2891 for (; i > 0; i--) {
2892 if (path[i] == '\\') {
2897 strcpy(path + i + 1, "lib\\");
2898 validate_dir(path, TRUE);
2899 init_file_paths(path, path);
2900 validate_dir(ANGBAND_DIR_APEX, FALSE);
2901 validate_dir(ANGBAND_DIR_BONE, FALSE);
2902 if (!check_dir(ANGBAND_DIR_EDIT)) {
2903 validate_dir(ANGBAND_DIR_DATA, TRUE);
2905 validate_dir(ANGBAND_DIR_DATA, FALSE);
2908 validate_dir(ANGBAND_DIR_FILE, TRUE);
2909 validate_dir(ANGBAND_DIR_HELP, FALSE);
2910 validate_dir(ANGBAND_DIR_INFO, FALSE);
2911 validate_dir(ANGBAND_DIR_PREF, TRUE);
2912 validate_dir(ANGBAND_DIR_SAVE, FALSE);
2913 validate_dir(ANGBAND_DIR_DEBUG_SAVE, FALSE);
2914 validate_dir(ANGBAND_DIR_USER, TRUE);
2915 validate_dir(ANGBAND_DIR_XTRA, TRUE);
2916 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
2918 validate_file(path);
2919 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
2920 ANGBAND_DIR_XTRA_GRAF = string_make(path);
2921 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
2923 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
2924 ANGBAND_DIR_XTRA_SOUND = string_make(path);
2925 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
2927 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
2928 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
2929 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
2933 * @brief コマンドラインから全スポイラー出力を行う
2934 * Create Spoiler files from Command Line
2935 * @return spoiler_output_status
2937 static spoiler_output_status create_debug_spoiler(LPSTR cmd_line)
2943 return SPOILER_OUTPUT_CANCEL;
2944 option = "--output-spoilers";
2946 if (strncmp(s, option, strlen(option)) != 0)
2947 return SPOILER_OUTPUT_CANCEL;
2950 init_angband(p_ptr, process_autopick_file_command, TRUE);
2952 return output_all_spoilers();
2956 * @todo よく見るとhMutexはちゃんと使われていない……?
2957 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
2959 static bool is_already_running(void)
2962 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
2963 if (GetLastError() == ERROR_ALREADY_EXISTS) {
2971 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
2973 int WINAPI WinMain(_In_ HINSTANCE hInst, _In_opt_ HINSTANCE hPrevInst, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
2979 setlocale(LC_ALL, "ja_JP");
2982 if (is_already_running()) {
2984 NULL, _("変愚蛮怒はすでに起動しています。", "Hengband is already running."), _("エラー!", "Error"), MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
2988 switch (create_debug_spoiler(lpCmdLine)) {
2989 case SPOILER_OUTPUT_SUCCESS:
2990 fprintf(stdout, "Successfully created a spoiler file.");
2993 case SPOILER_OUTPUT_FAIL_FOPEN:
2994 fprintf(stderr, "Cannot create spoiler file.");
2997 case SPOILER_OUTPUT_FAIL_FCLOSE:
2998 fprintf(stderr, "Cannot close spoiler file.");
3005 if (hPrevInst == NULL) {
3006 wc.style = CS_CLASSDC;
3007 wc.lpfnWndProc = AngbandWndProc;
3010 wc.hInstance = hInst;
3011 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
3012 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
3013 wc.hbrBackground = static_cast<HBRUSH>(GetStockObject(BLACK_BRUSH));
3014 wc.lpszMenuName = AppName;
3015 wc.lpszClassName = AppName;
3017 if (!RegisterClass(&wc))
3020 wc.lpfnWndProc = AngbandListProc;
3021 wc.lpszMenuName = NULL;
3022 wc.lpszClassName = AngList;
3024 if (!RegisterClass(&wc))
3028 plog_aux = hack_plog;
3029 quit_aux = hack_quit;
3030 core_aux = hack_quit;
3033 for (int i = 0; special_key_list[i]; ++i) {
3034 special_key[special_key_list[i]] = TRUE;
3037 for (int i = 0; ignore_key_list[i]; ++i) {
3038 ignore_key[ignore_key_list[i]] = TRUE;
3042 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
3043 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
3044 ReleaseDC(NULL, hdc);
3046 for (int i = 0; i < 256; i++) {
3047 byte rv = angband_color_table[i][1];
3048 byte gv = angband_color_table[i][2];
3049 byte bv = angband_color_table[i][3];
3050 win_clr[i] = PALETTERGB(rv, gv, bv);
3051 angband_color_table[i][0] = win_pal[i];
3060 plog_aux = hook_plog;
3061 quit_aux = hook_quit;
3062 core_aux = hook_quit;
3064 ANGBAND_SYS = "win";
3065 if (7 != GetKeyboardType(0))
3066 ANGBAND_KEYBOARD = "0";
3068 switch (GetKeyboardType(1)) {
3076 ANGBAND_KEYBOARD = "NEC98";
3080 ANGBAND_KEYBOARD = "JAPAN";
3085 term_activate(term_screen);
3086 init_angband(p_ptr, process_autopick_file_command, FALSE);
3088 check_for_save_file(p_ptr, lpCmdLine);
3089 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
3091 while (GetMessage(&msg, NULL, 0, 0)) {
3092 TranslateMessage(&msg);
3093 DispatchMessage(&msg);
3099 #endif /* WINDOWS */