3 * @brief Windows版固有実装(メインエントリポイント含む)
5 * @author Hengband Team
9 * Windows98かその前後の頃を起点としたAPI実装。
11 * DirectXといった昨今描画に標準的となったライブラリも用いていない。
12 * タイルの描画処理などについては、現在動作の詳細を検証中。
16 * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
18 * This software may be copied and distributed for educational, research,
19 * and not for profit purposes provided that this copyright and statement
20 * are included in all such copies.
23 * This file helps Angband work with Windows computers.
25 * To use this file, use an appropriate "Makefile" or "Project File",
26 * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
27 * make sure to obtain various extra files as described below.
29 * The official compilation uses the CodeWarrior Pro compiler, which
30 * includes a special project file and precompilable header file.
34 * <del>See also "main-dos.c" and "main-ibm.c".</del>
38 * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
39 * and/or color redefinitions.
43 * The "lib/user/font-win.prf" contains attr/char mappings for use with the
44 * normal "lib/xtra/font/*.fon" font files.
48 * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
49 * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
54 * Compiling this file, and using the resulting executable, requires
55 * several extra files not distributed with the standard Angband code.
56 * If "USE_GRAPHICS" is defined, then "readdib.h" and "readdib.c" must
57 * be placed into "src/", and the "8X8.BMP" bitmap file must be placed
58 * into "lib/xtra/graf". In any case, some "*.fon" files (including
59 * "8X13.FON" if nothing else) must be placed into "lib/xtra/font/".
60 * If "USE_SOUND" is defined, then some special library (for example,
61 * "winmm.lib") may need to be linked in, and desired "*.WAV" sound
62 * files must be placed into "lib/xtra/sound/". All of these extra
63 * files can be found in the "ext-win" archive.
67 * The "Term_xtra_win_clear()" function should probably do a low-level
68 * clear of the current window, and redraw the borders and other things,
69 * if only for efficiency.
73 * A simpler method is needed for selecting the "tile size" for windows.
77 * The various "warning" messages assume the existance of the "screen.w"
78 * window, I think, and only a few calls actually check for its existance,
79 * this may be okay since "NULL" means "on top of all windows". (?) The
80 * user must never be allowed to "hide" the main window, or the "menubar"
85 * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
86 * use with the "winhelp.exe" program. These files *may* be available
87 * at the ftp site somewhere, but I have not seen them.
91 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
93 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
95 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
96 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
104 #include "cmd-dump.h"
105 #include "view-mainwindow.h"
107 #include "floor-events.h"
125 * Extract the "WIN32" flag from the compiler
127 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
135 * Hack -- allow use of "screen saver" mode
141 * Menu constants -- see "ANGBAND.RC"
144 #define IDM_FILE_NEW 100
145 #define IDM_FILE_OPEN 101
146 #define IDM_FILE_SAVE 110
147 #define IDM_FILE_SCORE 120
148 #define IDM_FILE_MOVIE 121
149 #define IDM_FILE_EXIT 130
151 #define IDM_WINDOW_VIS_0 200
152 #define IDM_WINDOW_VIS_1 201
153 #define IDM_WINDOW_VIS_2 202
154 #define IDM_WINDOW_VIS_3 203
155 #define IDM_WINDOW_VIS_4 204
156 #define IDM_WINDOW_VIS_5 205
157 #define IDM_WINDOW_VIS_6 206
158 #define IDM_WINDOW_VIS_7 207
160 #define IDM_WINDOW_FONT_0 210
161 #define IDM_WINDOW_FONT_1 211
162 #define IDM_WINDOW_FONT_2 212
163 #define IDM_WINDOW_FONT_3 213
164 #define IDM_WINDOW_FONT_4 214
165 #define IDM_WINDOW_FONT_5 215
166 #define IDM_WINDOW_FONT_6 216
167 #define IDM_WINDOW_FONT_7 217
169 #define IDM_WINDOW_POS_0 220
170 #define IDM_WINDOW_POS_1 221
171 #define IDM_WINDOW_POS_2 222
172 #define IDM_WINDOW_POS_3 223
173 #define IDM_WINDOW_POS_4 224
174 #define IDM_WINDOW_POS_5 225
175 #define IDM_WINDOW_POS_6 226
176 #define IDM_WINDOW_POS_7 227
178 #define IDM_WINDOW_BIZ_0 230
179 #define IDM_WINDOW_BIZ_1 231
180 #define IDM_WINDOW_BIZ_2 232
181 #define IDM_WINDOW_BIZ_3 233
182 #define IDM_WINDOW_BIZ_4 234
183 #define IDM_WINDOW_BIZ_5 235
184 #define IDM_WINDOW_BIZ_6 236
185 #define IDM_WINDOW_BIZ_7 237
187 #define IDM_WINDOW_I_WID_0 240
188 #define IDM_WINDOW_I_WID_1 241
189 #define IDM_WINDOW_I_WID_2 242
190 #define IDM_WINDOW_I_WID_3 243
191 #define IDM_WINDOW_I_WID_4 244
192 #define IDM_WINDOW_I_WID_5 245
193 #define IDM_WINDOW_I_WID_6 246
194 #define IDM_WINDOW_I_WID_7 247
196 #define IDM_WINDOW_D_WID_0 250
197 #define IDM_WINDOW_D_WID_1 251
198 #define IDM_WINDOW_D_WID_2 252
199 #define IDM_WINDOW_D_WID_3 253
200 #define IDM_WINDOW_D_WID_4 254
201 #define IDM_WINDOW_D_WID_5 255
202 #define IDM_WINDOW_D_WID_6 256
203 #define IDM_WINDOW_D_WID_7 257
205 #define IDM_WINDOW_I_HGT_0 260
206 #define IDM_WINDOW_I_HGT_1 261
207 #define IDM_WINDOW_I_HGT_2 262
208 #define IDM_WINDOW_I_HGT_3 263
209 #define IDM_WINDOW_I_HGT_4 264
210 #define IDM_WINDOW_I_HGT_5 265
211 #define IDM_WINDOW_I_HGT_6 266
212 #define IDM_WINDOW_I_HGT_7 267
214 #define IDM_WINDOW_D_HGT_0 270
215 #define IDM_WINDOW_D_HGT_1 271
216 #define IDM_WINDOW_D_HGT_2 272
217 #define IDM_WINDOW_D_HGT_3 273
218 #define IDM_WINDOW_D_HGT_4 274
219 #define IDM_WINDOW_D_HGT_5 275
220 #define IDM_WINDOW_D_HGT_6 276
221 #define IDM_WINDOW_D_HGT_7 277
223 #define IDM_OPTIONS_NO_GRAPHICS 400
224 #define IDM_OPTIONS_OLD_GRAPHICS 401
225 #define IDM_OPTIONS_NEW_GRAPHICS 402
226 #define IDM_OPTIONS_NEW2_GRAPHICS 403
227 #define IDM_OPTIONS_BIGTILE 409
228 #define IDM_OPTIONS_SOUND 410
229 #define IDM_OPTIONS_MUSIC 411
230 #define IDM_OPTIONS_SAVER 420
231 #define IDM_OPTIONS_MAP 430
232 #define IDM_OPTIONS_BG 440
233 #define IDM_OPTIONS_OPEN_BG 441
235 #define IDM_DUMP_SCREEN_HTML 450
237 #define IDM_HELP_CONTENTS 901
240 * Exclude parts of WINDOWS.H that are not needed
242 #define NOCOMM /* Comm driver APIs and definitions */
243 #define NOLOGERROR /* LogError() and related definitions */
244 #define NOPROFILER /* Profiler APIs */
245 #define NOLFILEIO /* _l* file I/O routines */
246 #define NOOPENFILE /* OpenFile and related definitions */
247 #define NORESOURCE /* Resource management */
248 #define NOATOM /* Atom management */
249 #define NOLANGUAGE /* Character test routines */
250 #define NOLSTRING /* lstr* string management routines */
251 #define NODBCS /* Double-byte character set routines */
252 #define NOKEYBOARDINFO /* Keyboard driver routines */
253 #define NOCOLOR /* COLOR_* color values */
254 #define NODRAWTEXT /* DrawText() and related definitions */
255 #define NOSCALABLEFONT /* Truetype scalable font support */
256 #define NOMETAFILE /* Metafile support */
257 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
258 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
259 #define NOKEYSTATES /* MK_* message key state flags */
260 #define NOWH /* SetWindowsHook and related WH_* definitions */
261 #define NOCLIPBOARD /* Clipboard APIs and definitions */
262 #define NOICONS /* IDI_* icon IDs */
263 #define NOMDI /* MDI support */
264 #define NOHELP /* Help support */
266 /* Not defined since it breaks Borland C++ 5.5 */
267 /* #define NOCTLMGR */ /* Control management and controls */
270 * Exclude parts of WINDOWS.H that are not needed (Win32)
272 #define WIN32_LEAN_AND_MEAN
273 #define NONLS /* All NLS defines and routines */
274 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
275 #define NOKANJI /* Kanji support stuff. */
276 #define NOMCX /* Modem Configuration Extensions */
279 * Include the "windows" support file
284 * Exclude parts of MMSYSTEM.H that are not needed
286 #define MMNODRV /* Installable driver support */
287 #define MMNOWAVE /* Waveform support */
288 #define MMNOMIDI /* MIDI support */
289 #define MMNOAUX /* Auxiliary audio support */
290 #define MMNOTIMER /* Timer support */
291 #define MMNOJOY /* Joystick support */
292 #define MMNOMCI /* MCI support */
293 #define MMNOMMIO /* Multimedia file I/O support */
294 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
298 * Standard sound names
300 const concptr angband_sound_name[SOUND_MAX] =
372 * Standard music names
374 const concptr angband_music_basic_name[MUSIC_BASIC_MAX] =
400 * Include some more files. Note: the Cygnus Cygwin compiler
401 * doesn't use mmsystem.h instead it includes the winmm library
402 * which performs a similar function.
404 #include <mmsystem.h>
408 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
409 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
411 /* #define HTML_HELP */
414 #include <htmlhelp.h>
415 #endif /* HTML_HELP */
418 * Include the support for loading bitmaps
421 # include "readdib.h"
425 * Hack -- Fake declarations from "dos.h"
428 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
430 #define FA_LABEL 0x08 /* Volume label */
431 #define FA_DIREC 0x10 /* Directory */
432 unsigned _cdecl _dos_getfileattr(concptr , unsigned *);
436 * Silliness in WIN32 drawing routine
439 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
443 * Silliness for Windows 95
445 #ifndef WS_EX_TOOLWINDOW
446 # define WS_EX_TOOLWINDOW 0
450 * Foreground color bits (hard-coded by DOS)
452 #define VID_BLACK 0x00
453 #define VID_BLUE 0x01
454 #define VID_GREEN 0x02
455 #define VID_CYAN 0x03
457 #define VID_MAGENTA 0x05
458 #define VID_YELLOW 0x06
459 #define VID_WHITE 0x07
462 * Bright text (hard-coded by DOS)
464 #define VID_BRIGHT 0x08
467 * Background color bits (hard-coded by DOS)
469 #define VUD_BLACK 0x00
470 #define VUD_BLUE 0x10
471 #define VUD_GREEN 0x20
472 #define VUD_CYAN 0x30
474 #define VUD_MAGENTA 0x50
475 #define VUD_YELLOW 0x60
476 #define VUD_WHITE 0x70
479 * Blinking text (hard-coded by DOS)
481 #define VUD_BRIGHT 0x80
487 typedef struct _term_data term_data;
491 * @brief ターム情報構造体 / Extra "term" data
494 * pos_x / pos_y は各タームの左上点座標を指す。
497 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
498 * 1ドットずつ調整するステータスを指す。
499 * また、フォントを変更すると都度自動調整される。
502 * Note the use of "font_want" for the names of the font file requested by
503 * the user, and the use of "font_file" for the currently active font file.
505 * The "font_file" is uppercased, and takes the form "8X13.FON", while
506 * "font_want" can be in almost any form as long as it could be construed
507 * as attempting to represent the name of a font.
519 TERM_LEN rows; /* int -> uint */
522 uint pos_x; //!< タームの左上X座標
523 uint pos_y; //!< タームの左上Y座標
538 int font_wid; //!< フォント横幅
539 int font_hgt; //!< フォント縦幅
540 int tile_wid; //!< タイル横幅
541 int tile_hgt; //!< タイル縦幅
547 #if 1 /* #ifdef JP */
555 #define MAX_TERM_DATA 8 //!< Maximum number of windows
557 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
558 static term_data *my_td; //!< Hack -- global "window creation" pointer
559 POINT normsize; //!< Remember normal size of main window when maxmized
562 * was main window maximized on previous playing
564 bool win_maximized = FALSE;
569 bool game_in_progress = FALSE;
572 * note when "open"/"new" become valid
574 bool initialized = FALSE;
577 * screen paletted, i.e. 256 colors
579 bool paletted = FALSE;
582 * 16 colors screen, don't use RGB()
584 bool colors16 = FALSE;
587 * Saved instance handle
589 static HINSTANCE hInstance;
592 * Yellow brush for the cursor
594 static HBRUSH hbrYellow;
604 static HPALETTE hPal;
607 static HBITMAP hBG = NULL;
608 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
609 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
614 * The screen saver window
616 static HWND hwndSaver;
618 #endif /* USE_SAVER */
624 * 現在使用中のタイルID(0ならば未使用)
625 * Flag set once "graphics" has been initialized
627 static byte_hack current_graphics_mode = 0;
632 static DIBINIT infGraph;
635 * The global bitmap mask
637 static DIBINIT infMask;
639 #endif /* USE_GRAPHICS */
645 * Flag set once "sound" has been initialized
647 static bool can_use_sound = FALSE;
651 * An array of sound file names
653 static concptr sound_file[SOUND_MAX][SAMPLE_MAX];
655 #endif /* USE_SOUND */
661 #define SAMPLE_MUSIC_MAX 16
662 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
663 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
664 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
665 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
666 static bool can_use_music = FALSE;
668 static MCI_OPEN_PARMS mop;
669 static char mci_device_type[256];
671 int current_music_type = 0;
672 int current_music_id = 0;
674 #endif /* USE_MUSIC */
678 * Full path to ANGBAND.INI
680 static concptr ini_file = NULL;
683 * Name of application
685 static concptr AppName = "ANGBAND";
688 * Name of sub-window type
690 static concptr AngList = "AngList";
695 static concptr ANGBAND_DIR_XTRA_GRAF;
696 static concptr ANGBAND_DIR_XTRA_SOUND;
697 static concptr ANGBAND_DIR_XTRA_MUSIC;
698 static concptr ANGBAND_DIR_XTRA_HELP;
699 #if 0 /* #ifndef JP */
700 static concptr ANGBAND_DIR_XTRA_FONT;
703 static concptr ANGBAND_DIR_XTRA_MUSIC;
708 * The "complex" color values
710 static COLORREF win_clr[256];
714 * Flag for macro trigger with dump ASCII
716 static bool Term_no_press = FALSE;
721 static bool mouse_down = FALSE;
722 static bool paint_rect = FALSE;
723 static TERM_LEN mousex = 0, mousey = 0;
724 static TERM_LEN oldx, oldy;
728 * @brief The "simple" color values
730 * See "main-ibm.c" for original table information
731 * The entries below are taken from the "color bits" defined above.
732 * Note that many of the choices below suck, but so do crappy monitors.
734 static BYTE win_pal[256] =
736 VID_BLACK, /* Dark */
737 VID_WHITE, /* White */
738 VID_CYAN, /* Slate XXX */
739 VID_RED | VID_BRIGHT, /* Orange XXX */
741 VID_GREEN, /* Green */
743 VID_YELLOW, /* Umber XXX */
744 VID_BLACK | VID_BRIGHT, /* Light Dark */
745 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
746 VID_MAGENTA, /* Violet XXX */
747 VID_YELLOW | VID_BRIGHT, /* Yellow */
748 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
749 VID_GREEN | VID_BRIGHT, /* Light Green */
750 VID_BLUE | VID_BRIGHT, /* Light Blue */
751 VID_YELLOW /* Light Umber XXX */
756 * Hack -- define which keys are "special"
758 static bool special_key[256];
759 static bool ignore_key[256];
763 * Hack -- initialization list for "special_key"
765 static byte special_key_list[] = {
766 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
767 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
768 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
769 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
770 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
771 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
772 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
773 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
774 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
775 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
776 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
777 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
778 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
779 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
780 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
781 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
782 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
787 static byte ignore_key_list[] = {
788 VK_ESCAPE, VK_TAB, VK_SPACE,
789 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
790 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
791 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
797 * Hack -- initialization list for "special_key"
799 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
800 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
801 * catch the keypad keys (with and without numlock set, including keypad 5),
802 * the function keys (including the "menu" key which maps to F10), and the
803 * "pause" key (between scroll lock and numlock). We also catch a few odd
804 * keys which I do not recognize, but which are listed among keys which we
805 * do catch, so they should be harmless to catch.
807 static byte special_key_list[] =
809 VK_CLEAR, /* 0x0C (KP<5>) */
811 VK_PAUSE, /* 0x13 (pause) */
813 VK_PRIOR, /* 0x21 (KP<9>) */
814 VK_NEXT, /* 0x22 (KP<3>) */
815 VK_END, /* 0x23 (KP<1>) */
816 VK_HOME, /* 0x24 (KP<7>) */
817 VK_LEFT, /* 0x25 (KP<4>) */
818 VK_UP, /* 0x26 (KP<8>) */
819 VK_RIGHT, /* 0x27 (KP<6>) */
820 VK_DOWN, /* 0x28 (KP<2>) */
821 VK_SELECT, /* 0x29 (?????) */
822 VK_PRINT, /* 0x2A (?????) */
823 VK_EXECUTE, /* 0x2B (?????) */
824 VK_SNAPSHOT, /* 0x2C (?????) */
825 VK_INSERT, /* 0x2D (KP<0>) */
826 VK_DELETE, /* 0x2E (KP<.>) */
827 VK_HELP, /* 0x2F (?????) */
829 VK_NUMPAD0, /* 0x60 (KP<0>) */
830 VK_NUMPAD1, /* 0x61 (KP<1>) */
831 VK_NUMPAD2, /* 0x62 (KP<2>) */
832 VK_NUMPAD3, /* 0x63 (KP<3>) */
833 VK_NUMPAD4, /* 0x64 (KP<4>) */
834 VK_NUMPAD5, /* 0x65 (KP<5>) */
835 VK_NUMPAD6, /* 0x66 (KP<6>) */
836 VK_NUMPAD7, /* 0x67 (KP<7>) */
837 VK_NUMPAD8, /* 0x68 (KP<8>) */
838 VK_NUMPAD9, /* 0x69 (KP<9>) */
839 VK_MULTIPLY, /* 0x6A (KP<*>) */
840 VK_ADD, /* 0x6B (KP<+>) */
841 VK_SEPARATOR, /* 0x6C (?????) */
842 VK_SUBTRACT, /* 0x6D (KP<->) */
843 VK_DECIMAL, /* 0x6E (KP<.>) */
844 VK_DIVIDE, /* 0x6F (KP</>) */
875 /* Function prototype */
877 static bool is_already_running(void);
881 static void delete_bg(void)
890 static int init_bg(void)
892 char * bmfile = bg_bitmap_file;
895 if (use_bg == 0) return 0;
897 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
899 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
907 static void DrawBG(HDC hdc, RECT *r)
912 int x = r->left, y = r->top;
913 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
919 GetObject(hBG, sizeof(bm), &bm);
920 swid = bm.bmWidth; shgt = bm.bmHeight;
922 hdcSrc = CreateCompatibleDC(hdc);
923 hOld = SelectObject(hdcSrc, hBG);
927 cwid = MIN(swid - sx, r->right - nx);
930 chgt = MIN(shgt - sy, r->bottom - ny);
931 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
933 } while (ny < r->bottom);
936 } while (nx < r->right);
938 SelectObject(hdcSrc, hOld);
944 * Hack -- given a pathname, point at the filename
946 static concptr extract_file_name(concptr s)
950 /* Start at the end */
951 p = s + strlen(s) - 1;
953 /* Back up to divider */
954 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
956 /* Return file name */
963 * Hack -- given a simple filename, extract the "font size" info
965 * Return a pointer to a static buffer holding the capitalized base name.
967 #if 0 /* #ifndef JP */
968 static char *analyze_font(char *path, int *wp, int *hp)
974 /* Start at the end */
975 p = path + strlen(path) - 1;
977 /* Back up to divider */
978 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
980 /* Advance to file name */
986 /* Capitalize (be paranoid) */
987 if (islower(*s)) *s = toupper(*s);
991 s = my_strchr(p, 'X');
993 /* Extract font width */
997 hgt = s ? atoi(s+1) : 0;
1008 * Check for existance of a file
1010 static bool check_file(concptr s)
1020 unsigned int attrib;
1030 attrib = GetFileAttributes(path);
1032 /* Require valid filename */
1033 if (attrib == INVALID_FILE_NAME) return (FALSE);
1035 /* Prohibit directory */
1036 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
1040 /* Examine and verify */
1041 if (_dos_getfileattr(path, &attrib)) return (FALSE);
1043 /* Prohibit something */
1044 if (attrib & FA_LABEL) return (FALSE);
1046 /* Prohibit directory */
1047 if (attrib & FA_DIREC) return (FALSE);
1057 * Check for existance of a directory
1059 static bool check_dir(concptr s)
1071 unsigned int attrib;
1081 /* Remove trailing backslash */
1082 if (i && (path[i-1] == '\\')) path[--i] = '\0';
1087 attrib = GetFileAttributes(path);
1089 /* Require valid filename */
1090 if (attrib == INVALID_FILE_NAME) return (FALSE);
1092 /* Require directory */
1093 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
1097 /* Examine and verify */
1098 if (_dos_getfileattr(path, &attrib)) return (FALSE);
1100 /* Prohibit something */
1101 if (attrib & FA_LABEL) return (FALSE);
1103 /* Require directory */
1104 if (!(attrib & FA_DIREC)) return (FALSE);
1116 static void validate_file(concptr s)
1118 /* Verify or fail */
1121 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
1127 * Validate a directory
1129 static void validate_dir(concptr s, bool vital)
1131 /* Verify or fail */
1134 /* This directory contains needed data */
1137 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
1139 /* Attempt to create this directory */
1142 quit_fmt("Unable to create directory:\n%s", s);
1149 * @brief (Windows版固有実装)Get the "size" for a window
1151 static void term_getsize(term_data *td)
1155 if (td->cols < 1) td->cols = 1;
1156 if (td->rows < 1) td->rows = 1;
1159 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1160 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1162 /* Fake window size */
1164 rc.right = rc.left + wid;
1166 rc.bottom = rc.top + hgt;
1168 /* rc.right += 1; */
1169 /* rc.bottom += 1; */
1172 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1175 td->size_wid = rc.right - rc.left;
1176 td->size_hgt = rc.bottom - rc.top;
1178 /* See CreateWindowEx */
1181 /* Extract actual location */
1182 GetWindowRect(td->w, &rc);
1184 /* Save the location */
1185 td->pos_x = rc.left;
1191 * Write the "prefs" for a single term
1193 static void save_prefs_aux(int i)
1195 term_data *td = &data[i];
1196 GAME_TEXT sec_name[128];
1200 WINDOWPLACEMENT lpwndpl;
1203 /* Make section name */
1204 sprintf(sec_name, "Term-%d", i);
1209 strcpy(buf, td->visible ? "1" : "0");
1210 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1215 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "MS ゴシック");
1218 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1220 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1224 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1226 #if 1 /* #ifdef JP */
1227 wsprintf(buf, "%d", td->lf.lfWidth);
1228 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1229 wsprintf(buf, "%d", td->lf.lfHeight);
1230 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1231 wsprintf(buf, "%d", td->lf.lfWeight);
1232 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1235 strcpy(buf, td->bizarre ? "1" : "0");
1236 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1239 wsprintf(buf, "%d", td->tile_wid);
1240 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1243 wsprintf(buf, "%d", td->tile_hgt);
1244 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1246 /* Get window placement and dimensions */
1247 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1248 GetWindowPlacement(td->w, &lpwndpl);
1250 /* Acquire position in *normal* mode (not minimized) */
1251 rc = lpwndpl.rcNormalPosition;
1253 /* Window size (x) */
1254 if (i == 0) wsprintf(buf, "%d", normsize.x);
1255 else wsprintf(buf, "%d", td->cols);
1256 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1258 /* Window size (y) */
1259 if (i == 0) wsprintf(buf, "%d", normsize.y);
1260 else wsprintf(buf, "%d", td->rows);
1261 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1263 /* Maxmized (only main window) */
1266 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1267 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1270 /* Acquire position */
1271 GetWindowRect(td->w, &rc);
1273 /* Window position (x) */
1274 wsprintf(buf, "%d", rc.left);
1275 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1277 /* Window position (y) */
1278 wsprintf(buf, "%d", rc.top);
1279 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1281 /* Window Z position */
1284 strcpy(buf, td->posfix ? "1" : "0");
1285 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1292 * We assume that the windows have all been initialized
1294 static void save_prefs(void)
1300 /* Save the "arg_graphics" flag */
1301 sprintf(buf, "%d", arg_graphics);
1302 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1304 /* Save the "arg_bigtile" flag */
1305 strcpy(buf, arg_bigtile ? "1" : "0");
1306 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1308 /* Save the "arg_sound" flag */
1309 strcpy(buf, arg_sound ? "1" : "0");
1310 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1312 /* Save the "arg_sound" flag */
1313 strcpy(buf, arg_music ? "1" : "0");
1314 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1317 strcpy(buf, use_bg ? "1" : "0");
1318 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1319 WritePrivateProfileString("Angband", "BackGroundBitmap",
1320 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1322 /* Save window prefs */
1323 for (i = 0; i < MAX_TERM_DATA; ++i)
1331 * Load the "prefs" for a single term
1333 static void load_prefs_aux(int i)
1335 term_data *td = &data[i];
1336 GAME_TEXT sec_name[128];
1339 int wid, hgt, posx, posy;
1340 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1341 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1345 /* Make section name */
1346 sprintf(sec_name, "Term-%d", i);
1348 /* Make section name */
1349 sprintf(sec_name, "Term-%d", i);
1354 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1357 /* Desired font, with default */
1359 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1362 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1364 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1370 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1372 /* Analyze font, save desired font name */
1373 #if 1 /* #ifdef JP */
1374 td->font_want = string_make(tmp);
1376 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1377 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1378 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1380 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1385 #if 1 /* #ifdef JP */
1386 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1387 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1389 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1390 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1395 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1396 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1397 normsize.x = td->cols; normsize.y = td->rows;
1402 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
1405 /* Window position */
1406 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1407 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1408 td->pos_x = MIN(MAX(0, posx), dispx-128);
1409 td->pos_y = MIN(MAX(0, posy), dispy-128);
1411 /* Window Z position */
1414 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
1422 static void load_prefs(void)
1426 /* Extract the "arg_graphics" flag */
1427 arg_graphics = (byte_hack)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1429 /* Extract the "arg_bigtile" flag */
1430 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
1431 use_bigtile = arg_bigtile;
1433 /* Extract the "arg_sound" flag */
1434 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1436 /* Extract the "arg_sound" flag */
1437 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1440 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1441 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1443 /* Load window prefs */
1444 for (i = 0; i < MAX_TERM_DATA; ++i)
1450 #if defined(USE_SOUND) || defined(USE_MUSIC)
1453 * - Taken from files.c.
1455 * Extract "tokens" from a buffer
1457 * This function uses "whitespace" as delimiters, and treats any amount of
1458 * whitespace as a single delimiter. We will never return any empty tokens.
1459 * When given an empty buffer, or a buffer containing only "whitespace", we
1460 * will return no tokens. We will never extract more than "num" tokens.
1462 * By running a token through the "text_to_ascii()" function, you can allow
1463 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1465 * We save pointers to the tokens in "tokens", and return the number found.
1467 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1477 /* Skip leading whitespace */
1478 for ( ; *s && iswspace(*s); ++s) /* loop */;
1483 /* Find next whitespace, if any */
1484 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1486 /* Nuke and advance (if necessary) */
1487 if (*t) *t++ = '\0';
1489 /* Save the token */
1500 #endif /* USE_SOUND || USE_MUSIC */
1504 static void load_sound_prefs(void)
1508 char ini_path[1024];
1509 char wav_path[1024];
1510 char *zz[SAMPLE_MAX];
1512 /* Access the sound.cfg */
1514 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1516 for (i = 0; i < SOUND_MAX; i++)
1518 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1520 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1522 for (j = 0; j < num; j++)
1524 /* Access the sound */
1525 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1527 /* Save the sound filename, if it exists */
1528 if (check_file(wav_path))
1529 sound_file[i][j] = string_make(zz[j]);
1534 #endif /* USE_SOUND */
1538 static void load_music_prefs(void)
1542 char ini_path[1024];
1543 char wav_path[1024];
1544 char *zz[SAMPLE_MAX];
1547 /* Access the music.cfg */
1549 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1551 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1553 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1555 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1557 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1559 for (j = 0; j < num; j++)
1561 /* Access the sound */
1562 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1564 /* Save the sound filename, if it exists */
1565 if (check_file(wav_path))
1566 music_file[i][j] = string_make(zz[j]);
1570 for (i = 0; i < max_d_idx; i++)
1572 sprintf(key, "dungeon%03d", i);
1573 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1575 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1577 for (j = 0; j < num; j++)
1579 /* Access the sound */
1580 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1582 /* Save the sound filename, if it exists */
1583 if (check_file(wav_path))
1584 dungeon_music_file[i][j] = string_make(zz[j]);
1588 for (i = 0; i < max_q_idx; i++)
1590 sprintf(key, "quest%03d", i);
1591 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1593 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1595 for (j = 0; j < num; j++)
1597 /* Access the sound */
1598 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1600 /* Save the sound filename, if it exists */
1601 if (check_file(wav_path))
1602 quest_music_file[i][j] = string_make(zz[j]);
1606 for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1608 sprintf(key, "town%03d", i);
1609 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1611 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1613 for (j = 0; j < num; j++)
1615 /* Access the sound */
1616 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1618 /* Save the sound filename, if it exists */
1619 if (check_file(wav_path))
1620 town_music_file[i][j] = string_make(zz[j]);
1627 #endif /* USE_MUSIC */
1630 * Create the new global palette based on the bitmap palette
1631 * (if any), and the standard 16 entry palette derived from
1632 * "win_clr[]" which is used for the basic 16 Angband colors.
1634 * This function is never called before all windows are ready.
1636 * This function returns FALSE if the new palette could not be
1637 * prepared, which should normally be a fatal error. XXX XXX
1639 * Note that only some machines actually use a "palette".
1641 static int new_palette(void)
1649 LPLOGPALETTE pLogPal;
1650 LPPALETTEENTRY lppe;
1655 /* This makes no sense */
1656 if (!paletted) return (TRUE);
1666 /* Check the bitmap palette */
1667 hBmPal = infGraph.hPalette;
1669 /* Use the bitmap */
1672 lppeSize = 256 * sizeof(PALETTEENTRY);
1673 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1674 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1675 if ((nEntries == 0) || (nEntries > 220))
1678 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1681 rnfree(lppe, lppeSize);
1688 #endif /* USE_GRAPHICS */
1690 /* Size of palette */
1691 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1693 /* Allocate palette */
1694 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1697 pLogPal->palVersion = 0x300;
1699 /* Make room for bitmap and normal data */
1700 pLogPal->palNumEntries = nEntries + 16;
1702 /* Save the bitmap data */
1703 for (i = 0; i < nEntries; i++)
1705 pLogPal->palPalEntry[i] = lppe[i];
1708 /* Save the normal data */
1709 for (i = 0; i < 16; i++)
1713 /* Access the entry */
1714 p = &(pLogPal->palPalEntry[i+nEntries]);
1716 /* Save the colors */
1717 p->peRed = GetRValue(win_clr[i]);
1718 p->peGreen = GetGValue(win_clr[i]);
1719 p->peBlue = GetBValue(win_clr[i]);
1721 /* Save the flags */
1722 p->peFlags = PC_NOCOLLAPSE;
1725 /* Free something */
1726 if (lppe) rnfree(lppe, lppeSize);
1728 /* Create a new palette, or fail */
1729 hNewPal = CreatePalette(pLogPal);
1730 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1732 /* Free the palette */
1733 rnfree(pLogPal, pLogPalSize);
1738 /* Realize the palette */
1740 SelectPalette(hdc, hNewPal, 0);
1741 i = RealizePalette(hdc);
1742 ReleaseDC(td->w, hdc);
1743 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1747 for (i = 1; i < MAX_TERM_DATA; i++)
1752 SelectPalette(hdc, hNewPal, 0);
1753 ReleaseDC(td->w, hdc);
1756 /* Delete old palette */
1757 if (hPal) DeleteObject(hPal);
1759 /* Save new palette */
1769 * @brief グラフィクスを初期化する / Initialize graphics
1772 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1773 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1776 static bool init_graphics(void)
1778 /* Initialize once */
1780 BYTE wid, hgt, twid, thgt, ox, oy;
1783 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1793 ANGBAND_GRAF = "new";
1795 else if (arg_graphics == GRAPHICS_HENGBAND)
1815 ANGBAND_GRAF = "ne2";
1826 ANGBAND_GRAF = "old";
1829 /* Access the bitmap file */
1830 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1832 /* Load the bitmap or quit */
1833 if (!ReadDIB(data[0].w, buf, &infGraph))
1835 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1839 /* Save the new sizes */
1840 infGraph.CellWidth = wid;
1841 infGraph.CellHeight = hgt;
1842 infGraph.TileWidth = twid;
1843 infGraph.TileHeight = thgt;
1844 infGraph.OffsetX = ox;
1845 infGraph.OffsetY = oy;
1847 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1849 /* Access the mask file */
1850 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1852 /* Load the bitmap or quit */
1853 if (!ReadDIB(data[0].w, buf, &infMask))
1855 plog_fmt("Cannot read bitmap file '%s'", buf);
1859 if (arg_graphics == GRAPHICS_HENGBAND)
1861 /* Access the mask file */
1862 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1864 /* Load the bitmap or quit */
1865 if (!ReadDIB(data[0].w, buf, &infMask))
1867 plog_fmt("Cannot read bitmap file '%s'", buf);
1872 /* Activate a palette */
1877 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1881 /* Graphics available */
1882 current_graphics_mode = arg_graphics;
1883 return (current_graphics_mode);
1885 #endif /* USE_GRAPHICS */
1892 static bool init_music(void)
1894 /* Initialize once */
1897 /* Load the prefs */
1900 /* Sound available */
1901 can_use_music = TRUE;
1903 return (can_use_music);
1907 * Hack -- Stop a music
1909 static void stop_music(void)
1911 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1912 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1915 #endif /* USE_MUSIC */
1921 static bool init_sound(void)
1923 /* Initialize once */
1926 /* Load the prefs */
1929 /* Sound available */
1930 can_use_sound = TRUE;
1932 return (can_use_sound);
1934 #endif /* USE_SOUND */
1940 static void term_window_resize(term_data *td)
1942 /* Require window */
1945 /* Resize the window */
1946 SetWindowPos(td->w, 0, 0, 0,
1947 td->size_wid, td->size_hgt,
1948 SWP_NOMOVE | SWP_NOZORDER);
1951 InvalidateRect(td->w, NULL, TRUE);
1956 * Force the use of a new "font file" for a term_data
1958 * This function may be called before the "window" is ready
1960 * This function returns zero only if everything succeeds.
1962 * Note that the "font name" must be capitalized!!!
1964 static errr term_force_font(term_data *td, concptr path)
1968 #if 0 /* #ifndef JP */
1974 /* Forget the old font (if needed) */
1975 if (td->font_id) DeleteObject(td->font_id);
1977 #if 1 /* #ifdef JP */
1981 /* Create the font (using the 'base' of the font file name!) */
1982 td->font_id = CreateFontIndirect(&(td->lf));
1983 wid = td->lf.lfWidth;
1984 hgt = td->lf.lfHeight;
1985 if (!td->font_id) return (1);
1987 /* Forget old font */
1993 for (i = 0; i < MAX_TERM_DATA; i++)
1995 /* Don't check when closing the application */
1998 /* Check "screen" */
1999 if ((td != &data[i]) &&
2000 (data[i].font_file) &&
2001 (streq(data[i].font_file, td->font_file)))
2007 /* Remove unused font resources */
2008 if (!used) RemoveFontResource(td->font_file);
2010 /* Free the old name */
2011 string_free(td->font_file);
2014 td->font_file = NULL;
2018 if (!path) return (1);
2023 /* Analyze font path */
2024 base = analyze_font(buf, &wid, &hgt);
2027 if (!suffix(base, ".FON")) return (1);
2030 if (!check_file(buf)) return (1);
2032 /* Load the new font */
2033 if (!AddFontResource(buf)) return (1);
2035 /* Save new font name */
2036 td->font_file = string_make(base);
2038 /* Remove the "suffix" */
2039 base[strlen(base)-4] = '\0';
2041 /* Create the font (using the 'base' of the font file name!) */
2042 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
2043 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
2044 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
2045 FIXED_PITCH | FF_DONTCARE, base);
2048 /* Hack -- Unknown size */
2055 /* all this trouble to get the cell size */
2056 hdcDesktop = GetDC(HWND_DESKTOP);
2057 hfOld = SelectObject(hdcDesktop, td->font_id);
2058 GetTextMetrics(hdcDesktop, &tm);
2059 SelectObject(hdcDesktop, hfOld);
2060 ReleaseDC(HWND_DESKTOP, hdcDesktop);
2062 /* Font size info */
2063 wid = tm.tmAveCharWidth;
2067 /* Save the size info */
2078 * Allow the user to change the font for this window.
2080 static void term_change_font(term_data *td)
2082 #if 1 /* #ifdef JP */
2085 memset(&cf, 0, sizeof(cf));
2086 cf.lStructSize = sizeof(cf);
2087 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
2088 cf.lpLogFont = &(td->lf);
2090 if (ChooseFont(&cf))
2092 /* Force the font */
2093 term_force_font(td, NULL);
2095 /* Assume not bizarre */
2098 /* Reset the tile info */
2099 td->tile_wid = td->font_wid;
2100 td->tile_hgt = td->font_hgt;
2102 /* Analyze the font */
2105 /* Resize the window */
2106 term_window_resize(td);
2112 char tmp[1024] = "";
2114 /* Extract a default if possible */
2115 if (td->font_file) strcpy(tmp, td->font_file);
2117 /* Ask for a choice */
2118 memset(&ofn, 0, sizeof(ofn));
2119 ofn.lStructSize = sizeof(ofn);
2120 ofn.hwndOwner = data[0].w;
2121 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
2122 ofn.nFilterIndex = 1;
2123 ofn.lpstrFile = tmp;
2125 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
2126 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2127 ofn.lpstrDefExt = "fon";
2129 /* Force choice if legal */
2130 if (GetOpenFileName(&ofn))
2132 /* Force the font */
2133 if (term_force_font(td, tmp))
2135 /* Access the standard font file */
2136 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2138 /* Force the use of that font */
2139 (void)term_force_font(td, tmp);
2142 /* Assume not bizarre */
2143 td->bizarre = FALSE;
2145 /* Reset the tile info */
2146 td->tile_wid = td->font_wid;
2147 td->tile_hgt = td->font_hgt;
2149 /* Analyze the font */
2152 /* Resize the window */
2153 term_window_resize(td);
2160 * Allow the user to lock this window.
2162 static void term_window_pos(term_data *td, HWND hWnd)
2164 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2165 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2168 static void windows_map(void);
2171 * Hack -- redraw a term_data
2173 static void term_data_redraw(term_data *td)
2177 /* Redraw the map */
2182 /* Activate the term */
2183 Term_activate(&td->t);
2185 /* Redraw the contents */
2188 /* Restore the term */
2189 Term_activate(term_screen);
2194 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2198 HBRUSH myBrush, oldBrush;
2200 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2201 int tx = td->size_ow1 + x * td->tile_wid;
2202 int ty = td->size_oh1 + y * td->tile_hgt;
2203 int tw = w * td->tile_wid - 1;
2204 int th = h * td->tile_hgt - 1;
2207 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2208 oldBrush = SelectObject(hdc, myBrush);
2209 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2211 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2213 SelectObject(hdc, oldBrush);
2214 SelectObject(hdc, oldPen);
2219 /*** Function hooks needed by "Term" ***/
2225 * Initialize a new Term
2227 static void Term_init_win(term *t)
2236 static void Term_nuke_win(term *t)
2245 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
2247 static errr Term_user_win(int n)
2258 * React to global changes
2260 static errr Term_xtra_win_react(void)
2267 /* Save the default colors */
2268 for (i = 0; i < 256; i++)
2270 /* Simply accept the desired colors */
2271 win_pal[i] = angband_color_table[i][0];
2282 bool change = FALSE;
2284 /* Save the default colors */
2285 for (i = 0; i < 256; i++)
2287 /* Extract desired values */
2288 rv = angband_color_table[i][1];
2289 gv = angband_color_table[i][2];
2290 bv = angband_color_table[i][3];
2292 /* Extract a full color code */
2293 code = PALETTERGB(rv, gv, bv);
2295 /* Activate changes */
2296 if (win_clr[i] != code)
2298 /* Note the change */
2301 /* Apply the desired color */
2306 /* Activate the palette if needed */
2307 if (change) (void)new_palette();
2313 /* Handle "arg_sound" */
2314 if (use_sound != arg_sound)
2316 /* Initialize (if needed) */
2317 if (arg_sound && !init_sound())
2320 plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
2326 /* Change setting */
2327 use_sound = arg_sound;
2334 /* Handle "arg_sound" */
2335 if (use_music != arg_music)
2337 /* Initialize (if needed) */
2338 if (arg_music && !init_music())
2341 plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
2346 /* Change setting */
2347 use_music = arg_music;
2349 if(!arg_music) stop_music();
2350 else select_floor_music();
2359 /* Handle "arg_graphics" */
2360 if (use_graphics != arg_graphics)
2362 /* Initialize (if needed) */
2363 if (arg_graphics && !init_graphics())
2366 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
2369 arg_graphics = GRAPHICS_NONE;
2372 /* Change setting */
2373 use_graphics = arg_graphics;
2376 #ifdef ANGBAND_2_8_1
2378 #else /* ANGBAND_2_8_1 */
2379 reset_visuals(TRUE);
2380 #endif /* ANGBAND_2_8_1 */
2383 #endif /* USE_GRAPHICS */
2386 /* Clean up windows */
2387 for (i = 0; i < MAX_TERM_DATA; i++)
2391 term_data *td = &data[i];
2393 /* Update resized windows */
2394 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
2397 Term_activate(&td->t);
2399 /* Hack -- Resize the term */
2400 Term_resize(td->cols, td->rows);
2402 /* Redraw the contents */
2415 * Process at least one event
2417 static errr Term_xtra_win_event(int v)
2421 /* Wait for an event */
2425 if (GetMessage(&msg, NULL, 0, 0))
2427 TranslateMessage(&msg);
2428 DispatchMessage(&msg);
2432 /* Check for an event */
2436 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2438 TranslateMessage(&msg);
2439 DispatchMessage(&msg);
2449 * Process all pending events
2451 static errr Term_xtra_win_flush(void)
2455 /* Process all pending events */
2456 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2458 TranslateMessage(&msg);
2459 DispatchMessage(&msg);
2468 * Hack -- clear the screen
2470 * Make this more efficient
2472 static errr Term_xtra_win_clear(void)
2474 term_data *td = (term_data*)(Term->data);
2479 /* Rectangle to erase */
2480 rc.left = td->size_ow1;
2481 rc.right = rc.left + td->cols * td->tile_wid;
2482 rc.top = td->size_oh1;
2483 rc.bottom = rc.top + td->rows * td->tile_hgt;
2487 SetBkColor(hdc, RGB(0, 0, 0));
2488 SelectObject(hdc, td->font_id);
2489 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2494 rc.left = 0; rc.top = 0;
2497 ReleaseDC(td->w, hdc);
2505 * Hack -- make a noise
2507 static errr Term_xtra_win_noise(void)
2509 MessageBeep(MB_ICONASTERISK);
2515 * Hack -- make a sound
2517 static errr Term_xtra_win_sound(int v)
2522 #endif /* USE_SOUND */
2524 /* Sound disabled */
2525 if (!use_sound) return (1);
2528 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2532 /* Count the samples */
2533 for (i = 0; i < SAMPLE_MAX; i++)
2535 if (!sound_file[v][i])
2540 if (i == 0) return (1);
2542 /* Build the path */
2543 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2547 /* Play the sound, catch errors */
2548 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2552 /* Play the sound, catch errors */
2553 return (sndPlaySound(buf, SND_ASYNC));
2557 #else /* USE_SOUND */
2561 #endif /* USE_SOUND */
2565 * Hack -- play a music
2567 static errr Term_xtra_win_music(int n, int v)
2572 #endif /* USE_MUSIC */
2574 /* Sound disabled */
2576 if(!use_music) return (1);
2579 if(n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return (1);
2580 else if(v < 0 || v >= 1000) return(1); /*!< TODO */
2586 case TERM_XTRA_MUSIC_BASIC:
2587 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2589 case TERM_XTRA_MUSIC_DUNGEON:
2590 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2592 case TERM_XTRA_MUSIC_QUEST:
2593 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2595 case TERM_XTRA_MUSIC_TOWN:
2596 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2603 //mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2604 //mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2610 case TERM_XTRA_MUSIC_BASIC:
2611 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2613 case TERM_XTRA_MUSIC_DUNGEON:
2614 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2616 case TERM_XTRA_MUSIC_QUEST:
2617 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2619 case TERM_XTRA_MUSIC_TOWN:
2620 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2627 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2628 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2634 case TERM_XTRA_MUSIC_BASIC:
2635 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2637 case TERM_XTRA_MUSIC_DUNGEON:
2638 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2640 case TERM_XTRA_MUSIC_QUEST:
2641 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2643 case TERM_XTRA_MUSIC_TOWN:
2644 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2648 if(current_music_type == n && current_music_id == v)
2652 current_music_type = n;
2653 current_music_id = v;
2657 mop.lpstrDeviceType = mci_device_type;
2658 mop.lpstrElementName = buf;
2659 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2660 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2661 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2662 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2663 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2668 #else /* USE_MUSIC */
2672 #endif /* USE_MUSIC */
2678 * Delay for "x" milliseconds
2680 static int Term_xtra_win_delay(int v)
2694 t = GetTickCount() + v;
2697 while (GetTickCount() < t)
2699 /* Handle messages */
2700 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2702 TranslateMessage(&msg);
2703 DispatchMessage(&msg);
2715 * Do a "special thing"
2717 static errr Term_xtra_win(int n, int v)
2719 /* Handle a subset of the legal requests */
2722 /* Make a bell sound */
2723 case TERM_XTRA_NOISE:
2725 return (Term_xtra_win_noise());
2729 case TERM_XTRA_MUSIC_BASIC:
2730 case TERM_XTRA_MUSIC_DUNGEON:
2731 case TERM_XTRA_MUSIC_QUEST:
2732 case TERM_XTRA_MUSIC_TOWN:
2734 return (Term_xtra_win_music(n, v));
2737 /* Make a special sound */
2738 case TERM_XTRA_SOUND:
2740 return (Term_xtra_win_sound(v));
2743 /* Process random events */
2744 case TERM_XTRA_BORED:
2746 return (Term_xtra_win_event(0));
2749 /* Process an event */
2750 case TERM_XTRA_EVENT:
2752 return (Term_xtra_win_event(v));
2755 /* Flush all events */
2756 case TERM_XTRA_FLUSH:
2758 return (Term_xtra_win_flush());
2761 /* Clear the screen */
2762 case TERM_XTRA_CLEAR:
2764 return (Term_xtra_win_clear());
2767 /* React to global changes */
2768 case TERM_XTRA_REACT:
2770 return (Term_xtra_win_react());
2773 /* Delay for some milliseconds */
2774 case TERM_XTRA_DELAY:
2776 return (Term_xtra_win_delay(v));
2786 * Low level graphics (Assumes valid input).
2788 * Draw a "cursor" at (x,y), using a "yellow box".
2790 static errr Term_curs_win(int x, int y)
2792 term_data *td = (term_data*)(Term->data);
2797 int tile_wid, tile_hgt;
2801 tile_wid = td->map_tile_wid;
2802 tile_hgt = td->map_tile_hgt;
2806 tile_wid = td->tile_wid;
2807 tile_hgt = td->tile_hgt;
2810 /* Frame the grid */
2811 rc.left = x * tile_wid + td->size_ow1;
2812 rc.right = rc.left + tile_wid;
2813 rc.top = y * tile_hgt + td->size_oh1;
2814 rc.bottom = rc.top + tile_hgt;
2816 /* Cursor is done as a yellow "box" */
2818 FrameRect(hdc, &rc, hbrYellow);
2819 ReleaseDC(td->w, hdc);
2827 * Low level graphics (Assumes valid input).
2829 * Draw a "big cursor" at (x,y), using a "yellow box".
2831 static errr Term_bigcurs_win(int x, int y)
2833 term_data *td = (term_data*)(Term->data);
2838 int tile_wid, tile_hgt;
2842 /* Normal cursor in map window */
2843 Term_curs_win(x, y);
2848 tile_wid = td->tile_wid;
2849 tile_hgt = td->tile_hgt;
2852 /* Frame the grid */
2853 rc.left = x * tile_wid + td->size_ow1;
2854 rc.right = rc.left + 2 * tile_wid;
2855 rc.top = y * tile_hgt + td->size_oh1;
2856 rc.bottom = rc.top + tile_hgt;
2858 /* Cursor is done as a yellow "box" */
2860 FrameRect(hdc, &rc, hbrYellow);
2861 ReleaseDC(td->w, hdc);
2869 * Low level graphics (Assumes valid input).
2871 * Erase a "block" of "n" characters starting at (x,y).
2873 static errr Term_wipe_win(int x, int y, int n)
2875 term_data *td = (term_data*)(Term->data);
2880 /* Rectangle to erase in client coords */
2881 rc.left = x * td->tile_wid + td->size_ow1;
2882 rc.right = rc.left + n * td->tile_wid;
2883 rc.top = y * td->tile_hgt + td->size_oh1;
2884 rc.bottom = rc.top + td->tile_hgt;
2887 SetBkColor(hdc, RGB(0, 0, 0));
2888 SelectObject(hdc, td->font_id);
2893 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2894 ReleaseDC(td->w, hdc);
2902 * Low level graphics. Assumes valid input.
2904 * Draw several ("n") chars, with an attr, at a given location.
2906 * All "graphic" data is handled by "Term_pict_win()", below.
2908 * One would think there is a more efficient method for telling a window
2909 * what color it should be using to draw with, but perhaps simply changing
2910 * it every time is not too inefficient.
2912 static errr Term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
2914 term_data *td = (term_data*)(Term->data);
2918 #if 1 /* #ifdef JP */
2919 static HBITMAP WALL;
2920 static HBRUSH myBrush, oldBrush;
2922 static bool init_done = FALSE;
2925 WALL = LoadBitmap(hInstance, AppName);
2926 myBrush = CreatePatternBrush(WALL);
2931 /* Total rectangle */
2932 rc.left = x * td->tile_wid + td->size_ow1;
2933 rc.right = rc.left + n * td->tile_wid;
2934 rc.top = y * td->tile_hgt + td->size_oh1;
2935 rc.bottom = rc.top + td->tile_hgt;
2940 /* Background color */
2941 SetBkColor(hdc, RGB(0, 0, 0));
2943 /* Foreground color */
2946 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2950 SetTextColor(hdc, win_clr[a&0x0F]);
2954 SetTextColor(hdc, win_clr[a]);
2958 SelectObject(hdc, td->font_id);
2961 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2965 (td->tile_hgt != td->font_hgt) ||
2966 (td->tile_wid != td->font_wid))
2970 /* Erase complete rectangle */
2971 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2974 if (use_bg) DrawBG(hdc, &rc);
2977 rc.left += ((td->tile_wid - td->font_wid) / 2);
2978 rc.right = rc.left + td->font_wid;
2979 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2980 rc.bottom = rc.top + td->font_hgt;
2982 /* Dump each character */
2983 for (i = 0; i < n; i++)
2986 if (use_bigtile && *(s+i)=="■"[0] && *(s+i+1)=="■"[1])
2988 rc.right += td->font_wid;
2990 oldBrush = SelectObject(hdc, myBrush);
2991 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2994 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2996 SelectObject(hdc, oldBrush);
2997 SelectObject(hdc, oldPen);
2998 rc.right -= td->font_wid;
3002 rc.left += 2 * td->tile_wid;
3003 rc.right += 2 * td->tile_wid;
3005 else if ( iskanji(*(s+i)) ) /* 2バイト文字 */
3007 rc.right += td->font_wid;
3009 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
3011 rc.right -= td->font_wid;
3015 rc.left += 2 * td->tile_wid;
3016 rc.right += 2 * td->tile_wid;
3017 } else if (*(s+i)==127){
3018 oldBrush = SelectObject(hdc, myBrush);
3019 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
3022 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
3024 SelectObject(hdc, oldBrush);
3025 SelectObject(hdc, oldPen);
3028 rc.left += td->tile_wid;
3029 rc.right += td->tile_wid;
3032 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
3035 rc.left += td->tile_wid;
3036 rc.right += td->tile_wid;
3041 oldBrush = SelectObject(hdc, myBrush);
3042 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
3045 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
3047 SelectObject(hdc, oldBrush);
3048 SelectObject(hdc, oldPen);
3051 rc.left += td->tile_wid;
3052 rc.right += td->tile_wid;
3055 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
3059 rc.left += td->tile_wid;
3060 rc.right += td->tile_wid;
3064 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
3068 rc.left += td->tile_wid;
3069 rc.right += td->tile_wid;
3080 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
3085 ReleaseDC(td->w, hdc);
3093 * Low level graphics. Assumes valid input.
3095 * Draw an array of "special" attr/char pairs at the given location.
3097 * We use the "Term_pict_win()" function for "graphic" data, which are
3098 * encoded by setting the "high-bits" of both the "attr" and the "char"
3099 * data. We use the "attr" to represent the "row" of the main bitmap,
3100 * and the "char" to represent the "col" of the main bitmap. The use
3101 * of this function is induced by the "higher_pict" flag.
3103 * If "graphics" is not available, we simply "wipe" the given grids.
3105 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)
3107 term_data *td = (term_data*)(Term->data);
3112 TERM_LEN x1, y1, w1, h1, tw1, th1;
3113 TERM_LEN x2, y2, w2, h2, tw2 = 0;
3123 /* Erase the grids */
3124 return (Term_wipe_win(x, y, n));
3127 /* Size of bitmap cell */
3128 w1 = infGraph.CellWidth;
3129 h1 = infGraph.CellHeight;
3130 tw1 = infGraph.TileWidth;
3131 th1 = infGraph.TileHeight;
3133 /* Size of window cell */
3136 w2 = td->map_tile_wid;
3137 h2 = td->map_tile_hgt;
3146 if (use_bigtile) tw2 *= 2;
3149 /* Location of window cell */
3150 x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
3151 y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
3157 hdcSrc = CreateCompatibleDC(hdc);
3158 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
3160 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3162 hdcMask = CreateCompatibleDC(hdc);
3163 SelectObject(hdcMask, infMask.hBitmap);
3166 /* Draw attr/char pairs */
3167 for (i = 0; i < n; i++, x2 += w2)
3169 TERM_COLOR a = ap[i];
3173 /* Extract picture */
3174 int row = (a & 0x7F);
3175 int col = (c & 0x7F);
3177 /* Location of bitmap cell */
3181 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3183 x3 = (tcp[i] & 0x7F) * w1;
3184 y3 = (tap[i] & 0x7F) * h1;
3185 tw2 = tw2 * w1 / tw1;
3189 if ((tw1 == tw2) && (th1 == h2))
3191 /* Copy the terrain picture from the bitmap to the window */
3192 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
3194 /* Mask out the tile */
3195 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3198 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3201 /* Need to stretch */
3204 /* Set the correct mode for stretching the tiles */
3205 SetStretchBltMode(hdc, COLORONCOLOR);
3207 /* Copy the terrain picture from the bitmap to the window */
3208 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
3210 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
3212 /* Only draw if terrain and overlay are different */
3213 if ((x1 != x3) || (y1 != y3))
3215 /* Mask out the tile */
3216 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3219 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3226 if ((w1 == tw2) && (h1 == h2))
3228 /* Copy the picture from the bitmap to the window */
3229 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3232 /* Need to stretch */
3235 /* Set the correct mode for stretching the tiles */
3236 SetStretchBltMode(hdc, COLORONCOLOR);
3238 /* Copy the picture from the bitmap to the window */
3239 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3245 SelectObject(hdcSrc, hbmSrcOld);
3248 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3251 SelectObject(hdcMask, hbmSrcOld);
3256 ReleaseDC(td->w, hdc);
3258 #else /* USE_GRAPHICS */
3260 /* Just erase this grid */
3261 return (Term_wipe_win(x, y, n));
3263 #endif /* USE_GRAPHICS */
3270 static void windows_map(void)
3272 term_data *td = &data[0];
3275 TERM_LEN x, min_x, max_x;
3276 TERM_LEN y, min_y, max_y;
3281 /* Only in graphics mode */
3282 if (!use_graphics) return;
3283 Term_xtra_win_clear();
3285 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3286 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3287 td->map_active = TRUE;
3292 max_x = current_floor_ptr->width;
3293 max_y = current_floor_ptr->height;
3297 for (x = min_x; x < max_x; x++)
3299 for (y = min_y; y < max_y; y++)
3301 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3303 /* Ignore non-graphics */
3304 if ((a & 0x80) && (c & 0x80))
3306 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3311 /* Hilite the player */
3312 Term_curs_win(p_ptr->x - min_x, p_ptr->y - min_y);
3314 /* Wait for a keypress, flush key buffer */
3315 Term_inkey(&c, TRUE, TRUE);
3318 /* Switch off the map display */
3319 td->map_active = FALSE;
3321 /* Restore screen */
3322 Term_xtra_win_clear();
3327 /*** Other routines ***/
3331 * Create and initialize a "term_data" given a title
3333 static void term_data_link(term_data *td)
3337 /* Initialize the term */
3338 term_init(t, td->cols, td->rows, td->keys);
3340 /* Use a "software" cursor */
3341 t->soft_cursor = TRUE;
3343 /* Use "Term_pict" for "graphic" data */
3344 t->higher_pict = TRUE;
3346 /* Erase with "white space" */
3347 t->attr_blank = TERM_WHITE;
3348 t->char_blank = ' ';
3351 /* Prepare the init/nuke hooks */
3352 t->init_hook = Term_init_win;
3353 t->nuke_hook = Term_nuke_win;
3356 /* Prepare the template hooks */
3357 t->user_hook = Term_user_win;
3358 t->xtra_hook = Term_xtra_win;
3359 t->curs_hook = Term_curs_win;
3360 t->bigcurs_hook = Term_bigcurs_win;
3361 t->wipe_hook = Term_wipe_win;
3362 t->text_hook = Term_text_win;
3363 t->pict_hook = Term_pict_win;
3365 /* Remember where we came from */
3366 t->data = (vptr)(td);
3371 * Create the windows
3373 * First, instantiate the "default" values, then read the "ini_file"
3374 * to over-ride selected values, then create the windows, and fonts.
3376 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3377 * must make active to realize the palette.
3379 static void init_windows(void)
3385 #if 0 /* #ifndef JP */
3391 WIPE(td, term_data);
3395 td->s = angband_term_name[0];
3409 #if 1 /* #ifdef JP */
3413 for (i = 1; i < MAX_TERM_DATA; i++)
3416 WIPE(td, term_data);
3417 td->s = angband_term_name[i];
3421 td->visible = FALSE;
3426 td->pos_x = (7 - i) * 30;
3427 td->pos_y = (7 - i) * 20;
3429 #if 1 /* #ifdef JP */
3439 /* Main window (need these before term_getsize gets called) */
3441 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3442 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3447 /* Sub windows (need these before term_getsize gets called) */
3448 for (i = 1; i < MAX_TERM_DATA; i++)
3451 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3452 td->dwExStyle = (WS_EX_TOOLWINDOW);
3457 for (i = 0; i < MAX_TERM_DATA; i++)
3461 #if 1 /* #ifdef JP */
3462 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3463 td->lf.lfCharSet = DEFAULT_CHARSET;
3464 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3465 /* Activate the chosen font */
3466 term_force_font(td, NULL);
3467 if(!td->tile_wid) td->tile_wid = td->font_wid;
3468 if(!td->tile_hgt) td->tile_hgt = td->font_hgt;
3470 /* Access the standard font file */
3471 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3473 /* Activate the chosen font */
3474 if (term_force_font(td, buf))
3476 /* Access the standard font file */
3477 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3479 /* Force the use of that font */
3480 (void)term_force_font(td, buf);
3485 /* Assume not bizarre */
3486 td->bizarre = FALSE;
3491 /* Analyze the font */
3494 /* Resize the window */
3495 term_window_resize(td);
3499 /* Sub windows (reverse order) */
3500 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3505 td->w = CreateWindowEx(td->dwExStyle, AngList,
3507 td->pos_x, td->pos_y,
3508 td->size_wid, td->size_hgt,
3509 HWND_DESKTOP, NULL, hInstance, NULL);
3511 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3515 td->size_hack = TRUE;
3516 ShowWindow(td->w, SW_SHOW);
3517 td->size_hack = FALSE;
3521 angband_term[i] = &td->t;
3525 /* Activate the window */
3526 SetActiveWindow(td->w);
3531 term_window_pos(&data[i], HWND_TOPMOST);
3535 term_window_pos(&data[i], td->w);
3545 td->w = CreateWindowEx(td->dwExStyle, AppName,
3547 td->pos_x, td->pos_y,
3548 td->size_wid, td->size_hgt,
3549 HWND_DESKTOP, NULL, hInstance, NULL);
3551 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3554 angband_term[0] = &td->t;
3555 normsize.x = td->cols;
3556 normsize.y = td->rows;
3558 /* Activate the main window */
3559 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3560 else ShowWindow(td->w, SW_SHOW);
3562 /* Bring main window back to top */
3563 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3567 (void)new_palette();
3570 /* Create a "brush" for drawing the "cursor" */
3571 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3574 /* Process pending messages */
3575 (void)Term_xtra_win_flush();
3583 static void setup_menus(void)
3587 HMENU hm = GetMenu(data[0].w);
3590 /* Menu "File", Disable all */
3591 EnableMenuItem(hm, IDM_FILE_NEW,
3592 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3593 EnableMenuItem(hm, IDM_FILE_OPEN,
3594 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3595 EnableMenuItem(hm, IDM_FILE_SAVE,
3596 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3597 EnableMenuItem(hm, IDM_FILE_EXIT,
3598 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3599 EnableMenuItem(hm, IDM_FILE_SCORE,
3600 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3603 /* No character available */
3604 if (!current_world_ptr->character_generated)
3606 /* Menu "File", Item "New" */
3607 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3609 /* Menu "File", Item "Open" */
3610 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3613 /* A character available */
3614 if (current_world_ptr->character_generated)
3616 /* Menu "File", Item "Save" */
3617 EnableMenuItem(hm, IDM_FILE_SAVE,
3618 MF_BYCOMMAND | MF_ENABLED);
3621 /* Menu "File", Item "Exit" */
3622 EnableMenuItem(hm, IDM_FILE_EXIT,
3623 MF_BYCOMMAND | MF_ENABLED);
3625 EnableMenuItem(hm, IDM_FILE_SCORE,
3626 MF_BYCOMMAND | MF_ENABLED);
3629 /* Menu "Window::Visibility" */
3630 for (i = 0; i < MAX_TERM_DATA; i++)
3632 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3633 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3635 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3636 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3638 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3639 MF_BYCOMMAND | MF_ENABLED);
3642 /* Menu "Window::Font" */
3643 for (i = 0; i < MAX_TERM_DATA; i++)
3645 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3646 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3648 if (data[i].visible)
3650 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3651 MF_BYCOMMAND | MF_ENABLED);
3655 /* Menu "Window::Window Position Fix" */
3656 for (i = 0; i < MAX_TERM_DATA; i++)
3658 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3659 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3661 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3662 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3664 if (data[i].visible)
3666 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3667 MF_BYCOMMAND | MF_ENABLED);
3671 /* Menu "Window::Bizarre Display" */
3672 for (i = 0; i < MAX_TERM_DATA; i++)
3674 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3675 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3677 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3678 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3680 if (data[i].visible)
3682 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3683 MF_BYCOMMAND | MF_ENABLED);
3688 /* Menu "Window::Increase Tile Width" */
3689 for (i = 0; i < MAX_TERM_DATA; i++)
3691 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3692 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3694 if (data[i].visible)
3696 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3697 MF_BYCOMMAND | MF_ENABLED);
3702 /* Menu "Window::Decrease Tile Width" */
3703 for (i = 0; i < MAX_TERM_DATA; i++)
3705 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3706 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3708 if (data[i].visible)
3710 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3711 MF_BYCOMMAND | MF_ENABLED);
3716 /* Menu "Window::Increase Tile Height" */
3717 for (i = 0; i < MAX_TERM_DATA; i++)
3719 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3720 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3722 if (data[i].visible)
3724 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3725 MF_BYCOMMAND | MF_ENABLED);
3730 /* Menu "Window::Decrease Tile Height" */
3731 for (i = 0; i < MAX_TERM_DATA; i++)
3733 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3734 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3736 if (data[i].visible)
3738 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3739 MF_BYCOMMAND | MF_ENABLED);
3744 /* Menu "Options", disable all */
3745 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3746 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3747 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3748 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3749 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3750 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3751 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3752 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3753 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3754 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3756 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3757 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3760 /* Menu "Options", Item "Map" */
3761 if (use_graphics != GRAPHICS_NONE)
3762 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3764 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3765 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3767 /* Menu "Options", update all */
3768 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3769 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3770 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3771 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3772 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3773 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3774 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3775 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3776 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3777 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3778 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3779 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3780 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3781 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3782 CheckMenuItem(hm, IDM_OPTIONS_BG,
3783 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3785 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3786 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3790 /* Menu "Options", Item "Graphics" */
3791 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3792 /* Menu "Options", Item "Graphics" */
3793 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3794 /* Menu "Options", Item "Graphics" */
3795 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3796 /* Menu "Options", Item "Graphics" */
3797 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3798 #endif /* USE_GRAPHICS */
3801 /* Menu "Options", Item "Sound" */
3802 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3803 #endif /* USE_SOUND */
3806 /* Menu "Options", Item "ScreenSaver" */
3807 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3808 MF_BYCOMMAND | MF_ENABLED);
3809 #endif /* USE_SAVER */
3814 * Check for double clicked (or dragged) savefile
3816 * Apparently, Windows copies the entire filename into the first
3817 * piece of the "command line string". Perhaps we should extract
3818 * the "basename" of that filename and append it to the "save" dir.
3820 static void check_for_save_file(LPSTR cmd_line)
3830 /* Extract filename */
3831 strcat(savefile, s);
3833 /* Validate the file */
3834 validate_file(savefile);
3836 /* Game in progress */
3837 game_in_progress = TRUE;
3845 * Process a menu command
3847 static void process_menus(WORD wCmd)
3863 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3865 else if (game_in_progress)
3867 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3871 game_in_progress = TRUE;
3884 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3886 else if (game_in_progress)
3888 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3892 memset(&ofn, 0, sizeof(ofn));
3893 ofn.lStructSize = sizeof(ofn);
3894 ofn.hwndOwner = data[0].w;
3895 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3896 ofn.nFilterIndex = 1;
3897 ofn.lpstrFile = savefile;
3898 ofn.nMaxFile = 1024;
3899 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3900 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3902 if (GetOpenFileName(&ofn))
3904 /* Load 'savefile' */
3905 validate_file(savefile);
3906 game_in_progress = TRUE;
3918 if (game_in_progress && current_world_ptr->character_generated)
3922 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3926 /* Hack -- Forget messages */
3931 do_cmd_save_game(FALSE);
3932 #else /* ZANGBAND */
3934 #endif /* ZANGBAND */
3938 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3946 if (game_in_progress && current_world_ptr->character_generated)
3950 plog(_("今は終了できません。", "You may not do that right now."));
3954 /* Hack -- Forget messages */
3963 /* do_cmd_save_game(FALSE); */
3964 #else /* ZANGBAND */
3965 /* do_cmd_save_game(); */
3966 #endif /* ZANGBAND */
3967 Term_key_push(SPECIAL_KEY_QUIT);
3975 case IDM_FILE_SCORE:
3979 /* Build the filename */
3980 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3982 /* Open the binary high score file, for reading */
3983 highscore_fd = fd_open(buf, O_RDONLY);
3985 /* Paranoia -- No score file */
3986 if (highscore_fd < 0)
3988 msg_print("Score file unavailable.");
3995 /* Display the scores */
3996 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3998 /* Shut the high score file */
3999 (void)fd_close(highscore_fd);
4001 /* Forget the high score fd */
4005 /* Hack - Flush it */
4013 case IDM_FILE_MOVIE:
4017 plog(_("まだ初期化中です...", "You cannot do that yet..."));
4019 else if (game_in_progress)
4021 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
4025 memset(&ofn, 0, sizeof(ofn));
4026 ofn.lStructSize = sizeof(ofn);
4027 ofn.hwndOwner = data[0].w;
4028 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
4029 ofn.nFilterIndex = 1;
4030 ofn.lpstrFile = savefile;
4031 ofn.nMaxFile = 1024;
4032 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
4033 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
4035 if (GetOpenFileName(&ofn))
4037 /* Load 'savefile' */
4038 prepare_browse_movie_aux(savefile);
4048 case IDM_WINDOW_VIS_0:
4050 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
4054 /* Window visibility */
4055 case IDM_WINDOW_VIS_1:
4056 case IDM_WINDOW_VIS_2:
4057 case IDM_WINDOW_VIS_3:
4058 case IDM_WINDOW_VIS_4:
4059 case IDM_WINDOW_VIS_5:
4060 case IDM_WINDOW_VIS_6:
4061 case IDM_WINDOW_VIS_7:
4063 i = wCmd - IDM_WINDOW_VIS_0;
4065 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4072 ShowWindow(td->w, SW_SHOW);
4073 term_data_redraw(td);
4077 td->visible = FALSE;
4079 ShowWindow(td->w, SW_HIDE);
4086 case IDM_WINDOW_FONT_0:
4087 case IDM_WINDOW_FONT_1:
4088 case IDM_WINDOW_FONT_2:
4089 case IDM_WINDOW_FONT_3:
4090 case IDM_WINDOW_FONT_4:
4091 case IDM_WINDOW_FONT_5:
4092 case IDM_WINDOW_FONT_6:
4093 case IDM_WINDOW_FONT_7:
4095 i = wCmd - IDM_WINDOW_FONT_0;
4097 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4101 term_change_font(td);
4106 /* Window Z Position */
4107 case IDM_WINDOW_POS_1:
4108 case IDM_WINDOW_POS_2:
4109 case IDM_WINDOW_POS_3:
4110 case IDM_WINDOW_POS_4:
4111 case IDM_WINDOW_POS_5:
4112 case IDM_WINDOW_POS_6:
4113 case IDM_WINDOW_POS_7:
4115 i = wCmd - IDM_WINDOW_POS_0;
4117 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4121 if (!td->posfix && td->visible)
4124 term_window_pos(td, HWND_TOPMOST);
4129 term_window_pos(td, data[0].w);
4135 /* Bizarre Display */
4136 case IDM_WINDOW_BIZ_0:
4137 case IDM_WINDOW_BIZ_1:
4138 case IDM_WINDOW_BIZ_2:
4139 case IDM_WINDOW_BIZ_3:
4140 case IDM_WINDOW_BIZ_4:
4141 case IDM_WINDOW_BIZ_5:
4142 case IDM_WINDOW_BIZ_6:
4143 case IDM_WINDOW_BIZ_7:
4145 i = wCmd - IDM_WINDOW_BIZ_0;
4147 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4151 td->bizarre = !td->bizarre;
4155 term_window_resize(td);
4160 /* Increase Tile Width */
4161 case IDM_WINDOW_I_WID_0:
4162 case IDM_WINDOW_I_WID_1:
4163 case IDM_WINDOW_I_WID_2:
4164 case IDM_WINDOW_I_WID_3:
4165 case IDM_WINDOW_I_WID_4:
4166 case IDM_WINDOW_I_WID_5:
4167 case IDM_WINDOW_I_WID_6:
4168 case IDM_WINDOW_I_WID_7:
4170 i = wCmd - IDM_WINDOW_I_WID_0;
4172 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4180 term_window_resize(td);
4185 /* Decrease Tile Height */
4186 case IDM_WINDOW_D_WID_0:
4187 case IDM_WINDOW_D_WID_1:
4188 case IDM_WINDOW_D_WID_2:
4189 case IDM_WINDOW_D_WID_3:
4190 case IDM_WINDOW_D_WID_4:
4191 case IDM_WINDOW_D_WID_5:
4192 case IDM_WINDOW_D_WID_6:
4193 case IDM_WINDOW_D_WID_7:
4195 i = wCmd - IDM_WINDOW_D_WID_0;
4197 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4205 term_window_resize(td);
4210 /* Increase Tile Height */
4211 case IDM_WINDOW_I_HGT_0:
4212 case IDM_WINDOW_I_HGT_1:
4213 case IDM_WINDOW_I_HGT_2:
4214 case IDM_WINDOW_I_HGT_3:
4215 case IDM_WINDOW_I_HGT_4:
4216 case IDM_WINDOW_I_HGT_5:
4217 case IDM_WINDOW_I_HGT_6:
4218 case IDM_WINDOW_I_HGT_7:
4220 i = wCmd - IDM_WINDOW_I_HGT_0;
4222 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4230 term_window_resize(td);
4235 /* Decrease Tile Height */
4236 case IDM_WINDOW_D_HGT_0:
4237 case IDM_WINDOW_D_HGT_1:
4238 case IDM_WINDOW_D_HGT_2:
4239 case IDM_WINDOW_D_HGT_3:
4240 case IDM_WINDOW_D_HGT_4:
4241 case IDM_WINDOW_D_HGT_5:
4242 case IDM_WINDOW_D_HGT_6:
4243 case IDM_WINDOW_D_HGT_7:
4245 i = wCmd - IDM_WINDOW_D_HGT_0;
4247 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4255 term_window_resize(td);
4260 case IDM_OPTIONS_NO_GRAPHICS:
4264 plog("You may not do that right now.");
4268 /* Toggle "arg_graphics" */
4269 if (arg_graphics != GRAPHICS_NONE)
4271 arg_graphics = GRAPHICS_NONE;
4273 /* React to changes */
4274 Term_xtra_win_react();
4276 /* Hack -- Force redraw */
4277 Term_key_push(KTRL('R'));
4283 case IDM_OPTIONS_OLD_GRAPHICS:
4287 plog("You may not do that right now.");
4291 /* Toggle "arg_graphics" */
4292 if (arg_graphics != GRAPHICS_ORIGINAL)
4294 arg_graphics = GRAPHICS_ORIGINAL;
4296 /* React to changes */
4297 Term_xtra_win_react();
4299 /* Hack -- Force redraw */
4300 Term_key_push(KTRL('R'));
4306 case IDM_OPTIONS_NEW_GRAPHICS:
4310 plog("You may not do that right now.");
4314 /* Toggle "arg_graphics" */
4315 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4317 arg_graphics = GRAPHICS_ADAM_BOLT;
4319 /* React to changes */
4320 Term_xtra_win_react();
4322 /* Hack -- Force redraw */
4323 Term_key_push(KTRL('R'));
4329 case IDM_OPTIONS_NEW2_GRAPHICS:
4333 plog("You may not do that right now.");
4337 /* Toggle "arg_graphics" */
4338 if (arg_graphics != GRAPHICS_HENGBAND)
4340 arg_graphics = GRAPHICS_HENGBAND;
4342 /* React to changes */
4343 Term_xtra_win_react();
4345 /* Hack -- Force redraw */
4346 Term_key_push(KTRL('R'));
4352 case IDM_OPTIONS_BIGTILE:
4357 plog("You may not do that right now.");
4361 /* Toggle "arg_sound" */
4362 arg_bigtile = !arg_bigtile;
4365 Term_activate(&td->t);
4367 /* Resize the term */
4368 Term_resize(td->cols, td->rows);
4371 InvalidateRect(td->w, NULL, TRUE);
4376 case IDM_OPTIONS_MUSIC:
4380 plog("You may not do that right now.");
4384 /* Toggle "arg_sound" */
4385 arg_music = !arg_music;
4387 /* React to changes */
4388 Term_xtra_win_react();
4390 /* Hack -- Force redraw */
4391 Term_key_push(KTRL('R'));
4396 case IDM_OPTIONS_SOUND:
4400 plog("You may not do that right now.");
4404 /* Toggle "arg_sound" */
4405 arg_sound = !arg_sound;
4407 /* React to changes */
4408 Term_xtra_win_react();
4410 /* Hack -- Force redraw */
4411 Term_key_push(KTRL('R'));
4417 case IDM_OPTIONS_BG:
4421 plog("You may not do that right now.");
4425 /* Toggle "use_bg" */
4430 /* React to changes */
4431 Term_xtra_win_react();
4433 /* Hack -- Force redraw */
4434 Term_key_push(KTRL('R'));
4440 case IDM_OPTIONS_OPEN_BG:
4444 plog("You may not do that right now.");
4449 memset(&ofn, 0, sizeof(ofn));
4450 ofn.lStructSize = sizeof(ofn);
4451 ofn.hwndOwner = data[0].w;
4452 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4453 ofn.nFilterIndex = 1;
4454 ofn.lpstrFile = bg_bitmap_file;
4455 ofn.nMaxFile = 1023;
4456 ofn.lpstrInitialDir = NULL;
4457 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
4458 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4460 if (GetOpenFileName(&ofn))
4462 /* Load 'savefile' */
4467 /* React to changes */
4468 Term_xtra_win_react();
4470 /* Hack -- Force redraw */
4471 Term_key_push(KTRL('R'));
4476 case IDM_DUMP_SCREEN_HTML:
4478 static char buf[1024] = "";
4479 memset(&ofn, 0, sizeof(ofn));
4480 ofn.lStructSize = sizeof(ofn);
4481 ofn.hwndOwner = data[0].w;
4482 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4483 ofn.nFilterIndex = 1;
4484 ofn.lpstrFile = buf;
4485 ofn.nMaxFile = 1023;
4486 ofn.lpstrDefExt = "html";
4487 ofn.lpstrInitialDir = NULL;
4488 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
4489 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4491 if (GetSaveFileName(&ofn))
4493 do_cmd_save_screen_html_aux(buf, 0);
4500 case IDM_OPTIONS_SAVER:
4504 DestroyWindow(hwndSaver);
4509 /* Create a screen scaver window */
4510 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4511 "Angband Screensaver",
4512 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4513 0, 0, GetSystemMetrics(SM_CXSCREEN),
4514 GetSystemMetrics(SM_CYSCREEN),
4515 NULL, NULL, hInstance, NULL);
4519 /* Push the window to the bottom */
4520 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4524 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
4532 case IDM_OPTIONS_MAP:
4538 case IDM_HELP_CONTENTS:
4542 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4543 if (check_file(tmp))
4545 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4549 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4550 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4553 #else /* HTML_HELP */
4556 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4557 if (check_file(tmp))
4559 sprintf(buf, "winhelp.exe %s", tmp);
4560 WinExec(buf, SW_NORMAL);
4564 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4565 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4569 #endif /* HTML_HELP */
4575 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4582 /* Extract the modifiers */
4583 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4584 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4585 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4587 Term_no_press = (ma) ? TRUE : FALSE;
4589 /* Handle "special" keys */
4590 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4592 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4593 bool numpad = FALSE;
4595 /* Begin the macro trigger */
4598 /* Send the modifiers */
4599 if (mc) Term_keypress('C');
4600 if (ms) Term_keypress('S');
4601 if (ma) Term_keypress('A');
4603 /* Extract "scan code" */
4604 i = LOBYTE(HIWORD(lParam));
4606 /* Introduce the scan code */
4609 /* Extended key bit */
4612 /* Numpad Enter and '/' are extended key */
4614 Term_no_press = TRUE;
4615 case VK_RETURN: /* Enter */
4618 /* Other extended keys are on full keyboard */
4634 Term_no_press = TRUE;
4638 case VK_PRIOR: /* Page Up */
4639 case VK_NEXT: /* Page Down */
4649 /* Special modifiers for keypad keys */
4650 if (numpad) Term_keypress('K');
4652 /* Encode the hexidecimal scan code */
4653 Term_keypress(hexsym[i/16]);
4654 Term_keypress(hexsym[i%16]);
4656 /* End the macro trigger */
4667 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4668 WPARAM wParam, LPARAM lParam);
4669 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4670 WPARAM wParam, LPARAM lParam)
4671 #else /* __MWERKS__ */
4672 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4673 #endif /* __MWERKS__ */
4679 MINMAXINFO FAR *lpmmi;
4685 /* Acquire proper "term_data" info */
4686 td = (term_data *)GetWindowLong(hWnd, 0);
4688 /* Handle message */
4693 SetWindowLong(hWnd, 0, (LONG)(my_td));
4700 mop.dwCallback=(DWORD)hWnd;
4705 case WM_GETMINMAXINFO:
4707 MINMAXINFO FAR *lpmmi;
4710 lpmmi = (MINMAXINFO FAR *)lParam;
4712 /* this message was sent before WM_NCCREATE */
4715 /* Minimum window size is 80x24 */
4716 rc.left = rc.top = 0;
4717 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4718 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4721 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4723 /* Save minimum size */
4724 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4725 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4732 BeginPaint(hWnd, &ps);
4733 if (td) term_data_redraw(td);
4734 EndPaint(hWnd, &ps);
4735 ValidateRect(hWnd, NULL);
4742 if(wParam == MCI_NOTIFY_SUCCESSFUL)
4744 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4745 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4754 if (process_keydown(wParam, lParam))
4761 if (Term_no_press) Term_no_press = FALSE;
4762 else Term_keypress(wParam);
4766 case WM_LBUTTONDOWN:
4768 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4769 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4781 TERM_LEN dx = abs(oldx - mousex) + 1;
4782 TERM_LEN dy = abs(oldy - mousey) + 1;
4783 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
4784 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
4794 hGlobal = GlobalAlloc(GHND, sz + 1);
4795 if (hGlobal == NULL) return 0;
4796 lpStr = (LPSTR)GlobalLock(hGlobal);
4798 for (i = 0; i < dy; i++)
4802 char **scr = data[0].t.scr->c;
4804 C_MAKE(s, (dx + 1), char);
4805 strncpy(s, &scr[oy + i][ox], dx);
4809 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4812 if (ox + dx < data[0].cols)
4814 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4817 for (j = 0; j < dx; j++)
4819 if (s[j] == 127) s[j] = '#';
4823 for (j = 0; j < dx; j++)
4825 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4835 GlobalUnlock(hGlobal);
4836 if (OpenClipboard(hWnd) == 0)
4838 GlobalFree(hGlobal);
4842 SetClipboardData(CF_TEXT, hGlobal);
4855 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4856 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4861 dx = abs(oldx - mousex) + 1;
4862 dy = abs(oldy - mousey) + 1;
4863 ox = (oldx > mousex) ? mousex : oldx;
4864 oy = (oldy > mousey) ? mousey : oldy;
4865 Term_inversed_area(hWnd, ox, oy, dx, dy);
4872 dx = abs(cx - mousex) + 1;
4873 dy = abs(cy - mousey) + 1;
4874 ox = (cx > mousex) ? mousex : cx;
4875 oy = (cy > mousey) ? mousey : cy;
4876 Term_inversed_area(hWnd, ox, oy, dx, dy);
4892 if (game_in_progress && current_world_ptr->character_generated)
4896 plog(_("今は終了できません。", "You may not do that right now."));
4900 /* Hack -- Forget messages */
4909 /* do_cmd_save_game(FALSE); */
4910 #else /* ZANGBAND */
4911 /* do_cmd_save_game(); */
4912 #endif /* ZANGBAND */
4913 Term_key_push(SPECIAL_KEY_QUIT);
4920 case WM_QUERYENDSESSION:
4922 if (game_in_progress && current_world_ptr->character_generated)
4924 /* Hack -- Forget messages */
4927 /* Mega-Hack -- Delay death */
4928 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4929 do_cmd_write_nikki(NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4931 /* Hardcode panic save */
4932 p_ptr->panic_save = 1;
4934 /* Forbid suspend */
4935 signals_ignore_tstp();
4937 /* Indicate panic save */
4938 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4941 (void)save_player();
4955 process_menus(LOWORD(wParam));
4961 /* this message was sent before WM_NCCREATE */
4964 /* it was sent from inside CreateWindowEx */
4965 if (!td->w) return 1;
4967 /* was sent from WM_SIZE */
4968 if (td->size_hack) return 1;
4972 case SIZE_MINIMIZED:
4974 /* Hide sub-windows */
4975 for (i = 1; i < MAX_TERM_DATA; i++)
4977 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4982 case SIZE_MAXIMIZED:
4989 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4990 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4993 if ((td->cols != cols) || (td->rows != rows))
4995 /* Save the new size */
4999 if (!IsZoomed(td->w) && !IsIconic(td->w))
5001 normsize.x = td->cols;
5002 normsize.y = td->rows;
5006 Term_activate(&td->t);
5008 /* Resize the term */
5009 Term_resize(td->cols, td->rows);
5012 InvalidateRect(td->w, NULL, TRUE);
5015 td->size_hack = TRUE;
5017 /* Show sub-windows */
5018 for (i = 1; i < MAX_TERM_DATA; i++)
5020 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
5023 td->size_hack = FALSE;
5031 case WM_PALETTECHANGED:
5033 /* Ignore if palette change caused by itself */
5034 if ((HWND)wParam == hWnd) return 0;
5036 /* Fall through... */
5039 case WM_QUERYNEWPALETTE:
5041 if (!paletted) return 0;
5045 SelectPalette(hdc, hPal, FALSE);
5047 i = RealizePalette(hdc);
5049 /* if any palette entries changed, repaint the window. */
5050 if (i) InvalidateRect(hWnd, NULL, TRUE);
5052 ReleaseDC(hWnd, hdc);
5059 if (wParam && !HIWORD(lParam))
5061 /* Do something to sub-windows */
5062 for (i = 1; i < MAX_TERM_DATA; i++)
5064 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
5067 /* Focus on main window */
5076 case WM_ACTIVATEAPP:
5078 if (IsIconic(td->w)) break;
5080 for (i = 1; i < MAX_TERM_DATA; i++)
5086 ShowWindow(data[i].w, SW_SHOW);
5090 ShowWindow(data[i].w, SW_HIDE);
5097 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5102 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5103 WPARAM wParam, LPARAM lParam);
5104 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5105 WPARAM wParam, LPARAM lParam)
5106 #else /* __MWERKS__ */
5107 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5108 WPARAM wParam, LPARAM lParam)
5109 #endif /* __MWERKS__ */
5113 MINMAXINFO FAR *lpmmi;
5121 /* Acquire proper "term_data" info */
5122 td = (term_data *)GetWindowLong(hWnd, 0);
5124 /* Process message */
5129 SetWindowLong(hWnd, 0, (LONG)(my_td));
5138 case WM_GETMINMAXINFO:
5140 MINMAXINFO FAR *lpmmi;
5143 lpmmi = (MINMAXINFO FAR *)lParam;
5145 /* this message was sent before WM_NCCREATE */
5148 /* Minimum window size is 80x24 */
5149 rc.left = rc.top = 0;
5150 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5151 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5154 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5156 /* Save minimum size */
5157 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5158 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5168 /* this message was sent before WM_NCCREATE */
5171 /* it was sent from inside CreateWindowEx */
5172 if (!td->w) return 1;
5174 /* was sent from inside WM_SIZE */
5175 if (td->size_hack) return 1;
5177 td->size_hack = TRUE;
5179 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5180 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5183 if ((td->cols != cols) || (td->rows != rows))
5186 term *old_term = Term;
5188 /* Save the new size */
5193 Term_activate(&td->t);
5195 /* Resize the term */
5196 Term_resize(td->cols, td->rows);
5199 Term_activate(old_term);
5202 InvalidateRect(td->w, NULL, TRUE);
5204 /* HACK - Redraw all windows */
5205 p_ptr->window = 0xFFFFFFFF;
5209 td->size_hack = FALSE;
5216 BeginPaint(hWnd, &ps);
5217 if (td) term_data_redraw(td);
5218 EndPaint(hWnd, &ps);
5225 if (process_keydown(wParam, lParam))
5232 if (Term_no_press) Term_no_press = FALSE;
5233 else Term_keypress(wParam);
5237 case WM_PALETTECHANGED:
5239 /* ignore if palette change caused by itself */
5240 if ((HWND)wParam == hWnd) return FALSE;
5241 /* otherwise, fall through!!! */
5244 case WM_QUERYNEWPALETTE:
5246 if (!paletted) return 0;
5248 SelectPalette(hdc, hPal, FALSE);
5249 i = RealizePalette(hdc);
5250 /* if any palette entries changed, repaint the window. */
5251 if (i) InvalidateRect(hWnd, NULL, TRUE);
5252 ReleaseDC(hWnd, hdc);
5256 case WM_NCLBUTTONDOWN:
5260 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5261 #endif /* HTCLOSE */
5263 if (wParam == HTSYSMENU)
5267 td->visible = FALSE;
5268 ShowWindow(td->w, SW_HIDE);
5278 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5284 #define MOUSE_SENS 40
5287 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5288 WPARAM wParam, LPARAM lParam);
5289 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5290 WPARAM wParam, LPARAM lParam)
5291 #else /* __MWERKS__ */
5292 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5293 WPARAM wParam, LPARAM lParam)
5294 #endif /* __MWERKS__ */
5296 static int iMouse = 0;
5297 static WORD xMouse = 0;
5298 static WORD yMouse = 0;
5320 if (LOWORD(wParam) == WA_INACTIVE) break;
5322 /* else fall through */
5326 case WM_LBUTTONDOWN:
5327 case WM_MBUTTONDOWN:
5328 case WM_RBUTTONDOWN:
5331 SendMessage(hWnd, WM_CLOSE, 0, 0);
5339 dx = LOWORD(lParam) - xMouse;
5340 dy = HIWORD(lParam) - yMouse;
5342 if (dx < 0) dx = -dx;
5343 if (dy < 0) dy = -dy;
5345 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5347 SendMessage(hWnd, WM_CLOSE, 0, 0);
5351 /* Save last location */
5353 xMouse = LOWORD(lParam);
5354 yMouse = HIWORD(lParam);
5361 DestroyWindow(hwndSaver);
5367 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5370 #endif /* USE_SAVER */
5376 /*** Temporary Hooks ***/
5380 * Display warning message (see "z-util.c")
5382 static void hack_plog(concptr str)
5384 /* Give a warning */
5388 MessageBox(NULL, str, "警告!",
5389 MB_ICONEXCLAMATION | MB_OK);
5391 MessageBox(NULL, str, "Warning",
5392 MB_ICONEXCLAMATION | MB_OK);
5400 * Display error message and quit (see "z-util.c")
5402 static void hack_quit(concptr str)
5404 /* Give a warning */
5408 MessageBox(NULL, str, "エラー!",
5409 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5411 MessageBox(NULL, str, "Error",
5412 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5417 /* Unregister the classes */
5418 UnregisterClass(AppName, hInstance);
5420 /* Destroy the icon */
5421 if (hIcon) DestroyIcon(hIcon);
5429 /*** Various hooks ***/
5433 * Display warning message (see "z-util.c")
5435 static void hook_plog(concptr str)
5441 MessageBox(data[0].w, str, "警告!",
5442 MB_ICONEXCLAMATION | MB_OK);
5444 MessageBox(data[0].w, str, "Warning",
5445 MB_ICONEXCLAMATION | MB_OK);
5453 * Display error message and quit (see "z-util.c")
5455 static void hook_quit(concptr str)
5460 /* Give a warning */
5464 MessageBox(data[0].w, str, "エラー!",
5465 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5467 MessageBox(data[0].w, str, "Error",
5468 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5474 /* Save the preferences */
5478 /*** Could use 'Term_nuke_win()' */
5480 /* Destroy all windows */
5481 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5483 term_force_font(&data[i], NULL);
5484 if (data[i].font_want) string_free(data[i].font_want);
5485 if (data[i].w) DestroyWindow(data[i].w);
5489 /* Free the bitmap stuff */
5491 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5492 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5494 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5495 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5497 #endif /* USE_GRAPHICS */
5499 /*** Free some other stuff ***/
5501 DeleteObject(hbrYellow);
5506 if (hPal) DeleteObject(hPal);
5508 UnregisterClass(AppName, hInstance);
5510 if (hIcon) DestroyIcon(hIcon);
5517 /*** Initialize ***/
5523 static void init_stuff(void)
5530 /* Get program name with full path */
5531 GetModuleFileName(hInstance, path, 512);
5533 /* Save the "program name" */
5536 /* Get the name of the "*.ini" file */
5537 strcpy(path + strlen(path) - 4, ".INI");
5539 /* Save the the name of the ini-file */
5540 ini_file = string_make(path);
5542 /* Analyze the path */
5548 if (path[i] == '\\')
5555 /* Add "lib" to the path */
5556 strcpy(path + i + 1, "lib\\");
5558 /* Validate the path */
5559 validate_dir(path, TRUE);
5561 /* Init the file paths */
5562 init_file_paths(path);
5564 /* Hack -- Validate the paths */
5565 validate_dir(ANGBAND_DIR_APEX, FALSE);
5566 validate_dir(ANGBAND_DIR_BONE, FALSE);
5568 /* Allow missing 'edit' directory */
5569 if (!check_dir(ANGBAND_DIR_EDIT))
5571 /* Must have 'data'! */
5572 validate_dir(ANGBAND_DIR_DATA, TRUE);
5576 /* Don't need 'data' */
5577 validate_dir(ANGBAND_DIR_DATA, FALSE);
5580 validate_dir(ANGBAND_DIR_FILE, TRUE);
5581 validate_dir(ANGBAND_DIR_HELP, FALSE);
5582 validate_dir(ANGBAND_DIR_INFO, FALSE);
5583 validate_dir(ANGBAND_DIR_PREF, TRUE);
5584 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5585 validate_dir(ANGBAND_DIR_USER, TRUE);
5586 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5588 /* Build the filename */
5589 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
5591 /* Hack -- Validate the "news.txt" file */
5592 validate_file(path);
5595 #if 0 /* #ifndef JP */
5596 /* Build the "font" path */
5597 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5599 /* Allocate the path */
5600 ANGBAND_DIR_XTRA_FONT = string_make(path);
5602 /* Validate the "font" directory */
5603 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5605 /* Build the filename */
5606 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5608 /* Hack -- Validate the basic font */
5609 validate_file(path);
5615 /* Build the "graf" path */
5616 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5618 /* Allocate the path */
5619 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5621 /* Validate the "graf" directory */
5622 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5624 #endif /* USE_GRAPHICS */
5629 /* Build the "sound" path */
5630 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5632 /* Allocate the path */
5633 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5635 /* Validate the "sound" directory */
5636 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5638 #endif /* USE_SOUND */
5642 /* Build the "music" path */
5643 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5645 /* Allocate the path */
5646 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5648 /* Validate the "music" directory */
5649 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5651 #endif /* USE_MUSIC */
5653 /* Build the "help" path */
5654 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5656 /* Allocate the path */
5657 ANGBAND_DIR_XTRA_HELP = string_make(path);
5659 /* Validate the "help" directory */
5660 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5664 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
5666 static bool is_already_running(void)
5668 bool result = FALSE;
5671 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5672 if (GetLastError() == ERROR_ALREADY_EXISTS)
5681 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
5683 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5684 LPSTR lpCmdLine, int nCmdShow)
5692 setlocale(LC_ALL, "ja_JP.utf8");
5701 /* Prevent multiple run */
5702 if (is_already_running())
5705 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
5706 _("エラー!", "Error") ,
5707 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5711 if (hPrevInst == NULL)
5713 wc.style = CS_CLASSDC;
5714 wc.lpfnWndProc = AngbandWndProc;
5716 wc.cbWndExtra = 4; /* one long pointer to term_data */
5717 wc.hInstance = hInst;
5718 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5719 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5720 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5721 wc.lpszMenuName = AppName;
5722 wc.lpszClassName = AppName;
5724 if (!RegisterClass(&wc)) exit(1);
5726 wc.lpfnWndProc = AngbandListProc;
5727 wc.lpszMenuName = NULL;
5728 wc.lpszClassName = AngList;
5730 if (!RegisterClass(&wc)) exit(2);
5734 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5735 wc.lpfnWndProc = AngbandSaverProc;
5737 wc.lpszMenuName = NULL;
5738 wc.lpszClassName = "WindowsScreenSaverClass";
5740 if (!RegisterClass(&wc)) exit(3);
5746 /* Temporary hooks */
5747 plog_aux = hack_plog;
5748 quit_aux = hack_quit;
5749 core_aux = hack_quit;
5751 /* Prepare the filepaths */
5754 /* Initialize the keypress analyzer */
5755 for (i = 0; special_key_list[i]; ++i)
5757 special_key[special_key_list[i]] = TRUE;
5759 /* Initialize the keypress analyzer */
5760 for (i = 0; ignore_key_list[i]; ++i)
5762 ignore_key[ignore_key_list[i]] = TRUE;
5765 /* Determine if display is 16/256/true color */
5767 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5768 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5769 ReleaseDC(NULL, hdc);
5771 /* Initialize the colors */
5772 for (i = 0; i < 256; i++)
5776 /* Extract desired values */
5777 rv = angband_color_table[i][1];
5778 gv = angband_color_table[i][2];
5779 bv = angband_color_table[i][3];
5781 /* Extract the "complex" code */
5782 win_clr[i] = PALETTERGB(rv, gv, bv);
5784 /* Save the "simple" code */
5785 angband_color_table[i][0] = win_pal[i];
5788 /* Prepare the windows */
5794 /* Activate hooks */
5795 plog_aux = hook_plog;
5796 quit_aux = hook_quit;
5797 core_aux = hook_quit;
5799 /* Set the system suffix */
5800 ANGBAND_SYS = "win";
5802 /* Set the keyboard suffix */
5803 if (7 != GetKeyboardType(0))
5804 ANGBAND_KEYBOARD = "0";
5807 /* Japanese keyboard */
5808 switch (GetKeyboardType(1))
5810 case 0x0D01: case 0x0D02:
5811 case 0x0D03: case 0x0D04:
5812 case 0x0D05: case 0x0D06:
5814 ANGBAND_KEYBOARD = "NEC98";
5818 ANGBAND_KEYBOARD = "JAPAN";
5822 /* Catch nasty signals */
5825 Term_activate(term_screen);
5828 /* We are now initialized */
5831 if(lpCmdLine[0] == '-'){
5832 switch(lpCmdLine[1])
5837 if (!lpCmdLine[2]) break;
5838 chuukei_server = TRUE;
5839 if(connect_chuukei_server(&lpCmdLine[2])<0){
5840 msg_print("connect fail");
5843 msg_print("connect");
5851 if (!lpCmdLine[2]) break;
5852 chuukei_client = TRUE;
5853 connect_chuukei_server(&lpCmdLine[2]);
5861 if (!lpCmdLine[2]) break;
5862 prepare_browse_movie(&lpCmdLine[2]);
5872 /* Did the user double click on a save file? */
5873 if(!chuukei_server) check_for_save_file(lpCmdLine);
5875 /* Did the user double click on a save file? */
5876 check_for_save_file(lpCmdLine);
5879 /* Prompt the user */
5880 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
5884 /* Process messages forever */
5885 while (GetMessage(&msg, NULL, 0, 0))
5887 TranslateMessage(&msg);
5888 DispatchMessage(&msg);
5895 #endif /* WINDOWS */