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 * Hack -- allow use of "screen saver" mode
145 * Menu constants -- see "ANGBAND.RC"
148 #define IDM_FILE_NEW 100
149 #define IDM_FILE_OPEN 101
150 #define IDM_FILE_SAVE 110
151 #define IDM_FILE_SCORE 120
152 #define IDM_FILE_MOVIE 121
153 #define IDM_FILE_EXIT 130
155 #define IDM_WINDOW_VIS_0 200
156 #define IDM_WINDOW_VIS_1 201
157 #define IDM_WINDOW_VIS_2 202
158 #define IDM_WINDOW_VIS_3 203
159 #define IDM_WINDOW_VIS_4 204
160 #define IDM_WINDOW_VIS_5 205
161 #define IDM_WINDOW_VIS_6 206
162 #define IDM_WINDOW_VIS_7 207
164 #define IDM_WINDOW_FONT_0 210
165 #define IDM_WINDOW_FONT_1 211
166 #define IDM_WINDOW_FONT_2 212
167 #define IDM_WINDOW_FONT_3 213
168 #define IDM_WINDOW_FONT_4 214
169 #define IDM_WINDOW_FONT_5 215
170 #define IDM_WINDOW_FONT_6 216
171 #define IDM_WINDOW_FONT_7 217
173 #define IDM_WINDOW_POS_0 220
174 #define IDM_WINDOW_POS_1 221
175 #define IDM_WINDOW_POS_2 222
176 #define IDM_WINDOW_POS_3 223
177 #define IDM_WINDOW_POS_4 224
178 #define IDM_WINDOW_POS_5 225
179 #define IDM_WINDOW_POS_6 226
180 #define IDM_WINDOW_POS_7 227
182 #define IDM_WINDOW_BIZ_0 230
183 #define IDM_WINDOW_BIZ_1 231
184 #define IDM_WINDOW_BIZ_2 232
185 #define IDM_WINDOW_BIZ_3 233
186 #define IDM_WINDOW_BIZ_4 234
187 #define IDM_WINDOW_BIZ_5 235
188 #define IDM_WINDOW_BIZ_6 236
189 #define IDM_WINDOW_BIZ_7 237
191 #define IDM_WINDOW_I_WID_0 240
192 #define IDM_WINDOW_I_WID_1 241
193 #define IDM_WINDOW_I_WID_2 242
194 #define IDM_WINDOW_I_WID_3 243
195 #define IDM_WINDOW_I_WID_4 244
196 #define IDM_WINDOW_I_WID_5 245
197 #define IDM_WINDOW_I_WID_6 246
198 #define IDM_WINDOW_I_WID_7 247
200 #define IDM_WINDOW_D_WID_0 250
201 #define IDM_WINDOW_D_WID_1 251
202 #define IDM_WINDOW_D_WID_2 252
203 #define IDM_WINDOW_D_WID_3 253
204 #define IDM_WINDOW_D_WID_4 254
205 #define IDM_WINDOW_D_WID_5 255
206 #define IDM_WINDOW_D_WID_6 256
207 #define IDM_WINDOW_D_WID_7 257
209 #define IDM_WINDOW_I_HGT_0 260
210 #define IDM_WINDOW_I_HGT_1 261
211 #define IDM_WINDOW_I_HGT_2 262
212 #define IDM_WINDOW_I_HGT_3 263
213 #define IDM_WINDOW_I_HGT_4 264
214 #define IDM_WINDOW_I_HGT_5 265
215 #define IDM_WINDOW_I_HGT_6 266
216 #define IDM_WINDOW_I_HGT_7 267
218 #define IDM_WINDOW_D_HGT_0 270
219 #define IDM_WINDOW_D_HGT_1 271
220 #define IDM_WINDOW_D_HGT_2 272
221 #define IDM_WINDOW_D_HGT_3 273
222 #define IDM_WINDOW_D_HGT_4 274
223 #define IDM_WINDOW_D_HGT_5 275
224 #define IDM_WINDOW_D_HGT_6 276
225 #define IDM_WINDOW_D_HGT_7 277
227 #define IDM_OPTIONS_NO_GRAPHICS 400
228 #define IDM_OPTIONS_OLD_GRAPHICS 401
229 #define IDM_OPTIONS_NEW_GRAPHICS 402
230 #define IDM_OPTIONS_NEW2_GRAPHICS 403
231 #define IDM_OPTIONS_BIGTILE 409
232 #define IDM_OPTIONS_SOUND 410
233 #define IDM_OPTIONS_MUSIC 411
234 #define IDM_OPTIONS_SAVER 420
235 #define IDM_OPTIONS_MAP 430
236 #define IDM_OPTIONS_BG 440
237 #define IDM_OPTIONS_OPEN_BG 441
239 #define IDM_DUMP_SCREEN_HTML 450
241 #define IDM_HELP_CONTENTS 901
244 * Exclude parts of WINDOWS.H that are not needed
246 #define NOCOMM /* Comm driver APIs and definitions */
247 #define NOLOGERROR /* LogError() and related definitions */
248 #define NOPROFILER /* Profiler APIs */
249 #define NOLFILEIO /* _l* file I/O routines */
250 #define NOOPENFILE /* OpenFile and related definitions */
251 #define NORESOURCE /* Resource management */
252 #define NOATOM /* Atom management */
253 #define NOLANGUAGE /* Character test routines */
254 #define NOLSTRING /* lstr* string management routines */
255 #define NODBCS /* Double-byte character set routines */
256 #define NOKEYBOARDINFO /* Keyboard driver routines */
257 #define NOCOLOR /* COLOR_* color values */
258 #define NODRAWTEXT /* DrawText() and related definitions */
259 #define NOSCALABLEFONT /* Truetype scalable font support */
260 #define NOMETAFILE /* Metafile support */
261 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
262 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
263 #define NOKEYSTATES /* MK_* message key state flags */
264 #define NOWH /* SetWindowsHook and related WH_* definitions */
265 #define NOCLIPBOARD /* Clipboard APIs and definitions */
266 #define NOICONS /* IDI_* icon IDs */
267 #define NOMDI /* MDI support */
268 #define NOHELP /* Help support */
270 /* Not defined since it breaks Borland C++ 5.5 */
271 /* #define NOCTLMGR */ /* Control management and controls */
274 * Exclude parts of WINDOWS.H that are not needed (Win32)
276 #define WIN32_LEAN_AND_MEAN
277 #define NONLS /* All NLS defines and routines */
278 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
279 #define NOKANJI /* Kanji support stuff. */
280 #define NOMCX /* Modem Configuration Extensions */
283 * Include the "windows" support file
288 * Exclude parts of MMSYSTEM.H that are not needed
290 #define MMNODRV /* Installable driver support */
291 #define MMNOWAVE /* Waveform support */
292 #define MMNOMIDI /* MIDI support */
293 #define MMNOAUX /* Auxiliary audio support */
294 #define MMNOTIMER /* Timer support */
295 #define MMNOJOY /* Joystick support */
296 #define MMNOMCI /* MCI support */
297 #define MMNOMMIO /* Multimedia file I/O support */
298 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
301 * Standard sound names
303 const concptr angband_sound_name[SOUND_MAX] =
375 * Standard music names
377 const concptr angband_music_basic_name[MUSIC_BASIC_MAX] =
403 * Include some more files. Note: the Cygnus Cygwin compiler
404 * doesn't use mmsystem.h instead it includes the winmm library
405 * which performs a similar function.
407 #include <mmsystem.h>
411 * Include the support for loading bitmaps
416 * Hack -- Fake declarations from "dos.h"
419 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
421 #define FA_LABEL 0x08 /* Volume label */
422 #define FA_DIREC 0x10 /* Directory */
423 unsigned _cdecl _dos_getfileattr(concptr, unsigned *);
427 * Silliness in WIN32 drawing routine
430 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
434 * Silliness for Windows 95
436 #ifndef WS_EX_TOOLWINDOW
437 # define WS_EX_TOOLWINDOW 0
441 * Foreground color bits (hard-coded by DOS)
443 #define VID_BLACK 0x00
444 #define VID_BLUE 0x01
445 #define VID_GREEN 0x02
446 #define VID_CYAN 0x03
448 #define VID_MAGENTA 0x05
449 #define VID_YELLOW 0x06
450 #define VID_WHITE 0x07
453 * Bright text (hard-coded by DOS)
455 #define VID_BRIGHT 0x08
458 * Background color bits (hard-coded by DOS)
460 #define VUD_BLACK 0x00
461 #define VUD_BLUE 0x10
462 #define VUD_GREEN 0x20
463 #define VUD_CYAN 0x30
465 #define VUD_MAGENTA 0x50
466 #define VUD_YELLOW 0x60
467 #define VUD_WHITE 0x70
470 * Blinking text (hard-coded by DOS)
472 #define VUD_BRIGHT 0x80
478 typedef struct _term_data term_data;
482 * @brief ターム情報構造体 / Extra "term" data
485 * pos_x / pos_y は各タームの左上点座標を指す。
488 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
489 * 1ドットずつ調整するステータスを指す。
490 * また、フォントを変更すると都度自動調整される。
493 * Note the use of "font_want" for the names of the font file requested by
494 * the user, and the use of "font_file" for the currently active font file.
496 * The "font_file" is uppercased, and takes the form "8X13.FON", while
497 * "font_want" can be in almost any form as long as it could be construed
498 * as attempting to represent the name of a font.
510 TERM_LEN rows; /* int -> uint */
513 uint pos_x; //!< タームの左上X座標
514 uint pos_y; //!< タームの左上Y座標
529 int font_wid; //!< フォント横幅
530 int font_hgt; //!< フォント縦幅
531 int tile_wid; //!< タイル横幅
532 int tile_hgt; //!< タイル縦幅
544 #define MAX_TERM_DATA 8 //!< Maximum number of windows
546 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
547 static term_data *my_td; //!< Hack -- global "window creation" pointer
548 POINT normsize; //!< Remember normal size of main window when maxmized
551 * was main window maximized on previous playing
553 bool win_maximized = FALSE;
558 bool game_in_progress = FALSE;
561 * note when "open"/"new" become valid
563 bool initialized = FALSE;
566 * screen paletted, i.e. 256 colors
568 bool paletted = FALSE;
571 * 16 colors screen, don't use RGB()
573 bool colors16 = FALSE;
576 * Saved instance handle
578 static HINSTANCE hInstance;
581 * Yellow brush for the cursor
583 static HBRUSH hbrYellow;
593 static HPALETTE hPal;
596 static HBITMAP hBG = NULL;
597 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
598 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
603 * The screen saver window
605 static HWND hwndSaver;
607 #endif /* USE_SAVER */
611 * 現在使用中のタイルID(0ならば未使用)
612 * Flag set once "graphics" has been initialized
614 static byte_hack current_graphics_mode = 0;
619 static DIBINIT infGraph;
622 * The global bitmap mask
624 static DIBINIT infMask;
628 * Flag set once "sound" has been initialized
630 static bool can_use_sound = FALSE;
632 #define SAMPLE_SOUND_MAX 16
634 * An array of sound file names
636 static concptr sound_file[SOUND_MAX][SAMPLE_SOUND_MAX];
638 #define SAMPLE_MUSIC_MAX 16
639 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
640 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
641 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
642 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
643 static bool can_use_music = FALSE;
645 static MCI_OPEN_PARMS mop;
646 static char mci_device_type[256];
648 int current_music_type = 0;
649 int current_music_id = 0;
652 * Full path to ANGBAND.INI
654 static concptr ini_file = NULL;
657 * Name of application
659 static concptr AppName = "ANGBAND";
662 * Name of sub-window type
664 static concptr AngList = "AngList";
669 static concptr ANGBAND_DIR_XTRA_GRAF;
670 static concptr ANGBAND_DIR_XTRA_SOUND;
671 static concptr ANGBAND_DIR_XTRA_MUSIC;
672 static concptr ANGBAND_DIR_XTRA_HELP;
673 static concptr ANGBAND_DIR_XTRA_MUSIC;
676 * The "complex" color values
678 static COLORREF win_clr[256];
682 * Flag for macro trigger with dump ASCII
684 static bool term_no_press = FALSE;
689 static bool mouse_down = FALSE;
690 static bool paint_rect = FALSE;
691 static TERM_LEN mousex = 0, mousey = 0;
692 static TERM_LEN oldx, oldy;
696 * @brief The "simple" color values
698 * See "main-ibm.c" for original table information
699 * The entries below are taken from the "color bits" defined above.
700 * Note that many of the choices below suck, but so do crappy monitors.
702 static BYTE win_pal[256] =
704 VID_BLACK, /* Dark */
705 VID_WHITE, /* White */
706 VID_CYAN, /* Slate XXX */
707 VID_RED | VID_BRIGHT, /* Orange XXX */
709 VID_GREEN, /* Green */
711 VID_YELLOW, /* Umber XXX */
712 VID_BLACK | VID_BRIGHT, /* Light Dark */
713 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
714 VID_MAGENTA, /* Violet XXX */
715 VID_YELLOW | VID_BRIGHT, /* Yellow */
716 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
717 VID_GREEN | VID_BRIGHT, /* Light Green */
718 VID_BLUE | VID_BRIGHT, /* Light Blue */
719 VID_YELLOW /* Light Umber XXX */
724 * Hack -- define which keys are "special"
726 static bool special_key[256];
727 static bool ignore_key[256];
730 * Hack -- initialization list for "special_key"
732 static byte special_key_list[] = {
733 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
734 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
735 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
736 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
737 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
738 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
739 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
740 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
741 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
742 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
743 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
744 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
745 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
746 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
747 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
748 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
749 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
754 static byte ignore_key_list[] = {
755 VK_ESCAPE, VK_TAB, VK_SPACE,
756 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
757 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
758 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
763 /* Function prototype */
765 static bool is_already_running(void);
769 static void delete_bg(void)
778 static int init_bg(void)
780 char * bmfile = bg_bitmap_file;
783 if (use_bg == 0) return 0;
785 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
787 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
795 static void DrawBG(HDC hdc, RECT *r)
800 int x = r->left, y = r->top;
801 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
807 GetObject(hBG, sizeof(bm), &bm);
808 swid = bm.bmWidth; shgt = bm.bmHeight;
810 hdcSrc = CreateCompatibleDC(hdc);
811 hOld = SelectObject(hdcSrc, hBG);
815 cwid = MIN(swid - sx, r->right - nx);
818 chgt = MIN(shgt - sy, r->bottom - ny);
819 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
821 } while (ny < r->bottom);
824 } while (nx < r->right);
826 SelectObject(hdcSrc, hOld);
832 * Check for existance of a file
834 static bool check_file(concptr s)
854 attrib = GetFileAttributes(path);
856 /* Require valid filename */
857 if (attrib == INVALID_FILE_NAME) return FALSE;
859 /* Prohibit directory */
860 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return FALSE;
864 /* Examine and verify */
865 if (_dos_getfileattr(path, &attrib)) return FALSE;
867 /* Prohibit something */
868 if (attrib & FA_LABEL) return FALSE;
870 /* Prohibit directory */
871 if (attrib & FA_DIREC) return FALSE;
881 * Check for existance of a directory
883 static bool check_dir(concptr s)
905 /* Remove trailing backslash */
906 if (i && (path[i - 1] == '\\')) path[--i] = '\0';
911 attrib = GetFileAttributes(path);
913 /* Require valid filename */
914 if (attrib == INVALID_FILE_NAME) return FALSE;
916 /* Require directory */
917 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return FALSE;
921 /* Examine and verify */
922 if (_dos_getfileattr(path, &attrib)) return FALSE;
924 /* Prohibit something */
925 if (attrib & FA_LABEL) return FALSE;
927 /* Require directory */
928 if (!(attrib & FA_DIREC)) return FALSE;
940 static void validate_file(concptr s)
945 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
951 * Validate a directory
953 static void validate_dir(concptr s, bool vital)
958 /* This directory contains needed data */
961 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
963 /* Attempt to create this directory */
966 quit_fmt("Unable to create directory:\n%s", s);
973 * @brief (Windows版固有実装)Get the "size" for a window
975 static void term_getsize(term_data *td)
979 if (td->cols < 1) td->cols = 1;
980 if (td->rows < 1) td->rows = 1;
983 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
984 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
986 /* Fake window size */
988 rc.right = rc.left + wid;
990 rc.bottom = rc.top + hgt;
993 /* rc.bottom += 1; */
996 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
999 td->size_wid = rc.right - rc.left;
1000 td->size_hgt = rc.bottom - rc.top;
1002 /* See CreateWindowEx */
1005 /* Extract actual location */
1006 GetWindowRect(td->w, &rc);
1008 /* Save the location */
1009 td->pos_x = rc.left;
1015 * Write the "prefs" for a single term
1017 static void save_prefs_aux(int i)
1019 term_data *td = &data[i];
1020 GAME_TEXT sec_name[128];
1024 WINDOWPLACEMENT lpwndpl;
1027 /* Make section name */
1028 sprintf(sec_name, "Term-%d", i);
1033 strcpy(buf, td->visible ? "1" : "0");
1034 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1039 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "MS ゴシック");
1041 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "Courier");
1044 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1046 wsprintf(buf, "%d", td->lf.lfWidth);
1047 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1048 wsprintf(buf, "%d", td->lf.lfHeight);
1049 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1050 wsprintf(buf, "%d", td->lf.lfWeight);
1051 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1053 strcpy(buf, td->bizarre ? "1" : "0");
1054 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1057 wsprintf(buf, "%d", td->tile_wid);
1058 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1061 wsprintf(buf, "%d", td->tile_hgt);
1062 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1064 /* Get window placement and dimensions */
1065 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1066 GetWindowPlacement(td->w, &lpwndpl);
1068 /* Acquire position in *normal* mode (not minimized) */
1069 rc = lpwndpl.rcNormalPosition;
1071 /* Window size (x) */
1072 if (i == 0) wsprintf(buf, "%d", normsize.x);
1073 else wsprintf(buf, "%d", td->cols);
1074 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1076 /* Window size (y) */
1077 if (i == 0) wsprintf(buf, "%d", normsize.y);
1078 else wsprintf(buf, "%d", td->rows);
1079 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1081 /* Maxmized (only main window) */
1084 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1085 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1088 /* Acquire position */
1089 GetWindowRect(td->w, &rc);
1091 /* Window position (x) */
1092 wsprintf(buf, "%d", rc.left);
1093 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1095 /* Window position (y) */
1096 wsprintf(buf, "%d", rc.top);
1097 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1099 /* Window Z position */
1102 strcpy(buf, td->posfix ? "1" : "0");
1103 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1110 * We assume that the windows have all been initialized
1112 static void save_prefs(void)
1118 /* Save the "arg_graphics" flag */
1119 sprintf(buf, "%d", arg_graphics);
1120 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1122 /* Save the "arg_bigtile" flag */
1123 strcpy(buf, arg_bigtile ? "1" : "0");
1124 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1126 /* Save the "arg_sound" flag */
1127 strcpy(buf, arg_sound ? "1" : "0");
1128 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1130 /* Save the "arg_sound" flag */
1131 strcpy(buf, arg_music ? "1" : "0");
1132 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1135 strcpy(buf, use_bg ? "1" : "0");
1136 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1137 WritePrivateProfileString("Angband", "BackGroundBitmap",
1138 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1140 /* Save window prefs */
1141 for (i = 0; i < MAX_TERM_DATA; ++i)
1149 * Load the "prefs" for a single term
1151 static void load_prefs_aux(int i)
1153 term_data *td = &data[i];
1154 GAME_TEXT sec_name[128];
1157 int wid, hgt, posx, posy;
1158 int dispx = GetSystemMetrics(SM_CXVIRTUALSCREEN);
1159 int dispy = GetSystemMetrics(SM_CYVIRTUALSCREEN);
1163 /* Make section name */
1164 sprintf(sec_name, "Term-%d", i);
1166 /* Make section name */
1167 sprintf(sec_name, "Term-%d", i);
1172 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1175 /* Desired font, with default */
1177 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1179 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1184 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1186 /* Analyze font, save desired font name */
1187 td->font_want = string_make(tmp);
1189 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1190 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1191 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1194 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1195 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1198 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1199 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1200 normsize.x = td->cols; normsize.y = td->rows;
1205 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
1208 /* Window position */
1209 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1210 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1211 td->pos_x = MIN(MAX(0, posx), dispx - 128);
1212 td->pos_y = MIN(MAX(0, posy), dispy - 128);
1214 /* Window Z position */
1217 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
1225 static void load_prefs(void)
1229 /* Extract the "arg_graphics" flag */
1230 arg_graphics = (byte_hack)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1232 /* Extract the "arg_bigtile" flag */
1233 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
1234 use_bigtile = arg_bigtile;
1236 /* Extract the "arg_sound" flag */
1237 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1239 /* Extract the "arg_sound" flag */
1240 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1243 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1244 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1246 /* Load window prefs */
1247 for (i = 0; i < MAX_TERM_DATA; ++i)
1255 * - Taken from files.c.
1257 * Extract "tokens" from a buffer
1259 * This function uses "whitespace" as delimiters, and treats any amount of
1260 * whitespace as a single delimiter. We will never return any empty tokens.
1261 * When given an empty buffer, or a buffer containing only "whitespace", we
1262 * will return no tokens. We will never extract more than "num" tokens.
1264 * By running a token through the "text_to_ascii()" function, you can allow
1265 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1267 * We save pointers to the tokens in "tokens", and return the number found.
1269 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1279 /* Skip leading whitespace */
1280 for (; *s && iswspace(*s); ++s) /* loop */;
1285 /* Find next whitespace, if any */
1286 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1288 /* Nuke and advance (if necessary) */
1289 if (*t) *t++ = '\0';
1291 /* Save the token */
1303 static void load_sound_prefs(void)
1307 char ini_path[1024];
1308 char wav_path[1024];
1309 char *zz[SAMPLE_SOUND_MAX];
1311 /* Access the sound.cfg */
1313 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1315 for (i = 0; i < SOUND_MAX; i++)
1317 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1319 num = tokenize_whitespace(tmp, SAMPLE_SOUND_MAX, zz);
1321 for (j = 0; j < num; j++)
1323 /* Access the sound */
1324 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1326 /* Save the sound filename, if it exists */
1327 if (check_file(wav_path))
1328 sound_file[i][j] = string_make(zz[j]);
1334 static void load_music_prefs(void)
1338 char ini_path[1024];
1339 char wav_path[1024];
1340 char *zz[SAMPLE_MUSIC_MAX];
1343 /* Access the music.cfg */
1345 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1347 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1349 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1351 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1353 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1355 for (j = 0; j < num; j++)
1357 /* Access the sound */
1358 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1360 /* Save the sound filename, if it exists */
1361 if (check_file(wav_path))
1362 music_file[i][j] = string_make(zz[j]);
1366 for (i = 0; i < current_world_ptr->max_d_idx; i++)
1368 sprintf(key, "dungeon%03d", i);
1369 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1371 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1373 for (j = 0; j < num; j++)
1375 /* Access the sound */
1376 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1378 /* Save the sound filename, if it exists */
1379 if (check_file(wav_path))
1380 dungeon_music_file[i][j] = string_make(zz[j]);
1384 for (i = 0; i < max_q_idx; i++)
1386 sprintf(key, "quest%03d", i);
1387 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1389 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1391 for (j = 0; j < num; j++)
1393 /* Access the sound */
1394 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1396 /* Save the sound filename, if it exists */
1397 if (check_file(wav_path))
1398 quest_music_file[i][j] = string_make(zz[j]);
1402 for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1404 sprintf(key, "town%03d", i);
1405 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1407 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1409 for (j = 0; j < num; j++)
1411 /* Access the sound */
1412 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1414 /* Save the sound filename, if it exists */
1415 if (check_file(wav_path))
1416 town_music_file[i][j] = string_make(zz[j]);
1425 * Create the new global palette based on the bitmap palette
1426 * (if any), and the standard 16 entry palette derived from
1427 * "win_clr[]" which is used for the basic 16 Angband colors.
1429 * This function is never called before all windows are ready.
1431 * This function returns FALSE if the new palette could not be
1432 * prepared, which should normally be a fatal error. XXX XXX
1434 * Note that only some machines actually use a "palette".
1436 static int new_palette(void)
1444 LPLOGPALETTE pLogPal;
1445 LPPALETTEENTRY lppe;
1450 /* This makes no sense */
1451 if (!paletted) return TRUE;
1459 /* Check the bitmap palette */
1460 hBmPal = infGraph.hPalette;
1462 /* Use the bitmap */
1465 lppeSize = 256 * sizeof(PALETTEENTRY);
1466 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1467 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1468 if ((nEntries == 0) || (nEntries > 220))
1471 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1474 rnfree(lppe, lppeSize);
1481 /* Size of palette */
1482 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1484 /* Allocate palette */
1485 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1488 pLogPal->palVersion = 0x300;
1490 /* Make room for bitmap and normal data */
1491 pLogPal->palNumEntries = nEntries + 16;
1493 /* Save the bitmap data */
1494 for (i = 0; i < nEntries; i++)
1496 pLogPal->palPalEntry[i] = lppe[i];
1499 /* Save the normal data */
1500 for (i = 0; i < 16; i++)
1504 /* Access the entry */
1505 p = &(pLogPal->palPalEntry[i + nEntries]);
1507 /* Save the colors */
1508 p->peRed = GetRValue(win_clr[i]);
1509 p->peGreen = GetGValue(win_clr[i]);
1510 p->peBlue = GetBValue(win_clr[i]);
1512 /* Save the flags */
1513 p->peFlags = PC_NOCOLLAPSE;
1516 /* Free something */
1517 if (lppe) rnfree(lppe, lppeSize);
1519 /* Create a new palette, or fail */
1520 hNewPal = CreatePalette(pLogPal);
1521 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1523 /* Free the palette */
1524 rnfree(pLogPal, pLogPalSize);
1529 /* Realize the palette */
1531 SelectPalette(hdc, hNewPal, 0);
1532 i = RealizePalette(hdc);
1533 ReleaseDC(td->w, hdc);
1534 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1538 for (i = 1; i < MAX_TERM_DATA; i++)
1543 SelectPalette(hdc, hNewPal, 0);
1544 ReleaseDC(td->w, hdc);
1547 /* Delete old palette */
1548 if (hPal) DeleteObject(hPal);
1550 /* Save new palette */
1559 * @brief グラフィクスを初期化する / Initialize graphics
1562 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1563 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1566 static bool init_graphics(void)
1568 /* Initialize once */
1570 BYTE wid, hgt, twid, thgt, ox, oy;
1573 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1583 ANGBAND_GRAF = "new";
1585 else if (arg_graphics == GRAPHICS_HENGBAND)
1605 ANGBAND_GRAF = "ne2";
1616 ANGBAND_GRAF = "old";
1619 /* Access the bitmap file */
1620 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1622 /* Load the bitmap or quit */
1623 if (!ReadDIB(data[0].w, buf, &infGraph))
1625 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1629 /* Save the new sizes */
1630 infGraph.CellWidth = wid;
1631 infGraph.CellHeight = hgt;
1632 infGraph.TileWidth = twid;
1633 infGraph.TileHeight = thgt;
1634 infGraph.OffsetX = ox;
1635 infGraph.OffsetY = oy;
1637 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1639 /* Access the mask file */
1640 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1642 /* Load the bitmap or quit */
1643 if (!ReadDIB(data[0].w, buf, &infMask))
1645 plog_fmt("Cannot read bitmap file '%s'", buf);
1649 if (arg_graphics == GRAPHICS_HENGBAND)
1651 /* Access the mask file */
1652 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1654 /* Load the bitmap or quit */
1655 if (!ReadDIB(data[0].w, buf, &infMask))
1657 plog_fmt("Cannot read bitmap file '%s'", buf);
1662 /* Activate a palette */
1667 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1671 /* Graphics available */
1672 current_graphics_mode = arg_graphics;
1673 return (current_graphics_mode);
1680 static bool init_music(void)
1682 /* Initialize once */
1685 /* Load the prefs */
1688 /* Sound available */
1689 can_use_music = TRUE;
1691 return (can_use_music);
1695 * Hack -- Stop a music
1697 static void stop_music(void)
1699 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1700 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1707 static bool init_sound(void)
1709 /* Initialize once */
1712 /* Load the prefs */
1715 /* Sound available */
1716 can_use_sound = TRUE;
1718 return (can_use_sound);
1725 static void term_window_resize(term_data *td)
1727 /* Require window */
1730 /* Resize the window */
1731 SetWindowPos(td->w, 0, 0, 0,
1732 td->size_wid, td->size_hgt,
1733 SWP_NOMOVE | SWP_NOZORDER);
1736 InvalidateRect(td->w, NULL, TRUE);
1741 * Force the use of a new "font file" for a term_data
1743 * This function may be called before the "window" is ready
1745 * This function returns zero only if everything succeeds.
1747 * Note that the "font name" must be capitalized!!!
1749 static errr term_force_font(term_data *td, concptr path)
1753 /* Forget the old font (if needed) */
1754 if (td->font_id) DeleteObject(td->font_id);
1759 /* Create the font (using the 'base' of the font file name!) */
1760 td->font_id = CreateFontIndirect(&(td->lf));
1761 wid = td->lf.lfWidth;
1762 hgt = td->lf.lfHeight;
1763 if (!td->font_id) return 1;
1765 /* Hack -- Unknown size */
1772 /* all this trouble to get the cell size */
1773 hdcDesktop = GetDC(HWND_DESKTOP);
1774 hfOld = SelectObject(hdcDesktop, td->font_id);
1775 GetTextMetrics(hdcDesktop, &tm);
1776 SelectObject(hdcDesktop, hfOld);
1777 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1779 /* Font size info */
1780 wid = tm.tmAveCharWidth;
1784 /* Save the size info */
1795 * Allow the user to change the font for this window.
1797 static void term_change_font(term_data *td)
1801 memset(&cf, 0, sizeof(cf));
1802 cf.lStructSize = sizeof(cf);
1803 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1804 cf.lpLogFont = &(td->lf);
1806 if (ChooseFont(&cf))
1808 /* Force the font */
1809 term_force_font(td, NULL);
1811 /* Assume not bizarre */
1814 /* Reset the tile info */
1815 td->tile_wid = td->font_wid;
1816 td->tile_hgt = td->font_hgt;
1818 /* Analyze the font */
1821 /* Resize the window */
1822 term_window_resize(td);
1828 * Allow the user to lock this window.
1830 static void term_window_pos(term_data *td, HWND hWnd)
1832 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1833 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1836 static void windows_map(player_type *player_ptr);
1839 * Hack -- redraw a term_data
1841 static void term_data_redraw(player_type *player_ptr, term_data *td)
1845 /* Redraw the map */
1846 windows_map(player_ptr);
1850 /* Activate the term */
1851 Term_activate(&td->t);
1853 /* Redraw the contents */
1856 /* Restore the term */
1857 Term_activate(term_screen);
1862 void term_inversed_area(HWND hWnd, int x, int y, int w, int h)
1866 HBRUSH myBrush, oldBrush;
1868 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
1869 int tx = td->size_ow1 + x * td->tile_wid;
1870 int ty = td->size_oh1 + y * td->tile_hgt;
1871 int tw = w * td->tile_wid - 1;
1872 int th = h * td->tile_hgt - 1;
1875 myBrush = CreateSolidBrush(RGB(255, 255, 255));
1876 oldBrush = SelectObject(hdc, myBrush);
1877 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1879 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
1881 SelectObject(hdc, oldBrush);
1882 SelectObject(hdc, oldPen);
1887 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
1889 static errr term_user_win(int n)
1900 * React to global changes
1902 static errr term_xtra_win_react(player_type *player_ptr)
1909 /* Save the default colors */
1910 for (i = 0; i < 256; i++)
1912 /* Simply accept the desired colors */
1913 win_pal[i] = angband_color_table[i][0];
1924 bool change = FALSE;
1926 /* Save the default colors */
1927 for (i = 0; i < 256; i++)
1929 /* Extract desired values */
1930 rv = angband_color_table[i][1];
1931 gv = angband_color_table[i][2];
1932 bv = angband_color_table[i][3];
1934 /* Extract a full color code */
1935 code = PALETTERGB(rv, gv, bv);
1937 /* Activate changes */
1938 if (win_clr[i] != code)
1940 /* Note the change */
1943 /* Apply the desired color */
1948 /* Activate the palette if needed */
1949 if (change) (void)new_palette();
1952 /* Handle "arg_sound" */
1953 if (use_sound != arg_sound)
1955 /* Initialize (if needed) */
1956 if (arg_sound && !init_sound())
1959 plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
1965 /* Change setting */
1966 use_sound = arg_sound;
1969 /* Handle "arg_sound" */
1970 if (use_music != arg_music)
1972 /* Initialize (if needed) */
1973 if (arg_music && !init_music())
1976 plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
1981 /* Change setting */
1982 use_music = arg_music;
1984 if (!arg_music) stop_music();
1985 else select_floor_music(player_ptr);
1989 /* Handle "arg_graphics" */
1990 if (use_graphics != arg_graphics)
1992 /* Initialize (if needed) */
1993 if (arg_graphics && !init_graphics())
1996 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
1999 arg_graphics = GRAPHICS_NONE;
2002 /* Change setting */
2003 use_graphics = arg_graphics;
2006 reset_visuals(player_ptr);
2009 /* Clean up windows */
2010 for (i = 0; i < MAX_TERM_DATA; i++)
2014 term_data *td = &data[i];
2016 /* Update resized windows */
2017 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
2020 Term_activate(&td->t);
2022 /* Hack -- Resize the term */
2023 Term_resize(td->cols, td->rows);
2025 /* Redraw the contents */
2038 * Process at least one event
2040 static errr term_xtra_win_event(int v)
2044 /* Wait for an event */
2048 if (GetMessage(&msg, NULL, 0, 0))
2050 TranslateMessage(&msg);
2051 DispatchMessage(&msg);
2055 /* Check for an event */
2059 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2061 TranslateMessage(&msg);
2062 DispatchMessage(&msg);
2072 * Process all pending events
2074 static errr term_xtra_win_flush(void)
2078 /* Process all pending events */
2079 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2081 TranslateMessage(&msg);
2082 DispatchMessage(&msg);
2091 * Hack -- clear the screen
2093 * Make this more efficient
2095 static errr term_xtra_win_clear(void)
2097 term_data *td = (term_data*)(Term->data);
2102 /* Rectangle to erase */
2103 rc.left = td->size_ow1;
2104 rc.right = rc.left + td->cols * td->tile_wid;
2105 rc.top = td->size_oh1;
2106 rc.bottom = rc.top + td->rows * td->tile_hgt;
2110 SetBkColor(hdc, RGB(0, 0, 0));
2111 SelectObject(hdc, td->font_id);
2112 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2117 rc.left = 0; rc.top = 0;
2120 ReleaseDC(td->w, hdc);
2128 * Hack -- make a noise
2130 static errr term_xtra_win_noise(void)
2132 MessageBeep(MB_ICONASTERISK);
2138 * Hack -- make a sound
2140 static errr term_xtra_win_sound(int v)
2145 /* Sound disabled */
2146 if (!use_sound) return 1;
2149 if ((v < 0) || (v >= SOUND_MAX)) return 1;
2151 /* Count the samples */
2152 for (i = 0; i < SAMPLE_SOUND_MAX; i++)
2154 if (!sound_file[v][i])
2159 if (i == 0) return 1;
2161 /* Build the path */
2162 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2166 /* Play the sound, catch errors */
2167 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2171 /* Play the sound, catch errors */
2172 return (sndPlaySound(buf, SND_ASYNC));
2178 * Hack -- play a music
2180 static errr term_xtra_win_music(int n, int v)
2184 /* Sound disabled */
2185 if (n == TERM_XTRA_MUSIC_MUTE)
2187 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2188 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2191 if (!use_music) return 1;
2194 if (n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return 1;
2195 else if (v < 0 || v >= 1000) return(1); /*!< TODO */
2199 case TERM_XTRA_MUSIC_BASIC:
2200 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!music_file[v][i]) break;
2202 case TERM_XTRA_MUSIC_DUNGEON:
2203 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!dungeon_music_file[v][i]) break;
2205 case TERM_XTRA_MUSIC_QUEST:
2206 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!quest_music_file[v][i]) break;
2208 case TERM_XTRA_MUSIC_TOWN:
2209 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!town_music_file[v][i]) break;
2221 case TERM_XTRA_MUSIC_BASIC:
2222 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2224 case TERM_XTRA_MUSIC_DUNGEON:
2225 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2227 case TERM_XTRA_MUSIC_QUEST:
2228 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2230 case TERM_XTRA_MUSIC_TOWN:
2231 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2235 if (current_music_type == n && current_music_id == v)
2239 current_music_type = n;
2240 current_music_id = v;
2244 mop.lpstrDeviceType = mci_device_type;
2245 mop.lpstrElementName = buf;
2246 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2247 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2248 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2249 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2250 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2258 * Delay for "x" milliseconds
2260 static int term_xtra_win_delay(int v)
2274 t = GetTickCount() + v;
2277 while (GetTickCount() < t)
2279 /* Handle messages */
2280 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2282 TranslateMessage(&msg);
2283 DispatchMessage(&msg);
2295 * todo z-termに影響があるのでplayer_typeの追加は保留
2296 * Do a "special thing"
2298 static errr term_xtra_win(int n, int v)
2300 /* Handle a subset of the legal requests */
2303 /* Make a bell sound */
2304 case TERM_XTRA_NOISE:
2306 return (term_xtra_win_noise());
2310 case TERM_XTRA_MUSIC_BASIC:
2311 case TERM_XTRA_MUSIC_DUNGEON:
2312 case TERM_XTRA_MUSIC_QUEST:
2313 case TERM_XTRA_MUSIC_TOWN:
2315 return (term_xtra_win_music(n, v));
2318 /* Make a special sound */
2319 case TERM_XTRA_SOUND:
2321 return (term_xtra_win_sound(v));
2324 /* Process random events */
2325 case TERM_XTRA_BORED:
2327 return (term_xtra_win_event(0));
2330 /* Process an event */
2331 case TERM_XTRA_EVENT:
2333 return (term_xtra_win_event(v));
2336 /* Flush all events */
2337 case TERM_XTRA_FLUSH:
2339 return (term_xtra_win_flush());
2342 /* Clear the screen */
2343 case TERM_XTRA_CLEAR:
2345 return (term_xtra_win_clear());
2348 /* React to global changes */
2349 case TERM_XTRA_REACT:
2351 return (term_xtra_win_react(p_ptr));
2354 /* Delay for some milliseconds */
2355 case TERM_XTRA_DELAY:
2357 return (term_xtra_win_delay(v));
2367 * Low level graphics (Assumes valid input).
2369 * Draw a "cursor" at (x,y), using a "yellow box".
2371 static errr term_curs_win(int x, int y)
2373 term_data *td = (term_data*)(Term->data);
2378 int tile_wid, tile_hgt;
2382 tile_wid = td->map_tile_wid;
2383 tile_hgt = td->map_tile_hgt;
2387 tile_wid = td->tile_wid;
2388 tile_hgt = td->tile_hgt;
2391 /* Frame the grid */
2392 rc.left = x * tile_wid + td->size_ow1;
2393 rc.right = rc.left + tile_wid;
2394 rc.top = y * tile_hgt + td->size_oh1;
2395 rc.bottom = rc.top + tile_hgt;
2397 /* Cursor is done as a yellow "box" */
2399 FrameRect(hdc, &rc, hbrYellow);
2400 ReleaseDC(td->w, hdc);
2408 * Low level graphics (Assumes valid input).
2410 * Draw a "big cursor" at (x,y), using a "yellow box".
2412 static errr term_bigcurs_win(int x, int y)
2414 term_data *td = (term_data*)(Term->data);
2419 int tile_wid, tile_hgt;
2423 /* Normal cursor in map window */
2424 term_curs_win(x, y);
2429 tile_wid = td->tile_wid;
2430 tile_hgt = td->tile_hgt;
2433 /* Frame the grid */
2434 rc.left = x * tile_wid + td->size_ow1;
2435 rc.right = rc.left + 2 * tile_wid;
2436 rc.top = y * tile_hgt + td->size_oh1;
2437 rc.bottom = rc.top + tile_hgt;
2439 /* Cursor is done as a yellow "box" */
2441 FrameRect(hdc, &rc, hbrYellow);
2442 ReleaseDC(td->w, hdc);
2450 * Low level graphics (Assumes valid input).
2452 * Erase a "block" of "n" characters starting at (x,y).
2454 static errr term_wipe_win(int x, int y, int n)
2456 term_data *td = (term_data*)(Term->data);
2461 /* Rectangle to erase in client coords */
2462 rc.left = x * td->tile_wid + td->size_ow1;
2463 rc.right = rc.left + n * td->tile_wid;
2464 rc.top = y * td->tile_hgt + td->size_oh1;
2465 rc.bottom = rc.top + td->tile_hgt;
2468 SetBkColor(hdc, RGB(0, 0, 0));
2469 SelectObject(hdc, td->font_id);
2474 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2475 ReleaseDC(td->w, hdc);
2483 * Low level graphics. Assumes valid input.
2485 * Draw several ("n") chars, with an attr, at a given location.
2487 * All "graphic" data is handled by "term_pict_win()", below.
2489 * One would think there is a more efficient method for telling a window
2490 * what color it should be using to draw with, but perhaps simply changing
2491 * it every time is not too inefficient.
2493 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
2495 term_data *td = (term_data*)(Term->data);
2499 static HBITMAP WALL;
2500 static HBRUSH myBrush, oldBrush;
2502 static bool init_done = FALSE;
2505 WALL = LoadBitmap(hInstance, AppName);
2506 myBrush = CreatePatternBrush(WALL);
2510 /* Total rectangle */
2511 rc.left = x * td->tile_wid + td->size_ow1;
2512 rc.right = rc.left + n * td->tile_wid;
2513 rc.top = y * td->tile_hgt + td->size_oh1;
2514 rc.bottom = rc.top + td->tile_hgt;
2519 /* Background color */
2520 SetBkColor(hdc, RGB(0, 0, 0));
2522 /* Foreground color */
2525 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2529 SetTextColor(hdc, win_clr[a & 0x0F]);
2533 SetTextColor(hdc, win_clr[a]);
2537 SelectObject(hdc, td->font_id);
2540 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2544 (td->tile_hgt != td->font_hgt) ||
2545 (td->tile_wid != td->font_wid))
2549 /* Erase complete rectangle */
2550 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2553 if (use_bg) DrawBG(hdc, &rc);
2556 rc.left += ((td->tile_wid - td->font_wid) / 2);
2557 rc.right = rc.left + td->font_wid;
2558 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2559 rc.bottom = rc.top + td->font_hgt;
2561 /* Dump each character */
2562 for (i = 0; i < n; i++)
2565 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1])
2567 rc.right += td->font_wid;
2569 oldBrush = SelectObject(hdc, myBrush);
2570 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
2573 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2575 SelectObject(hdc, oldBrush);
2576 SelectObject(hdc, oldPen);
2577 rc.right -= td->font_wid;
2581 rc.left += 2 * td->tile_wid;
2582 rc.right += 2 * td->tile_wid;
2584 else if (iskanji(*(s + i))) /* 2バイト文字 */
2586 rc.right += td->font_wid;
2588 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2590 rc.right -= td->font_wid;
2594 rc.left += 2 * td->tile_wid;
2595 rc.right += 2 * td->tile_wid;
2597 else if (*(s + i) == 127) {
2598 oldBrush = SelectObject(hdc, myBrush);
2599 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
2602 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2604 SelectObject(hdc, oldBrush);
2605 SelectObject(hdc, oldPen);
2608 rc.left += td->tile_wid;
2609 rc.right += td->tile_wid;
2613 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
2616 rc.left += td->tile_wid;
2617 rc.right += td->tile_wid;
2620 if (*(s + i) == 127) {
2621 oldBrush = SelectObject(hdc, myBrush);
2622 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
2625 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2627 SelectObject(hdc, oldBrush);
2628 SelectObject(hdc, oldPen);
2631 rc.left += td->tile_wid;
2632 rc.right += td->tile_wid;
2636 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2640 rc.left += td->tile_wid;
2641 rc.right += td->tile_wid;
2652 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2657 ReleaseDC(td->w, hdc);
2665 * Low level graphics. Assumes valid input.
2667 * Draw an array of "special" attr/char pairs at the given location.
2669 * We use the "term_pict_win()" function for "graphic" data, which are
2670 * encoded by setting the "high-bits" of both the "attr" and the "char"
2671 * data. We use the "attr" to represent the "row" of the main bitmap,
2672 * and the "char" to represent the "col" of the main bitmap. The use
2673 * of this function is induced by the "higher_pict" flag.
2675 * If "graphics" is not available, we simply "wipe" the given grids.
2677 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)
2679 term_data *td = (term_data*)(Term->data);
2681 TERM_LEN x1, y1, w1, h1, tw1, th1;
2682 TERM_LEN x2, y2, w2, h2, tw2 = 0;
2692 /* Erase the grids */
2693 return (term_wipe_win(x, y, n));
2696 /* Size of bitmap cell */
2697 w1 = infGraph.CellWidth;
2698 h1 = infGraph.CellHeight;
2699 tw1 = infGraph.TileWidth;
2700 th1 = infGraph.TileHeight;
2702 /* Size of window cell */
2705 w2 = td->map_tile_wid;
2706 h2 = td->map_tile_hgt;
2715 if (use_bigtile) tw2 *= 2;
2718 /* Location of window cell */
2719 x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
2720 y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
2726 hdcSrc = CreateCompatibleDC(hdc);
2727 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2729 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2731 hdcMask = CreateCompatibleDC(hdc);
2732 SelectObject(hdcMask, infMask.hBitmap);
2735 /* Draw attr/char pairs */
2736 for (i = 0; i < n; i++, x2 += w2)
2738 TERM_COLOR a = ap[i];
2742 /* Extract picture */
2743 int row = (a & 0x7F);
2744 int col = (c & 0x7F);
2746 /* Location of bitmap cell */
2750 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2752 x3 = (tcp[i] & 0x7F) * w1;
2753 y3 = (tap[i] & 0x7F) * h1;
2754 tw2 = tw2 * w1 / tw1;
2758 if ((tw1 == tw2) && (th1 == h2))
2760 /* Copy the terrain picture from the bitmap to the window */
2761 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2763 /* Mask out the tile */
2764 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2767 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2770 /* Need to stretch */
2773 /* Set the correct mode for stretching the tiles */
2774 SetStretchBltMode(hdc, COLORONCOLOR);
2776 /* Copy the terrain picture from the bitmap to the window */
2777 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
2779 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
2781 /* Only draw if terrain and overlay are different */
2782 if ((x1 != x3) || (y1 != y3))
2784 /* Mask out the tile */
2785 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2788 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2795 if ((w1 == tw2) && (h1 == h2))
2797 /* Copy the picture from the bitmap to the window */
2798 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2801 /* Need to stretch */
2804 /* Set the correct mode for stretching the tiles */
2805 SetStretchBltMode(hdc, COLORONCOLOR);
2807 /* Copy the picture from the bitmap to the window */
2808 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2814 SelectObject(hdcSrc, hbmSrcOld);
2817 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2820 SelectObject(hdcMask, hbmSrcOld);
2825 ReleaseDC(td->w, hdc);
2832 static void windows_map(player_type *player_ptr)
2834 term_data *td = &data[0];
2837 TERM_LEN x, min_x, max_x;
2838 TERM_LEN y, min_y, max_y;
2843 /* Only in graphics mode */
2844 if (!use_graphics) return;
2845 term_xtra_win_clear();
2847 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2848 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2849 td->map_active = TRUE;
2854 max_x = player_ptr->current_floor_ptr->width;
2855 max_y = player_ptr->current_floor_ptr->height;
2859 for (x = min_x; x < max_x; x++)
2861 for (y = min_y; y < max_y; y++)
2863 map_info(player_ptr, y, x, &a, (char*)&c, &ta, (char*)&tc);
2865 /* Ignore non-graphics */
2866 if ((a & 0x80) && (c & 0x80))
2868 term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2873 /* Hilite the player */
2874 term_curs_win(player_ptr->x - min_x, player_ptr->y - min_y);
2876 /* Wait for a keypress, flush key buffer */
2877 Term_inkey(&c, TRUE, TRUE);
2880 /* Switch off the map display */
2881 td->map_active = FALSE;
2883 /* Restore screen */
2884 term_xtra_win_clear();
2889 /*** Other routines ***/
2893 * Create and initialize a "term_data" given a title
2895 static void term_data_link(term_data *td)
2899 /* Initialize the term */
2900 term_init(t, td->cols, td->rows, td->keys);
2902 /* Use a "software" cursor */
2903 t->soft_cursor = TRUE;
2905 /* Use "term_pict" for "graphic" data */
2906 t->higher_pict = TRUE;
2908 /* Erase with "white space" */
2909 t->attr_blank = TERM_WHITE;
2910 t->char_blank = ' ';
2912 /* Prepare the template hooks */
2913 t->user_hook = term_user_win;
2914 t->xtra_hook = term_xtra_win;
2915 t->curs_hook = term_curs_win;
2916 t->bigcurs_hook = term_bigcurs_win;
2917 t->wipe_hook = term_wipe_win;
2918 t->text_hook = term_text_win;
2919 t->pict_hook = term_pict_win;
2921 /* Remember where we came from */
2922 t->data = (vptr)(td);
2927 * Create the windows
2929 * First, instantiate the "default" values, then read the "ini_file"
2930 * to over-ride selected values, then create the windows, and fonts.
2932 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2933 * must make active to realize the palette.
2935 static void init_windows(void)
2943 WIPE(td, term_data);
2947 td->s = angband_term_name[0];
2963 for (i = 1; i < MAX_TERM_DATA; i++)
2966 WIPE(td, term_data);
2967 td->s = angband_term_name[i];
2971 td->visible = FALSE;
2976 td->pos_x = (7 - i) * 30;
2977 td->pos_y = (7 - i) * 20;
2985 /* Main window (need these before term_getsize gets called) */
2987 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2988 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2993 /* Sub windows (need these before term_getsize gets called) */
2994 for (i = 1; i < MAX_TERM_DATA; i++)
2997 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2998 td->dwExStyle = (WS_EX_TOOLWINDOW);
3003 for (i = 0; i < MAX_TERM_DATA; i++)
3007 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3008 td->lf.lfCharSet = DEFAULT_CHARSET;
3009 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3010 /* Activate the chosen font */
3011 term_force_font(td, NULL);
3012 if (!td->tile_wid) td->tile_wid = td->font_wid;
3013 if (!td->tile_hgt) td->tile_hgt = td->font_hgt;
3015 /* Analyze the font */
3018 /* Resize the window */
3019 term_window_resize(td);
3023 /* Sub windows (reverse order) */
3024 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3029 td->w = CreateWindowEx(td->dwExStyle, AngList,
3031 td->pos_x, td->pos_y,
3032 td->size_wid, td->size_hgt,
3033 HWND_DESKTOP, NULL, hInstance, NULL);
3035 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3039 td->size_hack = TRUE;
3040 ShowWindow(td->w, SW_SHOW);
3041 td->size_hack = FALSE;
3045 angband_term[i] = &td->t;
3049 /* Activate the window */
3050 SetActiveWindow(td->w);
3055 term_window_pos(&data[i], HWND_TOPMOST);
3059 term_window_pos(&data[i], td->w);
3069 td->w = CreateWindowEx(td->dwExStyle, AppName,
3071 td->pos_x, td->pos_y,
3072 td->size_wid, td->size_hgt,
3073 HWND_DESKTOP, NULL, hInstance, NULL);
3075 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3078 angband_term[0] = &td->t;
3079 normsize.x = td->cols;
3080 normsize.y = td->rows;
3082 /* Activate the main window */
3083 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3084 else ShowWindow(td->w, SW_SHOW);
3086 /* Bring main window back to top */
3087 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3091 (void)new_palette();
3094 /* Create a "brush" for drawing the "cursor" */
3095 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3098 /* Process pending messages */
3099 (void)term_xtra_win_flush();
3107 static void setup_menus(void)
3111 HMENU hm = GetMenu(data[0].w);
3114 /* Menu "File", Disable all */
3115 EnableMenuItem(hm, IDM_FILE_NEW,
3116 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3117 EnableMenuItem(hm, IDM_FILE_OPEN,
3118 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3119 EnableMenuItem(hm, IDM_FILE_SAVE,
3120 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3121 EnableMenuItem(hm, IDM_FILE_EXIT,
3122 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3123 EnableMenuItem(hm, IDM_FILE_SCORE,
3124 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3127 /* No character available */
3128 if (!current_world_ptr->character_generated)
3130 /* Menu "File", Item "New" */
3131 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3133 /* Menu "File", Item "Open" */
3134 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3137 /* A character available */
3138 if (current_world_ptr->character_generated)
3140 /* Menu "File", Item "Save" */
3141 EnableMenuItem(hm, IDM_FILE_SAVE,
3142 MF_BYCOMMAND | MF_ENABLED);
3145 /* Menu "File", Item "Exit" */
3146 EnableMenuItem(hm, IDM_FILE_EXIT,
3147 MF_BYCOMMAND | MF_ENABLED);
3149 EnableMenuItem(hm, IDM_FILE_SCORE,
3150 MF_BYCOMMAND | MF_ENABLED);
3153 /* Menu "Window::Visibility" */
3154 for (i = 0; i < MAX_TERM_DATA; i++)
3156 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3157 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3159 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3160 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3162 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3163 MF_BYCOMMAND | MF_ENABLED);
3166 /* Menu "Window::Font" */
3167 for (i = 0; i < MAX_TERM_DATA; i++)
3169 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3170 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3172 if (data[i].visible)
3174 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3175 MF_BYCOMMAND | MF_ENABLED);
3179 /* Menu "Window::Window Position Fix" */
3180 for (i = 0; i < MAX_TERM_DATA; i++)
3182 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3183 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3185 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3186 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3188 if (data[i].visible)
3190 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3191 MF_BYCOMMAND | MF_ENABLED);
3195 /* Menu "Window::Bizarre Display" */
3196 for (i = 0; i < MAX_TERM_DATA; i++)
3198 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3199 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3201 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3202 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3204 if (data[i].visible)
3206 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3207 MF_BYCOMMAND | MF_ENABLED);
3212 /* Menu "Window::Increase Tile Width" */
3213 for (i = 0; i < MAX_TERM_DATA; i++)
3215 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3216 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3218 if (data[i].visible)
3220 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3221 MF_BYCOMMAND | MF_ENABLED);
3226 /* Menu "Window::Decrease Tile Width" */
3227 for (i = 0; i < MAX_TERM_DATA; i++)
3229 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3230 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3232 if (data[i].visible)
3234 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3235 MF_BYCOMMAND | MF_ENABLED);
3240 /* Menu "Window::Increase Tile Height" */
3241 for (i = 0; i < MAX_TERM_DATA; i++)
3243 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3244 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3246 if (data[i].visible)
3248 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3249 MF_BYCOMMAND | MF_ENABLED);
3254 /* Menu "Window::Decrease Tile Height" */
3255 for (i = 0; i < MAX_TERM_DATA; i++)
3257 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3258 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3260 if (data[i].visible)
3262 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3263 MF_BYCOMMAND | MF_ENABLED);
3268 /* Menu "Options", disable all */
3269 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3270 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3271 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3272 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3273 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3274 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3275 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3276 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3277 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3278 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3282 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3283 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3286 /* Menu "Options", Item "Map" */
3287 if (use_graphics != GRAPHICS_NONE)
3288 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3290 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3291 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3293 /* Menu "Options", update all */
3294 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3295 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3296 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3297 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3298 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3299 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3300 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3301 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3302 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3303 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3304 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3305 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3306 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3307 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3308 CheckMenuItem(hm, IDM_OPTIONS_BG,
3309 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3313 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3314 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3317 /* Menu "Options", Item "Graphics" */
3318 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3319 /* Menu "Options", Item "Graphics" */
3320 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3321 /* Menu "Options", Item "Graphics" */
3322 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3323 /* Menu "Options", Item "Graphics" */
3324 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3326 /* Menu "Options", Item "Sound" */
3327 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3330 /* Menu "Options", Item "ScreenSaver" */
3331 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3332 MF_BYCOMMAND | MF_ENABLED);
3333 #endif /* USE_SAVER */
3338 * Check for double clicked (or dragged) savefile
3340 * Apparently, Windows copies the entire filename into the first
3341 * piece of the "command line string". Perhaps we should extract
3342 * the "basename" of that filename and append it to the "save" dir.
3344 static void check_for_save_file(player_type *player_ptr, LPSTR cmd_line)
3354 /* Extract filename */
3355 strcat(savefile, s);
3357 /* Validate the file */
3358 validate_file(savefile);
3360 /* Game in progress */
3361 game_in_progress = TRUE;
3364 play_game(player_ptr, FALSE);
3369 * Process a menu command
3371 static void process_menus(player_type *player_ptr, WORD wCmd)
3387 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3389 else if (game_in_progress)
3391 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3395 game_in_progress = TRUE;
3397 play_game(player_ptr, TRUE);
3408 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3410 else if (game_in_progress)
3412 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3416 memset(&ofn, 0, sizeof(ofn));
3417 ofn.lStructSize = sizeof(ofn);
3418 ofn.hwndOwner = data[0].w;
3419 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3420 ofn.nFilterIndex = 1;
3421 ofn.lpstrFile = savefile;
3422 ofn.nMaxFile = 1024;
3423 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3424 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3426 if (GetOpenFileName(&ofn))
3428 /* Load 'savefile' */
3429 validate_file(savefile);
3430 game_in_progress = TRUE;
3432 play_game(player_ptr, FALSE);
3442 if (game_in_progress && current_world_ptr->character_generated)
3446 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3450 /* Hack -- Forget messages */
3454 do_cmd_save_game(player_ptr, FALSE);
3458 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3465 if (game_in_progress && current_world_ptr->character_generated)
3469 plog(_("今は終了できません。", "You may not do that right now."));
3473 /* Hack -- Forget messages */
3476 forget_lite(player_ptr->current_floor_ptr);
3477 forget_view(player_ptr->current_floor_ptr);
3478 clear_mon_lite(player_ptr->current_floor_ptr);
3480 Term_key_push(SPECIAL_KEY_QUIT);
3488 case IDM_FILE_SCORE:
3491 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3493 /* Open the binary high score file, for reading */
3494 highscore_fd = fd_open(buf, O_RDONLY);
3496 /* Paranoia -- No score file */
3497 if (highscore_fd < 0)
3499 msg_print("Score file unavailable.");
3506 /* Display the scores */
3507 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3509 /* Shut the high score file */
3510 (void)fd_close(highscore_fd);
3512 /* Forget the high score fd */
3516 /* Hack - Flush it */
3524 case IDM_FILE_MOVIE:
3528 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3530 else if (game_in_progress)
3532 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
3536 memset(&ofn, 0, sizeof(ofn));
3537 ofn.lStructSize = sizeof(ofn);
3538 ofn.hwndOwner = data[0].w;
3539 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3540 ofn.nFilterIndex = 1;
3541 ofn.lpstrFile = savefile;
3542 ofn.nMaxFile = 1024;
3543 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3544 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3546 if (GetOpenFileName(&ofn))
3548 /* Load 'savefile' */
3549 prepare_browse_movie_aux(savefile);
3550 play_game(player_ptr, FALSE);
3559 case IDM_WINDOW_VIS_0:
3561 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
3565 /* Window visibility */
3566 case IDM_WINDOW_VIS_1:
3567 case IDM_WINDOW_VIS_2:
3568 case IDM_WINDOW_VIS_3:
3569 case IDM_WINDOW_VIS_4:
3570 case IDM_WINDOW_VIS_5:
3571 case IDM_WINDOW_VIS_6:
3572 case IDM_WINDOW_VIS_7:
3574 i = wCmd - IDM_WINDOW_VIS_0;
3576 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3583 ShowWindow(td->w, SW_SHOW);
3584 term_data_redraw(player_ptr, td);
3588 td->visible = FALSE;
3590 ShowWindow(td->w, SW_HIDE);
3597 case IDM_WINDOW_FONT_0:
3598 case IDM_WINDOW_FONT_1:
3599 case IDM_WINDOW_FONT_2:
3600 case IDM_WINDOW_FONT_3:
3601 case IDM_WINDOW_FONT_4:
3602 case IDM_WINDOW_FONT_5:
3603 case IDM_WINDOW_FONT_6:
3604 case IDM_WINDOW_FONT_7:
3606 i = wCmd - IDM_WINDOW_FONT_0;
3608 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3612 term_change_font(td);
3617 /* Window Z Position */
3618 case IDM_WINDOW_POS_1:
3619 case IDM_WINDOW_POS_2:
3620 case IDM_WINDOW_POS_3:
3621 case IDM_WINDOW_POS_4:
3622 case IDM_WINDOW_POS_5:
3623 case IDM_WINDOW_POS_6:
3624 case IDM_WINDOW_POS_7:
3626 i = wCmd - IDM_WINDOW_POS_0;
3628 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3632 if (!td->posfix && td->visible)
3635 term_window_pos(td, HWND_TOPMOST);
3640 term_window_pos(td, data[0].w);
3646 /* Bizarre Display */
3647 case IDM_WINDOW_BIZ_0:
3648 case IDM_WINDOW_BIZ_1:
3649 case IDM_WINDOW_BIZ_2:
3650 case IDM_WINDOW_BIZ_3:
3651 case IDM_WINDOW_BIZ_4:
3652 case IDM_WINDOW_BIZ_5:
3653 case IDM_WINDOW_BIZ_6:
3654 case IDM_WINDOW_BIZ_7:
3656 i = wCmd - IDM_WINDOW_BIZ_0;
3658 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3662 td->bizarre = !td->bizarre;
3666 term_window_resize(td);
3671 /* Increase Tile Width */
3672 case IDM_WINDOW_I_WID_0:
3673 case IDM_WINDOW_I_WID_1:
3674 case IDM_WINDOW_I_WID_2:
3675 case IDM_WINDOW_I_WID_3:
3676 case IDM_WINDOW_I_WID_4:
3677 case IDM_WINDOW_I_WID_5:
3678 case IDM_WINDOW_I_WID_6:
3679 case IDM_WINDOW_I_WID_7:
3681 i = wCmd - IDM_WINDOW_I_WID_0;
3683 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3691 term_window_resize(td);
3696 /* Decrease Tile Height */
3697 case IDM_WINDOW_D_WID_0:
3698 case IDM_WINDOW_D_WID_1:
3699 case IDM_WINDOW_D_WID_2:
3700 case IDM_WINDOW_D_WID_3:
3701 case IDM_WINDOW_D_WID_4:
3702 case IDM_WINDOW_D_WID_5:
3703 case IDM_WINDOW_D_WID_6:
3704 case IDM_WINDOW_D_WID_7:
3706 i = wCmd - IDM_WINDOW_D_WID_0;
3708 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3716 term_window_resize(td);
3721 /* Increase Tile Height */
3722 case IDM_WINDOW_I_HGT_0:
3723 case IDM_WINDOW_I_HGT_1:
3724 case IDM_WINDOW_I_HGT_2:
3725 case IDM_WINDOW_I_HGT_3:
3726 case IDM_WINDOW_I_HGT_4:
3727 case IDM_WINDOW_I_HGT_5:
3728 case IDM_WINDOW_I_HGT_6:
3729 case IDM_WINDOW_I_HGT_7:
3731 i = wCmd - IDM_WINDOW_I_HGT_0;
3733 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3741 term_window_resize(td);
3746 /* Decrease Tile Height */
3747 case IDM_WINDOW_D_HGT_0:
3748 case IDM_WINDOW_D_HGT_1:
3749 case IDM_WINDOW_D_HGT_2:
3750 case IDM_WINDOW_D_HGT_3:
3751 case IDM_WINDOW_D_HGT_4:
3752 case IDM_WINDOW_D_HGT_5:
3753 case IDM_WINDOW_D_HGT_6:
3754 case IDM_WINDOW_D_HGT_7:
3756 i = wCmd - IDM_WINDOW_D_HGT_0;
3758 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3766 term_window_resize(td);
3771 case IDM_OPTIONS_NO_GRAPHICS:
3775 plog("You may not do that right now.");
3779 if (arg_graphics != GRAPHICS_NONE)
3781 arg_graphics = GRAPHICS_NONE;
3782 term_xtra_win_react(player_ptr);
3783 Term_key_push(KTRL('R'));
3789 case IDM_OPTIONS_OLD_GRAPHICS:
3793 plog("You may not do that right now.");
3797 if (arg_graphics != GRAPHICS_ORIGINAL)
3799 arg_graphics = GRAPHICS_ORIGINAL;
3800 term_xtra_win_react(player_ptr);
3801 Term_key_push(KTRL('R'));
3807 case IDM_OPTIONS_NEW_GRAPHICS:
3811 plog("You may not do that right now.");
3815 if (arg_graphics != GRAPHICS_ADAM_BOLT)
3817 arg_graphics = GRAPHICS_ADAM_BOLT;
3818 term_xtra_win_react(player_ptr);
3819 Term_key_push(KTRL('R'));
3825 case IDM_OPTIONS_NEW2_GRAPHICS:
3829 plog("You may not do that right now.");
3833 if (arg_graphics != GRAPHICS_HENGBAND)
3835 arg_graphics = GRAPHICS_HENGBAND;
3836 term_xtra_win_react(player_ptr);
3837 Term_key_push(KTRL('R'));
3843 case IDM_OPTIONS_BIGTILE:
3848 plog("You may not do that right now.");
3852 arg_bigtile = !arg_bigtile;
3853 Term_activate(&td->t);
3854 Term_resize(td->cols, td->rows);
3855 InvalidateRect(td->w, NULL, TRUE);
3859 case IDM_OPTIONS_MUSIC:
3863 plog("You may not do that right now.");
3867 arg_music = !arg_music;
3868 term_xtra_win_react(player_ptr);
3869 Term_key_push(KTRL('R'));
3873 case IDM_OPTIONS_SOUND:
3877 plog("You may not do that right now.");
3881 arg_sound = !arg_sound;
3882 term_xtra_win_react(player_ptr);
3883 Term_key_push(KTRL('R'));
3888 case IDM_OPTIONS_BG:
3892 plog("You may not do that right now.");
3898 term_xtra_win_react(player_ptr);
3899 Term_key_push(KTRL('R'));
3904 case IDM_OPTIONS_OPEN_BG:
3908 plog("You may not do that right now.");
3913 memset(&ofn, 0, sizeof(ofn));
3914 ofn.lStructSize = sizeof(ofn);
3915 ofn.hwndOwner = data[0].w;
3916 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3917 ofn.nFilterIndex = 1;
3918 ofn.lpstrFile = bg_bitmap_file;
3919 ofn.nMaxFile = 1023;
3920 ofn.lpstrInitialDir = NULL;
3921 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
3922 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3924 if (GetOpenFileName(&ofn))
3926 /* Load 'savefile' */
3931 /* React to changes */
3932 term_xtra_win_react(player_ptr);
3934 /* Hack -- Force redraw */
3935 Term_key_push(KTRL('R'));
3940 case IDM_DUMP_SCREEN_HTML:
3942 static char buf[1024] = "";
3943 memset(&ofn, 0, sizeof(ofn));
3944 ofn.lStructSize = sizeof(ofn);
3945 ofn.hwndOwner = data[0].w;
3946 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
3947 ofn.nFilterIndex = 1;
3948 ofn.lpstrFile = buf;
3949 ofn.nMaxFile = 1023;
3950 ofn.lpstrDefExt = "html";
3951 ofn.lpstrInitialDir = NULL;
3952 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
3953 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
3955 if (GetSaveFileName(&ofn))
3957 do_cmd_save_screen_html_aux(buf, 0);
3964 case IDM_OPTIONS_SAVER:
3968 DestroyWindow(hwndSaver);
3973 /* Create a screen scaver window */
3974 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
3975 "Angband Screensaver",
3976 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
3977 0, 0, GetSystemMetrics(SM_CXSCREEN),
3978 GetSystemMetrics(SM_CYSCREEN),
3979 NULL, NULL, hInstance, NULL);
3983 /* Push the window to the bottom */
3984 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3988 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
3996 case IDM_OPTIONS_MAP:
3998 windows_map(player_ptr);
4002 case IDM_HELP_CONTENTS:
4006 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4007 if (check_file(tmp))
4009 sprintf(buf, "winhelp.exe %s", tmp);
4010 WinExec(buf, SW_NORMAL);
4014 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4015 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4024 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4030 /* Extract the modifiers */
4031 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4032 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4033 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4035 term_no_press = (ma) ? TRUE : FALSE;
4037 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]))
4039 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4040 bool numpad = FALSE;
4043 if (mc) Term_keypress('C');
4044 if (ms) Term_keypress('S');
4045 if (ma) Term_keypress('A');
4047 int i = LOBYTE(HIWORD(lParam));
4052 term_no_press = TRUE;
4071 term_no_press = TRUE;
4086 if (numpad) Term_keypress('K');
4088 Term_keypress(hexsym[i / 16]);
4089 Term_keypress(hexsym[i % 16]);
4100 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
4103 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4104 WPARAM wParam, LPARAM lParam);
4105 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4106 WPARAM wParam, LPARAM lParam)
4107 #else /* __MWERKS__ */
4108 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4109 #endif /* __MWERKS__ */
4114 td = (term_data *)GetWindowLong(hWnd, 0);
4120 SetWindowLong(hWnd, 0, (LONG)(my_td));
4125 mop.dwCallback = (DWORD)hWnd;
4128 case WM_GETMINMAXINFO:
4130 MINMAXINFO FAR *lpmmi;
4133 lpmmi = (MINMAXINFO FAR *)lParam;
4136 rc.left = rc.top = 0;
4137 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4138 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4140 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4142 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4143 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4149 BeginPaint(hWnd, &ps);
4150 if (td) term_data_redraw(p_ptr, td);
4151 EndPaint(hWnd, &ps);
4152 ValidateRect(hWnd, NULL);
4157 if (wParam == MCI_NOTIFY_SUCCESSFUL)
4159 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4160 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4168 if (process_keydown(wParam, lParam))
4174 if (term_no_press) term_no_press = FALSE;
4175 else Term_keypress(wParam);
4178 case WM_LBUTTONDOWN:
4180 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4181 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4191 TERM_LEN dx = abs(oldx - mousex) + 1;
4192 TERM_LEN dy = abs(oldy - mousey) + 1;
4193 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
4194 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
4200 int sz = (dx + 3) * dy;
4202 int sz = (dx + 2) * dy;
4204 hGlobal = GlobalAlloc(GHND, sz + 1);
4205 if (hGlobal == NULL) return 0;
4206 lpStr = (LPSTR)GlobalLock(hGlobal);
4208 for (int i = 0; i < dy; i++)
4212 char **scr = data[0].t.scr->c;
4214 C_MAKE(s, (dx + 1), char);
4215 strncpy(s, &scr[oy + i][ox], dx);
4219 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4222 if (ox + dx < data[0].cols)
4224 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4227 for (int j = 0; j < dx; j++)
4229 if (s[j] == 127) s[j] = '#';
4233 for (j = 0; j < dx; j++)
4235 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4245 GlobalUnlock(hGlobal);
4246 if (OpenClipboard(hWnd) == 0)
4248 GlobalFree(hGlobal);
4252 SetClipboardData(CF_TEXT, hGlobal);
4264 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4265 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4270 dx = abs(oldx - mousex) + 1;
4271 dy = abs(oldy - mousey) + 1;
4272 ox = (oldx > mousex) ? mousex : oldx;
4273 oy = (oldy > mousey) ? mousey : oldy;
4274 term_inversed_area(hWnd, ox, oy, dx, dy);
4281 dx = abs(cx - mousex) + 1;
4282 dy = abs(cy - mousey) + 1;
4283 ox = (cx > mousex) ? mousex : cx;
4284 oy = (cy > mousey) ? mousey : cy;
4285 term_inversed_area(hWnd, ox, oy, dx, dy);
4300 if (game_in_progress && current_world_ptr->character_generated)
4304 plog(_("今は終了できません。", "You may not do that right now."));
4309 forget_lite(p_ptr->current_floor_ptr);
4310 forget_view(p_ptr->current_floor_ptr);
4311 clear_mon_lite(p_ptr->current_floor_ptr);
4312 Term_key_push(SPECIAL_KEY_QUIT);
4319 case WM_QUERYENDSESSION:
4321 if (game_in_progress && current_world_ptr->character_generated)
4324 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4325 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4327 p_ptr->panic_save = 1;
4328 signals_ignore_tstp();
4329 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4330 (void)save_player(p_ptr);
4343 process_menus(p_ptr, LOWORD(wParam));
4349 if (!td->w) return 1;
4350 if (td->size_hack) return 1;
4354 case SIZE_MINIMIZED:
4356 /* Hide sub-windows */
4357 for (int i = 1; i < MAX_TERM_DATA; i++)
4359 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4364 case SIZE_MAXIMIZED:
4370 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4371 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4372 if ((td->cols != cols) || (td->rows != rows))
4376 if (!IsZoomed(td->w) && !IsIconic(td->w))
4378 normsize.x = td->cols;
4379 normsize.y = td->rows;
4382 Term_activate(&td->t);
4383 Term_resize(td->cols, td->rows);
4384 InvalidateRect(td->w, NULL, TRUE);
4387 td->size_hack = TRUE;
4388 for (int i = 1; i < MAX_TERM_DATA; i++)
4390 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4393 td->size_hack = FALSE;
4401 case WM_PALETTECHANGED:
4403 if ((HWND)wParam == hWnd) return 0;
4405 case WM_QUERYNEWPALETTE:
4407 if (!paletted) return 0;
4410 SelectPalette(hdc, hPal, FALSE);
4411 int i = RealizePalette(hdc);
4412 if (i) InvalidateRect(hWnd, NULL, TRUE);
4414 ReleaseDC(hWnd, hdc);
4419 if (wParam && !HIWORD(lParam))
4421 for (int i = 1; i < MAX_TERM_DATA; i++)
4423 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4432 case WM_ACTIVATEAPP:
4434 if (IsIconic(td->w)) break;
4436 for (int i = 1; i < MAX_TERM_DATA; i++)
4438 if (data[i].visible)
4442 ShowWindow(data[i].w, SW_SHOW);
4446 ShowWindow(data[i].w, SW_HIDE);
4453 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4458 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
4461 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4462 WPARAM wParam, LPARAM lParam);
4463 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4464 WPARAM wParam, LPARAM lParam)
4465 #else /* __MWERKS__ */
4466 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4467 WPARAM wParam, LPARAM lParam)
4468 #endif /* __MWERKS__ */
4473 td = (term_data *)GetWindowLong(hWnd, 0);
4479 SetWindowLong(hWnd, 0, (LONG)(my_td));
4486 case WM_GETMINMAXINFO:
4488 MINMAXINFO FAR *lpmmi;
4491 lpmmi = (MINMAXINFO FAR *)lParam;
4494 rc.left = rc.top = 0;
4495 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4496 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4498 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4499 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4500 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4507 if (!td->w) return 1;
4508 if (td->size_hack) return 1;
4510 td->size_hack = TRUE;
4512 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4513 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4514 if ((td->cols != cols) || (td->rows != rows))
4516 term *old_term = Term;
4519 Term_activate(&td->t);
4520 Term_resize(td->cols, td->rows);
4521 Term_activate(old_term);
4522 InvalidateRect(td->w, NULL, TRUE);
4523 p_ptr->window = 0xFFFFFFFF;
4524 handle_stuff(p_ptr);
4527 td->size_hack = FALSE;
4533 BeginPaint(hWnd, &ps);
4534 if (td) term_data_redraw(p_ptr, td);
4535 EndPaint(hWnd, &ps);
4541 if (process_keydown(wParam, lParam))
4547 if (term_no_press) term_no_press = FALSE;
4548 else Term_keypress(wParam);
4551 case WM_PALETTECHANGED:
4553 if ((HWND)wParam == hWnd) return FALSE;
4555 case WM_QUERYNEWPALETTE:
4557 if (!paletted) return 0;
4559 SelectPalette(hdc, hPal, FALSE);
4560 int i = RealizePalette(hdc);
4561 if (i) InvalidateRect(hWnd, NULL, TRUE);
4562 ReleaseDC(hWnd, hdc);
4565 case WM_NCLBUTTONDOWN:
4568 if (wParam == HTCLOSE) wParam = HTSYSMENU;
4569 #endif /* HTCLOSE */
4571 if (wParam == HTSYSMENU)
4575 td->visible = FALSE;
4576 ShowWindow(td->w, SW_HIDE);
4586 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4592 #define MOUSE_SENS 40
4595 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4596 WPARAM wParam, LPARAM lParam);
4597 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4598 WPARAM wParam, LPARAM lParam)
4599 #else /* __MWERKS__ */
4600 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4601 WPARAM wParam, LPARAM lParam)
4602 #endif /* __MWERKS__ */
4604 static int iMouse = 0;
4605 static WORD xMouse = 0;
4606 static WORD yMouse = 0;
4621 case WM_LBUTTONDOWN:
4622 case WM_MBUTTONDOWN:
4623 case WM_RBUTTONDOWN:
4626 SendMessage(hWnd, WM_CLOSE, 0, 0);
4633 int dx = LOWORD(lParam) - xMouse;
4634 int dy = HIWORD(lParam) - yMouse;
4636 if (dx < 0) dx = -dx;
4637 if (dy < 0) dy = -dy;
4639 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
4641 SendMessage(hWnd, WM_CLOSE, 0, 0);
4646 xMouse = LOWORD(lParam);
4647 yMouse = HIWORD(lParam);
4653 DestroyWindow(hwndSaver);
4659 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4662 #endif /* USE_SAVER */
4666 * Display warning message (see "z-util.c")
4668 static void hack_plog(concptr str)
4673 MessageBox(NULL, str, "警告!",
4674 MB_ICONEXCLAMATION | MB_OK);
4676 MessageBox(NULL, str, "Warning",
4677 MB_ICONEXCLAMATION | MB_OK);
4685 * Display error message and quit (see "z-util.c")
4687 static void hack_quit(concptr str)
4692 MessageBox(NULL, str, "エラー!",
4693 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4695 MessageBox(NULL, str, "Error",
4696 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4701 UnregisterClass(AppName, hInstance);
4702 if (hIcon) DestroyIcon(hIcon);
4709 * Display warning message (see "z-util.c")
4711 static void hook_plog(concptr str)
4716 MessageBox(data[0].w, str, "警告!",
4717 MB_ICONEXCLAMATION | MB_OK);
4719 MessageBox(data[0].w, str, "Warning",
4720 MB_ICONEXCLAMATION | MB_OK);
4728 * Display error message and quit (see "z-util.c")
4730 static void hook_quit(concptr str)
4735 MessageBox(data[0].w, str, "エラー!",
4736 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4738 MessageBox(data[0].w, str, "Error",
4739 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4744 for (int i = MAX_TERM_DATA - 1; i >= 0; --i)
4746 term_force_font(&data[i], NULL);
4747 if (data[i].font_want) string_free(data[i].font_want);
4748 if (data[i].w) DestroyWindow(data[i].w);
4752 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
4753 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
4754 if (infMask.hPalette) DeleteObject(infMask.hPalette);
4755 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
4757 DeleteObject(hbrYellow);
4760 if (hPal) DeleteObject(hPal);
4762 UnregisterClass(AppName, hInstance);
4763 if (hIcon) DestroyIcon(hIcon);
4772 static void init_stuff(void)
4775 GetModuleFileName(hInstance, path, 512);
4777 strcpy(path + strlen(path) - 4, ".INI");
4778 ini_file = string_make(path);
4779 int i = strlen(path);
4783 if (path[i] == '\\')
4789 strcpy(path + i + 1, "lib\\");
4790 validate_dir(path, TRUE);
4791 init_file_paths(path);
4792 validate_dir(ANGBAND_DIR_APEX, FALSE);
4793 validate_dir(ANGBAND_DIR_BONE, FALSE);
4794 if (!check_dir(ANGBAND_DIR_EDIT))
4796 validate_dir(ANGBAND_DIR_DATA, TRUE);
4800 validate_dir(ANGBAND_DIR_DATA, FALSE);
4803 validate_dir(ANGBAND_DIR_FILE, TRUE);
4804 validate_dir(ANGBAND_DIR_HELP, FALSE);
4805 validate_dir(ANGBAND_DIR_INFO, FALSE);
4806 validate_dir(ANGBAND_DIR_PREF, TRUE);
4807 validate_dir(ANGBAND_DIR_SAVE, FALSE);
4808 validate_dir(ANGBAND_DIR_USER, TRUE);
4809 validate_dir(ANGBAND_DIR_XTRA, TRUE);
4810 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
4812 validate_file(path);
4813 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
4814 ANGBAND_DIR_XTRA_GRAF = string_make(path);
4815 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
4817 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
4818 ANGBAND_DIR_XTRA_SOUND = string_make(path);
4819 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
4821 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
4822 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
4823 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
4825 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
4826 ANGBAND_DIR_XTRA_HELP = string_make(path);
4831 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
4833 static bool is_already_running(void)
4835 HANDLE hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
4836 if (GetLastError() == ERROR_ALREADY_EXISTS)
4846 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
4848 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
4849 LPSTR lpCmdLine, int nCmdShow)
4855 setlocale(LC_ALL, "ja_JP.utf8");
4858 if (is_already_running())
4861 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
4863 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4867 if (hPrevInst == NULL)
4869 wc.style = CS_CLASSDC;
4870 wc.lpfnWndProc = AngbandWndProc;
4873 wc.hInstance = hInst;
4874 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
4875 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
4876 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
4877 wc.lpszMenuName = AppName;
4878 wc.lpszClassName = AppName;
4880 if (!RegisterClass(&wc)) exit(1);
4882 wc.lpfnWndProc = AngbandListProc;
4883 wc.lpszMenuName = NULL;
4884 wc.lpszClassName = AngList;
4886 if (!RegisterClass(&wc)) exit(2);
4890 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
4891 wc.lpfnWndProc = AngbandSaverProc;
4893 wc.lpszMenuName = NULL;
4894 wc.lpszClassName = "WindowsScreenSaverClass";
4896 if (!RegisterClass(&wc)) exit(3);
4902 plog_aux = hack_plog;
4903 quit_aux = hack_quit;
4904 core_aux = hack_quit;
4907 for (int i = 0; special_key_list[i]; ++i)
4909 special_key[special_key_list[i]] = TRUE;
4912 for (int i = 0; ignore_key_list[i]; ++i)
4914 ignore_key[ignore_key_list[i]] = TRUE;
4918 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
4919 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
4920 ReleaseDC(NULL, hdc);
4922 for (int i = 0; i < 256; i++)
4924 byte rv = angband_color_table[i][1];
4925 byte gv = angband_color_table[i][2];
4926 byte bv = angband_color_table[i][3];
4927 win_clr[i] = PALETTERGB(rv, gv, bv);
4928 angband_color_table[i][0] = win_pal[i];
4934 plog_aux = hook_plog;
4935 quit_aux = hook_quit;
4936 core_aux = hook_quit;
4938 ANGBAND_SYS = "win";
4939 if (7 != GetKeyboardType(0))
4940 ANGBAND_KEYBOARD = "0";
4943 /* todo PC-98のサポートは打ち切ったので削除したい */
4944 switch (GetKeyboardType(1))
4946 case 0x0D01: case 0x0D02:
4947 case 0x0D03: case 0x0D04:
4948 case 0x0D05: case 0x0D06:
4950 ANGBAND_KEYBOARD = "NEC98";
4954 ANGBAND_KEYBOARD = "JAPAN";
4959 Term_activate(term_screen);
4960 init_angband(p_ptr);
4963 if (lpCmdLine[0] == '-') {
4964 switch (lpCmdLine[1])
4969 if (!lpCmdLine[2]) break;
4970 chuukei_server = TRUE;
4971 if (connect_chuukei_server(&lpCmdLine[2]) < 0) {
4972 msg_print("connect fail");
4975 msg_print("connect");
4983 if (!lpCmdLine[2]) break;
4984 chuukei_client = TRUE;
4985 connect_chuukei_server(&lpCmdLine[2]);
4986 play_game(player_ptr, FALSE);
4993 if (!lpCmdLine[2]) break;
4994 prepare_browse_movie(&lpCmdLine[2]);
4995 play_game(player_ptr, FALSE);
5004 if (!chuukei_server) check_for_save_file(lpCmdLine);
5006 check_for_save_file(p_ptr, lpCmdLine);
5009 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
5011 while (GetMessage(&msg, NULL, 0, 0))
5013 TranslateMessage(&msg);
5014 DispatchMessage(&msg);
5020 #endif /* WINDOWS */