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"
124 * Extract the "WIN32" flag from the compiler
126 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
134 * Hack -- allow use of "screen saver" mode
140 * Menu constants -- see "ANGBAND.RC"
143 #define IDM_FILE_NEW 100
144 #define IDM_FILE_OPEN 101
145 #define IDM_FILE_SAVE 110
146 #define IDM_FILE_SCORE 120
147 #define IDM_FILE_MOVIE 121
148 #define IDM_FILE_EXIT 130
150 #define IDM_WINDOW_VIS_0 200
151 #define IDM_WINDOW_VIS_1 201
152 #define IDM_WINDOW_VIS_2 202
153 #define IDM_WINDOW_VIS_3 203
154 #define IDM_WINDOW_VIS_4 204
155 #define IDM_WINDOW_VIS_5 205
156 #define IDM_WINDOW_VIS_6 206
157 #define IDM_WINDOW_VIS_7 207
159 #define IDM_WINDOW_FONT_0 210
160 #define IDM_WINDOW_FONT_1 211
161 #define IDM_WINDOW_FONT_2 212
162 #define IDM_WINDOW_FONT_3 213
163 #define IDM_WINDOW_FONT_4 214
164 #define IDM_WINDOW_FONT_5 215
165 #define IDM_WINDOW_FONT_6 216
166 #define IDM_WINDOW_FONT_7 217
168 #define IDM_WINDOW_POS_0 220
169 #define IDM_WINDOW_POS_1 221
170 #define IDM_WINDOW_POS_2 222
171 #define IDM_WINDOW_POS_3 223
172 #define IDM_WINDOW_POS_4 224
173 #define IDM_WINDOW_POS_5 225
174 #define IDM_WINDOW_POS_6 226
175 #define IDM_WINDOW_POS_7 227
177 #define IDM_WINDOW_BIZ_0 230
178 #define IDM_WINDOW_BIZ_1 231
179 #define IDM_WINDOW_BIZ_2 232
180 #define IDM_WINDOW_BIZ_3 233
181 #define IDM_WINDOW_BIZ_4 234
182 #define IDM_WINDOW_BIZ_5 235
183 #define IDM_WINDOW_BIZ_6 236
184 #define IDM_WINDOW_BIZ_7 237
186 #define IDM_WINDOW_I_WID_0 240
187 #define IDM_WINDOW_I_WID_1 241
188 #define IDM_WINDOW_I_WID_2 242
189 #define IDM_WINDOW_I_WID_3 243
190 #define IDM_WINDOW_I_WID_4 244
191 #define IDM_WINDOW_I_WID_5 245
192 #define IDM_WINDOW_I_WID_6 246
193 #define IDM_WINDOW_I_WID_7 247
195 #define IDM_WINDOW_D_WID_0 250
196 #define IDM_WINDOW_D_WID_1 251
197 #define IDM_WINDOW_D_WID_2 252
198 #define IDM_WINDOW_D_WID_3 253
199 #define IDM_WINDOW_D_WID_4 254
200 #define IDM_WINDOW_D_WID_5 255
201 #define IDM_WINDOW_D_WID_6 256
202 #define IDM_WINDOW_D_WID_7 257
204 #define IDM_WINDOW_I_HGT_0 260
205 #define IDM_WINDOW_I_HGT_1 261
206 #define IDM_WINDOW_I_HGT_2 262
207 #define IDM_WINDOW_I_HGT_3 263
208 #define IDM_WINDOW_I_HGT_4 264
209 #define IDM_WINDOW_I_HGT_5 265
210 #define IDM_WINDOW_I_HGT_6 266
211 #define IDM_WINDOW_I_HGT_7 267
213 #define IDM_WINDOW_D_HGT_0 270
214 #define IDM_WINDOW_D_HGT_1 271
215 #define IDM_WINDOW_D_HGT_2 272
216 #define IDM_WINDOW_D_HGT_3 273
217 #define IDM_WINDOW_D_HGT_4 274
218 #define IDM_WINDOW_D_HGT_5 275
219 #define IDM_WINDOW_D_HGT_6 276
220 #define IDM_WINDOW_D_HGT_7 277
222 #define IDM_OPTIONS_NO_GRAPHICS 400
223 #define IDM_OPTIONS_OLD_GRAPHICS 401
224 #define IDM_OPTIONS_NEW_GRAPHICS 402
225 #define IDM_OPTIONS_NEW2_GRAPHICS 403
226 #define IDM_OPTIONS_BIGTILE 409
227 #define IDM_OPTIONS_SOUND 410
228 #define IDM_OPTIONS_MUSIC 411
229 #define IDM_OPTIONS_SAVER 420
230 #define IDM_OPTIONS_MAP 430
231 #define IDM_OPTIONS_BG 440
232 #define IDM_OPTIONS_OPEN_BG 441
234 #define IDM_DUMP_SCREEN_HTML 450
236 #define IDM_HELP_CONTENTS 901
239 * Exclude parts of WINDOWS.H that are not needed
241 #define NOCOMM /* Comm driver APIs and definitions */
242 #define NOLOGERROR /* LogError() and related definitions */
243 #define NOPROFILER /* Profiler APIs */
244 #define NOLFILEIO /* _l* file I/O routines */
245 #define NOOPENFILE /* OpenFile and related definitions */
246 #define NORESOURCE /* Resource management */
247 #define NOATOM /* Atom management */
248 #define NOLANGUAGE /* Character test routines */
249 #define NOLSTRING /* lstr* string management routines */
250 #define NODBCS /* Double-byte character set routines */
251 #define NOKEYBOARDINFO /* Keyboard driver routines */
252 #define NOCOLOR /* COLOR_* color values */
253 #define NODRAWTEXT /* DrawText() and related definitions */
254 #define NOSCALABLEFONT /* Truetype scalable font support */
255 #define NOMETAFILE /* Metafile support */
256 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
257 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
258 #define NOKEYSTATES /* MK_* message key state flags */
259 #define NOWH /* SetWindowsHook and related WH_* definitions */
260 #define NOCLIPBOARD /* Clipboard APIs and definitions */
261 #define NOICONS /* IDI_* icon IDs */
262 #define NOMDI /* MDI support */
263 #define NOHELP /* Help support */
265 /* Not defined since it breaks Borland C++ 5.5 */
266 /* #define NOCTLMGR */ /* Control management and controls */
269 * Exclude parts of WINDOWS.H that are not needed (Win32)
271 #define WIN32_LEAN_AND_MEAN
272 #define NONLS /* All NLS defines and routines */
273 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
274 #define NOKANJI /* Kanji support stuff. */
275 #define NOMCX /* Modem Configuration Extensions */
278 * Include the "windows" support file
283 * Exclude parts of MMSYSTEM.H that are not needed
285 #define MMNODRV /* Installable driver support */
286 #define MMNOWAVE /* Waveform support */
287 #define MMNOMIDI /* MIDI support */
288 #define MMNOAUX /* Auxiliary audio support */
289 #define MMNOTIMER /* Timer support */
290 #define MMNOJOY /* Joystick support */
291 #define MMNOMCI /* MCI support */
292 #define MMNOMMIO /* Multimedia file I/O support */
293 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
296 * Include some more files. Note: the Cygnus Cygwin compiler
297 * doesn't use mmsystem.h instead it includes the winmm library
298 * which performs a similar function.
300 #include <mmsystem.h>
304 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
305 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
307 /* #define HTML_HELP */
310 #include <htmlhelp.h>
311 #endif /* HTML_HELP */
314 * Include the support for loading bitmaps
317 # include "readdib.h"
321 * Hack -- Fake declarations from "dos.h"
324 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
326 #define FA_LABEL 0x08 /* Volume label */
327 #define FA_DIREC 0x10 /* Directory */
328 unsigned _cdecl _dos_getfileattr(concptr , unsigned *);
332 * Silliness in WIN32 drawing routine
335 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
339 * Silliness for Windows 95
341 #ifndef WS_EX_TOOLWINDOW
342 # define WS_EX_TOOLWINDOW 0
346 * Foreground color bits (hard-coded by DOS)
348 #define VID_BLACK 0x00
349 #define VID_BLUE 0x01
350 #define VID_GREEN 0x02
351 #define VID_CYAN 0x03
353 #define VID_MAGENTA 0x05
354 #define VID_YELLOW 0x06
355 #define VID_WHITE 0x07
358 * Bright text (hard-coded by DOS)
360 #define VID_BRIGHT 0x08
363 * Background color bits (hard-coded by DOS)
365 #define VUD_BLACK 0x00
366 #define VUD_BLUE 0x10
367 #define VUD_GREEN 0x20
368 #define VUD_CYAN 0x30
370 #define VUD_MAGENTA 0x50
371 #define VUD_YELLOW 0x60
372 #define VUD_WHITE 0x70
375 * Blinking text (hard-coded by DOS)
377 #define VUD_BRIGHT 0x80
383 typedef struct _term_data term_data;
387 * @brief ターム情報構造体 / Extra "term" data
390 * pos_x / pos_y は各タームの左上点座標を指す。
393 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
394 * 1ドットずつ調整するステータスを指す。
395 * また、フォントを変更すると都度自動調整される。
398 * Note the use of "font_want" for the names of the font file requested by
399 * the user, and the use of "font_file" for the currently active font file.
401 * The "font_file" is uppercased, and takes the form "8X13.FON", while
402 * "font_want" can be in almost any form as long as it could be construed
403 * as attempting to represent the name of a font.
415 TERM_LEN rows; /* int -> uint */
418 uint pos_x; //!< タームの左上X座標
419 uint pos_y; //!< タームの左上Y座標
434 int font_wid; //!< フォント横幅
435 int font_hgt; //!< フォント縦幅
436 int tile_wid; //!< タイル横幅
437 int tile_hgt; //!< タイル縦幅
443 #if 1 /* #ifdef JP */
451 #define MAX_TERM_DATA 8 //!< Maximum number of windows
453 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
454 static term_data *my_td; //!< Hack -- global "window creation" pointer
455 POINT normsize; //!< Remember normal size of main window when maxmized
458 * was main window maximized on previous playing
460 bool win_maximized = FALSE;
465 bool game_in_progress = FALSE;
468 * note when "open"/"new" become valid
470 bool initialized = FALSE;
473 * screen paletted, i.e. 256 colors
475 bool paletted = FALSE;
478 * 16 colors screen, don't use RGB()
480 bool colors16 = FALSE;
483 * Saved instance handle
485 static HINSTANCE hInstance;
488 * Yellow brush for the cursor
490 static HBRUSH hbrYellow;
500 static HPALETTE hPal;
503 static HBITMAP hBG = NULL;
504 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
505 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
510 * The screen saver window
512 static HWND hwndSaver;
514 #endif /* USE_SAVER */
520 * 現在使用中のタイルID(0ならば未使用)
521 * Flag set once "graphics" has been initialized
523 static byte_hack current_graphics_mode = 0;
528 static DIBINIT infGraph;
531 * The global bitmap mask
533 static DIBINIT infMask;
535 #endif /* USE_GRAPHICS */
541 * Flag set once "sound" has been initialized
543 static bool can_use_sound = FALSE;
547 * An array of sound file names
549 static concptr sound_file[SOUND_MAX][SAMPLE_MAX];
551 #endif /* USE_SOUND */
557 #define SAMPLE_MUSIC_MAX 16
558 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
559 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
560 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
561 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
562 static bool can_use_music = FALSE;
564 static MCI_OPEN_PARMS mop;
565 static char mci_device_type[256];
567 int current_music_type = 0;
568 int current_music_id = 0;
570 #endif /* USE_MUSIC */
574 * Full path to ANGBAND.INI
576 static concptr ini_file = NULL;
579 * Name of application
581 static concptr AppName = "ANGBAND";
584 * Name of sub-window type
586 static concptr AngList = "AngList";
591 static concptr ANGBAND_DIR_XTRA_GRAF;
592 static concptr ANGBAND_DIR_XTRA_SOUND;
593 static concptr ANGBAND_DIR_XTRA_MUSIC;
594 static concptr ANGBAND_DIR_XTRA_HELP;
595 #if 0 /* #ifndef JP */
596 static concptr ANGBAND_DIR_XTRA_FONT;
599 static concptr ANGBAND_DIR_XTRA_MUSIC;
604 * The "complex" color values
606 static COLORREF win_clr[256];
610 * Flag for macro trigger with dump ASCII
612 static bool Term_no_press = FALSE;
617 static bool mouse_down = FALSE;
618 static bool paint_rect = FALSE;
619 static TERM_LEN mousex = 0, mousey = 0;
620 static TERM_LEN oldx, oldy;
624 * @brief The "simple" color values
626 * See "main-ibm.c" for original table information
627 * The entries below are taken from the "color bits" defined above.
628 * Note that many of the choices below suck, but so do crappy monitors.
630 static BYTE win_pal[256] =
632 VID_BLACK, /* Dark */
633 VID_WHITE, /* White */
634 VID_CYAN, /* Slate XXX */
635 VID_RED | VID_BRIGHT, /* Orange XXX */
637 VID_GREEN, /* Green */
639 VID_YELLOW, /* Umber XXX */
640 VID_BLACK | VID_BRIGHT, /* Light Dark */
641 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
642 VID_MAGENTA, /* Violet XXX */
643 VID_YELLOW | VID_BRIGHT, /* Yellow */
644 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
645 VID_GREEN | VID_BRIGHT, /* Light Green */
646 VID_BLUE | VID_BRIGHT, /* Light Blue */
647 VID_YELLOW /* Light Umber XXX */
652 * Hack -- define which keys are "special"
654 static bool special_key[256];
655 static bool ignore_key[256];
659 * Hack -- initialization list for "special_key"
661 static byte special_key_list[] = {
662 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
663 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
664 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
665 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
666 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
667 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
668 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
669 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
670 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
671 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
672 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
673 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
674 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
675 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
676 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
677 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
678 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
683 static byte ignore_key_list[] = {
684 VK_ESCAPE, VK_TAB, VK_SPACE,
685 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
686 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
687 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
693 * Hack -- initialization list for "special_key"
695 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
696 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
697 * catch the keypad keys (with and without numlock set, including keypad 5),
698 * the function keys (including the "menu" key which maps to F10), and the
699 * "pause" key (between scroll lock and numlock). We also catch a few odd
700 * keys which I do not recognize, but which are listed among keys which we
701 * do catch, so they should be harmless to catch.
703 static byte special_key_list[] =
705 VK_CLEAR, /* 0x0C (KP<5>) */
707 VK_PAUSE, /* 0x13 (pause) */
709 VK_PRIOR, /* 0x21 (KP<9>) */
710 VK_NEXT, /* 0x22 (KP<3>) */
711 VK_END, /* 0x23 (KP<1>) */
712 VK_HOME, /* 0x24 (KP<7>) */
713 VK_LEFT, /* 0x25 (KP<4>) */
714 VK_UP, /* 0x26 (KP<8>) */
715 VK_RIGHT, /* 0x27 (KP<6>) */
716 VK_DOWN, /* 0x28 (KP<2>) */
717 VK_SELECT, /* 0x29 (?????) */
718 VK_PRINT, /* 0x2A (?????) */
719 VK_EXECUTE, /* 0x2B (?????) */
720 VK_SNAPSHOT, /* 0x2C (?????) */
721 VK_INSERT, /* 0x2D (KP<0>) */
722 VK_DELETE, /* 0x2E (KP<.>) */
723 VK_HELP, /* 0x2F (?????) */
725 VK_NUMPAD0, /* 0x60 (KP<0>) */
726 VK_NUMPAD1, /* 0x61 (KP<1>) */
727 VK_NUMPAD2, /* 0x62 (KP<2>) */
728 VK_NUMPAD3, /* 0x63 (KP<3>) */
729 VK_NUMPAD4, /* 0x64 (KP<4>) */
730 VK_NUMPAD5, /* 0x65 (KP<5>) */
731 VK_NUMPAD6, /* 0x66 (KP<6>) */
732 VK_NUMPAD7, /* 0x67 (KP<7>) */
733 VK_NUMPAD8, /* 0x68 (KP<8>) */
734 VK_NUMPAD9, /* 0x69 (KP<9>) */
735 VK_MULTIPLY, /* 0x6A (KP<*>) */
736 VK_ADD, /* 0x6B (KP<+>) */
737 VK_SEPARATOR, /* 0x6C (?????) */
738 VK_SUBTRACT, /* 0x6D (KP<->) */
739 VK_DECIMAL, /* 0x6E (KP<.>) */
740 VK_DIVIDE, /* 0x6F (KP</>) */
771 /* Function prototype */
773 static bool is_already_running(void);
777 static void delete_bg(void)
786 static int init_bg(void)
788 char * bmfile = bg_bitmap_file;
791 if (use_bg == 0) return 0;
793 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
795 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
803 static void DrawBG(HDC hdc, RECT *r)
808 int x = r->left, y = r->top;
809 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
815 GetObject(hBG, sizeof(bm), &bm);
816 swid = bm.bmWidth; shgt = bm.bmHeight;
818 hdcSrc = CreateCompatibleDC(hdc);
819 hOld = SelectObject(hdcSrc, hBG);
823 cwid = MIN(swid - sx, r->right - nx);
826 chgt = MIN(shgt - sy, r->bottom - ny);
827 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
829 } while (ny < r->bottom);
832 } while (nx < r->right);
834 SelectObject(hdcSrc, hOld);
840 * Hack -- given a pathname, point at the filename
842 static concptr extract_file_name(concptr s)
846 /* Start at the end */
847 p = s + strlen(s) - 1;
849 /* Back up to divider */
850 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
852 /* Return file name */
859 * Hack -- given a simple filename, extract the "font size" info
861 * Return a pointer to a static buffer holding the capitalized base name.
863 #if 0 /* #ifndef JP */
864 static char *analyze_font(char *path, int *wp, int *hp)
870 /* Start at the end */
871 p = path + strlen(path) - 1;
873 /* Back up to divider */
874 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
876 /* Advance to file name */
882 /* Capitalize (be paranoid) */
883 if (islower(*s)) *s = toupper(*s);
887 s = my_strchr(p, 'X');
889 /* Extract font width */
893 hgt = s ? atoi(s+1) : 0;
904 * Check for existance of a file
906 static bool check_file(concptr s)
926 attrib = GetFileAttributes(path);
928 /* Require valid filename */
929 if (attrib == INVALID_FILE_NAME) return (FALSE);
931 /* Prohibit directory */
932 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
936 /* Examine and verify */
937 if (_dos_getfileattr(path, &attrib)) return (FALSE);
939 /* Prohibit something */
940 if (attrib & FA_LABEL) return (FALSE);
942 /* Prohibit directory */
943 if (attrib & FA_DIREC) return (FALSE);
953 * Check for existance of a directory
955 static bool check_dir(concptr s)
977 /* Remove trailing backslash */
978 if (i && (path[i-1] == '\\')) path[--i] = '\0';
983 attrib = GetFileAttributes(path);
985 /* Require valid filename */
986 if (attrib == INVALID_FILE_NAME) return (FALSE);
988 /* Require directory */
989 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
993 /* Examine and verify */
994 if (_dos_getfileattr(path, &attrib)) return (FALSE);
996 /* Prohibit something */
997 if (attrib & FA_LABEL) return (FALSE);
999 /* Require directory */
1000 if (!(attrib & FA_DIREC)) return (FALSE);
1012 static void validate_file(concptr s)
1014 /* Verify or fail */
1017 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
1023 * Validate a directory
1025 static void validate_dir(concptr s, bool vital)
1027 /* Verify or fail */
1030 /* This directory contains needed data */
1033 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
1035 /* Attempt to create this directory */
1038 quit_fmt("Unable to create directory:\n%s", s);
1045 * @brief (Windows版固有実装)Get the "size" for a window
1047 static void term_getsize(term_data *td)
1051 if (td->cols < 1) td->cols = 1;
1052 if (td->rows < 1) td->rows = 1;
1055 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1056 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1058 /* Fake window size */
1060 rc.right = rc.left + wid;
1062 rc.bottom = rc.top + hgt;
1064 /* rc.right += 1; */
1065 /* rc.bottom += 1; */
1068 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1071 td->size_wid = rc.right - rc.left;
1072 td->size_hgt = rc.bottom - rc.top;
1074 /* See CreateWindowEx */
1077 /* Extract actual location */
1078 GetWindowRect(td->w, &rc);
1080 /* Save the location */
1081 td->pos_x = rc.left;
1087 * Write the "prefs" for a single term
1089 static void save_prefs_aux(int i)
1091 term_data *td = &data[i];
1092 GAME_TEXT sec_name[128];
1096 WINDOWPLACEMENT lpwndpl;
1099 /* Make section name */
1100 sprintf(sec_name, "Term-%d", i);
1105 strcpy(buf, td->visible ? "1" : "0");
1106 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1111 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "MS ゴシック");
1114 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1116 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1120 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1122 #if 1 /* #ifdef JP */
1123 wsprintf(buf, "%d", td->lf.lfWidth);
1124 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1125 wsprintf(buf, "%d", td->lf.lfHeight);
1126 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1127 wsprintf(buf, "%d", td->lf.lfWeight);
1128 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1131 strcpy(buf, td->bizarre ? "1" : "0");
1132 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1135 wsprintf(buf, "%d", td->tile_wid);
1136 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1139 wsprintf(buf, "%d", td->tile_hgt);
1140 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1142 /* Get window placement and dimensions */
1143 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1144 GetWindowPlacement(td->w, &lpwndpl);
1146 /* Acquire position in *normal* mode (not minimized) */
1147 rc = lpwndpl.rcNormalPosition;
1149 /* Window size (x) */
1150 if (i == 0) wsprintf(buf, "%d", normsize.x);
1151 else wsprintf(buf, "%d", td->cols);
1152 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1154 /* Window size (y) */
1155 if (i == 0) wsprintf(buf, "%d", normsize.y);
1156 else wsprintf(buf, "%d", td->rows);
1157 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1159 /* Maxmized (only main window) */
1162 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1163 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1166 /* Acquire position */
1167 GetWindowRect(td->w, &rc);
1169 /* Window position (x) */
1170 wsprintf(buf, "%d", rc.left);
1171 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1173 /* Window position (y) */
1174 wsprintf(buf, "%d", rc.top);
1175 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1177 /* Window Z position */
1180 strcpy(buf, td->posfix ? "1" : "0");
1181 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1188 * We assume that the windows have all been initialized
1190 static void save_prefs(void)
1196 /* Save the "arg_graphics" flag */
1197 sprintf(buf, "%d", arg_graphics);
1198 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1200 /* Save the "arg_bigtile" flag */
1201 strcpy(buf, arg_bigtile ? "1" : "0");
1202 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1204 /* Save the "arg_sound" flag */
1205 strcpy(buf, arg_sound ? "1" : "0");
1206 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1208 /* Save the "arg_sound" flag */
1209 strcpy(buf, arg_music ? "1" : "0");
1210 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1213 strcpy(buf, use_bg ? "1" : "0");
1214 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1215 WritePrivateProfileString("Angband", "BackGroundBitmap",
1216 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1218 /* Save window prefs */
1219 for (i = 0; i < MAX_TERM_DATA; ++i)
1227 * Load the "prefs" for a single term
1229 static void load_prefs_aux(int i)
1231 term_data *td = &data[i];
1232 GAME_TEXT sec_name[128];
1235 int wid, hgt, posx, posy;
1236 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1237 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1241 /* Make section name */
1242 sprintf(sec_name, "Term-%d", i);
1244 /* Make section name */
1245 sprintf(sec_name, "Term-%d", i);
1250 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1253 /* Desired font, with default */
1255 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1258 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1260 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1266 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1268 /* Analyze font, save desired font name */
1269 #if 1 /* #ifdef JP */
1270 td->font_want = string_make(tmp);
1272 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1273 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1274 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1276 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1281 #if 1 /* #ifdef JP */
1282 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1283 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1285 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1286 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1291 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1292 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1293 normsize.x = td->cols; normsize.y = td->rows;
1298 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
1301 /* Window position */
1302 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1303 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1304 td->pos_x = MIN(MAX(0, posx), dispx-128);
1305 td->pos_y = MIN(MAX(0, posy), dispy-128);
1307 /* Window Z position */
1310 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
1318 static void load_prefs(void)
1322 /* Extract the "arg_graphics" flag */
1323 arg_graphics = (byte_hack)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1325 /* Extract the "arg_bigtile" flag */
1326 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
1327 use_bigtile = arg_bigtile;
1329 /* Extract the "arg_sound" flag */
1330 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1332 /* Extract the "arg_sound" flag */
1333 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1336 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1337 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1339 /* Load window prefs */
1340 for (i = 0; i < MAX_TERM_DATA; ++i)
1346 #if defined(USE_SOUND) || defined(USE_MUSIC)
1349 * - Taken from files.c.
1351 * Extract "tokens" from a buffer
1353 * This function uses "whitespace" as delimiters, and treats any amount of
1354 * whitespace as a single delimiter. We will never return any empty tokens.
1355 * When given an empty buffer, or a buffer containing only "whitespace", we
1356 * will return no tokens. We will never extract more than "num" tokens.
1358 * By running a token through the "text_to_ascii()" function, you can allow
1359 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1361 * We save pointers to the tokens in "tokens", and return the number found.
1363 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1373 /* Skip leading whitespace */
1374 for ( ; *s && iswspace(*s); ++s) /* loop */;
1379 /* Find next whitespace, if any */
1380 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1382 /* Nuke and advance (if necessary) */
1383 if (*t) *t++ = '\0';
1385 /* Save the token */
1396 #endif /* USE_SOUND || USE_MUSIC */
1400 static void load_sound_prefs(void)
1404 char ini_path[1024];
1405 char wav_path[1024];
1406 char *zz[SAMPLE_MAX];
1408 /* Access the sound.cfg */
1410 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1412 for (i = 0; i < SOUND_MAX; i++)
1414 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1416 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1418 for (j = 0; j < num; j++)
1420 /* Access the sound */
1421 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1423 /* Save the sound filename, if it exists */
1424 if (check_file(wav_path))
1425 sound_file[i][j] = string_make(zz[j]);
1430 #endif /* USE_SOUND */
1434 static void load_music_prefs(void)
1438 char ini_path[1024];
1439 char wav_path[1024];
1440 char *zz[SAMPLE_MAX];
1443 /* Access the music.cfg */
1445 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1447 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1449 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1451 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1453 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1455 for (j = 0; j < num; j++)
1457 /* Access the sound */
1458 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1460 /* Save the sound filename, if it exists */
1461 if (check_file(wav_path))
1462 music_file[i][j] = string_make(zz[j]);
1466 for (i = 0; i < max_d_idx; i++)
1468 sprintf(key, "dungeon%03d", i);
1469 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1471 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1473 for (j = 0; j < num; j++)
1475 /* Access the sound */
1476 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1478 /* Save the sound filename, if it exists */
1479 if (check_file(wav_path))
1480 dungeon_music_file[i][j] = string_make(zz[j]);
1484 for (i = 0; i < max_q_idx; i++)
1486 sprintf(key, "quest%03d", i);
1487 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1489 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1491 for (j = 0; j < num; j++)
1493 /* Access the sound */
1494 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1496 /* Save the sound filename, if it exists */
1497 if (check_file(wav_path))
1498 quest_music_file[i][j] = string_make(zz[j]);
1502 for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1504 sprintf(key, "town%03d", i);
1505 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1507 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1509 for (j = 0; j < num; j++)
1511 /* Access the sound */
1512 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1514 /* Save the sound filename, if it exists */
1515 if (check_file(wav_path))
1516 town_music_file[i][j] = string_make(zz[j]);
1523 #endif /* USE_MUSIC */
1526 * Create the new global palette based on the bitmap palette
1527 * (if any), and the standard 16 entry palette derived from
1528 * "win_clr[]" which is used for the basic 16 Angband colors.
1530 * This function is never called before all windows are ready.
1532 * This function returns FALSE if the new palette could not be
1533 * prepared, which should normally be a fatal error. XXX XXX
1535 * Note that only some machines actually use a "palette".
1537 static int new_palette(void)
1545 LPLOGPALETTE pLogPal;
1546 LPPALETTEENTRY lppe;
1551 /* This makes no sense */
1552 if (!paletted) return (TRUE);
1562 /* Check the bitmap palette */
1563 hBmPal = infGraph.hPalette;
1565 /* Use the bitmap */
1568 lppeSize = 256 * sizeof(PALETTEENTRY);
1569 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1570 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1571 if ((nEntries == 0) || (nEntries > 220))
1574 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1577 rnfree(lppe, lppeSize);
1584 #endif /* USE_GRAPHICS */
1586 /* Size of palette */
1587 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1589 /* Allocate palette */
1590 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1593 pLogPal->palVersion = 0x300;
1595 /* Make room for bitmap and normal data */
1596 pLogPal->palNumEntries = nEntries + 16;
1598 /* Save the bitmap data */
1599 for (i = 0; i < nEntries; i++)
1601 pLogPal->palPalEntry[i] = lppe[i];
1604 /* Save the normal data */
1605 for (i = 0; i < 16; i++)
1609 /* Access the entry */
1610 p = &(pLogPal->palPalEntry[i+nEntries]);
1612 /* Save the colors */
1613 p->peRed = GetRValue(win_clr[i]);
1614 p->peGreen = GetGValue(win_clr[i]);
1615 p->peBlue = GetBValue(win_clr[i]);
1617 /* Save the flags */
1618 p->peFlags = PC_NOCOLLAPSE;
1621 /* Free something */
1622 if (lppe) rnfree(lppe, lppeSize);
1624 /* Create a new palette, or fail */
1625 hNewPal = CreatePalette(pLogPal);
1626 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1628 /* Free the palette */
1629 rnfree(pLogPal, pLogPalSize);
1634 /* Realize the palette */
1636 SelectPalette(hdc, hNewPal, 0);
1637 i = RealizePalette(hdc);
1638 ReleaseDC(td->w, hdc);
1639 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1643 for (i = 1; i < MAX_TERM_DATA; i++)
1648 SelectPalette(hdc, hNewPal, 0);
1649 ReleaseDC(td->w, hdc);
1652 /* Delete old palette */
1653 if (hPal) DeleteObject(hPal);
1655 /* Save new palette */
1665 * @brief グラフィクスを初期化する / Initialize graphics
1668 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1669 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1672 static bool init_graphics(void)
1674 /* Initialize once */
1676 BYTE wid, hgt, twid, thgt, ox, oy;
1679 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1689 ANGBAND_GRAF = "new";
1691 else if (arg_graphics == GRAPHICS_HENGBAND)
1711 ANGBAND_GRAF = "ne2";
1722 ANGBAND_GRAF = "old";
1725 /* Access the bitmap file */
1726 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1728 /* Load the bitmap or quit */
1729 if (!ReadDIB(data[0].w, buf, &infGraph))
1731 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1735 /* Save the new sizes */
1736 infGraph.CellWidth = wid;
1737 infGraph.CellHeight = hgt;
1738 infGraph.TileWidth = twid;
1739 infGraph.TileHeight = thgt;
1740 infGraph.OffsetX = ox;
1741 infGraph.OffsetY = oy;
1743 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1745 /* Access the mask file */
1746 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1748 /* Load the bitmap or quit */
1749 if (!ReadDIB(data[0].w, buf, &infMask))
1751 plog_fmt("Cannot read bitmap file '%s'", buf);
1755 if (arg_graphics == GRAPHICS_HENGBAND)
1757 /* Access the mask file */
1758 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1760 /* Load the bitmap or quit */
1761 if (!ReadDIB(data[0].w, buf, &infMask))
1763 plog_fmt("Cannot read bitmap file '%s'", buf);
1768 /* Activate a palette */
1773 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1777 /* Graphics available */
1778 current_graphics_mode = arg_graphics;
1779 return (current_graphics_mode);
1781 #endif /* USE_GRAPHICS */
1788 static bool init_music(void)
1790 /* Initialize once */
1793 /* Load the prefs */
1796 /* Sound available */
1797 can_use_music = TRUE;
1799 return (can_use_music);
1803 * Hack -- Stop a music
1805 static void stop_music(void)
1807 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1808 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1811 #endif /* USE_MUSIC */
1817 static bool init_sound(void)
1819 /* Initialize once */
1822 /* Load the prefs */
1825 /* Sound available */
1826 can_use_sound = TRUE;
1828 return (can_use_sound);
1830 #endif /* USE_SOUND */
1836 static void term_window_resize(term_data *td)
1838 /* Require window */
1841 /* Resize the window */
1842 SetWindowPos(td->w, 0, 0, 0,
1843 td->size_wid, td->size_hgt,
1844 SWP_NOMOVE | SWP_NOZORDER);
1847 InvalidateRect(td->w, NULL, TRUE);
1852 * Force the use of a new "font file" for a term_data
1854 * This function may be called before the "window" is ready
1856 * This function returns zero only if everything succeeds.
1858 * Note that the "font name" must be capitalized!!!
1860 static errr term_force_font(term_data *td, concptr path)
1864 #if 0 /* #ifndef JP */
1870 /* Forget the old font (if needed) */
1871 if (td->font_id) DeleteObject(td->font_id);
1873 #if 1 /* #ifdef JP */
1877 /* Create the font (using the 'base' of the font file name!) */
1878 td->font_id = CreateFontIndirect(&(td->lf));
1879 wid = td->lf.lfWidth;
1880 hgt = td->lf.lfHeight;
1881 if (!td->font_id) return (1);
1883 /* Forget old font */
1889 for (i = 0; i < MAX_TERM_DATA; i++)
1891 /* Don't check when closing the application */
1894 /* Check "screen" */
1895 if ((td != &data[i]) &&
1896 (data[i].font_file) &&
1897 (streq(data[i].font_file, td->font_file)))
1903 /* Remove unused font resources */
1904 if (!used) RemoveFontResource(td->font_file);
1906 /* Free the old name */
1907 string_free(td->font_file);
1910 td->font_file = NULL;
1914 if (!path) return (1);
1919 /* Analyze font path */
1920 base = analyze_font(buf, &wid, &hgt);
1923 if (!suffix(base, ".FON")) return (1);
1926 if (!check_file(buf)) return (1);
1928 /* Load the new font */
1929 if (!AddFontResource(buf)) return (1);
1931 /* Save new font name */
1932 td->font_file = string_make(base);
1934 /* Remove the "suffix" */
1935 base[strlen(base)-4] = '\0';
1937 /* Create the font (using the 'base' of the font file name!) */
1938 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1939 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1940 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1941 FIXED_PITCH | FF_DONTCARE, base);
1944 /* Hack -- Unknown size */
1951 /* all this trouble to get the cell size */
1952 hdcDesktop = GetDC(HWND_DESKTOP);
1953 hfOld = SelectObject(hdcDesktop, td->font_id);
1954 GetTextMetrics(hdcDesktop, &tm);
1955 SelectObject(hdcDesktop, hfOld);
1956 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1958 /* Font size info */
1959 wid = tm.tmAveCharWidth;
1963 /* Save the size info */
1974 * Allow the user to change the font for this window.
1976 static void term_change_font(term_data *td)
1978 #if 1 /* #ifdef JP */
1981 memset(&cf, 0, sizeof(cf));
1982 cf.lStructSize = sizeof(cf);
1983 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1984 cf.lpLogFont = &(td->lf);
1986 if (ChooseFont(&cf))
1988 /* Force the font */
1989 term_force_font(td, NULL);
1991 /* Assume not bizarre */
1994 /* Reset the tile info */
1995 td->tile_wid = td->font_wid;
1996 td->tile_hgt = td->font_hgt;
1998 /* Analyze the font */
2001 /* Resize the window */
2002 term_window_resize(td);
2008 char tmp[1024] = "";
2010 /* Extract a default if possible */
2011 if (td->font_file) strcpy(tmp, td->font_file);
2013 /* Ask for a choice */
2014 memset(&ofn, 0, sizeof(ofn));
2015 ofn.lStructSize = sizeof(ofn);
2016 ofn.hwndOwner = data[0].w;
2017 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
2018 ofn.nFilterIndex = 1;
2019 ofn.lpstrFile = tmp;
2021 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
2022 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2023 ofn.lpstrDefExt = "fon";
2025 /* Force choice if legal */
2026 if (GetOpenFileName(&ofn))
2028 /* Force the font */
2029 if (term_force_font(td, tmp))
2031 /* Access the standard font file */
2032 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2034 /* Force the use of that font */
2035 (void)term_force_font(td, tmp);
2038 /* Assume not bizarre */
2039 td->bizarre = FALSE;
2041 /* Reset the tile info */
2042 td->tile_wid = td->font_wid;
2043 td->tile_hgt = td->font_hgt;
2045 /* Analyze the font */
2048 /* Resize the window */
2049 term_window_resize(td);
2056 * Allow the user to lock this window.
2058 static void term_window_pos(term_data *td, HWND hWnd)
2060 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2061 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2064 static void windows_map(void);
2067 * Hack -- redraw a term_data
2069 static void term_data_redraw(term_data *td)
2073 /* Redraw the map */
2078 /* Activate the term */
2079 Term_activate(&td->t);
2081 /* Redraw the contents */
2084 /* Restore the term */
2085 Term_activate(term_screen);
2090 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2094 HBRUSH myBrush, oldBrush;
2096 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2097 int tx = td->size_ow1 + x * td->tile_wid;
2098 int ty = td->size_oh1 + y * td->tile_hgt;
2099 int tw = w * td->tile_wid - 1;
2100 int th = h * td->tile_hgt - 1;
2103 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2104 oldBrush = SelectObject(hdc, myBrush);
2105 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2107 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2109 SelectObject(hdc, oldBrush);
2110 SelectObject(hdc, oldPen);
2115 /*** Function hooks needed by "Term" ***/
2121 * Initialize a new Term
2123 static void Term_init_win(term *t)
2132 static void Term_nuke_win(term *t)
2141 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
2143 static errr Term_user_win(int n)
2154 * React to global changes
2156 static errr Term_xtra_win_react(void)
2163 /* Save the default colors */
2164 for (i = 0; i < 256; i++)
2166 /* Simply accept the desired colors */
2167 win_pal[i] = angband_color_table[i][0];
2178 bool change = FALSE;
2180 /* Save the default colors */
2181 for (i = 0; i < 256; i++)
2183 /* Extract desired values */
2184 rv = angband_color_table[i][1];
2185 gv = angband_color_table[i][2];
2186 bv = angband_color_table[i][3];
2188 /* Extract a full color code */
2189 code = PALETTERGB(rv, gv, bv);
2191 /* Activate changes */
2192 if (win_clr[i] != code)
2194 /* Note the change */
2197 /* Apply the desired color */
2202 /* Activate the palette if needed */
2203 if (change) (void)new_palette();
2209 /* Handle "arg_sound" */
2210 if (use_sound != arg_sound)
2212 /* Initialize (if needed) */
2213 if (arg_sound && !init_sound())
2216 plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
2222 /* Change setting */
2223 use_sound = arg_sound;
2230 /* Handle "arg_sound" */
2231 if (use_music != arg_music)
2233 /* Initialize (if needed) */
2234 if (arg_music && !init_music())
2237 plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
2242 /* Change setting */
2243 use_music = arg_music;
2245 if(!arg_music) stop_music();
2246 else select_floor_music();
2255 /* Handle "arg_graphics" */
2256 if (use_graphics != arg_graphics)
2258 /* Initialize (if needed) */
2259 if (arg_graphics && !init_graphics())
2262 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
2265 arg_graphics = GRAPHICS_NONE;
2268 /* Change setting */
2269 use_graphics = arg_graphics;
2272 #ifdef ANGBAND_2_8_1
2274 #else /* ANGBAND_2_8_1 */
2275 reset_visuals(TRUE);
2276 #endif /* ANGBAND_2_8_1 */
2279 #endif /* USE_GRAPHICS */
2282 /* Clean up windows */
2283 for (i = 0; i < MAX_TERM_DATA; i++)
2287 term_data *td = &data[i];
2289 /* Update resized windows */
2290 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
2293 Term_activate(&td->t);
2295 /* Hack -- Resize the term */
2296 Term_resize(td->cols, td->rows);
2298 /* Redraw the contents */
2311 * Process at least one event
2313 static errr Term_xtra_win_event(int v)
2317 /* Wait for an event */
2321 if (GetMessage(&msg, NULL, 0, 0))
2323 TranslateMessage(&msg);
2324 DispatchMessage(&msg);
2328 /* Check for an event */
2332 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2334 TranslateMessage(&msg);
2335 DispatchMessage(&msg);
2345 * Process all pending events
2347 static errr Term_xtra_win_flush(void)
2351 /* Process all pending events */
2352 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2354 TranslateMessage(&msg);
2355 DispatchMessage(&msg);
2364 * Hack -- clear the screen
2366 * Make this more efficient
2368 static errr Term_xtra_win_clear(void)
2370 term_data *td = (term_data*)(Term->data);
2375 /* Rectangle to erase */
2376 rc.left = td->size_ow1;
2377 rc.right = rc.left + td->cols * td->tile_wid;
2378 rc.top = td->size_oh1;
2379 rc.bottom = rc.top + td->rows * td->tile_hgt;
2383 SetBkColor(hdc, RGB(0, 0, 0));
2384 SelectObject(hdc, td->font_id);
2385 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2390 rc.left = 0; rc.top = 0;
2393 ReleaseDC(td->w, hdc);
2401 * Hack -- make a noise
2403 static errr Term_xtra_win_noise(void)
2405 MessageBeep(MB_ICONASTERISK);
2411 * Hack -- make a sound
2413 static errr Term_xtra_win_sound(int v)
2418 #endif /* USE_SOUND */
2420 /* Sound disabled */
2421 if (!use_sound) return (1);
2424 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2428 /* Count the samples */
2429 for (i = 0; i < SAMPLE_MAX; i++)
2431 if (!sound_file[v][i])
2436 if (i == 0) return (1);
2438 /* Build the path */
2439 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2443 /* Play the sound, catch errors */
2444 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2448 /* Play the sound, catch errors */
2449 return (sndPlaySound(buf, SND_ASYNC));
2453 #else /* USE_SOUND */
2457 #endif /* USE_SOUND */
2461 * Hack -- play a music
2463 static errr Term_xtra_win_music(int n, int v)
2468 #endif /* USE_MUSIC */
2470 /* Sound disabled */
2472 if(!use_music) return (1);
2475 if(n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return (1);
2476 else if(v < 0 || v >= 1000) return(1); /*!< TODO */
2482 case TERM_XTRA_MUSIC_BASIC:
2483 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2485 case TERM_XTRA_MUSIC_DUNGEON:
2486 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2488 case TERM_XTRA_MUSIC_QUEST:
2489 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2491 case TERM_XTRA_MUSIC_TOWN:
2492 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2499 //mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2500 //mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2506 case TERM_XTRA_MUSIC_BASIC:
2507 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2509 case TERM_XTRA_MUSIC_DUNGEON:
2510 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2512 case TERM_XTRA_MUSIC_QUEST:
2513 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2515 case TERM_XTRA_MUSIC_TOWN:
2516 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2523 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2524 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2530 case TERM_XTRA_MUSIC_BASIC:
2531 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2533 case TERM_XTRA_MUSIC_DUNGEON:
2534 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2536 case TERM_XTRA_MUSIC_QUEST:
2537 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2539 case TERM_XTRA_MUSIC_TOWN:
2540 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2544 if(current_music_type == n && current_music_id == v)
2548 current_music_type = n;
2549 current_music_id = v;
2553 mop.lpstrDeviceType = mci_device_type;
2554 mop.lpstrElementName = buf;
2555 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2556 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2557 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2558 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2559 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2564 #else /* USE_MUSIC */
2568 #endif /* USE_MUSIC */
2574 * Delay for "x" milliseconds
2576 static int Term_xtra_win_delay(int v)
2590 t = GetTickCount() + v;
2593 while (GetTickCount() < t)
2595 /* Handle messages */
2596 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2598 TranslateMessage(&msg);
2599 DispatchMessage(&msg);
2611 * Do a "special thing"
2613 static errr Term_xtra_win(int n, int v)
2615 /* Handle a subset of the legal requests */
2618 /* Make a bell sound */
2619 case TERM_XTRA_NOISE:
2621 return (Term_xtra_win_noise());
2625 case TERM_XTRA_MUSIC_BASIC:
2626 case TERM_XTRA_MUSIC_DUNGEON:
2627 case TERM_XTRA_MUSIC_QUEST:
2628 case TERM_XTRA_MUSIC_TOWN:
2630 return (Term_xtra_win_music(n, v));
2633 /* Make a special sound */
2634 case TERM_XTRA_SOUND:
2636 return (Term_xtra_win_sound(v));
2639 /* Process random events */
2640 case TERM_XTRA_BORED:
2642 return (Term_xtra_win_event(0));
2645 /* Process an event */
2646 case TERM_XTRA_EVENT:
2648 return (Term_xtra_win_event(v));
2651 /* Flush all events */
2652 case TERM_XTRA_FLUSH:
2654 return (Term_xtra_win_flush());
2657 /* Clear the screen */
2658 case TERM_XTRA_CLEAR:
2660 return (Term_xtra_win_clear());
2663 /* React to global changes */
2664 case TERM_XTRA_REACT:
2666 return (Term_xtra_win_react());
2669 /* Delay for some milliseconds */
2670 case TERM_XTRA_DELAY:
2672 return (Term_xtra_win_delay(v));
2682 * Low level graphics (Assumes valid input).
2684 * Draw a "cursor" at (x,y), using a "yellow box".
2686 static errr Term_curs_win(int x, int y)
2688 term_data *td = (term_data*)(Term->data);
2693 int tile_wid, tile_hgt;
2697 tile_wid = td->map_tile_wid;
2698 tile_hgt = td->map_tile_hgt;
2702 tile_wid = td->tile_wid;
2703 tile_hgt = td->tile_hgt;
2706 /* Frame the grid */
2707 rc.left = x * tile_wid + td->size_ow1;
2708 rc.right = rc.left + tile_wid;
2709 rc.top = y * tile_hgt + td->size_oh1;
2710 rc.bottom = rc.top + tile_hgt;
2712 /* Cursor is done as a yellow "box" */
2714 FrameRect(hdc, &rc, hbrYellow);
2715 ReleaseDC(td->w, hdc);
2723 * Low level graphics (Assumes valid input).
2725 * Draw a "big cursor" at (x,y), using a "yellow box".
2727 static errr Term_bigcurs_win(int x, int y)
2729 term_data *td = (term_data*)(Term->data);
2734 int tile_wid, tile_hgt;
2738 /* Normal cursor in map window */
2739 Term_curs_win(x, y);
2744 tile_wid = td->tile_wid;
2745 tile_hgt = td->tile_hgt;
2748 /* Frame the grid */
2749 rc.left = x * tile_wid + td->size_ow1;
2750 rc.right = rc.left + 2 * tile_wid;
2751 rc.top = y * tile_hgt + td->size_oh1;
2752 rc.bottom = rc.top + tile_hgt;
2754 /* Cursor is done as a yellow "box" */
2756 FrameRect(hdc, &rc, hbrYellow);
2757 ReleaseDC(td->w, hdc);
2765 * Low level graphics (Assumes valid input).
2767 * Erase a "block" of "n" characters starting at (x,y).
2769 static errr Term_wipe_win(int x, int y, int n)
2771 term_data *td = (term_data*)(Term->data);
2776 /* Rectangle to erase in client coords */
2777 rc.left = x * td->tile_wid + td->size_ow1;
2778 rc.right = rc.left + n * td->tile_wid;
2779 rc.top = y * td->tile_hgt + td->size_oh1;
2780 rc.bottom = rc.top + td->tile_hgt;
2783 SetBkColor(hdc, RGB(0, 0, 0));
2784 SelectObject(hdc, td->font_id);
2789 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2790 ReleaseDC(td->w, hdc);
2798 * Low level graphics. Assumes valid input.
2800 * Draw several ("n") chars, with an attr, at a given location.
2802 * All "graphic" data is handled by "Term_pict_win()", below.
2804 * One would think there is a more efficient method for telling a window
2805 * what color it should be using to draw with, but perhaps simply changing
2806 * it every time is not too inefficient.
2808 static errr Term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
2810 term_data *td = (term_data*)(Term->data);
2814 #if 1 /* #ifdef JP */
2815 static HBITMAP WALL;
2816 static HBRUSH myBrush, oldBrush;
2818 static bool init_done = FALSE;
2821 WALL = LoadBitmap(hInstance, AppName);
2822 myBrush = CreatePatternBrush(WALL);
2827 /* Total rectangle */
2828 rc.left = x * td->tile_wid + td->size_ow1;
2829 rc.right = rc.left + n * td->tile_wid;
2830 rc.top = y * td->tile_hgt + td->size_oh1;
2831 rc.bottom = rc.top + td->tile_hgt;
2836 /* Background color */
2837 SetBkColor(hdc, RGB(0, 0, 0));
2839 /* Foreground color */
2842 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2846 SetTextColor(hdc, win_clr[a&0x0F]);
2850 SetTextColor(hdc, win_clr[a]);
2854 SelectObject(hdc, td->font_id);
2857 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2861 (td->tile_hgt != td->font_hgt) ||
2862 (td->tile_wid != td->font_wid))
2866 /* Erase complete rectangle */
2867 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2870 if (use_bg) DrawBG(hdc, &rc);
2873 rc.left += ((td->tile_wid - td->font_wid) / 2);
2874 rc.right = rc.left + td->font_wid;
2875 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2876 rc.bottom = rc.top + td->font_hgt;
2878 /* Dump each character */
2879 for (i = 0; i < n; i++)
2882 if (use_bigtile && *(s+i)=="■"[0] && *(s+i+1)=="■"[1])
2884 rc.right += td->font_wid;
2886 oldBrush = SelectObject(hdc, myBrush);
2887 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2890 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2892 SelectObject(hdc, oldBrush);
2893 SelectObject(hdc, oldPen);
2894 rc.right -= td->font_wid;
2898 rc.left += 2 * td->tile_wid;
2899 rc.right += 2 * td->tile_wid;
2901 else if ( iskanji(*(s+i)) ) /* 2バイト文字 */
2903 rc.right += td->font_wid;
2905 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2907 rc.right -= td->font_wid;
2911 rc.left += 2 * td->tile_wid;
2912 rc.right += 2 * td->tile_wid;
2913 } else if (*(s+i)==127){
2914 oldBrush = SelectObject(hdc, myBrush);
2915 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2918 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2920 SelectObject(hdc, oldBrush);
2921 SelectObject(hdc, oldPen);
2924 rc.left += td->tile_wid;
2925 rc.right += td->tile_wid;
2928 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2931 rc.left += td->tile_wid;
2932 rc.right += td->tile_wid;
2937 oldBrush = SelectObject(hdc, myBrush);
2938 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2941 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2943 SelectObject(hdc, oldBrush);
2944 SelectObject(hdc, oldPen);
2947 rc.left += td->tile_wid;
2948 rc.right += td->tile_wid;
2951 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2955 rc.left += td->tile_wid;
2956 rc.right += td->tile_wid;
2960 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2964 rc.left += td->tile_wid;
2965 rc.right += td->tile_wid;
2976 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2981 ReleaseDC(td->w, hdc);
2989 * Low level graphics. Assumes valid input.
2991 * Draw an array of "special" attr/char pairs at the given location.
2993 * We use the "Term_pict_win()" function for "graphic" data, which are
2994 * encoded by setting the "high-bits" of both the "attr" and the "char"
2995 * data. We use the "attr" to represent the "row" of the main bitmap,
2996 * and the "char" to represent the "col" of the main bitmap. The use
2997 * of this function is induced by the "higher_pict" flag.
2999 * If "graphics" is not available, we simply "wipe" the given grids.
3001 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)
3003 term_data *td = (term_data*)(Term->data);
3008 TERM_LEN x1, y1, w1, h1, tw1, th1;
3009 TERM_LEN x2, y2, w2, h2, tw2 = 0;
3019 /* Erase the grids */
3020 return (Term_wipe_win(x, y, n));
3023 /* Size of bitmap cell */
3024 w1 = infGraph.CellWidth;
3025 h1 = infGraph.CellHeight;
3026 tw1 = infGraph.TileWidth;
3027 th1 = infGraph.TileHeight;
3029 /* Size of window cell */
3032 w2 = td->map_tile_wid;
3033 h2 = td->map_tile_hgt;
3042 if (use_bigtile) tw2 *= 2;
3045 /* Location of window cell */
3046 x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
3047 y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
3053 hdcSrc = CreateCompatibleDC(hdc);
3054 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
3056 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3058 hdcMask = CreateCompatibleDC(hdc);
3059 SelectObject(hdcMask, infMask.hBitmap);
3062 /* Draw attr/char pairs */
3063 for (i = 0; i < n; i++, x2 += w2)
3065 TERM_COLOR a = ap[i];
3069 /* Extract picture */
3070 int row = (a & 0x7F);
3071 int col = (c & 0x7F);
3073 /* Location of bitmap cell */
3077 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3079 x3 = (tcp[i] & 0x7F) * w1;
3080 y3 = (tap[i] & 0x7F) * h1;
3081 tw2 = tw2 * w1 / tw1;
3085 if ((tw1 == tw2) && (th1 == h2))
3087 /* Copy the terrain picture from the bitmap to the window */
3088 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
3090 /* Mask out the tile */
3091 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3094 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3097 /* Need to stretch */
3100 /* Set the correct mode for stretching the tiles */
3101 SetStretchBltMode(hdc, COLORONCOLOR);
3103 /* Copy the terrain picture from the bitmap to the window */
3104 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
3106 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
3108 /* Only draw if terrain and overlay are different */
3109 if ((x1 != x3) || (y1 != y3))
3111 /* Mask out the tile */
3112 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3115 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3122 if ((w1 == tw2) && (h1 == h2))
3124 /* Copy the picture from the bitmap to the window */
3125 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3128 /* Need to stretch */
3131 /* Set the correct mode for stretching the tiles */
3132 SetStretchBltMode(hdc, COLORONCOLOR);
3134 /* Copy the picture from the bitmap to the window */
3135 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3141 SelectObject(hdcSrc, hbmSrcOld);
3144 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3147 SelectObject(hdcMask, hbmSrcOld);
3152 ReleaseDC(td->w, hdc);
3154 #else /* USE_GRAPHICS */
3156 /* Just erase this grid */
3157 return (Term_wipe_win(x, y, n));
3159 #endif /* USE_GRAPHICS */
3166 static void windows_map(void)
3168 term_data *td = &data[0];
3171 TERM_LEN x, min_x, max_x;
3172 TERM_LEN y, min_y, max_y;
3177 /* Only in graphics mode */
3178 if (!use_graphics) return;
3179 Term_xtra_win_clear();
3181 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3182 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3183 td->map_active = TRUE;
3188 max_x = current_floor_ptr->width;
3189 max_y = current_floor_ptr->height;
3193 for (x = min_x; x < max_x; x++)
3195 for (y = min_y; y < max_y; y++)
3197 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3199 /* Ignore non-graphics */
3200 if ((a & 0x80) && (c & 0x80))
3202 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3207 /* Hilite the player */
3208 Term_curs_win(p_ptr->x - min_x, p_ptr->y - min_y);
3210 /* Wait for a keypress, flush key buffer */
3211 Term_inkey(&c, TRUE, TRUE);
3214 /* Switch off the map display */
3215 td->map_active = FALSE;
3217 /* Restore screen */
3218 Term_xtra_win_clear();
3223 /*** Other routines ***/
3227 * Create and initialize a "term_data" given a title
3229 static void term_data_link(term_data *td)
3233 /* Initialize the term */
3234 term_init(t, td->cols, td->rows, td->keys);
3236 /* Use a "software" cursor */
3237 t->soft_cursor = TRUE;
3239 /* Use "Term_pict" for "graphic" data */
3240 t->higher_pict = TRUE;
3242 /* Erase with "white space" */
3243 t->attr_blank = TERM_WHITE;
3244 t->char_blank = ' ';
3247 /* Prepare the init/nuke hooks */
3248 t->init_hook = Term_init_win;
3249 t->nuke_hook = Term_nuke_win;
3252 /* Prepare the template hooks */
3253 t->user_hook = Term_user_win;
3254 t->xtra_hook = Term_xtra_win;
3255 t->curs_hook = Term_curs_win;
3256 t->bigcurs_hook = Term_bigcurs_win;
3257 t->wipe_hook = Term_wipe_win;
3258 t->text_hook = Term_text_win;
3259 t->pict_hook = Term_pict_win;
3261 /* Remember where we came from */
3262 t->data = (vptr)(td);
3267 * Create the windows
3269 * First, instantiate the "default" values, then read the "ini_file"
3270 * to over-ride selected values, then create the windows, and fonts.
3272 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3273 * must make active to realize the palette.
3275 static void init_windows(void)
3281 #if 0 /* #ifndef JP */
3287 WIPE(td, term_data);
3291 td->s = angband_term_name[0];
3305 #if 1 /* #ifdef JP */
3309 for (i = 1; i < MAX_TERM_DATA; i++)
3312 WIPE(td, term_data);
3313 td->s = angband_term_name[i];
3317 td->visible = FALSE;
3322 td->pos_x = (7 - i) * 30;
3323 td->pos_y = (7 - i) * 20;
3325 #if 1 /* #ifdef JP */
3335 /* Main window (need these before term_getsize gets called) */
3337 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3338 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3343 /* Sub windows (need these before term_getsize gets called) */
3344 for (i = 1; i < MAX_TERM_DATA; i++)
3347 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3348 td->dwExStyle = (WS_EX_TOOLWINDOW);
3353 for (i = 0; i < MAX_TERM_DATA; i++)
3357 #if 1 /* #ifdef JP */
3358 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3359 td->lf.lfCharSet = DEFAULT_CHARSET;
3360 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3361 /* Activate the chosen font */
3362 term_force_font(td, NULL);
3363 if(!td->tile_wid) td->tile_wid = td->font_wid;
3364 if(!td->tile_hgt) td->tile_hgt = td->font_hgt;
3366 /* Access the standard font file */
3367 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3369 /* Activate the chosen font */
3370 if (term_force_font(td, buf))
3372 /* Access the standard font file */
3373 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3375 /* Force the use of that font */
3376 (void)term_force_font(td, buf);
3381 /* Assume not bizarre */
3382 td->bizarre = FALSE;
3387 /* Analyze the font */
3390 /* Resize the window */
3391 term_window_resize(td);
3395 /* Sub windows (reverse order) */
3396 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3401 td->w = CreateWindowEx(td->dwExStyle, AngList,
3403 td->pos_x, td->pos_y,
3404 td->size_wid, td->size_hgt,
3405 HWND_DESKTOP, NULL, hInstance, NULL);
3407 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3411 td->size_hack = TRUE;
3412 ShowWindow(td->w, SW_SHOW);
3413 td->size_hack = FALSE;
3417 angband_term[i] = &td->t;
3421 /* Activate the window */
3422 SetActiveWindow(td->w);
3427 term_window_pos(&data[i], HWND_TOPMOST);
3431 term_window_pos(&data[i], td->w);
3441 td->w = CreateWindowEx(td->dwExStyle, AppName,
3443 td->pos_x, td->pos_y,
3444 td->size_wid, td->size_hgt,
3445 HWND_DESKTOP, NULL, hInstance, NULL);
3447 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3450 angband_term[0] = &td->t;
3451 normsize.x = td->cols;
3452 normsize.y = td->rows;
3454 /* Activate the main window */
3455 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3456 else ShowWindow(td->w, SW_SHOW);
3458 /* Bring main window back to top */
3459 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3463 (void)new_palette();
3466 /* Create a "brush" for drawing the "cursor" */
3467 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3470 /* Process pending messages */
3471 (void)Term_xtra_win_flush();
3479 static void setup_menus(void)
3483 HMENU hm = GetMenu(data[0].w);
3486 /* Menu "File", Disable all */
3487 EnableMenuItem(hm, IDM_FILE_NEW,
3488 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3489 EnableMenuItem(hm, IDM_FILE_OPEN,
3490 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3491 EnableMenuItem(hm, IDM_FILE_SAVE,
3492 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3493 EnableMenuItem(hm, IDM_FILE_EXIT,
3494 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3495 EnableMenuItem(hm, IDM_FILE_SCORE,
3496 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3499 /* No character available */
3500 if (!character_generated)
3502 /* Menu "File", Item "New" */
3503 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3505 /* Menu "File", Item "Open" */
3506 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3509 /* A character available */
3510 if (character_generated)
3512 /* Menu "File", Item "Save" */
3513 EnableMenuItem(hm, IDM_FILE_SAVE,
3514 MF_BYCOMMAND | MF_ENABLED);
3517 /* Menu "File", Item "Exit" */
3518 EnableMenuItem(hm, IDM_FILE_EXIT,
3519 MF_BYCOMMAND | MF_ENABLED);
3521 EnableMenuItem(hm, IDM_FILE_SCORE,
3522 MF_BYCOMMAND | MF_ENABLED);
3525 /* Menu "Window::Visibility" */
3526 for (i = 0; i < MAX_TERM_DATA; i++)
3528 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3529 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3531 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3532 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3534 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3535 MF_BYCOMMAND | MF_ENABLED);
3538 /* Menu "Window::Font" */
3539 for (i = 0; i < MAX_TERM_DATA; i++)
3541 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3542 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3544 if (data[i].visible)
3546 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3547 MF_BYCOMMAND | MF_ENABLED);
3551 /* Menu "Window::Window Position Fix" */
3552 for (i = 0; i < MAX_TERM_DATA; i++)
3554 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3555 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3557 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3558 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3560 if (data[i].visible)
3562 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3563 MF_BYCOMMAND | MF_ENABLED);
3567 /* Menu "Window::Bizarre Display" */
3568 for (i = 0; i < MAX_TERM_DATA; i++)
3570 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3571 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3573 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3574 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3576 if (data[i].visible)
3578 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3579 MF_BYCOMMAND | MF_ENABLED);
3584 /* Menu "Window::Increase Tile Width" */
3585 for (i = 0; i < MAX_TERM_DATA; i++)
3587 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3588 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3590 if (data[i].visible)
3592 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3593 MF_BYCOMMAND | MF_ENABLED);
3598 /* Menu "Window::Decrease Tile Width" */
3599 for (i = 0; i < MAX_TERM_DATA; i++)
3601 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3602 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3604 if (data[i].visible)
3606 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3607 MF_BYCOMMAND | MF_ENABLED);
3612 /* Menu "Window::Increase Tile Height" */
3613 for (i = 0; i < MAX_TERM_DATA; i++)
3615 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3616 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3618 if (data[i].visible)
3620 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3621 MF_BYCOMMAND | MF_ENABLED);
3626 /* Menu "Window::Decrease Tile Height" */
3627 for (i = 0; i < MAX_TERM_DATA; i++)
3629 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3630 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3632 if (data[i].visible)
3634 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3635 MF_BYCOMMAND | MF_ENABLED);
3640 /* Menu "Options", disable all */
3641 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3642 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3643 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3644 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3645 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3646 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3647 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3648 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3649 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3650 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3652 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3653 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3656 /* Menu "Options", Item "Map" */
3657 if (use_graphics != GRAPHICS_NONE)
3658 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3660 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3661 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3663 /* Menu "Options", update all */
3664 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3665 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3666 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3667 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3668 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3669 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3670 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3671 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3672 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3673 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3674 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3675 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3676 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3677 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3678 CheckMenuItem(hm, IDM_OPTIONS_BG,
3679 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3681 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3682 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3686 /* Menu "Options", Item "Graphics" */
3687 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3688 /* Menu "Options", Item "Graphics" */
3689 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3690 /* Menu "Options", Item "Graphics" */
3691 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3692 /* Menu "Options", Item "Graphics" */
3693 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3694 #endif /* USE_GRAPHICS */
3697 /* Menu "Options", Item "Sound" */
3698 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3699 #endif /* USE_SOUND */
3702 /* Menu "Options", Item "ScreenSaver" */
3703 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3704 MF_BYCOMMAND | MF_ENABLED);
3705 #endif /* USE_SAVER */
3710 * Check for double clicked (or dragged) savefile
3712 * Apparently, Windows copies the entire filename into the first
3713 * piece of the "command line string". Perhaps we should extract
3714 * the "basename" of that filename and append it to the "save" dir.
3716 static void check_for_save_file(LPSTR cmd_line)
3726 /* Extract filename */
3727 strcat(savefile, s);
3729 /* Validate the file */
3730 validate_file(savefile);
3732 /* Game in progress */
3733 game_in_progress = TRUE;
3741 * Process a menu command
3743 static void process_menus(WORD wCmd)
3759 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3761 else if (game_in_progress)
3763 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3767 game_in_progress = TRUE;
3780 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3782 else if (game_in_progress)
3784 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3788 memset(&ofn, 0, sizeof(ofn));
3789 ofn.lStructSize = sizeof(ofn);
3790 ofn.hwndOwner = data[0].w;
3791 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3792 ofn.nFilterIndex = 1;
3793 ofn.lpstrFile = savefile;
3794 ofn.nMaxFile = 1024;
3795 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3796 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3798 if (GetOpenFileName(&ofn))
3800 /* Load 'savefile' */
3801 validate_file(savefile);
3802 game_in_progress = TRUE;
3814 if (game_in_progress && character_generated)
3818 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3822 /* Hack -- Forget messages */
3827 do_cmd_save_game(FALSE);
3828 #else /* ZANGBAND */
3830 #endif /* ZANGBAND */
3834 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3842 if (game_in_progress && character_generated)
3846 plog(_("今は終了できません。", "You may not do that right now."));
3850 /* Hack -- Forget messages */
3859 /* do_cmd_save_game(FALSE); */
3860 #else /* ZANGBAND */
3861 /* do_cmd_save_game(); */
3862 #endif /* ZANGBAND */
3863 Term_key_push(SPECIAL_KEY_QUIT);
3871 case IDM_FILE_SCORE:
3875 /* Build the filename */
3876 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3878 /* Open the binary high score file, for reading */
3879 highscore_fd = fd_open(buf, O_RDONLY);
3881 /* Paranoia -- No score file */
3882 if (highscore_fd < 0)
3884 msg_print("Score file unavailable.");
3891 /* Display the scores */
3892 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3894 /* Shut the high score file */
3895 (void)fd_close(highscore_fd);
3897 /* Forget the high score fd */
3901 /* Hack - Flush it */
3909 case IDM_FILE_MOVIE:
3913 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3915 else if (game_in_progress)
3917 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
3921 memset(&ofn, 0, sizeof(ofn));
3922 ofn.lStructSize = sizeof(ofn);
3923 ofn.hwndOwner = data[0].w;
3924 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3925 ofn.nFilterIndex = 1;
3926 ofn.lpstrFile = savefile;
3927 ofn.nMaxFile = 1024;
3928 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3929 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3931 if (GetOpenFileName(&ofn))
3933 /* Load 'savefile' */
3934 prepare_browse_movie_aux(savefile);
3944 case IDM_WINDOW_VIS_0:
3946 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
3950 /* Window visibility */
3951 case IDM_WINDOW_VIS_1:
3952 case IDM_WINDOW_VIS_2:
3953 case IDM_WINDOW_VIS_3:
3954 case IDM_WINDOW_VIS_4:
3955 case IDM_WINDOW_VIS_5:
3956 case IDM_WINDOW_VIS_6:
3957 case IDM_WINDOW_VIS_7:
3959 i = wCmd - IDM_WINDOW_VIS_0;
3961 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3968 ShowWindow(td->w, SW_SHOW);
3969 term_data_redraw(td);
3973 td->visible = FALSE;
3975 ShowWindow(td->w, SW_HIDE);
3982 case IDM_WINDOW_FONT_0:
3983 case IDM_WINDOW_FONT_1:
3984 case IDM_WINDOW_FONT_2:
3985 case IDM_WINDOW_FONT_3:
3986 case IDM_WINDOW_FONT_4:
3987 case IDM_WINDOW_FONT_5:
3988 case IDM_WINDOW_FONT_6:
3989 case IDM_WINDOW_FONT_7:
3991 i = wCmd - IDM_WINDOW_FONT_0;
3993 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3997 term_change_font(td);
4002 /* Window Z Position */
4003 case IDM_WINDOW_POS_1:
4004 case IDM_WINDOW_POS_2:
4005 case IDM_WINDOW_POS_3:
4006 case IDM_WINDOW_POS_4:
4007 case IDM_WINDOW_POS_5:
4008 case IDM_WINDOW_POS_6:
4009 case IDM_WINDOW_POS_7:
4011 i = wCmd - IDM_WINDOW_POS_0;
4013 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4017 if (!td->posfix && td->visible)
4020 term_window_pos(td, HWND_TOPMOST);
4025 term_window_pos(td, data[0].w);
4031 /* Bizarre Display */
4032 case IDM_WINDOW_BIZ_0:
4033 case IDM_WINDOW_BIZ_1:
4034 case IDM_WINDOW_BIZ_2:
4035 case IDM_WINDOW_BIZ_3:
4036 case IDM_WINDOW_BIZ_4:
4037 case IDM_WINDOW_BIZ_5:
4038 case IDM_WINDOW_BIZ_6:
4039 case IDM_WINDOW_BIZ_7:
4041 i = wCmd - IDM_WINDOW_BIZ_0;
4043 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4047 td->bizarre = !td->bizarre;
4051 term_window_resize(td);
4056 /* Increase Tile Width */
4057 case IDM_WINDOW_I_WID_0:
4058 case IDM_WINDOW_I_WID_1:
4059 case IDM_WINDOW_I_WID_2:
4060 case IDM_WINDOW_I_WID_3:
4061 case IDM_WINDOW_I_WID_4:
4062 case IDM_WINDOW_I_WID_5:
4063 case IDM_WINDOW_I_WID_6:
4064 case IDM_WINDOW_I_WID_7:
4066 i = wCmd - IDM_WINDOW_I_WID_0;
4068 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4076 term_window_resize(td);
4081 /* Decrease Tile Height */
4082 case IDM_WINDOW_D_WID_0:
4083 case IDM_WINDOW_D_WID_1:
4084 case IDM_WINDOW_D_WID_2:
4085 case IDM_WINDOW_D_WID_3:
4086 case IDM_WINDOW_D_WID_4:
4087 case IDM_WINDOW_D_WID_5:
4088 case IDM_WINDOW_D_WID_6:
4089 case IDM_WINDOW_D_WID_7:
4091 i = wCmd - IDM_WINDOW_D_WID_0;
4093 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4101 term_window_resize(td);
4106 /* Increase Tile Height */
4107 case IDM_WINDOW_I_HGT_0:
4108 case IDM_WINDOW_I_HGT_1:
4109 case IDM_WINDOW_I_HGT_2:
4110 case IDM_WINDOW_I_HGT_3:
4111 case IDM_WINDOW_I_HGT_4:
4112 case IDM_WINDOW_I_HGT_5:
4113 case IDM_WINDOW_I_HGT_6:
4114 case IDM_WINDOW_I_HGT_7:
4116 i = wCmd - IDM_WINDOW_I_HGT_0;
4118 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4126 term_window_resize(td);
4131 /* Decrease Tile Height */
4132 case IDM_WINDOW_D_HGT_0:
4133 case IDM_WINDOW_D_HGT_1:
4134 case IDM_WINDOW_D_HGT_2:
4135 case IDM_WINDOW_D_HGT_3:
4136 case IDM_WINDOW_D_HGT_4:
4137 case IDM_WINDOW_D_HGT_5:
4138 case IDM_WINDOW_D_HGT_6:
4139 case IDM_WINDOW_D_HGT_7:
4141 i = wCmd - IDM_WINDOW_D_HGT_0;
4143 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4151 term_window_resize(td);
4156 case IDM_OPTIONS_NO_GRAPHICS:
4160 plog("You may not do that right now.");
4164 /* Toggle "arg_graphics" */
4165 if (arg_graphics != GRAPHICS_NONE)
4167 arg_graphics = GRAPHICS_NONE;
4169 /* React to changes */
4170 Term_xtra_win_react();
4172 /* Hack -- Force redraw */
4173 Term_key_push(KTRL('R'));
4179 case IDM_OPTIONS_OLD_GRAPHICS:
4183 plog("You may not do that right now.");
4187 /* Toggle "arg_graphics" */
4188 if (arg_graphics != GRAPHICS_ORIGINAL)
4190 arg_graphics = GRAPHICS_ORIGINAL;
4192 /* React to changes */
4193 Term_xtra_win_react();
4195 /* Hack -- Force redraw */
4196 Term_key_push(KTRL('R'));
4202 case IDM_OPTIONS_NEW_GRAPHICS:
4206 plog("You may not do that right now.");
4210 /* Toggle "arg_graphics" */
4211 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4213 arg_graphics = GRAPHICS_ADAM_BOLT;
4215 /* React to changes */
4216 Term_xtra_win_react();
4218 /* Hack -- Force redraw */
4219 Term_key_push(KTRL('R'));
4225 case IDM_OPTIONS_NEW2_GRAPHICS:
4229 plog("You may not do that right now.");
4233 /* Toggle "arg_graphics" */
4234 if (arg_graphics != GRAPHICS_HENGBAND)
4236 arg_graphics = GRAPHICS_HENGBAND;
4238 /* React to changes */
4239 Term_xtra_win_react();
4241 /* Hack -- Force redraw */
4242 Term_key_push(KTRL('R'));
4248 case IDM_OPTIONS_BIGTILE:
4253 plog("You may not do that right now.");
4257 /* Toggle "arg_sound" */
4258 arg_bigtile = !arg_bigtile;
4261 Term_activate(&td->t);
4263 /* Resize the term */
4264 Term_resize(td->cols, td->rows);
4267 InvalidateRect(td->w, NULL, TRUE);
4272 case IDM_OPTIONS_MUSIC:
4276 plog("You may not do that right now.");
4280 /* Toggle "arg_sound" */
4281 arg_music = !arg_music;
4283 /* React to changes */
4284 Term_xtra_win_react();
4286 /* Hack -- Force redraw */
4287 Term_key_push(KTRL('R'));
4292 case IDM_OPTIONS_SOUND:
4296 plog("You may not do that right now.");
4300 /* Toggle "arg_sound" */
4301 arg_sound = !arg_sound;
4303 /* React to changes */
4304 Term_xtra_win_react();
4306 /* Hack -- Force redraw */
4307 Term_key_push(KTRL('R'));
4313 case IDM_OPTIONS_BG:
4317 plog("You may not do that right now.");
4321 /* Toggle "use_bg" */
4326 /* React to changes */
4327 Term_xtra_win_react();
4329 /* Hack -- Force redraw */
4330 Term_key_push(KTRL('R'));
4336 case IDM_OPTIONS_OPEN_BG:
4340 plog("You may not do that right now.");
4345 memset(&ofn, 0, sizeof(ofn));
4346 ofn.lStructSize = sizeof(ofn);
4347 ofn.hwndOwner = data[0].w;
4348 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4349 ofn.nFilterIndex = 1;
4350 ofn.lpstrFile = bg_bitmap_file;
4351 ofn.nMaxFile = 1023;
4352 ofn.lpstrInitialDir = NULL;
4353 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
4354 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4356 if (GetOpenFileName(&ofn))
4358 /* Load 'savefile' */
4363 /* React to changes */
4364 Term_xtra_win_react();
4366 /* Hack -- Force redraw */
4367 Term_key_push(KTRL('R'));
4372 case IDM_DUMP_SCREEN_HTML:
4374 static char buf[1024] = "";
4375 memset(&ofn, 0, sizeof(ofn));
4376 ofn.lStructSize = sizeof(ofn);
4377 ofn.hwndOwner = data[0].w;
4378 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4379 ofn.nFilterIndex = 1;
4380 ofn.lpstrFile = buf;
4381 ofn.nMaxFile = 1023;
4382 ofn.lpstrDefExt = "html";
4383 ofn.lpstrInitialDir = NULL;
4384 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
4385 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4387 if (GetSaveFileName(&ofn))
4389 do_cmd_save_screen_html_aux(buf, 0);
4396 case IDM_OPTIONS_SAVER:
4400 DestroyWindow(hwndSaver);
4405 /* Create a screen scaver window */
4406 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4407 "Angband Screensaver",
4408 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4409 0, 0, GetSystemMetrics(SM_CXSCREEN),
4410 GetSystemMetrics(SM_CYSCREEN),
4411 NULL, NULL, hInstance, NULL);
4415 /* Push the window to the bottom */
4416 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4420 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
4428 case IDM_OPTIONS_MAP:
4434 case IDM_HELP_CONTENTS:
4438 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4439 if (check_file(tmp))
4441 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4445 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4446 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4449 #else /* HTML_HELP */
4452 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4453 if (check_file(tmp))
4455 sprintf(buf, "winhelp.exe %s", tmp);
4456 WinExec(buf, SW_NORMAL);
4460 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4461 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4465 #endif /* HTML_HELP */
4471 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4478 /* Extract the modifiers */
4479 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4480 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4481 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4483 Term_no_press = (ma) ? TRUE : FALSE;
4485 /* Handle "special" keys */
4486 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4488 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4489 bool numpad = FALSE;
4491 /* Begin the macro trigger */
4494 /* Send the modifiers */
4495 if (mc) Term_keypress('C');
4496 if (ms) Term_keypress('S');
4497 if (ma) Term_keypress('A');
4499 /* Extract "scan code" */
4500 i = LOBYTE(HIWORD(lParam));
4502 /* Introduce the scan code */
4505 /* Extended key bit */
4508 /* Numpad Enter and '/' are extended key */
4510 Term_no_press = TRUE;
4511 case VK_RETURN: /* Enter */
4514 /* Other extended keys are on full keyboard */
4530 Term_no_press = TRUE;
4534 case VK_PRIOR: /* Page Up */
4535 case VK_NEXT: /* Page Down */
4545 /* Special modifiers for keypad keys */
4546 if (numpad) Term_keypress('K');
4548 /* Encode the hexidecimal scan code */
4549 Term_keypress(hexsym[i/16]);
4550 Term_keypress(hexsym[i%16]);
4552 /* End the macro trigger */
4563 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4564 WPARAM wParam, LPARAM lParam);
4565 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4566 WPARAM wParam, LPARAM lParam)
4567 #else /* __MWERKS__ */
4568 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4569 #endif /* __MWERKS__ */
4575 MINMAXINFO FAR *lpmmi;
4581 /* Acquire proper "term_data" info */
4582 td = (term_data *)GetWindowLong(hWnd, 0);
4584 /* Handle message */
4589 SetWindowLong(hWnd, 0, (LONG)(my_td));
4596 mop.dwCallback=(DWORD)hWnd;
4601 case WM_GETMINMAXINFO:
4603 MINMAXINFO FAR *lpmmi;
4606 lpmmi = (MINMAXINFO FAR *)lParam;
4608 /* this message was sent before WM_NCCREATE */
4611 /* Minimum window size is 80x24 */
4612 rc.left = rc.top = 0;
4613 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4614 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4617 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4619 /* Save minimum size */
4620 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4621 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4628 BeginPaint(hWnd, &ps);
4629 if (td) term_data_redraw(td);
4630 EndPaint(hWnd, &ps);
4631 ValidateRect(hWnd, NULL);
4638 if(wParam == MCI_NOTIFY_SUCCESSFUL)
4640 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4641 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4650 if (process_keydown(wParam, lParam))
4657 if (Term_no_press) Term_no_press = FALSE;
4658 else Term_keypress(wParam);
4662 case WM_LBUTTONDOWN:
4664 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4665 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4677 TERM_LEN dx = abs(oldx - mousex) + 1;
4678 TERM_LEN dy = abs(oldy - mousey) + 1;
4679 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
4680 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
4690 hGlobal = GlobalAlloc(GHND, sz + 1);
4691 if (hGlobal == NULL) return 0;
4692 lpStr = (LPSTR)GlobalLock(hGlobal);
4694 for (i = 0; i < dy; i++)
4698 char **scr = data[0].t.scr->c;
4700 C_MAKE(s, (dx + 1), char);
4701 strncpy(s, &scr[oy + i][ox], dx);
4705 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4708 if (ox + dx < data[0].cols)
4710 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4713 for (j = 0; j < dx; j++)
4715 if (s[j] == 127) s[j] = '#';
4719 for (j = 0; j < dx; j++)
4721 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4731 GlobalUnlock(hGlobal);
4732 if (OpenClipboard(hWnd) == 0)
4734 GlobalFree(hGlobal);
4738 SetClipboardData(CF_TEXT, hGlobal);
4751 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4752 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4757 dx = abs(oldx - mousex) + 1;
4758 dy = abs(oldy - mousey) + 1;
4759 ox = (oldx > mousex) ? mousex : oldx;
4760 oy = (oldy > mousey) ? mousey : oldy;
4761 Term_inversed_area(hWnd, ox, oy, dx, dy);
4768 dx = abs(cx - mousex) + 1;
4769 dy = abs(cy - mousey) + 1;
4770 ox = (cx > mousex) ? mousex : cx;
4771 oy = (cy > mousey) ? mousey : cy;
4772 Term_inversed_area(hWnd, ox, oy, dx, dy);
4788 if (game_in_progress && character_generated)
4792 plog(_("今は終了できません。", "You may not do that right now."));
4796 /* Hack -- Forget messages */
4805 /* do_cmd_save_game(FALSE); */
4806 #else /* ZANGBAND */
4807 /* do_cmd_save_game(); */
4808 #endif /* ZANGBAND */
4809 Term_key_push(SPECIAL_KEY_QUIT);
4816 case WM_QUERYENDSESSION:
4818 if (game_in_progress && character_generated)
4820 /* Hack -- Forget messages */
4823 /* Mega-Hack -- Delay death */
4824 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4825 do_cmd_write_nikki(NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4827 /* Hardcode panic save */
4828 p_ptr->panic_save = 1;
4830 /* Forbid suspend */
4831 signals_ignore_tstp();
4833 /* Indicate panic save */
4834 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4837 (void)save_player();
4851 process_menus(LOWORD(wParam));
4857 /* this message was sent before WM_NCCREATE */
4860 /* it was sent from inside CreateWindowEx */
4861 if (!td->w) return 1;
4863 /* was sent from WM_SIZE */
4864 if (td->size_hack) return 1;
4868 case SIZE_MINIMIZED:
4870 /* Hide sub-windows */
4871 for (i = 1; i < MAX_TERM_DATA; i++)
4873 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4878 case SIZE_MAXIMIZED:
4885 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4886 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4889 if ((td->cols != cols) || (td->rows != rows))
4891 /* Save the new size */
4895 if (!IsZoomed(td->w) && !IsIconic(td->w))
4897 normsize.x = td->cols;
4898 normsize.y = td->rows;
4902 Term_activate(&td->t);
4904 /* Resize the term */
4905 Term_resize(td->cols, td->rows);
4908 InvalidateRect(td->w, NULL, TRUE);
4911 td->size_hack = TRUE;
4913 /* Show sub-windows */
4914 for (i = 1; i < MAX_TERM_DATA; i++)
4916 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4919 td->size_hack = FALSE;
4927 case WM_PALETTECHANGED:
4929 /* Ignore if palette change caused by itself */
4930 if ((HWND)wParam == hWnd) return 0;
4932 /* Fall through... */
4935 case WM_QUERYNEWPALETTE:
4937 if (!paletted) return 0;
4941 SelectPalette(hdc, hPal, FALSE);
4943 i = RealizePalette(hdc);
4945 /* if any palette entries changed, repaint the window. */
4946 if (i) InvalidateRect(hWnd, NULL, TRUE);
4948 ReleaseDC(hWnd, hdc);
4955 if (wParam && !HIWORD(lParam))
4957 /* Do something to sub-windows */
4958 for (i = 1; i < MAX_TERM_DATA; i++)
4960 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4963 /* Focus on main window */
4972 case WM_ACTIVATEAPP:
4974 if (IsIconic(td->w)) break;
4976 for (i = 1; i < MAX_TERM_DATA; i++)
4982 ShowWindow(data[i].w, SW_SHOW);
4986 ShowWindow(data[i].w, SW_HIDE);
4993 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4998 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4999 WPARAM wParam, LPARAM lParam);
5000 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5001 WPARAM wParam, LPARAM lParam)
5002 #else /* __MWERKS__ */
5003 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5004 WPARAM wParam, LPARAM lParam)
5005 #endif /* __MWERKS__ */
5009 MINMAXINFO FAR *lpmmi;
5017 /* Acquire proper "term_data" info */
5018 td = (term_data *)GetWindowLong(hWnd, 0);
5020 /* Process message */
5025 SetWindowLong(hWnd, 0, (LONG)(my_td));
5034 case WM_GETMINMAXINFO:
5036 MINMAXINFO FAR *lpmmi;
5039 lpmmi = (MINMAXINFO FAR *)lParam;
5041 /* this message was sent before WM_NCCREATE */
5044 /* Minimum window size is 80x24 */
5045 rc.left = rc.top = 0;
5046 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5047 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5050 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5052 /* Save minimum size */
5053 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5054 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5064 /* this message was sent before WM_NCCREATE */
5067 /* it was sent from inside CreateWindowEx */
5068 if (!td->w) return 1;
5070 /* was sent from inside WM_SIZE */
5071 if (td->size_hack) return 1;
5073 td->size_hack = TRUE;
5075 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5076 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5079 if ((td->cols != cols) || (td->rows != rows))
5082 term *old_term = Term;
5084 /* Save the new size */
5089 Term_activate(&td->t);
5091 /* Resize the term */
5092 Term_resize(td->cols, td->rows);
5095 Term_activate(old_term);
5098 InvalidateRect(td->w, NULL, TRUE);
5100 /* HACK - Redraw all windows */
5101 p_ptr->window = 0xFFFFFFFF;
5105 td->size_hack = FALSE;
5112 BeginPaint(hWnd, &ps);
5113 if (td) term_data_redraw(td);
5114 EndPaint(hWnd, &ps);
5121 if (process_keydown(wParam, lParam))
5128 if (Term_no_press) Term_no_press = FALSE;
5129 else Term_keypress(wParam);
5133 case WM_PALETTECHANGED:
5135 /* ignore if palette change caused by itself */
5136 if ((HWND)wParam == hWnd) return FALSE;
5137 /* otherwise, fall through!!! */
5140 case WM_QUERYNEWPALETTE:
5142 if (!paletted) return 0;
5144 SelectPalette(hdc, hPal, FALSE);
5145 i = RealizePalette(hdc);
5146 /* if any palette entries changed, repaint the window. */
5147 if (i) InvalidateRect(hWnd, NULL, TRUE);
5148 ReleaseDC(hWnd, hdc);
5152 case WM_NCLBUTTONDOWN:
5156 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5157 #endif /* HTCLOSE */
5159 if (wParam == HTSYSMENU)
5163 td->visible = FALSE;
5164 ShowWindow(td->w, SW_HIDE);
5174 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5180 #define MOUSE_SENS 40
5183 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5184 WPARAM wParam, LPARAM lParam);
5185 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5186 WPARAM wParam, LPARAM lParam)
5187 #else /* __MWERKS__ */
5188 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5189 WPARAM wParam, LPARAM lParam)
5190 #endif /* __MWERKS__ */
5192 static int iMouse = 0;
5193 static WORD xMouse = 0;
5194 static WORD yMouse = 0;
5216 if (LOWORD(wParam) == WA_INACTIVE) break;
5218 /* else fall through */
5222 case WM_LBUTTONDOWN:
5223 case WM_MBUTTONDOWN:
5224 case WM_RBUTTONDOWN:
5227 SendMessage(hWnd, WM_CLOSE, 0, 0);
5235 dx = LOWORD(lParam) - xMouse;
5236 dy = HIWORD(lParam) - yMouse;
5238 if (dx < 0) dx = -dx;
5239 if (dy < 0) dy = -dy;
5241 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5243 SendMessage(hWnd, WM_CLOSE, 0, 0);
5247 /* Save last location */
5249 xMouse = LOWORD(lParam);
5250 yMouse = HIWORD(lParam);
5257 DestroyWindow(hwndSaver);
5263 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5266 #endif /* USE_SAVER */
5272 /*** Temporary Hooks ***/
5276 * Display warning message (see "z-util.c")
5278 static void hack_plog(concptr str)
5280 /* Give a warning */
5284 MessageBox(NULL, str, "警告!",
5285 MB_ICONEXCLAMATION | MB_OK);
5287 MessageBox(NULL, str, "Warning",
5288 MB_ICONEXCLAMATION | MB_OK);
5296 * Display error message and quit (see "z-util.c")
5298 static void hack_quit(concptr str)
5300 /* Give a warning */
5304 MessageBox(NULL, str, "エラー!",
5305 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5307 MessageBox(NULL, str, "Error",
5308 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5313 /* Unregister the classes */
5314 UnregisterClass(AppName, hInstance);
5316 /* Destroy the icon */
5317 if (hIcon) DestroyIcon(hIcon);
5325 /*** Various hooks ***/
5329 * Display warning message (see "z-util.c")
5331 static void hook_plog(concptr str)
5337 MessageBox(data[0].w, str, "警告!",
5338 MB_ICONEXCLAMATION | MB_OK);
5340 MessageBox(data[0].w, str, "Warning",
5341 MB_ICONEXCLAMATION | MB_OK);
5349 * Display error message and quit (see "z-util.c")
5351 static void hook_quit(concptr str)
5356 /* Give a warning */
5360 MessageBox(data[0].w, str, "エラー!",
5361 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5363 MessageBox(data[0].w, str, "Error",
5364 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5370 /* Save the preferences */
5374 /*** Could use 'Term_nuke_win()' */
5376 /* Destroy all windows */
5377 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5379 term_force_font(&data[i], NULL);
5380 if (data[i].font_want) string_free(data[i].font_want);
5381 if (data[i].w) DestroyWindow(data[i].w);
5385 /* Free the bitmap stuff */
5387 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5388 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5390 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5391 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5393 #endif /* USE_GRAPHICS */
5395 /*** Free some other stuff ***/
5397 DeleteObject(hbrYellow);
5402 if (hPal) DeleteObject(hPal);
5404 UnregisterClass(AppName, hInstance);
5406 if (hIcon) DestroyIcon(hIcon);
5413 /*** Initialize ***/
5419 static void init_stuff(void)
5426 /* Get program name with full path */
5427 GetModuleFileName(hInstance, path, 512);
5429 /* Save the "program name" */
5432 /* Get the name of the "*.ini" file */
5433 strcpy(path + strlen(path) - 4, ".INI");
5435 /* Save the the name of the ini-file */
5436 ini_file = string_make(path);
5438 /* Analyze the path */
5444 if (path[i] == '\\')
5451 /* Add "lib" to the path */
5452 strcpy(path + i + 1, "lib\\");
5454 /* Validate the path */
5455 validate_dir(path, TRUE);
5457 /* Init the file paths */
5458 init_file_paths(path);
5460 /* Hack -- Validate the paths */
5461 validate_dir(ANGBAND_DIR_APEX, FALSE);
5462 validate_dir(ANGBAND_DIR_BONE, FALSE);
5464 /* Allow missing 'edit' directory */
5465 if (!check_dir(ANGBAND_DIR_EDIT))
5467 /* Must have 'data'! */
5468 validate_dir(ANGBAND_DIR_DATA, TRUE);
5472 /* Don't need 'data' */
5473 validate_dir(ANGBAND_DIR_DATA, FALSE);
5476 validate_dir(ANGBAND_DIR_FILE, TRUE);
5477 validate_dir(ANGBAND_DIR_HELP, FALSE);
5478 validate_dir(ANGBAND_DIR_INFO, FALSE);
5479 validate_dir(ANGBAND_DIR_PREF, TRUE);
5480 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5481 validate_dir(ANGBAND_DIR_USER, TRUE);
5482 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5484 /* Build the filename */
5485 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
5487 /* Hack -- Validate the "news.txt" file */
5488 validate_file(path);
5491 #if 0 /* #ifndef JP */
5492 /* Build the "font" path */
5493 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5495 /* Allocate the path */
5496 ANGBAND_DIR_XTRA_FONT = string_make(path);
5498 /* Validate the "font" directory */
5499 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5501 /* Build the filename */
5502 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5504 /* Hack -- Validate the basic font */
5505 validate_file(path);
5511 /* Build the "graf" path */
5512 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5514 /* Allocate the path */
5515 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5517 /* Validate the "graf" directory */
5518 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5520 #endif /* USE_GRAPHICS */
5525 /* Build the "sound" path */
5526 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5528 /* Allocate the path */
5529 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5531 /* Validate the "sound" directory */
5532 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5534 #endif /* USE_SOUND */
5538 /* Build the "music" path */
5539 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5541 /* Allocate the path */
5542 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5544 /* Validate the "music" directory */
5545 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5547 #endif /* USE_MUSIC */
5549 /* Build the "help" path */
5550 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5552 /* Allocate the path */
5553 ANGBAND_DIR_XTRA_HELP = string_make(path);
5555 /* Validate the "help" directory */
5556 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5560 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
5562 static bool is_already_running(void)
5564 bool result = FALSE;
5567 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5568 if (GetLastError() == ERROR_ALREADY_EXISTS)
5577 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
5579 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5580 LPSTR lpCmdLine, int nCmdShow)
5588 setlocale(LC_ALL, "ja_JP.utf8");
5597 /* Prevent multiple run */
5598 if (is_already_running())
5601 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
5602 _("エラー!", "Error") ,
5603 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5607 if (hPrevInst == NULL)
5609 wc.style = CS_CLASSDC;
5610 wc.lpfnWndProc = AngbandWndProc;
5612 wc.cbWndExtra = 4; /* one long pointer to term_data */
5613 wc.hInstance = hInst;
5614 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5615 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5616 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5617 wc.lpszMenuName = AppName;
5618 wc.lpszClassName = AppName;
5620 if (!RegisterClass(&wc)) exit(1);
5622 wc.lpfnWndProc = AngbandListProc;
5623 wc.lpszMenuName = NULL;
5624 wc.lpszClassName = AngList;
5626 if (!RegisterClass(&wc)) exit(2);
5630 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5631 wc.lpfnWndProc = AngbandSaverProc;
5633 wc.lpszMenuName = NULL;
5634 wc.lpszClassName = "WindowsScreenSaverClass";
5636 if (!RegisterClass(&wc)) exit(3);
5642 /* Temporary hooks */
5643 plog_aux = hack_plog;
5644 quit_aux = hack_quit;
5645 core_aux = hack_quit;
5647 /* Prepare the filepaths */
5650 /* Initialize the keypress analyzer */
5651 for (i = 0; special_key_list[i]; ++i)
5653 special_key[special_key_list[i]] = TRUE;
5655 /* Initialize the keypress analyzer */
5656 for (i = 0; ignore_key_list[i]; ++i)
5658 ignore_key[ignore_key_list[i]] = TRUE;
5661 /* Determine if display is 16/256/true color */
5663 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5664 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5665 ReleaseDC(NULL, hdc);
5667 /* Initialize the colors */
5668 for (i = 0; i < 256; i++)
5672 /* Extract desired values */
5673 rv = angband_color_table[i][1];
5674 gv = angband_color_table[i][2];
5675 bv = angband_color_table[i][3];
5677 /* Extract the "complex" code */
5678 win_clr[i] = PALETTERGB(rv, gv, bv);
5680 /* Save the "simple" code */
5681 angband_color_table[i][0] = win_pal[i];
5684 /* Prepare the windows */
5690 /* Activate hooks */
5691 plog_aux = hook_plog;
5692 quit_aux = hook_quit;
5693 core_aux = hook_quit;
5695 /* Set the system suffix */
5696 ANGBAND_SYS = "win";
5698 /* Set the keyboard suffix */
5699 if (7 != GetKeyboardType(0))
5700 ANGBAND_KEYBOARD = "0";
5703 /* Japanese keyboard */
5704 switch (GetKeyboardType(1))
5706 case 0x0D01: case 0x0D02:
5707 case 0x0D03: case 0x0D04:
5708 case 0x0D05: case 0x0D06:
5710 ANGBAND_KEYBOARD = "NEC98";
5714 ANGBAND_KEYBOARD = "JAPAN";
5718 /* Catch nasty signals */
5721 Term_activate(term_screen);
5724 /* We are now initialized */
5727 if(lpCmdLine[0] == '-'){
5728 switch(lpCmdLine[1])
5733 if (!lpCmdLine[2]) break;
5734 chuukei_server = TRUE;
5735 if(connect_chuukei_server(&lpCmdLine[2])<0){
5736 msg_print("connect fail");
5739 msg_print("connect");
5747 if (!lpCmdLine[2]) break;
5748 chuukei_client = TRUE;
5749 connect_chuukei_server(&lpCmdLine[2]);
5757 if (!lpCmdLine[2]) break;
5758 prepare_browse_movie(&lpCmdLine[2]);
5768 /* Did the user double click on a save file? */
5769 if(!chuukei_server) check_for_save_file(lpCmdLine);
5771 /* Did the user double click on a save file? */
5772 check_for_save_file(lpCmdLine);
5775 /* Prompt the user */
5776 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
5780 /* Process messages forever */
5781 while (GetMessage(&msg, NULL, 0, 0))
5783 TranslateMessage(&msg);
5784 DispatchMessage(&msg);
5791 #endif /* WINDOWS */