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 * If "USE_GRAPHICS" is defined, then "readdib.h" and "readdib.c" must
58 * be placed into "src/", and the "8X8.BMP" bitmap file must be placed
59 * into "lib/xtra/graf". In any case, some "*.fon" files (including
60 * "8X13.FON" if nothing else) must be placed into "lib/xtra/font/".
61 * If "USE_SOUND" is defined, then some special library (for example,
62 * "winmm.lib") may need to be linked in, and desired "*.WAV" sound
63 * files must be placed into "lib/xtra/sound/". All of these extra
64 * files can be found in the "ext-win" archive.
68 * The "term_xtra_win_clear()" function should probably do a low-level
69 * clear of the current window, and redraw the borders and other things,
70 * if only for efficiency.
74 * A simpler method is needed for selecting the "tile size" for windows.
78 * The various "warning" messages assume the existance of the "screen.w"
79 * window, I think, and only a few calls actually check for its existance,
80 * this may be okay since "NULL" means "on top of all windows". (?) The
81 * user must never be allowed to "hide" the main window, or the "menubar"
86 * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
87 * use with the "winhelp.exe" program. These files *may* be available
88 * at the ftp site somewhere, but I have not seen them.
92 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
94 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
96 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
97 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
105 #include "cmd-dump.h"
106 #include "view-mainwindow.h"
108 #include "floor-events.h"
127 * Extract the "WIN32" flag from the compiler
129 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
136 * Available graphic modes
138 #define GRAPHICS_NONE 0
139 #define GRAPHICS_ORIGINAL 1
140 #define GRAPHICS_ADAM_BOLT 2
141 #define GRAPHICS_HENGBAND 3
144 * Hack -- allow use of "screen saver" mode
150 * Menu constants -- see "ANGBAND.RC"
153 #define IDM_FILE_NEW 100
154 #define IDM_FILE_OPEN 101
155 #define IDM_FILE_SAVE 110
156 #define IDM_FILE_SCORE 120
157 #define IDM_FILE_MOVIE 121
158 #define IDM_FILE_EXIT 130
160 #define IDM_WINDOW_VIS_0 200
161 #define IDM_WINDOW_VIS_1 201
162 #define IDM_WINDOW_VIS_2 202
163 #define IDM_WINDOW_VIS_3 203
164 #define IDM_WINDOW_VIS_4 204
165 #define IDM_WINDOW_VIS_5 205
166 #define IDM_WINDOW_VIS_6 206
167 #define IDM_WINDOW_VIS_7 207
169 #define IDM_WINDOW_FONT_0 210
170 #define IDM_WINDOW_FONT_1 211
171 #define IDM_WINDOW_FONT_2 212
172 #define IDM_WINDOW_FONT_3 213
173 #define IDM_WINDOW_FONT_4 214
174 #define IDM_WINDOW_FONT_5 215
175 #define IDM_WINDOW_FONT_6 216
176 #define IDM_WINDOW_FONT_7 217
178 #define IDM_WINDOW_POS_0 220
179 #define IDM_WINDOW_POS_1 221
180 #define IDM_WINDOW_POS_2 222
181 #define IDM_WINDOW_POS_3 223
182 #define IDM_WINDOW_POS_4 224
183 #define IDM_WINDOW_POS_5 225
184 #define IDM_WINDOW_POS_6 226
185 #define IDM_WINDOW_POS_7 227
187 #define IDM_WINDOW_BIZ_0 230
188 #define IDM_WINDOW_BIZ_1 231
189 #define IDM_WINDOW_BIZ_2 232
190 #define IDM_WINDOW_BIZ_3 233
191 #define IDM_WINDOW_BIZ_4 234
192 #define IDM_WINDOW_BIZ_5 235
193 #define IDM_WINDOW_BIZ_6 236
194 #define IDM_WINDOW_BIZ_7 237
196 #define IDM_WINDOW_I_WID_0 240
197 #define IDM_WINDOW_I_WID_1 241
198 #define IDM_WINDOW_I_WID_2 242
199 #define IDM_WINDOW_I_WID_3 243
200 #define IDM_WINDOW_I_WID_4 244
201 #define IDM_WINDOW_I_WID_5 245
202 #define IDM_WINDOW_I_WID_6 246
203 #define IDM_WINDOW_I_WID_7 247
205 #define IDM_WINDOW_D_WID_0 250
206 #define IDM_WINDOW_D_WID_1 251
207 #define IDM_WINDOW_D_WID_2 252
208 #define IDM_WINDOW_D_WID_3 253
209 #define IDM_WINDOW_D_WID_4 254
210 #define IDM_WINDOW_D_WID_5 255
211 #define IDM_WINDOW_D_WID_6 256
212 #define IDM_WINDOW_D_WID_7 257
214 #define IDM_WINDOW_I_HGT_0 260
215 #define IDM_WINDOW_I_HGT_1 261
216 #define IDM_WINDOW_I_HGT_2 262
217 #define IDM_WINDOW_I_HGT_3 263
218 #define IDM_WINDOW_I_HGT_4 264
219 #define IDM_WINDOW_I_HGT_5 265
220 #define IDM_WINDOW_I_HGT_6 266
221 #define IDM_WINDOW_I_HGT_7 267
223 #define IDM_WINDOW_D_HGT_0 270
224 #define IDM_WINDOW_D_HGT_1 271
225 #define IDM_WINDOW_D_HGT_2 272
226 #define IDM_WINDOW_D_HGT_3 273
227 #define IDM_WINDOW_D_HGT_4 274
228 #define IDM_WINDOW_D_HGT_5 275
229 #define IDM_WINDOW_D_HGT_6 276
230 #define IDM_WINDOW_D_HGT_7 277
232 #define IDM_OPTIONS_NO_GRAPHICS 400
233 #define IDM_OPTIONS_OLD_GRAPHICS 401
234 #define IDM_OPTIONS_NEW_GRAPHICS 402
235 #define IDM_OPTIONS_NEW2_GRAPHICS 403
236 #define IDM_OPTIONS_BIGTILE 409
237 #define IDM_OPTIONS_SOUND 410
238 #define IDM_OPTIONS_MUSIC 411
239 #define IDM_OPTIONS_SAVER 420
240 #define IDM_OPTIONS_MAP 430
241 #define IDM_OPTIONS_BG 440
242 #define IDM_OPTIONS_OPEN_BG 441
244 #define IDM_DUMP_SCREEN_HTML 450
246 #define IDM_HELP_CONTENTS 901
249 * Exclude parts of WINDOWS.H that are not needed
251 #define NOCOMM /* Comm driver APIs and definitions */
252 #define NOLOGERROR /* LogError() and related definitions */
253 #define NOPROFILER /* Profiler APIs */
254 #define NOLFILEIO /* _l* file I/O routines */
255 #define NOOPENFILE /* OpenFile and related definitions */
256 #define NORESOURCE /* Resource management */
257 #define NOATOM /* Atom management */
258 #define NOLANGUAGE /* Character test routines */
259 #define NOLSTRING /* lstr* string management routines */
260 #define NODBCS /* Double-byte character set routines */
261 #define NOKEYBOARDINFO /* Keyboard driver routines */
262 #define NOCOLOR /* COLOR_* color values */
263 #define NODRAWTEXT /* DrawText() and related definitions */
264 #define NOSCALABLEFONT /* Truetype scalable font support */
265 #define NOMETAFILE /* Metafile support */
266 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
267 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
268 #define NOKEYSTATES /* MK_* message key state flags */
269 #define NOWH /* SetWindowsHook and related WH_* definitions */
270 #define NOCLIPBOARD /* Clipboard APIs and definitions */
271 #define NOICONS /* IDI_* icon IDs */
272 #define NOMDI /* MDI support */
273 #define NOHELP /* Help support */
275 /* Not defined since it breaks Borland C++ 5.5 */
276 /* #define NOCTLMGR */ /* Control management and controls */
279 * Exclude parts of WINDOWS.H that are not needed (Win32)
281 #define WIN32_LEAN_AND_MEAN
282 #define NONLS /* All NLS defines and routines */
283 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
284 #define NOKANJI /* Kanji support stuff. */
285 #define NOMCX /* Modem Configuration Extensions */
288 * Include the "windows" support file
293 * Exclude parts of MMSYSTEM.H that are not needed
295 #define MMNODRV /* Installable driver support */
296 #define MMNOWAVE /* Waveform support */
297 #define MMNOMIDI /* MIDI support */
298 #define MMNOAUX /* Auxiliary audio support */
299 #define MMNOTIMER /* Timer support */
300 #define MMNOJOY /* Joystick support */
301 #define MMNOMCI /* MCI support */
302 #define MMNOMMIO /* Multimedia file I/O support */
303 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
307 * Standard sound names
309 const concptr angband_sound_name[SOUND_MAX] =
381 * Standard music names
383 const concptr angband_music_basic_name[MUSIC_BASIC_MAX] =
409 * Include some more files. Note: the Cygnus Cygwin compiler
410 * doesn't use mmsystem.h instead it includes the winmm library
411 * which performs a similar function.
413 #include <mmsystem.h>
417 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
418 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
420 /* #define HTML_HELP */
423 #include <htmlhelp.h>
424 #endif /* HTML_HELP */
427 * Include the support for loading bitmaps
430 # include "readdib.h"
434 * Hack -- Fake declarations from "dos.h"
437 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
439 #define FA_LABEL 0x08 /* Volume label */
440 #define FA_DIREC 0x10 /* Directory */
441 unsigned _cdecl _dos_getfileattr(concptr, unsigned *);
445 * Silliness in WIN32 drawing routine
448 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
452 * Silliness for Windows 95
454 #ifndef WS_EX_TOOLWINDOW
455 # define WS_EX_TOOLWINDOW 0
459 * Foreground color bits (hard-coded by DOS)
461 #define VID_BLACK 0x00
462 #define VID_BLUE 0x01
463 #define VID_GREEN 0x02
464 #define VID_CYAN 0x03
466 #define VID_MAGENTA 0x05
467 #define VID_YELLOW 0x06
468 #define VID_WHITE 0x07
471 * Bright text (hard-coded by DOS)
473 #define VID_BRIGHT 0x08
476 * Background color bits (hard-coded by DOS)
478 #define VUD_BLACK 0x00
479 #define VUD_BLUE 0x10
480 #define VUD_GREEN 0x20
481 #define VUD_CYAN 0x30
483 #define VUD_MAGENTA 0x50
484 #define VUD_YELLOW 0x60
485 #define VUD_WHITE 0x70
488 * Blinking text (hard-coded by DOS)
490 #define VUD_BRIGHT 0x80
496 typedef struct _term_data term_data;
500 * @brief ターム情報構造体 / Extra "term" data
503 * pos_x / pos_y は各タームの左上点座標を指す。
506 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
507 * 1ドットずつ調整するステータスを指す。
508 * また、フォントを変更すると都度自動調整される。
511 * Note the use of "font_want" for the names of the font file requested by
512 * the user, and the use of "font_file" for the currently active font file.
514 * The "font_file" is uppercased, and takes the form "8X13.FON", while
515 * "font_want" can be in almost any form as long as it could be construed
516 * as attempting to represent the name of a font.
528 TERM_LEN rows; /* int -> uint */
531 uint pos_x; //!< タームの左上X座標
532 uint pos_y; //!< タームの左上Y座標
547 int font_wid; //!< フォント横幅
548 int font_hgt; //!< フォント縦幅
549 int tile_wid; //!< タイル横幅
550 int tile_hgt; //!< タイル縦幅
562 #define MAX_TERM_DATA 8 //!< Maximum number of windows
564 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
565 static term_data *my_td; //!< Hack -- global "window creation" pointer
566 POINT normsize; //!< Remember normal size of main window when maxmized
569 * was main window maximized on previous playing
571 bool win_maximized = FALSE;
576 bool game_in_progress = FALSE;
579 * note when "open"/"new" become valid
581 bool initialized = FALSE;
584 * screen paletted, i.e. 256 colors
586 bool paletted = FALSE;
589 * 16 colors screen, don't use RGB()
591 bool colors16 = FALSE;
594 * Saved instance handle
596 static HINSTANCE hInstance;
599 * Yellow brush for the cursor
601 static HBRUSH hbrYellow;
611 static HPALETTE hPal;
614 static HBITMAP hBG = NULL;
615 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
616 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
621 * The screen saver window
623 static HWND hwndSaver;
625 #endif /* USE_SAVER */
631 * 現在使用中のタイルID(0ならば未使用)
632 * Flag set once "graphics" has been initialized
634 static byte_hack current_graphics_mode = 0;
639 static DIBINIT infGraph;
642 * The global bitmap mask
644 static DIBINIT infMask;
646 #endif /* USE_GRAPHICS */
652 * Flag set once "sound" has been initialized
654 static bool can_use_sound = FALSE;
656 #define SAMPLE_SOUND_MAX 16
658 * An array of sound file names
660 static concptr sound_file[SOUND_MAX][SAMPLE_SOUND_MAX];
662 #endif /* USE_SOUND */
668 #define SAMPLE_MUSIC_MAX 16
669 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
670 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
671 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
672 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
673 static bool can_use_music = FALSE;
675 static MCI_OPEN_PARMS mop;
676 static char mci_device_type[256];
678 int current_music_type = 0;
679 int current_music_id = 0;
681 #endif /* USE_MUSIC */
685 * Full path to ANGBAND.INI
687 static concptr ini_file = NULL;
690 * Name of application
692 static concptr AppName = "ANGBAND";
695 * Name of sub-window type
697 static concptr AngList = "AngList";
702 static concptr ANGBAND_DIR_XTRA_GRAF;
703 static concptr ANGBAND_DIR_XTRA_SOUND;
704 static concptr ANGBAND_DIR_XTRA_MUSIC;
705 static concptr ANGBAND_DIR_XTRA_HELP;
707 static concptr ANGBAND_DIR_XTRA_MUSIC;
712 * The "complex" color values
714 static COLORREF win_clr[256];
718 * Flag for macro trigger with dump ASCII
720 static bool term_no_press = FALSE;
725 static bool mouse_down = FALSE;
726 static bool paint_rect = FALSE;
727 static TERM_LEN mousex = 0, mousey = 0;
728 static TERM_LEN oldx, oldy;
732 * @brief The "simple" color values
734 * See "main-ibm.c" for original table information
735 * The entries below are taken from the "color bits" defined above.
736 * Note that many of the choices below suck, but so do crappy monitors.
738 static BYTE win_pal[256] =
740 VID_BLACK, /* Dark */
741 VID_WHITE, /* White */
742 VID_CYAN, /* Slate XXX */
743 VID_RED | VID_BRIGHT, /* Orange XXX */
745 VID_GREEN, /* Green */
747 VID_YELLOW, /* Umber XXX */
748 VID_BLACK | VID_BRIGHT, /* Light Dark */
749 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
750 VID_MAGENTA, /* Violet XXX */
751 VID_YELLOW | VID_BRIGHT, /* Yellow */
752 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
753 VID_GREEN | VID_BRIGHT, /* Light Green */
754 VID_BLUE | VID_BRIGHT, /* Light Blue */
755 VID_YELLOW /* Light Umber XXX */
760 * Hack -- define which keys are "special"
762 static bool special_key[256];
763 static bool ignore_key[256];
766 * Hack -- initialization list for "special_key"
768 static byte special_key_list[] = {
769 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
770 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
771 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
772 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
773 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
774 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
775 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
776 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
777 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
778 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
779 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
780 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
781 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
782 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
783 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
784 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
785 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
790 static byte ignore_key_list[] = {
791 VK_ESCAPE, VK_TAB, VK_SPACE,
792 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
793 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
794 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
799 /* Function prototype */
801 static bool is_already_running(void);
805 static void delete_bg(void)
814 static int init_bg(void)
816 char * bmfile = bg_bitmap_file;
819 if (use_bg == 0) return 0;
821 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
823 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
831 static void DrawBG(HDC hdc, RECT *r)
836 int x = r->left, y = r->top;
837 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
843 GetObject(hBG, sizeof(bm), &bm);
844 swid = bm.bmWidth; shgt = bm.bmHeight;
846 hdcSrc = CreateCompatibleDC(hdc);
847 hOld = SelectObject(hdcSrc, hBG);
851 cwid = MIN(swid - sx, r->right - nx);
854 chgt = MIN(shgt - sy, r->bottom - ny);
855 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
857 } while (ny < r->bottom);
860 } while (nx < r->right);
862 SelectObject(hdcSrc, hOld);
868 * Check for existance of a file
870 static bool check_file(concptr s)
890 attrib = GetFileAttributes(path);
892 /* Require valid filename */
893 if (attrib == INVALID_FILE_NAME) return FALSE;
895 /* Prohibit directory */
896 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return FALSE;
900 /* Examine and verify */
901 if (_dos_getfileattr(path, &attrib)) return FALSE;
903 /* Prohibit something */
904 if (attrib & FA_LABEL) return FALSE;
906 /* Prohibit directory */
907 if (attrib & FA_DIREC) return FALSE;
917 * Check for existance of a directory
919 static bool check_dir(concptr s)
941 /* Remove trailing backslash */
942 if (i && (path[i - 1] == '\\')) path[--i] = '\0';
947 attrib = GetFileAttributes(path);
949 /* Require valid filename */
950 if (attrib == INVALID_FILE_NAME) return FALSE;
952 /* Require directory */
953 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return FALSE;
957 /* Examine and verify */
958 if (_dos_getfileattr(path, &attrib)) return FALSE;
960 /* Prohibit something */
961 if (attrib & FA_LABEL) return FALSE;
963 /* Require directory */
964 if (!(attrib & FA_DIREC)) return FALSE;
976 static void validate_file(concptr s)
981 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
987 * Validate a directory
989 static void validate_dir(concptr s, bool vital)
994 /* This directory contains needed data */
997 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
999 /* Attempt to create this directory */
1002 quit_fmt("Unable to create directory:\n%s", s);
1009 * @brief (Windows版固有実装)Get the "size" for a window
1011 static void term_getsize(term_data *td)
1015 if (td->cols < 1) td->cols = 1;
1016 if (td->rows < 1) td->rows = 1;
1019 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1020 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1022 /* Fake window size */
1024 rc.right = rc.left + wid;
1026 rc.bottom = rc.top + hgt;
1028 /* rc.right += 1; */
1029 /* rc.bottom += 1; */
1032 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1035 td->size_wid = rc.right - rc.left;
1036 td->size_hgt = rc.bottom - rc.top;
1038 /* See CreateWindowEx */
1041 /* Extract actual location */
1042 GetWindowRect(td->w, &rc);
1044 /* Save the location */
1045 td->pos_x = rc.left;
1051 * Write the "prefs" for a single term
1053 static void save_prefs_aux(int i)
1055 term_data *td = &data[i];
1056 GAME_TEXT sec_name[128];
1060 WINDOWPLACEMENT lpwndpl;
1063 /* Make section name */
1064 sprintf(sec_name, "Term-%d", i);
1069 strcpy(buf, td->visible ? "1" : "0");
1070 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1075 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "MS ゴシック");
1077 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "Courier");
1080 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1082 wsprintf(buf, "%d", td->lf.lfWidth);
1083 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1084 wsprintf(buf, "%d", td->lf.lfHeight);
1085 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1086 wsprintf(buf, "%d", td->lf.lfWeight);
1087 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1089 strcpy(buf, td->bizarre ? "1" : "0");
1090 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1093 wsprintf(buf, "%d", td->tile_wid);
1094 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1097 wsprintf(buf, "%d", td->tile_hgt);
1098 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1100 /* Get window placement and dimensions */
1101 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1102 GetWindowPlacement(td->w, &lpwndpl);
1104 /* Acquire position in *normal* mode (not minimized) */
1105 rc = lpwndpl.rcNormalPosition;
1107 /* Window size (x) */
1108 if (i == 0) wsprintf(buf, "%d", normsize.x);
1109 else wsprintf(buf, "%d", td->cols);
1110 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1112 /* Window size (y) */
1113 if (i == 0) wsprintf(buf, "%d", normsize.y);
1114 else wsprintf(buf, "%d", td->rows);
1115 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1117 /* Maxmized (only main window) */
1120 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1121 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1124 /* Acquire position */
1125 GetWindowRect(td->w, &rc);
1127 /* Window position (x) */
1128 wsprintf(buf, "%d", rc.left);
1129 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1131 /* Window position (y) */
1132 wsprintf(buf, "%d", rc.top);
1133 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1135 /* Window Z position */
1138 strcpy(buf, td->posfix ? "1" : "0");
1139 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1146 * We assume that the windows have all been initialized
1148 static void save_prefs(void)
1154 /* Save the "arg_graphics" flag */
1155 sprintf(buf, "%d", arg_graphics);
1156 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1158 /* Save the "arg_bigtile" flag */
1159 strcpy(buf, arg_bigtile ? "1" : "0");
1160 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1162 /* Save the "arg_sound" flag */
1163 strcpy(buf, arg_sound ? "1" : "0");
1164 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1166 /* Save the "arg_sound" flag */
1167 strcpy(buf, arg_music ? "1" : "0");
1168 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1171 strcpy(buf, use_bg ? "1" : "0");
1172 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1173 WritePrivateProfileString("Angband", "BackGroundBitmap",
1174 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1176 /* Save window prefs */
1177 for (i = 0; i < MAX_TERM_DATA; ++i)
1185 * Load the "prefs" for a single term
1187 static void load_prefs_aux(int i)
1189 term_data *td = &data[i];
1190 GAME_TEXT sec_name[128];
1193 int wid, hgt, posx, posy;
1194 int dispx = GetSystemMetrics(SM_CXVIRTUALSCREEN);
1195 int dispy = GetSystemMetrics(SM_CYVIRTUALSCREEN);
1199 /* Make section name */
1200 sprintf(sec_name, "Term-%d", i);
1202 /* Make section name */
1203 sprintf(sec_name, "Term-%d", i);
1208 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1211 /* Desired font, with default */
1213 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1215 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1220 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1222 /* Analyze font, save desired font name */
1223 td->font_want = string_make(tmp);
1225 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1226 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1227 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1230 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1231 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1234 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1235 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1236 normsize.x = td->cols; normsize.y = td->rows;
1241 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
1244 /* Window position */
1245 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1246 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1247 td->pos_x = MIN(MAX(0, posx), dispx - 128);
1248 td->pos_y = MIN(MAX(0, posy), dispy - 128);
1250 /* Window Z position */
1253 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
1261 static void load_prefs(void)
1265 /* Extract the "arg_graphics" flag */
1266 arg_graphics = (byte_hack)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1268 /* Extract the "arg_bigtile" flag */
1269 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
1270 use_bigtile = arg_bigtile;
1272 /* Extract the "arg_sound" flag */
1273 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1275 /* Extract the "arg_sound" flag */
1276 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1279 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1280 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1282 /* Load window prefs */
1283 for (i = 0; i < MAX_TERM_DATA; ++i)
1289 #if defined(USE_SOUND) || defined(USE_MUSIC)
1292 * - Taken from files.c.
1294 * Extract "tokens" from a buffer
1296 * This function uses "whitespace" as delimiters, and treats any amount of
1297 * whitespace as a single delimiter. We will never return any empty tokens.
1298 * When given an empty buffer, or a buffer containing only "whitespace", we
1299 * will return no tokens. We will never extract more than "num" tokens.
1301 * By running a token through the "text_to_ascii()" function, you can allow
1302 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1304 * We save pointers to the tokens in "tokens", and return the number found.
1306 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1316 /* Skip leading whitespace */
1317 for (; *s && iswspace(*s); ++s) /* loop */;
1322 /* Find next whitespace, if any */
1323 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1325 /* Nuke and advance (if necessary) */
1326 if (*t) *t++ = '\0';
1328 /* Save the token */
1339 #endif /* USE_SOUND || USE_MUSIC */
1343 static void load_sound_prefs(void)
1347 char ini_path[1024];
1348 char wav_path[1024];
1349 char *zz[SAMPLE_SOUND_MAX];
1351 /* Access the sound.cfg */
1353 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1355 for (i = 0; i < SOUND_MAX; i++)
1357 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1359 num = tokenize_whitespace(tmp, SAMPLE_SOUND_MAX, zz);
1361 for (j = 0; j < num; j++)
1363 /* Access the sound */
1364 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1366 /* Save the sound filename, if it exists */
1367 if (check_file(wav_path))
1368 sound_file[i][j] = string_make(zz[j]);
1373 #endif /* USE_SOUND */
1377 static void load_music_prefs(void)
1381 char ini_path[1024];
1382 char wav_path[1024];
1383 char *zz[SAMPLE_MUSIC_MAX];
1386 /* Access the music.cfg */
1388 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1390 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1392 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1394 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1396 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1398 for (j = 0; j < num; j++)
1400 /* Access the sound */
1401 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1403 /* Save the sound filename, if it exists */
1404 if (check_file(wav_path))
1405 music_file[i][j] = string_make(zz[j]);
1409 for (i = 0; i < current_world_ptr->max_d_idx; i++)
1411 sprintf(key, "dungeon%03d", i);
1412 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1414 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1416 for (j = 0; j < num; j++)
1418 /* Access the sound */
1419 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1421 /* Save the sound filename, if it exists */
1422 if (check_file(wav_path))
1423 dungeon_music_file[i][j] = string_make(zz[j]);
1427 for (i = 0; i < max_q_idx; i++)
1429 sprintf(key, "quest%03d", i);
1430 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1432 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1434 for (j = 0; j < num; j++)
1436 /* Access the sound */
1437 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1439 /* Save the sound filename, if it exists */
1440 if (check_file(wav_path))
1441 quest_music_file[i][j] = string_make(zz[j]);
1445 for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1447 sprintf(key, "town%03d", i);
1448 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1450 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1452 for (j = 0; j < num; j++)
1454 /* Access the sound */
1455 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1457 /* Save the sound filename, if it exists */
1458 if (check_file(wav_path))
1459 town_music_file[i][j] = string_make(zz[j]);
1466 #endif /* USE_MUSIC */
1469 * Create the new global palette based on the bitmap palette
1470 * (if any), and the standard 16 entry palette derived from
1471 * "win_clr[]" which is used for the basic 16 Angband colors.
1473 * This function is never called before all windows are ready.
1475 * This function returns FALSE if the new palette could not be
1476 * prepared, which should normally be a fatal error. XXX XXX
1478 * Note that only some machines actually use a "palette".
1480 static int new_palette(void)
1488 LPLOGPALETTE pLogPal;
1489 LPPALETTEENTRY lppe;
1494 /* This makes no sense */
1495 if (!paletted) return TRUE;
1505 /* Check the bitmap palette */
1506 hBmPal = infGraph.hPalette;
1508 /* Use the bitmap */
1511 lppeSize = 256 * sizeof(PALETTEENTRY);
1512 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1513 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1514 if ((nEntries == 0) || (nEntries > 220))
1517 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1520 rnfree(lppe, lppeSize);
1527 #endif /* USE_GRAPHICS */
1529 /* Size of palette */
1530 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1532 /* Allocate palette */
1533 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1536 pLogPal->palVersion = 0x300;
1538 /* Make room for bitmap and normal data */
1539 pLogPal->palNumEntries = nEntries + 16;
1541 /* Save the bitmap data */
1542 for (i = 0; i < nEntries; i++)
1544 pLogPal->palPalEntry[i] = lppe[i];
1547 /* Save the normal data */
1548 for (i = 0; i < 16; i++)
1552 /* Access the entry */
1553 p = &(pLogPal->palPalEntry[i + nEntries]);
1555 /* Save the colors */
1556 p->peRed = GetRValue(win_clr[i]);
1557 p->peGreen = GetGValue(win_clr[i]);
1558 p->peBlue = GetBValue(win_clr[i]);
1560 /* Save the flags */
1561 p->peFlags = PC_NOCOLLAPSE;
1564 /* Free something */
1565 if (lppe) rnfree(lppe, lppeSize);
1567 /* Create a new palette, or fail */
1568 hNewPal = CreatePalette(pLogPal);
1569 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1571 /* Free the palette */
1572 rnfree(pLogPal, pLogPalSize);
1577 /* Realize the palette */
1579 SelectPalette(hdc, hNewPal, 0);
1580 i = RealizePalette(hdc);
1581 ReleaseDC(td->w, hdc);
1582 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1586 for (i = 1; i < MAX_TERM_DATA; i++)
1591 SelectPalette(hdc, hNewPal, 0);
1592 ReleaseDC(td->w, hdc);
1595 /* Delete old palette */
1596 if (hPal) DeleteObject(hPal);
1598 /* Save new palette */
1608 * @brief グラフィクスを初期化する / Initialize graphics
1611 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1612 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1615 static bool init_graphics(void)
1617 /* Initialize once */
1619 BYTE wid, hgt, twid, thgt, ox, oy;
1622 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1632 ANGBAND_GRAF = "new";
1634 else if (arg_graphics == GRAPHICS_HENGBAND)
1654 ANGBAND_GRAF = "ne2";
1665 ANGBAND_GRAF = "old";
1668 /* Access the bitmap file */
1669 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1671 /* Load the bitmap or quit */
1672 if (!ReadDIB(data[0].w, buf, &infGraph))
1674 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1678 /* Save the new sizes */
1679 infGraph.CellWidth = wid;
1680 infGraph.CellHeight = hgt;
1681 infGraph.TileWidth = twid;
1682 infGraph.TileHeight = thgt;
1683 infGraph.OffsetX = ox;
1684 infGraph.OffsetY = oy;
1686 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1688 /* Access the mask file */
1689 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1691 /* Load the bitmap or quit */
1692 if (!ReadDIB(data[0].w, buf, &infMask))
1694 plog_fmt("Cannot read bitmap file '%s'", buf);
1698 if (arg_graphics == GRAPHICS_HENGBAND)
1700 /* Access the mask file */
1701 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1703 /* Load the bitmap or quit */
1704 if (!ReadDIB(data[0].w, buf, &infMask))
1706 plog_fmt("Cannot read bitmap file '%s'", buf);
1711 /* Activate a palette */
1716 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1720 /* Graphics available */
1721 current_graphics_mode = arg_graphics;
1722 return (current_graphics_mode);
1724 #endif /* USE_GRAPHICS */
1731 static bool init_music(void)
1733 /* Initialize once */
1736 /* Load the prefs */
1739 /* Sound available */
1740 can_use_music = TRUE;
1742 return (can_use_music);
1746 * Hack -- Stop a music
1748 static void stop_music(void)
1750 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1751 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1754 #endif /* USE_MUSIC */
1760 static bool init_sound(void)
1762 /* Initialize once */
1765 /* Load the prefs */
1768 /* Sound available */
1769 can_use_sound = TRUE;
1771 return (can_use_sound);
1773 #endif /* USE_SOUND */
1779 static void term_window_resize(term_data *td)
1781 /* Require window */
1784 /* Resize the window */
1785 SetWindowPos(td->w, 0, 0, 0,
1786 td->size_wid, td->size_hgt,
1787 SWP_NOMOVE | SWP_NOZORDER);
1790 InvalidateRect(td->w, NULL, TRUE);
1795 * Force the use of a new "font file" for a term_data
1797 * This function may be called before the "window" is ready
1799 * This function returns zero only if everything succeeds.
1801 * Note that the "font name" must be capitalized!!!
1803 static errr term_force_font(term_data *td, concptr path)
1807 /* Forget the old font (if needed) */
1808 if (td->font_id) DeleteObject(td->font_id);
1813 /* Create the font (using the 'base' of the font file name!) */
1814 td->font_id = CreateFontIndirect(&(td->lf));
1815 wid = td->lf.lfWidth;
1816 hgt = td->lf.lfHeight;
1817 if (!td->font_id) return 1;
1819 /* Hack -- Unknown size */
1826 /* all this trouble to get the cell size */
1827 hdcDesktop = GetDC(HWND_DESKTOP);
1828 hfOld = SelectObject(hdcDesktop, td->font_id);
1829 GetTextMetrics(hdcDesktop, &tm);
1830 SelectObject(hdcDesktop, hfOld);
1831 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1833 /* Font size info */
1834 wid = tm.tmAveCharWidth;
1838 /* Save the size info */
1849 * Allow the user to change the font for this window.
1851 static void term_change_font(term_data *td)
1855 memset(&cf, 0, sizeof(cf));
1856 cf.lStructSize = sizeof(cf);
1857 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1858 cf.lpLogFont = &(td->lf);
1860 if (ChooseFont(&cf))
1862 /* Force the font */
1863 term_force_font(td, NULL);
1865 /* Assume not bizarre */
1868 /* Reset the tile info */
1869 td->tile_wid = td->font_wid;
1870 td->tile_hgt = td->font_hgt;
1872 /* Analyze the font */
1875 /* Resize the window */
1876 term_window_resize(td);
1882 * Allow the user to lock this window.
1884 static void term_window_pos(term_data *td, HWND hWnd)
1886 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1887 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1890 static void windows_map(player_type *player_ptr);
1893 * Hack -- redraw a term_data
1895 static void term_data_redraw(player_type *player_ptr, term_data *td)
1899 /* Redraw the map */
1900 windows_map(player_ptr);
1904 /* Activate the term */
1905 Term_activate(&td->t);
1907 /* Redraw the contents */
1910 /* Restore the term */
1911 Term_activate(term_screen);
1916 void term_inversed_area(HWND hWnd, int x, int y, int w, int h)
1920 HBRUSH myBrush, oldBrush;
1922 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
1923 int tx = td->size_ow1 + x * td->tile_wid;
1924 int ty = td->size_oh1 + y * td->tile_hgt;
1925 int tw = w * td->tile_wid - 1;
1926 int th = h * td->tile_hgt - 1;
1929 myBrush = CreateSolidBrush(RGB(255, 255, 255));
1930 oldBrush = SelectObject(hdc, myBrush);
1931 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1933 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
1935 SelectObject(hdc, oldBrush);
1936 SelectObject(hdc, oldPen);
1941 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
1943 static errr term_user_win(int n)
1954 * React to global changes
1956 static errr term_xtra_win_react(player_type *player_ptr)
1963 /* Save the default colors */
1964 for (i = 0; i < 256; i++)
1966 /* Simply accept the desired colors */
1967 win_pal[i] = angband_color_table[i][0];
1978 bool change = FALSE;
1980 /* Save the default colors */
1981 for (i = 0; i < 256; i++)
1983 /* Extract desired values */
1984 rv = angband_color_table[i][1];
1985 gv = angband_color_table[i][2];
1986 bv = angband_color_table[i][3];
1988 /* Extract a full color code */
1989 code = PALETTERGB(rv, gv, bv);
1991 /* Activate changes */
1992 if (win_clr[i] != code)
1994 /* Note the change */
1997 /* Apply the desired color */
2002 /* Activate the palette if needed */
2003 if (change) (void)new_palette();
2009 /* Handle "arg_sound" */
2010 if (use_sound != arg_sound)
2012 /* Initialize (if needed) */
2013 if (arg_sound && !init_sound())
2016 plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
2022 /* Change setting */
2023 use_sound = arg_sound;
2030 /* Handle "arg_sound" */
2031 if (use_music != arg_music)
2033 /* Initialize (if needed) */
2034 if (arg_music && !init_music())
2037 plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
2042 /* Change setting */
2043 use_music = arg_music;
2045 if (!arg_music) stop_music();
2046 else select_floor_music(player_ptr);
2055 /* Handle "arg_graphics" */
2056 if (use_graphics != arg_graphics)
2058 /* Initialize (if needed) */
2059 if (arg_graphics && !init_graphics())
2062 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
2065 arg_graphics = GRAPHICS_NONE;
2068 /* Change setting */
2069 use_graphics = arg_graphics;
2072 reset_visuals(player_ptr);
2075 #endif /* USE_GRAPHICS */
2078 /* Clean up windows */
2079 for (i = 0; i < MAX_TERM_DATA; i++)
2083 term_data *td = &data[i];
2085 /* Update resized windows */
2086 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
2089 Term_activate(&td->t);
2091 /* Hack -- Resize the term */
2092 Term_resize(td->cols, td->rows);
2094 /* Redraw the contents */
2107 * Process at least one event
2109 static errr term_xtra_win_event(int v)
2113 /* Wait for an event */
2117 if (GetMessage(&msg, NULL, 0, 0))
2119 TranslateMessage(&msg);
2120 DispatchMessage(&msg);
2124 /* Check for an event */
2128 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2130 TranslateMessage(&msg);
2131 DispatchMessage(&msg);
2141 * Process all pending events
2143 static errr term_xtra_win_flush(void)
2147 /* Process all pending events */
2148 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2150 TranslateMessage(&msg);
2151 DispatchMessage(&msg);
2160 * Hack -- clear the screen
2162 * Make this more efficient
2164 static errr term_xtra_win_clear(void)
2166 term_data *td = (term_data*)(Term->data);
2171 /* Rectangle to erase */
2172 rc.left = td->size_ow1;
2173 rc.right = rc.left + td->cols * td->tile_wid;
2174 rc.top = td->size_oh1;
2175 rc.bottom = rc.top + td->rows * td->tile_hgt;
2179 SetBkColor(hdc, RGB(0, 0, 0));
2180 SelectObject(hdc, td->font_id);
2181 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2186 rc.left = 0; rc.top = 0;
2189 ReleaseDC(td->w, hdc);
2197 * Hack -- make a noise
2199 static errr term_xtra_win_noise(void)
2201 MessageBeep(MB_ICONASTERISK);
2207 * Hack -- make a sound
2209 static errr term_xtra_win_sound(int v)
2214 #endif /* USE_SOUND */
2216 /* Sound disabled */
2217 if (!use_sound) return 1;
2220 if ((v < 0) || (v >= SOUND_MAX)) return 1;
2224 /* Count the samples */
2225 for (i = 0; i < SAMPLE_SOUND_MAX; i++)
2227 if (!sound_file[v][i])
2232 if (i == 0) return 1;
2234 /* Build the path */
2235 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2239 /* Play the sound, catch errors */
2240 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2244 /* Play the sound, catch errors */
2245 return (sndPlaySound(buf, SND_ASYNC));
2249 #else /* USE_SOUND */
2253 #endif /* USE_SOUND */
2257 * Hack -- play a music
2259 static errr term_xtra_win_music(int n, int v)
2264 #endif /* USE_MUSIC */
2266 /* Sound disabled */
2267 if (n == TERM_XTRA_MUSIC_MUTE)
2269 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2270 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2273 if (!use_music) return 1;
2276 if (n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return 1;
2277 else if (v < 0 || v >= 1000) return(1); /*!< TODO */
2283 case TERM_XTRA_MUSIC_BASIC:
2284 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!music_file[v][i]) break;
2286 case TERM_XTRA_MUSIC_DUNGEON:
2287 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!dungeon_music_file[v][i]) break;
2289 case TERM_XTRA_MUSIC_QUEST:
2290 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!quest_music_file[v][i]) break;
2292 case TERM_XTRA_MUSIC_TOWN:
2293 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!town_music_file[v][i]) break;
2305 case TERM_XTRA_MUSIC_BASIC:
2306 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2308 case TERM_XTRA_MUSIC_DUNGEON:
2309 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2311 case TERM_XTRA_MUSIC_QUEST:
2312 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2314 case TERM_XTRA_MUSIC_TOWN:
2315 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2319 if (current_music_type == n && current_music_id == v)
2323 current_music_type = n;
2324 current_music_id = v;
2328 mop.lpstrDeviceType = mci_device_type;
2329 mop.lpstrElementName = buf;
2330 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2331 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2332 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2333 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2334 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2339 #else /* USE_MUSIC */
2343 #endif /* USE_MUSIC */
2349 * Delay for "x" milliseconds
2351 static int term_xtra_win_delay(int v)
2365 t = GetTickCount() + v;
2368 while (GetTickCount() < t)
2370 /* Handle messages */
2371 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2373 TranslateMessage(&msg);
2374 DispatchMessage(&msg);
2386 * todo z-termに影響があるのでplayer_typeの追加は保留
2387 * Do a "special thing"
2389 static errr term_xtra_win(int n, int v)
2391 /* Handle a subset of the legal requests */
2394 /* Make a bell sound */
2395 case TERM_XTRA_NOISE:
2397 return (term_xtra_win_noise());
2401 case TERM_XTRA_MUSIC_BASIC:
2402 case TERM_XTRA_MUSIC_DUNGEON:
2403 case TERM_XTRA_MUSIC_QUEST:
2404 case TERM_XTRA_MUSIC_TOWN:
2406 return (term_xtra_win_music(n, v));
2409 /* Make a special sound */
2410 case TERM_XTRA_SOUND:
2412 return (term_xtra_win_sound(v));
2415 /* Process random events */
2416 case TERM_XTRA_BORED:
2418 return (term_xtra_win_event(0));
2421 /* Process an event */
2422 case TERM_XTRA_EVENT:
2424 return (term_xtra_win_event(v));
2427 /* Flush all events */
2428 case TERM_XTRA_FLUSH:
2430 return (term_xtra_win_flush());
2433 /* Clear the screen */
2434 case TERM_XTRA_CLEAR:
2436 return (term_xtra_win_clear());
2439 /* React to global changes */
2440 case TERM_XTRA_REACT:
2442 return (term_xtra_win_react(p_ptr));
2445 /* Delay for some milliseconds */
2446 case TERM_XTRA_DELAY:
2448 return (term_xtra_win_delay(v));
2458 * Low level graphics (Assumes valid input).
2460 * Draw a "cursor" at (x,y), using a "yellow box".
2462 static errr term_curs_win(int x, int y)
2464 term_data *td = (term_data*)(Term->data);
2469 int tile_wid, tile_hgt;
2473 tile_wid = td->map_tile_wid;
2474 tile_hgt = td->map_tile_hgt;
2478 tile_wid = td->tile_wid;
2479 tile_hgt = td->tile_hgt;
2482 /* Frame the grid */
2483 rc.left = x * tile_wid + td->size_ow1;
2484 rc.right = rc.left + tile_wid;
2485 rc.top = y * tile_hgt + td->size_oh1;
2486 rc.bottom = rc.top + tile_hgt;
2488 /* Cursor is done as a yellow "box" */
2490 FrameRect(hdc, &rc, hbrYellow);
2491 ReleaseDC(td->w, hdc);
2499 * Low level graphics (Assumes valid input).
2501 * Draw a "big cursor" at (x,y), using a "yellow box".
2503 static errr term_bigcurs_win(int x, int y)
2505 term_data *td = (term_data*)(Term->data);
2510 int tile_wid, tile_hgt;
2514 /* Normal cursor in map window */
2515 term_curs_win(x, y);
2520 tile_wid = td->tile_wid;
2521 tile_hgt = td->tile_hgt;
2524 /* Frame the grid */
2525 rc.left = x * tile_wid + td->size_ow1;
2526 rc.right = rc.left + 2 * tile_wid;
2527 rc.top = y * tile_hgt + td->size_oh1;
2528 rc.bottom = rc.top + tile_hgt;
2530 /* Cursor is done as a yellow "box" */
2532 FrameRect(hdc, &rc, hbrYellow);
2533 ReleaseDC(td->w, hdc);
2541 * Low level graphics (Assumes valid input).
2543 * Erase a "block" of "n" characters starting at (x,y).
2545 static errr term_wipe_win(int x, int y, int n)
2547 term_data *td = (term_data*)(Term->data);
2552 /* Rectangle to erase in client coords */
2553 rc.left = x * td->tile_wid + td->size_ow1;
2554 rc.right = rc.left + n * td->tile_wid;
2555 rc.top = y * td->tile_hgt + td->size_oh1;
2556 rc.bottom = rc.top + td->tile_hgt;
2559 SetBkColor(hdc, RGB(0, 0, 0));
2560 SelectObject(hdc, td->font_id);
2565 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2566 ReleaseDC(td->w, hdc);
2574 * Low level graphics. Assumes valid input.
2576 * Draw several ("n") chars, with an attr, at a given location.
2578 * All "graphic" data is handled by "term_pict_win()", below.
2580 * One would think there is a more efficient method for telling a window
2581 * what color it should be using to draw with, but perhaps simply changing
2582 * it every time is not too inefficient.
2584 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
2586 term_data *td = (term_data*)(Term->data);
2590 static HBITMAP WALL;
2591 static HBRUSH myBrush, oldBrush;
2593 static bool init_done = FALSE;
2596 WALL = LoadBitmap(hInstance, AppName);
2597 myBrush = CreatePatternBrush(WALL);
2601 /* Total rectangle */
2602 rc.left = x * td->tile_wid + td->size_ow1;
2603 rc.right = rc.left + n * td->tile_wid;
2604 rc.top = y * td->tile_hgt + td->size_oh1;
2605 rc.bottom = rc.top + td->tile_hgt;
2610 /* Background color */
2611 SetBkColor(hdc, RGB(0, 0, 0));
2613 /* Foreground color */
2616 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2620 SetTextColor(hdc, win_clr[a & 0x0F]);
2624 SetTextColor(hdc, win_clr[a]);
2628 SelectObject(hdc, td->font_id);
2631 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2635 (td->tile_hgt != td->font_hgt) ||
2636 (td->tile_wid != td->font_wid))
2640 /* Erase complete rectangle */
2641 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2644 if (use_bg) DrawBG(hdc, &rc);
2647 rc.left += ((td->tile_wid - td->font_wid) / 2);
2648 rc.right = rc.left + td->font_wid;
2649 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2650 rc.bottom = rc.top + td->font_hgt;
2652 /* Dump each character */
2653 for (i = 0; i < n; i++)
2656 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1])
2658 rc.right += td->font_wid;
2660 oldBrush = SelectObject(hdc, myBrush);
2661 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
2664 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2666 SelectObject(hdc, oldBrush);
2667 SelectObject(hdc, oldPen);
2668 rc.right -= td->font_wid;
2672 rc.left += 2 * td->tile_wid;
2673 rc.right += 2 * td->tile_wid;
2675 else if (iskanji(*(s + i))) /* 2バイト文字 */
2677 rc.right += td->font_wid;
2679 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2681 rc.right -= td->font_wid;
2685 rc.left += 2 * td->tile_wid;
2686 rc.right += 2 * td->tile_wid;
2688 else if (*(s + i) == 127) {
2689 oldBrush = SelectObject(hdc, myBrush);
2690 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
2693 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2695 SelectObject(hdc, oldBrush);
2696 SelectObject(hdc, oldPen);
2699 rc.left += td->tile_wid;
2700 rc.right += td->tile_wid;
2704 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
2707 rc.left += td->tile_wid;
2708 rc.right += td->tile_wid;
2711 if (*(s + i) == 127) {
2712 oldBrush = SelectObject(hdc, myBrush);
2713 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
2716 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2718 SelectObject(hdc, oldBrush);
2719 SelectObject(hdc, oldPen);
2722 rc.left += td->tile_wid;
2723 rc.right += td->tile_wid;
2727 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2731 rc.left += td->tile_wid;
2732 rc.right += td->tile_wid;
2743 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2748 ReleaseDC(td->w, hdc);
2756 * Low level graphics. Assumes valid input.
2758 * Draw an array of "special" attr/char pairs at the given location.
2760 * We use the "term_pict_win()" function for "graphic" data, which are
2761 * encoded by setting the "high-bits" of both the "attr" and the "char"
2762 * data. We use the "attr" to represent the "row" of the main bitmap,
2763 * and the "char" to represent the "col" of the main bitmap. The use
2764 * of this function is induced by the "higher_pict" flag.
2766 * If "graphics" is not available, we simply "wipe" the given grids.
2768 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)
2770 term_data *td = (term_data*)(Term->data);
2775 TERM_LEN x1, y1, w1, h1, tw1, th1;
2776 TERM_LEN x2, y2, w2, h2, tw2 = 0;
2786 /* Erase the grids */
2787 return (term_wipe_win(x, y, n));
2790 /* Size of bitmap cell */
2791 w1 = infGraph.CellWidth;
2792 h1 = infGraph.CellHeight;
2793 tw1 = infGraph.TileWidth;
2794 th1 = infGraph.TileHeight;
2796 /* Size of window cell */
2799 w2 = td->map_tile_wid;
2800 h2 = td->map_tile_hgt;
2809 if (use_bigtile) tw2 *= 2;
2812 /* Location of window cell */
2813 x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
2814 y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
2820 hdcSrc = CreateCompatibleDC(hdc);
2821 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2823 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2825 hdcMask = CreateCompatibleDC(hdc);
2826 SelectObject(hdcMask, infMask.hBitmap);
2829 /* Draw attr/char pairs */
2830 for (i = 0; i < n; i++, x2 += w2)
2832 TERM_COLOR a = ap[i];
2836 /* Extract picture */
2837 int row = (a & 0x7F);
2838 int col = (c & 0x7F);
2840 /* Location of bitmap cell */
2844 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2846 x3 = (tcp[i] & 0x7F) * w1;
2847 y3 = (tap[i] & 0x7F) * h1;
2848 tw2 = tw2 * w1 / tw1;
2852 if ((tw1 == tw2) && (th1 == h2))
2854 /* Copy the terrain picture from the bitmap to the window */
2855 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2857 /* Mask out the tile */
2858 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2861 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2864 /* Need to stretch */
2867 /* Set the correct mode for stretching the tiles */
2868 SetStretchBltMode(hdc, COLORONCOLOR);
2870 /* Copy the terrain picture from the bitmap to the window */
2871 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
2873 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
2875 /* Only draw if terrain and overlay are different */
2876 if ((x1 != x3) || (y1 != y3))
2878 /* Mask out the tile */
2879 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2882 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2889 if ((w1 == tw2) && (h1 == h2))
2891 /* Copy the picture from the bitmap to the window */
2892 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2895 /* Need to stretch */
2898 /* Set the correct mode for stretching the tiles */
2899 SetStretchBltMode(hdc, COLORONCOLOR);
2901 /* Copy the picture from the bitmap to the window */
2902 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2908 SelectObject(hdcSrc, hbmSrcOld);
2911 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2914 SelectObject(hdcMask, hbmSrcOld);
2919 ReleaseDC(td->w, hdc);
2921 #else /* USE_GRAPHICS */
2923 /* Just erase this grid */
2924 return (Term_wipe_win(x, y, n));
2926 #endif /* USE_GRAPHICS */
2933 static void windows_map(player_type *player_ptr)
2935 term_data *td = &data[0];
2938 TERM_LEN x, min_x, max_x;
2939 TERM_LEN y, min_y, max_y;
2944 /* Only in graphics mode */
2945 if (!use_graphics) return;
2946 term_xtra_win_clear();
2948 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2949 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2950 td->map_active = TRUE;
2955 max_x = player_ptr->current_floor_ptr->width;
2956 max_y = player_ptr->current_floor_ptr->height;
2960 for (x = min_x; x < max_x; x++)
2962 for (y = min_y; y < max_y; y++)
2964 map_info(player_ptr, y, x, &a, (char*)&c, &ta, (char*)&tc);
2966 /* Ignore non-graphics */
2967 if ((a & 0x80) && (c & 0x80))
2969 term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2974 /* Hilite the player */
2975 term_curs_win(player_ptr->x - min_x, player_ptr->y - min_y);
2977 /* Wait for a keypress, flush key buffer */
2978 Term_inkey(&c, TRUE, TRUE);
2981 /* Switch off the map display */
2982 td->map_active = FALSE;
2984 /* Restore screen */
2985 term_xtra_win_clear();
2990 /*** Other routines ***/
2994 * Create and initialize a "term_data" given a title
2996 static void term_data_link(term_data *td)
3000 /* Initialize the term */
3001 term_init(t, td->cols, td->rows, td->keys);
3003 /* Use a "software" cursor */
3004 t->soft_cursor = TRUE;
3006 /* Use "term_pict" for "graphic" data */
3007 t->higher_pict = TRUE;
3009 /* Erase with "white space" */
3010 t->attr_blank = TERM_WHITE;
3011 t->char_blank = ' ';
3013 /* Prepare the template hooks */
3014 t->user_hook = term_user_win;
3015 t->xtra_hook = term_xtra_win;
3016 t->curs_hook = term_curs_win;
3017 t->bigcurs_hook = term_bigcurs_win;
3018 t->wipe_hook = term_wipe_win;
3019 t->text_hook = term_text_win;
3020 t->pict_hook = term_pict_win;
3022 /* Remember where we came from */
3023 t->data = (vptr)(td);
3028 * Create the windows
3030 * First, instantiate the "default" values, then read the "ini_file"
3031 * to over-ride selected values, then create the windows, and fonts.
3033 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3034 * must make active to realize the palette.
3036 static void init_windows(void)
3044 WIPE(td, term_data);
3048 td->s = angband_term_name[0];
3064 for (i = 1; i < MAX_TERM_DATA; i++)
3067 WIPE(td, term_data);
3068 td->s = angband_term_name[i];
3072 td->visible = FALSE;
3077 td->pos_x = (7 - i) * 30;
3078 td->pos_y = (7 - i) * 20;
3086 /* Main window (need these before term_getsize gets called) */
3088 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3089 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3094 /* Sub windows (need these before term_getsize gets called) */
3095 for (i = 1; i < MAX_TERM_DATA; i++)
3098 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3099 td->dwExStyle = (WS_EX_TOOLWINDOW);
3104 for (i = 0; i < MAX_TERM_DATA; i++)
3108 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3109 td->lf.lfCharSet = DEFAULT_CHARSET;
3110 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3111 /* Activate the chosen font */
3112 term_force_font(td, NULL);
3113 if (!td->tile_wid) td->tile_wid = td->font_wid;
3114 if (!td->tile_hgt) td->tile_hgt = td->font_hgt;
3116 /* Analyze the font */
3119 /* Resize the window */
3120 term_window_resize(td);
3124 /* Sub windows (reverse order) */
3125 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3130 td->w = CreateWindowEx(td->dwExStyle, AngList,
3132 td->pos_x, td->pos_y,
3133 td->size_wid, td->size_hgt,
3134 HWND_DESKTOP, NULL, hInstance, NULL);
3136 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3140 td->size_hack = TRUE;
3141 ShowWindow(td->w, SW_SHOW);
3142 td->size_hack = FALSE;
3146 angband_term[i] = &td->t;
3150 /* Activate the window */
3151 SetActiveWindow(td->w);
3156 term_window_pos(&data[i], HWND_TOPMOST);
3160 term_window_pos(&data[i], td->w);
3170 td->w = CreateWindowEx(td->dwExStyle, AppName,
3172 td->pos_x, td->pos_y,
3173 td->size_wid, td->size_hgt,
3174 HWND_DESKTOP, NULL, hInstance, NULL);
3176 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3179 angband_term[0] = &td->t;
3180 normsize.x = td->cols;
3181 normsize.y = td->rows;
3183 /* Activate the main window */
3184 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3185 else ShowWindow(td->w, SW_SHOW);
3187 /* Bring main window back to top */
3188 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3192 (void)new_palette();
3195 /* Create a "brush" for drawing the "cursor" */
3196 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3199 /* Process pending messages */
3200 (void)term_xtra_win_flush();
3208 static void setup_menus(void)
3212 HMENU hm = GetMenu(data[0].w);
3215 /* Menu "File", Disable all */
3216 EnableMenuItem(hm, IDM_FILE_NEW,
3217 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3218 EnableMenuItem(hm, IDM_FILE_OPEN,
3219 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3220 EnableMenuItem(hm, IDM_FILE_SAVE,
3221 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3222 EnableMenuItem(hm, IDM_FILE_EXIT,
3223 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3224 EnableMenuItem(hm, IDM_FILE_SCORE,
3225 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3228 /* No character available */
3229 if (!current_world_ptr->character_generated)
3231 /* Menu "File", Item "New" */
3232 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3234 /* Menu "File", Item "Open" */
3235 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3238 /* A character available */
3239 if (current_world_ptr->character_generated)
3241 /* Menu "File", Item "Save" */
3242 EnableMenuItem(hm, IDM_FILE_SAVE,
3243 MF_BYCOMMAND | MF_ENABLED);
3246 /* Menu "File", Item "Exit" */
3247 EnableMenuItem(hm, IDM_FILE_EXIT,
3248 MF_BYCOMMAND | MF_ENABLED);
3250 EnableMenuItem(hm, IDM_FILE_SCORE,
3251 MF_BYCOMMAND | MF_ENABLED);
3254 /* Menu "Window::Visibility" */
3255 for (i = 0; i < MAX_TERM_DATA; i++)
3257 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3258 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3260 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3261 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3263 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3264 MF_BYCOMMAND | MF_ENABLED);
3267 /* Menu "Window::Font" */
3268 for (i = 0; i < MAX_TERM_DATA; i++)
3270 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3271 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3273 if (data[i].visible)
3275 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3276 MF_BYCOMMAND | MF_ENABLED);
3280 /* Menu "Window::Window Position Fix" */
3281 for (i = 0; i < MAX_TERM_DATA; i++)
3283 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3284 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3286 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3287 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3289 if (data[i].visible)
3291 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3292 MF_BYCOMMAND | MF_ENABLED);
3296 /* Menu "Window::Bizarre Display" */
3297 for (i = 0; i < MAX_TERM_DATA; i++)
3299 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3300 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3302 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3303 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3305 if (data[i].visible)
3307 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3308 MF_BYCOMMAND | MF_ENABLED);
3313 /* Menu "Window::Increase Tile Width" */
3314 for (i = 0; i < MAX_TERM_DATA; i++)
3316 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3317 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3319 if (data[i].visible)
3321 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3322 MF_BYCOMMAND | MF_ENABLED);
3327 /* Menu "Window::Decrease Tile Width" */
3328 for (i = 0; i < MAX_TERM_DATA; i++)
3330 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3331 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3333 if (data[i].visible)
3335 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3336 MF_BYCOMMAND | MF_ENABLED);
3341 /* Menu "Window::Increase Tile Height" */
3342 for (i = 0; i < MAX_TERM_DATA; i++)
3344 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3345 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3347 if (data[i].visible)
3349 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3350 MF_BYCOMMAND | MF_ENABLED);
3355 /* Menu "Window::Decrease Tile Height" */
3356 for (i = 0; i < MAX_TERM_DATA; i++)
3358 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3359 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3361 if (data[i].visible)
3363 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3364 MF_BYCOMMAND | MF_ENABLED);
3369 /* Menu "Options", disable all */
3370 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3371 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3372 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3373 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3374 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3375 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3376 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3377 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3378 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3379 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3383 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3384 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3387 /* Menu "Options", Item "Map" */
3388 if (use_graphics != GRAPHICS_NONE)
3389 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3391 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3392 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3394 /* Menu "Options", update all */
3395 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3396 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3397 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3398 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3399 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3400 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3401 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3402 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3403 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3404 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3405 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3406 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3407 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3408 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3409 CheckMenuItem(hm, IDM_OPTIONS_BG,
3410 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3414 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3415 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3419 /* Menu "Options", Item "Graphics" */
3420 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3421 /* Menu "Options", Item "Graphics" */
3422 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3423 /* Menu "Options", Item "Graphics" */
3424 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3425 /* Menu "Options", Item "Graphics" */
3426 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3427 #endif /* USE_GRAPHICS */
3430 /* Menu "Options", Item "Sound" */
3431 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3432 #endif /* USE_SOUND */
3435 /* Menu "Options", Item "ScreenSaver" */
3436 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3437 MF_BYCOMMAND | MF_ENABLED);
3438 #endif /* USE_SAVER */
3443 * Check for double clicked (or dragged) savefile
3445 * Apparently, Windows copies the entire filename into the first
3446 * piece of the "command line string". Perhaps we should extract
3447 * the "basename" of that filename and append it to the "save" dir.
3449 static void check_for_save_file(player_type *player_ptr, LPSTR cmd_line)
3459 /* Extract filename */
3460 strcat(savefile, s);
3462 /* Validate the file */
3463 validate_file(savefile);
3465 /* Game in progress */
3466 game_in_progress = TRUE;
3469 play_game(player_ptr, FALSE);
3474 * Process a menu command
3476 static void process_menus(player_type *player_ptr, WORD wCmd)
3492 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3494 else if (game_in_progress)
3496 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3500 game_in_progress = TRUE;
3502 play_game(player_ptr, TRUE);
3513 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3515 else if (game_in_progress)
3517 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3521 memset(&ofn, 0, sizeof(ofn));
3522 ofn.lStructSize = sizeof(ofn);
3523 ofn.hwndOwner = data[0].w;
3524 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3525 ofn.nFilterIndex = 1;
3526 ofn.lpstrFile = savefile;
3527 ofn.nMaxFile = 1024;
3528 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3529 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3531 if (GetOpenFileName(&ofn))
3533 /* Load 'savefile' */
3534 validate_file(savefile);
3535 game_in_progress = TRUE;
3537 play_game(player_ptr, FALSE);
3547 if (game_in_progress && current_world_ptr->character_generated)
3551 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3555 /* Hack -- Forget messages */
3559 do_cmd_save_game(player_ptr, FALSE);
3563 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3570 if (game_in_progress && current_world_ptr->character_generated)
3574 plog(_("今は終了できません。", "You may not do that right now."));
3578 /* Hack -- Forget messages */
3581 forget_lite(player_ptr->current_floor_ptr);
3582 forget_view(player_ptr->current_floor_ptr);
3583 clear_mon_lite(player_ptr->current_floor_ptr);
3585 Term_key_push(SPECIAL_KEY_QUIT);
3593 case IDM_FILE_SCORE:
3596 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3598 /* Open the binary high score file, for reading */
3599 highscore_fd = fd_open(buf, O_RDONLY);
3601 /* Paranoia -- No score file */
3602 if (highscore_fd < 0)
3604 msg_print("Score file unavailable.");
3611 /* Display the scores */
3612 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3614 /* Shut the high score file */
3615 (void)fd_close(highscore_fd);
3617 /* Forget the high score fd */
3621 /* Hack - Flush it */
3629 case IDM_FILE_MOVIE:
3633 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3635 else if (game_in_progress)
3637 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
3641 memset(&ofn, 0, sizeof(ofn));
3642 ofn.lStructSize = sizeof(ofn);
3643 ofn.hwndOwner = data[0].w;
3644 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3645 ofn.nFilterIndex = 1;
3646 ofn.lpstrFile = savefile;
3647 ofn.nMaxFile = 1024;
3648 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3649 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3651 if (GetOpenFileName(&ofn))
3653 /* Load 'savefile' */
3654 prepare_browse_movie_aux(savefile);
3655 play_game(player_ptr, FALSE);
3664 case IDM_WINDOW_VIS_0:
3666 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
3670 /* Window visibility */
3671 case IDM_WINDOW_VIS_1:
3672 case IDM_WINDOW_VIS_2:
3673 case IDM_WINDOW_VIS_3:
3674 case IDM_WINDOW_VIS_4:
3675 case IDM_WINDOW_VIS_5:
3676 case IDM_WINDOW_VIS_6:
3677 case IDM_WINDOW_VIS_7:
3679 i = wCmd - IDM_WINDOW_VIS_0;
3681 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3688 ShowWindow(td->w, SW_SHOW);
3689 term_data_redraw(player_ptr, td);
3693 td->visible = FALSE;
3695 ShowWindow(td->w, SW_HIDE);
3702 case IDM_WINDOW_FONT_0:
3703 case IDM_WINDOW_FONT_1:
3704 case IDM_WINDOW_FONT_2:
3705 case IDM_WINDOW_FONT_3:
3706 case IDM_WINDOW_FONT_4:
3707 case IDM_WINDOW_FONT_5:
3708 case IDM_WINDOW_FONT_6:
3709 case IDM_WINDOW_FONT_7:
3711 i = wCmd - IDM_WINDOW_FONT_0;
3713 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3717 term_change_font(td);
3722 /* Window Z Position */
3723 case IDM_WINDOW_POS_1:
3724 case IDM_WINDOW_POS_2:
3725 case IDM_WINDOW_POS_3:
3726 case IDM_WINDOW_POS_4:
3727 case IDM_WINDOW_POS_5:
3728 case IDM_WINDOW_POS_6:
3729 case IDM_WINDOW_POS_7:
3731 i = wCmd - IDM_WINDOW_POS_0;
3733 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3737 if (!td->posfix && td->visible)
3740 term_window_pos(td, HWND_TOPMOST);
3745 term_window_pos(td, data[0].w);
3751 /* Bizarre Display */
3752 case IDM_WINDOW_BIZ_0:
3753 case IDM_WINDOW_BIZ_1:
3754 case IDM_WINDOW_BIZ_2:
3755 case IDM_WINDOW_BIZ_3:
3756 case IDM_WINDOW_BIZ_4:
3757 case IDM_WINDOW_BIZ_5:
3758 case IDM_WINDOW_BIZ_6:
3759 case IDM_WINDOW_BIZ_7:
3761 i = wCmd - IDM_WINDOW_BIZ_0;
3763 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3767 td->bizarre = !td->bizarre;
3771 term_window_resize(td);
3776 /* Increase Tile Width */
3777 case IDM_WINDOW_I_WID_0:
3778 case IDM_WINDOW_I_WID_1:
3779 case IDM_WINDOW_I_WID_2:
3780 case IDM_WINDOW_I_WID_3:
3781 case IDM_WINDOW_I_WID_4:
3782 case IDM_WINDOW_I_WID_5:
3783 case IDM_WINDOW_I_WID_6:
3784 case IDM_WINDOW_I_WID_7:
3786 i = wCmd - IDM_WINDOW_I_WID_0;
3788 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3796 term_window_resize(td);
3801 /* Decrease Tile Height */
3802 case IDM_WINDOW_D_WID_0:
3803 case IDM_WINDOW_D_WID_1:
3804 case IDM_WINDOW_D_WID_2:
3805 case IDM_WINDOW_D_WID_3:
3806 case IDM_WINDOW_D_WID_4:
3807 case IDM_WINDOW_D_WID_5:
3808 case IDM_WINDOW_D_WID_6:
3809 case IDM_WINDOW_D_WID_7:
3811 i = wCmd - IDM_WINDOW_D_WID_0;
3813 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3821 term_window_resize(td);
3826 /* Increase Tile Height */
3827 case IDM_WINDOW_I_HGT_0:
3828 case IDM_WINDOW_I_HGT_1:
3829 case IDM_WINDOW_I_HGT_2:
3830 case IDM_WINDOW_I_HGT_3:
3831 case IDM_WINDOW_I_HGT_4:
3832 case IDM_WINDOW_I_HGT_5:
3833 case IDM_WINDOW_I_HGT_6:
3834 case IDM_WINDOW_I_HGT_7:
3836 i = wCmd - IDM_WINDOW_I_HGT_0;
3838 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3846 term_window_resize(td);
3851 /* Decrease Tile Height */
3852 case IDM_WINDOW_D_HGT_0:
3853 case IDM_WINDOW_D_HGT_1:
3854 case IDM_WINDOW_D_HGT_2:
3855 case IDM_WINDOW_D_HGT_3:
3856 case IDM_WINDOW_D_HGT_4:
3857 case IDM_WINDOW_D_HGT_5:
3858 case IDM_WINDOW_D_HGT_6:
3859 case IDM_WINDOW_D_HGT_7:
3861 i = wCmd - IDM_WINDOW_D_HGT_0;
3863 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3871 term_window_resize(td);
3876 case IDM_OPTIONS_NO_GRAPHICS:
3880 plog("You may not do that right now.");
3884 if (arg_graphics != GRAPHICS_NONE)
3886 arg_graphics = GRAPHICS_NONE;
3887 term_xtra_win_react(player_ptr);
3888 Term_key_push(KTRL('R'));
3894 case IDM_OPTIONS_OLD_GRAPHICS:
3898 plog("You may not do that right now.");
3902 if (arg_graphics != GRAPHICS_ORIGINAL)
3904 arg_graphics = GRAPHICS_ORIGINAL;
3905 term_xtra_win_react(player_ptr);
3906 Term_key_push(KTRL('R'));
3912 case IDM_OPTIONS_NEW_GRAPHICS:
3916 plog("You may not do that right now.");
3920 if (arg_graphics != GRAPHICS_ADAM_BOLT)
3922 arg_graphics = GRAPHICS_ADAM_BOLT;
3923 term_xtra_win_react(player_ptr);
3924 Term_key_push(KTRL('R'));
3930 case IDM_OPTIONS_NEW2_GRAPHICS:
3934 plog("You may not do that right now.");
3938 if (arg_graphics != GRAPHICS_HENGBAND)
3940 arg_graphics = GRAPHICS_HENGBAND;
3941 term_xtra_win_react(player_ptr);
3942 Term_key_push(KTRL('R'));
3948 case IDM_OPTIONS_BIGTILE:
3953 plog("You may not do that right now.");
3957 arg_bigtile = !arg_bigtile;
3958 Term_activate(&td->t);
3959 Term_resize(td->cols, td->rows);
3960 InvalidateRect(td->w, NULL, TRUE);
3964 case IDM_OPTIONS_MUSIC:
3968 plog("You may not do that right now.");
3972 arg_music = !arg_music;
3973 term_xtra_win_react(player_ptr);
3974 Term_key_push(KTRL('R'));
3978 case IDM_OPTIONS_SOUND:
3982 plog("You may not do that right now.");
3986 arg_sound = !arg_sound;
3987 term_xtra_win_react(player_ptr);
3988 Term_key_push(KTRL('R'));
3993 case IDM_OPTIONS_BG:
3997 plog("You may not do that right now.");
4003 term_xtra_win_react(player_ptr);
4004 Term_key_push(KTRL('R'));
4009 case IDM_OPTIONS_OPEN_BG:
4013 plog("You may not do that right now.");
4018 memset(&ofn, 0, sizeof(ofn));
4019 ofn.lStructSize = sizeof(ofn);
4020 ofn.hwndOwner = data[0].w;
4021 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4022 ofn.nFilterIndex = 1;
4023 ofn.lpstrFile = bg_bitmap_file;
4024 ofn.nMaxFile = 1023;
4025 ofn.lpstrInitialDir = NULL;
4026 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
4027 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4029 if (GetOpenFileName(&ofn))
4031 /* Load 'savefile' */
4036 /* React to changes */
4037 term_xtra_win_react(player_ptr);
4039 /* Hack -- Force redraw */
4040 Term_key_push(KTRL('R'));
4045 case IDM_DUMP_SCREEN_HTML:
4047 static char buf[1024] = "";
4048 memset(&ofn, 0, sizeof(ofn));
4049 ofn.lStructSize = sizeof(ofn);
4050 ofn.hwndOwner = data[0].w;
4051 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4052 ofn.nFilterIndex = 1;
4053 ofn.lpstrFile = buf;
4054 ofn.nMaxFile = 1023;
4055 ofn.lpstrDefExt = "html";
4056 ofn.lpstrInitialDir = NULL;
4057 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
4058 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4060 if (GetSaveFileName(&ofn))
4062 do_cmd_save_screen_html_aux(buf, 0);
4069 case IDM_OPTIONS_SAVER:
4073 DestroyWindow(hwndSaver);
4078 /* Create a screen scaver window */
4079 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4080 "Angband Screensaver",
4081 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4082 0, 0, GetSystemMetrics(SM_CXSCREEN),
4083 GetSystemMetrics(SM_CYSCREEN),
4084 NULL, NULL, hInstance, NULL);
4088 /* Push the window to the bottom */
4089 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4093 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
4101 case IDM_OPTIONS_MAP:
4103 windows_map(player_ptr);
4107 case IDM_HELP_CONTENTS:
4111 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4112 if (check_file(tmp))
4114 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4118 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4119 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4122 #else /* HTML_HELP */
4125 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4126 if (check_file(tmp))
4128 sprintf(buf, "winhelp.exe %s", tmp);
4129 WinExec(buf, SW_NORMAL);
4133 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4134 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4138 #endif /* HTML_HELP */
4144 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4151 /* Extract the modifiers */
4152 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4153 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4154 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4156 term_no_press = (ma) ? TRUE : FALSE;
4158 /* Handle "special" keys */
4159 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]))
4161 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4162 bool numpad = FALSE;
4164 /* Begin the macro trigger */
4167 /* Send the modifiers */
4168 if (mc) Term_keypress('C');
4169 if (ms) Term_keypress('S');
4170 if (ma) Term_keypress('A');
4172 /* Extract "scan code" */
4173 i = LOBYTE(HIWORD(lParam));
4175 /* Introduce the scan code */
4178 /* Extended key bit */
4181 /* Numpad Enter and '/' are extended key */
4183 term_no_press = TRUE;
4184 case VK_RETURN: /* Enter */
4187 /* Other extended keys are on full keyboard */
4203 term_no_press = TRUE;
4207 case VK_PRIOR: /* Page Up */
4208 case VK_NEXT: /* Page Down */
4218 /* Special modifiers for keypad keys */
4219 if (numpad) Term_keypress('K');
4221 /* Encode the hexidecimal scan code */
4222 Term_keypress(hexsym[i / 16]);
4223 Term_keypress(hexsym[i % 16]);
4225 /* End the macro trigger */
4236 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
4239 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4240 WPARAM wParam, LPARAM lParam);
4241 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4242 WPARAM wParam, LPARAM lParam)
4243 #else /* __MWERKS__ */
4244 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4245 #endif /* __MWERKS__ */
4253 /* Acquire proper "term_data" info */
4254 td = (term_data *)GetWindowLong(hWnd, 0);
4256 /* Handle message */
4261 SetWindowLong(hWnd, 0, (LONG)(my_td));
4268 mop.dwCallback = (DWORD)hWnd;
4273 case WM_GETMINMAXINFO:
4275 MINMAXINFO FAR *lpmmi;
4278 lpmmi = (MINMAXINFO FAR *)lParam;
4280 /* this message was sent before WM_NCCREATE */
4283 /* Minimum window size is 80x24 */
4284 rc.left = rc.top = 0;
4285 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4286 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4289 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4291 /* Save minimum size */
4292 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4293 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4300 BeginPaint(hWnd, &ps);
4301 if (td) term_data_redraw(p_ptr, td);
4302 EndPaint(hWnd, &ps);
4303 ValidateRect(hWnd, NULL);
4310 if (wParam == MCI_NOTIFY_SUCCESSFUL)
4312 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4313 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4322 if (process_keydown(wParam, lParam))
4329 if (term_no_press) term_no_press = FALSE;
4330 else Term_keypress(wParam);
4334 case WM_LBUTTONDOWN:
4336 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4337 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4349 TERM_LEN dx = abs(oldx - mousex) + 1;
4350 TERM_LEN dy = abs(oldy - mousey) + 1;
4351 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
4352 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
4362 hGlobal = GlobalAlloc(GHND, sz + 1);
4363 if (hGlobal == NULL) return 0;
4364 lpStr = (LPSTR)GlobalLock(hGlobal);
4366 for (i = 0; i < dy; i++)
4370 char **scr = data[0].t.scr->c;
4372 C_MAKE(s, (dx + 1), char);
4373 strncpy(s, &scr[oy + i][ox], dx);
4377 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4380 if (ox + dx < data[0].cols)
4382 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4385 for (j = 0; j < dx; j++)
4387 if (s[j] == 127) s[j] = '#';
4391 for (j = 0; j < dx; j++)
4393 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4403 GlobalUnlock(hGlobal);
4404 if (OpenClipboard(hWnd) == 0)
4406 GlobalFree(hGlobal);
4410 SetClipboardData(CF_TEXT, hGlobal);
4423 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4424 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4429 dx = abs(oldx - mousex) + 1;
4430 dy = abs(oldy - mousey) + 1;
4431 ox = (oldx > mousex) ? mousex : oldx;
4432 oy = (oldy > mousey) ? mousey : oldy;
4433 term_inversed_area(hWnd, ox, oy, dx, dy);
4440 dx = abs(cx - mousex) + 1;
4441 dy = abs(cy - mousey) + 1;
4442 ox = (cx > mousex) ? mousex : cx;
4443 oy = (cy > mousey) ? mousey : cy;
4444 term_inversed_area(hWnd, ox, oy, dx, dy);
4460 if (game_in_progress && current_world_ptr->character_generated)
4464 plog(_("今は終了できません。", "You may not do that right now."));
4468 /* Hack -- Forget messages */
4471 forget_lite(p_ptr->current_floor_ptr);
4472 forget_view(p_ptr->current_floor_ptr);
4473 clear_mon_lite(p_ptr->current_floor_ptr);
4475 Term_key_push(SPECIAL_KEY_QUIT);
4482 case WM_QUERYENDSESSION:
4484 if (game_in_progress && current_world_ptr->character_generated)
4486 /* Hack -- Forget messages */
4489 /* Mega-Hack -- Delay death */
4490 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4491 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4493 /* Hardcode panic save */
4494 p_ptr->panic_save = 1;
4496 /* Forbid suspend */
4497 signals_ignore_tstp();
4499 /* Indicate panic save */
4500 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4503 (void)save_player(p_ptr);
4517 process_menus(p_ptr, LOWORD(wParam));
4523 /* this message was sent before WM_NCCREATE */
4526 /* it was sent from inside CreateWindowEx */
4527 if (!td->w) return 1;
4529 /* was sent from WM_SIZE */
4530 if (td->size_hack) return 1;
4534 case SIZE_MINIMIZED:
4536 /* Hide sub-windows */
4537 for (i = 1; i < MAX_TERM_DATA; i++)
4539 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4544 case SIZE_MAXIMIZED:
4551 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4552 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4555 if ((td->cols != cols) || (td->rows != rows))
4557 /* Save the new size */
4561 if (!IsZoomed(td->w) && !IsIconic(td->w))
4563 normsize.x = td->cols;
4564 normsize.y = td->rows;
4568 Term_activate(&td->t);
4570 /* Resize the term */
4571 Term_resize(td->cols, td->rows);
4574 InvalidateRect(td->w, NULL, TRUE);
4577 td->size_hack = TRUE;
4579 /* Show sub-windows */
4580 for (i = 1; i < MAX_TERM_DATA; i++)
4582 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4585 td->size_hack = FALSE;
4593 case WM_PALETTECHANGED:
4595 /* Ignore if palette change caused by itself */
4596 if ((HWND)wParam == hWnd) return 0;
4598 /* Fall through... */
4601 case WM_QUERYNEWPALETTE:
4603 if (!paletted) return 0;
4607 SelectPalette(hdc, hPal, FALSE);
4609 i = RealizePalette(hdc);
4611 /* if any palette entries changed, repaint the window. */
4612 if (i) InvalidateRect(hWnd, NULL, TRUE);
4614 ReleaseDC(hWnd, hdc);
4621 if (wParam && !HIWORD(lParam))
4623 /* Do something to sub-windows */
4624 for (i = 1; i < MAX_TERM_DATA; i++)
4626 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4629 /* Focus on main window */
4638 case WM_ACTIVATEAPP:
4640 if (IsIconic(td->w)) break;
4642 for (i = 1; i < MAX_TERM_DATA; i++)
4644 if (data[i].visible)
4648 ShowWindow(data[i].w, SW_SHOW);
4652 ShowWindow(data[i].w, SW_HIDE);
4659 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4664 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
4667 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4668 WPARAM wParam, LPARAM lParam);
4669 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4670 WPARAM wParam, LPARAM lParam)
4671 #else /* __MWERKS__ */
4672 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4673 WPARAM wParam, LPARAM lParam)
4674 #endif /* __MWERKS__ */
4682 /* Acquire proper "term_data" info */
4683 td = (term_data *)GetWindowLong(hWnd, 0);
4685 /* Process message */
4690 SetWindowLong(hWnd, 0, (LONG)(my_td));
4699 case WM_GETMINMAXINFO:
4701 MINMAXINFO FAR *lpmmi;
4704 lpmmi = (MINMAXINFO FAR *)lParam;
4706 /* this message was sent before WM_NCCREATE */
4709 /* Minimum window size is 80x24 */
4710 rc.left = rc.top = 0;
4711 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4712 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4715 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4717 /* Save minimum size */
4718 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4719 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4729 /* this message was sent before WM_NCCREATE */
4732 /* it was sent from inside CreateWindowEx */
4733 if (!td->w) return 1;
4735 /* was sent from inside WM_SIZE */
4736 if (td->size_hack) return 1;
4738 td->size_hack = TRUE;
4740 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4741 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4744 if ((td->cols != cols) || (td->rows != rows))
4747 term *old_term = Term;
4749 /* Save the new size */
4754 Term_activate(&td->t);
4756 /* Resize the term */
4757 Term_resize(td->cols, td->rows);
4760 Term_activate(old_term);
4763 InvalidateRect(td->w, NULL, TRUE);
4765 /* HACK - Redraw all windows */
4766 p_ptr->window = 0xFFFFFFFF;
4767 handle_stuff(p_ptr);
4770 td->size_hack = FALSE;
4777 BeginPaint(hWnd, &ps);
4778 if (td) term_data_redraw(p_ptr, td);
4779 EndPaint(hWnd, &ps);
4786 if (process_keydown(wParam, lParam))
4793 if (term_no_press) term_no_press = FALSE;
4794 else Term_keypress(wParam);
4798 case WM_PALETTECHANGED:
4800 /* ignore if palette change caused by itself */
4801 if ((HWND)wParam == hWnd) return FALSE;
4802 /* otherwise, fall through!!! */
4805 case WM_QUERYNEWPALETTE:
4807 if (!paletted) return 0;
4809 SelectPalette(hdc, hPal, FALSE);
4810 i = RealizePalette(hdc);
4811 /* if any palette entries changed, repaint the window. */
4812 if (i) InvalidateRect(hWnd, NULL, TRUE);
4813 ReleaseDC(hWnd, hdc);
4817 case WM_NCLBUTTONDOWN:
4821 if (wParam == HTCLOSE) wParam = HTSYSMENU;
4822 #endif /* HTCLOSE */
4824 if (wParam == HTSYSMENU)
4828 td->visible = FALSE;
4829 ShowWindow(td->w, SW_HIDE);
4839 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4845 #define MOUSE_SENS 40
4848 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4849 WPARAM wParam, LPARAM lParam);
4850 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4851 WPARAM wParam, LPARAM lParam)
4852 #else /* __MWERKS__ */
4853 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4854 WPARAM wParam, LPARAM lParam)
4855 #endif /* __MWERKS__ */
4857 static int iMouse = 0;
4858 static WORD xMouse = 0;
4859 static WORD yMouse = 0;
4878 case WM_LBUTTONDOWN:
4879 case WM_MBUTTONDOWN:
4880 case WM_RBUTTONDOWN:
4883 SendMessage(hWnd, WM_CLOSE, 0, 0);
4891 dx = LOWORD(lParam) - xMouse;
4892 dy = HIWORD(lParam) - yMouse;
4894 if (dx < 0) dx = -dx;
4895 if (dy < 0) dy = -dy;
4897 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
4899 SendMessage(hWnd, WM_CLOSE, 0, 0);
4903 /* Save last location */
4905 xMouse = LOWORD(lParam);
4906 yMouse = HIWORD(lParam);
4913 DestroyWindow(hwndSaver);
4919 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4922 #endif /* USE_SAVER */
4928 /*** Temporary Hooks ***/
4932 * Display warning message (see "z-util.c")
4934 static void hack_plog(concptr str)
4936 /* Give a warning */
4940 MessageBox(NULL, str, "警告!",
4941 MB_ICONEXCLAMATION | MB_OK);
4943 MessageBox(NULL, str, "Warning",
4944 MB_ICONEXCLAMATION | MB_OK);
4952 * Display error message and quit (see "z-util.c")
4954 static void hack_quit(concptr str)
4956 /* Give a warning */
4960 MessageBox(NULL, str, "エラー!",
4961 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4963 MessageBox(NULL, str, "Error",
4964 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4969 /* Unregister the classes */
4970 UnregisterClass(AppName, hInstance);
4972 /* Destroy the icon */
4973 if (hIcon) DestroyIcon(hIcon);
4980 /*** Various hooks ***/
4984 * Display warning message (see "z-util.c")
4986 static void hook_plog(concptr str)
4992 MessageBox(data[0].w, str, "警告!",
4993 MB_ICONEXCLAMATION | MB_OK);
4995 MessageBox(data[0].w, str, "Warning",
4996 MB_ICONEXCLAMATION | MB_OK);
5004 * Display error message and quit (see "z-util.c")
5006 static void hook_quit(concptr str)
5011 /* Give a warning */
5015 MessageBox(data[0].w, str, "エラー!",
5016 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5018 MessageBox(data[0].w, str, "Error",
5019 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5025 /* Save the preferences */
5028 /* Destroy all windows */
5029 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5031 term_force_font(&data[i], NULL);
5032 if (data[i].font_want) string_free(data[i].font_want);
5033 if (data[i].w) DestroyWindow(data[i].w);
5037 /* Free the bitmap stuff */
5039 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5040 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5042 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5043 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5045 #endif /* USE_GRAPHICS */
5047 /*** Free some other stuff ***/
5049 DeleteObject(hbrYellow);
5054 if (hPal) DeleteObject(hPal);
5056 UnregisterClass(AppName, hInstance);
5058 if (hIcon) DestroyIcon(hIcon);
5065 /*** Initialize ***/
5071 static void init_stuff(void)
5078 /* Get program name with full path */
5079 GetModuleFileName(hInstance, path, 512);
5081 /* Save the "program name" */
5084 /* Get the name of the "*.ini" file */
5085 strcpy(path + strlen(path) - 4, ".INI");
5087 /* Save the the name of the ini-file */
5088 ini_file = string_make(path);
5090 /* Analyze the path */
5096 if (path[i] == '\\')
5103 /* Add "lib" to the path */
5104 strcpy(path + i + 1, "lib\\");
5106 /* Validate the path */
5107 validate_dir(path, TRUE);
5109 /* Init the file paths */
5110 init_file_paths(path);
5112 /* Hack -- Validate the paths */
5113 validate_dir(ANGBAND_DIR_APEX, FALSE);
5114 validate_dir(ANGBAND_DIR_BONE, FALSE);
5116 /* Allow missing 'edit' directory */
5117 if (!check_dir(ANGBAND_DIR_EDIT))
5119 /* Must have 'data'! */
5120 validate_dir(ANGBAND_DIR_DATA, TRUE);
5124 /* Don't need 'data' */
5125 validate_dir(ANGBAND_DIR_DATA, FALSE);
5128 validate_dir(ANGBAND_DIR_FILE, TRUE);
5129 validate_dir(ANGBAND_DIR_HELP, FALSE);
5130 validate_dir(ANGBAND_DIR_INFO, FALSE);
5131 validate_dir(ANGBAND_DIR_PREF, TRUE);
5132 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5133 validate_dir(ANGBAND_DIR_USER, TRUE);
5134 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5135 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
5137 /* Hack -- Validate the "news.txt" file */
5138 validate_file(path);
5142 /* Build the "graf" path */
5143 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5145 /* Allocate the path */
5146 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5148 /* Validate the "graf" directory */
5149 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5151 #endif /* USE_GRAPHICS */
5156 /* Build the "sound" path */
5157 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5159 /* Allocate the path */
5160 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5162 /* Validate the "sound" directory */
5163 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5165 #endif /* USE_SOUND */
5169 /* Build the "music" path */
5170 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5172 /* Allocate the path */
5173 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5175 /* Validate the "music" directory */
5176 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5178 #endif /* USE_MUSIC */
5180 /* Build the "help" path */
5181 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5183 /* Allocate the path */
5184 ANGBAND_DIR_XTRA_HELP = string_make(path);
5186 /* Validate the "help" directory */
5187 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5191 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
5193 static bool is_already_running(void)
5195 bool result = FALSE;
5198 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5199 if (GetLastError() == ERROR_ALREADY_EXISTS)
5208 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
5210 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5211 LPSTR lpCmdLine, int nCmdShow)
5219 setlocale(LC_ALL, "ja_JP.utf8");
5228 /* Prevent multiple run */
5229 if (is_already_running())
5232 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
5234 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5238 if (hPrevInst == NULL)
5240 wc.style = CS_CLASSDC;
5241 wc.lpfnWndProc = AngbandWndProc;
5243 wc.cbWndExtra = 4; /* one long pointer to term_data */
5244 wc.hInstance = hInst;
5245 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5246 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5247 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5248 wc.lpszMenuName = AppName;
5249 wc.lpszClassName = AppName;
5251 if (!RegisterClass(&wc)) exit(1);
5253 wc.lpfnWndProc = AngbandListProc;
5254 wc.lpszMenuName = NULL;
5255 wc.lpszClassName = AngList;
5257 if (!RegisterClass(&wc)) exit(2);
5261 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5262 wc.lpfnWndProc = AngbandSaverProc;
5264 wc.lpszMenuName = NULL;
5265 wc.lpszClassName = "WindowsScreenSaverClass";
5267 if (!RegisterClass(&wc)) exit(3);
5273 /* Temporary hooks */
5274 plog_aux = hack_plog;
5275 quit_aux = hack_quit;
5276 core_aux = hack_quit;
5278 /* Prepare the filepaths */
5281 /* Initialize the keypress analyzer */
5282 for (i = 0; special_key_list[i]; ++i)
5284 special_key[special_key_list[i]] = TRUE;
5286 /* Initialize the keypress analyzer */
5287 for (i = 0; ignore_key_list[i]; ++i)
5289 ignore_key[ignore_key_list[i]] = TRUE;
5292 /* Determine if display is 16/256/true color */
5294 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5295 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5296 ReleaseDC(NULL, hdc);
5298 /* Initialize the colors */
5299 for (i = 0; i < 256; i++)
5303 /* Extract desired values */
5304 rv = angband_color_table[i][1];
5305 gv = angband_color_table[i][2];
5306 bv = angband_color_table[i][3];
5308 /* Extract the "complex" code */
5309 win_clr[i] = PALETTERGB(rv, gv, bv);
5311 /* Save the "simple" code */
5312 angband_color_table[i][0] = win_pal[i];
5315 /* Prepare the windows */
5321 /* Activate hooks */
5322 plog_aux = hook_plog;
5323 quit_aux = hook_quit;
5324 core_aux = hook_quit;
5326 /* Set the system suffix */
5327 ANGBAND_SYS = "win";
5329 /* Set the keyboard suffix */
5330 if (7 != GetKeyboardType(0))
5331 ANGBAND_KEYBOARD = "0";
5334 /* Japanese keyboard */
5335 switch (GetKeyboardType(1))
5337 case 0x0D01: case 0x0D02:
5338 case 0x0D03: case 0x0D04:
5339 case 0x0D05: case 0x0D06:
5341 ANGBAND_KEYBOARD = "NEC98";
5345 ANGBAND_KEYBOARD = "JAPAN";
5349 /* Catch nasty signals */
5352 Term_activate(term_screen);
5353 init_angband(p_ptr);
5355 /* We are now initialized */
5358 if (lpCmdLine[0] == '-') {
5359 switch (lpCmdLine[1])
5364 if (!lpCmdLine[2]) break;
5365 chuukei_server = TRUE;
5366 if (connect_chuukei_server(&lpCmdLine[2]) < 0) {
5367 msg_print("connect fail");
5370 msg_print("connect");
5378 if (!lpCmdLine[2]) break;
5379 chuukei_client = TRUE;
5380 connect_chuukei_server(&lpCmdLine[2]);
5381 play_game(player_ptr, FALSE);
5388 if (!lpCmdLine[2]) break;
5389 prepare_browse_movie(&lpCmdLine[2]);
5390 play_game(player_ptr, FALSE);
5399 /* Did the user double click on a save file? */
5400 if (!chuukei_server) check_for_save_file(lpCmdLine);
5402 /* Did the user double click on a save file? */
5403 check_for_save_file(p_ptr, lpCmdLine);
5406 /* Prompt the user */
5407 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
5411 /* Process messages forever */
5412 while (GetMessage(&msg, NULL, 0, 0))
5414 TranslateMessage(&msg);
5415 DispatchMessage(&msg);
5422 #endif /* WINDOWS */