1 /* File: main-win.c */
4 * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies.
13 * This file helps Angband work with Windows computers.
15 * To use this file, use an appropriate "Makefile" or "Project File",
16 * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
17 * make sure to obtain various extra files as described below.
19 * The official compilation uses the CodeWarrior Pro compiler, which
20 * includes a special project file and precompilable header file.
23 * See also "main-dos.c" and "main-ibm.c".
26 * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
27 * and/or color redefinitions.
29 * The "lib/user/font-win.prf" contains attr/char mappings for use with the
30 * normal "lib/xtra/font/*.fon" font files.
32 * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
33 * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
37 * Compiling this file, and using the resulting executable, requires
38 * several extra files not distributed with the standard Angband code.
39 * If "USE_GRAPHICS" is defined, then "readdib.h" and "readdib.c" must
40 * be placed into "src/", and the "8X8.BMP" bitmap file must be placed
41 * into "lib/xtra/graf". In any case, some "*.fon" files (including
42 * "8X13.FON" if nothing else) must be placed into "lib/xtra/font/".
43 * If "USE_SOUND" is defined, then some special library (for example,
44 * "winmm.lib") may need to be linked in, and desired "*.WAV" sound
45 * files must be placed into "lib/xtra/sound/". All of these extra
46 * files can be found in the "ext-win" archive.
49 * The "Term_xtra_win_clear()" function should probably do a low-level
50 * clear of the current window, and redraw the borders and other things,
51 * if only for efficiency. XXX XXX XXX
53 * A simpler method is needed for selecting the "tile size" for windows.
56 * The various "warning" messages assume the existance of the "screen.w"
57 * window, I think, and only a few calls actually check for its existance,
58 * this may be okay since "NULL" means "on top of all windows". (?) The
59 * user must never be allowed to "hide" the main window, or the "menubar"
60 * will disappear. XXX XXX XXX
62 * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
63 * use with the "winhelp.exe" program. These files *may* be available
64 * at the ftp site somewhere, but I have not seen them. XXX XXX XXX
67 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
69 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
71 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
72 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
84 * Extract the "WIN32" flag from the compiler
86 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
94 * Hack -- allow use of "screen saver" mode
100 * Menu constants -- see "ANGBAND.RC"
103 #define IDM_FILE_NEW 100
104 #define IDM_FILE_OPEN 101
105 #define IDM_FILE_SAVE 110
106 #define IDM_FILE_SCORE 120
107 #define IDM_FILE_MOVIE 121
108 #define IDM_FILE_EXIT 130
110 #define IDM_WINDOW_VIS_0 200
111 #define IDM_WINDOW_VIS_1 201
112 #define IDM_WINDOW_VIS_2 202
113 #define IDM_WINDOW_VIS_3 203
114 #define IDM_WINDOW_VIS_4 204
115 #define IDM_WINDOW_VIS_5 205
116 #define IDM_WINDOW_VIS_6 206
117 #define IDM_WINDOW_VIS_7 207
119 #define IDM_WINDOW_FONT_0 210
120 #define IDM_WINDOW_FONT_1 211
121 #define IDM_WINDOW_FONT_2 212
122 #define IDM_WINDOW_FONT_3 213
123 #define IDM_WINDOW_FONT_4 214
124 #define IDM_WINDOW_FONT_5 215
125 #define IDM_WINDOW_FONT_6 216
126 #define IDM_WINDOW_FONT_7 217
128 #define IDM_WINDOW_POS_0 220
129 #define IDM_WINDOW_POS_1 221
130 #define IDM_WINDOW_POS_2 222
131 #define IDM_WINDOW_POS_3 223
132 #define IDM_WINDOW_POS_4 224
133 #define IDM_WINDOW_POS_5 225
134 #define IDM_WINDOW_POS_6 226
135 #define IDM_WINDOW_POS_7 227
137 #define IDM_WINDOW_BIZ_0 230
138 #define IDM_WINDOW_BIZ_1 231
139 #define IDM_WINDOW_BIZ_2 232
140 #define IDM_WINDOW_BIZ_3 233
141 #define IDM_WINDOW_BIZ_4 234
142 #define IDM_WINDOW_BIZ_5 235
143 #define IDM_WINDOW_BIZ_6 236
144 #define IDM_WINDOW_BIZ_7 237
146 #define IDM_WINDOW_I_WID_0 240
147 #define IDM_WINDOW_I_WID_1 241
148 #define IDM_WINDOW_I_WID_2 242
149 #define IDM_WINDOW_I_WID_3 243
150 #define IDM_WINDOW_I_WID_4 244
151 #define IDM_WINDOW_I_WID_5 245
152 #define IDM_WINDOW_I_WID_6 246
153 #define IDM_WINDOW_I_WID_7 247
155 #define IDM_WINDOW_D_WID_0 250
156 #define IDM_WINDOW_D_WID_1 251
157 #define IDM_WINDOW_D_WID_2 252
158 #define IDM_WINDOW_D_WID_3 253
159 #define IDM_WINDOW_D_WID_4 254
160 #define IDM_WINDOW_D_WID_5 255
161 #define IDM_WINDOW_D_WID_6 256
162 #define IDM_WINDOW_D_WID_7 257
164 #define IDM_WINDOW_I_HGT_0 260
165 #define IDM_WINDOW_I_HGT_1 261
166 #define IDM_WINDOW_I_HGT_2 262
167 #define IDM_WINDOW_I_HGT_3 263
168 #define IDM_WINDOW_I_HGT_4 264
169 #define IDM_WINDOW_I_HGT_5 265
170 #define IDM_WINDOW_I_HGT_6 266
171 #define IDM_WINDOW_I_HGT_7 267
173 #define IDM_WINDOW_D_HGT_0 270
174 #define IDM_WINDOW_D_HGT_1 271
175 #define IDM_WINDOW_D_HGT_2 272
176 #define IDM_WINDOW_D_HGT_3 273
177 #define IDM_WINDOW_D_HGT_4 274
178 #define IDM_WINDOW_D_HGT_5 275
179 #define IDM_WINDOW_D_HGT_6 276
180 #define IDM_WINDOW_D_HGT_7 277
182 #define IDM_OPTIONS_NO_GRAPHICS 400
183 #define IDM_OPTIONS_OLD_GRAPHICS 401
184 #define IDM_OPTIONS_NEW_GRAPHICS 402
185 #define IDM_OPTIONS_NEW2_GRAPHICS 403
186 #define IDM_OPTIONS_BIGTILE 409
187 #define IDM_OPTIONS_SOUND 410
188 #define IDM_OPTIONS_MUSIC 411
189 #define IDM_OPTIONS_SAVER 420
190 #define IDM_OPTIONS_MAP 430
191 #define IDM_OPTIONS_BG 440
192 #define IDM_OPTIONS_OPEN_BG 441
194 #define IDM_DUMP_SCREEN_HTML 450
196 #define IDM_HELP_CONTENTS 901
201 * This may need to be removed for some compilers XXX XXX XXX
208 * Exclude parts of WINDOWS.H that are not needed
210 #define NOCOMM /* Comm driver APIs and definitions */
211 #define NOLOGERROR /* LogError() and related definitions */
212 #define NOPROFILER /* Profiler APIs */
213 #define NOLFILEIO /* _l* file I/O routines */
214 #define NOOPENFILE /* OpenFile and related definitions */
215 #define NORESOURCE /* Resource management */
216 #define NOATOM /* Atom management */
217 #define NOLANGUAGE /* Character test routines */
218 #define NOLSTRING /* lstr* string management routines */
219 #define NODBCS /* Double-byte character set routines */
220 #define NOKEYBOARDINFO /* Keyboard driver routines */
221 #define NOCOLOR /* COLOR_* color values */
222 #define NODRAWTEXT /* DrawText() and related definitions */
223 #define NOSCALABLEFONT /* Truetype scalable font support */
224 #define NOMETAFILE /* Metafile support */
225 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
226 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
227 #define NOKEYSTATES /* MK_* message key state flags */
228 #define NOWH /* SetWindowsHook and related WH_* definitions */
229 #define NOCLIPBOARD /* Clipboard APIs and definitions */
230 #define NOICONS /* IDI_* icon IDs */
231 #define NOMDI /* MDI support */
232 #define NOHELP /* Help support */
234 /* Not defined since it breaks Borland C++ 5.5 */
235 /* #define NOCTLMGR */ /* Control management and controls */
238 * Exclude parts of WINDOWS.H that are not needed (Win32)
240 #define WIN32_LEAN_AND_MEAN
241 #define NONLS /* All NLS defines and routines */
242 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
243 #define NOKANJI /* Kanji support stuff. */
244 #define NOMCX /* Modem Configuration Extensions */
247 * Include the "windows" support file
252 * Exclude parts of MMSYSTEM.H that are not needed
254 #define MMNODRV /* Installable driver support */
255 #define MMNOWAVE /* Waveform support */
256 #define MMNOMIDI /* MIDI support */
257 #define MMNOAUX /* Auxiliary audio support */
258 #define MMNOTIMER /* Timer support */
259 #define MMNOJOY /* Joystick support */
260 #define MMNOMCI /* MCI support */
261 #define MMNOMMIO /* Multimedia file I/O support */
262 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
265 * Include some more files. Note: the Cygnus Cygwin compiler
266 * doesn't use mmsystem.h instead it includes the winmm library
267 * which performs a similar function.
269 #include <mmsystem.h>
273 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
274 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
276 /* #define HTML_HELP */
279 #include <htmlhelp.h>
280 #endif /* HTML_HELP */
283 * Include the support for loading bitmaps
286 # include "readdib.h"
290 * Hack -- Fake declarations from "dos.h" XXX XXX XXX
293 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
295 #define FA_LABEL 0x08 /* Volume label */
296 #define FA_DIREC 0x10 /* Directory */
297 unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
301 * Silliness in WIN32 drawing routine
304 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
308 * Silliness for Windows 95
310 #ifndef WS_EX_TOOLWINDOW
311 # define WS_EX_TOOLWINDOW 0
315 * Foreground color bits (hard-coded by DOS)
317 #define VID_BLACK 0x00
318 #define VID_BLUE 0x01
319 #define VID_GREEN 0x02
320 #define VID_CYAN 0x03
322 #define VID_MAGENTA 0x05
323 #define VID_YELLOW 0x06
324 #define VID_WHITE 0x07
327 * Bright text (hard-coded by DOS)
329 #define VID_BRIGHT 0x08
332 * Background color bits (hard-coded by DOS)
334 #define VUD_BLACK 0x00
335 #define VUD_BLUE 0x10
336 #define VUD_GREEN 0x20
337 #define VUD_CYAN 0x30
339 #define VUD_MAGENTA 0x50
340 #define VUD_YELLOW 0x60
341 #define VUD_WHITE 0x70
344 * Blinking text (hard-coded by DOS)
346 #define VUD_BRIGHT 0x80
352 typedef struct _term_data term_data;
357 * Note the use of "font_want" for the names of the font file requested by
358 * the user, and the use of "font_file" for the currently active font file.
360 * The "font_file" is uppercased, and takes the form "8X13.FON", while
361 * "font_want" can be in almost any form as long as it could be construed
362 * as attempting to represent the name of a font.
377 uint rows; /* int -> uint */
413 #if 1 /* #ifdef JP */
428 * Maximum number of windows XXX XXX XXX
430 #define MAX_TERM_DATA 8
433 * An array of term_data's
435 static term_data data[MAX_TERM_DATA];
438 * Hack -- global "window creation" pointer
440 static term_data *my_td;
443 * Remember normal size of main window when maxmized
448 * was main window maximized on previous playing
450 bool win_maximized = FALSE;
455 bool game_in_progress = FALSE;
458 * note when "open"/"new" become valid
460 bool initialized = FALSE;
463 * screen paletted, i.e. 256 colors
465 bool paletted = FALSE;
468 * 16 colors screen, don't use RGB()
470 bool colors16 = FALSE;
473 * Saved instance handle
475 static HINSTANCE hInstance;
478 * Yellow brush for the cursor
480 static HBRUSH hbrYellow;
490 static HPALETTE hPal;
493 static HBITMAP hBG = NULL;
494 static int use_bg = 0;
495 static char bg_bitmap_file[1024] = "bg.bmp";
500 * The screen saver window
502 static HWND hwndSaver;
504 #endif /* USE_SAVER */
510 * Flag set once "graphics" has been initialized
512 static bool can_use_graphics = FALSE;
517 static DIBINIT infGraph;
520 * The global bitmap mask
522 static DIBINIT infMask;
524 #endif /* USE_GRAPHICS */
530 * Flag set once "sound" has been initialized
532 static bool can_use_sound = FALSE;
536 * An array of sound file names
538 static cptr sound_file[SOUND_MAX][SAMPLE_MAX];
540 #endif /* USE_SOUND */
546 #define SAMPLE_MUSIC_MAX 16
547 static cptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
548 static cptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
549 static cptr town_music_file[1000][SAMPLE_MUSIC_MAX];
550 static cptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
551 static bool can_use_music = FALSE;
553 static MCI_OPEN_PARMS mop;
554 static char mci_device_type[256];
556 int current_music_type = 0;
557 int current_music_id = 0;
559 #endif /* USE_MUSIC */
563 * Full path to ANGBAND.INI
565 static cptr ini_file = NULL;
568 * Name of application
570 static cptr AppName = "ANGBAND";
573 * Name of sub-window type
575 static cptr AngList = "AngList";
580 static cptr ANGBAND_DIR_XTRA_GRAF;
581 static cptr ANGBAND_DIR_XTRA_SOUND;
582 static cptr ANGBAND_DIR_XTRA_MUSIC;
583 static cptr ANGBAND_DIR_XTRA_HELP;
584 #if 0 /* #ifndef JP */
585 static cptr ANGBAND_DIR_XTRA_FONT;
588 static cptr ANGBAND_DIR_XTRA_MUSIC;
593 * The "complex" color values
595 static COLORREF win_clr[256];
599 * Flag for macro trigger with dump ASCII
601 static bool Term_no_press = FALSE;
606 static bool mouse_down = FALSE;
607 static bool paint_rect = FALSE;
608 static int mousex = 0, mousey = 0;
609 static int oldx, oldy;
613 * The "simple" color values
615 * See "main-ibm.c" for original table information
617 * The entries below are taken from the "color bits" defined above.
619 * Note that many of the choices below suck, but so do crappy monitors.
621 static BYTE win_pal[256] =
623 VID_BLACK, /* Dark */
624 VID_WHITE, /* White */
625 VID_CYAN, /* Slate XXX */
626 VID_RED | VID_BRIGHT, /* Orange XXX */
628 VID_GREEN, /* Green */
630 VID_YELLOW, /* Umber XXX */
631 VID_BLACK | VID_BRIGHT, /* Light Dark */
632 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
633 VID_MAGENTA, /* Violet XXX */
634 VID_YELLOW | VID_BRIGHT, /* Yellow */
635 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
636 VID_GREEN | VID_BRIGHT, /* Light Green */
637 VID_BLUE | VID_BRIGHT, /* Light Blue */
638 VID_YELLOW /* Light Umber XXX */
643 * Hack -- define which keys are "special"
645 static bool special_key[256];
646 static bool ignore_key[256];
650 * Hack -- initialization list for "special_key"
652 static byte special_key_list[] = {
653 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
654 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
655 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
656 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
657 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
658 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
659 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
660 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
661 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
662 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
663 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
664 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
665 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
666 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
667 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
668 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
669 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
674 static byte ignore_key_list[] = {
675 VK_ESCAPE, VK_TAB, VK_SPACE,
676 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
677 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
678 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
684 * Hack -- initialization list for "special_key"
686 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
687 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
688 * catch the keypad keys (with and without numlock set, including keypad 5),
689 * the function keys (including the "menu" key which maps to F10), and the
690 * "pause" key (between scroll lock and numlock). We also catch a few odd
691 * keys which I do not recognize, but which are listed among keys which we
692 * do catch, so they should be harmless to catch.
694 static byte special_key_list[] =
696 VK_CLEAR, /* 0x0C (KP<5>) */
698 VK_PAUSE, /* 0x13 (pause) */
700 VK_PRIOR, /* 0x21 (KP<9>) */
701 VK_NEXT, /* 0x22 (KP<3>) */
702 VK_END, /* 0x23 (KP<1>) */
703 VK_HOME, /* 0x24 (KP<7>) */
704 VK_LEFT, /* 0x25 (KP<4>) */
705 VK_UP, /* 0x26 (KP<8>) */
706 VK_RIGHT, /* 0x27 (KP<6>) */
707 VK_DOWN, /* 0x28 (KP<2>) */
708 VK_SELECT, /* 0x29 (?????) */
709 VK_PRINT, /* 0x2A (?????) */
710 VK_EXECUTE, /* 0x2B (?????) */
711 VK_SNAPSHOT, /* 0x2C (?????) */
712 VK_INSERT, /* 0x2D (KP<0>) */
713 VK_DELETE, /* 0x2E (KP<.>) */
714 VK_HELP, /* 0x2F (?????) */
716 VK_NUMPAD0, /* 0x60 (KP<0>) */
717 VK_NUMPAD1, /* 0x61 (KP<1>) */
718 VK_NUMPAD2, /* 0x62 (KP<2>) */
719 VK_NUMPAD3, /* 0x63 (KP<3>) */
720 VK_NUMPAD4, /* 0x64 (KP<4>) */
721 VK_NUMPAD5, /* 0x65 (KP<5>) */
722 VK_NUMPAD6, /* 0x66 (KP<6>) */
723 VK_NUMPAD7, /* 0x67 (KP<7>) */
724 VK_NUMPAD8, /* 0x68 (KP<8>) */
725 VK_NUMPAD9, /* 0x69 (KP<9>) */
726 VK_MULTIPLY, /* 0x6A (KP<*>) */
727 VK_ADD, /* 0x6B (KP<+>) */
728 VK_SEPARATOR, /* 0x6C (?????) */
729 VK_SUBTRACT, /* 0x6D (KP<->) */
730 VK_DECIMAL, /* 0x6E (KP<.>) */
731 VK_DIVIDE, /* 0x6F (KP</>) */
762 static void delete_bg(void)
771 static int init_bg(void)
773 char * bmfile = bg_bitmap_file;
776 if (use_bg == 0) return 0;
778 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
780 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
785 HDC wnddc, dcimage, dcbg;
786 HBITMAP bmimage, bmimage_old, bmbg_old;
792 dcimage = CreateCompatibleDC(wnddc);
793 dcbg = CreateCompatibleDC(wnddc);
795 bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
796 if (!bmimage) quit("bg.bmpが読みこめない!");
797 bmimage_old = SelectObject(dcimage, bmimage);
799 CreateCompatibleBitmap();
801 ReleaseDC(hwnd, wnddc);
807 static void DrawBG(HDC hdc, RECT *r)
812 int x = r->left, y = r->top;
813 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
819 GetObject(hBG, sizeof(bm), &bm);
820 swid = bm.bmWidth; shgt = bm.bmHeight;
822 hdcSrc = CreateCompatibleDC(hdc);
823 hOld = SelectObject(hdcSrc, hBG);
827 cwid = MIN(swid - sx, r->right - nx);
830 chgt = MIN(shgt - sy, r->bottom - ny);
831 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
833 } while (ny < r->bottom);
836 } while (nx < r->right);
838 SelectObject(hdcSrc, hOld);
844 * Hack -- given a pathname, point at the filename
846 static cptr extract_file_name(cptr s)
850 /* Start at the end */
851 p = s + strlen(s) - 1;
853 /* Back up to divider */
854 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
856 /* Return file name */
863 * Hack -- given a simple filename, extract the "font size" info
865 * Return a pointer to a static buffer holding the capitalized base name.
867 #if 0 /* #ifndef JP */
868 static char *analyze_font(char *path, int *wp, int *hp)
874 /* Start at the end */
875 p = path + strlen(path) - 1;
877 /* Back up to divider */
878 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
880 /* Advance to file name */
886 /* Capitalize (be paranoid) */
887 if (islower(*s)) *s = toupper(*s);
891 s = my_strchr(p, 'X');
893 /* Extract font width */
897 hgt = s ? atoi(s+1) : 0;
910 * Check for existance of a file
912 static bool check_file(cptr s)
932 attrib = GetFileAttributes(path);
934 /* Require valid filename */
935 if (attrib == INVALID_FILE_NAME) return (FALSE);
937 /* Prohibit directory */
938 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
942 /* Examine and verify */
943 if (_dos_getfileattr(path, &attrib)) return (FALSE);
945 /* Prohibit something */
946 if (attrib & FA_LABEL) return (FALSE);
948 /* Prohibit directory */
949 if (attrib & FA_DIREC) return (FALSE);
959 * Check for existance of a directory
961 static bool check_dir(cptr s)
983 /* Remove trailing backslash */
984 if (i && (path[i-1] == '\\')) path[--i] = '\0';
989 attrib = GetFileAttributes(path);
991 /* Require valid filename */
992 if (attrib == INVALID_FILE_NAME) return (FALSE);
994 /* Require directory */
995 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
999 /* Examine and verify */
1000 if (_dos_getfileattr(path, &attrib)) return (FALSE);
1002 /* Prohibit something */
1003 if (attrib & FA_LABEL) return (FALSE);
1005 /* Require directory */
1006 if (!(attrib & FA_DIREC)) return (FALSE);
1018 static void validate_file(cptr s)
1020 /* Verify or fail */
1023 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
1029 * Validate a directory
1031 static void validate_dir(cptr s, bool vital)
1033 /* Verify or fail */
1036 /* This directory contains needed data */
1039 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
1041 /* Attempt to create this directory */
1044 quit_fmt("Unable to create directory:\n%s", s);
1051 * Get the "size" for a window
1053 static void term_getsize(term_data *td)
1060 if (td->cols < 1) td->cols = 1;
1061 if (td->rows < 1) td->rows = 1;
1064 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1065 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1067 /* Fake window size */
1069 rc.right = rc.left + wid;
1071 rc.bottom = rc.top + hgt;
1074 /* rc.right += 1; */
1075 /* rc.bottom += 1; */
1078 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1081 td->size_wid = rc.right - rc.left;
1082 td->size_hgt = rc.bottom - rc.top;
1084 /* See CreateWindowEx */
1087 /* Extract actual location */
1088 GetWindowRect(td->w, &rc);
1090 /* Save the location */
1091 td->pos_x = rc.left;
1097 * Write the "prefs" for a single term
1099 static void save_prefs_aux(int i)
1101 term_data *td = &data[i];
1106 WINDOWPLACEMENT lpwndpl;
1111 /* Make section name */
1112 sprintf(sec_name, "Term-%d", i);
1117 strcpy(buf, td->visible ? "1" : "0");
1118 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1123 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "MS ゴシック");
1126 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1128 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1132 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1134 #if 1 /* #ifdef JP */
1135 wsprintf(buf, "%d", td->lf.lfWidth);
1136 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1137 wsprintf(buf, "%d", td->lf.lfHeight);
1138 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1139 wsprintf(buf, "%d", td->lf.lfWeight);
1140 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1143 strcpy(buf, td->bizarre ? "1" : "0");
1144 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1147 wsprintf(buf, "%d", td->tile_wid);
1148 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1151 wsprintf(buf, "%d", td->tile_hgt);
1152 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1154 /* Get window placement and dimensions */
1155 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1156 GetWindowPlacement(td->w, &lpwndpl);
1158 /* Acquire position in *normal* mode (not minimized) */
1159 rc = lpwndpl.rcNormalPosition;
1161 /* Window size (x) */
1162 if (i == 0) wsprintf(buf, "%d", normsize.x);
1163 else wsprintf(buf, "%d", td->cols);
1164 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1166 /* Window size (y) */
1167 if (i == 0) wsprintf(buf, "%d", normsize.y);
1168 else wsprintf(buf, "%d", td->rows);
1169 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1171 /* Maxmized (only main window) */
1174 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1175 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1178 /* Acquire position */
1179 GetWindowRect(td->w, &rc);
1181 /* Window position (x) */
1182 wsprintf(buf, "%d", rc.left);
1183 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1185 /* Window position (y) */
1186 wsprintf(buf, "%d", rc.top);
1187 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1189 /* Window Z position */
1192 strcpy(buf, td->posfix ? "1" : "0");
1193 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1201 * We assume that the windows have all been initialized
1203 static void save_prefs(void)
1209 /* Save the "arg_graphics" flag */
1210 sprintf(buf, "%d", arg_graphics);
1211 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1213 /* Save the "arg_bigtile" flag */
1214 strcpy(buf, arg_bigtile ? "1" : "0");
1215 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1217 /* Save the "arg_sound" flag */
1218 strcpy(buf, arg_sound ? "1" : "0");
1219 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1221 /* Save the "arg_sound" flag */
1222 strcpy(buf, arg_music ? "1" : "0");
1223 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1226 strcpy(buf, use_bg ? "1" : "0");
1227 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1228 WritePrivateProfileString("Angband", "BackGroundBitmap",
1229 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1231 /* Save window prefs */
1232 for (i = 0; i < MAX_TERM_DATA; ++i)
1240 * Load the "prefs" for a single term
1242 static void load_prefs_aux(int i)
1244 term_data *td = &data[i];
1248 int wid, hgt, posx, posy;
1249 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1250 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1254 /* Make section name */
1255 sprintf(sec_name, "Term-%d", i);
1257 /* Make section name */
1258 sprintf(sec_name, "Term-%d", i);
1263 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1266 /* Desired font, with default */
1268 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1271 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1273 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1279 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1281 /* Analyze font, save desired font name */
1282 #if 1 /* #ifdef JP */
1283 td->font_want = string_make(tmp);
1285 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1286 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1287 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1289 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1294 #if 1 /* #ifdef JP */
1295 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1296 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1298 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1299 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1304 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1305 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1306 normsize.x = td->cols; normsize.y = td->rows;
1311 win_maximized = GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file);
1314 /* Window position */
1315 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1316 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1317 td->pos_x = MIN(MAX(0, posx), dispx-128);
1318 td->pos_y = MIN(MAX(0, posy), dispy-128);
1320 /* Window Z position */
1323 td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1331 static void load_prefs(void)
1335 /* Extract the "arg_graphics" flag */
1336 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1338 /* Extract the "arg_bigtile" flag */
1339 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1340 use_bigtile = arg_bigtile;
1342 /* Extract the "arg_sound" flag */
1343 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1345 /* Extract the "arg_sound" flag */
1346 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1349 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1350 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1352 /* Load window prefs */
1353 for (i = 0; i < MAX_TERM_DATA; ++i)
1359 #if defined(USE_SOUND) || defined(USE_MUSIC)
1362 * XXX XXX XXX - Taken from files.c.
1364 * Extract "tokens" from a buffer
1366 * This function uses "whitespace" as delimiters, and treats any amount of
1367 * whitespace as a single delimiter. We will never return any empty tokens.
1368 * When given an empty buffer, or a buffer containing only "whitespace", we
1369 * will return no tokens. We will never extract more than "num" tokens.
1371 * By running a token through the "text_to_ascii()" function, you can allow
1372 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1374 * We save pointers to the tokens in "tokens", and return the number found.
1376 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1388 /* Skip leading whitespace */
1389 for ( ; *s && iswspace(*s); ++s) /* loop */;
1394 /* Find next whitespace, if any */
1395 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1397 /* Nuke and advance (if necessary) */
1398 if (*t) *t++ = '\0';
1400 /* Save the token */
1411 #endif /* USE_SOUND || USE_MUSIC */
1415 static void load_sound_prefs(void)
1419 char ini_path[1024];
1420 char wav_path[1024];
1421 char *zz[SAMPLE_MAX];
1423 /* Access the sound.cfg */
1425 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1427 for (i = 0; i < SOUND_MAX; i++)
1429 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1431 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1433 for (j = 0; j < num; j++)
1435 /* Access the sound */
1436 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1438 /* Save the sound filename, if it exists */
1439 if (check_file(wav_path))
1440 sound_file[i][j] = string_make(zz[j]);
1445 #endif /* USE_SOUND */
1449 static void load_music_prefs(void)
1453 char ini_path[1024];
1454 char wav_path[1024];
1455 char *zz[SAMPLE_MAX];
1458 /* Access the music.cfg */
1460 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1462 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1464 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1466 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1468 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1470 for (j = 0; j < num; j++)
1472 /* Access the sound */
1473 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1475 /* Save the sound filename, if it exists */
1476 if (check_file(wav_path))
1477 music_file[i][j] = string_make(zz[j]);
1481 for (i = 0; i < max_d_idx; i++)
1483 sprintf(key, "dungeon%03d", i);
1484 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1486 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1488 for (j = 0; j < num; j++)
1490 /* Access the sound */
1491 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1493 /* Save the sound filename, if it exists */
1494 if (check_file(wav_path))
1495 dungeon_music_file[i][j] = string_make(zz[j]);
1499 for (i = 0; i < 1000; i++) /*!< @todo クエスト最大数指定 */
1501 sprintf(key, "quest%03d", i);
1502 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1504 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1506 for (j = 0; j < num; j++)
1508 /* Access the sound */
1509 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1511 /* Save the sound filename, if it exists */
1512 if (check_file(wav_path))
1513 quest_music_file[i][j] = string_make(zz[j]);
1517 for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1519 sprintf(key, "town%03d", i);
1520 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1522 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1524 for (j = 0; j < num; j++)
1526 /* Access the sound */
1527 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1529 /* Save the sound filename, if it exists */
1530 if (check_file(wav_path))
1531 town_music_file[i][j] = string_make(zz[j]);
1538 #endif /* USE_MUSIC */
1541 * Create the new global palette based on the bitmap palette
1542 * (if any), and the standard 16 entry palette derived from
1543 * "win_clr[]" which is used for the basic 16 Angband colors.
1545 * This function is never called before all windows are ready.
1547 * This function returns FALSE if the new palette could not be
1548 * prepared, which should normally be a fatal error. XXX XXX
1550 * Note that only some machines actually use a "palette".
1552 static int new_palette(void)
1560 LPLOGPALETTE pLogPal;
1561 LPPALETTEENTRY lppe;
1566 /* This makes no sense */
1567 if (!paletted) return (TRUE);
1577 /* Check the bitmap palette */
1578 hBmPal = infGraph.hPalette;
1580 /* Use the bitmap */
1583 lppeSize = 256 * sizeof(PALETTEENTRY);
1584 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1585 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1586 if ((nEntries == 0) || (nEntries > 220))
1589 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1592 rnfree(lppe, lppeSize);
1599 #endif /* USE_GRAPHICS */
1601 /* Size of palette */
1602 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1604 /* Allocate palette */
1605 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1608 pLogPal->palVersion = 0x300;
1610 /* Make room for bitmap and normal data */
1611 pLogPal->palNumEntries = nEntries + 16;
1613 /* Save the bitmap data */
1614 for (i = 0; i < nEntries; i++)
1616 pLogPal->palPalEntry[i] = lppe[i];
1619 /* Save the normal data */
1620 for (i = 0; i < 16; i++)
1624 /* Access the entry */
1625 p = &(pLogPal->palPalEntry[i+nEntries]);
1627 /* Save the colors */
1628 p->peRed = GetRValue(win_clr[i]);
1629 p->peGreen = GetGValue(win_clr[i]);
1630 p->peBlue = GetBValue(win_clr[i]);
1632 /* Save the flags */
1633 p->peFlags = PC_NOCOLLAPSE;
1636 /* Free something */
1637 if (lppe) rnfree(lppe, lppeSize);
1639 /* Create a new palette, or fail */
1640 hNewPal = CreatePalette(pLogPal);
1641 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1643 /* Free the palette */
1644 rnfree(pLogPal, pLogPalSize);
1649 /* Realize the palette */
1651 SelectPalette(hdc, hNewPal, 0);
1652 i = RealizePalette(hdc);
1653 ReleaseDC(td->w, hdc);
1654 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1658 for (i = 1; i < MAX_TERM_DATA; i++)
1663 SelectPalette(hdc, hNewPal, 0);
1664 ReleaseDC(td->w, hdc);
1667 /* Delete old palette */
1668 if (hPal) DeleteObject(hPal);
1670 /* Save new palette */
1680 * Initialize graphics
1682 static bool init_graphics(void)
1684 /* Initialize once */
1685 /* if (can_use_graphics != arg_graphics) */
1688 int wid, hgt, twid, thgt, ox, oy;
1691 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1701 ANGBAND_GRAF = "new";
1703 else if (arg_graphics == GRAPHICS_HENGBAND)
1723 ANGBAND_GRAF = "ne2";
1734 ANGBAND_GRAF = "old";
1737 /* Access the bitmap file */
1738 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1740 /* Load the bitmap or quit */
1741 if (!ReadDIB(data[0].w, buf, &infGraph))
1743 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1747 /* Save the new sizes */
1748 infGraph.CellWidth = wid;
1749 infGraph.CellHeight = hgt;
1750 infGraph.TileWidth = twid;
1751 infGraph.TileHeight = thgt;
1752 infGraph.OffsetX = ox;
1753 infGraph.OffsetY = oy;
1755 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1757 /* Access the mask file */
1758 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1760 /* Load the bitmap or quit */
1761 if (!ReadDIB(data[0].w, buf, &infMask))
1763 plog_fmt("Cannot read bitmap file '%s'", buf);
1767 if (arg_graphics == GRAPHICS_HENGBAND)
1769 /* Access the mask file */
1770 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1772 /* Load the bitmap or quit */
1773 if (!ReadDIB(data[0].w, buf, &infMask))
1775 plog_fmt("Cannot read bitmap file '%s'", buf);
1780 /* Activate a palette */
1783 /* Free bitmap XXX XXX XXX */
1786 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1790 /* Graphics available */
1791 can_use_graphics = arg_graphics;
1795 return (can_use_graphics);
1797 #endif /* USE_GRAPHICS */
1804 static bool init_music(void)
1806 /* Initialize once */
1809 /* Load the prefs */
1812 /* Sound available */
1813 can_use_music = TRUE;
1817 return (can_use_music);
1821 * Hack -- Stop a music
1823 static void stop_music(void)
1825 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1826 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1829 #endif /* USE_MUSIC */
1835 static bool init_sound(void)
1837 /* Initialize once */
1840 /* Load the prefs */
1843 /* Sound available */
1844 can_use_sound = TRUE;
1848 return (can_use_sound);
1850 #endif /* USE_SOUND */
1856 static void term_window_resize(term_data *td)
1858 /* Require window */
1861 /* Resize the window */
1862 SetWindowPos(td->w, 0, 0, 0,
1863 td->size_wid, td->size_hgt,
1864 SWP_NOMOVE | SWP_NOZORDER);
1867 InvalidateRect(td->w, NULL, TRUE);
1872 * Force the use of a new "font file" for a term_data
1874 * This function may be called before the "window" is ready
1876 * This function returns zero only if everything succeeds.
1878 * Note that the "font name" must be capitalized!!!
1880 static errr term_force_font(term_data *td, cptr path)
1884 #if 0 /* #ifndef JP */
1890 /* Forget the old font (if needed) */
1891 if (td->font_id) DeleteObject(td->font_id);
1893 #if 1 /* #ifdef JP */
1897 /* Create the font (using the 'base' of the font file name!) */
1898 td->font_id = CreateFontIndirect(&(td->lf));
1899 wid = td->lf.lfWidth;
1900 hgt = td->lf.lfHeight;
1901 if (!td->font_id) return (1);
1903 /* Forget old font */
1909 for (i = 0; i < MAX_TERM_DATA; i++)
1911 /* Don't check when closing the application */
1914 /* Check "screen" */
1915 if ((td != &data[i]) &&
1916 (data[i].font_file) &&
1917 (streq(data[i].font_file, td->font_file)))
1923 /* Remove unused font resources */
1924 if (!used) RemoveFontResource(td->font_file);
1926 /* Free the old name */
1927 string_free(td->font_file);
1930 td->font_file = NULL;
1934 if (!path) return (1);
1939 /* Analyze font path */
1940 base = analyze_font(buf, &wid, &hgt);
1943 if (!suffix(base, ".FON")) return (1);
1946 if (!check_file(buf)) return (1);
1948 /* Load the new font */
1949 if (!AddFontResource(buf)) return (1);
1951 /* Save new font name */
1952 td->font_file = string_make(base);
1954 /* Remove the "suffix" */
1955 base[strlen(base)-4] = '\0';
1957 /* Create the font (using the 'base' of the font file name!) */
1958 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1959 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1960 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1961 FIXED_PITCH | FF_DONTCARE, base);
1964 /* Hack -- Unknown size */
1971 /* all this trouble to get the cell size */
1972 hdcDesktop = GetDC(HWND_DESKTOP);
1973 hfOld = SelectObject(hdcDesktop, td->font_id);
1974 GetTextMetrics(hdcDesktop, &tm);
1975 SelectObject(hdcDesktop, hfOld);
1976 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1978 /* Font size info */
1979 wid = tm.tmAveCharWidth;
1983 /* Save the size info */
1994 * Allow the user to change the font for this window.
1996 static void term_change_font(term_data *td)
1998 #if 1 /* #ifdef JP */
2001 memset(&cf, 0, sizeof(cf));
2002 cf.lStructSize = sizeof(cf);
2003 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
2004 cf.lpLogFont = &(td->lf);
2006 if (ChooseFont(&cf))
2008 /* Force the font */
2009 term_force_font(td, NULL);
2011 /* Assume not bizarre */
2014 /* Reset the tile info */
2015 td->tile_wid = td->font_wid;
2016 td->tile_hgt = td->font_hgt;
2018 /* Analyze the font */
2021 /* Resize the window */
2022 term_window_resize(td);
2028 char tmp[1024] = "";
2030 /* Extract a default if possible */
2031 if (td->font_file) strcpy(tmp, td->font_file);
2033 /* Ask for a choice */
2034 memset(&ofn, 0, sizeof(ofn));
2035 ofn.lStructSize = sizeof(ofn);
2036 ofn.hwndOwner = data[0].w;
2037 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
2038 ofn.nFilterIndex = 1;
2039 ofn.lpstrFile = tmp;
2041 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
2042 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2043 ofn.lpstrDefExt = "fon";
2045 /* Force choice if legal */
2046 if (GetOpenFileName(&ofn))
2048 /* Force the font */
2049 if (term_force_font(td, tmp))
2051 /* Access the standard font file */
2052 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2054 /* Force the use of that font */
2055 (void)term_force_font(td, tmp);
2058 /* Assume not bizarre */
2059 td->bizarre = FALSE;
2061 /* Reset the tile info */
2062 td->tile_wid = td->font_wid;
2063 td->tile_hgt = td->font_hgt;
2065 /* Analyze the font */
2068 /* Resize the window */
2069 term_window_resize(td);
2076 * Allow the user to lock this window.
2078 static void term_window_pos(term_data *td, HWND hWnd)
2080 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2081 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2084 static void windows_map(void);
2087 * Hack -- redraw a term_data
2089 static void term_data_redraw(term_data *td)
2093 /* Redraw the map */
2098 /* Activate the term */
2099 Term_activate(&td->t);
2101 /* Redraw the contents */
2104 /* Restore the term */
2105 Term_activate(term_screen);
2110 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2114 HBRUSH myBrush, oldBrush;
2116 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2117 int tx = td->size_ow1 + x * td->tile_wid;
2118 int ty = td->size_oh1 + y * td->tile_hgt;
2119 int tw = w * td->tile_wid - 1;
2120 int th = h * td->tile_hgt - 1;
2123 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2124 oldBrush = SelectObject(hdc, myBrush);
2125 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2127 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2129 SelectObject(hdc, oldBrush);
2130 SelectObject(hdc, oldPen);
2135 /*** Function hooks needed by "Term" ***/
2141 * Initialize a new Term
2143 static void Term_init_win(term *t)
2152 static void Term_nuke_win(term *t)
2161 * Interact with the User
2163 static errr Term_user_win(int n)
2174 * React to global changes
2176 static errr Term_xtra_win_react(void)
2184 /* Save the default colors */
2185 for (i = 0; i < 256; i++)
2187 /* Simply accept the desired colors */
2188 win_pal[i] = angband_color_table[i][0];
2199 bool change = FALSE;
2201 /* Save the default colors */
2202 for (i = 0; i < 256; i++)
2204 /* Extract desired values */
2205 rv = angband_color_table[i][1];
2206 gv = angband_color_table[i][2];
2207 bv = angband_color_table[i][3];
2209 /* Extract a full color code */
2210 code = PALETTERGB(rv, gv, bv);
2212 /* Activate changes */
2213 if (win_clr[i] != code)
2215 /* Note the change */
2218 /* Apply the desired color */
2223 /* Activate the palette if needed */
2224 if (change) (void)new_palette();
2230 /* Handle "arg_sound" */
2231 if (use_sound != arg_sound)
2233 /* Initialize (if needed) */
2234 if (arg_sound && !init_sound())
2237 plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
2243 /* Change setting */
2244 use_sound = arg_sound;
2251 /* Handle "arg_sound" */
2252 if (use_music != arg_music)
2254 /* Initialize (if needed) */
2255 if (arg_music && !init_music())
2258 plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
2263 /* Change setting */
2264 use_music = arg_music;
2266 if(!arg_music) stop_music();
2267 else select_floor_music();
2276 /* Handle "arg_graphics" */
2277 if (use_graphics != arg_graphics)
2279 /* Initialize (if needed) */
2280 if (arg_graphics && !init_graphics())
2283 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
2286 arg_graphics = GRAPHICS_NONE;
2289 /* Change setting */
2290 use_graphics = arg_graphics;
2293 #ifdef ANGBAND_2_8_1
2295 #else /* ANGBAND_2_8_1 */
2296 reset_visuals(TRUE);
2297 #endif /* ANGBAND_2_8_1 */
2300 #endif /* USE_GRAPHICS */
2303 /* Clean up windows */
2304 for (i = 0; i < MAX_TERM_DATA; i++)
2308 term_data *td = &data[i];
2310 /* Update resized windows */
2311 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2314 Term_activate(&td->t);
2316 /* Hack -- Resize the term */
2317 Term_resize(td->cols, td->rows);
2319 /* Redraw the contents */
2334 * Process at least one event
2336 static errr Term_xtra_win_event(int v)
2340 /* Wait for an event */
2344 if (GetMessage(&msg, NULL, 0, 0))
2346 TranslateMessage(&msg);
2347 DispatchMessage(&msg);
2351 /* Check for an event */
2355 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2357 TranslateMessage(&msg);
2358 DispatchMessage(&msg);
2368 * Process all pending events
2370 static errr Term_xtra_win_flush(void)
2374 /* Process all pending events */
2375 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2377 TranslateMessage(&msg);
2378 DispatchMessage(&msg);
2387 * Hack -- clear the screen
2389 * Make this more efficient XXX XXX XXX
2391 static errr Term_xtra_win_clear(void)
2393 term_data *td = (term_data*)(Term->data);
2398 /* Rectangle to erase */
2399 rc.left = td->size_ow1;
2400 rc.right = rc.left + td->cols * td->tile_wid;
2401 rc.top = td->size_oh1;
2402 rc.bottom = rc.top + td->rows * td->tile_hgt;
2406 SetBkColor(hdc, RGB(0, 0, 0));
2407 SelectObject(hdc, td->font_id);
2408 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2413 rc.left = 0; rc.top = 0;
2416 ReleaseDC(td->w, hdc);
2424 * Hack -- make a noise
2426 static errr Term_xtra_win_noise(void)
2428 MessageBeep(MB_ICONASTERISK);
2434 * Hack -- make a sound
2436 static errr Term_xtra_win_sound(int v)
2441 #endif /* USE_SOUND */
2443 /* Sound disabled */
2444 if (!use_sound) return (1);
2447 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2451 /* Count the samples */
2452 for (i = 0; i < SAMPLE_MAX; i++)
2454 if (!sound_file[v][i])
2459 if (i == 0) return (1);
2461 /* Build the path */
2462 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2466 /* Play the sound, catch errors */
2467 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2471 /* Play the sound, catch errors */
2472 return (sndPlaySound(buf, SND_ASYNC));
2476 #else /* USE_SOUND */
2481 #endif /* USE_SOUND */
2485 * Hack -- play a music
2487 static errr Term_xtra_win_music(int n, int v)
2492 #endif /* USE_MUSIC */
2494 /* Sound disabled */
2496 if(!use_music) return (1);
2499 if(n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return (1);
2500 else if(v < 0 || v >= 1000) return(1); /*!< TODO */
2506 case TERM_XTRA_MUSIC_BASIC:
2507 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2509 case TERM_XTRA_MUSIC_DUNGEON:
2510 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2512 case TERM_XTRA_MUSIC_QUEST:
2513 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2515 case TERM_XTRA_MUSIC_TOWN:
2516 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2523 //mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2524 //mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2530 case TERM_XTRA_MUSIC_BASIC:
2531 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2533 case TERM_XTRA_MUSIC_DUNGEON:
2534 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2536 case TERM_XTRA_MUSIC_QUEST:
2537 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2539 case TERM_XTRA_MUSIC_TOWN:
2540 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2547 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2548 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2554 case TERM_XTRA_MUSIC_BASIC:
2555 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2557 case TERM_XTRA_MUSIC_DUNGEON:
2558 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2560 case TERM_XTRA_MUSIC_QUEST:
2561 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2563 case TERM_XTRA_MUSIC_TOWN:
2564 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2568 if(current_music_type == n && current_music_id == v)
2572 current_music_type = n;
2573 current_music_id = v;
2577 mop.lpstrDeviceType = mci_device_type;
2578 mop.lpstrElementName = buf;
2579 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2580 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2581 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2582 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2583 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2588 #else /* USE_MUSIC */
2592 #endif /* USE_MUSIC */
2598 * Delay for "x" milliseconds
2600 static int Term_xtra_win_delay(int v)
2614 t = GetTickCount() + v;
2617 while (GetTickCount() < t)
2619 /* Handle messages */
2620 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2622 TranslateMessage(&msg);
2623 DispatchMessage(&msg);
2635 * Do a "special thing"
2637 static errr Term_xtra_win(int n, int v)
2639 /* Handle a subset of the legal requests */
2642 /* Make a bell sound */
2643 case TERM_XTRA_NOISE:
2645 return (Term_xtra_win_noise());
2649 case TERM_XTRA_MUSIC_BASIC:
2650 case TERM_XTRA_MUSIC_DUNGEON:
2651 case TERM_XTRA_MUSIC_QUEST:
2652 case TERM_XTRA_MUSIC_TOWN:
2654 return (Term_xtra_win_music(n, v));
2657 /* Make a special sound */
2658 case TERM_XTRA_SOUND:
2660 return (Term_xtra_win_sound(v));
2663 /* Process random events */
2664 case TERM_XTRA_BORED:
2666 return (Term_xtra_win_event(0));
2669 /* Process an event */
2670 case TERM_XTRA_EVENT:
2672 return (Term_xtra_win_event(v));
2675 /* Flush all events */
2676 case TERM_XTRA_FLUSH:
2678 return (Term_xtra_win_flush());
2681 /* Clear the screen */
2682 case TERM_XTRA_CLEAR:
2684 return (Term_xtra_win_clear());
2687 /* React to global changes */
2688 case TERM_XTRA_REACT:
2690 return (Term_xtra_win_react());
2693 /* Delay for some milliseconds */
2694 case TERM_XTRA_DELAY:
2696 return (Term_xtra_win_delay(v));
2707 * Low level graphics (Assumes valid input).
2709 * Draw a "cursor" at (x,y), using a "yellow box".
2711 static errr Term_curs_win(int x, int y)
2713 term_data *td = (term_data*)(Term->data);
2718 int tile_wid, tile_hgt;
2722 tile_wid = td->map_tile_wid;
2723 tile_hgt = td->map_tile_hgt;
2727 tile_wid = td->tile_wid;
2728 tile_hgt = td->tile_hgt;
2731 /* Frame the grid */
2732 rc.left = x * tile_wid + td->size_ow1;
2733 rc.right = rc.left + tile_wid;
2734 rc.top = y * tile_hgt + td->size_oh1;
2735 rc.bottom = rc.top + tile_hgt;
2737 /* Cursor is done as a yellow "box" */
2739 FrameRect(hdc, &rc, hbrYellow);
2740 ReleaseDC(td->w, hdc);
2748 * Low level graphics (Assumes valid input).
2750 * Draw a "big cursor" at (x,y), using a "yellow box".
2752 static errr Term_bigcurs_win(int x, int y)
2754 term_data *td = (term_data*)(Term->data);
2759 int tile_wid, tile_hgt;
2763 /* Normal cursor in map window */
2764 Term_curs_win(x, y);
2769 tile_wid = td->tile_wid;
2770 tile_hgt = td->tile_hgt;
2773 /* Frame the grid */
2774 rc.left = x * tile_wid + td->size_ow1;
2775 rc.right = rc.left + 2 * tile_wid;
2776 rc.top = y * tile_hgt + td->size_oh1;
2777 rc.bottom = rc.top + tile_hgt;
2779 /* Cursor is done as a yellow "box" */
2781 FrameRect(hdc, &rc, hbrYellow);
2782 ReleaseDC(td->w, hdc);
2790 * Low level graphics (Assumes valid input).
2792 * Erase a "block" of "n" characters starting at (x,y).
2794 static errr Term_wipe_win(int x, int y, int n)
2796 term_data *td = (term_data*)(Term->data);
2801 /* Rectangle to erase in client coords */
2802 rc.left = x * td->tile_wid + td->size_ow1;
2803 rc.right = rc.left + n * td->tile_wid;
2804 rc.top = y * td->tile_hgt + td->size_oh1;
2805 rc.bottom = rc.top + td->tile_hgt;
2808 SetBkColor(hdc, RGB(0, 0, 0));
2809 SelectObject(hdc, td->font_id);
2814 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2815 ReleaseDC(td->w, hdc);
2823 * Low level graphics. Assumes valid input.
2825 * Draw several ("n") chars, with an attr, at a given location.
2827 * All "graphic" data is handled by "Term_pict_win()", below.
2829 * One would think there is a more efficient method for telling a window
2830 * what color it should be using to draw with, but perhaps simply changing
2831 * it every time is not too inefficient. XXX XXX XXX
2833 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2835 term_data *td = (term_data*)(Term->data);
2839 #if 1 /* #ifdef JP */
2840 static HBITMAP WALL;
2841 static HBRUSH myBrush, oldBrush;
2843 static bool init_done = FALSE;
2846 WALL = LoadBitmap(hInstance, AppName);
2847 myBrush = CreatePatternBrush(WALL);
2852 /* Total rectangle */
2853 rc.left = x * td->tile_wid + td->size_ow1;
2854 rc.right = rc.left + n * td->tile_wid;
2855 rc.top = y * td->tile_hgt + td->size_oh1;
2856 rc.bottom = rc.top + td->tile_hgt;
2861 /* Background color */
2862 SetBkColor(hdc, RGB(0, 0, 0));
2864 /* Foreground color */
2867 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2871 SetTextColor(hdc, win_clr[a&0x0F]);
2875 SetTextColor(hdc, win_clr[a]);
2879 SelectObject(hdc, td->font_id);
2882 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2886 (td->tile_hgt != td->font_hgt) ||
2887 (td->tile_wid != td->font_wid))
2891 /* Erase complete rectangle */
2892 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2895 if (use_bg) DrawBG(hdc, &rc);
2898 rc.left += ((td->tile_wid - td->font_wid) / 2);
2899 rc.right = rc.left + td->font_wid;
2900 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2901 rc.bottom = rc.top + td->font_hgt;
2903 /* Dump each character */
2904 for (i = 0; i < n; i++)
2907 if (use_bigtile && *(s+i)=="■"[0] && *(s+i+1)=="■"[1])
2909 rc.right += td->font_wid;
2911 oldBrush = SelectObject(hdc, myBrush);
2912 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2915 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2917 SelectObject(hdc, oldBrush);
2918 SelectObject(hdc, oldPen);
2919 rc.right -= td->font_wid;
2923 rc.left += 2 * td->tile_wid;
2924 rc.right += 2 * td->tile_wid;
2926 else if ( iskanji(*(s+i)) ) /* 2バイト文字 */
2928 rc.right += td->font_wid;
2930 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2932 rc.right -= td->font_wid;
2936 rc.left += 2 * td->tile_wid;
2937 rc.right += 2 * td->tile_wid;
2938 } else if (*(s+i)==127){
2939 oldBrush = SelectObject(hdc, myBrush);
2940 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2943 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2945 SelectObject(hdc, oldBrush);
2946 SelectObject(hdc, oldPen);
2949 rc.left += td->tile_wid;
2950 rc.right += td->tile_wid;
2953 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2956 rc.left += td->tile_wid;
2957 rc.right += td->tile_wid;
2962 oldBrush = SelectObject(hdc, myBrush);
2963 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2966 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2968 SelectObject(hdc, oldBrush);
2969 SelectObject(hdc, oldPen);
2972 rc.left += td->tile_wid;
2973 rc.right += td->tile_wid;
2976 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2980 rc.left += td->tile_wid;
2981 rc.right += td->tile_wid;
2985 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2989 rc.left += td->tile_wid;
2990 rc.right += td->tile_wid;
3001 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
3006 ReleaseDC(td->w, hdc);
3014 * Low level graphics. Assumes valid input.
3016 * Draw an array of "special" attr/char pairs at the given location.
3018 * We use the "Term_pict_win()" function for "graphic" data, which are
3019 * encoded by setting the "high-bits" of both the "attr" and the "char"
3020 * data. We use the "attr" to represent the "row" of the main bitmap,
3021 * and the "char" to represent the "col" of the main bitmap. The use
3022 * of this function is induced by the "higher_pict" flag.
3024 * If "graphics" is not available, we simply "wipe" the given grids.
3026 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
3028 term_data *td = (term_data*)(Term->data);
3033 int x1, y1, w1, h1, tw1, th1;
3034 int x2, y2, w2, h2, tw2 = 0;
3046 /* Erase the grids */
3047 return (Term_wipe_win(x, y, n));
3050 /* Size of bitmap cell */
3051 w1 = infGraph.CellWidth;
3052 h1 = infGraph.CellHeight;
3053 tw1 = infGraph.TileWidth;
3054 th1 = infGraph.TileHeight;
3056 /* Size of window cell */
3059 w2 = td->map_tile_wid;
3060 h2 = td->map_tile_hgt;
3069 if (use_bigtile) tw2 *= 2;
3072 /* Location of window cell */
3073 x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
3074 y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
3080 hdcSrc = CreateCompatibleDC(hdc);
3081 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
3083 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3085 hdcMask = CreateCompatibleDC(hdc);
3086 SelectObject(hdcMask, infMask.hBitmap);
3089 /* Draw attr/char pairs */
3090 for (i = 0; i < n; i++, x2 += w2)
3096 /* Extract picture */
3097 int row = (a & 0x7F);
3098 int col = (c & 0x7F);
3100 /* Location of bitmap cell */
3104 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3106 x3 = (tcp[i] & 0x7F) * w1;
3107 y3 = (tap[i] & 0x7F) * h1;
3108 tw2 = tw2 * w1 / tw1;
3112 if ((tw1 == tw2) && (th1 == h2))
3114 /* Copy the terrain picture from the bitmap to the window */
3115 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
3117 /* Mask out the tile */
3118 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3121 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3124 /* Need to stretch */
3127 /* Set the correct mode for stretching the tiles */
3128 SetStretchBltMode(hdc, COLORONCOLOR);
3130 /* Copy the terrain picture from the bitmap to the window */
3131 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
3133 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
3135 /* Only draw if terrain and overlay are different */
3136 if ((x1 != x3) || (y1 != y3))
3138 /* Mask out the tile */
3139 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3142 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3149 if ((w1 == tw2) && (h1 == h2))
3151 /* Copy the picture from the bitmap to the window */
3152 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3155 /* Need to stretch */
3158 /* Set the correct mode for stretching the tiles */
3159 SetStretchBltMode(hdc, COLORONCOLOR);
3161 /* Copy the picture from the bitmap to the window */
3162 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3168 SelectObject(hdcSrc, hbmSrcOld);
3171 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3174 SelectObject(hdcMask, hbmSrcOld);
3179 ReleaseDC(td->w, hdc);
3181 #else /* USE_GRAPHICS */
3183 /* Just erase this grid */
3184 return (Term_wipe_win(x, y, n));
3186 #endif /* USE_GRAPHICS */
3193 static void windows_map(void)
3195 term_data *td = &data[0];
3197 int x, min_x, max_x;
3198 int y, min_y, max_y;
3202 /* Only in graphics mode */
3203 if (!use_graphics) return;
3206 Term_xtra_win_clear();
3208 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3209 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3210 td->map_active = TRUE;
3220 for (x = min_x; x < max_x; x++)
3222 for (y = min_y; y < max_y; y++)
3224 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3226 /* Ignore non-graphics */
3227 if ((a & 0x80) && (c & 0x80))
3229 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3234 /* Hilite the player */
3235 Term_curs_win(p_ptr->x - min_x, p_ptr->y - min_y);
3237 /* Wait for a keypress, flush key buffer */
3238 Term_inkey(&c, TRUE, TRUE);
3241 /* Switch off the map display */
3242 td->map_active = FALSE;
3244 /* Restore screen */
3245 Term_xtra_win_clear();
3250 /*** Other routines ***/
3254 * Create and initialize a "term_data" given a title
3256 static void term_data_link(term_data *td)
3260 /* Initialize the term */
3261 term_init(t, td->cols, td->rows, td->keys);
3263 /* Use a "software" cursor */
3264 t->soft_cursor = TRUE;
3266 /* Use "Term_pict" for "graphic" data */
3267 t->higher_pict = TRUE;
3269 /* Erase with "white space" */
3270 t->attr_blank = TERM_WHITE;
3271 t->char_blank = ' ';
3274 /* Prepare the init/nuke hooks */
3275 t->init_hook = Term_init_win;
3276 t->nuke_hook = Term_nuke_win;
3279 /* Prepare the template hooks */
3280 t->user_hook = Term_user_win;
3281 t->xtra_hook = Term_xtra_win;
3282 t->curs_hook = Term_curs_win;
3283 t->bigcurs_hook = Term_bigcurs_win;
3284 t->wipe_hook = Term_wipe_win;
3285 t->text_hook = Term_text_win;
3286 t->pict_hook = Term_pict_win;
3288 /* Remember where we came from */
3289 t->data = (vptr)(td);
3294 * Create the windows
3296 * First, instantiate the "default" values, then read the "ini_file"
3297 * to over-ride selected values, then create the windows, and fonts.
3299 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3300 * must make active to realize the palette. XXX XXX XXX
3302 static void init_windows(void)
3308 #if 0 /* #ifndef JP */
3314 WIPE(td, term_data);
3318 td->s = angband_term_name[0];
3332 #if 1 /* #ifdef JP */
3336 for (i = 1; i < MAX_TERM_DATA; i++)
3339 WIPE(td, term_data);
3340 td->s = angband_term_name[i];
3344 td->visible = FALSE;
3349 td->pos_x = (7 - i) * 30;
3350 td->pos_y = (7 - i) * 20;
3352 #if 1 /* #ifdef JP */
3362 /* Main window (need these before term_getsize gets called) */
3364 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3365 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3370 /* Sub windows (need these before term_getsize gets called) */
3371 for (i = 1; i < MAX_TERM_DATA; i++)
3374 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3375 td->dwExStyle = (WS_EX_TOOLWINDOW);
3380 for (i = 0; i < MAX_TERM_DATA; i++)
3384 #if 1 /* #ifdef JP */
3385 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3386 td->lf.lfCharSet = DEFAULT_CHARSET;
3387 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3388 /* Activate the chosen font */
3389 term_force_font(td, NULL);
3390 if(!td->tile_wid) td->tile_wid = td->font_wid;
3391 if(!td->tile_hgt) td->tile_hgt = td->font_hgt;
3393 /* Access the standard font file */
3394 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3396 /* Activate the chosen font */
3397 if (term_force_font(td, buf))
3399 /* Access the standard font file */
3400 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3402 /* Force the use of that font */
3403 (void)term_force_font(td, buf);
3409 /* Assume not bizarre */
3410 td->bizarre = FALSE;
3415 /* Analyze the font */
3418 /* Resize the window */
3419 term_window_resize(td);
3423 /* Sub windows (reverse order) */
3424 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3429 td->w = CreateWindowEx(td->dwExStyle, AngList,
3431 td->pos_x, td->pos_y,
3432 td->size_wid, td->size_hgt,
3433 HWND_DESKTOP, NULL, hInstance, NULL);
3435 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3439 td->size_hack = TRUE;
3440 ShowWindow(td->w, SW_SHOW);
3441 td->size_hack = FALSE;
3445 angband_term[i] = &td->t;
3449 /* Activate the window */
3450 SetActiveWindow(td->w);
3455 term_window_pos(&data[i], HWND_TOPMOST);
3459 term_window_pos(&data[i], td->w);
3469 td->w = CreateWindowEx(td->dwExStyle, AppName,
3471 td->pos_x, td->pos_y,
3472 td->size_wid, td->size_hgt,
3473 HWND_DESKTOP, NULL, hInstance, NULL);
3475 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3478 angband_term[0] = &td->t;
3479 normsize.x = td->cols;
3480 normsize.y = td->rows;
3482 /* Activate the main window */
3483 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3484 else ShowWindow(td->w, SW_SHOW);
3486 /* Bring main window back to top */
3487 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3490 /* New palette XXX XXX XXX */
3491 (void)new_palette();
3494 /* Create a "brush" for drawing the "cursor" */
3495 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3498 /* Process pending messages */
3499 (void)Term_xtra_win_flush();
3507 static void setup_menus(void)
3511 HMENU hm = GetMenu(data[0].w);
3514 /* Menu "File", Disable all */
3515 EnableMenuItem(hm, IDM_FILE_NEW,
3516 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3517 EnableMenuItem(hm, IDM_FILE_OPEN,
3518 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3519 EnableMenuItem(hm, IDM_FILE_SAVE,
3520 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3521 EnableMenuItem(hm, IDM_FILE_EXIT,
3522 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3523 EnableMenuItem(hm, IDM_FILE_SCORE,
3524 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3527 /* No character available */
3528 if (!character_generated)
3530 /* Menu "File", Item "New" */
3531 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3533 /* Menu "File", Item "Open" */
3534 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3537 /* A character available */
3538 if (character_generated)
3540 /* Menu "File", Item "Save" */
3541 EnableMenuItem(hm, IDM_FILE_SAVE,
3542 MF_BYCOMMAND | MF_ENABLED);
3545 /* Menu "File", Item "Exit" */
3546 EnableMenuItem(hm, IDM_FILE_EXIT,
3547 MF_BYCOMMAND | MF_ENABLED);
3549 EnableMenuItem(hm, IDM_FILE_SCORE,
3550 MF_BYCOMMAND | MF_ENABLED);
3553 /* Menu "Window::Visibility" */
3554 for (i = 0; i < MAX_TERM_DATA; i++)
3556 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3557 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3559 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3560 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3562 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3563 MF_BYCOMMAND | MF_ENABLED);
3566 /* Menu "Window::Font" */
3567 for (i = 0; i < MAX_TERM_DATA; i++)
3569 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3570 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3572 if (data[i].visible)
3574 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3575 MF_BYCOMMAND | MF_ENABLED);
3579 /* Menu "Window::Window Position Fix" */
3580 for (i = 0; i < MAX_TERM_DATA; i++)
3582 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3583 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3585 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3586 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3588 if (data[i].visible)
3590 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3591 MF_BYCOMMAND | MF_ENABLED);
3595 /* Menu "Window::Bizarre Display" */
3596 for (i = 0; i < MAX_TERM_DATA; i++)
3598 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3599 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3601 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3602 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3604 if (data[i].visible)
3606 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3607 MF_BYCOMMAND | MF_ENABLED);
3612 /* Menu "Window::Increase Tile Width" */
3613 for (i = 0; i < MAX_TERM_DATA; i++)
3615 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3616 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3618 if (data[i].visible)
3620 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3621 MF_BYCOMMAND | MF_ENABLED);
3626 /* Menu "Window::Decrease Tile Width" */
3627 for (i = 0; i < MAX_TERM_DATA; i++)
3629 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3630 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3632 if (data[i].visible)
3634 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3635 MF_BYCOMMAND | MF_ENABLED);
3640 /* Menu "Window::Increase Tile Height" */
3641 for (i = 0; i < MAX_TERM_DATA; i++)
3643 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3644 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3646 if (data[i].visible)
3648 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3649 MF_BYCOMMAND | MF_ENABLED);
3654 /* Menu "Window::Decrease Tile Height" */
3655 for (i = 0; i < MAX_TERM_DATA; i++)
3657 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3658 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3660 if (data[i].visible)
3662 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3663 MF_BYCOMMAND | MF_ENABLED);
3668 /* Menu "Options", disable all */
3669 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3670 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3671 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3672 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3673 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3674 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3675 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3676 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3677 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3678 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3680 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3681 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3684 /* Menu "Options", Item "Map" */
3685 if (use_graphics != GRAPHICS_NONE)
3686 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3688 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3689 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3691 /* Menu "Options", update all */
3692 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3693 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3694 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3695 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3696 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3697 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3698 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3699 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3700 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3701 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3702 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3703 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3704 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3705 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3706 CheckMenuItem(hm, IDM_OPTIONS_BG,
3707 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3709 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3710 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3714 /* Menu "Options", Item "Graphics" */
3715 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3716 /* Menu "Options", Item "Graphics" */
3717 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3718 /* Menu "Options", Item "Graphics" */
3719 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3720 /* Menu "Options", Item "Graphics" */
3721 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3722 #endif /* USE_GRAPHICS */
3725 /* Menu "Options", Item "Sound" */
3726 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3727 #endif /* USE_SOUND */
3730 /* Menu "Options", Item "ScreenSaver" */
3731 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3732 MF_BYCOMMAND | MF_ENABLED);
3733 #endif /* USE_SAVER */
3738 * Check for double clicked (or dragged) savefile
3740 * Apparently, Windows copies the entire filename into the first
3741 * piece of the "command line string". Perhaps we should extract
3742 * the "basename" of that filename and append it to the "save" dir.
3744 static void check_for_save_file(LPSTR cmd_line)
3754 /* Extract filename */
3755 strcat(savefile, s);
3757 /* Validate the file */
3758 validate_file(savefile);
3760 /* Game in progress */
3761 game_in_progress = TRUE;
3769 * Process a menu command
3771 static void process_menus(WORD wCmd)
3787 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3789 else if (game_in_progress)
3791 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3795 game_in_progress = TRUE;
3808 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3810 else if (game_in_progress)
3812 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3816 memset(&ofn, 0, sizeof(ofn));
3817 ofn.lStructSize = sizeof(ofn);
3818 ofn.hwndOwner = data[0].w;
3819 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3820 ofn.nFilterIndex = 1;
3821 ofn.lpstrFile = savefile;
3822 ofn.nMaxFile = 1024;
3823 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3824 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3826 if (GetOpenFileName(&ofn))
3828 /* Load 'savefile' */
3829 validate_file(savefile);
3830 game_in_progress = TRUE;
3842 if (game_in_progress && character_generated)
3847 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3851 /* Hack -- Forget messages */
3856 do_cmd_save_game(FALSE);
3857 #else /* ZANGBAND */
3859 #endif /* ZANGBAND */
3863 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3871 if (game_in_progress && character_generated)
3876 plog(_("今は終了できません。", "You may not do that right now."));
3880 /* Hack -- Forget messages */
3889 /* do_cmd_save_game(FALSE); */
3890 #else /* ZANGBAND */
3891 /* do_cmd_save_game(); */
3892 #endif /* ZANGBAND */
3893 Term_key_push(SPECIAL_KEY_QUIT);
3901 case IDM_FILE_SCORE:
3905 /* Build the filename */
3906 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3908 /* Open the binary high score file, for reading */
3909 highscore_fd = fd_open(buf, O_RDONLY);
3911 /* Paranoia -- No score file */
3912 if (highscore_fd < 0)
3914 msg_print("Score file unavailable.");
3924 /* Display the scores */
3925 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3927 /* Shut the high score file */
3928 (void)fd_close(highscore_fd);
3930 /* Forget the high score fd */
3936 /* Hack - Flush it */
3944 case IDM_FILE_MOVIE:
3948 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3950 else if (game_in_progress)
3952 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
3956 memset(&ofn, 0, sizeof(ofn));
3957 ofn.lStructSize = sizeof(ofn);
3958 ofn.hwndOwner = data[0].w;
3959 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3960 ofn.nFilterIndex = 1;
3961 ofn.lpstrFile = savefile;
3962 ofn.nMaxFile = 1024;
3963 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3964 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3966 if (GetOpenFileName(&ofn))
3968 /* Load 'savefile' */
3969 prepare_browse_movie_aux(savefile);
3979 case IDM_WINDOW_VIS_0:
3981 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
3985 /* Window visibility */
3986 case IDM_WINDOW_VIS_1:
3987 case IDM_WINDOW_VIS_2:
3988 case IDM_WINDOW_VIS_3:
3989 case IDM_WINDOW_VIS_4:
3990 case IDM_WINDOW_VIS_5:
3991 case IDM_WINDOW_VIS_6:
3992 case IDM_WINDOW_VIS_7:
3994 i = wCmd - IDM_WINDOW_VIS_0;
3996 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4003 ShowWindow(td->w, SW_SHOW);
4004 term_data_redraw(td);
4008 td->visible = FALSE;
4010 ShowWindow(td->w, SW_HIDE);
4017 case IDM_WINDOW_FONT_0:
4018 case IDM_WINDOW_FONT_1:
4019 case IDM_WINDOW_FONT_2:
4020 case IDM_WINDOW_FONT_3:
4021 case IDM_WINDOW_FONT_4:
4022 case IDM_WINDOW_FONT_5:
4023 case IDM_WINDOW_FONT_6:
4024 case IDM_WINDOW_FONT_7:
4026 i = wCmd - IDM_WINDOW_FONT_0;
4028 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4032 term_change_font(td);
4037 /* Window Z Position */
4038 case IDM_WINDOW_POS_1:
4039 case IDM_WINDOW_POS_2:
4040 case IDM_WINDOW_POS_3:
4041 case IDM_WINDOW_POS_4:
4042 case IDM_WINDOW_POS_5:
4043 case IDM_WINDOW_POS_6:
4044 case IDM_WINDOW_POS_7:
4046 i = wCmd - IDM_WINDOW_POS_0;
4048 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4052 if (!td->posfix && td->visible)
4055 term_window_pos(td, HWND_TOPMOST);
4060 term_window_pos(td, data[0].w);
4066 /* Bizarre Display */
4067 case IDM_WINDOW_BIZ_0:
4068 case IDM_WINDOW_BIZ_1:
4069 case IDM_WINDOW_BIZ_2:
4070 case IDM_WINDOW_BIZ_3:
4071 case IDM_WINDOW_BIZ_4:
4072 case IDM_WINDOW_BIZ_5:
4073 case IDM_WINDOW_BIZ_6:
4074 case IDM_WINDOW_BIZ_7:
4076 i = wCmd - IDM_WINDOW_BIZ_0;
4078 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4082 td->bizarre = !td->bizarre;
4086 term_window_resize(td);
4091 /* Increase Tile Width */
4092 case IDM_WINDOW_I_WID_0:
4093 case IDM_WINDOW_I_WID_1:
4094 case IDM_WINDOW_I_WID_2:
4095 case IDM_WINDOW_I_WID_3:
4096 case IDM_WINDOW_I_WID_4:
4097 case IDM_WINDOW_I_WID_5:
4098 case IDM_WINDOW_I_WID_6:
4099 case IDM_WINDOW_I_WID_7:
4101 i = wCmd - IDM_WINDOW_I_WID_0;
4103 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4111 term_window_resize(td);
4116 /* Decrease Tile Height */
4117 case IDM_WINDOW_D_WID_0:
4118 case IDM_WINDOW_D_WID_1:
4119 case IDM_WINDOW_D_WID_2:
4120 case IDM_WINDOW_D_WID_3:
4121 case IDM_WINDOW_D_WID_4:
4122 case IDM_WINDOW_D_WID_5:
4123 case IDM_WINDOW_D_WID_6:
4124 case IDM_WINDOW_D_WID_7:
4126 i = wCmd - IDM_WINDOW_D_WID_0;
4128 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4136 term_window_resize(td);
4141 /* Increase Tile Height */
4142 case IDM_WINDOW_I_HGT_0:
4143 case IDM_WINDOW_I_HGT_1:
4144 case IDM_WINDOW_I_HGT_2:
4145 case IDM_WINDOW_I_HGT_3:
4146 case IDM_WINDOW_I_HGT_4:
4147 case IDM_WINDOW_I_HGT_5:
4148 case IDM_WINDOW_I_HGT_6:
4149 case IDM_WINDOW_I_HGT_7:
4151 i = wCmd - IDM_WINDOW_I_HGT_0;
4153 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4161 term_window_resize(td);
4166 /* Decrease Tile Height */
4167 case IDM_WINDOW_D_HGT_0:
4168 case IDM_WINDOW_D_HGT_1:
4169 case IDM_WINDOW_D_HGT_2:
4170 case IDM_WINDOW_D_HGT_3:
4171 case IDM_WINDOW_D_HGT_4:
4172 case IDM_WINDOW_D_HGT_5:
4173 case IDM_WINDOW_D_HGT_6:
4174 case IDM_WINDOW_D_HGT_7:
4176 i = wCmd - IDM_WINDOW_D_HGT_0;
4178 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4186 term_window_resize(td);
4191 case IDM_OPTIONS_NO_GRAPHICS:
4196 plog("You may not do that right now.");
4200 /* Toggle "arg_graphics" */
4201 if (arg_graphics != GRAPHICS_NONE)
4203 arg_graphics = GRAPHICS_NONE;
4205 /* React to changes */
4206 Term_xtra_win_react();
4208 /* Hack -- Force redraw */
4209 Term_key_push(KTRL('R'));
4215 case IDM_OPTIONS_OLD_GRAPHICS:
4220 plog("You may not do that right now.");
4224 /* Toggle "arg_graphics" */
4225 if (arg_graphics != GRAPHICS_ORIGINAL)
4227 arg_graphics = GRAPHICS_ORIGINAL;
4229 /* React to changes */
4230 Term_xtra_win_react();
4232 /* Hack -- Force redraw */
4233 Term_key_push(KTRL('R'));
4239 case IDM_OPTIONS_NEW_GRAPHICS:
4244 plog("You may not do that right now.");
4248 /* Toggle "arg_graphics" */
4249 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4251 arg_graphics = GRAPHICS_ADAM_BOLT;
4253 /* React to changes */
4254 Term_xtra_win_react();
4256 /* Hack -- Force redraw */
4257 Term_key_push(KTRL('R'));
4263 case IDM_OPTIONS_NEW2_GRAPHICS:
4268 plog("You may not do that right now.");
4272 /* Toggle "arg_graphics" */
4273 if (arg_graphics != GRAPHICS_HENGBAND)
4275 arg_graphics = GRAPHICS_HENGBAND;
4277 /* React to changes */
4278 Term_xtra_win_react();
4280 /* Hack -- Force redraw */
4281 Term_key_push(KTRL('R'));
4287 case IDM_OPTIONS_BIGTILE:
4289 term_data *td = &data[0];
4294 plog("You may not do that right now.");
4298 /* Toggle "arg_sound" */
4299 arg_bigtile = !arg_bigtile;
4302 Term_activate(&td->t);
4304 /* Resize the term */
4305 Term_resize(td->cols, td->rows);
4308 InvalidateRect(td->w, NULL, TRUE);
4313 case IDM_OPTIONS_MUSIC:
4318 plog("You may not do that right now.");
4322 /* Toggle "arg_sound" */
4323 arg_music = !arg_music;
4325 /* React to changes */
4326 Term_xtra_win_react();
4328 /* Hack -- Force redraw */
4329 Term_key_push(KTRL('R'));
4334 case IDM_OPTIONS_SOUND:
4339 plog("You may not do that right now.");
4343 /* Toggle "arg_sound" */
4344 arg_sound = !arg_sound;
4346 /* React to changes */
4347 Term_xtra_win_react();
4349 /* Hack -- Force redraw */
4350 Term_key_push(KTRL('R'));
4356 case IDM_OPTIONS_BG:
4361 plog("You may not do that right now.");
4365 /* Toggle "use_bg" */
4370 /* React to changes */
4371 Term_xtra_win_react();
4373 /* Hack -- Force redraw */
4374 Term_key_push(KTRL('R'));
4380 case IDM_OPTIONS_OPEN_BG:
4385 plog("You may not do that right now.");
4390 memset(&ofn, 0, sizeof(ofn));
4391 ofn.lStructSize = sizeof(ofn);
4392 ofn.hwndOwner = data[0].w;
4393 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4394 ofn.nFilterIndex = 1;
4395 ofn.lpstrFile = bg_bitmap_file;
4396 ofn.nMaxFile = 1023;
4397 ofn.lpstrInitialDir = NULL;
4398 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
4399 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4401 if (GetOpenFileName(&ofn))
4403 /* Load 'savefile' */
4408 /* React to changes */
4409 Term_xtra_win_react();
4411 /* Hack -- Force redraw */
4412 Term_key_push(KTRL('R'));
4417 case IDM_DUMP_SCREEN_HTML:
4419 static char buf[1024] = "";
4420 memset(&ofn, 0, sizeof(ofn));
4421 ofn.lStructSize = sizeof(ofn);
4422 ofn.hwndOwner = data[0].w;
4423 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4424 ofn.nFilterIndex = 1;
4425 ofn.lpstrFile = buf;
4426 ofn.nMaxFile = 1023;
4427 ofn.lpstrDefExt = "html";
4428 ofn.lpstrInitialDir = NULL;
4429 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
4430 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4432 if (GetSaveFileName(&ofn))
4434 do_cmd_save_screen_html_aux(buf, 0);
4441 case IDM_OPTIONS_SAVER:
4445 DestroyWindow(hwndSaver);
4450 /* Create a screen scaver window */
4451 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4452 "Angband Screensaver",
4453 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4454 0, 0, GetSystemMetrics(SM_CXSCREEN),
4455 GetSystemMetrics(SM_CYSCREEN),
4456 NULL, NULL, hInstance, NULL);
4460 /* Push the window to the bottom XXX XXX XXX */
4461 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4465 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
4473 case IDM_OPTIONS_MAP:
4479 case IDM_HELP_CONTENTS:
4483 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4484 if (check_file(tmp))
4486 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4491 plog_fmt("ヘルプファイル[%s]が見付かりません。", tmp);
4492 plog("代わりにオンラインヘルプを使用してください。");
4494 plog_fmt("Cannot find help file: %s", tmp);
4495 plog("Use the online help files instead.");
4500 #else /* HTML_HELP */
4503 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4504 if (check_file(tmp))
4506 sprintf(buf, "winhelp.exe %s", tmp);
4507 WinExec(buf, SW_NORMAL);
4512 plog_fmt("ヘルプファイル[%s]が見付かりません。", tmp);
4513 plog("代わりにオンラインヘルプを使用してください。");
4515 plog_fmt("Cannot find help file: %s", tmp);
4516 plog("Use the online help files instead.");
4521 #endif /* HTML_HELP */
4527 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4534 /* Extract the modifiers */
4535 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4536 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4537 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4539 Term_no_press = (ma) ? TRUE : FALSE;
4541 /* Handle "special" keys */
4542 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4544 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4545 bool numpad = FALSE;
4547 /* Begin the macro trigger */
4550 /* Send the modifiers */
4551 if (mc) Term_keypress('C');
4552 if (ms) Term_keypress('S');
4553 if (ma) Term_keypress('A');
4555 /* Extract "scan code" */
4556 i = LOBYTE(HIWORD(lParam));
4558 /* Introduce the scan code */
4561 /* Extended key bit */
4564 /* Numpad Enter and '/' are extended key */
4566 Term_no_press = TRUE;
4567 case VK_RETURN: /* Enter */
4570 /* Other extended keys are on full keyboard */
4586 Term_no_press = TRUE;
4590 case VK_PRIOR: /* Page Up */
4591 case VK_NEXT: /* Page Down */
4601 /* Special modifiers for keypad keys */
4602 if (numpad) Term_keypress('K');
4604 /* Encode the hexidecimal scan code */
4605 Term_keypress(hexsym[i/16]);
4606 Term_keypress(hexsym[i%16]);
4608 /* End the macro trigger */
4619 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4620 WPARAM wParam, LPARAM lParam);
4621 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4622 WPARAM wParam, LPARAM lParam)
4623 #else /* __MWERKS__ */
4624 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4625 WPARAM wParam, LPARAM lParam)
4626 #endif /* __MWERKS__ */
4632 MINMAXINFO FAR *lpmmi;
4638 /* Acquire proper "term_data" info */
4639 td = (term_data *)GetWindowLong(hWnd, 0);
4641 /* Handle message */
4647 SetWindowLong(hWnd, 0, (LONG)(my_td));
4655 mop.dwCallback=(DWORD)hWnd;
4660 case WM_GETMINMAXINFO:
4662 MINMAXINFO FAR *lpmmi;
4665 lpmmi = (MINMAXINFO FAR *)lParam;
4667 /* this message was sent before WM_NCCREATE */
4670 /* Minimum window size is 80x24 */
4671 rc.left = rc.top = 0;
4672 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4673 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4676 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4678 /* Save minimum size */
4679 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4680 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4687 BeginPaint(hWnd, &ps);
4688 if (td) term_data_redraw(td);
4689 EndPaint(hWnd, &ps);
4690 ValidateRect(hWnd, NULL);
4697 if(wParam == MCI_NOTIFY_SUCCESSFUL)
4699 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4700 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4709 if (process_keydown(wParam, lParam))
4716 if (Term_no_press) Term_no_press = FALSE;
4717 else Term_keypress(wParam);
4721 case WM_LBUTTONDOWN:
4723 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4724 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4736 int dx = abs(oldx - mousex) + 1;
4737 int dy = abs(oldy - mousey) + 1;
4738 int ox = (oldx > mousex) ? mousex : oldx;
4739 int oy = (oldy > mousey) ? mousey : oldy;
4749 hGlobal = GlobalAlloc(GHND, sz + 1);
4750 if (hGlobal == NULL) return 0;
4751 lpStr = (LPSTR)GlobalLock(hGlobal);
4753 for (i = 0; i < dy; i++)
4757 char **scr = data[0].t.scr->c;
4759 C_MAKE(s, (dx + 1), char);
4760 strncpy(s, &scr[oy + i][ox], dx);
4764 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4767 if (ox + dx < data[0].cols)
4769 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4772 for (j = 0; j < dx; j++)
4774 if (s[j] == 127) s[j] = '#';
4778 for (j = 0; j < dx; j++)
4780 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4790 GlobalUnlock(hGlobal);
4791 if (OpenClipboard(hWnd) == 0)
4793 GlobalFree(hGlobal);
4797 SetClipboardData(CF_TEXT, hGlobal);
4810 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4811 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4816 dx = abs(oldx - mousex) + 1;
4817 dy = abs(oldy - mousey) + 1;
4818 ox = (oldx > mousex) ? mousex : oldx;
4819 oy = (oldy > mousey) ? mousey : oldy;
4820 Term_inversed_area(hWnd, ox, oy, dx, dy);
4827 dx = abs(cx - mousex) + 1;
4828 dy = abs(cy - mousey) + 1;
4829 ox = (cx > mousex) ? mousex : cx;
4830 oy = (cy > mousey) ? mousey : cy;
4831 Term_inversed_area(hWnd, ox, oy, dx, dy);
4847 if (game_in_progress && character_generated)
4851 plog(_("今は終了できません。", "You may not do that right now."));
4855 /* Hack -- Forget messages */
4864 /* do_cmd_save_game(FALSE); */
4865 #else /* ZANGBAND */
4866 /* do_cmd_save_game(); */
4867 #endif /* ZANGBAND */
4868 Term_key_push(SPECIAL_KEY_QUIT);
4875 case WM_QUERYENDSESSION:
4877 if (game_in_progress && character_generated)
4879 /* Hack -- Forget messages */
4882 /* Mega-Hack -- Delay death */
4883 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4884 do_cmd_write_nikki(NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4886 /* Hardcode panic save */
4887 p_ptr->panic_save = 1;
4889 /* Forbid suspend */
4890 signals_ignore_tstp();
4892 /* Indicate panic save */
4893 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4896 (void)save_player();
4910 process_menus(LOWORD(wParam));
4916 /* this message was sent before WM_NCCREATE */
4919 /* it was sent from inside CreateWindowEx */
4920 if (!td->w) return 1;
4922 /* was sent from WM_SIZE */
4923 if (td->size_hack) return 1;
4927 case SIZE_MINIMIZED:
4929 /* Hide sub-windows */
4930 for (i = 1; i < MAX_TERM_DATA; i++)
4932 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4937 case SIZE_MAXIMIZED:
4939 /* fall through XXX XXX XXX */
4944 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4945 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4948 if ((td->cols != cols) || (td->rows != rows))
4950 /* Save the new size */
4954 if (!IsZoomed(td->w) && !IsIconic(td->w))
4956 normsize.x = td->cols;
4957 normsize.y = td->rows;
4961 Term_activate(&td->t);
4963 /* Resize the term */
4964 Term_resize(td->cols, td->rows);
4967 InvalidateRect(td->w, NULL, TRUE);
4970 td->size_hack = TRUE;
4972 /* Show sub-windows */
4973 for (i = 1; i < MAX_TERM_DATA; i++)
4975 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4978 td->size_hack = FALSE;
4986 case WM_PALETTECHANGED:
4988 /* Ignore if palette change caused by itself */
4989 if ((HWND)wParam == hWnd) return 0;
4991 /* Fall through... */
4994 case WM_QUERYNEWPALETTE:
4996 if (!paletted) return 0;
5000 SelectPalette(hdc, hPal, FALSE);
5002 i = RealizePalette(hdc);
5004 /* if any palette entries changed, repaint the window. */
5005 if (i) InvalidateRect(hWnd, NULL, TRUE);
5007 ReleaseDC(hWnd, hdc);
5014 if (wParam && !HIWORD(lParam))
5016 /* Do something to sub-windows */
5017 for (i = 1; i < MAX_TERM_DATA; i++)
5019 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
5022 /* Focus on main window */
5031 case WM_ACTIVATEAPP:
5033 if (IsIconic(td->w)) break;
5035 for (i = 1; i < MAX_TERM_DATA; i++)
5041 ShowWindow(data[i].w, SW_SHOW);
5045 ShowWindow(data[i].w, SW_HIDE);
5052 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5057 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5058 WPARAM wParam, LPARAM lParam);
5059 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5060 WPARAM wParam, LPARAM lParam)
5061 #else /* __MWERKS__ */
5062 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5063 WPARAM wParam, LPARAM lParam)
5064 #endif /* __MWERKS__ */
5068 MINMAXINFO FAR *lpmmi;
5076 /* Acquire proper "term_data" info */
5077 td = (term_data *)GetWindowLong(hWnd, 0);
5079 /* Process message */
5085 SetWindowLong(hWnd, 0, (LONG)(my_td));
5095 case WM_GETMINMAXINFO:
5097 MINMAXINFO FAR *lpmmi;
5100 lpmmi = (MINMAXINFO FAR *)lParam;
5102 /* this message was sent before WM_NCCREATE */
5105 /* Minimum window size is 80x24 */
5106 rc.left = rc.top = 0;
5107 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5108 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5111 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5113 /* Save minimum size */
5114 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5115 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5125 /* this message was sent before WM_NCCREATE */
5128 /* it was sent from inside CreateWindowEx */
5129 if (!td->w) return 1;
5131 /* was sent from inside WM_SIZE */
5132 if (td->size_hack) return 1;
5134 td->size_hack = TRUE;
5136 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5137 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5140 if ((td->cols != cols) || (td->rows != rows))
5143 term *old_term = Term;
5145 /* Save the new size */
5150 Term_activate(&td->t);
5152 /* Resize the term */
5153 Term_resize(td->cols, td->rows);
5156 Term_activate(old_term);
5159 InvalidateRect(td->w, NULL, TRUE);
5161 /* HACK - Redraw all windows */
5162 p_ptr->window = 0xFFFFFFFF;
5166 td->size_hack = FALSE;
5173 BeginPaint(hWnd, &ps);
5174 if (td) term_data_redraw(td);
5175 EndPaint(hWnd, &ps);
5182 if (process_keydown(wParam, lParam))
5189 if (Term_no_press) Term_no_press = FALSE;
5190 else Term_keypress(wParam);
5194 case WM_PALETTECHANGED:
5196 /* ignore if palette change caused by itself */
5197 if ((HWND)wParam == hWnd) return FALSE;
5198 /* otherwise, fall through!!! */
5201 case WM_QUERYNEWPALETTE:
5203 if (!paletted) return 0;
5205 SelectPalette(hdc, hPal, FALSE);
5206 i = RealizePalette(hdc);
5207 /* if any palette entries changed, repaint the window. */
5208 if (i) InvalidateRect(hWnd, NULL, TRUE);
5209 ReleaseDC(hWnd, hdc);
5213 case WM_NCLBUTTONDOWN:
5217 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5218 #endif /* HTCLOSE */
5220 if (wParam == HTSYSMENU)
5224 td->visible = FALSE;
5225 ShowWindow(td->w, SW_HIDE);
5235 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5241 #define MOUSE_SENS 40
5244 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5245 WPARAM wParam, LPARAM lParam);
5246 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5247 WPARAM wParam, LPARAM lParam)
5248 #else /* __MWERKS__ */
5249 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5250 WPARAM wParam, LPARAM lParam)
5251 #endif /* __MWERKS__ */
5253 static int iMouse = 0;
5254 static WORD xMouse = 0;
5255 static WORD yMouse = 0;
5278 if (LOWORD(wParam) == WA_INACTIVE) break;
5280 /* else fall through */
5284 case WM_LBUTTONDOWN:
5285 case WM_MBUTTONDOWN:
5286 case WM_RBUTTONDOWN:
5289 SendMessage(hWnd, WM_CLOSE, 0, 0);
5297 dx = LOWORD(lParam) - xMouse;
5298 dy = HIWORD(lParam) - yMouse;
5300 if (dx < 0) dx = -dx;
5301 if (dy < 0) dy = -dy;
5303 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5305 SendMessage(hWnd, WM_CLOSE, 0, 0);
5309 /* Save last location */
5311 xMouse = LOWORD(lParam);
5312 yMouse = HIWORD(lParam);
5319 DestroyWindow(hwndSaver);
5326 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5329 #endif /* USE_SAVER */
5335 /*** Temporary Hooks ***/
5339 * Display warning message (see "z-util.c")
5341 static void hack_plog(cptr str)
5343 /* Give a warning */
5347 MessageBox(NULL, str, "警告!",
5348 MB_ICONEXCLAMATION | MB_OK);
5350 MessageBox(NULL, str, "Warning",
5351 MB_ICONEXCLAMATION | MB_OK);
5359 * Display error message and quit (see "z-util.c")
5361 static void hack_quit(cptr str)
5363 /* Give a warning */
5367 MessageBox(NULL, str, "エラー!",
5368 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5370 MessageBox(NULL, str, "Error",
5371 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5376 /* Unregister the classes */
5377 UnregisterClass(AppName, hInstance);
5379 /* Destroy the icon */
5380 if (hIcon) DestroyIcon(hIcon);
5388 /*** Various hooks ***/
5392 * Display warning message (see "z-util.c")
5394 static void hook_plog(cptr str)
5400 MessageBox(data[0].w, str, "警告!",
5401 MB_ICONEXCLAMATION | MB_OK);
5403 MessageBox(data[0].w, str, "Warning",
5404 MB_ICONEXCLAMATION | MB_OK);
5412 * Display error message and quit (see "z-util.c")
5414 static void hook_quit(cptr str)
5419 /* Give a warning */
5423 MessageBox(data[0].w, str, "エラー!",
5424 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5426 MessageBox(data[0].w, str, "Error",
5427 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5433 /* Save the preferences */
5437 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
5439 /* Destroy all windows */
5440 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5442 term_force_font(&data[i], NULL);
5443 if (data[i].font_want) string_free(data[i].font_want);
5444 if (data[i].w) DestroyWindow(data[i].w);
5448 /* Free the bitmap stuff */
5450 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5451 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5453 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5454 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5456 #endif /* USE_GRAPHICS */
5458 /*** Free some other stuff ***/
5460 DeleteObject(hbrYellow);
5465 if (hPal) DeleteObject(hPal);
5467 UnregisterClass(AppName, hInstance);
5469 if (hIcon) DestroyIcon(hIcon);
5476 /*** Initialize ***/
5482 static void init_stuff(void)
5489 /* Get program name with full path */
5490 GetModuleFileName(hInstance, path, 512);
5492 /* Save the "program name" XXX XXX XXX */
5495 /* Get the name of the "*.ini" file */
5496 strcpy(path + strlen(path) - 4, ".INI");
5498 /* Save the the name of the ini-file */
5499 ini_file = string_make(path);
5501 /* Analyze the path */
5507 if (path[i] == '\\')
5514 /* Add "lib" to the path */
5515 strcpy(path + i + 1, "lib\\");
5517 /* Validate the path */
5518 validate_dir(path, TRUE);
5520 /* Init the file paths */
5521 init_file_paths(path);
5523 /* Hack -- Validate the paths */
5524 validate_dir(ANGBAND_DIR_APEX, FALSE);
5525 validate_dir(ANGBAND_DIR_BONE, FALSE);
5527 /* Allow missing 'edit' directory */
5528 if (!check_dir(ANGBAND_DIR_EDIT))
5530 /* Must have 'data'! */
5531 validate_dir(ANGBAND_DIR_DATA, TRUE);
5535 /* Don't need 'data' */
5536 validate_dir(ANGBAND_DIR_DATA, FALSE);
5539 validate_dir(ANGBAND_DIR_FILE, TRUE);
5540 validate_dir(ANGBAND_DIR_HELP, FALSE);
5541 validate_dir(ANGBAND_DIR_INFO, FALSE);
5542 validate_dir(ANGBAND_DIR_PREF, TRUE);
5543 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5544 validate_dir(ANGBAND_DIR_USER, TRUE);
5545 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5547 /* Build the filename */
5548 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
5550 /* Hack -- Validate the "news.txt" file */
5551 validate_file(path);
5554 #if 0 /* #ifndef JP */
5555 /* Build the "font" path */
5556 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5558 /* Allocate the path */
5559 ANGBAND_DIR_XTRA_FONT = string_make(path);
5561 /* Validate the "font" directory */
5562 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5564 /* Build the filename */
5565 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5567 /* Hack -- Validate the basic font */
5568 validate_file(path);
5574 /* Build the "graf" path */
5575 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5577 /* Allocate the path */
5578 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5580 /* Validate the "graf" directory */
5581 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5583 #endif /* USE_GRAPHICS */
5588 /* Build the "sound" path */
5589 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5591 /* Allocate the path */
5592 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5594 /* Validate the "sound" directory */
5595 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5597 #endif /* USE_SOUND */
5601 /* Build the "music" path */
5602 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5604 /* Allocate the path */
5605 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5607 /* Validate the "music" directory */
5608 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5610 #endif /* USE_MUSIC */
5612 /* Build the "help" path */
5613 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5615 /* Allocate the path */
5616 ANGBAND_DIR_XTRA_HELP = string_make(path);
5618 /* Validate the "help" directory */
5619 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5622 bool is_already_running()
5624 bool result = FALSE;
5627 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5628 if (GetLastError() == ERROR_ALREADY_EXISTS)
5636 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5637 LPSTR lpCmdLine, int nCmdShow)
5645 setlocale( LC_ALL, "ja_JP" );
5654 /* Prevent multiple run */
5655 if (is_already_running())
5658 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
5659 _("エラー!", "Error") ,
5660 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5665 if (hPrevInst == NULL)
5667 wc.style = CS_CLASSDC;
5668 wc.lpfnWndProc = AngbandWndProc;
5670 wc.cbWndExtra = 4; /* one long pointer to term_data */
5671 wc.hInstance = hInst;
5672 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5673 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5674 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5675 wc.lpszMenuName = AppName;
5676 wc.lpszClassName = AppName;
5678 if (!RegisterClass(&wc)) exit(1);
5680 wc.lpfnWndProc = AngbandListProc;
5681 wc.lpszMenuName = NULL;
5682 wc.lpszClassName = AngList;
5684 if (!RegisterClass(&wc)) exit(2);
5688 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5689 wc.lpfnWndProc = AngbandSaverProc;
5691 wc.lpszMenuName = NULL;
5692 wc.lpszClassName = "WindowsScreenSaverClass";
5694 if (!RegisterClass(&wc)) exit(3);
5700 /* Temporary hooks */
5701 plog_aux = hack_plog;
5702 quit_aux = hack_quit;
5703 core_aux = hack_quit;
5705 /* Prepare the filepaths */
5708 /* Initialize the keypress analyzer */
5709 for (i = 0; special_key_list[i]; ++i)
5711 special_key[special_key_list[i]] = TRUE;
5713 /* Initialize the keypress analyzer */
5714 for (i = 0; ignore_key_list[i]; ++i)
5716 ignore_key[ignore_key_list[i]] = TRUE;
5719 /* Determine if display is 16/256/true color */
5721 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5722 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5723 ReleaseDC(NULL, hdc);
5725 /* Initialize the colors */
5726 for (i = 0; i < 256; i++)
5730 /* Extract desired values */
5731 rv = angband_color_table[i][1];
5732 gv = angband_color_table[i][2];
5733 bv = angband_color_table[i][3];
5735 /* Extract the "complex" code */
5736 win_clr[i] = PALETTERGB(rv, gv, bv);
5738 /* Save the "simple" code */
5739 angband_color_table[i][0] = win_pal[i];
5742 /* Prepare the windows */
5748 /* Activate hooks */
5749 plog_aux = hook_plog;
5750 quit_aux = hook_quit;
5751 core_aux = hook_quit;
5753 /* Set the system suffix */
5754 ANGBAND_SYS = "win";
5756 /* Set the keyboard suffix */
5757 if (7 != GetKeyboardType(0))
5758 ANGBAND_KEYBOARD = "0";
5761 /* Japanese keyboard */
5762 switch (GetKeyboardType(1))
5764 case 0x0D01: case 0x0D02:
5765 case 0x0D03: case 0x0D04:
5766 case 0x0D05: case 0x0D06:
5768 ANGBAND_KEYBOARD = "NEC98";
5772 ANGBAND_KEYBOARD = "JAPAN";
5776 /* Catch nasty signals */
5782 /* We are now initialized */
5785 if(lpCmdLine[0] == '-'){
5786 switch(lpCmdLine[1])
5791 if (!lpCmdLine[2]) break;
5792 chuukei_server = TRUE;
5793 if(connect_chuukei_server(&lpCmdLine[2])<0){
5794 msg_print("connect fail");
5797 msg_print("connect");
5805 if (!lpCmdLine[2]) break;
5806 chuukei_client = TRUE;
5807 connect_chuukei_server(&lpCmdLine[2]);
5815 if (!lpCmdLine[2]) break;
5816 prepare_browse_movie(&lpCmdLine[2]);
5826 /* Did the user double click on a save file? */
5827 if(!chuukei_server) check_for_save_file(lpCmdLine);
5829 /* Did the user double click on a save file? */
5830 check_for_save_file(lpCmdLine);
5833 /* Prompt the user */
5834 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
5838 /* Process messages forever */
5839 while (GetMessage(&msg, NULL, 0, 0))
5841 TranslateMessage(&msg);
5842 DispatchMessage(&msg);
5853 #endif /* WINDOWS */