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;
707 #if 0 /* #ifndef JP */
708 static concptr ANGBAND_DIR_XTRA_FONT;
711 static concptr ANGBAND_DIR_XTRA_MUSIC;
716 * The "complex" color values
718 static COLORREF win_clr[256];
722 * Flag for macro trigger with dump ASCII
724 static bool Term_no_press = FALSE;
729 static bool mouse_down = FALSE;
730 static bool paint_rect = FALSE;
731 static TERM_LEN mousex = 0, mousey = 0;
732 static TERM_LEN oldx, oldy;
736 * @brief The "simple" color values
738 * See "main-ibm.c" for original table information
739 * The entries below are taken from the "color bits" defined above.
740 * Note that many of the choices below suck, but so do crappy monitors.
742 static BYTE win_pal[256] =
744 VID_BLACK, /* Dark */
745 VID_WHITE, /* White */
746 VID_CYAN, /* Slate XXX */
747 VID_RED | VID_BRIGHT, /* Orange XXX */
749 VID_GREEN, /* Green */
751 VID_YELLOW, /* Umber XXX */
752 VID_BLACK | VID_BRIGHT, /* Light Dark */
753 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
754 VID_MAGENTA, /* Violet XXX */
755 VID_YELLOW | VID_BRIGHT, /* Yellow */
756 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
757 VID_GREEN | VID_BRIGHT, /* Light Green */
758 VID_BLUE | VID_BRIGHT, /* Light Blue */
759 VID_YELLOW /* Light Umber XXX */
764 * Hack -- define which keys are "special"
766 static bool special_key[256];
767 static bool ignore_key[256];
771 * Hack -- initialization list for "special_key"
773 static byte special_key_list[] = {
774 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
775 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
776 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
777 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
778 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
779 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
780 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
781 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
782 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
783 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
784 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
785 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
786 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
787 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
788 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
789 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
790 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
795 static byte ignore_key_list[] = {
796 VK_ESCAPE, VK_TAB, VK_SPACE,
797 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
798 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
799 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
805 * Hack -- initialization list for "special_key"
807 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
808 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
809 * catch the keypad keys (with and without numlock set, including keypad 5),
810 * the function keys (including the "menu" key which maps to F10), and the
811 * "pause" key (between scroll lock and numlock). We also catch a few odd
812 * keys which I do not recognize, but which are listed among keys which we
813 * do catch, so they should be harmless to catch.
815 static byte special_key_list[] =
817 VK_CLEAR, /* 0x0C (KP<5>) */
819 VK_PAUSE, /* 0x13 (pause) */
821 VK_PRIOR, /* 0x21 (KP<9>) */
822 VK_NEXT, /* 0x22 (KP<3>) */
823 VK_END, /* 0x23 (KP<1>) */
824 VK_HOME, /* 0x24 (KP<7>) */
825 VK_LEFT, /* 0x25 (KP<4>) */
826 VK_UP, /* 0x26 (KP<8>) */
827 VK_RIGHT, /* 0x27 (KP<6>) */
828 VK_DOWN, /* 0x28 (KP<2>) */
829 VK_SELECT, /* 0x29 (?????) */
830 VK_PRINT, /* 0x2A (?????) */
831 VK_EXECUTE, /* 0x2B (?????) */
832 VK_SNAPSHOT, /* 0x2C (?????) */
833 VK_INSERT, /* 0x2D (KP<0>) */
834 VK_DELETE, /* 0x2E (KP<.>) */
835 VK_HELP, /* 0x2F (?????) */
837 VK_NUMPAD0, /* 0x60 (KP<0>) */
838 VK_NUMPAD1, /* 0x61 (KP<1>) */
839 VK_NUMPAD2, /* 0x62 (KP<2>) */
840 VK_NUMPAD3, /* 0x63 (KP<3>) */
841 VK_NUMPAD4, /* 0x64 (KP<4>) */
842 VK_NUMPAD5, /* 0x65 (KP<5>) */
843 VK_NUMPAD6, /* 0x66 (KP<6>) */
844 VK_NUMPAD7, /* 0x67 (KP<7>) */
845 VK_NUMPAD8, /* 0x68 (KP<8>) */
846 VK_NUMPAD9, /* 0x69 (KP<9>) */
847 VK_MULTIPLY, /* 0x6A (KP<*>) */
848 VK_ADD, /* 0x6B (KP<+>) */
849 VK_SEPARATOR, /* 0x6C (?????) */
850 VK_SUBTRACT, /* 0x6D (KP<->) */
851 VK_DECIMAL, /* 0x6E (KP<.>) */
852 VK_DIVIDE, /* 0x6F (KP</>) */
883 /* Function prototype */
885 static bool is_already_running(void);
889 static void delete_bg(void)
898 static int init_bg(void)
900 char * bmfile = bg_bitmap_file;
903 if (use_bg == 0) return 0;
905 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
907 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
915 static void DrawBG(HDC hdc, RECT *r)
920 int x = r->left, y = r->top;
921 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
927 GetObject(hBG, sizeof(bm), &bm);
928 swid = bm.bmWidth; shgt = bm.bmHeight;
930 hdcSrc = CreateCompatibleDC(hdc);
931 hOld = SelectObject(hdcSrc, hBG);
935 cwid = MIN(swid - sx, r->right - nx);
938 chgt = MIN(shgt - sy, r->bottom - ny);
939 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
941 } while (ny < r->bottom);
944 } while (nx < r->right);
946 SelectObject(hdcSrc, hOld);
952 * Hack -- given a pathname, point at the filename
954 static concptr extract_file_name(concptr s)
958 /* Start at the end */
959 p = s + strlen(s) - 1;
961 /* Back up to divider */
962 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
964 /* Return file name */
971 * Hack -- given a simple filename, extract the "font size" info
973 * Return a pointer to a static buffer holding the capitalized base name.
975 #if 0 /* #ifndef JP */
976 static char *analyze_font(char *path, int *wp, int *hp)
982 /* Start at the end */
983 p = path + strlen(path) - 1;
985 /* Back up to divider */
986 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
988 /* Advance to file name */
994 /* Capitalize (be paranoid) */
995 if (islower(*s)) *s = toupper(*s);
999 s = my_strchr(p, 'X');
1001 /* Extract font width */
1004 /* Extract height */
1005 hgt = s ? atoi(s+1) : 0;
1016 * Check for existance of a file
1018 static bool check_file(concptr s)
1028 unsigned int attrib;
1038 attrib = GetFileAttributes(path);
1040 /* Require valid filename */
1041 if (attrib == INVALID_FILE_NAME) return (FALSE);
1043 /* Prohibit directory */
1044 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
1048 /* Examine and verify */
1049 if (_dos_getfileattr(path, &attrib)) return (FALSE);
1051 /* Prohibit something */
1052 if (attrib & FA_LABEL) return (FALSE);
1054 /* Prohibit directory */
1055 if (attrib & FA_DIREC) return (FALSE);
1065 * Check for existance of a directory
1067 static bool check_dir(concptr s)
1079 unsigned int attrib;
1089 /* Remove trailing backslash */
1090 if (i && (path[i-1] == '\\')) path[--i] = '\0';
1095 attrib = GetFileAttributes(path);
1097 /* Require valid filename */
1098 if (attrib == INVALID_FILE_NAME) return (FALSE);
1100 /* Require directory */
1101 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
1105 /* Examine and verify */
1106 if (_dos_getfileattr(path, &attrib)) return (FALSE);
1108 /* Prohibit something */
1109 if (attrib & FA_LABEL) return (FALSE);
1111 /* Require directory */
1112 if (!(attrib & FA_DIREC)) return (FALSE);
1124 static void validate_file(concptr s)
1126 /* Verify or fail */
1129 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
1135 * Validate a directory
1137 static void validate_dir(concptr s, bool vital)
1139 /* Verify or fail */
1142 /* This directory contains needed data */
1145 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
1147 /* Attempt to create this directory */
1150 quit_fmt("Unable to create directory:\n%s", s);
1157 * @brief (Windows版固有実装)Get the "size" for a window
1159 static void term_getsize(term_data *td)
1163 if (td->cols < 1) td->cols = 1;
1164 if (td->rows < 1) td->rows = 1;
1167 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1168 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1170 /* Fake window size */
1172 rc.right = rc.left + wid;
1174 rc.bottom = rc.top + hgt;
1176 /* rc.right += 1; */
1177 /* rc.bottom += 1; */
1180 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1183 td->size_wid = rc.right - rc.left;
1184 td->size_hgt = rc.bottom - rc.top;
1186 /* See CreateWindowEx */
1189 /* Extract actual location */
1190 GetWindowRect(td->w, &rc);
1192 /* Save the location */
1193 td->pos_x = rc.left;
1199 * Write the "prefs" for a single term
1201 static void save_prefs_aux(int i)
1203 term_data *td = &data[i];
1204 GAME_TEXT sec_name[128];
1208 WINDOWPLACEMENT lpwndpl;
1211 /* Make section name */
1212 sprintf(sec_name, "Term-%d", i);
1217 strcpy(buf, td->visible ? "1" : "0");
1218 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1223 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "MS ゴシック");
1226 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1228 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1232 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1234 #if 1 /* #ifdef JP */
1235 wsprintf(buf, "%d", td->lf.lfWidth);
1236 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1237 wsprintf(buf, "%d", td->lf.lfHeight);
1238 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1239 wsprintf(buf, "%d", td->lf.lfWeight);
1240 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1243 strcpy(buf, td->bizarre ? "1" : "0");
1244 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1247 wsprintf(buf, "%d", td->tile_wid);
1248 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1251 wsprintf(buf, "%d", td->tile_hgt);
1252 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1254 /* Get window placement and dimensions */
1255 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1256 GetWindowPlacement(td->w, &lpwndpl);
1258 /* Acquire position in *normal* mode (not minimized) */
1259 rc = lpwndpl.rcNormalPosition;
1261 /* Window size (x) */
1262 if (i == 0) wsprintf(buf, "%d", normsize.x);
1263 else wsprintf(buf, "%d", td->cols);
1264 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1266 /* Window size (y) */
1267 if (i == 0) wsprintf(buf, "%d", normsize.y);
1268 else wsprintf(buf, "%d", td->rows);
1269 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1271 /* Maxmized (only main window) */
1274 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1275 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1278 /* Acquire position */
1279 GetWindowRect(td->w, &rc);
1281 /* Window position (x) */
1282 wsprintf(buf, "%d", rc.left);
1283 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1285 /* Window position (y) */
1286 wsprintf(buf, "%d", rc.top);
1287 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1289 /* Window Z position */
1292 strcpy(buf, td->posfix ? "1" : "0");
1293 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1300 * We assume that the windows have all been initialized
1302 static void save_prefs(void)
1308 /* Save the "arg_graphics" flag */
1309 sprintf(buf, "%d", arg_graphics);
1310 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1312 /* Save the "arg_bigtile" flag */
1313 strcpy(buf, arg_bigtile ? "1" : "0");
1314 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1316 /* Save the "arg_sound" flag */
1317 strcpy(buf, arg_sound ? "1" : "0");
1318 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1320 /* Save the "arg_sound" flag */
1321 strcpy(buf, arg_music ? "1" : "0");
1322 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1325 strcpy(buf, use_bg ? "1" : "0");
1326 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1327 WritePrivateProfileString("Angband", "BackGroundBitmap",
1328 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1330 /* Save window prefs */
1331 for (i = 0; i < MAX_TERM_DATA; ++i)
1339 * Load the "prefs" for a single term
1341 static void load_prefs_aux(int i)
1343 term_data *td = &data[i];
1344 GAME_TEXT sec_name[128];
1347 int wid, hgt, posx, posy;
1348 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1349 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1353 /* Make section name */
1354 sprintf(sec_name, "Term-%d", i);
1356 /* Make section name */
1357 sprintf(sec_name, "Term-%d", i);
1362 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1365 /* Desired font, with default */
1367 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1370 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1372 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1378 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1380 /* Analyze font, save desired font name */
1381 #if 1 /* #ifdef JP */
1382 td->font_want = string_make(tmp);
1384 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1385 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1386 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1388 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1393 #if 1 /* #ifdef JP */
1394 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1395 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1397 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1398 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1403 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1404 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1405 normsize.x = td->cols; normsize.y = td->rows;
1410 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
1413 /* Window position */
1414 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1415 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1416 td->pos_x = MIN(MAX(0, posx), dispx-128);
1417 td->pos_y = MIN(MAX(0, posy), dispy-128);
1419 /* Window Z position */
1422 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
1430 static void load_prefs(void)
1434 /* Extract the "arg_graphics" flag */
1435 arg_graphics = (byte_hack)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1437 /* Extract the "arg_bigtile" flag */
1438 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
1439 use_bigtile = arg_bigtile;
1441 /* Extract the "arg_sound" flag */
1442 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1444 /* Extract the "arg_sound" flag */
1445 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1448 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1449 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1451 /* Load window prefs */
1452 for (i = 0; i < MAX_TERM_DATA; ++i)
1458 #if defined(USE_SOUND) || defined(USE_MUSIC)
1461 * - Taken from files.c.
1463 * Extract "tokens" from a buffer
1465 * This function uses "whitespace" as delimiters, and treats any amount of
1466 * whitespace as a single delimiter. We will never return any empty tokens.
1467 * When given an empty buffer, or a buffer containing only "whitespace", we
1468 * will return no tokens. We will never extract more than "num" tokens.
1470 * By running a token through the "text_to_ascii()" function, you can allow
1471 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1473 * We save pointers to the tokens in "tokens", and return the number found.
1475 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1485 /* Skip leading whitespace */
1486 for ( ; *s && iswspace(*s); ++s) /* loop */;
1491 /* Find next whitespace, if any */
1492 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1494 /* Nuke and advance (if necessary) */
1495 if (*t) *t++ = '\0';
1497 /* Save the token */
1508 #endif /* USE_SOUND || USE_MUSIC */
1512 static void load_sound_prefs(void)
1516 char ini_path[1024];
1517 char wav_path[1024];
1518 char *zz[SAMPLE_SOUND_MAX];
1520 /* Access the sound.cfg */
1522 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1524 for (i = 0; i < SOUND_MAX; i++)
1526 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1528 num = tokenize_whitespace(tmp, SAMPLE_SOUND_MAX, zz);
1530 for (j = 0; j < num; j++)
1532 /* Access the sound */
1533 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1535 /* Save the sound filename, if it exists */
1536 if (check_file(wav_path))
1537 sound_file[i][j] = string_make(zz[j]);
1542 #endif /* USE_SOUND */
1546 static void load_music_prefs(void)
1550 char ini_path[1024];
1551 char wav_path[1024];
1552 char *zz[SAMPLE_MUSIC_MAX];
1555 /* Access the music.cfg */
1557 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1559 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1561 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1563 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1565 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1567 for (j = 0; j < num; j++)
1569 /* Access the sound */
1570 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1572 /* Save the sound filename, if it exists */
1573 if (check_file(wav_path))
1574 music_file[i][j] = string_make(zz[j]);
1578 for (i = 0; i < current_world_ptr->max_d_idx; i++)
1580 sprintf(key, "dungeon%03d", i);
1581 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1583 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1585 for (j = 0; j < num; j++)
1587 /* Access the sound */
1588 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1590 /* Save the sound filename, if it exists */
1591 if (check_file(wav_path))
1592 dungeon_music_file[i][j] = string_make(zz[j]);
1596 for (i = 0; i < max_q_idx; i++)
1598 sprintf(key, "quest%03d", i);
1599 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1601 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1603 for (j = 0; j < num; j++)
1605 /* Access the sound */
1606 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1608 /* Save the sound filename, if it exists */
1609 if (check_file(wav_path))
1610 quest_music_file[i][j] = string_make(zz[j]);
1614 for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1616 sprintf(key, "town%03d", i);
1617 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1619 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1621 for (j = 0; j < num; j++)
1623 /* Access the sound */
1624 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1626 /* Save the sound filename, if it exists */
1627 if (check_file(wav_path))
1628 town_music_file[i][j] = string_make(zz[j]);
1635 #endif /* USE_MUSIC */
1638 * Create the new global palette based on the bitmap palette
1639 * (if any), and the standard 16 entry palette derived from
1640 * "win_clr[]" which is used for the basic 16 Angband colors.
1642 * This function is never called before all windows are ready.
1644 * This function returns FALSE if the new palette could not be
1645 * prepared, which should normally be a fatal error. XXX XXX
1647 * Note that only some machines actually use a "palette".
1649 static int new_palette(void)
1657 LPLOGPALETTE pLogPal;
1658 LPPALETTEENTRY lppe;
1663 /* This makes no sense */
1664 if (!paletted) return (TRUE);
1674 /* Check the bitmap palette */
1675 hBmPal = infGraph.hPalette;
1677 /* Use the bitmap */
1680 lppeSize = 256 * sizeof(PALETTEENTRY);
1681 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1682 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1683 if ((nEntries == 0) || (nEntries > 220))
1686 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1689 rnfree(lppe, lppeSize);
1696 #endif /* USE_GRAPHICS */
1698 /* Size of palette */
1699 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1701 /* Allocate palette */
1702 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1705 pLogPal->palVersion = 0x300;
1707 /* Make room for bitmap and normal data */
1708 pLogPal->palNumEntries = nEntries + 16;
1710 /* Save the bitmap data */
1711 for (i = 0; i < nEntries; i++)
1713 pLogPal->palPalEntry[i] = lppe[i];
1716 /* Save the normal data */
1717 for (i = 0; i < 16; i++)
1721 /* Access the entry */
1722 p = &(pLogPal->palPalEntry[i+nEntries]);
1724 /* Save the colors */
1725 p->peRed = GetRValue(win_clr[i]);
1726 p->peGreen = GetGValue(win_clr[i]);
1727 p->peBlue = GetBValue(win_clr[i]);
1729 /* Save the flags */
1730 p->peFlags = PC_NOCOLLAPSE;
1733 /* Free something */
1734 if (lppe) rnfree(lppe, lppeSize);
1736 /* Create a new palette, or fail */
1737 hNewPal = CreatePalette(pLogPal);
1738 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1740 /* Free the palette */
1741 rnfree(pLogPal, pLogPalSize);
1746 /* Realize the palette */
1748 SelectPalette(hdc, hNewPal, 0);
1749 i = RealizePalette(hdc);
1750 ReleaseDC(td->w, hdc);
1751 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1755 for (i = 1; i < MAX_TERM_DATA; i++)
1760 SelectPalette(hdc, hNewPal, 0);
1761 ReleaseDC(td->w, hdc);
1764 /* Delete old palette */
1765 if (hPal) DeleteObject(hPal);
1767 /* Save new palette */
1777 * @brief グラフィクスを初期化する / Initialize graphics
1780 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1781 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1784 static bool init_graphics(void)
1786 /* Initialize once */
1788 BYTE wid, hgt, twid, thgt, ox, oy;
1791 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1801 ANGBAND_GRAF = "new";
1803 else if (arg_graphics == GRAPHICS_HENGBAND)
1823 ANGBAND_GRAF = "ne2";
1834 ANGBAND_GRAF = "old";
1837 /* Access the bitmap file */
1838 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1840 /* Load the bitmap or quit */
1841 if (!ReadDIB(data[0].w, buf, &infGraph))
1843 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1847 /* Save the new sizes */
1848 infGraph.CellWidth = wid;
1849 infGraph.CellHeight = hgt;
1850 infGraph.TileWidth = twid;
1851 infGraph.TileHeight = thgt;
1852 infGraph.OffsetX = ox;
1853 infGraph.OffsetY = oy;
1855 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1857 /* Access the mask file */
1858 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1860 /* Load the bitmap or quit */
1861 if (!ReadDIB(data[0].w, buf, &infMask))
1863 plog_fmt("Cannot read bitmap file '%s'", buf);
1867 if (arg_graphics == GRAPHICS_HENGBAND)
1869 /* Access the mask file */
1870 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1872 /* Load the bitmap or quit */
1873 if (!ReadDIB(data[0].w, buf, &infMask))
1875 plog_fmt("Cannot read bitmap file '%s'", buf);
1880 /* Activate a palette */
1885 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1889 /* Graphics available */
1890 current_graphics_mode = arg_graphics;
1891 return (current_graphics_mode);
1893 #endif /* USE_GRAPHICS */
1900 static bool init_music(void)
1902 /* Initialize once */
1905 /* Load the prefs */
1908 /* Sound available */
1909 can_use_music = TRUE;
1911 return (can_use_music);
1915 * Hack -- Stop a music
1917 static void stop_music(void)
1919 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1920 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1923 #endif /* USE_MUSIC */
1929 static bool init_sound(void)
1931 /* Initialize once */
1934 /* Load the prefs */
1937 /* Sound available */
1938 can_use_sound = TRUE;
1940 return (can_use_sound);
1942 #endif /* USE_SOUND */
1948 static void term_window_resize(term_data *td)
1950 /* Require window */
1953 /* Resize the window */
1954 SetWindowPos(td->w, 0, 0, 0,
1955 td->size_wid, td->size_hgt,
1956 SWP_NOMOVE | SWP_NOZORDER);
1959 InvalidateRect(td->w, NULL, TRUE);
1964 * Force the use of a new "font file" for a term_data
1966 * This function may be called before the "window" is ready
1968 * This function returns zero only if everything succeeds.
1970 * Note that the "font name" must be capitalized!!!
1972 static errr term_force_font(term_data *td, concptr path)
1976 #if 0 /* #ifndef JP */
1982 /* Forget the old font (if needed) */
1983 if (td->font_id) DeleteObject(td->font_id);
1985 #if 1 /* #ifdef JP */
1989 /* Create the font (using the 'base' of the font file name!) */
1990 td->font_id = CreateFontIndirect(&(td->lf));
1991 wid = td->lf.lfWidth;
1992 hgt = td->lf.lfHeight;
1993 if (!td->font_id) return (1);
1995 /* Forget old font */
2001 for (i = 0; i < MAX_TERM_DATA; i++)
2003 /* Don't check when closing the application */
2006 /* Check "screen" */
2007 if ((td != &data[i]) &&
2008 (data[i].font_file) &&
2009 (streq(data[i].font_file, td->font_file)))
2015 /* Remove unused font resources */
2016 if (!used) RemoveFontResource(td->font_file);
2018 /* Free the old name */
2019 string_free(td->font_file);
2022 td->font_file = NULL;
2026 if (!path) return (1);
2031 /* Analyze font path */
2032 base = analyze_font(buf, &wid, &hgt);
2035 if (!suffix(base, ".FON")) return (1);
2038 if (!check_file(buf)) return (1);
2040 /* Load the new font */
2041 if (!AddFontResource(buf)) return (1);
2043 /* Save new font name */
2044 td->font_file = string_make(base);
2046 /* Remove the "suffix" */
2047 base[strlen(base)-4] = '\0';
2049 /* Create the font (using the 'base' of the font file name!) */
2050 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
2051 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
2052 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
2053 FIXED_PITCH | FF_DONTCARE, base);
2056 /* Hack -- Unknown size */
2063 /* all this trouble to get the cell size */
2064 hdcDesktop = GetDC(HWND_DESKTOP);
2065 hfOld = SelectObject(hdcDesktop, td->font_id);
2066 GetTextMetrics(hdcDesktop, &tm);
2067 SelectObject(hdcDesktop, hfOld);
2068 ReleaseDC(HWND_DESKTOP, hdcDesktop);
2070 /* Font size info */
2071 wid = tm.tmAveCharWidth;
2075 /* Save the size info */
2086 * Allow the user to change the font for this window.
2088 static void term_change_font(term_data *td)
2090 #if 1 /* #ifdef JP */
2093 memset(&cf, 0, sizeof(cf));
2094 cf.lStructSize = sizeof(cf);
2095 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
2096 cf.lpLogFont = &(td->lf);
2098 if (ChooseFont(&cf))
2100 /* Force the font */
2101 term_force_font(td, NULL);
2103 /* Assume not bizarre */
2106 /* Reset the tile info */
2107 td->tile_wid = td->font_wid;
2108 td->tile_hgt = td->font_hgt;
2110 /* Analyze the font */
2113 /* Resize the window */
2114 term_window_resize(td);
2120 char tmp[1024] = "";
2122 /* Extract a default if possible */
2123 if (td->font_file) strcpy(tmp, td->font_file);
2125 /* Ask for a choice */
2126 memset(&ofn, 0, sizeof(ofn));
2127 ofn.lStructSize = sizeof(ofn);
2128 ofn.hwndOwner = data[0].w;
2129 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
2130 ofn.nFilterIndex = 1;
2131 ofn.lpstrFile = tmp;
2133 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
2134 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2135 ofn.lpstrDefExt = "fon";
2137 /* Force choice if legal */
2138 if (GetOpenFileName(&ofn))
2140 /* Force the font */
2141 if (term_force_font(td, tmp))
2143 /* Access the standard font file */
2144 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2146 /* Force the use of that font */
2147 (void)term_force_font(td, tmp);
2150 /* Assume not bizarre */
2151 td->bizarre = FALSE;
2153 /* Reset the tile info */
2154 td->tile_wid = td->font_wid;
2155 td->tile_hgt = td->font_hgt;
2157 /* Analyze the font */
2160 /* Resize the window */
2161 term_window_resize(td);
2168 * Allow the user to lock this window.
2170 static void term_window_pos(term_data *td, HWND hWnd)
2172 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2173 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2176 static void windows_map(void);
2179 * Hack -- redraw a term_data
2181 static void term_data_redraw(term_data *td)
2185 /* Redraw the map */
2190 /* Activate the term */
2191 Term_activate(&td->t);
2193 /* Redraw the contents */
2196 /* Restore the term */
2197 Term_activate(term_screen);
2202 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2206 HBRUSH myBrush, oldBrush;
2208 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2209 int tx = td->size_ow1 + x * td->tile_wid;
2210 int ty = td->size_oh1 + y * td->tile_hgt;
2211 int tw = w * td->tile_wid - 1;
2212 int th = h * td->tile_hgt - 1;
2215 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2216 oldBrush = SelectObject(hdc, myBrush);
2217 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2219 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2221 SelectObject(hdc, oldBrush);
2222 SelectObject(hdc, oldPen);
2227 /*** Function hooks needed by "Term" ***/
2233 * Initialize a new Term
2235 static void Term_init_win(term *t)
2244 static void Term_nuke_win(term *t)
2253 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
2255 static errr Term_user_win(int n)
2266 * React to global changes
2268 static errr Term_xtra_win_react(void)
2275 /* Save the default colors */
2276 for (i = 0; i < 256; i++)
2278 /* Simply accept the desired colors */
2279 win_pal[i] = angband_color_table[i][0];
2290 bool change = FALSE;
2292 /* Save the default colors */
2293 for (i = 0; i < 256; i++)
2295 /* Extract desired values */
2296 rv = angband_color_table[i][1];
2297 gv = angband_color_table[i][2];
2298 bv = angband_color_table[i][3];
2300 /* Extract a full color code */
2301 code = PALETTERGB(rv, gv, bv);
2303 /* Activate changes */
2304 if (win_clr[i] != code)
2306 /* Note the change */
2309 /* Apply the desired color */
2314 /* Activate the palette if needed */
2315 if (change) (void)new_palette();
2321 /* Handle "arg_sound" */
2322 if (use_sound != arg_sound)
2324 /* Initialize (if needed) */
2325 if (arg_sound && !init_sound())
2328 plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
2334 /* Change setting */
2335 use_sound = arg_sound;
2342 /* Handle "arg_sound" */
2343 if (use_music != arg_music)
2345 /* Initialize (if needed) */
2346 if (arg_music && !init_music())
2349 plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
2354 /* Change setting */
2355 use_music = arg_music;
2357 if(!arg_music) stop_music();
2358 else select_floor_music(p_ptr);
2367 /* Handle "arg_graphics" */
2368 if (use_graphics != arg_graphics)
2370 /* Initialize (if needed) */
2371 if (arg_graphics && !init_graphics())
2374 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
2377 arg_graphics = GRAPHICS_NONE;
2380 /* Change setting */
2381 use_graphics = arg_graphics;
2384 #ifdef ANGBAND_2_8_1
2386 #else /* ANGBAND_2_8_1 */
2387 reset_visuals(TRUE);
2388 #endif /* ANGBAND_2_8_1 */
2391 #endif /* USE_GRAPHICS */
2394 /* Clean up windows */
2395 for (i = 0; i < MAX_TERM_DATA; i++)
2399 term_data *td = &data[i];
2401 /* Update resized windows */
2402 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
2405 Term_activate(&td->t);
2407 /* Hack -- Resize the term */
2408 Term_resize(td->cols, td->rows);
2410 /* Redraw the contents */
2423 * Process at least one event
2425 static errr Term_xtra_win_event(int v)
2429 /* Wait for an event */
2433 if (GetMessage(&msg, NULL, 0, 0))
2435 TranslateMessage(&msg);
2436 DispatchMessage(&msg);
2440 /* Check for an event */
2444 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2446 TranslateMessage(&msg);
2447 DispatchMessage(&msg);
2457 * Process all pending events
2459 static errr Term_xtra_win_flush(void)
2463 /* Process all pending events */
2464 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2466 TranslateMessage(&msg);
2467 DispatchMessage(&msg);
2476 * Hack -- clear the screen
2478 * Make this more efficient
2480 static errr Term_xtra_win_clear(void)
2482 term_data *td = (term_data*)(Term->data);
2487 /* Rectangle to erase */
2488 rc.left = td->size_ow1;
2489 rc.right = rc.left + td->cols * td->tile_wid;
2490 rc.top = td->size_oh1;
2491 rc.bottom = rc.top + td->rows * td->tile_hgt;
2495 SetBkColor(hdc, RGB(0, 0, 0));
2496 SelectObject(hdc, td->font_id);
2497 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2502 rc.left = 0; rc.top = 0;
2505 ReleaseDC(td->w, hdc);
2513 * Hack -- make a noise
2515 static errr Term_xtra_win_noise(void)
2517 MessageBeep(MB_ICONASTERISK);
2523 * Hack -- make a sound
2525 static errr Term_xtra_win_sound(int v)
2530 #endif /* USE_SOUND */
2532 /* Sound disabled */
2533 if (!use_sound) return (1);
2536 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2540 /* Count the samples */
2541 for (i = 0; i < SAMPLE_SOUND_MAX; i++)
2543 if (!sound_file[v][i])
2548 if (i == 0) return (1);
2550 /* Build the path */
2551 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2555 /* Play the sound, catch errors */
2556 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2560 /* Play the sound, catch errors */
2561 return (sndPlaySound(buf, SND_ASYNC));
2565 #else /* USE_SOUND */
2569 #endif /* USE_SOUND */
2573 * Hack -- play a music
2575 static errr Term_xtra_win_music(int n, int v)
2580 #endif /* USE_MUSIC */
2582 /* Sound disabled */
2583 if (n == TERM_XTRA_MUSIC_MUTE)
2585 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2586 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2589 if(!use_music) return (1);
2592 if(n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return (1);
2593 else if(v < 0 || v >= 1000) return(1); /*!< TODO */
2599 case TERM_XTRA_MUSIC_BASIC:
2600 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if(!music_file[v][i]) break;
2602 case TERM_XTRA_MUSIC_DUNGEON:
2603 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if(!dungeon_music_file[v][i]) break;
2605 case TERM_XTRA_MUSIC_QUEST:
2606 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if(!quest_music_file[v][i]) break;
2608 case TERM_XTRA_MUSIC_TOWN:
2609 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if(!town_music_file[v][i]) break;
2621 case TERM_XTRA_MUSIC_BASIC:
2622 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2624 case TERM_XTRA_MUSIC_DUNGEON:
2625 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2627 case TERM_XTRA_MUSIC_QUEST:
2628 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2630 case TERM_XTRA_MUSIC_TOWN:
2631 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2635 if(current_music_type == n && current_music_id == v)
2639 current_music_type = n;
2640 current_music_id = v;
2644 mop.lpstrDeviceType = mci_device_type;
2645 mop.lpstrElementName = buf;
2646 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2647 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2648 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2649 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2650 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2655 #else /* USE_MUSIC */
2659 #endif /* USE_MUSIC */
2665 * Delay for "x" milliseconds
2667 static int Term_xtra_win_delay(int v)
2681 t = GetTickCount() + v;
2684 while (GetTickCount() < t)
2686 /* Handle messages */
2687 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2689 TranslateMessage(&msg);
2690 DispatchMessage(&msg);
2702 * Do a "special thing"
2704 static errr Term_xtra_win(int n, int v)
2706 /* Handle a subset of the legal requests */
2709 /* Make a bell sound */
2710 case TERM_XTRA_NOISE:
2712 return (Term_xtra_win_noise());
2716 case TERM_XTRA_MUSIC_BASIC:
2717 case TERM_XTRA_MUSIC_DUNGEON:
2718 case TERM_XTRA_MUSIC_QUEST:
2719 case TERM_XTRA_MUSIC_TOWN:
2721 return (Term_xtra_win_music(n, v));
2724 /* Make a special sound */
2725 case TERM_XTRA_SOUND:
2727 return (Term_xtra_win_sound(v));
2730 /* Process random events */
2731 case TERM_XTRA_BORED:
2733 return (Term_xtra_win_event(0));
2736 /* Process an event */
2737 case TERM_XTRA_EVENT:
2739 return (Term_xtra_win_event(v));
2742 /* Flush all events */
2743 case TERM_XTRA_FLUSH:
2745 return (Term_xtra_win_flush());
2748 /* Clear the screen */
2749 case TERM_XTRA_CLEAR:
2751 return (Term_xtra_win_clear());
2754 /* React to global changes */
2755 case TERM_XTRA_REACT:
2757 return (Term_xtra_win_react());
2760 /* Delay for some milliseconds */
2761 case TERM_XTRA_DELAY:
2763 return (Term_xtra_win_delay(v));
2773 * Low level graphics (Assumes valid input).
2775 * Draw a "cursor" at (x,y), using a "yellow box".
2777 static errr Term_curs_win(int x, int y)
2779 term_data *td = (term_data*)(Term->data);
2784 int tile_wid, tile_hgt;
2788 tile_wid = td->map_tile_wid;
2789 tile_hgt = td->map_tile_hgt;
2793 tile_wid = td->tile_wid;
2794 tile_hgt = td->tile_hgt;
2797 /* Frame the grid */
2798 rc.left = x * tile_wid + td->size_ow1;
2799 rc.right = rc.left + tile_wid;
2800 rc.top = y * tile_hgt + td->size_oh1;
2801 rc.bottom = rc.top + tile_hgt;
2803 /* Cursor is done as a yellow "box" */
2805 FrameRect(hdc, &rc, hbrYellow);
2806 ReleaseDC(td->w, hdc);
2814 * Low level graphics (Assumes valid input).
2816 * Draw a "big cursor" at (x,y), using a "yellow box".
2818 static errr Term_bigcurs_win(int x, int y)
2820 term_data *td = (term_data*)(Term->data);
2825 int tile_wid, tile_hgt;
2829 /* Normal cursor in map window */
2830 Term_curs_win(x, y);
2835 tile_wid = td->tile_wid;
2836 tile_hgt = td->tile_hgt;
2839 /* Frame the grid */
2840 rc.left = x * tile_wid + td->size_ow1;
2841 rc.right = rc.left + 2 * tile_wid;
2842 rc.top = y * tile_hgt + td->size_oh1;
2843 rc.bottom = rc.top + tile_hgt;
2845 /* Cursor is done as a yellow "box" */
2847 FrameRect(hdc, &rc, hbrYellow);
2848 ReleaseDC(td->w, hdc);
2856 * Low level graphics (Assumes valid input).
2858 * Erase a "block" of "n" characters starting at (x,y).
2860 static errr Term_wipe_win(int x, int y, int n)
2862 term_data *td = (term_data*)(Term->data);
2867 /* Rectangle to erase in client coords */
2868 rc.left = x * td->tile_wid + td->size_ow1;
2869 rc.right = rc.left + n * td->tile_wid;
2870 rc.top = y * td->tile_hgt + td->size_oh1;
2871 rc.bottom = rc.top + td->tile_hgt;
2874 SetBkColor(hdc, RGB(0, 0, 0));
2875 SelectObject(hdc, td->font_id);
2880 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2881 ReleaseDC(td->w, hdc);
2889 * Low level graphics. Assumes valid input.
2891 * Draw several ("n") chars, with an attr, at a given location.
2893 * All "graphic" data is handled by "Term_pict_win()", below.
2895 * One would think there is a more efficient method for telling a window
2896 * what color it should be using to draw with, but perhaps simply changing
2897 * it every time is not too inefficient.
2899 static errr Term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
2901 term_data *td = (term_data*)(Term->data);
2905 #if 1 /* #ifdef JP */
2906 static HBITMAP WALL;
2907 static HBRUSH myBrush, oldBrush;
2909 static bool init_done = FALSE;
2912 WALL = LoadBitmap(hInstance, AppName);
2913 myBrush = CreatePatternBrush(WALL);
2918 /* Total rectangle */
2919 rc.left = x * td->tile_wid + td->size_ow1;
2920 rc.right = rc.left + n * td->tile_wid;
2921 rc.top = y * td->tile_hgt + td->size_oh1;
2922 rc.bottom = rc.top + td->tile_hgt;
2927 /* Background color */
2928 SetBkColor(hdc, RGB(0, 0, 0));
2930 /* Foreground color */
2933 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2937 SetTextColor(hdc, win_clr[a&0x0F]);
2941 SetTextColor(hdc, win_clr[a]);
2945 SelectObject(hdc, td->font_id);
2948 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2952 (td->tile_hgt != td->font_hgt) ||
2953 (td->tile_wid != td->font_wid))
2957 /* Erase complete rectangle */
2958 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2961 if (use_bg) DrawBG(hdc, &rc);
2964 rc.left += ((td->tile_wid - td->font_wid) / 2);
2965 rc.right = rc.left + td->font_wid;
2966 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2967 rc.bottom = rc.top + td->font_hgt;
2969 /* Dump each character */
2970 for (i = 0; i < n; i++)
2973 if (use_bigtile && *(s+i)=="■"[0] && *(s+i+1)=="■"[1])
2975 rc.right += td->font_wid;
2977 oldBrush = SelectObject(hdc, myBrush);
2978 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2981 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2983 SelectObject(hdc, oldBrush);
2984 SelectObject(hdc, oldPen);
2985 rc.right -= td->font_wid;
2989 rc.left += 2 * td->tile_wid;
2990 rc.right += 2 * td->tile_wid;
2992 else if ( iskanji(*(s+i)) ) /* 2バイト文字 */
2994 rc.right += td->font_wid;
2996 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2998 rc.right -= td->font_wid;
3002 rc.left += 2 * td->tile_wid;
3003 rc.right += 2 * td->tile_wid;
3004 } else if (*(s+i)==127){
3005 oldBrush = SelectObject(hdc, myBrush);
3006 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
3009 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
3011 SelectObject(hdc, oldBrush);
3012 SelectObject(hdc, oldPen);
3015 rc.left += td->tile_wid;
3016 rc.right += td->tile_wid;
3019 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
3022 rc.left += td->tile_wid;
3023 rc.right += td->tile_wid;
3028 oldBrush = SelectObject(hdc, myBrush);
3029 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
3032 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
3034 SelectObject(hdc, oldBrush);
3035 SelectObject(hdc, oldPen);
3038 rc.left += td->tile_wid;
3039 rc.right += td->tile_wid;
3042 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
3046 rc.left += td->tile_wid;
3047 rc.right += td->tile_wid;
3051 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
3055 rc.left += td->tile_wid;
3056 rc.right += td->tile_wid;
3067 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
3072 ReleaseDC(td->w, hdc);
3080 * Low level graphics. Assumes valid input.
3082 * Draw an array of "special" attr/char pairs at the given location.
3084 * We use the "Term_pict_win()" function for "graphic" data, which are
3085 * encoded by setting the "high-bits" of both the "attr" and the "char"
3086 * data. We use the "attr" to represent the "row" of the main bitmap,
3087 * and the "char" to represent the "col" of the main bitmap. The use
3088 * of this function is induced by the "higher_pict" flag.
3090 * If "graphics" is not available, we simply "wipe" the given grids.
3092 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)
3094 term_data *td = (term_data*)(Term->data);
3099 TERM_LEN x1, y1, w1, h1, tw1, th1;
3100 TERM_LEN x2, y2, w2, h2, tw2 = 0;
3110 /* Erase the grids */
3111 return (Term_wipe_win(x, y, n));
3114 /* Size of bitmap cell */
3115 w1 = infGraph.CellWidth;
3116 h1 = infGraph.CellHeight;
3117 tw1 = infGraph.TileWidth;
3118 th1 = infGraph.TileHeight;
3120 /* Size of window cell */
3123 w2 = td->map_tile_wid;
3124 h2 = td->map_tile_hgt;
3133 if (use_bigtile) tw2 *= 2;
3136 /* Location of window cell */
3137 x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
3138 y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
3144 hdcSrc = CreateCompatibleDC(hdc);
3145 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
3147 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3149 hdcMask = CreateCompatibleDC(hdc);
3150 SelectObject(hdcMask, infMask.hBitmap);
3153 /* Draw attr/char pairs */
3154 for (i = 0; i < n; i++, x2 += w2)
3156 TERM_COLOR a = ap[i];
3160 /* Extract picture */
3161 int row = (a & 0x7F);
3162 int col = (c & 0x7F);
3164 /* Location of bitmap cell */
3168 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3170 x3 = (tcp[i] & 0x7F) * w1;
3171 y3 = (tap[i] & 0x7F) * h1;
3172 tw2 = tw2 * w1 / tw1;
3176 if ((tw1 == tw2) && (th1 == h2))
3178 /* Copy the terrain picture from the bitmap to the window */
3179 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
3181 /* Mask out the tile */
3182 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3185 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3188 /* Need to stretch */
3191 /* Set the correct mode for stretching the tiles */
3192 SetStretchBltMode(hdc, COLORONCOLOR);
3194 /* Copy the terrain picture from the bitmap to the window */
3195 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
3197 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
3199 /* Only draw if terrain and overlay are different */
3200 if ((x1 != x3) || (y1 != y3))
3202 /* Mask out the tile */
3203 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3206 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3213 if ((w1 == tw2) && (h1 == h2))
3215 /* Copy the picture from the bitmap to the window */
3216 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3219 /* Need to stretch */
3222 /* Set the correct mode for stretching the tiles */
3223 SetStretchBltMode(hdc, COLORONCOLOR);
3225 /* Copy the picture from the bitmap to the window */
3226 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3232 SelectObject(hdcSrc, hbmSrcOld);
3235 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3238 SelectObject(hdcMask, hbmSrcOld);
3243 ReleaseDC(td->w, hdc);
3245 #else /* USE_GRAPHICS */
3247 /* Just erase this grid */
3248 return (Term_wipe_win(x, y, n));
3250 #endif /* USE_GRAPHICS */
3257 static void windows_map(void)
3259 term_data *td = &data[0];
3262 TERM_LEN x, min_x, max_x;
3263 TERM_LEN y, min_y, max_y;
3268 /* Only in graphics mode */
3269 if (!use_graphics) return;
3270 Term_xtra_win_clear();
3272 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3273 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3274 td->map_active = TRUE;
3279 max_x = p_ptr->current_floor_ptr->width;
3280 max_y = p_ptr->current_floor_ptr->height;
3284 for (x = min_x; x < max_x; x++)
3286 for (y = min_y; y < max_y; y++)
3288 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3290 /* Ignore non-graphics */
3291 if ((a & 0x80) && (c & 0x80))
3293 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3298 /* Hilite the player */
3299 Term_curs_win(p_ptr->x - min_x, p_ptr->y - min_y);
3301 /* Wait for a keypress, flush key buffer */
3302 Term_inkey(&c, TRUE, TRUE);
3305 /* Switch off the map display */
3306 td->map_active = FALSE;
3308 /* Restore screen */
3309 Term_xtra_win_clear();
3314 /*** Other routines ***/
3318 * Create and initialize a "term_data" given a title
3320 static void term_data_link(term_data *td)
3324 /* Initialize the term */
3325 term_init(t, td->cols, td->rows, td->keys);
3327 /* Use a "software" cursor */
3328 t->soft_cursor = TRUE;
3330 /* Use "Term_pict" for "graphic" data */
3331 t->higher_pict = TRUE;
3333 /* Erase with "white space" */
3334 t->attr_blank = TERM_WHITE;
3335 t->char_blank = ' ';
3338 /* Prepare the init/nuke hooks */
3339 t->init_hook = Term_init_win;
3340 t->nuke_hook = Term_nuke_win;
3343 /* Prepare the template hooks */
3344 t->user_hook = Term_user_win;
3345 t->xtra_hook = Term_xtra_win;
3346 t->curs_hook = Term_curs_win;
3347 t->bigcurs_hook = Term_bigcurs_win;
3348 t->wipe_hook = Term_wipe_win;
3349 t->text_hook = Term_text_win;
3350 t->pict_hook = Term_pict_win;
3352 /* Remember where we came from */
3353 t->data = (vptr)(td);
3358 * Create the windows
3360 * First, instantiate the "default" values, then read the "ini_file"
3361 * to over-ride selected values, then create the windows, and fonts.
3363 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3364 * must make active to realize the palette.
3366 static void init_windows(void)
3372 #if 0 /* #ifndef JP */
3378 WIPE(td, term_data);
3382 td->s = angband_term_name[0];
3396 #if 1 /* #ifdef JP */
3400 for (i = 1; i < MAX_TERM_DATA; i++)
3403 WIPE(td, term_data);
3404 td->s = angband_term_name[i];
3408 td->visible = FALSE;
3413 td->pos_x = (7 - i) * 30;
3414 td->pos_y = (7 - i) * 20;
3416 #if 1 /* #ifdef JP */
3426 /* Main window (need these before term_getsize gets called) */
3428 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3429 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3434 /* Sub windows (need these before term_getsize gets called) */
3435 for (i = 1; i < MAX_TERM_DATA; i++)
3438 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3439 td->dwExStyle = (WS_EX_TOOLWINDOW);
3444 for (i = 0; i < MAX_TERM_DATA; i++)
3448 #if 1 /* #ifdef JP */
3449 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3450 td->lf.lfCharSet = DEFAULT_CHARSET;
3451 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3452 /* Activate the chosen font */
3453 term_force_font(td, NULL);
3454 if(!td->tile_wid) td->tile_wid = td->font_wid;
3455 if(!td->tile_hgt) td->tile_hgt = td->font_hgt;
3457 /* Access the standard font file */
3458 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3460 /* Activate the chosen font */
3461 if (term_force_font(td, buf))
3463 /* Access the standard font file */
3464 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3466 /* Force the use of that font */
3467 (void)term_force_font(td, buf);
3472 /* Assume not bizarre */
3473 td->bizarre = FALSE;
3478 /* Analyze the font */
3481 /* Resize the window */
3482 term_window_resize(td);
3486 /* Sub windows (reverse order) */
3487 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3492 td->w = CreateWindowEx(td->dwExStyle, AngList,
3494 td->pos_x, td->pos_y,
3495 td->size_wid, td->size_hgt,
3496 HWND_DESKTOP, NULL, hInstance, NULL);
3498 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3502 td->size_hack = TRUE;
3503 ShowWindow(td->w, SW_SHOW);
3504 td->size_hack = FALSE;
3508 angband_term[i] = &td->t;
3512 /* Activate the window */
3513 SetActiveWindow(td->w);
3518 term_window_pos(&data[i], HWND_TOPMOST);
3522 term_window_pos(&data[i], td->w);
3532 td->w = CreateWindowEx(td->dwExStyle, AppName,
3534 td->pos_x, td->pos_y,
3535 td->size_wid, td->size_hgt,
3536 HWND_DESKTOP, NULL, hInstance, NULL);
3538 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3541 angband_term[0] = &td->t;
3542 normsize.x = td->cols;
3543 normsize.y = td->rows;
3545 /* Activate the main window */
3546 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3547 else ShowWindow(td->w, SW_SHOW);
3549 /* Bring main window back to top */
3550 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3554 (void)new_palette();
3557 /* Create a "brush" for drawing the "cursor" */
3558 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3561 /* Process pending messages */
3562 (void)Term_xtra_win_flush();
3570 static void setup_menus(void)
3574 HMENU hm = GetMenu(data[0].w);
3577 /* Menu "File", Disable all */
3578 EnableMenuItem(hm, IDM_FILE_NEW,
3579 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3580 EnableMenuItem(hm, IDM_FILE_OPEN,
3581 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3582 EnableMenuItem(hm, IDM_FILE_SAVE,
3583 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3584 EnableMenuItem(hm, IDM_FILE_EXIT,
3585 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3586 EnableMenuItem(hm, IDM_FILE_SCORE,
3587 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3590 /* No character available */
3591 if (!current_world_ptr->character_generated)
3593 /* Menu "File", Item "New" */
3594 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3596 /* Menu "File", Item "Open" */
3597 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3600 /* A character available */
3601 if (current_world_ptr->character_generated)
3603 /* Menu "File", Item "Save" */
3604 EnableMenuItem(hm, IDM_FILE_SAVE,
3605 MF_BYCOMMAND | MF_ENABLED);
3608 /* Menu "File", Item "Exit" */
3609 EnableMenuItem(hm, IDM_FILE_EXIT,
3610 MF_BYCOMMAND | MF_ENABLED);
3612 EnableMenuItem(hm, IDM_FILE_SCORE,
3613 MF_BYCOMMAND | MF_ENABLED);
3616 /* Menu "Window::Visibility" */
3617 for (i = 0; i < MAX_TERM_DATA; i++)
3619 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3620 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3622 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3623 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3625 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3626 MF_BYCOMMAND | MF_ENABLED);
3629 /* Menu "Window::Font" */
3630 for (i = 0; i < MAX_TERM_DATA; i++)
3632 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3633 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3635 if (data[i].visible)
3637 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3638 MF_BYCOMMAND | MF_ENABLED);
3642 /* Menu "Window::Window Position Fix" */
3643 for (i = 0; i < MAX_TERM_DATA; i++)
3645 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3646 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3648 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3649 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3651 if (data[i].visible)
3653 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3654 MF_BYCOMMAND | MF_ENABLED);
3658 /* Menu "Window::Bizarre Display" */
3659 for (i = 0; i < MAX_TERM_DATA; i++)
3661 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3662 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3664 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3665 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3667 if (data[i].visible)
3669 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3670 MF_BYCOMMAND | MF_ENABLED);
3675 /* Menu "Window::Increase Tile Width" */
3676 for (i = 0; i < MAX_TERM_DATA; i++)
3678 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3679 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3681 if (data[i].visible)
3683 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3684 MF_BYCOMMAND | MF_ENABLED);
3689 /* Menu "Window::Decrease Tile Width" */
3690 for (i = 0; i < MAX_TERM_DATA; i++)
3692 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3693 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3695 if (data[i].visible)
3697 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3698 MF_BYCOMMAND | MF_ENABLED);
3703 /* Menu "Window::Increase Tile Height" */
3704 for (i = 0; i < MAX_TERM_DATA; i++)
3706 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3707 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3709 if (data[i].visible)
3711 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3712 MF_BYCOMMAND | MF_ENABLED);
3717 /* Menu "Window::Decrease Tile Height" */
3718 for (i = 0; i < MAX_TERM_DATA; i++)
3720 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3721 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3723 if (data[i].visible)
3725 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3726 MF_BYCOMMAND | MF_ENABLED);
3731 /* Menu "Options", disable all */
3732 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3733 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3734 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3735 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3736 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3737 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3738 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3739 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3740 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3741 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3743 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3744 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3747 /* Menu "Options", Item "Map" */
3748 if (use_graphics != GRAPHICS_NONE)
3749 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3751 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3752 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3754 /* Menu "Options", update all */
3755 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3756 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3757 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3758 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3759 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3760 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3761 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3762 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3763 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3764 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3765 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3766 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3767 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3768 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3769 CheckMenuItem(hm, IDM_OPTIONS_BG,
3770 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3772 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3773 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3777 /* Menu "Options", Item "Graphics" */
3778 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3779 /* Menu "Options", Item "Graphics" */
3780 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3781 /* Menu "Options", Item "Graphics" */
3782 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3783 /* Menu "Options", Item "Graphics" */
3784 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3785 #endif /* USE_GRAPHICS */
3788 /* Menu "Options", Item "Sound" */
3789 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3790 #endif /* USE_SOUND */
3793 /* Menu "Options", Item "ScreenSaver" */
3794 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3795 MF_BYCOMMAND | MF_ENABLED);
3796 #endif /* USE_SAVER */
3801 * Check for double clicked (or dragged) savefile
3803 * Apparently, Windows copies the entire filename into the first
3804 * piece of the "command line string". Perhaps we should extract
3805 * the "basename" of that filename and append it to the "save" dir.
3807 static void check_for_save_file(LPSTR cmd_line)
3817 /* Extract filename */
3818 strcat(savefile, s);
3820 /* Validate the file */
3821 validate_file(savefile);
3823 /* Game in progress */
3824 game_in_progress = TRUE;
3827 play_game(p_ptr, FALSE);
3832 * Process a menu command
3834 static void process_menus(WORD wCmd)
3850 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3852 else if (game_in_progress)
3854 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3858 game_in_progress = TRUE;
3860 play_game(p_ptr, TRUE);
3871 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3873 else if (game_in_progress)
3875 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3879 memset(&ofn, 0, sizeof(ofn));
3880 ofn.lStructSize = sizeof(ofn);
3881 ofn.hwndOwner = data[0].w;
3882 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3883 ofn.nFilterIndex = 1;
3884 ofn.lpstrFile = savefile;
3885 ofn.nMaxFile = 1024;
3886 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3887 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3889 if (GetOpenFileName(&ofn))
3891 /* Load 'savefile' */
3892 validate_file(savefile);
3893 game_in_progress = TRUE;
3895 play_game(p_ptr, FALSE);
3905 if (game_in_progress && current_world_ptr->character_generated)
3909 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3913 /* Hack -- Forget messages */
3918 do_cmd_save_game(p_ptr, FALSE);
3919 #else /* ZANGBAND */
3921 #endif /* ZANGBAND */
3925 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3932 if (game_in_progress && current_world_ptr->character_generated)
3936 plog(_("今は終了できません。", "You may not do that right now."));
3940 /* Hack -- Forget messages */
3943 forget_lite(p_ptr->current_floor_ptr);
3944 forget_view(p_ptr->current_floor_ptr);
3945 clear_mon_lite(p_ptr->current_floor_ptr);
3949 /* do_cmd_save_game(FALSE); */
3950 #else /* ZANGBAND */
3951 /* do_cmd_save_game(); */
3952 #endif /* ZANGBAND */
3953 Term_key_push(SPECIAL_KEY_QUIT);
3961 case IDM_FILE_SCORE:
3964 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3966 /* Open the binary high score file, for reading */
3967 highscore_fd = fd_open(buf, O_RDONLY);
3969 /* Paranoia -- No score file */
3970 if (highscore_fd < 0)
3972 msg_print("Score file unavailable.");
3979 /* Display the scores */
3980 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3982 /* Shut the high score file */
3983 (void)fd_close(highscore_fd);
3985 /* Forget the high score fd */
3989 /* Hack - Flush it */
3997 case IDM_FILE_MOVIE:
4001 plog(_("まだ初期化中です...", "You cannot do that yet..."));
4003 else if (game_in_progress)
4005 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
4009 memset(&ofn, 0, sizeof(ofn));
4010 ofn.lStructSize = sizeof(ofn);
4011 ofn.hwndOwner = data[0].w;
4012 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
4013 ofn.nFilterIndex = 1;
4014 ofn.lpstrFile = savefile;
4015 ofn.nMaxFile = 1024;
4016 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
4017 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
4019 if (GetOpenFileName(&ofn))
4021 /* Load 'savefile' */
4022 prepare_browse_movie_aux(savefile);
4023 play_game(p_ptr, FALSE);
4032 case IDM_WINDOW_VIS_0:
4034 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
4038 /* Window visibility */
4039 case IDM_WINDOW_VIS_1:
4040 case IDM_WINDOW_VIS_2:
4041 case IDM_WINDOW_VIS_3:
4042 case IDM_WINDOW_VIS_4:
4043 case IDM_WINDOW_VIS_5:
4044 case IDM_WINDOW_VIS_6:
4045 case IDM_WINDOW_VIS_7:
4047 i = wCmd - IDM_WINDOW_VIS_0;
4049 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4056 ShowWindow(td->w, SW_SHOW);
4057 term_data_redraw(td);
4061 td->visible = FALSE;
4063 ShowWindow(td->w, SW_HIDE);
4070 case IDM_WINDOW_FONT_0:
4071 case IDM_WINDOW_FONT_1:
4072 case IDM_WINDOW_FONT_2:
4073 case IDM_WINDOW_FONT_3:
4074 case IDM_WINDOW_FONT_4:
4075 case IDM_WINDOW_FONT_5:
4076 case IDM_WINDOW_FONT_6:
4077 case IDM_WINDOW_FONT_7:
4079 i = wCmd - IDM_WINDOW_FONT_0;
4081 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4085 term_change_font(td);
4090 /* Window Z Position */
4091 case IDM_WINDOW_POS_1:
4092 case IDM_WINDOW_POS_2:
4093 case IDM_WINDOW_POS_3:
4094 case IDM_WINDOW_POS_4:
4095 case IDM_WINDOW_POS_5:
4096 case IDM_WINDOW_POS_6:
4097 case IDM_WINDOW_POS_7:
4099 i = wCmd - IDM_WINDOW_POS_0;
4101 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4105 if (!td->posfix && td->visible)
4108 term_window_pos(td, HWND_TOPMOST);
4113 term_window_pos(td, data[0].w);
4119 /* Bizarre Display */
4120 case IDM_WINDOW_BIZ_0:
4121 case IDM_WINDOW_BIZ_1:
4122 case IDM_WINDOW_BIZ_2:
4123 case IDM_WINDOW_BIZ_3:
4124 case IDM_WINDOW_BIZ_4:
4125 case IDM_WINDOW_BIZ_5:
4126 case IDM_WINDOW_BIZ_6:
4127 case IDM_WINDOW_BIZ_7:
4129 i = wCmd - IDM_WINDOW_BIZ_0;
4131 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4135 td->bizarre = !td->bizarre;
4139 term_window_resize(td);
4144 /* Increase Tile Width */
4145 case IDM_WINDOW_I_WID_0:
4146 case IDM_WINDOW_I_WID_1:
4147 case IDM_WINDOW_I_WID_2:
4148 case IDM_WINDOW_I_WID_3:
4149 case IDM_WINDOW_I_WID_4:
4150 case IDM_WINDOW_I_WID_5:
4151 case IDM_WINDOW_I_WID_6:
4152 case IDM_WINDOW_I_WID_7:
4154 i = wCmd - IDM_WINDOW_I_WID_0;
4156 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4164 term_window_resize(td);
4169 /* Decrease Tile Height */
4170 case IDM_WINDOW_D_WID_0:
4171 case IDM_WINDOW_D_WID_1:
4172 case IDM_WINDOW_D_WID_2:
4173 case IDM_WINDOW_D_WID_3:
4174 case IDM_WINDOW_D_WID_4:
4175 case IDM_WINDOW_D_WID_5:
4176 case IDM_WINDOW_D_WID_6:
4177 case IDM_WINDOW_D_WID_7:
4179 i = wCmd - IDM_WINDOW_D_WID_0;
4181 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4189 term_window_resize(td);
4194 /* Increase Tile Height */
4195 case IDM_WINDOW_I_HGT_0:
4196 case IDM_WINDOW_I_HGT_1:
4197 case IDM_WINDOW_I_HGT_2:
4198 case IDM_WINDOW_I_HGT_3:
4199 case IDM_WINDOW_I_HGT_4:
4200 case IDM_WINDOW_I_HGT_5:
4201 case IDM_WINDOW_I_HGT_6:
4202 case IDM_WINDOW_I_HGT_7:
4204 i = wCmd - IDM_WINDOW_I_HGT_0;
4206 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4214 term_window_resize(td);
4219 /* Decrease Tile Height */
4220 case IDM_WINDOW_D_HGT_0:
4221 case IDM_WINDOW_D_HGT_1:
4222 case IDM_WINDOW_D_HGT_2:
4223 case IDM_WINDOW_D_HGT_3:
4224 case IDM_WINDOW_D_HGT_4:
4225 case IDM_WINDOW_D_HGT_5:
4226 case IDM_WINDOW_D_HGT_6:
4227 case IDM_WINDOW_D_HGT_7:
4229 i = wCmd - IDM_WINDOW_D_HGT_0;
4231 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4239 term_window_resize(td);
4244 case IDM_OPTIONS_NO_GRAPHICS:
4248 plog("You may not do that right now.");
4252 if (arg_graphics != GRAPHICS_NONE)
4254 arg_graphics = GRAPHICS_NONE;
4255 Term_xtra_win_react();
4256 Term_key_push(KTRL('R'));
4262 case IDM_OPTIONS_OLD_GRAPHICS:
4266 plog("You may not do that right now.");
4270 if (arg_graphics != GRAPHICS_ORIGINAL)
4272 arg_graphics = GRAPHICS_ORIGINAL;
4273 Term_xtra_win_react();
4274 Term_key_push(KTRL('R'));
4280 case IDM_OPTIONS_NEW_GRAPHICS:
4284 plog("You may not do that right now.");
4288 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4290 arg_graphics = GRAPHICS_ADAM_BOLT;
4291 Term_xtra_win_react();
4292 Term_key_push(KTRL('R'));
4298 case IDM_OPTIONS_NEW2_GRAPHICS:
4302 plog("You may not do that right now.");
4306 if (arg_graphics != GRAPHICS_HENGBAND)
4308 arg_graphics = GRAPHICS_HENGBAND;
4309 Term_xtra_win_react();
4310 Term_key_push(KTRL('R'));
4316 case IDM_OPTIONS_BIGTILE:
4321 plog("You may not do that right now.");
4325 arg_bigtile = !arg_bigtile;
4326 Term_activate(&td->t);
4327 Term_resize(td->cols, td->rows);
4328 InvalidateRect(td->w, NULL, TRUE);
4332 case IDM_OPTIONS_MUSIC:
4336 plog("You may not do that right now.");
4340 arg_music = !arg_music;
4341 Term_xtra_win_react();
4342 Term_key_push(KTRL('R'));
4346 case IDM_OPTIONS_SOUND:
4350 plog("You may not do that right now.");
4354 arg_sound = !arg_sound;
4355 Term_xtra_win_react();
4356 Term_key_push(KTRL('R'));
4361 case IDM_OPTIONS_BG:
4365 plog("You may not do that right now.");
4371 Term_xtra_win_react();
4372 Term_key_push(KTRL('R'));
4377 case IDM_OPTIONS_OPEN_BG:
4381 plog("You may not do that right now.");
4386 memset(&ofn, 0, sizeof(ofn));
4387 ofn.lStructSize = sizeof(ofn);
4388 ofn.hwndOwner = data[0].w;
4389 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4390 ofn.nFilterIndex = 1;
4391 ofn.lpstrFile = bg_bitmap_file;
4392 ofn.nMaxFile = 1023;
4393 ofn.lpstrInitialDir = NULL;
4394 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
4395 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4397 if (GetOpenFileName(&ofn))
4399 /* Load 'savefile' */
4404 /* React to changes */
4405 Term_xtra_win_react();
4407 /* Hack -- Force redraw */
4408 Term_key_push(KTRL('R'));
4413 case IDM_DUMP_SCREEN_HTML:
4415 static char buf[1024] = "";
4416 memset(&ofn, 0, sizeof(ofn));
4417 ofn.lStructSize = sizeof(ofn);
4418 ofn.hwndOwner = data[0].w;
4419 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4420 ofn.nFilterIndex = 1;
4421 ofn.lpstrFile = buf;
4422 ofn.nMaxFile = 1023;
4423 ofn.lpstrDefExt = "html";
4424 ofn.lpstrInitialDir = NULL;
4425 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
4426 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4428 if (GetSaveFileName(&ofn))
4430 do_cmd_save_screen_html_aux(buf, 0);
4437 case IDM_OPTIONS_SAVER:
4441 DestroyWindow(hwndSaver);
4446 /* Create a screen scaver window */
4447 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4448 "Angband Screensaver",
4449 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4450 0, 0, GetSystemMetrics(SM_CXSCREEN),
4451 GetSystemMetrics(SM_CYSCREEN),
4452 NULL, NULL, hInstance, NULL);
4456 /* Push the window to the bottom */
4457 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4461 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
4469 case IDM_OPTIONS_MAP:
4475 case IDM_HELP_CONTENTS:
4479 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4480 if (check_file(tmp))
4482 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4486 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4487 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4490 #else /* HTML_HELP */
4493 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4494 if (check_file(tmp))
4496 sprintf(buf, "winhelp.exe %s", tmp);
4497 WinExec(buf, SW_NORMAL);
4501 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4502 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4506 #endif /* HTML_HELP */
4512 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4519 /* Extract the modifiers */
4520 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4521 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4522 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4524 Term_no_press = (ma) ? TRUE : FALSE;
4526 /* Handle "special" keys */
4527 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4529 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4530 bool numpad = FALSE;
4532 /* Begin the macro trigger */
4535 /* Send the modifiers */
4536 if (mc) Term_keypress('C');
4537 if (ms) Term_keypress('S');
4538 if (ma) Term_keypress('A');
4540 /* Extract "scan code" */
4541 i = LOBYTE(HIWORD(lParam));
4543 /* Introduce the scan code */
4546 /* Extended key bit */
4549 /* Numpad Enter and '/' are extended key */
4551 Term_no_press = TRUE;
4552 case VK_RETURN: /* Enter */
4555 /* Other extended keys are on full keyboard */
4571 Term_no_press = TRUE;
4575 case VK_PRIOR: /* Page Up */
4576 case VK_NEXT: /* Page Down */
4586 /* Special modifiers for keypad keys */
4587 if (numpad) Term_keypress('K');
4589 /* Encode the hexidecimal scan code */
4590 Term_keypress(hexsym[i/16]);
4591 Term_keypress(hexsym[i%16]);
4593 /* End the macro trigger */
4604 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4605 WPARAM wParam, LPARAM lParam);
4606 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4607 WPARAM wParam, LPARAM lParam)
4608 #else /* __MWERKS__ */
4609 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4610 #endif /* __MWERKS__ */
4616 MINMAXINFO FAR *lpmmi;
4622 /* Acquire proper "term_data" info */
4623 td = (term_data *)GetWindowLong(hWnd, 0);
4625 /* Handle message */
4630 SetWindowLong(hWnd, 0, (LONG)(my_td));
4637 mop.dwCallback=(DWORD)hWnd;
4642 case WM_GETMINMAXINFO:
4644 MINMAXINFO FAR *lpmmi;
4647 lpmmi = (MINMAXINFO FAR *)lParam;
4649 /* this message was sent before WM_NCCREATE */
4652 /* Minimum window size is 80x24 */
4653 rc.left = rc.top = 0;
4654 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4655 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4658 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4660 /* Save minimum size */
4661 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4662 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4669 BeginPaint(hWnd, &ps);
4670 if (td) term_data_redraw(td);
4671 EndPaint(hWnd, &ps);
4672 ValidateRect(hWnd, NULL);
4679 if(wParam == MCI_NOTIFY_SUCCESSFUL)
4681 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4682 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4691 if (process_keydown(wParam, lParam))
4698 if (Term_no_press) Term_no_press = FALSE;
4699 else Term_keypress(wParam);
4703 case WM_LBUTTONDOWN:
4705 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4706 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4718 TERM_LEN dx = abs(oldx - mousex) + 1;
4719 TERM_LEN dy = abs(oldy - mousey) + 1;
4720 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
4721 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
4731 hGlobal = GlobalAlloc(GHND, sz + 1);
4732 if (hGlobal == NULL) return 0;
4733 lpStr = (LPSTR)GlobalLock(hGlobal);
4735 for (i = 0; i < dy; i++)
4739 char **scr = data[0].t.scr->c;
4741 C_MAKE(s, (dx + 1), char);
4742 strncpy(s, &scr[oy + i][ox], dx);
4746 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4749 if (ox + dx < data[0].cols)
4751 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4754 for (j = 0; j < dx; j++)
4756 if (s[j] == 127) s[j] = '#';
4760 for (j = 0; j < dx; j++)
4762 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4772 GlobalUnlock(hGlobal);
4773 if (OpenClipboard(hWnd) == 0)
4775 GlobalFree(hGlobal);
4779 SetClipboardData(CF_TEXT, hGlobal);
4792 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4793 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4798 dx = abs(oldx - mousex) + 1;
4799 dy = abs(oldy - mousey) + 1;
4800 ox = (oldx > mousex) ? mousex : oldx;
4801 oy = (oldy > mousey) ? mousey : oldy;
4802 Term_inversed_area(hWnd, ox, oy, dx, dy);
4809 dx = abs(cx - mousex) + 1;
4810 dy = abs(cy - mousey) + 1;
4811 ox = (cx > mousex) ? mousex : cx;
4812 oy = (cy > mousey) ? mousey : cy;
4813 Term_inversed_area(hWnd, ox, oy, dx, dy);
4829 if (game_in_progress && current_world_ptr->character_generated)
4833 plog(_("今は終了できません。", "You may not do that right now."));
4837 /* Hack -- Forget messages */
4840 forget_lite(p_ptr->current_floor_ptr);
4841 forget_view(p_ptr->current_floor_ptr);
4842 clear_mon_lite(p_ptr->current_floor_ptr);
4846 /* do_cmd_save_game(FALSE); */
4847 #else /* ZANGBAND */
4848 /* do_cmd_save_game(); */
4849 #endif /* ZANGBAND */
4850 Term_key_push(SPECIAL_KEY_QUIT);
4857 case WM_QUERYENDSESSION:
4859 if (game_in_progress && current_world_ptr->character_generated)
4861 /* Hack -- Forget messages */
4864 /* Mega-Hack -- Delay death */
4865 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4866 exe_write_diary(p_ptr, NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4868 /* Hardcode panic save */
4869 p_ptr->panic_save = 1;
4871 /* Forbid suspend */
4872 signals_ignore_tstp();
4874 /* Indicate panic save */
4875 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4878 (void)save_player(p_ptr);
4892 process_menus(LOWORD(wParam));
4898 /* this message was sent before WM_NCCREATE */
4901 /* it was sent from inside CreateWindowEx */
4902 if (!td->w) return 1;
4904 /* was sent from WM_SIZE */
4905 if (td->size_hack) return 1;
4909 case SIZE_MINIMIZED:
4911 /* Hide sub-windows */
4912 for (i = 1; i < MAX_TERM_DATA; i++)
4914 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4919 case SIZE_MAXIMIZED:
4926 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4927 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4930 if ((td->cols != cols) || (td->rows != rows))
4932 /* Save the new size */
4936 if (!IsZoomed(td->w) && !IsIconic(td->w))
4938 normsize.x = td->cols;
4939 normsize.y = td->rows;
4943 Term_activate(&td->t);
4945 /* Resize the term */
4946 Term_resize(td->cols, td->rows);
4949 InvalidateRect(td->w, NULL, TRUE);
4952 td->size_hack = TRUE;
4954 /* Show sub-windows */
4955 for (i = 1; i < MAX_TERM_DATA; i++)
4957 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4960 td->size_hack = FALSE;
4968 case WM_PALETTECHANGED:
4970 /* Ignore if palette change caused by itself */
4971 if ((HWND)wParam == hWnd) return 0;
4973 /* Fall through... */
4976 case WM_QUERYNEWPALETTE:
4978 if (!paletted) return 0;
4982 SelectPalette(hdc, hPal, FALSE);
4984 i = RealizePalette(hdc);
4986 /* if any palette entries changed, repaint the window. */
4987 if (i) InvalidateRect(hWnd, NULL, TRUE);
4989 ReleaseDC(hWnd, hdc);
4996 if (wParam && !HIWORD(lParam))
4998 /* Do something to sub-windows */
4999 for (i = 1; i < MAX_TERM_DATA; i++)
5001 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
5004 /* Focus on main window */
5013 case WM_ACTIVATEAPP:
5015 if (IsIconic(td->w)) break;
5017 for (i = 1; i < MAX_TERM_DATA; i++)
5023 ShowWindow(data[i].w, SW_SHOW);
5027 ShowWindow(data[i].w, SW_HIDE);
5034 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5039 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5040 WPARAM wParam, LPARAM lParam);
5041 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5042 WPARAM wParam, LPARAM lParam)
5043 #else /* __MWERKS__ */
5044 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5045 WPARAM wParam, LPARAM lParam)
5046 #endif /* __MWERKS__ */
5050 MINMAXINFO FAR *lpmmi;
5058 /* Acquire proper "term_data" info */
5059 td = (term_data *)GetWindowLong(hWnd, 0);
5061 /* Process message */
5066 SetWindowLong(hWnd, 0, (LONG)(my_td));
5075 case WM_GETMINMAXINFO:
5077 MINMAXINFO FAR *lpmmi;
5080 lpmmi = (MINMAXINFO FAR *)lParam;
5082 /* this message was sent before WM_NCCREATE */
5085 /* Minimum window size is 80x24 */
5086 rc.left = rc.top = 0;
5087 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5088 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5091 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5093 /* Save minimum size */
5094 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5095 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5105 /* this message was sent before WM_NCCREATE */
5108 /* it was sent from inside CreateWindowEx */
5109 if (!td->w) return 1;
5111 /* was sent from inside WM_SIZE */
5112 if (td->size_hack) return 1;
5114 td->size_hack = TRUE;
5116 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5117 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5120 if ((td->cols != cols) || (td->rows != rows))
5123 term *old_term = Term;
5125 /* Save the new size */
5130 Term_activate(&td->t);
5132 /* Resize the term */
5133 Term_resize(td->cols, td->rows);
5136 Term_activate(old_term);
5139 InvalidateRect(td->w, NULL, TRUE);
5141 /* HACK - Redraw all windows */
5142 p_ptr->window = 0xFFFFFFFF;
5146 td->size_hack = FALSE;
5153 BeginPaint(hWnd, &ps);
5154 if (td) term_data_redraw(td);
5155 EndPaint(hWnd, &ps);
5162 if (process_keydown(wParam, lParam))
5169 if (Term_no_press) Term_no_press = FALSE;
5170 else Term_keypress(wParam);
5174 case WM_PALETTECHANGED:
5176 /* ignore if palette change caused by itself */
5177 if ((HWND)wParam == hWnd) return FALSE;
5178 /* otherwise, fall through!!! */
5181 case WM_QUERYNEWPALETTE:
5183 if (!paletted) return 0;
5185 SelectPalette(hdc, hPal, FALSE);
5186 i = RealizePalette(hdc);
5187 /* if any palette entries changed, repaint the window. */
5188 if (i) InvalidateRect(hWnd, NULL, TRUE);
5189 ReleaseDC(hWnd, hdc);
5193 case WM_NCLBUTTONDOWN:
5197 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5198 #endif /* HTCLOSE */
5200 if (wParam == HTSYSMENU)
5204 td->visible = FALSE;
5205 ShowWindow(td->w, SW_HIDE);
5215 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5221 #define MOUSE_SENS 40
5224 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5225 WPARAM wParam, LPARAM lParam);
5226 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5227 WPARAM wParam, LPARAM lParam)
5228 #else /* __MWERKS__ */
5229 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5230 WPARAM wParam, LPARAM lParam)
5231 #endif /* __MWERKS__ */
5233 static int iMouse = 0;
5234 static WORD xMouse = 0;
5235 static WORD yMouse = 0;
5257 if (LOWORD(wParam) == WA_INACTIVE) break;
5259 /* else fall through */
5263 case WM_LBUTTONDOWN:
5264 case WM_MBUTTONDOWN:
5265 case WM_RBUTTONDOWN:
5268 SendMessage(hWnd, WM_CLOSE, 0, 0);
5276 dx = LOWORD(lParam) - xMouse;
5277 dy = HIWORD(lParam) - yMouse;
5279 if (dx < 0) dx = -dx;
5280 if (dy < 0) dy = -dy;
5282 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5284 SendMessage(hWnd, WM_CLOSE, 0, 0);
5288 /* Save last location */
5290 xMouse = LOWORD(lParam);
5291 yMouse = HIWORD(lParam);
5298 DestroyWindow(hwndSaver);
5304 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5307 #endif /* USE_SAVER */
5313 /*** Temporary Hooks ***/
5317 * Display warning message (see "z-util.c")
5319 static void hack_plog(concptr str)
5321 /* Give a warning */
5325 MessageBox(NULL, str, "警告!",
5326 MB_ICONEXCLAMATION | MB_OK);
5328 MessageBox(NULL, str, "Warning",
5329 MB_ICONEXCLAMATION | MB_OK);
5337 * Display error message and quit (see "z-util.c")
5339 static void hack_quit(concptr str)
5341 /* Give a warning */
5345 MessageBox(NULL, str, "エラー!",
5346 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5348 MessageBox(NULL, str, "Error",
5349 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5354 /* Unregister the classes */
5355 UnregisterClass(AppName, hInstance);
5357 /* Destroy the icon */
5358 if (hIcon) DestroyIcon(hIcon);
5365 /*** Various hooks ***/
5369 * Display warning message (see "z-util.c")
5371 static void hook_plog(concptr str)
5377 MessageBox(data[0].w, str, "警告!",
5378 MB_ICONEXCLAMATION | MB_OK);
5380 MessageBox(data[0].w, str, "Warning",
5381 MB_ICONEXCLAMATION | MB_OK);
5389 * Display error message and quit (see "z-util.c")
5391 static void hook_quit(concptr str)
5396 /* Give a warning */
5400 MessageBox(data[0].w, str, "エラー!",
5401 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5403 MessageBox(data[0].w, str, "Error",
5404 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5410 /* Save the preferences */
5414 /*** Could use 'Term_nuke_win()' */
5416 /* Destroy all windows */
5417 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5419 term_force_font(&data[i], NULL);
5420 if (data[i].font_want) string_free(data[i].font_want);
5421 if (data[i].w) DestroyWindow(data[i].w);
5425 /* Free the bitmap stuff */
5427 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5428 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5430 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5431 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5433 #endif /* USE_GRAPHICS */
5435 /*** Free some other stuff ***/
5437 DeleteObject(hbrYellow);
5442 if (hPal) DeleteObject(hPal);
5444 UnregisterClass(AppName, hInstance);
5446 if (hIcon) DestroyIcon(hIcon);
5453 /*** Initialize ***/
5459 static void init_stuff(void)
5466 /* Get program name with full path */
5467 GetModuleFileName(hInstance, path, 512);
5469 /* Save the "program name" */
5472 /* Get the name of the "*.ini" file */
5473 strcpy(path + strlen(path) - 4, ".INI");
5475 /* Save the the name of the ini-file */
5476 ini_file = string_make(path);
5478 /* Analyze the path */
5484 if (path[i] == '\\')
5491 /* Add "lib" to the path */
5492 strcpy(path + i + 1, "lib\\");
5494 /* Validate the path */
5495 validate_dir(path, TRUE);
5497 /* Init the file paths */
5498 init_file_paths(path);
5500 /* Hack -- Validate the paths */
5501 validate_dir(ANGBAND_DIR_APEX, FALSE);
5502 validate_dir(ANGBAND_DIR_BONE, FALSE);
5504 /* Allow missing 'edit' directory */
5505 if (!check_dir(ANGBAND_DIR_EDIT))
5507 /* Must have 'data'! */
5508 validate_dir(ANGBAND_DIR_DATA, TRUE);
5512 /* Don't need 'data' */
5513 validate_dir(ANGBAND_DIR_DATA, FALSE);
5516 validate_dir(ANGBAND_DIR_FILE, TRUE);
5517 validate_dir(ANGBAND_DIR_HELP, FALSE);
5518 validate_dir(ANGBAND_DIR_INFO, FALSE);
5519 validate_dir(ANGBAND_DIR_PREF, TRUE);
5520 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5521 validate_dir(ANGBAND_DIR_USER, TRUE);
5522 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5523 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
5525 /* Hack -- Validate the "news.txt" file */
5526 validate_file(path);
5529 #if 0 /* #ifndef JP */
5530 /* Build the "font" path */
5531 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5533 /* Allocate the path */
5534 ANGBAND_DIR_XTRA_FONT = string_make(path);
5536 /* Validate the "font" directory */
5537 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5538 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5540 /* Hack -- Validate the basic font */
5541 validate_file(path);
5547 /* Build the "graf" path */
5548 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5550 /* Allocate the path */
5551 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5553 /* Validate the "graf" directory */
5554 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5556 #endif /* USE_GRAPHICS */
5561 /* Build the "sound" path */
5562 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5564 /* Allocate the path */
5565 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5567 /* Validate the "sound" directory */
5568 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5570 #endif /* USE_SOUND */
5574 /* Build the "music" path */
5575 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5577 /* Allocate the path */
5578 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5580 /* Validate the "music" directory */
5581 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5583 #endif /* USE_MUSIC */
5585 /* Build the "help" path */
5586 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5588 /* Allocate the path */
5589 ANGBAND_DIR_XTRA_HELP = string_make(path);
5591 /* Validate the "help" directory */
5592 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5596 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
5598 static bool is_already_running(void)
5600 bool result = FALSE;
5603 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5604 if (GetLastError() == ERROR_ALREADY_EXISTS)
5613 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
5615 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5616 LPSTR lpCmdLine, int nCmdShow)
5624 setlocale(LC_ALL, "ja_JP.utf8");
5633 /* Prevent multiple run */
5634 if (is_already_running())
5637 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
5638 _("エラー!", "Error") ,
5639 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5643 if (hPrevInst == NULL)
5645 wc.style = CS_CLASSDC;
5646 wc.lpfnWndProc = AngbandWndProc;
5648 wc.cbWndExtra = 4; /* one long pointer to term_data */
5649 wc.hInstance = hInst;
5650 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5651 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5652 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5653 wc.lpszMenuName = AppName;
5654 wc.lpszClassName = AppName;
5656 if (!RegisterClass(&wc)) exit(1);
5658 wc.lpfnWndProc = AngbandListProc;
5659 wc.lpszMenuName = NULL;
5660 wc.lpszClassName = AngList;
5662 if (!RegisterClass(&wc)) exit(2);
5666 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5667 wc.lpfnWndProc = AngbandSaverProc;
5669 wc.lpszMenuName = NULL;
5670 wc.lpszClassName = "WindowsScreenSaverClass";
5672 if (!RegisterClass(&wc)) exit(3);
5678 /* Temporary hooks */
5679 plog_aux = hack_plog;
5680 quit_aux = hack_quit;
5681 core_aux = hack_quit;
5683 /* Prepare the filepaths */
5686 /* Initialize the keypress analyzer */
5687 for (i = 0; special_key_list[i]; ++i)
5689 special_key[special_key_list[i]] = TRUE;
5691 /* Initialize the keypress analyzer */
5692 for (i = 0; ignore_key_list[i]; ++i)
5694 ignore_key[ignore_key_list[i]] = TRUE;
5697 /* Determine if display is 16/256/true color */
5699 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5700 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5701 ReleaseDC(NULL, hdc);
5703 /* Initialize the colors */
5704 for (i = 0; i < 256; i++)
5708 /* Extract desired values */
5709 rv = angband_color_table[i][1];
5710 gv = angband_color_table[i][2];
5711 bv = angband_color_table[i][3];
5713 /* Extract the "complex" code */
5714 win_clr[i] = PALETTERGB(rv, gv, bv);
5716 /* Save the "simple" code */
5717 angband_color_table[i][0] = win_pal[i];
5720 /* Prepare the windows */
5726 /* Activate hooks */
5727 plog_aux = hook_plog;
5728 quit_aux = hook_quit;
5729 core_aux = hook_quit;
5731 /* Set the system suffix */
5732 ANGBAND_SYS = "win";
5734 /* Set the keyboard suffix */
5735 if (7 != GetKeyboardType(0))
5736 ANGBAND_KEYBOARD = "0";
5739 /* Japanese keyboard */
5740 switch (GetKeyboardType(1))
5742 case 0x0D01: case 0x0D02:
5743 case 0x0D03: case 0x0D04:
5744 case 0x0D05: case 0x0D06:
5746 ANGBAND_KEYBOARD = "NEC98";
5750 ANGBAND_KEYBOARD = "JAPAN";
5754 /* Catch nasty signals */
5757 Term_activate(term_screen);
5758 init_angband(p_ptr);
5760 /* We are now initialized */
5763 if(lpCmdLine[0] == '-'){
5764 switch(lpCmdLine[1])
5769 if (!lpCmdLine[2]) break;
5770 chuukei_server = TRUE;
5771 if(connect_chuukei_server(&lpCmdLine[2])<0){
5772 msg_print("connect fail");
5775 msg_print("connect");
5783 if (!lpCmdLine[2]) break;
5784 chuukei_client = TRUE;
5785 connect_chuukei_server(&lpCmdLine[2]);
5786 play_game(p_ptr, FALSE);
5793 if (!lpCmdLine[2]) break;
5794 prepare_browse_movie(&lpCmdLine[2]);
5795 play_game(p_ptr, FALSE);
5804 /* Did the user double click on a save file? */
5805 if(!chuukei_server) check_for_save_file(lpCmdLine);
5807 /* Did the user double click on a save file? */
5808 check_for_save_file(lpCmdLine);
5811 /* Prompt the user */
5812 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
5816 /* Process messages forever */
5817 while (GetMessage(&msg, NULL, 0, 0))
5819 TranslateMessage(&msg);
5820 DispatchMessage(&msg);
5827 #endif /* WINDOWS */