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)
1038 if (td->cols < 1) td->cols = 1;
1039 if (td->rows < 1) td->rows = 1;
1042 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1043 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1045 /* Fake window size */
1047 rc.right = rc.left + wid;
1049 rc.bottom = rc.top + hgt;
1051 /* rc.right += 1; */
1052 /* rc.bottom += 1; */
1055 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1058 td->size_wid = rc.right - rc.left;
1059 td->size_hgt = rc.bottom - rc.top;
1061 /* See CreateWindowEx */
1064 /* Extract actual location */
1065 GetWindowRect(td->w, &rc);
1067 /* Save the location */
1068 td->pos_x = rc.left;
1074 * Write the "prefs" for a single term
1076 static void save_prefs_aux(int i)
1078 term_data *td = &data[i];
1079 GAME_TEXT sec_name[128];
1083 WINDOWPLACEMENT lpwndpl;
1088 /* Make section name */
1089 sprintf(sec_name, "Term-%d", i);
1094 strcpy(buf, td->visible ? "1" : "0");
1095 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1100 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "MS ゴシック");
1103 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1105 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1109 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1111 #if 1 /* #ifdef JP */
1112 wsprintf(buf, "%d", td->lf.lfWidth);
1113 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1114 wsprintf(buf, "%d", td->lf.lfHeight);
1115 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1116 wsprintf(buf, "%d", td->lf.lfWeight);
1117 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1120 strcpy(buf, td->bizarre ? "1" : "0");
1121 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1124 wsprintf(buf, "%d", td->tile_wid);
1125 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1128 wsprintf(buf, "%d", td->tile_hgt);
1129 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1131 /* Get window placement and dimensions */
1132 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1133 GetWindowPlacement(td->w, &lpwndpl);
1135 /* Acquire position in *normal* mode (not minimized) */
1136 rc = lpwndpl.rcNormalPosition;
1138 /* Window size (x) */
1139 if (i == 0) wsprintf(buf, "%d", normsize.x);
1140 else wsprintf(buf, "%d", td->cols);
1141 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1143 /* Window size (y) */
1144 if (i == 0) wsprintf(buf, "%d", normsize.y);
1145 else wsprintf(buf, "%d", td->rows);
1146 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1148 /* Maxmized (only main window) */
1151 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1152 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1155 /* Acquire position */
1156 GetWindowRect(td->w, &rc);
1158 /* Window position (x) */
1159 wsprintf(buf, "%d", rc.left);
1160 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1162 /* Window position (y) */
1163 wsprintf(buf, "%d", rc.top);
1164 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1166 /* Window Z position */
1169 strcpy(buf, td->posfix ? "1" : "0");
1170 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1177 * We assume that the windows have all been initialized
1179 static void save_prefs(void)
1185 /* Save the "arg_graphics" flag */
1186 sprintf(buf, "%d", arg_graphics);
1187 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1189 /* Save the "arg_bigtile" flag */
1190 strcpy(buf, arg_bigtile ? "1" : "0");
1191 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1193 /* Save the "arg_sound" flag */
1194 strcpy(buf, arg_sound ? "1" : "0");
1195 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1197 /* Save the "arg_sound" flag */
1198 strcpy(buf, arg_music ? "1" : "0");
1199 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1202 strcpy(buf, use_bg ? "1" : "0");
1203 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1204 WritePrivateProfileString("Angband", "BackGroundBitmap",
1205 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1207 /* Save window prefs */
1208 for (i = 0; i < MAX_TERM_DATA; ++i)
1216 * Load the "prefs" for a single term
1218 static void load_prefs_aux(int i)
1220 term_data *td = &data[i];
1221 GAME_TEXT sec_name[128];
1224 int wid, hgt, posx, posy;
1225 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1226 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1230 /* Make section name */
1231 sprintf(sec_name, "Term-%d", i);
1233 /* Make section name */
1234 sprintf(sec_name, "Term-%d", i);
1239 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1242 /* Desired font, with default */
1244 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1247 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1249 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1255 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1257 /* Analyze font, save desired font name */
1258 #if 1 /* #ifdef JP */
1259 td->font_want = string_make(tmp);
1261 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1262 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1263 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1265 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1270 #if 1 /* #ifdef JP */
1271 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1272 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1274 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1275 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1280 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1281 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1282 normsize.x = td->cols; normsize.y = td->rows;
1287 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
1290 /* Window position */
1291 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1292 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1293 td->pos_x = MIN(MAX(0, posx), dispx-128);
1294 td->pos_y = MIN(MAX(0, posy), dispy-128);
1296 /* Window Z position */
1299 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
1307 static void load_prefs(void)
1311 /* Extract the "arg_graphics" flag */
1312 arg_graphics = (byte_hack)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1314 /* Extract the "arg_bigtile" flag */
1315 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
1316 use_bigtile = arg_bigtile;
1318 /* Extract the "arg_sound" flag */
1319 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1321 /* Extract the "arg_sound" flag */
1322 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1325 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1326 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1328 /* Load window prefs */
1329 for (i = 0; i < MAX_TERM_DATA; ++i)
1335 #if defined(USE_SOUND) || defined(USE_MUSIC)
1338 * - Taken from files.c.
1340 * Extract "tokens" from a buffer
1342 * This function uses "whitespace" as delimiters, and treats any amount of
1343 * whitespace as a single delimiter. We will never return any empty tokens.
1344 * When given an empty buffer, or a buffer containing only "whitespace", we
1345 * will return no tokens. We will never extract more than "num" tokens.
1347 * By running a token through the "text_to_ascii()" function, you can allow
1348 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1350 * We save pointers to the tokens in "tokens", and return the number found.
1352 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1362 /* Skip leading whitespace */
1363 for ( ; *s && iswspace(*s); ++s) /* loop */;
1368 /* Find next whitespace, if any */
1369 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1371 /* Nuke and advance (if necessary) */
1372 if (*t) *t++ = '\0';
1374 /* Save the token */
1385 #endif /* USE_SOUND || USE_MUSIC */
1389 static void load_sound_prefs(void)
1393 char ini_path[1024];
1394 char wav_path[1024];
1395 char *zz[SAMPLE_MAX];
1397 /* Access the sound.cfg */
1399 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1401 for (i = 0; i < SOUND_MAX; i++)
1403 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1405 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1407 for (j = 0; j < num; j++)
1409 /* Access the sound */
1410 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1412 /* Save the sound filename, if it exists */
1413 if (check_file(wav_path))
1414 sound_file[i][j] = string_make(zz[j]);
1419 #endif /* USE_SOUND */
1423 static void load_music_prefs(void)
1427 char ini_path[1024];
1428 char wav_path[1024];
1429 char *zz[SAMPLE_MAX];
1432 /* Access the music.cfg */
1434 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1436 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1438 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1440 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1442 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1444 for (j = 0; j < num; j++)
1446 /* Access the sound */
1447 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1449 /* Save the sound filename, if it exists */
1450 if (check_file(wav_path))
1451 music_file[i][j] = string_make(zz[j]);
1455 for (i = 0; i < max_d_idx; i++)
1457 sprintf(key, "dungeon%03d", i);
1458 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1460 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1462 for (j = 0; j < num; j++)
1464 /* Access the sound */
1465 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1467 /* Save the sound filename, if it exists */
1468 if (check_file(wav_path))
1469 dungeon_music_file[i][j] = string_make(zz[j]);
1473 for (i = 0; i < max_q_idx; i++)
1475 sprintf(key, "quest%03d", i);
1476 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1478 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1480 for (j = 0; j < num; j++)
1482 /* Access the sound */
1483 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1485 /* Save the sound filename, if it exists */
1486 if (check_file(wav_path))
1487 quest_music_file[i][j] = string_make(zz[j]);
1491 for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1493 sprintf(key, "town%03d", i);
1494 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1496 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1498 for (j = 0; j < num; j++)
1500 /* Access the sound */
1501 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1503 /* Save the sound filename, if it exists */
1504 if (check_file(wav_path))
1505 town_music_file[i][j] = string_make(zz[j]);
1512 #endif /* USE_MUSIC */
1515 * Create the new global palette based on the bitmap palette
1516 * (if any), and the standard 16 entry palette derived from
1517 * "win_clr[]" which is used for the basic 16 Angband colors.
1519 * This function is never called before all windows are ready.
1521 * This function returns FALSE if the new palette could not be
1522 * prepared, which should normally be a fatal error. XXX XXX
1524 * Note that only some machines actually use a "palette".
1526 static int new_palette(void)
1534 LPLOGPALETTE pLogPal;
1535 LPPALETTEENTRY lppe;
1540 /* This makes no sense */
1541 if (!paletted) return (TRUE);
1551 /* Check the bitmap palette */
1552 hBmPal = infGraph.hPalette;
1554 /* Use the bitmap */
1557 lppeSize = 256 * sizeof(PALETTEENTRY);
1558 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1559 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1560 if ((nEntries == 0) || (nEntries > 220))
1563 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1566 rnfree(lppe, lppeSize);
1573 #endif /* USE_GRAPHICS */
1575 /* Size of palette */
1576 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1578 /* Allocate palette */
1579 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1582 pLogPal->palVersion = 0x300;
1584 /* Make room for bitmap and normal data */
1585 pLogPal->palNumEntries = nEntries + 16;
1587 /* Save the bitmap data */
1588 for (i = 0; i < nEntries; i++)
1590 pLogPal->palPalEntry[i] = lppe[i];
1593 /* Save the normal data */
1594 for (i = 0; i < 16; i++)
1598 /* Access the entry */
1599 p = &(pLogPal->palPalEntry[i+nEntries]);
1601 /* Save the colors */
1602 p->peRed = GetRValue(win_clr[i]);
1603 p->peGreen = GetGValue(win_clr[i]);
1604 p->peBlue = GetBValue(win_clr[i]);
1606 /* Save the flags */
1607 p->peFlags = PC_NOCOLLAPSE;
1610 /* Free something */
1611 if (lppe) rnfree(lppe, lppeSize);
1613 /* Create a new palette, or fail */
1614 hNewPal = CreatePalette(pLogPal);
1615 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1617 /* Free the palette */
1618 rnfree(pLogPal, pLogPalSize);
1623 /* Realize the palette */
1625 SelectPalette(hdc, hNewPal, 0);
1626 i = RealizePalette(hdc);
1627 ReleaseDC(td->w, hdc);
1628 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1632 for (i = 1; i < MAX_TERM_DATA; i++)
1637 SelectPalette(hdc, hNewPal, 0);
1638 ReleaseDC(td->w, hdc);
1641 /* Delete old palette */
1642 if (hPal) DeleteObject(hPal);
1644 /* Save new palette */
1654 * @brief グラフィクスを初期化する / Initialize graphics
1657 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1658 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1661 static bool init_graphics(void)
1663 /* Initialize once */
1665 BYTE wid, hgt, twid, thgt, ox, oy;
1668 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1678 ANGBAND_GRAF = "new";
1680 else if (arg_graphics == GRAPHICS_HENGBAND)
1700 ANGBAND_GRAF = "ne2";
1711 ANGBAND_GRAF = "old";
1714 /* Access the bitmap file */
1715 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1717 /* Load the bitmap or quit */
1718 if (!ReadDIB(data[0].w, buf, &infGraph))
1720 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1724 /* Save the new sizes */
1725 infGraph.CellWidth = wid;
1726 infGraph.CellHeight = hgt;
1727 infGraph.TileWidth = twid;
1728 infGraph.TileHeight = thgt;
1729 infGraph.OffsetX = ox;
1730 infGraph.OffsetY = oy;
1732 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1734 /* Access the mask file */
1735 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1737 /* Load the bitmap or quit */
1738 if (!ReadDIB(data[0].w, buf, &infMask))
1740 plog_fmt("Cannot read bitmap file '%s'", buf);
1744 if (arg_graphics == GRAPHICS_HENGBAND)
1746 /* Access the mask file */
1747 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1749 /* Load the bitmap or quit */
1750 if (!ReadDIB(data[0].w, buf, &infMask))
1752 plog_fmt("Cannot read bitmap file '%s'", buf);
1757 /* Activate a palette */
1762 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1766 /* Graphics available */
1767 current_graphics_mode = arg_graphics;
1768 return (current_graphics_mode);
1770 #endif /* USE_GRAPHICS */
1777 static bool init_music(void)
1779 /* Initialize once */
1782 /* Load the prefs */
1785 /* Sound available */
1786 can_use_music = TRUE;
1788 return (can_use_music);
1792 * Hack -- Stop a music
1794 static void stop_music(void)
1796 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1797 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1800 #endif /* USE_MUSIC */
1806 static bool init_sound(void)
1808 /* Initialize once */
1811 /* Load the prefs */
1814 /* Sound available */
1815 can_use_sound = TRUE;
1817 return (can_use_sound);
1819 #endif /* USE_SOUND */
1825 static void term_window_resize(term_data *td)
1827 /* Require window */
1830 /* Resize the window */
1831 SetWindowPos(td->w, 0, 0, 0,
1832 td->size_wid, td->size_hgt,
1833 SWP_NOMOVE | SWP_NOZORDER);
1836 InvalidateRect(td->w, NULL, TRUE);
1841 * Force the use of a new "font file" for a term_data
1843 * This function may be called before the "window" is ready
1845 * This function returns zero only if everything succeeds.
1847 * Note that the "font name" must be capitalized!!!
1849 static errr term_force_font(term_data *td, concptr path)
1853 #if 0 /* #ifndef JP */
1859 /* Forget the old font (if needed) */
1860 if (td->font_id) DeleteObject(td->font_id);
1862 #if 1 /* #ifdef JP */
1866 /* Create the font (using the 'base' of the font file name!) */
1867 td->font_id = CreateFontIndirect(&(td->lf));
1868 wid = td->lf.lfWidth;
1869 hgt = td->lf.lfHeight;
1870 if (!td->font_id) return (1);
1872 /* Forget old font */
1878 for (i = 0; i < MAX_TERM_DATA; i++)
1880 /* Don't check when closing the application */
1883 /* Check "screen" */
1884 if ((td != &data[i]) &&
1885 (data[i].font_file) &&
1886 (streq(data[i].font_file, td->font_file)))
1892 /* Remove unused font resources */
1893 if (!used) RemoveFontResource(td->font_file);
1895 /* Free the old name */
1896 string_free(td->font_file);
1899 td->font_file = NULL;
1903 if (!path) return (1);
1908 /* Analyze font path */
1909 base = analyze_font(buf, &wid, &hgt);
1912 if (!suffix(base, ".FON")) return (1);
1915 if (!check_file(buf)) return (1);
1917 /* Load the new font */
1918 if (!AddFontResource(buf)) return (1);
1920 /* Save new font name */
1921 td->font_file = string_make(base);
1923 /* Remove the "suffix" */
1924 base[strlen(base)-4] = '\0';
1926 /* Create the font (using the 'base' of the font file name!) */
1927 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1928 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1929 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1930 FIXED_PITCH | FF_DONTCARE, base);
1933 /* Hack -- Unknown size */
1940 /* all this trouble to get the cell size */
1941 hdcDesktop = GetDC(HWND_DESKTOP);
1942 hfOld = SelectObject(hdcDesktop, td->font_id);
1943 GetTextMetrics(hdcDesktop, &tm);
1944 SelectObject(hdcDesktop, hfOld);
1945 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1947 /* Font size info */
1948 wid = tm.tmAveCharWidth;
1952 /* Save the size info */
1963 * Allow the user to change the font for this window.
1965 static void term_change_font(term_data *td)
1967 #if 1 /* #ifdef JP */
1970 memset(&cf, 0, sizeof(cf));
1971 cf.lStructSize = sizeof(cf);
1972 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1973 cf.lpLogFont = &(td->lf);
1975 if (ChooseFont(&cf))
1977 /* Force the font */
1978 term_force_font(td, NULL);
1980 /* Assume not bizarre */
1983 /* Reset the tile info */
1984 td->tile_wid = td->font_wid;
1985 td->tile_hgt = td->font_hgt;
1987 /* Analyze the font */
1990 /* Resize the window */
1991 term_window_resize(td);
1997 char tmp[1024] = "";
1999 /* Extract a default if possible */
2000 if (td->font_file) strcpy(tmp, td->font_file);
2002 /* Ask for a choice */
2003 memset(&ofn, 0, sizeof(ofn));
2004 ofn.lStructSize = sizeof(ofn);
2005 ofn.hwndOwner = data[0].w;
2006 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
2007 ofn.nFilterIndex = 1;
2008 ofn.lpstrFile = tmp;
2010 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
2011 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2012 ofn.lpstrDefExt = "fon";
2014 /* Force choice if legal */
2015 if (GetOpenFileName(&ofn))
2017 /* Force the font */
2018 if (term_force_font(td, tmp))
2020 /* Access the standard font file */
2021 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2023 /* Force the use of that font */
2024 (void)term_force_font(td, tmp);
2027 /* Assume not bizarre */
2028 td->bizarre = FALSE;
2030 /* Reset the tile info */
2031 td->tile_wid = td->font_wid;
2032 td->tile_hgt = td->font_hgt;
2034 /* Analyze the font */
2037 /* Resize the window */
2038 term_window_resize(td);
2045 * Allow the user to lock this window.
2047 static void term_window_pos(term_data *td, HWND hWnd)
2049 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2050 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2053 static void windows_map(void);
2056 * Hack -- redraw a term_data
2058 static void term_data_redraw(term_data *td)
2062 /* Redraw the map */
2067 /* Activate the term */
2068 Term_activate(&td->t);
2070 /* Redraw the contents */
2073 /* Restore the term */
2074 Term_activate(term_screen);
2079 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2083 HBRUSH myBrush, oldBrush;
2085 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2086 int tx = td->size_ow1 + x * td->tile_wid;
2087 int ty = td->size_oh1 + y * td->tile_hgt;
2088 int tw = w * td->tile_wid - 1;
2089 int th = h * td->tile_hgt - 1;
2092 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2093 oldBrush = SelectObject(hdc, myBrush);
2094 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2096 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2098 SelectObject(hdc, oldBrush);
2099 SelectObject(hdc, oldPen);
2104 /*** Function hooks needed by "Term" ***/
2110 * Initialize a new Term
2112 static void Term_init_win(term *t)
2121 static void Term_nuke_win(term *t)
2130 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
2132 static errr Term_user_win(int n)
2143 * React to global changes
2145 static errr Term_xtra_win_react(void)
2152 /* Save the default colors */
2153 for (i = 0; i < 256; i++)
2155 /* Simply accept the desired colors */
2156 win_pal[i] = angband_color_table[i][0];
2167 bool change = FALSE;
2169 /* Save the default colors */
2170 for (i = 0; i < 256; i++)
2172 /* Extract desired values */
2173 rv = angband_color_table[i][1];
2174 gv = angband_color_table[i][2];
2175 bv = angband_color_table[i][3];
2177 /* Extract a full color code */
2178 code = PALETTERGB(rv, gv, bv);
2180 /* Activate changes */
2181 if (win_clr[i] != code)
2183 /* Note the change */
2186 /* Apply the desired color */
2191 /* Activate the palette if needed */
2192 if (change) (void)new_palette();
2198 /* Handle "arg_sound" */
2199 if (use_sound != arg_sound)
2201 /* Initialize (if needed) */
2202 if (arg_sound && !init_sound())
2205 plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
2211 /* Change setting */
2212 use_sound = arg_sound;
2219 /* Handle "arg_sound" */
2220 if (use_music != arg_music)
2222 /* Initialize (if needed) */
2223 if (arg_music && !init_music())
2226 plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
2231 /* Change setting */
2232 use_music = arg_music;
2234 if(!arg_music) stop_music();
2235 else select_floor_music();
2244 /* Handle "arg_graphics" */
2245 if (use_graphics != arg_graphics)
2247 /* Initialize (if needed) */
2248 if (arg_graphics && !init_graphics())
2251 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
2254 arg_graphics = GRAPHICS_NONE;
2257 /* Change setting */
2258 use_graphics = arg_graphics;
2261 #ifdef ANGBAND_2_8_1
2263 #else /* ANGBAND_2_8_1 */
2264 reset_visuals(TRUE);
2265 #endif /* ANGBAND_2_8_1 */
2268 #endif /* USE_GRAPHICS */
2271 /* Clean up windows */
2272 for (i = 0; i < MAX_TERM_DATA; i++)
2276 term_data *td = &data[i];
2278 /* Update resized windows */
2279 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
2282 Term_activate(&td->t);
2284 /* Hack -- Resize the term */
2285 Term_resize(td->cols, td->rows);
2287 /* Redraw the contents */
2300 * Process at least one event
2302 static errr Term_xtra_win_event(int v)
2306 /* Wait for an event */
2310 if (GetMessage(&msg, NULL, 0, 0))
2312 TranslateMessage(&msg);
2313 DispatchMessage(&msg);
2317 /* Check for an event */
2321 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2323 TranslateMessage(&msg);
2324 DispatchMessage(&msg);
2334 * Process all pending events
2336 static errr Term_xtra_win_flush(void)
2340 /* Process all pending events */
2341 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2343 TranslateMessage(&msg);
2344 DispatchMessage(&msg);
2353 * Hack -- clear the screen
2355 * Make this more efficient
2357 static errr Term_xtra_win_clear(void)
2359 term_data *td = (term_data*)(Term->data);
2364 /* Rectangle to erase */
2365 rc.left = td->size_ow1;
2366 rc.right = rc.left + td->cols * td->tile_wid;
2367 rc.top = td->size_oh1;
2368 rc.bottom = rc.top + td->rows * td->tile_hgt;
2372 SetBkColor(hdc, RGB(0, 0, 0));
2373 SelectObject(hdc, td->font_id);
2374 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2379 rc.left = 0; rc.top = 0;
2382 ReleaseDC(td->w, hdc);
2390 * Hack -- make a noise
2392 static errr Term_xtra_win_noise(void)
2394 MessageBeep(MB_ICONASTERISK);
2400 * Hack -- make a sound
2402 static errr Term_xtra_win_sound(int v)
2407 #endif /* USE_SOUND */
2409 /* Sound disabled */
2410 if (!use_sound) return (1);
2413 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2417 /* Count the samples */
2418 for (i = 0; i < SAMPLE_MAX; i++)
2420 if (!sound_file[v][i])
2425 if (i == 0) return (1);
2427 /* Build the path */
2428 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2432 /* Play the sound, catch errors */
2433 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2437 /* Play the sound, catch errors */
2438 return (sndPlaySound(buf, SND_ASYNC));
2442 #else /* USE_SOUND */
2446 #endif /* USE_SOUND */
2450 * Hack -- play a music
2452 static errr Term_xtra_win_music(int n, int v)
2457 #endif /* USE_MUSIC */
2459 /* Sound disabled */
2461 if(!use_music) return (1);
2464 if(n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return (1);
2465 else if(v < 0 || v >= 1000) return(1); /*!< TODO */
2471 case TERM_XTRA_MUSIC_BASIC:
2472 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2474 case TERM_XTRA_MUSIC_DUNGEON:
2475 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2477 case TERM_XTRA_MUSIC_QUEST:
2478 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2480 case TERM_XTRA_MUSIC_TOWN:
2481 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2488 //mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2489 //mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2495 case TERM_XTRA_MUSIC_BASIC:
2496 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2498 case TERM_XTRA_MUSIC_DUNGEON:
2499 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2501 case TERM_XTRA_MUSIC_QUEST:
2502 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2504 case TERM_XTRA_MUSIC_TOWN:
2505 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2512 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2513 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2519 case TERM_XTRA_MUSIC_BASIC:
2520 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2522 case TERM_XTRA_MUSIC_DUNGEON:
2523 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2525 case TERM_XTRA_MUSIC_QUEST:
2526 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2528 case TERM_XTRA_MUSIC_TOWN:
2529 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2533 if(current_music_type == n && current_music_id == v)
2537 current_music_type = n;
2538 current_music_id = v;
2542 mop.lpstrDeviceType = mci_device_type;
2543 mop.lpstrElementName = buf;
2544 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2545 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2546 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2547 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2548 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2553 #else /* USE_MUSIC */
2557 #endif /* USE_MUSIC */
2563 * Delay for "x" milliseconds
2565 static int Term_xtra_win_delay(int v)
2579 t = GetTickCount() + v;
2582 while (GetTickCount() < t)
2584 /* Handle messages */
2585 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2587 TranslateMessage(&msg);
2588 DispatchMessage(&msg);
2600 * Do a "special thing"
2602 static errr Term_xtra_win(int n, int v)
2604 /* Handle a subset of the legal requests */
2607 /* Make a bell sound */
2608 case TERM_XTRA_NOISE:
2610 return (Term_xtra_win_noise());
2614 case TERM_XTRA_MUSIC_BASIC:
2615 case TERM_XTRA_MUSIC_DUNGEON:
2616 case TERM_XTRA_MUSIC_QUEST:
2617 case TERM_XTRA_MUSIC_TOWN:
2619 return (Term_xtra_win_music(n, v));
2622 /* Make a special sound */
2623 case TERM_XTRA_SOUND:
2625 return (Term_xtra_win_sound(v));
2628 /* Process random events */
2629 case TERM_XTRA_BORED:
2631 return (Term_xtra_win_event(0));
2634 /* Process an event */
2635 case TERM_XTRA_EVENT:
2637 return (Term_xtra_win_event(v));
2640 /* Flush all events */
2641 case TERM_XTRA_FLUSH:
2643 return (Term_xtra_win_flush());
2646 /* Clear the screen */
2647 case TERM_XTRA_CLEAR:
2649 return (Term_xtra_win_clear());
2652 /* React to global changes */
2653 case TERM_XTRA_REACT:
2655 return (Term_xtra_win_react());
2658 /* Delay for some milliseconds */
2659 case TERM_XTRA_DELAY:
2661 return (Term_xtra_win_delay(v));
2671 * Low level graphics (Assumes valid input).
2673 * Draw a "cursor" at (x,y), using a "yellow box".
2675 static errr Term_curs_win(int x, int y)
2677 term_data *td = (term_data*)(Term->data);
2682 int tile_wid, tile_hgt;
2686 tile_wid = td->map_tile_wid;
2687 tile_hgt = td->map_tile_hgt;
2691 tile_wid = td->tile_wid;
2692 tile_hgt = td->tile_hgt;
2695 /* Frame the grid */
2696 rc.left = x * tile_wid + td->size_ow1;
2697 rc.right = rc.left + tile_wid;
2698 rc.top = y * tile_hgt + td->size_oh1;
2699 rc.bottom = rc.top + tile_hgt;
2701 /* Cursor is done as a yellow "box" */
2703 FrameRect(hdc, &rc, hbrYellow);
2704 ReleaseDC(td->w, hdc);
2712 * Low level graphics (Assumes valid input).
2714 * Draw a "big cursor" at (x,y), using a "yellow box".
2716 static errr Term_bigcurs_win(int x, int y)
2718 term_data *td = (term_data*)(Term->data);
2723 int tile_wid, tile_hgt;
2727 /* Normal cursor in map window */
2728 Term_curs_win(x, y);
2733 tile_wid = td->tile_wid;
2734 tile_hgt = td->tile_hgt;
2737 /* Frame the grid */
2738 rc.left = x * tile_wid + td->size_ow1;
2739 rc.right = rc.left + 2 * tile_wid;
2740 rc.top = y * tile_hgt + td->size_oh1;
2741 rc.bottom = rc.top + tile_hgt;
2743 /* Cursor is done as a yellow "box" */
2745 FrameRect(hdc, &rc, hbrYellow);
2746 ReleaseDC(td->w, hdc);
2754 * Low level graphics (Assumes valid input).
2756 * Erase a "block" of "n" characters starting at (x,y).
2758 static errr Term_wipe_win(int x, int y, int n)
2760 term_data *td = (term_data*)(Term->data);
2765 /* Rectangle to erase in client coords */
2766 rc.left = x * td->tile_wid + td->size_ow1;
2767 rc.right = rc.left + n * td->tile_wid;
2768 rc.top = y * td->tile_hgt + td->size_oh1;
2769 rc.bottom = rc.top + td->tile_hgt;
2772 SetBkColor(hdc, RGB(0, 0, 0));
2773 SelectObject(hdc, td->font_id);
2778 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2779 ReleaseDC(td->w, hdc);
2787 * Low level graphics. Assumes valid input.
2789 * Draw several ("n") chars, with an attr, at a given location.
2791 * All "graphic" data is handled by "Term_pict_win()", below.
2793 * One would think there is a more efficient method for telling a window
2794 * what color it should be using to draw with, but perhaps simply changing
2795 * it every time is not too inefficient.
2797 static errr Term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
2799 term_data *td = (term_data*)(Term->data);
2803 #if 1 /* #ifdef JP */
2804 static HBITMAP WALL;
2805 static HBRUSH myBrush, oldBrush;
2807 static bool init_done = FALSE;
2810 WALL = LoadBitmap(hInstance, AppName);
2811 myBrush = CreatePatternBrush(WALL);
2816 /* Total rectangle */
2817 rc.left = x * td->tile_wid + td->size_ow1;
2818 rc.right = rc.left + n * td->tile_wid;
2819 rc.top = y * td->tile_hgt + td->size_oh1;
2820 rc.bottom = rc.top + td->tile_hgt;
2825 /* Background color */
2826 SetBkColor(hdc, RGB(0, 0, 0));
2828 /* Foreground color */
2831 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2835 SetTextColor(hdc, win_clr[a&0x0F]);
2839 SetTextColor(hdc, win_clr[a]);
2843 SelectObject(hdc, td->font_id);
2846 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2850 (td->tile_hgt != td->font_hgt) ||
2851 (td->tile_wid != td->font_wid))
2855 /* Erase complete rectangle */
2856 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2859 if (use_bg) DrawBG(hdc, &rc);
2862 rc.left += ((td->tile_wid - td->font_wid) / 2);
2863 rc.right = rc.left + td->font_wid;
2864 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2865 rc.bottom = rc.top + td->font_hgt;
2867 /* Dump each character */
2868 for (i = 0; i < n; i++)
2871 if (use_bigtile && *(s+i)=="■"[0] && *(s+i+1)=="■"[1])
2873 rc.right += td->font_wid;
2875 oldBrush = SelectObject(hdc, myBrush);
2876 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2879 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2881 SelectObject(hdc, oldBrush);
2882 SelectObject(hdc, oldPen);
2883 rc.right -= td->font_wid;
2887 rc.left += 2 * td->tile_wid;
2888 rc.right += 2 * td->tile_wid;
2890 else if ( iskanji(*(s+i)) ) /* 2バイト文字 */
2892 rc.right += td->font_wid;
2894 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2896 rc.right -= td->font_wid;
2900 rc.left += 2 * td->tile_wid;
2901 rc.right += 2 * td->tile_wid;
2902 } else if (*(s+i)==127){
2903 oldBrush = SelectObject(hdc, myBrush);
2904 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2907 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2909 SelectObject(hdc, oldBrush);
2910 SelectObject(hdc, oldPen);
2913 rc.left += td->tile_wid;
2914 rc.right += td->tile_wid;
2917 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2920 rc.left += td->tile_wid;
2921 rc.right += td->tile_wid;
2926 oldBrush = SelectObject(hdc, myBrush);
2927 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2930 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2932 SelectObject(hdc, oldBrush);
2933 SelectObject(hdc, oldPen);
2936 rc.left += td->tile_wid;
2937 rc.right += td->tile_wid;
2940 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2944 rc.left += td->tile_wid;
2945 rc.right += td->tile_wid;
2949 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2953 rc.left += td->tile_wid;
2954 rc.right += td->tile_wid;
2965 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2970 ReleaseDC(td->w, hdc);
2978 * Low level graphics. Assumes valid input.
2980 * Draw an array of "special" attr/char pairs at the given location.
2982 * We use the "Term_pict_win()" function for "graphic" data, which are
2983 * encoded by setting the "high-bits" of both the "attr" and the "char"
2984 * data. We use the "attr" to represent the "row" of the main bitmap,
2985 * and the "char" to represent the "col" of the main bitmap. The use
2986 * of this function is induced by the "higher_pict" flag.
2988 * If "graphics" is not available, we simply "wipe" the given grids.
2990 static errr Term_pict_win(TERM_LEN x, TERM_LEN y, int n, const TERM_COLOR *ap, concptr cp, const TERM_COLOR *tap, concptr tcp)
2992 term_data *td = (term_data*)(Term->data);
2997 TERM_LEN x1, y1, w1, h1, tw1, th1;
2998 TERM_LEN x2, y2, w2, h2, tw2 = 0;
3010 /* Erase the grids */
3011 return (Term_wipe_win(x, y, n));
3014 /* Size of bitmap cell */
3015 w1 = infGraph.CellWidth;
3016 h1 = infGraph.CellHeight;
3017 tw1 = infGraph.TileWidth;
3018 th1 = infGraph.TileHeight;
3020 /* Size of window cell */
3023 w2 = td->map_tile_wid;
3024 h2 = td->map_tile_hgt;
3033 if (use_bigtile) tw2 *= 2;
3036 /* Location of window cell */
3037 x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
3038 y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
3044 hdcSrc = CreateCompatibleDC(hdc);
3045 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
3047 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3049 hdcMask = CreateCompatibleDC(hdc);
3050 SelectObject(hdcMask, infMask.hBitmap);
3053 /* Draw attr/char pairs */
3054 for (i = 0; i < n; i++, x2 += w2)
3056 TERM_COLOR a = ap[i];
3060 /* Extract picture */
3061 int row = (a & 0x7F);
3062 int col = (c & 0x7F);
3064 /* Location of bitmap cell */
3068 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3070 x3 = (tcp[i] & 0x7F) * w1;
3071 y3 = (tap[i] & 0x7F) * h1;
3072 tw2 = tw2 * w1 / tw1;
3076 if ((tw1 == tw2) && (th1 == h2))
3078 /* Copy the terrain picture from the bitmap to the window */
3079 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
3081 /* Mask out the tile */
3082 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3085 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3088 /* Need to stretch */
3091 /* Set the correct mode for stretching the tiles */
3092 SetStretchBltMode(hdc, COLORONCOLOR);
3094 /* Copy the terrain picture from the bitmap to the window */
3095 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
3097 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
3099 /* Only draw if terrain and overlay are different */
3100 if ((x1 != x3) || (y1 != y3))
3102 /* Mask out the tile */
3103 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3106 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3113 if ((w1 == tw2) && (h1 == h2))
3115 /* Copy the picture from the bitmap to the window */
3116 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3119 /* Need to stretch */
3122 /* Set the correct mode for stretching the tiles */
3123 SetStretchBltMode(hdc, COLORONCOLOR);
3125 /* Copy the picture from the bitmap to the window */
3126 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3132 SelectObject(hdcSrc, hbmSrcOld);
3135 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3138 SelectObject(hdcMask, hbmSrcOld);
3143 ReleaseDC(td->w, hdc);
3145 #else /* USE_GRAPHICS */
3147 /* Just erase this grid */
3148 return (Term_wipe_win(x, y, n));
3150 #endif /* USE_GRAPHICS */
3157 static void windows_map(void)
3159 term_data *td = &data[0];
3162 TERM_LEN x, min_x, max_x;
3163 TERM_LEN y, min_y, max_y;
3168 /* Only in graphics mode */
3169 if (!use_graphics) return;
3170 Term_xtra_win_clear();
3172 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3173 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3174 td->map_active = TRUE;
3184 for (x = min_x; x < max_x; x++)
3186 for (y = min_y; y < max_y; y++)
3188 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3190 /* Ignore non-graphics */
3191 if ((a & 0x80) && (c & 0x80))
3193 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3198 /* Hilite the player */
3199 Term_curs_win(p_ptr->x - min_x, p_ptr->y - min_y);
3201 /* Wait for a keypress, flush key buffer */
3202 Term_inkey(&c, TRUE, TRUE);
3205 /* Switch off the map display */
3206 td->map_active = FALSE;
3208 /* Restore screen */
3209 Term_xtra_win_clear();
3214 /*** Other routines ***/
3218 * Create and initialize a "term_data" given a title
3220 static void term_data_link(term_data *td)
3224 /* Initialize the term */
3225 term_init(t, td->cols, td->rows, td->keys);
3227 /* Use a "software" cursor */
3228 t->soft_cursor = TRUE;
3230 /* Use "Term_pict" for "graphic" data */
3231 t->higher_pict = TRUE;
3233 /* Erase with "white space" */
3234 t->attr_blank = TERM_WHITE;
3235 t->char_blank = ' ';
3238 /* Prepare the init/nuke hooks */
3239 t->init_hook = Term_init_win;
3240 t->nuke_hook = Term_nuke_win;
3243 /* Prepare the template hooks */
3244 t->user_hook = Term_user_win;
3245 t->xtra_hook = Term_xtra_win;
3246 t->curs_hook = Term_curs_win;
3247 t->bigcurs_hook = Term_bigcurs_win;
3248 t->wipe_hook = Term_wipe_win;
3249 t->text_hook = Term_text_win;
3250 t->pict_hook = Term_pict_win;
3252 /* Remember where we came from */
3253 t->data = (vptr)(td);
3258 * Create the windows
3260 * First, instantiate the "default" values, then read the "ini_file"
3261 * to over-ride selected values, then create the windows, and fonts.
3263 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3264 * must make active to realize the palette.
3266 static void init_windows(void)
3272 #if 0 /* #ifndef JP */
3278 WIPE(td, term_data);
3282 td->s = angband_term_name[0];
3296 #if 1 /* #ifdef JP */
3300 for (i = 1; i < MAX_TERM_DATA; i++)
3303 WIPE(td, term_data);
3304 td->s = angband_term_name[i];
3308 td->visible = FALSE;
3313 td->pos_x = (7 - i) * 30;
3314 td->pos_y = (7 - i) * 20;
3316 #if 1 /* #ifdef JP */
3326 /* Main window (need these before term_getsize gets called) */
3328 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3329 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3334 /* Sub windows (need these before term_getsize gets called) */
3335 for (i = 1; i < MAX_TERM_DATA; i++)
3338 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3339 td->dwExStyle = (WS_EX_TOOLWINDOW);
3344 for (i = 0; i < MAX_TERM_DATA; i++)
3348 #if 1 /* #ifdef JP */
3349 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3350 td->lf.lfCharSet = DEFAULT_CHARSET;
3351 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3352 /* Activate the chosen font */
3353 term_force_font(td, NULL);
3354 if(!td->tile_wid) td->tile_wid = td->font_wid;
3355 if(!td->tile_hgt) td->tile_hgt = td->font_hgt;
3357 /* Access the standard font file */
3358 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3360 /* Activate the chosen font */
3361 if (term_force_font(td, buf))
3363 /* Access the standard font file */
3364 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3366 /* Force the use of that font */
3367 (void)term_force_font(td, buf);
3372 /* Assume not bizarre */
3373 td->bizarre = FALSE;
3378 /* Analyze the font */
3381 /* Resize the window */
3382 term_window_resize(td);
3386 /* Sub windows (reverse order) */
3387 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3392 td->w = CreateWindowEx(td->dwExStyle, AngList,
3394 td->pos_x, td->pos_y,
3395 td->size_wid, td->size_hgt,
3396 HWND_DESKTOP, NULL, hInstance, NULL);
3398 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3402 td->size_hack = TRUE;
3403 ShowWindow(td->w, SW_SHOW);
3404 td->size_hack = FALSE;
3408 angband_term[i] = &td->t;
3412 /* Activate the window */
3413 SetActiveWindow(td->w);
3418 term_window_pos(&data[i], HWND_TOPMOST);
3422 term_window_pos(&data[i], td->w);
3432 td->w = CreateWindowEx(td->dwExStyle, AppName,
3434 td->pos_x, td->pos_y,
3435 td->size_wid, td->size_hgt,
3436 HWND_DESKTOP, NULL, hInstance, NULL);
3438 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3441 angband_term[0] = &td->t;
3442 normsize.x = td->cols;
3443 normsize.y = td->rows;
3445 /* Activate the main window */
3446 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3447 else ShowWindow(td->w, SW_SHOW);
3449 /* Bring main window back to top */
3450 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3454 (void)new_palette();
3457 /* Create a "brush" for drawing the "cursor" */
3458 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3461 /* Process pending messages */
3462 (void)Term_xtra_win_flush();
3470 static void setup_menus(void)
3474 HMENU hm = GetMenu(data[0].w);
3477 /* Menu "File", Disable all */
3478 EnableMenuItem(hm, IDM_FILE_NEW,
3479 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3480 EnableMenuItem(hm, IDM_FILE_OPEN,
3481 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3482 EnableMenuItem(hm, IDM_FILE_SAVE,
3483 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3484 EnableMenuItem(hm, IDM_FILE_EXIT,
3485 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3486 EnableMenuItem(hm, IDM_FILE_SCORE,
3487 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3490 /* No character available */
3491 if (!character_generated)
3493 /* Menu "File", Item "New" */
3494 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3496 /* Menu "File", Item "Open" */
3497 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3500 /* A character available */
3501 if (character_generated)
3503 /* Menu "File", Item "Save" */
3504 EnableMenuItem(hm, IDM_FILE_SAVE,
3505 MF_BYCOMMAND | MF_ENABLED);
3508 /* Menu "File", Item "Exit" */
3509 EnableMenuItem(hm, IDM_FILE_EXIT,
3510 MF_BYCOMMAND | MF_ENABLED);
3512 EnableMenuItem(hm, IDM_FILE_SCORE,
3513 MF_BYCOMMAND | MF_ENABLED);
3516 /* Menu "Window::Visibility" */
3517 for (i = 0; i < MAX_TERM_DATA; i++)
3519 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3520 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3522 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3523 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3525 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3526 MF_BYCOMMAND | MF_ENABLED);
3529 /* Menu "Window::Font" */
3530 for (i = 0; i < MAX_TERM_DATA; i++)
3532 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3533 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3535 if (data[i].visible)
3537 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3538 MF_BYCOMMAND | MF_ENABLED);
3542 /* Menu "Window::Window Position Fix" */
3543 for (i = 0; i < MAX_TERM_DATA; i++)
3545 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3546 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3548 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3549 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3551 if (data[i].visible)
3553 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3554 MF_BYCOMMAND | MF_ENABLED);
3558 /* Menu "Window::Bizarre Display" */
3559 for (i = 0; i < MAX_TERM_DATA; i++)
3561 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3562 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3564 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3565 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3567 if (data[i].visible)
3569 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3570 MF_BYCOMMAND | MF_ENABLED);
3575 /* Menu "Window::Increase Tile Width" */
3576 for (i = 0; i < MAX_TERM_DATA; i++)
3578 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3579 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3581 if (data[i].visible)
3583 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3584 MF_BYCOMMAND | MF_ENABLED);
3589 /* Menu "Window::Decrease Tile Width" */
3590 for (i = 0; i < MAX_TERM_DATA; i++)
3592 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3593 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3595 if (data[i].visible)
3597 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3598 MF_BYCOMMAND | MF_ENABLED);
3603 /* Menu "Window::Increase Tile Height" */
3604 for (i = 0; i < MAX_TERM_DATA; i++)
3606 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3607 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3609 if (data[i].visible)
3611 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3612 MF_BYCOMMAND | MF_ENABLED);
3617 /* Menu "Window::Decrease Tile Height" */
3618 for (i = 0; i < MAX_TERM_DATA; i++)
3620 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3621 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3623 if (data[i].visible)
3625 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3626 MF_BYCOMMAND | MF_ENABLED);
3631 /* Menu "Options", disable all */
3632 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3633 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3634 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3635 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3636 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3637 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3638 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3639 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3640 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3641 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3643 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3644 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3647 /* Menu "Options", Item "Map" */
3648 if (use_graphics != GRAPHICS_NONE)
3649 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3651 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3652 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3654 /* Menu "Options", update all */
3655 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3656 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3657 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3658 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3659 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3660 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3661 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3662 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3663 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3664 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3665 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3666 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3667 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3668 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3669 CheckMenuItem(hm, IDM_OPTIONS_BG,
3670 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3672 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3673 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3677 /* Menu "Options", Item "Graphics" */
3678 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3679 /* Menu "Options", Item "Graphics" */
3680 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3681 /* Menu "Options", Item "Graphics" */
3682 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3683 /* Menu "Options", Item "Graphics" */
3684 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3685 #endif /* USE_GRAPHICS */
3688 /* Menu "Options", Item "Sound" */
3689 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3690 #endif /* USE_SOUND */
3693 /* Menu "Options", Item "ScreenSaver" */
3694 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3695 MF_BYCOMMAND | MF_ENABLED);
3696 #endif /* USE_SAVER */
3701 * Check for double clicked (or dragged) savefile
3703 * Apparently, Windows copies the entire filename into the first
3704 * piece of the "command line string". Perhaps we should extract
3705 * the "basename" of that filename and append it to the "save" dir.
3707 static void check_for_save_file(LPSTR cmd_line)
3717 /* Extract filename */
3718 strcat(savefile, s);
3720 /* Validate the file */
3721 validate_file(savefile);
3723 /* Game in progress */
3724 game_in_progress = TRUE;
3732 * Process a menu command
3734 static void process_menus(WORD wCmd)
3750 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3752 else if (game_in_progress)
3754 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3758 game_in_progress = TRUE;
3771 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3773 else if (game_in_progress)
3775 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3779 memset(&ofn, 0, sizeof(ofn));
3780 ofn.lStructSize = sizeof(ofn);
3781 ofn.hwndOwner = data[0].w;
3782 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3783 ofn.nFilterIndex = 1;
3784 ofn.lpstrFile = savefile;
3785 ofn.nMaxFile = 1024;
3786 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3787 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3789 if (GetOpenFileName(&ofn))
3791 /* Load 'savefile' */
3792 validate_file(savefile);
3793 game_in_progress = TRUE;
3805 if (game_in_progress && character_generated)
3810 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3814 /* Hack -- Forget messages */
3819 do_cmd_save_game(FALSE);
3820 #else /* ZANGBAND */
3822 #endif /* ZANGBAND */
3826 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3834 if (game_in_progress && character_generated)
3839 plog(_("今は終了できません。", "You may not do that right now."));
3843 /* Hack -- Forget messages */
3852 /* do_cmd_save_game(FALSE); */
3853 #else /* ZANGBAND */
3854 /* do_cmd_save_game(); */
3855 #endif /* ZANGBAND */
3856 Term_key_push(SPECIAL_KEY_QUIT);
3864 case IDM_FILE_SCORE:
3868 /* Build the filename */
3869 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3871 /* Open the binary high score file, for reading */
3872 highscore_fd = fd_open(buf, O_RDONLY);
3874 /* Paranoia -- No score file */
3875 if (highscore_fd < 0)
3877 msg_print("Score file unavailable.");
3884 /* Display the scores */
3885 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3887 /* Shut the high score file */
3888 (void)fd_close(highscore_fd);
3890 /* Forget the high score fd */
3894 /* Hack - Flush it */
3902 case IDM_FILE_MOVIE:
3906 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3908 else if (game_in_progress)
3910 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
3914 memset(&ofn, 0, sizeof(ofn));
3915 ofn.lStructSize = sizeof(ofn);
3916 ofn.hwndOwner = data[0].w;
3917 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3918 ofn.nFilterIndex = 1;
3919 ofn.lpstrFile = savefile;
3920 ofn.nMaxFile = 1024;
3921 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3922 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3924 if (GetOpenFileName(&ofn))
3926 /* Load 'savefile' */
3927 prepare_browse_movie_aux(savefile);
3937 case IDM_WINDOW_VIS_0:
3939 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
3943 /* Window visibility */
3944 case IDM_WINDOW_VIS_1:
3945 case IDM_WINDOW_VIS_2:
3946 case IDM_WINDOW_VIS_3:
3947 case IDM_WINDOW_VIS_4:
3948 case IDM_WINDOW_VIS_5:
3949 case IDM_WINDOW_VIS_6:
3950 case IDM_WINDOW_VIS_7:
3952 i = wCmd - IDM_WINDOW_VIS_0;
3954 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3961 ShowWindow(td->w, SW_SHOW);
3962 term_data_redraw(td);
3966 td->visible = FALSE;
3968 ShowWindow(td->w, SW_HIDE);
3975 case IDM_WINDOW_FONT_0:
3976 case IDM_WINDOW_FONT_1:
3977 case IDM_WINDOW_FONT_2:
3978 case IDM_WINDOW_FONT_3:
3979 case IDM_WINDOW_FONT_4:
3980 case IDM_WINDOW_FONT_5:
3981 case IDM_WINDOW_FONT_6:
3982 case IDM_WINDOW_FONT_7:
3984 i = wCmd - IDM_WINDOW_FONT_0;
3986 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3990 term_change_font(td);
3995 /* Window Z Position */
3996 case IDM_WINDOW_POS_1:
3997 case IDM_WINDOW_POS_2:
3998 case IDM_WINDOW_POS_3:
3999 case IDM_WINDOW_POS_4:
4000 case IDM_WINDOW_POS_5:
4001 case IDM_WINDOW_POS_6:
4002 case IDM_WINDOW_POS_7:
4004 i = wCmd - IDM_WINDOW_POS_0;
4006 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4010 if (!td->posfix && td->visible)
4013 term_window_pos(td, HWND_TOPMOST);
4018 term_window_pos(td, data[0].w);
4024 /* Bizarre Display */
4025 case IDM_WINDOW_BIZ_0:
4026 case IDM_WINDOW_BIZ_1:
4027 case IDM_WINDOW_BIZ_2:
4028 case IDM_WINDOW_BIZ_3:
4029 case IDM_WINDOW_BIZ_4:
4030 case IDM_WINDOW_BIZ_5:
4031 case IDM_WINDOW_BIZ_6:
4032 case IDM_WINDOW_BIZ_7:
4034 i = wCmd - IDM_WINDOW_BIZ_0;
4036 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4040 td->bizarre = !td->bizarre;
4044 term_window_resize(td);
4049 /* Increase Tile Width */
4050 case IDM_WINDOW_I_WID_0:
4051 case IDM_WINDOW_I_WID_1:
4052 case IDM_WINDOW_I_WID_2:
4053 case IDM_WINDOW_I_WID_3:
4054 case IDM_WINDOW_I_WID_4:
4055 case IDM_WINDOW_I_WID_5:
4056 case IDM_WINDOW_I_WID_6:
4057 case IDM_WINDOW_I_WID_7:
4059 i = wCmd - IDM_WINDOW_I_WID_0;
4061 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4069 term_window_resize(td);
4074 /* Decrease Tile Height */
4075 case IDM_WINDOW_D_WID_0:
4076 case IDM_WINDOW_D_WID_1:
4077 case IDM_WINDOW_D_WID_2:
4078 case IDM_WINDOW_D_WID_3:
4079 case IDM_WINDOW_D_WID_4:
4080 case IDM_WINDOW_D_WID_5:
4081 case IDM_WINDOW_D_WID_6:
4082 case IDM_WINDOW_D_WID_7:
4084 i = wCmd - IDM_WINDOW_D_WID_0;
4086 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4094 term_window_resize(td);
4099 /* Increase Tile Height */
4100 case IDM_WINDOW_I_HGT_0:
4101 case IDM_WINDOW_I_HGT_1:
4102 case IDM_WINDOW_I_HGT_2:
4103 case IDM_WINDOW_I_HGT_3:
4104 case IDM_WINDOW_I_HGT_4:
4105 case IDM_WINDOW_I_HGT_5:
4106 case IDM_WINDOW_I_HGT_6:
4107 case IDM_WINDOW_I_HGT_7:
4109 i = wCmd - IDM_WINDOW_I_HGT_0;
4111 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4119 term_window_resize(td);
4124 /* Decrease Tile Height */
4125 case IDM_WINDOW_D_HGT_0:
4126 case IDM_WINDOW_D_HGT_1:
4127 case IDM_WINDOW_D_HGT_2:
4128 case IDM_WINDOW_D_HGT_3:
4129 case IDM_WINDOW_D_HGT_4:
4130 case IDM_WINDOW_D_HGT_5:
4131 case IDM_WINDOW_D_HGT_6:
4132 case IDM_WINDOW_D_HGT_7:
4134 i = wCmd - IDM_WINDOW_D_HGT_0;
4136 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4144 term_window_resize(td);
4149 case IDM_OPTIONS_NO_GRAPHICS:
4154 plog("You may not do that right now.");
4158 /* Toggle "arg_graphics" */
4159 if (arg_graphics != GRAPHICS_NONE)
4161 arg_graphics = GRAPHICS_NONE;
4163 /* React to changes */
4164 Term_xtra_win_react();
4166 /* Hack -- Force redraw */
4167 Term_key_push(KTRL('R'));
4173 case IDM_OPTIONS_OLD_GRAPHICS:
4178 plog("You may not do that right now.");
4182 /* Toggle "arg_graphics" */
4183 if (arg_graphics != GRAPHICS_ORIGINAL)
4185 arg_graphics = GRAPHICS_ORIGINAL;
4187 /* React to changes */
4188 Term_xtra_win_react();
4190 /* Hack -- Force redraw */
4191 Term_key_push(KTRL('R'));
4197 case IDM_OPTIONS_NEW_GRAPHICS:
4202 plog("You may not do that right now.");
4206 /* Toggle "arg_graphics" */
4207 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4209 arg_graphics = GRAPHICS_ADAM_BOLT;
4211 /* React to changes */
4212 Term_xtra_win_react();
4214 /* Hack -- Force redraw */
4215 Term_key_push(KTRL('R'));
4221 case IDM_OPTIONS_NEW2_GRAPHICS:
4226 plog("You may not do that right now.");
4230 /* Toggle "arg_graphics" */
4231 if (arg_graphics != GRAPHICS_HENGBAND)
4233 arg_graphics = GRAPHICS_HENGBAND;
4235 /* React to changes */
4236 Term_xtra_win_react();
4238 /* Hack -- Force redraw */
4239 Term_key_push(KTRL('R'));
4245 case IDM_OPTIONS_BIGTILE:
4252 plog("You may not do that right now.");
4256 /* Toggle "arg_sound" */
4257 arg_bigtile = !arg_bigtile;
4260 Term_activate(&td->t);
4262 /* Resize the term */
4263 Term_resize(td->cols, td->rows);
4266 InvalidateRect(td->w, NULL, TRUE);
4271 case IDM_OPTIONS_MUSIC:
4276 plog("You may not do that right now.");
4280 /* Toggle "arg_sound" */
4281 arg_music = !arg_music;
4283 /* React to changes */
4284 Term_xtra_win_react();
4286 /* Hack -- Force redraw */
4287 Term_key_push(KTRL('R'));
4292 case IDM_OPTIONS_SOUND:
4297 plog("You may not do that right now.");
4301 /* Toggle "arg_sound" */
4302 arg_sound = !arg_sound;
4304 /* React to changes */
4305 Term_xtra_win_react();
4307 /* Hack -- Force redraw */
4308 Term_key_push(KTRL('R'));
4314 case IDM_OPTIONS_BG:
4319 plog("You may not do that right now.");
4323 /* Toggle "use_bg" */
4328 /* React to changes */
4329 Term_xtra_win_react();
4331 /* Hack -- Force redraw */
4332 Term_key_push(KTRL('R'));
4338 case IDM_OPTIONS_OPEN_BG:
4343 plog("You may not do that right now.");
4348 memset(&ofn, 0, sizeof(ofn));
4349 ofn.lStructSize = sizeof(ofn);
4350 ofn.hwndOwner = data[0].w;
4351 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4352 ofn.nFilterIndex = 1;
4353 ofn.lpstrFile = bg_bitmap_file;
4354 ofn.nMaxFile = 1023;
4355 ofn.lpstrInitialDir = NULL;
4356 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
4357 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4359 if (GetOpenFileName(&ofn))
4361 /* Load 'savefile' */
4366 /* React to changes */
4367 Term_xtra_win_react();
4369 /* Hack -- Force redraw */
4370 Term_key_push(KTRL('R'));
4375 case IDM_DUMP_SCREEN_HTML:
4377 static char buf[1024] = "";
4378 memset(&ofn, 0, sizeof(ofn));
4379 ofn.lStructSize = sizeof(ofn);
4380 ofn.hwndOwner = data[0].w;
4381 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4382 ofn.nFilterIndex = 1;
4383 ofn.lpstrFile = buf;
4384 ofn.nMaxFile = 1023;
4385 ofn.lpstrDefExt = "html";
4386 ofn.lpstrInitialDir = NULL;
4387 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
4388 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4390 if (GetSaveFileName(&ofn))
4392 do_cmd_save_screen_html_aux(buf, 0);
4399 case IDM_OPTIONS_SAVER:
4403 DestroyWindow(hwndSaver);
4408 /* Create a screen scaver window */
4409 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4410 "Angband Screensaver",
4411 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4412 0, 0, GetSystemMetrics(SM_CXSCREEN),
4413 GetSystemMetrics(SM_CYSCREEN),
4414 NULL, NULL, hInstance, NULL);
4418 /* Push the window to the bottom */
4419 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4423 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
4431 case IDM_OPTIONS_MAP:
4437 case IDM_HELP_CONTENTS:
4441 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4442 if (check_file(tmp))
4444 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4448 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4449 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4452 #else /* HTML_HELP */
4455 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4456 if (check_file(tmp))
4458 sprintf(buf, "winhelp.exe %s", tmp);
4459 WinExec(buf, SW_NORMAL);
4463 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4464 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4468 #endif /* HTML_HELP */
4474 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4481 /* Extract the modifiers */
4482 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4483 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4484 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4486 Term_no_press = (ma) ? TRUE : FALSE;
4488 /* Handle "special" keys */
4489 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4491 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4492 bool numpad = FALSE;
4494 /* Begin the macro trigger */
4497 /* Send the modifiers */
4498 if (mc) Term_keypress('C');
4499 if (ms) Term_keypress('S');
4500 if (ma) Term_keypress('A');
4502 /* Extract "scan code" */
4503 i = LOBYTE(HIWORD(lParam));
4505 /* Introduce the scan code */
4508 /* Extended key bit */
4511 /* Numpad Enter and '/' are extended key */
4513 Term_no_press = TRUE;
4514 case VK_RETURN: /* Enter */
4517 /* Other extended keys are on full keyboard */
4533 Term_no_press = TRUE;
4537 case VK_PRIOR: /* Page Up */
4538 case VK_NEXT: /* Page Down */
4548 /* Special modifiers for keypad keys */
4549 if (numpad) Term_keypress('K');
4551 /* Encode the hexidecimal scan code */
4552 Term_keypress(hexsym[i/16]);
4553 Term_keypress(hexsym[i%16]);
4555 /* End the macro trigger */
4566 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4567 WPARAM wParam, LPARAM lParam);
4568 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4569 WPARAM wParam, LPARAM lParam)
4570 #else /* __MWERKS__ */
4571 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4572 #endif /* __MWERKS__ */
4578 MINMAXINFO FAR *lpmmi;
4584 /* Acquire proper "term_data" info */
4585 td = (term_data *)GetWindowLong(hWnd, 0);
4587 /* Handle message */
4592 SetWindowLong(hWnd, 0, (LONG)(my_td));
4599 mop.dwCallback=(DWORD)hWnd;
4604 case WM_GETMINMAXINFO:
4606 MINMAXINFO FAR *lpmmi;
4609 lpmmi = (MINMAXINFO FAR *)lParam;
4611 /* this message was sent before WM_NCCREATE */
4614 /* Minimum window size is 80x24 */
4615 rc.left = rc.top = 0;
4616 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4617 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4620 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4622 /* Save minimum size */
4623 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4624 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4631 BeginPaint(hWnd, &ps);
4632 if (td) term_data_redraw(td);
4633 EndPaint(hWnd, &ps);
4634 ValidateRect(hWnd, NULL);
4641 if(wParam == MCI_NOTIFY_SUCCESSFUL)
4643 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4644 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4653 if (process_keydown(wParam, lParam))
4660 if (Term_no_press) Term_no_press = FALSE;
4661 else Term_keypress(wParam);
4665 case WM_LBUTTONDOWN:
4667 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4668 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4680 TERM_LEN dx = abs(oldx - mousex) + 1;
4681 TERM_LEN dy = abs(oldy - mousey) + 1;
4682 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
4683 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
4693 hGlobal = GlobalAlloc(GHND, sz + 1);
4694 if (hGlobal == NULL) return 0;
4695 lpStr = (LPSTR)GlobalLock(hGlobal);
4697 for (i = 0; i < dy; i++)
4701 char **scr = data[0].t.scr->c;
4703 C_MAKE(s, (dx + 1), char);
4704 strncpy(s, &scr[oy + i][ox], dx);
4708 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4711 if (ox + dx < data[0].cols)
4713 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4716 for (j = 0; j < dx; j++)
4718 if (s[j] == 127) s[j] = '#';
4722 for (j = 0; j < dx; j++)
4724 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4734 GlobalUnlock(hGlobal);
4735 if (OpenClipboard(hWnd) == 0)
4737 GlobalFree(hGlobal);
4741 SetClipboardData(CF_TEXT, hGlobal);
4754 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4755 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4760 dx = abs(oldx - mousex) + 1;
4761 dy = abs(oldy - mousey) + 1;
4762 ox = (oldx > mousex) ? mousex : oldx;
4763 oy = (oldy > mousey) ? mousey : oldy;
4764 Term_inversed_area(hWnd, ox, oy, dx, dy);
4771 dx = abs(cx - mousex) + 1;
4772 dy = abs(cy - mousey) + 1;
4773 ox = (cx > mousex) ? mousex : cx;
4774 oy = (cy > mousey) ? mousey : cy;
4775 Term_inversed_area(hWnd, ox, oy, dx, dy);
4791 if (game_in_progress && character_generated)
4795 plog(_("今は終了できません。", "You may not do that right now."));
4799 /* Hack -- Forget messages */
4808 /* do_cmd_save_game(FALSE); */
4809 #else /* ZANGBAND */
4810 /* do_cmd_save_game(); */
4811 #endif /* ZANGBAND */
4812 Term_key_push(SPECIAL_KEY_QUIT);
4819 case WM_QUERYENDSESSION:
4821 if (game_in_progress && character_generated)
4823 /* Hack -- Forget messages */
4826 /* Mega-Hack -- Delay death */
4827 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4828 do_cmd_write_nikki(NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4830 /* Hardcode panic save */
4831 p_ptr->panic_save = 1;
4833 /* Forbid suspend */
4834 signals_ignore_tstp();
4836 /* Indicate panic save */
4837 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4840 (void)save_player();
4854 process_menus(LOWORD(wParam));
4860 /* this message was sent before WM_NCCREATE */
4863 /* it was sent from inside CreateWindowEx */
4864 if (!td->w) return 1;
4866 /* was sent from WM_SIZE */
4867 if (td->size_hack) return 1;
4871 case SIZE_MINIMIZED:
4873 /* Hide sub-windows */
4874 for (i = 1; i < MAX_TERM_DATA; i++)
4876 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4881 case SIZE_MAXIMIZED:
4888 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4889 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4892 if ((td->cols != cols) || (td->rows != rows))
4894 /* Save the new size */
4898 if (!IsZoomed(td->w) && !IsIconic(td->w))
4900 normsize.x = td->cols;
4901 normsize.y = td->rows;
4905 Term_activate(&td->t);
4907 /* Resize the term */
4908 Term_resize(td->cols, td->rows);
4911 InvalidateRect(td->w, NULL, TRUE);
4914 td->size_hack = TRUE;
4916 /* Show sub-windows */
4917 for (i = 1; i < MAX_TERM_DATA; i++)
4919 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4922 td->size_hack = FALSE;
4930 case WM_PALETTECHANGED:
4932 /* Ignore if palette change caused by itself */
4933 if ((HWND)wParam == hWnd) return 0;
4935 /* Fall through... */
4938 case WM_QUERYNEWPALETTE:
4940 if (!paletted) return 0;
4944 SelectPalette(hdc, hPal, FALSE);
4946 i = RealizePalette(hdc);
4948 /* if any palette entries changed, repaint the window. */
4949 if (i) InvalidateRect(hWnd, NULL, TRUE);
4951 ReleaseDC(hWnd, hdc);
4958 if (wParam && !HIWORD(lParam))
4960 /* Do something to sub-windows */
4961 for (i = 1; i < MAX_TERM_DATA; i++)
4963 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4966 /* Focus on main window */
4975 case WM_ACTIVATEAPP:
4977 if (IsIconic(td->w)) break;
4979 for (i = 1; i < MAX_TERM_DATA; i++)
4985 ShowWindow(data[i].w, SW_SHOW);
4989 ShowWindow(data[i].w, SW_HIDE);
4996 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5001 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5002 WPARAM wParam, LPARAM lParam);
5003 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5004 WPARAM wParam, LPARAM lParam)
5005 #else /* __MWERKS__ */
5006 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5007 WPARAM wParam, LPARAM lParam)
5008 #endif /* __MWERKS__ */
5012 MINMAXINFO FAR *lpmmi;
5020 /* Acquire proper "term_data" info */
5021 td = (term_data *)GetWindowLong(hWnd, 0);
5023 /* Process message */
5028 SetWindowLong(hWnd, 0, (LONG)(my_td));
5037 case WM_GETMINMAXINFO:
5039 MINMAXINFO FAR *lpmmi;
5042 lpmmi = (MINMAXINFO FAR *)lParam;
5044 /* this message was sent before WM_NCCREATE */
5047 /* Minimum window size is 80x24 */
5048 rc.left = rc.top = 0;
5049 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5050 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5053 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5055 /* Save minimum size */
5056 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5057 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5067 /* this message was sent before WM_NCCREATE */
5070 /* it was sent from inside CreateWindowEx */
5071 if (!td->w) return 1;
5073 /* was sent from inside WM_SIZE */
5074 if (td->size_hack) return 1;
5076 td->size_hack = TRUE;
5078 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5079 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5082 if ((td->cols != cols) || (td->rows != rows))
5085 term *old_term = Term;
5087 /* Save the new size */
5092 Term_activate(&td->t);
5094 /* Resize the term */
5095 Term_resize(td->cols, td->rows);
5098 Term_activate(old_term);
5101 InvalidateRect(td->w, NULL, TRUE);
5103 /* HACK - Redraw all windows */
5104 p_ptr->window = 0xFFFFFFFF;
5108 td->size_hack = FALSE;
5115 BeginPaint(hWnd, &ps);
5116 if (td) term_data_redraw(td);
5117 EndPaint(hWnd, &ps);
5124 if (process_keydown(wParam, lParam))
5131 if (Term_no_press) Term_no_press = FALSE;
5132 else Term_keypress(wParam);
5136 case WM_PALETTECHANGED:
5138 /* ignore if palette change caused by itself */
5139 if ((HWND)wParam == hWnd) return FALSE;
5140 /* otherwise, fall through!!! */
5143 case WM_QUERYNEWPALETTE:
5145 if (!paletted) return 0;
5147 SelectPalette(hdc, hPal, FALSE);
5148 i = RealizePalette(hdc);
5149 /* if any palette entries changed, repaint the window. */
5150 if (i) InvalidateRect(hWnd, NULL, TRUE);
5151 ReleaseDC(hWnd, hdc);
5155 case WM_NCLBUTTONDOWN:
5159 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5160 #endif /* HTCLOSE */
5162 if (wParam == HTSYSMENU)
5166 td->visible = FALSE;
5167 ShowWindow(td->w, SW_HIDE);
5177 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5183 #define MOUSE_SENS 40
5186 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5187 WPARAM wParam, LPARAM lParam);
5188 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5189 WPARAM wParam, LPARAM lParam)
5190 #else /* __MWERKS__ */
5191 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5192 WPARAM wParam, LPARAM lParam)
5193 #endif /* __MWERKS__ */
5195 static int iMouse = 0;
5196 static WORD xMouse = 0;
5197 static WORD yMouse = 0;
5219 if (LOWORD(wParam) == WA_INACTIVE) break;
5221 /* else fall through */
5225 case WM_LBUTTONDOWN:
5226 case WM_MBUTTONDOWN:
5227 case WM_RBUTTONDOWN:
5230 SendMessage(hWnd, WM_CLOSE, 0, 0);
5238 dx = LOWORD(lParam) - xMouse;
5239 dy = HIWORD(lParam) - yMouse;
5241 if (dx < 0) dx = -dx;
5242 if (dy < 0) dy = -dy;
5244 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5246 SendMessage(hWnd, WM_CLOSE, 0, 0);
5250 /* Save last location */
5252 xMouse = LOWORD(lParam);
5253 yMouse = HIWORD(lParam);
5260 DestroyWindow(hwndSaver);
5266 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5269 #endif /* USE_SAVER */
5275 /*** Temporary Hooks ***/
5279 * Display warning message (see "z-util.c")
5281 static void hack_plog(concptr str)
5283 /* Give a warning */
5287 MessageBox(NULL, str, "警告!",
5288 MB_ICONEXCLAMATION | MB_OK);
5290 MessageBox(NULL, str, "Warning",
5291 MB_ICONEXCLAMATION | MB_OK);
5299 * Display error message and quit (see "z-util.c")
5301 static void hack_quit(concptr str)
5303 /* Give a warning */
5307 MessageBox(NULL, str, "エラー!",
5308 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5310 MessageBox(NULL, str, "Error",
5311 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5316 /* Unregister the classes */
5317 UnregisterClass(AppName, hInstance);
5319 /* Destroy the icon */
5320 if (hIcon) DestroyIcon(hIcon);
5328 /*** Various hooks ***/
5332 * Display warning message (see "z-util.c")
5334 static void hook_plog(concptr str)
5340 MessageBox(data[0].w, str, "警告!",
5341 MB_ICONEXCLAMATION | MB_OK);
5343 MessageBox(data[0].w, str, "Warning",
5344 MB_ICONEXCLAMATION | MB_OK);
5352 * Display error message and quit (see "z-util.c")
5354 static void hook_quit(concptr str)
5359 /* Give a warning */
5363 MessageBox(data[0].w, str, "エラー!",
5364 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5366 MessageBox(data[0].w, str, "Error",
5367 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5373 /* Save the preferences */
5377 /*** Could use 'Term_nuke_win()' */
5379 /* Destroy all windows */
5380 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5382 term_force_font(&data[i], NULL);
5383 if (data[i].font_want) string_free(data[i].font_want);
5384 if (data[i].w) DestroyWindow(data[i].w);
5388 /* Free the bitmap stuff */
5390 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5391 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5393 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5394 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5396 #endif /* USE_GRAPHICS */
5398 /*** Free some other stuff ***/
5400 DeleteObject(hbrYellow);
5405 if (hPal) DeleteObject(hPal);
5407 UnregisterClass(AppName, hInstance);
5409 if (hIcon) DestroyIcon(hIcon);
5416 /*** Initialize ***/
5422 static void init_stuff(void)
5429 /* Get program name with full path */
5430 GetModuleFileName(hInstance, path, 512);
5432 /* Save the "program name" */
5435 /* Get the name of the "*.ini" file */
5436 strcpy(path + strlen(path) - 4, ".INI");
5438 /* Save the the name of the ini-file */
5439 ini_file = string_make(path);
5441 /* Analyze the path */
5447 if (path[i] == '\\')
5454 /* Add "lib" to the path */
5455 strcpy(path + i + 1, "lib\\");
5457 /* Validate the path */
5458 validate_dir(path, TRUE);
5460 /* Init the file paths */
5461 init_file_paths(path);
5463 /* Hack -- Validate the paths */
5464 validate_dir(ANGBAND_DIR_APEX, FALSE);
5465 validate_dir(ANGBAND_DIR_BONE, FALSE);
5467 /* Allow missing 'edit' directory */
5468 if (!check_dir(ANGBAND_DIR_EDIT))
5470 /* Must have 'data'! */
5471 validate_dir(ANGBAND_DIR_DATA, TRUE);
5475 /* Don't need 'data' */
5476 validate_dir(ANGBAND_DIR_DATA, FALSE);
5479 validate_dir(ANGBAND_DIR_FILE, TRUE);
5480 validate_dir(ANGBAND_DIR_HELP, FALSE);
5481 validate_dir(ANGBAND_DIR_INFO, FALSE);
5482 validate_dir(ANGBAND_DIR_PREF, TRUE);
5483 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5484 validate_dir(ANGBAND_DIR_USER, TRUE);
5485 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5487 /* Build the filename */
5488 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
5490 /* Hack -- Validate the "news.txt" file */
5491 validate_file(path);
5494 #if 0 /* #ifndef JP */
5495 /* Build the "font" path */
5496 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5498 /* Allocate the path */
5499 ANGBAND_DIR_XTRA_FONT = string_make(path);
5501 /* Validate the "font" directory */
5502 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5504 /* Build the filename */
5505 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5507 /* Hack -- Validate the basic font */
5508 validate_file(path);
5514 /* Build the "graf" path */
5515 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5517 /* Allocate the path */
5518 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5520 /* Validate the "graf" directory */
5521 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5523 #endif /* USE_GRAPHICS */
5528 /* Build the "sound" path */
5529 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5531 /* Allocate the path */
5532 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5534 /* Validate the "sound" directory */
5535 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5537 #endif /* USE_SOUND */
5541 /* Build the "music" path */
5542 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5544 /* Allocate the path */
5545 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5547 /* Validate the "music" directory */
5548 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5550 #endif /* USE_MUSIC */
5552 /* Build the "help" path */
5553 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5555 /* Allocate the path */
5556 ANGBAND_DIR_XTRA_HELP = string_make(path);
5558 /* Validate the "help" directory */
5559 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5563 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
5565 static bool is_already_running(void)
5567 bool result = FALSE;
5570 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5571 if (GetLastError() == ERROR_ALREADY_EXISTS)
5580 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
5582 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5583 LPSTR lpCmdLine, int nCmdShow)
5591 setlocale(LC_ALL, "ja_JP.utf8");
5600 /* Prevent multiple run */
5601 if (is_already_running())
5604 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
5605 _("エラー!", "Error") ,
5606 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5610 if (hPrevInst == NULL)
5612 wc.style = CS_CLASSDC;
5613 wc.lpfnWndProc = AngbandWndProc;
5615 wc.cbWndExtra = 4; /* one long pointer to term_data */
5616 wc.hInstance = hInst;
5617 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5618 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5619 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5620 wc.lpszMenuName = AppName;
5621 wc.lpszClassName = AppName;
5623 if (!RegisterClass(&wc)) exit(1);
5625 wc.lpfnWndProc = AngbandListProc;
5626 wc.lpszMenuName = NULL;
5627 wc.lpszClassName = AngList;
5629 if (!RegisterClass(&wc)) exit(2);
5633 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5634 wc.lpfnWndProc = AngbandSaverProc;
5636 wc.lpszMenuName = NULL;
5637 wc.lpszClassName = "WindowsScreenSaverClass";
5639 if (!RegisterClass(&wc)) exit(3);
5645 /* Temporary hooks */
5646 plog_aux = hack_plog;
5647 quit_aux = hack_quit;
5648 core_aux = hack_quit;
5650 /* Prepare the filepaths */
5653 /* Initialize the keypress analyzer */
5654 for (i = 0; special_key_list[i]; ++i)
5656 special_key[special_key_list[i]] = TRUE;
5658 /* Initialize the keypress analyzer */
5659 for (i = 0; ignore_key_list[i]; ++i)
5661 ignore_key[ignore_key_list[i]] = TRUE;
5664 /* Determine if display is 16/256/true color */
5666 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5667 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5668 ReleaseDC(NULL, hdc);
5670 /* Initialize the colors */
5671 for (i = 0; i < 256; i++)
5675 /* Extract desired values */
5676 rv = angband_color_table[i][1];
5677 gv = angband_color_table[i][2];
5678 bv = angband_color_table[i][3];
5680 /* Extract the "complex" code */
5681 win_clr[i] = PALETTERGB(rv, gv, bv);
5683 /* Save the "simple" code */
5684 angband_color_table[i][0] = win_pal[i];
5687 /* Prepare the windows */
5693 /* Activate hooks */
5694 plog_aux = hook_plog;
5695 quit_aux = hook_quit;
5696 core_aux = hook_quit;
5698 /* Set the system suffix */
5699 ANGBAND_SYS = "win";
5701 /* Set the keyboard suffix */
5702 if (7 != GetKeyboardType(0))
5703 ANGBAND_KEYBOARD = "0";
5706 /* Japanese keyboard */
5707 switch (GetKeyboardType(1))
5709 case 0x0D01: case 0x0D02:
5710 case 0x0D03: case 0x0D04:
5711 case 0x0D05: case 0x0D06:
5713 ANGBAND_KEYBOARD = "NEC98";
5717 ANGBAND_KEYBOARD = "JAPAN";
5721 /* Catch nasty signals */
5724 Term_activate(term_screen);
5727 /* We are now initialized */
5730 if(lpCmdLine[0] == '-'){
5731 switch(lpCmdLine[1])
5736 if (!lpCmdLine[2]) break;
5737 chuukei_server = TRUE;
5738 if(connect_chuukei_server(&lpCmdLine[2])<0){
5739 msg_print("connect fail");
5742 msg_print("connect");
5750 if (!lpCmdLine[2]) break;
5751 chuukei_client = TRUE;
5752 connect_chuukei_server(&lpCmdLine[2]);
5760 if (!lpCmdLine[2]) break;
5761 prepare_browse_movie(&lpCmdLine[2]);
5771 /* Did the user double click on a save file? */
5772 if(!chuukei_server) check_for_save_file(lpCmdLine);
5774 /* Did the user double click on a save file? */
5775 check_for_save_file(lpCmdLine);
5778 /* Prompt the user */
5779 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
5783 /* Process messages forever */
5784 while (GetMessage(&msg, NULL, 0, 0))
5786 TranslateMessage(&msg);
5787 DispatchMessage(&msg);
5798 #endif /* WINDOWS */