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).
83 * Extract the "WIN32" flag from the compiler
85 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
93 * Hack -- allow use of "screen saver" mode
99 * Menu constants -- see "ANGBAND.RC"
102 #define IDM_FILE_NEW 100
103 #define IDM_FILE_OPEN 101
104 #define IDM_FILE_SAVE 110
105 #define IDM_FILE_SCORE 120
106 #define IDM_FILE_EXIT 130
108 #define IDM_WINDOW_VIS_0 200
109 #define IDM_WINDOW_VIS_1 201
110 #define IDM_WINDOW_VIS_2 202
111 #define IDM_WINDOW_VIS_3 203
112 #define IDM_WINDOW_VIS_4 204
113 #define IDM_WINDOW_VIS_5 205
114 #define IDM_WINDOW_VIS_6 206
115 #define IDM_WINDOW_VIS_7 207
117 #define IDM_WINDOW_FONT_0 210
118 #define IDM_WINDOW_FONT_1 211
119 #define IDM_WINDOW_FONT_2 212
120 #define IDM_WINDOW_FONT_3 213
121 #define IDM_WINDOW_FONT_4 214
122 #define IDM_WINDOW_FONT_5 215
123 #define IDM_WINDOW_FONT_6 216
124 #define IDM_WINDOW_FONT_7 217
126 #define IDM_WINDOW_POS_0 220
127 #define IDM_WINDOW_POS_1 221
128 #define IDM_WINDOW_POS_2 222
129 #define IDM_WINDOW_POS_3 223
130 #define IDM_WINDOW_POS_4 224
131 #define IDM_WINDOW_POS_5 225
132 #define IDM_WINDOW_POS_6 226
133 #define IDM_WINDOW_POS_7 227
135 #define IDM_WINDOW_BIZ_0 230
136 #define IDM_WINDOW_BIZ_1 231
137 #define IDM_WINDOW_BIZ_2 232
138 #define IDM_WINDOW_BIZ_3 233
139 #define IDM_WINDOW_BIZ_4 234
140 #define IDM_WINDOW_BIZ_5 235
141 #define IDM_WINDOW_BIZ_6 236
142 #define IDM_WINDOW_BIZ_7 237
144 #define IDM_WINDOW_I_WID_0 240
145 #define IDM_WINDOW_I_WID_1 241
146 #define IDM_WINDOW_I_WID_2 242
147 #define IDM_WINDOW_I_WID_3 243
148 #define IDM_WINDOW_I_WID_4 244
149 #define IDM_WINDOW_I_WID_5 245
150 #define IDM_WINDOW_I_WID_6 246
151 #define IDM_WINDOW_I_WID_7 247
153 #define IDM_WINDOW_D_WID_0 250
154 #define IDM_WINDOW_D_WID_1 251
155 #define IDM_WINDOW_D_WID_2 252
156 #define IDM_WINDOW_D_WID_3 253
157 #define IDM_WINDOW_D_WID_4 254
158 #define IDM_WINDOW_D_WID_5 255
159 #define IDM_WINDOW_D_WID_6 256
160 #define IDM_WINDOW_D_WID_7 257
162 #define IDM_WINDOW_I_HGT_0 260
163 #define IDM_WINDOW_I_HGT_1 261
164 #define IDM_WINDOW_I_HGT_2 262
165 #define IDM_WINDOW_I_HGT_3 263
166 #define IDM_WINDOW_I_HGT_4 264
167 #define IDM_WINDOW_I_HGT_5 265
168 #define IDM_WINDOW_I_HGT_6 266
169 #define IDM_WINDOW_I_HGT_7 267
171 #define IDM_WINDOW_D_HGT_0 270
172 #define IDM_WINDOW_D_HGT_1 271
173 #define IDM_WINDOW_D_HGT_2 272
174 #define IDM_WINDOW_D_HGT_3 273
175 #define IDM_WINDOW_D_HGT_4 274
176 #define IDM_WINDOW_D_HGT_5 275
177 #define IDM_WINDOW_D_HGT_6 276
178 #define IDM_WINDOW_D_HGT_7 277
180 #define IDM_OPTIONS_NO_GRAPHICS 400
181 #define IDM_OPTIONS_OLD_GRAPHICS 401
182 #define IDM_OPTIONS_NEW_GRAPHICS 402
183 #define IDM_OPTIONS_BIGTILE 409
184 #define IDM_OPTIONS_SOUND 410
185 #define IDM_OPTIONS_SAVER 420
186 #define IDM_OPTIONS_MAP 430
187 #define IDM_OPTIONS_BG 440
188 #define IDM_OPTIONS_OPEN_BG 441
190 #define IDM_DUMP_SCREEN_HTML 450
192 #define IDM_HELP_CONTENTS 901
197 * This may need to be removed for some compilers XXX XXX XXX
202 * Exclude parts of WINDOWS.H that are not needed
204 #define NOCOMM /* Comm driver APIs and definitions */
205 #define NOLOGERROR /* LogError() and related definitions */
206 #define NOPROFILER /* Profiler APIs */
207 #define NOLFILEIO /* _l* file I/O routines */
208 #define NOOPENFILE /* OpenFile and related definitions */
209 #define NORESOURCE /* Resource management */
210 #define NOATOM /* Atom management */
211 #define NOLANGUAGE /* Character test routines */
212 #define NOLSTRING /* lstr* string management routines */
213 #define NODBCS /* Double-byte character set routines */
214 #define NOKEYBOARDINFO /* Keyboard driver routines */
215 #define NOCOLOR /* COLOR_* color values */
216 #define NODRAWTEXT /* DrawText() and related definitions */
217 #define NOSCALABLEFONT /* Truetype scalable font support */
218 #define NOMETAFILE /* Metafile support */
219 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
220 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
221 #define NOKEYSTATES /* MK_* message key state flags */
222 #define NOWH /* SetWindowsHook and related WH_* definitions */
223 #define NOCLIPBOARD /* Clipboard APIs and definitions */
224 #define NOICONS /* IDI_* icon IDs */
225 #define NOMDI /* MDI support */
226 #define NOHELP /* Help support */
228 /* Not defined since it breaks Borland C++ 5.5 */
229 /* #define NOCTLMGR */ /* Control management and controls */
232 * Exclude parts of WINDOWS.H that are not needed (Win32)
234 #define WIN32_LEAN_AND_MEAN
235 #define NONLS /* All NLS defines and routines */
236 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
237 #define NOKANJI /* Kanji support stuff. */
238 #define NOMCX /* Modem Configuration Extensions */
241 * Include the "windows" support file
246 * Exclude parts of MMSYSTEM.H that are not needed
248 #define MMNODRV /* Installable driver support */
249 #define MMNOWAVE /* Waveform support */
250 #define MMNOMIDI /* MIDI support */
251 #define MMNOAUX /* Auxiliary audio support */
252 #define MMNOTIMER /* Timer support */
253 #define MMNOJOY /* Joystick support */
254 #define MMNOMCI /* MCI support */
255 #define MMNOMMIO /* Multimedia file I/O support */
256 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
259 * Include some more files. Note: the Cygnus Cygwin compiler
260 * doesn't use mmsystem.h instead it includes the winmm library
261 * which performs a similar function.
263 #include <mmsystem.h>
267 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
268 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
270 /* #define HTML_HELP */
273 #include <htmlhelp.h>
274 #endif /* HTML_HELP */
277 * Include the support for loading bitmaps
280 # include "readdib.h"
284 * Hack -- Fake declarations from "dos.h" XXX XXX XXX
287 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
289 #define FA_LABEL 0x08 /* Volume label */
290 #define FA_DIREC 0x10 /* Directory */
291 unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
295 * Silliness in WIN32 drawing routine
298 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
302 * Silliness for Windows 95
304 #ifndef WS_EX_TOOLWINDOW
305 # define WS_EX_TOOLWINDOW 0
309 * Foreground color bits (hard-coded by DOS)
311 #define VID_BLACK 0x00
312 #define VID_BLUE 0x01
313 #define VID_GREEN 0x02
314 #define VID_CYAN 0x03
316 #define VID_MAGENTA 0x05
317 #define VID_YELLOW 0x06
318 #define VID_WHITE 0x07
321 * Bright text (hard-coded by DOS)
323 #define VID_BRIGHT 0x08
326 * Background color bits (hard-coded by DOS)
328 #define VUD_BLACK 0x00
329 #define VUD_BLUE 0x10
330 #define VUD_GREEN 0x20
331 #define VUD_CYAN 0x30
333 #define VUD_MAGENTA 0x50
334 #define VUD_YELLOW 0x60
335 #define VUD_WHITE 0x70
338 * Blinking text (hard-coded by DOS)
340 #define VUD_BRIGHT 0x80
346 typedef struct _term_data term_data;
351 * Note the use of "font_want" for the names of the font file requested by
352 * the user, and the use of "font_file" for the currently active font file.
354 * The "font_file" is uppercased, and takes the form "8X13.FON", while
355 * "font_want" can be in almost any form as long as it could be construed
356 * as attempting to represent the name of a font.
371 uint rows; /* int -> uint */
407 #if 1 /* #ifdef JP */
422 * Maximum number of windows XXX XXX XXX
424 #define MAX_TERM_DATA 8
427 * An array of term_data's
429 static term_data data[MAX_TERM_DATA];
432 * Hack -- global "window creation" pointer
434 static term_data *my_td;
439 bool game_in_progress = FALSE;
442 * note when "open"/"new" become valid
444 bool initialized = FALSE;
447 * screen paletted, i.e. 256 colors
449 bool paletted = FALSE;
452 * 16 colors screen, don't use RGB()
454 bool colors16 = FALSE;
457 * Saved instance handle
459 static HINSTANCE hInstance;
462 * Yellow brush for the cursor
464 static HBRUSH hbrYellow;
474 static HPALETTE hPal;
477 static HBITMAP hBG = NULL;
478 static int use_bg = 0;
479 static char bg_bitmap_file[1024] = "bg.bmp";
484 * The screen saver window
486 static HWND hwndSaver;
488 #endif /* USE_SAVER */
494 * Flag set once "graphics" has been initialized
496 static bool can_use_graphics = FALSE;
501 static DIBINIT infGraph;
504 * The global bitmap mask
506 static DIBINIT infMask;
508 #endif /* USE_GRAPHICS */
514 * Flag set once "sound" has been initialized
516 static bool can_use_sound = FALSE;
521 * An array of sound file names
523 static cptr sound_file[SOUND_MAX][SAMPLE_MAX];
525 #endif /* USE_SOUND */
529 * Full path to ANGBAND.INI
531 static cptr ini_file = NULL;
534 * Name of application
536 static cptr AppName = "ANGBAND";
539 * Name of sub-window type
541 static cptr AngList = "AngList";
546 static cptr ANGBAND_DIR_XTRA_GRAF;
547 static cptr ANGBAND_DIR_XTRA_SOUND;
548 static cptr ANGBAND_DIR_XTRA_HELP;
549 #if 0 /* #ifndef JP */
550 static cptr ANGBAND_DIR_XTRA_FONT;
553 static cptr ANGBAND_DIR_XTRA_MUSIC;
558 * The "complex" color values
560 static COLORREF win_clr[256];
564 * Flag for macro trigger with dump ASCII
566 static bool Term_no_press = FALSE;
570 * The "simple" color values
572 * See "main-ibm.c" for original table information
574 * The entries below are taken from the "color bits" defined above.
576 * Note that many of the choices below suck, but so do crappy monitors.
578 static BYTE win_pal[256] =
580 VID_BLACK, /* Dark */
581 VID_WHITE, /* White */
582 VID_CYAN, /* Slate XXX */
583 VID_RED | VID_BRIGHT, /* Orange XXX */
585 VID_GREEN, /* Green */
587 VID_YELLOW, /* Umber XXX */
588 VID_BLACK | VID_BRIGHT, /* Light Dark */
589 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
590 VID_MAGENTA, /* Violet XXX */
591 VID_YELLOW | VID_BRIGHT, /* Yellow */
592 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
593 VID_GREEN | VID_BRIGHT, /* Light Green */
594 VID_BLUE | VID_BRIGHT, /* Light Blue */
595 VID_YELLOW /* Light Umber XXX */
600 * Hack -- define which keys are "special"
602 static bool special_key[256];
603 static bool ignore_key[256];
607 * Hack -- initialization list for "special_key"
609 static byte special_key_list[] = {
610 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
611 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
612 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
613 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
614 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
615 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
616 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
617 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
618 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
619 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
620 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
621 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
622 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
623 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
624 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
625 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
626 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
631 static byte ignore_key_list[] = {
632 VK_ESCAPE, VK_TAB, VK_SPACE,
633 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
634 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
635 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
641 * Hack -- initialization list for "special_key"
643 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
644 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
645 * catch the keypad keys (with and without numlock set, including keypad 5),
646 * the function keys (including the "menu" key which maps to F10), and the
647 * "pause" key (between scroll lock and numlock). We also catch a few odd
648 * keys which I do not recognize, but which are listed among keys which we
649 * do catch, so they should be harmless to catch.
651 static byte special_key_list[] =
653 VK_CLEAR, /* 0x0C (KP<5>) */
655 VK_PAUSE, /* 0x13 (pause) */
657 VK_PRIOR, /* 0x21 (KP<9>) */
658 VK_NEXT, /* 0x22 (KP<3>) */
659 VK_END, /* 0x23 (KP<1>) */
660 VK_HOME, /* 0x24 (KP<7>) */
661 VK_LEFT, /* 0x25 (KP<4>) */
662 VK_UP, /* 0x26 (KP<8>) */
663 VK_RIGHT, /* 0x27 (KP<6>) */
664 VK_DOWN, /* 0x28 (KP<2>) */
665 VK_SELECT, /* 0x29 (?????) */
666 VK_PRINT, /* 0x2A (?????) */
667 VK_EXECUTE, /* 0x2B (?????) */
668 VK_SNAPSHOT, /* 0x2C (?????) */
669 VK_INSERT, /* 0x2D (KP<0>) */
670 VK_DELETE, /* 0x2E (KP<.>) */
671 VK_HELP, /* 0x2F (?????) */
673 VK_NUMPAD0, /* 0x60 (KP<0>) */
674 VK_NUMPAD1, /* 0x61 (KP<1>) */
675 VK_NUMPAD2, /* 0x62 (KP<2>) */
676 VK_NUMPAD3, /* 0x63 (KP<3>) */
677 VK_NUMPAD4, /* 0x64 (KP<4>) */
678 VK_NUMPAD5, /* 0x65 (KP<5>) */
679 VK_NUMPAD6, /* 0x66 (KP<6>) */
680 VK_NUMPAD7, /* 0x67 (KP<7>) */
681 VK_NUMPAD8, /* 0x68 (KP<8>) */
682 VK_NUMPAD9, /* 0x69 (KP<9>) */
683 VK_MULTIPLY, /* 0x6A (KP<*>) */
684 VK_ADD, /* 0x6B (KP<+>) */
685 VK_SEPARATOR, /* 0x6C (?????) */
686 VK_SUBTRACT, /* 0x6D (KP<->) */
687 VK_DECIMAL, /* 0x6E (KP<.>) */
688 VK_DIVIDE, /* 0x6F (KP</>) */
719 static void delete_bg(void)
728 static int init_bg(void)
730 char * bmfile = bg_bitmap_file;
733 if (use_bg == 0) return 0;
735 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
738 plog_fmt("ÊÉ»æÍÑ¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
740 plog_fmt("Can't load the bitmap file '%s'.", bmfile);
746 HDC wnddc, dcimage, dcbg;
747 HBITMAP bmimage, bmimage_old, bmbg_old;
753 dcimage = CreateCompatibleDC(wnddc);
754 dcbg = CreateCompatibleDC(wnddc);
756 bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
757 if (!bmimage) quit("bg.bmp¤¬Æɤߤ³¤á¤Ê¤¤¡ª");
758 bmimage_old = SelectObject(dcimage, bmimage);
760 CreateCompatibleBitmap();
762 ReleaseDC(hwnd, wnddc);
768 static void DrawBG(HDC hdc, RECT *r)
773 int x = r->left, y = r->top;
774 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
780 GetObject(hBG, sizeof(bm), &bm);
781 swid = bm.bmWidth; shgt = bm.bmHeight;
783 hdcSrc = CreateCompatibleDC(hdc);
784 hOld = SelectObject(hdcSrc, hBG);
788 cwid = MIN(swid - sx, r->right - nx);
791 chgt = MIN(shgt - sy, r->bottom - ny);
792 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
794 } while (ny < r->bottom);
797 } while (nx < r->right);
799 SelectObject(hdcSrc, hOld);
805 * Hack -- given a pathname, point at the filename
807 static cptr extract_file_name(cptr s)
811 /* Start at the end */
812 p = s + strlen(s) - 1;
814 /* Back up to divider */
815 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
817 /* Return file name */
824 * Hack -- given a simple filename, extract the "font size" info
826 * Return a pointer to a static buffer holding the capitalized base name.
828 #if 0 /* #ifndef JP */
829 static char *analyze_font(char *path, int *wp, int *hp)
835 /* Start at the end */
836 p = path + strlen(path) - 1;
838 /* Back up to divider */
839 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
841 /* Advance to file name */
847 /* Capitalize (be paranoid) */
848 if (islower(*s)) *s = toupper(*s);
852 s = my_strchr(p, 'X');
854 /* Extract font width */
858 hgt = s ? atoi(s+1) : 0;
871 * Check for existance of a file
873 static bool check_file(cptr s)
893 attrib = GetFileAttributes(path);
895 /* Require valid filename */
896 if (attrib == INVALID_FILE_NAME) return (FALSE);
898 /* Prohibit directory */
899 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
903 /* Examine and verify */
904 if (_dos_getfileattr(path, &attrib)) return (FALSE);
906 /* Prohibit something */
907 if (attrib & FA_LABEL) return (FALSE);
909 /* Prohibit directory */
910 if (attrib & FA_DIREC) return (FALSE);
920 * Check for existance of a directory
922 static bool check_dir(cptr s)
944 /* Remove trailing backslash */
945 if (i && (path[i-1] == '\\')) path[--i] = '\0';
950 attrib = GetFileAttributes(path);
952 /* Require valid filename */
953 if (attrib == INVALID_FILE_NAME) return (FALSE);
955 /* Require directory */
956 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
960 /* Examine and verify */
961 if (_dos_getfileattr(path, &attrib)) return (FALSE);
963 /* Prohibit something */
964 if (attrib & FA_LABEL) return (FALSE);
966 /* Require directory */
967 if (!(attrib & FA_DIREC)) return (FALSE);
979 static void validate_file(cptr s)
985 quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
987 quit_fmt("Cannot find required file:\n%s", s);
995 * Validate a directory
997 static void validate_dir(cptr s, bool vital)
1002 /* This directory contains needed data */
1006 quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
1008 quit_fmt("Cannot find required directory:\n%s", s);
1012 /* Attempt to create this directory */
1015 quit_fmt("Unable to create directory:\n%s", s);
1022 * Get the "size" for a window
1024 static void term_getsize(term_data *td)
1031 if (td->cols < 1) td->cols = 1;
1032 if (td->rows < 1) td->rows = 1;
1035 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1036 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1038 /* Fake window size */
1040 rc.right = rc.left + wid;
1042 rc.bottom = rc.top + hgt;
1045 /* rc.right += 1; */
1046 /* rc.bottom += 1; */
1049 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1052 td->size_wid = rc.right - rc.left;
1053 td->size_hgt = rc.bottom - rc.top;
1055 /* See CreateWindowEx */
1058 /* Extract actual location */
1059 GetWindowRect(td->w, &rc);
1061 /* Save the location */
1062 td->pos_x = rc.left;
1068 * Write the "prefs" for a single term
1070 static void save_prefs_aux(term_data *td, cptr sec_name)
1080 strcpy(buf, td->visible ? "1" : "0");
1081 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1085 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1088 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1090 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1094 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1096 #if 1 /* #ifdef JP */
1097 wsprintf(buf, "%d", td->lf.lfWidth);
1098 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1099 wsprintf(buf, "%d", td->lf.lfHeight);
1100 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1101 wsprintf(buf, "%d", td->lf.lfWeight);
1102 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1105 strcpy(buf, td->bizarre ? "1" : "0");
1106 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1109 wsprintf(buf, "%d", td->tile_wid);
1110 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1113 wsprintf(buf, "%d", td->tile_hgt);
1114 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1116 /* Window size (x) */
1117 wsprintf(buf, "%d", td->cols);
1118 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1120 /* Window size (y) */
1121 wsprintf(buf, "%d", td->rows);
1122 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1124 /* Acquire position */
1125 GetWindowRect(td->w, &rc);
1127 /* Window position (x) */
1128 wsprintf(buf, "%d", rc.left);
1129 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1131 /* Window position (y) */
1132 wsprintf(buf, "%d", rc.top);
1133 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1135 /* Window Z position */
1136 strcpy(buf, td->posfix ? "1" : "0");
1137 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1144 * We assume that the windows have all been initialized
1146 static void save_prefs(void)
1152 /* Save the "arg_graphics" flag */
1153 sprintf(buf, "%d", arg_graphics);
1154 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1156 /* Save the "arg_bigtile" flag */
1157 strcpy(buf, arg_bigtile ? "1" : "0");
1158 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1160 /* Save the "arg_sound" flag */
1161 strcpy(buf, arg_sound ? "1" : "0");
1162 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1165 strcpy(buf, use_bg ? "1" : "0");
1166 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1167 WritePrivateProfileString("Angband", "BackGroundBitmap",
1168 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1170 /* Save window prefs */
1171 for (i = 0; i < MAX_TERM_DATA; ++i)
1173 term_data *td = &data[i];
1175 sprintf(buf, "Term-%d", i);
1177 save_prefs_aux(td, buf);
1183 * Load the "prefs" for a single term
1185 static void load_prefs_aux(term_data *td, cptr sec_name)
1192 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1194 /* Desired font, with default */
1196 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1199 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1201 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1207 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1209 /* Analyze font, save desired font name */
1210 #if 1 /* #ifdef JP */
1211 td->font_want = string_make(tmp);
1213 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1214 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1215 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1217 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1222 #if 1 /* #ifdef JP */
1223 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1224 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1226 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1227 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1232 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1233 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1235 /* Window position */
1236 td->pos_x = GetPrivateProfileInt(sec_name, "PositionX", td->pos_x, ini_file);
1237 td->pos_y = GetPrivateProfileInt(sec_name, "PositionY", td->pos_y, ini_file);
1239 /* Window Z position */
1240 td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1247 static void load_prefs(void)
1253 /* Extract the "arg_graphics" flag */
1254 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1256 /* Extract the "arg_bigtile" flag */
1257 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1258 use_bigtile = arg_bigtile;
1260 /* Extract the "arg_sound" flag */
1261 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1264 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1265 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1267 /* Load window prefs */
1268 for (i = 0; i < MAX_TERM_DATA; ++i)
1270 term_data *td = &data[i];
1272 sprintf(buf, "Term-%d", i);
1274 load_prefs_aux(td, buf);
1281 * XXX XXX XXX - Taken from files.c.
1283 * Extract "tokens" from a buffer
1285 * This function uses "whitespace" as delimiters, and treats any amount of
1286 * whitespace as a single delimiter. We will never return any empty tokens.
1287 * When given an empty buffer, or a buffer containing only "whitespace", we
1288 * will return no tokens. We will never extract more than "num" tokens.
1290 * By running a token through the "text_to_ascii()" function, you can allow
1291 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1293 * We save pointers to the tokens in "tokens", and return the number found.
1295 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1307 /* Skip leading whitespace */
1308 for ( ; *s && isspace(*s); ++s) /* loop */;
1313 /* Find next whitespace, if any */
1314 for (t = s; *t && !isspace(*t); ++t) /* loop */;
1316 /* Nuke and advance (if necessary) */
1317 if (*t) *t++ = '\0';
1319 /* Save the token */
1330 static void load_sound_prefs(void)
1334 char ini_path[1024];
1335 char wav_path[1024];
1336 char *zz[SAMPLE_MAX];
1338 /* Access the sound.cfg */
1339 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1341 for (i = 0; i < SOUND_MAX; i++)
1343 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1345 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1347 for (j = 0; j < num; j++)
1349 /* Access the sound */
1350 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1352 /* Save the sound filename, if it exists */
1353 if (check_file(wav_path))
1354 sound_file[i][j] = string_make(zz[j]);
1359 #endif /* USE_SOUND */
1362 * Create the new global palette based on the bitmap palette
1363 * (if any), and the standard 16 entry palette derived from
1364 * "win_clr[]" which is used for the basic 16 Angband colors.
1366 * This function is never called before all windows are ready.
1368 * This function returns FALSE if the new palette could not be
1369 * prepared, which should normally be a fatal error. XXX XXX
1371 * Note that only some machines actually use a "palette".
1373 static int new_palette(void)
1381 LPLOGPALETTE pLogPal;
1382 LPPALETTEENTRY lppe;
1387 /* This makes no sense */
1388 if (!paletted) return (TRUE);
1398 /* Check the bitmap palette */
1399 hBmPal = infGraph.hPalette;
1401 /* Use the bitmap */
1404 lppeSize = 256 * sizeof(PALETTEENTRY);
1405 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1406 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1407 if ((nEntries == 0) || (nEntries > 220))
1411 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1413 plog("Please switch to high- or true-color mode.");
1418 rnfree(lppe, lppeSize);
1425 #endif /* USE_GRAPHICS */
1427 /* Size of palette */
1428 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1430 /* Allocate palette */
1431 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1434 pLogPal->palVersion = 0x300;
1436 /* Make room for bitmap and normal data */
1437 pLogPal->palNumEntries = nEntries + 16;
1439 /* Save the bitmap data */
1440 for (i = 0; i < nEntries; i++)
1442 pLogPal->palPalEntry[i] = lppe[i];
1445 /* Save the normal data */
1446 for (i = 0; i < 16; i++)
1450 /* Access the entry */
1451 p = &(pLogPal->palPalEntry[i+nEntries]);
1453 /* Save the colors */
1454 p->peRed = GetRValue(win_clr[i]);
1455 p->peGreen = GetGValue(win_clr[i]);
1456 p->peBlue = GetBValue(win_clr[i]);
1458 /* Save the flags */
1459 p->peFlags = PC_NOCOLLAPSE;
1462 /* Free something */
1463 if (lppe) rnfree(lppe, lppeSize);
1465 /* Create a new palette, or fail */
1466 hNewPal = CreatePalette(pLogPal);
1468 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1470 if (!hNewPal) quit("Cannot create palette!");
1474 /* Free the palette */
1475 rnfree(pLogPal, pLogPalSize);
1480 /* Realize the palette */
1482 SelectPalette(hdc, hNewPal, 0);
1483 i = RealizePalette(hdc);
1484 ReleaseDC(td->w, hdc);
1486 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1488 if (i == 0) quit("Cannot realize palette!");
1493 for (i = 1; i < MAX_TERM_DATA; i++)
1498 SelectPalette(hdc, hNewPal, 0);
1499 ReleaseDC(td->w, hdc);
1502 /* Delete old palette */
1503 if (hPal) DeleteObject(hPal);
1505 /* Save new palette */
1515 * Initialize graphics
1517 static bool init_graphics(void)
1519 /* Initialize once */
1520 /* if (can_use_graphics != arg_graphics) */
1526 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1533 ANGBAND_GRAF = "new";
1541 ANGBAND_GRAF = "old";
1544 /* Access the bitmap file */
1545 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1547 /* Load the bitmap or quit */
1548 if (!ReadDIB(data[0].w, buf, &infGraph))
1551 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1553 plog_fmt("Cannot read bitmap file '%s'", name);
1559 /* Save the new sizes */
1560 infGraph.CellWidth = wid;
1561 infGraph.CellHeight = hgt;
1563 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1565 /* Access the mask file */
1566 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1568 /* Load the bitmap or quit */
1569 if (!ReadDIB(data[0].w, buf, &infMask))
1571 plog_fmt("Cannot read bitmap file '%s'", buf);
1576 /* Activate a palette */
1579 /* Free bitmap XXX XXX XXX */
1583 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1585 plog("Cannot activate palette!");
1591 /* Graphics available */
1592 can_use_graphics = arg_graphics;
1596 return (can_use_graphics);
1598 #endif /* USE_GRAPHICS */
1605 static bool init_sound(void)
1607 /* Initialize once */
1610 /* Load the prefs */
1613 /* Sound available */
1614 can_use_sound = TRUE;
1618 return (can_use_sound);
1620 #endif /* USE_SOUND */
1626 static void term_window_resize(term_data *td)
1628 /* Require window */
1631 /* Resize the window */
1632 SetWindowPos(td->w, 0, 0, 0,
1633 td->size_wid, td->size_hgt,
1634 SWP_NOMOVE | SWP_NOZORDER);
1637 InvalidateRect(td->w, NULL, TRUE);
1642 * Force the use of a new "font file" for a term_data
1644 * This function may be called before the "window" is ready
1646 * This function returns zero only if everything succeeds.
1648 * Note that the "font name" must be capitalized!!!
1650 static errr term_force_font(term_data *td, cptr path)
1654 #if 0 /* #ifndef JP */
1660 /* Forget the old font (if needed) */
1661 if (td->font_id) DeleteObject(td->font_id);
1663 #if 1 /* #ifdef JP */
1667 /* Create the font (using the 'base' of the font file name!) */
1668 td->font_id = CreateFontIndirect(&(td->lf));
1669 wid = td->lf.lfWidth;
1670 hgt = td->lf.lfHeight;
1671 if (!td->font_id) return (1);
1673 /* Forget old font */
1679 for (i = 0; i < MAX_TERM_DATA; i++)
1681 /* Don't check when closing the application */
1684 /* Check "screen" */
1685 if ((td != &data[i]) &&
1686 (data[i].font_file) &&
1687 (streq(data[i].font_file, td->font_file)))
1693 /* Remove unused font resources */
1694 if (!used) RemoveFontResource(td->font_file);
1696 /* Free the old name */
1697 string_free(td->font_file);
1700 td->font_file = NULL;
1704 if (!path) return (1);
1709 /* Analyze font path */
1710 base = analyze_font(buf, &wid, &hgt);
1713 if (!suffix(base, ".FON")) return (1);
1716 if (!check_file(buf)) return (1);
1718 /* Load the new font */
1719 if (!AddFontResource(buf)) return (1);
1721 /* Save new font name */
1722 td->font_file = string_make(base);
1724 /* Remove the "suffix" */
1725 base[strlen(base)-4] = '\0';
1727 /* Create the font (using the 'base' of the font file name!) */
1728 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1729 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1730 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1731 FIXED_PITCH | FF_DONTCARE, base);
1734 /* Hack -- Unknown size */
1741 /* all this trouble to get the cell size */
1742 hdcDesktop = GetDC(HWND_DESKTOP);
1743 hfOld = SelectObject(hdcDesktop, td->font_id);
1744 GetTextMetrics(hdcDesktop, &tm);
1745 SelectObject(hdcDesktop, hfOld);
1746 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1748 /* Font size info */
1749 wid = tm.tmAveCharWidth;
1753 /* Save the size info */
1764 * Allow the user to change the font for this window.
1766 static void term_change_font(term_data *td)
1768 #if 1 /* #ifdef JP */
1771 memset(&cf, 0, sizeof(cf));
1772 cf.lStructSize = sizeof(cf);
1773 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1774 cf.lpLogFont = &(td->lf);
1776 if (ChooseFont(&cf))
1778 /* Force the font */
1779 term_force_font(td, NULL);
1781 /* Assume not bizarre */
1784 /* Reset the tile info */
1785 td->tile_wid = td->font_wid;
1786 td->tile_hgt = td->font_hgt;
1788 /* Analyze the font */
1791 /* Resize the window */
1792 term_window_resize(td);
1798 char tmp[1024] = "";
1800 /* Extract a default if possible */
1801 if (td->font_file) strcpy(tmp, td->font_file);
1803 /* Ask for a choice */
1804 memset(&ofn, 0, sizeof(ofn));
1805 ofn.lStructSize = sizeof(ofn);
1806 ofn.hwndOwner = data[0].w;
1807 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1808 ofn.nFilterIndex = 1;
1809 ofn.lpstrFile = tmp;
1811 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1812 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1813 ofn.lpstrDefExt = "fon";
1815 /* Force choice if legal */
1816 if (GetOpenFileName(&ofn))
1818 /* Force the font */
1819 if (term_force_font(td, tmp))
1821 /* Access the standard font file */
1822 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1824 /* Force the use of that font */
1825 (void)term_force_font(td, tmp);
1828 /* Assume not bizarre */
1829 td->bizarre = FALSE;
1831 /* Reset the tile info */
1832 td->tile_wid = td->font_wid;
1833 td->tile_hgt = td->font_hgt;
1835 /* Analyze the font */
1838 /* Resize the window */
1839 term_window_resize(td);
1846 * Allow the user to lock this window.
1848 static void term_window_pos(term_data *td, HWND hWnd)
1850 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1851 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1854 static void windows_map(void);
1857 * Hack -- redraw a term_data
1859 static void term_data_redraw(term_data *td)
1863 /* Redraw the map */
1868 /* Activate the term */
1869 Term_activate(&td->t);
1871 /* Redraw the contents */
1874 /* Restore the term */
1875 Term_activate(term_screen);
1883 /*** Function hooks needed by "Term" ***/
1889 * Initialize a new Term
1891 static void Term_init_win(term *t)
1900 static void Term_nuke_win(term *t)
1909 * Interact with the User
1911 static errr Term_user_win(int n)
1922 * React to global changes
1924 static errr Term_xtra_win_react(void)
1932 /* Save the default colors */
1933 for (i = 0; i < 256; i++)
1935 /* Simply accept the desired colors */
1936 win_pal[i] = angband_color_table[i][0];
1947 bool change = FALSE;
1949 /* Save the default colors */
1950 for (i = 0; i < 256; i++)
1952 /* Extract desired values */
1953 rv = angband_color_table[i][1];
1954 gv = angband_color_table[i][2];
1955 bv = angband_color_table[i][3];
1957 /* Extract a full color code */
1958 code = PALETTERGB(rv, gv, bv);
1960 /* Activate changes */
1961 if (win_clr[i] != code)
1963 /* Note the change */
1966 /* Apply the desired color */
1971 /* Activate the palette if needed */
1972 if (change) (void)new_palette();
1978 /* Handle "arg_sound" */
1979 if (use_sound != arg_sound)
1981 /* Initialize (if needed) */
1982 if (arg_sound && !init_sound())
1986 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
1988 plog("Cannot initialize sound!");
1996 /* Change setting */
1997 use_sound = arg_sound;
2005 /* Handle "arg_graphics" */
2006 if (use_graphics != arg_graphics)
2008 /* Initialize (if needed) */
2009 if (arg_graphics && !init_graphics())
2013 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
2015 plog("Cannot initialize graphics!");
2020 arg_graphics = GRAPHICS_NONE;
2023 /* Change setting */
2024 use_graphics = arg_graphics;
2027 #ifdef ANGBAND_2_8_1
2029 #else /* ANGBAND_2_8_1 */
2030 reset_visuals(TRUE);
2031 #endif /* ANGBAND_2_8_1 */
2034 #endif /* USE_GRAPHICS */
2037 /* Clean up windows */
2038 for (i = 0; i < MAX_TERM_DATA; i++)
2042 term_data *td = &data[i];
2044 /* Update resized windows */
2045 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2048 Term_activate(&td->t);
2050 /* Hack -- Resize the term */
2051 Term_resize(td->cols, td->rows);
2053 /* Redraw the contents */
2068 * Process at least one event
2070 static errr Term_xtra_win_event(int v)
2074 /* Wait for an event */
2078 if (GetMessage(&msg, NULL, 0, 0))
2080 TranslateMessage(&msg);
2081 DispatchMessage(&msg);
2085 /* Check for an event */
2089 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2091 TranslateMessage(&msg);
2092 DispatchMessage(&msg);
2102 * Process all pending events
2104 static errr Term_xtra_win_flush(void)
2108 /* Process all pending events */
2109 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2111 TranslateMessage(&msg);
2112 DispatchMessage(&msg);
2121 * Hack -- clear the screen
2123 * Make this more efficient XXX XXX XXX
2125 static errr Term_xtra_win_clear(void)
2127 term_data *td = (term_data*)(Term->data);
2132 /* Rectangle to erase */
2133 rc.left = td->size_ow1;
2134 rc.right = rc.left + td->cols * td->tile_wid;
2135 rc.top = td->size_oh1;
2136 rc.bottom = rc.top + td->rows * td->tile_hgt;
2140 SetBkColor(hdc, RGB(0, 0, 0));
2141 SelectObject(hdc, td->font_id);
2142 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2147 rc.left = 0; rc.top = 0;
2150 ReleaseDC(td->w, hdc);
2158 * Hack -- make a noise
2160 static errr Term_xtra_win_noise(void)
2162 MessageBeep(MB_ICONASTERISK);
2168 * Hack -- make a sound
2170 static errr Term_xtra_win_sound(int v)
2175 #endif /* USE_SOUND */
2177 /* Sound disabled */
2178 if (!use_sound) return (1);
2181 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2185 /* Count the samples */
2186 for (i = 0; i < SAMPLE_MAX; i++)
2188 if (!sound_file[v][i])
2193 if (i == 0) return (1);
2195 /* Build the path */
2196 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_simple(i)]);
2200 /* Play the sound, catch errors */
2201 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2205 /* Play the sound, catch errors */
2206 return (sndPlaySound(buf, SND_ASYNC));
2210 #else /* USE_SOUND */
2215 #endif /* USE_SOUND */
2220 * Delay for "x" milliseconds
2222 static int Term_xtra_win_delay(int v)
2236 t = GetTickCount() + v;
2239 while (GetTickCount() < t)
2241 /* Handle messages */
2242 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2244 TranslateMessage(&msg);
2245 DispatchMessage(&msg);
2257 * Do a "special thing"
2259 static errr Term_xtra_win(int n, int v)
2261 /* Handle a subset of the legal requests */
2264 /* Make a bell sound */
2265 case TERM_XTRA_NOISE:
2267 return (Term_xtra_win_noise());
2270 /* Make a special sound */
2271 case TERM_XTRA_SOUND:
2273 return (Term_xtra_win_sound(v));
2276 /* Process random events */
2277 case TERM_XTRA_BORED:
2279 return (Term_xtra_win_event(0));
2282 /* Process an event */
2283 case TERM_XTRA_EVENT:
2285 return (Term_xtra_win_event(v));
2288 /* Flush all events */
2289 case TERM_XTRA_FLUSH:
2291 return (Term_xtra_win_flush());
2294 /* Clear the screen */
2295 case TERM_XTRA_CLEAR:
2297 return (Term_xtra_win_clear());
2300 /* React to global changes */
2301 case TERM_XTRA_REACT:
2303 return (Term_xtra_win_react());
2306 /* Delay for some milliseconds */
2307 case TERM_XTRA_DELAY:
2309 return (Term_xtra_win_delay(v));
2320 * Low level graphics (Assumes valid input).
2322 * Draw a "cursor" at (x,y), using a "yellow box".
2324 static errr Term_curs_win(int x, int y)
2326 term_data *td = (term_data*)(Term->data);
2331 int tile_wid, tile_hgt;
2335 tile_wid = td->map_tile_wid;
2336 tile_hgt = td->map_tile_hgt;
2340 tile_wid = td->tile_wid;
2341 tile_hgt = td->tile_hgt;
2344 /* Frame the grid */
2345 rc.left = x * tile_wid + td->size_ow1;
2346 rc.right = rc.left + tile_wid;
2347 rc.top = y * tile_hgt + td->size_oh1;
2348 rc.bottom = rc.top + tile_hgt;
2350 /* Cursor is done as a yellow "box" */
2352 FrameRect(hdc, &rc, hbrYellow);
2353 ReleaseDC(td->w, hdc);
2361 * Low level graphics (Assumes valid input).
2363 * Draw a "big cursor" at (x,y), using a "yellow box".
2365 static errr Term_bigcurs_win(int x, int y)
2367 term_data *td = (term_data*)(Term->data);
2372 int tile_wid, tile_hgt;
2376 /* Normal cursor in map window */
2377 Term_curs_win(x, y);
2382 tile_wid = td->tile_wid;
2383 tile_hgt = td->tile_hgt;
2386 /* Frame the grid */
2387 rc.left = x * tile_wid + td->size_ow1;
2388 rc.right = rc.left + 2 * tile_wid;
2389 rc.top = y * tile_hgt + td->size_oh1;
2390 rc.bottom = rc.top + tile_hgt;
2392 /* Cursor is done as a yellow "box" */
2394 FrameRect(hdc, &rc, hbrYellow);
2395 ReleaseDC(td->w, hdc);
2403 * Low level graphics (Assumes valid input).
2405 * Erase a "block" of "n" characters starting at (x,y).
2407 static errr Term_wipe_win(int x, int y, int n)
2409 term_data *td = (term_data*)(Term->data);
2414 /* Rectangle to erase in client coords */
2415 rc.left = x * td->tile_wid + td->size_ow1;
2416 rc.right = rc.left + n * td->tile_wid;
2417 rc.top = y * td->tile_hgt + td->size_oh1;
2418 rc.bottom = rc.top + td->tile_hgt;
2421 SetBkColor(hdc, RGB(0, 0, 0));
2422 SelectObject(hdc, td->font_id);
2427 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2428 ReleaseDC(td->w, hdc);
2436 * Low level graphics. Assumes valid input.
2438 * Draw several ("n") chars, with an attr, at a given location.
2440 * All "graphic" data is handled by "Term_pict_win()", below.
2442 * One would think there is a more efficient method for telling a window
2443 * what color it should be using to draw with, but perhaps simply changing
2444 * it every time is not too inefficient. XXX XXX XXX
2446 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2448 term_data *td = (term_data*)(Term->data);
2452 #if 1 /* #ifdef JP */
2453 static HBITMAP WALL;
2454 static HBRUSH myBrush, oldBrush;
2456 static bool init_done = FALSE;
2459 WALL = LoadBitmap(hInstance, AppName);
2460 myBrush = CreatePatternBrush(WALL);
2465 /* Total rectangle */
2466 rc.left = x * td->tile_wid + td->size_ow1;
2467 rc.right = rc.left + n * td->tile_wid;
2468 rc.top = y * td->tile_hgt + td->size_oh1;
2469 rc.bottom = rc.top + td->tile_hgt;
2474 /* Background color */
2475 SetBkColor(hdc, RGB(0, 0, 0));
2477 /* Foreground color */
2480 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2484 SetTextColor(hdc, win_clr[a&0x0F]);
2488 SetTextColor(hdc, win_clr[a]);
2492 SelectObject(hdc, td->font_id);
2495 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2499 (td->tile_hgt != td->font_hgt) ||
2500 (td->tile_wid != td->font_wid))
2504 /* Erase complete rectangle */
2505 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2508 if (use_bg) DrawBG(hdc, &rc);
2511 rc.left += ((td->tile_wid - td->font_wid) / 2);
2512 rc.right = rc.left + td->font_wid;
2513 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2514 rc.bottom = rc.top + td->font_hgt;
2516 /* Dump each character */
2517 for (i = 0; i < n; i++)
2520 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2522 rc.right += td->font_wid;
2524 oldBrush = SelectObject(hdc, myBrush);
2525 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2528 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2530 SelectObject(hdc, oldBrush);
2531 SelectObject(hdc, oldPen);
2532 rc.right -= td->font_wid;
2536 rc.left += 2 * td->tile_wid;
2537 rc.right += 2 * td->tile_wid;
2539 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2541 rc.right += td->font_wid;
2543 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2545 rc.right -= td->font_wid;
2549 rc.left += 2 * td->tile_wid;
2550 rc.right += 2 * td->tile_wid;
2551 } else if (*(s+i)==127){
2552 oldBrush = SelectObject(hdc, myBrush);
2553 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2556 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2558 SelectObject(hdc, oldBrush);
2559 SelectObject(hdc, oldPen);
2562 rc.left += td->tile_wid;
2563 rc.right += td->tile_wid;
2566 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2570 rc.left += td->tile_wid;
2571 rc.right += td->tile_wid;
2576 oldBrush = SelectObject(hdc, myBrush);
2577 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2580 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2582 SelectObject(hdc, oldBrush);
2583 SelectObject(hdc, oldPen);
2586 rc.left += td->tile_wid;
2587 rc.right += td->tile_wid;
2590 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2594 rc.left += td->tile_wid;
2595 rc.right += td->tile_wid;
2599 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2603 rc.left += td->tile_wid;
2604 rc.right += td->tile_wid;
2615 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2620 ReleaseDC(td->w, hdc);
2628 * Low level graphics. Assumes valid input.
2630 * Draw an array of "special" attr/char pairs at the given location.
2632 * We use the "Term_pict_win()" function for "graphic" data, which are
2633 * encoded by setting the "high-bits" of both the "attr" and the "char"
2634 * data. We use the "attr" to represent the "row" of the main bitmap,
2635 * and the "char" to represent the "col" of the main bitmap. The use
2636 * of this function is induced by the "higher_pict" flag.
2638 * If "graphics" is not available, we simply "wipe" the given grids.
2640 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2642 term_data *td = (term_data*)(Term->data);
2648 int x2, y2, w2, h2, tw2;
2660 /* Erase the grids */
2661 return (Term_wipe_win(x, y, n));
2664 /* Size of bitmap cell */
2665 w1 = infGraph.CellWidth;
2666 h1 = infGraph.CellHeight;
2668 /* Size of window cell */
2671 w2 = td->map_tile_wid;
2672 h2 = td->map_tile_hgt;
2681 if (use_bigtile) tw2 *= 2;
2684 /* Location of window cell */
2685 x2 = x * w2 + td->size_ow1;
2686 y2 = y * h2 + td->size_oh1;
2692 hdcSrc = CreateCompatibleDC(hdc);
2693 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2695 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2697 hdcMask = CreateCompatibleDC(hdc);
2698 SelectObject(hdcMask, infMask.hBitmap);
2701 /* Draw attr/char pairs */
2702 for (i = 0; i < n; i++, x2 += w2)
2707 /* Extract picture */
2708 int row = (a & 0x7F);
2709 int col = (c & 0x7F);
2711 /* Location of bitmap cell */
2715 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2717 x3 = (tcp[i] & 0x7F) * w1;
2718 y3 = (tap[i] & 0x7F) * h1;
2721 if ((w1 == tw2) && (h1 == h2))
2723 /* Copy the terrain picture from the bitmap to the window */
2724 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2726 /* Mask out the tile */
2727 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2730 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2733 /* Need to stretch */
2736 /* Set the correct mode for stretching the tiles */
2737 SetStretchBltMode(hdc, COLORONCOLOR);
2739 /* Copy the terrain picture from the bitmap to the window */
2740 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
2742 /* Only draw if terrain and overlay are different */
2743 if ((x1 != x3) || (y1 != y3))
2745 /* Mask out the tile */
2746 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2749 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2756 if ((w1 == tw2) && (h1 == h2))
2758 /* Copy the picture from the bitmap to the window */
2759 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2762 /* Need to stretch */
2765 /* Set the correct mode for stretching the tiles */
2766 SetStretchBltMode(hdc, COLORONCOLOR);
2768 /* Copy the picture from the bitmap to the window */
2769 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2775 SelectObject(hdcSrc, hbmSrcOld);
2778 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2781 SelectObject(hdcMask, hbmSrcOld);
2786 ReleaseDC(td->w, hdc);
2788 #else /* USE_GRAPHICS */
2790 /* Just erase this grid */
2791 return (Term_wipe_win(x, y, n));
2793 #endif /* USE_GRAPHICS */
2800 static void windows_map(void)
2802 term_data *td = &data[0];
2804 int x, min_x, max_x;
2805 int y, min_y, max_y;
2809 /* Only in graphics mode */
2810 if (!use_graphics) return;
2813 Term_xtra_win_clear();
2815 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2816 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2817 td->map_active = TRUE;
2827 for (x = min_x; x < max_x; x++)
2829 for (y = min_y; y < max_y; y++)
2831 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
2833 /* Ignore non-graphics */
2834 if ((a & 0x80) && (c & 0x80))
2836 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2841 /* Hilite the player */
2842 Term_curs_win(px - min_x, py - min_y);
2844 /* Wait for a keypress, flush key buffer */
2845 Term_inkey(&c, TRUE, TRUE);
2848 /* Switch off the map display */
2849 td->map_active = FALSE;
2851 /* Restore screen */
2852 Term_xtra_win_clear();
2857 /*** Other routines ***/
2861 * Create and initialize a "term_data" given a title
2863 static void term_data_link(term_data *td)
2867 /* Initialize the term */
2868 term_init(t, td->cols, td->rows, td->keys);
2870 /* Use a "software" cursor */
2871 t->soft_cursor = TRUE;
2873 /* Use "Term_pict" for "graphic" data */
2874 t->higher_pict = TRUE;
2876 /* Erase with "white space" */
2877 t->attr_blank = TERM_WHITE;
2878 t->char_blank = ' ';
2881 /* Prepare the init/nuke hooks */
2882 t->init_hook = Term_init_win;
2883 t->nuke_hook = Term_nuke_win;
2886 /* Prepare the template hooks */
2887 t->user_hook = Term_user_win;
2888 t->xtra_hook = Term_xtra_win;
2889 t->curs_hook = Term_curs_win;
2890 t->bigcurs_hook = Term_bigcurs_win;
2891 t->wipe_hook = Term_wipe_win;
2892 t->text_hook = Term_text_win;
2893 t->pict_hook = Term_pict_win;
2895 /* Remember where we came from */
2896 t->data = (vptr)(td);
2901 * Create the windows
2903 * First, instantiate the "default" values, then read the "ini_file"
2904 * to over-ride selected values, then create the windows, and fonts.
2906 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2907 * must make active to realize the palette. XXX XXX XXX
2909 static void init_windows(void)
2915 #if 0 /* #ifndef JP */
2921 WIPE(td, term_data);
2925 td->s = angband_term_name[0];
2939 #if 1 /* #ifdef JP */
2943 for (i = 1; i < MAX_TERM_DATA; i++)
2946 WIPE(td, term_data);
2947 td->s = angband_term_name[i];
2951 td->visible = FALSE;
2956 td->pos_x = (7 - i) * 30;
2957 td->pos_y = (7 - i) * 20;
2959 #if 1 /* #ifdef JP */
2969 /* Main window (need these before term_getsize gets called) */
2971 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2972 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2977 /* Sub windows (need these before term_getsize gets called) */
2978 for (i = 1; i < MAX_TERM_DATA; i++)
2981 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2982 td->dwExStyle = (WS_EX_TOOLWINDOW);
2987 for (i = 0; i < MAX_TERM_DATA; i++)
2991 #if 1 /* #ifdef JP */
2992 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2994 td->lf.lfCharSet = SHIFTJIS_CHARSET;
2996 td->lf.lfCharSet = ANSI_CHARSET;
2998 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2999 /* Activate the chosen font */
3000 term_force_font(td, NULL);
3001 td->tile_wid = td->font_wid;
3002 td->tile_hgt = td->font_hgt;
3004 /* Access the standard font file */
3005 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3007 /* Activate the chosen font */
3008 if (term_force_font(td, buf))
3010 /* Access the standard font file */
3011 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3013 /* Force the use of that font */
3014 (void)term_force_font(td, buf);
3020 /* Assume not bizarre */
3021 td->bizarre = FALSE;
3026 /* Analyze the font */
3029 /* Resize the window */
3030 term_window_resize(td);
3034 /* Sub windows (reverse order) */
3035 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3040 td->w = CreateWindowEx(td->dwExStyle, AngList,
3042 td->pos_x, td->pos_y,
3043 td->size_wid, td->size_hgt,
3044 HWND_DESKTOP, NULL, hInstance, NULL);
3047 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3049 if (!td->w) quit("Failed to create sub-window");
3055 td->size_hack = TRUE;
3056 ShowWindow(td->w, SW_SHOW);
3057 td->size_hack = FALSE;
3061 angband_term[i] = &td->t;
3065 /* Activate the window */
3066 SetActiveWindow(td->w);
3071 term_window_pos(&data[i], HWND_TOPMOST);
3075 term_window_pos(&data[i], td->w);
3085 td->w = CreateWindowEx(td->dwExStyle, AppName,
3087 td->pos_x, td->pos_y,
3088 td->size_wid, td->size_hgt,
3089 HWND_DESKTOP, NULL, hInstance, NULL);
3092 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3094 if (!td->w) quit("Failed to create Angband window");
3099 angband_term[0] = &td->t;
3101 /* Activate the main window */
3102 SetActiveWindow(td->w);
3104 /* Bring main window back to top */
3105 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3108 /* New palette XXX XXX XXX */
3109 (void)new_palette();
3112 /* Create a "brush" for drawing the "cursor" */
3113 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3116 /* Process pending messages */
3117 (void)Term_xtra_win_flush();
3125 static void setup_menus(void)
3129 HMENU hm = GetMenu(data[0].w);
3132 /* Menu "File", Disable all */
3133 EnableMenuItem(hm, IDM_FILE_NEW,
3134 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3135 EnableMenuItem(hm, IDM_FILE_OPEN,
3136 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3137 EnableMenuItem(hm, IDM_FILE_SAVE,
3138 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3139 EnableMenuItem(hm, IDM_FILE_EXIT,
3140 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3141 EnableMenuItem(hm, IDM_FILE_SCORE,
3142 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3145 /* No character available */
3146 if (!character_generated)
3148 /* Menu "File", Item "New" */
3149 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3151 /* Menu "File", Item "Open" */
3152 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3155 /* A character available */
3156 if (character_generated)
3158 /* Menu "File", Item "Save" */
3159 EnableMenuItem(hm, IDM_FILE_SAVE,
3160 MF_BYCOMMAND | MF_ENABLED);
3163 /* Menu "File", Item "Exit" */
3164 EnableMenuItem(hm, IDM_FILE_EXIT,
3165 MF_BYCOMMAND | MF_ENABLED);
3167 EnableMenuItem(hm, IDM_FILE_SCORE,
3168 MF_BYCOMMAND | MF_ENABLED);
3171 /* Menu "Window::Visibility" */
3172 for (i = 0; i < MAX_TERM_DATA; i++)
3174 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3175 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3177 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3178 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3180 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3181 MF_BYCOMMAND | MF_ENABLED);
3184 /* Menu "Window::Font" */
3185 for (i = 0; i < MAX_TERM_DATA; i++)
3187 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3188 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3190 if (data[i].visible)
3192 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3193 MF_BYCOMMAND | MF_ENABLED);
3197 /* Menu "Window::Window Position Fix" */
3198 for (i = 0; i < MAX_TERM_DATA; i++)
3200 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3201 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3203 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3204 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3206 if (data[i].visible)
3208 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3209 MF_BYCOMMAND | MF_ENABLED);
3213 /* Menu "Window::Bizarre Display" */
3214 for (i = 0; i < MAX_TERM_DATA; i++)
3216 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3217 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3219 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3220 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3222 if (data[i].visible)
3224 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3225 MF_BYCOMMAND | MF_ENABLED);
3230 /* Menu "Window::Increase Tile Width" */
3231 for (i = 0; i < MAX_TERM_DATA; i++)
3233 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3234 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3236 if (data[i].visible)
3238 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3239 MF_BYCOMMAND | MF_ENABLED);
3244 /* Menu "Window::Decrease Tile Width" */
3245 for (i = 0; i < MAX_TERM_DATA; i++)
3247 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3248 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3250 if (data[i].visible)
3252 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3253 MF_BYCOMMAND | MF_ENABLED);
3258 /* Menu "Window::Increase Tile Height" */
3259 for (i = 0; i < MAX_TERM_DATA; i++)
3261 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3262 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3264 if (data[i].visible)
3266 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3267 MF_BYCOMMAND | MF_ENABLED);
3272 /* Menu "Window::Decrease Tile Height" */
3273 for (i = 0; i < MAX_TERM_DATA; i++)
3275 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3276 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3278 if (data[i].visible)
3280 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3281 MF_BYCOMMAND | MF_ENABLED);
3286 /* Menu "Options", disable all */
3287 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3288 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3289 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3290 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3291 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3292 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3293 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3294 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3295 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3296 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3298 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3299 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3302 /* Menu "Options", Item "Map" */
3303 if (use_graphics != GRAPHICS_NONE)
3304 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3306 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3307 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3309 /* Menu "Options", update all */
3310 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3311 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3312 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3313 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3314 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3315 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3316 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3317 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3318 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3319 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3320 CheckMenuItem(hm, IDM_OPTIONS_BG,
3321 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3323 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3324 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3328 /* Menu "Options", Item "Graphics" */
3329 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3330 /* Menu "Options", Item "Graphics" */
3331 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3332 /* Menu "Options", Item "Graphics" */
3333 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3334 /* Menu "Options", Item "Graphics" */
3335 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3336 #endif /* USE_GRAPHICS */
3339 /* Menu "Options", Item "Sound" */
3340 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3341 #endif /* USE_SOUND */
3344 /* Menu "Options", Item "ScreenSaver" */
3345 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3346 MF_BYCOMMAND | MF_ENABLED);
3347 #endif /* USE_SAVER */
3352 * Check for double clicked (or dragged) savefile
3354 * Apparently, Windows copies the entire filename into the first
3355 * piece of the "command line string". Perhaps we should extract
3356 * the "basename" of that filename and append it to the "save" dir.
3358 static void check_for_save_file(LPSTR cmd_line)
3368 /* Extract filename */
3369 strcat(savefile, s);
3371 /* Validate the file */
3372 validate_file(savefile);
3374 /* Game in progress */
3375 game_in_progress = TRUE;
3383 * Process a menu command
3385 static void process_menus(WORD wCmd)
3402 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3404 plog("You cannot do that yet...");
3408 else if (game_in_progress)
3411 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3413 plog("You can't start a new game while you're still playing!");
3419 game_in_progress = TRUE;
3433 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3435 plog("You cannot do that yet...");
3439 else if (game_in_progress)
3442 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3444 plog("You can't open a new game while you're still playing!");
3450 memset(&ofn, 0, sizeof(ofn));
3451 ofn.lStructSize = sizeof(ofn);
3452 ofn.hwndOwner = data[0].w;
3453 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3454 ofn.nFilterIndex = 1;
3455 ofn.lpstrFile = savefile;
3456 ofn.nMaxFile = 1024;
3457 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3458 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3460 if (GetOpenFileName(&ofn))
3462 /* Load 'savefile' */
3463 validate_file(savefile);
3464 game_in_progress = TRUE;
3476 if (game_in_progress && character_generated)
3482 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3484 plog("You may not do that right now.");
3490 /* Hack -- Forget messages */
3495 do_cmd_save_game(FALSE);
3496 #else /* ZANGBAND */
3498 #endif /* ZANGBAND */
3503 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3505 plog("You may not do that right now.");
3515 if (game_in_progress && character_generated)
3521 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3523 plog("You may not do that right now.");
3529 /* Hack -- Forget messages */
3538 /* do_cmd_save_game(FALSE); */
3539 #else /* ZANGBAND */
3540 /* do_cmd_save_game(); */
3541 #endif /* ZANGBAND */
3542 Term_key_push(SPECIAL_KEY_QUIT);
3550 case IDM_FILE_SCORE:
3554 /* Build the filename */
3555 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3557 /* Open the binary high score file, for reading */
3558 highscore_fd = fd_open(buf, O_RDONLY);
3560 /* Paranoia -- No score file */
3561 if (highscore_fd < 0)
3563 msg_print("Score file unavailable.");
3573 /* Display the scores */
3574 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3576 /* Shut the high score file */
3577 (void)fd_close(highscore_fd);
3579 /* Forget the high score fd */
3585 /* Hack - Flush it */
3593 case IDM_WINDOW_VIS_0:
3596 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3598 plog("You are not allowed to do that!");
3605 /* Window visibility */
3606 case IDM_WINDOW_VIS_1:
3607 case IDM_WINDOW_VIS_2:
3608 case IDM_WINDOW_VIS_3:
3609 case IDM_WINDOW_VIS_4:
3610 case IDM_WINDOW_VIS_5:
3611 case IDM_WINDOW_VIS_6:
3612 case IDM_WINDOW_VIS_7:
3614 i = wCmd - IDM_WINDOW_VIS_0;
3616 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3623 ShowWindow(td->w, SW_SHOW);
3624 term_data_redraw(td);
3628 td->visible = FALSE;
3630 ShowWindow(td->w, SW_HIDE);
3637 case IDM_WINDOW_FONT_0:
3638 case IDM_WINDOW_FONT_1:
3639 case IDM_WINDOW_FONT_2:
3640 case IDM_WINDOW_FONT_3:
3641 case IDM_WINDOW_FONT_4:
3642 case IDM_WINDOW_FONT_5:
3643 case IDM_WINDOW_FONT_6:
3644 case IDM_WINDOW_FONT_7:
3646 i = wCmd - IDM_WINDOW_FONT_0;
3648 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3652 term_change_font(td);
3657 /* Window Z Position */
3658 case IDM_WINDOW_POS_1:
3659 case IDM_WINDOW_POS_2:
3660 case IDM_WINDOW_POS_3:
3661 case IDM_WINDOW_POS_4:
3662 case IDM_WINDOW_POS_5:
3663 case IDM_WINDOW_POS_6:
3664 case IDM_WINDOW_POS_7:
3666 i = wCmd - IDM_WINDOW_POS_0;
3668 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3672 if (!td->posfix && td->visible)
3675 term_window_pos(td, HWND_TOPMOST);
3680 term_window_pos(td, data[0].w);
3686 /* Bizarre Display */
3687 case IDM_WINDOW_BIZ_0:
3688 case IDM_WINDOW_BIZ_1:
3689 case IDM_WINDOW_BIZ_2:
3690 case IDM_WINDOW_BIZ_3:
3691 case IDM_WINDOW_BIZ_4:
3692 case IDM_WINDOW_BIZ_5:
3693 case IDM_WINDOW_BIZ_6:
3694 case IDM_WINDOW_BIZ_7:
3696 i = wCmd - IDM_WINDOW_BIZ_0;
3698 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3702 td->bizarre = !td->bizarre;
3706 term_window_resize(td);
3711 /* Increase Tile Width */
3712 case IDM_WINDOW_I_WID_0:
3713 case IDM_WINDOW_I_WID_1:
3714 case IDM_WINDOW_I_WID_2:
3715 case IDM_WINDOW_I_WID_3:
3716 case IDM_WINDOW_I_WID_4:
3717 case IDM_WINDOW_I_WID_5:
3718 case IDM_WINDOW_I_WID_6:
3719 case IDM_WINDOW_I_WID_7:
3721 i = wCmd - IDM_WINDOW_I_WID_0;
3723 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3731 term_window_resize(td);
3736 /* Decrease Tile Height */
3737 case IDM_WINDOW_D_WID_0:
3738 case IDM_WINDOW_D_WID_1:
3739 case IDM_WINDOW_D_WID_2:
3740 case IDM_WINDOW_D_WID_3:
3741 case IDM_WINDOW_D_WID_4:
3742 case IDM_WINDOW_D_WID_5:
3743 case IDM_WINDOW_D_WID_6:
3744 case IDM_WINDOW_D_WID_7:
3746 i = wCmd - IDM_WINDOW_D_WID_0;
3748 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3756 term_window_resize(td);
3761 /* Increase Tile Height */
3762 case IDM_WINDOW_I_HGT_0:
3763 case IDM_WINDOW_I_HGT_1:
3764 case IDM_WINDOW_I_HGT_2:
3765 case IDM_WINDOW_I_HGT_3:
3766 case IDM_WINDOW_I_HGT_4:
3767 case IDM_WINDOW_I_HGT_5:
3768 case IDM_WINDOW_I_HGT_6:
3769 case IDM_WINDOW_I_HGT_7:
3771 i = wCmd - IDM_WINDOW_I_HGT_0;
3773 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3781 term_window_resize(td);
3786 /* Decrease Tile Height */
3787 case IDM_WINDOW_D_HGT_0:
3788 case IDM_WINDOW_D_HGT_1:
3789 case IDM_WINDOW_D_HGT_2:
3790 case IDM_WINDOW_D_HGT_3:
3791 case IDM_WINDOW_D_HGT_4:
3792 case IDM_WINDOW_D_HGT_5:
3793 case IDM_WINDOW_D_HGT_6:
3794 case IDM_WINDOW_D_HGT_7:
3796 i = wCmd - IDM_WINDOW_D_HGT_0;
3798 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3806 term_window_resize(td);
3811 case IDM_OPTIONS_NO_GRAPHICS:
3816 plog("You may not do that right now.");
3820 /* Toggle "arg_graphics" */
3821 if (arg_graphics != GRAPHICS_NONE)
3823 arg_graphics = GRAPHICS_NONE;
3825 /* React to changes */
3826 Term_xtra_win_react();
3828 /* Hack -- Force redraw */
3829 Term_key_push(KTRL('R'));
3835 case IDM_OPTIONS_OLD_GRAPHICS:
3840 plog("You may not do that right now.");
3844 /* Toggle "arg_graphics" */
3845 if (arg_graphics != GRAPHICS_ORIGINAL)
3847 arg_graphics = GRAPHICS_ORIGINAL;
3849 /* React to changes */
3850 Term_xtra_win_react();
3852 /* Hack -- Force redraw */
3853 Term_key_push(KTRL('R'));
3859 case IDM_OPTIONS_NEW_GRAPHICS:
3864 plog("You may not do that right now.");
3868 /* Toggle "arg_graphics" */
3869 if (arg_graphics != GRAPHICS_ADAM_BOLT)
3871 arg_graphics = GRAPHICS_ADAM_BOLT;
3873 /* React to changes */
3874 Term_xtra_win_react();
3876 /* Hack -- Force redraw */
3877 Term_key_push(KTRL('R'));
3883 case IDM_OPTIONS_BIGTILE:
3885 term_data *td = &data[0];
3890 plog("You may not do that right now.");
3894 /* Toggle "arg_sound" */
3895 arg_bigtile = !arg_bigtile;
3898 Term_activate(&td->t);
3900 /* Resize the term */
3901 Term_resize(td->cols, td->rows);
3904 InvalidateRect(td->w, NULL, TRUE);
3909 case IDM_OPTIONS_SOUND:
3914 plog("You may not do that right now.");
3918 /* Toggle "arg_sound" */
3919 arg_sound = !arg_sound;
3921 /* React to changes */
3922 Term_xtra_win_react();
3924 /* Hack -- Force redraw */
3925 Term_key_push(KTRL('R'));
3931 case IDM_OPTIONS_BG:
3936 plog("You may not do that right now.");
3940 /* Toggle "use_bg" */
3945 /* React to changes */
3946 Term_xtra_win_react();
3948 /* Hack -- Force redraw */
3949 Term_key_push(KTRL('R'));
3955 case IDM_OPTIONS_OPEN_BG:
3960 plog("You may not do that right now.");
3965 memset(&ofn, 0, sizeof(ofn));
3966 ofn.lStructSize = sizeof(ofn);
3967 ofn.hwndOwner = data[0].w;
3968 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3969 ofn.nFilterIndex = 1;
3970 ofn.lpstrFile = bg_bitmap_file;
3971 ofn.nMaxFile = 1023;
3972 ofn.lpstrInitialDir = NULL;
3974 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
3976 ofn.lpstrTitle = "Choose wall paper.";
3978 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3980 if (GetOpenFileName(&ofn))
3982 /* Load 'savefile' */
3987 /* React to changes */
3988 Term_xtra_win_react();
3990 /* Hack -- Force redraw */
3991 Term_key_push(KTRL('R'));
3996 case IDM_DUMP_SCREEN_HTML:
3998 static char buf[1024] = "";
3999 memset(&ofn, 0, sizeof(ofn));
4000 ofn.lStructSize = sizeof(ofn);
4001 ofn.hwndOwner = data[0].w;
4002 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4003 ofn.nFilterIndex = 1;
4004 ofn.lpstrFile = buf;
4005 ofn.nMaxFile = 1023;
4006 ofn.lpstrDefExt = "html";
4007 ofn.lpstrInitialDir = NULL;
4009 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
4011 ofn.lpstrTitle = "Save screen dump as HTML.";
4013 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4015 if (GetSaveFileName(&ofn))
4017 do_cmd_save_screen_html_aux(buf, 0);
4024 case IDM_OPTIONS_SAVER:
4028 DestroyWindow(hwndSaver);
4033 /* Create a screen scaver window */
4034 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4035 "Angband Screensaver",
4036 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4037 0, 0, GetSystemMetrics(SM_CXSCREEN),
4038 GetSystemMetrics(SM_CYSCREEN),
4039 NULL, NULL, hInstance, NULL);
4043 /* Push the window to the bottom XXX XXX XXX */
4044 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4049 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
4051 plog("Failed to create saver window");
4061 case IDM_OPTIONS_MAP:
4067 case IDM_HELP_CONTENTS:
4071 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4072 if (check_file(tmp))
4074 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4079 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4080 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4082 plog_fmt("Cannot find help file: %s", tmp);
4083 plog("Use the online help files instead.");
4088 #else /* HTML_HELP */
4091 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4092 if (check_file(tmp))
4094 sprintf(buf, "winhelp.exe %s", tmp);
4095 WinExec(buf, SW_NORMAL);
4100 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4101 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4103 plog_fmt("Cannot find help file: %s", tmp);
4104 plog("Use the online help files instead.");
4109 #endif /* HTML_HELP */
4115 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4122 /* Extract the modifiers */
4123 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4124 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4125 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4127 Term_no_press = (ma) ? TRUE : FALSE;
4129 /* Handle "special" keys */
4130 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4132 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4133 bool numpad = FALSE;
4135 /* Begin the macro trigger */
4138 /* Send the modifiers */
4139 if (mc) Term_keypress('C');
4140 if (ms) Term_keypress('S');
4141 if (ma) Term_keypress('A');
4143 /* Extract "scan code" */
4144 i = LOBYTE(HIWORD(lParam));
4146 /* Introduce the scan code */
4149 /* Extended key bit */
4152 /* Numpad Enter and '/' are extended key */
4154 Term_no_press = TRUE;
4155 case VK_RETURN: /* Enter */
4158 /* Other extended keys are on full keyboard */
4174 Term_no_press = TRUE;
4178 case VK_PRIOR: /* Page Up */
4179 case VK_NEXT: /* Page Down */
4189 /* Special modifiers for keypad keys */
4190 if (numpad) Term_keypress('K');
4192 /* Encode the hexidecimal scan code */
4193 Term_keypress(hexsym[i/16]);
4194 Term_keypress(hexsym[i%16]);
4196 /* End the macro trigger */
4207 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4208 WPARAM wParam, LPARAM lParam);
4209 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4210 WPARAM wParam, LPARAM lParam)
4211 #else /* __MWERKS__ */
4212 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4213 WPARAM wParam, LPARAM lParam)
4214 #endif /* __MWERKS__ */
4220 MINMAXINFO FAR *lpmmi;
4226 /* Acquire proper "term_data" info */
4227 td = (term_data *)GetWindowLong(hWnd, 0);
4229 /* Handle message */
4235 SetWindowLong(hWnd, 0, (LONG)(my_td));
4245 case WM_GETMINMAXINFO:
4247 MINMAXINFO FAR *lpmmi;
4250 lpmmi = (MINMAXINFO FAR *)lParam;
4252 /* this message was sent before WM_NCCREATE */
4255 /* Minimum window size is 80x24 */
4256 rc.left = rc.top = 0;
4257 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4258 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4261 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4263 /* Save minimum size */
4264 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4265 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4272 BeginPaint(hWnd, &ps);
4273 if (td) term_data_redraw(td);
4274 EndPaint(hWnd, &ps);
4275 ValidateRect(hWnd, NULL);
4282 if (process_keydown(wParam, lParam))
4289 if (Term_no_press) Term_no_press = FALSE;
4290 else Term_keypress(wParam);
4302 if (game_in_progress && character_generated)
4307 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4309 plog("You may not do that right now.");
4314 /* Hack -- Forget messages */
4323 /* do_cmd_save_game(FALSE); */
4324 #else /* ZANGBAND */
4325 /* do_cmd_save_game(); */
4326 #endif /* ZANGBAND */
4327 Term_key_push(SPECIAL_KEY_QUIT);
4334 case WM_QUERYENDSESSION:
4336 if (game_in_progress && character_generated)
4338 /* Hack -- Forget messages */
4341 /* Mega-Hack -- Delay death */
4342 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4345 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "----¥²¡¼¥àÃæÃÇ----");
4347 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "---- Save and Exit Game ----");
4350 /* Hardcode panic save */
4351 p_ptr->panic_save = 1;
4353 /* Forbid suspend */
4354 signals_ignore_tstp();
4356 /* Indicate panic save */
4358 (void)strcpy(p_ptr->died_from, "(¶ÛµÞ¥»¡¼¥Ö)");
4360 (void)strcpy(p_ptr->died_from, "(panic save)");
4364 (void)save_player();
4378 process_menus(LOWORD(wParam));
4384 /* this message was sent before WM_NCCREATE */
4387 /* it was sent from inside CreateWindowEx */
4388 if (!td->w) return 1;
4390 /* was sent from WM_SIZE */
4391 if (td->size_hack) return 1;
4395 case SIZE_MINIMIZED:
4397 /* Hide sub-windows */
4398 for (i = 1; i < MAX_TERM_DATA; i++)
4400 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4405 case SIZE_MAXIMIZED:
4407 /* fall through XXX XXX XXX */
4412 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4413 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4416 if ((td->cols != cols) || (td->rows != rows))
4418 /* Save the new size */
4423 Term_activate(&td->t);
4425 /* Resize the term */
4426 Term_resize(td->cols, td->rows);
4429 InvalidateRect(td->w, NULL, TRUE);
4432 td->size_hack = TRUE;
4434 /* Show sub-windows */
4435 for (i = 1; i < MAX_TERM_DATA; i++)
4437 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4440 td->size_hack = FALSE;
4448 case WM_PALETTECHANGED:
4450 /* Ignore if palette change caused by itself */
4451 if ((HWND)wParam == hWnd) return 0;
4453 /* Fall through... */
4456 case WM_QUERYNEWPALETTE:
4458 if (!paletted) return 0;
4462 SelectPalette(hdc, hPal, FALSE);
4464 i = RealizePalette(hdc);
4466 /* if any palette entries changed, repaint the window. */
4467 if (i) InvalidateRect(hWnd, NULL, TRUE);
4469 ReleaseDC(hWnd, hdc);
4476 if (wParam && !HIWORD(lParam))
4478 /* Do something to sub-windows */
4479 for (i = 1; i < MAX_TERM_DATA; i++)
4481 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4484 /* Focus on main window */
4493 case WM_ACTIVATEAPP:
4495 for (i = 1; i < MAX_TERM_DATA; i++)
4501 ShowWindow(data[i].w, SW_SHOW);
4505 ShowWindow(data[i].w, SW_HIDE);
4512 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4517 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4518 WPARAM wParam, LPARAM lParam);
4519 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4520 WPARAM wParam, LPARAM lParam)
4521 #else /* __MWERKS__ */
4522 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4523 WPARAM wParam, LPARAM lParam)
4524 #endif /* __MWERKS__ */
4528 MINMAXINFO FAR *lpmmi;
4536 /* Acquire proper "term_data" info */
4537 td = (term_data *)GetWindowLong(hWnd, 0);
4539 /* Process message */
4545 SetWindowLong(hWnd, 0, (LONG)(my_td));
4555 case WM_GETMINMAXINFO:
4557 MINMAXINFO FAR *lpmmi;
4560 lpmmi = (MINMAXINFO FAR *)lParam;
4562 /* this message was sent before WM_NCCREATE */
4565 /* Minimum window size is 80x24 */
4566 rc.left = rc.top = 0;
4567 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4568 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4571 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4573 /* Save minimum size */
4574 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4575 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4585 /* this message was sent before WM_NCCREATE */
4588 /* it was sent from inside CreateWindowEx */
4589 if (!td->w) return 1;
4591 /* was sent from inside WM_SIZE */
4592 if (td->size_hack) return 1;
4594 td->size_hack = TRUE;
4596 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4597 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4600 if ((td->cols != cols) || (td->rows != rows))
4603 term *old_term = Term;
4605 /* Save the new size */
4610 Term_activate(&td->t);
4612 /* Resize the term */
4613 Term_resize(td->cols, td->rows);
4616 Term_activate(old_term);
4619 InvalidateRect(td->w, NULL, TRUE);
4621 /* HACK - Redraw all windows */
4622 p_ptr->window = 0xFFFFFFFF;
4626 td->size_hack = FALSE;
4633 BeginPaint(hWnd, &ps);
4634 if (td) term_data_redraw(td);
4635 EndPaint(hWnd, &ps);
4642 if (process_keydown(wParam, lParam))
4649 if (Term_no_press) Term_no_press = FALSE;
4650 else Term_keypress(wParam);
4654 case WM_PALETTECHANGED:
4656 /* ignore if palette change caused by itself */
4657 if ((HWND)wParam == hWnd) return FALSE;
4658 /* otherwise, fall through!!! */
4661 case WM_QUERYNEWPALETTE:
4663 if (!paletted) return 0;
4665 SelectPalette(hdc, hPal, FALSE);
4666 i = RealizePalette(hdc);
4667 /* if any palette entries changed, repaint the window. */
4668 if (i) InvalidateRect(hWnd, NULL, TRUE);
4669 ReleaseDC(hWnd, hdc);
4673 case WM_NCLBUTTONDOWN:
4677 if (wParam == HTCLOSE) wParam = HTSYSMENU;
4678 #endif /* HTCLOSE */
4680 if (wParam == HTSYSMENU)
4684 td->visible = FALSE;
4685 ShowWindow(td->w, SW_HIDE);
4695 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4701 #define MOUSE_SENS 40
4704 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4705 WPARAM wParam, LPARAM lParam);
4706 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4707 WPARAM wParam, LPARAM lParam)
4708 #else /* __MWERKS__ */
4709 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4710 WPARAM wParam, LPARAM lParam)
4711 #endif /* __MWERKS__ */
4713 static int iMouse = 0;
4714 static WORD xMouse = 0;
4715 static WORD yMouse = 0;
4738 if (LOWORD(wParam) == WA_INACTIVE) break;
4740 /* else fall through */
4744 case WM_LBUTTONDOWN:
4745 case WM_MBUTTONDOWN:
4746 case WM_RBUTTONDOWN:
4749 SendMessage(hWnd, WM_CLOSE, 0, 0);
4757 dx = LOWORD(lParam) - xMouse;
4758 dy = HIWORD(lParam) - yMouse;
4760 if (dx < 0) dx = -dx;
4761 if (dy < 0) dy = -dy;
4763 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
4765 SendMessage(hWnd, WM_CLOSE, 0, 0);
4769 /* Save last location */
4771 xMouse = LOWORD(lParam);
4772 yMouse = HIWORD(lParam);
4779 DestroyWindow(hwndSaver);
4786 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4789 #endif /* USE_SAVER */
4795 /*** Temporary Hooks ***/
4799 * Display warning message (see "z-util.c")
4801 static void hack_plog(cptr str)
4803 /* Give a warning */
4807 MessageBox(NULL, str, "·Ù¹ð¡ª",
4808 MB_ICONEXCLAMATION | MB_OK);
4810 MessageBox(NULL, str, "Warning",
4811 MB_ICONEXCLAMATION | MB_OK);
4819 * Display error message and quit (see "z-util.c")
4821 static void hack_quit(cptr str)
4823 /* Give a warning */
4827 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
4828 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4830 MessageBox(NULL, str, "Error",
4831 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4836 /* Unregister the classes */
4837 UnregisterClass(AppName, hInstance);
4839 /* Destroy the icon */
4840 if (hIcon) DestroyIcon(hIcon);
4848 /*** Various hooks ***/
4852 * Display warning message (see "z-util.c")
4854 static void hook_plog(cptr str)
4860 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
4861 MB_ICONEXCLAMATION | MB_OK);
4863 MessageBox(data[0].w, str, "Warning",
4864 MB_ICONEXCLAMATION | MB_OK);
4872 * Display error message and quit (see "z-util.c")
4874 static void hook_quit(cptr str)
4879 /* Give a warning */
4883 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
4884 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4886 MessageBox(data[0].w, str, "Error",
4887 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4893 /* Save the preferences */
4897 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
4899 /* Destroy all windows */
4900 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
4902 term_force_font(&data[i], NULL);
4903 if (data[i].font_want) string_free(data[i].font_want);
4904 if (data[i].w) DestroyWindow(data[i].w);
4908 /* Free the bitmap stuff */
4910 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
4911 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
4913 if (infMask.hPalette) DeleteObject(infMask.hPalette);
4914 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
4916 #endif /* USE_GRAPHICS */
4918 /*** Free some other stuff ***/
4920 DeleteObject(hbrYellow);
4925 if (hPal) DeleteObject(hPal);
4927 UnregisterClass(AppName, hInstance);
4929 if (hIcon) DestroyIcon(hIcon);
4936 /*** Initialize ***/
4942 static void init_stuff(void)
4949 /* Get program name with full path */
4950 GetModuleFileName(hInstance, path, 512);
4952 /* Save the "program name" XXX XXX XXX */
4955 /* Get the name of the "*.ini" file */
4956 strcpy(path + strlen(path) - 4, ".INI");
4958 /* Save the the name of the ini-file */
4959 ini_file = string_make(path);
4961 /* Analyze the path */
4967 if (path[i] == '\\')
4974 /* Add "lib" to the path */
4975 strcpy(path + i + 1, "lib\\");
4977 /* Validate the path */
4978 validate_dir(path, TRUE);
4980 /* Init the file paths */
4981 init_file_paths(path);
4983 /* Hack -- Validate the paths */
4984 validate_dir(ANGBAND_DIR_APEX, FALSE);
4985 validate_dir(ANGBAND_DIR_BONE, FALSE);
4987 /* Allow missing 'edit' directory */
4988 if (!check_dir(ANGBAND_DIR_EDIT))
4990 /* Must have 'data'! */
4991 validate_dir(ANGBAND_DIR_DATA, TRUE);
4995 /* Don't need 'data' */
4996 validate_dir(ANGBAND_DIR_DATA, FALSE);
4999 validate_dir(ANGBAND_DIR_FILE, TRUE);
5000 validate_dir(ANGBAND_DIR_HELP, FALSE);
5001 validate_dir(ANGBAND_DIR_INFO, FALSE);
5002 validate_dir(ANGBAND_DIR_PREF, TRUE);
5003 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5004 validate_dir(ANGBAND_DIR_USER, TRUE);
5005 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5007 /* Build the filename */
5009 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
5011 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
5015 /* Hack -- Validate the "news.txt" file */
5016 validate_file(path);
5019 #if 0 /* #ifndef JP */
5020 /* Build the "font" path */
5021 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5023 /* Allocate the path */
5024 ANGBAND_DIR_XTRA_FONT = string_make(path);
5026 /* Validate the "font" directory */
5027 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5029 /* Build the filename */
5030 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5032 /* Hack -- Validate the basic font */
5033 validate_file(path);
5039 /* Build the "graf" path */
5040 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5042 /* Allocate the path */
5043 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5045 /* Validate the "graf" directory */
5046 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5048 #endif /* USE_GRAPHICS */
5053 /* Build the "sound" path */
5054 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5056 /* Allocate the path */
5057 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5059 /* Validate the "sound" directory */
5060 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5062 #endif /* USE_SOUND */
5066 /* Build the "music" path */
5067 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5069 /* Allocate the path */
5070 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5072 /* Validate the "music" directory */
5073 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5075 #endif /* USE_MUSIC */
5077 /* Build the "help" path */
5078 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5080 /* Allocate the path */
5081 ANGBAND_DIR_XTRA_HELP = string_make(path);
5083 /* Validate the "help" directory */
5084 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5088 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5089 LPSTR lpCmdLine, int nCmdShow)
5104 if (hPrevInst == NULL)
5106 wc.style = CS_CLASSDC;
5107 wc.lpfnWndProc = AngbandWndProc;
5109 wc.cbWndExtra = 4; /* one long pointer to term_data */
5110 wc.hInstance = hInst;
5111 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5112 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5113 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5114 wc.lpszMenuName = AppName;
5115 wc.lpszClassName = AppName;
5117 if (!RegisterClass(&wc)) exit(1);
5119 wc.lpfnWndProc = AngbandListProc;
5120 wc.lpszMenuName = NULL;
5121 wc.lpszClassName = AngList;
5123 if (!RegisterClass(&wc)) exit(2);
5127 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5128 wc.lpfnWndProc = AngbandSaverProc;
5130 wc.lpszMenuName = NULL;
5131 wc.lpszClassName = "WindowsScreenSaverClass";
5133 if (!RegisterClass(&wc)) exit(3);
5139 /* Temporary hooks */
5140 plog_aux = hack_plog;
5141 quit_aux = hack_quit;
5142 core_aux = hack_quit;
5144 /* Prepare the filepaths */
5147 /* Initialize the keypress analyzer */
5148 for (i = 0; special_key_list[i]; ++i)
5150 special_key[special_key_list[i]] = TRUE;
5152 /* Initialize the keypress analyzer */
5153 for (i = 0; ignore_key_list[i]; ++i)
5155 ignore_key[ignore_key_list[i]] = TRUE;
5158 /* Determine if display is 16/256/true color */
5160 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5161 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5162 ReleaseDC(NULL, hdc);
5164 /* Initialize the colors */
5165 for (i = 0; i < 256; i++)
5169 /* Extract desired values */
5170 rv = angband_color_table[i][1];
5171 gv = angband_color_table[i][2];
5172 bv = angband_color_table[i][3];
5174 /* Extract the "complex" code */
5175 win_clr[i] = PALETTERGB(rv, gv, bv);
5177 /* Save the "simple" code */
5178 angband_color_table[i][0] = win_pal[i];
5181 /* Prepare the windows */
5187 /* Activate hooks */
5188 plog_aux = hook_plog;
5189 quit_aux = hook_quit;
5190 core_aux = hook_quit;
5192 /* Set the system suffix */
5193 ANGBAND_SYS = "win";
5195 /* Set the keyboard suffix */
5196 if (7 != GetKeyboardType(0))
5197 ANGBAND_KEYBOARD = "0";
5200 /* Japanese keyboard */
5201 switch (GetKeyboardType(1))
5203 case 0x0D01: case 0x0D02:
5204 case 0x0D03: case 0x0D04:
5205 case 0x0D05: case 0x0D06:
5207 ANGBAND_KEYBOARD = "NEC98";
5211 ANGBAND_KEYBOARD = "JAPAN";
5215 /* Catch nasty signals */
5221 /* We are now initialized */
5225 if(lpCmdLine[0] == '-'){
5226 switch(lpCmdLine[1])
5231 if (!lpCmdLine[2]) break;
5232 chuukei_server = TRUE;
5233 if(connect_chuukei_server(&lpCmdLine[2])<0){
5234 msg_print("connect fail");
5237 msg_print("connect");
5245 if (!lpCmdLine[2]) break;
5246 chuukei_client = TRUE;
5247 connect_chuukei_server(&lpCmdLine[2]);
5257 /* Did the user double click on a save file? */
5258 if(!chuukei_server) check_for_save_file(lpCmdLine);
5260 /* Did the user double click on a save file? */
5261 check_for_save_file(lpCmdLine);
5264 /* Prompt the user */
5266 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5268 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5273 /* Process messages forever */
5274 while (GetMessage(&msg, NULL, 0, 0))
5276 TranslateMessage(&msg);
5277 DispatchMessage(&msg);
5288 #endif /* WINDOWS */