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 * <del>See also "main-dos.c" and "main-ibm.c".</del>
39 * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
40 * and/or color redefinitions.
44 * The "lib/user/font-win.prf" contains attr/char mappings for use with the
45 * normal "lib/xtra/font/*.fon" font files.
49 * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
50 * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
55 * Compiling this file, and using the resulting executable, requires
56 * several extra files not distributed with the standard Angband code.
57 * In any case, some "*.fon" files (including "8X13.FON" if nothing else)
58 * must be placed into "lib/xtra/font/". All of these extra files can be found
59 * in the "ext-win" archive.
63 * The "term_xtra_win_clear()" function should probably do a low-level
64 * clear of the current window, and redraw the borders and other things,
65 * if only for efficiency.
69 * A simpler method is needed for selecting the "tile size" for windows.
73 * The various "warning" messages assume the existance of the "screen.w"
74 * window, I think, and only a few calls actually check for its existance,
75 * this may be okay since "NULL" means "on top of all windows". (?) The
76 * user must never be allowed to "hide" the main window, or the "menubar"
81 * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
82 * use with the "winhelp.exe" program. These files *may* be available
83 * at the ftp site somewhere, but I have not seen them.
87 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
89 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
91 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
92 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
100 #include "cmd-dump.h"
101 #include "view-mainwindow.h"
103 #include "floor-events.h"
122 * Extract the "WIN32" flag from the compiler
124 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
131 * Available graphic modes
133 #define GRAPHICS_NONE 0
134 #define GRAPHICS_ORIGINAL 1
135 #define GRAPHICS_ADAM_BOLT 2
136 #define GRAPHICS_HENGBAND 3
139 * Menu constants -- see "ANGBAND.RC"
141 #define IDM_FILE_NEW 100
142 #define IDM_FILE_OPEN 101
143 #define IDM_FILE_SAVE 110
144 #define IDM_FILE_SCORE 120
145 #define IDM_FILE_MOVIE 121
146 #define IDM_FILE_EXIT 130
148 #define IDM_WINDOW_VIS_0 200
149 #define IDM_WINDOW_VIS_1 201
150 #define IDM_WINDOW_VIS_2 202
151 #define IDM_WINDOW_VIS_3 203
152 #define IDM_WINDOW_VIS_4 204
153 #define IDM_WINDOW_VIS_5 205
154 #define IDM_WINDOW_VIS_6 206
155 #define IDM_WINDOW_VIS_7 207
157 #define IDM_WINDOW_FONT_0 210
158 #define IDM_WINDOW_FONT_1 211
159 #define IDM_WINDOW_FONT_2 212
160 #define IDM_WINDOW_FONT_3 213
161 #define IDM_WINDOW_FONT_4 214
162 #define IDM_WINDOW_FONT_5 215
163 #define IDM_WINDOW_FONT_6 216
164 #define IDM_WINDOW_FONT_7 217
166 #define IDM_WINDOW_POS_0 220
167 #define IDM_WINDOW_POS_1 221
168 #define IDM_WINDOW_POS_2 222
169 #define IDM_WINDOW_POS_3 223
170 #define IDM_WINDOW_POS_4 224
171 #define IDM_WINDOW_POS_5 225
172 #define IDM_WINDOW_POS_6 226
173 #define IDM_WINDOW_POS_7 227
175 #define IDM_WINDOW_BIZ_0 230
176 #define IDM_WINDOW_BIZ_1 231
177 #define IDM_WINDOW_BIZ_2 232
178 #define IDM_WINDOW_BIZ_3 233
179 #define IDM_WINDOW_BIZ_4 234
180 #define IDM_WINDOW_BIZ_5 235
181 #define IDM_WINDOW_BIZ_6 236
182 #define IDM_WINDOW_BIZ_7 237
184 #define IDM_WINDOW_I_WID_0 240
185 #define IDM_WINDOW_I_WID_1 241
186 #define IDM_WINDOW_I_WID_2 242
187 #define IDM_WINDOW_I_WID_3 243
188 #define IDM_WINDOW_I_WID_4 244
189 #define IDM_WINDOW_I_WID_5 245
190 #define IDM_WINDOW_I_WID_6 246
191 #define IDM_WINDOW_I_WID_7 247
193 #define IDM_WINDOW_D_WID_0 250
194 #define IDM_WINDOW_D_WID_1 251
195 #define IDM_WINDOW_D_WID_2 252
196 #define IDM_WINDOW_D_WID_3 253
197 #define IDM_WINDOW_D_WID_4 254
198 #define IDM_WINDOW_D_WID_5 255
199 #define IDM_WINDOW_D_WID_6 256
200 #define IDM_WINDOW_D_WID_7 257
202 #define IDM_WINDOW_I_HGT_0 260
203 #define IDM_WINDOW_I_HGT_1 261
204 #define IDM_WINDOW_I_HGT_2 262
205 #define IDM_WINDOW_I_HGT_3 263
206 #define IDM_WINDOW_I_HGT_4 264
207 #define IDM_WINDOW_I_HGT_5 265
208 #define IDM_WINDOW_I_HGT_6 266
209 #define IDM_WINDOW_I_HGT_7 267
211 #define IDM_WINDOW_D_HGT_0 270
212 #define IDM_WINDOW_D_HGT_1 271
213 #define IDM_WINDOW_D_HGT_2 272
214 #define IDM_WINDOW_D_HGT_3 273
215 #define IDM_WINDOW_D_HGT_4 274
216 #define IDM_WINDOW_D_HGT_5 275
217 #define IDM_WINDOW_D_HGT_6 276
218 #define IDM_WINDOW_D_HGT_7 277
220 #define IDM_OPTIONS_NO_GRAPHICS 400
221 #define IDM_OPTIONS_OLD_GRAPHICS 401
222 #define IDM_OPTIONS_NEW_GRAPHICS 402
223 #define IDM_OPTIONS_NEW2_GRAPHICS 403
224 #define IDM_OPTIONS_BIGTILE 409
225 #define IDM_OPTIONS_SOUND 410
226 #define IDM_OPTIONS_MUSIC 411
227 #define IDM_OPTIONS_SAVER 420
228 #define IDM_OPTIONS_MAP 430
229 #define IDM_OPTIONS_BG 440
230 #define IDM_OPTIONS_OPEN_BG 441
232 #define IDM_DUMP_SCREEN_HTML 450
234 #define IDM_HELP_CONTENTS 901
237 * Exclude parts of WINDOWS.H that are not needed
239 #define NOCOMM /* Comm driver APIs and definitions */
240 #define NOLOGERROR /* LogError() and related definitions */
241 #define NOPROFILER /* Profiler APIs */
242 #define NOLFILEIO /* _l* file I/O routines */
243 #define NOOPENFILE /* OpenFile and related definitions */
244 #define NORESOURCE /* Resource management */
245 #define NOATOM /* Atom management */
246 #define NOLANGUAGE /* Character test routines */
247 #define NOLSTRING /* lstr* string management routines */
248 #define NODBCS /* Double-byte character set routines */
249 #define NOKEYBOARDINFO /* Keyboard driver routines */
250 #define NOCOLOR /* COLOR_* color values */
251 #define NODRAWTEXT /* DrawText() and related definitions */
252 #define NOSCALABLEFONT /* Truetype scalable font support */
253 #define NOMETAFILE /* Metafile support */
254 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
255 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
256 #define NOKEYSTATES /* MK_* message key state flags */
257 #define NOWH /* SetWindowsHook and related WH_* definitions */
258 #define NOCLIPBOARD /* Clipboard APIs and definitions */
259 #define NOICONS /* IDI_* icon IDs */
260 #define NOMDI /* MDI support */
261 #define NOHELP /* Help support */
263 /* Not defined since it breaks Borland C++ 5.5 */
264 /* #define NOCTLMGR */ /* Control management and controls */
267 * Exclude parts of WINDOWS.H that are not needed (Win32)
269 #define WIN32_LEAN_AND_MEAN
270 #define NONLS /* All NLS defines and routines */
271 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
272 #define NOKANJI /* Kanji support stuff. */
273 #define NOMCX /* Modem Configuration Extensions */
276 * Include the "windows" support file
281 * Exclude parts of MMSYSTEM.H that are not needed
283 #define MMNODRV /* Installable driver support */
284 #define MMNOWAVE /* Waveform support */
285 #define MMNOMIDI /* MIDI support */
286 #define MMNOAUX /* Auxiliary audio support */
287 #define MMNOTIMER /* Timer support */
288 #define MMNOJOY /* Joystick support */
289 #define MMNOMCI /* MCI support */
290 #define MMNOMMIO /* Multimedia file I/O support */
291 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
294 * Standard sound names
296 const concptr angband_sound_name[SOUND_MAX] =
368 * Standard music names
370 const concptr angband_music_basic_name[MUSIC_BASIC_MAX] =
396 * Include some more files. Note: the Cygnus Cygwin compiler
397 * doesn't use mmsystem.h instead it includes the winmm library
398 * which performs a similar function.
400 #include <mmsystem.h>
404 * Include the support for loading bitmaps
409 * Hack -- Fake declarations from "dos.h"
412 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
414 #define FA_LABEL 0x08 /* Volume label */
415 #define FA_DIREC 0x10 /* Directory */
416 unsigned _cdecl _dos_getfileattr(concptr, unsigned *);
420 * Silliness in WIN32 drawing routine
423 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
427 * Silliness for Windows 95
429 #ifndef WS_EX_TOOLWINDOW
430 # define WS_EX_TOOLWINDOW 0
434 * Foreground color bits (hard-coded by DOS)
436 #define VID_BLACK 0x00
437 #define VID_BLUE 0x01
438 #define VID_GREEN 0x02
439 #define VID_CYAN 0x03
441 #define VID_MAGENTA 0x05
442 #define VID_YELLOW 0x06
443 #define VID_WHITE 0x07
446 * Bright text (hard-coded by DOS)
448 #define VID_BRIGHT 0x08
451 * Background color bits (hard-coded by DOS)
453 #define VUD_BLACK 0x00
454 #define VUD_BLUE 0x10
455 #define VUD_GREEN 0x20
456 #define VUD_CYAN 0x30
458 #define VUD_MAGENTA 0x50
459 #define VUD_YELLOW 0x60
460 #define VUD_WHITE 0x70
463 * Blinking text (hard-coded by DOS)
465 #define VUD_BRIGHT 0x80
471 typedef struct _term_data term_data;
475 * @brief ターム情報構造体 / Extra "term" data
478 * pos_x / pos_y は各タームの左上点座標を指す。
481 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
482 * 1ドットずつ調整するステータスを指す。
483 * また、フォントを変更すると都度自動調整される。
486 * Note the use of "font_want" for the names of the font file requested by
487 * the user, and the use of "font_file" for the currently active font file.
489 * The "font_file" is uppercased, and takes the form "8X13.FON", while
490 * "font_want" can be in almost any form as long as it could be construed
491 * as attempting to represent the name of a font.
503 TERM_LEN rows; /* int -> uint */
506 uint pos_x; //!< タームの左上X座標
507 uint pos_y; //!< タームの左上Y座標
522 int font_wid; //!< フォント横幅
523 int font_hgt; //!< フォント縦幅
524 int tile_wid; //!< タイル横幅
525 int tile_hgt; //!< タイル縦幅
537 #define MAX_TERM_DATA 8 //!< Maximum number of windows
539 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
540 static term_data *my_td; //!< Hack -- global "window creation" pointer
541 POINT normsize; //!< Remember normal size of main window when maxmized
544 * was main window maximized on previous playing
546 bool win_maximized = FALSE;
551 bool game_in_progress = FALSE;
554 * note when "open"/"new" become valid
556 bool initialized = FALSE;
559 * screen paletted, i.e. 256 colors
561 bool paletted = FALSE;
564 * 16 colors screen, don't use RGB()
566 bool colors16 = FALSE;
569 * Saved instance handle
571 static HINSTANCE hInstance;
574 * Yellow brush for the cursor
576 static HBRUSH hbrYellow;
586 static HPALETTE hPal;
589 static HBITMAP hBG = NULL;
590 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
591 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
594 * The screen saver window
596 static HWND hwndSaver;
599 * 現在使用中のタイルID(0ならば未使用)
600 * Flag set once "graphics" has been initialized
602 static byte_hack current_graphics_mode = 0;
607 static DIBINIT infGraph;
610 * The global bitmap mask
612 static DIBINIT infMask;
615 * Flag set once "sound" has been initialized
617 static bool can_use_sound = FALSE;
619 #define SAMPLE_SOUND_MAX 16
621 * An array of sound file names
623 static concptr sound_file[SOUND_MAX][SAMPLE_SOUND_MAX];
625 #define SAMPLE_MUSIC_MAX 16
626 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
627 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
628 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
629 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
630 static bool can_use_music = FALSE;
632 static MCI_OPEN_PARMS mop;
633 static char mci_device_type[256];
635 int current_music_type = 0;
636 int current_music_id = 0;
639 * Full path to ANGBAND.INI
641 static concptr ini_file = NULL;
644 * Name of application
646 static concptr AppName = "ANGBAND";
649 * Name of sub-window type
651 static concptr AngList = "AngList";
656 static concptr ANGBAND_DIR_XTRA_GRAF;
657 static concptr ANGBAND_DIR_XTRA_SOUND;
658 static concptr ANGBAND_DIR_XTRA_MUSIC;
659 static concptr ANGBAND_DIR_XTRA_HELP;
660 static concptr ANGBAND_DIR_XTRA_MUSIC;
663 * The "complex" color values
665 static COLORREF win_clr[256];
669 * Flag for macro trigger with dump ASCII
671 static bool term_no_press = FALSE;
676 static bool mouse_down = FALSE;
677 static bool paint_rect = FALSE;
678 static TERM_LEN mousex = 0, mousey = 0;
679 static TERM_LEN oldx, oldy;
683 * @brief The "simple" color values
685 * See "main-ibm.c" for original table information
686 * The entries below are taken from the "color bits" defined above.
687 * Note that many of the choices below suck, but so do crappy monitors.
689 static BYTE win_pal[256] =
691 VID_BLACK, /* Dark */
692 VID_WHITE, /* White */
693 VID_CYAN, /* Slate XXX */
694 VID_RED | VID_BRIGHT, /* Orange XXX */
696 VID_GREEN, /* Green */
698 VID_YELLOW, /* Umber XXX */
699 VID_BLACK | VID_BRIGHT, /* Light Dark */
700 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
701 VID_MAGENTA, /* Violet XXX */
702 VID_YELLOW | VID_BRIGHT, /* Yellow */
703 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
704 VID_GREEN | VID_BRIGHT, /* Light Green */
705 VID_BLUE | VID_BRIGHT, /* Light Blue */
706 VID_YELLOW /* Light Umber XXX */
711 * Hack -- define which keys are "special"
713 static bool special_key[256];
714 static bool ignore_key[256];
717 * Hack -- initialization list for "special_key"
719 static byte special_key_list[] = {
720 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
721 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
722 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
723 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
724 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
725 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
726 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
727 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
728 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
729 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
730 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
731 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
732 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
733 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
734 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
735 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
736 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
741 static byte ignore_key_list[] = {
742 VK_ESCAPE, VK_TAB, VK_SPACE,
743 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
744 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
745 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
750 /* Function prototype */
752 static bool is_already_running(void);
756 static void delete_bg(void)
765 static int init_bg(void)
767 char * bmfile = bg_bitmap_file;
770 if (use_bg == 0) return 0;
772 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
774 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
782 static void DrawBG(HDC hdc, RECT *r)
787 int x = r->left, y = r->top;
788 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
794 GetObject(hBG, sizeof(bm), &bm);
795 swid = bm.bmWidth; shgt = bm.bmHeight;
797 hdcSrc = CreateCompatibleDC(hdc);
798 hOld = SelectObject(hdcSrc, hBG);
802 cwid = MIN(swid - sx, r->right - nx);
805 chgt = MIN(shgt - sy, r->bottom - ny);
806 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
808 } while (ny < r->bottom);
811 } while (nx < r->right);
813 SelectObject(hdcSrc, hOld);
819 * Check for existance of a file
821 static bool check_file(concptr s)
841 attrib = GetFileAttributes(path);
843 /* Require valid filename */
844 if (attrib == INVALID_FILE_NAME) return FALSE;
846 /* Prohibit directory */
847 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return FALSE;
851 /* Examine and verify */
852 if (_dos_getfileattr(path, &attrib)) return FALSE;
854 /* Prohibit something */
855 if (attrib & FA_LABEL) return FALSE;
857 /* Prohibit directory */
858 if (attrib & FA_DIREC) return FALSE;
868 * Check for existance of a directory
870 static bool check_dir(concptr s)
892 /* Remove trailing backslash */
893 if (i && (path[i - 1] == '\\')) path[--i] = '\0';
898 attrib = GetFileAttributes(path);
900 /* Require valid filename */
901 if (attrib == INVALID_FILE_NAME) return FALSE;
903 /* Require directory */
904 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return FALSE;
908 /* Examine and verify */
909 if (_dos_getfileattr(path, &attrib)) return FALSE;
911 /* Prohibit something */
912 if (attrib & FA_LABEL) return FALSE;
914 /* Require directory */
915 if (!(attrib & FA_DIREC)) return FALSE;
927 static void validate_file(concptr s)
932 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
938 * Validate a directory
940 static void validate_dir(concptr s, bool vital)
945 /* This directory contains needed data */
948 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
950 /* Attempt to create this directory */
953 quit_fmt("Unable to create directory:\n%s", s);
960 * @brief (Windows版固有実装)Get the "size" for a window
962 static void term_getsize(term_data *td)
966 if (td->cols < 1) td->cols = 1;
967 if (td->rows < 1) td->rows = 1;
970 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
971 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
973 /* Fake window size */
975 rc.right = rc.left + wid;
977 rc.bottom = rc.top + hgt;
980 /* rc.bottom += 1; */
983 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
986 td->size_wid = rc.right - rc.left;
987 td->size_hgt = rc.bottom - rc.top;
989 /* See CreateWindowEx */
992 /* Extract actual location */
993 GetWindowRect(td->w, &rc);
995 /* Save the location */
1002 * Write the "prefs" for a single term
1004 static void save_prefs_aux(int i)
1006 term_data *td = &data[i];
1007 GAME_TEXT sec_name[128];
1011 WINDOWPLACEMENT lpwndpl;
1014 /* Make section name */
1015 sprintf(sec_name, "Term-%d", i);
1020 strcpy(buf, td->visible ? "1" : "0");
1021 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1026 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "MS ゴシック");
1028 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "Courier");
1031 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1033 wsprintf(buf, "%d", td->lf.lfWidth);
1034 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1035 wsprintf(buf, "%d", td->lf.lfHeight);
1036 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1037 wsprintf(buf, "%d", td->lf.lfWeight);
1038 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1040 strcpy(buf, td->bizarre ? "1" : "0");
1041 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1044 wsprintf(buf, "%d", td->tile_wid);
1045 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1048 wsprintf(buf, "%d", td->tile_hgt);
1049 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1051 /* Get window placement and dimensions */
1052 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1053 GetWindowPlacement(td->w, &lpwndpl);
1055 /* Acquire position in *normal* mode (not minimized) */
1056 rc = lpwndpl.rcNormalPosition;
1058 /* Window size (x) */
1059 if (i == 0) wsprintf(buf, "%d", normsize.x);
1060 else wsprintf(buf, "%d", td->cols);
1061 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1063 /* Window size (y) */
1064 if (i == 0) wsprintf(buf, "%d", normsize.y);
1065 else wsprintf(buf, "%d", td->rows);
1066 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1068 /* Maxmized (only main window) */
1071 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1072 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1075 /* Acquire position */
1076 GetWindowRect(td->w, &rc);
1078 /* Window position (x) */
1079 wsprintf(buf, "%d", rc.left);
1080 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1082 /* Window position (y) */
1083 wsprintf(buf, "%d", rc.top);
1084 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1086 /* Window Z position */
1089 strcpy(buf, td->posfix ? "1" : "0");
1090 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1097 * We assume that the windows have all been initialized
1099 static void save_prefs(void)
1105 /* Save the "arg_graphics" flag */
1106 sprintf(buf, "%d", arg_graphics);
1107 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1109 /* Save the "arg_bigtile" flag */
1110 strcpy(buf, arg_bigtile ? "1" : "0");
1111 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1113 /* Save the "arg_sound" flag */
1114 strcpy(buf, arg_sound ? "1" : "0");
1115 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1117 /* Save the "arg_sound" flag */
1118 strcpy(buf, arg_music ? "1" : "0");
1119 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1122 strcpy(buf, use_bg ? "1" : "0");
1123 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1124 WritePrivateProfileString("Angband", "BackGroundBitmap",
1125 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1127 /* Save window prefs */
1128 for (i = 0; i < MAX_TERM_DATA; ++i)
1136 * Load the "prefs" for a single term
1138 static void load_prefs_aux(int i)
1140 term_data *td = &data[i];
1141 GAME_TEXT sec_name[128];
1144 int wid, hgt, posx, posy;
1145 int dispx = GetSystemMetrics(SM_CXVIRTUALSCREEN);
1146 int dispy = GetSystemMetrics(SM_CYVIRTUALSCREEN);
1150 /* Make section name */
1151 sprintf(sec_name, "Term-%d", i);
1153 /* Make section name */
1154 sprintf(sec_name, "Term-%d", i);
1159 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1162 /* Desired font, with default */
1164 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1166 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1171 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1173 /* Analyze font, save desired font name */
1174 td->font_want = string_make(tmp);
1176 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1177 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1178 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1181 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1182 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1185 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1186 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1187 normsize.x = td->cols; normsize.y = td->rows;
1192 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
1195 /* Window position */
1196 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1197 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1198 td->pos_x = MIN(MAX(0, posx), dispx - 128);
1199 td->pos_y = MIN(MAX(0, posy), dispy - 128);
1201 /* Window Z position */
1204 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
1212 static void load_prefs(void)
1216 /* Extract the "arg_graphics" flag */
1217 arg_graphics = (byte_hack)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1219 /* Extract the "arg_bigtile" flag */
1220 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
1221 use_bigtile = arg_bigtile;
1223 /* Extract the "arg_sound" flag */
1224 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1226 /* Extract the "arg_sound" flag */
1227 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1230 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1231 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1233 /* Load window prefs */
1234 for (i = 0; i < MAX_TERM_DATA; ++i)
1242 * - Taken from files.c.
1244 * Extract "tokens" from a buffer
1246 * This function uses "whitespace" as delimiters, and treats any amount of
1247 * whitespace as a single delimiter. We will never return any empty tokens.
1248 * When given an empty buffer, or a buffer containing only "whitespace", we
1249 * will return no tokens. We will never extract more than "num" tokens.
1251 * By running a token through the "text_to_ascii()" function, you can allow
1252 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1254 * We save pointers to the tokens in "tokens", and return the number found.
1256 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1266 /* Skip leading whitespace */
1267 for (; *s && iswspace(*s); ++s) /* loop */;
1272 /* Find next whitespace, if any */
1273 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1275 /* Nuke and advance (if necessary) */
1276 if (*t) *t++ = '\0';
1278 /* Save the token */
1290 static void load_sound_prefs(void)
1294 char ini_path[1024];
1295 char wav_path[1024];
1296 char *zz[SAMPLE_SOUND_MAX];
1298 /* Access the sound.cfg */
1300 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1302 for (i = 0; i < SOUND_MAX; i++)
1304 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1306 num = tokenize_whitespace(tmp, SAMPLE_SOUND_MAX, zz);
1308 for (j = 0; j < num; j++)
1310 /* Access the sound */
1311 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1313 /* Save the sound filename, if it exists */
1314 if (check_file(wav_path))
1315 sound_file[i][j] = string_make(zz[j]);
1321 static void load_music_prefs(void)
1325 char ini_path[1024];
1326 char wav_path[1024];
1327 char *zz[SAMPLE_MUSIC_MAX];
1330 /* Access the music.cfg */
1332 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1334 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1336 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1338 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1340 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1342 for (j = 0; j < num; j++)
1344 /* Access the sound */
1345 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1347 /* Save the sound filename, if it exists */
1348 if (check_file(wav_path))
1349 music_file[i][j] = string_make(zz[j]);
1353 for (i = 0; i < current_world_ptr->max_d_idx; i++)
1355 sprintf(key, "dungeon%03d", i);
1356 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1358 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1360 for (j = 0; j < num; j++)
1362 /* Access the sound */
1363 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1365 /* Save the sound filename, if it exists */
1366 if (check_file(wav_path))
1367 dungeon_music_file[i][j] = string_make(zz[j]);
1371 for (i = 0; i < max_q_idx; i++)
1373 sprintf(key, "quest%03d", i);
1374 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1376 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1378 for (j = 0; j < num; j++)
1380 /* Access the sound */
1381 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1383 /* Save the sound filename, if it exists */
1384 if (check_file(wav_path))
1385 quest_music_file[i][j] = string_make(zz[j]);
1389 for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1391 sprintf(key, "town%03d", i);
1392 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1394 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1396 for (j = 0; j < num; j++)
1398 /* Access the sound */
1399 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1401 /* Save the sound filename, if it exists */
1402 if (check_file(wav_path))
1403 town_music_file[i][j] = string_make(zz[j]);
1412 * Create the new global palette based on the bitmap palette
1413 * (if any), and the standard 16 entry palette derived from
1414 * "win_clr[]" which is used for the basic 16 Angband colors.
1416 * This function is never called before all windows are ready.
1418 * This function returns FALSE if the new palette could not be
1419 * prepared, which should normally be a fatal error. XXX XXX
1421 * Note that only some machines actually use a "palette".
1423 static int new_palette(void)
1431 LPLOGPALETTE pLogPal;
1432 LPPALETTEENTRY lppe;
1437 /* This makes no sense */
1438 if (!paletted) return TRUE;
1446 /* Check the bitmap palette */
1447 hBmPal = infGraph.hPalette;
1449 /* Use the bitmap */
1452 lppeSize = 256 * sizeof(PALETTEENTRY);
1453 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1454 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1455 if ((nEntries == 0) || (nEntries > 220))
1458 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1461 rnfree(lppe, lppeSize);
1468 /* Size of palette */
1469 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1471 /* Allocate palette */
1472 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1475 pLogPal->palVersion = 0x300;
1477 /* Make room for bitmap and normal data */
1478 pLogPal->palNumEntries = nEntries + 16;
1480 /* Save the bitmap data */
1481 for (i = 0; i < nEntries; i++)
1483 pLogPal->palPalEntry[i] = lppe[i];
1486 /* Save the normal data */
1487 for (i = 0; i < 16; i++)
1491 /* Access the entry */
1492 p = &(pLogPal->palPalEntry[i + nEntries]);
1494 /* Save the colors */
1495 p->peRed = GetRValue(win_clr[i]);
1496 p->peGreen = GetGValue(win_clr[i]);
1497 p->peBlue = GetBValue(win_clr[i]);
1499 /* Save the flags */
1500 p->peFlags = PC_NOCOLLAPSE;
1503 /* Free something */
1504 if (lppe) rnfree(lppe, lppeSize);
1506 /* Create a new palette, or fail */
1507 hNewPal = CreatePalette(pLogPal);
1508 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1510 /* Free the palette */
1511 rnfree(pLogPal, pLogPalSize);
1516 /* Realize the palette */
1518 SelectPalette(hdc, hNewPal, 0);
1519 i = RealizePalette(hdc);
1520 ReleaseDC(td->w, hdc);
1521 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1525 for (i = 1; i < MAX_TERM_DATA; i++)
1530 SelectPalette(hdc, hNewPal, 0);
1531 ReleaseDC(td->w, hdc);
1534 /* Delete old palette */
1535 if (hPal) DeleteObject(hPal);
1537 /* Save new palette */
1546 * @brief グラフィクスを初期化する / Initialize graphics
1549 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1550 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1553 static bool init_graphics(void)
1555 /* Initialize once */
1557 BYTE wid, hgt, twid, thgt, ox, oy;
1560 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1570 ANGBAND_GRAF = "new";
1572 else if (arg_graphics == GRAPHICS_HENGBAND)
1592 ANGBAND_GRAF = "ne2";
1603 ANGBAND_GRAF = "old";
1606 /* Access the bitmap file */
1607 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1609 /* Load the bitmap or quit */
1610 if (!ReadDIB(data[0].w, buf, &infGraph))
1612 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1616 /* Save the new sizes */
1617 infGraph.CellWidth = wid;
1618 infGraph.CellHeight = hgt;
1619 infGraph.TileWidth = twid;
1620 infGraph.TileHeight = thgt;
1621 infGraph.OffsetX = ox;
1622 infGraph.OffsetY = oy;
1624 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1626 /* Access the mask file */
1627 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1629 /* Load the bitmap or quit */
1630 if (!ReadDIB(data[0].w, buf, &infMask))
1632 plog_fmt("Cannot read bitmap file '%s'", buf);
1636 if (arg_graphics == GRAPHICS_HENGBAND)
1638 /* Access the mask file */
1639 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1641 /* Load the bitmap or quit */
1642 if (!ReadDIB(data[0].w, buf, &infMask))
1644 plog_fmt("Cannot read bitmap file '%s'", buf);
1649 /* Activate a palette */
1654 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1658 /* Graphics available */
1659 current_graphics_mode = arg_graphics;
1660 return (current_graphics_mode);
1667 static bool init_music(void)
1669 /* Initialize once */
1672 /* Load the prefs */
1675 /* Sound available */
1676 can_use_music = TRUE;
1678 return (can_use_music);
1682 * Hack -- Stop a music
1684 static void stop_music(void)
1686 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1687 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1694 static bool init_sound(void)
1696 /* Initialize once */
1699 /* Load the prefs */
1702 /* Sound available */
1703 can_use_sound = TRUE;
1705 return (can_use_sound);
1712 static void term_window_resize(term_data *td)
1714 /* Require window */
1717 /* Resize the window */
1718 SetWindowPos(td->w, 0, 0, 0,
1719 td->size_wid, td->size_hgt,
1720 SWP_NOMOVE | SWP_NOZORDER);
1723 InvalidateRect(td->w, NULL, TRUE);
1728 * Force the use of a new "font file" for a term_data
1730 * This function may be called before the "window" is ready
1732 * This function returns zero only if everything succeeds.
1734 * Note that the "font name" must be capitalized!!!
1736 static errr term_force_font(term_data *td, concptr path)
1740 /* Forget the old font (if needed) */
1741 if (td->font_id) DeleteObject(td->font_id);
1746 /* Create the font (using the 'base' of the font file name!) */
1747 td->font_id = CreateFontIndirect(&(td->lf));
1748 wid = td->lf.lfWidth;
1749 hgt = td->lf.lfHeight;
1750 if (!td->font_id) return 1;
1752 /* Hack -- Unknown size */
1759 /* all this trouble to get the cell size */
1760 hdcDesktop = GetDC(HWND_DESKTOP);
1761 hfOld = SelectObject(hdcDesktop, td->font_id);
1762 GetTextMetrics(hdcDesktop, &tm);
1763 SelectObject(hdcDesktop, hfOld);
1764 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1766 /* Font size info */
1767 wid = tm.tmAveCharWidth;
1771 /* Save the size info */
1782 * Allow the user to change the font for this window.
1784 static void term_change_font(term_data *td)
1788 memset(&cf, 0, sizeof(cf));
1789 cf.lStructSize = sizeof(cf);
1790 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1791 cf.lpLogFont = &(td->lf);
1793 if (ChooseFont(&cf))
1795 /* Force the font */
1796 term_force_font(td, NULL);
1798 /* Assume not bizarre */
1801 /* Reset the tile info */
1802 td->tile_wid = td->font_wid;
1803 td->tile_hgt = td->font_hgt;
1805 /* Analyze the font */
1808 /* Resize the window */
1809 term_window_resize(td);
1815 * Allow the user to lock this window.
1817 static void term_window_pos(term_data *td, HWND hWnd)
1819 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1820 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1823 static void windows_map(player_type *player_ptr);
1826 * Hack -- redraw a term_data
1828 static void term_data_redraw(player_type *player_ptr, term_data *td)
1832 /* Redraw the map */
1833 windows_map(player_ptr);
1837 /* Activate the term */
1838 Term_activate(&td->t);
1840 /* Redraw the contents */
1843 /* Restore the term */
1844 Term_activate(term_screen);
1849 void term_inversed_area(HWND hWnd, int x, int y, int w, int h)
1853 HBRUSH myBrush, oldBrush;
1855 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
1856 int tx = td->size_ow1 + x * td->tile_wid;
1857 int ty = td->size_oh1 + y * td->tile_hgt;
1858 int tw = w * td->tile_wid - 1;
1859 int th = h * td->tile_hgt - 1;
1862 myBrush = CreateSolidBrush(RGB(255, 255, 255));
1863 oldBrush = SelectObject(hdc, myBrush);
1864 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1866 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
1868 SelectObject(hdc, oldBrush);
1869 SelectObject(hdc, oldPen);
1874 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
1876 static errr term_user_win(int n)
1887 * React to global changes
1889 static errr term_xtra_win_react(player_type *player_ptr)
1896 /* Save the default colors */
1897 for (i = 0; i < 256; i++)
1899 /* Simply accept the desired colors */
1900 win_pal[i] = angband_color_table[i][0];
1911 bool change = FALSE;
1913 /* Save the default colors */
1914 for (i = 0; i < 256; i++)
1916 /* Extract desired values */
1917 rv = angband_color_table[i][1];
1918 gv = angband_color_table[i][2];
1919 bv = angband_color_table[i][3];
1921 /* Extract a full color code */
1922 code = PALETTERGB(rv, gv, bv);
1924 /* Activate changes */
1925 if (win_clr[i] != code)
1927 /* Note the change */
1930 /* Apply the desired color */
1935 /* Activate the palette if needed */
1936 if (change) (void)new_palette();
1939 /* Handle "arg_sound" */
1940 if (use_sound != arg_sound)
1942 /* Initialize (if needed) */
1943 if (arg_sound && !init_sound())
1946 plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
1952 /* Change setting */
1953 use_sound = arg_sound;
1956 /* Handle "arg_sound" */
1957 if (use_music != arg_music)
1959 /* Initialize (if needed) */
1960 if (arg_music && !init_music())
1963 plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
1968 /* Change setting */
1969 use_music = arg_music;
1971 if (!arg_music) stop_music();
1972 else select_floor_music(player_ptr);
1976 /* Handle "arg_graphics" */
1977 if (use_graphics != arg_graphics)
1979 /* Initialize (if needed) */
1980 if (arg_graphics && !init_graphics())
1983 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
1986 arg_graphics = GRAPHICS_NONE;
1989 /* Change setting */
1990 use_graphics = arg_graphics;
1993 reset_visuals(player_ptr);
1996 /* Clean up windows */
1997 for (i = 0; i < MAX_TERM_DATA; i++)
2001 term_data *td = &data[i];
2003 /* Update resized windows */
2004 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
2007 Term_activate(&td->t);
2009 /* Hack -- Resize the term */
2010 Term_resize(td->cols, td->rows);
2012 /* Redraw the contents */
2025 * Process at least one event
2027 static errr term_xtra_win_event(int v)
2031 /* Wait for an event */
2035 if (GetMessage(&msg, NULL, 0, 0))
2037 TranslateMessage(&msg);
2038 DispatchMessage(&msg);
2042 /* Check for an event */
2046 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2048 TranslateMessage(&msg);
2049 DispatchMessage(&msg);
2059 * Process all pending events
2061 static errr term_xtra_win_flush(void)
2065 /* Process all pending events */
2066 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2068 TranslateMessage(&msg);
2069 DispatchMessage(&msg);
2078 * Hack -- clear the screen
2080 * Make this more efficient
2082 static errr term_xtra_win_clear(void)
2084 term_data *td = (term_data*)(Term->data);
2089 /* Rectangle to erase */
2090 rc.left = td->size_ow1;
2091 rc.right = rc.left + td->cols * td->tile_wid;
2092 rc.top = td->size_oh1;
2093 rc.bottom = rc.top + td->rows * td->tile_hgt;
2097 SetBkColor(hdc, RGB(0, 0, 0));
2098 SelectObject(hdc, td->font_id);
2099 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2104 rc.left = 0; rc.top = 0;
2107 ReleaseDC(td->w, hdc);
2115 * Hack -- make a noise
2117 static errr term_xtra_win_noise(void)
2119 MessageBeep(MB_ICONASTERISK);
2125 * Hack -- make a sound
2127 static errr term_xtra_win_sound(int v)
2132 /* Sound disabled */
2133 if (!use_sound) return 1;
2136 if ((v < 0) || (v >= SOUND_MAX)) return 1;
2138 /* Count the samples */
2139 for (i = 0; i < SAMPLE_SOUND_MAX; i++)
2141 if (!sound_file[v][i])
2146 if (i == 0) return 1;
2148 /* Build the path */
2149 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2153 /* Play the sound, catch errors */
2154 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2158 /* Play the sound, catch errors */
2159 return (sndPlaySound(buf, SND_ASYNC));
2165 * Hack -- play a music
2167 static errr term_xtra_win_music(int n, int v)
2171 /* Sound disabled */
2172 if (n == TERM_XTRA_MUSIC_MUTE)
2174 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2175 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2178 if (!use_music) return 1;
2181 if (n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return 1;
2182 else if (v < 0 || v >= 1000) return(1); /*!< TODO */
2186 case TERM_XTRA_MUSIC_BASIC:
2187 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!music_file[v][i]) break;
2189 case TERM_XTRA_MUSIC_DUNGEON:
2190 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!dungeon_music_file[v][i]) break;
2192 case TERM_XTRA_MUSIC_QUEST:
2193 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!quest_music_file[v][i]) break;
2195 case TERM_XTRA_MUSIC_TOWN:
2196 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!town_music_file[v][i]) break;
2208 case TERM_XTRA_MUSIC_BASIC:
2209 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2211 case TERM_XTRA_MUSIC_DUNGEON:
2212 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2214 case TERM_XTRA_MUSIC_QUEST:
2215 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2217 case TERM_XTRA_MUSIC_TOWN:
2218 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2222 if (current_music_type == n && current_music_id == v)
2226 current_music_type = n;
2227 current_music_id = v;
2231 mop.lpstrDeviceType = mci_device_type;
2232 mop.lpstrElementName = buf;
2233 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2234 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2235 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2236 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2237 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2245 * Delay for "x" milliseconds
2247 static int term_xtra_win_delay(int v)
2261 t = GetTickCount() + v;
2264 while (GetTickCount() < t)
2266 /* Handle messages */
2267 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2269 TranslateMessage(&msg);
2270 DispatchMessage(&msg);
2282 * todo z-termに影響があるのでplayer_typeの追加は保留
2283 * Do a "special thing"
2285 static errr term_xtra_win(int n, int v)
2287 /* Handle a subset of the legal requests */
2290 /* Make a bell sound */
2291 case TERM_XTRA_NOISE:
2293 return (term_xtra_win_noise());
2297 case TERM_XTRA_MUSIC_BASIC:
2298 case TERM_XTRA_MUSIC_DUNGEON:
2299 case TERM_XTRA_MUSIC_QUEST:
2300 case TERM_XTRA_MUSIC_TOWN:
2302 return (term_xtra_win_music(n, v));
2305 /* Make a special sound */
2306 case TERM_XTRA_SOUND:
2308 return (term_xtra_win_sound(v));
2311 /* Process random events */
2312 case TERM_XTRA_BORED:
2314 return (term_xtra_win_event(0));
2317 /* Process an event */
2318 case TERM_XTRA_EVENT:
2320 return (term_xtra_win_event(v));
2323 /* Flush all events */
2324 case TERM_XTRA_FLUSH:
2326 return (term_xtra_win_flush());
2329 /* Clear the screen */
2330 case TERM_XTRA_CLEAR:
2332 return (term_xtra_win_clear());
2335 /* React to global changes */
2336 case TERM_XTRA_REACT:
2338 return (term_xtra_win_react(p_ptr));
2341 /* Delay for some milliseconds */
2342 case TERM_XTRA_DELAY:
2344 return (term_xtra_win_delay(v));
2354 * Low level graphics (Assumes valid input).
2356 * Draw a "cursor" at (x,y), using a "yellow box".
2358 static errr term_curs_win(int x, int y)
2360 term_data *td = (term_data*)(Term->data);
2365 int tile_wid, tile_hgt;
2369 tile_wid = td->map_tile_wid;
2370 tile_hgt = td->map_tile_hgt;
2374 tile_wid = td->tile_wid;
2375 tile_hgt = td->tile_hgt;
2378 /* Frame the grid */
2379 rc.left = x * tile_wid + td->size_ow1;
2380 rc.right = rc.left + tile_wid;
2381 rc.top = y * tile_hgt + td->size_oh1;
2382 rc.bottom = rc.top + tile_hgt;
2384 /* Cursor is done as a yellow "box" */
2386 FrameRect(hdc, &rc, hbrYellow);
2387 ReleaseDC(td->w, hdc);
2395 * Low level graphics (Assumes valid input).
2397 * Draw a "big cursor" at (x,y), using a "yellow box".
2399 static errr term_bigcurs_win(int x, int y)
2401 term_data *td = (term_data*)(Term->data);
2406 int tile_wid, tile_hgt;
2410 /* Normal cursor in map window */
2411 term_curs_win(x, y);
2416 tile_wid = td->tile_wid;
2417 tile_hgt = td->tile_hgt;
2420 /* Frame the grid */
2421 rc.left = x * tile_wid + td->size_ow1;
2422 rc.right = rc.left + 2 * tile_wid;
2423 rc.top = y * tile_hgt + td->size_oh1;
2424 rc.bottom = rc.top + tile_hgt;
2426 /* Cursor is done as a yellow "box" */
2428 FrameRect(hdc, &rc, hbrYellow);
2429 ReleaseDC(td->w, hdc);
2437 * Low level graphics (Assumes valid input).
2439 * Erase a "block" of "n" characters starting at (x,y).
2441 static errr term_wipe_win(int x, int y, int n)
2443 term_data *td = (term_data*)(Term->data);
2448 /* Rectangle to erase in client coords */
2449 rc.left = x * td->tile_wid + td->size_ow1;
2450 rc.right = rc.left + n * td->tile_wid;
2451 rc.top = y * td->tile_hgt + td->size_oh1;
2452 rc.bottom = rc.top + td->tile_hgt;
2455 SetBkColor(hdc, RGB(0, 0, 0));
2456 SelectObject(hdc, td->font_id);
2461 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2462 ReleaseDC(td->w, hdc);
2470 * Low level graphics. Assumes valid input.
2472 * Draw several ("n") chars, with an attr, at a given location.
2474 * All "graphic" data is handled by "term_pict_win()", below.
2476 * One would think there is a more efficient method for telling a window
2477 * what color it should be using to draw with, but perhaps simply changing
2478 * it every time is not too inefficient.
2480 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
2482 term_data *td = (term_data*)(Term->data);
2486 static HBITMAP WALL;
2487 static HBRUSH myBrush, oldBrush;
2489 static bool init_done = FALSE;
2492 WALL = LoadBitmap(hInstance, AppName);
2493 myBrush = CreatePatternBrush(WALL);
2497 /* Total rectangle */
2498 rc.left = x * td->tile_wid + td->size_ow1;
2499 rc.right = rc.left + n * td->tile_wid;
2500 rc.top = y * td->tile_hgt + td->size_oh1;
2501 rc.bottom = rc.top + td->tile_hgt;
2506 /* Background color */
2507 SetBkColor(hdc, RGB(0, 0, 0));
2509 /* Foreground color */
2512 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2516 SetTextColor(hdc, win_clr[a & 0x0F]);
2520 SetTextColor(hdc, win_clr[a]);
2524 SelectObject(hdc, td->font_id);
2527 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2531 (td->tile_hgt != td->font_hgt) ||
2532 (td->tile_wid != td->font_wid))
2536 /* Erase complete rectangle */
2537 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2540 if (use_bg) DrawBG(hdc, &rc);
2543 rc.left += ((td->tile_wid - td->font_wid) / 2);
2544 rc.right = rc.left + td->font_wid;
2545 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2546 rc.bottom = rc.top + td->font_hgt;
2548 /* Dump each character */
2549 for (i = 0; i < n; i++)
2552 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1])
2554 rc.right += td->font_wid;
2556 oldBrush = SelectObject(hdc, myBrush);
2557 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
2560 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2562 SelectObject(hdc, oldBrush);
2563 SelectObject(hdc, oldPen);
2564 rc.right -= td->font_wid;
2568 rc.left += 2 * td->tile_wid;
2569 rc.right += 2 * td->tile_wid;
2571 else if (iskanji(*(s + i))) /* 2バイト文字 */
2573 rc.right += td->font_wid;
2575 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2577 rc.right -= td->font_wid;
2581 rc.left += 2 * td->tile_wid;
2582 rc.right += 2 * td->tile_wid;
2584 else if (*(s + i) == 127) {
2585 oldBrush = SelectObject(hdc, myBrush);
2586 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
2589 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2591 SelectObject(hdc, oldBrush);
2592 SelectObject(hdc, oldPen);
2595 rc.left += td->tile_wid;
2596 rc.right += td->tile_wid;
2600 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
2603 rc.left += td->tile_wid;
2604 rc.right += td->tile_wid;
2607 if (*(s + i) == 127) {
2608 oldBrush = SelectObject(hdc, myBrush);
2609 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
2612 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2614 SelectObject(hdc, oldBrush);
2615 SelectObject(hdc, oldPen);
2618 rc.left += td->tile_wid;
2619 rc.right += td->tile_wid;
2623 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2627 rc.left += td->tile_wid;
2628 rc.right += td->tile_wid;
2639 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2644 ReleaseDC(td->w, hdc);
2652 * Low level graphics. Assumes valid input.
2654 * Draw an array of "special" attr/char pairs at the given location.
2656 * We use the "term_pict_win()" function for "graphic" data, which are
2657 * encoded by setting the "high-bits" of both the "attr" and the "char"
2658 * data. We use the "attr" to represent the "row" of the main bitmap,
2659 * and the "char" to represent the "col" of the main bitmap. The use
2660 * of this function is induced by the "higher_pict" flag.
2662 * If "graphics" is not available, we simply "wipe" the given grids.
2664 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)
2666 term_data *td = (term_data*)(Term->data);
2668 TERM_LEN x1, y1, w1, h1, tw1, th1;
2669 TERM_LEN x2, y2, w2, h2, tw2 = 0;
2679 /* Erase the grids */
2680 return (term_wipe_win(x, y, n));
2683 /* Size of bitmap cell */
2684 w1 = infGraph.CellWidth;
2685 h1 = infGraph.CellHeight;
2686 tw1 = infGraph.TileWidth;
2687 th1 = infGraph.TileHeight;
2689 /* Size of window cell */
2692 w2 = td->map_tile_wid;
2693 h2 = td->map_tile_hgt;
2702 if (use_bigtile) tw2 *= 2;
2705 /* Location of window cell */
2706 x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
2707 y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
2713 hdcSrc = CreateCompatibleDC(hdc);
2714 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2716 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2718 hdcMask = CreateCompatibleDC(hdc);
2719 SelectObject(hdcMask, infMask.hBitmap);
2722 /* Draw attr/char pairs */
2723 for (i = 0; i < n; i++, x2 += w2)
2725 TERM_COLOR a = ap[i];
2729 /* Extract picture */
2730 int row = (a & 0x7F);
2731 int col = (c & 0x7F);
2733 /* Location of bitmap cell */
2737 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2739 x3 = (tcp[i] & 0x7F) * w1;
2740 y3 = (tap[i] & 0x7F) * h1;
2741 tw2 = tw2 * w1 / tw1;
2745 if ((tw1 == tw2) && (th1 == h2))
2747 /* Copy the terrain picture from the bitmap to the window */
2748 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2750 /* Mask out the tile */
2751 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2754 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2757 /* Need to stretch */
2760 /* Set the correct mode for stretching the tiles */
2761 SetStretchBltMode(hdc, COLORONCOLOR);
2763 /* Copy the terrain picture from the bitmap to the window */
2764 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
2766 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
2768 /* Only draw if terrain and overlay are different */
2769 if ((x1 != x3) || (y1 != y3))
2771 /* Mask out the tile */
2772 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2775 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2782 if ((w1 == tw2) && (h1 == h2))
2784 /* Copy the picture from the bitmap to the window */
2785 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2788 /* Need to stretch */
2791 /* Set the correct mode for stretching the tiles */
2792 SetStretchBltMode(hdc, COLORONCOLOR);
2794 /* Copy the picture from the bitmap to the window */
2795 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2801 SelectObject(hdcSrc, hbmSrcOld);
2804 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2807 SelectObject(hdcMask, hbmSrcOld);
2812 ReleaseDC(td->w, hdc);
2819 static void windows_map(player_type *player_ptr)
2821 term_data *td = &data[0];
2824 TERM_LEN x, min_x, max_x;
2825 TERM_LEN y, min_y, max_y;
2830 /* Only in graphics mode */
2831 if (!use_graphics) return;
2832 term_xtra_win_clear();
2834 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2835 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2836 td->map_active = TRUE;
2841 max_x = player_ptr->current_floor_ptr->width;
2842 max_y = player_ptr->current_floor_ptr->height;
2846 for (x = min_x; x < max_x; x++)
2848 for (y = min_y; y < max_y; y++)
2850 map_info(player_ptr, y, x, &a, (char*)&c, &ta, (char*)&tc);
2852 /* Ignore non-graphics */
2853 if ((a & 0x80) && (c & 0x80))
2855 term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2860 /* Hilite the player */
2861 term_curs_win(player_ptr->x - min_x, player_ptr->y - min_y);
2863 /* Wait for a keypress, flush key buffer */
2864 Term_inkey(&c, TRUE, TRUE);
2867 /* Switch off the map display */
2868 td->map_active = FALSE;
2870 /* Restore screen */
2871 term_xtra_win_clear();
2876 /*** Other routines ***/
2880 * Create and initialize a "term_data" given a title
2882 static void term_data_link(term_data *td)
2886 /* Initialize the term */
2887 term_init(t, td->cols, td->rows, td->keys);
2889 /* Use a "software" cursor */
2890 t->soft_cursor = TRUE;
2892 /* Use "term_pict" for "graphic" data */
2893 t->higher_pict = TRUE;
2895 /* Erase with "white space" */
2896 t->attr_blank = TERM_WHITE;
2897 t->char_blank = ' ';
2899 /* Prepare the template hooks */
2900 t->user_hook = term_user_win;
2901 t->xtra_hook = term_xtra_win;
2902 t->curs_hook = term_curs_win;
2903 t->bigcurs_hook = term_bigcurs_win;
2904 t->wipe_hook = term_wipe_win;
2905 t->text_hook = term_text_win;
2906 t->pict_hook = term_pict_win;
2908 /* Remember where we came from */
2909 t->data = (vptr)(td);
2914 * Create the windows
2916 * First, instantiate the "default" values, then read the "ini_file"
2917 * to over-ride selected values, then create the windows, and fonts.
2919 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2920 * must make active to realize the palette.
2922 static void init_windows(void)
2930 WIPE(td, term_data);
2934 td->s = angband_term_name[0];
2950 for (i = 1; i < MAX_TERM_DATA; i++)
2953 WIPE(td, term_data);
2954 td->s = angband_term_name[i];
2958 td->visible = FALSE;
2963 td->pos_x = (7 - i) * 30;
2964 td->pos_y = (7 - i) * 20;
2972 /* Main window (need these before term_getsize gets called) */
2974 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2975 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2980 /* Sub windows (need these before term_getsize gets called) */
2981 for (i = 1; i < MAX_TERM_DATA; i++)
2984 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2985 td->dwExStyle = (WS_EX_TOOLWINDOW);
2990 for (i = 0; i < MAX_TERM_DATA; i++)
2994 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2995 td->lf.lfCharSet = DEFAULT_CHARSET;
2996 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2997 /* Activate the chosen font */
2998 term_force_font(td, NULL);
2999 if (!td->tile_wid) td->tile_wid = td->font_wid;
3000 if (!td->tile_hgt) td->tile_hgt = td->font_hgt;
3002 /* Analyze the font */
3005 /* Resize the window */
3006 term_window_resize(td);
3010 /* Sub windows (reverse order) */
3011 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3016 td->w = CreateWindowEx(td->dwExStyle, AngList,
3018 td->pos_x, td->pos_y,
3019 td->size_wid, td->size_hgt,
3020 HWND_DESKTOP, NULL, hInstance, NULL);
3022 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3026 td->size_hack = TRUE;
3027 ShowWindow(td->w, SW_SHOW);
3028 td->size_hack = FALSE;
3032 angband_term[i] = &td->t;
3036 /* Activate the window */
3037 SetActiveWindow(td->w);
3042 term_window_pos(&data[i], HWND_TOPMOST);
3046 term_window_pos(&data[i], td->w);
3056 td->w = CreateWindowEx(td->dwExStyle, AppName,
3058 td->pos_x, td->pos_y,
3059 td->size_wid, td->size_hgt,
3060 HWND_DESKTOP, NULL, hInstance, NULL);
3062 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3065 angband_term[0] = &td->t;
3066 normsize.x = td->cols;
3067 normsize.y = td->rows;
3069 /* Activate the main window */
3070 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3071 else ShowWindow(td->w, SW_SHOW);
3073 /* Bring main window back to top */
3074 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3078 (void)new_palette();
3081 /* Create a "brush" for drawing the "cursor" */
3082 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3085 /* Process pending messages */
3086 (void)term_xtra_win_flush();
3094 static void setup_menus(void)
3098 HMENU hm = GetMenu(data[0].w);
3101 /* Menu "File", Disable all */
3102 EnableMenuItem(hm, IDM_FILE_NEW,
3103 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3104 EnableMenuItem(hm, IDM_FILE_OPEN,
3105 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3106 EnableMenuItem(hm, IDM_FILE_SAVE,
3107 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3108 EnableMenuItem(hm, IDM_FILE_EXIT,
3109 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3110 EnableMenuItem(hm, IDM_FILE_SCORE,
3111 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3114 /* No character available */
3115 if (!current_world_ptr->character_generated)
3117 /* Menu "File", Item "New" */
3118 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3120 /* Menu "File", Item "Open" */
3121 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3124 /* A character available */
3125 if (current_world_ptr->character_generated)
3127 /* Menu "File", Item "Save" */
3128 EnableMenuItem(hm, IDM_FILE_SAVE,
3129 MF_BYCOMMAND | MF_ENABLED);
3132 /* Menu "File", Item "Exit" */
3133 EnableMenuItem(hm, IDM_FILE_EXIT,
3134 MF_BYCOMMAND | MF_ENABLED);
3136 EnableMenuItem(hm, IDM_FILE_SCORE,
3137 MF_BYCOMMAND | MF_ENABLED);
3140 /* Menu "Window::Visibility" */
3141 for (i = 0; i < MAX_TERM_DATA; i++)
3143 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3144 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3146 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3147 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3149 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3150 MF_BYCOMMAND | MF_ENABLED);
3153 /* Menu "Window::Font" */
3154 for (i = 0; i < MAX_TERM_DATA; i++)
3156 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3157 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3159 if (data[i].visible)
3161 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3162 MF_BYCOMMAND | MF_ENABLED);
3166 /* Menu "Window::Window Position Fix" */
3167 for (i = 0; i < MAX_TERM_DATA; i++)
3169 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3170 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3172 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3173 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3175 if (data[i].visible)
3177 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3178 MF_BYCOMMAND | MF_ENABLED);
3182 /* Menu "Window::Bizarre Display" */
3183 for (i = 0; i < MAX_TERM_DATA; i++)
3185 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3186 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3188 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3189 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3191 if (data[i].visible)
3193 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3194 MF_BYCOMMAND | MF_ENABLED);
3199 /* Menu "Window::Increase Tile Width" */
3200 for (i = 0; i < MAX_TERM_DATA; i++)
3202 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3203 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3205 if (data[i].visible)
3207 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3208 MF_BYCOMMAND | MF_ENABLED);
3213 /* Menu "Window::Decrease Tile Width" */
3214 for (i = 0; i < MAX_TERM_DATA; i++)
3216 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3217 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3219 if (data[i].visible)
3221 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3222 MF_BYCOMMAND | MF_ENABLED);
3227 /* Menu "Window::Increase Tile Height" */
3228 for (i = 0; i < MAX_TERM_DATA; i++)
3230 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3231 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3233 if (data[i].visible)
3235 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3236 MF_BYCOMMAND | MF_ENABLED);
3241 /* Menu "Window::Decrease Tile Height" */
3242 for (i = 0; i < MAX_TERM_DATA; i++)
3244 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3245 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3247 if (data[i].visible)
3249 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3250 MF_BYCOMMAND | MF_ENABLED);
3255 /* Menu "Options", disable all */
3256 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3257 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3258 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3259 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3260 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3261 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3262 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3263 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3264 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3265 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3269 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3270 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3273 /* Menu "Options", Item "Map" */
3274 if (use_graphics != GRAPHICS_NONE)
3275 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3277 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3278 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3280 /* Menu "Options", update all */
3281 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3282 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3283 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3284 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3285 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3286 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3287 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3288 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3289 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3290 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3291 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3292 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3293 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3294 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3295 CheckMenuItem(hm, IDM_OPTIONS_BG,
3296 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3299 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3300 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3302 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3303 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3304 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3305 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3306 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3307 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3308 MF_BYCOMMAND | MF_ENABLED);
3313 * Check for double clicked (or dragged) savefile
3315 * Apparently, Windows copies the entire filename into the first
3316 * piece of the "command line string". Perhaps we should extract
3317 * the "basename" of that filename and append it to the "save" dir.
3319 static void check_for_save_file(player_type *player_ptr, LPSTR cmd_line)
3329 /* Extract filename */
3330 strcat(savefile, s);
3332 /* Validate the file */
3333 validate_file(savefile);
3335 /* Game in progress */
3336 game_in_progress = TRUE;
3339 play_game(player_ptr, FALSE);
3344 * Process a menu command
3346 static void process_menus(player_type *player_ptr, WORD wCmd)
3356 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3358 else if (game_in_progress)
3360 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3364 game_in_progress = TRUE;
3366 play_game(player_ptr, TRUE);
3375 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3377 else if (game_in_progress)
3379 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3383 memset(&ofn, 0, sizeof(ofn));
3384 ofn.lStructSize = sizeof(ofn);
3385 ofn.hwndOwner = data[0].w;
3386 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3387 ofn.nFilterIndex = 1;
3388 ofn.lpstrFile = savefile;
3389 ofn.nMaxFile = 1024;
3390 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3391 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3393 if (GetOpenFileName(&ofn))
3395 validate_file(savefile);
3396 game_in_progress = TRUE;
3398 play_game(player_ptr, FALSE);
3406 if (game_in_progress && current_world_ptr->character_generated)
3410 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3415 do_cmd_save_game(player_ptr, FALSE);
3419 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3426 if (game_in_progress && current_world_ptr->character_generated)
3430 plog(_("今は終了できません。", "You may not do that right now."));
3435 forget_lite(player_ptr->current_floor_ptr);
3436 forget_view(player_ptr->current_floor_ptr);
3437 clear_mon_lite(player_ptr->current_floor_ptr);
3439 Term_key_push(SPECIAL_KEY_QUIT);
3446 case IDM_FILE_SCORE:
3449 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3450 highscore_fd = fd_open(buf, O_RDONLY);
3451 if (highscore_fd < 0)
3453 msg_print("Score file unavailable.");
3459 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3460 (void)fd_close(highscore_fd);
3468 case IDM_FILE_MOVIE:
3472 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3474 else if (game_in_progress)
3476 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
3480 memset(&ofn, 0, sizeof(ofn));
3481 ofn.lStructSize = sizeof(ofn);
3482 ofn.hwndOwner = data[0].w;
3483 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3484 ofn.nFilterIndex = 1;
3485 ofn.lpstrFile = savefile;
3486 ofn.nMaxFile = 1024;
3487 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3488 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3490 if (GetOpenFileName(&ofn))
3492 prepare_browse_movie_aux(savefile);
3493 play_game(player_ptr, FALSE);
3500 case IDM_WINDOW_VIS_0:
3502 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
3505 case IDM_WINDOW_VIS_1:
3506 case IDM_WINDOW_VIS_2:
3507 case IDM_WINDOW_VIS_3:
3508 case IDM_WINDOW_VIS_4:
3509 case IDM_WINDOW_VIS_5:
3510 case IDM_WINDOW_VIS_6:
3511 case IDM_WINDOW_VIS_7:
3513 int i = wCmd - IDM_WINDOW_VIS_0;
3514 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3521 ShowWindow(td->w, SW_SHOW);
3522 term_data_redraw(player_ptr, td);
3526 td->visible = FALSE;
3528 ShowWindow(td->w, SW_HIDE);
3533 case IDM_WINDOW_FONT_0:
3534 case IDM_WINDOW_FONT_1:
3535 case IDM_WINDOW_FONT_2:
3536 case IDM_WINDOW_FONT_3:
3537 case IDM_WINDOW_FONT_4:
3538 case IDM_WINDOW_FONT_5:
3539 case IDM_WINDOW_FONT_6:
3540 case IDM_WINDOW_FONT_7:
3542 int i = wCmd - IDM_WINDOW_FONT_0;
3543 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3546 term_change_font(td);
3549 case IDM_WINDOW_POS_1:
3550 case IDM_WINDOW_POS_2:
3551 case IDM_WINDOW_POS_3:
3552 case IDM_WINDOW_POS_4:
3553 case IDM_WINDOW_POS_5:
3554 case IDM_WINDOW_POS_6:
3555 case IDM_WINDOW_POS_7:
3557 int i = wCmd - IDM_WINDOW_POS_0;
3558 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3561 if (!td->posfix && td->visible)
3564 term_window_pos(td, HWND_TOPMOST);
3569 term_window_pos(td, data[0].w);
3574 case IDM_WINDOW_BIZ_0:
3575 case IDM_WINDOW_BIZ_1:
3576 case IDM_WINDOW_BIZ_2:
3577 case IDM_WINDOW_BIZ_3:
3578 case IDM_WINDOW_BIZ_4:
3579 case IDM_WINDOW_BIZ_5:
3580 case IDM_WINDOW_BIZ_6:
3581 case IDM_WINDOW_BIZ_7:
3583 int i = wCmd - IDM_WINDOW_BIZ_0;
3584 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3587 td->bizarre = !td->bizarre;
3589 term_window_resize(td);
3592 case IDM_WINDOW_I_WID_0:
3593 case IDM_WINDOW_I_WID_1:
3594 case IDM_WINDOW_I_WID_2:
3595 case IDM_WINDOW_I_WID_3:
3596 case IDM_WINDOW_I_WID_4:
3597 case IDM_WINDOW_I_WID_5:
3598 case IDM_WINDOW_I_WID_6:
3599 case IDM_WINDOW_I_WID_7:
3601 int i = wCmd - IDM_WINDOW_I_WID_0;
3602 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3607 term_window_resize(td);
3610 case IDM_WINDOW_D_WID_0:
3611 case IDM_WINDOW_D_WID_1:
3612 case IDM_WINDOW_D_WID_2:
3613 case IDM_WINDOW_D_WID_3:
3614 case IDM_WINDOW_D_WID_4:
3615 case IDM_WINDOW_D_WID_5:
3616 case IDM_WINDOW_D_WID_6:
3617 case IDM_WINDOW_D_WID_7:
3619 int i = wCmd - IDM_WINDOW_D_WID_0;
3620 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3625 term_window_resize(td);
3628 case IDM_WINDOW_I_HGT_0:
3629 case IDM_WINDOW_I_HGT_1:
3630 case IDM_WINDOW_I_HGT_2:
3631 case IDM_WINDOW_I_HGT_3:
3632 case IDM_WINDOW_I_HGT_4:
3633 case IDM_WINDOW_I_HGT_5:
3634 case IDM_WINDOW_I_HGT_6:
3635 case IDM_WINDOW_I_HGT_7:
3637 int i = wCmd - IDM_WINDOW_I_HGT_0;
3638 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3643 term_window_resize(td);
3646 case IDM_WINDOW_D_HGT_0:
3647 case IDM_WINDOW_D_HGT_1:
3648 case IDM_WINDOW_D_HGT_2:
3649 case IDM_WINDOW_D_HGT_3:
3650 case IDM_WINDOW_D_HGT_4:
3651 case IDM_WINDOW_D_HGT_5:
3652 case IDM_WINDOW_D_HGT_6:
3653 case IDM_WINDOW_D_HGT_7:
3655 int i = wCmd - IDM_WINDOW_D_HGT_0;
3656 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3661 term_window_resize(td);
3664 case IDM_OPTIONS_NO_GRAPHICS:
3668 plog("You may not do that right now.");
3672 if (arg_graphics != GRAPHICS_NONE)
3674 arg_graphics = GRAPHICS_NONE;
3675 term_xtra_win_react(player_ptr);
3676 Term_key_push(KTRL('R'));
3681 case IDM_OPTIONS_OLD_GRAPHICS:
3685 plog("You may not do that right now.");
3689 if (arg_graphics != GRAPHICS_ORIGINAL)
3691 arg_graphics = GRAPHICS_ORIGINAL;
3692 term_xtra_win_react(player_ptr);
3693 Term_key_push(KTRL('R'));
3698 case IDM_OPTIONS_NEW_GRAPHICS:
3702 plog("You may not do that right now.");
3706 if (arg_graphics != GRAPHICS_ADAM_BOLT)
3708 arg_graphics = GRAPHICS_ADAM_BOLT;
3709 term_xtra_win_react(player_ptr);
3710 Term_key_push(KTRL('R'));
3715 case IDM_OPTIONS_NEW2_GRAPHICS:
3719 plog("You may not do that right now.");
3723 if (arg_graphics != GRAPHICS_HENGBAND)
3725 arg_graphics = GRAPHICS_HENGBAND;
3726 term_xtra_win_react(player_ptr);
3727 Term_key_push(KTRL('R'));
3732 case IDM_OPTIONS_BIGTILE:
3737 plog("You may not do that right now.");
3741 arg_bigtile = !arg_bigtile;
3742 Term_activate(&td->t);
3743 Term_resize(td->cols, td->rows);
3744 InvalidateRect(td->w, NULL, TRUE);
3747 case IDM_OPTIONS_MUSIC:
3751 plog("You may not do that right now.");
3755 arg_music = !arg_music;
3756 term_xtra_win_react(player_ptr);
3757 Term_key_push(KTRL('R'));
3760 case IDM_OPTIONS_SOUND:
3764 plog("You may not do that right now.");
3768 arg_sound = !arg_sound;
3769 term_xtra_win_react(player_ptr);
3770 Term_key_push(KTRL('R'));
3773 case IDM_OPTIONS_BG:
3777 plog("You may not do that right now.");
3783 term_xtra_win_react(player_ptr);
3784 Term_key_push(KTRL('R'));
3787 case IDM_OPTIONS_OPEN_BG:
3791 plog("You may not do that right now.");
3796 memset(&ofn, 0, sizeof(ofn));
3797 ofn.lStructSize = sizeof(ofn);
3798 ofn.hwndOwner = data[0].w;
3799 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3800 ofn.nFilterIndex = 1;
3801 ofn.lpstrFile = bg_bitmap_file;
3802 ofn.nMaxFile = 1023;
3803 ofn.lpstrInitialDir = NULL;
3804 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
3805 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3807 if (GetOpenFileName(&ofn))
3813 term_xtra_win_react(player_ptr);
3814 Term_key_push(KTRL('R'));
3819 case IDM_DUMP_SCREEN_HTML:
3821 static char buf[1024] = "";
3822 memset(&ofn, 0, sizeof(ofn));
3823 ofn.lStructSize = sizeof(ofn);
3824 ofn.hwndOwner = data[0].w;
3825 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
3826 ofn.nFilterIndex = 1;
3827 ofn.lpstrFile = buf;
3828 ofn.nMaxFile = 1023;
3829 ofn.lpstrDefExt = "html";
3830 ofn.lpstrInitialDir = NULL;
3831 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
3832 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
3834 if (GetSaveFileName(&ofn))
3836 do_cmd_save_screen_html_aux(buf, 0);
3840 case IDM_OPTIONS_SAVER:
3844 DestroyWindow(hwndSaver);
3849 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
3850 "Angband Screensaver",
3851 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
3852 0, 0, GetSystemMetrics(SM_CXSCREEN),
3853 GetSystemMetrics(SM_CYSCREEN),
3854 NULL, NULL, hInstance, NULL);
3858 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3862 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
3868 case IDM_OPTIONS_MAP:
3870 windows_map(player_ptr);
3874 case IDM_HELP_CONTENTS:
3878 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
3879 if (check_file(tmp))
3881 sprintf(buf, "winhelp.exe %s", tmp);
3882 WinExec(buf, SW_NORMAL);
3886 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
3887 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
3896 static bool process_keydown(WPARAM wParam, LPARAM lParam)
3902 /* Extract the modifiers */
3903 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
3904 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
3905 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
3907 term_no_press = (ma) ? TRUE : FALSE;
3909 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]))
3911 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
3912 bool numpad = FALSE;
3915 if (mc) Term_keypress('C');
3916 if (ms) Term_keypress('S');
3917 if (ma) Term_keypress('A');
3919 int i = LOBYTE(HIWORD(lParam));
3924 term_no_press = TRUE;
3943 term_no_press = TRUE;
3958 if (numpad) Term_keypress('K');
3960 Term_keypress(hexsym[i / 16]);
3961 Term_keypress(hexsym[i % 16]);
3972 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
3975 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
3976 WPARAM wParam, LPARAM lParam);
3977 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
3978 WPARAM wParam, LPARAM lParam)
3979 #else /* __MWERKS__ */
3980 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3981 #endif /* __MWERKS__ */
3986 td = (term_data *)GetWindowLong(hWnd, 0);
3992 SetWindowLong(hWnd, 0, (LONG)(my_td));
3997 mop.dwCallback = (DWORD)hWnd;
4000 case WM_GETMINMAXINFO:
4002 MINMAXINFO FAR *lpmmi;
4005 lpmmi = (MINMAXINFO FAR *)lParam;
4008 rc.left = rc.top = 0;
4009 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4010 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4012 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4014 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4015 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4021 BeginPaint(hWnd, &ps);
4022 if (td) term_data_redraw(p_ptr, td);
4023 EndPaint(hWnd, &ps);
4024 ValidateRect(hWnd, NULL);
4029 if (wParam == MCI_NOTIFY_SUCCESSFUL)
4031 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4032 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4040 if (process_keydown(wParam, lParam))
4046 if (term_no_press) term_no_press = FALSE;
4047 else Term_keypress(wParam);
4050 case WM_LBUTTONDOWN:
4052 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4053 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4063 TERM_LEN dx = abs(oldx - mousex) + 1;
4064 TERM_LEN dy = abs(oldy - mousey) + 1;
4065 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
4066 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
4072 int sz = (dx + 3) * dy;
4074 int sz = (dx + 2) * dy;
4076 hGlobal = GlobalAlloc(GHND, sz + 1);
4077 if (hGlobal == NULL) return 0;
4078 lpStr = (LPSTR)GlobalLock(hGlobal);
4080 for (int i = 0; i < dy; i++)
4084 char **scr = data[0].t.scr->c;
4086 C_MAKE(s, (dx + 1), char);
4087 strncpy(s, &scr[oy + i][ox], dx);
4091 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4094 if (ox + dx < data[0].cols)
4096 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4099 for (int j = 0; j < dx; j++)
4101 if (s[j] == 127) s[j] = '#';
4105 for (int j = 0; j < dx; j++)
4107 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4117 GlobalUnlock(hGlobal);
4118 if (OpenClipboard(hWnd) == 0)
4120 GlobalFree(hGlobal);
4124 SetClipboardData(CF_TEXT, hGlobal);
4136 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4137 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4142 dx = abs(oldx - mousex) + 1;
4143 dy = abs(oldy - mousey) + 1;
4144 ox = (oldx > mousex) ? mousex : oldx;
4145 oy = (oldy > mousey) ? mousey : oldy;
4146 term_inversed_area(hWnd, ox, oy, dx, dy);
4153 dx = abs(cx - mousex) + 1;
4154 dy = abs(cy - mousey) + 1;
4155 ox = (cx > mousex) ? mousex : cx;
4156 oy = (cy > mousey) ? mousey : cy;
4157 term_inversed_area(hWnd, ox, oy, dx, dy);
4172 if (game_in_progress && current_world_ptr->character_generated)
4176 plog(_("今は終了できません。", "You may not do that right now."));
4181 forget_lite(p_ptr->current_floor_ptr);
4182 forget_view(p_ptr->current_floor_ptr);
4183 clear_mon_lite(p_ptr->current_floor_ptr);
4184 Term_key_push(SPECIAL_KEY_QUIT);
4191 case WM_QUERYENDSESSION:
4193 if (game_in_progress && current_world_ptr->character_generated)
4196 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4197 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4199 p_ptr->panic_save = 1;
4200 signals_ignore_tstp();
4201 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4202 (void)save_player(p_ptr);
4215 process_menus(p_ptr, LOWORD(wParam));
4221 if (!td->w) return 1;
4222 if (td->size_hack) return 1;
4226 case SIZE_MINIMIZED:
4228 /* Hide sub-windows */
4229 for (int i = 1; i < MAX_TERM_DATA; i++)
4231 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4236 case SIZE_MAXIMIZED:
4242 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4243 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4244 if ((td->cols != cols) || (td->rows != rows))
4248 if (!IsZoomed(td->w) && !IsIconic(td->w))
4250 normsize.x = td->cols;
4251 normsize.y = td->rows;
4254 Term_activate(&td->t);
4255 Term_resize(td->cols, td->rows);
4256 InvalidateRect(td->w, NULL, TRUE);
4259 td->size_hack = TRUE;
4260 for (int i = 1; i < MAX_TERM_DATA; i++)
4262 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4265 td->size_hack = FALSE;
4273 case WM_PALETTECHANGED:
4275 if ((HWND)wParam == hWnd) return 0;
4277 case WM_QUERYNEWPALETTE:
4279 if (!paletted) return 0;
4282 SelectPalette(hdc, hPal, FALSE);
4283 int i = RealizePalette(hdc);
4284 if (i) InvalidateRect(hWnd, NULL, TRUE);
4286 ReleaseDC(hWnd, hdc);
4291 if (wParam && !HIWORD(lParam))
4293 for (int i = 1; i < MAX_TERM_DATA; i++)
4295 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4304 case WM_ACTIVATEAPP:
4306 if (IsIconic(td->w)) break;
4308 for (int i = 1; i < MAX_TERM_DATA; i++)
4310 if (data[i].visible)
4314 ShowWindow(data[i].w, SW_SHOW);
4318 ShowWindow(data[i].w, SW_HIDE);
4325 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4330 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
4333 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4334 WPARAM wParam, LPARAM lParam);
4335 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4336 WPARAM wParam, LPARAM lParam)
4337 #else /* __MWERKS__ */
4338 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4339 WPARAM wParam, LPARAM lParam)
4340 #endif /* __MWERKS__ */
4345 td = (term_data *)GetWindowLong(hWnd, 0);
4351 SetWindowLong(hWnd, 0, (LONG)(my_td));
4358 case WM_GETMINMAXINFO:
4360 MINMAXINFO FAR *lpmmi;
4363 lpmmi = (MINMAXINFO FAR *)lParam;
4366 rc.left = rc.top = 0;
4367 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4368 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4370 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4371 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4372 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4379 if (!td->w) return 1;
4380 if (td->size_hack) return 1;
4382 td->size_hack = TRUE;
4384 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4385 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4386 if ((td->cols != cols) || (td->rows != rows))
4388 term *old_term = Term;
4391 Term_activate(&td->t);
4392 Term_resize(td->cols, td->rows);
4393 Term_activate(old_term);
4394 InvalidateRect(td->w, NULL, TRUE);
4395 p_ptr->window = 0xFFFFFFFF;
4396 handle_stuff(p_ptr);
4399 td->size_hack = FALSE;
4405 BeginPaint(hWnd, &ps);
4406 if (td) term_data_redraw(p_ptr, td);
4407 EndPaint(hWnd, &ps);
4413 if (process_keydown(wParam, lParam))
4419 if (term_no_press) term_no_press = FALSE;
4420 else Term_keypress(wParam);
4423 case WM_PALETTECHANGED:
4425 if ((HWND)wParam == hWnd) return FALSE;
4427 case WM_QUERYNEWPALETTE:
4429 if (!paletted) return 0;
4431 SelectPalette(hdc, hPal, FALSE);
4432 int i = RealizePalette(hdc);
4433 if (i) InvalidateRect(hWnd, NULL, TRUE);
4434 ReleaseDC(hWnd, hdc);
4437 case WM_NCLBUTTONDOWN:
4440 if (wParam == HTCLOSE) wParam = HTSYSMENU;
4441 #endif /* HTCLOSE */
4443 if (wParam == HTSYSMENU)
4447 td->visible = FALSE;
4448 ShowWindow(td->w, SW_HIDE);
4458 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4462 #define MOUSE_SENS 40
4465 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4466 WPARAM wParam, LPARAM lParam);
4467 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4468 WPARAM wParam, LPARAM lParam)
4469 #else /* __MWERKS__ */
4470 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4471 WPARAM wParam, LPARAM lParam)
4472 #endif /* __MWERKS__ */
4474 static int iMouse = 0;
4475 static WORD xMouse = 0;
4476 static WORD yMouse = 0;
4491 case WM_LBUTTONDOWN:
4492 case WM_MBUTTONDOWN:
4493 case WM_RBUTTONDOWN:
4496 SendMessage(hWnd, WM_CLOSE, 0, 0);
4503 int dx = LOWORD(lParam) - xMouse;
4504 int dy = HIWORD(lParam) - yMouse;
4506 if (dx < 0) dx = -dx;
4507 if (dy < 0) dy = -dy;
4509 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
4511 SendMessage(hWnd, WM_CLOSE, 0, 0);
4516 xMouse = LOWORD(lParam);
4517 yMouse = HIWORD(lParam);
4523 DestroyWindow(hwndSaver);
4529 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4534 * Display warning message (see "z-util.c")
4536 static void hack_plog(concptr str)
4541 MessageBox(NULL, str, "警告!",
4542 MB_ICONEXCLAMATION | MB_OK);
4544 MessageBox(NULL, str, "Warning",
4545 MB_ICONEXCLAMATION | MB_OK);
4553 * Display error message and quit (see "z-util.c")
4555 static void hack_quit(concptr str)
4560 MessageBox(NULL, str, "エラー!",
4561 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4563 MessageBox(NULL, str, "Error",
4564 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4569 UnregisterClass(AppName, hInstance);
4570 if (hIcon) DestroyIcon(hIcon);
4577 * Display warning message (see "z-util.c")
4579 static void hook_plog(concptr str)
4584 MessageBox(data[0].w, str, "警告!",
4585 MB_ICONEXCLAMATION | MB_OK);
4587 MessageBox(data[0].w, str, "Warning",
4588 MB_ICONEXCLAMATION | MB_OK);
4596 * Display error message and quit (see "z-util.c")
4598 static void hook_quit(concptr str)
4603 MessageBox(data[0].w, str, "エラー!",
4604 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4606 MessageBox(data[0].w, str, "Error",
4607 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4612 for (int i = MAX_TERM_DATA - 1; i >= 0; --i)
4614 term_force_font(&data[i], NULL);
4615 if (data[i].font_want) string_free(data[i].font_want);
4616 if (data[i].w) DestroyWindow(data[i].w);
4620 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
4621 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
4622 if (infMask.hPalette) DeleteObject(infMask.hPalette);
4623 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
4625 DeleteObject(hbrYellow);
4628 if (hPal) DeleteObject(hPal);
4630 UnregisterClass(AppName, hInstance);
4631 if (hIcon) DestroyIcon(hIcon);
4640 static void init_stuff(void)
4643 GetModuleFileName(hInstance, path, 512);
4645 strcpy(path + strlen(path) - 4, ".INI");
4646 ini_file = string_make(path);
4647 int i = strlen(path);
4651 if (path[i] == '\\')
4657 strcpy(path + i + 1, "lib\\");
4658 validate_dir(path, TRUE);
4659 init_file_paths(path);
4660 validate_dir(ANGBAND_DIR_APEX, FALSE);
4661 validate_dir(ANGBAND_DIR_BONE, FALSE);
4662 if (!check_dir(ANGBAND_DIR_EDIT))
4664 validate_dir(ANGBAND_DIR_DATA, TRUE);
4668 validate_dir(ANGBAND_DIR_DATA, FALSE);
4671 validate_dir(ANGBAND_DIR_FILE, TRUE);
4672 validate_dir(ANGBAND_DIR_HELP, FALSE);
4673 validate_dir(ANGBAND_DIR_INFO, FALSE);
4674 validate_dir(ANGBAND_DIR_PREF, TRUE);
4675 validate_dir(ANGBAND_DIR_SAVE, FALSE);
4676 validate_dir(ANGBAND_DIR_USER, TRUE);
4677 validate_dir(ANGBAND_DIR_XTRA, TRUE);
4678 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
4680 validate_file(path);
4681 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
4682 ANGBAND_DIR_XTRA_GRAF = string_make(path);
4683 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
4685 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
4686 ANGBAND_DIR_XTRA_SOUND = string_make(path);
4687 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
4689 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
4690 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
4691 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
4693 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
4694 ANGBAND_DIR_XTRA_HELP = string_make(path);
4699 * todo よく見るとhMutexはちゃんと使われていない……?
4700 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
4702 static bool is_already_running(void)
4705 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
4706 if (GetLastError() == ERROR_ALREADY_EXISTS)
4716 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
4718 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
4719 LPSTR lpCmdLine, int nCmdShow)
4725 setlocale(LC_ALL, "ja_JP.utf8");
4728 if (is_already_running())
4731 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
4733 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4737 if (hPrevInst == NULL)
4739 wc.style = CS_CLASSDC;
4740 wc.lpfnWndProc = AngbandWndProc;
4743 wc.hInstance = hInst;
4744 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
4745 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
4746 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
4747 wc.lpszMenuName = AppName;
4748 wc.lpszClassName = AppName;
4750 if (!RegisterClass(&wc)) exit(1);
4752 wc.lpfnWndProc = AngbandListProc;
4753 wc.lpszMenuName = NULL;
4754 wc.lpszClassName = AngList;
4756 if (!RegisterClass(&wc)) exit(2);
4758 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
4759 wc.lpfnWndProc = AngbandSaverProc;
4761 wc.lpszMenuName = NULL;
4762 wc.lpszClassName = "WindowsScreenSaverClass";
4764 if (!RegisterClass(&wc)) exit(3);
4767 plog_aux = hack_plog;
4768 quit_aux = hack_quit;
4769 core_aux = hack_quit;
4772 for (int i = 0; special_key_list[i]; ++i)
4774 special_key[special_key_list[i]] = TRUE;
4777 for (int i = 0; ignore_key_list[i]; ++i)
4779 ignore_key[ignore_key_list[i]] = TRUE;
4783 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
4784 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
4785 ReleaseDC(NULL, hdc);
4787 for (int i = 0; i < 256; i++)
4789 byte rv = angband_color_table[i][1];
4790 byte gv = angband_color_table[i][2];
4791 byte bv = angband_color_table[i][3];
4792 win_clr[i] = PALETTERGB(rv, gv, bv);
4793 angband_color_table[i][0] = win_pal[i];
4799 plog_aux = hook_plog;
4800 quit_aux = hook_quit;
4801 core_aux = hook_quit;
4803 ANGBAND_SYS = "win";
4804 if (7 != GetKeyboardType(0))
4805 ANGBAND_KEYBOARD = "0";
4808 /* todo PC-98のサポートは打ち切ったので削除したい */
4809 switch (GetKeyboardType(1))
4811 case 0x0D01: case 0x0D02:
4812 case 0x0D03: case 0x0D04:
4813 case 0x0D05: case 0x0D06:
4815 ANGBAND_KEYBOARD = "NEC98";
4819 ANGBAND_KEYBOARD = "JAPAN";
4824 Term_activate(term_screen);
4825 init_angband(p_ptr);
4828 if (lpCmdLine[0] == '-') {
4829 switch (lpCmdLine[1])
4834 if (!lpCmdLine[2]) break;
4835 chuukei_server = TRUE;
4836 if (connect_chuukei_server(&lpCmdLine[2]) < 0) {
4837 msg_print("connect fail");
4840 msg_print("connect");
4848 if (!lpCmdLine[2]) break;
4849 chuukei_client = TRUE;
4850 connect_chuukei_server(&lpCmdLine[2]);
4851 play_game(player_ptr, FALSE);
4858 if (!lpCmdLine[2]) break;
4859 prepare_browse_movie(&lpCmdLine[2]);
4860 play_game(player_ptr, FALSE);
4869 if (!chuukei_server) check_for_save_file(lpCmdLine);
4871 check_for_save_file(p_ptr, lpCmdLine);
4874 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
4876 while (GetMessage(&msg, NULL, 0, 0))
4878 TranslateMessage(&msg);
4879 DispatchMessage(&msg);
4885 #endif /* WINDOWS */