2 * todo main関数を含むファイルの割に長過ぎる。main-win-utils.cなどといった形で分割したい
4 * @brief Windows版固有実装(メインエントリポイント含む)
6 * @author Hengband Team
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 * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
78 * use with the "winhelp.exe" program. These files *may* be available
79 * at the ftp site somewhere, but I have not seen them.
83 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
85 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
87 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
88 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
92 #include "autopick/autopick-pref-processor.h"
93 #include "cmd-io/cmd-process-screen.h"
94 #include "cmd-io/cmd-save.h"
95 #include "core/game-play.h"
96 #include "core/player-processor.h"
97 #include "core/scores.h"
98 #include "core/special-internal-keys.h"
99 #include "core/stuff-handler.h"
100 #include "core/visuals-reseter.h"
101 #include "dungeon/quest.h"
102 #include "floor/floor-base-definitions.h"
103 #include "floor/floor-events.h"
104 #include "game-option/game-play-options.h"
105 #include "game-option/runtime-arguments.h"
106 #include "game-option/special-options.h"
107 #include "io/files-util.h"
109 #include "io/input-key-acceptor.h"
110 #include "io/record-play-movie.h"
111 #include "io/signal-handlers.h"
112 #include "io/write-diary.h"
113 #include "main/angband-initializer.h"
114 #include "main/music-definitions-table.h"
115 #include "main/sound-definitions-table.h"
116 #include "main/sound-of-music.h"
117 #include "monster-floor/monster-lite.h"
118 #include "system/angband-version.h"
119 #include "system/angband.h"
120 #include "system/floor-type-definition.h"
121 #include "system/system-variables.h"
122 #include "term/gameterm.h"
123 #include "term/screen-processor.h"
124 #include "term/term-color-types.h"
125 #include "util/angband-files.h"
126 #include "util/int-char-converter.h"
127 #include "util/string-processor.h"
128 #include "view/display-map.h"
129 #include "view/display-messages.h"
130 #include "wizard/spoiler-util.h"
131 #include "wizard/wizard-spoiler.h"
132 #include "world/world.h"
135 #include "dungeon/dungeon.h"
136 #include "save/save.h"
142 * Available graphic modes
144 #define GRAPHICS_NONE 0
145 #define GRAPHICS_ORIGINAL 1
146 #define GRAPHICS_ADAM_BOLT 2
147 #define GRAPHICS_HENGBAND 3
150 * Menu constants -- see "ANGBAND.RC"
152 #define IDM_FILE_NEW 100
153 #define IDM_FILE_OPEN 101
154 #define IDM_FILE_SAVE 110
155 #define IDM_FILE_SCORE 120
156 #define IDM_FILE_MOVIE 121
157 #define IDM_FILE_EXIT 130
159 #define IDM_WINDOW_VIS_0 200
160 #define IDM_WINDOW_VIS_1 201
161 #define IDM_WINDOW_VIS_2 202
162 #define IDM_WINDOW_VIS_3 203
163 #define IDM_WINDOW_VIS_4 204
164 #define IDM_WINDOW_VIS_5 205
165 #define IDM_WINDOW_VIS_6 206
166 #define IDM_WINDOW_VIS_7 207
168 #define IDM_WINDOW_FONT_0 210
169 #define IDM_WINDOW_FONT_1 211
170 #define IDM_WINDOW_FONT_2 212
171 #define IDM_WINDOW_FONT_3 213
172 #define IDM_WINDOW_FONT_4 214
173 #define IDM_WINDOW_FONT_5 215
174 #define IDM_WINDOW_FONT_6 216
175 #define IDM_WINDOW_FONT_7 217
177 #define IDM_WINDOW_POS_0 220
178 #define IDM_WINDOW_POS_1 221
179 #define IDM_WINDOW_POS_2 222
180 #define IDM_WINDOW_POS_3 223
181 #define IDM_WINDOW_POS_4 224
182 #define IDM_WINDOW_POS_5 225
183 #define IDM_WINDOW_POS_6 226
184 #define IDM_WINDOW_POS_7 227
186 #define IDM_WINDOW_BIZ_0 230
187 #define IDM_WINDOW_BIZ_1 231
188 #define IDM_WINDOW_BIZ_2 232
189 #define IDM_WINDOW_BIZ_3 233
190 #define IDM_WINDOW_BIZ_4 234
191 #define IDM_WINDOW_BIZ_5 235
192 #define IDM_WINDOW_BIZ_6 236
193 #define IDM_WINDOW_BIZ_7 237
195 #define IDM_WINDOW_I_WID_0 240
196 #define IDM_WINDOW_I_WID_1 241
197 #define IDM_WINDOW_I_WID_2 242
198 #define IDM_WINDOW_I_WID_3 243
199 #define IDM_WINDOW_I_WID_4 244
200 #define IDM_WINDOW_I_WID_5 245
201 #define IDM_WINDOW_I_WID_6 246
202 #define IDM_WINDOW_I_WID_7 247
204 #define IDM_WINDOW_D_WID_0 250
205 #define IDM_WINDOW_D_WID_1 251
206 #define IDM_WINDOW_D_WID_2 252
207 #define IDM_WINDOW_D_WID_3 253
208 #define IDM_WINDOW_D_WID_4 254
209 #define IDM_WINDOW_D_WID_5 255
210 #define IDM_WINDOW_D_WID_6 256
211 #define IDM_WINDOW_D_WID_7 257
213 #define IDM_WINDOW_I_HGT_0 260
214 #define IDM_WINDOW_I_HGT_1 261
215 #define IDM_WINDOW_I_HGT_2 262
216 #define IDM_WINDOW_I_HGT_3 263
217 #define IDM_WINDOW_I_HGT_4 264
218 #define IDM_WINDOW_I_HGT_5 265
219 #define IDM_WINDOW_I_HGT_6 266
220 #define IDM_WINDOW_I_HGT_7 267
222 #define IDM_WINDOW_D_HGT_0 270
223 #define IDM_WINDOW_D_HGT_1 271
224 #define IDM_WINDOW_D_HGT_2 272
225 #define IDM_WINDOW_D_HGT_3 273
226 #define IDM_WINDOW_D_HGT_4 274
227 #define IDM_WINDOW_D_HGT_5 275
228 #define IDM_WINDOW_D_HGT_6 276
229 #define IDM_WINDOW_D_HGT_7 277
231 #define IDM_WINDOW_KEEP_SUBWINDOWS 280
233 #define IDM_OPTIONS_NO_GRAPHICS 400
234 #define IDM_OPTIONS_OLD_GRAPHICS 401
235 #define IDM_OPTIONS_NEW_GRAPHICS 402
236 #define IDM_OPTIONS_NEW2_GRAPHICS 403
237 #define IDM_OPTIONS_BIGTILE 409
238 #define IDM_OPTIONS_SOUND 410
239 #define IDM_OPTIONS_MUSIC 411
240 #define IDM_OPTIONS_SAVER 420
241 #define IDM_OPTIONS_MAP 430
242 #define IDM_OPTIONS_BG 440
243 #define IDM_OPTIONS_OPEN_BG 441
245 #define IDM_DUMP_SCREEN_HTML 450
247 #define IDM_HELP_CONTENTS 901
250 * Exclude parts of WINDOWS.H that are not needed (Win32)
252 #define WIN32_LEAN_AND_MEAN
253 #define NONLS /* All NLS defines and routines */
254 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
255 #define NOMCX /* Modem Configuration Extensions */
258 * Include the "windows" support file
263 * Exclude parts of MMSYSTEM.H that are not needed
265 #define MMNODRV /* Installable driver support */
266 #define MMNOWAVE /* Waveform support */
267 #define MMNOMIDI /* MIDI support */
268 #define MMNOAUX /* Auxiliary audio support */
269 #define MMNOTIMER /* Timer support */
270 #define MMNOJOY /* Joystick support */
271 #define MMNOMCI /* MCI support */
272 #define MMNOMMIO /* Multimedia file I/O support */
274 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
275 #define MOUSE_SENS 40
278 * Include some more files. Note: the Cygnus Cygwin compiler
279 * doesn't use mmsystem.h instead it includes the winmm library
280 * which performs a similar function.
283 #include <mmsystem.h>
286 * Include the support for loading bitmaps
288 #include "term/readdib.h"
290 #define MoveTo(H, X, Y) MoveToEx(H, X, Y, NULL)
293 * Foreground color bits
295 #define VID_BLACK 0x00
296 #define VID_BLUE 0x01
297 #define VID_GREEN 0x02
298 #define VID_CYAN 0x03
300 #define VID_MAGENTA 0x05
301 #define VID_YELLOW 0x06
302 #define VID_WHITE 0x07
307 #define VID_BRIGHT 0x08
311 * @brief ターム情報構造体 / Extra "term" data
314 * pos_x / pos_y は各タームの左上点座標を指す。
317 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
318 * 1ドットずつ調整するステータスを指す。
319 * また、フォントを変更すると都度自動調整される。
322 * Note the use of "font_want" for the names of the font file requested by
323 * the user, and the use of "font_file" for the currently active font file.
325 * The "font_file" is uppercased, and takes the form "8X13.FON", while
326 * "font_want" can be in almost any form as long as it could be construed
327 * as attempting to represent the name of a font.
338 TERM_LEN rows; /* int -> uint */
341 uint pos_x; //!< タームの左上X座標
342 uint pos_y; //!< タームの左上Y座標
357 int font_wid; //!< フォント横幅
358 int font_hgt; //!< フォント縦幅
359 int tile_wid; //!< タイル横幅
360 int tile_hgt; //!< タイル縦幅
371 #define MAX_TERM_DATA 8 //!< Maximum number of windows
373 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
374 static term_data *my_td; //!< Hack -- global "window creation" pointer
375 POINT normsize; //!< Remember normal size of main window when maxmized
378 * was main window maximized on previous playing
380 bool win_maximized = FALSE;
385 bool game_in_progress = FALSE;
388 * note when "open"/"new" become valid
390 bool initialized = FALSE;
393 * screen paletted, i.e. 256 colors
395 bool paletted = FALSE;
398 * 16 colors screen, don't use RGB()
400 bool colors16 = FALSE;
403 * Saved instance handle
405 static HINSTANCE hInstance;
408 * Yellow brush for the cursor
410 static HBRUSH hbrYellow;
420 static HPALETTE hPal;
423 static HBITMAP hBG = NULL;
424 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
425 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
428 * The screen saver window
430 static HWND hwndSaver;
433 * 現在使用中のタイルID(0ならば未使用)
434 * Flag set once "graphics" has been initialized
436 static byte current_graphics_mode = 0;
441 static DIBINIT infGraph;
444 * The global bitmap mask
446 static DIBINIT infMask;
449 * Flag set once "sound" has been initialized
451 static bool can_use_sound = FALSE;
454 * Show sub-windows even when Hengband is not in focus
456 static bool keep_subwindows = TRUE;
458 #define SAMPLE_SOUND_MAX 16
460 * An array of sound file names
462 static concptr sound_file[SOUND_MAX][SAMPLE_SOUND_MAX];
464 #define SAMPLE_MUSIC_MAX 16
465 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
466 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
467 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
468 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
469 static bool can_use_music = FALSE;
471 static MCI_OPEN_PARMS mop;
472 static char mci_device_type[256];
474 static int current_music_type = TERM_XTRA_MUSIC_MUTE;
475 static int current_music_id = 0;
476 static char current_music_path[1024];
479 * Full path to ANGBAND.INI
481 static concptr ini_file = NULL;
484 * Name of application
486 static concptr AppName = "ANGBAND";
489 * Name of sub-window type
491 static concptr AngList = "AngList";
496 static concptr ANGBAND_DIR_XTRA_GRAF;
497 static concptr ANGBAND_DIR_XTRA_SOUND;
498 static concptr ANGBAND_DIR_XTRA_HELP;
499 static concptr ANGBAND_DIR_XTRA_MUSIC;
502 * The "complex" color values
504 static COLORREF win_clr[256];
507 * Flag for macro trigger with dump ASCII
509 static bool term_no_press = FALSE;
514 static bool mouse_down = FALSE;
515 static bool paint_rect = FALSE;
516 static TERM_LEN mousex = 0, mousey = 0;
517 static TERM_LEN oldx, oldy;
520 * @brief The "simple" color values
522 * See "main-ibm.c" for original table information
523 * The entries below are taken from the "color bits" defined above.
524 * Note that many of the choices below suck, but so do crappy monitors.
526 static BYTE win_pal[256] = {
527 VID_BLACK, /* Dark */
528 VID_WHITE, /* White */
529 VID_CYAN, /* Slate XXX */
530 VID_RED | VID_BRIGHT, /* Orange XXX */
532 VID_GREEN, /* Green */
534 VID_YELLOW, /* Umber XXX */
535 VID_BLACK | VID_BRIGHT, /* Light Dark */
536 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
537 VID_MAGENTA, /* Violet XXX */
538 VID_YELLOW | VID_BRIGHT, /* Yellow */
539 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
540 VID_GREEN | VID_BRIGHT, /* Light Green */
541 VID_BLUE | VID_BRIGHT, /* Light Blue */
542 VID_YELLOW /* Light Umber XXX */
546 * Hack -- define which keys are "special"
548 static bool special_key[256];
549 static bool ignore_key[256];
552 * Hack -- initialization list for "special_key"
554 static byte special_key_list[] = {
555 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,
556 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,
557 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,
558 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,
559 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,
563 static byte ignore_key_list[] = {
564 VK_ESCAPE, VK_TAB, VK_SPACE, 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
565 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 */
568 /* Function prototype */
570 static bool is_already_running(void);
573 static void delete_bg(void)
581 static int init_bg(void)
583 char *bmfile = bg_bitmap_file;
588 hBG = static_cast<HBITMAP>(LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE));
590 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
599 static void DrawBG(HDC hdc, RECT *r)
604 int x = r->left, y = r->top;
608 GetObject(hBG, sizeof(bm), &bm);
609 int swid = bm.bmWidth;
610 int shgt = bm.bmHeight;
612 HDC hdcSrc = CreateCompatibleDC(hdc);
613 HBITMAP hOld = static_cast<HBITMAP>(SelectObject(hdcSrc, hBG));
617 int cwid = MIN(swid - sx, r->right - nx);
620 int chgt = MIN(shgt - sy, r->bottom - ny);
621 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
623 } while (ny < r->bottom);
627 } while (nx < r->right);
629 SelectObject(hdcSrc, hOld);
634 * Check for existance of a file
636 static bool check_file(concptr s)
640 DWORD attrib = GetFileAttributes(path);
641 if (attrib == INVALID_FILE_NAME)
643 if (attrib & FILE_ATTRIBUTE_DIRECTORY)
650 * Check for existance of a directory
652 static bool check_dir(concptr s)
656 int i = strlen(path);
657 if (i && (path[i - 1] == '\\'))
660 DWORD attrib = GetFileAttributes(path);
661 if (attrib == INVALID_FILE_NAME)
663 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY))
672 static void validate_file(concptr s)
677 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
681 * Validate a directory
683 static void validate_dir(concptr s, bool vital)
689 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
690 } else if (mkdir(s)) {
691 quit_fmt("Unable to create directory:\n%s", s);
696 * @brief (Windows版固有実装)Get the "size" for a window
698 static void term_getsize(term_data *td)
705 TERM_LEN wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
706 TERM_LEN hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
710 GetWindowRect(td->w, &rw);
711 GetClientRect(td->w, &rc);
713 td->size_wid = (rw.right - rw.left) - (rc.right - rc.left) + wid;
714 td->size_hgt = (rw.bottom - rw.top) - (rc.bottom - rc.top) + hgt;
719 /* Tempolary calculation */
724 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
725 td->size_wid = rc.right - rc.left;
726 td->size_hgt = rc.bottom - rc.top;
731 * Write the "prefs" for a single term
733 static void save_prefs_aux(int i)
735 term_data *td = &data[i];
736 GAME_TEXT sec_name[128];
742 sprintf(sec_name, "Term-%d", i);
745 strcpy(buf, td->visible ? "1" : "0");
746 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
750 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "MS ゴシック");
752 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "Courier");
755 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
757 wsprintf(buf, "%d", td->lf.lfWidth);
758 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
759 wsprintf(buf, "%d", td->lf.lfHeight);
760 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
761 wsprintf(buf, "%d", td->lf.lfWeight);
762 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
764 strcpy(buf, td->bizarre ? "1" : "0");
765 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
767 wsprintf(buf, "%d", td->tile_wid);
768 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
770 wsprintf(buf, "%d", td->tile_hgt);
771 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
773 WINDOWPLACEMENT lpwndpl;
774 lpwndpl.length = sizeof(WINDOWPLACEMENT);
775 GetWindowPlacement(td->w, &lpwndpl);
777 RECT rc = lpwndpl.rcNormalPosition;
779 wsprintf(buf, "%d", normsize.x);
781 wsprintf(buf, "%d", td->cols);
783 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
786 wsprintf(buf, "%d", normsize.y);
788 wsprintf(buf, "%d", td->rows);
790 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
792 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
793 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
796 GetWindowRect(td->w, &rc);
797 wsprintf(buf, "%d", rc.left);
798 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
800 wsprintf(buf, "%d", rc.top);
801 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
803 strcpy(buf, td->posfix ? "1" : "0");
804 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
810 * We assume that the windows have all been initialized
812 static void save_prefs(void)
815 sprintf(buf, "%d", arg_graphics);
816 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
818 strcpy(buf, arg_bigtile ? "1" : "0");
819 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
821 strcpy(buf, arg_sound ? "1" : "0");
822 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
824 strcpy(buf, arg_music ? "1" : "0");
825 WritePrivateProfileString("Angband", "Music", buf, ini_file);
827 strcpy(buf, use_bg ? "1" : "0");
828 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
829 WritePrivateProfileString("Angband", "BackGroundBitmap", bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
831 int path_length = strlen(ANGBAND_DIR) - 4; /* \libの4文字分を削除 */
833 strncat(tmp, ANGBAND_DIR, path_length);
835 int n = strncmp(tmp, savefile, path_length);
837 char relative_path[1024] = "";
838 snprintf(relative_path, sizeof(relative_path), ".\\%s", (savefile + path_length));
839 WritePrivateProfileString("Angband", "SaveFile", relative_path, ini_file);
841 WritePrivateProfileString("Angband", "SaveFile", savefile, ini_file);
844 strcpy(buf, keep_subwindows ? "1" : "0");
845 WritePrivateProfileString("Angband", "KeepSubwindows", buf, ini_file);
847 for (int i = 0; i < MAX_TERM_DATA; ++i) {
853 * Load the "prefs" for a single term
855 static void load_prefs_aux(int i)
857 term_data *td = &data[i];
858 GAME_TEXT sec_name[128];
861 int dispx = GetSystemMetrics(SM_CXVIRTUALSCREEN);
862 int dispy = GetSystemMetrics(SM_CYVIRTUALSCREEN);
866 sprintf(sec_name, "Term-%d", i);
867 sprintf(sec_name, "Term-%d", i);
869 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
873 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
875 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
878 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
880 td->font_want = string_make(tmp);
883 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
884 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
885 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
887 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
888 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
890 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
891 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
892 normsize.x = td->cols;
893 normsize.y = td->rows;
896 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
899 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
900 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
901 td->pos_x = MIN(MAX(0, posx), dispx - 128);
902 td->pos_y = MIN(MAX(0, posy), dispy - 128);
905 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
912 static void load_prefs(void)
914 arg_graphics = (byte)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
915 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
916 use_bigtile = arg_bigtile;
917 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
918 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
919 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
920 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
921 GetPrivateProfileString("Angband", "SaveFile", "", savefile, 1023, ini_file);
923 int n = strncmp(".\\", savefile, 2);
925 int path_length = strlen(ANGBAND_DIR) - 4; /* \libの4文字分を削除 */
927 strncat(tmp, ANGBAND_DIR, path_length);
928 strncat(tmp, savefile + 2, strlen(savefile) - 2 + path_length);
929 strncpy(savefile, tmp, strlen(tmp));
932 keep_subwindows = (GetPrivateProfileInt("Angband", "KeepSubwindows", 0, ini_file) != 0);
933 for (int i = 0; i < MAX_TERM_DATA; ++i) {
939 * - Taken from files.c.
941 * Extract "tokens" from a buffer
943 * This function uses "whitespace" as delimiters, and treats any amount of
944 * whitespace as a single delimiter. We will never return any empty tokens.
945 * When given an empty buffer, or a buffer containing only "whitespace", we
946 * will return no tokens. We will never extract more than "num" tokens.
948 * By running a token through the "text_to_ascii()" function, you can allow
949 * that token to include (encoded) whitespace, using "\s" to encode spaces.
951 * We save pointers to the tokens in "tokens", and return the number found.
953 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
960 for (; *s && iswspace(*s); ++s) /* loop */
966 for (t = s; *t && !iswspace(*t); ++t) /* loop */
979 static void load_sound_prefs(void)
984 char *zz[SAMPLE_SOUND_MAX];
986 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound_debug.cfg");
987 if (GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path) == 0) {
988 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
989 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
992 for (int i = 0; i < SOUND_MAX; i++) {
993 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
994 int num = tokenize_whitespace(tmp, SAMPLE_SOUND_MAX, zz);
995 for (int j = 0; j < num; j++) {
996 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
997 if (check_file(wav_path))
998 sound_file[i][j] = string_make(zz[j]);
1003 static void load_music_prefs(void)
1006 char ini_path[1024];
1007 char wav_path[1024];
1008 char *zz[SAMPLE_MUSIC_MAX];
1011 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music_debug.cfg");
1012 if (GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path) == 0) {
1013 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1014 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1017 for (int i = 0; i < MUSIC_BASIC_MAX; i++) {
1018 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1019 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1020 for (int j = 0; j < num; j++) {
1021 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1022 if (check_file(wav_path))
1023 music_file[i][j] = string_make(zz[j]);
1027 for (int i = 0; i < current_world_ptr->max_d_idx; i++) {
1028 sprintf(key, "dungeon%03d", i);
1029 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1030 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1031 for (int j = 0; j < num; j++) {
1032 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1033 if (check_file(wav_path))
1034 dungeon_music_file[i][j] = string_make(zz[j]);
1038 for (int i = 0; i < max_q_idx; i++) {
1039 sprintf(key, "quest%03d", i);
1040 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1041 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1042 for (int j = 0; j < num; j++) {
1043 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1044 if (check_file(wav_path))
1045 quest_music_file[i][j] = string_make(zz[j]);
1049 for (int i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1051 sprintf(key, "town%03d", i);
1052 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1053 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1054 for (int j = 0; j < num; j++) {
1055 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1056 if (check_file(wav_path))
1057 town_music_file[i][j] = string_make(zz[j]);
1063 * Create the new global palette based on the bitmap palette
1064 * (if any), and the standard 16 entry palette derived from
1065 * "win_clr[]" which is used for the basic 16 Angband colors.
1067 * This function is never called before all windows are ready.
1069 * This function returns FALSE if the new palette could not be
1070 * prepared, which should normally be a fatal error. XXX XXX
1072 * Note that only some machines actually use a "palette".
1074 static int new_palette(void)
1079 LPLOGPALETTE pLogPal;
1080 LPPALETTEENTRY lppe;
1089 HPALETTE hBmPal = static_cast<HPALETTE>(infGraph.hPalette);
1091 lppeSize = 256 * sizeof(PALETTEENTRY);
1092 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1093 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1094 if ((nEntries == 0) || (nEntries > 220)) {
1095 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1096 rnfree(lppe, lppeSize);
1101 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1102 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1103 pLogPal->palVersion = 0x300;
1104 pLogPal->palNumEntries = nEntries + 16;
1105 for (i = 0; i < nEntries; i++) {
1106 pLogPal->palPalEntry[i] = lppe[i];
1109 for (i = 0; i < 16; i++) {
1111 p = &(pLogPal->palPalEntry[i + nEntries]);
1112 p->peRed = GetRValue(win_clr[i]);
1113 p->peGreen = GetGValue(win_clr[i]);
1114 p->peBlue = GetBValue(win_clr[i]);
1115 p->peFlags = PC_NOCOLLAPSE;
1119 rnfree(lppe, lppeSize);
1121 HPALETTE hNewPal = CreatePalette(pLogPal);
1123 quit(_("パレットを作成できません!", "Cannot create palette!"));
1125 rnfree(pLogPal, pLogPalSize);
1127 HDC hdc = GetDC(td->w);
1128 SelectPalette(hdc, hNewPal, 0);
1129 i = RealizePalette(hdc);
1130 ReleaseDC(td->w, hdc);
1132 quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1134 for (i = 1; i < MAX_TERM_DATA; i++) {
1137 SelectPalette(hdc, hNewPal, 0);
1138 ReleaseDC(td->w, hdc);
1149 * @brief グラフィクスを初期化する / Initialize graphics
1152 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1153 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1156 static bool init_graphics(void)
1159 BYTE wid, hgt, twid, thgt, ox, oy;
1162 if (arg_graphics == GRAPHICS_ADAM_BOLT) {
1171 ANGBAND_GRAF = "new";
1172 } else if (arg_graphics == GRAPHICS_HENGBAND) {
1181 ANGBAND_GRAF = "ne2";
1190 ANGBAND_GRAF = "old";
1193 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1194 if (!ReadDIB(data[0].w, buf, &infGraph)) {
1195 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1199 infGraph.CellWidth = wid;
1200 infGraph.CellHeight = hgt;
1201 infGraph.TileWidth = twid;
1202 infGraph.TileHeight = thgt;
1203 infGraph.OffsetX = ox;
1204 infGraph.OffsetY = oy;
1206 if (arg_graphics == GRAPHICS_ADAM_BOLT) {
1207 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1208 if (!ReadDIB(data[0].w, buf, &infMask)) {
1209 plog_fmt("Cannot read bitmap file '%s'", buf);
1214 if (arg_graphics == GRAPHICS_HENGBAND) {
1215 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1216 if (!ReadDIB(data[0].w, buf, &infMask)) {
1217 plog_fmt("Cannot read bitmap file '%s'", buf);
1222 if (!new_palette()) {
1223 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1227 current_graphics_mode = arg_graphics;
1228 return current_graphics_mode != 0;
1234 static void init_music(void)
1236 if (!can_use_music) {
1238 can_use_music = TRUE;
1243 * Hack -- Stop a music
1245 static void stop_music(void)
1247 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1248 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1249 current_music_type = TERM_XTRA_MUSIC_MUTE;
1250 current_music_id = 0;
1251 strcpy(current_music_path, "\0");
1257 static void init_sound(void)
1259 if (!can_use_sound) {
1261 can_use_sound = TRUE;
1268 static void term_window_resize(term_data *td)
1273 SetWindowPos(td->w, 0, 0, 0, td->size_wid, td->size_hgt, SWP_NOMOVE | SWP_NOZORDER);
1274 InvalidateRect(td->w, NULL, TRUE);
1279 * Force the use of a new "font file" for a term_data.
1280 * This function may be called before the "window" is ready.
1281 * This function returns zero only if everything succeeds.
1282 * Note that the "font name" must be capitalized!!!
1284 static errr term_force_font(term_data *td, concptr path)
1287 DeleteObject(td->font_id);
1290 td->font_id = CreateFontIndirect(&(td->lf));
1291 int wid = td->lf.lfWidth;
1292 int hgt = td->lf.lfHeight;
1301 hdcDesktop = GetDC(HWND_DESKTOP);
1302 hfOld = static_cast<HFONT>(SelectObject(hdcDesktop, td->font_id));
1303 GetTextMetrics(hdcDesktop, &tm);
1304 SelectObject(hdcDesktop, hfOld);
1305 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1307 wid = tm.tmAveCharWidth;
1318 * Allow the user to change the font for this window.
1320 static void term_change_font(term_data *td)
1323 memset(&cf, 0, sizeof(cf));
1324 cf.lStructSize = sizeof(cf);
1325 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1326 cf.lpLogFont = &(td->lf);
1328 if (!ChooseFont(&cf))
1331 term_force_font(td, NULL);
1333 td->tile_wid = td->font_wid;
1334 td->tile_hgt = td->font_hgt;
1336 term_window_resize(td);
1340 * Allow the user to lock this window.
1342 static void term_window_pos(term_data *td, HWND hWnd) { SetWindowPos(td->w, hWnd, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); }
1344 static void windows_map(player_type *player_ptr);
1347 * Hack -- redraw a term_data
1349 static void term_data_redraw(player_type *player_ptr, term_data *td)
1351 if (td->map_active) {
1352 windows_map(player_ptr);
1356 term_activate(&td->t);
1358 term_activate(term_screen);
1361 void term_inversed_area(HWND hWnd, int x, int y, int w, int h)
1363 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
1364 int tx = td->size_ow1 + x * td->tile_wid;
1365 int ty = td->size_oh1 + y * td->tile_hgt;
1366 int tw = w * td->tile_wid - 1;
1367 int th = h * td->tile_hgt - 1;
1369 HDC hdc = GetDC(hWnd);
1370 HBRUSH myBrush = CreateSolidBrush(RGB(255, 255, 255));
1371 HBRUSH oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1372 HPEN oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1374 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
1376 SelectObject(hdc, oldBrush);
1377 SelectObject(hdc, oldPen);
1381 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
1383 static errr term_user_win(int n)
1390 * React to global changes
1392 static errr term_xtra_win_react(player_type *player_ptr)
1395 for (int i = 0; i < 256; i++) {
1396 win_pal[i] = angband_color_table[i][0];
1401 bool change = FALSE;
1402 for (int i = 0; i < 256; i++) {
1403 rv = angband_color_table[i][1];
1404 gv = angband_color_table[i][2];
1405 bv = angband_color_table[i][3];
1406 code = PALETTERGB(rv, gv, bv);
1407 if (win_clr[i] != code) {
1414 (void)new_palette();
1417 if (use_sound != arg_sound) {
1419 use_sound = arg_sound;
1422 if (use_music != arg_music) {
1424 use_music = arg_music;
1428 select_floor_music(player_ptr);
1431 if (use_graphics != (arg_graphics > 0)) {
1432 if (arg_graphics && !init_graphics()) {
1433 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
1434 arg_graphics = GRAPHICS_NONE;
1437 use_graphics = (arg_graphics > 0);
1438 reset_visuals(player_ptr, process_autopick_file_command);
1441 for (int i = 0; i < MAX_TERM_DATA; i++) {
1442 term_type *old = Term;
1443 term_data *td = &data[i];
1444 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt)) {
1445 term_activate(&td->t);
1446 term_resize(td->cols, td->rows);
1456 * Process at least one event
1458 static errr term_xtra_win_event(int v)
1462 if (GetMessage(&msg, NULL, 0, 0)) {
1463 TranslateMessage(&msg);
1464 DispatchMessage(&msg);
1467 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
1468 TranslateMessage(&msg);
1469 DispatchMessage(&msg);
1477 * Process all pending events
1479 static errr term_xtra_win_flush(void)
1482 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
1483 TranslateMessage(&msg);
1484 DispatchMessage(&msg);
1491 * Hack -- clear the screen
1493 * Make this more efficient
1495 static errr term_xtra_win_clear(void)
1497 term_data *td = (term_data *)(Term->data);
1500 rc.left = td->size_ow1;
1501 rc.right = rc.left + td->cols * td->tile_wid;
1502 rc.top = td->size_oh1;
1503 rc.bottom = rc.top + td->rows * td->tile_hgt;
1505 HDC hdc = GetDC(td->w);
1506 SetBkColor(hdc, RGB(0, 0, 0));
1507 SelectObject(hdc, td->font_id);
1508 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1516 ReleaseDC(td->w, hdc);
1521 * Hack -- make a noise
1523 static errr term_xtra_win_noise(void)
1525 MessageBeep(MB_ICONASTERISK);
1530 * Hack -- make a sound
1532 static errr term_xtra_win_sound(int v)
1537 if ((v < 0) || (v >= SOUND_MAX))
1541 for (i = 0; i < SAMPLE_SOUND_MAX; i++) {
1542 if (!sound_file[v][i])
1549 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
1550 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
1554 * Hack -- play a music
1556 static errr term_xtra_win_music(int n, int v)
1561 if (n == TERM_XTRA_MUSIC_MUTE)
1568 if (n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX)))
1570 else if (v < 0 || v >= 1000)
1571 return (1); /*!< TODO */
1574 case TERM_XTRA_MUSIC_BASIC:
1575 for (i = 0; i < SAMPLE_MUSIC_MAX; i++)
1576 if (!music_file[v][i])
1579 case TERM_XTRA_MUSIC_DUNGEON:
1580 for (i = 0; i < SAMPLE_MUSIC_MAX; i++)
1581 if (!dungeon_music_file[v][i])
1584 case TERM_XTRA_MUSIC_QUEST:
1585 for (i = 0; i < SAMPLE_MUSIC_MAX; i++)
1586 if (!quest_music_file[v][i])
1589 case TERM_XTRA_MUSIC_TOWN:
1590 for (i = 0; i < SAMPLE_MUSIC_MAX; i++)
1591 if (!town_music_file[v][i])
1601 case TERM_XTRA_MUSIC_BASIC:
1602 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
1604 case TERM_XTRA_MUSIC_DUNGEON:
1605 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
1607 case TERM_XTRA_MUSIC_QUEST:
1608 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
1610 case TERM_XTRA_MUSIC_TOWN:
1611 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
1615 if (current_music_type == n && current_music_id == v)
1618 if (current_music_type != TERM_XTRA_MUSIC_MUTE && n != TERM_XTRA_MUSIC_MUTE)
1619 if (0 == strcmp(current_music_path, buf))
1622 current_music_type = n;
1623 current_music_id = v;
1624 strcpy(current_music_path, buf);
1626 mop.lpstrDeviceType = mci_device_type;
1627 mop.lpstrElementName = buf;
1628 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1629 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1630 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
1631 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
1632 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
1637 * Delay for "x" milliseconds
1639 static int term_xtra_win_delay(int v)
1646 * todo z-termに影響があるのでplayer_typeの追加は保留
1647 * Do a "special thing"
1649 static errr term_xtra_win(int n, int v)
1652 case TERM_XTRA_NOISE: {
1653 return (term_xtra_win_noise());
1655 case TERM_XTRA_MUSIC_BASIC:
1656 case TERM_XTRA_MUSIC_DUNGEON:
1657 case TERM_XTRA_MUSIC_QUEST:
1658 case TERM_XTRA_MUSIC_TOWN:
1659 case TERM_XTRA_MUSIC_MUTE: {
1660 return (term_xtra_win_music(n, v));
1662 case TERM_XTRA_SOUND: {
1663 return (term_xtra_win_sound(v));
1665 case TERM_XTRA_BORED: {
1666 return (term_xtra_win_event(0));
1668 case TERM_XTRA_EVENT: {
1669 return (term_xtra_win_event(v));
1671 case TERM_XTRA_FLUSH: {
1672 return (term_xtra_win_flush());
1674 case TERM_XTRA_CLEAR: {
1675 return (term_xtra_win_clear());
1677 case TERM_XTRA_REACT: {
1678 return (term_xtra_win_react(p_ptr));
1680 case TERM_XTRA_DELAY: {
1681 return (term_xtra_win_delay(v));
1689 * Low level graphics (Assumes valid input).
1691 * Draw a "cursor" at (x,y), using a "yellow box".
1693 static errr term_curs_win(int x, int y)
1695 term_data *td = (term_data *)(Term->data);
1696 int tile_wid, tile_hgt;
1697 if (td->map_active) {
1698 tile_wid = td->map_tile_wid;
1699 tile_hgt = td->map_tile_hgt;
1701 tile_wid = td->tile_wid;
1702 tile_hgt = td->tile_hgt;
1706 rc.left = x * tile_wid + td->size_ow1;
1707 rc.right = rc.left + tile_wid;
1708 rc.top = y * tile_hgt + td->size_oh1;
1709 rc.bottom = rc.top + tile_hgt;
1711 HDC hdc = GetDC(td->w);
1712 FrameRect(hdc, &rc, hbrYellow);
1713 ReleaseDC(td->w, hdc);
1718 * Low level graphics (Assumes valid input).
1720 * Draw a "big cursor" at (x,y), using a "yellow box".
1722 static errr term_bigcurs_win(int x, int y)
1724 term_data *td = (term_data *)(Term->data);
1725 int tile_wid, tile_hgt;
1726 if (td->map_active) {
1727 term_curs_win(x, y);
1730 tile_wid = td->tile_wid;
1731 tile_hgt = td->tile_hgt;
1735 rc.left = x * tile_wid + td->size_ow1;
1736 rc.right = rc.left + 2 * tile_wid;
1737 rc.top = y * tile_hgt + td->size_oh1;
1738 rc.bottom = rc.top + tile_hgt;
1740 HDC hdc = GetDC(td->w);
1741 FrameRect(hdc, &rc, hbrYellow);
1742 ReleaseDC(td->w, hdc);
1747 * Low level graphics (Assumes valid input).
1749 * Erase a "block" of "n" characters starting at (x,y).
1751 static errr term_wipe_win(int x, int y, int n)
1753 term_data *td = (term_data *)(Term->data);
1755 rc.left = x * td->tile_wid + td->size_ow1;
1756 rc.right = rc.left + n * td->tile_wid;
1757 rc.top = y * td->tile_hgt + td->size_oh1;
1758 rc.bottom = rc.top + td->tile_hgt;
1760 HDC hdc = GetDC(td->w);
1761 SetBkColor(hdc, RGB(0, 0, 0));
1762 SelectObject(hdc, td->font_id);
1766 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1768 ReleaseDC(td->w, hdc);
1773 * Low level graphics. Assumes valid input.
1775 * Draw several ("n") chars, with an attr, at a given location.
1777 * All "graphic" data is handled by "term_pict_win()", below.
1779 * One would think there is a more efficient method for telling a window
1780 * what color it should be using to draw with, but perhaps simply changing
1781 * it every time is not too inefficient.
1783 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
1785 term_data *td = (term_data *)(Term->data);
1786 static HBITMAP WALL;
1787 static HBRUSH myBrush, oldBrush;
1789 static bool init_done = FALSE;
1792 WALL = LoadBitmap(hInstance, AppName);
1793 myBrush = CreatePatternBrush(WALL);
1798 rc.left = x * td->tile_wid + td->size_ow1;
1799 rc.right = rc.left + n * td->tile_wid;
1800 rc.top = y * td->tile_hgt + td->size_oh1;
1801 rc.bottom = rc.top + td->tile_hgt;
1803 HDC hdc = GetDC(td->w);
1804 SetBkColor(hdc, RGB(0, 0, 0));
1806 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
1807 } else if (paletted) {
1808 SetTextColor(hdc, win_clr[a & 0x0F]);
1810 SetTextColor(hdc, win_clr[a]);
1813 SelectObject(hdc, td->font_id);
1815 SetBkMode(hdc, TRANSPARENT);
1817 if (td->bizarre || (td->tile_hgt != td->font_hgt) || (td->tile_wid != td->font_wid)) {
1818 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1822 rc.left += ((td->tile_wid - td->font_wid) / 2);
1823 rc.right = rc.left + td->font_wid;
1824 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
1825 rc.bottom = rc.top + td->font_hgt;
1827 for (int i = 0; i < n; i++) {
1829 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1]) {
1830 rc.right += td->font_wid;
1831 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1832 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1833 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1834 SelectObject(hdc, oldBrush);
1835 SelectObject(hdc, oldPen);
1836 rc.right -= td->font_wid;
1838 rc.left += 2 * td->tile_wid;
1839 rc.right += 2 * td->tile_wid;
1840 } else if (iskanji(*(s + i))) /* 2バイト文字 */
1842 rc.right += td->font_wid;
1843 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 2, NULL);
1844 rc.right -= td->font_wid;
1846 rc.left += 2 * td->tile_wid;
1847 rc.right += 2 * td->tile_wid;
1848 } else if (*(s + i) == 127) {
1849 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1850 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1851 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1852 SelectObject(hdc, oldBrush);
1853 SelectObject(hdc, oldPen);
1854 rc.left += td->tile_wid;
1855 rc.right += td->tile_wid;
1857 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1858 rc.left += td->tile_wid;
1859 rc.right += td->tile_wid;
1862 if (*(s + i) == 127) {
1863 oldBrush = static_cast<HBRUSH>(SelectObject(hdc, myBrush));
1864 oldPen = static_cast<HPEN>(SelectObject(hdc, GetStockObject(NULL_PEN)));
1865 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1866 SelectObject(hdc, oldBrush);
1867 SelectObject(hdc, oldPen);
1868 rc.left += td->tile_wid;
1869 rc.right += td->tile_wid;
1871 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1872 rc.left += td->tile_wid;
1873 rc.right += td->tile_wid;
1878 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc, s, n, NULL);
1881 ReleaseDC(td->w, hdc);
1886 * Low level graphics. Assumes valid input.
1888 * Draw an array of "special" attr/char pairs at the given location.
1890 * We use the "term_pict_win()" function for "graphic" data, which are
1891 * encoded by setting the "high-bits" of both the "attr" and the "char"
1892 * data. We use the "attr" to represent the "row" of the main bitmap,
1893 * and the "char" to represent the "col" of the main bitmap. The use
1894 * of this function is induced by the "higher_pict" flag.
1896 * If "graphics" is not available, we simply "wipe" the given grids.
1898 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)
1900 term_data *td = (term_data *)(Term->data);
1903 if (!use_graphics) {
1904 return (term_wipe_win(x, y, n));
1907 TERM_LEN w1 = infGraph.CellWidth;
1908 TERM_LEN h1 = infGraph.CellHeight;
1909 TERM_LEN tw1 = infGraph.TileWidth;
1910 TERM_LEN th1 = infGraph.TileHeight;
1911 TERM_LEN w2, h2, tw2 = 0;
1912 if (td->map_active) {
1913 w2 = td->map_tile_wid;
1914 h2 = td->map_tile_hgt;
1923 TERM_LEN x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
1924 TERM_LEN y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
1925 HDC hdc = GetDC(td->w);
1926 HDC hdcSrc = CreateCompatibleDC(hdc);
1927 HBITMAP hbmSrcOld = static_cast<HBITMAP>(SelectObject(hdcSrc, infGraph.hBitmap));
1929 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1930 hdcMask = CreateCompatibleDC(hdc);
1931 SelectObject(hdcMask, infMask.hBitmap);
1934 for (i = 0; i < n; i++, x2 += w2) {
1935 TERM_COLOR a = ap[i];
1937 int row = (a & 0x7F);
1938 int col = (c & 0x7F);
1939 TERM_LEN x1 = col * w1;
1940 TERM_LEN y1 = row * h1;
1942 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1943 TERM_LEN x3 = (tcp[i] & 0x7F) * w1;
1944 TERM_LEN y3 = (tap[i] & 0x7F) * h1;
1945 tw2 = tw2 * w1 / tw1;
1947 if ((tw1 == tw2) && (th1 == h2)) {
1948 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
1949 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
1950 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
1954 SetStretchBltMode(hdc, COLORONCOLOR);
1955 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
1956 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
1957 if ((x1 != x3) || (y1 != y3)) {
1958 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
1959 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
1965 if ((w1 == tw2) && (h1 == h2)) {
1966 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
1970 SetStretchBltMode(hdc, COLORONCOLOR);
1971 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
1974 SelectObject(hdcSrc, hbmSrcOld);
1976 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1977 SelectObject(hdcMask, hbmSrcOld);
1981 ReleaseDC(td->w, hdc);
1985 static void windows_map(player_type *player_ptr)
1987 term_data *td = &data[0];
1992 term_xtra_win_clear();
1993 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
1994 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
1995 td->map_active = TRUE;
1999 TERM_LEN max_x = player_ptr->current_floor_ptr->width;
2000 TERM_LEN max_y = player_ptr->current_floor_ptr->height;
2003 for (TERM_LEN x = min_x; x < max_x; x++) {
2004 for (TERM_LEN y = min_y; y < max_y; y++) {
2007 map_info(player_ptr, y, x, &a, (char *)&c, &ta, (char *)&tc);
2008 if ((a & 0x80) && (c & 0x80)) {
2009 term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2014 term_curs_win(player_ptr->x - min_x, player_ptr->y - min_y);
2015 term_inkey(&c, TRUE, TRUE);
2017 td->map_active = FALSE;
2018 term_xtra_win_clear();
2023 * Create and initialize a "term_data" given a title
2025 static void term_data_link(term_data *td)
2027 term_type *t = &td->t;
2028 term_init(t, td->cols, td->rows, FILE_READ_BUFF_SIZE);
2029 t->soft_cursor = TRUE;
2030 t->higher_pict = TRUE;
2031 t->attr_blank = TERM_WHITE;
2032 t->char_blank = ' ';
2033 t->user_hook = term_user_win;
2034 t->xtra_hook = term_xtra_win;
2035 t->curs_hook = term_curs_win;
2036 t->bigcurs_hook = term_bigcurs_win;
2037 t->wipe_hook = term_wipe_win;
2038 t->text_hook = term_text_win;
2039 t->pict_hook = term_pict_win;
2040 t->data = (vptr)(td);
2044 * Create the windows
2046 * First, instantiate the "default" values, then read the "ini_file"
2047 * to over-ride selected values, then create the windows, and fonts.
2049 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2050 * must make active to realize the palette.
2052 static void init_windows(void)
2056 WIPE(td, term_data);
2060 td->s = angband_term_name[0];
2076 for (int i = 1; i < MAX_TERM_DATA; i++) {
2078 WIPE(td, term_data);
2079 td->s = angband_term_name[i];
2083 td->visible = FALSE;
2088 td->pos_x = (7 - i) * 30;
2089 td->pos_y = (7 - i) * 20;
2096 /* Atrributes of main window */
2098 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_VISIBLE);
2102 /* Attributes of sub windows */
2103 for (int i = 1; i < MAX_TERM_DATA; i++) {
2105 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2106 td->dwExStyle = (WS_EX_TOOLWINDOW);
2109 /* Font of each window */
2110 for (int i = 0; i < MAX_TERM_DATA; i++) {
2112 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2113 td->lf.lfCharSet = DEFAULT_CHARSET;
2114 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2115 term_force_font(td, NULL);
2117 td->tile_wid = td->font_wid;
2119 td->tile_hgt = td->font_hgt;
2121 term_window_resize(td);
2124 /* Create sub windows */
2125 for (int i = MAX_TERM_DATA - 1; i >= 1; --i) {
2130 = 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);
2134 quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
2136 td->size_hack = TRUE;
2138 term_window_resize(td);
2141 ShowWindow(td->w, SW_SHOW);
2143 td->size_hack = FALSE;
2146 angband_term[i] = &td->t;
2149 /* Activate the window */
2150 SetActiveWindow(td->w);
2154 term_window_pos(td, HWND_TOPMOST);
2156 term_window_pos(td, td->w);
2160 /* Create main window */
2163 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);
2167 quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
2170 td->size_hack = TRUE;
2172 term_window_resize(td);
2173 td->size_hack = FALSE;
2176 angband_term[0] = &td->t;
2177 normsize.x = td->cols;
2178 normsize.y = td->rows;
2181 ShowWindow(td->w, SW_SHOWMAXIMIZED);
2183 ShowWindow(td->w, SW_SHOW);
2185 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2186 (void)new_palette();
2187 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
2188 (void)term_xtra_win_flush();
2194 static void setup_menus(void)
2196 HMENU hm = GetMenu(data[0].w);
2197 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2198 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2199 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2200 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2201 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2203 if (!current_world_ptr->character_generated) {
2204 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
2205 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
2208 if (current_world_ptr->character_generated) {
2209 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_ENABLED);
2212 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_ENABLED);
2213 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_ENABLED);
2215 for (int i = 0; i < MAX_TERM_DATA; i++) {
2216 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2217 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i, (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
2218 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_ENABLED);
2221 for (int i = 0; i < MAX_TERM_DATA; i++) {
2222 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2224 if (data[i].visible) {
2225 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2229 for (int i = 0; i < MAX_TERM_DATA; i++) {
2230 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2231 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i, (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
2232 if (data[i].visible) {
2233 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_ENABLED);
2237 for (int i = 0; i < MAX_TERM_DATA; i++) {
2238 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2239 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i, (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
2240 if (data[i].visible) {
2241 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_ENABLED);
2245 for (int i = 0; i < MAX_TERM_DATA; i++) {
2246 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2247 if (data[i].visible) {
2248 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
2252 for (int i = 0; i < MAX_TERM_DATA; i++) {
2253 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2254 if (data[i].visible) {
2255 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
2259 for (int i = 0; i < MAX_TERM_DATA; i++) {
2260 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2261 if (data[i].visible) {
2262 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2266 for (int i = 0; i < MAX_TERM_DATA; i++) {
2267 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2269 if (data[i].visible) {
2270 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2273 EnableMenuItem(hm, IDM_WINDOW_KEEP_SUBWINDOWS, MF_BYCOMMAND | MF_ENABLED);
2274 CheckMenuItem(hm, IDM_WINDOW_KEEP_SUBWINDOWS, (keep_subwindows ? MF_CHECKED : MF_UNCHECKED));
2276 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2277 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2278 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2279 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2280 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2283 EnableMenuItem(hm, IDM_OPTIONS_SAVER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2286 if (use_graphics != GRAPHICS_NONE)
2287 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
2289 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2291 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
2292 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
2293 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
2294 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS, (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
2295 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE, (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
2296 CheckMenuItem(hm, IDM_OPTIONS_MUSIC, (arg_music ? MF_CHECKED : MF_UNCHECKED));
2297 CheckMenuItem(hm, IDM_OPTIONS_SOUND, (arg_sound ? MF_CHECKED : MF_UNCHECKED));
2298 CheckMenuItem(hm, IDM_OPTIONS_BG, (use_bg ? MF_CHECKED : MF_UNCHECKED));
2301 CheckMenuItem(hm, IDM_OPTIONS_SAVER, (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
2303 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
2304 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
2305 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
2306 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
2307 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
2308 EnableMenuItem(hm, IDM_OPTIONS_SAVER, MF_BYCOMMAND | MF_ENABLED);
2312 * Check for double clicked (or dragged) savefile
2314 * Apparently, Windows copies the entire filename into the first
2315 * piece of the "command line string". Perhaps we should extract
2316 * the "basename" of that filename and append it to the "save" dir.
2318 static void check_for_save_file(player_type *player_ptr, LPSTR cmd_line)
2325 strcpy(savefile, s);
2326 validate_file(savefile);
2327 game_in_progress = TRUE;
2328 play_game(player_ptr, FALSE, FALSE);
2332 * Process a menu command
2334 static void process_menus(player_type *player_ptr, WORD wCmd)
2339 case IDM_FILE_NEW: {
2341 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2342 } else if (game_in_progress) {
2343 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
2345 game_in_progress = TRUE;
2347 strcpy(savefile, "");
2348 play_game(player_ptr, TRUE, FALSE);
2354 case IDM_FILE_OPEN: {
2356 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2357 } else if (game_in_progress) {
2358 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
2360 memset(&ofn, 0, sizeof(ofn));
2361 ofn.lStructSize = sizeof(ofn);
2362 ofn.hwndOwner = data[0].w;
2363 ofn.lpstrFilter = "Save Files (*.)\0*\0";
2364 ofn.nFilterIndex = 1;
2365 ofn.lpstrFile = savefile;
2366 ofn.nMaxFile = 1024;
2367 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
2368 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
2370 if (GetOpenFileName(&ofn)) {
2371 validate_file(savefile);
2372 game_in_progress = TRUE;
2374 play_game(player_ptr, FALSE, FALSE);
2381 case IDM_FILE_SAVE: {
2382 if (game_in_progress && current_world_ptr->character_generated) {
2384 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
2389 do_cmd_save_game(player_ptr, FALSE);
2391 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
2396 case IDM_FILE_EXIT: {
2397 if (game_in_progress && current_world_ptr->character_generated) {
2399 plog(_("今は終了できません。", "You may not do that right now."));
2404 forget_lite(player_ptr->current_floor_ptr);
2405 forget_view(player_ptr->current_floor_ptr);
2406 clear_mon_lite(player_ptr->current_floor_ptr);
2408 term_key_push(SPECIAL_KEY_QUIT);
2415 case IDM_FILE_SCORE: {
2417 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
2418 highscore_fd = fd_open(buf, O_RDONLY);
2419 if (highscore_fd < 0) {
2420 msg_print("Score file unavailable.");
2424 display_scores_aux(0, MAX_HISCORES, -1, NULL);
2425 (void)fd_close(highscore_fd);
2433 case IDM_FILE_MOVIE: {
2435 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2436 } else if (game_in_progress) {
2437 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
2439 memset(&ofn, 0, sizeof(ofn));
2440 ofn.lStructSize = sizeof(ofn);
2441 ofn.hwndOwner = data[0].w;
2442 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
2443 ofn.nFilterIndex = 1;
2444 ofn.lpstrFile = savefile;
2445 ofn.nMaxFile = 1024;
2446 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
2447 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2449 if (GetOpenFileName(&ofn)) {
2450 prepare_browse_movie_without_path_build(savefile);
2451 play_game(player_ptr, FALSE, TRUE);
2459 case IDM_WINDOW_VIS_0: {
2460 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
2463 case IDM_WINDOW_VIS_1:
2464 case IDM_WINDOW_VIS_2:
2465 case IDM_WINDOW_VIS_3:
2466 case IDM_WINDOW_VIS_4:
2467 case IDM_WINDOW_VIS_5:
2468 case IDM_WINDOW_VIS_6:
2469 case IDM_WINDOW_VIS_7: {
2470 int i = wCmd - IDM_WINDOW_VIS_0;
2471 if ((i < 0) || (i >= MAX_TERM_DATA))
2477 ShowWindow(td->w, SW_SHOW);
2478 term_data_redraw(player_ptr, td);
2480 td->visible = FALSE;
2482 ShowWindow(td->w, SW_HIDE);
2487 case IDM_WINDOW_FONT_0:
2488 case IDM_WINDOW_FONT_1:
2489 case IDM_WINDOW_FONT_2:
2490 case IDM_WINDOW_FONT_3:
2491 case IDM_WINDOW_FONT_4:
2492 case IDM_WINDOW_FONT_5:
2493 case IDM_WINDOW_FONT_6:
2494 case IDM_WINDOW_FONT_7: {
2495 int i = wCmd - IDM_WINDOW_FONT_0;
2496 if ((i < 0) || (i >= MAX_TERM_DATA))
2500 term_change_font(td);
2503 case IDM_WINDOW_POS_1:
2504 case IDM_WINDOW_POS_2:
2505 case IDM_WINDOW_POS_3:
2506 case IDM_WINDOW_POS_4:
2507 case IDM_WINDOW_POS_5:
2508 case IDM_WINDOW_POS_6:
2509 case IDM_WINDOW_POS_7: {
2510 int i = wCmd - IDM_WINDOW_POS_0;
2511 if ((i < 0) || (i >= MAX_TERM_DATA))
2515 if (!td->posfix && td->visible) {
2517 term_window_pos(td, HWND_TOPMOST);
2520 term_window_pos(td, data[0].w);
2525 case IDM_WINDOW_BIZ_0:
2526 case IDM_WINDOW_BIZ_1:
2527 case IDM_WINDOW_BIZ_2:
2528 case IDM_WINDOW_BIZ_3:
2529 case IDM_WINDOW_BIZ_4:
2530 case IDM_WINDOW_BIZ_5:
2531 case IDM_WINDOW_BIZ_6:
2532 case IDM_WINDOW_BIZ_7: {
2533 int i = wCmd - IDM_WINDOW_BIZ_0;
2534 if ((i < 0) || (i >= MAX_TERM_DATA))
2538 td->bizarre = !td->bizarre;
2540 term_window_resize(td);
2543 case IDM_WINDOW_I_WID_0:
2544 case IDM_WINDOW_I_WID_1:
2545 case IDM_WINDOW_I_WID_2:
2546 case IDM_WINDOW_I_WID_3:
2547 case IDM_WINDOW_I_WID_4:
2548 case IDM_WINDOW_I_WID_5:
2549 case IDM_WINDOW_I_WID_6:
2550 case IDM_WINDOW_I_WID_7: {
2551 int i = wCmd - IDM_WINDOW_I_WID_0;
2552 if ((i < 0) || (i >= MAX_TERM_DATA))
2558 term_window_resize(td);
2561 case IDM_WINDOW_D_WID_0:
2562 case IDM_WINDOW_D_WID_1:
2563 case IDM_WINDOW_D_WID_2:
2564 case IDM_WINDOW_D_WID_3:
2565 case IDM_WINDOW_D_WID_4:
2566 case IDM_WINDOW_D_WID_5:
2567 case IDM_WINDOW_D_WID_6:
2568 case IDM_WINDOW_D_WID_7: {
2569 int i = wCmd - IDM_WINDOW_D_WID_0;
2570 if ((i < 0) || (i >= MAX_TERM_DATA))
2576 term_window_resize(td);
2579 case IDM_WINDOW_I_HGT_0:
2580 case IDM_WINDOW_I_HGT_1:
2581 case IDM_WINDOW_I_HGT_2:
2582 case IDM_WINDOW_I_HGT_3:
2583 case IDM_WINDOW_I_HGT_4:
2584 case IDM_WINDOW_I_HGT_5:
2585 case IDM_WINDOW_I_HGT_6:
2586 case IDM_WINDOW_I_HGT_7: {
2587 int i = wCmd - IDM_WINDOW_I_HGT_0;
2588 if ((i < 0) || (i >= MAX_TERM_DATA))
2594 term_window_resize(td);
2597 case IDM_WINDOW_D_HGT_0:
2598 case IDM_WINDOW_D_HGT_1:
2599 case IDM_WINDOW_D_HGT_2:
2600 case IDM_WINDOW_D_HGT_3:
2601 case IDM_WINDOW_D_HGT_4:
2602 case IDM_WINDOW_D_HGT_5:
2603 case IDM_WINDOW_D_HGT_6:
2604 case IDM_WINDOW_D_HGT_7: {
2605 int i = wCmd - IDM_WINDOW_D_HGT_0;
2606 if ((i < 0) || (i >= MAX_TERM_DATA))
2612 term_window_resize(td);
2615 case IDM_WINDOW_KEEP_SUBWINDOWS: {
2616 keep_subwindows = !keep_subwindows;
2619 case IDM_OPTIONS_NO_GRAPHICS: {
2621 plog("You may not do that right now.");
2625 if (arg_graphics != GRAPHICS_NONE) {
2626 arg_graphics = GRAPHICS_NONE;
2627 term_xtra_win_react(player_ptr);
2628 term_key_push(KTRL('R'));
2633 case IDM_OPTIONS_OLD_GRAPHICS: {
2635 plog("You may not do that right now.");
2639 if (arg_graphics != GRAPHICS_ORIGINAL) {
2640 arg_graphics = GRAPHICS_ORIGINAL;
2641 term_xtra_win_react(player_ptr);
2642 term_key_push(KTRL('R'));
2647 case IDM_OPTIONS_NEW_GRAPHICS: {
2649 plog("You may not do that right now.");
2653 if (arg_graphics != GRAPHICS_ADAM_BOLT) {
2654 arg_graphics = GRAPHICS_ADAM_BOLT;
2655 term_xtra_win_react(player_ptr);
2656 term_key_push(KTRL('R'));
2661 case IDM_OPTIONS_NEW2_GRAPHICS: {
2663 plog("You may not do that right now.");
2667 if (arg_graphics != GRAPHICS_HENGBAND) {
2668 arg_graphics = GRAPHICS_HENGBAND;
2669 term_xtra_win_react(player_ptr);
2670 term_key_push(KTRL('R'));
2675 case IDM_OPTIONS_BIGTILE: {
2678 plog("You may not do that right now.");
2682 arg_bigtile = !arg_bigtile;
2683 term_activate(&td->t);
2684 term_resize(td->cols, td->rows);
2685 InvalidateRect(td->w, NULL, TRUE);
2688 case IDM_OPTIONS_MUSIC: {
2690 plog("You may not do that right now.");
2694 arg_music = !arg_music;
2695 term_xtra_win_react(player_ptr);
2696 term_key_push(KTRL('R'));
2699 case IDM_OPTIONS_SOUND: {
2701 plog("You may not do that right now.");
2705 arg_sound = !arg_sound;
2706 term_xtra_win_react(player_ptr);
2707 term_key_push(KTRL('R'));
2710 case IDM_OPTIONS_BG: {
2712 plog("You may not do that right now.");
2718 term_xtra_win_react(player_ptr);
2719 term_key_push(KTRL('R'));
2722 case IDM_OPTIONS_OPEN_BG: {
2724 plog("You may not do that right now.");
2728 memset(&ofn, 0, sizeof(ofn));
2729 ofn.lStructSize = sizeof(ofn);
2730 ofn.hwndOwner = data[0].w;
2731 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
2732 ofn.nFilterIndex = 1;
2733 ofn.lpstrFile = bg_bitmap_file;
2734 ofn.nMaxFile = 1023;
2735 ofn.lpstrInitialDir = NULL;
2736 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
2737 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
2739 if (GetOpenFileName(&ofn)) {
2744 term_xtra_win_react(player_ptr);
2745 term_key_push(KTRL('R'));
2748 case IDM_DUMP_SCREEN_HTML: {
2749 static char buf[1024] = "";
2750 memset(&ofn, 0, sizeof(ofn));
2751 ofn.lStructSize = sizeof(ofn);
2752 ofn.hwndOwner = data[0].w;
2753 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
2754 ofn.nFilterIndex = 1;
2755 ofn.lpstrFile = buf;
2756 ofn.nMaxFile = 1023;
2757 ofn.lpstrDefExt = "html";
2758 ofn.lpstrInitialDir = NULL;
2759 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
2760 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
2762 if (GetSaveFileName(&ofn)) {
2763 do_cmd_save_screen_html_aux(buf, 0);
2768 case IDM_OPTIONS_SAVER: {
2770 DestroyWindow(hwndSaver);
2775 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass", "Angband Screensaver", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE, 0, 0,
2776 GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL);
2779 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2781 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
2786 case IDM_OPTIONS_MAP: {
2787 windows_map(player_ptr);
2791 case IDM_HELP_CONTENTS: {
2794 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
2795 if (check_file(tmp)) {
2796 sprintf(buf, "winhelp.exe %s", tmp);
2797 WinExec(buf, SW_NORMAL);
2801 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
2802 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
2809 * Add a keypress to the "queue"
2811 static errr term_keypress(int k)
2813 /* Refuse to enqueue non-keys */
2817 /* Store the char, advance the queue */
2818 Term->key_queue[Term->key_head++] = (char)k;
2820 /* Circular queue, handle wrap */
2821 if (Term->key_head == Term->key_size)
2824 if (Term->key_head != Term->key_tail)
2830 static bool process_keydown(WPARAM wParam, LPARAM lParam)
2836 if (GetKeyState(VK_CONTROL) & 0x8000)
2838 if (GetKeyState(VK_SHIFT) & 0x8000)
2840 if (GetKeyState(VK_MENU) & 0x8000)
2843 term_no_press = (ma) ? TRUE : FALSE;
2844 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)])) {
2845 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
2846 bool numpad = FALSE;
2856 int i = LOBYTE(HIWORD(lParam));
2860 term_no_press = TRUE;
2879 term_no_press = TRUE;
2897 term_keypress(hexsym[i / 16]);
2898 term_keypress(hexsym[i % 16]);
2908 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
2910 LRESULT PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2914 td = (term_data *)GetWindowLong(hWnd, 0);
2918 SetWindowLong(hWnd, 0, (LONG)(my_td));
2922 mop.dwCallback = (DWORD)hWnd;
2925 case WM_GETMINMAXINFO: {
2929 lpmmi = (MINMAXINFO *)lParam;
2933 rc.left = rc.top = 0;
2934 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
2935 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
2937 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
2939 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
2940 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
2945 BeginPaint(hWnd, &ps);
2947 term_data_redraw(p_ptr, td);
2948 EndPaint(hWnd, &ps);
2949 ValidateRect(hWnd, NULL);
2952 case MM_MCINOTIFY: {
2953 if (wParam == MCI_NOTIFY_SUCCESSFUL) {
2954 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2955 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2962 if (process_keydown(wParam, lParam))
2968 term_no_press = FALSE;
2970 term_keypress(wParam);
2973 case WM_LBUTTONDOWN: {
2974 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
2975 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
2981 case WM_LBUTTONUP: {
2984 TERM_LEN dx = abs(oldx - mousex) + 1;
2985 TERM_LEN dy = abs(oldy - mousey) + 1;
2986 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
2987 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
2993 int sz = (dx + 3) * dy;
2995 int sz = (dx + 2) * dy;
2997 hGlobal = GlobalAlloc(GHND, sz + 1);
2998 if (hGlobal == NULL)
3000 lpStr = (LPSTR)GlobalLock(hGlobal);
3002 for (int i = 0; i < dy; i++) {
3005 char **scr = data[0].t.scr->c;
3007 C_MAKE(s, (dx + 1), char);
3008 strncpy(s, &scr[oy + i][ox], dx);
3011 if (iskanji(scr[oy + i][ox - 1]))
3015 if (ox + dx < data[0].cols) {
3016 if (iskanji(scr[oy + i][ox + dx - 1]))
3020 for (int j = 0; j < dx; j++) {
3026 for (int j = 0; j < dx; j++) {
3027 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
3036 GlobalUnlock(hGlobal);
3037 if (OpenClipboard(hWnd) == 0) {
3038 GlobalFree(hGlobal);
3043 SetClipboardData(CF_TEXT, hGlobal);
3048 case WM_MOUSEMOVE: {
3053 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
3054 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
3058 dx = abs(oldx - mousex) + 1;
3059 dy = abs(oldy - mousey) + 1;
3060 ox = (oldx > mousex) ? mousex : oldx;
3061 oy = (oldy > mousey) ? mousey : oldy;
3062 term_inversed_area(hWnd, ox, oy, dx, dy);
3067 dx = abs(cx - mousex) + 1;
3068 dy = abs(cy - mousey) + 1;
3069 ox = (cx > mousex) ? mousex : cx;
3070 oy = (cy > mousey) ? mousey : cy;
3071 term_inversed_area(hWnd, ox, oy, dx, dy);
3082 if (!game_in_progress || !current_world_ptr->character_generated) {
3088 plog(_("今は終了できません。", "You may not do that right now."));
3093 forget_lite(p_ptr->current_floor_ptr);
3094 forget_view(p_ptr->current_floor_ptr);
3095 clear_mon_lite(p_ptr->current_floor_ptr);
3096 term_key_push(SPECIAL_KEY_QUIT);
3099 case WM_QUERYENDSESSION: {
3100 if (!game_in_progress || !current_world_ptr->character_generated) {
3107 p_ptr->is_dead = FALSE;
3108 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
3110 p_ptr->panic_save = 1;
3111 signals_ignore_tstp();
3112 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
3113 (void)save_player(p_ptr, SAVE_TYPE_CLOSE_GAME);
3122 process_menus(p_ptr, LOWORD(wParam));
3133 // todo 二重のswitch文。後で分割する.
3135 case SIZE_MINIMIZED: {
3136 for (int i = 1; i < MAX_TERM_DATA; i++) {
3137 if (data[i].visible)
3138 ShowWindow(data[i].w, SW_HIDE);
3143 case SIZE_MAXIMIZED:
3144 case SIZE_RESTORED: {
3145 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
3146 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
3147 if ((td->cols != cols) || (td->rows != rows)) {
3150 if (!IsZoomed(td->w) && !IsIconic(td->w)) {
3151 normsize.x = td->cols;
3152 normsize.y = td->rows;
3155 term_activate(&td->t);
3156 term_resize(td->cols, td->rows);
3157 InvalidateRect(td->w, NULL, TRUE);
3160 td->size_hack = TRUE;
3161 for (int i = 1; i < MAX_TERM_DATA; i++) {
3162 if (data[i].visible)
3163 ShowWindow(data[i].w, SW_SHOW);
3166 td->size_hack = FALSE;
3174 case WM_PALETTECHANGED: {
3175 if ((HWND)wParam == hWnd)
3178 case WM_QUERYNEWPALETTE: {
3182 HDC hdc = GetDC(hWnd);
3183 SelectPalette(hdc, hPal, FALSE);
3184 int i = RealizePalette(hdc);
3186 InvalidateRect(hWnd, NULL, TRUE);
3188 ReleaseDC(hWnd, hdc);
3192 if (!wParam || HIWORD(lParam))
3195 for (int i = 1; i < MAX_TERM_DATA; i++) {
3196 if (!data[i].posfix)
3197 term_window_pos(&data[i], hWnd);
3203 case WM_ACTIVATEAPP: {
3204 if (IsIconic(td->w))
3207 for (int i = 1; i < MAX_TERM_DATA; i++) {
3208 if (data[i].visible) {
3209 if (wParam == TRUE) {
3210 ShowWindow(data[i].w, SW_SHOW);
3212 ShowWindow(data[i].w, SW_HIDE);
3218 if (wParam == FALSE && keep_subwindows) {
3219 for (int i = 0; i < MAX_TERM_DATA; i++) {
3220 if (data[i].visible) {
3221 ShowWindow(data[i].w, SW_SHOW);
3228 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3232 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
3234 LRESULT PASCAL AngbandListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3238 td = (term_data *)GetWindowLong(hWnd, 0);
3242 SetWindowLong(hWnd, 0, (LONG)(my_td));
3248 case WM_GETMINMAXINFO: {
3252 lpmmi = (MINMAXINFO *)lParam;
3256 rc.left = rc.top = 0;
3257 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
3258 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
3260 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3261 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
3262 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
3273 td->size_hack = TRUE;
3275 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
3276 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
3277 if ((td->cols != cols) || (td->rows != rows)) {
3278 term_type *old_term = Term;
3281 term_activate(&td->t);
3282 term_resize(td->cols, td->rows);
3283 term_activate(old_term);
3284 InvalidateRect(td->w, NULL, TRUE);
3285 p_ptr->window_flags = 0xFFFFFFFF;
3286 handle_stuff(p_ptr);
3289 td->size_hack = FALSE;
3293 BeginPaint(hWnd, &ps);
3295 term_data_redraw(p_ptr, td);
3296 EndPaint(hWnd, &ps);
3301 if (process_keydown(wParam, lParam))
3308 term_no_press = FALSE;
3310 term_keypress(wParam);
3313 case WM_PALETTECHANGED: {
3314 if ((HWND)wParam == hWnd)
3317 case WM_QUERYNEWPALETTE: {
3321 HDC hdc = GetDC(hWnd);
3322 SelectPalette(hdc, hPal, FALSE);
3323 int i = RealizePalette(hdc);
3325 InvalidateRect(hWnd, NULL, TRUE);
3327 ReleaseDC(hWnd, hdc);
3330 case WM_NCLBUTTONDOWN: {
3331 if (wParam == HTCLOSE)
3334 if (wParam == HTSYSMENU) {
3336 td->visible = FALSE;
3337 ShowWindow(td->w, SW_HIDE);
3347 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3350 LRESULT PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3352 static int iMouse = 0;
3353 static WORD xMouse = 0;
3354 static WORD yMouse = 0;
3361 case WM_SETCURSOR: {
3366 case WM_LBUTTONDOWN:
3367 case WM_MBUTTONDOWN:
3368 case WM_RBUTTONDOWN:
3370 SendMessage(hWnd, WM_CLOSE, 0, 0);
3373 case WM_MOUSEMOVE: {
3375 int dx = LOWORD(lParam) - xMouse;
3376 int dy = HIWORD(lParam) - yMouse;
3383 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS)) {
3384 SendMessage(hWnd, WM_CLOSE, 0, 0);
3389 xMouse = LOWORD(lParam);
3390 yMouse = HIWORD(lParam);
3395 DestroyWindow(hwndSaver);
3401 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3405 * Display warning message (see "z-util.c")
3407 static void hack_plog(concptr str)
3411 MessageBox(NULL, str, "警告!", MB_ICONEXCLAMATION | MB_OK);
3413 MessageBox(NULL, str, "Warning", MB_ICONEXCLAMATION | MB_OK);
3419 * Display error message and quit (see "z-util.c")
3421 static void hack_quit(concptr str)
3425 MessageBox(NULL, str, "エラー!", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3427 MessageBox(NULL, str, "Error", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3431 UnregisterClass(AppName, hInstance);
3439 * Display warning message (see "z-util.c")
3441 static void hook_plog(concptr str)
3445 MessageBox(data[0].w, str, "警告!", MB_ICONEXCLAMATION | MB_OK);
3447 MessageBox(data[0].w, str, "Warning", MB_ICONEXCLAMATION | MB_OK);
3453 * Display error message and quit (see "z-util.c")
3455 static void hook_quit(concptr str)
3459 MessageBox(data[0].w, str, "エラー!", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3461 MessageBox(data[0].w, str, "Error", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3466 for (int i = MAX_TERM_DATA - 1; i >= 0; --i) {
3467 term_force_font(&data[i], NULL);
3468 if (data[i].font_want)
3469 string_free(data[i].font_want);
3471 DestroyWindow(data[i].w);
3475 if (infGraph.hPalette)
3476 DeleteObject(infGraph.hPalette);
3477 if (infGraph.hBitmap)
3478 DeleteObject(infGraph.hBitmap);
3479 if (infMask.hPalette)
3480 DeleteObject(infMask.hPalette);
3481 if (infMask.hBitmap)
3482 DeleteObject(infMask.hBitmap);
3484 DeleteObject(hbrYellow);
3490 UnregisterClass(AppName, hInstance);
3500 static void init_stuff(void)
3503 GetModuleFileName(hInstance, path, 512);
3505 strcpy(path + strlen(path) - 4, ".INI");
3506 ini_file = string_make(path);
3507 int i = strlen(path);
3509 for (; i > 0; i--) {
3510 if (path[i] == '\\') {
3515 strcpy(path + i + 1, "lib\\");
3516 validate_dir(path, TRUE);
3517 init_file_paths(path, path);
3518 validate_dir(ANGBAND_DIR_APEX, FALSE);
3519 validate_dir(ANGBAND_DIR_BONE, FALSE);
3520 if (!check_dir(ANGBAND_DIR_EDIT)) {
3521 validate_dir(ANGBAND_DIR_DATA, TRUE);
3523 validate_dir(ANGBAND_DIR_DATA, FALSE);
3526 validate_dir(ANGBAND_DIR_FILE, TRUE);
3527 validate_dir(ANGBAND_DIR_HELP, FALSE);
3528 validate_dir(ANGBAND_DIR_INFO, FALSE);
3529 validate_dir(ANGBAND_DIR_PREF, TRUE);
3530 validate_dir(ANGBAND_DIR_SAVE, FALSE);
3531 validate_dir(ANGBAND_DIR_DEBUG_SAVE, FALSE);
3532 validate_dir(ANGBAND_DIR_USER, TRUE);
3533 validate_dir(ANGBAND_DIR_XTRA, TRUE);
3534 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
3536 validate_file(path);
3537 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
3538 ANGBAND_DIR_XTRA_GRAF = string_make(path);
3539 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
3541 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
3542 ANGBAND_DIR_XTRA_SOUND = string_make(path);
3543 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
3545 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
3546 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
3547 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
3549 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
3550 ANGBAND_DIR_XTRA_HELP = string_make(path);
3554 * @brief コマンドラインから全スポイラー出力を行う
3555 * Create Spoiler files from Command Line
3556 * @return spoiler_output_status
3558 static spoiler_output_status create_debug_spoiler(LPSTR cmd_line)
3564 return SPOILER_OUTPUT_CANCEL;
3565 option = "--output-spoilers";
3567 if (strncmp(s, option, strlen(option)) != 0)
3568 return SPOILER_OUTPUT_CANCEL;
3571 init_angband(p_ptr, process_autopick_file_command, TRUE);
3573 return output_all_spoilers();
3577 * todo よく見るとhMutexはちゃんと使われていない……?
3578 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
3580 static bool is_already_running(void)
3583 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
3584 if (GetLastError() == ERROR_ALREADY_EXISTS) {
3592 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
3594 int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
3600 setlocale(LC_ALL, "ja_JP");
3603 if (is_already_running()) {
3605 NULL, _("変愚蛮怒はすでに起動しています。", "Hengband is already running."), _("エラー!", "Error"), MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3609 switch (create_debug_spoiler(lpCmdLine)) {
3610 case SPOILER_OUTPUT_SUCCESS:
3611 fprintf(stdout, "Successfully created a spoiler file.");
3614 case SPOILER_OUTPUT_FAIL_FOPEN:
3615 fprintf(stderr, "Cannot create spoiler file.");
3618 case SPOILER_OUTPUT_FAIL_FCLOSE:
3619 fprintf(stderr, "Cannot close spoiler file.");
3626 if (hPrevInst == NULL) {
3627 wc.style = CS_CLASSDC;
3628 wc.lpfnWndProc = AngbandWndProc;
3631 wc.hInstance = hInst;
3632 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
3633 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
3634 wc.hbrBackground = static_cast<HBRUSH>(GetStockObject(BLACK_BRUSH));
3635 wc.lpszMenuName = AppName;
3636 wc.lpszClassName = AppName;
3638 if (!RegisterClass(&wc))
3641 wc.lpfnWndProc = AngbandListProc;
3642 wc.lpszMenuName = NULL;
3643 wc.lpszClassName = AngList;
3645 if (!RegisterClass(&wc))
3648 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
3649 wc.lpfnWndProc = AngbandSaverProc;
3651 wc.lpszMenuName = NULL;
3652 wc.lpszClassName = "WindowsScreenSaverClass";
3654 if (!RegisterClass(&wc))
3658 plog_aux = hack_plog;
3659 quit_aux = hack_quit;
3660 core_aux = hack_quit;
3663 for (int i = 0; special_key_list[i]; ++i) {
3664 special_key[special_key_list[i]] = TRUE;
3667 for (int i = 0; ignore_key_list[i]; ++i) {
3668 ignore_key[ignore_key_list[i]] = TRUE;
3672 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
3673 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
3674 ReleaseDC(NULL, hdc);
3676 for (int i = 0; i < 256; i++) {
3677 byte rv = angband_color_table[i][1];
3678 byte gv = angband_color_table[i][2];
3679 byte bv = angband_color_table[i][3];
3680 win_clr[i] = PALETTERGB(rv, gv, bv);
3681 angband_color_table[i][0] = win_pal[i];
3687 plog_aux = hook_plog;
3688 quit_aux = hook_quit;
3689 core_aux = hook_quit;
3691 ANGBAND_SYS = "win";
3692 if (7 != GetKeyboardType(0))
3693 ANGBAND_KEYBOARD = "0";
3695 switch (GetKeyboardType(1)) {
3703 ANGBAND_KEYBOARD = "NEC98";
3707 ANGBAND_KEYBOARD = "JAPAN";
3712 term_activate(term_screen);
3713 init_angband(p_ptr, process_autopick_file_command, FALSE);
3715 check_for_save_file(p_ptr, lpCmdLine);
3716 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
3718 while (GetMessage(&msg, NULL, 0, 0)) {
3719 TranslateMessage(&msg);
3720 DispatchMessage(&msg);
3726 #endif /* WINDOWS */