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).
109 * Extract the "WIN32" flag from the compiler
111 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
119 * Hack -- allow use of "screen saver" mode
125 * Menu constants -- see "ANGBAND.RC"
128 #define IDM_FILE_NEW 100
129 #define IDM_FILE_OPEN 101
130 #define IDM_FILE_SAVE 110
131 #define IDM_FILE_SCORE 120
132 #define IDM_FILE_MOVIE 121
133 #define IDM_FILE_EXIT 130
135 #define IDM_WINDOW_VIS_0 200
136 #define IDM_WINDOW_VIS_1 201
137 #define IDM_WINDOW_VIS_2 202
138 #define IDM_WINDOW_VIS_3 203
139 #define IDM_WINDOW_VIS_4 204
140 #define IDM_WINDOW_VIS_5 205
141 #define IDM_WINDOW_VIS_6 206
142 #define IDM_WINDOW_VIS_7 207
144 #define IDM_WINDOW_FONT_0 210
145 #define IDM_WINDOW_FONT_1 211
146 #define IDM_WINDOW_FONT_2 212
147 #define IDM_WINDOW_FONT_3 213
148 #define IDM_WINDOW_FONT_4 214
149 #define IDM_WINDOW_FONT_5 215
150 #define IDM_WINDOW_FONT_6 216
151 #define IDM_WINDOW_FONT_7 217
153 #define IDM_WINDOW_POS_0 220
154 #define IDM_WINDOW_POS_1 221
155 #define IDM_WINDOW_POS_2 222
156 #define IDM_WINDOW_POS_3 223
157 #define IDM_WINDOW_POS_4 224
158 #define IDM_WINDOW_POS_5 225
159 #define IDM_WINDOW_POS_6 226
160 #define IDM_WINDOW_POS_7 227
162 #define IDM_WINDOW_BIZ_0 230
163 #define IDM_WINDOW_BIZ_1 231
164 #define IDM_WINDOW_BIZ_2 232
165 #define IDM_WINDOW_BIZ_3 233
166 #define IDM_WINDOW_BIZ_4 234
167 #define IDM_WINDOW_BIZ_5 235
168 #define IDM_WINDOW_BIZ_6 236
169 #define IDM_WINDOW_BIZ_7 237
171 #define IDM_WINDOW_I_WID_0 240
172 #define IDM_WINDOW_I_WID_1 241
173 #define IDM_WINDOW_I_WID_2 242
174 #define IDM_WINDOW_I_WID_3 243
175 #define IDM_WINDOW_I_WID_4 244
176 #define IDM_WINDOW_I_WID_5 245
177 #define IDM_WINDOW_I_WID_6 246
178 #define IDM_WINDOW_I_WID_7 247
180 #define IDM_WINDOW_D_WID_0 250
181 #define IDM_WINDOW_D_WID_1 251
182 #define IDM_WINDOW_D_WID_2 252
183 #define IDM_WINDOW_D_WID_3 253
184 #define IDM_WINDOW_D_WID_4 254
185 #define IDM_WINDOW_D_WID_5 255
186 #define IDM_WINDOW_D_WID_6 256
187 #define IDM_WINDOW_D_WID_7 257
189 #define IDM_WINDOW_I_HGT_0 260
190 #define IDM_WINDOW_I_HGT_1 261
191 #define IDM_WINDOW_I_HGT_2 262
192 #define IDM_WINDOW_I_HGT_3 263
193 #define IDM_WINDOW_I_HGT_4 264
194 #define IDM_WINDOW_I_HGT_5 265
195 #define IDM_WINDOW_I_HGT_6 266
196 #define IDM_WINDOW_I_HGT_7 267
198 #define IDM_WINDOW_D_HGT_0 270
199 #define IDM_WINDOW_D_HGT_1 271
200 #define IDM_WINDOW_D_HGT_2 272
201 #define IDM_WINDOW_D_HGT_3 273
202 #define IDM_WINDOW_D_HGT_4 274
203 #define IDM_WINDOW_D_HGT_5 275
204 #define IDM_WINDOW_D_HGT_6 276
205 #define IDM_WINDOW_D_HGT_7 277
207 #define IDM_OPTIONS_NO_GRAPHICS 400
208 #define IDM_OPTIONS_OLD_GRAPHICS 401
209 #define IDM_OPTIONS_NEW_GRAPHICS 402
210 #define IDM_OPTIONS_NEW2_GRAPHICS 403
211 #define IDM_OPTIONS_BIGTILE 409
212 #define IDM_OPTIONS_SOUND 410
213 #define IDM_OPTIONS_MUSIC 411
214 #define IDM_OPTIONS_SAVER 420
215 #define IDM_OPTIONS_MAP 430
216 #define IDM_OPTIONS_BG 440
217 #define IDM_OPTIONS_OPEN_BG 441
219 #define IDM_DUMP_SCREEN_HTML 450
221 #define IDM_HELP_CONTENTS 901
224 * Exclude parts of WINDOWS.H that are not needed
226 #define NOCOMM /* Comm driver APIs and definitions */
227 #define NOLOGERROR /* LogError() and related definitions */
228 #define NOPROFILER /* Profiler APIs */
229 #define NOLFILEIO /* _l* file I/O routines */
230 #define NOOPENFILE /* OpenFile and related definitions */
231 #define NORESOURCE /* Resource management */
232 #define NOATOM /* Atom management */
233 #define NOLANGUAGE /* Character test routines */
234 #define NOLSTRING /* lstr* string management routines */
235 #define NODBCS /* Double-byte character set routines */
236 #define NOKEYBOARDINFO /* Keyboard driver routines */
237 #define NOCOLOR /* COLOR_* color values */
238 #define NODRAWTEXT /* DrawText() and related definitions */
239 #define NOSCALABLEFONT /* Truetype scalable font support */
240 #define NOMETAFILE /* Metafile support */
241 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
242 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
243 #define NOKEYSTATES /* MK_* message key state flags */
244 #define NOWH /* SetWindowsHook and related WH_* definitions */
245 #define NOCLIPBOARD /* Clipboard APIs and definitions */
246 #define NOICONS /* IDI_* icon IDs */
247 #define NOMDI /* MDI support */
248 #define NOHELP /* Help support */
250 /* Not defined since it breaks Borland C++ 5.5 */
251 /* #define NOCTLMGR */ /* Control management and controls */
254 * Exclude parts of WINDOWS.H that are not needed (Win32)
256 #define WIN32_LEAN_AND_MEAN
257 #define NONLS /* All NLS defines and routines */
258 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
259 #define NOKANJI /* Kanji support stuff. */
260 #define NOMCX /* Modem Configuration Extensions */
263 * Include the "windows" support file
268 * Exclude parts of MMSYSTEM.H that are not needed
270 #define MMNODRV /* Installable driver support */
271 #define MMNOWAVE /* Waveform support */
272 #define MMNOMIDI /* MIDI support */
273 #define MMNOAUX /* Auxiliary audio support */
274 #define MMNOTIMER /* Timer support */
275 #define MMNOJOY /* Joystick support */
276 #define MMNOMCI /* MCI support */
277 #define MMNOMMIO /* Multimedia file I/O support */
278 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
281 * Include some more files. Note: the Cygnus Cygwin compiler
282 * doesn't use mmsystem.h instead it includes the winmm library
283 * which performs a similar function.
285 #include <mmsystem.h>
289 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
290 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
292 /* #define HTML_HELP */
295 #include <htmlhelp.h>
296 #endif /* HTML_HELP */
299 * Include the support for loading bitmaps
302 # include "readdib.h"
306 * Hack -- Fake declarations from "dos.h"
309 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
311 #define FA_LABEL 0x08 /* Volume label */
312 #define FA_DIREC 0x10 /* Directory */
313 unsigned _cdecl _dos_getfileattr(concptr , unsigned *);
317 * Silliness in WIN32 drawing routine
320 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
324 * Silliness for Windows 95
326 #ifndef WS_EX_TOOLWINDOW
327 # define WS_EX_TOOLWINDOW 0
331 * Foreground color bits (hard-coded by DOS)
333 #define VID_BLACK 0x00
334 #define VID_BLUE 0x01
335 #define VID_GREEN 0x02
336 #define VID_CYAN 0x03
338 #define VID_MAGENTA 0x05
339 #define VID_YELLOW 0x06
340 #define VID_WHITE 0x07
343 * Bright text (hard-coded by DOS)
345 #define VID_BRIGHT 0x08
348 * Background color bits (hard-coded by DOS)
350 #define VUD_BLACK 0x00
351 #define VUD_BLUE 0x10
352 #define VUD_GREEN 0x20
353 #define VUD_CYAN 0x30
355 #define VUD_MAGENTA 0x50
356 #define VUD_YELLOW 0x60
357 #define VUD_WHITE 0x70
360 * Blinking text (hard-coded by DOS)
362 #define VUD_BRIGHT 0x80
368 typedef struct _term_data term_data;
372 * @brief ターム情報構造体 / Extra "term" data
375 * pos_x / pos_y は各タームの左上点座標を指す。
378 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
379 * 1ドットずつ調整するステータスを指す。
380 * また、フォントを変更すると都度自動調整される。
383 * Note the use of "font_want" for the names of the font file requested by
384 * the user, and the use of "font_file" for the currently active font file.
386 * The "font_file" is uppercased, and takes the form "8X13.FON", while
387 * "font_want" can be in almost any form as long as it could be construed
388 * as attempting to represent the name of a font.
400 TERM_LEN rows; /* int -> uint */
403 uint pos_x; //!< タームの左上X座標
404 uint pos_y; //!< タームの左上Y座標
419 int font_wid; //!< フォント横幅
420 int font_hgt; //!< フォント縦幅
421 int tile_wid; //!< タイル横幅
422 int tile_hgt; //!< タイル縦幅
428 #if 1 /* #ifdef JP */
436 #define MAX_TERM_DATA 8 //!< Maximum number of windows
438 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
439 static term_data *my_td; //!< Hack -- global "window creation" pointer
440 POINT normsize; //!< Remember normal size of main window when maxmized
443 * was main window maximized on previous playing
445 bool win_maximized = FALSE;
450 bool game_in_progress = FALSE;
453 * note when "open"/"new" become valid
455 bool initialized = FALSE;
458 * screen paletted, i.e. 256 colors
460 bool paletted = FALSE;
463 * 16 colors screen, don't use RGB()
465 bool colors16 = FALSE;
468 * Saved instance handle
470 static HINSTANCE hInstance;
473 * Yellow brush for the cursor
475 static HBRUSH hbrYellow;
485 static HPALETTE hPal;
488 static HBITMAP hBG = NULL;
489 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
490 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
495 * The screen saver window
497 static HWND hwndSaver;
499 #endif /* USE_SAVER */
505 * 現在使用中のタイルID(0ならば未使用)
506 * Flag set once "graphics" has been initialized
508 static byte_hack current_graphics_mode = 0;
513 static DIBINIT infGraph;
516 * The global bitmap mask
518 static DIBINIT infMask;
520 #endif /* USE_GRAPHICS */
526 * Flag set once "sound" has been initialized
528 static bool can_use_sound = FALSE;
532 * An array of sound file names
534 static concptr sound_file[SOUND_MAX][SAMPLE_MAX];
536 #endif /* USE_SOUND */
542 #define SAMPLE_MUSIC_MAX 16
543 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
544 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
545 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
546 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
547 static bool can_use_music = FALSE;
549 static MCI_OPEN_PARMS mop;
550 static char mci_device_type[256];
552 int current_music_type = 0;
553 int current_music_id = 0;
555 #endif /* USE_MUSIC */
559 * Full path to ANGBAND.INI
561 static concptr ini_file = NULL;
564 * Name of application
566 static concptr AppName = "ANGBAND";
569 * Name of sub-window type
571 static concptr AngList = "AngList";
576 static concptr ANGBAND_DIR_XTRA_GRAF;
577 static concptr ANGBAND_DIR_XTRA_SOUND;
578 static concptr ANGBAND_DIR_XTRA_MUSIC;
579 static concptr ANGBAND_DIR_XTRA_HELP;
580 #if 0 /* #ifndef JP */
581 static concptr ANGBAND_DIR_XTRA_FONT;
584 static concptr ANGBAND_DIR_XTRA_MUSIC;
589 * The "complex" color values
591 static COLORREF win_clr[256];
595 * Flag for macro trigger with dump ASCII
597 static bool Term_no_press = FALSE;
602 static bool mouse_down = FALSE;
603 static bool paint_rect = FALSE;
604 static TERM_LEN mousex = 0, mousey = 0;
605 static TERM_LEN oldx, oldy;
609 * @brief The "simple" color values
611 * See "main-ibm.c" for original table information
612 * The entries below are taken from the "color bits" defined above.
613 * Note that many of the choices below suck, but so do crappy monitors.
615 static BYTE win_pal[256] =
617 VID_BLACK, /* Dark */
618 VID_WHITE, /* White */
619 VID_CYAN, /* Slate XXX */
620 VID_RED | VID_BRIGHT, /* Orange XXX */
622 VID_GREEN, /* Green */
624 VID_YELLOW, /* Umber XXX */
625 VID_BLACK | VID_BRIGHT, /* Light Dark */
626 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
627 VID_MAGENTA, /* Violet XXX */
628 VID_YELLOW | VID_BRIGHT, /* Yellow */
629 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
630 VID_GREEN | VID_BRIGHT, /* Light Green */
631 VID_BLUE | VID_BRIGHT, /* Light Blue */
632 VID_YELLOW /* Light Umber XXX */
637 * Hack -- define which keys are "special"
639 static bool special_key[256];
640 static bool ignore_key[256];
644 * Hack -- initialization list for "special_key"
646 static byte special_key_list[] = {
647 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
648 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
649 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
650 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
651 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
652 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
653 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
654 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
655 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
656 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
657 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
658 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
659 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
660 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
661 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
662 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
663 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
668 static byte ignore_key_list[] = {
669 VK_ESCAPE, VK_TAB, VK_SPACE,
670 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
671 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
672 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
678 * Hack -- initialization list for "special_key"
680 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
681 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
682 * catch the keypad keys (with and without numlock set, including keypad 5),
683 * the function keys (including the "menu" key which maps to F10), and the
684 * "pause" key (between scroll lock and numlock). We also catch a few odd
685 * keys which I do not recognize, but which are listed among keys which we
686 * do catch, so they should be harmless to catch.
688 static byte special_key_list[] =
690 VK_CLEAR, /* 0x0C (KP<5>) */
692 VK_PAUSE, /* 0x13 (pause) */
694 VK_PRIOR, /* 0x21 (KP<9>) */
695 VK_NEXT, /* 0x22 (KP<3>) */
696 VK_END, /* 0x23 (KP<1>) */
697 VK_HOME, /* 0x24 (KP<7>) */
698 VK_LEFT, /* 0x25 (KP<4>) */
699 VK_UP, /* 0x26 (KP<8>) */
700 VK_RIGHT, /* 0x27 (KP<6>) */
701 VK_DOWN, /* 0x28 (KP<2>) */
702 VK_SELECT, /* 0x29 (?????) */
703 VK_PRINT, /* 0x2A (?????) */
704 VK_EXECUTE, /* 0x2B (?????) */
705 VK_SNAPSHOT, /* 0x2C (?????) */
706 VK_INSERT, /* 0x2D (KP<0>) */
707 VK_DELETE, /* 0x2E (KP<.>) */
708 VK_HELP, /* 0x2F (?????) */
710 VK_NUMPAD0, /* 0x60 (KP<0>) */
711 VK_NUMPAD1, /* 0x61 (KP<1>) */
712 VK_NUMPAD2, /* 0x62 (KP<2>) */
713 VK_NUMPAD3, /* 0x63 (KP<3>) */
714 VK_NUMPAD4, /* 0x64 (KP<4>) */
715 VK_NUMPAD5, /* 0x65 (KP<5>) */
716 VK_NUMPAD6, /* 0x66 (KP<6>) */
717 VK_NUMPAD7, /* 0x67 (KP<7>) */
718 VK_NUMPAD8, /* 0x68 (KP<8>) */
719 VK_NUMPAD9, /* 0x69 (KP<9>) */
720 VK_MULTIPLY, /* 0x6A (KP<*>) */
721 VK_ADD, /* 0x6B (KP<+>) */
722 VK_SEPARATOR, /* 0x6C (?????) */
723 VK_SUBTRACT, /* 0x6D (KP<->) */
724 VK_DECIMAL, /* 0x6E (KP<.>) */
725 VK_DIVIDE, /* 0x6F (KP</>) */
756 /* Function prototype */
758 static bool is_already_running(void);
762 static void delete_bg(void)
771 static int init_bg(void)
773 char * bmfile = bg_bitmap_file;
776 if (use_bg == 0) return 0;
778 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
780 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
788 static void DrawBG(HDC hdc, RECT *r)
793 int x = r->left, y = r->top;
794 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
800 GetObject(hBG, sizeof(bm), &bm);
801 swid = bm.bmWidth; shgt = bm.bmHeight;
803 hdcSrc = CreateCompatibleDC(hdc);
804 hOld = SelectObject(hdcSrc, hBG);
808 cwid = MIN(swid - sx, r->right - nx);
811 chgt = MIN(shgt - sy, r->bottom - ny);
812 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
814 } while (ny < r->bottom);
817 } while (nx < r->right);
819 SelectObject(hdcSrc, hOld);
825 * Hack -- given a pathname, point at the filename
827 static concptr extract_file_name(concptr s)
831 /* Start at the end */
832 p = s + strlen(s) - 1;
834 /* Back up to divider */
835 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
837 /* Return file name */
844 * Hack -- given a simple filename, extract the "font size" info
846 * Return a pointer to a static buffer holding the capitalized base name.
848 #if 0 /* #ifndef JP */
849 static char *analyze_font(char *path, int *wp, int *hp)
855 /* Start at the end */
856 p = path + strlen(path) - 1;
858 /* Back up to divider */
859 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
861 /* Advance to file name */
867 /* Capitalize (be paranoid) */
868 if (islower(*s)) *s = toupper(*s);
872 s = my_strchr(p, 'X');
874 /* Extract font width */
878 hgt = s ? atoi(s+1) : 0;
889 * Check for existance of a file
891 static bool check_file(concptr s)
911 attrib = GetFileAttributes(path);
913 /* Require valid filename */
914 if (attrib == INVALID_FILE_NAME) return (FALSE);
916 /* Prohibit directory */
917 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
921 /* Examine and verify */
922 if (_dos_getfileattr(path, &attrib)) return (FALSE);
924 /* Prohibit something */
925 if (attrib & FA_LABEL) return (FALSE);
927 /* Prohibit directory */
928 if (attrib & FA_DIREC) return (FALSE);
938 * Check for existance of a directory
940 static bool check_dir(concptr s)
962 /* Remove trailing backslash */
963 if (i && (path[i-1] == '\\')) path[--i] = '\0';
968 attrib = GetFileAttributes(path);
970 /* Require valid filename */
971 if (attrib == INVALID_FILE_NAME) return (FALSE);
973 /* Require directory */
974 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
978 /* Examine and verify */
979 if (_dos_getfileattr(path, &attrib)) return (FALSE);
981 /* Prohibit something */
982 if (attrib & FA_LABEL) return (FALSE);
984 /* Require directory */
985 if (!(attrib & FA_DIREC)) return (FALSE);
997 static void validate_file(concptr s)
1002 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
1008 * Validate a directory
1010 static void validate_dir(concptr s, bool vital)
1012 /* Verify or fail */
1015 /* This directory contains needed data */
1018 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
1020 /* Attempt to create this directory */
1023 quit_fmt("Unable to create directory:\n%s", s);
1030 * @brief (Windows版固有実装)Get the "size" for a window
1032 static void term_getsize(term_data *td)
1036 if (td->cols < 1) td->cols = 1;
1037 if (td->rows < 1) td->rows = 1;
1040 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1041 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1043 /* Fake window size */
1045 rc.right = rc.left + wid;
1047 rc.bottom = rc.top + hgt;
1049 /* rc.right += 1; */
1050 /* rc.bottom += 1; */
1053 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1056 td->size_wid = rc.right - rc.left;
1057 td->size_hgt = rc.bottom - rc.top;
1059 /* See CreateWindowEx */
1062 /* Extract actual location */
1063 GetWindowRect(td->w, &rc);
1065 /* Save the location */
1066 td->pos_x = rc.left;
1072 * Write the "prefs" for a single term
1074 static void save_prefs_aux(int i)
1076 term_data *td = &data[i];
1077 GAME_TEXT sec_name[128];
1081 WINDOWPLACEMENT lpwndpl;
1084 /* Make section name */
1085 sprintf(sec_name, "Term-%d", i);
1090 strcpy(buf, td->visible ? "1" : "0");
1091 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1096 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "MS ゴシック");
1099 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1101 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1105 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1107 #if 1 /* #ifdef JP */
1108 wsprintf(buf, "%d", td->lf.lfWidth);
1109 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1110 wsprintf(buf, "%d", td->lf.lfHeight);
1111 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1112 wsprintf(buf, "%d", td->lf.lfWeight);
1113 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1116 strcpy(buf, td->bizarre ? "1" : "0");
1117 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1120 wsprintf(buf, "%d", td->tile_wid);
1121 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1124 wsprintf(buf, "%d", td->tile_hgt);
1125 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1127 /* Get window placement and dimensions */
1128 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1129 GetWindowPlacement(td->w, &lpwndpl);
1131 /* Acquire position in *normal* mode (not minimized) */
1132 rc = lpwndpl.rcNormalPosition;
1134 /* Window size (x) */
1135 if (i == 0) wsprintf(buf, "%d", normsize.x);
1136 else wsprintf(buf, "%d", td->cols);
1137 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1139 /* Window size (y) */
1140 if (i == 0) wsprintf(buf, "%d", normsize.y);
1141 else wsprintf(buf, "%d", td->rows);
1142 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1144 /* Maxmized (only main window) */
1147 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1148 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1151 /* Acquire position */
1152 GetWindowRect(td->w, &rc);
1154 /* Window position (x) */
1155 wsprintf(buf, "%d", rc.left);
1156 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1158 /* Window position (y) */
1159 wsprintf(buf, "%d", rc.top);
1160 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1162 /* Window Z position */
1165 strcpy(buf, td->posfix ? "1" : "0");
1166 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1173 * We assume that the windows have all been initialized
1175 static void save_prefs(void)
1181 /* Save the "arg_graphics" flag */
1182 sprintf(buf, "%d", arg_graphics);
1183 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1185 /* Save the "arg_bigtile" flag */
1186 strcpy(buf, arg_bigtile ? "1" : "0");
1187 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1189 /* Save the "arg_sound" flag */
1190 strcpy(buf, arg_sound ? "1" : "0");
1191 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1193 /* Save the "arg_sound" flag */
1194 strcpy(buf, arg_music ? "1" : "0");
1195 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1198 strcpy(buf, use_bg ? "1" : "0");
1199 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1200 WritePrivateProfileString("Angband", "BackGroundBitmap",
1201 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1203 /* Save window prefs */
1204 for (i = 0; i < MAX_TERM_DATA; ++i)
1212 * Load the "prefs" for a single term
1214 static void load_prefs_aux(int i)
1216 term_data *td = &data[i];
1217 GAME_TEXT sec_name[128];
1220 int wid, hgt, posx, posy;
1221 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1222 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1226 /* Make section name */
1227 sprintf(sec_name, "Term-%d", i);
1229 /* Make section name */
1230 sprintf(sec_name, "Term-%d", i);
1235 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1238 /* Desired font, with default */
1240 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1243 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1245 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1251 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1253 /* Analyze font, save desired font name */
1254 #if 1 /* #ifdef JP */
1255 td->font_want = string_make(tmp);
1257 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1258 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1259 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1261 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1266 #if 1 /* #ifdef JP */
1267 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1268 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1270 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1271 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1276 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1277 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1278 normsize.x = td->cols; normsize.y = td->rows;
1283 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
1286 /* Window position */
1287 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1288 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1289 td->pos_x = MIN(MAX(0, posx), dispx-128);
1290 td->pos_y = MIN(MAX(0, posy), dispy-128);
1292 /* Window Z position */
1295 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
1303 static void load_prefs(void)
1307 /* Extract the "arg_graphics" flag */
1308 arg_graphics = (byte_hack)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1310 /* Extract the "arg_bigtile" flag */
1311 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
1312 use_bigtile = arg_bigtile;
1314 /* Extract the "arg_sound" flag */
1315 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1317 /* Extract the "arg_sound" flag */
1318 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1321 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1322 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1324 /* Load window prefs */
1325 for (i = 0; i < MAX_TERM_DATA; ++i)
1331 #if defined(USE_SOUND) || defined(USE_MUSIC)
1334 * - Taken from files.c.
1336 * Extract "tokens" from a buffer
1338 * This function uses "whitespace" as delimiters, and treats any amount of
1339 * whitespace as a single delimiter. We will never return any empty tokens.
1340 * When given an empty buffer, or a buffer containing only "whitespace", we
1341 * will return no tokens. We will never extract more than "num" tokens.
1343 * By running a token through the "text_to_ascii()" function, you can allow
1344 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1346 * We save pointers to the tokens in "tokens", and return the number found.
1348 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1358 /* Skip leading whitespace */
1359 for ( ; *s && iswspace(*s); ++s) /* loop */;
1364 /* Find next whitespace, if any */
1365 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1367 /* Nuke and advance (if necessary) */
1368 if (*t) *t++ = '\0';
1370 /* Save the token */
1381 #endif /* USE_SOUND || USE_MUSIC */
1385 static void load_sound_prefs(void)
1389 char ini_path[1024];
1390 char wav_path[1024];
1391 char *zz[SAMPLE_MAX];
1393 /* Access the sound.cfg */
1395 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1397 for (i = 0; i < SOUND_MAX; i++)
1399 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1401 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1403 for (j = 0; j < num; j++)
1405 /* Access the sound */
1406 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1408 /* Save the sound filename, if it exists */
1409 if (check_file(wav_path))
1410 sound_file[i][j] = string_make(zz[j]);
1415 #endif /* USE_SOUND */
1419 static void load_music_prefs(void)
1423 char ini_path[1024];
1424 char wav_path[1024];
1425 char *zz[SAMPLE_MAX];
1428 /* Access the music.cfg */
1430 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1432 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1434 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1436 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1438 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1440 for (j = 0; j < num; j++)
1442 /* Access the sound */
1443 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1445 /* Save the sound filename, if it exists */
1446 if (check_file(wav_path))
1447 music_file[i][j] = string_make(zz[j]);
1451 for (i = 0; i < max_d_idx; i++)
1453 sprintf(key, "dungeon%03d", i);
1454 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1456 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1458 for (j = 0; j < num; j++)
1460 /* Access the sound */
1461 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1463 /* Save the sound filename, if it exists */
1464 if (check_file(wav_path))
1465 dungeon_music_file[i][j] = string_make(zz[j]);
1469 for (i = 0; i < max_q_idx; i++)
1471 sprintf(key, "quest%03d", i);
1472 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1474 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1476 for (j = 0; j < num; j++)
1478 /* Access the sound */
1479 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1481 /* Save the sound filename, if it exists */
1482 if (check_file(wav_path))
1483 quest_music_file[i][j] = string_make(zz[j]);
1487 for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1489 sprintf(key, "town%03d", i);
1490 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1492 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1494 for (j = 0; j < num; j++)
1496 /* Access the sound */
1497 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1499 /* Save the sound filename, if it exists */
1500 if (check_file(wav_path))
1501 town_music_file[i][j] = string_make(zz[j]);
1508 #endif /* USE_MUSIC */
1511 * Create the new global palette based on the bitmap palette
1512 * (if any), and the standard 16 entry palette derived from
1513 * "win_clr[]" which is used for the basic 16 Angband colors.
1515 * This function is never called before all windows are ready.
1517 * This function returns FALSE if the new palette could not be
1518 * prepared, which should normally be a fatal error. XXX XXX
1520 * Note that only some machines actually use a "palette".
1522 static int new_palette(void)
1530 LPLOGPALETTE pLogPal;
1531 LPPALETTEENTRY lppe;
1536 /* This makes no sense */
1537 if (!paletted) return (TRUE);
1547 /* Check the bitmap palette */
1548 hBmPal = infGraph.hPalette;
1550 /* Use the bitmap */
1553 lppeSize = 256 * sizeof(PALETTEENTRY);
1554 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1555 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1556 if ((nEntries == 0) || (nEntries > 220))
1559 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1562 rnfree(lppe, lppeSize);
1569 #endif /* USE_GRAPHICS */
1571 /* Size of palette */
1572 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1574 /* Allocate palette */
1575 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1578 pLogPal->palVersion = 0x300;
1580 /* Make room for bitmap and normal data */
1581 pLogPal->palNumEntries = nEntries + 16;
1583 /* Save the bitmap data */
1584 for (i = 0; i < nEntries; i++)
1586 pLogPal->palPalEntry[i] = lppe[i];
1589 /* Save the normal data */
1590 for (i = 0; i < 16; i++)
1594 /* Access the entry */
1595 p = &(pLogPal->palPalEntry[i+nEntries]);
1597 /* Save the colors */
1598 p->peRed = GetRValue(win_clr[i]);
1599 p->peGreen = GetGValue(win_clr[i]);
1600 p->peBlue = GetBValue(win_clr[i]);
1602 /* Save the flags */
1603 p->peFlags = PC_NOCOLLAPSE;
1606 /* Free something */
1607 if (lppe) rnfree(lppe, lppeSize);
1609 /* Create a new palette, or fail */
1610 hNewPal = CreatePalette(pLogPal);
1611 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1613 /* Free the palette */
1614 rnfree(pLogPal, pLogPalSize);
1619 /* Realize the palette */
1621 SelectPalette(hdc, hNewPal, 0);
1622 i = RealizePalette(hdc);
1623 ReleaseDC(td->w, hdc);
1624 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1628 for (i = 1; i < MAX_TERM_DATA; i++)
1633 SelectPalette(hdc, hNewPal, 0);
1634 ReleaseDC(td->w, hdc);
1637 /* Delete old palette */
1638 if (hPal) DeleteObject(hPal);
1640 /* Save new palette */
1650 * @brief グラフィクスを初期化する / Initialize graphics
1653 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1654 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1657 static bool init_graphics(void)
1659 /* Initialize once */
1661 BYTE wid, hgt, twid, thgt, ox, oy;
1664 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1674 ANGBAND_GRAF = "new";
1676 else if (arg_graphics == GRAPHICS_HENGBAND)
1696 ANGBAND_GRAF = "ne2";
1707 ANGBAND_GRAF = "old";
1710 /* Access the bitmap file */
1711 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1713 /* Load the bitmap or quit */
1714 if (!ReadDIB(data[0].w, buf, &infGraph))
1716 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1720 /* Save the new sizes */
1721 infGraph.CellWidth = wid;
1722 infGraph.CellHeight = hgt;
1723 infGraph.TileWidth = twid;
1724 infGraph.TileHeight = thgt;
1725 infGraph.OffsetX = ox;
1726 infGraph.OffsetY = oy;
1728 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1730 /* Access the mask file */
1731 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1733 /* Load the bitmap or quit */
1734 if (!ReadDIB(data[0].w, buf, &infMask))
1736 plog_fmt("Cannot read bitmap file '%s'", buf);
1740 if (arg_graphics == GRAPHICS_HENGBAND)
1742 /* Access the mask file */
1743 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1745 /* Load the bitmap or quit */
1746 if (!ReadDIB(data[0].w, buf, &infMask))
1748 plog_fmt("Cannot read bitmap file '%s'", buf);
1753 /* Activate a palette */
1758 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1762 /* Graphics available */
1763 current_graphics_mode = arg_graphics;
1764 return (current_graphics_mode);
1766 #endif /* USE_GRAPHICS */
1773 static bool init_music(void)
1775 /* Initialize once */
1778 /* Load the prefs */
1781 /* Sound available */
1782 can_use_music = TRUE;
1784 return (can_use_music);
1788 * Hack -- Stop a music
1790 static void stop_music(void)
1792 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1793 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1796 #endif /* USE_MUSIC */
1802 static bool init_sound(void)
1804 /* Initialize once */
1807 /* Load the prefs */
1810 /* Sound available */
1811 can_use_sound = TRUE;
1813 return (can_use_sound);
1815 #endif /* USE_SOUND */
1821 static void term_window_resize(term_data *td)
1823 /* Require window */
1826 /* Resize the window */
1827 SetWindowPos(td->w, 0, 0, 0,
1828 td->size_wid, td->size_hgt,
1829 SWP_NOMOVE | SWP_NOZORDER);
1832 InvalidateRect(td->w, NULL, TRUE);
1837 * Force the use of a new "font file" for a term_data
1839 * This function may be called before the "window" is ready
1841 * This function returns zero only if everything succeeds.
1843 * Note that the "font name" must be capitalized!!!
1845 static errr term_force_font(term_data *td, concptr path)
1849 #if 0 /* #ifndef JP */
1855 /* Forget the old font (if needed) */
1856 if (td->font_id) DeleteObject(td->font_id);
1858 #if 1 /* #ifdef JP */
1862 /* Create the font (using the 'base' of the font file name!) */
1863 td->font_id = CreateFontIndirect(&(td->lf));
1864 wid = td->lf.lfWidth;
1865 hgt = td->lf.lfHeight;
1866 if (!td->font_id) return (1);
1868 /* Forget old font */
1874 for (i = 0; i < MAX_TERM_DATA; i++)
1876 /* Don't check when closing the application */
1879 /* Check "screen" */
1880 if ((td != &data[i]) &&
1881 (data[i].font_file) &&
1882 (streq(data[i].font_file, td->font_file)))
1888 /* Remove unused font resources */
1889 if (!used) RemoveFontResource(td->font_file);
1891 /* Free the old name */
1892 string_free(td->font_file);
1895 td->font_file = NULL;
1899 if (!path) return (1);
1904 /* Analyze font path */
1905 base = analyze_font(buf, &wid, &hgt);
1908 if (!suffix(base, ".FON")) return (1);
1911 if (!check_file(buf)) return (1);
1913 /* Load the new font */
1914 if (!AddFontResource(buf)) return (1);
1916 /* Save new font name */
1917 td->font_file = string_make(base);
1919 /* Remove the "suffix" */
1920 base[strlen(base)-4] = '\0';
1922 /* Create the font (using the 'base' of the font file name!) */
1923 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1924 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1925 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1926 FIXED_PITCH | FF_DONTCARE, base);
1929 /* Hack -- Unknown size */
1936 /* all this trouble to get the cell size */
1937 hdcDesktop = GetDC(HWND_DESKTOP);
1938 hfOld = SelectObject(hdcDesktop, td->font_id);
1939 GetTextMetrics(hdcDesktop, &tm);
1940 SelectObject(hdcDesktop, hfOld);
1941 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1943 /* Font size info */
1944 wid = tm.tmAveCharWidth;
1948 /* Save the size info */
1959 * Allow the user to change the font for this window.
1961 static void term_change_font(term_data *td)
1963 #if 1 /* #ifdef JP */
1966 memset(&cf, 0, sizeof(cf));
1967 cf.lStructSize = sizeof(cf);
1968 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1969 cf.lpLogFont = &(td->lf);
1971 if (ChooseFont(&cf))
1973 /* Force the font */
1974 term_force_font(td, NULL);
1976 /* Assume not bizarre */
1979 /* Reset the tile info */
1980 td->tile_wid = td->font_wid;
1981 td->tile_hgt = td->font_hgt;
1983 /* Analyze the font */
1986 /* Resize the window */
1987 term_window_resize(td);
1993 char tmp[1024] = "";
1995 /* Extract a default if possible */
1996 if (td->font_file) strcpy(tmp, td->font_file);
1998 /* Ask for a choice */
1999 memset(&ofn, 0, sizeof(ofn));
2000 ofn.lStructSize = sizeof(ofn);
2001 ofn.hwndOwner = data[0].w;
2002 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
2003 ofn.nFilterIndex = 1;
2004 ofn.lpstrFile = tmp;
2006 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
2007 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2008 ofn.lpstrDefExt = "fon";
2010 /* Force choice if legal */
2011 if (GetOpenFileName(&ofn))
2013 /* Force the font */
2014 if (term_force_font(td, tmp))
2016 /* Access the standard font file */
2017 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2019 /* Force the use of that font */
2020 (void)term_force_font(td, tmp);
2023 /* Assume not bizarre */
2024 td->bizarre = FALSE;
2026 /* Reset the tile info */
2027 td->tile_wid = td->font_wid;
2028 td->tile_hgt = td->font_hgt;
2030 /* Analyze the font */
2033 /* Resize the window */
2034 term_window_resize(td);
2041 * Allow the user to lock this window.
2043 static void term_window_pos(term_data *td, HWND hWnd)
2045 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2046 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2049 static void windows_map(void);
2052 * Hack -- redraw a term_data
2054 static void term_data_redraw(term_data *td)
2058 /* Redraw the map */
2063 /* Activate the term */
2064 Term_activate(&td->t);
2066 /* Redraw the contents */
2069 /* Restore the term */
2070 Term_activate(term_screen);
2075 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2079 HBRUSH myBrush, oldBrush;
2081 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2082 int tx = td->size_ow1 + x * td->tile_wid;
2083 int ty = td->size_oh1 + y * td->tile_hgt;
2084 int tw = w * td->tile_wid - 1;
2085 int th = h * td->tile_hgt - 1;
2088 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2089 oldBrush = SelectObject(hdc, myBrush);
2090 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2092 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2094 SelectObject(hdc, oldBrush);
2095 SelectObject(hdc, oldPen);
2100 /*** Function hooks needed by "Term" ***/
2106 * Initialize a new Term
2108 static void Term_init_win(term *t)
2117 static void Term_nuke_win(term *t)
2126 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
2128 static errr Term_user_win(int n)
2139 * React to global changes
2141 static errr Term_xtra_win_react(void)
2148 /* Save the default colors */
2149 for (i = 0; i < 256; i++)
2151 /* Simply accept the desired colors */
2152 win_pal[i] = angband_color_table[i][0];
2163 bool change = FALSE;
2165 /* Save the default colors */
2166 for (i = 0; i < 256; i++)
2168 /* Extract desired values */
2169 rv = angband_color_table[i][1];
2170 gv = angband_color_table[i][2];
2171 bv = angband_color_table[i][3];
2173 /* Extract a full color code */
2174 code = PALETTERGB(rv, gv, bv);
2176 /* Activate changes */
2177 if (win_clr[i] != code)
2179 /* Note the change */
2182 /* Apply the desired color */
2187 /* Activate the palette if needed */
2188 if (change) (void)new_palette();
2194 /* Handle "arg_sound" */
2195 if (use_sound != arg_sound)
2197 /* Initialize (if needed) */
2198 if (arg_sound && !init_sound())
2201 plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
2207 /* Change setting */
2208 use_sound = arg_sound;
2215 /* Handle "arg_sound" */
2216 if (use_music != arg_music)
2218 /* Initialize (if needed) */
2219 if (arg_music && !init_music())
2222 plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
2227 /* Change setting */
2228 use_music = arg_music;
2230 if(!arg_music) stop_music();
2231 else select_floor_music();
2240 /* Handle "arg_graphics" */
2241 if (use_graphics != arg_graphics)
2243 /* Initialize (if needed) */
2244 if (arg_graphics && !init_graphics())
2247 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
2250 arg_graphics = GRAPHICS_NONE;
2253 /* Change setting */
2254 use_graphics = arg_graphics;
2257 #ifdef ANGBAND_2_8_1
2259 #else /* ANGBAND_2_8_1 */
2260 reset_visuals(TRUE);
2261 #endif /* ANGBAND_2_8_1 */
2264 #endif /* USE_GRAPHICS */
2267 /* Clean up windows */
2268 for (i = 0; i < MAX_TERM_DATA; i++)
2272 term_data *td = &data[i];
2274 /* Update resized windows */
2275 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
2278 Term_activate(&td->t);
2280 /* Hack -- Resize the term */
2281 Term_resize(td->cols, td->rows);
2283 /* Redraw the contents */
2296 * Process at least one event
2298 static errr Term_xtra_win_event(int v)
2302 /* Wait for an event */
2306 if (GetMessage(&msg, NULL, 0, 0))
2308 TranslateMessage(&msg);
2309 DispatchMessage(&msg);
2313 /* Check for an event */
2317 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2319 TranslateMessage(&msg);
2320 DispatchMessage(&msg);
2330 * Process all pending events
2332 static errr Term_xtra_win_flush(void)
2336 /* Process all pending events */
2337 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2339 TranslateMessage(&msg);
2340 DispatchMessage(&msg);
2349 * Hack -- clear the screen
2351 * Make this more efficient
2353 static errr Term_xtra_win_clear(void)
2355 term_data *td = (term_data*)(Term->data);
2360 /* Rectangle to erase */
2361 rc.left = td->size_ow1;
2362 rc.right = rc.left + td->cols * td->tile_wid;
2363 rc.top = td->size_oh1;
2364 rc.bottom = rc.top + td->rows * td->tile_hgt;
2368 SetBkColor(hdc, RGB(0, 0, 0));
2369 SelectObject(hdc, td->font_id);
2370 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2375 rc.left = 0; rc.top = 0;
2378 ReleaseDC(td->w, hdc);
2386 * Hack -- make a noise
2388 static errr Term_xtra_win_noise(void)
2390 MessageBeep(MB_ICONASTERISK);
2396 * Hack -- make a sound
2398 static errr Term_xtra_win_sound(int v)
2403 #endif /* USE_SOUND */
2405 /* Sound disabled */
2406 if (!use_sound) return (1);
2409 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2413 /* Count the samples */
2414 for (i = 0; i < SAMPLE_MAX; i++)
2416 if (!sound_file[v][i])
2421 if (i == 0) return (1);
2423 /* Build the path */
2424 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2428 /* Play the sound, catch errors */
2429 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2433 /* Play the sound, catch errors */
2434 return (sndPlaySound(buf, SND_ASYNC));
2438 #else /* USE_SOUND */
2442 #endif /* USE_SOUND */
2446 * Hack -- play a music
2448 static errr Term_xtra_win_music(int n, int v)
2453 #endif /* USE_MUSIC */
2455 /* Sound disabled */
2457 if(!use_music) return (1);
2460 if(n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return (1);
2461 else if(v < 0 || v >= 1000) return(1); /*!< TODO */
2467 case TERM_XTRA_MUSIC_BASIC:
2468 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2470 case TERM_XTRA_MUSIC_DUNGEON:
2471 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2473 case TERM_XTRA_MUSIC_QUEST:
2474 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2476 case TERM_XTRA_MUSIC_TOWN:
2477 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2484 //mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2485 //mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2491 case TERM_XTRA_MUSIC_BASIC:
2492 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2494 case TERM_XTRA_MUSIC_DUNGEON:
2495 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2497 case TERM_XTRA_MUSIC_QUEST:
2498 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2500 case TERM_XTRA_MUSIC_TOWN:
2501 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2508 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2509 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2515 case TERM_XTRA_MUSIC_BASIC:
2516 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2518 case TERM_XTRA_MUSIC_DUNGEON:
2519 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2521 case TERM_XTRA_MUSIC_QUEST:
2522 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2524 case TERM_XTRA_MUSIC_TOWN:
2525 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2529 if(current_music_type == n && current_music_id == v)
2533 current_music_type = n;
2534 current_music_id = v;
2538 mop.lpstrDeviceType = mci_device_type;
2539 mop.lpstrElementName = buf;
2540 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2541 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2542 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2543 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2544 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2549 #else /* USE_MUSIC */
2553 #endif /* USE_MUSIC */
2559 * Delay for "x" milliseconds
2561 static int Term_xtra_win_delay(int v)
2575 t = GetTickCount() + v;
2578 while (GetTickCount() < t)
2580 /* Handle messages */
2581 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2583 TranslateMessage(&msg);
2584 DispatchMessage(&msg);
2596 * Do a "special thing"
2598 static errr Term_xtra_win(int n, int v)
2600 /* Handle a subset of the legal requests */
2603 /* Make a bell sound */
2604 case TERM_XTRA_NOISE:
2606 return (Term_xtra_win_noise());
2610 case TERM_XTRA_MUSIC_BASIC:
2611 case TERM_XTRA_MUSIC_DUNGEON:
2612 case TERM_XTRA_MUSIC_QUEST:
2613 case TERM_XTRA_MUSIC_TOWN:
2615 return (Term_xtra_win_music(n, v));
2618 /* Make a special sound */
2619 case TERM_XTRA_SOUND:
2621 return (Term_xtra_win_sound(v));
2624 /* Process random events */
2625 case TERM_XTRA_BORED:
2627 return (Term_xtra_win_event(0));
2630 /* Process an event */
2631 case TERM_XTRA_EVENT:
2633 return (Term_xtra_win_event(v));
2636 /* Flush all events */
2637 case TERM_XTRA_FLUSH:
2639 return (Term_xtra_win_flush());
2642 /* Clear the screen */
2643 case TERM_XTRA_CLEAR:
2645 return (Term_xtra_win_clear());
2648 /* React to global changes */
2649 case TERM_XTRA_REACT:
2651 return (Term_xtra_win_react());
2654 /* Delay for some milliseconds */
2655 case TERM_XTRA_DELAY:
2657 return (Term_xtra_win_delay(v));
2667 * Low level graphics (Assumes valid input).
2669 * Draw a "cursor" at (x,y), using a "yellow box".
2671 static errr Term_curs_win(int x, int y)
2673 term_data *td = (term_data*)(Term->data);
2678 int tile_wid, tile_hgt;
2682 tile_wid = td->map_tile_wid;
2683 tile_hgt = td->map_tile_hgt;
2687 tile_wid = td->tile_wid;
2688 tile_hgt = td->tile_hgt;
2691 /* Frame the grid */
2692 rc.left = x * tile_wid + td->size_ow1;
2693 rc.right = rc.left + tile_wid;
2694 rc.top = y * tile_hgt + td->size_oh1;
2695 rc.bottom = rc.top + tile_hgt;
2697 /* Cursor is done as a yellow "box" */
2699 FrameRect(hdc, &rc, hbrYellow);
2700 ReleaseDC(td->w, hdc);
2708 * Low level graphics (Assumes valid input).
2710 * Draw a "big cursor" at (x,y), using a "yellow box".
2712 static errr Term_bigcurs_win(int x, int y)
2714 term_data *td = (term_data*)(Term->data);
2719 int tile_wid, tile_hgt;
2723 /* Normal cursor in map window */
2724 Term_curs_win(x, y);
2729 tile_wid = td->tile_wid;
2730 tile_hgt = td->tile_hgt;
2733 /* Frame the grid */
2734 rc.left = x * tile_wid + td->size_ow1;
2735 rc.right = rc.left + 2 * tile_wid;
2736 rc.top = y * tile_hgt + td->size_oh1;
2737 rc.bottom = rc.top + tile_hgt;
2739 /* Cursor is done as a yellow "box" */
2741 FrameRect(hdc, &rc, hbrYellow);
2742 ReleaseDC(td->w, hdc);
2750 * Low level graphics (Assumes valid input).
2752 * Erase a "block" of "n" characters starting at (x,y).
2754 static errr Term_wipe_win(int x, int y, int n)
2756 term_data *td = (term_data*)(Term->data);
2761 /* Rectangle to erase in client coords */
2762 rc.left = x * td->tile_wid + td->size_ow1;
2763 rc.right = rc.left + n * td->tile_wid;
2764 rc.top = y * td->tile_hgt + td->size_oh1;
2765 rc.bottom = rc.top + td->tile_hgt;
2768 SetBkColor(hdc, RGB(0, 0, 0));
2769 SelectObject(hdc, td->font_id);
2774 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2775 ReleaseDC(td->w, hdc);
2783 * Low level graphics. Assumes valid input.
2785 * Draw several ("n") chars, with an attr, at a given location.
2787 * All "graphic" data is handled by "Term_pict_win()", below.
2789 * One would think there is a more efficient method for telling a window
2790 * what color it should be using to draw with, but perhaps simply changing
2791 * it every time is not too inefficient.
2793 static errr Term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
2795 term_data *td = (term_data*)(Term->data);
2799 #if 1 /* #ifdef JP */
2800 static HBITMAP WALL;
2801 static HBRUSH myBrush, oldBrush;
2803 static bool init_done = FALSE;
2806 WALL = LoadBitmap(hInstance, AppName);
2807 myBrush = CreatePatternBrush(WALL);
2812 /* Total rectangle */
2813 rc.left = x * td->tile_wid + td->size_ow1;
2814 rc.right = rc.left + n * td->tile_wid;
2815 rc.top = y * td->tile_hgt + td->size_oh1;
2816 rc.bottom = rc.top + td->tile_hgt;
2821 /* Background color */
2822 SetBkColor(hdc, RGB(0, 0, 0));
2824 /* Foreground color */
2827 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2831 SetTextColor(hdc, win_clr[a&0x0F]);
2835 SetTextColor(hdc, win_clr[a]);
2839 SelectObject(hdc, td->font_id);
2842 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2846 (td->tile_hgt != td->font_hgt) ||
2847 (td->tile_wid != td->font_wid))
2851 /* Erase complete rectangle */
2852 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2855 if (use_bg) DrawBG(hdc, &rc);
2858 rc.left += ((td->tile_wid - td->font_wid) / 2);
2859 rc.right = rc.left + td->font_wid;
2860 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2861 rc.bottom = rc.top + td->font_hgt;
2863 /* Dump each character */
2864 for (i = 0; i < n; i++)
2867 if (use_bigtile && *(s+i)=="■"[0] && *(s+i+1)=="■"[1])
2869 rc.right += td->font_wid;
2871 oldBrush = SelectObject(hdc, myBrush);
2872 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2875 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2877 SelectObject(hdc, oldBrush);
2878 SelectObject(hdc, oldPen);
2879 rc.right -= td->font_wid;
2883 rc.left += 2 * td->tile_wid;
2884 rc.right += 2 * td->tile_wid;
2886 else if ( iskanji(*(s+i)) ) /* 2バイト文字 */
2888 rc.right += td->font_wid;
2890 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2892 rc.right -= td->font_wid;
2896 rc.left += 2 * td->tile_wid;
2897 rc.right += 2 * td->tile_wid;
2898 } else if (*(s+i)==127){
2899 oldBrush = SelectObject(hdc, myBrush);
2900 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2903 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2905 SelectObject(hdc, oldBrush);
2906 SelectObject(hdc, oldPen);
2909 rc.left += td->tile_wid;
2910 rc.right += td->tile_wid;
2913 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2916 rc.left += td->tile_wid;
2917 rc.right += td->tile_wid;
2922 oldBrush = SelectObject(hdc, myBrush);
2923 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2926 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2928 SelectObject(hdc, oldBrush);
2929 SelectObject(hdc, oldPen);
2932 rc.left += td->tile_wid;
2933 rc.right += td->tile_wid;
2936 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2940 rc.left += td->tile_wid;
2941 rc.right += td->tile_wid;
2945 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2949 rc.left += td->tile_wid;
2950 rc.right += td->tile_wid;
2961 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2966 ReleaseDC(td->w, hdc);
2974 * Low level graphics. Assumes valid input.
2976 * Draw an array of "special" attr/char pairs at the given location.
2978 * We use the "Term_pict_win()" function for "graphic" data, which are
2979 * encoded by setting the "high-bits" of both the "attr" and the "char"
2980 * data. We use the "attr" to represent the "row" of the main bitmap,
2981 * and the "char" to represent the "col" of the main bitmap. The use
2982 * of this function is induced by the "higher_pict" flag.
2984 * If "graphics" is not available, we simply "wipe" the given grids.
2986 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)
2988 term_data *td = (term_data*)(Term->data);
2993 TERM_LEN x1, y1, w1, h1, tw1, th1;
2994 TERM_LEN x2, y2, w2, h2, tw2 = 0;
3004 /* Erase the grids */
3005 return (Term_wipe_win(x, y, n));
3008 /* Size of bitmap cell */
3009 w1 = infGraph.CellWidth;
3010 h1 = infGraph.CellHeight;
3011 tw1 = infGraph.TileWidth;
3012 th1 = infGraph.TileHeight;
3014 /* Size of window cell */
3017 w2 = td->map_tile_wid;
3018 h2 = td->map_tile_hgt;
3027 if (use_bigtile) tw2 *= 2;
3030 /* Location of window cell */
3031 x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
3032 y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
3038 hdcSrc = CreateCompatibleDC(hdc);
3039 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
3041 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3043 hdcMask = CreateCompatibleDC(hdc);
3044 SelectObject(hdcMask, infMask.hBitmap);
3047 /* Draw attr/char pairs */
3048 for (i = 0; i < n; i++, x2 += w2)
3050 TERM_COLOR a = ap[i];
3054 /* Extract picture */
3055 int row = (a & 0x7F);
3056 int col = (c & 0x7F);
3058 /* Location of bitmap cell */
3062 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3064 x3 = (tcp[i] & 0x7F) * w1;
3065 y3 = (tap[i] & 0x7F) * h1;
3066 tw2 = tw2 * w1 / tw1;
3070 if ((tw1 == tw2) && (th1 == h2))
3072 /* Copy the terrain picture from the bitmap to the window */
3073 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
3075 /* Mask out the tile */
3076 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3079 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3082 /* Need to stretch */
3085 /* Set the correct mode for stretching the tiles */
3086 SetStretchBltMode(hdc, COLORONCOLOR);
3088 /* Copy the terrain picture from the bitmap to the window */
3089 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
3091 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
3093 /* Only draw if terrain and overlay are different */
3094 if ((x1 != x3) || (y1 != y3))
3096 /* Mask out the tile */
3097 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3100 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3107 if ((w1 == tw2) && (h1 == h2))
3109 /* Copy the picture from the bitmap to the window */
3110 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3113 /* Need to stretch */
3116 /* Set the correct mode for stretching the tiles */
3117 SetStretchBltMode(hdc, COLORONCOLOR);
3119 /* Copy the picture from the bitmap to the window */
3120 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3126 SelectObject(hdcSrc, hbmSrcOld);
3129 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3132 SelectObject(hdcMask, hbmSrcOld);
3137 ReleaseDC(td->w, hdc);
3139 #else /* USE_GRAPHICS */
3141 /* Just erase this grid */
3142 return (Term_wipe_win(x, y, n));
3144 #endif /* USE_GRAPHICS */
3151 static void windows_map(void)
3153 term_data *td = &data[0];
3156 TERM_LEN x, min_x, max_x;
3157 TERM_LEN y, min_y, max_y;
3162 /* Only in graphics mode */
3163 if (!use_graphics) return;
3164 Term_xtra_win_clear();
3166 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3167 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3168 td->map_active = TRUE;
3173 max_x = current_floor_ptr->width;
3174 max_y = current_floor_ptr->height;
3178 for (x = min_x; x < max_x; x++)
3180 for (y = min_y; y < max_y; y++)
3182 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3184 /* Ignore non-graphics */
3185 if ((a & 0x80) && (c & 0x80))
3187 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3192 /* Hilite the player */
3193 Term_curs_win(p_ptr->x - min_x, p_ptr->y - min_y);
3195 /* Wait for a keypress, flush key buffer */
3196 Term_inkey(&c, TRUE, TRUE);
3199 /* Switch off the map display */
3200 td->map_active = FALSE;
3202 /* Restore screen */
3203 Term_xtra_win_clear();
3208 /*** Other routines ***/
3212 * Create and initialize a "term_data" given a title
3214 static void term_data_link(term_data *td)
3218 /* Initialize the term */
3219 term_init(t, td->cols, td->rows, td->keys);
3221 /* Use a "software" cursor */
3222 t->soft_cursor = TRUE;
3224 /* Use "Term_pict" for "graphic" data */
3225 t->higher_pict = TRUE;
3227 /* Erase with "white space" */
3228 t->attr_blank = TERM_WHITE;
3229 t->char_blank = ' ';
3232 /* Prepare the init/nuke hooks */
3233 t->init_hook = Term_init_win;
3234 t->nuke_hook = Term_nuke_win;
3237 /* Prepare the template hooks */
3238 t->user_hook = Term_user_win;
3239 t->xtra_hook = Term_xtra_win;
3240 t->curs_hook = Term_curs_win;
3241 t->bigcurs_hook = Term_bigcurs_win;
3242 t->wipe_hook = Term_wipe_win;
3243 t->text_hook = Term_text_win;
3244 t->pict_hook = Term_pict_win;
3246 /* Remember where we came from */
3247 t->data = (vptr)(td);
3252 * Create the windows
3254 * First, instantiate the "default" values, then read the "ini_file"
3255 * to over-ride selected values, then create the windows, and fonts.
3257 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3258 * must make active to realize the palette.
3260 static void init_windows(void)
3266 #if 0 /* #ifndef JP */
3272 WIPE(td, term_data);
3276 td->s = angband_term_name[0];
3290 #if 1 /* #ifdef JP */
3294 for (i = 1; i < MAX_TERM_DATA; i++)
3297 WIPE(td, term_data);
3298 td->s = angband_term_name[i];
3302 td->visible = FALSE;
3307 td->pos_x = (7 - i) * 30;
3308 td->pos_y = (7 - i) * 20;
3310 #if 1 /* #ifdef JP */
3320 /* Main window (need these before term_getsize gets called) */
3322 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3323 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3328 /* Sub windows (need these before term_getsize gets called) */
3329 for (i = 1; i < MAX_TERM_DATA; i++)
3332 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3333 td->dwExStyle = (WS_EX_TOOLWINDOW);
3338 for (i = 0; i < MAX_TERM_DATA; i++)
3342 #if 1 /* #ifdef JP */
3343 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3344 td->lf.lfCharSet = DEFAULT_CHARSET;
3345 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3346 /* Activate the chosen font */
3347 term_force_font(td, NULL);
3348 if(!td->tile_wid) td->tile_wid = td->font_wid;
3349 if(!td->tile_hgt) td->tile_hgt = td->font_hgt;
3351 /* Access the standard font file */
3352 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3354 /* Activate the chosen font */
3355 if (term_force_font(td, buf))
3357 /* Access the standard font file */
3358 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3360 /* Force the use of that font */
3361 (void)term_force_font(td, buf);
3366 /* Assume not bizarre */
3367 td->bizarre = FALSE;
3372 /* Analyze the font */
3375 /* Resize the window */
3376 term_window_resize(td);
3380 /* Sub windows (reverse order) */
3381 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3386 td->w = CreateWindowEx(td->dwExStyle, AngList,
3388 td->pos_x, td->pos_y,
3389 td->size_wid, td->size_hgt,
3390 HWND_DESKTOP, NULL, hInstance, NULL);
3392 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3396 td->size_hack = TRUE;
3397 ShowWindow(td->w, SW_SHOW);
3398 td->size_hack = FALSE;
3402 angband_term[i] = &td->t;
3406 /* Activate the window */
3407 SetActiveWindow(td->w);
3412 term_window_pos(&data[i], HWND_TOPMOST);
3416 term_window_pos(&data[i], td->w);
3426 td->w = CreateWindowEx(td->dwExStyle, AppName,
3428 td->pos_x, td->pos_y,
3429 td->size_wid, td->size_hgt,
3430 HWND_DESKTOP, NULL, hInstance, NULL);
3432 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3435 angband_term[0] = &td->t;
3436 normsize.x = td->cols;
3437 normsize.y = td->rows;
3439 /* Activate the main window */
3440 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3441 else ShowWindow(td->w, SW_SHOW);
3443 /* Bring main window back to top */
3444 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3448 (void)new_palette();
3451 /* Create a "brush" for drawing the "cursor" */
3452 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3455 /* Process pending messages */
3456 (void)Term_xtra_win_flush();
3464 static void setup_menus(void)
3468 HMENU hm = GetMenu(data[0].w);
3471 /* Menu "File", Disable all */
3472 EnableMenuItem(hm, IDM_FILE_NEW,
3473 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3474 EnableMenuItem(hm, IDM_FILE_OPEN,
3475 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3476 EnableMenuItem(hm, IDM_FILE_SAVE,
3477 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3478 EnableMenuItem(hm, IDM_FILE_EXIT,
3479 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3480 EnableMenuItem(hm, IDM_FILE_SCORE,
3481 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3484 /* No character available */
3485 if (!character_generated)
3487 /* Menu "File", Item "New" */
3488 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3490 /* Menu "File", Item "Open" */
3491 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3494 /* A character available */
3495 if (character_generated)
3497 /* Menu "File", Item "Save" */
3498 EnableMenuItem(hm, IDM_FILE_SAVE,
3499 MF_BYCOMMAND | MF_ENABLED);
3502 /* Menu "File", Item "Exit" */
3503 EnableMenuItem(hm, IDM_FILE_EXIT,
3504 MF_BYCOMMAND | MF_ENABLED);
3506 EnableMenuItem(hm, IDM_FILE_SCORE,
3507 MF_BYCOMMAND | MF_ENABLED);
3510 /* Menu "Window::Visibility" */
3511 for (i = 0; i < MAX_TERM_DATA; i++)
3513 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3514 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3516 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3517 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3519 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3520 MF_BYCOMMAND | MF_ENABLED);
3523 /* Menu "Window::Font" */
3524 for (i = 0; i < MAX_TERM_DATA; i++)
3526 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3527 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3529 if (data[i].visible)
3531 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3532 MF_BYCOMMAND | MF_ENABLED);
3536 /* Menu "Window::Window Position Fix" */
3537 for (i = 0; i < MAX_TERM_DATA; i++)
3539 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3540 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3542 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3543 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3545 if (data[i].visible)
3547 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3548 MF_BYCOMMAND | MF_ENABLED);
3552 /* Menu "Window::Bizarre Display" */
3553 for (i = 0; i < MAX_TERM_DATA; i++)
3555 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3556 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3558 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3559 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3561 if (data[i].visible)
3563 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3564 MF_BYCOMMAND | MF_ENABLED);
3569 /* Menu "Window::Increase Tile Width" */
3570 for (i = 0; i < MAX_TERM_DATA; i++)
3572 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3573 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3575 if (data[i].visible)
3577 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3578 MF_BYCOMMAND | MF_ENABLED);
3583 /* Menu "Window::Decrease Tile Width" */
3584 for (i = 0; i < MAX_TERM_DATA; i++)
3586 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3587 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3589 if (data[i].visible)
3591 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3592 MF_BYCOMMAND | MF_ENABLED);
3597 /* Menu "Window::Increase Tile Height" */
3598 for (i = 0; i < MAX_TERM_DATA; i++)
3600 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3601 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3603 if (data[i].visible)
3605 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3606 MF_BYCOMMAND | MF_ENABLED);
3611 /* Menu "Window::Decrease Tile Height" */
3612 for (i = 0; i < MAX_TERM_DATA; i++)
3614 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3615 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3617 if (data[i].visible)
3619 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3620 MF_BYCOMMAND | MF_ENABLED);
3625 /* Menu "Options", disable all */
3626 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3627 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3628 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3629 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3630 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3631 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3632 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3633 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3634 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3635 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3637 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3638 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3641 /* Menu "Options", Item "Map" */
3642 if (use_graphics != GRAPHICS_NONE)
3643 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3645 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3646 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3648 /* Menu "Options", update all */
3649 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3650 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3651 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3652 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3653 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3654 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3655 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3656 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3657 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3658 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3659 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3660 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3661 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3662 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3663 CheckMenuItem(hm, IDM_OPTIONS_BG,
3664 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3666 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3667 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3671 /* Menu "Options", Item "Graphics" */
3672 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3673 /* Menu "Options", Item "Graphics" */
3674 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3675 /* Menu "Options", Item "Graphics" */
3676 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3677 /* Menu "Options", Item "Graphics" */
3678 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3679 #endif /* USE_GRAPHICS */
3682 /* Menu "Options", Item "Sound" */
3683 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3684 #endif /* USE_SOUND */
3687 /* Menu "Options", Item "ScreenSaver" */
3688 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3689 MF_BYCOMMAND | MF_ENABLED);
3690 #endif /* USE_SAVER */
3695 * Check for double clicked (or dragged) savefile
3697 * Apparently, Windows copies the entire filename into the first
3698 * piece of the "command line string". Perhaps we should extract
3699 * the "basename" of that filename and append it to the "save" dir.
3701 static void check_for_save_file(LPSTR cmd_line)
3711 /* Extract filename */
3712 strcat(savefile, s);
3714 /* Validate the file */
3715 validate_file(savefile);
3717 /* Game in progress */
3718 game_in_progress = TRUE;
3726 * Process a menu command
3728 static void process_menus(WORD wCmd)
3744 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3746 else if (game_in_progress)
3748 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3752 game_in_progress = TRUE;
3765 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3767 else if (game_in_progress)
3769 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3773 memset(&ofn, 0, sizeof(ofn));
3774 ofn.lStructSize = sizeof(ofn);
3775 ofn.hwndOwner = data[0].w;
3776 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3777 ofn.nFilterIndex = 1;
3778 ofn.lpstrFile = savefile;
3779 ofn.nMaxFile = 1024;
3780 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3781 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3783 if (GetOpenFileName(&ofn))
3785 /* Load 'savefile' */
3786 validate_file(savefile);
3787 game_in_progress = TRUE;
3799 if (game_in_progress && character_generated)
3803 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3807 /* Hack -- Forget messages */
3812 do_cmd_save_game(FALSE);
3813 #else /* ZANGBAND */
3815 #endif /* ZANGBAND */
3819 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3827 if (game_in_progress && character_generated)
3831 plog(_("今は終了できません。", "You may not do that right now."));
3835 /* Hack -- Forget messages */
3844 /* do_cmd_save_game(FALSE); */
3845 #else /* ZANGBAND */
3846 /* do_cmd_save_game(); */
3847 #endif /* ZANGBAND */
3848 Term_key_push(SPECIAL_KEY_QUIT);
3856 case IDM_FILE_SCORE:
3860 /* Build the filename */
3861 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3863 /* Open the binary high score file, for reading */
3864 highscore_fd = fd_open(buf, O_RDONLY);
3866 /* Paranoia -- No score file */
3867 if (highscore_fd < 0)
3869 msg_print("Score file unavailable.");
3876 /* Display the scores */
3877 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3879 /* Shut the high score file */
3880 (void)fd_close(highscore_fd);
3882 /* Forget the high score fd */
3886 /* Hack - Flush it */
3894 case IDM_FILE_MOVIE:
3898 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3900 else if (game_in_progress)
3902 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
3906 memset(&ofn, 0, sizeof(ofn));
3907 ofn.lStructSize = sizeof(ofn);
3908 ofn.hwndOwner = data[0].w;
3909 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3910 ofn.nFilterIndex = 1;
3911 ofn.lpstrFile = savefile;
3912 ofn.nMaxFile = 1024;
3913 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3914 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3916 if (GetOpenFileName(&ofn))
3918 /* Load 'savefile' */
3919 prepare_browse_movie_aux(savefile);
3929 case IDM_WINDOW_VIS_0:
3931 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
3935 /* Window visibility */
3936 case IDM_WINDOW_VIS_1:
3937 case IDM_WINDOW_VIS_2:
3938 case IDM_WINDOW_VIS_3:
3939 case IDM_WINDOW_VIS_4:
3940 case IDM_WINDOW_VIS_5:
3941 case IDM_WINDOW_VIS_6:
3942 case IDM_WINDOW_VIS_7:
3944 i = wCmd - IDM_WINDOW_VIS_0;
3946 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3953 ShowWindow(td->w, SW_SHOW);
3954 term_data_redraw(td);
3958 td->visible = FALSE;
3960 ShowWindow(td->w, SW_HIDE);
3967 case IDM_WINDOW_FONT_0:
3968 case IDM_WINDOW_FONT_1:
3969 case IDM_WINDOW_FONT_2:
3970 case IDM_WINDOW_FONT_3:
3971 case IDM_WINDOW_FONT_4:
3972 case IDM_WINDOW_FONT_5:
3973 case IDM_WINDOW_FONT_6:
3974 case IDM_WINDOW_FONT_7:
3976 i = wCmd - IDM_WINDOW_FONT_0;
3978 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3982 term_change_font(td);
3987 /* Window Z Position */
3988 case IDM_WINDOW_POS_1:
3989 case IDM_WINDOW_POS_2:
3990 case IDM_WINDOW_POS_3:
3991 case IDM_WINDOW_POS_4:
3992 case IDM_WINDOW_POS_5:
3993 case IDM_WINDOW_POS_6:
3994 case IDM_WINDOW_POS_7:
3996 i = wCmd - IDM_WINDOW_POS_0;
3998 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4002 if (!td->posfix && td->visible)
4005 term_window_pos(td, HWND_TOPMOST);
4010 term_window_pos(td, data[0].w);
4016 /* Bizarre Display */
4017 case IDM_WINDOW_BIZ_0:
4018 case IDM_WINDOW_BIZ_1:
4019 case IDM_WINDOW_BIZ_2:
4020 case IDM_WINDOW_BIZ_3:
4021 case IDM_WINDOW_BIZ_4:
4022 case IDM_WINDOW_BIZ_5:
4023 case IDM_WINDOW_BIZ_6:
4024 case IDM_WINDOW_BIZ_7:
4026 i = wCmd - IDM_WINDOW_BIZ_0;
4028 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4032 td->bizarre = !td->bizarre;
4036 term_window_resize(td);
4041 /* Increase Tile Width */
4042 case IDM_WINDOW_I_WID_0:
4043 case IDM_WINDOW_I_WID_1:
4044 case IDM_WINDOW_I_WID_2:
4045 case IDM_WINDOW_I_WID_3:
4046 case IDM_WINDOW_I_WID_4:
4047 case IDM_WINDOW_I_WID_5:
4048 case IDM_WINDOW_I_WID_6:
4049 case IDM_WINDOW_I_WID_7:
4051 i = wCmd - IDM_WINDOW_I_WID_0;
4053 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4061 term_window_resize(td);
4066 /* Decrease Tile Height */
4067 case IDM_WINDOW_D_WID_0:
4068 case IDM_WINDOW_D_WID_1:
4069 case IDM_WINDOW_D_WID_2:
4070 case IDM_WINDOW_D_WID_3:
4071 case IDM_WINDOW_D_WID_4:
4072 case IDM_WINDOW_D_WID_5:
4073 case IDM_WINDOW_D_WID_6:
4074 case IDM_WINDOW_D_WID_7:
4076 i = wCmd - IDM_WINDOW_D_WID_0;
4078 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4086 term_window_resize(td);
4091 /* Increase Tile Height */
4092 case IDM_WINDOW_I_HGT_0:
4093 case IDM_WINDOW_I_HGT_1:
4094 case IDM_WINDOW_I_HGT_2:
4095 case IDM_WINDOW_I_HGT_3:
4096 case IDM_WINDOW_I_HGT_4:
4097 case IDM_WINDOW_I_HGT_5:
4098 case IDM_WINDOW_I_HGT_6:
4099 case IDM_WINDOW_I_HGT_7:
4101 i = wCmd - IDM_WINDOW_I_HGT_0;
4103 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4111 term_window_resize(td);
4116 /* Decrease Tile Height */
4117 case IDM_WINDOW_D_HGT_0:
4118 case IDM_WINDOW_D_HGT_1:
4119 case IDM_WINDOW_D_HGT_2:
4120 case IDM_WINDOW_D_HGT_3:
4121 case IDM_WINDOW_D_HGT_4:
4122 case IDM_WINDOW_D_HGT_5:
4123 case IDM_WINDOW_D_HGT_6:
4124 case IDM_WINDOW_D_HGT_7:
4126 i = wCmd - IDM_WINDOW_D_HGT_0;
4128 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4136 term_window_resize(td);
4141 case IDM_OPTIONS_NO_GRAPHICS:
4145 plog("You may not do that right now.");
4149 /* Toggle "arg_graphics" */
4150 if (arg_graphics != GRAPHICS_NONE)
4152 arg_graphics = GRAPHICS_NONE;
4154 /* React to changes */
4155 Term_xtra_win_react();
4157 /* Hack -- Force redraw */
4158 Term_key_push(KTRL('R'));
4164 case IDM_OPTIONS_OLD_GRAPHICS:
4168 plog("You may not do that right now.");
4172 /* Toggle "arg_graphics" */
4173 if (arg_graphics != GRAPHICS_ORIGINAL)
4175 arg_graphics = GRAPHICS_ORIGINAL;
4177 /* React to changes */
4178 Term_xtra_win_react();
4180 /* Hack -- Force redraw */
4181 Term_key_push(KTRL('R'));
4187 case IDM_OPTIONS_NEW_GRAPHICS:
4191 plog("You may not do that right now.");
4195 /* Toggle "arg_graphics" */
4196 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4198 arg_graphics = GRAPHICS_ADAM_BOLT;
4200 /* React to changes */
4201 Term_xtra_win_react();
4203 /* Hack -- Force redraw */
4204 Term_key_push(KTRL('R'));
4210 case IDM_OPTIONS_NEW2_GRAPHICS:
4214 plog("You may not do that right now.");
4218 /* Toggle "arg_graphics" */
4219 if (arg_graphics != GRAPHICS_HENGBAND)
4221 arg_graphics = GRAPHICS_HENGBAND;
4223 /* React to changes */
4224 Term_xtra_win_react();
4226 /* Hack -- Force redraw */
4227 Term_key_push(KTRL('R'));
4233 case IDM_OPTIONS_BIGTILE:
4238 plog("You may not do that right now.");
4242 /* Toggle "arg_sound" */
4243 arg_bigtile = !arg_bigtile;
4246 Term_activate(&td->t);
4248 /* Resize the term */
4249 Term_resize(td->cols, td->rows);
4252 InvalidateRect(td->w, NULL, TRUE);
4257 case IDM_OPTIONS_MUSIC:
4261 plog("You may not do that right now.");
4265 /* Toggle "arg_sound" */
4266 arg_music = !arg_music;
4268 /* React to changes */
4269 Term_xtra_win_react();
4271 /* Hack -- Force redraw */
4272 Term_key_push(KTRL('R'));
4277 case IDM_OPTIONS_SOUND:
4281 plog("You may not do that right now.");
4285 /* Toggle "arg_sound" */
4286 arg_sound = !arg_sound;
4288 /* React to changes */
4289 Term_xtra_win_react();
4291 /* Hack -- Force redraw */
4292 Term_key_push(KTRL('R'));
4298 case IDM_OPTIONS_BG:
4302 plog("You may not do that right now.");
4306 /* Toggle "use_bg" */
4311 /* React to changes */
4312 Term_xtra_win_react();
4314 /* Hack -- Force redraw */
4315 Term_key_push(KTRL('R'));
4321 case IDM_OPTIONS_OPEN_BG:
4325 plog("You may not do that right now.");
4330 memset(&ofn, 0, sizeof(ofn));
4331 ofn.lStructSize = sizeof(ofn);
4332 ofn.hwndOwner = data[0].w;
4333 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4334 ofn.nFilterIndex = 1;
4335 ofn.lpstrFile = bg_bitmap_file;
4336 ofn.nMaxFile = 1023;
4337 ofn.lpstrInitialDir = NULL;
4338 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
4339 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4341 if (GetOpenFileName(&ofn))
4343 /* Load 'savefile' */
4348 /* React to changes */
4349 Term_xtra_win_react();
4351 /* Hack -- Force redraw */
4352 Term_key_push(KTRL('R'));
4357 case IDM_DUMP_SCREEN_HTML:
4359 static char buf[1024] = "";
4360 memset(&ofn, 0, sizeof(ofn));
4361 ofn.lStructSize = sizeof(ofn);
4362 ofn.hwndOwner = data[0].w;
4363 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4364 ofn.nFilterIndex = 1;
4365 ofn.lpstrFile = buf;
4366 ofn.nMaxFile = 1023;
4367 ofn.lpstrDefExt = "html";
4368 ofn.lpstrInitialDir = NULL;
4369 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
4370 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4372 if (GetSaveFileName(&ofn))
4374 do_cmd_save_screen_html_aux(buf, 0);
4381 case IDM_OPTIONS_SAVER:
4385 DestroyWindow(hwndSaver);
4390 /* Create a screen scaver window */
4391 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4392 "Angband Screensaver",
4393 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4394 0, 0, GetSystemMetrics(SM_CXSCREEN),
4395 GetSystemMetrics(SM_CYSCREEN),
4396 NULL, NULL, hInstance, NULL);
4400 /* Push the window to the bottom */
4401 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4405 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
4413 case IDM_OPTIONS_MAP:
4419 case IDM_HELP_CONTENTS:
4423 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4424 if (check_file(tmp))
4426 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4430 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4431 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4434 #else /* HTML_HELP */
4437 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4438 if (check_file(tmp))
4440 sprintf(buf, "winhelp.exe %s", tmp);
4441 WinExec(buf, SW_NORMAL);
4445 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4446 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4450 #endif /* HTML_HELP */
4456 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4463 /* Extract the modifiers */
4464 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4465 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4466 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4468 Term_no_press = (ma) ? TRUE : FALSE;
4470 /* Handle "special" keys */
4471 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4473 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4474 bool numpad = FALSE;
4476 /* Begin the macro trigger */
4479 /* Send the modifiers */
4480 if (mc) Term_keypress('C');
4481 if (ms) Term_keypress('S');
4482 if (ma) Term_keypress('A');
4484 /* Extract "scan code" */
4485 i = LOBYTE(HIWORD(lParam));
4487 /* Introduce the scan code */
4490 /* Extended key bit */
4493 /* Numpad Enter and '/' are extended key */
4495 Term_no_press = TRUE;
4496 case VK_RETURN: /* Enter */
4499 /* Other extended keys are on full keyboard */
4515 Term_no_press = TRUE;
4519 case VK_PRIOR: /* Page Up */
4520 case VK_NEXT: /* Page Down */
4530 /* Special modifiers for keypad keys */
4531 if (numpad) Term_keypress('K');
4533 /* Encode the hexidecimal scan code */
4534 Term_keypress(hexsym[i/16]);
4535 Term_keypress(hexsym[i%16]);
4537 /* End the macro trigger */
4548 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4549 WPARAM wParam, LPARAM lParam);
4550 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4551 WPARAM wParam, LPARAM lParam)
4552 #else /* __MWERKS__ */
4553 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4554 #endif /* __MWERKS__ */
4560 MINMAXINFO FAR *lpmmi;
4566 /* Acquire proper "term_data" info */
4567 td = (term_data *)GetWindowLong(hWnd, 0);
4569 /* Handle message */
4574 SetWindowLong(hWnd, 0, (LONG)(my_td));
4581 mop.dwCallback=(DWORD)hWnd;
4586 case WM_GETMINMAXINFO:
4588 MINMAXINFO FAR *lpmmi;
4591 lpmmi = (MINMAXINFO FAR *)lParam;
4593 /* this message was sent before WM_NCCREATE */
4596 /* Minimum window size is 80x24 */
4597 rc.left = rc.top = 0;
4598 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4599 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4602 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4604 /* Save minimum size */
4605 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4606 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4613 BeginPaint(hWnd, &ps);
4614 if (td) term_data_redraw(td);
4615 EndPaint(hWnd, &ps);
4616 ValidateRect(hWnd, NULL);
4623 if(wParam == MCI_NOTIFY_SUCCESSFUL)
4625 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4626 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4635 if (process_keydown(wParam, lParam))
4642 if (Term_no_press) Term_no_press = FALSE;
4643 else Term_keypress(wParam);
4647 case WM_LBUTTONDOWN:
4649 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4650 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4662 TERM_LEN dx = abs(oldx - mousex) + 1;
4663 TERM_LEN dy = abs(oldy - mousey) + 1;
4664 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
4665 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
4675 hGlobal = GlobalAlloc(GHND, sz + 1);
4676 if (hGlobal == NULL) return 0;
4677 lpStr = (LPSTR)GlobalLock(hGlobal);
4679 for (i = 0; i < dy; i++)
4683 char **scr = data[0].t.scr->c;
4685 C_MAKE(s, (dx + 1), char);
4686 strncpy(s, &scr[oy + i][ox], dx);
4690 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4693 if (ox + dx < data[0].cols)
4695 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4698 for (j = 0; j < dx; j++)
4700 if (s[j] == 127) s[j] = '#';
4704 for (j = 0; j < dx; j++)
4706 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4716 GlobalUnlock(hGlobal);
4717 if (OpenClipboard(hWnd) == 0)
4719 GlobalFree(hGlobal);
4723 SetClipboardData(CF_TEXT, hGlobal);
4736 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4737 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4742 dx = abs(oldx - mousex) + 1;
4743 dy = abs(oldy - mousey) + 1;
4744 ox = (oldx > mousex) ? mousex : oldx;
4745 oy = (oldy > mousey) ? mousey : oldy;
4746 Term_inversed_area(hWnd, ox, oy, dx, dy);
4753 dx = abs(cx - mousex) + 1;
4754 dy = abs(cy - mousey) + 1;
4755 ox = (cx > mousex) ? mousex : cx;
4756 oy = (cy > mousey) ? mousey : cy;
4757 Term_inversed_area(hWnd, ox, oy, dx, dy);
4773 if (game_in_progress && character_generated)
4777 plog(_("今は終了できません。", "You may not do that right now."));
4781 /* Hack -- Forget messages */
4790 /* do_cmd_save_game(FALSE); */
4791 #else /* ZANGBAND */
4792 /* do_cmd_save_game(); */
4793 #endif /* ZANGBAND */
4794 Term_key_push(SPECIAL_KEY_QUIT);
4801 case WM_QUERYENDSESSION:
4803 if (game_in_progress && character_generated)
4805 /* Hack -- Forget messages */
4808 /* Mega-Hack -- Delay death */
4809 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4810 do_cmd_write_nikki(NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4812 /* Hardcode panic save */
4813 p_ptr->panic_save = 1;
4815 /* Forbid suspend */
4816 signals_ignore_tstp();
4818 /* Indicate panic save */
4819 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4822 (void)save_player();
4836 process_menus(LOWORD(wParam));
4842 /* this message was sent before WM_NCCREATE */
4845 /* it was sent from inside CreateWindowEx */
4846 if (!td->w) return 1;
4848 /* was sent from WM_SIZE */
4849 if (td->size_hack) return 1;
4853 case SIZE_MINIMIZED:
4855 /* Hide sub-windows */
4856 for (i = 1; i < MAX_TERM_DATA; i++)
4858 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4863 case SIZE_MAXIMIZED:
4870 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4871 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4874 if ((td->cols != cols) || (td->rows != rows))
4876 /* Save the new size */
4880 if (!IsZoomed(td->w) && !IsIconic(td->w))
4882 normsize.x = td->cols;
4883 normsize.y = td->rows;
4887 Term_activate(&td->t);
4889 /* Resize the term */
4890 Term_resize(td->cols, td->rows);
4893 InvalidateRect(td->w, NULL, TRUE);
4896 td->size_hack = TRUE;
4898 /* Show sub-windows */
4899 for (i = 1; i < MAX_TERM_DATA; i++)
4901 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4904 td->size_hack = FALSE;
4912 case WM_PALETTECHANGED:
4914 /* Ignore if palette change caused by itself */
4915 if ((HWND)wParam == hWnd) return 0;
4917 /* Fall through... */
4920 case WM_QUERYNEWPALETTE:
4922 if (!paletted) return 0;
4926 SelectPalette(hdc, hPal, FALSE);
4928 i = RealizePalette(hdc);
4930 /* if any palette entries changed, repaint the window. */
4931 if (i) InvalidateRect(hWnd, NULL, TRUE);
4933 ReleaseDC(hWnd, hdc);
4940 if (wParam && !HIWORD(lParam))
4942 /* Do something to sub-windows */
4943 for (i = 1; i < MAX_TERM_DATA; i++)
4945 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4948 /* Focus on main window */
4957 case WM_ACTIVATEAPP:
4959 if (IsIconic(td->w)) break;
4961 for (i = 1; i < MAX_TERM_DATA; i++)
4967 ShowWindow(data[i].w, SW_SHOW);
4971 ShowWindow(data[i].w, SW_HIDE);
4978 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4983 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4984 WPARAM wParam, LPARAM lParam);
4985 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4986 WPARAM wParam, LPARAM lParam)
4987 #else /* __MWERKS__ */
4988 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4989 WPARAM wParam, LPARAM lParam)
4990 #endif /* __MWERKS__ */
4994 MINMAXINFO FAR *lpmmi;
5002 /* Acquire proper "term_data" info */
5003 td = (term_data *)GetWindowLong(hWnd, 0);
5005 /* Process message */
5010 SetWindowLong(hWnd, 0, (LONG)(my_td));
5019 case WM_GETMINMAXINFO:
5021 MINMAXINFO FAR *lpmmi;
5024 lpmmi = (MINMAXINFO FAR *)lParam;
5026 /* this message was sent before WM_NCCREATE */
5029 /* Minimum window size is 80x24 */
5030 rc.left = rc.top = 0;
5031 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5032 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5035 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5037 /* Save minimum size */
5038 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5039 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5049 /* this message was sent before WM_NCCREATE */
5052 /* it was sent from inside CreateWindowEx */
5053 if (!td->w) return 1;
5055 /* was sent from inside WM_SIZE */
5056 if (td->size_hack) return 1;
5058 td->size_hack = TRUE;
5060 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5061 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5064 if ((td->cols != cols) || (td->rows != rows))
5067 term *old_term = Term;
5069 /* Save the new size */
5074 Term_activate(&td->t);
5076 /* Resize the term */
5077 Term_resize(td->cols, td->rows);
5080 Term_activate(old_term);
5083 InvalidateRect(td->w, NULL, TRUE);
5085 /* HACK - Redraw all windows */
5086 p_ptr->window = 0xFFFFFFFF;
5090 td->size_hack = FALSE;
5097 BeginPaint(hWnd, &ps);
5098 if (td) term_data_redraw(td);
5099 EndPaint(hWnd, &ps);
5106 if (process_keydown(wParam, lParam))
5113 if (Term_no_press) Term_no_press = FALSE;
5114 else Term_keypress(wParam);
5118 case WM_PALETTECHANGED:
5120 /* ignore if palette change caused by itself */
5121 if ((HWND)wParam == hWnd) return FALSE;
5122 /* otherwise, fall through!!! */
5125 case WM_QUERYNEWPALETTE:
5127 if (!paletted) return 0;
5129 SelectPalette(hdc, hPal, FALSE);
5130 i = RealizePalette(hdc);
5131 /* if any palette entries changed, repaint the window. */
5132 if (i) InvalidateRect(hWnd, NULL, TRUE);
5133 ReleaseDC(hWnd, hdc);
5137 case WM_NCLBUTTONDOWN:
5141 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5142 #endif /* HTCLOSE */
5144 if (wParam == HTSYSMENU)
5148 td->visible = FALSE;
5149 ShowWindow(td->w, SW_HIDE);
5159 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5165 #define MOUSE_SENS 40
5168 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5169 WPARAM wParam, LPARAM lParam);
5170 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5171 WPARAM wParam, LPARAM lParam)
5172 #else /* __MWERKS__ */
5173 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5174 WPARAM wParam, LPARAM lParam)
5175 #endif /* __MWERKS__ */
5177 static int iMouse = 0;
5178 static WORD xMouse = 0;
5179 static WORD yMouse = 0;
5201 if (LOWORD(wParam) == WA_INACTIVE) break;
5203 /* else fall through */
5207 case WM_LBUTTONDOWN:
5208 case WM_MBUTTONDOWN:
5209 case WM_RBUTTONDOWN:
5212 SendMessage(hWnd, WM_CLOSE, 0, 0);
5220 dx = LOWORD(lParam) - xMouse;
5221 dy = HIWORD(lParam) - yMouse;
5223 if (dx < 0) dx = -dx;
5224 if (dy < 0) dy = -dy;
5226 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5228 SendMessage(hWnd, WM_CLOSE, 0, 0);
5232 /* Save last location */
5234 xMouse = LOWORD(lParam);
5235 yMouse = HIWORD(lParam);
5242 DestroyWindow(hwndSaver);
5248 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5251 #endif /* USE_SAVER */
5257 /*** Temporary Hooks ***/
5261 * Display warning message (see "z-util.c")
5263 static void hack_plog(concptr str)
5265 /* Give a warning */
5269 MessageBox(NULL, str, "警告!",
5270 MB_ICONEXCLAMATION | MB_OK);
5272 MessageBox(NULL, str, "Warning",
5273 MB_ICONEXCLAMATION | MB_OK);
5281 * Display error message and quit (see "z-util.c")
5283 static void hack_quit(concptr str)
5285 /* Give a warning */
5289 MessageBox(NULL, str, "エラー!",
5290 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5292 MessageBox(NULL, str, "Error",
5293 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5298 /* Unregister the classes */
5299 UnregisterClass(AppName, hInstance);
5301 /* Destroy the icon */
5302 if (hIcon) DestroyIcon(hIcon);
5310 /*** Various hooks ***/
5314 * Display warning message (see "z-util.c")
5316 static void hook_plog(concptr str)
5322 MessageBox(data[0].w, str, "警告!",
5323 MB_ICONEXCLAMATION | MB_OK);
5325 MessageBox(data[0].w, str, "Warning",
5326 MB_ICONEXCLAMATION | MB_OK);
5334 * Display error message and quit (see "z-util.c")
5336 static void hook_quit(concptr str)
5341 /* Give a warning */
5345 MessageBox(data[0].w, str, "エラー!",
5346 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5348 MessageBox(data[0].w, str, "Error",
5349 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5355 /* Save the preferences */
5359 /*** Could use 'Term_nuke_win()' */
5361 /* Destroy all windows */
5362 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5364 term_force_font(&data[i], NULL);
5365 if (data[i].font_want) string_free(data[i].font_want);
5366 if (data[i].w) DestroyWindow(data[i].w);
5370 /* Free the bitmap stuff */
5372 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5373 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5375 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5376 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5378 #endif /* USE_GRAPHICS */
5380 /*** Free some other stuff ***/
5382 DeleteObject(hbrYellow);
5387 if (hPal) DeleteObject(hPal);
5389 UnregisterClass(AppName, hInstance);
5391 if (hIcon) DestroyIcon(hIcon);
5398 /*** Initialize ***/
5404 static void init_stuff(void)
5411 /* Get program name with full path */
5412 GetModuleFileName(hInstance, path, 512);
5414 /* Save the "program name" */
5417 /* Get the name of the "*.ini" file */
5418 strcpy(path + strlen(path) - 4, ".INI");
5420 /* Save the the name of the ini-file */
5421 ini_file = string_make(path);
5423 /* Analyze the path */
5429 if (path[i] == '\\')
5436 /* Add "lib" to the path */
5437 strcpy(path + i + 1, "lib\\");
5439 /* Validate the path */
5440 validate_dir(path, TRUE);
5442 /* Init the file paths */
5443 init_file_paths(path, path, path);
5445 /* Hack -- Validate the paths */
5446 validate_dir(ANGBAND_DIR_APEX, FALSE);
5447 validate_dir(ANGBAND_DIR_BONE, FALSE);
5449 /* Allow missing 'edit' directory */
5450 if (!check_dir(ANGBAND_DIR_EDIT))
5452 /* Must have 'data'! */
5453 validate_dir(ANGBAND_DIR_DATA, TRUE);
5457 /* Don't need 'data' */
5458 validate_dir(ANGBAND_DIR_DATA, FALSE);
5461 validate_dir(ANGBAND_DIR_FILE, TRUE);
5462 validate_dir(ANGBAND_DIR_HELP, FALSE);
5463 validate_dir(ANGBAND_DIR_INFO, FALSE);
5464 validate_dir(ANGBAND_DIR_PREF, TRUE);
5465 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5466 validate_dir(ANGBAND_DIR_USER, TRUE);
5467 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5469 /* Build the filename */
5470 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
5472 /* Hack -- Validate the "news.txt" file */
5473 validate_file(path);
5476 #if 0 /* #ifndef JP */
5477 /* Build the "font" path */
5478 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5480 /* Allocate the path */
5481 ANGBAND_DIR_XTRA_FONT = string_make(path);
5483 /* Validate the "font" directory */
5484 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5486 /* Build the filename */
5487 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5489 /* Hack -- Validate the basic font */
5490 validate_file(path);
5496 /* Build the "graf" path */
5497 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5499 /* Allocate the path */
5500 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5502 /* Validate the "graf" directory */
5503 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5505 #endif /* USE_GRAPHICS */
5510 /* Build the "sound" path */
5511 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5513 /* Allocate the path */
5514 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5516 /* Validate the "sound" directory */
5517 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5519 #endif /* USE_SOUND */
5523 /* Build the "music" path */
5524 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5526 /* Allocate the path */
5527 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5529 /* Validate the "music" directory */
5530 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5532 #endif /* USE_MUSIC */
5534 /* Build the "help" path */
5535 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5537 /* Allocate the path */
5538 ANGBAND_DIR_XTRA_HELP = string_make(path);
5540 /* Validate the "help" directory */
5541 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5545 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
5547 static bool is_already_running(void)
5549 bool result = FALSE;
5552 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5553 if (GetLastError() == ERROR_ALREADY_EXISTS)
5562 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
5564 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5565 LPSTR lpCmdLine, int nCmdShow)
5573 setlocale(LC_ALL, "ja_JP.utf8");
5582 /* Prevent multiple run */
5583 if (is_already_running())
5586 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
5587 _("エラー!", "Error") ,
5588 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5592 if (hPrevInst == NULL)
5594 wc.style = CS_CLASSDC;
5595 wc.lpfnWndProc = AngbandWndProc;
5597 wc.cbWndExtra = 4; /* one long pointer to term_data */
5598 wc.hInstance = hInst;
5599 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5600 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5601 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5602 wc.lpszMenuName = AppName;
5603 wc.lpszClassName = AppName;
5605 if (!RegisterClass(&wc)) exit(1);
5607 wc.lpfnWndProc = AngbandListProc;
5608 wc.lpszMenuName = NULL;
5609 wc.lpszClassName = AngList;
5611 if (!RegisterClass(&wc)) exit(2);
5615 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5616 wc.lpfnWndProc = AngbandSaverProc;
5618 wc.lpszMenuName = NULL;
5619 wc.lpszClassName = "WindowsScreenSaverClass";
5621 if (!RegisterClass(&wc)) exit(3);
5627 /* Temporary hooks */
5628 plog_aux = hack_plog;
5629 quit_aux = hack_quit;
5630 core_aux = hack_quit;
5632 /* Prepare the filepaths */
5635 /* Initialize the keypress analyzer */
5636 for (i = 0; special_key_list[i]; ++i)
5638 special_key[special_key_list[i]] = TRUE;
5640 /* Initialize the keypress analyzer */
5641 for (i = 0; ignore_key_list[i]; ++i)
5643 ignore_key[ignore_key_list[i]] = TRUE;
5646 /* Determine if display is 16/256/true color */
5648 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5649 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5650 ReleaseDC(NULL, hdc);
5652 /* Initialize the colors */
5653 for (i = 0; i < 256; i++)
5657 /* Extract desired values */
5658 rv = angband_color_table[i][1];
5659 gv = angband_color_table[i][2];
5660 bv = angband_color_table[i][3];
5662 /* Extract the "complex" code */
5663 win_clr[i] = PALETTERGB(rv, gv, bv);
5665 /* Save the "simple" code */
5666 angband_color_table[i][0] = win_pal[i];
5669 /* Prepare the windows */
5675 /* Activate hooks */
5676 plog_aux = hook_plog;
5677 quit_aux = hook_quit;
5678 core_aux = hook_quit;
5680 /* Set the system suffix */
5681 ANGBAND_SYS = "win";
5683 /* Set the keyboard suffix */
5684 if (7 != GetKeyboardType(0))
5685 ANGBAND_KEYBOARD = "0";
5688 /* Japanese keyboard */
5689 switch (GetKeyboardType(1))
5691 case 0x0D01: case 0x0D02:
5692 case 0x0D03: case 0x0D04:
5693 case 0x0D05: case 0x0D06:
5695 ANGBAND_KEYBOARD = "NEC98";
5699 ANGBAND_KEYBOARD = "JAPAN";
5703 /* Catch nasty signals */
5706 Term_activate(term_screen);
5709 /* We are now initialized */
5712 if(lpCmdLine[0] == '-'){
5713 switch(lpCmdLine[1])
5718 if (!lpCmdLine[2]) break;
5719 chuukei_server = TRUE;
5720 if(connect_chuukei_server(&lpCmdLine[2])<0){
5721 msg_print("connect fail");
5724 msg_print("connect");
5732 if (!lpCmdLine[2]) break;
5733 chuukei_client = TRUE;
5734 connect_chuukei_server(&lpCmdLine[2]);
5742 if (!lpCmdLine[2]) break;
5743 prepare_browse_movie(&lpCmdLine[2]);
5753 /* Did the user double click on a save file? */
5754 if(!chuukei_server) check_for_save_file(lpCmdLine);
5756 /* Did the user double click on a save file? */
5757 check_for_save_file(lpCmdLine);
5760 /* Prompt the user */
5761 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
5765 /* Process messages forever */
5766 while (GetMessage(&msg, NULL, 0, 0))
5768 TranslateMessage(&msg);
5769 DispatchMessage(&msg);
5776 #endif /* WINDOWS */