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).
101 #include "view-mainwindow.h"
102 #include "floor-events.h"
113 * Extract the "WIN32" flag from the compiler
115 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
123 * Hack -- allow use of "screen saver" mode
129 * Menu constants -- see "ANGBAND.RC"
132 #define IDM_FILE_NEW 100
133 #define IDM_FILE_OPEN 101
134 #define IDM_FILE_SAVE 110
135 #define IDM_FILE_SCORE 120
136 #define IDM_FILE_MOVIE 121
137 #define IDM_FILE_EXIT 130
139 #define IDM_WINDOW_VIS_0 200
140 #define IDM_WINDOW_VIS_1 201
141 #define IDM_WINDOW_VIS_2 202
142 #define IDM_WINDOW_VIS_3 203
143 #define IDM_WINDOW_VIS_4 204
144 #define IDM_WINDOW_VIS_5 205
145 #define IDM_WINDOW_VIS_6 206
146 #define IDM_WINDOW_VIS_7 207
148 #define IDM_WINDOW_FONT_0 210
149 #define IDM_WINDOW_FONT_1 211
150 #define IDM_WINDOW_FONT_2 212
151 #define IDM_WINDOW_FONT_3 213
152 #define IDM_WINDOW_FONT_4 214
153 #define IDM_WINDOW_FONT_5 215
154 #define IDM_WINDOW_FONT_6 216
155 #define IDM_WINDOW_FONT_7 217
157 #define IDM_WINDOW_POS_0 220
158 #define IDM_WINDOW_POS_1 221
159 #define IDM_WINDOW_POS_2 222
160 #define IDM_WINDOW_POS_3 223
161 #define IDM_WINDOW_POS_4 224
162 #define IDM_WINDOW_POS_5 225
163 #define IDM_WINDOW_POS_6 226
164 #define IDM_WINDOW_POS_7 227
166 #define IDM_WINDOW_BIZ_0 230
167 #define IDM_WINDOW_BIZ_1 231
168 #define IDM_WINDOW_BIZ_2 232
169 #define IDM_WINDOW_BIZ_3 233
170 #define IDM_WINDOW_BIZ_4 234
171 #define IDM_WINDOW_BIZ_5 235
172 #define IDM_WINDOW_BIZ_6 236
173 #define IDM_WINDOW_BIZ_7 237
175 #define IDM_WINDOW_I_WID_0 240
176 #define IDM_WINDOW_I_WID_1 241
177 #define IDM_WINDOW_I_WID_2 242
178 #define IDM_WINDOW_I_WID_3 243
179 #define IDM_WINDOW_I_WID_4 244
180 #define IDM_WINDOW_I_WID_5 245
181 #define IDM_WINDOW_I_WID_6 246
182 #define IDM_WINDOW_I_WID_7 247
184 #define IDM_WINDOW_D_WID_0 250
185 #define IDM_WINDOW_D_WID_1 251
186 #define IDM_WINDOW_D_WID_2 252
187 #define IDM_WINDOW_D_WID_3 253
188 #define IDM_WINDOW_D_WID_4 254
189 #define IDM_WINDOW_D_WID_5 255
190 #define IDM_WINDOW_D_WID_6 256
191 #define IDM_WINDOW_D_WID_7 257
193 #define IDM_WINDOW_I_HGT_0 260
194 #define IDM_WINDOW_I_HGT_1 261
195 #define IDM_WINDOW_I_HGT_2 262
196 #define IDM_WINDOW_I_HGT_3 263
197 #define IDM_WINDOW_I_HGT_4 264
198 #define IDM_WINDOW_I_HGT_5 265
199 #define IDM_WINDOW_I_HGT_6 266
200 #define IDM_WINDOW_I_HGT_7 267
202 #define IDM_WINDOW_D_HGT_0 270
203 #define IDM_WINDOW_D_HGT_1 271
204 #define IDM_WINDOW_D_HGT_2 272
205 #define IDM_WINDOW_D_HGT_3 273
206 #define IDM_WINDOW_D_HGT_4 274
207 #define IDM_WINDOW_D_HGT_5 275
208 #define IDM_WINDOW_D_HGT_6 276
209 #define IDM_WINDOW_D_HGT_7 277
211 #define IDM_OPTIONS_NO_GRAPHICS 400
212 #define IDM_OPTIONS_OLD_GRAPHICS 401
213 #define IDM_OPTIONS_NEW_GRAPHICS 402
214 #define IDM_OPTIONS_NEW2_GRAPHICS 403
215 #define IDM_OPTIONS_BIGTILE 409
216 #define IDM_OPTIONS_SOUND 410
217 #define IDM_OPTIONS_MUSIC 411
218 #define IDM_OPTIONS_SAVER 420
219 #define IDM_OPTIONS_MAP 430
220 #define IDM_OPTIONS_BG 440
221 #define IDM_OPTIONS_OPEN_BG 441
223 #define IDM_DUMP_SCREEN_HTML 450
225 #define IDM_HELP_CONTENTS 901
228 * Exclude parts of WINDOWS.H that are not needed
230 #define NOCOMM /* Comm driver APIs and definitions */
231 #define NOLOGERROR /* LogError() and related definitions */
232 #define NOPROFILER /* Profiler APIs */
233 #define NOLFILEIO /* _l* file I/O routines */
234 #define NOOPENFILE /* OpenFile and related definitions */
235 #define NORESOURCE /* Resource management */
236 #define NOATOM /* Atom management */
237 #define NOLANGUAGE /* Character test routines */
238 #define NOLSTRING /* lstr* string management routines */
239 #define NODBCS /* Double-byte character set routines */
240 #define NOKEYBOARDINFO /* Keyboard driver routines */
241 #define NOCOLOR /* COLOR_* color values */
242 #define NODRAWTEXT /* DrawText() and related definitions */
243 #define NOSCALABLEFONT /* Truetype scalable font support */
244 #define NOMETAFILE /* Metafile support */
245 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
246 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
247 #define NOKEYSTATES /* MK_* message key state flags */
248 #define NOWH /* SetWindowsHook and related WH_* definitions */
249 #define NOCLIPBOARD /* Clipboard APIs and definitions */
250 #define NOICONS /* IDI_* icon IDs */
251 #define NOMDI /* MDI support */
252 #define NOHELP /* Help support */
254 /* Not defined since it breaks Borland C++ 5.5 */
255 /* #define NOCTLMGR */ /* Control management and controls */
258 * Exclude parts of WINDOWS.H that are not needed (Win32)
260 #define WIN32_LEAN_AND_MEAN
261 #define NONLS /* All NLS defines and routines */
262 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
263 #define NOKANJI /* Kanji support stuff. */
264 #define NOMCX /* Modem Configuration Extensions */
267 * Include the "windows" support file
272 * Exclude parts of MMSYSTEM.H that are not needed
274 #define MMNODRV /* Installable driver support */
275 #define MMNOWAVE /* Waveform support */
276 #define MMNOMIDI /* MIDI support */
277 #define MMNOAUX /* Auxiliary audio support */
278 #define MMNOTIMER /* Timer support */
279 #define MMNOJOY /* Joystick support */
280 #define MMNOMCI /* MCI support */
281 #define MMNOMMIO /* Multimedia file I/O support */
282 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
285 * Include some more files. Note: the Cygnus Cygwin compiler
286 * doesn't use mmsystem.h instead it includes the winmm library
287 * which performs a similar function.
289 #include <mmsystem.h>
293 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
294 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
296 /* #define HTML_HELP */
299 #include <htmlhelp.h>
300 #endif /* HTML_HELP */
303 * Include the support for loading bitmaps
306 # include "readdib.h"
310 * Hack -- Fake declarations from "dos.h"
313 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
315 #define FA_LABEL 0x08 /* Volume label */
316 #define FA_DIREC 0x10 /* Directory */
317 unsigned _cdecl _dos_getfileattr(concptr , unsigned *);
321 * Silliness in WIN32 drawing routine
324 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
328 * Silliness for Windows 95
330 #ifndef WS_EX_TOOLWINDOW
331 # define WS_EX_TOOLWINDOW 0
335 * Foreground color bits (hard-coded by DOS)
337 #define VID_BLACK 0x00
338 #define VID_BLUE 0x01
339 #define VID_GREEN 0x02
340 #define VID_CYAN 0x03
342 #define VID_MAGENTA 0x05
343 #define VID_YELLOW 0x06
344 #define VID_WHITE 0x07
347 * Bright text (hard-coded by DOS)
349 #define VID_BRIGHT 0x08
352 * Background color bits (hard-coded by DOS)
354 #define VUD_BLACK 0x00
355 #define VUD_BLUE 0x10
356 #define VUD_GREEN 0x20
357 #define VUD_CYAN 0x30
359 #define VUD_MAGENTA 0x50
360 #define VUD_YELLOW 0x60
361 #define VUD_WHITE 0x70
364 * Blinking text (hard-coded by DOS)
366 #define VUD_BRIGHT 0x80
372 typedef struct _term_data term_data;
376 * @brief ターム情報構造体 / Extra "term" data
379 * pos_x / pos_y は各タームの左上点座標を指す。
382 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
383 * 1ドットずつ調整するステータスを指す。
384 * また、フォントを変更すると都度自動調整される。
387 * Note the use of "font_want" for the names of the font file requested by
388 * the user, and the use of "font_file" for the currently active font file.
390 * The "font_file" is uppercased, and takes the form "8X13.FON", while
391 * "font_want" can be in almost any form as long as it could be construed
392 * as attempting to represent the name of a font.
404 TERM_LEN rows; /* int -> uint */
407 uint pos_x; //!< タームの左上X座標
408 uint pos_y; //!< タームの左上Y座標
423 int font_wid; //!< フォント横幅
424 int font_hgt; //!< フォント縦幅
425 int tile_wid; //!< タイル横幅
426 int tile_hgt; //!< タイル縦幅
432 #if 1 /* #ifdef JP */
440 #define MAX_TERM_DATA 8 //!< Maximum number of windows
442 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
443 static term_data *my_td; //!< Hack -- global "window creation" pointer
444 POINT normsize; //!< Remember normal size of main window when maxmized
447 * was main window maximized on previous playing
449 bool win_maximized = FALSE;
454 bool game_in_progress = FALSE;
457 * note when "open"/"new" become valid
459 bool initialized = FALSE;
462 * screen paletted, i.e. 256 colors
464 bool paletted = FALSE;
467 * 16 colors screen, don't use RGB()
469 bool colors16 = FALSE;
472 * Saved instance handle
474 static HINSTANCE hInstance;
477 * Yellow brush for the cursor
479 static HBRUSH hbrYellow;
489 static HPALETTE hPal;
492 static HBITMAP hBG = NULL;
493 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
494 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
499 * The screen saver window
501 static HWND hwndSaver;
503 #endif /* USE_SAVER */
509 * 現在使用中のタイルID(0ならば未使用)
510 * Flag set once "graphics" has been initialized
512 static byte_hack current_graphics_mode = 0;
517 static DIBINIT infGraph;
520 * The global bitmap mask
522 static DIBINIT infMask;
524 #endif /* USE_GRAPHICS */
530 * Flag set once "sound" has been initialized
532 static bool can_use_sound = FALSE;
536 * An array of sound file names
538 static concptr sound_file[SOUND_MAX][SAMPLE_MAX];
540 #endif /* USE_SOUND */
546 #define SAMPLE_MUSIC_MAX 16
547 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
548 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
549 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
550 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
551 static bool can_use_music = FALSE;
553 static MCI_OPEN_PARMS mop;
554 static char mci_device_type[256];
556 int current_music_type = 0;
557 int current_music_id = 0;
559 #endif /* USE_MUSIC */
563 * Full path to ANGBAND.INI
565 static concptr ini_file = NULL;
568 * Name of application
570 static concptr AppName = "ANGBAND";
573 * Name of sub-window type
575 static concptr AngList = "AngList";
580 static concptr ANGBAND_DIR_XTRA_GRAF;
581 static concptr ANGBAND_DIR_XTRA_SOUND;
582 static concptr ANGBAND_DIR_XTRA_MUSIC;
583 static concptr ANGBAND_DIR_XTRA_HELP;
584 #if 0 /* #ifndef JP */
585 static concptr ANGBAND_DIR_XTRA_FONT;
588 static concptr ANGBAND_DIR_XTRA_MUSIC;
593 * The "complex" color values
595 static COLORREF win_clr[256];
599 * Flag for macro trigger with dump ASCII
601 static bool Term_no_press = FALSE;
606 static bool mouse_down = FALSE;
607 static bool paint_rect = FALSE;
608 static TERM_LEN mousex = 0, mousey = 0;
609 static TERM_LEN oldx, oldy;
613 * @brief The "simple" color values
615 * See "main-ibm.c" for original table information
616 * The entries below are taken from the "color bits" defined above.
617 * Note that many of the choices below suck, but so do crappy monitors.
619 static BYTE win_pal[256] =
621 VID_BLACK, /* Dark */
622 VID_WHITE, /* White */
623 VID_CYAN, /* Slate XXX */
624 VID_RED | VID_BRIGHT, /* Orange XXX */
626 VID_GREEN, /* Green */
628 VID_YELLOW, /* Umber XXX */
629 VID_BLACK | VID_BRIGHT, /* Light Dark */
630 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
631 VID_MAGENTA, /* Violet XXX */
632 VID_YELLOW | VID_BRIGHT, /* Yellow */
633 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
634 VID_GREEN | VID_BRIGHT, /* Light Green */
635 VID_BLUE | VID_BRIGHT, /* Light Blue */
636 VID_YELLOW /* Light Umber XXX */
641 * Hack -- define which keys are "special"
643 static bool special_key[256];
644 static bool ignore_key[256];
648 * Hack -- initialization list for "special_key"
650 static byte special_key_list[] = {
651 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
652 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
653 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
654 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
655 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
656 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
657 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
658 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
659 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
660 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
661 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
662 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
663 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
664 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
665 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
666 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
667 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
672 static byte ignore_key_list[] = {
673 VK_ESCAPE, VK_TAB, VK_SPACE,
674 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
675 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
676 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
682 * Hack -- initialization list for "special_key"
684 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
685 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
686 * catch the keypad keys (with and without numlock set, including keypad 5),
687 * the function keys (including the "menu" key which maps to F10), and the
688 * "pause" key (between scroll lock and numlock). We also catch a few odd
689 * keys which I do not recognize, but which are listed among keys which we
690 * do catch, so they should be harmless to catch.
692 static byte special_key_list[] =
694 VK_CLEAR, /* 0x0C (KP<5>) */
696 VK_PAUSE, /* 0x13 (pause) */
698 VK_PRIOR, /* 0x21 (KP<9>) */
699 VK_NEXT, /* 0x22 (KP<3>) */
700 VK_END, /* 0x23 (KP<1>) */
701 VK_HOME, /* 0x24 (KP<7>) */
702 VK_LEFT, /* 0x25 (KP<4>) */
703 VK_UP, /* 0x26 (KP<8>) */
704 VK_RIGHT, /* 0x27 (KP<6>) */
705 VK_DOWN, /* 0x28 (KP<2>) */
706 VK_SELECT, /* 0x29 (?????) */
707 VK_PRINT, /* 0x2A (?????) */
708 VK_EXECUTE, /* 0x2B (?????) */
709 VK_SNAPSHOT, /* 0x2C (?????) */
710 VK_INSERT, /* 0x2D (KP<0>) */
711 VK_DELETE, /* 0x2E (KP<.>) */
712 VK_HELP, /* 0x2F (?????) */
714 VK_NUMPAD0, /* 0x60 (KP<0>) */
715 VK_NUMPAD1, /* 0x61 (KP<1>) */
716 VK_NUMPAD2, /* 0x62 (KP<2>) */
717 VK_NUMPAD3, /* 0x63 (KP<3>) */
718 VK_NUMPAD4, /* 0x64 (KP<4>) */
719 VK_NUMPAD5, /* 0x65 (KP<5>) */
720 VK_NUMPAD6, /* 0x66 (KP<6>) */
721 VK_NUMPAD7, /* 0x67 (KP<7>) */
722 VK_NUMPAD8, /* 0x68 (KP<8>) */
723 VK_NUMPAD9, /* 0x69 (KP<9>) */
724 VK_MULTIPLY, /* 0x6A (KP<*>) */
725 VK_ADD, /* 0x6B (KP<+>) */
726 VK_SEPARATOR, /* 0x6C (?????) */
727 VK_SUBTRACT, /* 0x6D (KP<->) */
728 VK_DECIMAL, /* 0x6E (KP<.>) */
729 VK_DIVIDE, /* 0x6F (KP</>) */
760 /* Function prototype */
762 static bool is_already_running(void);
766 static void delete_bg(void)
775 static int init_bg(void)
777 char * bmfile = bg_bitmap_file;
780 if (use_bg == 0) return 0;
782 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
784 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
792 static void DrawBG(HDC hdc, RECT *r)
797 int x = r->left, y = r->top;
798 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
804 GetObject(hBG, sizeof(bm), &bm);
805 swid = bm.bmWidth; shgt = bm.bmHeight;
807 hdcSrc = CreateCompatibleDC(hdc);
808 hOld = SelectObject(hdcSrc, hBG);
812 cwid = MIN(swid - sx, r->right - nx);
815 chgt = MIN(shgt - sy, r->bottom - ny);
816 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
818 } while (ny < r->bottom);
821 } while (nx < r->right);
823 SelectObject(hdcSrc, hOld);
829 * Hack -- given a pathname, point at the filename
831 static concptr extract_file_name(concptr s)
835 /* Start at the end */
836 p = s + strlen(s) - 1;
838 /* Back up to divider */
839 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
841 /* Return file name */
848 * Hack -- given a simple filename, extract the "font size" info
850 * Return a pointer to a static buffer holding the capitalized base name.
852 #if 0 /* #ifndef JP */
853 static char *analyze_font(char *path, int *wp, int *hp)
859 /* Start at the end */
860 p = path + strlen(path) - 1;
862 /* Back up to divider */
863 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
865 /* Advance to file name */
871 /* Capitalize (be paranoid) */
872 if (islower(*s)) *s = toupper(*s);
876 s = my_strchr(p, 'X');
878 /* Extract font width */
882 hgt = s ? atoi(s+1) : 0;
893 * Check for existance of a file
895 static bool check_file(concptr s)
915 attrib = GetFileAttributes(path);
917 /* Require valid filename */
918 if (attrib == INVALID_FILE_NAME) return (FALSE);
920 /* Prohibit directory */
921 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
925 /* Examine and verify */
926 if (_dos_getfileattr(path, &attrib)) return (FALSE);
928 /* Prohibit something */
929 if (attrib & FA_LABEL) return (FALSE);
931 /* Prohibit directory */
932 if (attrib & FA_DIREC) return (FALSE);
942 * Check for existance of a directory
944 static bool check_dir(concptr s)
966 /* Remove trailing backslash */
967 if (i && (path[i-1] == '\\')) path[--i] = '\0';
972 attrib = GetFileAttributes(path);
974 /* Require valid filename */
975 if (attrib == INVALID_FILE_NAME) return (FALSE);
977 /* Require directory */
978 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
982 /* Examine and verify */
983 if (_dos_getfileattr(path, &attrib)) return (FALSE);
985 /* Prohibit something */
986 if (attrib & FA_LABEL) return (FALSE);
988 /* Require directory */
989 if (!(attrib & FA_DIREC)) return (FALSE);
1001 static void validate_file(concptr s)
1003 /* Verify or fail */
1006 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
1012 * Validate a directory
1014 static void validate_dir(concptr s, bool vital)
1016 /* Verify or fail */
1019 /* This directory contains needed data */
1022 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
1024 /* Attempt to create this directory */
1027 quit_fmt("Unable to create directory:\n%s", s);
1034 * @brief (Windows版固有実装)Get the "size" for a window
1036 static void term_getsize(term_data *td)
1040 if (td->cols < 1) td->cols = 1;
1041 if (td->rows < 1) td->rows = 1;
1044 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1045 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1047 /* Fake window size */
1049 rc.right = rc.left + wid;
1051 rc.bottom = rc.top + hgt;
1053 /* rc.right += 1; */
1054 /* rc.bottom += 1; */
1057 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1060 td->size_wid = rc.right - rc.left;
1061 td->size_hgt = rc.bottom - rc.top;
1063 /* See CreateWindowEx */
1066 /* Extract actual location */
1067 GetWindowRect(td->w, &rc);
1069 /* Save the location */
1070 td->pos_x = rc.left;
1076 * Write the "prefs" for a single term
1078 static void save_prefs_aux(int i)
1080 term_data *td = &data[i];
1081 GAME_TEXT sec_name[128];
1085 WINDOWPLACEMENT lpwndpl;
1088 /* Make section name */
1089 sprintf(sec_name, "Term-%d", i);
1094 strcpy(buf, td->visible ? "1" : "0");
1095 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1100 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "MS ゴシック");
1103 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1105 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1109 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1111 #if 1 /* #ifdef JP */
1112 wsprintf(buf, "%d", td->lf.lfWidth);
1113 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1114 wsprintf(buf, "%d", td->lf.lfHeight);
1115 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1116 wsprintf(buf, "%d", td->lf.lfWeight);
1117 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1120 strcpy(buf, td->bizarre ? "1" : "0");
1121 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1124 wsprintf(buf, "%d", td->tile_wid);
1125 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1128 wsprintf(buf, "%d", td->tile_hgt);
1129 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1131 /* Get window placement and dimensions */
1132 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1133 GetWindowPlacement(td->w, &lpwndpl);
1135 /* Acquire position in *normal* mode (not minimized) */
1136 rc = lpwndpl.rcNormalPosition;
1138 /* Window size (x) */
1139 if (i == 0) wsprintf(buf, "%d", normsize.x);
1140 else wsprintf(buf, "%d", td->cols);
1141 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1143 /* Window size (y) */
1144 if (i == 0) wsprintf(buf, "%d", normsize.y);
1145 else wsprintf(buf, "%d", td->rows);
1146 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1148 /* Maxmized (only main window) */
1151 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1152 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1155 /* Acquire position */
1156 GetWindowRect(td->w, &rc);
1158 /* Window position (x) */
1159 wsprintf(buf, "%d", rc.left);
1160 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1162 /* Window position (y) */
1163 wsprintf(buf, "%d", rc.top);
1164 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1166 /* Window Z position */
1169 strcpy(buf, td->posfix ? "1" : "0");
1170 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1177 * We assume that the windows have all been initialized
1179 static void save_prefs(void)
1185 /* Save the "arg_graphics" flag */
1186 sprintf(buf, "%d", arg_graphics);
1187 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1189 /* Save the "arg_bigtile" flag */
1190 strcpy(buf, arg_bigtile ? "1" : "0");
1191 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1193 /* Save the "arg_sound" flag */
1194 strcpy(buf, arg_sound ? "1" : "0");
1195 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1197 /* Save the "arg_sound" flag */
1198 strcpy(buf, arg_music ? "1" : "0");
1199 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1202 strcpy(buf, use_bg ? "1" : "0");
1203 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1204 WritePrivateProfileString("Angband", "BackGroundBitmap",
1205 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1207 /* Save window prefs */
1208 for (i = 0; i < MAX_TERM_DATA; ++i)
1216 * Load the "prefs" for a single term
1218 static void load_prefs_aux(int i)
1220 term_data *td = &data[i];
1221 GAME_TEXT sec_name[128];
1224 int wid, hgt, posx, posy;
1225 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1226 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1230 /* Make section name */
1231 sprintf(sec_name, "Term-%d", i);
1233 /* Make section name */
1234 sprintf(sec_name, "Term-%d", i);
1239 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1242 /* Desired font, with default */
1244 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1247 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1249 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1255 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1257 /* Analyze font, save desired font name */
1258 #if 1 /* #ifdef JP */
1259 td->font_want = string_make(tmp);
1261 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1262 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1263 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1265 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1270 #if 1 /* #ifdef JP */
1271 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1272 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1274 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1275 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1280 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1281 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1282 normsize.x = td->cols; normsize.y = td->rows;
1287 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
1290 /* Window position */
1291 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1292 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1293 td->pos_x = MIN(MAX(0, posx), dispx-128);
1294 td->pos_y = MIN(MAX(0, posy), dispy-128);
1296 /* Window Z position */
1299 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
1307 static void load_prefs(void)
1311 /* Extract the "arg_graphics" flag */
1312 arg_graphics = (byte_hack)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1314 /* Extract the "arg_bigtile" flag */
1315 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
1316 use_bigtile = arg_bigtile;
1318 /* Extract the "arg_sound" flag */
1319 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1321 /* Extract the "arg_sound" flag */
1322 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1325 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1326 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1328 /* Load window prefs */
1329 for (i = 0; i < MAX_TERM_DATA; ++i)
1335 #if defined(USE_SOUND) || defined(USE_MUSIC)
1338 * - Taken from files.c.
1340 * Extract "tokens" from a buffer
1342 * This function uses "whitespace" as delimiters, and treats any amount of
1343 * whitespace as a single delimiter. We will never return any empty tokens.
1344 * When given an empty buffer, or a buffer containing only "whitespace", we
1345 * will return no tokens. We will never extract more than "num" tokens.
1347 * By running a token through the "text_to_ascii()" function, you can allow
1348 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1350 * We save pointers to the tokens in "tokens", and return the number found.
1352 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1362 /* Skip leading whitespace */
1363 for ( ; *s && iswspace(*s); ++s) /* loop */;
1368 /* Find next whitespace, if any */
1369 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1371 /* Nuke and advance (if necessary) */
1372 if (*t) *t++ = '\0';
1374 /* Save the token */
1385 #endif /* USE_SOUND || USE_MUSIC */
1389 static void load_sound_prefs(void)
1393 char ini_path[1024];
1394 char wav_path[1024];
1395 char *zz[SAMPLE_MAX];
1397 /* Access the sound.cfg */
1399 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1401 for (i = 0; i < SOUND_MAX; i++)
1403 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1405 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1407 for (j = 0; j < num; j++)
1409 /* Access the sound */
1410 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1412 /* Save the sound filename, if it exists */
1413 if (check_file(wav_path))
1414 sound_file[i][j] = string_make(zz[j]);
1419 #endif /* USE_SOUND */
1423 static void load_music_prefs(void)
1427 char ini_path[1024];
1428 char wav_path[1024];
1429 char *zz[SAMPLE_MAX];
1432 /* Access the music.cfg */
1434 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1436 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1438 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1440 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1442 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1444 for (j = 0; j < num; j++)
1446 /* Access the sound */
1447 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1449 /* Save the sound filename, if it exists */
1450 if (check_file(wav_path))
1451 music_file[i][j] = string_make(zz[j]);
1455 for (i = 0; i < max_d_idx; i++)
1457 sprintf(key, "dungeon%03d", i);
1458 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1460 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1462 for (j = 0; j < num; j++)
1464 /* Access the sound */
1465 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1467 /* Save the sound filename, if it exists */
1468 if (check_file(wav_path))
1469 dungeon_music_file[i][j] = string_make(zz[j]);
1473 for (i = 0; i < max_q_idx; i++)
1475 sprintf(key, "quest%03d", i);
1476 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1478 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1480 for (j = 0; j < num; j++)
1482 /* Access the sound */
1483 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1485 /* Save the sound filename, if it exists */
1486 if (check_file(wav_path))
1487 quest_music_file[i][j] = string_make(zz[j]);
1491 for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1493 sprintf(key, "town%03d", i);
1494 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1496 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1498 for (j = 0; j < num; j++)
1500 /* Access the sound */
1501 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1503 /* Save the sound filename, if it exists */
1504 if (check_file(wav_path))
1505 town_music_file[i][j] = string_make(zz[j]);
1512 #endif /* USE_MUSIC */
1515 * Create the new global palette based on the bitmap palette
1516 * (if any), and the standard 16 entry palette derived from
1517 * "win_clr[]" which is used for the basic 16 Angband colors.
1519 * This function is never called before all windows are ready.
1521 * This function returns FALSE if the new palette could not be
1522 * prepared, which should normally be a fatal error. XXX XXX
1524 * Note that only some machines actually use a "palette".
1526 static int new_palette(void)
1534 LPLOGPALETTE pLogPal;
1535 LPPALETTEENTRY lppe;
1540 /* This makes no sense */
1541 if (!paletted) return (TRUE);
1551 /* Check the bitmap palette */
1552 hBmPal = infGraph.hPalette;
1554 /* Use the bitmap */
1557 lppeSize = 256 * sizeof(PALETTEENTRY);
1558 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1559 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1560 if ((nEntries == 0) || (nEntries > 220))
1563 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1566 rnfree(lppe, lppeSize);
1573 #endif /* USE_GRAPHICS */
1575 /* Size of palette */
1576 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1578 /* Allocate palette */
1579 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1582 pLogPal->palVersion = 0x300;
1584 /* Make room for bitmap and normal data */
1585 pLogPal->palNumEntries = nEntries + 16;
1587 /* Save the bitmap data */
1588 for (i = 0; i < nEntries; i++)
1590 pLogPal->palPalEntry[i] = lppe[i];
1593 /* Save the normal data */
1594 for (i = 0; i < 16; i++)
1598 /* Access the entry */
1599 p = &(pLogPal->palPalEntry[i+nEntries]);
1601 /* Save the colors */
1602 p->peRed = GetRValue(win_clr[i]);
1603 p->peGreen = GetGValue(win_clr[i]);
1604 p->peBlue = GetBValue(win_clr[i]);
1606 /* Save the flags */
1607 p->peFlags = PC_NOCOLLAPSE;
1610 /* Free something */
1611 if (lppe) rnfree(lppe, lppeSize);
1613 /* Create a new palette, or fail */
1614 hNewPal = CreatePalette(pLogPal);
1615 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1617 /* Free the palette */
1618 rnfree(pLogPal, pLogPalSize);
1623 /* Realize the palette */
1625 SelectPalette(hdc, hNewPal, 0);
1626 i = RealizePalette(hdc);
1627 ReleaseDC(td->w, hdc);
1628 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1632 for (i = 1; i < MAX_TERM_DATA; i++)
1637 SelectPalette(hdc, hNewPal, 0);
1638 ReleaseDC(td->w, hdc);
1641 /* Delete old palette */
1642 if (hPal) DeleteObject(hPal);
1644 /* Save new palette */
1654 * @brief グラフィクスを初期化する / Initialize graphics
1657 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1658 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1661 static bool init_graphics(void)
1663 /* Initialize once */
1665 BYTE wid, hgt, twid, thgt, ox, oy;
1668 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1678 ANGBAND_GRAF = "new";
1680 else if (arg_graphics == GRAPHICS_HENGBAND)
1700 ANGBAND_GRAF = "ne2";
1711 ANGBAND_GRAF = "old";
1714 /* Access the bitmap file */
1715 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1717 /* Load the bitmap or quit */
1718 if (!ReadDIB(data[0].w, buf, &infGraph))
1720 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1724 /* Save the new sizes */
1725 infGraph.CellWidth = wid;
1726 infGraph.CellHeight = hgt;
1727 infGraph.TileWidth = twid;
1728 infGraph.TileHeight = thgt;
1729 infGraph.OffsetX = ox;
1730 infGraph.OffsetY = oy;
1732 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1734 /* Access the mask file */
1735 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1737 /* Load the bitmap or quit */
1738 if (!ReadDIB(data[0].w, buf, &infMask))
1740 plog_fmt("Cannot read bitmap file '%s'", buf);
1744 if (arg_graphics == GRAPHICS_HENGBAND)
1746 /* Access the mask file */
1747 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1749 /* Load the bitmap or quit */
1750 if (!ReadDIB(data[0].w, buf, &infMask))
1752 plog_fmt("Cannot read bitmap file '%s'", buf);
1757 /* Activate a palette */
1762 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1766 /* Graphics available */
1767 current_graphics_mode = arg_graphics;
1768 return (current_graphics_mode);
1770 #endif /* USE_GRAPHICS */
1777 static bool init_music(void)
1779 /* Initialize once */
1782 /* Load the prefs */
1785 /* Sound available */
1786 can_use_music = TRUE;
1788 return (can_use_music);
1792 * Hack -- Stop a music
1794 static void stop_music(void)
1796 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1797 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1800 #endif /* USE_MUSIC */
1806 static bool init_sound(void)
1808 /* Initialize once */
1811 /* Load the prefs */
1814 /* Sound available */
1815 can_use_sound = TRUE;
1817 return (can_use_sound);
1819 #endif /* USE_SOUND */
1825 static void term_window_resize(term_data *td)
1827 /* Require window */
1830 /* Resize the window */
1831 SetWindowPos(td->w, 0, 0, 0,
1832 td->size_wid, td->size_hgt,
1833 SWP_NOMOVE | SWP_NOZORDER);
1836 InvalidateRect(td->w, NULL, TRUE);
1841 * Force the use of a new "font file" for a term_data
1843 * This function may be called before the "window" is ready
1845 * This function returns zero only if everything succeeds.
1847 * Note that the "font name" must be capitalized!!!
1849 static errr term_force_font(term_data *td, concptr path)
1853 #if 0 /* #ifndef JP */
1859 /* Forget the old font (if needed) */
1860 if (td->font_id) DeleteObject(td->font_id);
1862 #if 1 /* #ifdef JP */
1866 /* Create the font (using the 'base' of the font file name!) */
1867 td->font_id = CreateFontIndirect(&(td->lf));
1868 wid = td->lf.lfWidth;
1869 hgt = td->lf.lfHeight;
1870 if (!td->font_id) return (1);
1872 /* Forget old font */
1878 for (i = 0; i < MAX_TERM_DATA; i++)
1880 /* Don't check when closing the application */
1883 /* Check "screen" */
1884 if ((td != &data[i]) &&
1885 (data[i].font_file) &&
1886 (streq(data[i].font_file, td->font_file)))
1892 /* Remove unused font resources */
1893 if (!used) RemoveFontResource(td->font_file);
1895 /* Free the old name */
1896 string_free(td->font_file);
1899 td->font_file = NULL;
1903 if (!path) return (1);
1908 /* Analyze font path */
1909 base = analyze_font(buf, &wid, &hgt);
1912 if (!suffix(base, ".FON")) return (1);
1915 if (!check_file(buf)) return (1);
1917 /* Load the new font */
1918 if (!AddFontResource(buf)) return (1);
1920 /* Save new font name */
1921 td->font_file = string_make(base);
1923 /* Remove the "suffix" */
1924 base[strlen(base)-4] = '\0';
1926 /* Create the font (using the 'base' of the font file name!) */
1927 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1928 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1929 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1930 FIXED_PITCH | FF_DONTCARE, base);
1933 /* Hack -- Unknown size */
1940 /* all this trouble to get the cell size */
1941 hdcDesktop = GetDC(HWND_DESKTOP);
1942 hfOld = SelectObject(hdcDesktop, td->font_id);
1943 GetTextMetrics(hdcDesktop, &tm);
1944 SelectObject(hdcDesktop, hfOld);
1945 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1947 /* Font size info */
1948 wid = tm.tmAveCharWidth;
1952 /* Save the size info */
1963 * Allow the user to change the font for this window.
1965 static void term_change_font(term_data *td)
1967 #if 1 /* #ifdef JP */
1970 memset(&cf, 0, sizeof(cf));
1971 cf.lStructSize = sizeof(cf);
1972 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1973 cf.lpLogFont = &(td->lf);
1975 if (ChooseFont(&cf))
1977 /* Force the font */
1978 term_force_font(td, NULL);
1980 /* Assume not bizarre */
1983 /* Reset the tile info */
1984 td->tile_wid = td->font_wid;
1985 td->tile_hgt = td->font_hgt;
1987 /* Analyze the font */
1990 /* Resize the window */
1991 term_window_resize(td);
1997 char tmp[1024] = "";
1999 /* Extract a default if possible */
2000 if (td->font_file) strcpy(tmp, td->font_file);
2002 /* Ask for a choice */
2003 memset(&ofn, 0, sizeof(ofn));
2004 ofn.lStructSize = sizeof(ofn);
2005 ofn.hwndOwner = data[0].w;
2006 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
2007 ofn.nFilterIndex = 1;
2008 ofn.lpstrFile = tmp;
2010 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
2011 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2012 ofn.lpstrDefExt = "fon";
2014 /* Force choice if legal */
2015 if (GetOpenFileName(&ofn))
2017 /* Force the font */
2018 if (term_force_font(td, tmp))
2020 /* Access the standard font file */
2021 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2023 /* Force the use of that font */
2024 (void)term_force_font(td, tmp);
2027 /* Assume not bizarre */
2028 td->bizarre = FALSE;
2030 /* Reset the tile info */
2031 td->tile_wid = td->font_wid;
2032 td->tile_hgt = td->font_hgt;
2034 /* Analyze the font */
2037 /* Resize the window */
2038 term_window_resize(td);
2045 * Allow the user to lock this window.
2047 static void term_window_pos(term_data *td, HWND hWnd)
2049 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2050 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2053 static void windows_map(void);
2056 * Hack -- redraw a term_data
2058 static void term_data_redraw(term_data *td)
2062 /* Redraw the map */
2067 /* Activate the term */
2068 Term_activate(&td->t);
2070 /* Redraw the contents */
2073 /* Restore the term */
2074 Term_activate(term_screen);
2079 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2083 HBRUSH myBrush, oldBrush;
2085 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2086 int tx = td->size_ow1 + x * td->tile_wid;
2087 int ty = td->size_oh1 + y * td->tile_hgt;
2088 int tw = w * td->tile_wid - 1;
2089 int th = h * td->tile_hgt - 1;
2092 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2093 oldBrush = SelectObject(hdc, myBrush);
2094 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2096 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2098 SelectObject(hdc, oldBrush);
2099 SelectObject(hdc, oldPen);
2104 /*** Function hooks needed by "Term" ***/
2110 * Initialize a new Term
2112 static void Term_init_win(term *t)
2121 static void Term_nuke_win(term *t)
2130 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
2132 static errr Term_user_win(int n)
2143 * React to global changes
2145 static errr Term_xtra_win_react(void)
2152 /* Save the default colors */
2153 for (i = 0; i < 256; i++)
2155 /* Simply accept the desired colors */
2156 win_pal[i] = angband_color_table[i][0];
2167 bool change = FALSE;
2169 /* Save the default colors */
2170 for (i = 0; i < 256; i++)
2172 /* Extract desired values */
2173 rv = angband_color_table[i][1];
2174 gv = angband_color_table[i][2];
2175 bv = angband_color_table[i][3];
2177 /* Extract a full color code */
2178 code = PALETTERGB(rv, gv, bv);
2180 /* Activate changes */
2181 if (win_clr[i] != code)
2183 /* Note the change */
2186 /* Apply the desired color */
2191 /* Activate the palette if needed */
2192 if (change) (void)new_palette();
2198 /* Handle "arg_sound" */
2199 if (use_sound != arg_sound)
2201 /* Initialize (if needed) */
2202 if (arg_sound && !init_sound())
2205 plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
2211 /* Change setting */
2212 use_sound = arg_sound;
2219 /* Handle "arg_sound" */
2220 if (use_music != arg_music)
2222 /* Initialize (if needed) */
2223 if (arg_music && !init_music())
2226 plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
2231 /* Change setting */
2232 use_music = arg_music;
2234 if(!arg_music) stop_music();
2235 else select_floor_music();
2244 /* Handle "arg_graphics" */
2245 if (use_graphics != arg_graphics)
2247 /* Initialize (if needed) */
2248 if (arg_graphics && !init_graphics())
2251 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
2254 arg_graphics = GRAPHICS_NONE;
2257 /* Change setting */
2258 use_graphics = arg_graphics;
2261 #ifdef ANGBAND_2_8_1
2263 #else /* ANGBAND_2_8_1 */
2264 reset_visuals(TRUE);
2265 #endif /* ANGBAND_2_8_1 */
2268 #endif /* USE_GRAPHICS */
2271 /* Clean up windows */
2272 for (i = 0; i < MAX_TERM_DATA; i++)
2276 term_data *td = &data[i];
2278 /* Update resized windows */
2279 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
2282 Term_activate(&td->t);
2284 /* Hack -- Resize the term */
2285 Term_resize(td->cols, td->rows);
2287 /* Redraw the contents */
2300 * Process at least one event
2302 static errr Term_xtra_win_event(int v)
2306 /* Wait for an event */
2310 if (GetMessage(&msg, NULL, 0, 0))
2312 TranslateMessage(&msg);
2313 DispatchMessage(&msg);
2317 /* Check for an event */
2321 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2323 TranslateMessage(&msg);
2324 DispatchMessage(&msg);
2334 * Process all pending events
2336 static errr Term_xtra_win_flush(void)
2340 /* Process all pending events */
2341 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2343 TranslateMessage(&msg);
2344 DispatchMessage(&msg);
2353 * Hack -- clear the screen
2355 * Make this more efficient
2357 static errr Term_xtra_win_clear(void)
2359 term_data *td = (term_data*)(Term->data);
2364 /* Rectangle to erase */
2365 rc.left = td->size_ow1;
2366 rc.right = rc.left + td->cols * td->tile_wid;
2367 rc.top = td->size_oh1;
2368 rc.bottom = rc.top + td->rows * td->tile_hgt;
2372 SetBkColor(hdc, RGB(0, 0, 0));
2373 SelectObject(hdc, td->font_id);
2374 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2379 rc.left = 0; rc.top = 0;
2382 ReleaseDC(td->w, hdc);
2390 * Hack -- make a noise
2392 static errr Term_xtra_win_noise(void)
2394 MessageBeep(MB_ICONASTERISK);
2400 * Hack -- make a sound
2402 static errr Term_xtra_win_sound(int v)
2407 #endif /* USE_SOUND */
2409 /* Sound disabled */
2410 if (!use_sound) return (1);
2413 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2417 /* Count the samples */
2418 for (i = 0; i < SAMPLE_MAX; i++)
2420 if (!sound_file[v][i])
2425 if (i == 0) return (1);
2427 /* Build the path */
2428 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2432 /* Play the sound, catch errors */
2433 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2437 /* Play the sound, catch errors */
2438 return (sndPlaySound(buf, SND_ASYNC));
2442 #else /* USE_SOUND */
2446 #endif /* USE_SOUND */
2450 * Hack -- play a music
2452 static errr Term_xtra_win_music(int n, int v)
2457 #endif /* USE_MUSIC */
2459 /* Sound disabled */
2461 if(!use_music) return (1);
2464 if(n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return (1);
2465 else if(v < 0 || v >= 1000) return(1); /*!< TODO */
2471 case TERM_XTRA_MUSIC_BASIC:
2472 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2474 case TERM_XTRA_MUSIC_DUNGEON:
2475 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2477 case TERM_XTRA_MUSIC_QUEST:
2478 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2480 case TERM_XTRA_MUSIC_TOWN:
2481 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2488 //mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2489 //mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2495 case TERM_XTRA_MUSIC_BASIC:
2496 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2498 case TERM_XTRA_MUSIC_DUNGEON:
2499 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2501 case TERM_XTRA_MUSIC_QUEST:
2502 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2504 case TERM_XTRA_MUSIC_TOWN:
2505 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2512 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2513 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2519 case TERM_XTRA_MUSIC_BASIC:
2520 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2522 case TERM_XTRA_MUSIC_DUNGEON:
2523 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2525 case TERM_XTRA_MUSIC_QUEST:
2526 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2528 case TERM_XTRA_MUSIC_TOWN:
2529 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2533 if(current_music_type == n && current_music_id == v)
2537 current_music_type = n;
2538 current_music_id = v;
2542 mop.lpstrDeviceType = mci_device_type;
2543 mop.lpstrElementName = buf;
2544 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2545 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2546 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2547 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2548 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2553 #else /* USE_MUSIC */
2557 #endif /* USE_MUSIC */
2563 * Delay for "x" milliseconds
2565 static int Term_xtra_win_delay(int v)
2579 t = GetTickCount() + v;
2582 while (GetTickCount() < t)
2584 /* Handle messages */
2585 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2587 TranslateMessage(&msg);
2588 DispatchMessage(&msg);
2600 * Do a "special thing"
2602 static errr Term_xtra_win(int n, int v)
2604 /* Handle a subset of the legal requests */
2607 /* Make a bell sound */
2608 case TERM_XTRA_NOISE:
2610 return (Term_xtra_win_noise());
2614 case TERM_XTRA_MUSIC_BASIC:
2615 case TERM_XTRA_MUSIC_DUNGEON:
2616 case TERM_XTRA_MUSIC_QUEST:
2617 case TERM_XTRA_MUSIC_TOWN:
2619 return (Term_xtra_win_music(n, v));
2622 /* Make a special sound */
2623 case TERM_XTRA_SOUND:
2625 return (Term_xtra_win_sound(v));
2628 /* Process random events */
2629 case TERM_XTRA_BORED:
2631 return (Term_xtra_win_event(0));
2634 /* Process an event */
2635 case TERM_XTRA_EVENT:
2637 return (Term_xtra_win_event(v));
2640 /* Flush all events */
2641 case TERM_XTRA_FLUSH:
2643 return (Term_xtra_win_flush());
2646 /* Clear the screen */
2647 case TERM_XTRA_CLEAR:
2649 return (Term_xtra_win_clear());
2652 /* React to global changes */
2653 case TERM_XTRA_REACT:
2655 return (Term_xtra_win_react());
2658 /* Delay for some milliseconds */
2659 case TERM_XTRA_DELAY:
2661 return (Term_xtra_win_delay(v));
2671 * Low level graphics (Assumes valid input).
2673 * Draw a "cursor" at (x,y), using a "yellow box".
2675 static errr Term_curs_win(int x, int y)
2677 term_data *td = (term_data*)(Term->data);
2682 int tile_wid, tile_hgt;
2686 tile_wid = td->map_tile_wid;
2687 tile_hgt = td->map_tile_hgt;
2691 tile_wid = td->tile_wid;
2692 tile_hgt = td->tile_hgt;
2695 /* Frame the grid */
2696 rc.left = x * tile_wid + td->size_ow1;
2697 rc.right = rc.left + tile_wid;
2698 rc.top = y * tile_hgt + td->size_oh1;
2699 rc.bottom = rc.top + tile_hgt;
2701 /* Cursor is done as a yellow "box" */
2703 FrameRect(hdc, &rc, hbrYellow);
2704 ReleaseDC(td->w, hdc);
2712 * Low level graphics (Assumes valid input).
2714 * Draw a "big cursor" at (x,y), using a "yellow box".
2716 static errr Term_bigcurs_win(int x, int y)
2718 term_data *td = (term_data*)(Term->data);
2723 int tile_wid, tile_hgt;
2727 /* Normal cursor in map window */
2728 Term_curs_win(x, y);
2733 tile_wid = td->tile_wid;
2734 tile_hgt = td->tile_hgt;
2737 /* Frame the grid */
2738 rc.left = x * tile_wid + td->size_ow1;
2739 rc.right = rc.left + 2 * tile_wid;
2740 rc.top = y * tile_hgt + td->size_oh1;
2741 rc.bottom = rc.top + tile_hgt;
2743 /* Cursor is done as a yellow "box" */
2745 FrameRect(hdc, &rc, hbrYellow);
2746 ReleaseDC(td->w, hdc);
2754 * Low level graphics (Assumes valid input).
2756 * Erase a "block" of "n" characters starting at (x,y).
2758 static errr Term_wipe_win(int x, int y, int n)
2760 term_data *td = (term_data*)(Term->data);
2765 /* Rectangle to erase in client coords */
2766 rc.left = x * td->tile_wid + td->size_ow1;
2767 rc.right = rc.left + n * td->tile_wid;
2768 rc.top = y * td->tile_hgt + td->size_oh1;
2769 rc.bottom = rc.top + td->tile_hgt;
2772 SetBkColor(hdc, RGB(0, 0, 0));
2773 SelectObject(hdc, td->font_id);
2778 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2779 ReleaseDC(td->w, hdc);
2787 * Low level graphics. Assumes valid input.
2789 * Draw several ("n") chars, with an attr, at a given location.
2791 * All "graphic" data is handled by "Term_pict_win()", below.
2793 * One would think there is a more efficient method for telling a window
2794 * what color it should be using to draw with, but perhaps simply changing
2795 * it every time is not too inefficient.
2797 static errr Term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
2799 term_data *td = (term_data*)(Term->data);
2803 #if 1 /* #ifdef JP */
2804 static HBITMAP WALL;
2805 static HBRUSH myBrush, oldBrush;
2807 static bool init_done = FALSE;
2810 WALL = LoadBitmap(hInstance, AppName);
2811 myBrush = CreatePatternBrush(WALL);
2816 /* Total rectangle */
2817 rc.left = x * td->tile_wid + td->size_ow1;
2818 rc.right = rc.left + n * td->tile_wid;
2819 rc.top = y * td->tile_hgt + td->size_oh1;
2820 rc.bottom = rc.top + td->tile_hgt;
2825 /* Background color */
2826 SetBkColor(hdc, RGB(0, 0, 0));
2828 /* Foreground color */
2831 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2835 SetTextColor(hdc, win_clr[a&0x0F]);
2839 SetTextColor(hdc, win_clr[a]);
2843 SelectObject(hdc, td->font_id);
2846 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2850 (td->tile_hgt != td->font_hgt) ||
2851 (td->tile_wid != td->font_wid))
2855 /* Erase complete rectangle */
2856 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2859 if (use_bg) DrawBG(hdc, &rc);
2862 rc.left += ((td->tile_wid - td->font_wid) / 2);
2863 rc.right = rc.left + td->font_wid;
2864 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2865 rc.bottom = rc.top + td->font_hgt;
2867 /* Dump each character */
2868 for (i = 0; i < n; i++)
2871 if (use_bigtile && *(s+i)=="■"[0] && *(s+i+1)=="■"[1])
2873 rc.right += td->font_wid;
2875 oldBrush = SelectObject(hdc, myBrush);
2876 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2879 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2881 SelectObject(hdc, oldBrush);
2882 SelectObject(hdc, oldPen);
2883 rc.right -= td->font_wid;
2887 rc.left += 2 * td->tile_wid;
2888 rc.right += 2 * td->tile_wid;
2890 else if ( iskanji(*(s+i)) ) /* 2バイト文字 */
2892 rc.right += td->font_wid;
2894 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2896 rc.right -= td->font_wid;
2900 rc.left += 2 * td->tile_wid;
2901 rc.right += 2 * td->tile_wid;
2902 } else if (*(s+i)==127){
2903 oldBrush = SelectObject(hdc, myBrush);
2904 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2907 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2909 SelectObject(hdc, oldBrush);
2910 SelectObject(hdc, oldPen);
2913 rc.left += td->tile_wid;
2914 rc.right += td->tile_wid;
2917 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2920 rc.left += td->tile_wid;
2921 rc.right += td->tile_wid;
2926 oldBrush = SelectObject(hdc, myBrush);
2927 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2930 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2932 SelectObject(hdc, oldBrush);
2933 SelectObject(hdc, oldPen);
2936 rc.left += td->tile_wid;
2937 rc.right += td->tile_wid;
2940 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2944 rc.left += td->tile_wid;
2945 rc.right += td->tile_wid;
2949 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2953 rc.left += td->tile_wid;
2954 rc.right += td->tile_wid;
2965 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2970 ReleaseDC(td->w, hdc);
2978 * Low level graphics. Assumes valid input.
2980 * Draw an array of "special" attr/char pairs at the given location.
2982 * We use the "Term_pict_win()" function for "graphic" data, which are
2983 * encoded by setting the "high-bits" of both the "attr" and the "char"
2984 * data. We use the "attr" to represent the "row" of the main bitmap,
2985 * and the "char" to represent the "col" of the main bitmap. The use
2986 * of this function is induced by the "higher_pict" flag.
2988 * If "graphics" is not available, we simply "wipe" the given grids.
2990 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)
2992 term_data *td = (term_data*)(Term->data);
2997 TERM_LEN x1, y1, w1, h1, tw1, th1;
2998 TERM_LEN x2, y2, w2, h2, tw2 = 0;
3008 /* Erase the grids */
3009 return (Term_wipe_win(x, y, n));
3012 /* Size of bitmap cell */
3013 w1 = infGraph.CellWidth;
3014 h1 = infGraph.CellHeight;
3015 tw1 = infGraph.TileWidth;
3016 th1 = infGraph.TileHeight;
3018 /* Size of window cell */
3021 w2 = td->map_tile_wid;
3022 h2 = td->map_tile_hgt;
3031 if (use_bigtile) tw2 *= 2;
3034 /* Location of window cell */
3035 x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
3036 y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
3042 hdcSrc = CreateCompatibleDC(hdc);
3043 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
3045 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3047 hdcMask = CreateCompatibleDC(hdc);
3048 SelectObject(hdcMask, infMask.hBitmap);
3051 /* Draw attr/char pairs */
3052 for (i = 0; i < n; i++, x2 += w2)
3054 TERM_COLOR a = ap[i];
3058 /* Extract picture */
3059 int row = (a & 0x7F);
3060 int col = (c & 0x7F);
3062 /* Location of bitmap cell */
3066 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3068 x3 = (tcp[i] & 0x7F) * w1;
3069 y3 = (tap[i] & 0x7F) * h1;
3070 tw2 = tw2 * w1 / tw1;
3074 if ((tw1 == tw2) && (th1 == h2))
3076 /* Copy the terrain picture from the bitmap to the window */
3077 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
3079 /* Mask out the tile */
3080 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3083 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3086 /* Need to stretch */
3089 /* Set the correct mode for stretching the tiles */
3090 SetStretchBltMode(hdc, COLORONCOLOR);
3092 /* Copy the terrain picture from the bitmap to the window */
3093 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
3095 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
3097 /* Only draw if terrain and overlay are different */
3098 if ((x1 != x3) || (y1 != y3))
3100 /* Mask out the tile */
3101 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3104 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3111 if ((w1 == tw2) && (h1 == h2))
3113 /* Copy the picture from the bitmap to the window */
3114 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3117 /* Need to stretch */
3120 /* Set the correct mode for stretching the tiles */
3121 SetStretchBltMode(hdc, COLORONCOLOR);
3123 /* Copy the picture from the bitmap to the window */
3124 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3130 SelectObject(hdcSrc, hbmSrcOld);
3133 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3136 SelectObject(hdcMask, hbmSrcOld);
3141 ReleaseDC(td->w, hdc);
3143 #else /* USE_GRAPHICS */
3145 /* Just erase this grid */
3146 return (Term_wipe_win(x, y, n));
3148 #endif /* USE_GRAPHICS */
3155 static void windows_map(void)
3157 term_data *td = &data[0];
3160 TERM_LEN x, min_x, max_x;
3161 TERM_LEN y, min_y, max_y;
3166 /* Only in graphics mode */
3167 if (!use_graphics) return;
3168 Term_xtra_win_clear();
3170 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3171 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3172 td->map_active = TRUE;
3177 max_x = current_floor_ptr->width;
3178 max_y = current_floor_ptr->height;
3182 for (x = min_x; x < max_x; x++)
3184 for (y = min_y; y < max_y; y++)
3186 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3188 /* Ignore non-graphics */
3189 if ((a & 0x80) && (c & 0x80))
3191 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3196 /* Hilite the player */
3197 Term_curs_win(p_ptr->x - min_x, p_ptr->y - min_y);
3199 /* Wait for a keypress, flush key buffer */
3200 Term_inkey(&c, TRUE, TRUE);
3203 /* Switch off the map display */
3204 td->map_active = FALSE;
3206 /* Restore screen */
3207 Term_xtra_win_clear();
3212 /*** Other routines ***/
3216 * Create and initialize a "term_data" given a title
3218 static void term_data_link(term_data *td)
3222 /* Initialize the term */
3223 term_init(t, td->cols, td->rows, td->keys);
3225 /* Use a "software" cursor */
3226 t->soft_cursor = TRUE;
3228 /* Use "Term_pict" for "graphic" data */
3229 t->higher_pict = TRUE;
3231 /* Erase with "white space" */
3232 t->attr_blank = TERM_WHITE;
3233 t->char_blank = ' ';
3236 /* Prepare the init/nuke hooks */
3237 t->init_hook = Term_init_win;
3238 t->nuke_hook = Term_nuke_win;
3241 /* Prepare the template hooks */
3242 t->user_hook = Term_user_win;
3243 t->xtra_hook = Term_xtra_win;
3244 t->curs_hook = Term_curs_win;
3245 t->bigcurs_hook = Term_bigcurs_win;
3246 t->wipe_hook = Term_wipe_win;
3247 t->text_hook = Term_text_win;
3248 t->pict_hook = Term_pict_win;
3250 /* Remember where we came from */
3251 t->data = (vptr)(td);
3256 * Create the windows
3258 * First, instantiate the "default" values, then read the "ini_file"
3259 * to over-ride selected values, then create the windows, and fonts.
3261 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3262 * must make active to realize the palette.
3264 static void init_windows(void)
3270 #if 0 /* #ifndef JP */
3276 WIPE(td, term_data);
3280 td->s = angband_term_name[0];
3294 #if 1 /* #ifdef JP */
3298 for (i = 1; i < MAX_TERM_DATA; i++)
3301 WIPE(td, term_data);
3302 td->s = angband_term_name[i];
3306 td->visible = FALSE;
3311 td->pos_x = (7 - i) * 30;
3312 td->pos_y = (7 - i) * 20;
3314 #if 1 /* #ifdef JP */
3324 /* Main window (need these before term_getsize gets called) */
3326 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3327 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3332 /* Sub windows (need these before term_getsize gets called) */
3333 for (i = 1; i < MAX_TERM_DATA; i++)
3336 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3337 td->dwExStyle = (WS_EX_TOOLWINDOW);
3342 for (i = 0; i < MAX_TERM_DATA; i++)
3346 #if 1 /* #ifdef JP */
3347 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3348 td->lf.lfCharSet = DEFAULT_CHARSET;
3349 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3350 /* Activate the chosen font */
3351 term_force_font(td, NULL);
3352 if(!td->tile_wid) td->tile_wid = td->font_wid;
3353 if(!td->tile_hgt) td->tile_hgt = td->font_hgt;
3355 /* Access the standard font file */
3356 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3358 /* Activate the chosen font */
3359 if (term_force_font(td, buf))
3361 /* Access the standard font file */
3362 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3364 /* Force the use of that font */
3365 (void)term_force_font(td, buf);
3370 /* Assume not bizarre */
3371 td->bizarre = FALSE;
3376 /* Analyze the font */
3379 /* Resize the window */
3380 term_window_resize(td);
3384 /* Sub windows (reverse order) */
3385 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3390 td->w = CreateWindowEx(td->dwExStyle, AngList,
3392 td->pos_x, td->pos_y,
3393 td->size_wid, td->size_hgt,
3394 HWND_DESKTOP, NULL, hInstance, NULL);
3396 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3400 td->size_hack = TRUE;
3401 ShowWindow(td->w, SW_SHOW);
3402 td->size_hack = FALSE;
3406 angband_term[i] = &td->t;
3410 /* Activate the window */
3411 SetActiveWindow(td->w);
3416 term_window_pos(&data[i], HWND_TOPMOST);
3420 term_window_pos(&data[i], td->w);
3430 td->w = CreateWindowEx(td->dwExStyle, AppName,
3432 td->pos_x, td->pos_y,
3433 td->size_wid, td->size_hgt,
3434 HWND_DESKTOP, NULL, hInstance, NULL);
3436 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3439 angband_term[0] = &td->t;
3440 normsize.x = td->cols;
3441 normsize.y = td->rows;
3443 /* Activate the main window */
3444 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3445 else ShowWindow(td->w, SW_SHOW);
3447 /* Bring main window back to top */
3448 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3452 (void)new_palette();
3455 /* Create a "brush" for drawing the "cursor" */
3456 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3459 /* Process pending messages */
3460 (void)Term_xtra_win_flush();
3468 static void setup_menus(void)
3472 HMENU hm = GetMenu(data[0].w);
3475 /* Menu "File", Disable all */
3476 EnableMenuItem(hm, IDM_FILE_NEW,
3477 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3478 EnableMenuItem(hm, IDM_FILE_OPEN,
3479 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3480 EnableMenuItem(hm, IDM_FILE_SAVE,
3481 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3482 EnableMenuItem(hm, IDM_FILE_EXIT,
3483 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3484 EnableMenuItem(hm, IDM_FILE_SCORE,
3485 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3488 /* No character available */
3489 if (!character_generated)
3491 /* Menu "File", Item "New" */
3492 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3494 /* Menu "File", Item "Open" */
3495 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3498 /* A character available */
3499 if (character_generated)
3501 /* Menu "File", Item "Save" */
3502 EnableMenuItem(hm, IDM_FILE_SAVE,
3503 MF_BYCOMMAND | MF_ENABLED);
3506 /* Menu "File", Item "Exit" */
3507 EnableMenuItem(hm, IDM_FILE_EXIT,
3508 MF_BYCOMMAND | MF_ENABLED);
3510 EnableMenuItem(hm, IDM_FILE_SCORE,
3511 MF_BYCOMMAND | MF_ENABLED);
3514 /* Menu "Window::Visibility" */
3515 for (i = 0; i < MAX_TERM_DATA; i++)
3517 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3518 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3520 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3521 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3523 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3524 MF_BYCOMMAND | MF_ENABLED);
3527 /* Menu "Window::Font" */
3528 for (i = 0; i < MAX_TERM_DATA; i++)
3530 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3531 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3533 if (data[i].visible)
3535 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3536 MF_BYCOMMAND | MF_ENABLED);
3540 /* Menu "Window::Window Position Fix" */
3541 for (i = 0; i < MAX_TERM_DATA; i++)
3543 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3544 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3546 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3547 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3549 if (data[i].visible)
3551 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3552 MF_BYCOMMAND | MF_ENABLED);
3556 /* Menu "Window::Bizarre Display" */
3557 for (i = 0; i < MAX_TERM_DATA; i++)
3559 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3560 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3562 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3563 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3565 if (data[i].visible)
3567 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3568 MF_BYCOMMAND | MF_ENABLED);
3573 /* Menu "Window::Increase Tile Width" */
3574 for (i = 0; i < MAX_TERM_DATA; i++)
3576 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3577 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3579 if (data[i].visible)
3581 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3582 MF_BYCOMMAND | MF_ENABLED);
3587 /* Menu "Window::Decrease Tile Width" */
3588 for (i = 0; i < MAX_TERM_DATA; i++)
3590 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3591 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3593 if (data[i].visible)
3595 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3596 MF_BYCOMMAND | MF_ENABLED);
3601 /* Menu "Window::Increase Tile Height" */
3602 for (i = 0; i < MAX_TERM_DATA; i++)
3604 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3605 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3607 if (data[i].visible)
3609 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3610 MF_BYCOMMAND | MF_ENABLED);
3615 /* Menu "Window::Decrease Tile Height" */
3616 for (i = 0; i < MAX_TERM_DATA; i++)
3618 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3619 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3621 if (data[i].visible)
3623 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3624 MF_BYCOMMAND | MF_ENABLED);
3629 /* Menu "Options", disable all */
3630 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3631 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3632 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3633 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3634 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3635 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3636 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3637 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3638 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3639 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3641 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3642 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3645 /* Menu "Options", Item "Map" */
3646 if (use_graphics != GRAPHICS_NONE)
3647 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3649 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3650 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3652 /* Menu "Options", update all */
3653 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3654 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3655 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3656 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3657 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3658 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3659 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3660 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3661 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3662 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3663 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3664 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3665 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3666 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3667 CheckMenuItem(hm, IDM_OPTIONS_BG,
3668 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3670 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3671 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3675 /* Menu "Options", Item "Graphics" */
3676 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3677 /* Menu "Options", Item "Graphics" */
3678 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3679 /* Menu "Options", Item "Graphics" */
3680 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3681 /* Menu "Options", Item "Graphics" */
3682 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3683 #endif /* USE_GRAPHICS */
3686 /* Menu "Options", Item "Sound" */
3687 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3688 #endif /* USE_SOUND */
3691 /* Menu "Options", Item "ScreenSaver" */
3692 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3693 MF_BYCOMMAND | MF_ENABLED);
3694 #endif /* USE_SAVER */
3699 * Check for double clicked (or dragged) savefile
3701 * Apparently, Windows copies the entire filename into the first
3702 * piece of the "command line string". Perhaps we should extract
3703 * the "basename" of that filename and append it to the "save" dir.
3705 static void check_for_save_file(LPSTR cmd_line)
3715 /* Extract filename */
3716 strcat(savefile, s);
3718 /* Validate the file */
3719 validate_file(savefile);
3721 /* Game in progress */
3722 game_in_progress = TRUE;
3730 * Process a menu command
3732 static void process_menus(WORD wCmd)
3748 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3750 else if (game_in_progress)
3752 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3756 game_in_progress = TRUE;
3769 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3771 else if (game_in_progress)
3773 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3777 memset(&ofn, 0, sizeof(ofn));
3778 ofn.lStructSize = sizeof(ofn);
3779 ofn.hwndOwner = data[0].w;
3780 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3781 ofn.nFilterIndex = 1;
3782 ofn.lpstrFile = savefile;
3783 ofn.nMaxFile = 1024;
3784 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3785 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3787 if (GetOpenFileName(&ofn))
3789 /* Load 'savefile' */
3790 validate_file(savefile);
3791 game_in_progress = TRUE;
3803 if (game_in_progress && character_generated)
3807 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3811 /* Hack -- Forget messages */
3816 do_cmd_save_game(FALSE);
3817 #else /* ZANGBAND */
3819 #endif /* ZANGBAND */
3823 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3831 if (game_in_progress && character_generated)
3835 plog(_("今は終了できません。", "You may not do that right now."));
3839 /* Hack -- Forget messages */
3848 /* do_cmd_save_game(FALSE); */
3849 #else /* ZANGBAND */
3850 /* do_cmd_save_game(); */
3851 #endif /* ZANGBAND */
3852 Term_key_push(SPECIAL_KEY_QUIT);
3860 case IDM_FILE_SCORE:
3864 /* Build the filename */
3865 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3867 /* Open the binary high score file, for reading */
3868 highscore_fd = fd_open(buf, O_RDONLY);
3870 /* Paranoia -- No score file */
3871 if (highscore_fd < 0)
3873 msg_print("Score file unavailable.");
3880 /* Display the scores */
3881 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3883 /* Shut the high score file */
3884 (void)fd_close(highscore_fd);
3886 /* Forget the high score fd */
3890 /* Hack - Flush it */
3898 case IDM_FILE_MOVIE:
3902 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3904 else if (game_in_progress)
3906 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
3910 memset(&ofn, 0, sizeof(ofn));
3911 ofn.lStructSize = sizeof(ofn);
3912 ofn.hwndOwner = data[0].w;
3913 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3914 ofn.nFilterIndex = 1;
3915 ofn.lpstrFile = savefile;
3916 ofn.nMaxFile = 1024;
3917 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3918 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3920 if (GetOpenFileName(&ofn))
3922 /* Load 'savefile' */
3923 prepare_browse_movie_aux(savefile);
3933 case IDM_WINDOW_VIS_0:
3935 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
3939 /* Window visibility */
3940 case IDM_WINDOW_VIS_1:
3941 case IDM_WINDOW_VIS_2:
3942 case IDM_WINDOW_VIS_3:
3943 case IDM_WINDOW_VIS_4:
3944 case IDM_WINDOW_VIS_5:
3945 case IDM_WINDOW_VIS_6:
3946 case IDM_WINDOW_VIS_7:
3948 i = wCmd - IDM_WINDOW_VIS_0;
3950 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3957 ShowWindow(td->w, SW_SHOW);
3958 term_data_redraw(td);
3962 td->visible = FALSE;
3964 ShowWindow(td->w, SW_HIDE);
3971 case IDM_WINDOW_FONT_0:
3972 case IDM_WINDOW_FONT_1:
3973 case IDM_WINDOW_FONT_2:
3974 case IDM_WINDOW_FONT_3:
3975 case IDM_WINDOW_FONT_4:
3976 case IDM_WINDOW_FONT_5:
3977 case IDM_WINDOW_FONT_6:
3978 case IDM_WINDOW_FONT_7:
3980 i = wCmd - IDM_WINDOW_FONT_0;
3982 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3986 term_change_font(td);
3991 /* Window Z Position */
3992 case IDM_WINDOW_POS_1:
3993 case IDM_WINDOW_POS_2:
3994 case IDM_WINDOW_POS_3:
3995 case IDM_WINDOW_POS_4:
3996 case IDM_WINDOW_POS_5:
3997 case IDM_WINDOW_POS_6:
3998 case IDM_WINDOW_POS_7:
4000 i = wCmd - IDM_WINDOW_POS_0;
4002 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4006 if (!td->posfix && td->visible)
4009 term_window_pos(td, HWND_TOPMOST);
4014 term_window_pos(td, data[0].w);
4020 /* Bizarre Display */
4021 case IDM_WINDOW_BIZ_0:
4022 case IDM_WINDOW_BIZ_1:
4023 case IDM_WINDOW_BIZ_2:
4024 case IDM_WINDOW_BIZ_3:
4025 case IDM_WINDOW_BIZ_4:
4026 case IDM_WINDOW_BIZ_5:
4027 case IDM_WINDOW_BIZ_6:
4028 case IDM_WINDOW_BIZ_7:
4030 i = wCmd - IDM_WINDOW_BIZ_0;
4032 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4036 td->bizarre = !td->bizarre;
4040 term_window_resize(td);
4045 /* Increase Tile Width */
4046 case IDM_WINDOW_I_WID_0:
4047 case IDM_WINDOW_I_WID_1:
4048 case IDM_WINDOW_I_WID_2:
4049 case IDM_WINDOW_I_WID_3:
4050 case IDM_WINDOW_I_WID_4:
4051 case IDM_WINDOW_I_WID_5:
4052 case IDM_WINDOW_I_WID_6:
4053 case IDM_WINDOW_I_WID_7:
4055 i = wCmd - IDM_WINDOW_I_WID_0;
4057 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4065 term_window_resize(td);
4070 /* Decrease Tile Height */
4071 case IDM_WINDOW_D_WID_0:
4072 case IDM_WINDOW_D_WID_1:
4073 case IDM_WINDOW_D_WID_2:
4074 case IDM_WINDOW_D_WID_3:
4075 case IDM_WINDOW_D_WID_4:
4076 case IDM_WINDOW_D_WID_5:
4077 case IDM_WINDOW_D_WID_6:
4078 case IDM_WINDOW_D_WID_7:
4080 i = wCmd - IDM_WINDOW_D_WID_0;
4082 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4090 term_window_resize(td);
4095 /* Increase Tile Height */
4096 case IDM_WINDOW_I_HGT_0:
4097 case IDM_WINDOW_I_HGT_1:
4098 case IDM_WINDOW_I_HGT_2:
4099 case IDM_WINDOW_I_HGT_3:
4100 case IDM_WINDOW_I_HGT_4:
4101 case IDM_WINDOW_I_HGT_5:
4102 case IDM_WINDOW_I_HGT_6:
4103 case IDM_WINDOW_I_HGT_7:
4105 i = wCmd - IDM_WINDOW_I_HGT_0;
4107 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4115 term_window_resize(td);
4120 /* Decrease Tile Height */
4121 case IDM_WINDOW_D_HGT_0:
4122 case IDM_WINDOW_D_HGT_1:
4123 case IDM_WINDOW_D_HGT_2:
4124 case IDM_WINDOW_D_HGT_3:
4125 case IDM_WINDOW_D_HGT_4:
4126 case IDM_WINDOW_D_HGT_5:
4127 case IDM_WINDOW_D_HGT_6:
4128 case IDM_WINDOW_D_HGT_7:
4130 i = wCmd - IDM_WINDOW_D_HGT_0;
4132 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4140 term_window_resize(td);
4145 case IDM_OPTIONS_NO_GRAPHICS:
4149 plog("You may not do that right now.");
4153 /* Toggle "arg_graphics" */
4154 if (arg_graphics != GRAPHICS_NONE)
4156 arg_graphics = GRAPHICS_NONE;
4158 /* React to changes */
4159 Term_xtra_win_react();
4161 /* Hack -- Force redraw */
4162 Term_key_push(KTRL('R'));
4168 case IDM_OPTIONS_OLD_GRAPHICS:
4172 plog("You may not do that right now.");
4176 /* Toggle "arg_graphics" */
4177 if (arg_graphics != GRAPHICS_ORIGINAL)
4179 arg_graphics = GRAPHICS_ORIGINAL;
4181 /* React to changes */
4182 Term_xtra_win_react();
4184 /* Hack -- Force redraw */
4185 Term_key_push(KTRL('R'));
4191 case IDM_OPTIONS_NEW_GRAPHICS:
4195 plog("You may not do that right now.");
4199 /* Toggle "arg_graphics" */
4200 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4202 arg_graphics = GRAPHICS_ADAM_BOLT;
4204 /* React to changes */
4205 Term_xtra_win_react();
4207 /* Hack -- Force redraw */
4208 Term_key_push(KTRL('R'));
4214 case IDM_OPTIONS_NEW2_GRAPHICS:
4218 plog("You may not do that right now.");
4222 /* Toggle "arg_graphics" */
4223 if (arg_graphics != GRAPHICS_HENGBAND)
4225 arg_graphics = GRAPHICS_HENGBAND;
4227 /* React to changes */
4228 Term_xtra_win_react();
4230 /* Hack -- Force redraw */
4231 Term_key_push(KTRL('R'));
4237 case IDM_OPTIONS_BIGTILE:
4242 plog("You may not do that right now.");
4246 /* Toggle "arg_sound" */
4247 arg_bigtile = !arg_bigtile;
4250 Term_activate(&td->t);
4252 /* Resize the term */
4253 Term_resize(td->cols, td->rows);
4256 InvalidateRect(td->w, NULL, TRUE);
4261 case IDM_OPTIONS_MUSIC:
4265 plog("You may not do that right now.");
4269 /* Toggle "arg_sound" */
4270 arg_music = !arg_music;
4272 /* React to changes */
4273 Term_xtra_win_react();
4275 /* Hack -- Force redraw */
4276 Term_key_push(KTRL('R'));
4281 case IDM_OPTIONS_SOUND:
4285 plog("You may not do that right now.");
4289 /* Toggle "arg_sound" */
4290 arg_sound = !arg_sound;
4292 /* React to changes */
4293 Term_xtra_win_react();
4295 /* Hack -- Force redraw */
4296 Term_key_push(KTRL('R'));
4302 case IDM_OPTIONS_BG:
4306 plog("You may not do that right now.");
4310 /* Toggle "use_bg" */
4315 /* React to changes */
4316 Term_xtra_win_react();
4318 /* Hack -- Force redraw */
4319 Term_key_push(KTRL('R'));
4325 case IDM_OPTIONS_OPEN_BG:
4329 plog("You may not do that right now.");
4334 memset(&ofn, 0, sizeof(ofn));
4335 ofn.lStructSize = sizeof(ofn);
4336 ofn.hwndOwner = data[0].w;
4337 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4338 ofn.nFilterIndex = 1;
4339 ofn.lpstrFile = bg_bitmap_file;
4340 ofn.nMaxFile = 1023;
4341 ofn.lpstrInitialDir = NULL;
4342 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
4343 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4345 if (GetOpenFileName(&ofn))
4347 /* Load 'savefile' */
4352 /* React to changes */
4353 Term_xtra_win_react();
4355 /* Hack -- Force redraw */
4356 Term_key_push(KTRL('R'));
4361 case IDM_DUMP_SCREEN_HTML:
4363 static char buf[1024] = "";
4364 memset(&ofn, 0, sizeof(ofn));
4365 ofn.lStructSize = sizeof(ofn);
4366 ofn.hwndOwner = data[0].w;
4367 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4368 ofn.nFilterIndex = 1;
4369 ofn.lpstrFile = buf;
4370 ofn.nMaxFile = 1023;
4371 ofn.lpstrDefExt = "html";
4372 ofn.lpstrInitialDir = NULL;
4373 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
4374 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4376 if (GetSaveFileName(&ofn))
4378 do_cmd_save_screen_html_aux(buf, 0);
4385 case IDM_OPTIONS_SAVER:
4389 DestroyWindow(hwndSaver);
4394 /* Create a screen scaver window */
4395 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4396 "Angband Screensaver",
4397 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4398 0, 0, GetSystemMetrics(SM_CXSCREEN),
4399 GetSystemMetrics(SM_CYSCREEN),
4400 NULL, NULL, hInstance, NULL);
4404 /* Push the window to the bottom */
4405 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4409 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
4417 case IDM_OPTIONS_MAP:
4423 case IDM_HELP_CONTENTS:
4427 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4428 if (check_file(tmp))
4430 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4434 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4435 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4438 #else /* HTML_HELP */
4441 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4442 if (check_file(tmp))
4444 sprintf(buf, "winhelp.exe %s", tmp);
4445 WinExec(buf, SW_NORMAL);
4449 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4450 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4454 #endif /* HTML_HELP */
4460 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4467 /* Extract the modifiers */
4468 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4469 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4470 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4472 Term_no_press = (ma) ? TRUE : FALSE;
4474 /* Handle "special" keys */
4475 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4477 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4478 bool numpad = FALSE;
4480 /* Begin the macro trigger */
4483 /* Send the modifiers */
4484 if (mc) Term_keypress('C');
4485 if (ms) Term_keypress('S');
4486 if (ma) Term_keypress('A');
4488 /* Extract "scan code" */
4489 i = LOBYTE(HIWORD(lParam));
4491 /* Introduce the scan code */
4494 /* Extended key bit */
4497 /* Numpad Enter and '/' are extended key */
4499 Term_no_press = TRUE;
4500 case VK_RETURN: /* Enter */
4503 /* Other extended keys are on full keyboard */
4519 Term_no_press = TRUE;
4523 case VK_PRIOR: /* Page Up */
4524 case VK_NEXT: /* Page Down */
4534 /* Special modifiers for keypad keys */
4535 if (numpad) Term_keypress('K');
4537 /* Encode the hexidecimal scan code */
4538 Term_keypress(hexsym[i/16]);
4539 Term_keypress(hexsym[i%16]);
4541 /* End the macro trigger */
4552 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4553 WPARAM wParam, LPARAM lParam);
4554 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4555 WPARAM wParam, LPARAM lParam)
4556 #else /* __MWERKS__ */
4557 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4558 #endif /* __MWERKS__ */
4564 MINMAXINFO FAR *lpmmi;
4570 /* Acquire proper "term_data" info */
4571 td = (term_data *)GetWindowLong(hWnd, 0);
4573 /* Handle message */
4578 SetWindowLong(hWnd, 0, (LONG)(my_td));
4585 mop.dwCallback=(DWORD)hWnd;
4590 case WM_GETMINMAXINFO:
4592 MINMAXINFO FAR *lpmmi;
4595 lpmmi = (MINMAXINFO FAR *)lParam;
4597 /* this message was sent before WM_NCCREATE */
4600 /* Minimum window size is 80x24 */
4601 rc.left = rc.top = 0;
4602 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4603 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4606 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4608 /* Save minimum size */
4609 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4610 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4617 BeginPaint(hWnd, &ps);
4618 if (td) term_data_redraw(td);
4619 EndPaint(hWnd, &ps);
4620 ValidateRect(hWnd, NULL);
4627 if(wParam == MCI_NOTIFY_SUCCESSFUL)
4629 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4630 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4639 if (process_keydown(wParam, lParam))
4646 if (Term_no_press) Term_no_press = FALSE;
4647 else Term_keypress(wParam);
4651 case WM_LBUTTONDOWN:
4653 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4654 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4666 TERM_LEN dx = abs(oldx - mousex) + 1;
4667 TERM_LEN dy = abs(oldy - mousey) + 1;
4668 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
4669 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
4679 hGlobal = GlobalAlloc(GHND, sz + 1);
4680 if (hGlobal == NULL) return 0;
4681 lpStr = (LPSTR)GlobalLock(hGlobal);
4683 for (i = 0; i < dy; i++)
4687 char **scr = data[0].t.scr->c;
4689 C_MAKE(s, (dx + 1), char);
4690 strncpy(s, &scr[oy + i][ox], dx);
4694 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4697 if (ox + dx < data[0].cols)
4699 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4702 for (j = 0; j < dx; j++)
4704 if (s[j] == 127) s[j] = '#';
4708 for (j = 0; j < dx; j++)
4710 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4720 GlobalUnlock(hGlobal);
4721 if (OpenClipboard(hWnd) == 0)
4723 GlobalFree(hGlobal);
4727 SetClipboardData(CF_TEXT, hGlobal);
4740 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4741 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4746 dx = abs(oldx - mousex) + 1;
4747 dy = abs(oldy - mousey) + 1;
4748 ox = (oldx > mousex) ? mousex : oldx;
4749 oy = (oldy > mousey) ? mousey : oldy;
4750 Term_inversed_area(hWnd, ox, oy, dx, dy);
4757 dx = abs(cx - mousex) + 1;
4758 dy = abs(cy - mousey) + 1;
4759 ox = (cx > mousex) ? mousex : cx;
4760 oy = (cy > mousey) ? mousey : cy;
4761 Term_inversed_area(hWnd, ox, oy, dx, dy);
4777 if (game_in_progress && character_generated)
4781 plog(_("今は終了できません。", "You may not do that right now."));
4785 /* Hack -- Forget messages */
4794 /* do_cmd_save_game(FALSE); */
4795 #else /* ZANGBAND */
4796 /* do_cmd_save_game(); */
4797 #endif /* ZANGBAND */
4798 Term_key_push(SPECIAL_KEY_QUIT);
4805 case WM_QUERYENDSESSION:
4807 if (game_in_progress && character_generated)
4809 /* Hack -- Forget messages */
4812 /* Mega-Hack -- Delay death */
4813 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4814 do_cmd_write_nikki(NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4816 /* Hardcode panic save */
4817 p_ptr->panic_save = 1;
4819 /* Forbid suspend */
4820 signals_ignore_tstp();
4822 /* Indicate panic save */
4823 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4826 (void)save_player();
4840 process_menus(LOWORD(wParam));
4846 /* this message was sent before WM_NCCREATE */
4849 /* it was sent from inside CreateWindowEx */
4850 if (!td->w) return 1;
4852 /* was sent from WM_SIZE */
4853 if (td->size_hack) return 1;
4857 case SIZE_MINIMIZED:
4859 /* Hide sub-windows */
4860 for (i = 1; i < MAX_TERM_DATA; i++)
4862 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4867 case SIZE_MAXIMIZED:
4874 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4875 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4878 if ((td->cols != cols) || (td->rows != rows))
4880 /* Save the new size */
4884 if (!IsZoomed(td->w) && !IsIconic(td->w))
4886 normsize.x = td->cols;
4887 normsize.y = td->rows;
4891 Term_activate(&td->t);
4893 /* Resize the term */
4894 Term_resize(td->cols, td->rows);
4897 InvalidateRect(td->w, NULL, TRUE);
4900 td->size_hack = TRUE;
4902 /* Show sub-windows */
4903 for (i = 1; i < MAX_TERM_DATA; i++)
4905 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4908 td->size_hack = FALSE;
4916 case WM_PALETTECHANGED:
4918 /* Ignore if palette change caused by itself */
4919 if ((HWND)wParam == hWnd) return 0;
4921 /* Fall through... */
4924 case WM_QUERYNEWPALETTE:
4926 if (!paletted) return 0;
4930 SelectPalette(hdc, hPal, FALSE);
4932 i = RealizePalette(hdc);
4934 /* if any palette entries changed, repaint the window. */
4935 if (i) InvalidateRect(hWnd, NULL, TRUE);
4937 ReleaseDC(hWnd, hdc);
4944 if (wParam && !HIWORD(lParam))
4946 /* Do something to sub-windows */
4947 for (i = 1; i < MAX_TERM_DATA; i++)
4949 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4952 /* Focus on main window */
4961 case WM_ACTIVATEAPP:
4963 if (IsIconic(td->w)) break;
4965 for (i = 1; i < MAX_TERM_DATA; i++)
4971 ShowWindow(data[i].w, SW_SHOW);
4975 ShowWindow(data[i].w, SW_HIDE);
4982 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4987 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4988 WPARAM wParam, LPARAM lParam);
4989 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4990 WPARAM wParam, LPARAM lParam)
4991 #else /* __MWERKS__ */
4992 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4993 WPARAM wParam, LPARAM lParam)
4994 #endif /* __MWERKS__ */
4998 MINMAXINFO FAR *lpmmi;
5006 /* Acquire proper "term_data" info */
5007 td = (term_data *)GetWindowLong(hWnd, 0);
5009 /* Process message */
5014 SetWindowLong(hWnd, 0, (LONG)(my_td));
5023 case WM_GETMINMAXINFO:
5025 MINMAXINFO FAR *lpmmi;
5028 lpmmi = (MINMAXINFO FAR *)lParam;
5030 /* this message was sent before WM_NCCREATE */
5033 /* Minimum window size is 80x24 */
5034 rc.left = rc.top = 0;
5035 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5036 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5039 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5041 /* Save minimum size */
5042 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5043 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5053 /* this message was sent before WM_NCCREATE */
5056 /* it was sent from inside CreateWindowEx */
5057 if (!td->w) return 1;
5059 /* was sent from inside WM_SIZE */
5060 if (td->size_hack) return 1;
5062 td->size_hack = TRUE;
5064 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5065 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5068 if ((td->cols != cols) || (td->rows != rows))
5071 term *old_term = Term;
5073 /* Save the new size */
5078 Term_activate(&td->t);
5080 /* Resize the term */
5081 Term_resize(td->cols, td->rows);
5084 Term_activate(old_term);
5087 InvalidateRect(td->w, NULL, TRUE);
5089 /* HACK - Redraw all windows */
5090 p_ptr->window = 0xFFFFFFFF;
5094 td->size_hack = FALSE;
5101 BeginPaint(hWnd, &ps);
5102 if (td) term_data_redraw(td);
5103 EndPaint(hWnd, &ps);
5110 if (process_keydown(wParam, lParam))
5117 if (Term_no_press) Term_no_press = FALSE;
5118 else Term_keypress(wParam);
5122 case WM_PALETTECHANGED:
5124 /* ignore if palette change caused by itself */
5125 if ((HWND)wParam == hWnd) return FALSE;
5126 /* otherwise, fall through!!! */
5129 case WM_QUERYNEWPALETTE:
5131 if (!paletted) return 0;
5133 SelectPalette(hdc, hPal, FALSE);
5134 i = RealizePalette(hdc);
5135 /* if any palette entries changed, repaint the window. */
5136 if (i) InvalidateRect(hWnd, NULL, TRUE);
5137 ReleaseDC(hWnd, hdc);
5141 case WM_NCLBUTTONDOWN:
5145 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5146 #endif /* HTCLOSE */
5148 if (wParam == HTSYSMENU)
5152 td->visible = FALSE;
5153 ShowWindow(td->w, SW_HIDE);
5163 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5169 #define MOUSE_SENS 40
5172 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5173 WPARAM wParam, LPARAM lParam);
5174 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5175 WPARAM wParam, LPARAM lParam)
5176 #else /* __MWERKS__ */
5177 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5178 WPARAM wParam, LPARAM lParam)
5179 #endif /* __MWERKS__ */
5181 static int iMouse = 0;
5182 static WORD xMouse = 0;
5183 static WORD yMouse = 0;
5205 if (LOWORD(wParam) == WA_INACTIVE) break;
5207 /* else fall through */
5211 case WM_LBUTTONDOWN:
5212 case WM_MBUTTONDOWN:
5213 case WM_RBUTTONDOWN:
5216 SendMessage(hWnd, WM_CLOSE, 0, 0);
5224 dx = LOWORD(lParam) - xMouse;
5225 dy = HIWORD(lParam) - yMouse;
5227 if (dx < 0) dx = -dx;
5228 if (dy < 0) dy = -dy;
5230 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5232 SendMessage(hWnd, WM_CLOSE, 0, 0);
5236 /* Save last location */
5238 xMouse = LOWORD(lParam);
5239 yMouse = HIWORD(lParam);
5246 DestroyWindow(hwndSaver);
5252 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5255 #endif /* USE_SAVER */
5261 /*** Temporary Hooks ***/
5265 * Display warning message (see "z-util.c")
5267 static void hack_plog(concptr str)
5269 /* Give a warning */
5273 MessageBox(NULL, str, "警告!",
5274 MB_ICONEXCLAMATION | MB_OK);
5276 MessageBox(NULL, str, "Warning",
5277 MB_ICONEXCLAMATION | MB_OK);
5285 * Display error message and quit (see "z-util.c")
5287 static void hack_quit(concptr str)
5289 /* Give a warning */
5293 MessageBox(NULL, str, "エラー!",
5294 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5296 MessageBox(NULL, str, "Error",
5297 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5302 /* Unregister the classes */
5303 UnregisterClass(AppName, hInstance);
5305 /* Destroy the icon */
5306 if (hIcon) DestroyIcon(hIcon);
5314 /*** Various hooks ***/
5318 * Display warning message (see "z-util.c")
5320 static void hook_plog(concptr str)
5326 MessageBox(data[0].w, str, "警告!",
5327 MB_ICONEXCLAMATION | MB_OK);
5329 MessageBox(data[0].w, str, "Warning",
5330 MB_ICONEXCLAMATION | MB_OK);
5338 * Display error message and quit (see "z-util.c")
5340 static void hook_quit(concptr str)
5345 /* Give a warning */
5349 MessageBox(data[0].w, str, "エラー!",
5350 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5352 MessageBox(data[0].w, str, "Error",
5353 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5359 /* Save the preferences */
5363 /*** Could use 'Term_nuke_win()' */
5365 /* Destroy all windows */
5366 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5368 term_force_font(&data[i], NULL);
5369 if (data[i].font_want) string_free(data[i].font_want);
5370 if (data[i].w) DestroyWindow(data[i].w);
5374 /* Free the bitmap stuff */
5376 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5377 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5379 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5380 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5382 #endif /* USE_GRAPHICS */
5384 /*** Free some other stuff ***/
5386 DeleteObject(hbrYellow);
5391 if (hPal) DeleteObject(hPal);
5393 UnregisterClass(AppName, hInstance);
5395 if (hIcon) DestroyIcon(hIcon);
5402 /*** Initialize ***/
5408 static void init_stuff(void)
5415 /* Get program name with full path */
5416 GetModuleFileName(hInstance, path, 512);
5418 /* Save the "program name" */
5421 /* Get the name of the "*.ini" file */
5422 strcpy(path + strlen(path) - 4, ".INI");
5424 /* Save the the name of the ini-file */
5425 ini_file = string_make(path);
5427 /* Analyze the path */
5433 if (path[i] == '\\')
5440 /* Add "lib" to the path */
5441 strcpy(path + i + 1, "lib\\");
5443 /* Validate the path */
5444 validate_dir(path, TRUE);
5446 /* Init the file paths */
5447 init_file_paths(path);
5449 /* Hack -- Validate the paths */
5450 validate_dir(ANGBAND_DIR_APEX, FALSE);
5451 validate_dir(ANGBAND_DIR_BONE, FALSE);
5453 /* Allow missing 'edit' directory */
5454 if (!check_dir(ANGBAND_DIR_EDIT))
5456 /* Must have 'data'! */
5457 validate_dir(ANGBAND_DIR_DATA, TRUE);
5461 /* Don't need 'data' */
5462 validate_dir(ANGBAND_DIR_DATA, FALSE);
5465 validate_dir(ANGBAND_DIR_FILE, TRUE);
5466 validate_dir(ANGBAND_DIR_HELP, FALSE);
5467 validate_dir(ANGBAND_DIR_INFO, FALSE);
5468 validate_dir(ANGBAND_DIR_PREF, TRUE);
5469 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5470 validate_dir(ANGBAND_DIR_USER, TRUE);
5471 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5473 /* Build the filename */
5474 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
5476 /* Hack -- Validate the "news.txt" file */
5477 validate_file(path);
5480 #if 0 /* #ifndef JP */
5481 /* Build the "font" path */
5482 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5484 /* Allocate the path */
5485 ANGBAND_DIR_XTRA_FONT = string_make(path);
5487 /* Validate the "font" directory */
5488 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5490 /* Build the filename */
5491 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5493 /* Hack -- Validate the basic font */
5494 validate_file(path);
5500 /* Build the "graf" path */
5501 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5503 /* Allocate the path */
5504 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5506 /* Validate the "graf" directory */
5507 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5509 #endif /* USE_GRAPHICS */
5514 /* Build the "sound" path */
5515 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5517 /* Allocate the path */
5518 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5520 /* Validate the "sound" directory */
5521 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5523 #endif /* USE_SOUND */
5527 /* Build the "music" path */
5528 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5530 /* Allocate the path */
5531 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5533 /* Validate the "music" directory */
5534 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5536 #endif /* USE_MUSIC */
5538 /* Build the "help" path */
5539 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5541 /* Allocate the path */
5542 ANGBAND_DIR_XTRA_HELP = string_make(path);
5544 /* Validate the "help" directory */
5545 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5549 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
5551 static bool is_already_running(void)
5553 bool result = FALSE;
5556 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5557 if (GetLastError() == ERROR_ALREADY_EXISTS)
5566 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
5568 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5569 LPSTR lpCmdLine, int nCmdShow)
5577 setlocale(LC_ALL, "ja_JP.utf8");
5586 /* Prevent multiple run */
5587 if (is_already_running())
5590 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
5591 _("エラー!", "Error") ,
5592 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5596 if (hPrevInst == NULL)
5598 wc.style = CS_CLASSDC;
5599 wc.lpfnWndProc = AngbandWndProc;
5601 wc.cbWndExtra = 4; /* one long pointer to term_data */
5602 wc.hInstance = hInst;
5603 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5604 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5605 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5606 wc.lpszMenuName = AppName;
5607 wc.lpszClassName = AppName;
5609 if (!RegisterClass(&wc)) exit(1);
5611 wc.lpfnWndProc = AngbandListProc;
5612 wc.lpszMenuName = NULL;
5613 wc.lpszClassName = AngList;
5615 if (!RegisterClass(&wc)) exit(2);
5619 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5620 wc.lpfnWndProc = AngbandSaverProc;
5622 wc.lpszMenuName = NULL;
5623 wc.lpszClassName = "WindowsScreenSaverClass";
5625 if (!RegisterClass(&wc)) exit(3);
5631 /* Temporary hooks */
5632 plog_aux = hack_plog;
5633 quit_aux = hack_quit;
5634 core_aux = hack_quit;
5636 /* Prepare the filepaths */
5639 /* Initialize the keypress analyzer */
5640 for (i = 0; special_key_list[i]; ++i)
5642 special_key[special_key_list[i]] = TRUE;
5644 /* Initialize the keypress analyzer */
5645 for (i = 0; ignore_key_list[i]; ++i)
5647 ignore_key[ignore_key_list[i]] = TRUE;
5650 /* Determine if display is 16/256/true color */
5652 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5653 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5654 ReleaseDC(NULL, hdc);
5656 /* Initialize the colors */
5657 for (i = 0; i < 256; i++)
5661 /* Extract desired values */
5662 rv = angband_color_table[i][1];
5663 gv = angband_color_table[i][2];
5664 bv = angband_color_table[i][3];
5666 /* Extract the "complex" code */
5667 win_clr[i] = PALETTERGB(rv, gv, bv);
5669 /* Save the "simple" code */
5670 angband_color_table[i][0] = win_pal[i];
5673 /* Prepare the windows */
5679 /* Activate hooks */
5680 plog_aux = hook_plog;
5681 quit_aux = hook_quit;
5682 core_aux = hook_quit;
5684 /* Set the system suffix */
5685 ANGBAND_SYS = "win";
5687 /* Set the keyboard suffix */
5688 if (7 != GetKeyboardType(0))
5689 ANGBAND_KEYBOARD = "0";
5692 /* Japanese keyboard */
5693 switch (GetKeyboardType(1))
5695 case 0x0D01: case 0x0D02:
5696 case 0x0D03: case 0x0D04:
5697 case 0x0D05: case 0x0D06:
5699 ANGBAND_KEYBOARD = "NEC98";
5703 ANGBAND_KEYBOARD = "JAPAN";
5707 /* Catch nasty signals */
5710 Term_activate(term_screen);
5713 /* We are now initialized */
5716 if(lpCmdLine[0] == '-'){
5717 switch(lpCmdLine[1])
5722 if (!lpCmdLine[2]) break;
5723 chuukei_server = TRUE;
5724 if(connect_chuukei_server(&lpCmdLine[2])<0){
5725 msg_print("connect fail");
5728 msg_print("connect");
5736 if (!lpCmdLine[2]) break;
5737 chuukei_client = TRUE;
5738 connect_chuukei_server(&lpCmdLine[2]);
5746 if (!lpCmdLine[2]) break;
5747 prepare_browse_movie(&lpCmdLine[2]);
5757 /* Did the user double click on a save file? */
5758 if(!chuukei_server) check_for_save_file(lpCmdLine);
5760 /* Did the user double click on a save file? */
5761 check_for_save_file(lpCmdLine);
5764 /* Prompt the user */
5765 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
5769 /* Process messages forever */
5770 while (GetMessage(&msg, NULL, 0, 0))
5772 TranslateMessage(&msg);
5773 DispatchMessage(&msg);
5780 #endif /* WINDOWS */