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).
103 #include "cmd-dump.h"
104 #include "view-mainwindow.h"
106 #include "floor-events.h"
118 * Extract the "WIN32" flag from the compiler
120 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
128 * Hack -- allow use of "screen saver" mode
134 * Menu constants -- see "ANGBAND.RC"
137 #define IDM_FILE_NEW 100
138 #define IDM_FILE_OPEN 101
139 #define IDM_FILE_SAVE 110
140 #define IDM_FILE_SCORE 120
141 #define IDM_FILE_MOVIE 121
142 #define IDM_FILE_EXIT 130
144 #define IDM_WINDOW_VIS_0 200
145 #define IDM_WINDOW_VIS_1 201
146 #define IDM_WINDOW_VIS_2 202
147 #define IDM_WINDOW_VIS_3 203
148 #define IDM_WINDOW_VIS_4 204
149 #define IDM_WINDOW_VIS_5 205
150 #define IDM_WINDOW_VIS_6 206
151 #define IDM_WINDOW_VIS_7 207
153 #define IDM_WINDOW_FONT_0 210
154 #define IDM_WINDOW_FONT_1 211
155 #define IDM_WINDOW_FONT_2 212
156 #define IDM_WINDOW_FONT_3 213
157 #define IDM_WINDOW_FONT_4 214
158 #define IDM_WINDOW_FONT_5 215
159 #define IDM_WINDOW_FONT_6 216
160 #define IDM_WINDOW_FONT_7 217
162 #define IDM_WINDOW_POS_0 220
163 #define IDM_WINDOW_POS_1 221
164 #define IDM_WINDOW_POS_2 222
165 #define IDM_WINDOW_POS_3 223
166 #define IDM_WINDOW_POS_4 224
167 #define IDM_WINDOW_POS_5 225
168 #define IDM_WINDOW_POS_6 226
169 #define IDM_WINDOW_POS_7 227
171 #define IDM_WINDOW_BIZ_0 230
172 #define IDM_WINDOW_BIZ_1 231
173 #define IDM_WINDOW_BIZ_2 232
174 #define IDM_WINDOW_BIZ_3 233
175 #define IDM_WINDOW_BIZ_4 234
176 #define IDM_WINDOW_BIZ_5 235
177 #define IDM_WINDOW_BIZ_6 236
178 #define IDM_WINDOW_BIZ_7 237
180 #define IDM_WINDOW_I_WID_0 240
181 #define IDM_WINDOW_I_WID_1 241
182 #define IDM_WINDOW_I_WID_2 242
183 #define IDM_WINDOW_I_WID_3 243
184 #define IDM_WINDOW_I_WID_4 244
185 #define IDM_WINDOW_I_WID_5 245
186 #define IDM_WINDOW_I_WID_6 246
187 #define IDM_WINDOW_I_WID_7 247
189 #define IDM_WINDOW_D_WID_0 250
190 #define IDM_WINDOW_D_WID_1 251
191 #define IDM_WINDOW_D_WID_2 252
192 #define IDM_WINDOW_D_WID_3 253
193 #define IDM_WINDOW_D_WID_4 254
194 #define IDM_WINDOW_D_WID_5 255
195 #define IDM_WINDOW_D_WID_6 256
196 #define IDM_WINDOW_D_WID_7 257
198 #define IDM_WINDOW_I_HGT_0 260
199 #define IDM_WINDOW_I_HGT_1 261
200 #define IDM_WINDOW_I_HGT_2 262
201 #define IDM_WINDOW_I_HGT_3 263
202 #define IDM_WINDOW_I_HGT_4 264
203 #define IDM_WINDOW_I_HGT_5 265
204 #define IDM_WINDOW_I_HGT_6 266
205 #define IDM_WINDOW_I_HGT_7 267
207 #define IDM_WINDOW_D_HGT_0 270
208 #define IDM_WINDOW_D_HGT_1 271
209 #define IDM_WINDOW_D_HGT_2 272
210 #define IDM_WINDOW_D_HGT_3 273
211 #define IDM_WINDOW_D_HGT_4 274
212 #define IDM_WINDOW_D_HGT_5 275
213 #define IDM_WINDOW_D_HGT_6 276
214 #define IDM_WINDOW_D_HGT_7 277
216 #define IDM_OPTIONS_NO_GRAPHICS 400
217 #define IDM_OPTIONS_OLD_GRAPHICS 401
218 #define IDM_OPTIONS_NEW_GRAPHICS 402
219 #define IDM_OPTIONS_NEW2_GRAPHICS 403
220 #define IDM_OPTIONS_BIGTILE 409
221 #define IDM_OPTIONS_SOUND 410
222 #define IDM_OPTIONS_MUSIC 411
223 #define IDM_OPTIONS_SAVER 420
224 #define IDM_OPTIONS_MAP 430
225 #define IDM_OPTIONS_BG 440
226 #define IDM_OPTIONS_OPEN_BG 441
228 #define IDM_DUMP_SCREEN_HTML 450
230 #define IDM_HELP_CONTENTS 901
233 * Exclude parts of WINDOWS.H that are not needed
235 #define NOCOMM /* Comm driver APIs and definitions */
236 #define NOLOGERROR /* LogError() and related definitions */
237 #define NOPROFILER /* Profiler APIs */
238 #define NOLFILEIO /* _l* file I/O routines */
239 #define NOOPENFILE /* OpenFile and related definitions */
240 #define NORESOURCE /* Resource management */
241 #define NOATOM /* Atom management */
242 #define NOLANGUAGE /* Character test routines */
243 #define NOLSTRING /* lstr* string management routines */
244 #define NODBCS /* Double-byte character set routines */
245 #define NOKEYBOARDINFO /* Keyboard driver routines */
246 #define NOCOLOR /* COLOR_* color values */
247 #define NODRAWTEXT /* DrawText() and related definitions */
248 #define NOSCALABLEFONT /* Truetype scalable font support */
249 #define NOMETAFILE /* Metafile support */
250 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
251 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
252 #define NOKEYSTATES /* MK_* message key state flags */
253 #define NOWH /* SetWindowsHook and related WH_* definitions */
254 #define NOCLIPBOARD /* Clipboard APIs and definitions */
255 #define NOICONS /* IDI_* icon IDs */
256 #define NOMDI /* MDI support */
257 #define NOHELP /* Help support */
259 /* Not defined since it breaks Borland C++ 5.5 */
260 /* #define NOCTLMGR */ /* Control management and controls */
263 * Exclude parts of WINDOWS.H that are not needed (Win32)
265 #define WIN32_LEAN_AND_MEAN
266 #define NONLS /* All NLS defines and routines */
267 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
268 #define NOKANJI /* Kanji support stuff. */
269 #define NOMCX /* Modem Configuration Extensions */
272 * Include the "windows" support file
277 * Exclude parts of MMSYSTEM.H that are not needed
279 #define MMNODRV /* Installable driver support */
280 #define MMNOWAVE /* Waveform support */
281 #define MMNOMIDI /* MIDI support */
282 #define MMNOAUX /* Auxiliary audio support */
283 #define MMNOTIMER /* Timer support */
284 #define MMNOJOY /* Joystick support */
285 #define MMNOMCI /* MCI support */
286 #define MMNOMMIO /* Multimedia file I/O support */
287 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
290 * Include some more files. Note: the Cygnus Cygwin compiler
291 * doesn't use mmsystem.h instead it includes the winmm library
292 * which performs a similar function.
294 #include <mmsystem.h>
298 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
299 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
301 /* #define HTML_HELP */
304 #include <htmlhelp.h>
305 #endif /* HTML_HELP */
308 * Include the support for loading bitmaps
311 # include "readdib.h"
315 * Hack -- Fake declarations from "dos.h"
318 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
320 #define FA_LABEL 0x08 /* Volume label */
321 #define FA_DIREC 0x10 /* Directory */
322 unsigned _cdecl _dos_getfileattr(concptr , unsigned *);
326 * Silliness in WIN32 drawing routine
329 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
333 * Silliness for Windows 95
335 #ifndef WS_EX_TOOLWINDOW
336 # define WS_EX_TOOLWINDOW 0
340 * Foreground color bits (hard-coded by DOS)
342 #define VID_BLACK 0x00
343 #define VID_BLUE 0x01
344 #define VID_GREEN 0x02
345 #define VID_CYAN 0x03
347 #define VID_MAGENTA 0x05
348 #define VID_YELLOW 0x06
349 #define VID_WHITE 0x07
352 * Bright text (hard-coded by DOS)
354 #define VID_BRIGHT 0x08
357 * Background color bits (hard-coded by DOS)
359 #define VUD_BLACK 0x00
360 #define VUD_BLUE 0x10
361 #define VUD_GREEN 0x20
362 #define VUD_CYAN 0x30
364 #define VUD_MAGENTA 0x50
365 #define VUD_YELLOW 0x60
366 #define VUD_WHITE 0x70
369 * Blinking text (hard-coded by DOS)
371 #define VUD_BRIGHT 0x80
377 typedef struct _term_data term_data;
381 * @brief ターム情報構造体 / Extra "term" data
384 * pos_x / pos_y は各タームの左上点座標を指す。
387 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
388 * 1ドットずつ調整するステータスを指す。
389 * また、フォントを変更すると都度自動調整される。
392 * Note the use of "font_want" for the names of the font file requested by
393 * the user, and the use of "font_file" for the currently active font file.
395 * The "font_file" is uppercased, and takes the form "8X13.FON", while
396 * "font_want" can be in almost any form as long as it could be construed
397 * as attempting to represent the name of a font.
409 TERM_LEN rows; /* int -> uint */
412 uint pos_x; //!< タームの左上X座標
413 uint pos_y; //!< タームの左上Y座標
428 int font_wid; //!< フォント横幅
429 int font_hgt; //!< フォント縦幅
430 int tile_wid; //!< タイル横幅
431 int tile_hgt; //!< タイル縦幅
437 #if 1 /* #ifdef JP */
445 #define MAX_TERM_DATA 8 //!< Maximum number of windows
447 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
448 static term_data *my_td; //!< Hack -- global "window creation" pointer
449 POINT normsize; //!< Remember normal size of main window when maxmized
452 * was main window maximized on previous playing
454 bool win_maximized = FALSE;
459 bool game_in_progress = FALSE;
462 * note when "open"/"new" become valid
464 bool initialized = FALSE;
467 * screen paletted, i.e. 256 colors
469 bool paletted = FALSE;
472 * 16 colors screen, don't use RGB()
474 bool colors16 = FALSE;
477 * Saved instance handle
479 static HINSTANCE hInstance;
482 * Yellow brush for the cursor
484 static HBRUSH hbrYellow;
494 static HPALETTE hPal;
497 static HBITMAP hBG = NULL;
498 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
499 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
504 * The screen saver window
506 static HWND hwndSaver;
508 #endif /* USE_SAVER */
514 * 現在使用中のタイルID(0ならば未使用)
515 * Flag set once "graphics" has been initialized
517 static byte_hack current_graphics_mode = 0;
522 static DIBINIT infGraph;
525 * The global bitmap mask
527 static DIBINIT infMask;
529 #endif /* USE_GRAPHICS */
535 * Flag set once "sound" has been initialized
537 static bool can_use_sound = FALSE;
541 * An array of sound file names
543 static concptr sound_file[SOUND_MAX][SAMPLE_MAX];
545 #endif /* USE_SOUND */
551 #define SAMPLE_MUSIC_MAX 16
552 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
553 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
554 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
555 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
556 static bool can_use_music = FALSE;
558 static MCI_OPEN_PARMS mop;
559 static char mci_device_type[256];
561 int current_music_type = 0;
562 int current_music_id = 0;
564 #endif /* USE_MUSIC */
568 * Full path to ANGBAND.INI
570 static concptr ini_file = NULL;
573 * Name of application
575 static concptr AppName = "ANGBAND";
578 * Name of sub-window type
580 static concptr AngList = "AngList";
585 static concptr ANGBAND_DIR_XTRA_GRAF;
586 static concptr ANGBAND_DIR_XTRA_SOUND;
587 static concptr ANGBAND_DIR_XTRA_MUSIC;
588 static concptr ANGBAND_DIR_XTRA_HELP;
589 #if 0 /* #ifndef JP */
590 static concptr ANGBAND_DIR_XTRA_FONT;
593 static concptr ANGBAND_DIR_XTRA_MUSIC;
598 * The "complex" color values
600 static COLORREF win_clr[256];
604 * Flag for macro trigger with dump ASCII
606 static bool Term_no_press = FALSE;
611 static bool mouse_down = FALSE;
612 static bool paint_rect = FALSE;
613 static TERM_LEN mousex = 0, mousey = 0;
614 static TERM_LEN oldx, oldy;
618 * @brief The "simple" color values
620 * See "main-ibm.c" for original table information
621 * The entries below are taken from the "color bits" defined above.
622 * Note that many of the choices below suck, but so do crappy monitors.
624 static BYTE win_pal[256] =
626 VID_BLACK, /* Dark */
627 VID_WHITE, /* White */
628 VID_CYAN, /* Slate XXX */
629 VID_RED | VID_BRIGHT, /* Orange XXX */
631 VID_GREEN, /* Green */
633 VID_YELLOW, /* Umber XXX */
634 VID_BLACK | VID_BRIGHT, /* Light Dark */
635 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
636 VID_MAGENTA, /* Violet XXX */
637 VID_YELLOW | VID_BRIGHT, /* Yellow */
638 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
639 VID_GREEN | VID_BRIGHT, /* Light Green */
640 VID_BLUE | VID_BRIGHT, /* Light Blue */
641 VID_YELLOW /* Light Umber XXX */
646 * Hack -- define which keys are "special"
648 static bool special_key[256];
649 static bool ignore_key[256];
653 * Hack -- initialization list for "special_key"
655 static byte special_key_list[] = {
656 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
657 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
658 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
659 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
660 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
661 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
662 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
663 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
664 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
665 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
666 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
667 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
668 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
669 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
670 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
671 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
672 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
677 static byte ignore_key_list[] = {
678 VK_ESCAPE, VK_TAB, VK_SPACE,
679 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
680 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
681 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
687 * Hack -- initialization list for "special_key"
689 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
690 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
691 * catch the keypad keys (with and without numlock set, including keypad 5),
692 * the function keys (including the "menu" key which maps to F10), and the
693 * "pause" key (between scroll lock and numlock). We also catch a few odd
694 * keys which I do not recognize, but which are listed among keys which we
695 * do catch, so they should be harmless to catch.
697 static byte special_key_list[] =
699 VK_CLEAR, /* 0x0C (KP<5>) */
701 VK_PAUSE, /* 0x13 (pause) */
703 VK_PRIOR, /* 0x21 (KP<9>) */
704 VK_NEXT, /* 0x22 (KP<3>) */
705 VK_END, /* 0x23 (KP<1>) */
706 VK_HOME, /* 0x24 (KP<7>) */
707 VK_LEFT, /* 0x25 (KP<4>) */
708 VK_UP, /* 0x26 (KP<8>) */
709 VK_RIGHT, /* 0x27 (KP<6>) */
710 VK_DOWN, /* 0x28 (KP<2>) */
711 VK_SELECT, /* 0x29 (?????) */
712 VK_PRINT, /* 0x2A (?????) */
713 VK_EXECUTE, /* 0x2B (?????) */
714 VK_SNAPSHOT, /* 0x2C (?????) */
715 VK_INSERT, /* 0x2D (KP<0>) */
716 VK_DELETE, /* 0x2E (KP<.>) */
717 VK_HELP, /* 0x2F (?????) */
719 VK_NUMPAD0, /* 0x60 (KP<0>) */
720 VK_NUMPAD1, /* 0x61 (KP<1>) */
721 VK_NUMPAD2, /* 0x62 (KP<2>) */
722 VK_NUMPAD3, /* 0x63 (KP<3>) */
723 VK_NUMPAD4, /* 0x64 (KP<4>) */
724 VK_NUMPAD5, /* 0x65 (KP<5>) */
725 VK_NUMPAD6, /* 0x66 (KP<6>) */
726 VK_NUMPAD7, /* 0x67 (KP<7>) */
727 VK_NUMPAD8, /* 0x68 (KP<8>) */
728 VK_NUMPAD9, /* 0x69 (KP<9>) */
729 VK_MULTIPLY, /* 0x6A (KP<*>) */
730 VK_ADD, /* 0x6B (KP<+>) */
731 VK_SEPARATOR, /* 0x6C (?????) */
732 VK_SUBTRACT, /* 0x6D (KP<->) */
733 VK_DECIMAL, /* 0x6E (KP<.>) */
734 VK_DIVIDE, /* 0x6F (KP</>) */
765 /* Function prototype */
767 static bool is_already_running(void);
771 static void delete_bg(void)
780 static int init_bg(void)
782 char * bmfile = bg_bitmap_file;
785 if (use_bg == 0) return 0;
787 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
789 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
797 static void DrawBG(HDC hdc, RECT *r)
802 int x = r->left, y = r->top;
803 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
809 GetObject(hBG, sizeof(bm), &bm);
810 swid = bm.bmWidth; shgt = bm.bmHeight;
812 hdcSrc = CreateCompatibleDC(hdc);
813 hOld = SelectObject(hdcSrc, hBG);
817 cwid = MIN(swid - sx, r->right - nx);
820 chgt = MIN(shgt - sy, r->bottom - ny);
821 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
823 } while (ny < r->bottom);
826 } while (nx < r->right);
828 SelectObject(hdcSrc, hOld);
834 * Hack -- given a pathname, point at the filename
836 static concptr extract_file_name(concptr s)
840 /* Start at the end */
841 p = s + strlen(s) - 1;
843 /* Back up to divider */
844 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
846 /* Return file name */
853 * Hack -- given a simple filename, extract the "font size" info
855 * Return a pointer to a static buffer holding the capitalized base name.
857 #if 0 /* #ifndef JP */
858 static char *analyze_font(char *path, int *wp, int *hp)
864 /* Start at the end */
865 p = path + strlen(path) - 1;
867 /* Back up to divider */
868 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
870 /* Advance to file name */
876 /* Capitalize (be paranoid) */
877 if (islower(*s)) *s = toupper(*s);
881 s = my_strchr(p, 'X');
883 /* Extract font width */
887 hgt = s ? atoi(s+1) : 0;
898 * Check for existance of a file
900 static bool check_file(concptr s)
920 attrib = GetFileAttributes(path);
922 /* Require valid filename */
923 if (attrib == INVALID_FILE_NAME) return (FALSE);
925 /* Prohibit directory */
926 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
930 /* Examine and verify */
931 if (_dos_getfileattr(path, &attrib)) return (FALSE);
933 /* Prohibit something */
934 if (attrib & FA_LABEL) return (FALSE);
936 /* Prohibit directory */
937 if (attrib & FA_DIREC) return (FALSE);
947 * Check for existance of a directory
949 static bool check_dir(concptr s)
971 /* Remove trailing backslash */
972 if (i && (path[i-1] == '\\')) path[--i] = '\0';
977 attrib = GetFileAttributes(path);
979 /* Require valid filename */
980 if (attrib == INVALID_FILE_NAME) return (FALSE);
982 /* Require directory */
983 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
987 /* Examine and verify */
988 if (_dos_getfileattr(path, &attrib)) return (FALSE);
990 /* Prohibit something */
991 if (attrib & FA_LABEL) return (FALSE);
993 /* Require directory */
994 if (!(attrib & FA_DIREC)) return (FALSE);
1006 static void validate_file(concptr s)
1008 /* Verify or fail */
1011 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
1017 * Validate a directory
1019 static void validate_dir(concptr s, bool vital)
1021 /* Verify or fail */
1024 /* This directory contains needed data */
1027 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
1029 /* Attempt to create this directory */
1032 quit_fmt("Unable to create directory:\n%s", s);
1039 * @brief (Windows版固有実装)Get the "size" for a window
1041 static void term_getsize(term_data *td)
1045 if (td->cols < 1) td->cols = 1;
1046 if (td->rows < 1) td->rows = 1;
1049 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1050 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1052 /* Fake window size */
1054 rc.right = rc.left + wid;
1056 rc.bottom = rc.top + hgt;
1058 /* rc.right += 1; */
1059 /* rc.bottom += 1; */
1062 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1065 td->size_wid = rc.right - rc.left;
1066 td->size_hgt = rc.bottom - rc.top;
1068 /* See CreateWindowEx */
1071 /* Extract actual location */
1072 GetWindowRect(td->w, &rc);
1074 /* Save the location */
1075 td->pos_x = rc.left;
1081 * Write the "prefs" for a single term
1083 static void save_prefs_aux(int i)
1085 term_data *td = &data[i];
1086 GAME_TEXT sec_name[128];
1090 WINDOWPLACEMENT lpwndpl;
1093 /* Make section name */
1094 sprintf(sec_name, "Term-%d", i);
1099 strcpy(buf, td->visible ? "1" : "0");
1100 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1105 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "MS ゴシック");
1108 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1110 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1114 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1116 #if 1 /* #ifdef JP */
1117 wsprintf(buf, "%d", td->lf.lfWidth);
1118 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1119 wsprintf(buf, "%d", td->lf.lfHeight);
1120 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1121 wsprintf(buf, "%d", td->lf.lfWeight);
1122 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1125 strcpy(buf, td->bizarre ? "1" : "0");
1126 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1129 wsprintf(buf, "%d", td->tile_wid);
1130 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1133 wsprintf(buf, "%d", td->tile_hgt);
1134 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1136 /* Get window placement and dimensions */
1137 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1138 GetWindowPlacement(td->w, &lpwndpl);
1140 /* Acquire position in *normal* mode (not minimized) */
1141 rc = lpwndpl.rcNormalPosition;
1143 /* Window size (x) */
1144 if (i == 0) wsprintf(buf, "%d", normsize.x);
1145 else wsprintf(buf, "%d", td->cols);
1146 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1148 /* Window size (y) */
1149 if (i == 0) wsprintf(buf, "%d", normsize.y);
1150 else wsprintf(buf, "%d", td->rows);
1151 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1153 /* Maxmized (only main window) */
1156 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1157 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1160 /* Acquire position */
1161 GetWindowRect(td->w, &rc);
1163 /* Window position (x) */
1164 wsprintf(buf, "%d", rc.left);
1165 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1167 /* Window position (y) */
1168 wsprintf(buf, "%d", rc.top);
1169 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1171 /* Window Z position */
1174 strcpy(buf, td->posfix ? "1" : "0");
1175 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1182 * We assume that the windows have all been initialized
1184 static void save_prefs(void)
1190 /* Save the "arg_graphics" flag */
1191 sprintf(buf, "%d", arg_graphics);
1192 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1194 /* Save the "arg_bigtile" flag */
1195 strcpy(buf, arg_bigtile ? "1" : "0");
1196 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1198 /* Save the "arg_sound" flag */
1199 strcpy(buf, arg_sound ? "1" : "0");
1200 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1202 /* Save the "arg_sound" flag */
1203 strcpy(buf, arg_music ? "1" : "0");
1204 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1207 strcpy(buf, use_bg ? "1" : "0");
1208 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1209 WritePrivateProfileString("Angband", "BackGroundBitmap",
1210 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1212 /* Save window prefs */
1213 for (i = 0; i < MAX_TERM_DATA; ++i)
1221 * Load the "prefs" for a single term
1223 static void load_prefs_aux(int i)
1225 term_data *td = &data[i];
1226 GAME_TEXT sec_name[128];
1229 int wid, hgt, posx, posy;
1230 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1231 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1235 /* Make section name */
1236 sprintf(sec_name, "Term-%d", i);
1238 /* Make section name */
1239 sprintf(sec_name, "Term-%d", i);
1244 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1247 /* Desired font, with default */
1249 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1252 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1254 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1260 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1262 /* Analyze font, save desired font name */
1263 #if 1 /* #ifdef JP */
1264 td->font_want = string_make(tmp);
1266 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1267 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1268 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1270 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1275 #if 1 /* #ifdef JP */
1276 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1277 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1279 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1280 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1285 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1286 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1287 normsize.x = td->cols; normsize.y = td->rows;
1292 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
1295 /* Window position */
1296 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1297 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1298 td->pos_x = MIN(MAX(0, posx), dispx-128);
1299 td->pos_y = MIN(MAX(0, posy), dispy-128);
1301 /* Window Z position */
1304 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
1312 static void load_prefs(void)
1316 /* Extract the "arg_graphics" flag */
1317 arg_graphics = (byte_hack)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1319 /* Extract the "arg_bigtile" flag */
1320 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
1321 use_bigtile = arg_bigtile;
1323 /* Extract the "arg_sound" flag */
1324 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1326 /* Extract the "arg_sound" flag */
1327 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1330 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1331 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1333 /* Load window prefs */
1334 for (i = 0; i < MAX_TERM_DATA; ++i)
1340 #if defined(USE_SOUND) || defined(USE_MUSIC)
1343 * - Taken from files.c.
1345 * Extract "tokens" from a buffer
1347 * This function uses "whitespace" as delimiters, and treats any amount of
1348 * whitespace as a single delimiter. We will never return any empty tokens.
1349 * When given an empty buffer, or a buffer containing only "whitespace", we
1350 * will return no tokens. We will never extract more than "num" tokens.
1352 * By running a token through the "text_to_ascii()" function, you can allow
1353 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1355 * We save pointers to the tokens in "tokens", and return the number found.
1357 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1367 /* Skip leading whitespace */
1368 for ( ; *s && iswspace(*s); ++s) /* loop */;
1373 /* Find next whitespace, if any */
1374 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1376 /* Nuke and advance (if necessary) */
1377 if (*t) *t++ = '\0';
1379 /* Save the token */
1390 #endif /* USE_SOUND || USE_MUSIC */
1394 static void load_sound_prefs(void)
1398 char ini_path[1024];
1399 char wav_path[1024];
1400 char *zz[SAMPLE_MAX];
1402 /* Access the sound.cfg */
1404 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1406 for (i = 0; i < SOUND_MAX; i++)
1408 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1410 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1412 for (j = 0; j < num; j++)
1414 /* Access the sound */
1415 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1417 /* Save the sound filename, if it exists */
1418 if (check_file(wav_path))
1419 sound_file[i][j] = string_make(zz[j]);
1424 #endif /* USE_SOUND */
1428 static void load_music_prefs(void)
1432 char ini_path[1024];
1433 char wav_path[1024];
1434 char *zz[SAMPLE_MAX];
1437 /* Access the music.cfg */
1439 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1441 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1443 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1445 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1447 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1449 for (j = 0; j < num; j++)
1451 /* Access the sound */
1452 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1454 /* Save the sound filename, if it exists */
1455 if (check_file(wav_path))
1456 music_file[i][j] = string_make(zz[j]);
1460 for (i = 0; i < max_d_idx; i++)
1462 sprintf(key, "dungeon%03d", i);
1463 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1465 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1467 for (j = 0; j < num; j++)
1469 /* Access the sound */
1470 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1472 /* Save the sound filename, if it exists */
1473 if (check_file(wav_path))
1474 dungeon_music_file[i][j] = string_make(zz[j]);
1478 for (i = 0; i < max_q_idx; i++)
1480 sprintf(key, "quest%03d", i);
1481 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1483 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1485 for (j = 0; j < num; j++)
1487 /* Access the sound */
1488 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1490 /* Save the sound filename, if it exists */
1491 if (check_file(wav_path))
1492 quest_music_file[i][j] = string_make(zz[j]);
1496 for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1498 sprintf(key, "town%03d", i);
1499 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1501 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1503 for (j = 0; j < num; j++)
1505 /* Access the sound */
1506 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1508 /* Save the sound filename, if it exists */
1509 if (check_file(wav_path))
1510 town_music_file[i][j] = string_make(zz[j]);
1517 #endif /* USE_MUSIC */
1520 * Create the new global palette based on the bitmap palette
1521 * (if any), and the standard 16 entry palette derived from
1522 * "win_clr[]" which is used for the basic 16 Angband colors.
1524 * This function is never called before all windows are ready.
1526 * This function returns FALSE if the new palette could not be
1527 * prepared, which should normally be a fatal error. XXX XXX
1529 * Note that only some machines actually use a "palette".
1531 static int new_palette(void)
1539 LPLOGPALETTE pLogPal;
1540 LPPALETTEENTRY lppe;
1545 /* This makes no sense */
1546 if (!paletted) return (TRUE);
1556 /* Check the bitmap palette */
1557 hBmPal = infGraph.hPalette;
1559 /* Use the bitmap */
1562 lppeSize = 256 * sizeof(PALETTEENTRY);
1563 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1564 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1565 if ((nEntries == 0) || (nEntries > 220))
1568 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1571 rnfree(lppe, lppeSize);
1578 #endif /* USE_GRAPHICS */
1580 /* Size of palette */
1581 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1583 /* Allocate palette */
1584 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1587 pLogPal->palVersion = 0x300;
1589 /* Make room for bitmap and normal data */
1590 pLogPal->palNumEntries = nEntries + 16;
1592 /* Save the bitmap data */
1593 for (i = 0; i < nEntries; i++)
1595 pLogPal->palPalEntry[i] = lppe[i];
1598 /* Save the normal data */
1599 for (i = 0; i < 16; i++)
1603 /* Access the entry */
1604 p = &(pLogPal->palPalEntry[i+nEntries]);
1606 /* Save the colors */
1607 p->peRed = GetRValue(win_clr[i]);
1608 p->peGreen = GetGValue(win_clr[i]);
1609 p->peBlue = GetBValue(win_clr[i]);
1611 /* Save the flags */
1612 p->peFlags = PC_NOCOLLAPSE;
1615 /* Free something */
1616 if (lppe) rnfree(lppe, lppeSize);
1618 /* Create a new palette, or fail */
1619 hNewPal = CreatePalette(pLogPal);
1620 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1622 /* Free the palette */
1623 rnfree(pLogPal, pLogPalSize);
1628 /* Realize the palette */
1630 SelectPalette(hdc, hNewPal, 0);
1631 i = RealizePalette(hdc);
1632 ReleaseDC(td->w, hdc);
1633 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1637 for (i = 1; i < MAX_TERM_DATA; i++)
1642 SelectPalette(hdc, hNewPal, 0);
1643 ReleaseDC(td->w, hdc);
1646 /* Delete old palette */
1647 if (hPal) DeleteObject(hPal);
1649 /* Save new palette */
1659 * @brief グラフィクスを初期化する / Initialize graphics
1662 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1663 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1666 static bool init_graphics(void)
1668 /* Initialize once */
1670 BYTE wid, hgt, twid, thgt, ox, oy;
1673 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1683 ANGBAND_GRAF = "new";
1685 else if (arg_graphics == GRAPHICS_HENGBAND)
1705 ANGBAND_GRAF = "ne2";
1716 ANGBAND_GRAF = "old";
1719 /* Access the bitmap file */
1720 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1722 /* Load the bitmap or quit */
1723 if (!ReadDIB(data[0].w, buf, &infGraph))
1725 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1729 /* Save the new sizes */
1730 infGraph.CellWidth = wid;
1731 infGraph.CellHeight = hgt;
1732 infGraph.TileWidth = twid;
1733 infGraph.TileHeight = thgt;
1734 infGraph.OffsetX = ox;
1735 infGraph.OffsetY = oy;
1737 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1739 /* Access the mask file */
1740 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1742 /* Load the bitmap or quit */
1743 if (!ReadDIB(data[0].w, buf, &infMask))
1745 plog_fmt("Cannot read bitmap file '%s'", buf);
1749 if (arg_graphics == GRAPHICS_HENGBAND)
1751 /* Access the mask file */
1752 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1754 /* Load the bitmap or quit */
1755 if (!ReadDIB(data[0].w, buf, &infMask))
1757 plog_fmt("Cannot read bitmap file '%s'", buf);
1762 /* Activate a palette */
1767 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1771 /* Graphics available */
1772 current_graphics_mode = arg_graphics;
1773 return (current_graphics_mode);
1775 #endif /* USE_GRAPHICS */
1782 static bool init_music(void)
1784 /* Initialize once */
1787 /* Load the prefs */
1790 /* Sound available */
1791 can_use_music = TRUE;
1793 return (can_use_music);
1797 * Hack -- Stop a music
1799 static void stop_music(void)
1801 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1802 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1805 #endif /* USE_MUSIC */
1811 static bool init_sound(void)
1813 /* Initialize once */
1816 /* Load the prefs */
1819 /* Sound available */
1820 can_use_sound = TRUE;
1822 return (can_use_sound);
1824 #endif /* USE_SOUND */
1830 static void term_window_resize(term_data *td)
1832 /* Require window */
1835 /* Resize the window */
1836 SetWindowPos(td->w, 0, 0, 0,
1837 td->size_wid, td->size_hgt,
1838 SWP_NOMOVE | SWP_NOZORDER);
1841 InvalidateRect(td->w, NULL, TRUE);
1846 * Force the use of a new "font file" for a term_data
1848 * This function may be called before the "window" is ready
1850 * This function returns zero only if everything succeeds.
1852 * Note that the "font name" must be capitalized!!!
1854 static errr term_force_font(term_data *td, concptr path)
1858 #if 0 /* #ifndef JP */
1864 /* Forget the old font (if needed) */
1865 if (td->font_id) DeleteObject(td->font_id);
1867 #if 1 /* #ifdef JP */
1871 /* Create the font (using the 'base' of the font file name!) */
1872 td->font_id = CreateFontIndirect(&(td->lf));
1873 wid = td->lf.lfWidth;
1874 hgt = td->lf.lfHeight;
1875 if (!td->font_id) return (1);
1877 /* Forget old font */
1883 for (i = 0; i < MAX_TERM_DATA; i++)
1885 /* Don't check when closing the application */
1888 /* Check "screen" */
1889 if ((td != &data[i]) &&
1890 (data[i].font_file) &&
1891 (streq(data[i].font_file, td->font_file)))
1897 /* Remove unused font resources */
1898 if (!used) RemoveFontResource(td->font_file);
1900 /* Free the old name */
1901 string_free(td->font_file);
1904 td->font_file = NULL;
1908 if (!path) return (1);
1913 /* Analyze font path */
1914 base = analyze_font(buf, &wid, &hgt);
1917 if (!suffix(base, ".FON")) return (1);
1920 if (!check_file(buf)) return (1);
1922 /* Load the new font */
1923 if (!AddFontResource(buf)) return (1);
1925 /* Save new font name */
1926 td->font_file = string_make(base);
1928 /* Remove the "suffix" */
1929 base[strlen(base)-4] = '\0';
1931 /* Create the font (using the 'base' of the font file name!) */
1932 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1933 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1934 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1935 FIXED_PITCH | FF_DONTCARE, base);
1938 /* Hack -- Unknown size */
1945 /* all this trouble to get the cell size */
1946 hdcDesktop = GetDC(HWND_DESKTOP);
1947 hfOld = SelectObject(hdcDesktop, td->font_id);
1948 GetTextMetrics(hdcDesktop, &tm);
1949 SelectObject(hdcDesktop, hfOld);
1950 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1952 /* Font size info */
1953 wid = tm.tmAveCharWidth;
1957 /* Save the size info */
1968 * Allow the user to change the font for this window.
1970 static void term_change_font(term_data *td)
1972 #if 1 /* #ifdef JP */
1975 memset(&cf, 0, sizeof(cf));
1976 cf.lStructSize = sizeof(cf);
1977 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1978 cf.lpLogFont = &(td->lf);
1980 if (ChooseFont(&cf))
1982 /* Force the font */
1983 term_force_font(td, NULL);
1985 /* Assume not bizarre */
1988 /* Reset the tile info */
1989 td->tile_wid = td->font_wid;
1990 td->tile_hgt = td->font_hgt;
1992 /* Analyze the font */
1995 /* Resize the window */
1996 term_window_resize(td);
2002 char tmp[1024] = "";
2004 /* Extract a default if possible */
2005 if (td->font_file) strcpy(tmp, td->font_file);
2007 /* Ask for a choice */
2008 memset(&ofn, 0, sizeof(ofn));
2009 ofn.lStructSize = sizeof(ofn);
2010 ofn.hwndOwner = data[0].w;
2011 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
2012 ofn.nFilterIndex = 1;
2013 ofn.lpstrFile = tmp;
2015 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
2016 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2017 ofn.lpstrDefExt = "fon";
2019 /* Force choice if legal */
2020 if (GetOpenFileName(&ofn))
2022 /* Force the font */
2023 if (term_force_font(td, tmp))
2025 /* Access the standard font file */
2026 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2028 /* Force the use of that font */
2029 (void)term_force_font(td, tmp);
2032 /* Assume not bizarre */
2033 td->bizarre = FALSE;
2035 /* Reset the tile info */
2036 td->tile_wid = td->font_wid;
2037 td->tile_hgt = td->font_hgt;
2039 /* Analyze the font */
2042 /* Resize the window */
2043 term_window_resize(td);
2050 * Allow the user to lock this window.
2052 static void term_window_pos(term_data *td, HWND hWnd)
2054 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2055 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2058 static void windows_map(void);
2061 * Hack -- redraw a term_data
2063 static void term_data_redraw(term_data *td)
2067 /* Redraw the map */
2072 /* Activate the term */
2073 Term_activate(&td->t);
2075 /* Redraw the contents */
2078 /* Restore the term */
2079 Term_activate(term_screen);
2084 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2088 HBRUSH myBrush, oldBrush;
2090 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2091 int tx = td->size_ow1 + x * td->tile_wid;
2092 int ty = td->size_oh1 + y * td->tile_hgt;
2093 int tw = w * td->tile_wid - 1;
2094 int th = h * td->tile_hgt - 1;
2097 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2098 oldBrush = SelectObject(hdc, myBrush);
2099 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2101 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2103 SelectObject(hdc, oldBrush);
2104 SelectObject(hdc, oldPen);
2109 /*** Function hooks needed by "Term" ***/
2115 * Initialize a new Term
2117 static void Term_init_win(term *t)
2126 static void Term_nuke_win(term *t)
2135 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
2137 static errr Term_user_win(int n)
2148 * React to global changes
2150 static errr Term_xtra_win_react(void)
2157 /* Save the default colors */
2158 for (i = 0; i < 256; i++)
2160 /* Simply accept the desired colors */
2161 win_pal[i] = angband_color_table[i][0];
2172 bool change = FALSE;
2174 /* Save the default colors */
2175 for (i = 0; i < 256; i++)
2177 /* Extract desired values */
2178 rv = angband_color_table[i][1];
2179 gv = angband_color_table[i][2];
2180 bv = angband_color_table[i][3];
2182 /* Extract a full color code */
2183 code = PALETTERGB(rv, gv, bv);
2185 /* Activate changes */
2186 if (win_clr[i] != code)
2188 /* Note the change */
2191 /* Apply the desired color */
2196 /* Activate the palette if needed */
2197 if (change) (void)new_palette();
2203 /* Handle "arg_sound" */
2204 if (use_sound != arg_sound)
2206 /* Initialize (if needed) */
2207 if (arg_sound && !init_sound())
2210 plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
2216 /* Change setting */
2217 use_sound = arg_sound;
2224 /* Handle "arg_sound" */
2225 if (use_music != arg_music)
2227 /* Initialize (if needed) */
2228 if (arg_music && !init_music())
2231 plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
2236 /* Change setting */
2237 use_music = arg_music;
2239 if(!arg_music) stop_music();
2240 else select_floor_music();
2249 /* Handle "arg_graphics" */
2250 if (use_graphics != arg_graphics)
2252 /* Initialize (if needed) */
2253 if (arg_graphics && !init_graphics())
2256 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
2259 arg_graphics = GRAPHICS_NONE;
2262 /* Change setting */
2263 use_graphics = arg_graphics;
2266 #ifdef ANGBAND_2_8_1
2268 #else /* ANGBAND_2_8_1 */
2269 reset_visuals(TRUE);
2270 #endif /* ANGBAND_2_8_1 */
2273 #endif /* USE_GRAPHICS */
2276 /* Clean up windows */
2277 for (i = 0; i < MAX_TERM_DATA; i++)
2281 term_data *td = &data[i];
2283 /* Update resized windows */
2284 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
2287 Term_activate(&td->t);
2289 /* Hack -- Resize the term */
2290 Term_resize(td->cols, td->rows);
2292 /* Redraw the contents */
2305 * Process at least one event
2307 static errr Term_xtra_win_event(int v)
2311 /* Wait for an event */
2315 if (GetMessage(&msg, NULL, 0, 0))
2317 TranslateMessage(&msg);
2318 DispatchMessage(&msg);
2322 /* Check for an event */
2326 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2328 TranslateMessage(&msg);
2329 DispatchMessage(&msg);
2339 * Process all pending events
2341 static errr Term_xtra_win_flush(void)
2345 /* Process all pending events */
2346 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2348 TranslateMessage(&msg);
2349 DispatchMessage(&msg);
2358 * Hack -- clear the screen
2360 * Make this more efficient
2362 static errr Term_xtra_win_clear(void)
2364 term_data *td = (term_data*)(Term->data);
2369 /* Rectangle to erase */
2370 rc.left = td->size_ow1;
2371 rc.right = rc.left + td->cols * td->tile_wid;
2372 rc.top = td->size_oh1;
2373 rc.bottom = rc.top + td->rows * td->tile_hgt;
2377 SetBkColor(hdc, RGB(0, 0, 0));
2378 SelectObject(hdc, td->font_id);
2379 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2384 rc.left = 0; rc.top = 0;
2387 ReleaseDC(td->w, hdc);
2395 * Hack -- make a noise
2397 static errr Term_xtra_win_noise(void)
2399 MessageBeep(MB_ICONASTERISK);
2405 * Hack -- make a sound
2407 static errr Term_xtra_win_sound(int v)
2412 #endif /* USE_SOUND */
2414 /* Sound disabled */
2415 if (!use_sound) return (1);
2418 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2422 /* Count the samples */
2423 for (i = 0; i < SAMPLE_MAX; i++)
2425 if (!sound_file[v][i])
2430 if (i == 0) return (1);
2432 /* Build the path */
2433 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2437 /* Play the sound, catch errors */
2438 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2442 /* Play the sound, catch errors */
2443 return (sndPlaySound(buf, SND_ASYNC));
2447 #else /* USE_SOUND */
2451 #endif /* USE_SOUND */
2455 * Hack -- play a music
2457 static errr Term_xtra_win_music(int n, int v)
2462 #endif /* USE_MUSIC */
2464 /* Sound disabled */
2466 if(!use_music) return (1);
2469 if(n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return (1);
2470 else if(v < 0 || v >= 1000) return(1); /*!< TODO */
2476 case TERM_XTRA_MUSIC_BASIC:
2477 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2479 case TERM_XTRA_MUSIC_DUNGEON:
2480 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2482 case TERM_XTRA_MUSIC_QUEST:
2483 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2485 case TERM_XTRA_MUSIC_TOWN:
2486 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2493 //mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2494 //mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2500 case TERM_XTRA_MUSIC_BASIC:
2501 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2503 case TERM_XTRA_MUSIC_DUNGEON:
2504 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2506 case TERM_XTRA_MUSIC_QUEST:
2507 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2509 case TERM_XTRA_MUSIC_TOWN:
2510 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2517 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2518 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2524 case TERM_XTRA_MUSIC_BASIC:
2525 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2527 case TERM_XTRA_MUSIC_DUNGEON:
2528 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2530 case TERM_XTRA_MUSIC_QUEST:
2531 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2533 case TERM_XTRA_MUSIC_TOWN:
2534 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2538 if(current_music_type == n && current_music_id == v)
2542 current_music_type = n;
2543 current_music_id = v;
2547 mop.lpstrDeviceType = mci_device_type;
2548 mop.lpstrElementName = buf;
2549 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2550 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2551 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2552 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2553 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2558 #else /* USE_MUSIC */
2562 #endif /* USE_MUSIC */
2568 * Delay for "x" milliseconds
2570 static int Term_xtra_win_delay(int v)
2584 t = GetTickCount() + v;
2587 while (GetTickCount() < t)
2589 /* Handle messages */
2590 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2592 TranslateMessage(&msg);
2593 DispatchMessage(&msg);
2605 * Do a "special thing"
2607 static errr Term_xtra_win(int n, int v)
2609 /* Handle a subset of the legal requests */
2612 /* Make a bell sound */
2613 case TERM_XTRA_NOISE:
2615 return (Term_xtra_win_noise());
2619 case TERM_XTRA_MUSIC_BASIC:
2620 case TERM_XTRA_MUSIC_DUNGEON:
2621 case TERM_XTRA_MUSIC_QUEST:
2622 case TERM_XTRA_MUSIC_TOWN:
2624 return (Term_xtra_win_music(n, v));
2627 /* Make a special sound */
2628 case TERM_XTRA_SOUND:
2630 return (Term_xtra_win_sound(v));
2633 /* Process random events */
2634 case TERM_XTRA_BORED:
2636 return (Term_xtra_win_event(0));
2639 /* Process an event */
2640 case TERM_XTRA_EVENT:
2642 return (Term_xtra_win_event(v));
2645 /* Flush all events */
2646 case TERM_XTRA_FLUSH:
2648 return (Term_xtra_win_flush());
2651 /* Clear the screen */
2652 case TERM_XTRA_CLEAR:
2654 return (Term_xtra_win_clear());
2657 /* React to global changes */
2658 case TERM_XTRA_REACT:
2660 return (Term_xtra_win_react());
2663 /* Delay for some milliseconds */
2664 case TERM_XTRA_DELAY:
2666 return (Term_xtra_win_delay(v));
2676 * Low level graphics (Assumes valid input).
2678 * Draw a "cursor" at (x,y), using a "yellow box".
2680 static errr Term_curs_win(int x, int y)
2682 term_data *td = (term_data*)(Term->data);
2687 int tile_wid, tile_hgt;
2691 tile_wid = td->map_tile_wid;
2692 tile_hgt = td->map_tile_hgt;
2696 tile_wid = td->tile_wid;
2697 tile_hgt = td->tile_hgt;
2700 /* Frame the grid */
2701 rc.left = x * tile_wid + td->size_ow1;
2702 rc.right = rc.left + tile_wid;
2703 rc.top = y * tile_hgt + td->size_oh1;
2704 rc.bottom = rc.top + tile_hgt;
2706 /* Cursor is done as a yellow "box" */
2708 FrameRect(hdc, &rc, hbrYellow);
2709 ReleaseDC(td->w, hdc);
2717 * Low level graphics (Assumes valid input).
2719 * Draw a "big cursor" at (x,y), using a "yellow box".
2721 static errr Term_bigcurs_win(int x, int y)
2723 term_data *td = (term_data*)(Term->data);
2728 int tile_wid, tile_hgt;
2732 /* Normal cursor in map window */
2733 Term_curs_win(x, y);
2738 tile_wid = td->tile_wid;
2739 tile_hgt = td->tile_hgt;
2742 /* Frame the grid */
2743 rc.left = x * tile_wid + td->size_ow1;
2744 rc.right = rc.left + 2 * tile_wid;
2745 rc.top = y * tile_hgt + td->size_oh1;
2746 rc.bottom = rc.top + tile_hgt;
2748 /* Cursor is done as a yellow "box" */
2750 FrameRect(hdc, &rc, hbrYellow);
2751 ReleaseDC(td->w, hdc);
2759 * Low level graphics (Assumes valid input).
2761 * Erase a "block" of "n" characters starting at (x,y).
2763 static errr Term_wipe_win(int x, int y, int n)
2765 term_data *td = (term_data*)(Term->data);
2770 /* Rectangle to erase in client coords */
2771 rc.left = x * td->tile_wid + td->size_ow1;
2772 rc.right = rc.left + n * td->tile_wid;
2773 rc.top = y * td->tile_hgt + td->size_oh1;
2774 rc.bottom = rc.top + td->tile_hgt;
2777 SetBkColor(hdc, RGB(0, 0, 0));
2778 SelectObject(hdc, td->font_id);
2783 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2784 ReleaseDC(td->w, hdc);
2792 * Low level graphics. Assumes valid input.
2794 * Draw several ("n") chars, with an attr, at a given location.
2796 * All "graphic" data is handled by "Term_pict_win()", below.
2798 * One would think there is a more efficient method for telling a window
2799 * what color it should be using to draw with, but perhaps simply changing
2800 * it every time is not too inefficient.
2802 static errr Term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
2804 term_data *td = (term_data*)(Term->data);
2808 #if 1 /* #ifdef JP */
2809 static HBITMAP WALL;
2810 static HBRUSH myBrush, oldBrush;
2812 static bool init_done = FALSE;
2815 WALL = LoadBitmap(hInstance, AppName);
2816 myBrush = CreatePatternBrush(WALL);
2821 /* Total rectangle */
2822 rc.left = x * td->tile_wid + td->size_ow1;
2823 rc.right = rc.left + n * td->tile_wid;
2824 rc.top = y * td->tile_hgt + td->size_oh1;
2825 rc.bottom = rc.top + td->tile_hgt;
2830 /* Background color */
2831 SetBkColor(hdc, RGB(0, 0, 0));
2833 /* Foreground color */
2836 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2840 SetTextColor(hdc, win_clr[a&0x0F]);
2844 SetTextColor(hdc, win_clr[a]);
2848 SelectObject(hdc, td->font_id);
2851 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2855 (td->tile_hgt != td->font_hgt) ||
2856 (td->tile_wid != td->font_wid))
2860 /* Erase complete rectangle */
2861 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2864 if (use_bg) DrawBG(hdc, &rc);
2867 rc.left += ((td->tile_wid - td->font_wid) / 2);
2868 rc.right = rc.left + td->font_wid;
2869 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2870 rc.bottom = rc.top + td->font_hgt;
2872 /* Dump each character */
2873 for (i = 0; i < n; i++)
2876 if (use_bigtile && *(s+i)=="■"[0] && *(s+i+1)=="■"[1])
2878 rc.right += td->font_wid;
2880 oldBrush = SelectObject(hdc, myBrush);
2881 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2884 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2886 SelectObject(hdc, oldBrush);
2887 SelectObject(hdc, oldPen);
2888 rc.right -= td->font_wid;
2892 rc.left += 2 * td->tile_wid;
2893 rc.right += 2 * td->tile_wid;
2895 else if ( iskanji(*(s+i)) ) /* 2バイト文字 */
2897 rc.right += td->font_wid;
2899 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2901 rc.right -= td->font_wid;
2905 rc.left += 2 * td->tile_wid;
2906 rc.right += 2 * td->tile_wid;
2907 } else if (*(s+i)==127){
2908 oldBrush = SelectObject(hdc, myBrush);
2909 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2912 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2914 SelectObject(hdc, oldBrush);
2915 SelectObject(hdc, oldPen);
2918 rc.left += td->tile_wid;
2919 rc.right += td->tile_wid;
2922 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2925 rc.left += td->tile_wid;
2926 rc.right += td->tile_wid;
2931 oldBrush = SelectObject(hdc, myBrush);
2932 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2935 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2937 SelectObject(hdc, oldBrush);
2938 SelectObject(hdc, oldPen);
2941 rc.left += td->tile_wid;
2942 rc.right += td->tile_wid;
2945 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2949 rc.left += td->tile_wid;
2950 rc.right += td->tile_wid;
2954 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2958 rc.left += td->tile_wid;
2959 rc.right += td->tile_wid;
2970 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2975 ReleaseDC(td->w, hdc);
2983 * Low level graphics. Assumes valid input.
2985 * Draw an array of "special" attr/char pairs at the given location.
2987 * We use the "Term_pict_win()" function for "graphic" data, which are
2988 * encoded by setting the "high-bits" of both the "attr" and the "char"
2989 * data. We use the "attr" to represent the "row" of the main bitmap,
2990 * and the "char" to represent the "col" of the main bitmap. The use
2991 * of this function is induced by the "higher_pict" flag.
2993 * If "graphics" is not available, we simply "wipe" the given grids.
2995 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)
2997 term_data *td = (term_data*)(Term->data);
3002 TERM_LEN x1, y1, w1, h1, tw1, th1;
3003 TERM_LEN x2, y2, w2, h2, tw2 = 0;
3013 /* Erase the grids */
3014 return (Term_wipe_win(x, y, n));
3017 /* Size of bitmap cell */
3018 w1 = infGraph.CellWidth;
3019 h1 = infGraph.CellHeight;
3020 tw1 = infGraph.TileWidth;
3021 th1 = infGraph.TileHeight;
3023 /* Size of window cell */
3026 w2 = td->map_tile_wid;
3027 h2 = td->map_tile_hgt;
3036 if (use_bigtile) tw2 *= 2;
3039 /* Location of window cell */
3040 x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
3041 y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
3047 hdcSrc = CreateCompatibleDC(hdc);
3048 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
3050 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3052 hdcMask = CreateCompatibleDC(hdc);
3053 SelectObject(hdcMask, infMask.hBitmap);
3056 /* Draw attr/char pairs */
3057 for (i = 0; i < n; i++, x2 += w2)
3059 TERM_COLOR a = ap[i];
3063 /* Extract picture */
3064 int row = (a & 0x7F);
3065 int col = (c & 0x7F);
3067 /* Location of bitmap cell */
3071 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3073 x3 = (tcp[i] & 0x7F) * w1;
3074 y3 = (tap[i] & 0x7F) * h1;
3075 tw2 = tw2 * w1 / tw1;
3079 if ((tw1 == tw2) && (th1 == h2))
3081 /* Copy the terrain picture from the bitmap to the window */
3082 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
3084 /* Mask out the tile */
3085 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3088 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3091 /* Need to stretch */
3094 /* Set the correct mode for stretching the tiles */
3095 SetStretchBltMode(hdc, COLORONCOLOR);
3097 /* Copy the terrain picture from the bitmap to the window */
3098 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
3100 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
3102 /* Only draw if terrain and overlay are different */
3103 if ((x1 != x3) || (y1 != y3))
3105 /* Mask out the tile */
3106 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3109 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3116 if ((w1 == tw2) && (h1 == h2))
3118 /* Copy the picture from the bitmap to the window */
3119 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3122 /* Need to stretch */
3125 /* Set the correct mode for stretching the tiles */
3126 SetStretchBltMode(hdc, COLORONCOLOR);
3128 /* Copy the picture from the bitmap to the window */
3129 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3135 SelectObject(hdcSrc, hbmSrcOld);
3138 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3141 SelectObject(hdcMask, hbmSrcOld);
3146 ReleaseDC(td->w, hdc);
3148 #else /* USE_GRAPHICS */
3150 /* Just erase this grid */
3151 return (Term_wipe_win(x, y, n));
3153 #endif /* USE_GRAPHICS */
3160 static void windows_map(void)
3162 term_data *td = &data[0];
3165 TERM_LEN x, min_x, max_x;
3166 TERM_LEN y, min_y, max_y;
3171 /* Only in graphics mode */
3172 if (!use_graphics) return;
3173 Term_xtra_win_clear();
3175 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3176 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3177 td->map_active = TRUE;
3182 max_x = current_floor_ptr->width;
3183 max_y = current_floor_ptr->height;
3187 for (x = min_x; x < max_x; x++)
3189 for (y = min_y; y < max_y; y++)
3191 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3193 /* Ignore non-graphics */
3194 if ((a & 0x80) && (c & 0x80))
3196 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3201 /* Hilite the player */
3202 Term_curs_win(p_ptr->x - min_x, p_ptr->y - min_y);
3204 /* Wait for a keypress, flush key buffer */
3205 Term_inkey(&c, TRUE, TRUE);
3208 /* Switch off the map display */
3209 td->map_active = FALSE;
3211 /* Restore screen */
3212 Term_xtra_win_clear();
3217 /*** Other routines ***/
3221 * Create and initialize a "term_data" given a title
3223 static void term_data_link(term_data *td)
3227 /* Initialize the term */
3228 term_init(t, td->cols, td->rows, td->keys);
3230 /* Use a "software" cursor */
3231 t->soft_cursor = TRUE;
3233 /* Use "Term_pict" for "graphic" data */
3234 t->higher_pict = TRUE;
3236 /* Erase with "white space" */
3237 t->attr_blank = TERM_WHITE;
3238 t->char_blank = ' ';
3241 /* Prepare the init/nuke hooks */
3242 t->init_hook = Term_init_win;
3243 t->nuke_hook = Term_nuke_win;
3246 /* Prepare the template hooks */
3247 t->user_hook = Term_user_win;
3248 t->xtra_hook = Term_xtra_win;
3249 t->curs_hook = Term_curs_win;
3250 t->bigcurs_hook = Term_bigcurs_win;
3251 t->wipe_hook = Term_wipe_win;
3252 t->text_hook = Term_text_win;
3253 t->pict_hook = Term_pict_win;
3255 /* Remember where we came from */
3256 t->data = (vptr)(td);
3261 * Create the windows
3263 * First, instantiate the "default" values, then read the "ini_file"
3264 * to over-ride selected values, then create the windows, and fonts.
3266 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3267 * must make active to realize the palette.
3269 static void init_windows(void)
3275 #if 0 /* #ifndef JP */
3281 WIPE(td, term_data);
3285 td->s = angband_term_name[0];
3299 #if 1 /* #ifdef JP */
3303 for (i = 1; i < MAX_TERM_DATA; i++)
3306 WIPE(td, term_data);
3307 td->s = angband_term_name[i];
3311 td->visible = FALSE;
3316 td->pos_x = (7 - i) * 30;
3317 td->pos_y = (7 - i) * 20;
3319 #if 1 /* #ifdef JP */
3329 /* Main window (need these before term_getsize gets called) */
3331 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3332 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3337 /* Sub windows (need these before term_getsize gets called) */
3338 for (i = 1; i < MAX_TERM_DATA; i++)
3341 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3342 td->dwExStyle = (WS_EX_TOOLWINDOW);
3347 for (i = 0; i < MAX_TERM_DATA; i++)
3351 #if 1 /* #ifdef JP */
3352 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3353 td->lf.lfCharSet = DEFAULT_CHARSET;
3354 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3355 /* Activate the chosen font */
3356 term_force_font(td, NULL);
3357 if(!td->tile_wid) td->tile_wid = td->font_wid;
3358 if(!td->tile_hgt) td->tile_hgt = td->font_hgt;
3360 /* Access the standard font file */
3361 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3363 /* Activate the chosen font */
3364 if (term_force_font(td, buf))
3366 /* Access the standard font file */
3367 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3369 /* Force the use of that font */
3370 (void)term_force_font(td, buf);
3375 /* Assume not bizarre */
3376 td->bizarre = FALSE;
3381 /* Analyze the font */
3384 /* Resize the window */
3385 term_window_resize(td);
3389 /* Sub windows (reverse order) */
3390 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3395 td->w = CreateWindowEx(td->dwExStyle, AngList,
3397 td->pos_x, td->pos_y,
3398 td->size_wid, td->size_hgt,
3399 HWND_DESKTOP, NULL, hInstance, NULL);
3401 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3405 td->size_hack = TRUE;
3406 ShowWindow(td->w, SW_SHOW);
3407 td->size_hack = FALSE;
3411 angband_term[i] = &td->t;
3415 /* Activate the window */
3416 SetActiveWindow(td->w);
3421 term_window_pos(&data[i], HWND_TOPMOST);
3425 term_window_pos(&data[i], td->w);
3435 td->w = CreateWindowEx(td->dwExStyle, AppName,
3437 td->pos_x, td->pos_y,
3438 td->size_wid, td->size_hgt,
3439 HWND_DESKTOP, NULL, hInstance, NULL);
3441 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3444 angband_term[0] = &td->t;
3445 normsize.x = td->cols;
3446 normsize.y = td->rows;
3448 /* Activate the main window */
3449 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3450 else ShowWindow(td->w, SW_SHOW);
3452 /* Bring main window back to top */
3453 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3457 (void)new_palette();
3460 /* Create a "brush" for drawing the "cursor" */
3461 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3464 /* Process pending messages */
3465 (void)Term_xtra_win_flush();
3473 static void setup_menus(void)
3477 HMENU hm = GetMenu(data[0].w);
3480 /* Menu "File", Disable all */
3481 EnableMenuItem(hm, IDM_FILE_NEW,
3482 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3483 EnableMenuItem(hm, IDM_FILE_OPEN,
3484 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3485 EnableMenuItem(hm, IDM_FILE_SAVE,
3486 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3487 EnableMenuItem(hm, IDM_FILE_EXIT,
3488 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3489 EnableMenuItem(hm, IDM_FILE_SCORE,
3490 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3493 /* No character available */
3494 if (!character_generated)
3496 /* Menu "File", Item "New" */
3497 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3499 /* Menu "File", Item "Open" */
3500 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3503 /* A character available */
3504 if (character_generated)
3506 /* Menu "File", Item "Save" */
3507 EnableMenuItem(hm, IDM_FILE_SAVE,
3508 MF_BYCOMMAND | MF_ENABLED);
3511 /* Menu "File", Item "Exit" */
3512 EnableMenuItem(hm, IDM_FILE_EXIT,
3513 MF_BYCOMMAND | MF_ENABLED);
3515 EnableMenuItem(hm, IDM_FILE_SCORE,
3516 MF_BYCOMMAND | MF_ENABLED);
3519 /* Menu "Window::Visibility" */
3520 for (i = 0; i < MAX_TERM_DATA; i++)
3522 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3523 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3525 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3526 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3528 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3529 MF_BYCOMMAND | MF_ENABLED);
3532 /* Menu "Window::Font" */
3533 for (i = 0; i < MAX_TERM_DATA; i++)
3535 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3536 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3538 if (data[i].visible)
3540 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3541 MF_BYCOMMAND | MF_ENABLED);
3545 /* Menu "Window::Window Position Fix" */
3546 for (i = 0; i < MAX_TERM_DATA; i++)
3548 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3549 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3551 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3552 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3554 if (data[i].visible)
3556 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3557 MF_BYCOMMAND | MF_ENABLED);
3561 /* Menu "Window::Bizarre Display" */
3562 for (i = 0; i < MAX_TERM_DATA; i++)
3564 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3565 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3567 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3568 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3570 if (data[i].visible)
3572 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3573 MF_BYCOMMAND | MF_ENABLED);
3578 /* Menu "Window::Increase Tile Width" */
3579 for (i = 0; i < MAX_TERM_DATA; i++)
3581 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3582 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3584 if (data[i].visible)
3586 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3587 MF_BYCOMMAND | MF_ENABLED);
3592 /* Menu "Window::Decrease Tile Width" */
3593 for (i = 0; i < MAX_TERM_DATA; i++)
3595 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3596 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3598 if (data[i].visible)
3600 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3601 MF_BYCOMMAND | MF_ENABLED);
3606 /* Menu "Window::Increase Tile Height" */
3607 for (i = 0; i < MAX_TERM_DATA; i++)
3609 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3610 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3612 if (data[i].visible)
3614 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3615 MF_BYCOMMAND | MF_ENABLED);
3620 /* Menu "Window::Decrease Tile Height" */
3621 for (i = 0; i < MAX_TERM_DATA; i++)
3623 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3624 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3626 if (data[i].visible)
3628 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3629 MF_BYCOMMAND | MF_ENABLED);
3634 /* Menu "Options", disable all */
3635 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3636 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3637 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3638 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3639 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3640 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3641 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3642 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3643 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3644 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3646 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3647 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3650 /* Menu "Options", Item "Map" */
3651 if (use_graphics != GRAPHICS_NONE)
3652 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3654 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3655 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3657 /* Menu "Options", update all */
3658 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3659 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3660 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3661 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3662 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3663 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3664 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3665 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3666 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3667 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3668 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3669 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3670 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3671 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3672 CheckMenuItem(hm, IDM_OPTIONS_BG,
3673 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3675 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3676 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3680 /* Menu "Options", Item "Graphics" */
3681 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3682 /* Menu "Options", Item "Graphics" */
3683 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3684 /* Menu "Options", Item "Graphics" */
3685 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3686 /* Menu "Options", Item "Graphics" */
3687 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3688 #endif /* USE_GRAPHICS */
3691 /* Menu "Options", Item "Sound" */
3692 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3693 #endif /* USE_SOUND */
3696 /* Menu "Options", Item "ScreenSaver" */
3697 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3698 MF_BYCOMMAND | MF_ENABLED);
3699 #endif /* USE_SAVER */
3704 * Check for double clicked (or dragged) savefile
3706 * Apparently, Windows copies the entire filename into the first
3707 * piece of the "command line string". Perhaps we should extract
3708 * the "basename" of that filename and append it to the "save" dir.
3710 static void check_for_save_file(LPSTR cmd_line)
3720 /* Extract filename */
3721 strcat(savefile, s);
3723 /* Validate the file */
3724 validate_file(savefile);
3726 /* Game in progress */
3727 game_in_progress = TRUE;
3735 * Process a menu command
3737 static void process_menus(WORD wCmd)
3753 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3755 else if (game_in_progress)
3757 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3761 game_in_progress = TRUE;
3774 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3776 else if (game_in_progress)
3778 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3782 memset(&ofn, 0, sizeof(ofn));
3783 ofn.lStructSize = sizeof(ofn);
3784 ofn.hwndOwner = data[0].w;
3785 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3786 ofn.nFilterIndex = 1;
3787 ofn.lpstrFile = savefile;
3788 ofn.nMaxFile = 1024;
3789 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3790 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3792 if (GetOpenFileName(&ofn))
3794 /* Load 'savefile' */
3795 validate_file(savefile);
3796 game_in_progress = TRUE;
3808 if (game_in_progress && character_generated)
3812 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3816 /* Hack -- Forget messages */
3821 do_cmd_save_game(FALSE);
3822 #else /* ZANGBAND */
3824 #endif /* ZANGBAND */
3828 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3836 if (game_in_progress && character_generated)
3840 plog(_("今は終了できません。", "You may not do that right now."));
3844 /* Hack -- Forget messages */
3853 /* do_cmd_save_game(FALSE); */
3854 #else /* ZANGBAND */
3855 /* do_cmd_save_game(); */
3856 #endif /* ZANGBAND */
3857 Term_key_push(SPECIAL_KEY_QUIT);
3865 case IDM_FILE_SCORE:
3869 /* Build the filename */
3870 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3872 /* Open the binary high score file, for reading */
3873 highscore_fd = fd_open(buf, O_RDONLY);
3875 /* Paranoia -- No score file */
3876 if (highscore_fd < 0)
3878 msg_print("Score file unavailable.");
3885 /* Display the scores */
3886 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3888 /* Shut the high score file */
3889 (void)fd_close(highscore_fd);
3891 /* Forget the high score fd */
3895 /* Hack - Flush it */
3903 case IDM_FILE_MOVIE:
3907 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3909 else if (game_in_progress)
3911 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
3915 memset(&ofn, 0, sizeof(ofn));
3916 ofn.lStructSize = sizeof(ofn);
3917 ofn.hwndOwner = data[0].w;
3918 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3919 ofn.nFilterIndex = 1;
3920 ofn.lpstrFile = savefile;
3921 ofn.nMaxFile = 1024;
3922 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3923 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3925 if (GetOpenFileName(&ofn))
3927 /* Load 'savefile' */
3928 prepare_browse_movie_aux(savefile);
3938 case IDM_WINDOW_VIS_0:
3940 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
3944 /* Window visibility */
3945 case IDM_WINDOW_VIS_1:
3946 case IDM_WINDOW_VIS_2:
3947 case IDM_WINDOW_VIS_3:
3948 case IDM_WINDOW_VIS_4:
3949 case IDM_WINDOW_VIS_5:
3950 case IDM_WINDOW_VIS_6:
3951 case IDM_WINDOW_VIS_7:
3953 i = wCmd - IDM_WINDOW_VIS_0;
3955 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3962 ShowWindow(td->w, SW_SHOW);
3963 term_data_redraw(td);
3967 td->visible = FALSE;
3969 ShowWindow(td->w, SW_HIDE);
3976 case IDM_WINDOW_FONT_0:
3977 case IDM_WINDOW_FONT_1:
3978 case IDM_WINDOW_FONT_2:
3979 case IDM_WINDOW_FONT_3:
3980 case IDM_WINDOW_FONT_4:
3981 case IDM_WINDOW_FONT_5:
3982 case IDM_WINDOW_FONT_6:
3983 case IDM_WINDOW_FONT_7:
3985 i = wCmd - IDM_WINDOW_FONT_0;
3987 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3991 term_change_font(td);
3996 /* Window Z Position */
3997 case IDM_WINDOW_POS_1:
3998 case IDM_WINDOW_POS_2:
3999 case IDM_WINDOW_POS_3:
4000 case IDM_WINDOW_POS_4:
4001 case IDM_WINDOW_POS_5:
4002 case IDM_WINDOW_POS_6:
4003 case IDM_WINDOW_POS_7:
4005 i = wCmd - IDM_WINDOW_POS_0;
4007 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4011 if (!td->posfix && td->visible)
4014 term_window_pos(td, HWND_TOPMOST);
4019 term_window_pos(td, data[0].w);
4025 /* Bizarre Display */
4026 case IDM_WINDOW_BIZ_0:
4027 case IDM_WINDOW_BIZ_1:
4028 case IDM_WINDOW_BIZ_2:
4029 case IDM_WINDOW_BIZ_3:
4030 case IDM_WINDOW_BIZ_4:
4031 case IDM_WINDOW_BIZ_5:
4032 case IDM_WINDOW_BIZ_6:
4033 case IDM_WINDOW_BIZ_7:
4035 i = wCmd - IDM_WINDOW_BIZ_0;
4037 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4041 td->bizarre = !td->bizarre;
4045 term_window_resize(td);
4050 /* Increase Tile Width */
4051 case IDM_WINDOW_I_WID_0:
4052 case IDM_WINDOW_I_WID_1:
4053 case IDM_WINDOW_I_WID_2:
4054 case IDM_WINDOW_I_WID_3:
4055 case IDM_WINDOW_I_WID_4:
4056 case IDM_WINDOW_I_WID_5:
4057 case IDM_WINDOW_I_WID_6:
4058 case IDM_WINDOW_I_WID_7:
4060 i = wCmd - IDM_WINDOW_I_WID_0;
4062 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4070 term_window_resize(td);
4075 /* Decrease Tile Height */
4076 case IDM_WINDOW_D_WID_0:
4077 case IDM_WINDOW_D_WID_1:
4078 case IDM_WINDOW_D_WID_2:
4079 case IDM_WINDOW_D_WID_3:
4080 case IDM_WINDOW_D_WID_4:
4081 case IDM_WINDOW_D_WID_5:
4082 case IDM_WINDOW_D_WID_6:
4083 case IDM_WINDOW_D_WID_7:
4085 i = wCmd - IDM_WINDOW_D_WID_0;
4087 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4095 term_window_resize(td);
4100 /* Increase Tile Height */
4101 case IDM_WINDOW_I_HGT_0:
4102 case IDM_WINDOW_I_HGT_1:
4103 case IDM_WINDOW_I_HGT_2:
4104 case IDM_WINDOW_I_HGT_3:
4105 case IDM_WINDOW_I_HGT_4:
4106 case IDM_WINDOW_I_HGT_5:
4107 case IDM_WINDOW_I_HGT_6:
4108 case IDM_WINDOW_I_HGT_7:
4110 i = wCmd - IDM_WINDOW_I_HGT_0;
4112 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4120 term_window_resize(td);
4125 /* Decrease Tile Height */
4126 case IDM_WINDOW_D_HGT_0:
4127 case IDM_WINDOW_D_HGT_1:
4128 case IDM_WINDOW_D_HGT_2:
4129 case IDM_WINDOW_D_HGT_3:
4130 case IDM_WINDOW_D_HGT_4:
4131 case IDM_WINDOW_D_HGT_5:
4132 case IDM_WINDOW_D_HGT_6:
4133 case IDM_WINDOW_D_HGT_7:
4135 i = wCmd - IDM_WINDOW_D_HGT_0;
4137 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4145 term_window_resize(td);
4150 case IDM_OPTIONS_NO_GRAPHICS:
4154 plog("You may not do that right now.");
4158 /* Toggle "arg_graphics" */
4159 if (arg_graphics != GRAPHICS_NONE)
4161 arg_graphics = GRAPHICS_NONE;
4163 /* React to changes */
4164 Term_xtra_win_react();
4166 /* Hack -- Force redraw */
4167 Term_key_push(KTRL('R'));
4173 case IDM_OPTIONS_OLD_GRAPHICS:
4177 plog("You may not do that right now.");
4181 /* Toggle "arg_graphics" */
4182 if (arg_graphics != GRAPHICS_ORIGINAL)
4184 arg_graphics = GRAPHICS_ORIGINAL;
4186 /* React to changes */
4187 Term_xtra_win_react();
4189 /* Hack -- Force redraw */
4190 Term_key_push(KTRL('R'));
4196 case IDM_OPTIONS_NEW_GRAPHICS:
4200 plog("You may not do that right now.");
4204 /* Toggle "arg_graphics" */
4205 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4207 arg_graphics = GRAPHICS_ADAM_BOLT;
4209 /* React to changes */
4210 Term_xtra_win_react();
4212 /* Hack -- Force redraw */
4213 Term_key_push(KTRL('R'));
4219 case IDM_OPTIONS_NEW2_GRAPHICS:
4223 plog("You may not do that right now.");
4227 /* Toggle "arg_graphics" */
4228 if (arg_graphics != GRAPHICS_HENGBAND)
4230 arg_graphics = GRAPHICS_HENGBAND;
4232 /* React to changes */
4233 Term_xtra_win_react();
4235 /* Hack -- Force redraw */
4236 Term_key_push(KTRL('R'));
4242 case IDM_OPTIONS_BIGTILE:
4247 plog("You may not do that right now.");
4251 /* Toggle "arg_sound" */
4252 arg_bigtile = !arg_bigtile;
4255 Term_activate(&td->t);
4257 /* Resize the term */
4258 Term_resize(td->cols, td->rows);
4261 InvalidateRect(td->w, NULL, TRUE);
4266 case IDM_OPTIONS_MUSIC:
4270 plog("You may not do that right now.");
4274 /* Toggle "arg_sound" */
4275 arg_music = !arg_music;
4277 /* React to changes */
4278 Term_xtra_win_react();
4280 /* Hack -- Force redraw */
4281 Term_key_push(KTRL('R'));
4286 case IDM_OPTIONS_SOUND:
4290 plog("You may not do that right now.");
4294 /* Toggle "arg_sound" */
4295 arg_sound = !arg_sound;
4297 /* React to changes */
4298 Term_xtra_win_react();
4300 /* Hack -- Force redraw */
4301 Term_key_push(KTRL('R'));
4307 case IDM_OPTIONS_BG:
4311 plog("You may not do that right now.");
4315 /* Toggle "use_bg" */
4320 /* React to changes */
4321 Term_xtra_win_react();
4323 /* Hack -- Force redraw */
4324 Term_key_push(KTRL('R'));
4330 case IDM_OPTIONS_OPEN_BG:
4334 plog("You may not do that right now.");
4339 memset(&ofn, 0, sizeof(ofn));
4340 ofn.lStructSize = sizeof(ofn);
4341 ofn.hwndOwner = data[0].w;
4342 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4343 ofn.nFilterIndex = 1;
4344 ofn.lpstrFile = bg_bitmap_file;
4345 ofn.nMaxFile = 1023;
4346 ofn.lpstrInitialDir = NULL;
4347 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
4348 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4350 if (GetOpenFileName(&ofn))
4352 /* Load 'savefile' */
4357 /* React to changes */
4358 Term_xtra_win_react();
4360 /* Hack -- Force redraw */
4361 Term_key_push(KTRL('R'));
4366 case IDM_DUMP_SCREEN_HTML:
4368 static char buf[1024] = "";
4369 memset(&ofn, 0, sizeof(ofn));
4370 ofn.lStructSize = sizeof(ofn);
4371 ofn.hwndOwner = data[0].w;
4372 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4373 ofn.nFilterIndex = 1;
4374 ofn.lpstrFile = buf;
4375 ofn.nMaxFile = 1023;
4376 ofn.lpstrDefExt = "html";
4377 ofn.lpstrInitialDir = NULL;
4378 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
4379 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4381 if (GetSaveFileName(&ofn))
4383 do_cmd_save_screen_html_aux(buf, 0);
4390 case IDM_OPTIONS_SAVER:
4394 DestroyWindow(hwndSaver);
4399 /* Create a screen scaver window */
4400 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4401 "Angband Screensaver",
4402 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4403 0, 0, GetSystemMetrics(SM_CXSCREEN),
4404 GetSystemMetrics(SM_CYSCREEN),
4405 NULL, NULL, hInstance, NULL);
4409 /* Push the window to the bottom */
4410 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4414 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
4422 case IDM_OPTIONS_MAP:
4428 case IDM_HELP_CONTENTS:
4432 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4433 if (check_file(tmp))
4435 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4439 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4440 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4443 #else /* HTML_HELP */
4446 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4447 if (check_file(tmp))
4449 sprintf(buf, "winhelp.exe %s", tmp);
4450 WinExec(buf, SW_NORMAL);
4454 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
4455 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
4459 #endif /* HTML_HELP */
4465 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4472 /* Extract the modifiers */
4473 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4474 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4475 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4477 Term_no_press = (ma) ? TRUE : FALSE;
4479 /* Handle "special" keys */
4480 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4482 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4483 bool numpad = FALSE;
4485 /* Begin the macro trigger */
4488 /* Send the modifiers */
4489 if (mc) Term_keypress('C');
4490 if (ms) Term_keypress('S');
4491 if (ma) Term_keypress('A');
4493 /* Extract "scan code" */
4494 i = LOBYTE(HIWORD(lParam));
4496 /* Introduce the scan code */
4499 /* Extended key bit */
4502 /* Numpad Enter and '/' are extended key */
4504 Term_no_press = TRUE;
4505 case VK_RETURN: /* Enter */
4508 /* Other extended keys are on full keyboard */
4524 Term_no_press = TRUE;
4528 case VK_PRIOR: /* Page Up */
4529 case VK_NEXT: /* Page Down */
4539 /* Special modifiers for keypad keys */
4540 if (numpad) Term_keypress('K');
4542 /* Encode the hexidecimal scan code */
4543 Term_keypress(hexsym[i/16]);
4544 Term_keypress(hexsym[i%16]);
4546 /* End the macro trigger */
4557 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4558 WPARAM wParam, LPARAM lParam);
4559 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4560 WPARAM wParam, LPARAM lParam)
4561 #else /* __MWERKS__ */
4562 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4563 #endif /* __MWERKS__ */
4569 MINMAXINFO FAR *lpmmi;
4575 /* Acquire proper "term_data" info */
4576 td = (term_data *)GetWindowLong(hWnd, 0);
4578 /* Handle message */
4583 SetWindowLong(hWnd, 0, (LONG)(my_td));
4590 mop.dwCallback=(DWORD)hWnd;
4595 case WM_GETMINMAXINFO:
4597 MINMAXINFO FAR *lpmmi;
4600 lpmmi = (MINMAXINFO FAR *)lParam;
4602 /* this message was sent before WM_NCCREATE */
4605 /* Minimum window size is 80x24 */
4606 rc.left = rc.top = 0;
4607 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4608 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4611 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4613 /* Save minimum size */
4614 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4615 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4622 BeginPaint(hWnd, &ps);
4623 if (td) term_data_redraw(td);
4624 EndPaint(hWnd, &ps);
4625 ValidateRect(hWnd, NULL);
4632 if(wParam == MCI_NOTIFY_SUCCESSFUL)
4634 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4635 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4644 if (process_keydown(wParam, lParam))
4651 if (Term_no_press) Term_no_press = FALSE;
4652 else Term_keypress(wParam);
4656 case WM_LBUTTONDOWN:
4658 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4659 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4671 TERM_LEN dx = abs(oldx - mousex) + 1;
4672 TERM_LEN dy = abs(oldy - mousey) + 1;
4673 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
4674 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
4684 hGlobal = GlobalAlloc(GHND, sz + 1);
4685 if (hGlobal == NULL) return 0;
4686 lpStr = (LPSTR)GlobalLock(hGlobal);
4688 for (i = 0; i < dy; i++)
4692 char **scr = data[0].t.scr->c;
4694 C_MAKE(s, (dx + 1), char);
4695 strncpy(s, &scr[oy + i][ox], dx);
4699 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4702 if (ox + dx < data[0].cols)
4704 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4707 for (j = 0; j < dx; j++)
4709 if (s[j] == 127) s[j] = '#';
4713 for (j = 0; j < dx; j++)
4715 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4725 GlobalUnlock(hGlobal);
4726 if (OpenClipboard(hWnd) == 0)
4728 GlobalFree(hGlobal);
4732 SetClipboardData(CF_TEXT, hGlobal);
4745 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4746 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4751 dx = abs(oldx - mousex) + 1;
4752 dy = abs(oldy - mousey) + 1;
4753 ox = (oldx > mousex) ? mousex : oldx;
4754 oy = (oldy > mousey) ? mousey : oldy;
4755 Term_inversed_area(hWnd, ox, oy, dx, dy);
4762 dx = abs(cx - mousex) + 1;
4763 dy = abs(cy - mousey) + 1;
4764 ox = (cx > mousex) ? mousex : cx;
4765 oy = (cy > mousey) ? mousey : cy;
4766 Term_inversed_area(hWnd, ox, oy, dx, dy);
4782 if (game_in_progress && character_generated)
4786 plog(_("今は終了できません。", "You may not do that right now."));
4790 /* Hack -- Forget messages */
4799 /* do_cmd_save_game(FALSE); */
4800 #else /* ZANGBAND */
4801 /* do_cmd_save_game(); */
4802 #endif /* ZANGBAND */
4803 Term_key_push(SPECIAL_KEY_QUIT);
4810 case WM_QUERYENDSESSION:
4812 if (game_in_progress && character_generated)
4814 /* Hack -- Forget messages */
4817 /* Mega-Hack -- Delay death */
4818 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4819 do_cmd_write_nikki(NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4821 /* Hardcode panic save */
4822 p_ptr->panic_save = 1;
4824 /* Forbid suspend */
4825 signals_ignore_tstp();
4827 /* Indicate panic save */
4828 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4831 (void)save_player();
4845 process_menus(LOWORD(wParam));
4851 /* this message was sent before WM_NCCREATE */
4854 /* it was sent from inside CreateWindowEx */
4855 if (!td->w) return 1;
4857 /* was sent from WM_SIZE */
4858 if (td->size_hack) return 1;
4862 case SIZE_MINIMIZED:
4864 /* Hide sub-windows */
4865 for (i = 1; i < MAX_TERM_DATA; i++)
4867 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4872 case SIZE_MAXIMIZED:
4879 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4880 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4883 if ((td->cols != cols) || (td->rows != rows))
4885 /* Save the new size */
4889 if (!IsZoomed(td->w) && !IsIconic(td->w))
4891 normsize.x = td->cols;
4892 normsize.y = td->rows;
4896 Term_activate(&td->t);
4898 /* Resize the term */
4899 Term_resize(td->cols, td->rows);
4902 InvalidateRect(td->w, NULL, TRUE);
4905 td->size_hack = TRUE;
4907 /* Show sub-windows */
4908 for (i = 1; i < MAX_TERM_DATA; i++)
4910 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4913 td->size_hack = FALSE;
4921 case WM_PALETTECHANGED:
4923 /* Ignore if palette change caused by itself */
4924 if ((HWND)wParam == hWnd) return 0;
4926 /* Fall through... */
4929 case WM_QUERYNEWPALETTE:
4931 if (!paletted) return 0;
4935 SelectPalette(hdc, hPal, FALSE);
4937 i = RealizePalette(hdc);
4939 /* if any palette entries changed, repaint the window. */
4940 if (i) InvalidateRect(hWnd, NULL, TRUE);
4942 ReleaseDC(hWnd, hdc);
4949 if (wParam && !HIWORD(lParam))
4951 /* Do something to sub-windows */
4952 for (i = 1; i < MAX_TERM_DATA; i++)
4954 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4957 /* Focus on main window */
4966 case WM_ACTIVATEAPP:
4968 if (IsIconic(td->w)) break;
4970 for (i = 1; i < MAX_TERM_DATA; i++)
4976 ShowWindow(data[i].w, SW_SHOW);
4980 ShowWindow(data[i].w, SW_HIDE);
4987 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4992 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4993 WPARAM wParam, LPARAM lParam);
4994 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4995 WPARAM wParam, LPARAM lParam)
4996 #else /* __MWERKS__ */
4997 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4998 WPARAM wParam, LPARAM lParam)
4999 #endif /* __MWERKS__ */
5003 MINMAXINFO FAR *lpmmi;
5011 /* Acquire proper "term_data" info */
5012 td = (term_data *)GetWindowLong(hWnd, 0);
5014 /* Process message */
5019 SetWindowLong(hWnd, 0, (LONG)(my_td));
5028 case WM_GETMINMAXINFO:
5030 MINMAXINFO FAR *lpmmi;
5033 lpmmi = (MINMAXINFO FAR *)lParam;
5035 /* this message was sent before WM_NCCREATE */
5038 /* Minimum window size is 80x24 */
5039 rc.left = rc.top = 0;
5040 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5041 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5044 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5046 /* Save minimum size */
5047 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5048 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5058 /* this message was sent before WM_NCCREATE */
5061 /* it was sent from inside CreateWindowEx */
5062 if (!td->w) return 1;
5064 /* was sent from inside WM_SIZE */
5065 if (td->size_hack) return 1;
5067 td->size_hack = TRUE;
5069 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5070 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5073 if ((td->cols != cols) || (td->rows != rows))
5076 term *old_term = Term;
5078 /* Save the new size */
5083 Term_activate(&td->t);
5085 /* Resize the term */
5086 Term_resize(td->cols, td->rows);
5089 Term_activate(old_term);
5092 InvalidateRect(td->w, NULL, TRUE);
5094 /* HACK - Redraw all windows */
5095 p_ptr->window = 0xFFFFFFFF;
5099 td->size_hack = FALSE;
5106 BeginPaint(hWnd, &ps);
5107 if (td) term_data_redraw(td);
5108 EndPaint(hWnd, &ps);
5115 if (process_keydown(wParam, lParam))
5122 if (Term_no_press) Term_no_press = FALSE;
5123 else Term_keypress(wParam);
5127 case WM_PALETTECHANGED:
5129 /* ignore if palette change caused by itself */
5130 if ((HWND)wParam == hWnd) return FALSE;
5131 /* otherwise, fall through!!! */
5134 case WM_QUERYNEWPALETTE:
5136 if (!paletted) return 0;
5138 SelectPalette(hdc, hPal, FALSE);
5139 i = RealizePalette(hdc);
5140 /* if any palette entries changed, repaint the window. */
5141 if (i) InvalidateRect(hWnd, NULL, TRUE);
5142 ReleaseDC(hWnd, hdc);
5146 case WM_NCLBUTTONDOWN:
5150 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5151 #endif /* HTCLOSE */
5153 if (wParam == HTSYSMENU)
5157 td->visible = FALSE;
5158 ShowWindow(td->w, SW_HIDE);
5168 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5174 #define MOUSE_SENS 40
5177 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5178 WPARAM wParam, LPARAM lParam);
5179 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5180 WPARAM wParam, LPARAM lParam)
5181 #else /* __MWERKS__ */
5182 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5183 WPARAM wParam, LPARAM lParam)
5184 #endif /* __MWERKS__ */
5186 static int iMouse = 0;
5187 static WORD xMouse = 0;
5188 static WORD yMouse = 0;
5210 if (LOWORD(wParam) == WA_INACTIVE) break;
5212 /* else fall through */
5216 case WM_LBUTTONDOWN:
5217 case WM_MBUTTONDOWN:
5218 case WM_RBUTTONDOWN:
5221 SendMessage(hWnd, WM_CLOSE, 0, 0);
5229 dx = LOWORD(lParam) - xMouse;
5230 dy = HIWORD(lParam) - yMouse;
5232 if (dx < 0) dx = -dx;
5233 if (dy < 0) dy = -dy;
5235 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5237 SendMessage(hWnd, WM_CLOSE, 0, 0);
5241 /* Save last location */
5243 xMouse = LOWORD(lParam);
5244 yMouse = HIWORD(lParam);
5251 DestroyWindow(hwndSaver);
5257 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5260 #endif /* USE_SAVER */
5266 /*** Temporary Hooks ***/
5270 * Display warning message (see "z-util.c")
5272 static void hack_plog(concptr str)
5274 /* Give a warning */
5278 MessageBox(NULL, str, "警告!",
5279 MB_ICONEXCLAMATION | MB_OK);
5281 MessageBox(NULL, str, "Warning",
5282 MB_ICONEXCLAMATION | MB_OK);
5290 * Display error message and quit (see "z-util.c")
5292 static void hack_quit(concptr str)
5294 /* Give a warning */
5298 MessageBox(NULL, str, "エラー!",
5299 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5301 MessageBox(NULL, str, "Error",
5302 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5307 /* Unregister the classes */
5308 UnregisterClass(AppName, hInstance);
5310 /* Destroy the icon */
5311 if (hIcon) DestroyIcon(hIcon);
5319 /*** Various hooks ***/
5323 * Display warning message (see "z-util.c")
5325 static void hook_plog(concptr str)
5331 MessageBox(data[0].w, str, "警告!",
5332 MB_ICONEXCLAMATION | MB_OK);
5334 MessageBox(data[0].w, str, "Warning",
5335 MB_ICONEXCLAMATION | MB_OK);
5343 * Display error message and quit (see "z-util.c")
5345 static void hook_quit(concptr str)
5350 /* Give a warning */
5354 MessageBox(data[0].w, str, "エラー!",
5355 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5357 MessageBox(data[0].w, str, "Error",
5358 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5364 /* Save the preferences */
5368 /*** Could use 'Term_nuke_win()' */
5370 /* Destroy all windows */
5371 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5373 term_force_font(&data[i], NULL);
5374 if (data[i].font_want) string_free(data[i].font_want);
5375 if (data[i].w) DestroyWindow(data[i].w);
5379 /* Free the bitmap stuff */
5381 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5382 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5384 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5385 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5387 #endif /* USE_GRAPHICS */
5389 /*** Free some other stuff ***/
5391 DeleteObject(hbrYellow);
5396 if (hPal) DeleteObject(hPal);
5398 UnregisterClass(AppName, hInstance);
5400 if (hIcon) DestroyIcon(hIcon);
5407 /*** Initialize ***/
5413 static void init_stuff(void)
5420 /* Get program name with full path */
5421 GetModuleFileName(hInstance, path, 512);
5423 /* Save the "program name" */
5426 /* Get the name of the "*.ini" file */
5427 strcpy(path + strlen(path) - 4, ".INI");
5429 /* Save the the name of the ini-file */
5430 ini_file = string_make(path);
5432 /* Analyze the path */
5438 if (path[i] == '\\')
5445 /* Add "lib" to the path */
5446 strcpy(path + i + 1, "lib\\");
5448 /* Validate the path */
5449 validate_dir(path, TRUE);
5451 /* Init the file paths */
5452 init_file_paths(path);
5454 /* Hack -- Validate the paths */
5455 validate_dir(ANGBAND_DIR_APEX, FALSE);
5456 validate_dir(ANGBAND_DIR_BONE, FALSE);
5458 /* Allow missing 'edit' directory */
5459 if (!check_dir(ANGBAND_DIR_EDIT))
5461 /* Must have 'data'! */
5462 validate_dir(ANGBAND_DIR_DATA, TRUE);
5466 /* Don't need 'data' */
5467 validate_dir(ANGBAND_DIR_DATA, FALSE);
5470 validate_dir(ANGBAND_DIR_FILE, TRUE);
5471 validate_dir(ANGBAND_DIR_HELP, FALSE);
5472 validate_dir(ANGBAND_DIR_INFO, FALSE);
5473 validate_dir(ANGBAND_DIR_PREF, TRUE);
5474 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5475 validate_dir(ANGBAND_DIR_USER, TRUE);
5476 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5478 /* Build the filename */
5479 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
5481 /* Hack -- Validate the "news.txt" file */
5482 validate_file(path);
5485 #if 0 /* #ifndef JP */
5486 /* Build the "font" path */
5487 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5489 /* Allocate the path */
5490 ANGBAND_DIR_XTRA_FONT = string_make(path);
5492 /* Validate the "font" directory */
5493 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5495 /* Build the filename */
5496 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5498 /* Hack -- Validate the basic font */
5499 validate_file(path);
5505 /* Build the "graf" path */
5506 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5508 /* Allocate the path */
5509 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5511 /* Validate the "graf" directory */
5512 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5514 #endif /* USE_GRAPHICS */
5519 /* Build the "sound" path */
5520 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5522 /* Allocate the path */
5523 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5525 /* Validate the "sound" directory */
5526 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5528 #endif /* USE_SOUND */
5532 /* Build the "music" path */
5533 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5535 /* Allocate the path */
5536 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5538 /* Validate the "music" directory */
5539 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5541 #endif /* USE_MUSIC */
5543 /* Build the "help" path */
5544 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5546 /* Allocate the path */
5547 ANGBAND_DIR_XTRA_HELP = string_make(path);
5549 /* Validate the "help" directory */
5550 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5554 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
5556 static bool is_already_running(void)
5558 bool result = FALSE;
5561 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5562 if (GetLastError() == ERROR_ALREADY_EXISTS)
5571 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
5573 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5574 LPSTR lpCmdLine, int nCmdShow)
5582 setlocale(LC_ALL, "ja_JP.utf8");
5591 /* Prevent multiple run */
5592 if (is_already_running())
5595 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
5596 _("エラー!", "Error") ,
5597 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5601 if (hPrevInst == NULL)
5603 wc.style = CS_CLASSDC;
5604 wc.lpfnWndProc = AngbandWndProc;
5606 wc.cbWndExtra = 4; /* one long pointer to term_data */
5607 wc.hInstance = hInst;
5608 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5609 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5610 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5611 wc.lpszMenuName = AppName;
5612 wc.lpszClassName = AppName;
5614 if (!RegisterClass(&wc)) exit(1);
5616 wc.lpfnWndProc = AngbandListProc;
5617 wc.lpszMenuName = NULL;
5618 wc.lpszClassName = AngList;
5620 if (!RegisterClass(&wc)) exit(2);
5624 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5625 wc.lpfnWndProc = AngbandSaverProc;
5627 wc.lpszMenuName = NULL;
5628 wc.lpszClassName = "WindowsScreenSaverClass";
5630 if (!RegisterClass(&wc)) exit(3);
5636 /* Temporary hooks */
5637 plog_aux = hack_plog;
5638 quit_aux = hack_quit;
5639 core_aux = hack_quit;
5641 /* Prepare the filepaths */
5644 /* Initialize the keypress analyzer */
5645 for (i = 0; special_key_list[i]; ++i)
5647 special_key[special_key_list[i]] = TRUE;
5649 /* Initialize the keypress analyzer */
5650 for (i = 0; ignore_key_list[i]; ++i)
5652 ignore_key[ignore_key_list[i]] = TRUE;
5655 /* Determine if display is 16/256/true color */
5657 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5658 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5659 ReleaseDC(NULL, hdc);
5661 /* Initialize the colors */
5662 for (i = 0; i < 256; i++)
5666 /* Extract desired values */
5667 rv = angband_color_table[i][1];
5668 gv = angband_color_table[i][2];
5669 bv = angband_color_table[i][3];
5671 /* Extract the "complex" code */
5672 win_clr[i] = PALETTERGB(rv, gv, bv);
5674 /* Save the "simple" code */
5675 angband_color_table[i][0] = win_pal[i];
5678 /* Prepare the windows */
5684 /* Activate hooks */
5685 plog_aux = hook_plog;
5686 quit_aux = hook_quit;
5687 core_aux = hook_quit;
5689 /* Set the system suffix */
5690 ANGBAND_SYS = "win";
5692 /* Set the keyboard suffix */
5693 if (7 != GetKeyboardType(0))
5694 ANGBAND_KEYBOARD = "0";
5697 /* Japanese keyboard */
5698 switch (GetKeyboardType(1))
5700 case 0x0D01: case 0x0D02:
5701 case 0x0D03: case 0x0D04:
5702 case 0x0D05: case 0x0D06:
5704 ANGBAND_KEYBOARD = "NEC98";
5708 ANGBAND_KEYBOARD = "JAPAN";
5712 /* Catch nasty signals */
5715 Term_activate(term_screen);
5718 /* We are now initialized */
5721 if(lpCmdLine[0] == '-'){
5722 switch(lpCmdLine[1])
5727 if (!lpCmdLine[2]) break;
5728 chuukei_server = TRUE;
5729 if(connect_chuukei_server(&lpCmdLine[2])<0){
5730 msg_print("connect fail");
5733 msg_print("connect");
5741 if (!lpCmdLine[2]) break;
5742 chuukei_client = TRUE;
5743 connect_chuukei_server(&lpCmdLine[2]);
5751 if (!lpCmdLine[2]) break;
5752 prepare_browse_movie(&lpCmdLine[2]);
5762 /* Did the user double click on a save file? */
5763 if(!chuukei_server) check_for_save_file(lpCmdLine);
5765 /* Did the user double click on a save file? */
5766 check_for_save_file(lpCmdLine);
5769 /* Prompt the user */
5770 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
5774 /* Process messages forever */
5775 while (GetMessage(&msg, NULL, 0, 0))
5777 TranslateMessage(&msg);
5778 DispatchMessage(&msg);
5785 #endif /* WINDOWS */