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).
103 #include "view-mainwindow.h"
105 #include "floor-events.h"
117 * Extract the "WIN32" flag from the compiler
119 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
127 * Hack -- allow use of "screen saver" mode
133 * Menu constants -- see "ANGBAND.RC"
136 #define IDM_FILE_NEW 100
137 #define IDM_FILE_OPEN 101
138 #define IDM_FILE_SAVE 110
139 #define IDM_FILE_SCORE 120
140 #define IDM_FILE_MOVIE 121
141 #define IDM_FILE_EXIT 130
143 #define IDM_WINDOW_VIS_0 200
144 #define IDM_WINDOW_VIS_1 201
145 #define IDM_WINDOW_VIS_2 202
146 #define IDM_WINDOW_VIS_3 203
147 #define IDM_WINDOW_VIS_4 204
148 #define IDM_WINDOW_VIS_5 205
149 #define IDM_WINDOW_VIS_6 206
150 #define IDM_WINDOW_VIS_7 207
152 #define IDM_WINDOW_FONT_0 210
153 #define IDM_WINDOW_FONT_1 211
154 #define IDM_WINDOW_FONT_2 212
155 #define IDM_WINDOW_FONT_3 213
156 #define IDM_WINDOW_FONT_4 214
157 #define IDM_WINDOW_FONT_5 215
158 #define IDM_WINDOW_FONT_6 216
159 #define IDM_WINDOW_FONT_7 217
161 #define IDM_WINDOW_POS_0 220
162 #define IDM_WINDOW_POS_1 221
163 #define IDM_WINDOW_POS_2 222
164 #define IDM_WINDOW_POS_3 223
165 #define IDM_WINDOW_POS_4 224
166 #define IDM_WINDOW_POS_5 225
167 #define IDM_WINDOW_POS_6 226
168 #define IDM_WINDOW_POS_7 227
170 #define IDM_WINDOW_BIZ_0 230
171 #define IDM_WINDOW_BIZ_1 231
172 #define IDM_WINDOW_BIZ_2 232
173 #define IDM_WINDOW_BIZ_3 233
174 #define IDM_WINDOW_BIZ_4 234
175 #define IDM_WINDOW_BIZ_5 235
176 #define IDM_WINDOW_BIZ_6 236
177 #define IDM_WINDOW_BIZ_7 237
179 #define IDM_WINDOW_I_WID_0 240
180 #define IDM_WINDOW_I_WID_1 241
181 #define IDM_WINDOW_I_WID_2 242
182 #define IDM_WINDOW_I_WID_3 243
183 #define IDM_WINDOW_I_WID_4 244
184 #define IDM_WINDOW_I_WID_5 245
185 #define IDM_WINDOW_I_WID_6 246
186 #define IDM_WINDOW_I_WID_7 247
188 #define IDM_WINDOW_D_WID_0 250
189 #define IDM_WINDOW_D_WID_1 251
190 #define IDM_WINDOW_D_WID_2 252
191 #define IDM_WINDOW_D_WID_3 253
192 #define IDM_WINDOW_D_WID_4 254
193 #define IDM_WINDOW_D_WID_5 255
194 #define IDM_WINDOW_D_WID_6 256
195 #define IDM_WINDOW_D_WID_7 257
197 #define IDM_WINDOW_I_HGT_0 260
198 #define IDM_WINDOW_I_HGT_1 261
199 #define IDM_WINDOW_I_HGT_2 262
200 #define IDM_WINDOW_I_HGT_3 263
201 #define IDM_WINDOW_I_HGT_4 264
202 #define IDM_WINDOW_I_HGT_5 265
203 #define IDM_WINDOW_I_HGT_6 266
204 #define IDM_WINDOW_I_HGT_7 267
206 #define IDM_WINDOW_D_HGT_0 270
207 #define IDM_WINDOW_D_HGT_1 271
208 #define IDM_WINDOW_D_HGT_2 272
209 #define IDM_WINDOW_D_HGT_3 273
210 #define IDM_WINDOW_D_HGT_4 274
211 #define IDM_WINDOW_D_HGT_5 275
212 #define IDM_WINDOW_D_HGT_6 276
213 #define IDM_WINDOW_D_HGT_7 277
215 #define IDM_OPTIONS_NO_GRAPHICS 400
216 #define IDM_OPTIONS_OLD_GRAPHICS 401
217 #define IDM_OPTIONS_NEW_GRAPHICS 402
218 #define IDM_OPTIONS_NEW2_GRAPHICS 403
219 #define IDM_OPTIONS_BIGTILE 409
220 #define IDM_OPTIONS_SOUND 410
221 #define IDM_OPTIONS_MUSIC 411
222 #define IDM_OPTIONS_SAVER 420
223 #define IDM_OPTIONS_MAP 430
224 #define IDM_OPTIONS_BG 440
225 #define IDM_OPTIONS_OPEN_BG 441
227 #define IDM_DUMP_SCREEN_HTML 450
229 #define IDM_HELP_CONTENTS 901
232 * Exclude parts of WINDOWS.H that are not needed
234 #define NOCOMM /* Comm driver APIs and definitions */
235 #define NOLOGERROR /* LogError() and related definitions */
236 #define NOPROFILER /* Profiler APIs */
237 #define NOLFILEIO /* _l* file I/O routines */
238 #define NOOPENFILE /* OpenFile and related definitions */
239 #define NORESOURCE /* Resource management */
240 #define NOATOM /* Atom management */
241 #define NOLANGUAGE /* Character test routines */
242 #define NOLSTRING /* lstr* string management routines */
243 #define NODBCS /* Double-byte character set routines */
244 #define NOKEYBOARDINFO /* Keyboard driver routines */
245 #define NOCOLOR /* COLOR_* color values */
246 #define NODRAWTEXT /* DrawText() and related definitions */
247 #define NOSCALABLEFONT /* Truetype scalable font support */
248 #define NOMETAFILE /* Metafile support */
249 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
250 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
251 #define NOKEYSTATES /* MK_* message key state flags */
252 #define NOWH /* SetWindowsHook and related WH_* definitions */
253 #define NOCLIPBOARD /* Clipboard APIs and definitions */
254 #define NOICONS /* IDI_* icon IDs */
255 #define NOMDI /* MDI support */
256 #define NOHELP /* Help support */
258 /* Not defined since it breaks Borland C++ 5.5 */
259 /* #define NOCTLMGR */ /* Control management and controls */
262 * Exclude parts of WINDOWS.H that are not needed (Win32)
264 #define WIN32_LEAN_AND_MEAN
265 #define NONLS /* All NLS defines and routines */
266 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
267 #define NOKANJI /* Kanji support stuff. */
268 #define NOMCX /* Modem Configuration Extensions */
271 * Include the "windows" support file
276 * Exclude parts of MMSYSTEM.H that are not needed
278 #define MMNODRV /* Installable driver support */
279 #define MMNOWAVE /* Waveform support */
280 #define MMNOMIDI /* MIDI support */
281 #define MMNOAUX /* Auxiliary audio support */
282 #define MMNOTIMER /* Timer support */
283 #define MMNOJOY /* Joystick support */
284 #define MMNOMCI /* MCI support */
285 #define MMNOMMIO /* Multimedia file I/O support */
286 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
289 * Include some more files. Note: the Cygnus Cygwin compiler
290 * doesn't use mmsystem.h instead it includes the winmm library
291 * which performs a similar function.
293 #include <mmsystem.h>
297 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
298 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
300 /* #define HTML_HELP */
303 #include <htmlhelp.h>
304 #endif /* HTML_HELP */
307 * Include the support for loading bitmaps
310 # include "readdib.h"
314 * Hack -- Fake declarations from "dos.h"
317 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
319 #define FA_LABEL 0x08 /* Volume label */
320 #define FA_DIREC 0x10 /* Directory */
321 unsigned _cdecl _dos_getfileattr(concptr , unsigned *);
325 * Silliness in WIN32 drawing routine
328 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
332 * Silliness for Windows 95
334 #ifndef WS_EX_TOOLWINDOW
335 # define WS_EX_TOOLWINDOW 0
339 * Foreground color bits (hard-coded by DOS)
341 #define VID_BLACK 0x00
342 #define VID_BLUE 0x01
343 #define VID_GREEN 0x02
344 #define VID_CYAN 0x03
346 #define VID_MAGENTA 0x05
347 #define VID_YELLOW 0x06
348 #define VID_WHITE 0x07
351 * Bright text (hard-coded by DOS)
353 #define VID_BRIGHT 0x08
356 * Background color bits (hard-coded by DOS)
358 #define VUD_BLACK 0x00
359 #define VUD_BLUE 0x10
360 #define VUD_GREEN 0x20
361 #define VUD_CYAN 0x30
363 #define VUD_MAGENTA 0x50
364 #define VUD_YELLOW 0x60
365 #define VUD_WHITE 0x70
368 * Blinking text (hard-coded by DOS)
370 #define VUD_BRIGHT 0x80
376 typedef struct _term_data term_data;
380 * @brief ターム情報構造体 / Extra "term" data
383 * pos_x / pos_y は各タームの左上点座標を指す。
386 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
387 * 1ドットずつ調整するステータスを指す。
388 * また、フォントを変更すると都度自動調整される。
391 * Note the use of "font_want" for the names of the font file requested by
392 * the user, and the use of "font_file" for the currently active font file.
394 * The "font_file" is uppercased, and takes the form "8X13.FON", while
395 * "font_want" can be in almost any form as long as it could be construed
396 * as attempting to represent the name of a font.
408 TERM_LEN rows; /* int -> uint */
411 uint pos_x; //!< タームの左上X座標
412 uint pos_y; //!< タームの左上Y座標
427 int font_wid; //!< フォント横幅
428 int font_hgt; //!< フォント縦幅
429 int tile_wid; //!< タイル横幅
430 int tile_hgt; //!< タイル縦幅
436 #if 1 /* #ifdef JP */
444 #define MAX_TERM_DATA 8 //!< Maximum number of windows
446 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
447 static term_data *my_td; //!< Hack -- global "window creation" pointer
448 POINT normsize; //!< Remember normal size of main window when maxmized
451 * was main window maximized on previous playing
453 bool win_maximized = FALSE;
458 bool game_in_progress = FALSE;
461 * note when "open"/"new" become valid
463 bool initialized = FALSE;
466 * screen paletted, i.e. 256 colors
468 bool paletted = FALSE;
471 * 16 colors screen, don't use RGB()
473 bool colors16 = FALSE;
476 * Saved instance handle
478 static HINSTANCE hInstance;
481 * Yellow brush for the cursor
483 static HBRUSH hbrYellow;
493 static HPALETTE hPal;
496 static HBITMAP hBG = NULL;
497 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
498 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
503 * The screen saver window
505 static HWND hwndSaver;
507 #endif /* USE_SAVER */
513 * 現在使用中のタイルID(0ならば未使用)
514 * Flag set once "graphics" has been initialized
516 static byte_hack current_graphics_mode = 0;
521 static DIBINIT infGraph;
524 * The global bitmap mask
526 static DIBINIT infMask;
528 #endif /* USE_GRAPHICS */
534 * Flag set once "sound" has been initialized
536 static bool can_use_sound = FALSE;
540 * An array of sound file names
542 static concptr sound_file[SOUND_MAX][SAMPLE_MAX];
544 #endif /* USE_SOUND */
550 #define SAMPLE_MUSIC_MAX 16
551 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
552 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
553 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
554 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
555 static bool can_use_music = FALSE;
557 static MCI_OPEN_PARMS mop;
558 static char mci_device_type[256];
560 int current_music_type = 0;
561 int current_music_id = 0;
563 #endif /* USE_MUSIC */
567 * Full path to ANGBAND.INI
569 static concptr ini_file = NULL;
572 * Name of application
574 static concptr AppName = "ANGBAND";
577 * Name of sub-window type
579 static concptr AngList = "AngList";
584 static concptr ANGBAND_DIR_XTRA_GRAF;
585 static concptr ANGBAND_DIR_XTRA_SOUND;
586 static concptr ANGBAND_DIR_XTRA_MUSIC;
587 static concptr ANGBAND_DIR_XTRA_HELP;
588 #if 0 /* #ifndef JP */
589 static concptr ANGBAND_DIR_XTRA_FONT;
592 static concptr ANGBAND_DIR_XTRA_MUSIC;
597 * The "complex" color values
599 static COLORREF win_clr[256];
603 * Flag for macro trigger with dump ASCII
605 static bool Term_no_press = FALSE;
610 static bool mouse_down = FALSE;
611 static bool paint_rect = FALSE;
612 static TERM_LEN mousex = 0, mousey = 0;
613 static TERM_LEN oldx, oldy;
617 * @brief The "simple" color values
619 * See "main-ibm.c" for original table information
620 * The entries below are taken from the "color bits" defined above.
621 * Note that many of the choices below suck, but so do crappy monitors.
623 static BYTE win_pal[256] =
625 VID_BLACK, /* Dark */
626 VID_WHITE, /* White */
627 VID_CYAN, /* Slate XXX */
628 VID_RED | VID_BRIGHT, /* Orange XXX */
630 VID_GREEN, /* Green */
632 VID_YELLOW, /* Umber XXX */
633 VID_BLACK | VID_BRIGHT, /* Light Dark */
634 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
635 VID_MAGENTA, /* Violet XXX */
636 VID_YELLOW | VID_BRIGHT, /* Yellow */
637 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
638 VID_GREEN | VID_BRIGHT, /* Light Green */
639 VID_BLUE | VID_BRIGHT, /* Light Blue */
640 VID_YELLOW /* Light Umber XXX */
645 * Hack -- define which keys are "special"
647 static bool special_key[256];
648 static bool ignore_key[256];
652 * Hack -- initialization list for "special_key"
654 static byte special_key_list[] = {
655 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
656 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
657 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
658 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
659 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
660 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
661 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
662 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
663 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
664 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
665 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
666 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
667 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
668 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
669 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
670 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
671 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
676 static byte ignore_key_list[] = {
677 VK_ESCAPE, VK_TAB, VK_SPACE,
678 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
679 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
680 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
686 * Hack -- initialization list for "special_key"
688 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
689 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
690 * catch the keypad keys (with and without numlock set, including keypad 5),
691 * the function keys (including the "menu" key which maps to F10), and the
692 * "pause" key (between scroll lock and numlock). We also catch a few odd
693 * keys which I do not recognize, but which are listed among keys which we
694 * do catch, so they should be harmless to catch.
696 static byte special_key_list[] =
698 VK_CLEAR, /* 0x0C (KP<5>) */
700 VK_PAUSE, /* 0x13 (pause) */
702 VK_PRIOR, /* 0x21 (KP<9>) */
703 VK_NEXT, /* 0x22 (KP<3>) */
704 VK_END, /* 0x23 (KP<1>) */
705 VK_HOME, /* 0x24 (KP<7>) */
706 VK_LEFT, /* 0x25 (KP<4>) */
707 VK_UP, /* 0x26 (KP<8>) */
708 VK_RIGHT, /* 0x27 (KP<6>) */
709 VK_DOWN, /* 0x28 (KP<2>) */
710 VK_SELECT, /* 0x29 (?????) */
711 VK_PRINT, /* 0x2A (?????) */
712 VK_EXECUTE, /* 0x2B (?????) */
713 VK_SNAPSHOT, /* 0x2C (?????) */
714 VK_INSERT, /* 0x2D (KP<0>) */
715 VK_DELETE, /* 0x2E (KP<.>) */
716 VK_HELP, /* 0x2F (?????) */
718 VK_NUMPAD0, /* 0x60 (KP<0>) */
719 VK_NUMPAD1, /* 0x61 (KP<1>) */
720 VK_NUMPAD2, /* 0x62 (KP<2>) */
721 VK_NUMPAD3, /* 0x63 (KP<3>) */
722 VK_NUMPAD4, /* 0x64 (KP<4>) */
723 VK_NUMPAD5, /* 0x65 (KP<5>) */
724 VK_NUMPAD6, /* 0x66 (KP<6>) */
725 VK_NUMPAD7, /* 0x67 (KP<7>) */
726 VK_NUMPAD8, /* 0x68 (KP<8>) */
727 VK_NUMPAD9, /* 0x69 (KP<9>) */
728 VK_MULTIPLY, /* 0x6A (KP<*>) */
729 VK_ADD, /* 0x6B (KP<+>) */
730 VK_SEPARATOR, /* 0x6C (?????) */
731 VK_SUBTRACT, /* 0x6D (KP<->) */
732 VK_DECIMAL, /* 0x6E (KP<.>) */
733 VK_DIVIDE, /* 0x6F (KP</>) */
764 /* Function prototype */
766 static bool is_already_running(void);
770 static void delete_bg(void)
779 static int init_bg(void)
781 char * bmfile = bg_bitmap_file;
784 if (use_bg == 0) return 0;
786 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
788 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
796 static void DrawBG(HDC hdc, RECT *r)
801 int x = r->left, y = r->top;
802 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
808 GetObject(hBG, sizeof(bm), &bm);
809 swid = bm.bmWidth; shgt = bm.bmHeight;
811 hdcSrc = CreateCompatibleDC(hdc);
812 hOld = SelectObject(hdcSrc, hBG);
816 cwid = MIN(swid - sx, r->right - nx);
819 chgt = MIN(shgt - sy, r->bottom - ny);
820 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
822 } while (ny < r->bottom);
825 } while (nx < r->right);
827 SelectObject(hdcSrc, hOld);
833 * Hack -- given a pathname, point at the filename
835 static concptr extract_file_name(concptr s)
839 /* Start at the end */
840 p = s + strlen(s) - 1;
842 /* Back up to divider */
843 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
845 /* Return file name */
852 * Hack -- given a simple filename, extract the "font size" info
854 * Return a pointer to a static buffer holding the capitalized base name.
856 #if 0 /* #ifndef JP */
857 static char *analyze_font(char *path, int *wp, int *hp)
863 /* Start at the end */
864 p = path + strlen(path) - 1;
866 /* Back up to divider */
867 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
869 /* Advance to file name */
875 /* Capitalize (be paranoid) */
876 if (islower(*s)) *s = toupper(*s);
880 s = my_strchr(p, 'X');
882 /* Extract font width */
886 hgt = s ? atoi(s+1) : 0;
897 * Check for existance of a file
899 static bool check_file(concptr s)
919 attrib = GetFileAttributes(path);
921 /* Require valid filename */
922 if (attrib == INVALID_FILE_NAME) return (FALSE);
924 /* Prohibit directory */
925 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
929 /* Examine and verify */
930 if (_dos_getfileattr(path, &attrib)) return (FALSE);
932 /* Prohibit something */
933 if (attrib & FA_LABEL) return (FALSE);
935 /* Prohibit directory */
936 if (attrib & FA_DIREC) return (FALSE);
946 * Check for existance of a directory
948 static bool check_dir(concptr s)
970 /* Remove trailing backslash */
971 if (i && (path[i-1] == '\\')) path[--i] = '\0';
976 attrib = GetFileAttributes(path);
978 /* Require valid filename */
979 if (attrib == INVALID_FILE_NAME) return (FALSE);
981 /* Require directory */
982 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
986 /* Examine and verify */
987 if (_dos_getfileattr(path, &attrib)) return (FALSE);
989 /* Prohibit something */
990 if (attrib & FA_LABEL) return (FALSE);
992 /* Require directory */
993 if (!(attrib & FA_DIREC)) return (FALSE);
1005 static void validate_file(concptr s)
1007 /* Verify or fail */
1010 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
1016 * Validate a directory
1018 static void validate_dir(concptr s, bool vital)
1020 /* Verify or fail */
1023 /* This directory contains needed data */
1026 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
1028 /* Attempt to create this directory */
1031 quit_fmt("Unable to create directory:\n%s", s);
1038 * @brief (Windows版固有実装)Get the "size" for a window
1040 static void term_getsize(term_data *td)
1044 if (td->cols < 1) td->cols = 1;
1045 if (td->rows < 1) td->rows = 1;
1048 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1049 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1051 /* Fake window size */
1053 rc.right = rc.left + wid;
1055 rc.bottom = rc.top + hgt;
1057 /* rc.right += 1; */
1058 /* rc.bottom += 1; */
1061 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1064 td->size_wid = rc.right - rc.left;
1065 td->size_hgt = rc.bottom - rc.top;
1067 /* See CreateWindowEx */
1070 /* Extract actual location */
1071 GetWindowRect(td->w, &rc);
1073 /* Save the location */
1074 td->pos_x = rc.left;
1080 * Write the "prefs" for a single term
1082 static void save_prefs_aux(int i)
1084 term_data *td = &data[i];
1085 GAME_TEXT sec_name[128];
1089 WINDOWPLACEMENT lpwndpl;
1092 /* Make section name */
1093 sprintf(sec_name, "Term-%d", i);
1098 strcpy(buf, td->visible ? "1" : "0");
1099 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1104 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "MS ゴシック");
1107 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1109 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1113 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1115 #if 1 /* #ifdef JP */
1116 wsprintf(buf, "%d", td->lf.lfWidth);
1117 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1118 wsprintf(buf, "%d", td->lf.lfHeight);
1119 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1120 wsprintf(buf, "%d", td->lf.lfWeight);
1121 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1124 strcpy(buf, td->bizarre ? "1" : "0");
1125 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1128 wsprintf(buf, "%d", td->tile_wid);
1129 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1132 wsprintf(buf, "%d", td->tile_hgt);
1133 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1135 /* Get window placement and dimensions */
1136 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1137 GetWindowPlacement(td->w, &lpwndpl);
1139 /* Acquire position in *normal* mode (not minimized) */
1140 rc = lpwndpl.rcNormalPosition;
1142 /* Window size (x) */
1143 if (i == 0) wsprintf(buf, "%d", normsize.x);
1144 else wsprintf(buf, "%d", td->cols);
1145 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1147 /* Window size (y) */
1148 if (i == 0) wsprintf(buf, "%d", normsize.y);
1149 else wsprintf(buf, "%d", td->rows);
1150 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1152 /* Maxmized (only main window) */
1155 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1156 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1159 /* Acquire position */
1160 GetWindowRect(td->w, &rc);
1162 /* Window position (x) */
1163 wsprintf(buf, "%d", rc.left);
1164 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1166 /* Window position (y) */
1167 wsprintf(buf, "%d", rc.top);
1168 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1170 /* Window Z position */
1173 strcpy(buf, td->posfix ? "1" : "0");
1174 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1181 * We assume that the windows have all been initialized
1183 static void save_prefs(void)
1189 /* Save the "arg_graphics" flag */
1190 sprintf(buf, "%d", arg_graphics);
1191 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1193 /* Save the "arg_bigtile" flag */
1194 strcpy(buf, arg_bigtile ? "1" : "0");
1195 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1197 /* Save the "arg_sound" flag */
1198 strcpy(buf, arg_sound ? "1" : "0");
1199 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1201 /* Save the "arg_sound" flag */
1202 strcpy(buf, arg_music ? "1" : "0");
1203 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1206 strcpy(buf, use_bg ? "1" : "0");
1207 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1208 WritePrivateProfileString("Angband", "BackGroundBitmap",
1209 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1211 /* Save window prefs */
1212 for (i = 0; i < MAX_TERM_DATA; ++i)
1220 * Load the "prefs" for a single term
1222 static void load_prefs_aux(int i)
1224 term_data *td = &data[i];
1225 GAME_TEXT sec_name[128];
1228 int wid, hgt, posx, posy;
1229 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1230 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1234 /* Make section name */
1235 sprintf(sec_name, "Term-%d", i);
1237 /* Make section name */
1238 sprintf(sec_name, "Term-%d", i);
1243 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1246 /* Desired font, with default */
1248 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1251 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1253 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1259 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1261 /* Analyze font, save desired font name */
1262 #if 1 /* #ifdef JP */
1263 td->font_want = string_make(tmp);
1265 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1266 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1267 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1269 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1274 #if 1 /* #ifdef JP */
1275 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1276 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1278 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1279 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1284 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1285 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1286 normsize.x = td->cols; normsize.y = td->rows;
1291 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
1294 /* Window position */
1295 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1296 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1297 td->pos_x = MIN(MAX(0, posx), dispx-128);
1298 td->pos_y = MIN(MAX(0, posy), dispy-128);
1300 /* Window Z position */
1303 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
1311 static void load_prefs(void)
1315 /* Extract the "arg_graphics" flag */
1316 arg_graphics = (byte_hack)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1318 /* Extract the "arg_bigtile" flag */
1319 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
1320 use_bigtile = arg_bigtile;
1322 /* Extract the "arg_sound" flag */
1323 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1325 /* Extract the "arg_sound" flag */
1326 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1329 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1330 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1332 /* Load window prefs */
1333 for (i = 0; i < MAX_TERM_DATA; ++i)
1339 #if defined(USE_SOUND) || defined(USE_MUSIC)
1342 * - Taken from files.c.
1344 * Extract "tokens" from a buffer
1346 * This function uses "whitespace" as delimiters, and treats any amount of
1347 * whitespace as a single delimiter. We will never return any empty tokens.
1348 * When given an empty buffer, or a buffer containing only "whitespace", we
1349 * will return no tokens. We will never extract more than "num" tokens.
1351 * By running a token through the "text_to_ascii()" function, you can allow
1352 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1354 * We save pointers to the tokens in "tokens", and return the number found.
1356 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1366 /* Skip leading whitespace */
1367 for ( ; *s && iswspace(*s); ++s) /* loop */;
1372 /* Find next whitespace, if any */
1373 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1375 /* Nuke and advance (if necessary) */
1376 if (*t) *t++ = '\0';
1378 /* Save the token */
1389 #endif /* USE_SOUND || USE_MUSIC */
1393 static void load_sound_prefs(void)
1397 char ini_path[1024];
1398 char wav_path[1024];
1399 char *zz[SAMPLE_MAX];
1401 /* Access the sound.cfg */
1403 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1405 for (i = 0; i < SOUND_MAX; i++)
1407 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1409 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1411 for (j = 0; j < num; j++)
1413 /* Access the sound */
1414 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1416 /* Save the sound filename, if it exists */
1417 if (check_file(wav_path))
1418 sound_file[i][j] = string_make(zz[j]);
1423 #endif /* USE_SOUND */
1427 static void load_music_prefs(void)
1431 char ini_path[1024];
1432 char wav_path[1024];
1433 char *zz[SAMPLE_MAX];
1436 /* Access the music.cfg */
1438 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1440 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1442 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1444 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1446 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1448 for (j = 0; j < num; j++)
1450 /* Access the sound */
1451 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1453 /* Save the sound filename, if it exists */
1454 if (check_file(wav_path))
1455 music_file[i][j] = string_make(zz[j]);
1459 for (i = 0; i < max_d_idx; i++)
1461 sprintf(key, "dungeon%03d", i);
1462 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1464 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1466 for (j = 0; j < num; j++)
1468 /* Access the sound */
1469 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1471 /* Save the sound filename, if it exists */
1472 if (check_file(wav_path))
1473 dungeon_music_file[i][j] = string_make(zz[j]);
1477 for (i = 0; i < max_q_idx; i++)
1479 sprintf(key, "quest%03d", i);
1480 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1482 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1484 for (j = 0; j < num; j++)
1486 /* Access the sound */
1487 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1489 /* Save the sound filename, if it exists */
1490 if (check_file(wav_path))
1491 quest_music_file[i][j] = string_make(zz[j]);
1495 for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1497 sprintf(key, "town%03d", i);
1498 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1500 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1502 for (j = 0; j < num; j++)
1504 /* Access the sound */
1505 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1507 /* Save the sound filename, if it exists */
1508 if (check_file(wav_path))
1509 town_music_file[i][j] = string_make(zz[j]);
1516 #endif /* USE_MUSIC */
1519 * Create the new global palette based on the bitmap palette
1520 * (if any), and the standard 16 entry palette derived from
1521 * "win_clr[]" which is used for the basic 16 Angband colors.
1523 * This function is never called before all windows are ready.
1525 * This function returns FALSE if the new palette could not be
1526 * prepared, which should normally be a fatal error. XXX XXX
1528 * Note that only some machines actually use a "palette".
1530 static int new_palette(void)
1538 LPLOGPALETTE pLogPal;
1539 LPPALETTEENTRY lppe;
1544 /* This makes no sense */
1545 if (!paletted) return (TRUE);
1555 /* Check the bitmap palette */
1556 hBmPal = infGraph.hPalette;
1558 /* Use the bitmap */
1561 lppeSize = 256 * sizeof(PALETTEENTRY);
1562 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1563 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1564 if ((nEntries == 0) || (nEntries > 220))
1567 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1570 rnfree(lppe, lppeSize);
1577 #endif /* USE_GRAPHICS */
1579 /* Size of palette */
1580 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1582 /* Allocate palette */
1583 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1586 pLogPal->palVersion = 0x300;
1588 /* Make room for bitmap and normal data */
1589 pLogPal->palNumEntries = nEntries + 16;
1591 /* Save the bitmap data */
1592 for (i = 0; i < nEntries; i++)
1594 pLogPal->palPalEntry[i] = lppe[i];
1597 /* Save the normal data */
1598 for (i = 0; i < 16; i++)
1602 /* Access the entry */
1603 p = &(pLogPal->palPalEntry[i+nEntries]);
1605 /* Save the colors */
1606 p->peRed = GetRValue(win_clr[i]);
1607 p->peGreen = GetGValue(win_clr[i]);
1608 p->peBlue = GetBValue(win_clr[i]);
1610 /* Save the flags */
1611 p->peFlags = PC_NOCOLLAPSE;
1614 /* Free something */
1615 if (lppe) rnfree(lppe, lppeSize);
1617 /* Create a new palette, or fail */
1618 hNewPal = CreatePalette(pLogPal);
1619 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1621 /* Free the palette */
1622 rnfree(pLogPal, pLogPalSize);
1627 /* Realize the palette */
1629 SelectPalette(hdc, hNewPal, 0);
1630 i = RealizePalette(hdc);
1631 ReleaseDC(td->w, hdc);
1632 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1636 for (i = 1; i < MAX_TERM_DATA; i++)
1641 SelectPalette(hdc, hNewPal, 0);
1642 ReleaseDC(td->w, hdc);
1645 /* Delete old palette */
1646 if (hPal) DeleteObject(hPal);
1648 /* Save new palette */
1658 * @brief グラフィクスを初期化する / Initialize graphics
1661 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1662 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1665 static bool init_graphics(void)
1667 /* Initialize once */
1669 BYTE wid, hgt, twid, thgt, ox, oy;
1672 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1682 ANGBAND_GRAF = "new";
1684 else if (arg_graphics == GRAPHICS_HENGBAND)
1704 ANGBAND_GRAF = "ne2";
1715 ANGBAND_GRAF = "old";
1718 /* Access the bitmap file */
1719 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1721 /* Load the bitmap or quit */
1722 if (!ReadDIB(data[0].w, buf, &infGraph))
1724 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1728 /* Save the new sizes */
1729 infGraph.CellWidth = wid;
1730 infGraph.CellHeight = hgt;
1731 infGraph.TileWidth = twid;
1732 infGraph.TileHeight = thgt;
1733 infGraph.OffsetX = ox;
1734 infGraph.OffsetY = oy;
1736 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1738 /* Access the mask file */
1739 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1741 /* Load the bitmap or quit */
1742 if (!ReadDIB(data[0].w, buf, &infMask))
1744 plog_fmt("Cannot read bitmap file '%s'", buf);
1748 if (arg_graphics == GRAPHICS_HENGBAND)
1750 /* Access the mask file */
1751 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1753 /* Load the bitmap or quit */
1754 if (!ReadDIB(data[0].w, buf, &infMask))
1756 plog_fmt("Cannot read bitmap file '%s'", buf);
1761 /* Activate a palette */
1766 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1770 /* Graphics available */
1771 current_graphics_mode = arg_graphics;
1772 return (current_graphics_mode);
1774 #endif /* USE_GRAPHICS */
1781 static bool init_music(void)
1783 /* Initialize once */
1786 /* Load the prefs */
1789 /* Sound available */
1790 can_use_music = TRUE;
1792 return (can_use_music);
1796 * Hack -- Stop a music
1798 static void stop_music(void)
1800 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1801 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1804 #endif /* USE_MUSIC */
1810 static bool init_sound(void)
1812 /* Initialize once */
1815 /* Load the prefs */
1818 /* Sound available */
1819 can_use_sound = TRUE;
1821 return (can_use_sound);
1823 #endif /* USE_SOUND */
1829 static void term_window_resize(term_data *td)
1831 /* Require window */
1834 /* Resize the window */
1835 SetWindowPos(td->w, 0, 0, 0,
1836 td->size_wid, td->size_hgt,
1837 SWP_NOMOVE | SWP_NOZORDER);
1840 InvalidateRect(td->w, NULL, TRUE);
1845 * Force the use of a new "font file" for a term_data
1847 * This function may be called before the "window" is ready
1849 * This function returns zero only if everything succeeds.
1851 * Note that the "font name" must be capitalized!!!
1853 static errr term_force_font(term_data *td, concptr path)
1857 #if 0 /* #ifndef JP */
1863 /* Forget the old font (if needed) */
1864 if (td->font_id) DeleteObject(td->font_id);
1866 #if 1 /* #ifdef JP */
1870 /* Create the font (using the 'base' of the font file name!) */
1871 td->font_id = CreateFontIndirect(&(td->lf));
1872 wid = td->lf.lfWidth;
1873 hgt = td->lf.lfHeight;
1874 if (!td->font_id) return (1);
1876 /* Forget old font */
1882 for (i = 0; i < MAX_TERM_DATA; i++)
1884 /* Don't check when closing the application */
1887 /* Check "screen" */
1888 if ((td != &data[i]) &&
1889 (data[i].font_file) &&
1890 (streq(data[i].font_file, td->font_file)))
1896 /* Remove unused font resources */
1897 if (!used) RemoveFontResource(td->font_file);
1899 /* Free the old name */
1900 string_free(td->font_file);
1903 td->font_file = NULL;
1907 if (!path) return (1);
1912 /* Analyze font path */
1913 base = analyze_font(buf, &wid, &hgt);
1916 if (!suffix(base, ".FON")) return (1);
1919 if (!check_file(buf)) return (1);
1921 /* Load the new font */
1922 if (!AddFontResource(buf)) return (1);
1924 /* Save new font name */
1925 td->font_file = string_make(base);
1927 /* Remove the "suffix" */
1928 base[strlen(base)-4] = '\0';
1930 /* Create the font (using the 'base' of the font file name!) */
1931 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1932 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1933 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1934 FIXED_PITCH | FF_DONTCARE, base);
1937 /* Hack -- Unknown size */
1944 /* all this trouble to get the cell size */
1945 hdcDesktop = GetDC(HWND_DESKTOP);
1946 hfOld = SelectObject(hdcDesktop, td->font_id);
1947 GetTextMetrics(hdcDesktop, &tm);
1948 SelectObject(hdcDesktop, hfOld);
1949 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1951 /* Font size info */
1952 wid = tm.tmAveCharWidth;
1956 /* Save the size info */
1967 * Allow the user to change the font for this window.
1969 static void term_change_font(term_data *td)
1971 #if 1 /* #ifdef JP */
1974 memset(&cf, 0, sizeof(cf));
1975 cf.lStructSize = sizeof(cf);
1976 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1977 cf.lpLogFont = &(td->lf);
1979 if (ChooseFont(&cf))
1981 /* Force the font */
1982 term_force_font(td, NULL);
1984 /* Assume not bizarre */
1987 /* Reset the tile info */
1988 td->tile_wid = td->font_wid;
1989 td->tile_hgt = td->font_hgt;
1991 /* Analyze the font */
1994 /* Resize the window */
1995 term_window_resize(td);
2001 char tmp[1024] = "";
2003 /* Extract a default if possible */
2004 if (td->font_file) strcpy(tmp, td->font_file);
2006 /* Ask for a choice */
2007 memset(&ofn, 0, sizeof(ofn));
2008 ofn.lStructSize = sizeof(ofn);
2009 ofn.hwndOwner = data[0].w;
2010 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
2011 ofn.nFilterIndex = 1;
2012 ofn.lpstrFile = tmp;
2014 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
2015 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2016 ofn.lpstrDefExt = "fon";
2018 /* Force choice if legal */
2019 if (GetOpenFileName(&ofn))
2021 /* Force the font */
2022 if (term_force_font(td, tmp))
2024 /* Access the standard font file */
2025 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2027 /* Force the use of that font */
2028 (void)term_force_font(td, tmp);
2031 /* Assume not bizarre */
2032 td->bizarre = FALSE;
2034 /* Reset the tile info */
2035 td->tile_wid = td->font_wid;
2036 td->tile_hgt = td->font_hgt;
2038 /* Analyze the font */
2041 /* Resize the window */
2042 term_window_resize(td);
2049 * Allow the user to lock this window.
2051 static void term_window_pos(term_data *td, HWND hWnd)
2053 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2054 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2057 static void windows_map(void);
2060 * Hack -- redraw a term_data
2062 static void term_data_redraw(term_data *td)
2066 /* Redraw the map */
2071 /* Activate the term */
2072 Term_activate(&td->t);
2074 /* Redraw the contents */
2077 /* Restore the term */
2078 Term_activate(term_screen);
2083 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2087 HBRUSH myBrush, oldBrush;
2089 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2090 int tx = td->size_ow1 + x * td->tile_wid;
2091 int ty = td->size_oh1 + y * td->tile_hgt;
2092 int tw = w * td->tile_wid - 1;
2093 int th = h * td->tile_hgt - 1;
2096 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2097 oldBrush = SelectObject(hdc, myBrush);
2098 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2100 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2102 SelectObject(hdc, oldBrush);
2103 SelectObject(hdc, oldPen);
2108 /*** Function hooks needed by "Term" ***/
2114 * Initialize a new Term
2116 static void Term_init_win(term *t)
2125 static void Term_nuke_win(term *t)
2134 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
2136 static errr Term_user_win(int n)
2147 * React to global changes
2149 static errr Term_xtra_win_react(void)
2156 /* Save the default colors */
2157 for (i = 0; i < 256; i++)
2159 /* Simply accept the desired colors */
2160 win_pal[i] = angband_color_table[i][0];
2171 bool change = FALSE;
2173 /* Save the default colors */
2174 for (i = 0; i < 256; i++)
2176 /* Extract desired values */
2177 rv = angband_color_table[i][1];
2178 gv = angband_color_table[i][2];
2179 bv = angband_color_table[i][3];
2181 /* Extract a full color code */
2182 code = PALETTERGB(rv, gv, bv);
2184 /* Activate changes */
2185 if (win_clr[i] != code)
2187 /* Note the change */
2190 /* Apply the desired color */
2195 /* Activate the palette if needed */
2196 if (change) (void)new_palette();
2202 /* Handle "arg_sound" */
2203 if (use_sound != arg_sound)
2205 /* Initialize (if needed) */
2206 if (arg_sound && !init_sound())
2209 plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
2215 /* Change setting */
2216 use_sound = arg_sound;
2223 /* Handle "arg_sound" */
2224 if (use_music != arg_music)
2226 /* Initialize (if needed) */
2227 if (arg_music && !init_music())
2230 plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
2235 /* Change setting */
2236 use_music = arg_music;
2238 if(!arg_music) stop_music();
2239 else select_floor_music();
2248 /* Handle "arg_graphics" */
2249 if (use_graphics != arg_graphics)
2251 /* Initialize (if needed) */
2252 if (arg_graphics && !init_graphics())
2255 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
2258 arg_graphics = GRAPHICS_NONE;
2261 /* Change setting */
2262 use_graphics = arg_graphics;
2265 #ifdef ANGBAND_2_8_1
2267 #else /* ANGBAND_2_8_1 */
2268 reset_visuals(TRUE);
2269 #endif /* ANGBAND_2_8_1 */
2272 #endif /* USE_GRAPHICS */
2275 /* Clean up windows */
2276 for (i = 0; i < MAX_TERM_DATA; i++)
2280 term_data *td = &data[i];
2282 /* Update resized windows */
2283 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
2286 Term_activate(&td->t);
2288 /* Hack -- Resize the term */
2289 Term_resize(td->cols, td->rows);
2291 /* Redraw the contents */
2304 * Process at least one event
2306 static errr Term_xtra_win_event(int v)
2310 /* Wait for an event */
2314 if (GetMessage(&msg, NULL, 0, 0))
2316 TranslateMessage(&msg);
2317 DispatchMessage(&msg);
2321 /* Check for an event */
2325 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2327 TranslateMessage(&msg);
2328 DispatchMessage(&msg);
2338 * Process all pending events
2340 static errr Term_xtra_win_flush(void)
2344 /* Process all pending events */
2345 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2347 TranslateMessage(&msg);
2348 DispatchMessage(&msg);
2357 * Hack -- clear the screen
2359 * Make this more efficient
2361 static errr Term_xtra_win_clear(void)
2363 term_data *td = (term_data*)(Term->data);
2368 /* Rectangle to erase */
2369 rc.left = td->size_ow1;
2370 rc.right = rc.left + td->cols * td->tile_wid;
2371 rc.top = td->size_oh1;
2372 rc.bottom = rc.top + td->rows * td->tile_hgt;
2376 SetBkColor(hdc, RGB(0, 0, 0));
2377 SelectObject(hdc, td->font_id);
2378 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2383 rc.left = 0; rc.top = 0;
2386 ReleaseDC(td->w, hdc);
2394 * Hack -- make a noise
2396 static errr Term_xtra_win_noise(void)
2398 MessageBeep(MB_ICONASTERISK);
2404 * Hack -- make a sound
2406 static errr Term_xtra_win_sound(int v)
2411 #endif /* USE_SOUND */
2413 /* Sound disabled */
2414 if (!use_sound) return (1);
2417 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2421 /* Count the samples */
2422 for (i = 0; i < SAMPLE_MAX; i++)
2424 if (!sound_file[v][i])
2429 if (i == 0) return (1);
2431 /* Build the path */
2432 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2436 /* Play the sound, catch errors */
2437 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2441 /* Play the sound, catch errors */
2442 return (sndPlaySound(buf, SND_ASYNC));
2446 #else /* USE_SOUND */
2450 #endif /* USE_SOUND */
2454 * Hack -- play a music
2456 static errr Term_xtra_win_music(int n, int v)
2461 #endif /* USE_MUSIC */
2463 /* Sound disabled */
2465 if(!use_music) return (1);
2468 if(n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return (1);
2469 else if(v < 0 || v >= 1000) return(1); /*!< TODO */
2475 case TERM_XTRA_MUSIC_BASIC:
2476 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2478 case TERM_XTRA_MUSIC_DUNGEON:
2479 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2481 case TERM_XTRA_MUSIC_QUEST:
2482 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2484 case TERM_XTRA_MUSIC_TOWN:
2485 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2492 //mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2493 //mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2499 case TERM_XTRA_MUSIC_BASIC:
2500 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2502 case TERM_XTRA_MUSIC_DUNGEON:
2503 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2505 case TERM_XTRA_MUSIC_QUEST:
2506 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2508 case TERM_XTRA_MUSIC_TOWN:
2509 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2516 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2517 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2523 case TERM_XTRA_MUSIC_BASIC:
2524 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2526 case TERM_XTRA_MUSIC_DUNGEON:
2527 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2529 case TERM_XTRA_MUSIC_QUEST:
2530 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2532 case TERM_XTRA_MUSIC_TOWN:
2533 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2537 if(current_music_type == n && current_music_id == v)
2541 current_music_type = n;
2542 current_music_id = v;
2546 mop.lpstrDeviceType = mci_device_type;
2547 mop.lpstrElementName = buf;
2548 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2549 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2550 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2551 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2552 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2557 #else /* USE_MUSIC */
2561 #endif /* USE_MUSIC */
2567 * Delay for "x" milliseconds
2569 static int Term_xtra_win_delay(int v)
2583 t = GetTickCount() + v;
2586 while (GetTickCount() < t)
2588 /* Handle messages */
2589 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2591 TranslateMessage(&msg);
2592 DispatchMessage(&msg);
2604 * Do a "special thing"
2606 static errr Term_xtra_win(int n, int v)
2608 /* Handle a subset of the legal requests */
2611 /* Make a bell sound */
2612 case TERM_XTRA_NOISE:
2614 return (Term_xtra_win_noise());
2618 case TERM_XTRA_MUSIC_BASIC:
2619 case TERM_XTRA_MUSIC_DUNGEON:
2620 case TERM_XTRA_MUSIC_QUEST:
2621 case TERM_XTRA_MUSIC_TOWN:
2623 return (Term_xtra_win_music(n, v));
2626 /* Make a special sound */
2627 case TERM_XTRA_SOUND:
2629 return (Term_xtra_win_sound(v));
2632 /* Process random events */
2633 case TERM_XTRA_BORED:
2635 return (Term_xtra_win_event(0));
2638 /* Process an event */
2639 case TERM_XTRA_EVENT:
2641 return (Term_xtra_win_event(v));
2644 /* Flush all events */
2645 case TERM_XTRA_FLUSH:
2647 return (Term_xtra_win_flush());
2650 /* Clear the screen */
2651 case TERM_XTRA_CLEAR:
2653 return (Term_xtra_win_clear());
2656 /* React to global changes */
2657 case TERM_XTRA_REACT:
2659 return (Term_xtra_win_react());
2662 /* Delay for some milliseconds */
2663 case TERM_XTRA_DELAY:
2665 return (Term_xtra_win_delay(v));
2675 * Low level graphics (Assumes valid input).
2677 * Draw a "cursor" at (x,y), using a "yellow box".
2679 static errr Term_curs_win(int x, int y)
2681 term_data *td = (term_data*)(Term->data);
2686 int tile_wid, tile_hgt;
2690 tile_wid = td->map_tile_wid;
2691 tile_hgt = td->map_tile_hgt;
2695 tile_wid = td->tile_wid;
2696 tile_hgt = td->tile_hgt;
2699 /* Frame the grid */
2700 rc.left = x * tile_wid + td->size_ow1;
2701 rc.right = rc.left + tile_wid;
2702 rc.top = y * tile_hgt + td->size_oh1;
2703 rc.bottom = rc.top + tile_hgt;
2705 /* Cursor is done as a yellow "box" */
2707 FrameRect(hdc, &rc, hbrYellow);
2708 ReleaseDC(td->w, hdc);
2716 * Low level graphics (Assumes valid input).
2718 * Draw a "big cursor" at (x,y), using a "yellow box".
2720 static errr Term_bigcurs_win(int x, int y)
2722 term_data *td = (term_data*)(Term->data);
2727 int tile_wid, tile_hgt;
2731 /* Normal cursor in map window */
2732 Term_curs_win(x, y);
2737 tile_wid = td->tile_wid;
2738 tile_hgt = td->tile_hgt;
2741 /* Frame the grid */
2742 rc.left = x * tile_wid + td->size_ow1;
2743 rc.right = rc.left + 2 * tile_wid;
2744 rc.top = y * tile_hgt + td->size_oh1;
2745 rc.bottom = rc.top + tile_hgt;
2747 /* Cursor is done as a yellow "box" */
2749 FrameRect(hdc, &rc, hbrYellow);
2750 ReleaseDC(td->w, hdc);
2758 * Low level graphics (Assumes valid input).
2760 * Erase a "block" of "n" characters starting at (x,y).
2762 static errr Term_wipe_win(int x, int y, int n)
2764 term_data *td = (term_data*)(Term->data);
2769 /* Rectangle to erase in client coords */
2770 rc.left = x * td->tile_wid + td->size_ow1;
2771 rc.right = rc.left + n * td->tile_wid;
2772 rc.top = y * td->tile_hgt + td->size_oh1;
2773 rc.bottom = rc.top + td->tile_hgt;
2776 SetBkColor(hdc, RGB(0, 0, 0));
2777 SelectObject(hdc, td->font_id);
2782 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2783 ReleaseDC(td->w, hdc);
2791 * Low level graphics. Assumes valid input.
2793 * Draw several ("n") chars, with an attr, at a given location.
2795 * All "graphic" data is handled by "Term_pict_win()", below.
2797 * One would think there is a more efficient method for telling a window
2798 * what color it should be using to draw with, but perhaps simply changing
2799 * it every time is not too inefficient.
2801 static errr Term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
2803 term_data *td = (term_data*)(Term->data);
2807 #if 1 /* #ifdef JP */
2808 static HBITMAP WALL;
2809 static HBRUSH myBrush, oldBrush;
2811 static bool init_done = FALSE;
2814 WALL = LoadBitmap(hInstance, AppName);
2815 myBrush = CreatePatternBrush(WALL);
2820 /* Total rectangle */
2821 rc.left = x * td->tile_wid + td->size_ow1;
2822 rc.right = rc.left + n * td->tile_wid;
2823 rc.top = y * td->tile_hgt + td->size_oh1;
2824 rc.bottom = rc.top + td->tile_hgt;
2829 /* Background color */
2830 SetBkColor(hdc, RGB(0, 0, 0));
2832 /* Foreground color */
2835 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2839 SetTextColor(hdc, win_clr[a&0x0F]);
2843 SetTextColor(hdc, win_clr[a]);
2847 SelectObject(hdc, td->font_id);
2850 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2854 (td->tile_hgt != td->font_hgt) ||
2855 (td->tile_wid != td->font_wid))
2859 /* Erase complete rectangle */
2860 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2863 if (use_bg) DrawBG(hdc, &rc);
2866 rc.left += ((td->tile_wid - td->font_wid) / 2);
2867 rc.right = rc.left + td->font_wid;
2868 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2869 rc.bottom = rc.top + td->font_hgt;
2871 /* Dump each character */
2872 for (i = 0; i < n; i++)
2875 if (use_bigtile && *(s+i)=="■"[0] && *(s+i+1)=="■"[1])
2877 rc.right += td->font_wid;
2879 oldBrush = SelectObject(hdc, myBrush);
2880 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2883 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2885 SelectObject(hdc, oldBrush);
2886 SelectObject(hdc, oldPen);
2887 rc.right -= td->font_wid;
2891 rc.left += 2 * td->tile_wid;
2892 rc.right += 2 * td->tile_wid;
2894 else if ( iskanji(*(s+i)) ) /* 2バイト文字 */
2896 rc.right += td->font_wid;
2898 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2900 rc.right -= td->font_wid;
2904 rc.left += 2 * td->tile_wid;
2905 rc.right += 2 * td->tile_wid;
2906 } else if (*(s+i)==127){
2907 oldBrush = SelectObject(hdc, myBrush);
2908 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2911 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2913 SelectObject(hdc, oldBrush);
2914 SelectObject(hdc, oldPen);
2917 rc.left += td->tile_wid;
2918 rc.right += td->tile_wid;
2921 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2924 rc.left += td->tile_wid;
2925 rc.right += td->tile_wid;
2930 oldBrush = SelectObject(hdc, myBrush);
2931 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2934 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2936 SelectObject(hdc, oldBrush);
2937 SelectObject(hdc, oldPen);
2940 rc.left += td->tile_wid;
2941 rc.right += td->tile_wid;
2944 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2948 rc.left += td->tile_wid;
2949 rc.right += td->tile_wid;
2953 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2957 rc.left += td->tile_wid;
2958 rc.right += td->tile_wid;
2969 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2974 ReleaseDC(td->w, hdc);
2982 * Low level graphics. Assumes valid input.
2984 * Draw an array of "special" attr/char pairs at the given location.
2986 * We use the "Term_pict_win()" function for "graphic" data, which are
2987 * encoded by setting the "high-bits" of both the "attr" and the "char"
2988 * data. We use the "attr" to represent the "row" of the main bitmap,
2989 * and the "char" to represent the "col" of the main bitmap. The use
2990 * of this function is induced by the "higher_pict" flag.
2992 * If "graphics" is not available, we simply "wipe" the given grids.
2994 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)
2996 term_data *td = (term_data*)(Term->data);
3001 TERM_LEN x1, y1, w1, h1, tw1, th1;
3002 TERM_LEN x2, y2, w2, h2, tw2 = 0;
3012 /* Erase the grids */
3013 return (Term_wipe_win(x, y, n));
3016 /* Size of bitmap cell */
3017 w1 = infGraph.CellWidth;
3018 h1 = infGraph.CellHeight;
3019 tw1 = infGraph.TileWidth;
3020 th1 = infGraph.TileHeight;
3022 /* Size of window cell */
3025 w2 = td->map_tile_wid;
3026 h2 = td->map_tile_hgt;
3035 if (use_bigtile) tw2 *= 2;
3038 /* Location of window cell */
3039 x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
3040 y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
3046 hdcSrc = CreateCompatibleDC(hdc);
3047 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
3049 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3051 hdcMask = CreateCompatibleDC(hdc);
3052 SelectObject(hdcMask, infMask.hBitmap);
3055 /* Draw attr/char pairs */
3056 for (i = 0; i < n; i++, x2 += w2)
3058 TERM_COLOR a = ap[i];
3062 /* Extract picture */
3063 int row = (a & 0x7F);
3064 int col = (c & 0x7F);
3066 /* Location of bitmap cell */
3070 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3072 x3 = (tcp[i] & 0x7F) * w1;
3073 y3 = (tap[i] & 0x7F) * h1;
3074 tw2 = tw2 * w1 / tw1;
3078 if ((tw1 == tw2) && (th1 == h2))
3080 /* Copy the terrain picture from the bitmap to the window */
3081 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
3083 /* Mask out the tile */
3084 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3087 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3090 /* Need to stretch */
3093 /* Set the correct mode for stretching the tiles */
3094 SetStretchBltMode(hdc, COLORONCOLOR);
3096 /* Copy the terrain picture from the bitmap to the window */
3097 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
3099 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
3101 /* Only draw if terrain and overlay are different */
3102 if ((x1 != x3) || (y1 != y3))
3104 /* Mask out the tile */
3105 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3108 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3115 if ((w1 == tw2) && (h1 == h2))
3117 /* Copy the picture from the bitmap to the window */
3118 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3121 /* Need to stretch */
3124 /* Set the correct mode for stretching the tiles */
3125 SetStretchBltMode(hdc, COLORONCOLOR);
3127 /* Copy the picture from the bitmap to the window */
3128 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3134 SelectObject(hdcSrc, hbmSrcOld);
3137 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3140 SelectObject(hdcMask, hbmSrcOld);
3145 ReleaseDC(td->w, hdc);
3147 #else /* USE_GRAPHICS */
3149 /* Just erase this grid */
3150 return (Term_wipe_win(x, y, n));
3152 #endif /* USE_GRAPHICS */
3159 static void windows_map(void)
3161 term_data *td = &data[0];
3164 TERM_LEN x, min_x, max_x;
3165 TERM_LEN y, min_y, max_y;
3170 /* Only in graphics mode */
3171 if (!use_graphics) return;
3172 Term_xtra_win_clear();
3174 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3175 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3176 td->map_active = TRUE;
3181 max_x = current_floor_ptr->width;
3182 max_y = current_floor_ptr->height;
3186 for (x = min_x; x < max_x; x++)
3188 for (y = min_y; y < max_y; y++)
3190 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3192 /* Ignore non-graphics */
3193 if ((a & 0x80) && (c & 0x80))
3195 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3200 /* Hilite the player */
3201 Term_curs_win(p_ptr->x - min_x, p_ptr->y - min_y);
3203 /* Wait for a keypress, flush key buffer */
3204 Term_inkey(&c, TRUE, TRUE);
3207 /* Switch off the map display */
3208 td->map_active = FALSE;
3210 /* Restore screen */
3211 Term_xtra_win_clear();
3216 /*** Other routines ***/
3220 * Create and initialize a "term_data" given a title
3222 static void term_data_link(term_data *td)
3226 /* Initialize the term */
3227 term_init(t, td->cols, td->rows, td->keys);
3229 /* Use a "software" cursor */
3230 t->soft_cursor = TRUE;
3232 /* Use "Term_pict" for "graphic" data */
3233 t->higher_pict = TRUE;
3235 /* Erase with "white space" */
3236 t->attr_blank = TERM_WHITE;
3237 t->char_blank = ' ';
3240 /* Prepare the init/nuke hooks */
3241 t->init_hook = Term_init_win;
3242 t->nuke_hook = Term_nuke_win;
3245 /* Prepare the template hooks */
3246 t->user_hook = Term_user_win;
3247 t->xtra_hook = Term_xtra_win;
3248 t->curs_hook = Term_curs_win;
3249 t->bigcurs_hook = Term_bigcurs_win;
3250 t->wipe_hook = Term_wipe_win;
3251 t->text_hook = Term_text_win;
3252 t->pict_hook = Term_pict_win;
3254 /* Remember where we came from */
3255 t->data = (vptr)(td);
3260 * Create the windows
3262 * First, instantiate the "default" values, then read the "ini_file"
3263 * to over-ride selected values, then create the windows, and fonts.
3265 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3266 * must make active to realize the palette.
3268 static void init_windows(void)
3274 #if 0 /* #ifndef JP */
3280 WIPE(td, term_data);
3284 td->s = angband_term_name[0];
3298 #if 1 /* #ifdef JP */
3302 for (i = 1; i < MAX_TERM_DATA; i++)
3305 WIPE(td, term_data);
3306 td->s = angband_term_name[i];
3310 td->visible = FALSE;
3315 td->pos_x = (7 - i) * 30;
3316 td->pos_y = (7 - i) * 20;
3318 #if 1 /* #ifdef JP */
3328 /* Main window (need these before term_getsize gets called) */
3330 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3331 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3336 /* Sub windows (need these before term_getsize gets called) */
3337 for (i = 1; i < MAX_TERM_DATA; i++)
3340 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3341 td->dwExStyle = (WS_EX_TOOLWINDOW);
3346 for (i = 0; i < MAX_TERM_DATA; i++)
3350 #if 1 /* #ifdef JP */
3351 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3352 td->lf.lfCharSet = DEFAULT_CHARSET;
3353 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3354 /* Activate the chosen font */
3355 term_force_font(td, NULL);
3356 if(!td->tile_wid) td->tile_wid = td->font_wid;
3357 if(!td->tile_hgt) td->tile_hgt = td->font_hgt;
3359 /* Access the standard font file */
3360 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3362 /* Activate the chosen font */
3363 if (term_force_font(td, buf))
3365 /* Access the standard font file */
3366 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3368 /* Force the use of that font */
3369 (void)term_force_font(td, buf);
3374 /* Assume not bizarre */
3375 td->bizarre = FALSE;
3380 /* Analyze the font */
3383 /* Resize the window */
3384 term_window_resize(td);
3388 /* Sub windows (reverse order) */
3389 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3394 td->w = CreateWindowEx(td->dwExStyle, AngList,
3396 td->pos_x, td->pos_y,
3397 td->size_wid, td->size_hgt,
3398 HWND_DESKTOP, NULL, hInstance, NULL);
3400 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3404 td->size_hack = TRUE;
3405 ShowWindow(td->w, SW_SHOW);
3406 td->size_hack = FALSE;
3410 angband_term[i] = &td->t;
3414 /* Activate the window */
3415 SetActiveWindow(td->w);
3420 term_window_pos(&data[i], HWND_TOPMOST);
3424 term_window_pos(&data[i], td->w);
3434 td->w = CreateWindowEx(td->dwExStyle, AppName,
3436 td->pos_x, td->pos_y,
3437 td->size_wid, td->size_hgt,
3438 HWND_DESKTOP, NULL, hInstance, NULL);
3440 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3443 angband_term[0] = &td->t;
3444 normsize.x = td->cols;
3445 normsize.y = td->rows;
3447 /* Activate the main window */
3448 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3449 else ShowWindow(td->w, SW_SHOW);
3451 /* Bring main window back to top */
3452 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3456 (void)new_palette();
3459 /* Create a "brush" for drawing the "cursor" */
3460 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3463 /* Process pending messages */
3464 (void)Term_xtra_win_flush();
3472 static void setup_menus(void)
3476 HMENU hm = GetMenu(data[0].w);
3479 /* Menu "File", Disable all */
3480 EnableMenuItem(hm, IDM_FILE_NEW,
3481 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3482 EnableMenuItem(hm, IDM_FILE_OPEN,
3483 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3484 EnableMenuItem(hm, IDM_FILE_SAVE,
3485 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3486 EnableMenuItem(hm, IDM_FILE_EXIT,
3487 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3488 EnableMenuItem(hm, IDM_FILE_SCORE,
3489 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3492 /* No character available */
3493 if (!character_generated)
3495 /* Menu "File", Item "New" */
3496 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3498 /* Menu "File", Item "Open" */
3499 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3502 /* A character available */
3503 if (character_generated)
3505 /* Menu "File", Item "Save" */
3506 EnableMenuItem(hm, IDM_FILE_SAVE,
3507 MF_BYCOMMAND | MF_ENABLED);
3510 /* Menu "File", Item "Exit" */
3511 EnableMenuItem(hm, IDM_FILE_EXIT,
3512 MF_BYCOMMAND | MF_ENABLED);
3514 EnableMenuItem(hm, IDM_FILE_SCORE,
3515 MF_BYCOMMAND | MF_ENABLED);
3518 /* Menu "Window::Visibility" */
3519 for (i = 0; i < MAX_TERM_DATA; i++)
3521 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3522 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3524 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3525 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3527 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3528 MF_BYCOMMAND | MF_ENABLED);
3531 /* Menu "Window::Font" */
3532 for (i = 0; i < MAX_TERM_DATA; i++)
3534 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3535 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3537 if (data[i].visible)
3539 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3540 MF_BYCOMMAND | MF_ENABLED);
3544 /* Menu "Window::Window Position Fix" */
3545 for (i = 0; i < MAX_TERM_DATA; i++)
3547 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3548 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3550 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3551 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3553 if (data[i].visible)
3555 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3556 MF_BYCOMMAND | MF_ENABLED);
3560 /* Menu "Window::Bizarre Display" */
3561 for (i = 0; i < MAX_TERM_DATA; i++)
3563 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3564 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3566 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3567 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3569 if (data[i].visible)
3571 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3572 MF_BYCOMMAND | MF_ENABLED);
3577 /* Menu "Window::Increase Tile Width" */
3578 for (i = 0; i < MAX_TERM_DATA; i++)
3580 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3581 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3583 if (data[i].visible)
3585 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3586 MF_BYCOMMAND | MF_ENABLED);
3591 /* Menu "Window::Decrease Tile Width" */
3592 for (i = 0; i < MAX_TERM_DATA; i++)
3594 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3595 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3597 if (data[i].visible)
3599 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3600 MF_BYCOMMAND | MF_ENABLED);
3605 /* Menu "Window::Increase Tile Height" */
3606 for (i = 0; i < MAX_TERM_DATA; i++)
3608 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3609 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3611 if (data[i].visible)
3613 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3614 MF_BYCOMMAND | MF_ENABLED);
3619 /* Menu "Window::Decrease Tile Height" */
3620 for (i = 0; i < MAX_TERM_DATA; i++)
3622 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3623 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3625 if (data[i].visible)
3627 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3628 MF_BYCOMMAND | MF_ENABLED);
3633 /* Menu "Options", disable all */
3634 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3635 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3636 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3637 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3638 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3639 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3640 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3641 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3642 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3643 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3645 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3646 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3649 /* Menu "Options", Item "Map" */
3650 if (use_graphics != GRAPHICS_NONE)
3651 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3653 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3654 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3656 /* Menu "Options", update all */
3657 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3658 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3659 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3660 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3661 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3662 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3663 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3664 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3665 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3666 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3667 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3668 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3669 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3670 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3671 CheckMenuItem(hm, IDM_OPTIONS_BG,
3672 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3674 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3675 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3679 /* Menu "Options", Item "Graphics" */
3680 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3681 /* Menu "Options", Item "Graphics" */
3682 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3683 /* Menu "Options", Item "Graphics" */
3684 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3685 /* Menu "Options", Item "Graphics" */
3686 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3687 #endif /* USE_GRAPHICS */
3690 /* Menu "Options", Item "Sound" */
3691 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3692 #endif /* USE_SOUND */
3695 /* Menu "Options", Item "ScreenSaver" */
3696 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3697 MF_BYCOMMAND | MF_ENABLED);
3698 #endif /* USE_SAVER */
3703 * Check for double clicked (or dragged) savefile
3705 * Apparently, Windows copies the entire filename into the first
3706 * piece of the "command line string". Perhaps we should extract
3707 * the "basename" of that filename and append it to the "save" dir.
3709 static void check_for_save_file(LPSTR cmd_line)
3719 /* Extract filename */
3720 strcat(savefile, s);
3722 /* Validate the file */
3723 validate_file(savefile);
3725 /* Game in progress */
3726 game_in_progress = TRUE;
3734 * Process a menu command
3736 static void process_menus(WORD wCmd)
3752 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3754 else if (game_in_progress)
3756 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3760 game_in_progress = TRUE;
3773 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3775 else if (game_in_progress)
3777 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3781 memset(&ofn, 0, sizeof(ofn));
3782 ofn.lStructSize = sizeof(ofn);
3783 ofn.hwndOwner = data[0].w;
3784 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3785 ofn.nFilterIndex = 1;
3786 ofn.lpstrFile = savefile;
3787 ofn.nMaxFile = 1024;
3788 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3789 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3791 if (GetOpenFileName(&ofn))
3793 /* Load 'savefile' */
3794 validate_file(savefile);
3795 game_in_progress = TRUE;
3807 if (game_in_progress && character_generated)
3811 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3815 /* Hack -- Forget messages */
3820 do_cmd_save_game(FALSE);
3821 #else /* ZANGBAND */
3823 #endif /* ZANGBAND */
3827 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3835 if (game_in_progress && character_generated)
3839 plog(_("今は終了できません。", "You may not do that right now."));
3843 /* Hack -- Forget messages */
3852 /* do_cmd_save_game(FALSE); */
3853 #else /* ZANGBAND */
3854 /* do_cmd_save_game(); */
3855 #endif /* ZANGBAND */
3856 Term_key_push(SPECIAL_KEY_QUIT);
3864 case IDM_FILE_SCORE:
3868 /* Build the filename */
3869 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3871 /* Open the binary high score file, for reading */
3872 highscore_fd = fd_open(buf, O_RDONLY);
3874 /* Paranoia -- No score file */
3875 if (highscore_fd < 0)
3877 msg_print("Score file unavailable.");
3884 /* Display the scores */
3885 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3887 /* Shut the high score file */
3888 (void)fd_close(highscore_fd);
3890 /* Forget the high score fd */
3894 /* Hack - Flush it */
3902 case IDM_FILE_MOVIE:
3906 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3908 else if (game_in_progress)
3910 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
3914 memset(&ofn, 0, sizeof(ofn));
3915 ofn.lStructSize = sizeof(ofn);
3916 ofn.hwndOwner = data[0].w;
3917 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3918 ofn.nFilterIndex = 1;
3919 ofn.lpstrFile = savefile;
3920 ofn.nMaxFile = 1024;
3921 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3922 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3924 if (GetOpenFileName(&ofn))
3926 /* Load 'savefile' */
3927 prepare_browse_movie_aux(savefile);
3937 case IDM_WINDOW_VIS_0:
3939 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
3943 /* Window visibility */
3944 case IDM_WINDOW_VIS_1:
3945 case IDM_WINDOW_VIS_2:
3946 case IDM_WINDOW_VIS_3:
3947 case IDM_WINDOW_VIS_4:
3948 case IDM_WINDOW_VIS_5:
3949 case IDM_WINDOW_VIS_6:
3950 case IDM_WINDOW_VIS_7:
3952 i = wCmd - IDM_WINDOW_VIS_0;
3954 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3961 ShowWindow(td->w, SW_SHOW);
3962 term_data_redraw(td);
3966 td->visible = FALSE;
3968 ShowWindow(td->w, SW_HIDE);
3975 case IDM_WINDOW_FONT_0:
3976 case IDM_WINDOW_FONT_1:
3977 case IDM_WINDOW_FONT_2:
3978 case IDM_WINDOW_FONT_3:
3979 case IDM_WINDOW_FONT_4:
3980 case IDM_WINDOW_FONT_5:
3981 case IDM_WINDOW_FONT_6:
3982 case IDM_WINDOW_FONT_7:
3984 i = wCmd - IDM_WINDOW_FONT_0;
3986 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3990 term_change_font(td);
3995 /* Window Z Position */
3996 case IDM_WINDOW_POS_1:
3997 case IDM_WINDOW_POS_2:
3998 case IDM_WINDOW_POS_3:
3999 case IDM_WINDOW_POS_4:
4000 case IDM_WINDOW_POS_5:
4001 case IDM_WINDOW_POS_6:
4002 case IDM_WINDOW_POS_7:
4004 i = wCmd - IDM_WINDOW_POS_0;
4006 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4010 if (!td->posfix && td->visible)
4013 term_window_pos(td, HWND_TOPMOST);
4018 term_window_pos(td, data[0].w);
4024 /* Bizarre Display */
4025 case IDM_WINDOW_BIZ_0:
4026 case IDM_WINDOW_BIZ_1:
4027 case IDM_WINDOW_BIZ_2:
4028 case IDM_WINDOW_BIZ_3:
4029 case IDM_WINDOW_BIZ_4:
4030 case IDM_WINDOW_BIZ_5:
4031 case IDM_WINDOW_BIZ_6:
4032 case IDM_WINDOW_BIZ_7:
4034 i = wCmd - IDM_WINDOW_BIZ_0;
4036 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4040 td->bizarre = !td->bizarre;
4044 term_window_resize(td);
4049 /* Increase Tile Width */
4050 case IDM_WINDOW_I_WID_0:
4051 case IDM_WINDOW_I_WID_1:
4052 case IDM_WINDOW_I_WID_2:
4053 case IDM_WINDOW_I_WID_3:
4054 case IDM_WINDOW_I_WID_4:
4055 case IDM_WINDOW_I_WID_5:
4056 case IDM_WINDOW_I_WID_6:
4057 case IDM_WINDOW_I_WID_7:
4059 i = wCmd - IDM_WINDOW_I_WID_0;
4061 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4069 term_window_resize(td);
4074 /* Decrease Tile Height */
4075 case IDM_WINDOW_D_WID_0:
4076 case IDM_WINDOW_D_WID_1:
4077 case IDM_WINDOW_D_WID_2:
4078 case IDM_WINDOW_D_WID_3:
4079 case IDM_WINDOW_D_WID_4:
4080 case IDM_WINDOW_D_WID_5:
4081 case IDM_WINDOW_D_WID_6:
4082 case IDM_WINDOW_D_WID_7:
4084 i = wCmd - IDM_WINDOW_D_WID_0;
4086 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4094 term_window_resize(td);
4099 /* Increase Tile Height */
4100 case IDM_WINDOW_I_HGT_0:
4101 case IDM_WINDOW_I_HGT_1:
4102 case IDM_WINDOW_I_HGT_2:
4103 case IDM_WINDOW_I_HGT_3:
4104 case IDM_WINDOW_I_HGT_4:
4105 case IDM_WINDOW_I_HGT_5:
4106 case IDM_WINDOW_I_HGT_6:
4107 case IDM_WINDOW_I_HGT_7:
4109 i = wCmd - IDM_WINDOW_I_HGT_0;
4111 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4119 term_window_resize(td);
4124 /* Decrease Tile Height */
4125 case IDM_WINDOW_D_HGT_0:
4126 case IDM_WINDOW_D_HGT_1:
4127 case IDM_WINDOW_D_HGT_2:
4128 case IDM_WINDOW_D_HGT_3:
4129 case IDM_WINDOW_D_HGT_4:
4130 case IDM_WINDOW_D_HGT_5:
4131 case IDM_WINDOW_D_HGT_6:
4132 case IDM_WINDOW_D_HGT_7:
4134 i = wCmd - IDM_WINDOW_D_HGT_0;
4136 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4144 term_window_resize(td);
4149 case IDM_OPTIONS_NO_GRAPHICS:
4153 plog("You may not do that right now.");
4157 /* Toggle "arg_graphics" */
4158 if (arg_graphics != GRAPHICS_NONE)
4160 arg_graphics = GRAPHICS_NONE;
4162 /* React to changes */
4163 Term_xtra_win_react();
4165 /* Hack -- Force redraw */
4166 Term_key_push(KTRL('R'));
4172 case IDM_OPTIONS_OLD_GRAPHICS:
4176 plog("You may not do that right now.");
4180 /* Toggle "arg_graphics" */
4181 if (arg_graphics != GRAPHICS_ORIGINAL)
4183 arg_graphics = GRAPHICS_ORIGINAL;
4185 /* React to changes */
4186 Term_xtra_win_react();
4188 /* Hack -- Force redraw */
4189 Term_key_push(KTRL('R'));
4195 case IDM_OPTIONS_NEW_GRAPHICS:
4199 plog("You may not do that right now.");
4203 /* Toggle "arg_graphics" */
4204 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4206 arg_graphics = GRAPHICS_ADAM_BOLT;
4208 /* React to changes */
4209 Term_xtra_win_react();
4211 /* Hack -- Force redraw */
4212 Term_key_push(KTRL('R'));
4218 case IDM_OPTIONS_NEW2_GRAPHICS:
4222 plog("You may not do that right now.");
4226 /* Toggle "arg_graphics" */
4227 if (arg_graphics != GRAPHICS_HENGBAND)
4229 arg_graphics = GRAPHICS_HENGBAND;
4231 /* React to changes */
4232 Term_xtra_win_react();
4234 /* Hack -- Force redraw */
4235 Term_key_push(KTRL('R'));
4241 case IDM_OPTIONS_BIGTILE:
4246 plog("You may not do that right now.");
4250 /* Toggle "arg_sound" */
4251 arg_bigtile = !arg_bigtile;
4254 Term_activate(&td->t);
4256 /* Resize the term */
4257 Term_resize(td->cols, td->rows);
4260 InvalidateRect(td->w, NULL, TRUE);
4265 case IDM_OPTIONS_MUSIC:
4269 plog("You may not do that right now.");
4273 /* Toggle "arg_sound" */
4274 arg_music = !arg_music;
4276 /* React to changes */
4277 Term_xtra_win_react();
4279 /* Hack -- Force redraw */
4280 Term_key_push(KTRL('R'));
4285 case IDM_OPTIONS_SOUND:
4289 plog("You may not do that right now.");
4293 /* Toggle "arg_sound" */
4294 arg_sound = !arg_sound;
4296 /* React to changes */
4297 Term_xtra_win_react();
4299 /* Hack -- Force redraw */
4300 Term_key_push(KTRL('R'));
4306 case IDM_OPTIONS_BG:
4310 plog("You may not do that right now.");
4314 /* Toggle "use_bg" */
4319 /* React to changes */
4320 Term_xtra_win_react();
4322 /* Hack -- Force redraw */
4323 Term_key_push(KTRL('R'));
4329 case IDM_OPTIONS_OPEN_BG:
4333 plog("You may not do that right now.");
4338 memset(&ofn, 0, sizeof(ofn));
4339 ofn.lStructSize = sizeof(ofn);
4340 ofn.hwndOwner = data[0].w;
4341 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4342 ofn.nFilterIndex = 1;
4343 ofn.lpstrFile = bg_bitmap_file;
4344 ofn.nMaxFile = 1023;
4345 ofn.lpstrInitialDir = NULL;
4346 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
4347 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4349 if (GetOpenFileName(&ofn))
4351 /* Load 'savefile' */
4356 /* React to changes */
4357 Term_xtra_win_react();
4359 /* Hack -- Force redraw */
4360 Term_key_push(KTRL('R'));
4365 case IDM_DUMP_SCREEN_HTML:
4367 static char buf[1024] = "";
4368 memset(&ofn, 0, sizeof(ofn));
4369 ofn.lStructSize = sizeof(ofn);
4370 ofn.hwndOwner = data[0].w;
4371 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4372 ofn.nFilterIndex = 1;
4373 ofn.lpstrFile = buf;
4374 ofn.nMaxFile = 1023;
4375 ofn.lpstrDefExt = "html";
4376 ofn.lpstrInitialDir = NULL;
4377 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
4378 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4380 if (GetSaveFileName(&ofn))
4382 do_cmd_save_screen_html_aux(buf, 0);
4389 case IDM_OPTIONS_SAVER:
4393 DestroyWindow(hwndSaver);
4398 /* Create a screen scaver window */
4399 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4400 "Angband Screensaver",
4401 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4402 0, 0, GetSystemMetrics(SM_CXSCREEN),
4403 GetSystemMetrics(SM_CYSCREEN),
4404 NULL, NULL, hInstance, NULL);
4408 /* Push the window to the bottom */
4409 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4413 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
4421 case IDM_OPTIONS_MAP:
4427 case IDM_HELP_CONTENTS:
4431 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4432 if (check_file(tmp))
4434 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4438 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4439 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4442 #else /* HTML_HELP */
4445 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4446 if (check_file(tmp))
4448 sprintf(buf, "winhelp.exe %s", tmp);
4449 WinExec(buf, SW_NORMAL);
4453 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4454 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4458 #endif /* HTML_HELP */
4464 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4471 /* Extract the modifiers */
4472 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4473 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4474 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4476 Term_no_press = (ma) ? TRUE : FALSE;
4478 /* Handle "special" keys */
4479 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4481 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4482 bool numpad = FALSE;
4484 /* Begin the macro trigger */
4487 /* Send the modifiers */
4488 if (mc) Term_keypress('C');
4489 if (ms) Term_keypress('S');
4490 if (ma) Term_keypress('A');
4492 /* Extract "scan code" */
4493 i = LOBYTE(HIWORD(lParam));
4495 /* Introduce the scan code */
4498 /* Extended key bit */
4501 /* Numpad Enter and '/' are extended key */
4503 Term_no_press = TRUE;
4504 case VK_RETURN: /* Enter */
4507 /* Other extended keys are on full keyboard */
4523 Term_no_press = TRUE;
4527 case VK_PRIOR: /* Page Up */
4528 case VK_NEXT: /* Page Down */
4538 /* Special modifiers for keypad keys */
4539 if (numpad) Term_keypress('K');
4541 /* Encode the hexidecimal scan code */
4542 Term_keypress(hexsym[i/16]);
4543 Term_keypress(hexsym[i%16]);
4545 /* End the macro trigger */
4556 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4557 WPARAM wParam, LPARAM lParam);
4558 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4559 WPARAM wParam, LPARAM lParam)
4560 #else /* __MWERKS__ */
4561 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4562 #endif /* __MWERKS__ */
4568 MINMAXINFO FAR *lpmmi;
4574 /* Acquire proper "term_data" info */
4575 td = (term_data *)GetWindowLong(hWnd, 0);
4577 /* Handle message */
4582 SetWindowLong(hWnd, 0, (LONG)(my_td));
4589 mop.dwCallback=(DWORD)hWnd;
4594 case WM_GETMINMAXINFO:
4596 MINMAXINFO FAR *lpmmi;
4599 lpmmi = (MINMAXINFO FAR *)lParam;
4601 /* this message was sent before WM_NCCREATE */
4604 /* Minimum window size is 80x24 */
4605 rc.left = rc.top = 0;
4606 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4607 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4610 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4612 /* Save minimum size */
4613 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4614 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4621 BeginPaint(hWnd, &ps);
4622 if (td) term_data_redraw(td);
4623 EndPaint(hWnd, &ps);
4624 ValidateRect(hWnd, NULL);
4631 if(wParam == MCI_NOTIFY_SUCCESSFUL)
4633 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4634 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4643 if (process_keydown(wParam, lParam))
4650 if (Term_no_press) Term_no_press = FALSE;
4651 else Term_keypress(wParam);
4655 case WM_LBUTTONDOWN:
4657 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4658 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4670 TERM_LEN dx = abs(oldx - mousex) + 1;
4671 TERM_LEN dy = abs(oldy - mousey) + 1;
4672 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
4673 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
4683 hGlobal = GlobalAlloc(GHND, sz + 1);
4684 if (hGlobal == NULL) return 0;
4685 lpStr = (LPSTR)GlobalLock(hGlobal);
4687 for (i = 0; i < dy; i++)
4691 char **scr = data[0].t.scr->c;
4693 C_MAKE(s, (dx + 1), char);
4694 strncpy(s, &scr[oy + i][ox], dx);
4698 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4701 if (ox + dx < data[0].cols)
4703 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4706 for (j = 0; j < dx; j++)
4708 if (s[j] == 127) s[j] = '#';
4712 for (j = 0; j < dx; j++)
4714 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4724 GlobalUnlock(hGlobal);
4725 if (OpenClipboard(hWnd) == 0)
4727 GlobalFree(hGlobal);
4731 SetClipboardData(CF_TEXT, hGlobal);
4744 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4745 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4750 dx = abs(oldx - mousex) + 1;
4751 dy = abs(oldy - mousey) + 1;
4752 ox = (oldx > mousex) ? mousex : oldx;
4753 oy = (oldy > mousey) ? mousey : oldy;
4754 Term_inversed_area(hWnd, ox, oy, dx, dy);
4761 dx = abs(cx - mousex) + 1;
4762 dy = abs(cy - mousey) + 1;
4763 ox = (cx > mousex) ? mousex : cx;
4764 oy = (cy > mousey) ? mousey : cy;
4765 Term_inversed_area(hWnd, ox, oy, dx, dy);
4781 if (game_in_progress && character_generated)
4785 plog(_("今は終了できません。", "You may not do that right now."));
4789 /* Hack -- Forget messages */
4798 /* do_cmd_save_game(FALSE); */
4799 #else /* ZANGBAND */
4800 /* do_cmd_save_game(); */
4801 #endif /* ZANGBAND */
4802 Term_key_push(SPECIAL_KEY_QUIT);
4809 case WM_QUERYENDSESSION:
4811 if (game_in_progress && character_generated)
4813 /* Hack -- Forget messages */
4816 /* Mega-Hack -- Delay death */
4817 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4818 do_cmd_write_nikki(NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4820 /* Hardcode panic save */
4821 p_ptr->panic_save = 1;
4823 /* Forbid suspend */
4824 signals_ignore_tstp();
4826 /* Indicate panic save */
4827 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4830 (void)save_player();
4844 process_menus(LOWORD(wParam));
4850 /* this message was sent before WM_NCCREATE */
4853 /* it was sent from inside CreateWindowEx */
4854 if (!td->w) return 1;
4856 /* was sent from WM_SIZE */
4857 if (td->size_hack) return 1;
4861 case SIZE_MINIMIZED:
4863 /* Hide sub-windows */
4864 for (i = 1; i < MAX_TERM_DATA; i++)
4866 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4871 case SIZE_MAXIMIZED:
4878 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4879 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4882 if ((td->cols != cols) || (td->rows != rows))
4884 /* Save the new size */
4888 if (!IsZoomed(td->w) && !IsIconic(td->w))
4890 normsize.x = td->cols;
4891 normsize.y = td->rows;
4895 Term_activate(&td->t);
4897 /* Resize the term */
4898 Term_resize(td->cols, td->rows);
4901 InvalidateRect(td->w, NULL, TRUE);
4904 td->size_hack = TRUE;
4906 /* Show sub-windows */
4907 for (i = 1; i < MAX_TERM_DATA; i++)
4909 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4912 td->size_hack = FALSE;
4920 case WM_PALETTECHANGED:
4922 /* Ignore if palette change caused by itself */
4923 if ((HWND)wParam == hWnd) return 0;
4925 /* Fall through... */
4928 case WM_QUERYNEWPALETTE:
4930 if (!paletted) return 0;
4934 SelectPalette(hdc, hPal, FALSE);
4936 i = RealizePalette(hdc);
4938 /* if any palette entries changed, repaint the window. */
4939 if (i) InvalidateRect(hWnd, NULL, TRUE);
4941 ReleaseDC(hWnd, hdc);
4948 if (wParam && !HIWORD(lParam))
4950 /* Do something to sub-windows */
4951 for (i = 1; i < MAX_TERM_DATA; i++)
4953 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4956 /* Focus on main window */
4965 case WM_ACTIVATEAPP:
4967 if (IsIconic(td->w)) break;
4969 for (i = 1; i < MAX_TERM_DATA; i++)
4975 ShowWindow(data[i].w, SW_SHOW);
4979 ShowWindow(data[i].w, SW_HIDE);
4986 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4991 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4992 WPARAM wParam, LPARAM lParam);
4993 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4994 WPARAM wParam, LPARAM lParam)
4995 #else /* __MWERKS__ */
4996 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4997 WPARAM wParam, LPARAM lParam)
4998 #endif /* __MWERKS__ */
5002 MINMAXINFO FAR *lpmmi;
5010 /* Acquire proper "term_data" info */
5011 td = (term_data *)GetWindowLong(hWnd, 0);
5013 /* Process message */
5018 SetWindowLong(hWnd, 0, (LONG)(my_td));
5027 case WM_GETMINMAXINFO:
5029 MINMAXINFO FAR *lpmmi;
5032 lpmmi = (MINMAXINFO FAR *)lParam;
5034 /* this message was sent before WM_NCCREATE */
5037 /* Minimum window size is 80x24 */
5038 rc.left = rc.top = 0;
5039 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5040 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5043 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5045 /* Save minimum size */
5046 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5047 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5057 /* this message was sent before WM_NCCREATE */
5060 /* it was sent from inside CreateWindowEx */
5061 if (!td->w) return 1;
5063 /* was sent from inside WM_SIZE */
5064 if (td->size_hack) return 1;
5066 td->size_hack = TRUE;
5068 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5069 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5072 if ((td->cols != cols) || (td->rows != rows))
5075 term *old_term = Term;
5077 /* Save the new size */
5082 Term_activate(&td->t);
5084 /* Resize the term */
5085 Term_resize(td->cols, td->rows);
5088 Term_activate(old_term);
5091 InvalidateRect(td->w, NULL, TRUE);
5093 /* HACK - Redraw all windows */
5094 p_ptr->window = 0xFFFFFFFF;
5098 td->size_hack = FALSE;
5105 BeginPaint(hWnd, &ps);
5106 if (td) term_data_redraw(td);
5107 EndPaint(hWnd, &ps);
5114 if (process_keydown(wParam, lParam))
5121 if (Term_no_press) Term_no_press = FALSE;
5122 else Term_keypress(wParam);
5126 case WM_PALETTECHANGED:
5128 /* ignore if palette change caused by itself */
5129 if ((HWND)wParam == hWnd) return FALSE;
5130 /* otherwise, fall through!!! */
5133 case WM_QUERYNEWPALETTE:
5135 if (!paletted) return 0;
5137 SelectPalette(hdc, hPal, FALSE);
5138 i = RealizePalette(hdc);
5139 /* if any palette entries changed, repaint the window. */
5140 if (i) InvalidateRect(hWnd, NULL, TRUE);
5141 ReleaseDC(hWnd, hdc);
5145 case WM_NCLBUTTONDOWN:
5149 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5150 #endif /* HTCLOSE */
5152 if (wParam == HTSYSMENU)
5156 td->visible = FALSE;
5157 ShowWindow(td->w, SW_HIDE);
5167 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5173 #define MOUSE_SENS 40
5176 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5177 WPARAM wParam, LPARAM lParam);
5178 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5179 WPARAM wParam, LPARAM lParam)
5180 #else /* __MWERKS__ */
5181 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5182 WPARAM wParam, LPARAM lParam)
5183 #endif /* __MWERKS__ */
5185 static int iMouse = 0;
5186 static WORD xMouse = 0;
5187 static WORD yMouse = 0;
5209 if (LOWORD(wParam) == WA_INACTIVE) break;
5211 /* else fall through */
5215 case WM_LBUTTONDOWN:
5216 case WM_MBUTTONDOWN:
5217 case WM_RBUTTONDOWN:
5220 SendMessage(hWnd, WM_CLOSE, 0, 0);
5228 dx = LOWORD(lParam) - xMouse;
5229 dy = HIWORD(lParam) - yMouse;
5231 if (dx < 0) dx = -dx;
5232 if (dy < 0) dy = -dy;
5234 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5236 SendMessage(hWnd, WM_CLOSE, 0, 0);
5240 /* Save last location */
5242 xMouse = LOWORD(lParam);
5243 yMouse = HIWORD(lParam);
5250 DestroyWindow(hwndSaver);
5256 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5259 #endif /* USE_SAVER */
5265 /*** Temporary Hooks ***/
5269 * Display warning message (see "z-util.c")
5271 static void hack_plog(concptr str)
5273 /* Give a warning */
5277 MessageBox(NULL, str, "警告!",
5278 MB_ICONEXCLAMATION | MB_OK);
5280 MessageBox(NULL, str, "Warning",
5281 MB_ICONEXCLAMATION | MB_OK);
5289 * Display error message and quit (see "z-util.c")
5291 static void hack_quit(concptr str)
5293 /* Give a warning */
5297 MessageBox(NULL, str, "エラー!",
5298 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5300 MessageBox(NULL, str, "Error",
5301 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5306 /* Unregister the classes */
5307 UnregisterClass(AppName, hInstance);
5309 /* Destroy the icon */
5310 if (hIcon) DestroyIcon(hIcon);
5318 /*** Various hooks ***/
5322 * Display warning message (see "z-util.c")
5324 static void hook_plog(concptr str)
5330 MessageBox(data[0].w, str, "警告!",
5331 MB_ICONEXCLAMATION | MB_OK);
5333 MessageBox(data[0].w, str, "Warning",
5334 MB_ICONEXCLAMATION | MB_OK);
5342 * Display error message and quit (see "z-util.c")
5344 static void hook_quit(concptr str)
5349 /* Give a warning */
5353 MessageBox(data[0].w, str, "エラー!",
5354 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5356 MessageBox(data[0].w, str, "Error",
5357 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5363 /* Save the preferences */
5367 /*** Could use 'Term_nuke_win()' */
5369 /* Destroy all windows */
5370 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5372 term_force_font(&data[i], NULL);
5373 if (data[i].font_want) string_free(data[i].font_want);
5374 if (data[i].w) DestroyWindow(data[i].w);
5378 /* Free the bitmap stuff */
5380 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5381 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5383 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5384 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5386 #endif /* USE_GRAPHICS */
5388 /*** Free some other stuff ***/
5390 DeleteObject(hbrYellow);
5395 if (hPal) DeleteObject(hPal);
5397 UnregisterClass(AppName, hInstance);
5399 if (hIcon) DestroyIcon(hIcon);
5406 /*** Initialize ***/
5412 static void init_stuff(void)
5419 /* Get program name with full path */
5420 GetModuleFileName(hInstance, path, 512);
5422 /* Save the "program name" */
5425 /* Get the name of the "*.ini" file */
5426 strcpy(path + strlen(path) - 4, ".INI");
5428 /* Save the the name of the ini-file */
5429 ini_file = string_make(path);
5431 /* Analyze the path */
5437 if (path[i] == '\\')
5444 /* Add "lib" to the path */
5445 strcpy(path + i + 1, "lib\\");
5447 /* Validate the path */
5448 validate_dir(path, TRUE);
5450 /* Init the file paths */
5451 init_file_paths(path);
5453 /* Hack -- Validate the paths */
5454 validate_dir(ANGBAND_DIR_APEX, FALSE);
5455 validate_dir(ANGBAND_DIR_BONE, FALSE);
5457 /* Allow missing 'edit' directory */
5458 if (!check_dir(ANGBAND_DIR_EDIT))
5460 /* Must have 'data'! */
5461 validate_dir(ANGBAND_DIR_DATA, TRUE);
5465 /* Don't need 'data' */
5466 validate_dir(ANGBAND_DIR_DATA, FALSE);
5469 validate_dir(ANGBAND_DIR_FILE, TRUE);
5470 validate_dir(ANGBAND_DIR_HELP, FALSE);
5471 validate_dir(ANGBAND_DIR_INFO, FALSE);
5472 validate_dir(ANGBAND_DIR_PREF, TRUE);
5473 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5474 validate_dir(ANGBAND_DIR_USER, TRUE);
5475 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5477 /* Build the filename */
5478 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
5480 /* Hack -- Validate the "news.txt" file */
5481 validate_file(path);
5484 #if 0 /* #ifndef JP */
5485 /* Build the "font" path */
5486 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5488 /* Allocate the path */
5489 ANGBAND_DIR_XTRA_FONT = string_make(path);
5491 /* Validate the "font" directory */
5492 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5494 /* Build the filename */
5495 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5497 /* Hack -- Validate the basic font */
5498 validate_file(path);
5504 /* Build the "graf" path */
5505 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5507 /* Allocate the path */
5508 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5510 /* Validate the "graf" directory */
5511 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5513 #endif /* USE_GRAPHICS */
5518 /* Build the "sound" path */
5519 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5521 /* Allocate the path */
5522 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5524 /* Validate the "sound" directory */
5525 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5527 #endif /* USE_SOUND */
5531 /* Build the "music" path */
5532 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5534 /* Allocate the path */
5535 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5537 /* Validate the "music" directory */
5538 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5540 #endif /* USE_MUSIC */
5542 /* Build the "help" path */
5543 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5545 /* Allocate the path */
5546 ANGBAND_DIR_XTRA_HELP = string_make(path);
5548 /* Validate the "help" directory */
5549 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5553 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
5555 static bool is_already_running(void)
5557 bool result = FALSE;
5560 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5561 if (GetLastError() == ERROR_ALREADY_EXISTS)
5570 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
5572 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5573 LPSTR lpCmdLine, int nCmdShow)
5581 setlocale(LC_ALL, "ja_JP.utf8");
5590 /* Prevent multiple run */
5591 if (is_already_running())
5594 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
5595 _("エラー!", "Error") ,
5596 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5600 if (hPrevInst == NULL)
5602 wc.style = CS_CLASSDC;
5603 wc.lpfnWndProc = AngbandWndProc;
5605 wc.cbWndExtra = 4; /* one long pointer to term_data */
5606 wc.hInstance = hInst;
5607 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5608 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5609 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5610 wc.lpszMenuName = AppName;
5611 wc.lpszClassName = AppName;
5613 if (!RegisterClass(&wc)) exit(1);
5615 wc.lpfnWndProc = AngbandListProc;
5616 wc.lpszMenuName = NULL;
5617 wc.lpszClassName = AngList;
5619 if (!RegisterClass(&wc)) exit(2);
5623 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5624 wc.lpfnWndProc = AngbandSaverProc;
5626 wc.lpszMenuName = NULL;
5627 wc.lpszClassName = "WindowsScreenSaverClass";
5629 if (!RegisterClass(&wc)) exit(3);
5635 /* Temporary hooks */
5636 plog_aux = hack_plog;
5637 quit_aux = hack_quit;
5638 core_aux = hack_quit;
5640 /* Prepare the filepaths */
5643 /* Initialize the keypress analyzer */
5644 for (i = 0; special_key_list[i]; ++i)
5646 special_key[special_key_list[i]] = TRUE;
5648 /* Initialize the keypress analyzer */
5649 for (i = 0; ignore_key_list[i]; ++i)
5651 ignore_key[ignore_key_list[i]] = TRUE;
5654 /* Determine if display is 16/256/true color */
5656 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5657 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5658 ReleaseDC(NULL, hdc);
5660 /* Initialize the colors */
5661 for (i = 0; i < 256; i++)
5665 /* Extract desired values */
5666 rv = angband_color_table[i][1];
5667 gv = angband_color_table[i][2];
5668 bv = angband_color_table[i][3];
5670 /* Extract the "complex" code */
5671 win_clr[i] = PALETTERGB(rv, gv, bv);
5673 /* Save the "simple" code */
5674 angband_color_table[i][0] = win_pal[i];
5677 /* Prepare the windows */
5683 /* Activate hooks */
5684 plog_aux = hook_plog;
5685 quit_aux = hook_quit;
5686 core_aux = hook_quit;
5688 /* Set the system suffix */
5689 ANGBAND_SYS = "win";
5691 /* Set the keyboard suffix */
5692 if (7 != GetKeyboardType(0))
5693 ANGBAND_KEYBOARD = "0";
5696 /* Japanese keyboard */
5697 switch (GetKeyboardType(1))
5699 case 0x0D01: case 0x0D02:
5700 case 0x0D03: case 0x0D04:
5701 case 0x0D05: case 0x0D06:
5703 ANGBAND_KEYBOARD = "NEC98";
5707 ANGBAND_KEYBOARD = "JAPAN";
5711 /* Catch nasty signals */
5714 Term_activate(term_screen);
5717 /* We are now initialized */
5720 if(lpCmdLine[0] == '-'){
5721 switch(lpCmdLine[1])
5726 if (!lpCmdLine[2]) break;
5727 chuukei_server = TRUE;
5728 if(connect_chuukei_server(&lpCmdLine[2])<0){
5729 msg_print("connect fail");
5732 msg_print("connect");
5740 if (!lpCmdLine[2]) break;
5741 chuukei_client = TRUE;
5742 connect_chuukei_server(&lpCmdLine[2]);
5750 if (!lpCmdLine[2]) break;
5751 prepare_browse_movie(&lpCmdLine[2]);
5761 /* Did the user double click on a save file? */
5762 if(!chuukei_server) check_for_save_file(lpCmdLine);
5764 /* Did the user double click on a save file? */
5765 check_for_save_file(lpCmdLine);
5768 /* Prompt the user */
5769 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
5773 /* Process messages forever */
5774 while (GetMessage(&msg, NULL, 0, 0))
5776 TranslateMessage(&msg);
5777 DispatchMessage(&msg);
5784 #endif /* WINDOWS */