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"
126 * Extract the "WIN32" flag from the compiler
128 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
136 * Hack -- allow use of "screen saver" mode
142 * Menu constants -- see "ANGBAND.RC"
145 #define IDM_FILE_NEW 100
146 #define IDM_FILE_OPEN 101
147 #define IDM_FILE_SAVE 110
148 #define IDM_FILE_SCORE 120
149 #define IDM_FILE_MOVIE 121
150 #define IDM_FILE_EXIT 130
152 #define IDM_WINDOW_VIS_0 200
153 #define IDM_WINDOW_VIS_1 201
154 #define IDM_WINDOW_VIS_2 202
155 #define IDM_WINDOW_VIS_3 203
156 #define IDM_WINDOW_VIS_4 204
157 #define IDM_WINDOW_VIS_5 205
158 #define IDM_WINDOW_VIS_6 206
159 #define IDM_WINDOW_VIS_7 207
161 #define IDM_WINDOW_FONT_0 210
162 #define IDM_WINDOW_FONT_1 211
163 #define IDM_WINDOW_FONT_2 212
164 #define IDM_WINDOW_FONT_3 213
165 #define IDM_WINDOW_FONT_4 214
166 #define IDM_WINDOW_FONT_5 215
167 #define IDM_WINDOW_FONT_6 216
168 #define IDM_WINDOW_FONT_7 217
170 #define IDM_WINDOW_POS_0 220
171 #define IDM_WINDOW_POS_1 221
172 #define IDM_WINDOW_POS_2 222
173 #define IDM_WINDOW_POS_3 223
174 #define IDM_WINDOW_POS_4 224
175 #define IDM_WINDOW_POS_5 225
176 #define IDM_WINDOW_POS_6 226
177 #define IDM_WINDOW_POS_7 227
179 #define IDM_WINDOW_BIZ_0 230
180 #define IDM_WINDOW_BIZ_1 231
181 #define IDM_WINDOW_BIZ_2 232
182 #define IDM_WINDOW_BIZ_3 233
183 #define IDM_WINDOW_BIZ_4 234
184 #define IDM_WINDOW_BIZ_5 235
185 #define IDM_WINDOW_BIZ_6 236
186 #define IDM_WINDOW_BIZ_7 237
188 #define IDM_WINDOW_I_WID_0 240
189 #define IDM_WINDOW_I_WID_1 241
190 #define IDM_WINDOW_I_WID_2 242
191 #define IDM_WINDOW_I_WID_3 243
192 #define IDM_WINDOW_I_WID_4 244
193 #define IDM_WINDOW_I_WID_5 245
194 #define IDM_WINDOW_I_WID_6 246
195 #define IDM_WINDOW_I_WID_7 247
197 #define IDM_WINDOW_D_WID_0 250
198 #define IDM_WINDOW_D_WID_1 251
199 #define IDM_WINDOW_D_WID_2 252
200 #define IDM_WINDOW_D_WID_3 253
201 #define IDM_WINDOW_D_WID_4 254
202 #define IDM_WINDOW_D_WID_5 255
203 #define IDM_WINDOW_D_WID_6 256
204 #define IDM_WINDOW_D_WID_7 257
206 #define IDM_WINDOW_I_HGT_0 260
207 #define IDM_WINDOW_I_HGT_1 261
208 #define IDM_WINDOW_I_HGT_2 262
209 #define IDM_WINDOW_I_HGT_3 263
210 #define IDM_WINDOW_I_HGT_4 264
211 #define IDM_WINDOW_I_HGT_5 265
212 #define IDM_WINDOW_I_HGT_6 266
213 #define IDM_WINDOW_I_HGT_7 267
215 #define IDM_WINDOW_D_HGT_0 270
216 #define IDM_WINDOW_D_HGT_1 271
217 #define IDM_WINDOW_D_HGT_2 272
218 #define IDM_WINDOW_D_HGT_3 273
219 #define IDM_WINDOW_D_HGT_4 274
220 #define IDM_WINDOW_D_HGT_5 275
221 #define IDM_WINDOW_D_HGT_6 276
222 #define IDM_WINDOW_D_HGT_7 277
224 #define IDM_OPTIONS_NO_GRAPHICS 400
225 #define IDM_OPTIONS_OLD_GRAPHICS 401
226 #define IDM_OPTIONS_NEW_GRAPHICS 402
227 #define IDM_OPTIONS_NEW2_GRAPHICS 403
228 #define IDM_OPTIONS_BIGTILE 409
229 #define IDM_OPTIONS_SOUND 410
230 #define IDM_OPTIONS_MUSIC 411
231 #define IDM_OPTIONS_SAVER 420
232 #define IDM_OPTIONS_MAP 430
233 #define IDM_OPTIONS_BG 440
234 #define IDM_OPTIONS_OPEN_BG 441
236 #define IDM_DUMP_SCREEN_HTML 450
238 #define IDM_HELP_CONTENTS 901
241 * Exclude parts of WINDOWS.H that are not needed
243 #define NOCOMM /* Comm driver APIs and definitions */
244 #define NOLOGERROR /* LogError() and related definitions */
245 #define NOPROFILER /* Profiler APIs */
246 #define NOLFILEIO /* _l* file I/O routines */
247 #define NOOPENFILE /* OpenFile and related definitions */
248 #define NORESOURCE /* Resource management */
249 #define NOATOM /* Atom management */
250 #define NOLANGUAGE /* Character test routines */
251 #define NOLSTRING /* lstr* string management routines */
252 #define NODBCS /* Double-byte character set routines */
253 #define NOKEYBOARDINFO /* Keyboard driver routines */
254 #define NOCOLOR /* COLOR_* color values */
255 #define NODRAWTEXT /* DrawText() and related definitions */
256 #define NOSCALABLEFONT /* Truetype scalable font support */
257 #define NOMETAFILE /* Metafile support */
258 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
259 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
260 #define NOKEYSTATES /* MK_* message key state flags */
261 #define NOWH /* SetWindowsHook and related WH_* definitions */
262 #define NOCLIPBOARD /* Clipboard APIs and definitions */
263 #define NOICONS /* IDI_* icon IDs */
264 #define NOMDI /* MDI support */
265 #define NOHELP /* Help support */
267 /* Not defined since it breaks Borland C++ 5.5 */
268 /* #define NOCTLMGR */ /* Control management and controls */
271 * Exclude parts of WINDOWS.H that are not needed (Win32)
273 #define WIN32_LEAN_AND_MEAN
274 #define NONLS /* All NLS defines and routines */
275 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
276 #define NOKANJI /* Kanji support stuff. */
277 #define NOMCX /* Modem Configuration Extensions */
280 * Include the "windows" support file
285 * Exclude parts of MMSYSTEM.H that are not needed
287 #define MMNODRV /* Installable driver support */
288 #define MMNOWAVE /* Waveform support */
289 #define MMNOMIDI /* MIDI support */
290 #define MMNOAUX /* Auxiliary audio support */
291 #define MMNOTIMER /* Timer support */
292 #define MMNOJOY /* Joystick support */
293 #define MMNOMCI /* MCI support */
294 #define MMNOMMIO /* Multimedia file I/O support */
295 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
299 * Standard sound names
301 const concptr angband_sound_name[SOUND_MAX] =
373 * Standard music names
375 const concptr angband_music_basic_name[MUSIC_BASIC_MAX] =
401 * Include some more files. Note: the Cygnus Cygwin compiler
402 * doesn't use mmsystem.h instead it includes the winmm library
403 * which performs a similar function.
405 #include <mmsystem.h>
409 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
410 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
412 /* #define HTML_HELP */
415 #include <htmlhelp.h>
416 #endif /* HTML_HELP */
419 * Include the support for loading bitmaps
422 # include "readdib.h"
426 * Hack -- Fake declarations from "dos.h"
429 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
431 #define FA_LABEL 0x08 /* Volume label */
432 #define FA_DIREC 0x10 /* Directory */
433 unsigned _cdecl _dos_getfileattr(concptr , unsigned *);
437 * Silliness in WIN32 drawing routine
440 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
444 * Silliness for Windows 95
446 #ifndef WS_EX_TOOLWINDOW
447 # define WS_EX_TOOLWINDOW 0
451 * Foreground color bits (hard-coded by DOS)
453 #define VID_BLACK 0x00
454 #define VID_BLUE 0x01
455 #define VID_GREEN 0x02
456 #define VID_CYAN 0x03
458 #define VID_MAGENTA 0x05
459 #define VID_YELLOW 0x06
460 #define VID_WHITE 0x07
463 * Bright text (hard-coded by DOS)
465 #define VID_BRIGHT 0x08
468 * Background color bits (hard-coded by DOS)
470 #define VUD_BLACK 0x00
471 #define VUD_BLUE 0x10
472 #define VUD_GREEN 0x20
473 #define VUD_CYAN 0x30
475 #define VUD_MAGENTA 0x50
476 #define VUD_YELLOW 0x60
477 #define VUD_WHITE 0x70
480 * Blinking text (hard-coded by DOS)
482 #define VUD_BRIGHT 0x80
488 typedef struct _term_data term_data;
492 * @brief ターム情報構造体 / Extra "term" data
495 * pos_x / pos_y は各タームの左上点座標を指す。
498 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
499 * 1ドットずつ調整するステータスを指す。
500 * また、フォントを変更すると都度自動調整される。
503 * Note the use of "font_want" for the names of the font file requested by
504 * the user, and the use of "font_file" for the currently active font file.
506 * The "font_file" is uppercased, and takes the form "8X13.FON", while
507 * "font_want" can be in almost any form as long as it could be construed
508 * as attempting to represent the name of a font.
520 TERM_LEN rows; /* int -> uint */
523 uint pos_x; //!< タームの左上X座標
524 uint pos_y; //!< タームの左上Y座標
539 int font_wid; //!< フォント横幅
540 int font_hgt; //!< フォント縦幅
541 int tile_wid; //!< タイル横幅
542 int tile_hgt; //!< タイル縦幅
548 #if 1 /* #ifdef JP */
556 #define MAX_TERM_DATA 8 //!< Maximum number of windows
558 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
559 static term_data *my_td; //!< Hack -- global "window creation" pointer
560 POINT normsize; //!< Remember normal size of main window when maxmized
563 * was main window maximized on previous playing
565 bool win_maximized = FALSE;
570 bool game_in_progress = FALSE;
573 * note when "open"/"new" become valid
575 bool initialized = FALSE;
578 * screen paletted, i.e. 256 colors
580 bool paletted = FALSE;
583 * 16 colors screen, don't use RGB()
585 bool colors16 = FALSE;
588 * Saved instance handle
590 static HINSTANCE hInstance;
593 * Yellow brush for the cursor
595 static HBRUSH hbrYellow;
605 static HPALETTE hPal;
608 static HBITMAP hBG = NULL;
609 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
610 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
615 * The screen saver window
617 static HWND hwndSaver;
619 #endif /* USE_SAVER */
625 * 現在使用中のタイルID(0ならば未使用)
626 * Flag set once "graphics" has been initialized
628 static byte_hack current_graphics_mode = 0;
633 static DIBINIT infGraph;
636 * The global bitmap mask
638 static DIBINIT infMask;
640 #endif /* USE_GRAPHICS */
646 * Flag set once "sound" has been initialized
648 static bool can_use_sound = FALSE;
652 * An array of sound file names
654 static concptr sound_file[SOUND_MAX][SAMPLE_MAX];
656 #endif /* USE_SOUND */
662 #define SAMPLE_MUSIC_MAX 16
663 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
664 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
665 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
666 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
667 static bool can_use_music = FALSE;
669 static MCI_OPEN_PARMS mop;
670 static char mci_device_type[256];
672 int current_music_type = 0;
673 int current_music_id = 0;
675 #endif /* USE_MUSIC */
679 * Full path to ANGBAND.INI
681 static concptr ini_file = NULL;
684 * Name of application
686 static concptr AppName = "ANGBAND";
689 * Name of sub-window type
691 static concptr AngList = "AngList";
696 static concptr ANGBAND_DIR_XTRA_GRAF;
697 static concptr ANGBAND_DIR_XTRA_SOUND;
698 static concptr ANGBAND_DIR_XTRA_MUSIC;
699 static concptr ANGBAND_DIR_XTRA_HELP;
700 #if 0 /* #ifndef JP */
701 static concptr ANGBAND_DIR_XTRA_FONT;
704 static concptr ANGBAND_DIR_XTRA_MUSIC;
709 * The "complex" color values
711 static COLORREF win_clr[256];
715 * Flag for macro trigger with dump ASCII
717 static bool Term_no_press = FALSE;
722 static bool mouse_down = FALSE;
723 static bool paint_rect = FALSE;
724 static TERM_LEN mousex = 0, mousey = 0;
725 static TERM_LEN oldx, oldy;
729 * @brief The "simple" color values
731 * See "main-ibm.c" for original table information
732 * The entries below are taken from the "color bits" defined above.
733 * Note that many of the choices below suck, but so do crappy monitors.
735 static BYTE win_pal[256] =
737 VID_BLACK, /* Dark */
738 VID_WHITE, /* White */
739 VID_CYAN, /* Slate XXX */
740 VID_RED | VID_BRIGHT, /* Orange XXX */
742 VID_GREEN, /* Green */
744 VID_YELLOW, /* Umber XXX */
745 VID_BLACK | VID_BRIGHT, /* Light Dark */
746 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
747 VID_MAGENTA, /* Violet XXX */
748 VID_YELLOW | VID_BRIGHT, /* Yellow */
749 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
750 VID_GREEN | VID_BRIGHT, /* Light Green */
751 VID_BLUE | VID_BRIGHT, /* Light Blue */
752 VID_YELLOW /* Light Umber XXX */
757 * Hack -- define which keys are "special"
759 static bool special_key[256];
760 static bool ignore_key[256];
764 * Hack -- initialization list for "special_key"
766 static byte special_key_list[] = {
767 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
768 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
769 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
770 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
771 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
772 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
773 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
774 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
775 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
776 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
777 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
778 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
779 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
780 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
781 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
782 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
783 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
788 static byte ignore_key_list[] = {
789 VK_ESCAPE, VK_TAB, VK_SPACE,
790 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
791 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
792 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
798 * Hack -- initialization list for "special_key"
800 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
801 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
802 * catch the keypad keys (with and without numlock set, including keypad 5),
803 * the function keys (including the "menu" key which maps to F10), and the
804 * "pause" key (between scroll lock and numlock). We also catch a few odd
805 * keys which I do not recognize, but which are listed among keys which we
806 * do catch, so they should be harmless to catch.
808 static byte special_key_list[] =
810 VK_CLEAR, /* 0x0C (KP<5>) */
812 VK_PAUSE, /* 0x13 (pause) */
814 VK_PRIOR, /* 0x21 (KP<9>) */
815 VK_NEXT, /* 0x22 (KP<3>) */
816 VK_END, /* 0x23 (KP<1>) */
817 VK_HOME, /* 0x24 (KP<7>) */
818 VK_LEFT, /* 0x25 (KP<4>) */
819 VK_UP, /* 0x26 (KP<8>) */
820 VK_RIGHT, /* 0x27 (KP<6>) */
821 VK_DOWN, /* 0x28 (KP<2>) */
822 VK_SELECT, /* 0x29 (?????) */
823 VK_PRINT, /* 0x2A (?????) */
824 VK_EXECUTE, /* 0x2B (?????) */
825 VK_SNAPSHOT, /* 0x2C (?????) */
826 VK_INSERT, /* 0x2D (KP<0>) */
827 VK_DELETE, /* 0x2E (KP<.>) */
828 VK_HELP, /* 0x2F (?????) */
830 VK_NUMPAD0, /* 0x60 (KP<0>) */
831 VK_NUMPAD1, /* 0x61 (KP<1>) */
832 VK_NUMPAD2, /* 0x62 (KP<2>) */
833 VK_NUMPAD3, /* 0x63 (KP<3>) */
834 VK_NUMPAD4, /* 0x64 (KP<4>) */
835 VK_NUMPAD5, /* 0x65 (KP<5>) */
836 VK_NUMPAD6, /* 0x66 (KP<6>) */
837 VK_NUMPAD7, /* 0x67 (KP<7>) */
838 VK_NUMPAD8, /* 0x68 (KP<8>) */
839 VK_NUMPAD9, /* 0x69 (KP<9>) */
840 VK_MULTIPLY, /* 0x6A (KP<*>) */
841 VK_ADD, /* 0x6B (KP<+>) */
842 VK_SEPARATOR, /* 0x6C (?????) */
843 VK_SUBTRACT, /* 0x6D (KP<->) */
844 VK_DECIMAL, /* 0x6E (KP<.>) */
845 VK_DIVIDE, /* 0x6F (KP</>) */
876 /* Function prototype */
878 static bool is_already_running(void);
882 static void delete_bg(void)
891 static int init_bg(void)
893 char * bmfile = bg_bitmap_file;
896 if (use_bg == 0) return 0;
898 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
900 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
908 static void DrawBG(HDC hdc, RECT *r)
913 int x = r->left, y = r->top;
914 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
920 GetObject(hBG, sizeof(bm), &bm);
921 swid = bm.bmWidth; shgt = bm.bmHeight;
923 hdcSrc = CreateCompatibleDC(hdc);
924 hOld = SelectObject(hdcSrc, hBG);
928 cwid = MIN(swid - sx, r->right - nx);
931 chgt = MIN(shgt - sy, r->bottom - ny);
932 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
934 } while (ny < r->bottom);
937 } while (nx < r->right);
939 SelectObject(hdcSrc, hOld);
945 * Hack -- given a pathname, point at the filename
947 static concptr extract_file_name(concptr s)
951 /* Start at the end */
952 p = s + strlen(s) - 1;
954 /* Back up to divider */
955 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
957 /* Return file name */
964 * Hack -- given a simple filename, extract the "font size" info
966 * Return a pointer to a static buffer holding the capitalized base name.
968 #if 0 /* #ifndef JP */
969 static char *analyze_font(char *path, int *wp, int *hp)
975 /* Start at the end */
976 p = path + strlen(path) - 1;
978 /* Back up to divider */
979 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
981 /* Advance to file name */
987 /* Capitalize (be paranoid) */
988 if (islower(*s)) *s = toupper(*s);
992 s = my_strchr(p, 'X');
994 /* Extract font width */
998 hgt = s ? atoi(s+1) : 0;
1009 * Check for existance of a file
1011 static bool check_file(concptr s)
1021 unsigned int attrib;
1031 attrib = GetFileAttributes(path);
1033 /* Require valid filename */
1034 if (attrib == INVALID_FILE_NAME) return (FALSE);
1036 /* Prohibit directory */
1037 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
1041 /* Examine and verify */
1042 if (_dos_getfileattr(path, &attrib)) return (FALSE);
1044 /* Prohibit something */
1045 if (attrib & FA_LABEL) return (FALSE);
1047 /* Prohibit directory */
1048 if (attrib & FA_DIREC) return (FALSE);
1058 * Check for existance of a directory
1060 static bool check_dir(concptr s)
1072 unsigned int attrib;
1082 /* Remove trailing backslash */
1083 if (i && (path[i-1] == '\\')) path[--i] = '\0';
1088 attrib = GetFileAttributes(path);
1090 /* Require valid filename */
1091 if (attrib == INVALID_FILE_NAME) return (FALSE);
1093 /* Require directory */
1094 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
1098 /* Examine and verify */
1099 if (_dos_getfileattr(path, &attrib)) return (FALSE);
1101 /* Prohibit something */
1102 if (attrib & FA_LABEL) return (FALSE);
1104 /* Require directory */
1105 if (!(attrib & FA_DIREC)) return (FALSE);
1117 static void validate_file(concptr s)
1119 /* Verify or fail */
1122 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
1128 * Validate a directory
1130 static void validate_dir(concptr s, bool vital)
1132 /* Verify or fail */
1135 /* This directory contains needed data */
1138 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
1140 /* Attempt to create this directory */
1143 quit_fmt("Unable to create directory:\n%s", s);
1150 * @brief (Windows版固有実装)Get the "size" for a window
1152 static void term_getsize(term_data *td)
1156 if (td->cols < 1) td->cols = 1;
1157 if (td->rows < 1) td->rows = 1;
1160 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1161 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1163 /* Fake window size */
1165 rc.right = rc.left + wid;
1167 rc.bottom = rc.top + hgt;
1169 /* rc.right += 1; */
1170 /* rc.bottom += 1; */
1173 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1176 td->size_wid = rc.right - rc.left;
1177 td->size_hgt = rc.bottom - rc.top;
1179 /* See CreateWindowEx */
1182 /* Extract actual location */
1183 GetWindowRect(td->w, &rc);
1185 /* Save the location */
1186 td->pos_x = rc.left;
1192 * Write the "prefs" for a single term
1194 static void save_prefs_aux(int i)
1196 term_data *td = &data[i];
1197 GAME_TEXT sec_name[128];
1201 WINDOWPLACEMENT lpwndpl;
1204 /* Make section name */
1205 sprintf(sec_name, "Term-%d", i);
1210 strcpy(buf, td->visible ? "1" : "0");
1211 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1216 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "MS ゴシック");
1219 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1221 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1225 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1227 #if 1 /* #ifdef JP */
1228 wsprintf(buf, "%d", td->lf.lfWidth);
1229 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1230 wsprintf(buf, "%d", td->lf.lfHeight);
1231 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1232 wsprintf(buf, "%d", td->lf.lfWeight);
1233 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1236 strcpy(buf, td->bizarre ? "1" : "0");
1237 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1240 wsprintf(buf, "%d", td->tile_wid);
1241 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1244 wsprintf(buf, "%d", td->tile_hgt);
1245 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1247 /* Get window placement and dimensions */
1248 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1249 GetWindowPlacement(td->w, &lpwndpl);
1251 /* Acquire position in *normal* mode (not minimized) */
1252 rc = lpwndpl.rcNormalPosition;
1254 /* Window size (x) */
1255 if (i == 0) wsprintf(buf, "%d", normsize.x);
1256 else wsprintf(buf, "%d", td->cols);
1257 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1259 /* Window size (y) */
1260 if (i == 0) wsprintf(buf, "%d", normsize.y);
1261 else wsprintf(buf, "%d", td->rows);
1262 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1264 /* Maxmized (only main window) */
1267 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1268 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1271 /* Acquire position */
1272 GetWindowRect(td->w, &rc);
1274 /* Window position (x) */
1275 wsprintf(buf, "%d", rc.left);
1276 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1278 /* Window position (y) */
1279 wsprintf(buf, "%d", rc.top);
1280 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1282 /* Window Z position */
1285 strcpy(buf, td->posfix ? "1" : "0");
1286 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1293 * We assume that the windows have all been initialized
1295 static void save_prefs(void)
1301 /* Save the "arg_graphics" flag */
1302 sprintf(buf, "%d", arg_graphics);
1303 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1305 /* Save the "arg_bigtile" flag */
1306 strcpy(buf, arg_bigtile ? "1" : "0");
1307 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1309 /* Save the "arg_sound" flag */
1310 strcpy(buf, arg_sound ? "1" : "0");
1311 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1313 /* Save the "arg_sound" flag */
1314 strcpy(buf, arg_music ? "1" : "0");
1315 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1318 strcpy(buf, use_bg ? "1" : "0");
1319 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1320 WritePrivateProfileString("Angband", "BackGroundBitmap",
1321 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1323 /* Save window prefs */
1324 for (i = 0; i < MAX_TERM_DATA; ++i)
1332 * Load the "prefs" for a single term
1334 static void load_prefs_aux(int i)
1336 term_data *td = &data[i];
1337 GAME_TEXT sec_name[128];
1340 int wid, hgt, posx, posy;
1341 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1342 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1346 /* Make section name */
1347 sprintf(sec_name, "Term-%d", i);
1349 /* Make section name */
1350 sprintf(sec_name, "Term-%d", i);
1355 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1358 /* Desired font, with default */
1360 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1363 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1365 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1371 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1373 /* Analyze font, save desired font name */
1374 #if 1 /* #ifdef JP */
1375 td->font_want = string_make(tmp);
1377 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1378 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1379 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1381 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1386 #if 1 /* #ifdef JP */
1387 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1388 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1390 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1391 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1396 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1397 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1398 normsize.x = td->cols; normsize.y = td->rows;
1403 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
1406 /* Window position */
1407 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1408 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1409 td->pos_x = MIN(MAX(0, posx), dispx-128);
1410 td->pos_y = MIN(MAX(0, posy), dispy-128);
1412 /* Window Z position */
1415 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
1423 static void load_prefs(void)
1427 /* Extract the "arg_graphics" flag */
1428 arg_graphics = (byte_hack)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1430 /* Extract the "arg_bigtile" flag */
1431 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
1432 use_bigtile = arg_bigtile;
1434 /* Extract the "arg_sound" flag */
1435 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1437 /* Extract the "arg_sound" flag */
1438 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1441 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1442 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1444 /* Load window prefs */
1445 for (i = 0; i < MAX_TERM_DATA; ++i)
1451 #if defined(USE_SOUND) || defined(USE_MUSIC)
1454 * - Taken from files.c.
1456 * Extract "tokens" from a buffer
1458 * This function uses "whitespace" as delimiters, and treats any amount of
1459 * whitespace as a single delimiter. We will never return any empty tokens.
1460 * When given an empty buffer, or a buffer containing only "whitespace", we
1461 * will return no tokens. We will never extract more than "num" tokens.
1463 * By running a token through the "text_to_ascii()" function, you can allow
1464 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1466 * We save pointers to the tokens in "tokens", and return the number found.
1468 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1478 /* Skip leading whitespace */
1479 for ( ; *s && iswspace(*s); ++s) /* loop */;
1484 /* Find next whitespace, if any */
1485 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1487 /* Nuke and advance (if necessary) */
1488 if (*t) *t++ = '\0';
1490 /* Save the token */
1501 #endif /* USE_SOUND || USE_MUSIC */
1505 static void load_sound_prefs(void)
1509 char ini_path[1024];
1510 char wav_path[1024];
1511 char *zz[SAMPLE_MAX];
1513 /* Access the sound.cfg */
1515 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1517 for (i = 0; i < SOUND_MAX; i++)
1519 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1521 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1523 for (j = 0; j < num; j++)
1525 /* Access the sound */
1526 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1528 /* Save the sound filename, if it exists */
1529 if (check_file(wav_path))
1530 sound_file[i][j] = string_make(zz[j]);
1535 #endif /* USE_SOUND */
1539 static void load_music_prefs(void)
1543 char ini_path[1024];
1544 char wav_path[1024];
1545 char *zz[SAMPLE_MAX];
1548 /* Access the music.cfg */
1550 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1552 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1554 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1556 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1558 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1560 for (j = 0; j < num; j++)
1562 /* Access the sound */
1563 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1565 /* Save the sound filename, if it exists */
1566 if (check_file(wav_path))
1567 music_file[i][j] = string_make(zz[j]);
1571 for (i = 0; i < max_d_idx; i++)
1573 sprintf(key, "dungeon%03d", i);
1574 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1576 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1578 for (j = 0; j < num; j++)
1580 /* Access the sound */
1581 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1583 /* Save the sound filename, if it exists */
1584 if (check_file(wav_path))
1585 dungeon_music_file[i][j] = string_make(zz[j]);
1589 for (i = 0; i < max_q_idx; i++)
1591 sprintf(key, "quest%03d", i);
1592 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1594 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1596 for (j = 0; j < num; j++)
1598 /* Access the sound */
1599 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1601 /* Save the sound filename, if it exists */
1602 if (check_file(wav_path))
1603 quest_music_file[i][j] = string_make(zz[j]);
1607 for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1609 sprintf(key, "town%03d", i);
1610 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1612 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1614 for (j = 0; j < num; j++)
1616 /* Access the sound */
1617 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1619 /* Save the sound filename, if it exists */
1620 if (check_file(wav_path))
1621 town_music_file[i][j] = string_make(zz[j]);
1628 #endif /* USE_MUSIC */
1631 * Create the new global palette based on the bitmap palette
1632 * (if any), and the standard 16 entry palette derived from
1633 * "win_clr[]" which is used for the basic 16 Angband colors.
1635 * This function is never called before all windows are ready.
1637 * This function returns FALSE if the new palette could not be
1638 * prepared, which should normally be a fatal error. XXX XXX
1640 * Note that only some machines actually use a "palette".
1642 static int new_palette(void)
1650 LPLOGPALETTE pLogPal;
1651 LPPALETTEENTRY lppe;
1656 /* This makes no sense */
1657 if (!paletted) return (TRUE);
1667 /* Check the bitmap palette */
1668 hBmPal = infGraph.hPalette;
1670 /* Use the bitmap */
1673 lppeSize = 256 * sizeof(PALETTEENTRY);
1674 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1675 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1676 if ((nEntries == 0) || (nEntries > 220))
1679 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1682 rnfree(lppe, lppeSize);
1689 #endif /* USE_GRAPHICS */
1691 /* Size of palette */
1692 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1694 /* Allocate palette */
1695 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1698 pLogPal->palVersion = 0x300;
1700 /* Make room for bitmap and normal data */
1701 pLogPal->palNumEntries = nEntries + 16;
1703 /* Save the bitmap data */
1704 for (i = 0; i < nEntries; i++)
1706 pLogPal->palPalEntry[i] = lppe[i];
1709 /* Save the normal data */
1710 for (i = 0; i < 16; i++)
1714 /* Access the entry */
1715 p = &(pLogPal->palPalEntry[i+nEntries]);
1717 /* Save the colors */
1718 p->peRed = GetRValue(win_clr[i]);
1719 p->peGreen = GetGValue(win_clr[i]);
1720 p->peBlue = GetBValue(win_clr[i]);
1722 /* Save the flags */
1723 p->peFlags = PC_NOCOLLAPSE;
1726 /* Free something */
1727 if (lppe) rnfree(lppe, lppeSize);
1729 /* Create a new palette, or fail */
1730 hNewPal = CreatePalette(pLogPal);
1731 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1733 /* Free the palette */
1734 rnfree(pLogPal, pLogPalSize);
1739 /* Realize the palette */
1741 SelectPalette(hdc, hNewPal, 0);
1742 i = RealizePalette(hdc);
1743 ReleaseDC(td->w, hdc);
1744 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1748 for (i = 1; i < MAX_TERM_DATA; i++)
1753 SelectPalette(hdc, hNewPal, 0);
1754 ReleaseDC(td->w, hdc);
1757 /* Delete old palette */
1758 if (hPal) DeleteObject(hPal);
1760 /* Save new palette */
1770 * @brief グラフィクスを初期化する / Initialize graphics
1773 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1774 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1777 static bool init_graphics(void)
1779 /* Initialize once */
1781 BYTE wid, hgt, twid, thgt, ox, oy;
1784 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1794 ANGBAND_GRAF = "new";
1796 else if (arg_graphics == GRAPHICS_HENGBAND)
1816 ANGBAND_GRAF = "ne2";
1827 ANGBAND_GRAF = "old";
1830 /* Access the bitmap file */
1831 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1833 /* Load the bitmap or quit */
1834 if (!ReadDIB(data[0].w, buf, &infGraph))
1836 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1840 /* Save the new sizes */
1841 infGraph.CellWidth = wid;
1842 infGraph.CellHeight = hgt;
1843 infGraph.TileWidth = twid;
1844 infGraph.TileHeight = thgt;
1845 infGraph.OffsetX = ox;
1846 infGraph.OffsetY = oy;
1848 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1850 /* Access the mask file */
1851 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1853 /* Load the bitmap or quit */
1854 if (!ReadDIB(data[0].w, buf, &infMask))
1856 plog_fmt("Cannot read bitmap file '%s'", buf);
1860 if (arg_graphics == GRAPHICS_HENGBAND)
1862 /* Access the mask file */
1863 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1865 /* Load the bitmap or quit */
1866 if (!ReadDIB(data[0].w, buf, &infMask))
1868 plog_fmt("Cannot read bitmap file '%s'", buf);
1873 /* Activate a palette */
1878 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1882 /* Graphics available */
1883 current_graphics_mode = arg_graphics;
1884 return (current_graphics_mode);
1886 #endif /* USE_GRAPHICS */
1893 static bool init_music(void)
1895 /* Initialize once */
1898 /* Load the prefs */
1901 /* Sound available */
1902 can_use_music = TRUE;
1904 return (can_use_music);
1908 * Hack -- Stop a music
1910 static void stop_music(void)
1912 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1913 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1916 #endif /* USE_MUSIC */
1922 static bool init_sound(void)
1924 /* Initialize once */
1927 /* Load the prefs */
1930 /* Sound available */
1931 can_use_sound = TRUE;
1933 return (can_use_sound);
1935 #endif /* USE_SOUND */
1941 static void term_window_resize(term_data *td)
1943 /* Require window */
1946 /* Resize the window */
1947 SetWindowPos(td->w, 0, 0, 0,
1948 td->size_wid, td->size_hgt,
1949 SWP_NOMOVE | SWP_NOZORDER);
1952 InvalidateRect(td->w, NULL, TRUE);
1957 * Force the use of a new "font file" for a term_data
1959 * This function may be called before the "window" is ready
1961 * This function returns zero only if everything succeeds.
1963 * Note that the "font name" must be capitalized!!!
1965 static errr term_force_font(term_data *td, concptr path)
1969 #if 0 /* #ifndef JP */
1975 /* Forget the old font (if needed) */
1976 if (td->font_id) DeleteObject(td->font_id);
1978 #if 1 /* #ifdef JP */
1982 /* Create the font (using the 'base' of the font file name!) */
1983 td->font_id = CreateFontIndirect(&(td->lf));
1984 wid = td->lf.lfWidth;
1985 hgt = td->lf.lfHeight;
1986 if (!td->font_id) return (1);
1988 /* Forget old font */
1994 for (i = 0; i < MAX_TERM_DATA; i++)
1996 /* Don't check when closing the application */
1999 /* Check "screen" */
2000 if ((td != &data[i]) &&
2001 (data[i].font_file) &&
2002 (streq(data[i].font_file, td->font_file)))
2008 /* Remove unused font resources */
2009 if (!used) RemoveFontResource(td->font_file);
2011 /* Free the old name */
2012 string_free(td->font_file);
2015 td->font_file = NULL;
2019 if (!path) return (1);
2024 /* Analyze font path */
2025 base = analyze_font(buf, &wid, &hgt);
2028 if (!suffix(base, ".FON")) return (1);
2031 if (!check_file(buf)) return (1);
2033 /* Load the new font */
2034 if (!AddFontResource(buf)) return (1);
2036 /* Save new font name */
2037 td->font_file = string_make(base);
2039 /* Remove the "suffix" */
2040 base[strlen(base)-4] = '\0';
2042 /* Create the font (using the 'base' of the font file name!) */
2043 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
2044 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
2045 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
2046 FIXED_PITCH | FF_DONTCARE, base);
2049 /* Hack -- Unknown size */
2056 /* all this trouble to get the cell size */
2057 hdcDesktop = GetDC(HWND_DESKTOP);
2058 hfOld = SelectObject(hdcDesktop, td->font_id);
2059 GetTextMetrics(hdcDesktop, &tm);
2060 SelectObject(hdcDesktop, hfOld);
2061 ReleaseDC(HWND_DESKTOP, hdcDesktop);
2063 /* Font size info */
2064 wid = tm.tmAveCharWidth;
2068 /* Save the size info */
2079 * Allow the user to change the font for this window.
2081 static void term_change_font(term_data *td)
2083 #if 1 /* #ifdef JP */
2086 memset(&cf, 0, sizeof(cf));
2087 cf.lStructSize = sizeof(cf);
2088 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
2089 cf.lpLogFont = &(td->lf);
2091 if (ChooseFont(&cf))
2093 /* Force the font */
2094 term_force_font(td, NULL);
2096 /* Assume not bizarre */
2099 /* Reset the tile info */
2100 td->tile_wid = td->font_wid;
2101 td->tile_hgt = td->font_hgt;
2103 /* Analyze the font */
2106 /* Resize the window */
2107 term_window_resize(td);
2113 char tmp[1024] = "";
2115 /* Extract a default if possible */
2116 if (td->font_file) strcpy(tmp, td->font_file);
2118 /* Ask for a choice */
2119 memset(&ofn, 0, sizeof(ofn));
2120 ofn.lStructSize = sizeof(ofn);
2121 ofn.hwndOwner = data[0].w;
2122 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
2123 ofn.nFilterIndex = 1;
2124 ofn.lpstrFile = tmp;
2126 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
2127 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2128 ofn.lpstrDefExt = "fon";
2130 /* Force choice if legal */
2131 if (GetOpenFileName(&ofn))
2133 /* Force the font */
2134 if (term_force_font(td, tmp))
2136 /* Access the standard font file */
2137 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2139 /* Force the use of that font */
2140 (void)term_force_font(td, tmp);
2143 /* Assume not bizarre */
2144 td->bizarre = FALSE;
2146 /* Reset the tile info */
2147 td->tile_wid = td->font_wid;
2148 td->tile_hgt = td->font_hgt;
2150 /* Analyze the font */
2153 /* Resize the window */
2154 term_window_resize(td);
2161 * Allow the user to lock this window.
2163 static void term_window_pos(term_data *td, HWND hWnd)
2165 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2166 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2169 static void windows_map(void);
2172 * Hack -- redraw a term_data
2174 static void term_data_redraw(term_data *td)
2178 /* Redraw the map */
2183 /* Activate the term */
2184 Term_activate(&td->t);
2186 /* Redraw the contents */
2189 /* Restore the term */
2190 Term_activate(term_screen);
2195 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2199 HBRUSH myBrush, oldBrush;
2201 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2202 int tx = td->size_ow1 + x * td->tile_wid;
2203 int ty = td->size_oh1 + y * td->tile_hgt;
2204 int tw = w * td->tile_wid - 1;
2205 int th = h * td->tile_hgt - 1;
2208 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2209 oldBrush = SelectObject(hdc, myBrush);
2210 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2212 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2214 SelectObject(hdc, oldBrush);
2215 SelectObject(hdc, oldPen);
2220 /*** Function hooks needed by "Term" ***/
2226 * Initialize a new Term
2228 static void Term_init_win(term *t)
2237 static void Term_nuke_win(term *t)
2246 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
2248 static errr Term_user_win(int n)
2259 * React to global changes
2261 static errr Term_xtra_win_react(void)
2268 /* Save the default colors */
2269 for (i = 0; i < 256; i++)
2271 /* Simply accept the desired colors */
2272 win_pal[i] = angband_color_table[i][0];
2283 bool change = FALSE;
2285 /* Save the default colors */
2286 for (i = 0; i < 256; i++)
2288 /* Extract desired values */
2289 rv = angband_color_table[i][1];
2290 gv = angband_color_table[i][2];
2291 bv = angband_color_table[i][3];
2293 /* Extract a full color code */
2294 code = PALETTERGB(rv, gv, bv);
2296 /* Activate changes */
2297 if (win_clr[i] != code)
2299 /* Note the change */
2302 /* Apply the desired color */
2307 /* Activate the palette if needed */
2308 if (change) (void)new_palette();
2314 /* Handle "arg_sound" */
2315 if (use_sound != arg_sound)
2317 /* Initialize (if needed) */
2318 if (arg_sound && !init_sound())
2321 plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
2327 /* Change setting */
2328 use_sound = arg_sound;
2335 /* Handle "arg_sound" */
2336 if (use_music != arg_music)
2338 /* Initialize (if needed) */
2339 if (arg_music && !init_music())
2342 plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
2347 /* Change setting */
2348 use_music = arg_music;
2350 if(!arg_music) stop_music();
2351 else select_floor_music();
2360 /* Handle "arg_graphics" */
2361 if (use_graphics != arg_graphics)
2363 /* Initialize (if needed) */
2364 if (arg_graphics && !init_graphics())
2367 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
2370 arg_graphics = GRAPHICS_NONE;
2373 /* Change setting */
2374 use_graphics = arg_graphics;
2377 #ifdef ANGBAND_2_8_1
2379 #else /* ANGBAND_2_8_1 */
2380 reset_visuals(TRUE);
2381 #endif /* ANGBAND_2_8_1 */
2384 #endif /* USE_GRAPHICS */
2387 /* Clean up windows */
2388 for (i = 0; i < MAX_TERM_DATA; i++)
2392 term_data *td = &data[i];
2394 /* Update resized windows */
2395 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
2398 Term_activate(&td->t);
2400 /* Hack -- Resize the term */
2401 Term_resize(td->cols, td->rows);
2403 /* Redraw the contents */
2416 * Process at least one event
2418 static errr Term_xtra_win_event(int v)
2422 /* Wait for an event */
2426 if (GetMessage(&msg, NULL, 0, 0))
2428 TranslateMessage(&msg);
2429 DispatchMessage(&msg);
2433 /* Check for an event */
2437 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2439 TranslateMessage(&msg);
2440 DispatchMessage(&msg);
2450 * Process all pending events
2452 static errr Term_xtra_win_flush(void)
2456 /* Process all pending events */
2457 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2459 TranslateMessage(&msg);
2460 DispatchMessage(&msg);
2469 * Hack -- clear the screen
2471 * Make this more efficient
2473 static errr Term_xtra_win_clear(void)
2475 term_data *td = (term_data*)(Term->data);
2480 /* Rectangle to erase */
2481 rc.left = td->size_ow1;
2482 rc.right = rc.left + td->cols * td->tile_wid;
2483 rc.top = td->size_oh1;
2484 rc.bottom = rc.top + td->rows * td->tile_hgt;
2488 SetBkColor(hdc, RGB(0, 0, 0));
2489 SelectObject(hdc, td->font_id);
2490 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2495 rc.left = 0; rc.top = 0;
2498 ReleaseDC(td->w, hdc);
2506 * Hack -- make a noise
2508 static errr Term_xtra_win_noise(void)
2510 MessageBeep(MB_ICONASTERISK);
2516 * Hack -- make a sound
2518 static errr Term_xtra_win_sound(int v)
2523 #endif /* USE_SOUND */
2525 /* Sound disabled */
2526 if (!use_sound) return (1);
2529 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2533 /* Count the samples */
2534 for (i = 0; i < SAMPLE_MAX; i++)
2536 if (!sound_file[v][i])
2541 if (i == 0) return (1);
2543 /* Build the path */
2544 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2548 /* Play the sound, catch errors */
2549 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2553 /* Play the sound, catch errors */
2554 return (sndPlaySound(buf, SND_ASYNC));
2558 #else /* USE_SOUND */
2562 #endif /* USE_SOUND */
2566 * Hack -- play a music
2568 static errr Term_xtra_win_music(int n, int v)
2573 #endif /* USE_MUSIC */
2575 /* Sound disabled */
2577 if(!use_music) return (1);
2580 if(n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return (1);
2581 else if(v < 0 || v >= 1000) return(1); /*!< TODO */
2587 case TERM_XTRA_MUSIC_BASIC:
2588 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2590 case TERM_XTRA_MUSIC_DUNGEON:
2591 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2593 case TERM_XTRA_MUSIC_QUEST:
2594 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2596 case TERM_XTRA_MUSIC_TOWN:
2597 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2604 //mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2605 //mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2611 case TERM_XTRA_MUSIC_BASIC:
2612 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2614 case TERM_XTRA_MUSIC_DUNGEON:
2615 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2617 case TERM_XTRA_MUSIC_QUEST:
2618 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2620 case TERM_XTRA_MUSIC_TOWN:
2621 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2628 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2629 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2635 case TERM_XTRA_MUSIC_BASIC:
2636 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2638 case TERM_XTRA_MUSIC_DUNGEON:
2639 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2641 case TERM_XTRA_MUSIC_QUEST:
2642 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2644 case TERM_XTRA_MUSIC_TOWN:
2645 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2649 if(current_music_type == n && current_music_id == v)
2653 current_music_type = n;
2654 current_music_id = v;
2658 mop.lpstrDeviceType = mci_device_type;
2659 mop.lpstrElementName = buf;
2660 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2661 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2662 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2663 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2664 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2669 #else /* USE_MUSIC */
2673 #endif /* USE_MUSIC */
2679 * Delay for "x" milliseconds
2681 static int Term_xtra_win_delay(int v)
2695 t = GetTickCount() + v;
2698 while (GetTickCount() < t)
2700 /* Handle messages */
2701 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2703 TranslateMessage(&msg);
2704 DispatchMessage(&msg);
2716 * Do a "special thing"
2718 static errr Term_xtra_win(int n, int v)
2720 /* Handle a subset of the legal requests */
2723 /* Make a bell sound */
2724 case TERM_XTRA_NOISE:
2726 return (Term_xtra_win_noise());
2730 case TERM_XTRA_MUSIC_BASIC:
2731 case TERM_XTRA_MUSIC_DUNGEON:
2732 case TERM_XTRA_MUSIC_QUEST:
2733 case TERM_XTRA_MUSIC_TOWN:
2735 return (Term_xtra_win_music(n, v));
2738 /* Make a special sound */
2739 case TERM_XTRA_SOUND:
2741 return (Term_xtra_win_sound(v));
2744 /* Process random events */
2745 case TERM_XTRA_BORED:
2747 return (Term_xtra_win_event(0));
2750 /* Process an event */
2751 case TERM_XTRA_EVENT:
2753 return (Term_xtra_win_event(v));
2756 /* Flush all events */
2757 case TERM_XTRA_FLUSH:
2759 return (Term_xtra_win_flush());
2762 /* Clear the screen */
2763 case TERM_XTRA_CLEAR:
2765 return (Term_xtra_win_clear());
2768 /* React to global changes */
2769 case TERM_XTRA_REACT:
2771 return (Term_xtra_win_react());
2774 /* Delay for some milliseconds */
2775 case TERM_XTRA_DELAY:
2777 return (Term_xtra_win_delay(v));
2787 * Low level graphics (Assumes valid input).
2789 * Draw a "cursor" at (x,y), using a "yellow box".
2791 static errr Term_curs_win(int x, int y)
2793 term_data *td = (term_data*)(Term->data);
2798 int tile_wid, tile_hgt;
2802 tile_wid = td->map_tile_wid;
2803 tile_hgt = td->map_tile_hgt;
2807 tile_wid = td->tile_wid;
2808 tile_hgt = td->tile_hgt;
2811 /* Frame the grid */
2812 rc.left = x * tile_wid + td->size_ow1;
2813 rc.right = rc.left + tile_wid;
2814 rc.top = y * tile_hgt + td->size_oh1;
2815 rc.bottom = rc.top + tile_hgt;
2817 /* Cursor is done as a yellow "box" */
2819 FrameRect(hdc, &rc, hbrYellow);
2820 ReleaseDC(td->w, hdc);
2828 * Low level graphics (Assumes valid input).
2830 * Draw a "big cursor" at (x,y), using a "yellow box".
2832 static errr Term_bigcurs_win(int x, int y)
2834 term_data *td = (term_data*)(Term->data);
2839 int tile_wid, tile_hgt;
2843 /* Normal cursor in map window */
2844 Term_curs_win(x, y);
2849 tile_wid = td->tile_wid;
2850 tile_hgt = td->tile_hgt;
2853 /* Frame the grid */
2854 rc.left = x * tile_wid + td->size_ow1;
2855 rc.right = rc.left + 2 * tile_wid;
2856 rc.top = y * tile_hgt + td->size_oh1;
2857 rc.bottom = rc.top + tile_hgt;
2859 /* Cursor is done as a yellow "box" */
2861 FrameRect(hdc, &rc, hbrYellow);
2862 ReleaseDC(td->w, hdc);
2870 * Low level graphics (Assumes valid input).
2872 * Erase a "block" of "n" characters starting at (x,y).
2874 static errr Term_wipe_win(int x, int y, int n)
2876 term_data *td = (term_data*)(Term->data);
2881 /* Rectangle to erase in client coords */
2882 rc.left = x * td->tile_wid + td->size_ow1;
2883 rc.right = rc.left + n * td->tile_wid;
2884 rc.top = y * td->tile_hgt + td->size_oh1;
2885 rc.bottom = rc.top + td->tile_hgt;
2888 SetBkColor(hdc, RGB(0, 0, 0));
2889 SelectObject(hdc, td->font_id);
2894 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2895 ReleaseDC(td->w, hdc);
2903 * Low level graphics. Assumes valid input.
2905 * Draw several ("n") chars, with an attr, at a given location.
2907 * All "graphic" data is handled by "Term_pict_win()", below.
2909 * One would think there is a more efficient method for telling a window
2910 * what color it should be using to draw with, but perhaps simply changing
2911 * it every time is not too inefficient.
2913 static errr Term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
2915 term_data *td = (term_data*)(Term->data);
2919 #if 1 /* #ifdef JP */
2920 static HBITMAP WALL;
2921 static HBRUSH myBrush, oldBrush;
2923 static bool init_done = FALSE;
2926 WALL = LoadBitmap(hInstance, AppName);
2927 myBrush = CreatePatternBrush(WALL);
2932 /* Total rectangle */
2933 rc.left = x * td->tile_wid + td->size_ow1;
2934 rc.right = rc.left + n * td->tile_wid;
2935 rc.top = y * td->tile_hgt + td->size_oh1;
2936 rc.bottom = rc.top + td->tile_hgt;
2941 /* Background color */
2942 SetBkColor(hdc, RGB(0, 0, 0));
2944 /* Foreground color */
2947 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2951 SetTextColor(hdc, win_clr[a&0x0F]);
2955 SetTextColor(hdc, win_clr[a]);
2959 SelectObject(hdc, td->font_id);
2962 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2966 (td->tile_hgt != td->font_hgt) ||
2967 (td->tile_wid != td->font_wid))
2971 /* Erase complete rectangle */
2972 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2975 if (use_bg) DrawBG(hdc, &rc);
2978 rc.left += ((td->tile_wid - td->font_wid) / 2);
2979 rc.right = rc.left + td->font_wid;
2980 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2981 rc.bottom = rc.top + td->font_hgt;
2983 /* Dump each character */
2984 for (i = 0; i < n; i++)
2987 if (use_bigtile && *(s+i)=="■"[0] && *(s+i+1)=="■"[1])
2989 rc.right += td->font_wid;
2991 oldBrush = SelectObject(hdc, myBrush);
2992 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2995 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2997 SelectObject(hdc, oldBrush);
2998 SelectObject(hdc, oldPen);
2999 rc.right -= td->font_wid;
3003 rc.left += 2 * td->tile_wid;
3004 rc.right += 2 * td->tile_wid;
3006 else if ( iskanji(*(s+i)) ) /* 2バイト文字 */
3008 rc.right += td->font_wid;
3010 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
3012 rc.right -= td->font_wid;
3016 rc.left += 2 * td->tile_wid;
3017 rc.right += 2 * td->tile_wid;
3018 } else if (*(s+i)==127){
3019 oldBrush = SelectObject(hdc, myBrush);
3020 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
3023 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
3025 SelectObject(hdc, oldBrush);
3026 SelectObject(hdc, oldPen);
3029 rc.left += td->tile_wid;
3030 rc.right += td->tile_wid;
3033 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
3036 rc.left += td->tile_wid;
3037 rc.right += td->tile_wid;
3042 oldBrush = SelectObject(hdc, myBrush);
3043 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
3046 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
3048 SelectObject(hdc, oldBrush);
3049 SelectObject(hdc, oldPen);
3052 rc.left += td->tile_wid;
3053 rc.right += td->tile_wid;
3056 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
3060 rc.left += td->tile_wid;
3061 rc.right += td->tile_wid;
3065 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
3069 rc.left += td->tile_wid;
3070 rc.right += td->tile_wid;
3081 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
3086 ReleaseDC(td->w, hdc);
3094 * Low level graphics. Assumes valid input.
3096 * Draw an array of "special" attr/char pairs at the given location.
3098 * We use the "Term_pict_win()" function for "graphic" data, which are
3099 * encoded by setting the "high-bits" of both the "attr" and the "char"
3100 * data. We use the "attr" to represent the "row" of the main bitmap,
3101 * and the "char" to represent the "col" of the main bitmap. The use
3102 * of this function is induced by the "higher_pict" flag.
3104 * If "graphics" is not available, we simply "wipe" the given grids.
3106 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)
3108 term_data *td = (term_data*)(Term->data);
3113 TERM_LEN x1, y1, w1, h1, tw1, th1;
3114 TERM_LEN x2, y2, w2, h2, tw2 = 0;
3124 /* Erase the grids */
3125 return (Term_wipe_win(x, y, n));
3128 /* Size of bitmap cell */
3129 w1 = infGraph.CellWidth;
3130 h1 = infGraph.CellHeight;
3131 tw1 = infGraph.TileWidth;
3132 th1 = infGraph.TileHeight;
3134 /* Size of window cell */
3137 w2 = td->map_tile_wid;
3138 h2 = td->map_tile_hgt;
3147 if (use_bigtile) tw2 *= 2;
3150 /* Location of window cell */
3151 x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
3152 y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
3158 hdcSrc = CreateCompatibleDC(hdc);
3159 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
3161 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3163 hdcMask = CreateCompatibleDC(hdc);
3164 SelectObject(hdcMask, infMask.hBitmap);
3167 /* Draw attr/char pairs */
3168 for (i = 0; i < n; i++, x2 += w2)
3170 TERM_COLOR a = ap[i];
3174 /* Extract picture */
3175 int row = (a & 0x7F);
3176 int col = (c & 0x7F);
3178 /* Location of bitmap cell */
3182 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3184 x3 = (tcp[i] & 0x7F) * w1;
3185 y3 = (tap[i] & 0x7F) * h1;
3186 tw2 = tw2 * w1 / tw1;
3190 if ((tw1 == tw2) && (th1 == h2))
3192 /* Copy the terrain picture from the bitmap to the window */
3193 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
3195 /* Mask out the tile */
3196 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3199 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3202 /* Need to stretch */
3205 /* Set the correct mode for stretching the tiles */
3206 SetStretchBltMode(hdc, COLORONCOLOR);
3208 /* Copy the terrain picture from the bitmap to the window */
3209 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
3211 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
3213 /* Only draw if terrain and overlay are different */
3214 if ((x1 != x3) || (y1 != y3))
3216 /* Mask out the tile */
3217 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3220 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3227 if ((w1 == tw2) && (h1 == h2))
3229 /* Copy the picture from the bitmap to the window */
3230 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3233 /* Need to stretch */
3236 /* Set the correct mode for stretching the tiles */
3237 SetStretchBltMode(hdc, COLORONCOLOR);
3239 /* Copy the picture from the bitmap to the window */
3240 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3246 SelectObject(hdcSrc, hbmSrcOld);
3249 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3252 SelectObject(hdcMask, hbmSrcOld);
3257 ReleaseDC(td->w, hdc);
3259 #else /* USE_GRAPHICS */
3261 /* Just erase this grid */
3262 return (Term_wipe_win(x, y, n));
3264 #endif /* USE_GRAPHICS */
3271 static void windows_map(void)
3273 term_data *td = &data[0];
3276 TERM_LEN x, min_x, max_x;
3277 TERM_LEN y, min_y, max_y;
3282 /* Only in graphics mode */
3283 if (!use_graphics) return;
3284 Term_xtra_win_clear();
3286 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3287 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3288 td->map_active = TRUE;
3293 max_x = current_floor_ptr->width;
3294 max_y = current_floor_ptr->height;
3298 for (x = min_x; x < max_x; x++)
3300 for (y = min_y; y < max_y; y++)
3302 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3304 /* Ignore non-graphics */
3305 if ((a & 0x80) && (c & 0x80))
3307 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3312 /* Hilite the player */
3313 Term_curs_win(p_ptr->x - min_x, p_ptr->y - min_y);
3315 /* Wait for a keypress, flush key buffer */
3316 Term_inkey(&c, TRUE, TRUE);
3319 /* Switch off the map display */
3320 td->map_active = FALSE;
3322 /* Restore screen */
3323 Term_xtra_win_clear();
3328 /*** Other routines ***/
3332 * Create and initialize a "term_data" given a title
3334 static void term_data_link(term_data *td)
3338 /* Initialize the term */
3339 term_init(t, td->cols, td->rows, td->keys);
3341 /* Use a "software" cursor */
3342 t->soft_cursor = TRUE;
3344 /* Use "Term_pict" for "graphic" data */
3345 t->higher_pict = TRUE;
3347 /* Erase with "white space" */
3348 t->attr_blank = TERM_WHITE;
3349 t->char_blank = ' ';
3352 /* Prepare the init/nuke hooks */
3353 t->init_hook = Term_init_win;
3354 t->nuke_hook = Term_nuke_win;
3357 /* Prepare the template hooks */
3358 t->user_hook = Term_user_win;
3359 t->xtra_hook = Term_xtra_win;
3360 t->curs_hook = Term_curs_win;
3361 t->bigcurs_hook = Term_bigcurs_win;
3362 t->wipe_hook = Term_wipe_win;
3363 t->text_hook = Term_text_win;
3364 t->pict_hook = Term_pict_win;
3366 /* Remember where we came from */
3367 t->data = (vptr)(td);
3372 * Create the windows
3374 * First, instantiate the "default" values, then read the "ini_file"
3375 * to over-ride selected values, then create the windows, and fonts.
3377 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3378 * must make active to realize the palette.
3380 static void init_windows(void)
3386 #if 0 /* #ifndef JP */
3392 WIPE(td, term_data);
3396 td->s = angband_term_name[0];
3410 #if 1 /* #ifdef JP */
3414 for (i = 1; i < MAX_TERM_DATA; i++)
3417 WIPE(td, term_data);
3418 td->s = angband_term_name[i];
3422 td->visible = FALSE;
3427 td->pos_x = (7 - i) * 30;
3428 td->pos_y = (7 - i) * 20;
3430 #if 1 /* #ifdef JP */
3440 /* Main window (need these before term_getsize gets called) */
3442 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3443 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3448 /* Sub windows (need these before term_getsize gets called) */
3449 for (i = 1; i < MAX_TERM_DATA; i++)
3452 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3453 td->dwExStyle = (WS_EX_TOOLWINDOW);
3458 for (i = 0; i < MAX_TERM_DATA; i++)
3462 #if 1 /* #ifdef JP */
3463 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3464 td->lf.lfCharSet = DEFAULT_CHARSET;
3465 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3466 /* Activate the chosen font */
3467 term_force_font(td, NULL);
3468 if(!td->tile_wid) td->tile_wid = td->font_wid;
3469 if(!td->tile_hgt) td->tile_hgt = td->font_hgt;
3471 /* Access the standard font file */
3472 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3474 /* Activate the chosen font */
3475 if (term_force_font(td, buf))
3477 /* Access the standard font file */
3478 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3480 /* Force the use of that font */
3481 (void)term_force_font(td, buf);
3486 /* Assume not bizarre */
3487 td->bizarre = FALSE;
3492 /* Analyze the font */
3495 /* Resize the window */
3496 term_window_resize(td);
3500 /* Sub windows (reverse order) */
3501 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3506 td->w = CreateWindowEx(td->dwExStyle, AngList,
3508 td->pos_x, td->pos_y,
3509 td->size_wid, td->size_hgt,
3510 HWND_DESKTOP, NULL, hInstance, NULL);
3512 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3516 td->size_hack = TRUE;
3517 ShowWindow(td->w, SW_SHOW);
3518 td->size_hack = FALSE;
3522 angband_term[i] = &td->t;
3526 /* Activate the window */
3527 SetActiveWindow(td->w);
3532 term_window_pos(&data[i], HWND_TOPMOST);
3536 term_window_pos(&data[i], td->w);
3546 td->w = CreateWindowEx(td->dwExStyle, AppName,
3548 td->pos_x, td->pos_y,
3549 td->size_wid, td->size_hgt,
3550 HWND_DESKTOP, NULL, hInstance, NULL);
3552 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3555 angband_term[0] = &td->t;
3556 normsize.x = td->cols;
3557 normsize.y = td->rows;
3559 /* Activate the main window */
3560 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3561 else ShowWindow(td->w, SW_SHOW);
3563 /* Bring main window back to top */
3564 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3568 (void)new_palette();
3571 /* Create a "brush" for drawing the "cursor" */
3572 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3575 /* Process pending messages */
3576 (void)Term_xtra_win_flush();
3584 static void setup_menus(void)
3588 HMENU hm = GetMenu(data[0].w);
3591 /* Menu "File", Disable all */
3592 EnableMenuItem(hm, IDM_FILE_NEW,
3593 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3594 EnableMenuItem(hm, IDM_FILE_OPEN,
3595 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3596 EnableMenuItem(hm, IDM_FILE_SAVE,
3597 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3598 EnableMenuItem(hm, IDM_FILE_EXIT,
3599 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3600 EnableMenuItem(hm, IDM_FILE_SCORE,
3601 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3604 /* No character available */
3605 if (!current_world_ptr->character_generated)
3607 /* Menu "File", Item "New" */
3608 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3610 /* Menu "File", Item "Open" */
3611 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3614 /* A character available */
3615 if (current_world_ptr->character_generated)
3617 /* Menu "File", Item "Save" */
3618 EnableMenuItem(hm, IDM_FILE_SAVE,
3619 MF_BYCOMMAND | MF_ENABLED);
3622 /* Menu "File", Item "Exit" */
3623 EnableMenuItem(hm, IDM_FILE_EXIT,
3624 MF_BYCOMMAND | MF_ENABLED);
3626 EnableMenuItem(hm, IDM_FILE_SCORE,
3627 MF_BYCOMMAND | MF_ENABLED);
3630 /* Menu "Window::Visibility" */
3631 for (i = 0; i < MAX_TERM_DATA; i++)
3633 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3634 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3636 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3637 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3639 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3640 MF_BYCOMMAND | MF_ENABLED);
3643 /* Menu "Window::Font" */
3644 for (i = 0; i < MAX_TERM_DATA; i++)
3646 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3647 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3649 if (data[i].visible)
3651 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3652 MF_BYCOMMAND | MF_ENABLED);
3656 /* Menu "Window::Window Position Fix" */
3657 for (i = 0; i < MAX_TERM_DATA; i++)
3659 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3660 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3662 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3663 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3665 if (data[i].visible)
3667 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3668 MF_BYCOMMAND | MF_ENABLED);
3672 /* Menu "Window::Bizarre Display" */
3673 for (i = 0; i < MAX_TERM_DATA; i++)
3675 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3676 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3678 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3679 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3681 if (data[i].visible)
3683 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3684 MF_BYCOMMAND | MF_ENABLED);
3689 /* Menu "Window::Increase Tile Width" */
3690 for (i = 0; i < MAX_TERM_DATA; i++)
3692 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3693 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3695 if (data[i].visible)
3697 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3698 MF_BYCOMMAND | MF_ENABLED);
3703 /* Menu "Window::Decrease Tile Width" */
3704 for (i = 0; i < MAX_TERM_DATA; i++)
3706 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3707 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3709 if (data[i].visible)
3711 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3712 MF_BYCOMMAND | MF_ENABLED);
3717 /* Menu "Window::Increase Tile Height" */
3718 for (i = 0; i < MAX_TERM_DATA; i++)
3720 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3721 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3723 if (data[i].visible)
3725 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3726 MF_BYCOMMAND | MF_ENABLED);
3731 /* Menu "Window::Decrease Tile Height" */
3732 for (i = 0; i < MAX_TERM_DATA; i++)
3734 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3735 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3737 if (data[i].visible)
3739 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3740 MF_BYCOMMAND | MF_ENABLED);
3745 /* Menu "Options", disable all */
3746 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3747 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3748 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3749 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3750 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3751 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3752 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3753 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3754 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3755 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3757 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3758 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3761 /* Menu "Options", Item "Map" */
3762 if (use_graphics != GRAPHICS_NONE)
3763 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3765 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3766 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3768 /* Menu "Options", update all */
3769 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3770 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3771 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3772 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3773 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3774 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3775 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3776 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3777 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3778 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3779 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3780 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3781 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3782 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3783 CheckMenuItem(hm, IDM_OPTIONS_BG,
3784 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3786 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3787 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3791 /* Menu "Options", Item "Graphics" */
3792 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3793 /* Menu "Options", Item "Graphics" */
3794 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3795 /* Menu "Options", Item "Graphics" */
3796 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3797 /* Menu "Options", Item "Graphics" */
3798 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3799 #endif /* USE_GRAPHICS */
3802 /* Menu "Options", Item "Sound" */
3803 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3804 #endif /* USE_SOUND */
3807 /* Menu "Options", Item "ScreenSaver" */
3808 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3809 MF_BYCOMMAND | MF_ENABLED);
3810 #endif /* USE_SAVER */
3815 * Check for double clicked (or dragged) savefile
3817 * Apparently, Windows copies the entire filename into the first
3818 * piece of the "command line string". Perhaps we should extract
3819 * the "basename" of that filename and append it to the "save" dir.
3821 static void check_for_save_file(LPSTR cmd_line)
3831 /* Extract filename */
3832 strcat(savefile, s);
3834 /* Validate the file */
3835 validate_file(savefile);
3837 /* Game in progress */
3838 game_in_progress = TRUE;
3846 * Process a menu command
3848 static void process_menus(WORD wCmd)
3864 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3866 else if (game_in_progress)
3868 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3872 game_in_progress = TRUE;
3885 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3887 else if (game_in_progress)
3889 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3893 memset(&ofn, 0, sizeof(ofn));
3894 ofn.lStructSize = sizeof(ofn);
3895 ofn.hwndOwner = data[0].w;
3896 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3897 ofn.nFilterIndex = 1;
3898 ofn.lpstrFile = savefile;
3899 ofn.nMaxFile = 1024;
3900 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3901 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3903 if (GetOpenFileName(&ofn))
3905 /* Load 'savefile' */
3906 validate_file(savefile);
3907 game_in_progress = TRUE;
3919 if (game_in_progress && current_world_ptr->character_generated)
3923 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3927 /* Hack -- Forget messages */
3932 do_cmd_save_game(FALSE);
3933 #else /* ZANGBAND */
3935 #endif /* ZANGBAND */
3939 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3947 if (game_in_progress && current_world_ptr->character_generated)
3951 plog(_("今は終了できません。", "You may not do that right now."));
3955 /* Hack -- Forget messages */
3964 /* do_cmd_save_game(FALSE); */
3965 #else /* ZANGBAND */
3966 /* do_cmd_save_game(); */
3967 #endif /* ZANGBAND */
3968 Term_key_push(SPECIAL_KEY_QUIT);
3976 case IDM_FILE_SCORE:
3980 /* Build the filename */
3981 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3983 /* Open the binary high score file, for reading */
3984 highscore_fd = fd_open(buf, O_RDONLY);
3986 /* Paranoia -- No score file */
3987 if (highscore_fd < 0)
3989 msg_print("Score file unavailable.");
3996 /* Display the scores */
3997 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3999 /* Shut the high score file */
4000 (void)fd_close(highscore_fd);
4002 /* Forget the high score fd */
4006 /* Hack - Flush it */
4014 case IDM_FILE_MOVIE:
4018 plog(_("まだ初期化中です...", "You cannot do that yet..."));
4020 else if (game_in_progress)
4022 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
4026 memset(&ofn, 0, sizeof(ofn));
4027 ofn.lStructSize = sizeof(ofn);
4028 ofn.hwndOwner = data[0].w;
4029 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
4030 ofn.nFilterIndex = 1;
4031 ofn.lpstrFile = savefile;
4032 ofn.nMaxFile = 1024;
4033 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
4034 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
4036 if (GetOpenFileName(&ofn))
4038 /* Load 'savefile' */
4039 prepare_browse_movie_aux(savefile);
4049 case IDM_WINDOW_VIS_0:
4051 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
4055 /* Window visibility */
4056 case IDM_WINDOW_VIS_1:
4057 case IDM_WINDOW_VIS_2:
4058 case IDM_WINDOW_VIS_3:
4059 case IDM_WINDOW_VIS_4:
4060 case IDM_WINDOW_VIS_5:
4061 case IDM_WINDOW_VIS_6:
4062 case IDM_WINDOW_VIS_7:
4064 i = wCmd - IDM_WINDOW_VIS_0;
4066 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4073 ShowWindow(td->w, SW_SHOW);
4074 term_data_redraw(td);
4078 td->visible = FALSE;
4080 ShowWindow(td->w, SW_HIDE);
4087 case IDM_WINDOW_FONT_0:
4088 case IDM_WINDOW_FONT_1:
4089 case IDM_WINDOW_FONT_2:
4090 case IDM_WINDOW_FONT_3:
4091 case IDM_WINDOW_FONT_4:
4092 case IDM_WINDOW_FONT_5:
4093 case IDM_WINDOW_FONT_6:
4094 case IDM_WINDOW_FONT_7:
4096 i = wCmd - IDM_WINDOW_FONT_0;
4098 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4102 term_change_font(td);
4107 /* Window Z Position */
4108 case IDM_WINDOW_POS_1:
4109 case IDM_WINDOW_POS_2:
4110 case IDM_WINDOW_POS_3:
4111 case IDM_WINDOW_POS_4:
4112 case IDM_WINDOW_POS_5:
4113 case IDM_WINDOW_POS_6:
4114 case IDM_WINDOW_POS_7:
4116 i = wCmd - IDM_WINDOW_POS_0;
4118 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4122 if (!td->posfix && td->visible)
4125 term_window_pos(td, HWND_TOPMOST);
4130 term_window_pos(td, data[0].w);
4136 /* Bizarre Display */
4137 case IDM_WINDOW_BIZ_0:
4138 case IDM_WINDOW_BIZ_1:
4139 case IDM_WINDOW_BIZ_2:
4140 case IDM_WINDOW_BIZ_3:
4141 case IDM_WINDOW_BIZ_4:
4142 case IDM_WINDOW_BIZ_5:
4143 case IDM_WINDOW_BIZ_6:
4144 case IDM_WINDOW_BIZ_7:
4146 i = wCmd - IDM_WINDOW_BIZ_0;
4148 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4152 td->bizarre = !td->bizarre;
4156 term_window_resize(td);
4161 /* Increase Tile Width */
4162 case IDM_WINDOW_I_WID_0:
4163 case IDM_WINDOW_I_WID_1:
4164 case IDM_WINDOW_I_WID_2:
4165 case IDM_WINDOW_I_WID_3:
4166 case IDM_WINDOW_I_WID_4:
4167 case IDM_WINDOW_I_WID_5:
4168 case IDM_WINDOW_I_WID_6:
4169 case IDM_WINDOW_I_WID_7:
4171 i = wCmd - IDM_WINDOW_I_WID_0;
4173 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4181 term_window_resize(td);
4186 /* Decrease Tile Height */
4187 case IDM_WINDOW_D_WID_0:
4188 case IDM_WINDOW_D_WID_1:
4189 case IDM_WINDOW_D_WID_2:
4190 case IDM_WINDOW_D_WID_3:
4191 case IDM_WINDOW_D_WID_4:
4192 case IDM_WINDOW_D_WID_5:
4193 case IDM_WINDOW_D_WID_6:
4194 case IDM_WINDOW_D_WID_7:
4196 i = wCmd - IDM_WINDOW_D_WID_0;
4198 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4206 term_window_resize(td);
4211 /* Increase Tile Height */
4212 case IDM_WINDOW_I_HGT_0:
4213 case IDM_WINDOW_I_HGT_1:
4214 case IDM_WINDOW_I_HGT_2:
4215 case IDM_WINDOW_I_HGT_3:
4216 case IDM_WINDOW_I_HGT_4:
4217 case IDM_WINDOW_I_HGT_5:
4218 case IDM_WINDOW_I_HGT_6:
4219 case IDM_WINDOW_I_HGT_7:
4221 i = wCmd - IDM_WINDOW_I_HGT_0;
4223 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4231 term_window_resize(td);
4236 /* Decrease Tile Height */
4237 case IDM_WINDOW_D_HGT_0:
4238 case IDM_WINDOW_D_HGT_1:
4239 case IDM_WINDOW_D_HGT_2:
4240 case IDM_WINDOW_D_HGT_3:
4241 case IDM_WINDOW_D_HGT_4:
4242 case IDM_WINDOW_D_HGT_5:
4243 case IDM_WINDOW_D_HGT_6:
4244 case IDM_WINDOW_D_HGT_7:
4246 i = wCmd - IDM_WINDOW_D_HGT_0;
4248 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4256 term_window_resize(td);
4261 case IDM_OPTIONS_NO_GRAPHICS:
4265 plog("You may not do that right now.");
4269 /* Toggle "arg_graphics" */
4270 if (arg_graphics != GRAPHICS_NONE)
4272 arg_graphics = GRAPHICS_NONE;
4274 /* React to changes */
4275 Term_xtra_win_react();
4277 /* Hack -- Force redraw */
4278 Term_key_push(KTRL('R'));
4284 case IDM_OPTIONS_OLD_GRAPHICS:
4288 plog("You may not do that right now.");
4292 /* Toggle "arg_graphics" */
4293 if (arg_graphics != GRAPHICS_ORIGINAL)
4295 arg_graphics = GRAPHICS_ORIGINAL;
4297 /* React to changes */
4298 Term_xtra_win_react();
4300 /* Hack -- Force redraw */
4301 Term_key_push(KTRL('R'));
4307 case IDM_OPTIONS_NEW_GRAPHICS:
4311 plog("You may not do that right now.");
4315 /* Toggle "arg_graphics" */
4316 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4318 arg_graphics = GRAPHICS_ADAM_BOLT;
4320 /* React to changes */
4321 Term_xtra_win_react();
4323 /* Hack -- Force redraw */
4324 Term_key_push(KTRL('R'));
4330 case IDM_OPTIONS_NEW2_GRAPHICS:
4334 plog("You may not do that right now.");
4338 /* Toggle "arg_graphics" */
4339 if (arg_graphics != GRAPHICS_HENGBAND)
4341 arg_graphics = GRAPHICS_HENGBAND;
4343 /* React to changes */
4344 Term_xtra_win_react();
4346 /* Hack -- Force redraw */
4347 Term_key_push(KTRL('R'));
4353 case IDM_OPTIONS_BIGTILE:
4358 plog("You may not do that right now.");
4362 /* Toggle "arg_sound" */
4363 arg_bigtile = !arg_bigtile;
4366 Term_activate(&td->t);
4368 /* Resize the term */
4369 Term_resize(td->cols, td->rows);
4372 InvalidateRect(td->w, NULL, TRUE);
4377 case IDM_OPTIONS_MUSIC:
4381 plog("You may not do that right now.");
4385 /* Toggle "arg_sound" */
4386 arg_music = !arg_music;
4388 /* React to changes */
4389 Term_xtra_win_react();
4391 /* Hack -- Force redraw */
4392 Term_key_push(KTRL('R'));
4397 case IDM_OPTIONS_SOUND:
4401 plog("You may not do that right now.");
4405 /* Toggle "arg_sound" */
4406 arg_sound = !arg_sound;
4408 /* React to changes */
4409 Term_xtra_win_react();
4411 /* Hack -- Force redraw */
4412 Term_key_push(KTRL('R'));
4418 case IDM_OPTIONS_BG:
4422 plog("You may not do that right now.");
4426 /* Toggle "use_bg" */
4431 /* React to changes */
4432 Term_xtra_win_react();
4434 /* Hack -- Force redraw */
4435 Term_key_push(KTRL('R'));
4441 case IDM_OPTIONS_OPEN_BG:
4445 plog("You may not do that right now.");
4450 memset(&ofn, 0, sizeof(ofn));
4451 ofn.lStructSize = sizeof(ofn);
4452 ofn.hwndOwner = data[0].w;
4453 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4454 ofn.nFilterIndex = 1;
4455 ofn.lpstrFile = bg_bitmap_file;
4456 ofn.nMaxFile = 1023;
4457 ofn.lpstrInitialDir = NULL;
4458 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
4459 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4461 if (GetOpenFileName(&ofn))
4463 /* Load 'savefile' */
4468 /* React to changes */
4469 Term_xtra_win_react();
4471 /* Hack -- Force redraw */
4472 Term_key_push(KTRL('R'));
4477 case IDM_DUMP_SCREEN_HTML:
4479 static char buf[1024] = "";
4480 memset(&ofn, 0, sizeof(ofn));
4481 ofn.lStructSize = sizeof(ofn);
4482 ofn.hwndOwner = data[0].w;
4483 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4484 ofn.nFilterIndex = 1;
4485 ofn.lpstrFile = buf;
4486 ofn.nMaxFile = 1023;
4487 ofn.lpstrDefExt = "html";
4488 ofn.lpstrInitialDir = NULL;
4489 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
4490 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4492 if (GetSaveFileName(&ofn))
4494 do_cmd_save_screen_html_aux(buf, 0);
4501 case IDM_OPTIONS_SAVER:
4505 DestroyWindow(hwndSaver);
4510 /* Create a screen scaver window */
4511 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4512 "Angband Screensaver",
4513 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4514 0, 0, GetSystemMetrics(SM_CXSCREEN),
4515 GetSystemMetrics(SM_CYSCREEN),
4516 NULL, NULL, hInstance, NULL);
4520 /* Push the window to the bottom */
4521 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4525 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
4533 case IDM_OPTIONS_MAP:
4539 case IDM_HELP_CONTENTS:
4543 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4544 if (check_file(tmp))
4546 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4550 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4551 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4554 #else /* HTML_HELP */
4557 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4558 if (check_file(tmp))
4560 sprintf(buf, "winhelp.exe %s", tmp);
4561 WinExec(buf, SW_NORMAL);
4565 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4566 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4570 #endif /* HTML_HELP */
4576 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4583 /* Extract the modifiers */
4584 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4585 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4586 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4588 Term_no_press = (ma) ? TRUE : FALSE;
4590 /* Handle "special" keys */
4591 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4593 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4594 bool numpad = FALSE;
4596 /* Begin the macro trigger */
4599 /* Send the modifiers */
4600 if (mc) Term_keypress('C');
4601 if (ms) Term_keypress('S');
4602 if (ma) Term_keypress('A');
4604 /* Extract "scan code" */
4605 i = LOBYTE(HIWORD(lParam));
4607 /* Introduce the scan code */
4610 /* Extended key bit */
4613 /* Numpad Enter and '/' are extended key */
4615 Term_no_press = TRUE;
4616 case VK_RETURN: /* Enter */
4619 /* Other extended keys are on full keyboard */
4635 Term_no_press = TRUE;
4639 case VK_PRIOR: /* Page Up */
4640 case VK_NEXT: /* Page Down */
4650 /* Special modifiers for keypad keys */
4651 if (numpad) Term_keypress('K');
4653 /* Encode the hexidecimal scan code */
4654 Term_keypress(hexsym[i/16]);
4655 Term_keypress(hexsym[i%16]);
4657 /* End the macro trigger */
4668 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4669 WPARAM wParam, LPARAM lParam);
4670 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4671 WPARAM wParam, LPARAM lParam)
4672 #else /* __MWERKS__ */
4673 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4674 #endif /* __MWERKS__ */
4680 MINMAXINFO FAR *lpmmi;
4686 /* Acquire proper "term_data" info */
4687 td = (term_data *)GetWindowLong(hWnd, 0);
4689 /* Handle message */
4694 SetWindowLong(hWnd, 0, (LONG)(my_td));
4701 mop.dwCallback=(DWORD)hWnd;
4706 case WM_GETMINMAXINFO:
4708 MINMAXINFO FAR *lpmmi;
4711 lpmmi = (MINMAXINFO FAR *)lParam;
4713 /* this message was sent before WM_NCCREATE */
4716 /* Minimum window size is 80x24 */
4717 rc.left = rc.top = 0;
4718 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4719 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4722 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4724 /* Save minimum size */
4725 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4726 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4733 BeginPaint(hWnd, &ps);
4734 if (td) term_data_redraw(td);
4735 EndPaint(hWnd, &ps);
4736 ValidateRect(hWnd, NULL);
4743 if(wParam == MCI_NOTIFY_SUCCESSFUL)
4745 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4746 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4755 if (process_keydown(wParam, lParam))
4762 if (Term_no_press) Term_no_press = FALSE;
4763 else Term_keypress(wParam);
4767 case WM_LBUTTONDOWN:
4769 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4770 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4782 TERM_LEN dx = abs(oldx - mousex) + 1;
4783 TERM_LEN dy = abs(oldy - mousey) + 1;
4784 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
4785 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
4795 hGlobal = GlobalAlloc(GHND, sz + 1);
4796 if (hGlobal == NULL) return 0;
4797 lpStr = (LPSTR)GlobalLock(hGlobal);
4799 for (i = 0; i < dy; i++)
4803 char **scr = data[0].t.scr->c;
4805 C_MAKE(s, (dx + 1), char);
4806 strncpy(s, &scr[oy + i][ox], dx);
4810 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4813 if (ox + dx < data[0].cols)
4815 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4818 for (j = 0; j < dx; j++)
4820 if (s[j] == 127) s[j] = '#';
4824 for (j = 0; j < dx; j++)
4826 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4836 GlobalUnlock(hGlobal);
4837 if (OpenClipboard(hWnd) == 0)
4839 GlobalFree(hGlobal);
4843 SetClipboardData(CF_TEXT, hGlobal);
4856 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4857 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4862 dx = abs(oldx - mousex) + 1;
4863 dy = abs(oldy - mousey) + 1;
4864 ox = (oldx > mousex) ? mousex : oldx;
4865 oy = (oldy > mousey) ? mousey : oldy;
4866 Term_inversed_area(hWnd, ox, oy, dx, dy);
4873 dx = abs(cx - mousex) + 1;
4874 dy = abs(cy - mousey) + 1;
4875 ox = (cx > mousex) ? mousex : cx;
4876 oy = (cy > mousey) ? mousey : cy;
4877 Term_inversed_area(hWnd, ox, oy, dx, dy);
4893 if (game_in_progress && current_world_ptr->character_generated)
4897 plog(_("今は終了できません。", "You may not do that right now."));
4901 /* Hack -- Forget messages */
4910 /* do_cmd_save_game(FALSE); */
4911 #else /* ZANGBAND */
4912 /* do_cmd_save_game(); */
4913 #endif /* ZANGBAND */
4914 Term_key_push(SPECIAL_KEY_QUIT);
4921 case WM_QUERYENDSESSION:
4923 if (game_in_progress && current_world_ptr->character_generated)
4925 /* Hack -- Forget messages */
4928 /* Mega-Hack -- Delay death */
4929 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4930 do_cmd_write_nikki(NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4932 /* Hardcode panic save */
4933 p_ptr->panic_save = 1;
4935 /* Forbid suspend */
4936 signals_ignore_tstp();
4938 /* Indicate panic save */
4939 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4942 (void)save_player();
4956 process_menus(LOWORD(wParam));
4962 /* this message was sent before WM_NCCREATE */
4965 /* it was sent from inside CreateWindowEx */
4966 if (!td->w) return 1;
4968 /* was sent from WM_SIZE */
4969 if (td->size_hack) return 1;
4973 case SIZE_MINIMIZED:
4975 /* Hide sub-windows */
4976 for (i = 1; i < MAX_TERM_DATA; i++)
4978 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4983 case SIZE_MAXIMIZED:
4990 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4991 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4994 if ((td->cols != cols) || (td->rows != rows))
4996 /* Save the new size */
5000 if (!IsZoomed(td->w) && !IsIconic(td->w))
5002 normsize.x = td->cols;
5003 normsize.y = td->rows;
5007 Term_activate(&td->t);
5009 /* Resize the term */
5010 Term_resize(td->cols, td->rows);
5013 InvalidateRect(td->w, NULL, TRUE);
5016 td->size_hack = TRUE;
5018 /* Show sub-windows */
5019 for (i = 1; i < MAX_TERM_DATA; i++)
5021 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
5024 td->size_hack = FALSE;
5032 case WM_PALETTECHANGED:
5034 /* Ignore if palette change caused by itself */
5035 if ((HWND)wParam == hWnd) return 0;
5037 /* Fall through... */
5040 case WM_QUERYNEWPALETTE:
5042 if (!paletted) return 0;
5046 SelectPalette(hdc, hPal, FALSE);
5048 i = RealizePalette(hdc);
5050 /* if any palette entries changed, repaint the window. */
5051 if (i) InvalidateRect(hWnd, NULL, TRUE);
5053 ReleaseDC(hWnd, hdc);
5060 if (wParam && !HIWORD(lParam))
5062 /* Do something to sub-windows */
5063 for (i = 1; i < MAX_TERM_DATA; i++)
5065 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
5068 /* Focus on main window */
5077 case WM_ACTIVATEAPP:
5079 if (IsIconic(td->w)) break;
5081 for (i = 1; i < MAX_TERM_DATA; i++)
5087 ShowWindow(data[i].w, SW_SHOW);
5091 ShowWindow(data[i].w, SW_HIDE);
5098 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5103 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5104 WPARAM wParam, LPARAM lParam);
5105 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5106 WPARAM wParam, LPARAM lParam)
5107 #else /* __MWERKS__ */
5108 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5109 WPARAM wParam, LPARAM lParam)
5110 #endif /* __MWERKS__ */
5114 MINMAXINFO FAR *lpmmi;
5122 /* Acquire proper "term_data" info */
5123 td = (term_data *)GetWindowLong(hWnd, 0);
5125 /* Process message */
5130 SetWindowLong(hWnd, 0, (LONG)(my_td));
5139 case WM_GETMINMAXINFO:
5141 MINMAXINFO FAR *lpmmi;
5144 lpmmi = (MINMAXINFO FAR *)lParam;
5146 /* this message was sent before WM_NCCREATE */
5149 /* Minimum window size is 80x24 */
5150 rc.left = rc.top = 0;
5151 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5152 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5155 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5157 /* Save minimum size */
5158 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5159 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5169 /* this message was sent before WM_NCCREATE */
5172 /* it was sent from inside CreateWindowEx */
5173 if (!td->w) return 1;
5175 /* was sent from inside WM_SIZE */
5176 if (td->size_hack) return 1;
5178 td->size_hack = TRUE;
5180 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5181 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5184 if ((td->cols != cols) || (td->rows != rows))
5187 term *old_term = Term;
5189 /* Save the new size */
5194 Term_activate(&td->t);
5196 /* Resize the term */
5197 Term_resize(td->cols, td->rows);
5200 Term_activate(old_term);
5203 InvalidateRect(td->w, NULL, TRUE);
5205 /* HACK - Redraw all windows */
5206 p_ptr->window = 0xFFFFFFFF;
5210 td->size_hack = FALSE;
5217 BeginPaint(hWnd, &ps);
5218 if (td) term_data_redraw(td);
5219 EndPaint(hWnd, &ps);
5226 if (process_keydown(wParam, lParam))
5233 if (Term_no_press) Term_no_press = FALSE;
5234 else Term_keypress(wParam);
5238 case WM_PALETTECHANGED:
5240 /* ignore if palette change caused by itself */
5241 if ((HWND)wParam == hWnd) return FALSE;
5242 /* otherwise, fall through!!! */
5245 case WM_QUERYNEWPALETTE:
5247 if (!paletted) return 0;
5249 SelectPalette(hdc, hPal, FALSE);
5250 i = RealizePalette(hdc);
5251 /* if any palette entries changed, repaint the window. */
5252 if (i) InvalidateRect(hWnd, NULL, TRUE);
5253 ReleaseDC(hWnd, hdc);
5257 case WM_NCLBUTTONDOWN:
5261 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5262 #endif /* HTCLOSE */
5264 if (wParam == HTSYSMENU)
5268 td->visible = FALSE;
5269 ShowWindow(td->w, SW_HIDE);
5279 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5285 #define MOUSE_SENS 40
5288 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5289 WPARAM wParam, LPARAM lParam);
5290 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5291 WPARAM wParam, LPARAM lParam)
5292 #else /* __MWERKS__ */
5293 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5294 WPARAM wParam, LPARAM lParam)
5295 #endif /* __MWERKS__ */
5297 static int iMouse = 0;
5298 static WORD xMouse = 0;
5299 static WORD yMouse = 0;
5321 if (LOWORD(wParam) == WA_INACTIVE) break;
5323 /* else fall through */
5327 case WM_LBUTTONDOWN:
5328 case WM_MBUTTONDOWN:
5329 case WM_RBUTTONDOWN:
5332 SendMessage(hWnd, WM_CLOSE, 0, 0);
5340 dx = LOWORD(lParam) - xMouse;
5341 dy = HIWORD(lParam) - yMouse;
5343 if (dx < 0) dx = -dx;
5344 if (dy < 0) dy = -dy;
5346 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5348 SendMessage(hWnd, WM_CLOSE, 0, 0);
5352 /* Save last location */
5354 xMouse = LOWORD(lParam);
5355 yMouse = HIWORD(lParam);
5362 DestroyWindow(hwndSaver);
5368 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5371 #endif /* USE_SAVER */
5377 /*** Temporary Hooks ***/
5381 * Display warning message (see "z-util.c")
5383 static void hack_plog(concptr str)
5385 /* Give a warning */
5389 MessageBox(NULL, str, "警告!",
5390 MB_ICONEXCLAMATION | MB_OK);
5392 MessageBox(NULL, str, "Warning",
5393 MB_ICONEXCLAMATION | MB_OK);
5401 * Display error message and quit (see "z-util.c")
5403 static void hack_quit(concptr str)
5405 /* Give a warning */
5409 MessageBox(NULL, str, "エラー!",
5410 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5412 MessageBox(NULL, str, "Error",
5413 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5418 /* Unregister the classes */
5419 UnregisterClass(AppName, hInstance);
5421 /* Destroy the icon */
5422 if (hIcon) DestroyIcon(hIcon);
5430 /*** Various hooks ***/
5434 * Display warning message (see "z-util.c")
5436 static void hook_plog(concptr str)
5442 MessageBox(data[0].w, str, "警告!",
5443 MB_ICONEXCLAMATION | MB_OK);
5445 MessageBox(data[0].w, str, "Warning",
5446 MB_ICONEXCLAMATION | MB_OK);
5454 * Display error message and quit (see "z-util.c")
5456 static void hook_quit(concptr str)
5461 /* Give a warning */
5465 MessageBox(data[0].w, str, "エラー!",
5466 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5468 MessageBox(data[0].w, str, "Error",
5469 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5475 /* Save the preferences */
5479 /*** Could use 'Term_nuke_win()' */
5481 /* Destroy all windows */
5482 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5484 term_force_font(&data[i], NULL);
5485 if (data[i].font_want) string_free(data[i].font_want);
5486 if (data[i].w) DestroyWindow(data[i].w);
5490 /* Free the bitmap stuff */
5492 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5493 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5495 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5496 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5498 #endif /* USE_GRAPHICS */
5500 /*** Free some other stuff ***/
5502 DeleteObject(hbrYellow);
5507 if (hPal) DeleteObject(hPal);
5509 UnregisterClass(AppName, hInstance);
5511 if (hIcon) DestroyIcon(hIcon);
5518 /*** Initialize ***/
5524 static void init_stuff(void)
5531 /* Get program name with full path */
5532 GetModuleFileName(hInstance, path, 512);
5534 /* Save the "program name" */
5537 /* Get the name of the "*.ini" file */
5538 strcpy(path + strlen(path) - 4, ".INI");
5540 /* Save the the name of the ini-file */
5541 ini_file = string_make(path);
5543 /* Analyze the path */
5549 if (path[i] == '\\')
5556 /* Add "lib" to the path */
5557 strcpy(path + i + 1, "lib\\");
5559 /* Validate the path */
5560 validate_dir(path, TRUE);
5562 /* Init the file paths */
5563 init_file_paths(path);
5565 /* Hack -- Validate the paths */
5566 validate_dir(ANGBAND_DIR_APEX, FALSE);
5567 validate_dir(ANGBAND_DIR_BONE, FALSE);
5569 /* Allow missing 'edit' directory */
5570 if (!check_dir(ANGBAND_DIR_EDIT))
5572 /* Must have 'data'! */
5573 validate_dir(ANGBAND_DIR_DATA, TRUE);
5577 /* Don't need 'data' */
5578 validate_dir(ANGBAND_DIR_DATA, FALSE);
5581 validate_dir(ANGBAND_DIR_FILE, TRUE);
5582 validate_dir(ANGBAND_DIR_HELP, FALSE);
5583 validate_dir(ANGBAND_DIR_INFO, FALSE);
5584 validate_dir(ANGBAND_DIR_PREF, TRUE);
5585 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5586 validate_dir(ANGBAND_DIR_USER, TRUE);
5587 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5589 /* Build the filename */
5590 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
5592 /* Hack -- Validate the "news.txt" file */
5593 validate_file(path);
5596 #if 0 /* #ifndef JP */
5597 /* Build the "font" path */
5598 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5600 /* Allocate the path */
5601 ANGBAND_DIR_XTRA_FONT = string_make(path);
5603 /* Validate the "font" directory */
5604 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5606 /* Build the filename */
5607 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5609 /* Hack -- Validate the basic font */
5610 validate_file(path);
5616 /* Build the "graf" path */
5617 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5619 /* Allocate the path */
5620 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5622 /* Validate the "graf" directory */
5623 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5625 #endif /* USE_GRAPHICS */
5630 /* Build the "sound" path */
5631 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5633 /* Allocate the path */
5634 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5636 /* Validate the "sound" directory */
5637 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5639 #endif /* USE_SOUND */
5643 /* Build the "music" path */
5644 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5646 /* Allocate the path */
5647 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5649 /* Validate the "music" directory */
5650 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5652 #endif /* USE_MUSIC */
5654 /* Build the "help" path */
5655 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5657 /* Allocate the path */
5658 ANGBAND_DIR_XTRA_HELP = string_make(path);
5660 /* Validate the "help" directory */
5661 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5665 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
5667 static bool is_already_running(void)
5669 bool result = FALSE;
5672 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5673 if (GetLastError() == ERROR_ALREADY_EXISTS)
5682 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
5684 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5685 LPSTR lpCmdLine, int nCmdShow)
5693 setlocale(LC_ALL, "ja_JP.utf8");
5702 /* Prevent multiple run */
5703 if (is_already_running())
5706 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
5707 _("エラー!", "Error") ,
5708 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5712 if (hPrevInst == NULL)
5714 wc.style = CS_CLASSDC;
5715 wc.lpfnWndProc = AngbandWndProc;
5717 wc.cbWndExtra = 4; /* one long pointer to term_data */
5718 wc.hInstance = hInst;
5719 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5720 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5721 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5722 wc.lpszMenuName = AppName;
5723 wc.lpszClassName = AppName;
5725 if (!RegisterClass(&wc)) exit(1);
5727 wc.lpfnWndProc = AngbandListProc;
5728 wc.lpszMenuName = NULL;
5729 wc.lpszClassName = AngList;
5731 if (!RegisterClass(&wc)) exit(2);
5735 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5736 wc.lpfnWndProc = AngbandSaverProc;
5738 wc.lpszMenuName = NULL;
5739 wc.lpszClassName = "WindowsScreenSaverClass";
5741 if (!RegisterClass(&wc)) exit(3);
5747 /* Temporary hooks */
5748 plog_aux = hack_plog;
5749 quit_aux = hack_quit;
5750 core_aux = hack_quit;
5752 /* Prepare the filepaths */
5755 /* Initialize the keypress analyzer */
5756 for (i = 0; special_key_list[i]; ++i)
5758 special_key[special_key_list[i]] = TRUE;
5760 /* Initialize the keypress analyzer */
5761 for (i = 0; ignore_key_list[i]; ++i)
5763 ignore_key[ignore_key_list[i]] = TRUE;
5766 /* Determine if display is 16/256/true color */
5768 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5769 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5770 ReleaseDC(NULL, hdc);
5772 /* Initialize the colors */
5773 for (i = 0; i < 256; i++)
5777 /* Extract desired values */
5778 rv = angband_color_table[i][1];
5779 gv = angband_color_table[i][2];
5780 bv = angband_color_table[i][3];
5782 /* Extract the "complex" code */
5783 win_clr[i] = PALETTERGB(rv, gv, bv);
5785 /* Save the "simple" code */
5786 angband_color_table[i][0] = win_pal[i];
5789 /* Prepare the windows */
5795 /* Activate hooks */
5796 plog_aux = hook_plog;
5797 quit_aux = hook_quit;
5798 core_aux = hook_quit;
5800 /* Set the system suffix */
5801 ANGBAND_SYS = "win";
5803 /* Set the keyboard suffix */
5804 if (7 != GetKeyboardType(0))
5805 ANGBAND_KEYBOARD = "0";
5808 /* Japanese keyboard */
5809 switch (GetKeyboardType(1))
5811 case 0x0D01: case 0x0D02:
5812 case 0x0D03: case 0x0D04:
5813 case 0x0D05: case 0x0D06:
5815 ANGBAND_KEYBOARD = "NEC98";
5819 ANGBAND_KEYBOARD = "JAPAN";
5823 /* Catch nasty signals */
5826 Term_activate(term_screen);
5829 /* We are now initialized */
5832 if(lpCmdLine[0] == '-'){
5833 switch(lpCmdLine[1])
5838 if (!lpCmdLine[2]) break;
5839 chuukei_server = TRUE;
5840 if(connect_chuukei_server(&lpCmdLine[2])<0){
5841 msg_print("connect fail");
5844 msg_print("connect");
5852 if (!lpCmdLine[2]) break;
5853 chuukei_client = TRUE;
5854 connect_chuukei_server(&lpCmdLine[2]);
5862 if (!lpCmdLine[2]) break;
5863 prepare_browse_movie(&lpCmdLine[2]);
5873 /* Did the user double click on a save file? */
5874 if(!chuukei_server) check_for_save_file(lpCmdLine);
5876 /* Did the user double click on a save file? */
5877 check_for_save_file(lpCmdLine);
5880 /* Prompt the user */
5881 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
5885 /* Process messages forever */
5886 while (GetMessage(&msg, NULL, 0, 0))
5888 TranslateMessage(&msg);
5889 DispatchMessage(&msg);
5896 #endif /* WINDOWS */