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);
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.
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 : "£Í£Ó ¥´¥·¥Ã¥¯");
1087 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1090 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1093 wsprintf(buf, "%d", td->lf.lfWidth);
1094 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1095 wsprintf(buf, "%d", td->lf.lfHeight);
1096 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1097 wsprintf(buf, "%d", td->lf.lfWeight);
1098 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1101 strcpy(buf, td->bizarre ? "1" : "0");
1102 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1105 wsprintf(buf, "%d", td->tile_wid);
1106 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1109 wsprintf(buf, "%d", td->tile_hgt);
1110 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1112 /* Window size (x) */
1113 wsprintf(buf, "%d", td->cols);
1114 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1116 /* Window size (y) */
1117 wsprintf(buf, "%d", td->rows);
1118 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1120 /* Acquire position */
1121 GetWindowRect(td->w, &rc);
1123 /* Window position (x) */
1124 wsprintf(buf, "%d", rc.left);
1125 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1127 /* Window position (y) */
1128 wsprintf(buf, "%d", rc.top);
1129 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1131 /* Window Z position */
1132 strcpy(buf, td->posfix ? "1" : "0");
1133 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1140 * We assume that the windows have all been initialized
1142 static void save_prefs(void)
1148 /* Save the "arg_graphics" flag */
1149 sprintf(buf, "%d", arg_graphics);
1150 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1152 /* Save the "arg_bigtile" flag */
1153 strcpy(buf, arg_bigtile ? "1" : "0");
1154 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1156 /* Save the "arg_sound" flag */
1157 strcpy(buf, arg_sound ? "1" : "0");
1158 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1161 strcpy(buf, use_bg ? "1" : "0");
1162 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1163 WritePrivateProfileString("Angband", "BackGroundBitmap",
1164 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1166 /* Save window prefs */
1167 for (i = 0; i < MAX_TERM_DATA; ++i)
1169 term_data *td = &data[i];
1171 sprintf(buf, "Term-%d", i);
1173 save_prefs_aux(td, buf);
1179 * Load the "prefs" for a single term
1181 static void load_prefs_aux(term_data *td, cptr sec_name)
1188 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1190 /* Desired font, with default */
1192 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1194 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1199 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1201 /* Analyze font, save desired font name */
1203 td->font_want = string_make(tmp);
1205 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1206 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1207 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1209 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1215 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1216 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1218 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1219 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1224 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1225 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1227 /* Window position */
1228 td->pos_x = GetPrivateProfileInt(sec_name, "PositionX", td->pos_x, ini_file);
1229 td->pos_y = GetPrivateProfileInt(sec_name, "PositionY", td->pos_y, ini_file);
1231 /* Window Z position */
1232 td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1239 static void load_prefs(void)
1245 /* Extract the "arg_graphics" flag */
1246 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1248 /* Extract the "arg_bigtile" flag */
1249 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1250 use_bigtile = arg_bigtile;
1252 /* Extract the "arg_sound" flag */
1253 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1256 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1257 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1259 /* Load window prefs */
1260 for (i = 0; i < MAX_TERM_DATA; ++i)
1262 term_data *td = &data[i];
1264 sprintf(buf, "Term-%d", i);
1266 load_prefs_aux(td, buf);
1273 * XXX XXX XXX - Taken from files.c.
1275 * Extract "tokens" from a buffer
1277 * This function uses "whitespace" as delimiters, and treats any amount of
1278 * whitespace as a single delimiter. We will never return any empty tokens.
1279 * When given an empty buffer, or a buffer containing only "whitespace", we
1280 * will return no tokens. We will never extract more than "num" tokens.
1282 * By running a token through the "text_to_ascii()" function, you can allow
1283 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1285 * We save pointers to the tokens in "tokens", and return the number found.
1287 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1299 /* Skip leading whitespace */
1300 for ( ; *s && isspace(*s); ++s) /* loop */;
1305 /* Find next whitespace, if any */
1306 for (t = s; *t && !isspace(*t); ++t) /* loop */;
1308 /* Nuke and advance (if necessary) */
1309 if (*t) *t++ = '\0';
1311 /* Save the token */
1322 static void load_sound_prefs(void)
1326 char ini_path[1024];
1327 char wav_path[1024];
1328 char *zz[SAMPLE_MAX];
1330 /* Access the sound.cfg */
1331 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1333 for (i = 0; i < SOUND_MAX; i++)
1335 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1337 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1339 for (j = 0; j < num; j++)
1341 /* Access the sound */
1342 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1344 /* Save the sound filename, if it exists */
1345 if (check_file(wav_path))
1346 sound_file[i][j] = string_make(zz[j]);
1351 #endif /* USE_SOUND */
1354 * Create the new global palette based on the bitmap palette
1355 * (if any), and the standard 16 entry palette derived from
1356 * "win_clr[]" which is used for the basic 16 Angband colors.
1358 * This function is never called before all windows are ready.
1360 * This function returns FALSE if the new palette could not be
1361 * prepared, which should normally be a fatal error. XXX XXX
1363 * Note that only some machines actually use a "palette".
1365 static int new_palette(void)
1373 LPLOGPALETTE pLogPal;
1374 LPPALETTEENTRY lppe;
1379 /* This makes no sense */
1380 if (!paletted) return (TRUE);
1390 /* Check the bitmap palette */
1391 hBmPal = infGraph.hPalette;
1393 /* Use the bitmap */
1396 lppeSize = 256 * sizeof(PALETTEENTRY);
1397 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1398 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1399 if ((nEntries == 0) || (nEntries > 220))
1403 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1405 plog("Please switch to high- or true-color mode.");
1410 rnfree(lppe, lppeSize);
1417 #endif /* USE_GRAPHICS */
1419 /* Size of palette */
1420 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1422 /* Allocate palette */
1423 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1426 pLogPal->palVersion = 0x300;
1428 /* Make room for bitmap and normal data */
1429 pLogPal->palNumEntries = nEntries + 16;
1431 /* Save the bitmap data */
1432 for (i = 0; i < nEntries; i++)
1434 pLogPal->palPalEntry[i] = lppe[i];
1437 /* Save the normal data */
1438 for (i = 0; i < 16; i++)
1442 /* Access the entry */
1443 p = &(pLogPal->palPalEntry[i+nEntries]);
1445 /* Save the colors */
1446 p->peRed = GetRValue(win_clr[i]);
1447 p->peGreen = GetGValue(win_clr[i]);
1448 p->peBlue = GetBValue(win_clr[i]);
1450 /* Save the flags */
1451 p->peFlags = PC_NOCOLLAPSE;
1454 /* Free something */
1455 if (lppe) rnfree(lppe, lppeSize);
1457 /* Create a new palette, or fail */
1458 hNewPal = CreatePalette(pLogPal);
1460 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1462 if (!hNewPal) quit("Cannot create palette!");
1466 /* Free the palette */
1467 rnfree(pLogPal, pLogPalSize);
1472 /* Realize the palette */
1474 SelectPalette(hdc, hNewPal, 0);
1475 i = RealizePalette(hdc);
1476 ReleaseDC(td->w, hdc);
1478 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1480 if (i == 0) quit("Cannot realize palette!");
1485 for (i = 1; i < MAX_TERM_DATA; i++)
1490 SelectPalette(hdc, hNewPal, 0);
1491 ReleaseDC(td->w, hdc);
1494 /* Delete old palette */
1495 if (hPal) DeleteObject(hPal);
1497 /* Save new palette */
1507 * Initialize graphics
1509 static bool init_graphics(void)
1511 /* Initialize once */
1512 /* if (can_use_graphics != arg_graphics) */
1518 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1525 ANGBAND_GRAF = "new";
1533 ANGBAND_GRAF = "old";
1536 /* Access the bitmap file */
1537 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1539 /* Load the bitmap or quit */
1540 if (!ReadDIB(data[0].w, buf, &infGraph))
1543 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1545 plog_fmt("Cannot read bitmap file '%s'", name);
1551 /* Save the new sizes */
1552 infGraph.CellWidth = wid;
1553 infGraph.CellHeight = hgt;
1555 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1557 /* Access the mask file */
1558 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1560 /* Load the bitmap or quit */
1561 if (!ReadDIB(data[0].w, buf, &infMask))
1563 plog_fmt("Cannot read bitmap file '%s'", buf);
1568 /* Activate a palette */
1571 /* Free bitmap XXX XXX XXX */
1575 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1577 plog("Cannot activate palette!");
1583 /* Graphics available */
1584 can_use_graphics = arg_graphics;
1588 return (can_use_graphics);
1590 #endif /* USE_GRAPHICS */
1597 static bool init_sound(void)
1599 /* Initialize once */
1602 /* Load the prefs */
1605 /* Sound available */
1606 can_use_sound = TRUE;
1610 return (can_use_sound);
1612 #endif /* USE_SOUND */
1618 static void term_window_resize(term_data *td)
1620 /* Require window */
1623 /* Resize the window */
1624 SetWindowPos(td->w, 0, 0, 0,
1625 td->size_wid, td->size_hgt,
1626 SWP_NOMOVE | SWP_NOZORDER);
1629 InvalidateRect(td->w, NULL, TRUE);
1634 * Force the use of a new "font file" for a term_data
1636 * This function may be called before the "window" is ready
1638 * This function returns zero only if everything succeeds.
1640 * Note that the "font name" must be capitalized!!!
1642 static errr term_force_font(term_data *td, cptr path)
1652 /* Forget the old font (if needed) */
1653 if (td->font_id) DeleteObject(td->font_id);
1659 /* Create the font (using the 'base' of the font file name!) */
1660 td->font_id = CreateFontIndirect(&(td->lf));
1661 wid = td->lf.lfWidth;
1662 hgt = td->lf.lfHeight;
1663 if (!td->font_id) return (1);
1665 /* Forget old font */
1671 for (i = 0; i < MAX_TERM_DATA; i++)
1673 /* Don't check when closing the application */
1676 /* Check "screen" */
1677 if ((td != &data[i]) &&
1678 (data[i].font_file) &&
1679 (streq(data[i].font_file, td->font_file)))
1685 /* Remove unused font resources */
1686 if (!used) RemoveFontResource(td->font_file);
1688 /* Free the old name */
1689 string_free(td->font_file);
1692 td->font_file = NULL;
1696 if (!path) return (1);
1701 /* Analyze font path */
1702 base = analyze_font(buf, &wid, &hgt);
1705 if (!suffix(base, ".FON")) return (1);
1708 if (!check_file(buf)) return (1);
1710 /* Load the new font */
1711 if (!AddFontResource(buf)) return (1);
1713 /* Save new font name */
1714 td->font_file = string_make(base);
1716 /* Remove the "suffix" */
1717 base[strlen(base)-4] = '\0';
1719 /* Create the font (using the 'base' of the font file name!) */
1720 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1721 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1722 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1723 FIXED_PITCH | FF_DONTCARE, base);
1726 /* Hack -- Unknown size */
1733 /* all this trouble to get the cell size */
1734 hdcDesktop = GetDC(HWND_DESKTOP);
1735 hfOld = SelectObject(hdcDesktop, td->font_id);
1736 GetTextMetrics(hdcDesktop, &tm);
1737 SelectObject(hdcDesktop, hfOld);
1738 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1740 /* Font size info */
1741 wid = tm.tmAveCharWidth;
1745 /* Save the size info */
1756 * Allow the user to change the font for this window.
1758 static void term_change_font(term_data *td)
1763 memset(&cf, 0, sizeof(cf));
1764 cf.lStructSize = sizeof(cf);
1765 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1766 cf.lpLogFont = &(td->lf);
1768 if (ChooseFont(&cf))
1770 /* Force the font */
1771 term_force_font(td, NULL);
1773 /* Assume not bizarre */
1776 /* Reset the tile info */
1777 td->tile_wid = td->font_wid;
1778 td->tile_hgt = td->font_hgt;
1780 /* Analyze the font */
1783 /* Resize the window */
1784 term_window_resize(td);
1790 char tmp[1024] = "";
1792 /* Extract a default if possible */
1793 if (td->font_file) strcpy(tmp, td->font_file);
1795 /* Ask for a choice */
1796 memset(&ofn, 0, sizeof(ofn));
1797 ofn.lStructSize = sizeof(ofn);
1798 ofn.hwndOwner = data[0].w;
1799 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1800 ofn.nFilterIndex = 1;
1801 ofn.lpstrFile = tmp;
1803 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1804 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1805 ofn.lpstrDefExt = "fon";
1807 /* Force choice if legal */
1808 if (GetOpenFileName(&ofn))
1810 /* Force the font */
1811 if (term_force_font(td, tmp))
1813 /* Access the standard font file */
1814 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1816 /* Force the use of that font */
1817 (void)term_force_font(td, tmp);
1820 /* Assume not bizarre */
1821 td->bizarre = FALSE;
1823 /* Reset the tile info */
1824 td->tile_wid = td->font_wid;
1825 td->tile_hgt = td->font_hgt;
1827 /* Analyze the font */
1830 /* Resize the window */
1831 term_window_resize(td);
1838 * Allow the user to lock this window.
1840 static void term_window_pos(term_data *td, HWND hWnd)
1842 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1843 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1846 static void windows_map(void);
1849 * Hack -- redraw a term_data
1851 static void term_data_redraw(term_data *td)
1855 /* Redraw the map */
1860 /* Activate the term */
1861 Term_activate(&td->t);
1863 /* Redraw the contents */
1866 /* Restore the term */
1867 Term_activate(term_screen);
1875 /*** Function hooks needed by "Term" ***/
1881 * Initialize a new Term
1883 static void Term_init_win(term *t)
1892 static void Term_nuke_win(term *t)
1901 * Interact with the User
1903 static errr Term_user_win(int n)
1914 * React to global changes
1916 static errr Term_xtra_win_react(void)
1924 /* Save the default colors */
1925 for (i = 0; i < 256; i++)
1927 /* Simply accept the desired colors */
1928 win_pal[i] = angband_color_table[i][0];
1939 bool change = FALSE;
1941 /* Save the default colors */
1942 for (i = 0; i < 256; i++)
1944 /* Extract desired values */
1945 rv = angband_color_table[i][1];
1946 gv = angband_color_table[i][2];
1947 bv = angband_color_table[i][3];
1949 /* Extract a full color code */
1950 code = PALETTERGB(rv, gv, bv);
1952 /* Activate changes */
1953 if (win_clr[i] != code)
1955 /* Note the change */
1958 /* Apply the desired color */
1963 /* Activate the palette if needed */
1964 if (change) (void)new_palette();
1970 /* Handle "arg_sound" */
1971 if (use_sound != arg_sound)
1973 /* Initialize (if needed) */
1974 if (arg_sound && !init_sound())
1978 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
1980 plog("Cannot initialize sound!");
1988 /* Change setting */
1989 use_sound = arg_sound;
1997 /* Handle "arg_graphics" */
1998 if (use_graphics != arg_graphics)
2000 /* Initialize (if needed) */
2001 if (arg_graphics && !init_graphics())
2005 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
2007 plog("Cannot initialize graphics!");
2012 arg_graphics = GRAPHICS_NONE;
2015 /* Change setting */
2016 use_graphics = arg_graphics;
2019 #ifdef ANGBAND_2_8_1
2021 #else /* ANGBAND_2_8_1 */
2022 reset_visuals(TRUE);
2023 #endif /* ANGBAND_2_8_1 */
2026 #endif /* USE_GRAPHICS */
2029 /* Clean up windows */
2030 for (i = 0; i < MAX_TERM_DATA; i++)
2034 term_data *td = &data[i];
2036 /* Update resized windows */
2037 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2040 Term_activate(&td->t);
2042 /* Hack -- Resize the term */
2043 Term_resize(td->cols, td->rows);
2045 /* Redraw the contents */
2060 * Process at least one event
2062 static errr Term_xtra_win_event(int v)
2066 /* Wait for an event */
2070 if (GetMessage(&msg, NULL, 0, 0))
2072 TranslateMessage(&msg);
2073 DispatchMessage(&msg);
2077 /* Check for an event */
2081 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2083 TranslateMessage(&msg);
2084 DispatchMessage(&msg);
2094 * Process all pending events
2096 static errr Term_xtra_win_flush(void)
2100 /* Process all pending events */
2101 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2103 TranslateMessage(&msg);
2104 DispatchMessage(&msg);
2113 * Hack -- clear the screen
2115 * Make this more efficient XXX XXX XXX
2117 static errr Term_xtra_win_clear(void)
2119 term_data *td = (term_data*)(Term->data);
2124 /* Rectangle to erase */
2125 rc.left = td->size_ow1;
2126 rc.right = rc.left + td->cols * td->tile_wid;
2127 rc.top = td->size_oh1;
2128 rc.bottom = rc.top + td->rows * td->tile_hgt;
2132 SetBkColor(hdc, RGB(0, 0, 0));
2133 SelectObject(hdc, td->font_id);
2134 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2139 rc.left = 0; rc.top = 0;
2142 ReleaseDC(td->w, hdc);
2150 * Hack -- make a noise
2152 static errr Term_xtra_win_noise(void)
2154 MessageBeep(MB_ICONASTERISK);
2160 * Hack -- make a sound
2162 static errr Term_xtra_win_sound(int v)
2167 #endif /* USE_SOUND */
2169 /* Sound disabled */
2170 if (!use_sound) return (1);
2173 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2177 /* Count the samples */
2178 for (i = 0; i < SAMPLE_MAX; i++)
2180 if (!sound_file[v][i])
2185 if (i == 0) return (1);
2187 /* Build the path */
2188 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_simple(i)]);
2192 /* Play the sound, catch errors */
2193 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2197 /* Play the sound, catch errors */
2198 return (sndPlaySound(buf, SND_ASYNC));
2202 #else /* USE_SOUND */
2207 #endif /* USE_SOUND */
2212 * Delay for "x" milliseconds
2214 static int Term_xtra_win_delay(int v)
2228 t = GetTickCount() + v;
2231 while (GetTickCount() < t)
2233 /* Handle messages */
2234 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2236 TranslateMessage(&msg);
2237 DispatchMessage(&msg);
2249 * Do a "special thing"
2251 static errr Term_xtra_win(int n, int v)
2253 /* Handle a subset of the legal requests */
2256 /* Make a bell sound */
2257 case TERM_XTRA_NOISE:
2259 return (Term_xtra_win_noise());
2262 /* Make a special sound */
2263 case TERM_XTRA_SOUND:
2265 return (Term_xtra_win_sound(v));
2268 /* Process random events */
2269 case TERM_XTRA_BORED:
2271 return (Term_xtra_win_event(0));
2274 /* Process an event */
2275 case TERM_XTRA_EVENT:
2277 return (Term_xtra_win_event(v));
2280 /* Flush all events */
2281 case TERM_XTRA_FLUSH:
2283 return (Term_xtra_win_flush());
2286 /* Clear the screen */
2287 case TERM_XTRA_CLEAR:
2289 return (Term_xtra_win_clear());
2292 /* React to global changes */
2293 case TERM_XTRA_REACT:
2295 return (Term_xtra_win_react());
2298 /* Delay for some milliseconds */
2299 case TERM_XTRA_DELAY:
2301 return (Term_xtra_win_delay(v));
2312 * Low level graphics (Assumes valid input).
2314 * Draw a "cursor" at (x,y), using a "yellow box".
2316 static errr Term_curs_win(int x, int y)
2318 term_data *td = (term_data*)(Term->data);
2323 int tile_wid, tile_hgt;
2327 tile_wid = td->map_tile_wid;
2328 tile_hgt = td->map_tile_hgt;
2332 tile_wid = td->tile_wid;
2333 tile_hgt = td->tile_hgt;
2336 /* Frame the grid */
2337 rc.left = x * tile_wid + td->size_ow1;
2338 rc.right = rc.left + tile_wid;
2339 rc.top = y * tile_hgt + td->size_oh1;
2340 rc.bottom = rc.top + tile_hgt;
2342 /* Cursor is done as a yellow "box" */
2344 FrameRect(hdc, &rc, hbrYellow);
2345 ReleaseDC(td->w, hdc);
2353 * Low level graphics (Assumes valid input).
2355 * Draw a "big cursor" at (x,y), using a "yellow box".
2357 static errr Term_bigcurs_win(int x, int y)
2359 term_data *td = (term_data*)(Term->data);
2364 int tile_wid, tile_hgt;
2368 /* Normal cursor in map window */
2369 Term_curs_win(x, y);
2374 tile_wid = td->tile_wid;
2375 tile_hgt = td->tile_hgt;
2378 /* Frame the grid */
2379 rc.left = x * tile_wid + td->size_ow1;
2380 rc.right = rc.left + 2 * tile_wid;
2381 rc.top = y * tile_hgt + td->size_oh1;
2382 rc.bottom = rc.top + tile_hgt;
2384 /* Cursor is done as a yellow "box" */
2386 FrameRect(hdc, &rc, hbrYellow);
2387 ReleaseDC(td->w, hdc);
2395 * Low level graphics (Assumes valid input).
2397 * Erase a "block" of "n" characters starting at (x,y).
2399 static errr Term_wipe_win(int x, int y, int n)
2401 term_data *td = (term_data*)(Term->data);
2406 /* Rectangle to erase in client coords */
2407 rc.left = x * td->tile_wid + td->size_ow1;
2408 rc.right = rc.left + n * td->tile_wid;
2409 rc.top = y * td->tile_hgt + td->size_oh1;
2410 rc.bottom = rc.top + td->tile_hgt;
2413 SetBkColor(hdc, RGB(0, 0, 0));
2414 SelectObject(hdc, td->font_id);
2419 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2420 ReleaseDC(td->w, hdc);
2428 * Low level graphics. Assumes valid input.
2430 * Draw several ("n") chars, with an attr, at a given location.
2432 * All "graphic" data is handled by "Term_pict_win()", below.
2434 * One would think there is a more efficient method for telling a window
2435 * what color it should be using to draw with, but perhaps simply changing
2436 * it every time is not too inefficient. XXX XXX XXX
2438 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2440 term_data *td = (term_data*)(Term->data);
2446 static HBITMAP WALL;
2447 static HBRUSH myBrush, oldBrush;
2449 static bool init_done = FALSE;
2452 WALL = LoadBitmap(hInstance, AppName);
2453 myBrush = CreatePatternBrush(WALL);
2458 /* Total rectangle */
2459 rc.left = x * td->tile_wid + td->size_ow1;
2460 rc.right = rc.left + n * td->tile_wid;
2461 rc.top = y * td->tile_hgt + td->size_oh1;
2462 rc.bottom = rc.top + td->tile_hgt;
2467 /* Background color */
2468 SetBkColor(hdc, RGB(0, 0, 0));
2470 /* Foreground color */
2473 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2477 SetTextColor(hdc, win_clr[a&0x0F]);
2481 SetTextColor(hdc, win_clr[a]);
2485 SelectObject(hdc, td->font_id);
2488 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2492 (td->tile_hgt != td->font_hgt) ||
2493 (td->tile_wid != td->font_wid))
2497 /* Erase complete rectangle */
2498 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2501 if (use_bg) DrawBG(hdc, &rc);
2504 rc.left += ((td->tile_wid - td->font_wid) / 2);
2505 rc.right = rc.left + td->font_wid;
2506 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2507 rc.bottom = rc.top + td->font_hgt;
2509 /* Dump each character */
2510 for (i = 0; i < n; i++)
2513 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2515 rc.right += td->font_wid;
2517 oldBrush = SelectObject(hdc, myBrush);
2518 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2521 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2523 SelectObject(hdc, oldBrush);
2524 SelectObject(hdc, oldPen);
2525 rc.right -= td->font_wid;
2529 rc.left += 2 * td->tile_wid;
2530 rc.right += 2 * td->tile_wid;
2532 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2534 rc.right += td->font_wid;
2536 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2538 rc.right -= td->font_wid;
2542 rc.left += 2 * td->tile_wid;
2543 rc.right += 2 * td->tile_wid;
2544 } else if (*(s+i)==127){
2545 oldBrush = SelectObject(hdc, myBrush);
2546 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2549 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2551 SelectObject(hdc, oldBrush);
2552 SelectObject(hdc, oldPen);
2555 rc.left += td->tile_wid;
2556 rc.right += td->tile_wid;
2559 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2563 rc.left += td->tile_wid;
2564 rc.right += td->tile_wid;
2568 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2572 rc.left += td->tile_wid;
2573 rc.right += td->tile_wid;
2583 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2588 ReleaseDC(td->w, hdc);
2596 * Low level graphics. Assumes valid input.
2598 * Draw an array of "special" attr/char pairs at the given location.
2600 * We use the "Term_pict_win()" function for "graphic" data, which are
2601 * encoded by setting the "high-bits" of both the "attr" and the "char"
2602 * data. We use the "attr" to represent the "row" of the main bitmap,
2603 * and the "char" to represent the "col" of the main bitmap. The use
2604 * of this function is induced by the "higher_pict" flag.
2606 * If "graphics" is not available, we simply "wipe" the given grids.
2608 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2610 term_data *td = (term_data*)(Term->data);
2616 int x2, y2, w2, h2, tw2;
2628 /* Erase the grids */
2629 return (Term_wipe_win(x, y, n));
2632 /* Size of bitmap cell */
2633 w1 = infGraph.CellWidth;
2634 h1 = infGraph.CellHeight;
2636 /* Size of window cell */
2639 w2 = td->map_tile_wid;
2640 h2 = td->map_tile_hgt;
2649 if (use_bigtile) tw2 *= 2;
2652 /* Location of window cell */
2653 x2 = x * w2 + td->size_ow1;
2654 y2 = y * h2 + td->size_oh1;
2660 hdcSrc = CreateCompatibleDC(hdc);
2661 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2663 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2665 hdcMask = CreateCompatibleDC(hdc);
2666 SelectObject(hdcMask, infMask.hBitmap);
2669 /* Draw attr/char pairs */
2670 for (i = 0; i < n; i++, x2 += w2)
2675 /* Extract picture */
2676 int row = (a & 0x7F);
2677 int col = (c & 0x7F);
2679 /* Location of bitmap cell */
2683 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2685 x3 = (tcp[i] & 0x7F) * w1;
2686 y3 = (tap[i] & 0x7F) * h1;
2689 if ((w1 == tw2) && (h1 == h2))
2691 /* Copy the terrain picture from the bitmap to the window */
2692 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2694 /* Mask out the tile */
2695 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2698 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2701 /* Need to stretch */
2704 /* Set the correct mode for stretching the tiles */
2705 SetStretchBltMode(hdc, COLORONCOLOR);
2707 /* Copy the terrain picture from the bitmap to the window */
2708 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
2710 /* Only draw if terrain and overlay are different */
2711 if ((x1 != x3) || (y1 != y3))
2713 /* Mask out the tile */
2714 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2717 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2724 if ((w1 == tw2) && (h1 == h2))
2726 /* Copy the picture from the bitmap to the window */
2727 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2730 /* Need to stretch */
2733 /* Set the correct mode for stretching the tiles */
2734 SetStretchBltMode(hdc, COLORONCOLOR);
2736 /* Copy the picture from the bitmap to the window */
2737 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2743 SelectObject(hdcSrc, hbmSrcOld);
2746 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2749 SelectObject(hdcMask, hbmSrcOld);
2754 ReleaseDC(td->w, hdc);
2756 #else /* USE_GRAPHICS */
2758 /* Just erase this grid */
2759 return (Term_wipe_win(x, y, n));
2761 #endif /* USE_GRAPHICS */
2768 static void windows_map(void)
2770 term_data *td = &data[0];
2772 int x, min_x, max_x;
2773 int y, min_y, max_y;
2777 /* Only in graphics mode */
2778 if (!use_graphics) return;
2781 Term_xtra_win_clear();
2783 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2784 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2785 td->map_active = TRUE;
2795 for (x = min_x; x < max_x; x++)
2797 for (y = min_y; y < max_y; y++)
2799 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
2801 /* Ignore non-graphics */
2802 if ((a & 0x80) && (c & 0x80))
2804 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2809 /* Hilite the player */
2810 Term_curs_win(px - min_x, py - min_y);
2812 /* Wait for a keypress, flush key buffer */
2813 Term_inkey(&c, TRUE, TRUE);
2816 /* Switch off the map display */
2817 td->map_active = FALSE;
2819 /* Restore screen */
2820 Term_xtra_win_clear();
2825 /*** Other routines ***/
2829 * Create and initialize a "term_data" given a title
2831 static void term_data_link(term_data *td)
2835 /* Initialize the term */
2836 term_init(t, td->cols, td->rows, td->keys);
2838 /* Use a "software" cursor */
2839 t->soft_cursor = TRUE;
2841 /* Use "Term_pict" for "graphic" data */
2842 t->higher_pict = TRUE;
2844 /* Erase with "white space" */
2845 t->attr_blank = TERM_WHITE;
2846 t->char_blank = ' ';
2849 /* Prepare the init/nuke hooks */
2850 t->init_hook = Term_init_win;
2851 t->nuke_hook = Term_nuke_win;
2854 /* Prepare the template hooks */
2855 t->user_hook = Term_user_win;
2856 t->xtra_hook = Term_xtra_win;
2857 t->curs_hook = Term_curs_win;
2858 t->bigcurs_hook = Term_bigcurs_win;
2859 t->wipe_hook = Term_wipe_win;
2860 t->text_hook = Term_text_win;
2861 t->pict_hook = Term_pict_win;
2863 /* Remember where we came from */
2864 t->data = (vptr)(td);
2869 * Create the windows
2871 * First, instantiate the "default" values, then read the "ini_file"
2872 * to over-ride selected values, then create the windows, and fonts.
2874 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2875 * must make active to realize the palette. XXX XXX XXX
2877 static void init_windows(void)
2889 WIPE(td, term_data);
2893 td->s = angband_term_name[0];
2912 for (i = 1; i < MAX_TERM_DATA; i++)
2915 WIPE(td, term_data);
2916 td->s = angband_term_name[i];
2920 td->visible = FALSE;
2925 td->pos_x = (7 - i) * 30;
2926 td->pos_y = (7 - i) * 20;
2938 /* Main window (need these before term_getsize gets called) */
2940 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2941 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2946 /* Sub windows (need these before term_getsize gets called) */
2947 for (i = 1; i < MAX_TERM_DATA; i++)
2950 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2951 td->dwExStyle = (WS_EX_TOOLWINDOW);
2956 for (i = 0; i < MAX_TERM_DATA; i++)
2961 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2962 td->lf.lfCharSet = SHIFTJIS_CHARSET;
2963 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2964 /* Activate the chosen font */
2965 term_force_font(td, NULL);
2966 td->tile_wid = td->font_wid;
2967 td->tile_hgt = td->font_hgt;
2969 /* Access the standard font file */
2970 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
2972 /* Activate the chosen font */
2973 if (term_force_font(td, buf))
2975 /* Access the standard font file */
2976 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2978 /* Force the use of that font */
2979 (void)term_force_font(td, buf);
2985 /* Assume not bizarre */
2986 td->bizarre = FALSE;
2991 /* Analyze the font */
2994 /* Resize the window */
2995 term_window_resize(td);
2999 /* Sub windows (reverse order) */
3000 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3005 td->w = CreateWindowEx(td->dwExStyle, AngList,
3007 td->pos_x, td->pos_y,
3008 td->size_wid, td->size_hgt,
3009 HWND_DESKTOP, NULL, hInstance, NULL);
3012 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3014 if (!td->w) quit("Failed to create sub-window");
3020 td->size_hack = TRUE;
3021 ShowWindow(td->w, SW_SHOW);
3022 td->size_hack = FALSE;
3026 angband_term[i] = &td->t;
3030 /* Activate the window */
3031 SetActiveWindow(td->w);
3036 term_window_pos(&data[i], HWND_TOPMOST);
3040 term_window_pos(&data[i], td->w);
3050 td->w = CreateWindowEx(td->dwExStyle, AppName,
3052 td->pos_x, td->pos_y,
3053 td->size_wid, td->size_hgt,
3054 HWND_DESKTOP, NULL, hInstance, NULL);
3057 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3059 if (!td->w) quit("Failed to create Angband window");
3064 angband_term[0] = &td->t;
3066 /* Activate the main window */
3067 SetActiveWindow(td->w);
3069 /* Bring main window back to top */
3070 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3073 /* New palette XXX XXX XXX */
3074 (void)new_palette();
3077 /* Create a "brush" for drawing the "cursor" */
3078 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3081 /* Process pending messages */
3082 (void)Term_xtra_win_flush();
3090 static void setup_menus(void)
3094 HMENU hm = GetMenu(data[0].w);
3097 /* Menu "File", Disable all */
3098 EnableMenuItem(hm, IDM_FILE_NEW,
3099 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3100 EnableMenuItem(hm, IDM_FILE_OPEN,
3101 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3102 EnableMenuItem(hm, IDM_FILE_SAVE,
3103 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3104 EnableMenuItem(hm, IDM_FILE_EXIT,
3105 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3106 EnableMenuItem(hm, IDM_FILE_SCORE,
3107 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3110 /* No character available */
3111 if (!character_generated)
3113 /* Menu "File", Item "New" */
3114 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3116 /* Menu "File", Item "Open" */
3117 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3120 /* A character available */
3121 if (character_generated)
3123 /* Menu "File", Item "Save" */
3124 EnableMenuItem(hm, IDM_FILE_SAVE,
3125 MF_BYCOMMAND | MF_ENABLED);
3128 /* Menu "File", Item "Exit" */
3129 EnableMenuItem(hm, IDM_FILE_EXIT,
3130 MF_BYCOMMAND | MF_ENABLED);
3132 EnableMenuItem(hm, IDM_FILE_SCORE,
3133 MF_BYCOMMAND | MF_ENABLED);
3136 /* Menu "Window::Visibility" */
3137 for (i = 0; i < MAX_TERM_DATA; i++)
3139 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3140 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3142 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3143 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3145 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3146 MF_BYCOMMAND | MF_ENABLED);
3149 /* Menu "Window::Font" */
3150 for (i = 0; i < MAX_TERM_DATA; i++)
3152 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3153 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3155 if (data[i].visible)
3157 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3158 MF_BYCOMMAND | MF_ENABLED);
3162 /* Menu "Window::Window Position Fix" */
3163 for (i = 0; i < MAX_TERM_DATA; i++)
3165 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3166 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3168 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3169 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3171 if (data[i].visible)
3173 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3174 MF_BYCOMMAND | MF_ENABLED);
3178 /* Menu "Window::Bizarre Display" */
3179 for (i = 0; i < MAX_TERM_DATA; i++)
3181 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3182 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3184 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3185 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3187 if (data[i].visible)
3189 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3190 MF_BYCOMMAND | MF_ENABLED);
3195 /* Menu "Window::Increase Tile Width" */
3196 for (i = 0; i < MAX_TERM_DATA; i++)
3198 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3199 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3201 if (data[i].visible)
3203 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3204 MF_BYCOMMAND | MF_ENABLED);
3209 /* Menu "Window::Decrease Tile Width" */
3210 for (i = 0; i < MAX_TERM_DATA; i++)
3212 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3213 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3215 if (data[i].visible)
3217 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3218 MF_BYCOMMAND | MF_ENABLED);
3223 /* Menu "Window::Increase Tile Height" */
3224 for (i = 0; i < MAX_TERM_DATA; i++)
3226 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3227 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3229 if (data[i].visible)
3231 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3232 MF_BYCOMMAND | MF_ENABLED);
3237 /* Menu "Window::Decrease Tile Height" */
3238 for (i = 0; i < MAX_TERM_DATA; i++)
3240 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3241 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3243 if (data[i].visible)
3245 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3246 MF_BYCOMMAND | MF_ENABLED);
3251 /* Menu "Options", disable all */
3252 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3253 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3254 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3255 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3256 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3257 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3258 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3259 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3260 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3261 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3263 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3264 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3267 /* Menu "Options", Item "Map" */
3268 if (use_graphics != GRAPHICS_NONE)
3269 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3271 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3272 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3274 /* Menu "Options", update all */
3275 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3276 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3277 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3278 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3279 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3280 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3281 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3282 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3283 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3284 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3285 CheckMenuItem(hm, IDM_OPTIONS_BG,
3286 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3288 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3289 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3293 /* Menu "Options", Item "Graphics" */
3294 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3295 /* Menu "Options", Item "Graphics" */
3296 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3297 /* Menu "Options", Item "Graphics" */
3298 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3299 /* Menu "Options", Item "Graphics" */
3300 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3301 #endif /* USE_GRAPHICS */
3304 /* Menu "Options", Item "Sound" */
3305 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3306 #endif /* USE_SOUND */
3309 /* Menu "Options", Item "ScreenSaver" */
3310 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3311 MF_BYCOMMAND | MF_ENABLED);
3312 #endif /* USE_SAVER */
3317 * Check for double clicked (or dragged) savefile
3319 * Apparently, Windows copies the entire filename into the first
3320 * piece of the "command line string". Perhaps we should extract
3321 * the "basename" of that filename and append it to the "save" dir.
3323 static void check_for_save_file(LPSTR cmd_line)
3333 /* Extract filename */
3334 strcat(savefile, s);
3336 /* Validate the file */
3337 validate_file(savefile);
3339 /* Game in progress */
3340 game_in_progress = TRUE;
3348 * Process a menu command
3350 static void process_menus(WORD wCmd)
3367 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3369 plog("You cannot do that yet...");
3373 else if (game_in_progress)
3376 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3378 plog("You can't start a new game while you're still playing!");
3384 game_in_progress = TRUE;
3398 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3400 plog("You cannot do that yet...");
3404 else if (game_in_progress)
3407 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3409 plog("You can't open a new game while you're still playing!");
3415 memset(&ofn, 0, sizeof(ofn));
3416 ofn.lStructSize = sizeof(ofn);
3417 ofn.hwndOwner = data[0].w;
3418 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3419 ofn.nFilterIndex = 1;
3420 ofn.lpstrFile = savefile;
3421 ofn.nMaxFile = 1024;
3422 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3423 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3425 if (GetOpenFileName(&ofn))
3427 /* Load 'savefile' */
3428 validate_file(savefile);
3429 game_in_progress = TRUE;
3441 if (game_in_progress && character_generated)
3447 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3449 plog("You may not do that right now.");
3455 /* Hack -- Forget messages */
3460 do_cmd_save_game(FALSE);
3461 #else /* ZANGBAND */
3463 #endif /* ZANGBAND */
3468 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3470 plog("You may not do that right now.");
3480 if (game_in_progress && character_generated)
3486 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3488 plog("You may not do that right now.");
3494 /* Hack -- Forget messages */
3503 /* do_cmd_save_game(FALSE); */
3504 #else /* ZANGBAND */
3505 /* do_cmd_save_game(); */
3506 #endif /* ZANGBAND */
3507 Term_key_push(SPECIAL_KEY_QUIT);
3515 case IDM_FILE_SCORE:
3519 /* Build the filename */
3520 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3522 /* Open the binary high score file, for reading */
3523 highscore_fd = fd_open(buf, O_RDONLY);
3525 /* Paranoia -- No score file */
3526 if (highscore_fd < 0)
3528 msg_print("Score file unavailable.");
3538 /* Display the scores */
3539 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3541 /* Shut the high score file */
3542 (void)fd_close(highscore_fd);
3544 /* Forget the high score fd */
3550 /* Hack - Flush it */
3558 case IDM_WINDOW_VIS_0:
3561 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3563 plog("You are not allowed to do that!");
3570 /* Window visibility */
3571 case IDM_WINDOW_VIS_1:
3572 case IDM_WINDOW_VIS_2:
3573 case IDM_WINDOW_VIS_3:
3574 case IDM_WINDOW_VIS_4:
3575 case IDM_WINDOW_VIS_5:
3576 case IDM_WINDOW_VIS_6:
3577 case IDM_WINDOW_VIS_7:
3579 i = wCmd - IDM_WINDOW_VIS_0;
3581 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3588 ShowWindow(td->w, SW_SHOW);
3589 term_data_redraw(td);
3593 td->visible = FALSE;
3595 ShowWindow(td->w, SW_HIDE);
3602 case IDM_WINDOW_FONT_0:
3603 case IDM_WINDOW_FONT_1:
3604 case IDM_WINDOW_FONT_2:
3605 case IDM_WINDOW_FONT_3:
3606 case IDM_WINDOW_FONT_4:
3607 case IDM_WINDOW_FONT_5:
3608 case IDM_WINDOW_FONT_6:
3609 case IDM_WINDOW_FONT_7:
3611 i = wCmd - IDM_WINDOW_FONT_0;
3613 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3617 term_change_font(td);
3622 /* Window Z Position */
3623 case IDM_WINDOW_POS_1:
3624 case IDM_WINDOW_POS_2:
3625 case IDM_WINDOW_POS_3:
3626 case IDM_WINDOW_POS_4:
3627 case IDM_WINDOW_POS_5:
3628 case IDM_WINDOW_POS_6:
3629 case IDM_WINDOW_POS_7:
3631 i = wCmd - IDM_WINDOW_POS_0;
3633 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3637 if (!td->posfix && td->visible)
3640 term_window_pos(td, HWND_TOPMOST);
3645 term_window_pos(td, data[0].w);
3651 /* Bizarre Display */
3652 case IDM_WINDOW_BIZ_0:
3653 case IDM_WINDOW_BIZ_1:
3654 case IDM_WINDOW_BIZ_2:
3655 case IDM_WINDOW_BIZ_3:
3656 case IDM_WINDOW_BIZ_4:
3657 case IDM_WINDOW_BIZ_5:
3658 case IDM_WINDOW_BIZ_6:
3659 case IDM_WINDOW_BIZ_7:
3661 i = wCmd - IDM_WINDOW_BIZ_0;
3663 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3667 td->bizarre = !td->bizarre;
3671 term_window_resize(td);
3676 /* Increase Tile Width */
3677 case IDM_WINDOW_I_WID_0:
3678 case IDM_WINDOW_I_WID_1:
3679 case IDM_WINDOW_I_WID_2:
3680 case IDM_WINDOW_I_WID_3:
3681 case IDM_WINDOW_I_WID_4:
3682 case IDM_WINDOW_I_WID_5:
3683 case IDM_WINDOW_I_WID_6:
3684 case IDM_WINDOW_I_WID_7:
3686 i = wCmd - IDM_WINDOW_I_WID_0;
3688 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3696 term_window_resize(td);
3701 /* Decrease Tile Height */
3702 case IDM_WINDOW_D_WID_0:
3703 case IDM_WINDOW_D_WID_1:
3704 case IDM_WINDOW_D_WID_2:
3705 case IDM_WINDOW_D_WID_3:
3706 case IDM_WINDOW_D_WID_4:
3707 case IDM_WINDOW_D_WID_5:
3708 case IDM_WINDOW_D_WID_6:
3709 case IDM_WINDOW_D_WID_7:
3711 i = wCmd - IDM_WINDOW_D_WID_0;
3713 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3721 term_window_resize(td);
3726 /* Increase Tile Height */
3727 case IDM_WINDOW_I_HGT_0:
3728 case IDM_WINDOW_I_HGT_1:
3729 case IDM_WINDOW_I_HGT_2:
3730 case IDM_WINDOW_I_HGT_3:
3731 case IDM_WINDOW_I_HGT_4:
3732 case IDM_WINDOW_I_HGT_5:
3733 case IDM_WINDOW_I_HGT_6:
3734 case IDM_WINDOW_I_HGT_7:
3736 i = wCmd - IDM_WINDOW_I_HGT_0;
3738 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3746 term_window_resize(td);
3751 /* Decrease Tile Height */
3752 case IDM_WINDOW_D_HGT_0:
3753 case IDM_WINDOW_D_HGT_1:
3754 case IDM_WINDOW_D_HGT_2:
3755 case IDM_WINDOW_D_HGT_3:
3756 case IDM_WINDOW_D_HGT_4:
3757 case IDM_WINDOW_D_HGT_5:
3758 case IDM_WINDOW_D_HGT_6:
3759 case IDM_WINDOW_D_HGT_7:
3761 i = wCmd - IDM_WINDOW_D_HGT_0;
3763 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3771 term_window_resize(td);
3776 case IDM_OPTIONS_NO_GRAPHICS:
3781 plog("You may not do that right now.");
3785 /* Toggle "arg_graphics" */
3786 if (arg_graphics != GRAPHICS_NONE)
3788 arg_graphics = GRAPHICS_NONE;
3790 /* React to changes */
3791 Term_xtra_win_react();
3793 /* Hack -- Force redraw */
3794 Term_key_push(KTRL('R'));
3800 case IDM_OPTIONS_OLD_GRAPHICS:
3805 plog("You may not do that right now.");
3809 /* Toggle "arg_graphics" */
3810 if (arg_graphics != GRAPHICS_ORIGINAL)
3812 arg_graphics = GRAPHICS_ORIGINAL;
3814 /* React to changes */
3815 Term_xtra_win_react();
3817 /* Hack -- Force redraw */
3818 Term_key_push(KTRL('R'));
3824 case IDM_OPTIONS_NEW_GRAPHICS:
3829 plog("You may not do that right now.");
3833 /* Toggle "arg_graphics" */
3834 if (arg_graphics != GRAPHICS_ADAM_BOLT)
3836 arg_graphics = GRAPHICS_ADAM_BOLT;
3838 /* React to changes */
3839 Term_xtra_win_react();
3841 /* Hack -- Force redraw */
3842 Term_key_push(KTRL('R'));
3848 case IDM_OPTIONS_BIGTILE:
3850 term_data *td = &data[0];
3855 plog("You may not do that right now.");
3859 /* Toggle "arg_sound" */
3860 arg_bigtile = !arg_bigtile;
3863 Term_activate(&td->t);
3865 /* Resize the term */
3866 Term_resize(td->cols, td->rows);
3869 InvalidateRect(td->w, NULL, TRUE);
3874 case IDM_OPTIONS_SOUND:
3879 plog("You may not do that right now.");
3883 /* Toggle "arg_sound" */
3884 arg_sound = !arg_sound;
3886 /* React to changes */
3887 Term_xtra_win_react();
3889 /* Hack -- Force redraw */
3890 Term_key_push(KTRL('R'));
3896 case IDM_OPTIONS_BG:
3901 plog("You may not do that right now.");
3905 /* Toggle "use_bg" */
3910 /* React to changes */
3911 Term_xtra_win_react();
3913 /* Hack -- Force redraw */
3914 Term_key_push(KTRL('R'));
3920 case IDM_OPTIONS_OPEN_BG:
3925 plog("You may not do that right now.");
3930 memset(&ofn, 0, sizeof(ofn));
3931 ofn.lStructSize = sizeof(ofn);
3932 ofn.hwndOwner = data[0].w;
3933 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3934 ofn.nFilterIndex = 1;
3935 ofn.lpstrFile = bg_bitmap_file;
3936 ofn.nMaxFile = 1023;
3937 ofn.lpstrInitialDir = NULL;
3939 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
3941 ofn.lpstrTitle = "Choose wall paper.";
3943 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3945 if (GetOpenFileName(&ofn))
3947 /* Load 'savefile' */
3952 /* React to changes */
3953 Term_xtra_win_react();
3955 /* Hack -- Force redraw */
3956 Term_key_push(KTRL('R'));
3961 case IDM_DUMP_SCREEN_HTML:
3963 static char buf[1024] = "";
3964 memset(&ofn, 0, sizeof(ofn));
3965 ofn.lStructSize = sizeof(ofn);
3966 ofn.hwndOwner = data[0].w;
3967 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
3968 ofn.nFilterIndex = 1;
3969 ofn.lpstrFile = buf;
3970 ofn.nMaxFile = 1023;
3971 ofn.lpstrDefExt = "html";
3972 ofn.lpstrInitialDir = NULL;
3974 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
3976 ofn.lpstrTitle = "Save screen dump as HTML.";
3978 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
3980 if (GetSaveFileName(&ofn))
3982 do_cmd_save_screen_html_aux(buf, 0);
3989 case IDM_OPTIONS_SAVER:
3993 DestroyWindow(hwndSaver);
3998 /* Create a screen scaver window */
3999 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4000 "Angband Screensaver",
4001 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4002 0, 0, GetSystemMetrics(SM_CXSCREEN),
4003 GetSystemMetrics(SM_CYSCREEN),
4004 NULL, NULL, hInstance, NULL);
4008 /* Push the window to the bottom XXX XXX XXX */
4009 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4014 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
4016 plog("Failed to create saver window");
4026 case IDM_OPTIONS_MAP:
4032 case IDM_HELP_CONTENTS:
4036 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4037 if (check_file(tmp))
4039 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4044 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4045 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4047 plog_fmt("Cannot find help file: %s", tmp);
4048 plog("Use the online help files instead.");
4053 #else /* HTML_HELP */
4056 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4057 if (check_file(tmp))
4059 sprintf(buf, "winhelp.exe %s", tmp);
4060 WinExec(buf, SW_NORMAL);
4065 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4066 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4068 plog_fmt("Cannot find help file: %s", tmp);
4069 plog("Use the online help files instead.");
4074 #endif /* HTML_HELP */
4080 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4087 /* Extract the modifiers */
4088 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4089 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4090 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4092 Term_no_press = (ma) ? TRUE : FALSE;
4094 /* Handle "special" keys */
4095 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4097 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4098 bool numpad = FALSE;
4100 /* Begin the macro trigger */
4103 /* Send the modifiers */
4104 if (mc) Term_keypress('C');
4105 if (ms) Term_keypress('S');
4106 if (ma) Term_keypress('A');
4108 /* Extract "scan code" */
4109 i = LOBYTE(HIWORD(lParam));
4111 /* Introduce the scan code */
4114 /* Extended key bit */
4117 /* Numpad Enter and '/' are extended key */
4119 Term_no_press = TRUE;
4120 case VK_RETURN: /* Enter */
4123 /* Other extended keys are on full keyboard */
4139 Term_no_press = TRUE;
4143 case VK_PRIOR: /* Page Up */
4144 case VK_NEXT: /* Page Down */
4154 /* Special modifiers for keypad keys */
4155 if (numpad) Term_keypress('K');
4157 /* Encode the hexidecimal scan code */
4158 Term_keypress(hexsym[i/16]);
4159 Term_keypress(hexsym[i%16]);
4161 /* End the macro trigger */
4172 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4173 WPARAM wParam, LPARAM lParam);
4174 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4175 WPARAM wParam, LPARAM lParam)
4176 #else /* __MWERKS__ */
4177 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4178 WPARAM wParam, LPARAM lParam)
4179 #endif /* __MWERKS__ */
4185 MINMAXINFO FAR *lpmmi;
4191 /* Acquire proper "term_data" info */
4192 td = (term_data *)GetWindowLong(hWnd, 0);
4194 /* Handle message */
4200 SetWindowLong(hWnd, 0, (LONG)(my_td));
4210 case WM_GETMINMAXINFO:
4212 MINMAXINFO FAR *lpmmi;
4215 lpmmi = (MINMAXINFO FAR *)lParam;
4217 /* this message was sent before WM_NCCREATE */
4220 /* Minimum window size is 80x24 */
4221 rc.left = rc.top = 0;
4222 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4223 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4226 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4228 /* Save minimum size */
4229 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4230 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4237 BeginPaint(hWnd, &ps);
4238 if (td) term_data_redraw(td);
4239 EndPaint(hWnd, &ps);
4240 ValidateRect(hWnd, NULL);
4247 if (process_keydown(wParam, lParam))
4254 if (Term_no_press) Term_no_press = FALSE;
4255 else Term_keypress(wParam);
4267 if (game_in_progress && character_generated)
4272 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4274 plog("You may not do that right now.");
4279 /* Hack -- Forget messages */
4288 /* do_cmd_save_game(FALSE); */
4289 #else /* ZANGBAND */
4290 /* do_cmd_save_game(); */
4291 #endif /* ZANGBAND */
4292 Term_key_push(SPECIAL_KEY_QUIT);
4299 case WM_QUERYENDSESSION:
4301 if (game_in_progress && character_generated)
4303 /* Hack -- Forget messages */
4306 /* Mega-Hack -- Delay death */
4307 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4310 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "----¥²¡¼¥àÃæÃÇ----");
4312 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "---- Save and Exit Game ----");
4315 /* Hardcode panic save */
4316 p_ptr->panic_save = 1;
4318 /* Forbid suspend */
4319 signals_ignore_tstp();
4321 /* Indicate panic save */
4323 (void)strcpy(p_ptr->died_from, "(¶ÛµÞ¥»¡¼¥Ö)");
4325 (void)strcpy(p_ptr->died_from, "(panic save)");
4329 (void)save_player();
4343 process_menus(LOWORD(wParam));
4349 /* this message was sent before WM_NCCREATE */
4352 /* it was sent from inside CreateWindowEx */
4353 if (!td->w) return 1;
4355 /* was sent from WM_SIZE */
4356 if (td->size_hack) return 1;
4360 case SIZE_MINIMIZED:
4362 /* Hide sub-windows */
4363 for (i = 1; i < MAX_TERM_DATA; i++)
4365 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4370 case SIZE_MAXIMIZED:
4372 /* fall through XXX XXX XXX */
4377 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4378 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4381 if ((td->cols != cols) || (td->rows != rows))
4383 /* Save the new size */
4388 Term_activate(&td->t);
4390 /* Resize the term */
4391 Term_resize(td->cols, td->rows);
4394 InvalidateRect(td->w, NULL, TRUE);
4397 td->size_hack = TRUE;
4399 /* Show sub-windows */
4400 for (i = 1; i < MAX_TERM_DATA; i++)
4402 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4405 td->size_hack = FALSE;
4413 case WM_PALETTECHANGED:
4415 /* Ignore if palette change caused by itself */
4416 if ((HWND)wParam == hWnd) return 0;
4418 /* Fall through... */
4421 case WM_QUERYNEWPALETTE:
4423 if (!paletted) return 0;
4427 SelectPalette(hdc, hPal, FALSE);
4429 i = RealizePalette(hdc);
4431 /* if any palette entries changed, repaint the window. */
4432 if (i) InvalidateRect(hWnd, NULL, TRUE);
4434 ReleaseDC(hWnd, hdc);
4441 if (wParam && !HIWORD(lParam))
4443 /* Do something to sub-windows */
4444 for (i = 1; i < MAX_TERM_DATA; i++)
4446 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4449 /* Focus on main window */
4458 case WM_ACTIVATEAPP:
4460 for (i = 1; i < MAX_TERM_DATA; i++)
4466 ShowWindow(data[i].w, SW_SHOW);
4470 ShowWindow(data[i].w, SW_HIDE);
4477 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4482 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4483 WPARAM wParam, LPARAM lParam);
4484 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4485 WPARAM wParam, LPARAM lParam)
4486 #else /* __MWERKS__ */
4487 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4488 WPARAM wParam, LPARAM lParam)
4489 #endif /* __MWERKS__ */
4493 MINMAXINFO FAR *lpmmi;
4501 /* Acquire proper "term_data" info */
4502 td = (term_data *)GetWindowLong(hWnd, 0);
4504 /* Process message */
4510 SetWindowLong(hWnd, 0, (LONG)(my_td));
4520 case WM_GETMINMAXINFO:
4522 MINMAXINFO FAR *lpmmi;
4525 lpmmi = (MINMAXINFO FAR *)lParam;
4527 /* this message was sent before WM_NCCREATE */
4530 /* Minimum window size is 80x24 */
4531 rc.left = rc.top = 0;
4532 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4533 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4536 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4538 /* Save minimum size */
4539 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4540 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4550 /* this message was sent before WM_NCCREATE */
4553 /* it was sent from inside CreateWindowEx */
4554 if (!td->w) return 1;
4556 /* was sent from inside WM_SIZE */
4557 if (td->size_hack) return 1;
4559 td->size_hack = TRUE;
4561 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4562 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4565 if ((td->cols != cols) || (td->rows != rows))
4568 term *old_term = Term;
4570 /* Save the new size */
4575 Term_activate(&td->t);
4577 /* Resize the term */
4578 Term_resize(td->cols, td->rows);
4581 Term_activate(old_term);
4584 InvalidateRect(td->w, NULL, TRUE);
4586 /* HACK - Redraw all windows */
4587 p_ptr->window = 0xFFFFFFFF;
4591 td->size_hack = FALSE;
4598 BeginPaint(hWnd, &ps);
4599 if (td) term_data_redraw(td);
4600 EndPaint(hWnd, &ps);
4607 if (process_keydown(wParam, lParam))
4614 if (Term_no_press) Term_no_press = FALSE;
4615 else Term_keypress(wParam);
4619 case WM_PALETTECHANGED:
4621 /* ignore if palette change caused by itself */
4622 if ((HWND)wParam == hWnd) return FALSE;
4623 /* otherwise, fall through!!! */
4626 case WM_QUERYNEWPALETTE:
4628 if (!paletted) return 0;
4630 SelectPalette(hdc, hPal, FALSE);
4631 i = RealizePalette(hdc);
4632 /* if any palette entries changed, repaint the window. */
4633 if (i) InvalidateRect(hWnd, NULL, TRUE);
4634 ReleaseDC(hWnd, hdc);
4638 case WM_NCLBUTTONDOWN:
4642 if (wParam == HTCLOSE) wParam = HTSYSMENU;
4643 #endif /* HTCLOSE */
4645 if (wParam == HTSYSMENU)
4649 td->visible = FALSE;
4650 ShowWindow(td->w, SW_HIDE);
4660 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4666 #define MOUSE_SENS 40
4669 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4670 WPARAM wParam, LPARAM lParam);
4671 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4672 WPARAM wParam, LPARAM lParam)
4673 #else /* __MWERKS__ */
4674 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4675 WPARAM wParam, LPARAM lParam)
4676 #endif /* __MWERKS__ */
4678 static int iMouse = 0;
4679 static WORD xMouse = 0;
4680 static WORD yMouse = 0;
4703 if (LOWORD(wParam) == WA_INACTIVE) break;
4705 /* else fall through */
4709 case WM_LBUTTONDOWN:
4710 case WM_MBUTTONDOWN:
4711 case WM_RBUTTONDOWN:
4714 SendMessage(hWnd, WM_CLOSE, 0, 0);
4722 dx = LOWORD(lParam) - xMouse;
4723 dy = HIWORD(lParam) - yMouse;
4725 if (dx < 0) dx = -dx;
4726 if (dy < 0) dy = -dy;
4728 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
4730 SendMessage(hWnd, WM_CLOSE, 0, 0);
4734 /* Save last location */
4736 xMouse = LOWORD(lParam);
4737 yMouse = HIWORD(lParam);
4744 DestroyWindow(hwndSaver);
4751 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4754 #endif /* USE_SAVER */
4760 /*** Temporary Hooks ***/
4764 * Display warning message (see "z-util.c")
4766 static void hack_plog(cptr str)
4768 /* Give a warning */
4772 MessageBox(NULL, str, "·Ù¹ð¡ª",
4773 MB_ICONEXCLAMATION | MB_OK);
4775 MessageBox(NULL, str, "Warning",
4776 MB_ICONEXCLAMATION | MB_OK);
4784 * Display error message and quit (see "z-util.c")
4786 static void hack_quit(cptr str)
4788 /* Give a warning */
4792 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
4793 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4795 MessageBox(NULL, str, "Error",
4796 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4801 /* Unregister the classes */
4802 UnregisterClass(AppName, hInstance);
4804 /* Destroy the icon */
4805 if (hIcon) DestroyIcon(hIcon);
4813 /*** Various hooks ***/
4817 * Display warning message (see "z-util.c")
4819 static void hook_plog(cptr str)
4825 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
4826 MB_ICONEXCLAMATION | MB_OK);
4828 MessageBox(data[0].w, str, "Warning",
4829 MB_ICONEXCLAMATION | MB_OK);
4837 * Display error message and quit (see "z-util.c")
4839 static void hook_quit(cptr str)
4844 /* Give a warning */
4848 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
4849 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4851 MessageBox(data[0].w, str, "Error",
4852 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4858 /* Save the preferences */
4862 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
4864 /* Destroy all windows */
4865 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
4867 term_force_font(&data[i], NULL);
4868 if (data[i].font_want) string_free(data[i].font_want);
4869 if (data[i].w) DestroyWindow(data[i].w);
4873 /* Free the bitmap stuff */
4875 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
4876 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
4878 if (infMask.hPalette) DeleteObject(infMask.hPalette);
4879 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
4881 #endif /* USE_GRAPHICS */
4883 /*** Free some other stuff ***/
4885 DeleteObject(hbrYellow);
4890 if (hPal) DeleteObject(hPal);
4892 UnregisterClass(AppName, hInstance);
4894 if (hIcon) DestroyIcon(hIcon);
4901 /*** Initialize ***/
4907 static void init_stuff(void)
4914 /* Get program name with full path */
4915 GetModuleFileName(hInstance, path, 512);
4917 /* Save the "program name" XXX XXX XXX */
4920 /* Get the name of the "*.ini" file */
4921 strcpy(path + strlen(path) - 4, ".INI");
4923 /* Save the the name of the ini-file */
4924 ini_file = string_make(path);
4926 /* Analyze the path */
4932 if (path[i] == '\\')
4939 /* Add "lib" to the path */
4940 strcpy(path + i + 1, "lib\\");
4942 /* Validate the path */
4943 validate_dir(path, TRUE);
4945 /* Init the file paths */
4946 init_file_paths(path);
4948 /* Hack -- Validate the paths */
4949 validate_dir(ANGBAND_DIR_APEX, FALSE);
4950 validate_dir(ANGBAND_DIR_BONE, FALSE);
4952 /* Allow missing 'edit' directory */
4953 if (!check_dir(ANGBAND_DIR_EDIT))
4955 /* Must have 'data'! */
4956 validate_dir(ANGBAND_DIR_DATA, TRUE);
4960 /* Don't need 'data' */
4961 validate_dir(ANGBAND_DIR_DATA, FALSE);
4964 validate_dir(ANGBAND_DIR_FILE, TRUE);
4965 validate_dir(ANGBAND_DIR_HELP, FALSE);
4966 validate_dir(ANGBAND_DIR_INFO, FALSE);
4967 validate_dir(ANGBAND_DIR_PREF, TRUE);
4968 validate_dir(ANGBAND_DIR_SAVE, FALSE);
4969 validate_dir(ANGBAND_DIR_USER, TRUE);
4970 validate_dir(ANGBAND_DIR_XTRA, TRUE);
4972 /* Build the filename */
4974 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
4976 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
4980 /* Hack -- Validate the "news.txt" file */
4981 validate_file(path);
4985 /* Build the "font" path */
4986 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
4988 /* Allocate the path */
4989 ANGBAND_DIR_XTRA_FONT = string_make(path);
4991 /* Validate the "font" directory */
4992 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
4994 /* Build the filename */
4995 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
4997 /* Hack -- Validate the basic font */
4998 validate_file(path);
5004 /* Build the "graf" path */
5005 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5007 /* Allocate the path */
5008 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5010 /* Validate the "graf" directory */
5011 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5013 #endif /* USE_GRAPHICS */
5018 /* Build the "sound" path */
5019 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5021 /* Allocate the path */
5022 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5024 /* Validate the "sound" directory */
5025 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5027 #endif /* USE_SOUND */
5031 /* Build the "music" path */
5032 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5034 /* Allocate the path */
5035 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5037 /* Validate the "music" directory */
5038 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5040 #endif /* USE_MUSIC */
5042 /* Build the "help" path */
5043 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5045 /* Allocate the path */
5046 ANGBAND_DIR_XTRA_HELP = string_make(path);
5048 /* Validate the "help" directory */
5049 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5053 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5054 LPSTR lpCmdLine, int nCmdShow)
5069 if (hPrevInst == NULL)
5071 wc.style = CS_CLASSDC;
5072 wc.lpfnWndProc = AngbandWndProc;
5074 wc.cbWndExtra = 4; /* one long pointer to term_data */
5075 wc.hInstance = hInst;
5076 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5077 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5078 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5079 wc.lpszMenuName = AppName;
5080 wc.lpszClassName = AppName;
5082 if (!RegisterClass(&wc)) exit(1);
5084 wc.lpfnWndProc = AngbandListProc;
5085 wc.lpszMenuName = NULL;
5086 wc.lpszClassName = AngList;
5088 if (!RegisterClass(&wc)) exit(2);
5092 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5093 wc.lpfnWndProc = AngbandSaverProc;
5095 wc.lpszMenuName = NULL;
5096 wc.lpszClassName = "WindowsScreenSaverClass";
5098 if (!RegisterClass(&wc)) exit(3);
5104 /* Temporary hooks */
5105 plog_aux = hack_plog;
5106 quit_aux = hack_quit;
5107 core_aux = hack_quit;
5109 /* Prepare the filepaths */
5112 /* Initialize the keypress analyzer */
5113 for (i = 0; special_key_list[i]; ++i)
5115 special_key[special_key_list[i]] = TRUE;
5117 /* Initialize the keypress analyzer */
5118 for (i = 0; ignore_key_list[i]; ++i)
5120 ignore_key[ignore_key_list[i]] = TRUE;
5123 /* Determine if display is 16/256/true color */
5125 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5126 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5127 ReleaseDC(NULL, hdc);
5129 /* Initialize the colors */
5130 for (i = 0; i < 256; i++)
5134 /* Extract desired values */
5135 rv = angband_color_table[i][1];
5136 gv = angband_color_table[i][2];
5137 bv = angband_color_table[i][3];
5139 /* Extract the "complex" code */
5140 win_clr[i] = PALETTERGB(rv, gv, bv);
5142 /* Save the "simple" code */
5143 angband_color_table[i][0] = win_pal[i];
5146 /* Prepare the windows */
5152 /* Activate hooks */
5153 plog_aux = hook_plog;
5154 quit_aux = hook_quit;
5155 core_aux = hook_quit;
5157 /* Set the system suffix */
5158 ANGBAND_SYS = "win";
5160 /* Set the keyboard suffix */
5161 if (7 != GetKeyboardType(0))
5162 ANGBAND_KEYBOARD = "0";
5165 /* Japanese keyboard */
5166 switch (GetKeyboardType(1))
5168 case 0x0D01: case 0x0D02:
5169 case 0x0D03: case 0x0D04:
5170 case 0x0D05: case 0x0D06:
5172 ANGBAND_KEYBOARD = "NEC98";
5176 ANGBAND_KEYBOARD = "JAPAN";
5180 /* Catch nasty signals */
5186 /* We are now initialized */
5190 if(lpCmdLine[0] == '-'){
5191 switch(lpCmdLine[1])
5196 if (!lpCmdLine[2]) break;
5197 chuukei_server = TRUE;
5198 if(connect_chuukei_server(&lpCmdLine[2])<0){
5199 msg_print("connect fail");
5202 msg_print("connect");
5210 if (!lpCmdLine[2]) break;
5211 chuukei_client = TRUE;
5212 connect_chuukei_server(&lpCmdLine[2]);
5222 /* Did the user double click on a save file? */
5223 if(!chuukei_server) check_for_save_file(lpCmdLine);
5225 /* Did the user double click on a save file? */
5226 check_for_save_file(lpCmdLine);
5229 /* Prompt the user */
5231 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5233 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5238 /* Process messages forever */
5239 while (GetMessage(&msg, NULL, 0, 0))
5241 TranslateMessage(&msg);
5242 DispatchMessage(&msg);
5253 #endif /* WINDOWS */