3 * @brief Windows版固有実装(メインエントリポイント含む)
5 * @author Hengband Team
9 * Windows98かその前後の頃を起点としたAPI実装。
11 * DirectXといった昨今描画に標準的となったライブラリも用いていない。
12 * タイルの描画処理などについては、現在動作の詳細を検証中。
16 * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
18 * This software may be copied and distributed for educational, research,
19 * and not for profit purposes provided that this copyright and statement
20 * are included in all such copies.
23 * This file helps Angband work with Windows computers.
25 * To use this file, use an appropriate "Makefile" or "Project File",
26 * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
27 * make sure to obtain various extra files as described below.
29 * The official compilation uses the CodeWarrior Pro compiler, which
30 * includes a special project file and precompilable header file.
34 * <del>See also "main-dos.c" and "main-ibm.c".</del>
38 * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
39 * and/or color redefinitions.
43 * The "lib/user/font-win.prf" contains attr/char mappings for use with the
44 * normal "lib/xtra/font/*.fon" font files.
48 * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
49 * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
54 * Compiling this file, and using the resulting executable, requires
55 * several extra files not distributed with the standard Angband code.
56 * If "USE_GRAPHICS" is defined, then "readdib.h" and "readdib.c" must
57 * be placed into "src/", and the "8X8.BMP" bitmap file must be placed
58 * into "lib/xtra/graf". In any case, some "*.fon" files (including
59 * "8X13.FON" if nothing else) must be placed into "lib/xtra/font/".
60 * If "USE_SOUND" is defined, then some special library (for example,
61 * "winmm.lib") may need to be linked in, and desired "*.WAV" sound
62 * files must be placed into "lib/xtra/sound/". All of these extra
63 * files can be found in the "ext-win" archive.
67 * The "Term_xtra_win_clear()" function should probably do a low-level
68 * clear of the current window, and redraw the borders and other things,
69 * if only for efficiency.
73 * A simpler method is needed for selecting the "tile size" for windows.
77 * The various "warning" messages assume the existance of the "screen.w"
78 * window, I think, and only a few calls actually check for its existance,
79 * this may be okay since "NULL" means "on top of all windows". (?) The
80 * user must never be allowed to "hide" the main window, or the "menubar"
85 * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
86 * use with the "winhelp.exe" program. These files *may* be available
87 * at the ftp site somewhere, but I have not seen them.
91 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
93 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
95 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
96 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
104 #include "cmd-dump.h"
105 #include "view-mainwindow.h"
107 #include "floor-events.h"
126 * Extract the "WIN32" flag from the compiler
128 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
135 * Available graphic modes
137 #define GRAPHICS_NONE 0
138 #define GRAPHICS_ORIGINAL 1
139 #define GRAPHICS_ADAM_BOLT 2
140 #define GRAPHICS_HENGBAND 3
143 * Hack -- allow use of "screen saver" mode
149 * Menu constants -- see "ANGBAND.RC"
152 #define IDM_FILE_NEW 100
153 #define IDM_FILE_OPEN 101
154 #define IDM_FILE_SAVE 110
155 #define IDM_FILE_SCORE 120
156 #define IDM_FILE_MOVIE 121
157 #define IDM_FILE_EXIT 130
159 #define IDM_WINDOW_VIS_0 200
160 #define IDM_WINDOW_VIS_1 201
161 #define IDM_WINDOW_VIS_2 202
162 #define IDM_WINDOW_VIS_3 203
163 #define IDM_WINDOW_VIS_4 204
164 #define IDM_WINDOW_VIS_5 205
165 #define IDM_WINDOW_VIS_6 206
166 #define IDM_WINDOW_VIS_7 207
168 #define IDM_WINDOW_FONT_0 210
169 #define IDM_WINDOW_FONT_1 211
170 #define IDM_WINDOW_FONT_2 212
171 #define IDM_WINDOW_FONT_3 213
172 #define IDM_WINDOW_FONT_4 214
173 #define IDM_WINDOW_FONT_5 215
174 #define IDM_WINDOW_FONT_6 216
175 #define IDM_WINDOW_FONT_7 217
177 #define IDM_WINDOW_POS_0 220
178 #define IDM_WINDOW_POS_1 221
179 #define IDM_WINDOW_POS_2 222
180 #define IDM_WINDOW_POS_3 223
181 #define IDM_WINDOW_POS_4 224
182 #define IDM_WINDOW_POS_5 225
183 #define IDM_WINDOW_POS_6 226
184 #define IDM_WINDOW_POS_7 227
186 #define IDM_WINDOW_BIZ_0 230
187 #define IDM_WINDOW_BIZ_1 231
188 #define IDM_WINDOW_BIZ_2 232
189 #define IDM_WINDOW_BIZ_3 233
190 #define IDM_WINDOW_BIZ_4 234
191 #define IDM_WINDOW_BIZ_5 235
192 #define IDM_WINDOW_BIZ_6 236
193 #define IDM_WINDOW_BIZ_7 237
195 #define IDM_WINDOW_I_WID_0 240
196 #define IDM_WINDOW_I_WID_1 241
197 #define IDM_WINDOW_I_WID_2 242
198 #define IDM_WINDOW_I_WID_3 243
199 #define IDM_WINDOW_I_WID_4 244
200 #define IDM_WINDOW_I_WID_5 245
201 #define IDM_WINDOW_I_WID_6 246
202 #define IDM_WINDOW_I_WID_7 247
204 #define IDM_WINDOW_D_WID_0 250
205 #define IDM_WINDOW_D_WID_1 251
206 #define IDM_WINDOW_D_WID_2 252
207 #define IDM_WINDOW_D_WID_3 253
208 #define IDM_WINDOW_D_WID_4 254
209 #define IDM_WINDOW_D_WID_5 255
210 #define IDM_WINDOW_D_WID_6 256
211 #define IDM_WINDOW_D_WID_7 257
213 #define IDM_WINDOW_I_HGT_0 260
214 #define IDM_WINDOW_I_HGT_1 261
215 #define IDM_WINDOW_I_HGT_2 262
216 #define IDM_WINDOW_I_HGT_3 263
217 #define IDM_WINDOW_I_HGT_4 264
218 #define IDM_WINDOW_I_HGT_5 265
219 #define IDM_WINDOW_I_HGT_6 266
220 #define IDM_WINDOW_I_HGT_7 267
222 #define IDM_WINDOW_D_HGT_0 270
223 #define IDM_WINDOW_D_HGT_1 271
224 #define IDM_WINDOW_D_HGT_2 272
225 #define IDM_WINDOW_D_HGT_3 273
226 #define IDM_WINDOW_D_HGT_4 274
227 #define IDM_WINDOW_D_HGT_5 275
228 #define IDM_WINDOW_D_HGT_6 276
229 #define IDM_WINDOW_D_HGT_7 277
231 #define IDM_OPTIONS_NO_GRAPHICS 400
232 #define IDM_OPTIONS_OLD_GRAPHICS 401
233 #define IDM_OPTIONS_NEW_GRAPHICS 402
234 #define IDM_OPTIONS_NEW2_GRAPHICS 403
235 #define IDM_OPTIONS_BIGTILE 409
236 #define IDM_OPTIONS_SOUND 410
237 #define IDM_OPTIONS_MUSIC 411
238 #define IDM_OPTIONS_SAVER 420
239 #define IDM_OPTIONS_MAP 430
240 #define IDM_OPTIONS_BG 440
241 #define IDM_OPTIONS_OPEN_BG 441
243 #define IDM_DUMP_SCREEN_HTML 450
245 #define IDM_HELP_CONTENTS 901
248 * Exclude parts of WINDOWS.H that are not needed
250 #define NOCOMM /* Comm driver APIs and definitions */
251 #define NOLOGERROR /* LogError() and related definitions */
252 #define NOPROFILER /* Profiler APIs */
253 #define NOLFILEIO /* _l* file I/O routines */
254 #define NOOPENFILE /* OpenFile and related definitions */
255 #define NORESOURCE /* Resource management */
256 #define NOATOM /* Atom management */
257 #define NOLANGUAGE /* Character test routines */
258 #define NOLSTRING /* lstr* string management routines */
259 #define NODBCS /* Double-byte character set routines */
260 #define NOKEYBOARDINFO /* Keyboard driver routines */
261 #define NOCOLOR /* COLOR_* color values */
262 #define NODRAWTEXT /* DrawText() and related definitions */
263 #define NOSCALABLEFONT /* Truetype scalable font support */
264 #define NOMETAFILE /* Metafile support */
265 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
266 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
267 #define NOKEYSTATES /* MK_* message key state flags */
268 #define NOWH /* SetWindowsHook and related WH_* definitions */
269 #define NOCLIPBOARD /* Clipboard APIs and definitions */
270 #define NOICONS /* IDI_* icon IDs */
271 #define NOMDI /* MDI support */
272 #define NOHELP /* Help support */
274 /* Not defined since it breaks Borland C++ 5.5 */
275 /* #define NOCTLMGR */ /* Control management and controls */
278 * Exclude parts of WINDOWS.H that are not needed (Win32)
280 #define WIN32_LEAN_AND_MEAN
281 #define NONLS /* All NLS defines and routines */
282 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
283 #define NOKANJI /* Kanji support stuff. */
284 #define NOMCX /* Modem Configuration Extensions */
287 * Include the "windows" support file
292 * Exclude parts of MMSYSTEM.H that are not needed
294 #define MMNODRV /* Installable driver support */
295 #define MMNOWAVE /* Waveform support */
296 #define MMNOMIDI /* MIDI support */
297 #define MMNOAUX /* Auxiliary audio support */
298 #define MMNOTIMER /* Timer support */
299 #define MMNOJOY /* Joystick support */
300 #define MMNOMCI /* MCI support */
301 #define MMNOMMIO /* Multimedia file I/O support */
302 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
306 * Standard sound names
308 const concptr angband_sound_name[SOUND_MAX] =
380 * Standard music names
382 const concptr angband_music_basic_name[MUSIC_BASIC_MAX] =
408 * Include some more files. Note: the Cygnus Cygwin compiler
409 * doesn't use mmsystem.h instead it includes the winmm library
410 * which performs a similar function.
412 #include <mmsystem.h>
416 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
417 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
419 /* #define HTML_HELP */
422 #include <htmlhelp.h>
423 #endif /* HTML_HELP */
426 * Include the support for loading bitmaps
429 # include "readdib.h"
433 * Hack -- Fake declarations from "dos.h"
436 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
438 #define FA_LABEL 0x08 /* Volume label */
439 #define FA_DIREC 0x10 /* Directory */
440 unsigned _cdecl _dos_getfileattr(concptr , unsigned *);
444 * Silliness in WIN32 drawing routine
447 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
451 * Silliness for Windows 95
453 #ifndef WS_EX_TOOLWINDOW
454 # define WS_EX_TOOLWINDOW 0
458 * Foreground color bits (hard-coded by DOS)
460 #define VID_BLACK 0x00
461 #define VID_BLUE 0x01
462 #define VID_GREEN 0x02
463 #define VID_CYAN 0x03
465 #define VID_MAGENTA 0x05
466 #define VID_YELLOW 0x06
467 #define VID_WHITE 0x07
470 * Bright text (hard-coded by DOS)
472 #define VID_BRIGHT 0x08
475 * Background color bits (hard-coded by DOS)
477 #define VUD_BLACK 0x00
478 #define VUD_BLUE 0x10
479 #define VUD_GREEN 0x20
480 #define VUD_CYAN 0x30
482 #define VUD_MAGENTA 0x50
483 #define VUD_YELLOW 0x60
484 #define VUD_WHITE 0x70
487 * Blinking text (hard-coded by DOS)
489 #define VUD_BRIGHT 0x80
495 typedef struct _term_data term_data;
499 * @brief ターム情報構造体 / Extra "term" data
502 * pos_x / pos_y は各タームの左上点座標を指す。
505 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
506 * 1ドットずつ調整するステータスを指す。
507 * また、フォントを変更すると都度自動調整される。
510 * Note the use of "font_want" for the names of the font file requested by
511 * the user, and the use of "font_file" for the currently active font file.
513 * The "font_file" is uppercased, and takes the form "8X13.FON", while
514 * "font_want" can be in almost any form as long as it could be construed
515 * as attempting to represent the name of a font.
527 TERM_LEN rows; /* int -> uint */
530 uint pos_x; //!< タームの左上X座標
531 uint pos_y; //!< タームの左上Y座標
546 int font_wid; //!< フォント横幅
547 int font_hgt; //!< フォント縦幅
548 int tile_wid; //!< タイル横幅
549 int tile_hgt; //!< タイル縦幅
555 #if 1 /* #ifdef JP */
563 #define MAX_TERM_DATA 8 //!< Maximum number of windows
565 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
566 static term_data *my_td; //!< Hack -- global "window creation" pointer
567 POINT normsize; //!< Remember normal size of main window when maxmized
570 * was main window maximized on previous playing
572 bool win_maximized = FALSE;
577 bool game_in_progress = FALSE;
580 * note when "open"/"new" become valid
582 bool initialized = FALSE;
585 * screen paletted, i.e. 256 colors
587 bool paletted = FALSE;
590 * 16 colors screen, don't use RGB()
592 bool colors16 = FALSE;
595 * Saved instance handle
597 static HINSTANCE hInstance;
600 * Yellow brush for the cursor
602 static HBRUSH hbrYellow;
612 static HPALETTE hPal;
615 static HBITMAP hBG = NULL;
616 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
617 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
622 * The screen saver window
624 static HWND hwndSaver;
626 #endif /* USE_SAVER */
632 * 現在使用中のタイルID(0ならば未使用)
633 * Flag set once "graphics" has been initialized
635 static byte_hack current_graphics_mode = 0;
640 static DIBINIT infGraph;
643 * The global bitmap mask
645 static DIBINIT infMask;
647 #endif /* USE_GRAPHICS */
653 * Flag set once "sound" has been initialized
655 static bool can_use_sound = FALSE;
657 #define SAMPLE_SOUND_MAX 16
659 * An array of sound file names
661 static concptr sound_file[SOUND_MAX][SAMPLE_SOUND_MAX];
663 #endif /* USE_SOUND */
669 #define SAMPLE_MUSIC_MAX 16
670 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
671 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
672 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
673 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
674 static bool can_use_music = FALSE;
676 static MCI_OPEN_PARMS mop;
677 static char mci_device_type[256];
679 int current_music_type = 0;
680 int current_music_id = 0;
682 #endif /* USE_MUSIC */
686 * Full path to ANGBAND.INI
688 static concptr ini_file = NULL;
691 * Name of application
693 static concptr AppName = "ANGBAND";
696 * Name of sub-window type
698 static concptr AngList = "AngList";
703 static concptr ANGBAND_DIR_XTRA_GRAF;
704 static concptr ANGBAND_DIR_XTRA_SOUND;
705 static concptr ANGBAND_DIR_XTRA_MUSIC;
706 static concptr ANGBAND_DIR_XTRA_HELP;
708 static concptr ANGBAND_DIR_XTRA_MUSIC;
713 * The "complex" color values
715 static COLORREF win_clr[256];
719 * Flag for macro trigger with dump ASCII
721 static bool Term_no_press = FALSE;
726 static bool mouse_down = FALSE;
727 static bool paint_rect = FALSE;
728 static TERM_LEN mousex = 0, mousey = 0;
729 static TERM_LEN oldx, oldy;
733 * @brief The "simple" color values
735 * See "main-ibm.c" for original table information
736 * The entries below are taken from the "color bits" defined above.
737 * Note that many of the choices below suck, but so do crappy monitors.
739 static BYTE win_pal[256] =
741 VID_BLACK, /* Dark */
742 VID_WHITE, /* White */
743 VID_CYAN, /* Slate XXX */
744 VID_RED | VID_BRIGHT, /* Orange XXX */
746 VID_GREEN, /* Green */
748 VID_YELLOW, /* Umber XXX */
749 VID_BLACK | VID_BRIGHT, /* Light Dark */
750 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
751 VID_MAGENTA, /* Violet XXX */
752 VID_YELLOW | VID_BRIGHT, /* Yellow */
753 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
754 VID_GREEN | VID_BRIGHT, /* Light Green */
755 VID_BLUE | VID_BRIGHT, /* Light Blue */
756 VID_YELLOW /* Light Umber XXX */
761 * Hack -- define which keys are "special"
763 static bool special_key[256];
764 static bool ignore_key[256];
768 * Hack -- initialization list for "special_key"
770 static byte special_key_list[] = {
771 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
772 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
773 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
774 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
775 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
776 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
777 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
778 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
779 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
780 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
781 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
782 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
783 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
784 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
785 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
786 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
787 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
792 static byte ignore_key_list[] = {
793 VK_ESCAPE, VK_TAB, VK_SPACE,
794 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
795 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
796 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
802 * Hack -- initialization list for "special_key"
804 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
805 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
806 * catch the keypad keys (with and without numlock set, including keypad 5),
807 * the function keys (including the "menu" key which maps to F10), and the
808 * "pause" key (between scroll lock and numlock). We also catch a few odd
809 * keys which I do not recognize, but which are listed among keys which we
810 * do catch, so they should be harmless to catch.
812 static byte special_key_list[] =
814 VK_CLEAR, /* 0x0C (KP<5>) */
816 VK_PAUSE, /* 0x13 (pause) */
818 VK_PRIOR, /* 0x21 (KP<9>) */
819 VK_NEXT, /* 0x22 (KP<3>) */
820 VK_END, /* 0x23 (KP<1>) */
821 VK_HOME, /* 0x24 (KP<7>) */
822 VK_LEFT, /* 0x25 (KP<4>) */
823 VK_UP, /* 0x26 (KP<8>) */
824 VK_RIGHT, /* 0x27 (KP<6>) */
825 VK_DOWN, /* 0x28 (KP<2>) */
826 VK_SELECT, /* 0x29 (?????) */
827 VK_PRINT, /* 0x2A (?????) */
828 VK_EXECUTE, /* 0x2B (?????) */
829 VK_SNAPSHOT, /* 0x2C (?????) */
830 VK_INSERT, /* 0x2D (KP<0>) */
831 VK_DELETE, /* 0x2E (KP<.>) */
832 VK_HELP, /* 0x2F (?????) */
862 /* Function prototype */
864 static bool is_already_running(void);
868 static void delete_bg(void)
877 static int init_bg(void)
879 char * bmfile = bg_bitmap_file;
882 if (use_bg == 0) return 0;
884 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
886 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
894 static void DrawBG(HDC hdc, RECT *r)
899 int x = r->left, y = r->top;
900 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
906 GetObject(hBG, sizeof(bm), &bm);
907 swid = bm.bmWidth; shgt = bm.bmHeight;
909 hdcSrc = CreateCompatibleDC(hdc);
910 hOld = SelectObject(hdcSrc, hBG);
914 cwid = MIN(swid - sx, r->right - nx);
917 chgt = MIN(shgt - sy, r->bottom - ny);
918 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
920 } while (ny < r->bottom);
923 } while (nx < r->right);
925 SelectObject(hdcSrc, hOld);
931 * Check for existance of a file
933 static bool check_file(concptr s)
953 attrib = GetFileAttributes(path);
955 /* Require valid filename */
956 if (attrib == INVALID_FILE_NAME) return FALSE;
958 /* Prohibit directory */
959 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return FALSE;
963 /* Examine and verify */
964 if (_dos_getfileattr(path, &attrib)) return FALSE;
966 /* Prohibit something */
967 if (attrib & FA_LABEL) return FALSE;
969 /* Prohibit directory */
970 if (attrib & FA_DIREC) return FALSE;
980 * Check for existance of a directory
982 static bool check_dir(concptr s)
1004 /* Remove trailing backslash */
1005 if (i && (path[i-1] == '\\')) path[--i] = '\0';
1010 attrib = GetFileAttributes(path);
1012 /* Require valid filename */
1013 if (attrib == INVALID_FILE_NAME) return FALSE;
1015 /* Require directory */
1016 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return FALSE;
1020 /* Examine and verify */
1021 if (_dos_getfileattr(path, &attrib)) return FALSE;
1023 /* Prohibit something */
1024 if (attrib & FA_LABEL) return FALSE;
1026 /* Require directory */
1027 if (!(attrib & FA_DIREC)) return FALSE;
1039 static void validate_file(concptr s)
1041 /* Verify or fail */
1044 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
1050 * Validate a directory
1052 static void validate_dir(concptr s, bool vital)
1054 /* Verify or fail */
1057 /* This directory contains needed data */
1060 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
1062 /* Attempt to create this directory */
1065 quit_fmt("Unable to create directory:\n%s", s);
1072 * @brief (Windows版固有実装)Get the "size" for a window
1074 static void term_getsize(term_data *td)
1078 if (td->cols < 1) td->cols = 1;
1079 if (td->rows < 1) td->rows = 1;
1082 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1083 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1085 /* Fake window size */
1087 rc.right = rc.left + wid;
1089 rc.bottom = rc.top + hgt;
1091 /* rc.right += 1; */
1092 /* rc.bottom += 1; */
1095 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1098 td->size_wid = rc.right - rc.left;
1099 td->size_hgt = rc.bottom - rc.top;
1101 /* See CreateWindowEx */
1104 /* Extract actual location */
1105 GetWindowRect(td->w, &rc);
1107 /* Save the location */
1108 td->pos_x = rc.left;
1114 * Write the "prefs" for a single term
1116 static void save_prefs_aux(int i)
1118 term_data *td = &data[i];
1119 GAME_TEXT sec_name[128];
1123 WINDOWPLACEMENT lpwndpl;
1126 /* Make section name */
1127 sprintf(sec_name, "Term-%d", i);
1132 strcpy(buf, td->visible ? "1" : "0");
1133 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1138 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "MS ゴシック");
1140 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1143 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1145 #if 1 /* #ifdef JP */
1146 wsprintf(buf, "%d", td->lf.lfWidth);
1147 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1148 wsprintf(buf, "%d", td->lf.lfHeight);
1149 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1150 wsprintf(buf, "%d", td->lf.lfWeight);
1151 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1154 strcpy(buf, td->bizarre ? "1" : "0");
1155 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1158 wsprintf(buf, "%d", td->tile_wid);
1159 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1162 wsprintf(buf, "%d", td->tile_hgt);
1163 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1165 /* Get window placement and dimensions */
1166 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1167 GetWindowPlacement(td->w, &lpwndpl);
1169 /* Acquire position in *normal* mode (not minimized) */
1170 rc = lpwndpl.rcNormalPosition;
1172 /* Window size (x) */
1173 if (i == 0) wsprintf(buf, "%d", normsize.x);
1174 else wsprintf(buf, "%d", td->cols);
1175 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1177 /* Window size (y) */
1178 if (i == 0) wsprintf(buf, "%d", normsize.y);
1179 else wsprintf(buf, "%d", td->rows);
1180 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1182 /* Maxmized (only main window) */
1185 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1186 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1189 /* Acquire position */
1190 GetWindowRect(td->w, &rc);
1192 /* Window position (x) */
1193 wsprintf(buf, "%d", rc.left);
1194 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1196 /* Window position (y) */
1197 wsprintf(buf, "%d", rc.top);
1198 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1200 /* Window Z position */
1203 strcpy(buf, td->posfix ? "1" : "0");
1204 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1211 * We assume that the windows have all been initialized
1213 static void save_prefs(void)
1219 /* Save the "arg_graphics" flag */
1220 sprintf(buf, "%d", arg_graphics);
1221 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1223 /* Save the "arg_bigtile" flag */
1224 strcpy(buf, arg_bigtile ? "1" : "0");
1225 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1227 /* Save the "arg_sound" flag */
1228 strcpy(buf, arg_sound ? "1" : "0");
1229 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1231 /* Save the "arg_sound" flag */
1232 strcpy(buf, arg_music ? "1" : "0");
1233 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1236 strcpy(buf, use_bg ? "1" : "0");
1237 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1238 WritePrivateProfileString("Angband", "BackGroundBitmap",
1239 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1241 /* Save window prefs */
1242 for (i = 0; i < MAX_TERM_DATA; ++i)
1250 * Load the "prefs" for a single term
1252 static void load_prefs_aux(int i)
1254 term_data *td = &data[i];
1255 GAME_TEXT sec_name[128];
1258 int wid, hgt, posx, posy;
1259 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1260 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1264 /* Make section name */
1265 sprintf(sec_name, "Term-%d", i);
1267 /* Make section name */
1268 sprintf(sec_name, "Term-%d", i);
1273 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1276 /* Desired font, with default */
1278 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1280 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1285 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1287 /* Analyze font, save desired font name */
1288 #if 1 /* #ifdef JP */
1289 td->font_want = string_make(tmp);
1291 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1292 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1293 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1295 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1300 #if 1 /* #ifdef JP */
1301 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1302 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1304 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1305 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1310 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1311 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1312 normsize.x = td->cols; normsize.y = td->rows;
1317 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
1320 /* Window position */
1321 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1322 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1323 td->pos_x = MIN(MAX(0, posx), dispx-128);
1324 td->pos_y = MIN(MAX(0, posy), dispy-128);
1326 /* Window Z position */
1329 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
1337 static void load_prefs(void)
1341 /* Extract the "arg_graphics" flag */
1342 arg_graphics = (byte_hack)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1344 /* Extract the "arg_bigtile" flag */
1345 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
1346 use_bigtile = arg_bigtile;
1348 /* Extract the "arg_sound" flag */
1349 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1351 /* Extract the "arg_sound" flag */
1352 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1355 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1356 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1358 /* Load window prefs */
1359 for (i = 0; i < MAX_TERM_DATA; ++i)
1365 #if defined(USE_SOUND) || defined(USE_MUSIC)
1368 * - Taken from files.c.
1370 * Extract "tokens" from a buffer
1372 * This function uses "whitespace" as delimiters, and treats any amount of
1373 * whitespace as a single delimiter. We will never return any empty tokens.
1374 * When given an empty buffer, or a buffer containing only "whitespace", we
1375 * will return no tokens. We will never extract more than "num" tokens.
1377 * By running a token through the "text_to_ascii()" function, you can allow
1378 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1380 * We save pointers to the tokens in "tokens", and return the number found.
1382 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1392 /* Skip leading whitespace */
1393 for ( ; *s && iswspace(*s); ++s) /* loop */;
1398 /* Find next whitespace, if any */
1399 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1401 /* Nuke and advance (if necessary) */
1402 if (*t) *t++ = '\0';
1404 /* Save the token */
1415 #endif /* USE_SOUND || USE_MUSIC */
1419 static void load_sound_prefs(void)
1423 char ini_path[1024];
1424 char wav_path[1024];
1425 char *zz[SAMPLE_SOUND_MAX];
1427 /* Access the sound.cfg */
1429 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1431 for (i = 0; i < SOUND_MAX; i++)
1433 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1435 num = tokenize_whitespace(tmp, SAMPLE_SOUND_MAX, zz);
1437 for (j = 0; j < num; j++)
1439 /* Access the sound */
1440 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1442 /* Save the sound filename, if it exists */
1443 if (check_file(wav_path))
1444 sound_file[i][j] = string_make(zz[j]);
1449 #endif /* USE_SOUND */
1453 static void load_music_prefs(void)
1457 char ini_path[1024];
1458 char wav_path[1024];
1459 char *zz[SAMPLE_MUSIC_MAX];
1462 /* Access the music.cfg */
1464 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1466 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1468 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1470 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1472 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1474 for (j = 0; j < num; j++)
1476 /* Access the sound */
1477 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1479 /* Save the sound filename, if it exists */
1480 if (check_file(wav_path))
1481 music_file[i][j] = string_make(zz[j]);
1485 for (i = 0; i < current_world_ptr->max_d_idx; i++)
1487 sprintf(key, "dungeon%03d", i);
1488 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1490 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1492 for (j = 0; j < num; j++)
1494 /* Access the sound */
1495 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1497 /* Save the sound filename, if it exists */
1498 if (check_file(wav_path))
1499 dungeon_music_file[i][j] = string_make(zz[j]);
1503 for (i = 0; i < max_q_idx; i++)
1505 sprintf(key, "quest%03d", i);
1506 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1508 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1510 for (j = 0; j < num; j++)
1512 /* Access the sound */
1513 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1515 /* Save the sound filename, if it exists */
1516 if (check_file(wav_path))
1517 quest_music_file[i][j] = string_make(zz[j]);
1521 for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1523 sprintf(key, "town%03d", i);
1524 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1526 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1528 for (j = 0; j < num; j++)
1530 /* Access the sound */
1531 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1533 /* Save the sound filename, if it exists */
1534 if (check_file(wav_path))
1535 town_music_file[i][j] = string_make(zz[j]);
1542 #endif /* USE_MUSIC */
1545 * Create the new global palette based on the bitmap palette
1546 * (if any), and the standard 16 entry palette derived from
1547 * "win_clr[]" which is used for the basic 16 Angband colors.
1549 * This function is never called before all windows are ready.
1551 * This function returns FALSE if the new palette could not be
1552 * prepared, which should normally be a fatal error. XXX XXX
1554 * Note that only some machines actually use a "palette".
1556 static int new_palette(void)
1564 LPLOGPALETTE pLogPal;
1565 LPPALETTEENTRY lppe;
1570 /* This makes no sense */
1571 if (!paletted) return TRUE;
1581 /* Check the bitmap palette */
1582 hBmPal = infGraph.hPalette;
1584 /* Use the bitmap */
1587 lppeSize = 256 * sizeof(PALETTEENTRY);
1588 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1589 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1590 if ((nEntries == 0) || (nEntries > 220))
1593 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1596 rnfree(lppe, lppeSize);
1603 #endif /* USE_GRAPHICS */
1605 /* Size of palette */
1606 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1608 /* Allocate palette */
1609 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1612 pLogPal->palVersion = 0x300;
1614 /* Make room for bitmap and normal data */
1615 pLogPal->palNumEntries = nEntries + 16;
1617 /* Save the bitmap data */
1618 for (i = 0; i < nEntries; i++)
1620 pLogPal->palPalEntry[i] = lppe[i];
1623 /* Save the normal data */
1624 for (i = 0; i < 16; i++)
1628 /* Access the entry */
1629 p = &(pLogPal->palPalEntry[i+nEntries]);
1631 /* Save the colors */
1632 p->peRed = GetRValue(win_clr[i]);
1633 p->peGreen = GetGValue(win_clr[i]);
1634 p->peBlue = GetBValue(win_clr[i]);
1636 /* Save the flags */
1637 p->peFlags = PC_NOCOLLAPSE;
1640 /* Free something */
1641 if (lppe) rnfree(lppe, lppeSize);
1643 /* Create a new palette, or fail */
1644 hNewPal = CreatePalette(pLogPal);
1645 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1647 /* Free the palette */
1648 rnfree(pLogPal, pLogPalSize);
1653 /* Realize the palette */
1655 SelectPalette(hdc, hNewPal, 0);
1656 i = RealizePalette(hdc);
1657 ReleaseDC(td->w, hdc);
1658 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1662 for (i = 1; i < MAX_TERM_DATA; i++)
1667 SelectPalette(hdc, hNewPal, 0);
1668 ReleaseDC(td->w, hdc);
1671 /* Delete old palette */
1672 if (hPal) DeleteObject(hPal);
1674 /* Save new palette */
1684 * @brief グラフィクスを初期化する / Initialize graphics
1687 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1688 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1691 static bool init_graphics(void)
1693 /* Initialize once */
1695 BYTE wid, hgt, twid, thgt, ox, oy;
1698 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1708 ANGBAND_GRAF = "new";
1710 else if (arg_graphics == GRAPHICS_HENGBAND)
1730 ANGBAND_GRAF = "ne2";
1741 ANGBAND_GRAF = "old";
1744 /* Access the bitmap file */
1745 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1747 /* Load the bitmap or quit */
1748 if (!ReadDIB(data[0].w, buf, &infGraph))
1750 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1754 /* Save the new sizes */
1755 infGraph.CellWidth = wid;
1756 infGraph.CellHeight = hgt;
1757 infGraph.TileWidth = twid;
1758 infGraph.TileHeight = thgt;
1759 infGraph.OffsetX = ox;
1760 infGraph.OffsetY = oy;
1762 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1764 /* Access the mask file */
1765 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1767 /* Load the bitmap or quit */
1768 if (!ReadDIB(data[0].w, buf, &infMask))
1770 plog_fmt("Cannot read bitmap file '%s'", buf);
1774 if (arg_graphics == GRAPHICS_HENGBAND)
1776 /* Access the mask file */
1777 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1779 /* Load the bitmap or quit */
1780 if (!ReadDIB(data[0].w, buf, &infMask))
1782 plog_fmt("Cannot read bitmap file '%s'", buf);
1787 /* Activate a palette */
1792 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1796 /* Graphics available */
1797 current_graphics_mode = arg_graphics;
1798 return (current_graphics_mode);
1800 #endif /* USE_GRAPHICS */
1807 static bool init_music(void)
1809 /* Initialize once */
1812 /* Load the prefs */
1815 /* Sound available */
1816 can_use_music = TRUE;
1818 return (can_use_music);
1822 * Hack -- Stop a music
1824 static void stop_music(void)
1826 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1827 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1830 #endif /* USE_MUSIC */
1836 static bool init_sound(void)
1838 /* Initialize once */
1841 /* Load the prefs */
1844 /* Sound available */
1845 can_use_sound = TRUE;
1847 return (can_use_sound);
1849 #endif /* USE_SOUND */
1855 static void term_window_resize(term_data *td)
1857 /* Require window */
1860 /* Resize the window */
1861 SetWindowPos(td->w, 0, 0, 0,
1862 td->size_wid, td->size_hgt,
1863 SWP_NOMOVE | SWP_NOZORDER);
1866 InvalidateRect(td->w, NULL, TRUE);
1871 * Force the use of a new "font file" for a term_data
1873 * This function may be called before the "window" is ready
1875 * This function returns zero only if everything succeeds.
1877 * Note that the "font name" must be capitalized!!!
1879 static errr term_force_font(term_data *td, concptr path)
1883 /* Forget the old font (if needed) */
1884 if (td->font_id) DeleteObject(td->font_id);
1886 #if 1 /* #ifdef JP */
1890 /* Create the font (using the 'base' of the font file name!) */
1891 td->font_id = CreateFontIndirect(&(td->lf));
1892 wid = td->lf.lfWidth;
1893 hgt = td->lf.lfHeight;
1894 if (!td->font_id) return 1;
1896 /* Forget old font */
1902 for (i = 0; i < MAX_TERM_DATA; i++)
1904 /* Don't check when closing the application */
1907 /* Check "screen" */
1908 if ((td != &data[i]) &&
1909 (data[i].font_file) &&
1910 (streq(data[i].font_file, td->font_file)))
1916 /* Remove unused font resources */
1917 if (!used) RemoveFontResource(td->font_file);
1919 /* Free the old name */
1920 string_free(td->font_file);
1923 td->font_file = NULL;
1927 if (!path) return 1;
1932 /* Analyze font path */
1933 base = analyze_font(buf, &wid, &hgt);
1936 if (!suffix(base, ".FON")) return 1;
1939 if (!check_file(buf)) return 1;
1941 /* Load the new font */
1942 if (!AddFontResource(buf)) return 1;
1944 /* Save new font name */
1945 td->font_file = string_make(base);
1947 /* Remove the "suffix" */
1948 base[strlen(base)-4] = '\0';
1950 /* Create the font (using the 'base' of the font file name!) */
1951 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1952 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1953 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1954 FIXED_PITCH | FF_DONTCARE, base);
1957 /* Hack -- Unknown size */
1964 /* all this trouble to get the cell size */
1965 hdcDesktop = GetDC(HWND_DESKTOP);
1966 hfOld = SelectObject(hdcDesktop, td->font_id);
1967 GetTextMetrics(hdcDesktop, &tm);
1968 SelectObject(hdcDesktop, hfOld);
1969 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1971 /* Font size info */
1972 wid = tm.tmAveCharWidth;
1976 /* Save the size info */
1987 * Allow the user to change the font for this window.
1989 static void term_change_font(term_data *td)
1991 #if 1 /* #ifdef JP */
1994 memset(&cf, 0, sizeof(cf));
1995 cf.lStructSize = sizeof(cf);
1996 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1997 cf.lpLogFont = &(td->lf);
1999 if (ChooseFont(&cf))
2001 /* Force the font */
2002 term_force_font(td, NULL);
2004 /* Assume not bizarre */
2007 /* Reset the tile info */
2008 td->tile_wid = td->font_wid;
2009 td->tile_hgt = td->font_hgt;
2011 /* Analyze the font */
2014 /* Resize the window */
2015 term_window_resize(td);
2021 char tmp[1024] = "";
2023 /* Extract a default if possible */
2024 if (td->font_file) strcpy(tmp, td->font_file);
2026 /* Ask for a choice */
2027 memset(&ofn, 0, sizeof(ofn));
2028 ofn.lStructSize = sizeof(ofn);
2029 ofn.hwndOwner = data[0].w;
2030 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
2031 ofn.nFilterIndex = 1;
2032 ofn.lpstrFile = tmp;
2034 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
2035 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2036 ofn.lpstrDefExt = "fon";
2038 /* Force choice if legal */
2039 if (GetOpenFileName(&ofn))
2041 /* Force the font */
2042 if (term_force_font(td, tmp))
2044 /* Access the standard font file */
2045 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2047 /* Force the use of that font */
2048 (void)term_force_font(td, tmp);
2051 /* Assume not bizarre */
2052 td->bizarre = FALSE;
2054 /* Reset the tile info */
2055 td->tile_wid = td->font_wid;
2056 td->tile_hgt = td->font_hgt;
2058 /* Analyze the font */
2061 /* Resize the window */
2062 term_window_resize(td);
2069 * Allow the user to lock this window.
2071 static void term_window_pos(term_data *td, HWND hWnd)
2073 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2074 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2077 static void windows_map(void);
2080 * Hack -- redraw a term_data
2082 static void term_data_redraw(term_data *td)
2086 /* Redraw the map */
2091 /* Activate the term */
2092 Term_activate(&td->t);
2094 /* Redraw the contents */
2097 /* Restore the term */
2098 Term_activate(term_screen);
2103 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2107 HBRUSH myBrush, oldBrush;
2109 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2110 int tx = td->size_ow1 + x * td->tile_wid;
2111 int ty = td->size_oh1 + y * td->tile_hgt;
2112 int tw = w * td->tile_wid - 1;
2113 int th = h * td->tile_hgt - 1;
2116 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2117 oldBrush = SelectObject(hdc, myBrush);
2118 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2120 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2122 SelectObject(hdc, oldBrush);
2123 SelectObject(hdc, oldPen);
2128 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
2130 static errr Term_user_win(int n)
2141 * React to global changes
2143 static errr Term_xtra_win_react(void)
2150 /* Save the default colors */
2151 for (i = 0; i < 256; i++)
2153 /* Simply accept the desired colors */
2154 win_pal[i] = angband_color_table[i][0];
2165 bool change = FALSE;
2167 /* Save the default colors */
2168 for (i = 0; i < 256; i++)
2170 /* Extract desired values */
2171 rv = angband_color_table[i][1];
2172 gv = angband_color_table[i][2];
2173 bv = angband_color_table[i][3];
2175 /* Extract a full color code */
2176 code = PALETTERGB(rv, gv, bv);
2178 /* Activate changes */
2179 if (win_clr[i] != code)
2181 /* Note the change */
2184 /* Apply the desired color */
2189 /* Activate the palette if needed */
2190 if (change) (void)new_palette();
2196 /* Handle "arg_sound" */
2197 if (use_sound != arg_sound)
2199 /* Initialize (if needed) */
2200 if (arg_sound && !init_sound())
2203 plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
2209 /* Change setting */
2210 use_sound = arg_sound;
2217 /* Handle "arg_sound" */
2218 if (use_music != arg_music)
2220 /* Initialize (if needed) */
2221 if (arg_music && !init_music())
2224 plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
2229 /* Change setting */
2230 use_music = arg_music;
2232 if(!arg_music) stop_music();
2233 else select_floor_music(p_ptr);
2242 /* Handle "arg_graphics" */
2243 if (use_graphics != arg_graphics)
2245 /* Initialize (if needed) */
2246 if (arg_graphics && !init_graphics())
2249 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
2252 arg_graphics = GRAPHICS_NONE;
2255 /* Change setting */
2256 use_graphics = arg_graphics;
2259 #ifdef ANGBAND_2_8_1
2261 #else /* ANGBAND_2_8_1 */
2262 reset_visuals(TRUE);
2263 #endif /* ANGBAND_2_8_1 */
2266 #endif /* USE_GRAPHICS */
2269 /* Clean up windows */
2270 for (i = 0; i < MAX_TERM_DATA; i++)
2274 term_data *td = &data[i];
2276 /* Update resized windows */
2277 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
2280 Term_activate(&td->t);
2282 /* Hack -- Resize the term */
2283 Term_resize(td->cols, td->rows);
2285 /* Redraw the contents */
2298 * Process at least one event
2300 static errr Term_xtra_win_event(int v)
2304 /* Wait for an event */
2308 if (GetMessage(&msg, NULL, 0, 0))
2310 TranslateMessage(&msg);
2311 DispatchMessage(&msg);
2315 /* Check for an event */
2319 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2321 TranslateMessage(&msg);
2322 DispatchMessage(&msg);
2332 * Process all pending events
2334 static errr Term_xtra_win_flush(void)
2338 /* Process all pending events */
2339 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2341 TranslateMessage(&msg);
2342 DispatchMessage(&msg);
2351 * Hack -- clear the screen
2353 * Make this more efficient
2355 static errr Term_xtra_win_clear(void)
2357 term_data *td = (term_data*)(Term->data);
2362 /* Rectangle to erase */
2363 rc.left = td->size_ow1;
2364 rc.right = rc.left + td->cols * td->tile_wid;
2365 rc.top = td->size_oh1;
2366 rc.bottom = rc.top + td->rows * td->tile_hgt;
2370 SetBkColor(hdc, RGB(0, 0, 0));
2371 SelectObject(hdc, td->font_id);
2372 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2377 rc.left = 0; rc.top = 0;
2380 ReleaseDC(td->w, hdc);
2388 * Hack -- make a noise
2390 static errr Term_xtra_win_noise(void)
2392 MessageBeep(MB_ICONASTERISK);
2398 * Hack -- make a sound
2400 static errr Term_xtra_win_sound(int v)
2405 #endif /* USE_SOUND */
2407 /* Sound disabled */
2408 if (!use_sound) return 1;
2411 if ((v < 0) || (v >= SOUND_MAX)) return 1;
2415 /* Count the samples */
2416 for (i = 0; i < SAMPLE_SOUND_MAX; i++)
2418 if (!sound_file[v][i])
2423 if (i == 0) return 1;
2425 /* Build the path */
2426 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2430 /* Play the sound, catch errors */
2431 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2435 /* Play the sound, catch errors */
2436 return (sndPlaySound(buf, SND_ASYNC));
2440 #else /* USE_SOUND */
2444 #endif /* USE_SOUND */
2448 * Hack -- play a music
2450 static errr Term_xtra_win_music(int n, int v)
2455 #endif /* USE_MUSIC */
2457 /* Sound disabled */
2458 if (n == TERM_XTRA_MUSIC_MUTE)
2460 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2461 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2464 if(!use_music) return 1;
2467 if(n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return 1;
2468 else if(v < 0 || v >= 1000) return(1); /*!< TODO */
2474 case TERM_XTRA_MUSIC_BASIC:
2475 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if(!music_file[v][i]) break;
2477 case TERM_XTRA_MUSIC_DUNGEON:
2478 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if(!dungeon_music_file[v][i]) break;
2480 case TERM_XTRA_MUSIC_QUEST:
2481 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if(!quest_music_file[v][i]) break;
2483 case TERM_XTRA_MUSIC_TOWN:
2484 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if(!town_music_file[v][i]) break;
2496 case TERM_XTRA_MUSIC_BASIC:
2497 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2499 case TERM_XTRA_MUSIC_DUNGEON:
2500 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2502 case TERM_XTRA_MUSIC_QUEST:
2503 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2505 case TERM_XTRA_MUSIC_TOWN:
2506 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2510 if(current_music_type == n && current_music_id == v)
2514 current_music_type = n;
2515 current_music_id = v;
2519 mop.lpstrDeviceType = mci_device_type;
2520 mop.lpstrElementName = buf;
2521 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2522 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2523 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2524 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2525 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2530 #else /* USE_MUSIC */
2534 #endif /* USE_MUSIC */
2540 * Delay for "x" milliseconds
2542 static int Term_xtra_win_delay(int v)
2556 t = GetTickCount() + v;
2559 while (GetTickCount() < t)
2561 /* Handle messages */
2562 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2564 TranslateMessage(&msg);
2565 DispatchMessage(&msg);
2577 * Do a "special thing"
2579 static errr Term_xtra_win(int n, int v)
2581 /* Handle a subset of the legal requests */
2584 /* Make a bell sound */
2585 case TERM_XTRA_NOISE:
2587 return (Term_xtra_win_noise());
2591 case TERM_XTRA_MUSIC_BASIC:
2592 case TERM_XTRA_MUSIC_DUNGEON:
2593 case TERM_XTRA_MUSIC_QUEST:
2594 case TERM_XTRA_MUSIC_TOWN:
2596 return (Term_xtra_win_music(n, v));
2599 /* Make a special sound */
2600 case TERM_XTRA_SOUND:
2602 return (Term_xtra_win_sound(v));
2605 /* Process random events */
2606 case TERM_XTRA_BORED:
2608 return (Term_xtra_win_event(0));
2611 /* Process an event */
2612 case TERM_XTRA_EVENT:
2614 return (Term_xtra_win_event(v));
2617 /* Flush all events */
2618 case TERM_XTRA_FLUSH:
2620 return (Term_xtra_win_flush());
2623 /* Clear the screen */
2624 case TERM_XTRA_CLEAR:
2626 return (Term_xtra_win_clear());
2629 /* React to global changes */
2630 case TERM_XTRA_REACT:
2632 return (Term_xtra_win_react());
2635 /* Delay for some milliseconds */
2636 case TERM_XTRA_DELAY:
2638 return (Term_xtra_win_delay(v));
2648 * Low level graphics (Assumes valid input).
2650 * Draw a "cursor" at (x,y), using a "yellow box".
2652 static errr Term_curs_win(int x, int y)
2654 term_data *td = (term_data*)(Term->data);
2659 int tile_wid, tile_hgt;
2663 tile_wid = td->map_tile_wid;
2664 tile_hgt = td->map_tile_hgt;
2668 tile_wid = td->tile_wid;
2669 tile_hgt = td->tile_hgt;
2672 /* Frame the grid */
2673 rc.left = x * tile_wid + td->size_ow1;
2674 rc.right = rc.left + tile_wid;
2675 rc.top = y * tile_hgt + td->size_oh1;
2676 rc.bottom = rc.top + tile_hgt;
2678 /* Cursor is done as a yellow "box" */
2680 FrameRect(hdc, &rc, hbrYellow);
2681 ReleaseDC(td->w, hdc);
2689 * Low level graphics (Assumes valid input).
2691 * Draw a "big cursor" at (x,y), using a "yellow box".
2693 static errr Term_bigcurs_win(int x, int y)
2695 term_data *td = (term_data*)(Term->data);
2700 int tile_wid, tile_hgt;
2704 /* Normal cursor in map window */
2705 Term_curs_win(x, y);
2710 tile_wid = td->tile_wid;
2711 tile_hgt = td->tile_hgt;
2714 /* Frame the grid */
2715 rc.left = x * tile_wid + td->size_ow1;
2716 rc.right = rc.left + 2 * tile_wid;
2717 rc.top = y * tile_hgt + td->size_oh1;
2718 rc.bottom = rc.top + tile_hgt;
2720 /* Cursor is done as a yellow "box" */
2722 FrameRect(hdc, &rc, hbrYellow);
2723 ReleaseDC(td->w, hdc);
2731 * Low level graphics (Assumes valid input).
2733 * Erase a "block" of "n" characters starting at (x,y).
2735 static errr Term_wipe_win(int x, int y, int n)
2737 term_data *td = (term_data*)(Term->data);
2742 /* Rectangle to erase in client coords */
2743 rc.left = x * td->tile_wid + td->size_ow1;
2744 rc.right = rc.left + n * td->tile_wid;
2745 rc.top = y * td->tile_hgt + td->size_oh1;
2746 rc.bottom = rc.top + td->tile_hgt;
2749 SetBkColor(hdc, RGB(0, 0, 0));
2750 SelectObject(hdc, td->font_id);
2755 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2756 ReleaseDC(td->w, hdc);
2764 * Low level graphics. Assumes valid input.
2766 * Draw several ("n") chars, with an attr, at a given location.
2768 * All "graphic" data is handled by "Term_pict_win()", below.
2770 * One would think there is a more efficient method for telling a window
2771 * what color it should be using to draw with, but perhaps simply changing
2772 * it every time is not too inefficient.
2774 static errr Term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
2776 term_data *td = (term_data*)(Term->data);
2780 #if 1 /* #ifdef JP */
2781 static HBITMAP WALL;
2782 static HBRUSH myBrush, oldBrush;
2784 static bool init_done = FALSE;
2787 WALL = LoadBitmap(hInstance, AppName);
2788 myBrush = CreatePatternBrush(WALL);
2793 /* Total rectangle */
2794 rc.left = x * td->tile_wid + td->size_ow1;
2795 rc.right = rc.left + n * td->tile_wid;
2796 rc.top = y * td->tile_hgt + td->size_oh1;
2797 rc.bottom = rc.top + td->tile_hgt;
2802 /* Background color */
2803 SetBkColor(hdc, RGB(0, 0, 0));
2805 /* Foreground color */
2808 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2812 SetTextColor(hdc, win_clr[a&0x0F]);
2816 SetTextColor(hdc, win_clr[a]);
2820 SelectObject(hdc, td->font_id);
2823 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2827 (td->tile_hgt != td->font_hgt) ||
2828 (td->tile_wid != td->font_wid))
2832 /* Erase complete rectangle */
2833 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2836 if (use_bg) DrawBG(hdc, &rc);
2839 rc.left += ((td->tile_wid - td->font_wid) / 2);
2840 rc.right = rc.left + td->font_wid;
2841 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2842 rc.bottom = rc.top + td->font_hgt;
2844 /* Dump each character */
2845 for (i = 0; i < n; i++)
2848 if (use_bigtile && *(s+i)=="■"[0] && *(s+i+1)=="■"[1])
2850 rc.right += td->font_wid;
2852 oldBrush = SelectObject(hdc, myBrush);
2853 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2856 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2858 SelectObject(hdc, oldBrush);
2859 SelectObject(hdc, oldPen);
2860 rc.right -= td->font_wid;
2864 rc.left += 2 * td->tile_wid;
2865 rc.right += 2 * td->tile_wid;
2867 else if ( iskanji(*(s+i)) ) /* 2バイト文字 */
2869 rc.right += td->font_wid;
2871 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2873 rc.right -= td->font_wid;
2877 rc.left += 2 * td->tile_wid;
2878 rc.right += 2 * td->tile_wid;
2879 } else if (*(s+i)==127){
2880 oldBrush = SelectObject(hdc, myBrush);
2881 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2884 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2886 SelectObject(hdc, oldBrush);
2887 SelectObject(hdc, oldPen);
2890 rc.left += td->tile_wid;
2891 rc.right += td->tile_wid;
2894 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2897 rc.left += td->tile_wid;
2898 rc.right += td->tile_wid;
2903 oldBrush = SelectObject(hdc, myBrush);
2904 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2907 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2909 SelectObject(hdc, oldBrush);
2910 SelectObject(hdc, oldPen);
2913 rc.left += td->tile_wid;
2914 rc.right += td->tile_wid;
2917 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2921 rc.left += td->tile_wid;
2922 rc.right += td->tile_wid;
2926 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2930 rc.left += td->tile_wid;
2931 rc.right += td->tile_wid;
2942 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2947 ReleaseDC(td->w, hdc);
2955 * Low level graphics. Assumes valid input.
2957 * Draw an array of "special" attr/char pairs at the given location.
2959 * We use the "Term_pict_win()" function for "graphic" data, which are
2960 * encoded by setting the "high-bits" of both the "attr" and the "char"
2961 * data. We use the "attr" to represent the "row" of the main bitmap,
2962 * and the "char" to represent the "col" of the main bitmap. The use
2963 * of this function is induced by the "higher_pict" flag.
2965 * If "graphics" is not available, we simply "wipe" the given grids.
2967 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)
2969 term_data *td = (term_data*)(Term->data);
2974 TERM_LEN x1, y1, w1, h1, tw1, th1;
2975 TERM_LEN x2, y2, w2, h2, tw2 = 0;
2985 /* Erase the grids */
2986 return (Term_wipe_win(x, y, n));
2989 /* Size of bitmap cell */
2990 w1 = infGraph.CellWidth;
2991 h1 = infGraph.CellHeight;
2992 tw1 = infGraph.TileWidth;
2993 th1 = infGraph.TileHeight;
2995 /* Size of window cell */
2998 w2 = td->map_tile_wid;
2999 h2 = td->map_tile_hgt;
3008 if (use_bigtile) tw2 *= 2;
3011 /* Location of window cell */
3012 x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
3013 y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
3019 hdcSrc = CreateCompatibleDC(hdc);
3020 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
3022 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3024 hdcMask = CreateCompatibleDC(hdc);
3025 SelectObject(hdcMask, infMask.hBitmap);
3028 /* Draw attr/char pairs */
3029 for (i = 0; i < n; i++, x2 += w2)
3031 TERM_COLOR a = ap[i];
3035 /* Extract picture */
3036 int row = (a & 0x7F);
3037 int col = (c & 0x7F);
3039 /* Location of bitmap cell */
3043 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3045 x3 = (tcp[i] & 0x7F) * w1;
3046 y3 = (tap[i] & 0x7F) * h1;
3047 tw2 = tw2 * w1 / tw1;
3051 if ((tw1 == tw2) && (th1 == h2))
3053 /* Copy the terrain picture from the bitmap to the window */
3054 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
3056 /* Mask out the tile */
3057 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3060 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3063 /* Need to stretch */
3066 /* Set the correct mode for stretching the tiles */
3067 SetStretchBltMode(hdc, COLORONCOLOR);
3069 /* Copy the terrain picture from the bitmap to the window */
3070 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
3072 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
3074 /* Only draw if terrain and overlay are different */
3075 if ((x1 != x3) || (y1 != y3))
3077 /* Mask out the tile */
3078 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3081 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3088 if ((w1 == tw2) && (h1 == h2))
3090 /* Copy the picture from the bitmap to the window */
3091 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3094 /* Need to stretch */
3097 /* Set the correct mode for stretching the tiles */
3098 SetStretchBltMode(hdc, COLORONCOLOR);
3100 /* Copy the picture from the bitmap to the window */
3101 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3107 SelectObject(hdcSrc, hbmSrcOld);
3110 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3113 SelectObject(hdcMask, hbmSrcOld);
3118 ReleaseDC(td->w, hdc);
3120 #else /* USE_GRAPHICS */
3122 /* Just erase this grid */
3123 return (Term_wipe_win(x, y, n));
3125 #endif /* USE_GRAPHICS */
3132 static void windows_map(void)
3134 term_data *td = &data[0];
3137 TERM_LEN x, min_x, max_x;
3138 TERM_LEN y, min_y, max_y;
3143 /* Only in graphics mode */
3144 if (!use_graphics) return;
3145 Term_xtra_win_clear();
3147 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3148 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3149 td->map_active = TRUE;
3154 max_x = p_ptr->current_floor_ptr->width;
3155 max_y = p_ptr->current_floor_ptr->height;
3159 for (x = min_x; x < max_x; x++)
3161 for (y = min_y; y < max_y; y++)
3163 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3165 /* Ignore non-graphics */
3166 if ((a & 0x80) && (c & 0x80))
3168 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3173 /* Hilite the player */
3174 Term_curs_win(p_ptr->x - min_x, p_ptr->y - min_y);
3176 /* Wait for a keypress, flush key buffer */
3177 Term_inkey(&c, TRUE, TRUE);
3180 /* Switch off the map display */
3181 td->map_active = FALSE;
3183 /* Restore screen */
3184 Term_xtra_win_clear();
3189 /*** Other routines ***/
3193 * Create and initialize a "term_data" given a title
3195 static void term_data_link(term_data *td)
3199 /* Initialize the term */
3200 term_init(t, td->cols, td->rows, td->keys);
3202 /* Use a "software" cursor */
3203 t->soft_cursor = TRUE;
3205 /* Use "Term_pict" for "graphic" data */
3206 t->higher_pict = TRUE;
3208 /* Erase with "white space" */
3209 t->attr_blank = TERM_WHITE;
3210 t->char_blank = ' ';
3212 /* Prepare the template hooks */
3213 t->user_hook = Term_user_win;
3214 t->xtra_hook = Term_xtra_win;
3215 t->curs_hook = Term_curs_win;
3216 t->bigcurs_hook = Term_bigcurs_win;
3217 t->wipe_hook = Term_wipe_win;
3218 t->text_hook = Term_text_win;
3219 t->pict_hook = Term_pict_win;
3221 /* Remember where we came from */
3222 t->data = (vptr)(td);
3227 * Create the windows
3229 * First, instantiate the "default" values, then read the "ini_file"
3230 * to over-ride selected values, then create the windows, and fonts.
3232 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3233 * must make active to realize the palette.
3235 static void init_windows(void)
3243 WIPE(td, term_data);
3247 td->s = angband_term_name[0];
3261 #if 1 /* #ifdef JP */
3265 for (i = 1; i < MAX_TERM_DATA; i++)
3268 WIPE(td, term_data);
3269 td->s = angband_term_name[i];
3273 td->visible = FALSE;
3278 td->pos_x = (7 - i) * 30;
3279 td->pos_y = (7 - i) * 20;
3281 #if 1 /* #ifdef JP */
3291 /* Main window (need these before term_getsize gets called) */
3293 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3294 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3299 /* Sub windows (need these before term_getsize gets called) */
3300 for (i = 1; i < MAX_TERM_DATA; i++)
3303 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3304 td->dwExStyle = (WS_EX_TOOLWINDOW);
3309 for (i = 0; i < MAX_TERM_DATA; i++)
3313 #if 1 /* #ifdef JP */
3314 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3315 td->lf.lfCharSet = DEFAULT_CHARSET;
3316 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3317 /* Activate the chosen font */
3318 term_force_font(td, NULL);
3319 if(!td->tile_wid) td->tile_wid = td->font_wid;
3320 if(!td->tile_hgt) td->tile_hgt = td->font_hgt;
3322 /* Access the standard font file */
3323 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3325 /* Activate the chosen font */
3326 if (term_force_font(td, buf))
3328 /* Access the standard font file */
3329 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3331 /* Force the use of that font */
3332 (void)term_force_font(td, buf);
3337 /* Assume not bizarre */
3338 td->bizarre = FALSE;
3343 /* Analyze the font */
3346 /* Resize the window */
3347 term_window_resize(td);
3351 /* Sub windows (reverse order) */
3352 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3357 td->w = CreateWindowEx(td->dwExStyle, AngList,
3359 td->pos_x, td->pos_y,
3360 td->size_wid, td->size_hgt,
3361 HWND_DESKTOP, NULL, hInstance, NULL);
3363 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3367 td->size_hack = TRUE;
3368 ShowWindow(td->w, SW_SHOW);
3369 td->size_hack = FALSE;
3373 angband_term[i] = &td->t;
3377 /* Activate the window */
3378 SetActiveWindow(td->w);
3383 term_window_pos(&data[i], HWND_TOPMOST);
3387 term_window_pos(&data[i], td->w);
3397 td->w = CreateWindowEx(td->dwExStyle, AppName,
3399 td->pos_x, td->pos_y,
3400 td->size_wid, td->size_hgt,
3401 HWND_DESKTOP, NULL, hInstance, NULL);
3403 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3406 angband_term[0] = &td->t;
3407 normsize.x = td->cols;
3408 normsize.y = td->rows;
3410 /* Activate the main window */
3411 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3412 else ShowWindow(td->w, SW_SHOW);
3414 /* Bring main window back to top */
3415 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3419 (void)new_palette();
3422 /* Create a "brush" for drawing the "cursor" */
3423 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3426 /* Process pending messages */
3427 (void)Term_xtra_win_flush();
3435 static void setup_menus(void)
3439 HMENU hm = GetMenu(data[0].w);
3442 /* Menu "File", Disable all */
3443 EnableMenuItem(hm, IDM_FILE_NEW,
3444 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3445 EnableMenuItem(hm, IDM_FILE_OPEN,
3446 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3447 EnableMenuItem(hm, IDM_FILE_SAVE,
3448 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3449 EnableMenuItem(hm, IDM_FILE_EXIT,
3450 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3451 EnableMenuItem(hm, IDM_FILE_SCORE,
3452 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3455 /* No character available */
3456 if (!current_world_ptr->character_generated)
3458 /* Menu "File", Item "New" */
3459 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3461 /* Menu "File", Item "Open" */
3462 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3465 /* A character available */
3466 if (current_world_ptr->character_generated)
3468 /* Menu "File", Item "Save" */
3469 EnableMenuItem(hm, IDM_FILE_SAVE,
3470 MF_BYCOMMAND | MF_ENABLED);
3473 /* Menu "File", Item "Exit" */
3474 EnableMenuItem(hm, IDM_FILE_EXIT,
3475 MF_BYCOMMAND | MF_ENABLED);
3477 EnableMenuItem(hm, IDM_FILE_SCORE,
3478 MF_BYCOMMAND | MF_ENABLED);
3481 /* Menu "Window::Visibility" */
3482 for (i = 0; i < MAX_TERM_DATA; i++)
3484 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3485 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3487 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3488 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3490 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3491 MF_BYCOMMAND | MF_ENABLED);
3494 /* Menu "Window::Font" */
3495 for (i = 0; i < MAX_TERM_DATA; i++)
3497 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3498 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3500 if (data[i].visible)
3502 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3503 MF_BYCOMMAND | MF_ENABLED);
3507 /* Menu "Window::Window Position Fix" */
3508 for (i = 0; i < MAX_TERM_DATA; i++)
3510 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3511 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3513 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3514 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3516 if (data[i].visible)
3518 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3519 MF_BYCOMMAND | MF_ENABLED);
3523 /* Menu "Window::Bizarre Display" */
3524 for (i = 0; i < MAX_TERM_DATA; i++)
3526 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3527 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3529 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3530 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3532 if (data[i].visible)
3534 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3535 MF_BYCOMMAND | MF_ENABLED);
3540 /* Menu "Window::Increase Tile Width" */
3541 for (i = 0; i < MAX_TERM_DATA; i++)
3543 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3544 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3546 if (data[i].visible)
3548 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3549 MF_BYCOMMAND | MF_ENABLED);
3554 /* Menu "Window::Decrease Tile Width" */
3555 for (i = 0; i < MAX_TERM_DATA; i++)
3557 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3558 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3560 if (data[i].visible)
3562 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3563 MF_BYCOMMAND | MF_ENABLED);
3568 /* Menu "Window::Increase Tile Height" */
3569 for (i = 0; i < MAX_TERM_DATA; i++)
3571 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3572 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3574 if (data[i].visible)
3576 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3577 MF_BYCOMMAND | MF_ENABLED);
3582 /* Menu "Window::Decrease Tile Height" */
3583 for (i = 0; i < MAX_TERM_DATA; i++)
3585 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3586 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3588 if (data[i].visible)
3590 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3591 MF_BYCOMMAND | MF_ENABLED);
3596 /* Menu "Options", disable all */
3597 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3598 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3599 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3600 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3601 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3602 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3603 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3604 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3605 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3606 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3608 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3609 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3612 /* Menu "Options", Item "Map" */
3613 if (use_graphics != GRAPHICS_NONE)
3614 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3616 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3617 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3619 /* Menu "Options", update all */
3620 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3621 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3622 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3623 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3624 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3625 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3626 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3627 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3628 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3629 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3630 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3631 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3632 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3633 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3634 CheckMenuItem(hm, IDM_OPTIONS_BG,
3635 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3637 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3638 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3642 /* Menu "Options", Item "Graphics" */
3643 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3644 /* Menu "Options", Item "Graphics" */
3645 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3646 /* Menu "Options", Item "Graphics" */
3647 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3648 /* Menu "Options", Item "Graphics" */
3649 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3650 #endif /* USE_GRAPHICS */
3653 /* Menu "Options", Item "Sound" */
3654 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3655 #endif /* USE_SOUND */
3658 /* Menu "Options", Item "ScreenSaver" */
3659 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3660 MF_BYCOMMAND | MF_ENABLED);
3661 #endif /* USE_SAVER */
3666 * Check for double clicked (or dragged) savefile
3668 * Apparently, Windows copies the entire filename into the first
3669 * piece of the "command line string". Perhaps we should extract
3670 * the "basename" of that filename and append it to the "save" dir.
3672 static void check_for_save_file(LPSTR cmd_line)
3682 /* Extract filename */
3683 strcat(savefile, s);
3685 /* Validate the file */
3686 validate_file(savefile);
3688 /* Game in progress */
3689 game_in_progress = TRUE;
3692 play_game(p_ptr, FALSE);
3697 * Process a menu command
3699 static void process_menus(WORD wCmd)
3715 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3717 else if (game_in_progress)
3719 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3723 game_in_progress = TRUE;
3725 play_game(p_ptr, TRUE);
3736 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3738 else if (game_in_progress)
3740 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3744 memset(&ofn, 0, sizeof(ofn));
3745 ofn.lStructSize = sizeof(ofn);
3746 ofn.hwndOwner = data[0].w;
3747 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3748 ofn.nFilterIndex = 1;
3749 ofn.lpstrFile = savefile;
3750 ofn.nMaxFile = 1024;
3751 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3752 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3754 if (GetOpenFileName(&ofn))
3756 /* Load 'savefile' */
3757 validate_file(savefile);
3758 game_in_progress = TRUE;
3760 play_game(p_ptr, FALSE);
3770 if (game_in_progress && current_world_ptr->character_generated)
3774 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3778 /* Hack -- Forget messages */
3783 do_cmd_save_game(p_ptr, FALSE);
3784 #else /* ZANGBAND */
3786 #endif /* ZANGBAND */
3790 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3797 if (game_in_progress && current_world_ptr->character_generated)
3801 plog(_("今は終了できません。", "You may not do that right now."));
3805 /* Hack -- Forget messages */
3808 forget_lite(p_ptr->current_floor_ptr);
3809 forget_view(p_ptr->current_floor_ptr);
3810 clear_mon_lite(p_ptr->current_floor_ptr);
3814 /* do_cmd_save_game(FALSE); */
3815 #else /* ZANGBAND */
3816 /* do_cmd_save_game(); */
3817 #endif /* ZANGBAND */
3818 Term_key_push(SPECIAL_KEY_QUIT);
3826 case IDM_FILE_SCORE:
3829 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3831 /* Open the binary high score file, for reading */
3832 highscore_fd = fd_open(buf, O_RDONLY);
3834 /* Paranoia -- No score file */
3835 if (highscore_fd < 0)
3837 msg_print("Score file unavailable.");
3844 /* Display the scores */
3845 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3847 /* Shut the high score file */
3848 (void)fd_close(highscore_fd);
3850 /* Forget the high score fd */
3854 /* Hack - Flush it */
3862 case IDM_FILE_MOVIE:
3866 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3868 else if (game_in_progress)
3870 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
3874 memset(&ofn, 0, sizeof(ofn));
3875 ofn.lStructSize = sizeof(ofn);
3876 ofn.hwndOwner = data[0].w;
3877 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3878 ofn.nFilterIndex = 1;
3879 ofn.lpstrFile = savefile;
3880 ofn.nMaxFile = 1024;
3881 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3882 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3884 if (GetOpenFileName(&ofn))
3886 /* Load 'savefile' */
3887 prepare_browse_movie_aux(savefile);
3888 play_game(p_ptr, FALSE);
3897 case IDM_WINDOW_VIS_0:
3899 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
3903 /* Window visibility */
3904 case IDM_WINDOW_VIS_1:
3905 case IDM_WINDOW_VIS_2:
3906 case IDM_WINDOW_VIS_3:
3907 case IDM_WINDOW_VIS_4:
3908 case IDM_WINDOW_VIS_5:
3909 case IDM_WINDOW_VIS_6:
3910 case IDM_WINDOW_VIS_7:
3912 i = wCmd - IDM_WINDOW_VIS_0;
3914 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3921 ShowWindow(td->w, SW_SHOW);
3922 term_data_redraw(td);
3926 td->visible = FALSE;
3928 ShowWindow(td->w, SW_HIDE);
3935 case IDM_WINDOW_FONT_0:
3936 case IDM_WINDOW_FONT_1:
3937 case IDM_WINDOW_FONT_2:
3938 case IDM_WINDOW_FONT_3:
3939 case IDM_WINDOW_FONT_4:
3940 case IDM_WINDOW_FONT_5:
3941 case IDM_WINDOW_FONT_6:
3942 case IDM_WINDOW_FONT_7:
3944 i = wCmd - IDM_WINDOW_FONT_0;
3946 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3950 term_change_font(td);
3955 /* Window Z Position */
3956 case IDM_WINDOW_POS_1:
3957 case IDM_WINDOW_POS_2:
3958 case IDM_WINDOW_POS_3:
3959 case IDM_WINDOW_POS_4:
3960 case IDM_WINDOW_POS_5:
3961 case IDM_WINDOW_POS_6:
3962 case IDM_WINDOW_POS_7:
3964 i = wCmd - IDM_WINDOW_POS_0;
3966 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3970 if (!td->posfix && td->visible)
3973 term_window_pos(td, HWND_TOPMOST);
3978 term_window_pos(td, data[0].w);
3984 /* Bizarre Display */
3985 case IDM_WINDOW_BIZ_0:
3986 case IDM_WINDOW_BIZ_1:
3987 case IDM_WINDOW_BIZ_2:
3988 case IDM_WINDOW_BIZ_3:
3989 case IDM_WINDOW_BIZ_4:
3990 case IDM_WINDOW_BIZ_5:
3991 case IDM_WINDOW_BIZ_6:
3992 case IDM_WINDOW_BIZ_7:
3994 i = wCmd - IDM_WINDOW_BIZ_0;
3996 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4000 td->bizarre = !td->bizarre;
4004 term_window_resize(td);
4009 /* Increase Tile Width */
4010 case IDM_WINDOW_I_WID_0:
4011 case IDM_WINDOW_I_WID_1:
4012 case IDM_WINDOW_I_WID_2:
4013 case IDM_WINDOW_I_WID_3:
4014 case IDM_WINDOW_I_WID_4:
4015 case IDM_WINDOW_I_WID_5:
4016 case IDM_WINDOW_I_WID_6:
4017 case IDM_WINDOW_I_WID_7:
4019 i = wCmd - IDM_WINDOW_I_WID_0;
4021 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4029 term_window_resize(td);
4034 /* Decrease Tile Height */
4035 case IDM_WINDOW_D_WID_0:
4036 case IDM_WINDOW_D_WID_1:
4037 case IDM_WINDOW_D_WID_2:
4038 case IDM_WINDOW_D_WID_3:
4039 case IDM_WINDOW_D_WID_4:
4040 case IDM_WINDOW_D_WID_5:
4041 case IDM_WINDOW_D_WID_6:
4042 case IDM_WINDOW_D_WID_7:
4044 i = wCmd - IDM_WINDOW_D_WID_0;
4046 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4054 term_window_resize(td);
4059 /* Increase Tile Height */
4060 case IDM_WINDOW_I_HGT_0:
4061 case IDM_WINDOW_I_HGT_1:
4062 case IDM_WINDOW_I_HGT_2:
4063 case IDM_WINDOW_I_HGT_3:
4064 case IDM_WINDOW_I_HGT_4:
4065 case IDM_WINDOW_I_HGT_5:
4066 case IDM_WINDOW_I_HGT_6:
4067 case IDM_WINDOW_I_HGT_7:
4069 i = wCmd - IDM_WINDOW_I_HGT_0;
4071 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4079 term_window_resize(td);
4084 /* Decrease Tile Height */
4085 case IDM_WINDOW_D_HGT_0:
4086 case IDM_WINDOW_D_HGT_1:
4087 case IDM_WINDOW_D_HGT_2:
4088 case IDM_WINDOW_D_HGT_3:
4089 case IDM_WINDOW_D_HGT_4:
4090 case IDM_WINDOW_D_HGT_5:
4091 case IDM_WINDOW_D_HGT_6:
4092 case IDM_WINDOW_D_HGT_7:
4094 i = wCmd - IDM_WINDOW_D_HGT_0;
4096 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4104 term_window_resize(td);
4109 case IDM_OPTIONS_NO_GRAPHICS:
4113 plog("You may not do that right now.");
4117 if (arg_graphics != GRAPHICS_NONE)
4119 arg_graphics = GRAPHICS_NONE;
4120 Term_xtra_win_react();
4121 Term_key_push(KTRL('R'));
4127 case IDM_OPTIONS_OLD_GRAPHICS:
4131 plog("You may not do that right now.");
4135 if (arg_graphics != GRAPHICS_ORIGINAL)
4137 arg_graphics = GRAPHICS_ORIGINAL;
4138 Term_xtra_win_react();
4139 Term_key_push(KTRL('R'));
4145 case IDM_OPTIONS_NEW_GRAPHICS:
4149 plog("You may not do that right now.");
4153 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4155 arg_graphics = GRAPHICS_ADAM_BOLT;
4156 Term_xtra_win_react();
4157 Term_key_push(KTRL('R'));
4163 case IDM_OPTIONS_NEW2_GRAPHICS:
4167 plog("You may not do that right now.");
4171 if (arg_graphics != GRAPHICS_HENGBAND)
4173 arg_graphics = GRAPHICS_HENGBAND;
4174 Term_xtra_win_react();
4175 Term_key_push(KTRL('R'));
4181 case IDM_OPTIONS_BIGTILE:
4186 plog("You may not do that right now.");
4190 arg_bigtile = !arg_bigtile;
4191 Term_activate(&td->t);
4192 Term_resize(td->cols, td->rows);
4193 InvalidateRect(td->w, NULL, TRUE);
4197 case IDM_OPTIONS_MUSIC:
4201 plog("You may not do that right now.");
4205 arg_music = !arg_music;
4206 Term_xtra_win_react();
4207 Term_key_push(KTRL('R'));
4211 case IDM_OPTIONS_SOUND:
4215 plog("You may not do that right now.");
4219 arg_sound = !arg_sound;
4220 Term_xtra_win_react();
4221 Term_key_push(KTRL('R'));
4226 case IDM_OPTIONS_BG:
4230 plog("You may not do that right now.");
4236 Term_xtra_win_react();
4237 Term_key_push(KTRL('R'));
4242 case IDM_OPTIONS_OPEN_BG:
4246 plog("You may not do that right now.");
4251 memset(&ofn, 0, sizeof(ofn));
4252 ofn.lStructSize = sizeof(ofn);
4253 ofn.hwndOwner = data[0].w;
4254 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4255 ofn.nFilterIndex = 1;
4256 ofn.lpstrFile = bg_bitmap_file;
4257 ofn.nMaxFile = 1023;
4258 ofn.lpstrInitialDir = NULL;
4259 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
4260 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4262 if (GetOpenFileName(&ofn))
4264 /* Load 'savefile' */
4269 /* React to changes */
4270 Term_xtra_win_react();
4272 /* Hack -- Force redraw */
4273 Term_key_push(KTRL('R'));
4278 case IDM_DUMP_SCREEN_HTML:
4280 static char buf[1024] = "";
4281 memset(&ofn, 0, sizeof(ofn));
4282 ofn.lStructSize = sizeof(ofn);
4283 ofn.hwndOwner = data[0].w;
4284 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4285 ofn.nFilterIndex = 1;
4286 ofn.lpstrFile = buf;
4287 ofn.nMaxFile = 1023;
4288 ofn.lpstrDefExt = "html";
4289 ofn.lpstrInitialDir = NULL;
4290 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
4291 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4293 if (GetSaveFileName(&ofn))
4295 do_cmd_save_screen_html_aux(buf, 0);
4302 case IDM_OPTIONS_SAVER:
4306 DestroyWindow(hwndSaver);
4311 /* Create a screen scaver window */
4312 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4313 "Angband Screensaver",
4314 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4315 0, 0, GetSystemMetrics(SM_CXSCREEN),
4316 GetSystemMetrics(SM_CYSCREEN),
4317 NULL, NULL, hInstance, NULL);
4321 /* Push the window to the bottom */
4322 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4326 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
4334 case IDM_OPTIONS_MAP:
4340 case IDM_HELP_CONTENTS:
4344 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4345 if (check_file(tmp))
4347 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4351 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4352 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4355 #else /* HTML_HELP */
4358 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4359 if (check_file(tmp))
4361 sprintf(buf, "winhelp.exe %s", tmp);
4362 WinExec(buf, SW_NORMAL);
4366 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4367 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4371 #endif /* HTML_HELP */
4377 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4384 /* Extract the modifiers */
4385 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4386 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4387 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4389 Term_no_press = (ma) ? TRUE : FALSE;
4391 /* Handle "special" keys */
4392 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4394 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4395 bool numpad = FALSE;
4397 /* Begin the macro trigger */
4400 /* Send the modifiers */
4401 if (mc) Term_keypress('C');
4402 if (ms) Term_keypress('S');
4403 if (ma) Term_keypress('A');
4405 /* Extract "scan code" */
4406 i = LOBYTE(HIWORD(lParam));
4408 /* Introduce the scan code */
4411 /* Extended key bit */
4414 /* Numpad Enter and '/' are extended key */
4416 Term_no_press = TRUE;
4417 case VK_RETURN: /* Enter */
4420 /* Other extended keys are on full keyboard */
4436 Term_no_press = TRUE;
4440 case VK_PRIOR: /* Page Up */
4441 case VK_NEXT: /* Page Down */
4451 /* Special modifiers for keypad keys */
4452 if (numpad) Term_keypress('K');
4454 /* Encode the hexidecimal scan code */
4455 Term_keypress(hexsym[i/16]);
4456 Term_keypress(hexsym[i%16]);
4458 /* End the macro trigger */
4469 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4470 WPARAM wParam, LPARAM lParam);
4471 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4472 WPARAM wParam, LPARAM lParam)
4473 #else /* __MWERKS__ */
4474 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4475 #endif /* __MWERKS__ */
4483 /* Acquire proper "term_data" info */
4484 td = (term_data *)GetWindowLong(hWnd, 0);
4486 /* Handle message */
4491 SetWindowLong(hWnd, 0, (LONG)(my_td));
4498 mop.dwCallback=(DWORD)hWnd;
4503 case WM_GETMINMAXINFO:
4505 MINMAXINFO FAR *lpmmi;
4508 lpmmi = (MINMAXINFO FAR *)lParam;
4510 /* this message was sent before WM_NCCREATE */
4513 /* Minimum window size is 80x24 */
4514 rc.left = rc.top = 0;
4515 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4516 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4519 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4521 /* Save minimum size */
4522 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4523 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4530 BeginPaint(hWnd, &ps);
4531 if (td) term_data_redraw(td);
4532 EndPaint(hWnd, &ps);
4533 ValidateRect(hWnd, NULL);
4540 if(wParam == MCI_NOTIFY_SUCCESSFUL)
4542 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4543 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4552 if (process_keydown(wParam, lParam))
4559 if (Term_no_press) Term_no_press = FALSE;
4560 else Term_keypress(wParam);
4564 case WM_LBUTTONDOWN:
4566 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4567 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4579 TERM_LEN dx = abs(oldx - mousex) + 1;
4580 TERM_LEN dy = abs(oldy - mousey) + 1;
4581 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
4582 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
4592 hGlobal = GlobalAlloc(GHND, sz + 1);
4593 if (hGlobal == NULL) return 0;
4594 lpStr = (LPSTR)GlobalLock(hGlobal);
4596 for (i = 0; i < dy; i++)
4600 char **scr = data[0].t.scr->c;
4602 C_MAKE(s, (dx + 1), char);
4603 strncpy(s, &scr[oy + i][ox], dx);
4607 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4610 if (ox + dx < data[0].cols)
4612 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4615 for (j = 0; j < dx; j++)
4617 if (s[j] == 127) s[j] = '#';
4621 for (j = 0; j < dx; j++)
4623 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4633 GlobalUnlock(hGlobal);
4634 if (OpenClipboard(hWnd) == 0)
4636 GlobalFree(hGlobal);
4640 SetClipboardData(CF_TEXT, hGlobal);
4653 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4654 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4659 dx = abs(oldx - mousex) + 1;
4660 dy = abs(oldy - mousey) + 1;
4661 ox = (oldx > mousex) ? mousex : oldx;
4662 oy = (oldy > mousey) ? mousey : oldy;
4663 Term_inversed_area(hWnd, ox, oy, dx, dy);
4670 dx = abs(cx - mousex) + 1;
4671 dy = abs(cy - mousey) + 1;
4672 ox = (cx > mousex) ? mousex : cx;
4673 oy = (cy > mousey) ? mousey : cy;
4674 Term_inversed_area(hWnd, ox, oy, dx, dy);
4690 if (game_in_progress && current_world_ptr->character_generated)
4694 plog(_("今は終了できません。", "You may not do that right now."));
4698 /* Hack -- Forget messages */
4701 forget_lite(p_ptr->current_floor_ptr);
4702 forget_view(p_ptr->current_floor_ptr);
4703 clear_mon_lite(p_ptr->current_floor_ptr);
4707 /* do_cmd_save_game(FALSE); */
4708 #else /* ZANGBAND */
4709 /* do_cmd_save_game(); */
4710 #endif /* ZANGBAND */
4711 Term_key_push(SPECIAL_KEY_QUIT);
4718 case WM_QUERYENDSESSION:
4720 if (game_in_progress && current_world_ptr->character_generated)
4722 /* Hack -- Forget messages */
4725 /* Mega-Hack -- Delay death */
4726 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4727 exe_write_diary(p_ptr, NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4729 /* Hardcode panic save */
4730 p_ptr->panic_save = 1;
4732 /* Forbid suspend */
4733 signals_ignore_tstp();
4735 /* Indicate panic save */
4736 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4739 (void)save_player(p_ptr);
4753 process_menus(LOWORD(wParam));
4759 /* this message was sent before WM_NCCREATE */
4762 /* it was sent from inside CreateWindowEx */
4763 if (!td->w) return 1;
4765 /* was sent from WM_SIZE */
4766 if (td->size_hack) return 1;
4770 case SIZE_MINIMIZED:
4772 /* Hide sub-windows */
4773 for (i = 1; i < MAX_TERM_DATA; i++)
4775 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4780 case SIZE_MAXIMIZED:
4787 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4788 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4791 if ((td->cols != cols) || (td->rows != rows))
4793 /* Save the new size */
4797 if (!IsZoomed(td->w) && !IsIconic(td->w))
4799 normsize.x = td->cols;
4800 normsize.y = td->rows;
4804 Term_activate(&td->t);
4806 /* Resize the term */
4807 Term_resize(td->cols, td->rows);
4810 InvalidateRect(td->w, NULL, TRUE);
4813 td->size_hack = TRUE;
4815 /* Show sub-windows */
4816 for (i = 1; i < MAX_TERM_DATA; i++)
4818 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4821 td->size_hack = FALSE;
4829 case WM_PALETTECHANGED:
4831 /* Ignore if palette change caused by itself */
4832 if ((HWND)wParam == hWnd) return 0;
4834 /* Fall through... */
4837 case WM_QUERYNEWPALETTE:
4839 if (!paletted) return 0;
4843 SelectPalette(hdc, hPal, FALSE);
4845 i = RealizePalette(hdc);
4847 /* if any palette entries changed, repaint the window. */
4848 if (i) InvalidateRect(hWnd, NULL, TRUE);
4850 ReleaseDC(hWnd, hdc);
4857 if (wParam && !HIWORD(lParam))
4859 /* Do something to sub-windows */
4860 for (i = 1; i < MAX_TERM_DATA; i++)
4862 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4865 /* Focus on main window */
4874 case WM_ACTIVATEAPP:
4876 if (IsIconic(td->w)) break;
4878 for (i = 1; i < MAX_TERM_DATA; i++)
4884 ShowWindow(data[i].w, SW_SHOW);
4888 ShowWindow(data[i].w, SW_HIDE);
4895 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4900 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4901 WPARAM wParam, LPARAM lParam);
4902 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4903 WPARAM wParam, LPARAM lParam)
4904 #else /* __MWERKS__ */
4905 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4906 WPARAM wParam, LPARAM lParam)
4907 #endif /* __MWERKS__ */
4915 /* Acquire proper "term_data" info */
4916 td = (term_data *)GetWindowLong(hWnd, 0);
4918 /* Process message */
4923 SetWindowLong(hWnd, 0, (LONG)(my_td));
4932 case WM_GETMINMAXINFO:
4934 MINMAXINFO FAR *lpmmi;
4937 lpmmi = (MINMAXINFO FAR *)lParam;
4939 /* this message was sent before WM_NCCREATE */
4942 /* Minimum window size is 80x24 */
4943 rc.left = rc.top = 0;
4944 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4945 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4948 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4950 /* Save minimum size */
4951 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4952 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4962 /* this message was sent before WM_NCCREATE */
4965 /* it was sent from inside CreateWindowEx */
4966 if (!td->w) return 1;
4968 /* was sent from inside WM_SIZE */
4969 if (td->size_hack) return 1;
4971 td->size_hack = TRUE;
4973 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4974 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4977 if ((td->cols != cols) || (td->rows != rows))
4980 term *old_term = Term;
4982 /* Save the new size */
4987 Term_activate(&td->t);
4989 /* Resize the term */
4990 Term_resize(td->cols, td->rows);
4993 Term_activate(old_term);
4996 InvalidateRect(td->w, NULL, TRUE);
4998 /* HACK - Redraw all windows */
4999 p_ptr->window = 0xFFFFFFFF;
5000 handle_stuff(p_ptr);
5003 td->size_hack = FALSE;
5010 BeginPaint(hWnd, &ps);
5011 if (td) term_data_redraw(td);
5012 EndPaint(hWnd, &ps);
5019 if (process_keydown(wParam, lParam))
5026 if (Term_no_press) Term_no_press = FALSE;
5027 else Term_keypress(wParam);
5031 case WM_PALETTECHANGED:
5033 /* ignore if palette change caused by itself */
5034 if ((HWND)wParam == hWnd) return FALSE;
5035 /* otherwise, fall through!!! */
5038 case WM_QUERYNEWPALETTE:
5040 if (!paletted) return 0;
5042 SelectPalette(hdc, hPal, FALSE);
5043 i = RealizePalette(hdc);
5044 /* if any palette entries changed, repaint the window. */
5045 if (i) InvalidateRect(hWnd, NULL, TRUE);
5046 ReleaseDC(hWnd, hdc);
5050 case WM_NCLBUTTONDOWN:
5054 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5055 #endif /* HTCLOSE */
5057 if (wParam == HTSYSMENU)
5061 td->visible = FALSE;
5062 ShowWindow(td->w, SW_HIDE);
5072 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5078 #define MOUSE_SENS 40
5081 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5082 WPARAM wParam, LPARAM lParam);
5083 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5084 WPARAM wParam, LPARAM lParam)
5085 #else /* __MWERKS__ */
5086 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5087 WPARAM wParam, LPARAM lParam)
5088 #endif /* __MWERKS__ */
5090 static int iMouse = 0;
5091 static WORD xMouse = 0;
5092 static WORD yMouse = 0;
5111 case WM_LBUTTONDOWN:
5112 case WM_MBUTTONDOWN:
5113 case WM_RBUTTONDOWN:
5116 SendMessage(hWnd, WM_CLOSE, 0, 0);
5124 dx = LOWORD(lParam) - xMouse;
5125 dy = HIWORD(lParam) - yMouse;
5127 if (dx < 0) dx = -dx;
5128 if (dy < 0) dy = -dy;
5130 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5132 SendMessage(hWnd, WM_CLOSE, 0, 0);
5136 /* Save last location */
5138 xMouse = LOWORD(lParam);
5139 yMouse = HIWORD(lParam);
5146 DestroyWindow(hwndSaver);
5152 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5155 #endif /* USE_SAVER */
5161 /*** Temporary Hooks ***/
5165 * Display warning message (see "z-util.c")
5167 static void hack_plog(concptr str)
5169 /* Give a warning */
5173 MessageBox(NULL, str, "警告!",
5174 MB_ICONEXCLAMATION | MB_OK);
5176 MessageBox(NULL, str, "Warning",
5177 MB_ICONEXCLAMATION | MB_OK);
5185 * Display error message and quit (see "z-util.c")
5187 static void hack_quit(concptr str)
5189 /* Give a warning */
5193 MessageBox(NULL, str, "エラー!",
5194 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5196 MessageBox(NULL, str, "Error",
5197 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5202 /* Unregister the classes */
5203 UnregisterClass(AppName, hInstance);
5205 /* Destroy the icon */
5206 if (hIcon) DestroyIcon(hIcon);
5213 /*** Various hooks ***/
5217 * Display warning message (see "z-util.c")
5219 static void hook_plog(concptr str)
5225 MessageBox(data[0].w, str, "警告!",
5226 MB_ICONEXCLAMATION | MB_OK);
5228 MessageBox(data[0].w, str, "Warning",
5229 MB_ICONEXCLAMATION | MB_OK);
5237 * Display error message and quit (see "z-util.c")
5239 static void hook_quit(concptr str)
5244 /* Give a warning */
5248 MessageBox(data[0].w, str, "エラー!",
5249 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5251 MessageBox(data[0].w, str, "Error",
5252 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5258 /* Save the preferences */
5262 /*** Could use 'Term_nuke_win()' */
5264 /* Destroy all windows */
5265 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5267 term_force_font(&data[i], NULL);
5268 if (data[i].font_want) string_free(data[i].font_want);
5269 if (data[i].w) DestroyWindow(data[i].w);
5273 /* Free the bitmap stuff */
5275 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5276 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5278 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5279 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5281 #endif /* USE_GRAPHICS */
5283 /*** Free some other stuff ***/
5285 DeleteObject(hbrYellow);
5290 if (hPal) DeleteObject(hPal);
5292 UnregisterClass(AppName, hInstance);
5294 if (hIcon) DestroyIcon(hIcon);
5301 /*** Initialize ***/
5307 static void init_stuff(void)
5314 /* Get program name with full path */
5315 GetModuleFileName(hInstance, path, 512);
5317 /* Save the "program name" */
5320 /* Get the name of the "*.ini" file */
5321 strcpy(path + strlen(path) - 4, ".INI");
5323 /* Save the the name of the ini-file */
5324 ini_file = string_make(path);
5326 /* Analyze the path */
5332 if (path[i] == '\\')
5339 /* Add "lib" to the path */
5340 strcpy(path + i + 1, "lib\\");
5342 /* Validate the path */
5343 validate_dir(path, TRUE);
5345 /* Init the file paths */
5346 init_file_paths(path);
5348 /* Hack -- Validate the paths */
5349 validate_dir(ANGBAND_DIR_APEX, FALSE);
5350 validate_dir(ANGBAND_DIR_BONE, FALSE);
5352 /* Allow missing 'edit' directory */
5353 if (!check_dir(ANGBAND_DIR_EDIT))
5355 /* Must have 'data'! */
5356 validate_dir(ANGBAND_DIR_DATA, TRUE);
5360 /* Don't need 'data' */
5361 validate_dir(ANGBAND_DIR_DATA, FALSE);
5364 validate_dir(ANGBAND_DIR_FILE, TRUE);
5365 validate_dir(ANGBAND_DIR_HELP, FALSE);
5366 validate_dir(ANGBAND_DIR_INFO, FALSE);
5367 validate_dir(ANGBAND_DIR_PREF, TRUE);
5368 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5369 validate_dir(ANGBAND_DIR_USER, TRUE);
5370 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5371 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
5373 /* Hack -- Validate the "news.txt" file */
5374 validate_file(path);
5378 /* Build the "graf" path */
5379 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5381 /* Allocate the path */
5382 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5384 /* Validate the "graf" directory */
5385 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5387 #endif /* USE_GRAPHICS */
5392 /* Build the "sound" path */
5393 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5395 /* Allocate the path */
5396 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5398 /* Validate the "sound" directory */
5399 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5401 #endif /* USE_SOUND */
5405 /* Build the "music" path */
5406 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5408 /* Allocate the path */
5409 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5411 /* Validate the "music" directory */
5412 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5414 #endif /* USE_MUSIC */
5416 /* Build the "help" path */
5417 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5419 /* Allocate the path */
5420 ANGBAND_DIR_XTRA_HELP = string_make(path);
5422 /* Validate the "help" directory */
5423 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5427 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
5429 static bool is_already_running(void)
5431 bool result = FALSE;
5434 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5435 if (GetLastError() == ERROR_ALREADY_EXISTS)
5444 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
5446 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5447 LPSTR lpCmdLine, int nCmdShow)
5455 setlocale(LC_ALL, "ja_JP.utf8");
5464 /* Prevent multiple run */
5465 if (is_already_running())
5468 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
5469 _("エラー!", "Error") ,
5470 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5474 if (hPrevInst == NULL)
5476 wc.style = CS_CLASSDC;
5477 wc.lpfnWndProc = AngbandWndProc;
5479 wc.cbWndExtra = 4; /* one long pointer to term_data */
5480 wc.hInstance = hInst;
5481 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5482 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5483 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5484 wc.lpszMenuName = AppName;
5485 wc.lpszClassName = AppName;
5487 if (!RegisterClass(&wc)) exit(1);
5489 wc.lpfnWndProc = AngbandListProc;
5490 wc.lpszMenuName = NULL;
5491 wc.lpszClassName = AngList;
5493 if (!RegisterClass(&wc)) exit(2);
5497 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5498 wc.lpfnWndProc = AngbandSaverProc;
5500 wc.lpszMenuName = NULL;
5501 wc.lpszClassName = "WindowsScreenSaverClass";
5503 if (!RegisterClass(&wc)) exit(3);
5509 /* Temporary hooks */
5510 plog_aux = hack_plog;
5511 quit_aux = hack_quit;
5512 core_aux = hack_quit;
5514 /* Prepare the filepaths */
5517 /* Initialize the keypress analyzer */
5518 for (i = 0; special_key_list[i]; ++i)
5520 special_key[special_key_list[i]] = TRUE;
5522 /* Initialize the keypress analyzer */
5523 for (i = 0; ignore_key_list[i]; ++i)
5525 ignore_key[ignore_key_list[i]] = TRUE;
5528 /* Determine if display is 16/256/true color */
5530 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5531 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5532 ReleaseDC(NULL, hdc);
5534 /* Initialize the colors */
5535 for (i = 0; i < 256; i++)
5539 /* Extract desired values */
5540 rv = angband_color_table[i][1];
5541 gv = angband_color_table[i][2];
5542 bv = angband_color_table[i][3];
5544 /* Extract the "complex" code */
5545 win_clr[i] = PALETTERGB(rv, gv, bv);
5547 /* Save the "simple" code */
5548 angband_color_table[i][0] = win_pal[i];
5551 /* Prepare the windows */
5557 /* Activate hooks */
5558 plog_aux = hook_plog;
5559 quit_aux = hook_quit;
5560 core_aux = hook_quit;
5562 /* Set the system suffix */
5563 ANGBAND_SYS = "win";
5565 /* Set the keyboard suffix */
5566 if (7 != GetKeyboardType(0))
5567 ANGBAND_KEYBOARD = "0";
5570 /* Japanese keyboard */
5571 switch (GetKeyboardType(1))
5573 case 0x0D01: case 0x0D02:
5574 case 0x0D03: case 0x0D04:
5575 case 0x0D05: case 0x0D06:
5577 ANGBAND_KEYBOARD = "NEC98";
5581 ANGBAND_KEYBOARD = "JAPAN";
5585 /* Catch nasty signals */
5588 Term_activate(term_screen);
5589 init_angband(p_ptr);
5591 /* We are now initialized */
5594 if(lpCmdLine[0] == '-'){
5595 switch(lpCmdLine[1])
5600 if (!lpCmdLine[2]) break;
5601 chuukei_server = TRUE;
5602 if(connect_chuukei_server(&lpCmdLine[2])<0){
5603 msg_print("connect fail");
5606 msg_print("connect");
5614 if (!lpCmdLine[2]) break;
5615 chuukei_client = TRUE;
5616 connect_chuukei_server(&lpCmdLine[2]);
5617 play_game(p_ptr, FALSE);
5624 if (!lpCmdLine[2]) break;
5625 prepare_browse_movie(&lpCmdLine[2]);
5626 play_game(p_ptr, FALSE);
5635 /* Did the user double click on a save file? */
5636 if(!chuukei_server) check_for_save_file(lpCmdLine);
5638 /* Did the user double click on a save file? */
5639 check_for_save_file(lpCmdLine);
5642 /* Prompt the user */
5643 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
5647 /* Process messages forever */
5648 while (GetMessage(&msg, NULL, 0, 0))
5650 TranslateMessage(&msg);
5651 DispatchMessage(&msg);
5658 #endif /* WINDOWS */