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 */
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;
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);
737 plog_fmt("ÊÉ»æÍÑ¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
742 HDC wnddc, dcimage, dcbg;
743 HBITMAP bmimage, bmimage_old, bmbg_old;
749 dcimage = CreateCompatibleDC(wnddc);
750 dcbg = CreateCompatibleDC(wnddc);
752 bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
753 if (!bmimage) quit("bg.bmp¤¬Æɤߤ³¤á¤Ê¤¤¡ª");
754 bmimage_old = SelectObject(dcimage, bmimage);
756 CreateCompatibleBitmap();
758 ReleaseDC(hwnd, wnddc);
764 static void DrawBG(HDC hdc, RECT *r)
769 int x = r->left, y = r->top;
770 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
776 GetObject(hBG, sizeof(bm), &bm);
777 swid = bm.bmWidth; shgt = bm.bmHeight;
779 hdcSrc = CreateCompatibleDC(hdc);
780 hOld = SelectObject(hdcSrc, hBG);
784 cwid = MIN(swid - sx, r->right - nx);
787 chgt = MIN(shgt - sy, r->bottom - ny);
788 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
790 } while (ny < r->bottom);
793 } while (nx < r->right);
795 SelectObject(hdcSrc, hOld);
801 * Hack -- given a pathname, point at the filename
803 static cptr extract_file_name(cptr s)
807 /* Start at the end */
808 p = s + strlen(s) - 1;
810 /* Back up to divider */
811 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
813 /* Return file name */
820 * Hack -- given a simple filename, extract the "font size" info
822 * Return a pointer to a static buffer holding the capitalized base name.
825 static char *analyze_font(char *path, int *wp, int *hp)
831 /* Start at the end */
832 p = path + strlen(path) - 1;
834 /* Back up to divider */
835 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
837 /* Advance to file name */
843 /* Capitalize (be paranoid) */
844 if (islower(*s)) *s = toupper(*s);
848 s = my_strchr(p, 'X');
850 /* Extract font width */
854 hgt = s ? atoi(s+1) : 0;
867 * Check for existance of a file
869 static bool check_file(cptr s)
889 attrib = GetFileAttributes(path);
891 /* Require valid filename */
892 if (attrib == INVALID_FILE_NAME) return (FALSE);
894 /* Prohibit directory */
895 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
899 /* Examine and verify */
900 if (_dos_getfileattr(path, &attrib)) return (FALSE);
902 /* Prohibit something */
903 if (attrib & FA_LABEL) return (FALSE);
905 /* Prohibit directory */
906 if (attrib & FA_DIREC) return (FALSE);
916 * Check for existance of a directory
918 static bool check_dir(cptr s)
940 /* Remove trailing backslash */
941 if (i && (path[i-1] == '\\')) path[--i] = '\0';
946 attrib = GetFileAttributes(path);
948 /* Require valid filename */
949 if (attrib == INVALID_FILE_NAME) return (FALSE);
951 /* Require directory */
952 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
956 /* Examine and verify */
957 if (_dos_getfileattr(path, &attrib)) return (FALSE);
959 /* Prohibit something */
960 if (attrib & FA_LABEL) return (FALSE);
962 /* Require directory */
963 if (!(attrib & FA_DIREC)) return (FALSE);
975 static void validate_file(cptr s)
981 quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
983 quit_fmt("Cannot find required file:\n%s", s);
991 * Validate a directory
993 static void validate_dir(cptr s, bool vital)
998 /* This directory contains needed data */
1002 quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
1004 quit_fmt("Cannot find required directory:\n%s", s);
1008 /* Attempt to create this directory */
1011 quit_fmt("Unable to create directory:\n%s", s);
1018 * Get the "size" for a window
1020 static void term_getsize(term_data *td)
1027 if (td->cols < 1) td->cols = 1;
1028 if (td->rows < 1) td->rows = 1;
1031 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1032 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1034 /* Fake window size */
1036 rc.right = rc.left + wid;
1038 rc.bottom = rc.top + hgt;
1041 /* rc.right += 1; */
1042 /* rc.bottom += 1; */
1045 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1048 td->size_wid = rc.right - rc.left;
1049 td->size_hgt = rc.bottom - rc.top;
1051 /* See CreateWindowEx */
1054 /* Extract actual location */
1055 GetWindowRect(td->w, &rc);
1057 /* Save the location */
1058 td->pos_x = rc.left;
1064 * Write the "prefs" for a single term
1066 static void save_prefs_aux(term_data *td, cptr sec_name)
1076 strcpy(buf, td->visible ? "1" : "0");
1077 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1081 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1083 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1086 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1089 wsprintf(buf, "%d", td->lf.lfWidth);
1090 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1091 wsprintf(buf, "%d", td->lf.lfHeight);
1092 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1093 wsprintf(buf, "%d", td->lf.lfWeight);
1094 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1097 strcpy(buf, td->bizarre ? "1" : "0");
1098 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1101 wsprintf(buf, "%d", td->tile_wid);
1102 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1105 wsprintf(buf, "%d", td->tile_hgt);
1106 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1108 /* Window size (x) */
1109 wsprintf(buf, "%d", td->cols);
1110 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1112 /* Window size (y) */
1113 wsprintf(buf, "%d", td->rows);
1114 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1116 /* Acquire position */
1117 GetWindowRect(td->w, &rc);
1119 /* Window position (x) */
1120 wsprintf(buf, "%d", rc.left);
1121 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1123 /* Window position (y) */
1124 wsprintf(buf, "%d", rc.top);
1125 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1127 /* Window Z position */
1128 strcpy(buf, td->posfix ? "1" : "0");
1129 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1136 * We assume that the windows have all been initialized
1138 static void save_prefs(void)
1144 /* Save the "arg_graphics" flag */
1145 sprintf(buf, "%d", arg_graphics);
1146 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1148 /* Save the "arg_bigtile" flag */
1149 strcpy(buf, arg_bigtile ? "1" : "0");
1150 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1152 /* Save the "arg_sound" flag */
1153 strcpy(buf, arg_sound ? "1" : "0");
1154 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1157 strcpy(buf, use_bg ? "1" : "0");
1158 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1159 WritePrivateProfileString("Angband", "BackGroundBitmap",
1160 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1162 /* Save window prefs */
1163 for (i = 0; i < MAX_TERM_DATA; ++i)
1165 term_data *td = &data[i];
1167 sprintf(buf, "Term-%d", i);
1169 save_prefs_aux(td, buf);
1175 * Load the "prefs" for a single term
1177 static void load_prefs_aux(term_data *td, cptr sec_name)
1184 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1186 /* Desired font, with default */
1188 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1190 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1195 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1197 /* Analyze font, save desired font name */
1199 td->font_want = string_make(tmp);
1201 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1202 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1203 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1205 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1211 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1212 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1214 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1215 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1220 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1221 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1223 /* Window position */
1224 td->pos_x = GetPrivateProfileInt(sec_name, "PositionX", td->pos_x, ini_file);
1225 td->pos_y = GetPrivateProfileInt(sec_name, "PositionY", td->pos_y, ini_file);
1227 /* Window Z position */
1228 td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1235 static void load_prefs(void)
1241 /* Extract the "arg_graphics" flag */
1242 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1244 /* Extract the "arg_bigtile" flag */
1245 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1246 use_bigtile = arg_bigtile;
1248 /* Extract the "arg_sound" flag */
1249 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1252 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1253 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1255 /* Load window prefs */
1256 for (i = 0; i < MAX_TERM_DATA; ++i)
1258 term_data *td = &data[i];
1260 sprintf(buf, "Term-%d", i);
1262 load_prefs_aux(td, buf);
1269 * XXX XXX XXX - Taken from files.c.
1271 * Extract "tokens" from a buffer
1273 * This function uses "whitespace" as delimiters, and treats any amount of
1274 * whitespace as a single delimiter. We will never return any empty tokens.
1275 * When given an empty buffer, or a buffer containing only "whitespace", we
1276 * will return no tokens. We will never extract more than "num" tokens.
1278 * By running a token through the "text_to_ascii()" function, you can allow
1279 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1281 * We save pointers to the tokens in "tokens", and return the number found.
1283 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1295 /* Skip leading whitespace */
1296 for ( ; *s && isspace(*s); ++s) /* loop */;
1301 /* Find next whitespace, if any */
1302 for (t = s; *t && !isspace(*t); ++t) /* loop */;
1304 /* Nuke and advance (if necessary) */
1305 if (*t) *t++ = '\0';
1307 /* Save the token */
1318 static void load_sound_prefs(void)
1322 char ini_path[1024];
1323 char wav_path[1024];
1324 char *zz[SAMPLE_MAX];
1326 /* Access the sound.cfg */
1327 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1329 for (i = 0; i < SOUND_MAX; i++)
1331 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1333 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1335 for (j = 0; j < num; j++)
1337 /* Access the sound */
1338 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1340 /* Save the sound filename, if it exists */
1341 if (check_file(wav_path))
1342 sound_file[i][j] = string_make(zz[j]);
1347 #endif /* USE_SOUND */
1350 * Create the new global palette based on the bitmap palette
1351 * (if any), and the standard 16 entry palette derived from
1352 * "win_clr[]" which is used for the basic 16 Angband colors.
1354 * This function is never called before all windows are ready.
1356 * This function returns FALSE if the new palette could not be
1357 * prepared, which should normally be a fatal error. XXX XXX
1359 * Note that only some machines actually use a "palette".
1361 static int new_palette(void)
1369 LPLOGPALETTE pLogPal;
1370 LPPALETTEENTRY lppe;
1375 /* This makes no sense */
1376 if (!paletted) return (TRUE);
1386 /* Check the bitmap palette */
1387 hBmPal = infGraph.hPalette;
1389 /* Use the bitmap */
1392 lppeSize = 256 * sizeof(PALETTEENTRY);
1393 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1394 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1395 if ((nEntries == 0) || (nEntries > 220))
1399 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1401 plog("Please switch to high- or true-color mode.");
1406 rnfree(lppe, lppeSize);
1413 #endif /* USE_GRAPHICS */
1415 /* Size of palette */
1416 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1418 /* Allocate palette */
1419 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1422 pLogPal->palVersion = 0x300;
1424 /* Make room for bitmap and normal data */
1425 pLogPal->palNumEntries = nEntries + 16;
1427 /* Save the bitmap data */
1428 for (i = 0; i < nEntries; i++)
1430 pLogPal->palPalEntry[i] = lppe[i];
1433 /* Save the normal data */
1434 for (i = 0; i < 16; i++)
1438 /* Access the entry */
1439 p = &(pLogPal->palPalEntry[i+nEntries]);
1441 /* Save the colors */
1442 p->peRed = GetRValue(win_clr[i]);
1443 p->peGreen = GetGValue(win_clr[i]);
1444 p->peBlue = GetBValue(win_clr[i]);
1446 /* Save the flags */
1447 p->peFlags = PC_NOCOLLAPSE;
1450 /* Free something */
1451 if (lppe) rnfree(lppe, lppeSize);
1453 /* Create a new palette, or fail */
1454 hNewPal = CreatePalette(pLogPal);
1456 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1458 if (!hNewPal) quit("Cannot create palette!");
1462 /* Free the palette */
1463 rnfree(pLogPal, pLogPalSize);
1468 /* Realize the palette */
1470 SelectPalette(hdc, hNewPal, 0);
1471 i = RealizePalette(hdc);
1472 ReleaseDC(td->w, hdc);
1474 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1476 if (i == 0) quit("Cannot realize palette!");
1481 for (i = 1; i < MAX_TERM_DATA; i++)
1486 SelectPalette(hdc, hNewPal, 0);
1487 ReleaseDC(td->w, hdc);
1490 /* Delete old palette */
1491 if (hPal) DeleteObject(hPal);
1493 /* Save new palette */
1503 * Initialize graphics
1505 static bool init_graphics(void)
1507 /* Initialize once */
1508 /* if (can_use_graphics != arg_graphics) */
1514 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1521 ANGBAND_GRAF = "new";
1529 ANGBAND_GRAF = "old";
1532 /* Access the bitmap file */
1533 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1535 /* Load the bitmap or quit */
1536 if (!ReadDIB(data[0].w, buf, &infGraph))
1539 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1541 plog_fmt("Cannot read bitmap file '%s'", name);
1547 /* Save the new sizes */
1548 infGraph.CellWidth = wid;
1549 infGraph.CellHeight = hgt;
1551 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1553 /* Access the mask file */
1554 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1556 /* Load the bitmap or quit */
1557 if (!ReadDIB(data[0].w, buf, &infMask))
1559 plog_fmt("Cannot read bitmap file '%s'", buf);
1564 /* Activate a palette */
1567 /* Free bitmap XXX XXX XXX */
1571 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1573 plog("Cannot activate palette!");
1579 /* Graphics available */
1580 can_use_graphics = arg_graphics;
1584 return (can_use_graphics);
1586 #endif /* USE_GRAPHICS */
1593 static bool init_sound(void)
1595 /* Initialize once */
1598 /* Load the prefs */
1601 /* Sound available */
1602 can_use_sound = TRUE;
1606 return (can_use_sound);
1608 #endif /* USE_SOUND */
1614 static void term_window_resize(term_data *td)
1616 /* Require window */
1619 /* Resize the window */
1620 SetWindowPos(td->w, 0, 0, 0,
1621 td->size_wid, td->size_hgt,
1622 SWP_NOMOVE | SWP_NOZORDER);
1625 InvalidateRect(td->w, NULL, TRUE);
1630 * Force the use of a new "font file" for a term_data
1632 * This function may be called before the "window" is ready
1634 * This function returns zero only if everything succeeds.
1636 * Note that the "font name" must be capitalized!!!
1638 static errr term_force_font(term_data *td, cptr path)
1648 /* Forget the old font (if needed) */
1649 if (td->font_id) DeleteObject(td->font_id);
1655 /* Create the font (using the 'base' of the font file name!) */
1656 td->font_id = CreateFontIndirect(&(td->lf));
1657 wid = td->lf.lfWidth;
1658 hgt = td->lf.lfHeight;
1659 if (!td->font_id) return (1);
1661 /* Forget old font */
1667 for (i = 0; i < MAX_TERM_DATA; i++)
1669 /* Don't check when closing the application */
1672 /* Check "screen" */
1673 if ((td != &data[i]) &&
1674 (data[i].font_file) &&
1675 (streq(data[i].font_file, td->font_file)))
1681 /* Remove unused font resources */
1682 if (!used) RemoveFontResource(td->font_file);
1684 /* Free the old name */
1685 string_free(td->font_file);
1688 td->font_file = NULL;
1692 if (!path) return (1);
1697 /* Analyze font path */
1698 base = analyze_font(buf, &wid, &hgt);
1701 if (!suffix(base, ".FON")) return (1);
1704 if (!check_file(buf)) return (1);
1706 /* Load the new font */
1707 if (!AddFontResource(buf)) return (1);
1709 /* Save new font name */
1710 td->font_file = string_make(base);
1712 /* Remove the "suffix" */
1713 base[strlen(base)-4] = '\0';
1715 /* Create the font (using the 'base' of the font file name!) */
1716 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1717 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1718 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1719 FIXED_PITCH | FF_DONTCARE, base);
1722 /* Hack -- Unknown size */
1729 /* all this trouble to get the cell size */
1730 hdcDesktop = GetDC(HWND_DESKTOP);
1731 hfOld = SelectObject(hdcDesktop, td->font_id);
1732 GetTextMetrics(hdcDesktop, &tm);
1733 SelectObject(hdcDesktop, hfOld);
1734 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1736 /* Font size info */
1737 wid = tm.tmAveCharWidth;
1741 /* Save the size info */
1752 * Allow the user to change the font for this window.
1754 static void term_change_font(term_data *td)
1759 memset(&cf, 0, sizeof(cf));
1760 cf.lStructSize = sizeof(cf);
1761 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1762 cf.lpLogFont = &(td->lf);
1764 if (ChooseFont(&cf))
1766 /* Force the font */
1767 term_force_font(td, NULL);
1769 /* Assume not bizarre */
1772 /* Reset the tile info */
1773 td->tile_wid = td->font_wid;
1774 td->tile_hgt = td->font_hgt;
1776 /* Analyze the font */
1779 /* Resize the window */
1780 term_window_resize(td);
1786 char tmp[1024] = "";
1788 /* Extract a default if possible */
1789 if (td->font_file) strcpy(tmp, td->font_file);
1791 /* Ask for a choice */
1792 memset(&ofn, 0, sizeof(ofn));
1793 ofn.lStructSize = sizeof(ofn);
1794 ofn.hwndOwner = data[0].w;
1795 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1796 ofn.nFilterIndex = 1;
1797 ofn.lpstrFile = tmp;
1799 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1800 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1801 ofn.lpstrDefExt = "fon";
1803 /* Force choice if legal */
1804 if (GetOpenFileName(&ofn))
1806 /* Force the font */
1807 if (term_force_font(td, tmp))
1809 /* Access the standard font file */
1810 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1812 /* Force the use of that font */
1813 (void)term_force_font(td, tmp);
1816 /* Assume not bizarre */
1817 td->bizarre = FALSE;
1819 /* Reset the tile info */
1820 td->tile_wid = td->font_wid;
1821 td->tile_hgt = td->font_hgt;
1823 /* Analyze the font */
1826 /* Resize the window */
1827 term_window_resize(td);
1834 * Allow the user to lock this window.
1836 static void term_window_pos(term_data *td, HWND hWnd)
1838 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1839 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1842 static void windows_map(void);
1845 * Hack -- redraw a term_data
1847 static void term_data_redraw(term_data *td)
1851 /* Redraw the map */
1856 /* Activate the term */
1857 Term_activate(&td->t);
1859 /* Redraw the contents */
1862 /* Restore the term */
1863 Term_activate(term_screen);
1871 /*** Function hooks needed by "Term" ***/
1877 * Initialize a new Term
1879 static void Term_init_win(term *t)
1888 static void Term_nuke_win(term *t)
1897 * Interact with the User
1899 static errr Term_user_win(int n)
1910 * React to global changes
1912 static errr Term_xtra_win_react(void)
1920 /* Save the default colors */
1921 for (i = 0; i < 256; i++)
1923 /* Simply accept the desired colors */
1924 win_pal[i] = angband_color_table[i][0];
1935 bool change = FALSE;
1937 /* Save the default colors */
1938 for (i = 0; i < 256; i++)
1940 /* Extract desired values */
1941 rv = angband_color_table[i][1];
1942 gv = angband_color_table[i][2];
1943 bv = angband_color_table[i][3];
1945 /* Extract a full color code */
1946 code = PALETTERGB(rv, gv, bv);
1948 /* Activate changes */
1949 if (win_clr[i] != code)
1951 /* Note the change */
1954 /* Apply the desired color */
1959 /* Activate the palette if needed */
1960 if (change) (void)new_palette();
1966 /* Handle "arg_sound" */
1967 if (use_sound != arg_sound)
1969 /* Initialize (if needed) */
1970 if (arg_sound && !init_sound())
1974 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
1976 plog("Cannot initialize sound!");
1984 /* Change setting */
1985 use_sound = arg_sound;
1993 /* Handle "arg_graphics" */
1994 if (use_graphics != arg_graphics)
1996 /* Initialize (if needed) */
1997 if (arg_graphics && !init_graphics())
2001 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
2003 plog("Cannot initialize graphics!");
2008 arg_graphics = GRAPHICS_NONE;
2011 /* Change setting */
2012 use_graphics = arg_graphics;
2015 #ifdef ANGBAND_2_8_1
2017 #else /* ANGBAND_2_8_1 */
2018 reset_visuals(TRUE);
2019 #endif /* ANGBAND_2_8_1 */
2022 #endif /* USE_GRAPHICS */
2025 /* Clean up windows */
2026 for (i = 0; i < MAX_TERM_DATA; i++)
2030 term_data *td = &data[i];
2032 /* Update resized windows */
2033 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2036 Term_activate(&td->t);
2038 /* Hack -- Resize the term */
2039 Term_resize(td->cols, td->rows);
2041 /* Redraw the contents */
2056 * Process at least one event
2058 static errr Term_xtra_win_event(int v)
2062 /* Wait for an event */
2066 if (GetMessage(&msg, NULL, 0, 0))
2068 TranslateMessage(&msg);
2069 DispatchMessage(&msg);
2073 /* Check for an event */
2077 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2079 TranslateMessage(&msg);
2080 DispatchMessage(&msg);
2090 * Process all pending events
2092 static errr Term_xtra_win_flush(void)
2096 /* Process all pending events */
2097 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2099 TranslateMessage(&msg);
2100 DispatchMessage(&msg);
2109 * Hack -- clear the screen
2111 * Make this more efficient XXX XXX XXX
2113 static errr Term_xtra_win_clear(void)
2115 term_data *td = (term_data*)(Term->data);
2120 /* Rectangle to erase */
2121 rc.left = td->size_ow1;
2122 rc.right = rc.left + td->cols * td->tile_wid;
2123 rc.top = td->size_oh1;
2124 rc.bottom = rc.top + td->rows * td->tile_hgt;
2128 SetBkColor(hdc, RGB(0, 0, 0));
2129 SelectObject(hdc, td->font_id);
2130 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2135 rc.left = 0; rc.top = 0;
2138 ReleaseDC(td->w, hdc);
2146 * Hack -- make a noise
2148 static errr Term_xtra_win_noise(void)
2150 MessageBeep(MB_ICONASTERISK);
2156 * Hack -- make a sound
2158 static errr Term_xtra_win_sound(int v)
2163 #endif /* USE_SOUND */
2165 /* Sound disabled */
2166 if (!use_sound) return (1);
2169 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2173 /* Count the samples */
2174 for (i = 0; i < SAMPLE_MAX; i++)
2176 if (!sound_file[v][i])
2181 if (i == 0) return (1);
2183 /* Build the path */
2184 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_simple(i)]);
2188 /* Play the sound, catch errors */
2189 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2193 /* Play the sound, catch errors */
2194 return (sndPlaySound(buf, SND_ASYNC));
2198 #else /* USE_SOUND */
2203 #endif /* USE_SOUND */
2208 * Delay for "x" milliseconds
2210 static int Term_xtra_win_delay(int v)
2224 t = GetTickCount() + v;
2227 while (GetTickCount() < t)
2229 /* Handle messages */
2230 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2232 TranslateMessage(&msg);
2233 DispatchMessage(&msg);
2245 * Do a "special thing"
2247 static errr Term_xtra_win(int n, int v)
2249 /* Handle a subset of the legal requests */
2252 /* Make a bell sound */
2253 case TERM_XTRA_NOISE:
2255 return (Term_xtra_win_noise());
2258 /* Make a special sound */
2259 case TERM_XTRA_SOUND:
2261 return (Term_xtra_win_sound(v));
2264 /* Process random events */
2265 case TERM_XTRA_BORED:
2267 return (Term_xtra_win_event(0));
2270 /* Process an event */
2271 case TERM_XTRA_EVENT:
2273 return (Term_xtra_win_event(v));
2276 /* Flush all events */
2277 case TERM_XTRA_FLUSH:
2279 return (Term_xtra_win_flush());
2282 /* Clear the screen */
2283 case TERM_XTRA_CLEAR:
2285 return (Term_xtra_win_clear());
2288 /* React to global changes */
2289 case TERM_XTRA_REACT:
2291 return (Term_xtra_win_react());
2294 /* Delay for some milliseconds */
2295 case TERM_XTRA_DELAY:
2297 return (Term_xtra_win_delay(v));
2308 * Low level graphics (Assumes valid input).
2310 * Draw a "cursor" at (x,y), using a "yellow box".
2312 static errr Term_curs_win(int x, int y)
2314 term_data *td = (term_data*)(Term->data);
2319 int tile_wid, tile_hgt;
2323 tile_wid = td->map_tile_wid;
2324 tile_hgt = td->map_tile_hgt;
2328 tile_wid = td->tile_wid;
2329 tile_hgt = td->tile_hgt;
2332 /* Frame the grid */
2333 rc.left = x * tile_wid + td->size_ow1;
2334 rc.right = rc.left + tile_wid;
2335 rc.top = y * tile_hgt + td->size_oh1;
2336 rc.bottom = rc.top + tile_hgt;
2338 /* Cursor is done as a yellow "box" */
2340 FrameRect(hdc, &rc, hbrYellow);
2341 ReleaseDC(td->w, hdc);
2349 * Low level graphics (Assumes valid input).
2351 * Draw a "big cursor" at (x,y), using a "yellow box".
2353 static errr Term_bigcurs_win(int x, int y)
2355 term_data *td = (term_data*)(Term->data);
2360 int tile_wid, tile_hgt;
2364 /* Normal cursor in map window */
2365 Term_curs_win(x, y);
2370 tile_wid = td->tile_wid;
2371 tile_hgt = td->tile_hgt;
2374 /* Frame the grid */
2375 rc.left = x * tile_wid + td->size_ow1;
2376 rc.right = rc.left + 2 * tile_wid;
2377 rc.top = y * tile_hgt + td->size_oh1;
2378 rc.bottom = rc.top + tile_hgt;
2380 /* Cursor is done as a yellow "box" */
2382 FrameRect(hdc, &rc, hbrYellow);
2383 ReleaseDC(td->w, hdc);
2391 * Low level graphics (Assumes valid input).
2393 * Erase a "block" of "n" characters starting at (x,y).
2395 static errr Term_wipe_win(int x, int y, int n)
2397 term_data *td = (term_data*)(Term->data);
2402 /* Rectangle to erase in client coords */
2403 rc.left = x * td->tile_wid + td->size_ow1;
2404 rc.right = rc.left + n * td->tile_wid;
2405 rc.top = y * td->tile_hgt + td->size_oh1;
2406 rc.bottom = rc.top + td->tile_hgt;
2409 SetBkColor(hdc, RGB(0, 0, 0));
2410 SelectObject(hdc, td->font_id);
2415 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2416 ReleaseDC(td->w, hdc);
2424 * Low level graphics. Assumes valid input.
2426 * Draw several ("n") chars, with an attr, at a given location.
2428 * All "graphic" data is handled by "Term_pict_win()", below.
2430 * One would think there is a more efficient method for telling a window
2431 * what color it should be using to draw with, but perhaps simply changing
2432 * it every time is not too inefficient. XXX XXX XXX
2434 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2436 term_data *td = (term_data*)(Term->data);
2442 static HBITMAP WALL;
2443 static HBRUSH myBrush, oldBrush;
2445 static bool init_done = FALSE;
2448 WALL = LoadBitmap(hInstance, AppName);
2449 myBrush = CreatePatternBrush(WALL);
2454 /* Total rectangle */
2455 rc.left = x * td->tile_wid + td->size_ow1;
2456 rc.right = rc.left + n * td->tile_wid;
2457 rc.top = y * td->tile_hgt + td->size_oh1;
2458 rc.bottom = rc.top + td->tile_hgt;
2463 /* Background color */
2464 SetBkColor(hdc, RGB(0, 0, 0));
2466 /* Foreground color */
2469 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2473 SetTextColor(hdc, win_clr[a&0x0F]);
2477 SetTextColor(hdc, win_clr[a]);
2481 SelectObject(hdc, td->font_id);
2484 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2488 (td->tile_hgt != td->font_hgt) ||
2489 (td->tile_wid != td->font_wid))
2493 /* Erase complete rectangle */
2494 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2497 if (use_bg) DrawBG(hdc, &rc);
2500 rc.left += ((td->tile_wid - td->font_wid) / 2);
2501 rc.right = rc.left + td->font_wid;
2502 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2503 rc.bottom = rc.top + td->font_hgt;
2505 /* Dump each character */
2506 for (i = 0; i < n; i++)
2509 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2511 rc.right += td->font_wid;
2513 oldBrush = SelectObject(hdc, myBrush);
2514 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2517 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2519 SelectObject(hdc, oldBrush);
2520 SelectObject(hdc, oldPen);
2521 rc.right -= td->font_wid;
2525 rc.left += 2 * td->tile_wid;
2526 rc.right += 2 * td->tile_wid;
2528 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2530 rc.right += td->font_wid;
2532 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2534 rc.right -= td->font_wid;
2538 rc.left += 2 * td->tile_wid;
2539 rc.right += 2 * td->tile_wid;
2540 } else if (*(s+i)==127){
2541 oldBrush = SelectObject(hdc, myBrush);
2542 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2545 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2547 SelectObject(hdc, oldBrush);
2548 SelectObject(hdc, oldPen);
2551 rc.left += td->tile_wid;
2552 rc.right += td->tile_wid;
2555 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2559 rc.left += td->tile_wid;
2560 rc.right += td->tile_wid;
2564 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2568 rc.left += td->tile_wid;
2569 rc.right += td->tile_wid;
2579 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2584 ReleaseDC(td->w, hdc);
2592 * Low level graphics. Assumes valid input.
2594 * Draw an array of "special" attr/char pairs at the given location.
2596 * We use the "Term_pict_win()" function for "graphic" data, which are
2597 * encoded by setting the "high-bits" of both the "attr" and the "char"
2598 * data. We use the "attr" to represent the "row" of the main bitmap,
2599 * and the "char" to represent the "col" of the main bitmap. The use
2600 * of this function is induced by the "higher_pict" flag.
2602 * If "graphics" is not available, we simply "wipe" the given grids.
2604 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2606 term_data *td = (term_data*)(Term->data);
2612 int x2, y2, w2, h2, tw2;
2624 /* Erase the grids */
2625 return (Term_wipe_win(x, y, n));
2628 /* Size of bitmap cell */
2629 w1 = infGraph.CellWidth;
2630 h1 = infGraph.CellHeight;
2632 /* Size of window cell */
2635 w2 = td->map_tile_wid;
2636 h2 = td->map_tile_hgt;
2645 if (use_bigtile) tw2 *= 2;
2648 /* Location of window cell */
2649 x2 = x * w2 + td->size_ow1;
2650 y2 = y * h2 + td->size_oh1;
2656 hdcSrc = CreateCompatibleDC(hdc);
2657 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2659 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2661 hdcMask = CreateCompatibleDC(hdc);
2662 SelectObject(hdcMask, infMask.hBitmap);
2665 /* Draw attr/char pairs */
2666 for (i = 0; i < n; i++, x2 += w2)
2671 /* Extract picture */
2672 int row = (a & 0x7F);
2673 int col = (c & 0x7F);
2675 /* Location of bitmap cell */
2679 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2681 x3 = (tcp[i] & 0x7F) * w1;
2682 y3 = (tap[i] & 0x7F) * h1;
2685 if ((w1 == tw2) && (h1 == h2))
2687 /* Copy the terrain picture from the bitmap to the window */
2688 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2690 /* Mask out the tile */
2691 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2694 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2697 /* Need to stretch */
2700 /* Set the correct mode for stretching the tiles */
2701 SetStretchBltMode(hdc, COLORONCOLOR);
2703 /* Copy the terrain picture from the bitmap to the window */
2704 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
2706 /* Only draw if terrain and overlay are different */
2707 if ((x1 != x3) || (y1 != y3))
2709 /* Mask out the tile */
2710 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2713 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2720 if ((w1 == tw2) && (h1 == h2))
2722 /* Copy the picture from the bitmap to the window */
2723 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2726 /* Need to stretch */
2729 /* Set the correct mode for stretching the tiles */
2730 SetStretchBltMode(hdc, COLORONCOLOR);
2732 /* Copy the picture from the bitmap to the window */
2733 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2739 SelectObject(hdcSrc, hbmSrcOld);
2742 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2745 SelectObject(hdcMask, hbmSrcOld);
2750 ReleaseDC(td->w, hdc);
2752 #else /* USE_GRAPHICS */
2754 /* Just erase this grid */
2755 return (Term_wipe_win(x, y, n));
2757 #endif /* USE_GRAPHICS */
2764 static void windows_map(void)
2766 term_data *td = &data[0];
2768 int x, min_x, max_x;
2769 int y, min_y, max_y;
2773 /* Only in graphics mode */
2774 if (!use_graphics) return;
2777 Term_xtra_win_clear();
2779 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2780 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2781 td->map_active = TRUE;
2791 for (x = min_x; x < max_x; x++)
2793 for (y = min_y; y < max_y; y++)
2795 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
2797 /* Ignore non-graphics */
2798 if ((a & 0x80) && (c & 0x80))
2800 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2805 /* Hilite the player */
2806 Term_curs_win(px - min_x, py - min_y);
2808 /* Wait for a keypress, flush key buffer */
2809 Term_inkey(&c, TRUE, TRUE);
2812 /* Switch off the map display */
2813 td->map_active = FALSE;
2815 /* Restore screen */
2816 Term_xtra_win_clear();
2821 /*** Other routines ***/
2825 * Create and initialize a "term_data" given a title
2827 static void term_data_link(term_data *td)
2831 /* Initialize the term */
2832 term_init(t, td->cols, td->rows, td->keys);
2834 /* Use a "software" cursor */
2835 t->soft_cursor = TRUE;
2837 /* Use "Term_pict" for "graphic" data */
2838 t->higher_pict = TRUE;
2840 /* Erase with "white space" */
2841 t->attr_blank = TERM_WHITE;
2842 t->char_blank = ' ';
2845 /* Prepare the init/nuke hooks */
2846 t->init_hook = Term_init_win;
2847 t->nuke_hook = Term_nuke_win;
2850 /* Prepare the template hooks */
2851 t->user_hook = Term_user_win;
2852 t->xtra_hook = Term_xtra_win;
2853 t->curs_hook = Term_curs_win;
2854 t->bigcurs_hook = Term_bigcurs_win;
2855 t->wipe_hook = Term_wipe_win;
2856 t->text_hook = Term_text_win;
2857 t->pict_hook = Term_pict_win;
2859 /* Remember where we came from */
2860 t->data = (vptr)(td);
2865 * Create the windows
2867 * First, instantiate the "default" values, then read the "ini_file"
2868 * to over-ride selected values, then create the windows, and fonts.
2870 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2871 * must make active to realize the palette. XXX XXX XXX
2873 static void init_windows(void)
2885 WIPE(td, term_data);
2889 td->s = angband_term_name[0];
2908 for (i = 1; i < MAX_TERM_DATA; i++)
2911 WIPE(td, term_data);
2912 td->s = angband_term_name[i];
2916 td->visible = FALSE;
2921 td->pos_x = (7 - i) * 30;
2922 td->pos_y = (7 - i) * 20;
2934 /* Main window (need these before term_getsize gets called) */
2936 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2937 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2942 /* Sub windows (need these before term_getsize gets called) */
2943 for (i = 1; i < MAX_TERM_DATA; i++)
2946 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2947 td->dwExStyle = (WS_EX_TOOLWINDOW);
2952 for (i = 0; i < MAX_TERM_DATA; i++)
2957 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2958 td->lf.lfCharSet = SHIFTJIS_CHARSET;
2959 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2960 /* Activate the chosen font */
2961 term_force_font(td, NULL);
2962 td->tile_wid = td->font_wid;
2963 td->tile_hgt = td->font_hgt;
2965 /* Access the standard font file */
2966 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
2968 /* Activate the chosen font */
2969 if (term_force_font(td, buf))
2971 /* Access the standard font file */
2972 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2974 /* Force the use of that font */
2975 (void)term_force_font(td, buf);
2981 /* Assume not bizarre */
2982 td->bizarre = FALSE;
2987 /* Analyze the font */
2990 /* Resize the window */
2991 term_window_resize(td);
2995 /* Sub windows (reverse order) */
2996 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3001 td->w = CreateWindowEx(td->dwExStyle, AngList,
3003 td->pos_x, td->pos_y,
3004 td->size_wid, td->size_hgt,
3005 HWND_DESKTOP, NULL, hInstance, NULL);
3008 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3010 if (!td->w) quit("Failed to create sub-window");
3016 td->size_hack = TRUE;
3017 ShowWindow(td->w, SW_SHOW);
3018 td->size_hack = FALSE;
3022 angband_term[i] = &td->t;
3026 /* Activate the window */
3027 SetActiveWindow(td->w);
3032 term_window_pos(&data[i], HWND_TOPMOST);
3036 term_window_pos(&data[i], td->w);
3046 td->w = CreateWindowEx(td->dwExStyle, AppName,
3048 td->pos_x, td->pos_y,
3049 td->size_wid, td->size_hgt,
3050 HWND_DESKTOP, NULL, hInstance, NULL);
3053 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3055 if (!td->w) quit("Failed to create Angband window");
3060 angband_term[0] = &td->t;
3062 /* Activate the main window */
3063 SetActiveWindow(td->w);
3065 /* Bring main window back to top */
3066 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3069 /* New palette XXX XXX XXX */
3070 (void)new_palette();
3073 /* Create a "brush" for drawing the "cursor" */
3074 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3077 /* Process pending messages */
3078 (void)Term_xtra_win_flush();
3086 static void setup_menus(void)
3090 HMENU hm = GetMenu(data[0].w);
3093 /* Menu "File", Disable all */
3094 EnableMenuItem(hm, IDM_FILE_NEW,
3095 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3096 EnableMenuItem(hm, IDM_FILE_OPEN,
3097 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3098 EnableMenuItem(hm, IDM_FILE_SAVE,
3099 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3100 EnableMenuItem(hm, IDM_FILE_EXIT,
3101 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3102 EnableMenuItem(hm, IDM_FILE_SCORE,
3103 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3106 /* No character available */
3107 if (!character_generated)
3109 /* Menu "File", Item "New" */
3110 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3112 /* Menu "File", Item "Open" */
3113 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3116 /* A character available */
3117 if (character_generated)
3119 /* Menu "File", Item "Save" */
3120 EnableMenuItem(hm, IDM_FILE_SAVE,
3121 MF_BYCOMMAND | MF_ENABLED);
3124 /* Menu "File", Item "Exit" */
3125 EnableMenuItem(hm, IDM_FILE_EXIT,
3126 MF_BYCOMMAND | MF_ENABLED);
3128 EnableMenuItem(hm, IDM_FILE_SCORE,
3129 MF_BYCOMMAND | MF_ENABLED);
3132 /* Menu "Window::Visibility" */
3133 for (i = 0; i < MAX_TERM_DATA; i++)
3135 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3136 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3138 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3139 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3141 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3142 MF_BYCOMMAND | MF_ENABLED);
3145 /* Menu "Window::Font" */
3146 for (i = 0; i < MAX_TERM_DATA; i++)
3148 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3149 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3151 if (data[i].visible)
3153 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3154 MF_BYCOMMAND | MF_ENABLED);
3158 /* Menu "Window::Window Position Fix" */
3159 for (i = 0; i < MAX_TERM_DATA; i++)
3161 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3162 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3164 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3165 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3167 if (data[i].visible)
3169 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3170 MF_BYCOMMAND | MF_ENABLED);
3174 /* Menu "Window::Bizarre Display" */
3175 for (i = 0; i < MAX_TERM_DATA; i++)
3177 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3178 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3180 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3181 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3183 if (data[i].visible)
3185 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3186 MF_BYCOMMAND | MF_ENABLED);
3191 /* Menu "Window::Increase Tile Width" */
3192 for (i = 0; i < MAX_TERM_DATA; i++)
3194 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3195 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3197 if (data[i].visible)
3199 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3200 MF_BYCOMMAND | MF_ENABLED);
3205 /* Menu "Window::Decrease Tile Width" */
3206 for (i = 0; i < MAX_TERM_DATA; i++)
3208 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3209 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3211 if (data[i].visible)
3213 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3214 MF_BYCOMMAND | MF_ENABLED);
3219 /* Menu "Window::Increase Tile Height" */
3220 for (i = 0; i < MAX_TERM_DATA; i++)
3222 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3223 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3225 if (data[i].visible)
3227 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3228 MF_BYCOMMAND | MF_ENABLED);
3233 /* Menu "Window::Decrease Tile Height" */
3234 for (i = 0; i < MAX_TERM_DATA; i++)
3236 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3237 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3239 if (data[i].visible)
3241 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3242 MF_BYCOMMAND | MF_ENABLED);
3247 /* Menu "Options", disable all */
3248 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3249 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3250 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3251 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3252 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3253 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3254 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3255 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3256 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3257 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3259 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3260 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3263 /* Menu "Options", Item "Map" */
3264 if (use_graphics != GRAPHICS_NONE)
3265 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3267 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3268 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3270 /* Menu "Options", update all */
3271 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3272 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3273 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3274 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3275 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3276 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3277 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3278 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3279 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3280 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3281 CheckMenuItem(hm, IDM_OPTIONS_BG,
3282 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3284 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3285 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3289 /* Menu "Options", Item "Graphics" */
3290 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3291 /* Menu "Options", Item "Graphics" */
3292 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3293 /* Menu "Options", Item "Graphics" */
3294 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3295 /* Menu "Options", Item "Graphics" */
3296 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3297 #endif /* USE_GRAPHICS */
3300 /* Menu "Options", Item "Sound" */
3301 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3302 #endif /* USE_SOUND */
3305 /* Menu "Options", Item "ScreenSaver" */
3306 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3307 MF_BYCOMMAND | MF_ENABLED);
3308 #endif /* USE_SAVER */
3313 * Check for double clicked (or dragged) savefile
3315 * Apparently, Windows copies the entire filename into the first
3316 * piece of the "command line string". Perhaps we should extract
3317 * the "basename" of that filename and append it to the "save" dir.
3319 static void check_for_save_file(LPSTR cmd_line)
3329 /* Extract filename */
3330 strcat(savefile, s);
3332 /* Validate the file */
3333 validate_file(savefile);
3335 /* Game in progress */
3336 game_in_progress = TRUE;
3344 * Process a menu command
3346 static void process_menus(WORD wCmd)
3363 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3365 plog("You cannot do that yet...");
3369 else if (game_in_progress)
3372 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3374 plog("You can't start a new game while you're still playing!");
3380 game_in_progress = TRUE;
3394 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3396 plog("You cannot do that yet...");
3400 else if (game_in_progress)
3403 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3405 plog("You can't open a new game while you're still playing!");
3411 memset(&ofn, 0, sizeof(ofn));
3412 ofn.lStructSize = sizeof(ofn);
3413 ofn.hwndOwner = data[0].w;
3414 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3415 ofn.nFilterIndex = 1;
3416 ofn.lpstrFile = savefile;
3417 ofn.nMaxFile = 1024;
3418 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3419 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3421 if (GetOpenFileName(&ofn))
3423 /* Load 'savefile' */
3424 validate_file(savefile);
3425 game_in_progress = TRUE;
3437 if (game_in_progress && character_generated)
3443 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3445 plog("You may not do that right now.");
3451 /* Hack -- Forget messages */
3456 do_cmd_save_game(FALSE);
3457 #else /* ZANGBAND */
3459 #endif /* ZANGBAND */
3464 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3466 plog("You may not do that right now.");
3476 if (game_in_progress && character_generated)
3482 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3484 plog("You may not do that right now.");
3490 /* Hack -- Forget messages */
3499 /* do_cmd_save_game(FALSE); */
3500 #else /* ZANGBAND */
3501 /* do_cmd_save_game(); */
3502 #endif /* ZANGBAND */
3503 Term_key_push(SPECIAL_KEY_QUIT);
3511 case IDM_FILE_SCORE:
3515 /* Build the filename */
3516 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3518 /* Open the binary high score file, for reading */
3519 highscore_fd = fd_open(buf, O_RDONLY);
3521 /* Paranoia -- No score file */
3522 if (highscore_fd < 0)
3524 msg_print("Score file unavailable.");
3534 /* Display the scores */
3535 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3537 /* Shut the high score file */
3538 (void)fd_close(highscore_fd);
3540 /* Forget the high score fd */
3546 /* Hack - Flush it */
3554 case IDM_WINDOW_VIS_0:
3557 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3559 plog("You are not allowed to do that!");
3566 /* Window visibility */
3567 case IDM_WINDOW_VIS_1:
3568 case IDM_WINDOW_VIS_2:
3569 case IDM_WINDOW_VIS_3:
3570 case IDM_WINDOW_VIS_4:
3571 case IDM_WINDOW_VIS_5:
3572 case IDM_WINDOW_VIS_6:
3573 case IDM_WINDOW_VIS_7:
3575 i = wCmd - IDM_WINDOW_VIS_0;
3577 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3584 ShowWindow(td->w, SW_SHOW);
3585 term_data_redraw(td);
3589 td->visible = FALSE;
3591 ShowWindow(td->w, SW_HIDE);
3598 case IDM_WINDOW_FONT_0:
3599 case IDM_WINDOW_FONT_1:
3600 case IDM_WINDOW_FONT_2:
3601 case IDM_WINDOW_FONT_3:
3602 case IDM_WINDOW_FONT_4:
3603 case IDM_WINDOW_FONT_5:
3604 case IDM_WINDOW_FONT_6:
3605 case IDM_WINDOW_FONT_7:
3607 i = wCmd - IDM_WINDOW_FONT_0;
3609 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3613 term_change_font(td);
3618 /* Window Z Position */
3619 case IDM_WINDOW_POS_1:
3620 case IDM_WINDOW_POS_2:
3621 case IDM_WINDOW_POS_3:
3622 case IDM_WINDOW_POS_4:
3623 case IDM_WINDOW_POS_5:
3624 case IDM_WINDOW_POS_6:
3625 case IDM_WINDOW_POS_7:
3627 i = wCmd - IDM_WINDOW_POS_0;
3629 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3633 if (!td->posfix && td->visible)
3636 term_window_pos(td, HWND_TOPMOST);
3641 term_window_pos(td, data[0].w);
3647 /* Bizarre Display */
3648 case IDM_WINDOW_BIZ_0:
3649 case IDM_WINDOW_BIZ_1:
3650 case IDM_WINDOW_BIZ_2:
3651 case IDM_WINDOW_BIZ_3:
3652 case IDM_WINDOW_BIZ_4:
3653 case IDM_WINDOW_BIZ_5:
3654 case IDM_WINDOW_BIZ_6:
3655 case IDM_WINDOW_BIZ_7:
3657 i = wCmd - IDM_WINDOW_BIZ_0;
3659 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3663 td->bizarre = !td->bizarre;
3667 term_window_resize(td);
3672 /* Increase Tile Width */
3673 case IDM_WINDOW_I_WID_0:
3674 case IDM_WINDOW_I_WID_1:
3675 case IDM_WINDOW_I_WID_2:
3676 case IDM_WINDOW_I_WID_3:
3677 case IDM_WINDOW_I_WID_4:
3678 case IDM_WINDOW_I_WID_5:
3679 case IDM_WINDOW_I_WID_6:
3680 case IDM_WINDOW_I_WID_7:
3682 i = wCmd - IDM_WINDOW_I_WID_0;
3684 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3692 term_window_resize(td);
3697 /* Decrease Tile Height */
3698 case IDM_WINDOW_D_WID_0:
3699 case IDM_WINDOW_D_WID_1:
3700 case IDM_WINDOW_D_WID_2:
3701 case IDM_WINDOW_D_WID_3:
3702 case IDM_WINDOW_D_WID_4:
3703 case IDM_WINDOW_D_WID_5:
3704 case IDM_WINDOW_D_WID_6:
3705 case IDM_WINDOW_D_WID_7:
3707 i = wCmd - IDM_WINDOW_D_WID_0;
3709 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3717 term_window_resize(td);
3722 /* Increase Tile Height */
3723 case IDM_WINDOW_I_HGT_0:
3724 case IDM_WINDOW_I_HGT_1:
3725 case IDM_WINDOW_I_HGT_2:
3726 case IDM_WINDOW_I_HGT_3:
3727 case IDM_WINDOW_I_HGT_4:
3728 case IDM_WINDOW_I_HGT_5:
3729 case IDM_WINDOW_I_HGT_6:
3730 case IDM_WINDOW_I_HGT_7:
3732 i = wCmd - IDM_WINDOW_I_HGT_0;
3734 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3742 term_window_resize(td);
3747 /* Decrease Tile Height */
3748 case IDM_WINDOW_D_HGT_0:
3749 case IDM_WINDOW_D_HGT_1:
3750 case IDM_WINDOW_D_HGT_2:
3751 case IDM_WINDOW_D_HGT_3:
3752 case IDM_WINDOW_D_HGT_4:
3753 case IDM_WINDOW_D_HGT_5:
3754 case IDM_WINDOW_D_HGT_6:
3755 case IDM_WINDOW_D_HGT_7:
3757 i = wCmd - IDM_WINDOW_D_HGT_0;
3759 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3767 term_window_resize(td);
3772 case IDM_OPTIONS_NO_GRAPHICS:
3777 plog("You may not do that right now.");
3781 /* Toggle "arg_graphics" */
3782 if (arg_graphics != GRAPHICS_NONE)
3784 arg_graphics = GRAPHICS_NONE;
3786 /* React to changes */
3787 Term_xtra_win_react();
3789 /* Hack -- Force redraw */
3790 Term_key_push(KTRL('R'));
3796 case IDM_OPTIONS_OLD_GRAPHICS:
3801 plog("You may not do that right now.");
3805 /* Toggle "arg_graphics" */
3806 if (arg_graphics != GRAPHICS_ORIGINAL)
3808 arg_graphics = GRAPHICS_ORIGINAL;
3810 /* React to changes */
3811 Term_xtra_win_react();
3813 /* Hack -- Force redraw */
3814 Term_key_push(KTRL('R'));
3820 case IDM_OPTIONS_NEW_GRAPHICS:
3825 plog("You may not do that right now.");
3829 /* Toggle "arg_graphics" */
3830 if (arg_graphics != GRAPHICS_ADAM_BOLT)
3832 arg_graphics = GRAPHICS_ADAM_BOLT;
3834 /* React to changes */
3835 Term_xtra_win_react();
3837 /* Hack -- Force redraw */
3838 Term_key_push(KTRL('R'));
3844 case IDM_OPTIONS_BIGTILE:
3846 term_data *td = &data[0];
3851 plog("You may not do that right now.");
3855 /* Toggle "arg_sound" */
3856 arg_bigtile = !arg_bigtile;
3859 Term_activate(&td->t);
3861 /* Resize the term */
3862 Term_resize(td->cols, td->rows);
3865 InvalidateRect(td->w, NULL, TRUE);
3870 case IDM_OPTIONS_SOUND:
3875 plog("You may not do that right now.");
3879 /* Toggle "arg_sound" */
3880 arg_sound = !arg_sound;
3882 /* React to changes */
3883 Term_xtra_win_react();
3885 /* Hack -- Force redraw */
3886 Term_key_push(KTRL('R'));
3892 case IDM_OPTIONS_BG:
3897 plog("You may not do that right now.");
3901 /* Toggle "use_bg" */
3906 /* React to changes */
3907 Term_xtra_win_react();
3909 /* Hack -- Force redraw */
3910 Term_key_push(KTRL('R'));
3916 case IDM_OPTIONS_OPEN_BG:
3921 plog("You may not do that right now.");
3926 memset(&ofn, 0, sizeof(ofn));
3927 ofn.lStructSize = sizeof(ofn);
3928 ofn.hwndOwner = data[0].w;
3929 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3930 ofn.nFilterIndex = 1;
3931 ofn.lpstrFile = bg_bitmap_file;
3932 ofn.nMaxFile = 1023;
3933 ofn.lpstrInitialDir = NULL;
3935 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
3937 ofn.lpstrTitle = "Choose wall paper.";
3939 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3941 if (GetOpenFileName(&ofn))
3943 /* Load 'savefile' */
3948 /* React to changes */
3949 Term_xtra_win_react();
3951 /* Hack -- Force redraw */
3952 Term_key_push(KTRL('R'));
3957 case IDM_DUMP_SCREEN_HTML:
3959 static char buf[1024] = "";
3960 memset(&ofn, 0, sizeof(ofn));
3961 ofn.lStructSize = sizeof(ofn);
3962 ofn.hwndOwner = data[0].w;
3963 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
3964 ofn.nFilterIndex = 1;
3965 ofn.lpstrFile = buf;
3966 ofn.nMaxFile = 1023;
3967 ofn.lpstrDefExt = "html";
3968 ofn.lpstrInitialDir = NULL;
3970 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
3972 ofn.lpstrTitle = "Save screen dump as HTML.";
3974 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
3976 if (GetSaveFileName(&ofn))
3978 do_cmd_save_screen_html_aux(buf, 0);
3985 case IDM_OPTIONS_SAVER:
3989 DestroyWindow(hwndSaver);
3994 /* Create a screen scaver window */
3995 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
3996 "Angband Screensaver",
3997 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
3998 0, 0, GetSystemMetrics(SM_CXSCREEN),
3999 GetSystemMetrics(SM_CYSCREEN),
4000 NULL, NULL, hInstance, NULL);
4004 /* Push the window to the bottom XXX XXX XXX */
4005 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4010 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
4012 plog("Failed to create saver window");
4022 case IDM_OPTIONS_MAP:
4028 case IDM_HELP_CONTENTS:
4032 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4033 if (check_file(tmp))
4035 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4040 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4041 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4043 plog_fmt("Cannot find help file: %s", tmp);
4044 plog("Use the online help files instead.");
4049 #else /* HTML_HELP */
4052 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4053 if (check_file(tmp))
4055 sprintf(buf, "winhelp.exe %s", tmp);
4056 WinExec(buf, SW_NORMAL);
4061 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4062 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4064 plog_fmt("Cannot find help file: %s", tmp);
4065 plog("Use the online help files instead.");
4070 #endif /* HTML_HELP */
4076 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4083 /* Extract the modifiers */
4084 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4085 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4086 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4088 Term_no_press = (ma) ? TRUE : FALSE;
4090 /* Handle "special" keys */
4091 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4093 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4094 bool numpad = FALSE;
4096 /* Begin the macro trigger */
4099 /* Send the modifiers */
4100 if (mc) Term_keypress('C');
4101 if (ms) Term_keypress('S');
4102 if (ma) Term_keypress('A');
4104 /* Extract "scan code" */
4105 i = LOBYTE(HIWORD(lParam));
4107 /* Introduce the scan code */
4110 /* Extended key bit */
4113 /* Numpad Enter and '/' are extended key */
4115 Term_no_press = TRUE;
4116 case VK_RETURN: /* Enter */
4119 /* Other extended keys are on full keyboard */
4135 Term_no_press = TRUE;
4139 case VK_PRIOR: /* Page Up */
4140 case VK_NEXT: /* Page Down */
4150 /* Special modifiers for keypad keys */
4151 if (numpad) Term_keypress('K');
4153 /* Encode the hexidecimal scan code */
4154 Term_keypress(hexsym[i/16]);
4155 Term_keypress(hexsym[i%16]);
4157 /* End the macro trigger */
4168 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4169 WPARAM wParam, LPARAM lParam);
4170 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4171 WPARAM wParam, LPARAM lParam)
4172 #else /* __MWERKS__ */
4173 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4174 WPARAM wParam, LPARAM lParam)
4175 #endif /* __MWERKS__ */
4181 MINMAXINFO FAR *lpmmi;
4187 /* Acquire proper "term_data" info */
4188 td = (term_data *)GetWindowLong(hWnd, 0);
4190 /* Handle message */
4196 SetWindowLong(hWnd, 0, (LONG)(my_td));
4206 case WM_GETMINMAXINFO:
4208 MINMAXINFO FAR *lpmmi;
4211 lpmmi = (MINMAXINFO FAR *)lParam;
4213 /* this message was sent before WM_NCCREATE */
4216 /* Minimum window size is 80x24 */
4217 rc.left = rc.top = 0;
4218 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4219 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4222 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4224 /* Save minimum size */
4225 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4226 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4233 BeginPaint(hWnd, &ps);
4234 if (td) term_data_redraw(td);
4235 EndPaint(hWnd, &ps);
4236 ValidateRect(hWnd, NULL);
4243 if (process_keydown(wParam, lParam))
4250 if (Term_no_press) Term_no_press = FALSE;
4251 else Term_keypress(wParam);
4263 if (game_in_progress && character_generated)
4268 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4270 plog("You may not do that right now.");
4275 /* Hack -- Forget messages */
4284 /* do_cmd_save_game(FALSE); */
4285 #else /* ZANGBAND */
4286 /* do_cmd_save_game(); */
4287 #endif /* ZANGBAND */
4288 Term_key_push(SPECIAL_KEY_QUIT);
4295 case WM_QUERYENDSESSION:
4297 if (game_in_progress && character_generated)
4299 /* Hack -- Forget messages */
4302 /* Mega-Hack -- Delay death */
4303 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4305 /* Hardcode panic save */
4306 p_ptr->panic_save = 1;
4308 /* Forbid suspend */
4309 signals_ignore_tstp();
4311 /* Indicate panic save */
4313 (void)strcpy(p_ptr->died_from, "(¶ÛµÞ¥»¡¼¥Ö)");
4315 (void)strcpy(p_ptr->died_from, "(panic save)");
4319 (void)save_player();
4333 process_menus(LOWORD(wParam));
4339 /* this message was sent before WM_NCCREATE */
4342 /* it was sent from inside CreateWindowEx */
4343 if (!td->w) return 1;
4345 /* was sent from WM_SIZE */
4346 if (td->size_hack) return 1;
4350 case SIZE_MINIMIZED:
4352 /* Hide sub-windows */
4353 for (i = 1; i < MAX_TERM_DATA; i++)
4355 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4360 case SIZE_MAXIMIZED:
4362 /* fall through XXX XXX XXX */
4367 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4368 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4371 if ((td->cols != cols) || (td->rows != rows))
4373 /* Save the new size */
4378 Term_activate(&td->t);
4380 /* Resize the term */
4381 Term_resize(td->cols, td->rows);
4384 InvalidateRect(td->w, NULL, TRUE);
4387 td->size_hack = TRUE;
4389 /* Show sub-windows */
4390 for (i = 1; i < MAX_TERM_DATA; i++)
4392 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4395 td->size_hack = FALSE;
4403 case WM_PALETTECHANGED:
4405 /* Ignore if palette change caused by itself */
4406 if ((HWND)wParam == hWnd) return 0;
4408 /* Fall through... */
4411 case WM_QUERYNEWPALETTE:
4413 if (!paletted) return 0;
4417 SelectPalette(hdc, hPal, FALSE);
4419 i = RealizePalette(hdc);
4421 /* if any palette entries changed, repaint the window. */
4422 if (i) InvalidateRect(hWnd, NULL, TRUE);
4424 ReleaseDC(hWnd, hdc);
4431 if (wParam && !HIWORD(lParam))
4433 /* Do something to sub-windows */
4434 for (i = 1; i < MAX_TERM_DATA; i++)
4436 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4439 /* Focus on main window */
4448 case WM_ACTIVATEAPP:
4450 for (i = 1; i < MAX_TERM_DATA; i++)
4456 ShowWindow(data[i].w, SW_SHOW);
4460 ShowWindow(data[i].w, SW_HIDE);
4467 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4472 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4473 WPARAM wParam, LPARAM lParam);
4474 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4475 WPARAM wParam, LPARAM lParam)
4476 #else /* __MWERKS__ */
4477 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4478 WPARAM wParam, LPARAM lParam)
4479 #endif /* __MWERKS__ */
4483 MINMAXINFO FAR *lpmmi;
4491 /* Acquire proper "term_data" info */
4492 td = (term_data *)GetWindowLong(hWnd, 0);
4494 /* Process message */
4500 SetWindowLong(hWnd, 0, (LONG)(my_td));
4510 case WM_GETMINMAXINFO:
4512 MINMAXINFO FAR *lpmmi;
4515 lpmmi = (MINMAXINFO FAR *)lParam;
4517 /* this message was sent before WM_NCCREATE */
4520 /* Minimum window size is 80x24 */
4521 rc.left = rc.top = 0;
4522 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4523 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4526 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4528 /* Save minimum size */
4529 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4530 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4540 /* this message was sent before WM_NCCREATE */
4543 /* it was sent from inside CreateWindowEx */
4544 if (!td->w) return 1;
4546 /* was sent from inside WM_SIZE */
4547 if (td->size_hack) return 1;
4549 td->size_hack = TRUE;
4551 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4552 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4555 if ((td->cols != cols) || (td->rows != rows))
4558 term *old_term = Term;
4560 /* Save the new size */
4565 Term_activate(&td->t);
4567 /* Resize the term */
4568 Term_resize(td->cols, td->rows);
4571 Term_activate(old_term);
4574 InvalidateRect(td->w, NULL, TRUE);
4576 /* HACK - Redraw all windows */
4577 p_ptr->window = 0xFFFFFFFF;
4581 td->size_hack = FALSE;
4588 BeginPaint(hWnd, &ps);
4589 if (td) term_data_redraw(td);
4590 EndPaint(hWnd, &ps);
4597 if (process_keydown(wParam, lParam))
4604 if (Term_no_press) Term_no_press = FALSE;
4605 else Term_keypress(wParam);
4609 case WM_PALETTECHANGED:
4611 /* ignore if palette change caused by itself */
4612 if ((HWND)wParam == hWnd) return FALSE;
4613 /* otherwise, fall through!!! */
4616 case WM_QUERYNEWPALETTE:
4618 if (!paletted) return 0;
4620 SelectPalette(hdc, hPal, FALSE);
4621 i = RealizePalette(hdc);
4622 /* if any palette entries changed, repaint the window. */
4623 if (i) InvalidateRect(hWnd, NULL, TRUE);
4624 ReleaseDC(hWnd, hdc);
4628 case WM_NCLBUTTONDOWN:
4632 if (wParam == HTCLOSE) wParam = HTSYSMENU;
4633 #endif /* HTCLOSE */
4635 if (wParam == HTSYSMENU)
4639 td->visible = FALSE;
4640 ShowWindow(td->w, SW_HIDE);
4650 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4656 #define MOUSE_SENS 40
4659 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4660 WPARAM wParam, LPARAM lParam);
4661 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4662 WPARAM wParam, LPARAM lParam)
4663 #else /* __MWERKS__ */
4664 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4665 WPARAM wParam, LPARAM lParam)
4666 #endif /* __MWERKS__ */
4668 static int iMouse = 0;
4669 static WORD xMouse = 0;
4670 static WORD yMouse = 0;
4693 if (LOWORD(wParam) == WA_INACTIVE) break;
4695 /* else fall through */
4699 case WM_LBUTTONDOWN:
4700 case WM_MBUTTONDOWN:
4701 case WM_RBUTTONDOWN:
4704 SendMessage(hWnd, WM_CLOSE, 0, 0);
4712 dx = LOWORD(lParam) - xMouse;
4713 dy = HIWORD(lParam) - yMouse;
4715 if (dx < 0) dx = -dx;
4716 if (dy < 0) dy = -dy;
4718 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
4720 SendMessage(hWnd, WM_CLOSE, 0, 0);
4724 /* Save last location */
4726 xMouse = LOWORD(lParam);
4727 yMouse = HIWORD(lParam);
4734 DestroyWindow(hwndSaver);
4741 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4744 #endif /* USE_SAVER */
4750 /*** Temporary Hooks ***/
4754 * Display warning message (see "z-util.c")
4756 static void hack_plog(cptr str)
4758 /* Give a warning */
4762 MessageBox(NULL, str, "·Ù¹ð¡ª",
4763 MB_ICONEXCLAMATION | MB_OK);
4765 MessageBox(NULL, str, "Warning",
4766 MB_ICONEXCLAMATION | MB_OK);
4774 * Display error message and quit (see "z-util.c")
4776 static void hack_quit(cptr str)
4778 /* Give a warning */
4782 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
4783 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4785 MessageBox(NULL, str, "Error",
4786 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4791 /* Unregister the classes */
4792 UnregisterClass(AppName, hInstance);
4794 /* Destroy the icon */
4795 if (hIcon) DestroyIcon(hIcon);
4803 /*** Various hooks ***/
4807 * Display warning message (see "z-util.c")
4809 static void hook_plog(cptr str)
4815 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
4816 MB_ICONEXCLAMATION | MB_OK);
4818 MessageBox(data[0].w, str, "Warning",
4819 MB_ICONEXCLAMATION | MB_OK);
4827 * Display error message and quit (see "z-util.c")
4829 static void hook_quit(cptr str)
4834 /* Give a warning */
4838 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
4839 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4841 MessageBox(data[0].w, str, "Error",
4842 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4848 /* Save the preferences */
4852 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
4854 /* Destroy all windows */
4855 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
4857 term_force_font(&data[i], NULL);
4858 if (data[i].font_want) string_free(data[i].font_want);
4859 if (data[i].w) DestroyWindow(data[i].w);
4863 /* Free the bitmap stuff */
4865 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
4866 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
4868 if (infMask.hPalette) DeleteObject(infMask.hPalette);
4869 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
4871 #endif /* USE_GRAPHICS */
4873 /*** Free some other stuff ***/
4875 DeleteObject(hbrYellow);
4880 if (hPal) DeleteObject(hPal);
4882 UnregisterClass(AppName, hInstance);
4884 if (hIcon) DestroyIcon(hIcon);
4891 /*** Initialize ***/
4897 static void init_stuff(void)
4904 /* Get program name with full path */
4905 GetModuleFileName(hInstance, path, 512);
4907 /* Save the "program name" XXX XXX XXX */
4910 /* Get the name of the "*.ini" file */
4911 strcpy(path + strlen(path) - 4, ".INI");
4913 /* Save the the name of the ini-file */
4914 ini_file = string_make(path);
4916 /* Analyze the path */
4922 if (path[i] == '\\')
4929 /* Add "lib" to the path */
4930 strcpy(path + i + 1, "lib\\");
4932 /* Validate the path */
4933 validate_dir(path, TRUE);
4935 /* Init the file paths */
4936 init_file_paths(path);
4938 /* Hack -- Validate the paths */
4939 validate_dir(ANGBAND_DIR_APEX, FALSE);
4940 validate_dir(ANGBAND_DIR_BONE, FALSE);
4942 /* Allow missing 'edit' directory */
4943 if (!check_dir(ANGBAND_DIR_EDIT))
4945 /* Must have 'data'! */
4946 validate_dir(ANGBAND_DIR_DATA, TRUE);
4950 /* Don't need 'data' */
4951 validate_dir(ANGBAND_DIR_DATA, FALSE);
4954 validate_dir(ANGBAND_DIR_FILE, TRUE);
4955 validate_dir(ANGBAND_DIR_HELP, FALSE);
4956 validate_dir(ANGBAND_DIR_INFO, FALSE);
4957 validate_dir(ANGBAND_DIR_PREF, TRUE);
4958 validate_dir(ANGBAND_DIR_SAVE, FALSE);
4959 validate_dir(ANGBAND_DIR_USER, TRUE);
4960 validate_dir(ANGBAND_DIR_XTRA, TRUE);
4962 /* Build the filename */
4964 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
4966 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
4970 /* Hack -- Validate the "news.txt" file */
4971 validate_file(path);
4975 /* Build the "font" path */
4976 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
4978 /* Allocate the path */
4979 ANGBAND_DIR_XTRA_FONT = string_make(path);
4981 /* Validate the "font" directory */
4982 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
4984 /* Build the filename */
4985 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
4987 /* Hack -- Validate the basic font */
4988 validate_file(path);
4994 /* Build the "graf" path */
4995 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
4997 /* Allocate the path */
4998 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5000 /* Validate the "graf" directory */
5001 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5003 #endif /* USE_GRAPHICS */
5008 /* Build the "sound" path */
5009 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5011 /* Allocate the path */
5012 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5014 /* Validate the "sound" directory */
5015 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5017 #endif /* USE_SOUND */
5021 /* Build the "music" path */
5022 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5024 /* Allocate the path */
5025 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5027 /* Validate the "music" directory */
5028 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5030 #endif /* USE_MUSIC */
5032 /* Build the "help" path */
5033 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5035 /* Allocate the path */
5036 ANGBAND_DIR_XTRA_HELP = string_make(path);
5038 /* Validate the "help" directory */
5039 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5043 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5044 LPSTR lpCmdLine, int nCmdShow)
5059 if (hPrevInst == NULL)
5061 wc.style = CS_CLASSDC;
5062 wc.lpfnWndProc = AngbandWndProc;
5064 wc.cbWndExtra = 4; /* one long pointer to term_data */
5065 wc.hInstance = hInst;
5066 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5067 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5068 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5069 wc.lpszMenuName = AppName;
5070 wc.lpszClassName = AppName;
5072 if (!RegisterClass(&wc)) exit(1);
5074 wc.lpfnWndProc = AngbandListProc;
5075 wc.lpszMenuName = NULL;
5076 wc.lpszClassName = AngList;
5078 if (!RegisterClass(&wc)) exit(2);
5082 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5083 wc.lpfnWndProc = AngbandSaverProc;
5085 wc.lpszMenuName = NULL;
5086 wc.lpszClassName = "WindowsScreenSaverClass";
5088 if (!RegisterClass(&wc)) exit(3);
5094 /* Temporary hooks */
5095 plog_aux = hack_plog;
5096 quit_aux = hack_quit;
5097 core_aux = hack_quit;
5099 /* Prepare the filepaths */
5102 /* Initialize the keypress analyzer */
5103 for (i = 0; special_key_list[i]; ++i)
5105 special_key[special_key_list[i]] = TRUE;
5107 /* Initialize the keypress analyzer */
5108 for (i = 0; ignore_key_list[i]; ++i)
5110 ignore_key[ignore_key_list[i]] = TRUE;
5113 /* Determine if display is 16/256/true color */
5115 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5116 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5117 ReleaseDC(NULL, hdc);
5119 /* Initialize the colors */
5120 for (i = 0; i < 256; i++)
5124 /* Extract desired values */
5125 rv = angband_color_table[i][1];
5126 gv = angband_color_table[i][2];
5127 bv = angband_color_table[i][3];
5129 /* Extract the "complex" code */
5130 win_clr[i] = PALETTERGB(rv, gv, bv);
5132 /* Save the "simple" code */
5133 angband_color_table[i][0] = win_pal[i];
5136 /* Prepare the windows */
5142 /* Activate hooks */
5143 plog_aux = hook_plog;
5144 quit_aux = hook_quit;
5145 core_aux = hook_quit;
5147 /* Set the system suffix */
5148 ANGBAND_SYS = "win";
5150 /* Set the keyboard suffix */
5151 if (7 != GetKeyboardType(0))
5152 ANGBAND_KEYBOARD = "0";
5155 /* Japanese keyboard */
5156 switch (GetKeyboardType(1))
5158 case 0x0D01: case 0x0D02:
5159 case 0x0D03: case 0x0D04:
5160 case 0x0D05: case 0x0D06:
5162 ANGBAND_KEYBOARD = "NEC98";
5166 ANGBAND_KEYBOARD = "JAPAN";
5174 /* We are now initialized */
5178 if(lpCmdLine[0] == '-'){
5179 switch(lpCmdLine[1])
5184 if (!lpCmdLine[2]) break;
5185 chuukei_server = TRUE;
5186 if(connect_chuukei_server(&lpCmdLine[2])<0){
5187 msg_print("connect fail");
5190 msg_print("connect");
5198 if (!lpCmdLine[2]) break;
5199 chuukei_client = TRUE;
5200 connect_chuukei_server(&lpCmdLine[2]);
5210 /* Did the user double click on a save file? */
5211 if(!chuukei_server) check_for_save_file(lpCmdLine);
5213 /* Did the user double click on a save file? */
5214 check_for_save_file(lpCmdLine);
5217 /* Prompt the user */
5219 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5221 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5226 /* Process messages forever */
5227 while (GetMessage(&msg, NULL, 0, 0))
5229 TranslateMessage(&msg);
5230 DispatchMessage(&msg);
5241 #endif /* WINDOWS */