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;
503 #ifdef USE_TRANSPARENCY
506 * The global bitmap mask
508 static DIBINIT infMask;
510 #endif /* USE_TRANSPARENCY */
512 #endif /* USE_GRAPHICS */
518 * Flag set once "sound" has been initialized
520 static bool can_use_sound = FALSE;
525 * An array of sound file names
527 static cptr sound_file[SOUND_MAX][SAMPLE_MAX];
529 #endif /* USE_SOUND */
533 * Full path to ANGBAND.INI
535 static cptr ini_file = NULL;
538 * Name of application
540 static cptr AppName = "ANGBAND";
543 * Name of sub-window type
545 static cptr AngList = "AngList";
550 static cptr ANGBAND_DIR_XTRA_GRAF;
551 static cptr ANGBAND_DIR_XTRA_SOUND;
552 static cptr ANGBAND_DIR_XTRA_HELP;
554 static cptr ANGBAND_DIR_XTRA_FONT;
557 static cptr ANGBAND_DIR_XTRA_MUSIC;
562 * The "complex" color values
564 static COLORREF win_clr[256];
568 * Flag for macro trigger with dump ASCII
570 static bool Term_no_press = FALSE;
574 * The "simple" color values
576 * See "main-ibm.c" for original table information
578 * The entries below are taken from the "color bits" defined above.
580 * Note that many of the choices below suck, but so do crappy monitors.
582 static BYTE win_pal[256] =
584 VID_BLACK, /* Dark */
585 VID_WHITE, /* White */
586 VID_CYAN, /* Slate XXX */
587 VID_RED | VID_BRIGHT, /* Orange XXX */
589 VID_GREEN, /* Green */
591 VID_YELLOW, /* Umber XXX */
592 VID_BLACK | VID_BRIGHT, /* Light Dark */
593 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
594 VID_MAGENTA, /* Violet XXX */
595 VID_YELLOW | VID_BRIGHT, /* Yellow */
596 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
597 VID_GREEN | VID_BRIGHT, /* Light Green */
598 VID_BLUE | VID_BRIGHT, /* Light Blue */
599 VID_YELLOW /* Light Umber XXX */
604 * Hack -- define which keys are "special"
606 static bool special_key[256];
607 static bool ignore_key[256];
611 * Hack -- initialization list for "special_key"
613 static byte special_key_list[] = {
614 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
615 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
616 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
617 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
618 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
619 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
620 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
621 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
622 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
623 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
624 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
625 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
626 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
627 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
628 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
629 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
630 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
635 static byte ignore_key_list[] = {
636 VK_ESCAPE, VK_TAB, VK_SPACE,
637 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
638 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
639 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
645 * Hack -- initialization list for "special_key"
647 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
648 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
649 * catch the keypad keys (with and without numlock set, including keypad 5),
650 * the function keys (including the "menu" key which maps to F10), and the
651 * "pause" key (between scroll lock and numlock). We also catch a few odd
652 * keys which I do not recognize, but which are listed among keys which we
653 * do catch, so they should be harmless to catch.
655 static byte special_key_list[] =
657 VK_CLEAR, /* 0x0C (KP<5>) */
659 VK_PAUSE, /* 0x13 (pause) */
661 VK_PRIOR, /* 0x21 (KP<9>) */
662 VK_NEXT, /* 0x22 (KP<3>) */
663 VK_END, /* 0x23 (KP<1>) */
664 VK_HOME, /* 0x24 (KP<7>) */
665 VK_LEFT, /* 0x25 (KP<4>) */
666 VK_UP, /* 0x26 (KP<8>) */
667 VK_RIGHT, /* 0x27 (KP<6>) */
668 VK_DOWN, /* 0x28 (KP<2>) */
669 VK_SELECT, /* 0x29 (?????) */
670 VK_PRINT, /* 0x2A (?????) */
671 VK_EXECUTE, /* 0x2B (?????) */
672 VK_SNAPSHOT, /* 0x2C (?????) */
673 VK_INSERT, /* 0x2D (KP<0>) */
674 VK_DELETE, /* 0x2E (KP<.>) */
675 VK_HELP, /* 0x2F (?????) */
677 VK_NUMPAD0, /* 0x60 (KP<0>) */
678 VK_NUMPAD1, /* 0x61 (KP<1>) */
679 VK_NUMPAD2, /* 0x62 (KP<2>) */
680 VK_NUMPAD3, /* 0x63 (KP<3>) */
681 VK_NUMPAD4, /* 0x64 (KP<4>) */
682 VK_NUMPAD5, /* 0x65 (KP<5>) */
683 VK_NUMPAD6, /* 0x66 (KP<6>) */
684 VK_NUMPAD7, /* 0x67 (KP<7>) */
685 VK_NUMPAD8, /* 0x68 (KP<8>) */
686 VK_NUMPAD9, /* 0x69 (KP<9>) */
687 VK_MULTIPLY, /* 0x6A (KP<*>) */
688 VK_ADD, /* 0x6B (KP<+>) */
689 VK_SEPARATOR, /* 0x6C (?????) */
690 VK_SUBTRACT, /* 0x6D (KP<->) */
691 VK_DECIMAL, /* 0x6E (KP<.>) */
692 VK_DIVIDE, /* 0x6F (KP</>) */
723 static void delete_bg(void)
732 static int init_bg(void)
734 char * bmfile = bg_bitmap_file;
737 if (use_bg == 0) return 0;
739 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
741 plog_fmt("ÊÉ»æÍÑ¥Ó¥Ã¥È¥Þ¥Ã¥× '%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);
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 #ifdef USE_TRANSPARENCY
1557 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1559 /* Access the mask file */
1560 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1562 /* Load the bitmap or quit */
1563 if (!ReadDIB(data[0].w, buf, &infMask))
1565 plog_fmt("Cannot read bitmap file '%s'", buf);
1570 #endif /* USE_TRANSPARENCY */
1572 /* Activate a palette */
1575 /* Free bitmap XXX XXX XXX */
1579 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1581 plog("Cannot activate palette!");
1587 /* Graphics available */
1588 can_use_graphics = arg_graphics;
1592 return (can_use_graphics);
1594 #endif /* USE_GRAPHICS */
1601 static bool init_sound(void)
1603 /* Initialize once */
1606 /* Load the prefs */
1609 /* Sound available */
1610 can_use_sound = TRUE;
1614 return (can_use_sound);
1616 #endif /* USE_SOUND */
1622 static void term_window_resize(term_data *td)
1624 /* Require window */
1627 /* Resize the window */
1628 SetWindowPos(td->w, 0, 0, 0,
1629 td->size_wid, td->size_hgt,
1630 SWP_NOMOVE | SWP_NOZORDER);
1633 InvalidateRect(td->w, NULL, TRUE);
1638 * Force the use of a new "font file" for a term_data
1640 * This function may be called before the "window" is ready
1642 * This function returns zero only if everything succeeds.
1644 * Note that the "font name" must be capitalized!!!
1646 static errr term_force_font(term_data *td, cptr path)
1656 /* Forget the old font (if needed) */
1657 if (td->font_id) DeleteObject(td->font_id);
1663 /* Create the font (using the 'base' of the font file name!) */
1664 td->font_id = CreateFontIndirect(&(td->lf));
1665 wid = td->lf.lfWidth;
1666 hgt = td->lf.lfHeight;
1667 if (!td->font_id) return (1);
1669 /* Forget old font */
1675 for (i = 0; i < MAX_TERM_DATA; i++)
1677 /* Don't check when closing the application */
1680 /* Check "screen" */
1681 if ((td != &data[i]) &&
1682 (data[i].font_file) &&
1683 (streq(data[i].font_file, td->font_file)))
1689 /* Remove unused font resources */
1690 if (!used) RemoveFontResource(td->font_file);
1692 /* Free the old name */
1693 string_free(td->font_file);
1696 td->font_file = NULL;
1700 if (!path) return (1);
1705 /* Analyze font path */
1706 base = analyze_font(buf, &wid, &hgt);
1709 if (!suffix(base, ".FON")) return (1);
1712 if (!check_file(buf)) return (1);
1714 /* Load the new font */
1715 if (!AddFontResource(buf)) return (1);
1717 /* Save new font name */
1718 td->font_file = string_make(base);
1720 /* Remove the "suffix" */
1721 base[strlen(base)-4] = '\0';
1723 /* Create the font (using the 'base' of the font file name!) */
1724 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1725 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1726 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1727 FIXED_PITCH | FF_DONTCARE, base);
1730 /* Hack -- Unknown size */
1737 /* all this trouble to get the cell size */
1738 hdcDesktop = GetDC(HWND_DESKTOP);
1739 hfOld = SelectObject(hdcDesktop, td->font_id);
1740 GetTextMetrics(hdcDesktop, &tm);
1741 SelectObject(hdcDesktop, hfOld);
1742 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1744 /* Font size info */
1745 wid = tm.tmAveCharWidth;
1749 /* Save the size info */
1760 * Allow the user to change the font for this window.
1762 static void term_change_font(term_data *td)
1767 memset(&cf, 0, sizeof(cf));
1768 cf.lStructSize = sizeof(cf);
1769 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1770 cf.lpLogFont = &(td->lf);
1772 if (ChooseFont(&cf))
1774 /* Force the font */
1775 term_force_font(td, NULL);
1777 /* Assume not bizarre */
1780 /* Reset the tile info */
1781 td->tile_wid = td->font_wid;
1782 td->tile_hgt = td->font_hgt;
1784 /* Analyze the font */
1787 /* Resize the window */
1788 term_window_resize(td);
1794 char tmp[1024] = "";
1796 /* Extract a default if possible */
1797 if (td->font_file) strcpy(tmp, td->font_file);
1799 /* Ask for a choice */
1800 memset(&ofn, 0, sizeof(ofn));
1801 ofn.lStructSize = sizeof(ofn);
1802 ofn.hwndOwner = data[0].w;
1803 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1804 ofn.nFilterIndex = 1;
1805 ofn.lpstrFile = tmp;
1807 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1808 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1809 ofn.lpstrDefExt = "fon";
1811 /* Force choice if legal */
1812 if (GetOpenFileName(&ofn))
1814 /* Force the font */
1815 if (term_force_font(td, tmp))
1817 /* Access the standard font file */
1818 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1820 /* Force the use of that font */
1821 (void)term_force_font(td, tmp);
1824 /* Assume not bizarre */
1825 td->bizarre = FALSE;
1827 /* Reset the tile info */
1828 td->tile_wid = td->font_wid;
1829 td->tile_hgt = td->font_hgt;
1831 /* Analyze the font */
1834 /* Resize the window */
1835 term_window_resize(td);
1842 * Allow the user to lock this window.
1844 static void term_window_pos(term_data *td, HWND hWnd)
1846 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1847 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1850 static void windows_map(void);
1853 * Hack -- redraw a term_data
1855 static void term_data_redraw(term_data *td)
1859 /* Redraw the map */
1864 /* Activate the term */
1865 Term_activate(&td->t);
1867 /* Redraw the contents */
1870 /* Restore the term */
1871 Term_activate(term_screen);
1879 /*** Function hooks needed by "Term" ***/
1885 * Initialize a new Term
1887 static void Term_init_win(term *t)
1896 static void Term_nuke_win(term *t)
1905 * Interact with the User
1907 static errr Term_user_win(int n)
1918 * React to global changes
1920 static errr Term_xtra_win_react(void)
1928 /* Save the default colors */
1929 for (i = 0; i < 256; i++)
1931 /* Simply accept the desired colors */
1932 win_pal[i] = angband_color_table[i][0];
1943 bool change = FALSE;
1945 /* Save the default colors */
1946 for (i = 0; i < 256; i++)
1948 /* Extract desired values */
1949 rv = angband_color_table[i][1];
1950 gv = angband_color_table[i][2];
1951 bv = angband_color_table[i][3];
1953 /* Extract a full color code */
1954 code = PALETTERGB(rv, gv, bv);
1956 /* Activate changes */
1957 if (win_clr[i] != code)
1959 /* Note the change */
1962 /* Apply the desired color */
1967 /* Activate the palette if needed */
1968 if (change) (void)new_palette();
1974 /* Handle "arg_sound" */
1975 if (use_sound != arg_sound)
1977 /* Initialize (if needed) */
1978 if (arg_sound && !init_sound())
1982 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
1984 plog("Cannot initialize sound!");
1992 /* Change setting */
1993 use_sound = arg_sound;
2001 /* Handle "arg_graphics" */
2002 if (use_graphics != arg_graphics)
2004 /* Initialize (if needed) */
2005 if (arg_graphics && !init_graphics())
2009 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
2011 plog("Cannot initialize graphics!");
2016 arg_graphics = GRAPHICS_NONE;
2019 /* Change setting */
2020 use_graphics = arg_graphics;
2023 #ifdef ANGBAND_2_8_1
2025 #else /* ANGBAND_2_8_1 */
2026 reset_visuals(TRUE);
2027 #endif /* ANGBAND_2_8_1 */
2030 #endif /* USE_GRAPHICS */
2033 /* Clean up windows */
2034 for (i = 0; i < MAX_TERM_DATA; i++)
2038 term_data *td = &data[i];
2040 /* Update resized windows */
2041 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2044 Term_activate(&td->t);
2046 /* Hack -- Resize the term */
2047 Term_resize(td->cols, td->rows);
2049 /* Redraw the contents */
2064 * Process at least one event
2066 static errr Term_xtra_win_event(int v)
2070 /* Wait for an event */
2074 if (GetMessage(&msg, NULL, 0, 0))
2076 TranslateMessage(&msg);
2077 DispatchMessage(&msg);
2081 /* Check for an event */
2085 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2087 TranslateMessage(&msg);
2088 DispatchMessage(&msg);
2098 * Process all pending events
2100 static errr Term_xtra_win_flush(void)
2104 /* Process all pending events */
2105 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2107 TranslateMessage(&msg);
2108 DispatchMessage(&msg);
2117 * Hack -- clear the screen
2119 * Make this more efficient XXX XXX XXX
2121 static errr Term_xtra_win_clear(void)
2123 term_data *td = (term_data*)(Term->data);
2128 /* Rectangle to erase */
2129 rc.left = td->size_ow1;
2130 rc.right = rc.left + td->cols * td->tile_wid;
2131 rc.top = td->size_oh1;
2132 rc.bottom = rc.top + td->rows * td->tile_hgt;
2136 SetBkColor(hdc, RGB(0, 0, 0));
2137 SelectObject(hdc, td->font_id);
2138 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2143 rc.left = 0; rc.top = 0;
2146 ReleaseDC(td->w, hdc);
2154 * Hack -- make a noise
2156 static errr Term_xtra_win_noise(void)
2158 MessageBeep(MB_ICONASTERISK);
2164 * Hack -- make a sound
2166 static errr Term_xtra_win_sound(int v)
2171 #endif /* USE_SOUND */
2173 /* Sound disabled */
2174 if (!use_sound) return (1);
2177 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2181 /* Count the samples */
2182 for (i = 0; i < SAMPLE_MAX; i++)
2184 if (!sound_file[v][i])
2189 if (i == 0) return (1);
2191 /* Build the path */
2192 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_simple(i)]);
2196 /* Play the sound, catch errors */
2197 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2201 /* Play the sound, catch errors */
2202 return (sndPlaySound(buf, SND_ASYNC));
2206 #else /* USE_SOUND */
2211 #endif /* USE_SOUND */
2216 * Delay for "x" milliseconds
2218 static int Term_xtra_win_delay(int v)
2232 t = GetTickCount() + v;
2235 while (GetTickCount() < t)
2237 /* Handle messages */
2238 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2240 TranslateMessage(&msg);
2241 DispatchMessage(&msg);
2253 * Do a "special thing"
2255 static errr Term_xtra_win(int n, int v)
2257 /* Handle a subset of the legal requests */
2260 /* Make a bell sound */
2261 case TERM_XTRA_NOISE:
2263 return (Term_xtra_win_noise());
2266 /* Make a special sound */
2267 case TERM_XTRA_SOUND:
2269 return (Term_xtra_win_sound(v));
2272 /* Process random events */
2273 case TERM_XTRA_BORED:
2275 return (Term_xtra_win_event(0));
2278 /* Process an event */
2279 case TERM_XTRA_EVENT:
2281 return (Term_xtra_win_event(v));
2284 /* Flush all events */
2285 case TERM_XTRA_FLUSH:
2287 return (Term_xtra_win_flush());
2290 /* Clear the screen */
2291 case TERM_XTRA_CLEAR:
2293 return (Term_xtra_win_clear());
2296 /* React to global changes */
2297 case TERM_XTRA_REACT:
2299 return (Term_xtra_win_react());
2302 /* Delay for some milliseconds */
2303 case TERM_XTRA_DELAY:
2305 return (Term_xtra_win_delay(v));
2316 * Low level graphics (Assumes valid input).
2318 * Draw a "cursor" at (x,y), using a "yellow box".
2320 static errr Term_curs_win(int x, int y)
2322 term_data *td = (term_data*)(Term->data);
2327 int tile_wid, tile_hgt;
2331 tile_wid = td->map_tile_wid;
2332 tile_hgt = td->map_tile_hgt;
2336 tile_wid = td->tile_wid;
2337 tile_hgt = td->tile_hgt;
2340 /* Frame the grid */
2341 rc.left = x * tile_wid + td->size_ow1;
2342 rc.right = rc.left + tile_wid;
2343 rc.top = y * tile_hgt + td->size_oh1;
2344 rc.bottom = rc.top + tile_hgt;
2346 /* Cursor is done as a yellow "box" */
2348 FrameRect(hdc, &rc, hbrYellow);
2349 ReleaseDC(td->w, hdc);
2357 * Low level graphics (Assumes valid input).
2359 * Draw a "big cursor" at (x,y), using a "yellow box".
2361 static errr Term_bigcurs_win(int x, int y)
2363 term_data *td = (term_data*)(Term->data);
2368 int tile_wid, tile_hgt;
2372 /* Normal cursor in map window */
2373 Term_curs_win(x, y);
2378 tile_wid = td->tile_wid;
2379 tile_hgt = td->tile_hgt;
2382 /* Frame the grid */
2383 rc.left = x * tile_wid + td->size_ow1;
2384 rc.right = rc.left + 2 * tile_wid;
2385 rc.top = y * tile_hgt + td->size_oh1;
2386 rc.bottom = rc.top + tile_hgt;
2388 /* Cursor is done as a yellow "box" */
2390 FrameRect(hdc, &rc, hbrYellow);
2391 ReleaseDC(td->w, hdc);
2399 * Low level graphics (Assumes valid input).
2401 * Erase a "block" of "n" characters starting at (x,y).
2403 static errr Term_wipe_win(int x, int y, int n)
2405 term_data *td = (term_data*)(Term->data);
2410 /* Rectangle to erase in client coords */
2411 rc.left = x * td->tile_wid + td->size_ow1;
2412 rc.right = rc.left + n * td->tile_wid;
2413 rc.top = y * td->tile_hgt + td->size_oh1;
2414 rc.bottom = rc.top + td->tile_hgt;
2417 SetBkColor(hdc, RGB(0, 0, 0));
2418 SelectObject(hdc, td->font_id);
2423 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2424 ReleaseDC(td->w, hdc);
2432 * Low level graphics. Assumes valid input.
2434 * Draw several ("n") chars, with an attr, at a given location.
2436 * All "graphic" data is handled by "Term_pict_win()", below.
2438 * One would think there is a more efficient method for telling a window
2439 * what color it should be using to draw with, but perhaps simply changing
2440 * it every time is not too inefficient. XXX XXX XXX
2442 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2444 term_data *td = (term_data*)(Term->data);
2450 static HBITMAP WALL;
2451 static HBRUSH myBrush, oldBrush;
2453 static bool init_done = FALSE;
2456 WALL = LoadBitmap(hInstance, AppName);
2457 myBrush = CreatePatternBrush(WALL);
2462 /* Total rectangle */
2463 rc.left = x * td->tile_wid + td->size_ow1;
2464 rc.right = rc.left + n * td->tile_wid;
2465 rc.top = y * td->tile_hgt + td->size_oh1;
2466 rc.bottom = rc.top + td->tile_hgt;
2471 /* Background color */
2472 SetBkColor(hdc, RGB(0, 0, 0));
2474 /* Foreground color */
2477 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2481 SetTextColor(hdc, win_clr[a&0x0F]);
2485 SetTextColor(hdc, win_clr[a]);
2489 SelectObject(hdc, td->font_id);
2492 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2496 (td->tile_hgt != td->font_hgt) ||
2497 (td->tile_wid != td->font_wid))
2501 /* Erase complete rectangle */
2502 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2505 if (use_bg) DrawBG(hdc, &rc);
2508 rc.left += ((td->tile_wid - td->font_wid) / 2);
2509 rc.right = rc.left + td->font_wid;
2510 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2511 rc.bottom = rc.top + td->font_hgt;
2513 /* Dump each character */
2514 for (i = 0; i < n; i++)
2517 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2519 rc.right += td->font_wid;
2521 oldBrush = SelectObject(hdc, myBrush);
2522 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2525 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2527 SelectObject(hdc, oldBrush);
2528 SelectObject(hdc, oldPen);
2529 rc.right -= td->font_wid;
2533 rc.left += 2 * td->tile_wid;
2534 rc.right += 2 * td->tile_wid;
2536 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2538 rc.right += td->font_wid;
2540 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2542 rc.right -= td->font_wid;
2546 rc.left += 2 * td->tile_wid;
2547 rc.right += 2 * td->tile_wid;
2548 } else if (*(s+i)==127){
2549 oldBrush = SelectObject(hdc, myBrush);
2550 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2553 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2555 SelectObject(hdc, oldBrush);
2556 SelectObject(hdc, oldPen);
2559 rc.left += td->tile_wid;
2560 rc.right += td->tile_wid;
2563 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2567 rc.left += td->tile_wid;
2568 rc.right += td->tile_wid;
2572 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2576 rc.left += td->tile_wid;
2577 rc.right += td->tile_wid;
2587 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2592 ReleaseDC(td->w, hdc);
2600 * Low level graphics. Assumes valid input.
2602 * Draw an array of "special" attr/char pairs at the given location.
2604 * We use the "Term_pict_win()" function for "graphic" data, which are
2605 * encoded by setting the "high-bits" of both the "attr" and the "char"
2606 * data. We use the "attr" to represent the "row" of the main bitmap,
2607 * and the "char" to represent the "col" of the main bitmap. The use
2608 * of this function is induced by the "higher_pict" flag.
2610 * If "graphics" is not available, we simply "wipe" the given grids.
2612 # ifdef USE_TRANSPARENCY
2613 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2614 # else /* USE_TRANSPARENCY */
2615 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp)
2616 # endif /* USE_TRANSPARENCY */
2618 term_data *td = (term_data*)(Term->data);
2624 int x2, y2, w2, h2, tw2;
2626 # ifdef USE_TRANSPARENCY
2632 # endif /* USE_TRANSPARENCY */
2641 /* Erase the grids */
2642 return (Term_wipe_win(x, y, n));
2645 /* Size of bitmap cell */
2646 w1 = infGraph.CellWidth;
2647 h1 = infGraph.CellHeight;
2649 /* Size of window cell */
2652 w2 = td->map_tile_wid;
2653 h2 = td->map_tile_hgt;
2662 if (use_bigtile) tw2 *= 2;
2665 /* Location of window cell */
2666 x2 = x * w2 + td->size_ow1;
2667 y2 = y * h2 + td->size_oh1;
2673 hdcSrc = CreateCompatibleDC(hdc);
2674 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2676 # ifdef USE_TRANSPARENCY
2678 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2680 hdcMask = CreateCompatibleDC(hdc);
2681 SelectObject(hdcMask, infMask.hBitmap);
2684 # endif /* USE_TRANSPARENCY */
2686 /* Draw attr/char pairs */
2687 for (i = 0; i < n; i++, x2 += w2)
2692 /* Extract picture */
2693 int row = (a & 0x7F);
2694 int col = (c & 0x7F);
2696 /* Location of bitmap cell */
2700 # ifdef USE_TRANSPARENCY
2702 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2704 x3 = (tcp[i] & 0x7F) * w1;
2705 y3 = (tap[i] & 0x7F) * h1;
2708 if ((w1 == tw2) && (h1 == h2))
2710 /* Copy the terrain picture from the bitmap to the window */
2711 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2713 /* Mask out the tile */
2714 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2717 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2720 /* Need to stretch */
2723 /* Set the correct mode for stretching the tiles */
2724 SetStretchBltMode(hdc, COLORONCOLOR);
2726 /* Copy the terrain picture from the bitmap to the window */
2727 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
2729 /* Only draw if terrain and overlay are different */
2730 if ((x1 != x3) || (y1 != y3))
2732 /* Mask out the tile */
2733 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2736 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2742 # endif /* USE_TRANSPARENCY */
2746 if ((w1 == tw2) && (h1 == h2))
2748 /* Copy the picture from the bitmap to the window */
2749 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2752 /* Need to stretch */
2755 /* Set the correct mode for stretching the tiles */
2756 SetStretchBltMode(hdc, COLORONCOLOR);
2758 /* Copy the picture from the bitmap to the window */
2759 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2765 SelectObject(hdcSrc, hbmSrcOld);
2768 # ifdef USE_TRANSPARENCY
2770 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2773 SelectObject(hdcMask, hbmSrcOld);
2777 # endif /* USE_TRANSPARENCY */
2780 ReleaseDC(td->w, hdc);
2782 #else /* USE_GRAPHICS */
2784 /* Just erase this grid */
2785 return (Term_wipe_win(x, y, n));
2787 #endif /* USE_GRAPHICS */
2794 static void windows_map(void)
2796 term_data *td = &data[0];
2798 int x, min_x, max_x;
2799 int y, min_y, max_y;
2801 #ifdef USE_TRANSPARENCY
2805 /* Only in graphics mode */
2806 if (!use_graphics) return;
2809 Term_xtra_win_clear();
2811 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2812 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2813 td->map_active = TRUE;
2823 for (x = min_x; x < max_x; x++)
2825 for (y = min_y; y < max_y; y++)
2827 #ifdef USE_TRANSPARENCY
2828 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
2829 #else /* USE_TRANSPARENCY */
2830 map_info(y, x, &a, (char*)&c);
2831 #endif /* USE_TRANSPARENCY */
2833 /* Ignore non-graphics */
2834 if ((a & 0x80) && (c & 0x80))
2836 #ifdef USE_TRANSPARENCY
2837 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2838 #else /* USE_TRANSPARENCY */
2839 Term_pict_win(x - min_x, y - min_y, 1, &a, &c);
2840 #endif /* USE_TRANSPARENCY */
2845 /* Hilite the player */
2846 Term_curs_win(px - min_x, py - min_y);
2848 /* Wait for a keypress, flush key buffer */
2849 Term_inkey(&c, TRUE, TRUE);
2852 /* Switch off the map display */
2853 td->map_active = FALSE;
2855 /* Restore screen */
2856 Term_xtra_win_clear();
2861 /*** Other routines ***/
2865 * Create and initialize a "term_data" given a title
2867 static void term_data_link(term_data *td)
2871 /* Initialize the term */
2872 term_init(t, td->cols, td->rows, td->keys);
2874 /* Use a "software" cursor */
2875 t->soft_cursor = TRUE;
2877 /* Use "Term_pict" for "graphic" data */
2878 t->higher_pict = TRUE;
2880 /* Erase with "white space" */
2881 t->attr_blank = TERM_WHITE;
2882 t->char_blank = ' ';
2885 /* Prepare the init/nuke hooks */
2886 t->init_hook = Term_init_win;
2887 t->nuke_hook = Term_nuke_win;
2890 /* Prepare the template hooks */
2891 t->user_hook = Term_user_win;
2892 t->xtra_hook = Term_xtra_win;
2893 t->curs_hook = Term_curs_win;
2894 t->bigcurs_hook = Term_bigcurs_win;
2895 t->wipe_hook = Term_wipe_win;
2896 t->text_hook = Term_text_win;
2897 t->pict_hook = Term_pict_win;
2899 /* Remember where we came from */
2900 t->data = (vptr)(td);
2905 * Create the windows
2907 * First, instantiate the "default" values, then read the "ini_file"
2908 * to over-ride selected values, then create the windows, and fonts.
2910 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2911 * must make active to realize the palette. XXX XXX XXX
2913 static void init_windows(void)
2925 WIPE(td, term_data);
2929 td->s = angband_term_name[0];
2948 for (i = 1; i < MAX_TERM_DATA; i++)
2951 WIPE(td, term_data);
2952 td->s = angband_term_name[i];
2956 td->visible = FALSE;
2961 td->pos_x = (7 - i) * 30;
2962 td->pos_y = (7 - i) * 20;
2974 /* Main window (need these before term_getsize gets called) */
2976 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2977 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2982 /* Sub windows (need these before term_getsize gets called) */
2983 for (i = 1; i < MAX_TERM_DATA; i++)
2986 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2987 td->dwExStyle = (WS_EX_TOOLWINDOW);
2992 for (i = 0; i < MAX_TERM_DATA; i++)
2997 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2998 td->lf.lfCharSet = SHIFTJIS_CHARSET;
2999 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3000 /* Activate the chosen font */
3001 term_force_font(td, NULL);
3002 td->tile_wid = td->font_wid;
3003 td->tile_hgt = td->font_hgt;
3005 /* Access the standard font file */
3006 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3008 /* Activate the chosen font */
3009 if (term_force_font(td, buf))
3011 /* Access the standard font file */
3012 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3014 /* Force the use of that font */
3015 (void)term_force_font(td, buf);
3021 /* Assume not bizarre */
3022 td->bizarre = FALSE;
3027 /* Analyze the font */
3030 /* Resize the window */
3031 term_window_resize(td);
3035 /* Sub windows (reverse order) */
3036 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3041 td->w = CreateWindowEx(td->dwExStyle, AngList,
3043 td->pos_x, td->pos_y,
3044 td->size_wid, td->size_hgt,
3045 HWND_DESKTOP, NULL, hInstance, NULL);
3048 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3050 if (!td->w) quit("Failed to create sub-window");
3056 td->size_hack = TRUE;
3057 ShowWindow(td->w, SW_SHOW);
3058 td->size_hack = FALSE;
3062 angband_term[i] = &td->t;
3066 /* Activate the window */
3067 SetActiveWindow(td->w);
3072 term_window_pos(&data[i], HWND_TOPMOST);
3076 term_window_pos(&data[i], td->w);
3086 td->w = CreateWindowEx(td->dwExStyle, AppName,
3088 td->pos_x, td->pos_y,
3089 td->size_wid, td->size_hgt,
3090 HWND_DESKTOP, NULL, hInstance, NULL);
3093 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3095 if (!td->w) quit("Failed to create Angband window");
3100 angband_term[0] = &td->t;
3102 /* Activate the main window */
3103 SetActiveWindow(td->w);
3105 /* Bring main window back to top */
3106 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3109 /* New palette XXX XXX XXX */
3110 (void)new_palette();
3113 /* Create a "brush" for drawing the "cursor" */
3114 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3117 /* Process pending messages */
3118 (void)Term_xtra_win_flush();
3126 static void setup_menus(void)
3130 HMENU hm = GetMenu(data[0].w);
3133 /* Menu "File", Disable all */
3134 EnableMenuItem(hm, IDM_FILE_NEW,
3135 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3136 EnableMenuItem(hm, IDM_FILE_OPEN,
3137 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3138 EnableMenuItem(hm, IDM_FILE_SAVE,
3139 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3140 EnableMenuItem(hm, IDM_FILE_EXIT,
3141 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3142 EnableMenuItem(hm, IDM_FILE_SCORE,
3143 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3146 /* No character available */
3147 if (!character_generated)
3149 /* Menu "File", Item "New" */
3150 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3152 /* Menu "File", Item "Open" */
3153 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3156 /* A character available */
3157 if (character_generated)
3159 /* Menu "File", Item "Save" */
3160 EnableMenuItem(hm, IDM_FILE_SAVE,
3161 MF_BYCOMMAND | MF_ENABLED);
3164 /* Menu "File", Item "Exit" */
3165 EnableMenuItem(hm, IDM_FILE_EXIT,
3166 MF_BYCOMMAND | MF_ENABLED);
3168 EnableMenuItem(hm, IDM_FILE_SCORE,
3169 MF_BYCOMMAND | MF_ENABLED);
3172 /* Menu "Window::Visibility" */
3173 for (i = 0; i < MAX_TERM_DATA; i++)
3175 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3176 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3178 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3179 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3181 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3182 MF_BYCOMMAND | MF_ENABLED);
3185 /* Menu "Window::Font" */
3186 for (i = 0; i < MAX_TERM_DATA; i++)
3188 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3189 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3191 if (data[i].visible)
3193 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3194 MF_BYCOMMAND | MF_ENABLED);
3198 /* Menu "Window::Window Position Fix" */
3199 for (i = 0; i < MAX_TERM_DATA; i++)
3201 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3202 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3204 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3205 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3207 if (data[i].visible)
3209 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3210 MF_BYCOMMAND | MF_ENABLED);
3214 /* Menu "Window::Bizarre Display" */
3215 for (i = 0; i < MAX_TERM_DATA; i++)
3217 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3218 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3220 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3221 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3223 if (data[i].visible)
3225 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3226 MF_BYCOMMAND | MF_ENABLED);
3231 /* Menu "Window::Increase Tile Width" */
3232 for (i = 0; i < MAX_TERM_DATA; i++)
3234 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3235 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3237 if (data[i].visible)
3239 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3240 MF_BYCOMMAND | MF_ENABLED);
3245 /* Menu "Window::Decrease Tile Width" */
3246 for (i = 0; i < MAX_TERM_DATA; i++)
3248 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3249 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3251 if (data[i].visible)
3253 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3254 MF_BYCOMMAND | MF_ENABLED);
3259 /* Menu "Window::Increase Tile Height" */
3260 for (i = 0; i < MAX_TERM_DATA; i++)
3262 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3263 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3265 if (data[i].visible)
3267 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3268 MF_BYCOMMAND | MF_ENABLED);
3273 /* Menu "Window::Decrease Tile Height" */
3274 for (i = 0; i < MAX_TERM_DATA; i++)
3276 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3277 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3279 if (data[i].visible)
3281 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3282 MF_BYCOMMAND | MF_ENABLED);
3287 /* Menu "Options", disable all */
3288 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3289 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3290 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3291 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3292 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3293 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3294 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3295 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3296 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3297 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3299 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3300 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3303 /* Menu "Options", Item "Map" */
3304 if (use_graphics != GRAPHICS_NONE)
3305 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3307 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3308 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3310 /* Menu "Options", update all */
3311 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3312 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3313 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3314 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3315 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3316 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3317 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3318 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3319 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3320 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3321 CheckMenuItem(hm, IDM_OPTIONS_BG,
3322 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3324 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3325 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3329 /* Menu "Options", Item "Graphics" */
3330 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3331 /* Menu "Options", Item "Graphics" */
3332 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3333 /* Menu "Options", Item "Graphics" */
3334 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3335 /* Menu "Options", Item "Graphics" */
3336 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3337 #endif /* USE_GRAPHICS */
3340 /* Menu "Options", Item "Sound" */
3341 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3342 #endif /* USE_SOUND */
3345 /* Menu "Options", Item "ScreenSaver" */
3346 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3347 MF_BYCOMMAND | MF_ENABLED);
3348 #endif /* USE_SAVER */
3353 * Check for double clicked (or dragged) savefile
3355 * Apparently, Windows copies the entire filename into the first
3356 * piece of the "command line string". Perhaps we should extract
3357 * the "basename" of that filename and append it to the "save" dir.
3359 static void check_for_save_file(LPSTR cmd_line)
3369 /* Extract filename */
3370 strcat(savefile, s);
3372 /* Validate the file */
3373 validate_file(savefile);
3375 /* Game in progress */
3376 game_in_progress = TRUE;
3384 * Process a menu command
3386 static void process_menus(WORD wCmd)
3403 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3405 plog("You cannot do that yet...");
3409 else if (game_in_progress)
3412 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3414 plog("You can't start a new game while you're still playing!");
3420 game_in_progress = TRUE;
3434 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3436 plog("You cannot do that yet...");
3440 else if (game_in_progress)
3443 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3445 plog("You can't open a new game while you're still playing!");
3451 memset(&ofn, 0, sizeof(ofn));
3452 ofn.lStructSize = sizeof(ofn);
3453 ofn.hwndOwner = data[0].w;
3454 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3455 ofn.nFilterIndex = 1;
3456 ofn.lpstrFile = savefile;
3457 ofn.nMaxFile = 1024;
3458 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3459 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3461 if (GetOpenFileName(&ofn))
3463 /* Load 'savefile' */
3464 validate_file(savefile);
3465 game_in_progress = TRUE;
3477 if (game_in_progress && character_generated)
3483 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3485 plog("You may not do that right now.");
3491 /* Hack -- Forget messages */
3496 do_cmd_save_game(FALSE);
3497 #else /* ZANGBAND */
3499 #endif /* ZANGBAND */
3504 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3506 plog("You may not do that right now.");
3516 if (game_in_progress && character_generated)
3522 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3524 plog("You may not do that right now.");
3530 /* Hack -- Forget messages */
3539 /* do_cmd_save_game(FALSE); */
3540 #else /* ZANGBAND */
3541 /* do_cmd_save_game(); */
3542 #endif /* ZANGBAND */
3543 Term_key_push(SPECIAL_KEY_QUIT);
3551 case IDM_FILE_SCORE:
3555 /* Build the filename */
3556 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3558 /* Open the binary high score file, for reading */
3559 highscore_fd = fd_open(buf, O_RDONLY);
3561 /* Paranoia -- No score file */
3562 if (highscore_fd < 0)
3564 msg_print("Score file unavailable.");
3574 /* Display the scores */
3575 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3577 /* Shut the high score file */
3578 (void)fd_close(highscore_fd);
3580 /* Forget the high score fd */
3586 /* Hack - Flush it */
3594 case IDM_WINDOW_VIS_0:
3597 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3599 plog("You are not allowed to do that!");
3606 /* Window visibility */
3607 case IDM_WINDOW_VIS_1:
3608 case IDM_WINDOW_VIS_2:
3609 case IDM_WINDOW_VIS_3:
3610 case IDM_WINDOW_VIS_4:
3611 case IDM_WINDOW_VIS_5:
3612 case IDM_WINDOW_VIS_6:
3613 case IDM_WINDOW_VIS_7:
3615 i = wCmd - IDM_WINDOW_VIS_0;
3617 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3624 ShowWindow(td->w, SW_SHOW);
3625 term_data_redraw(td);
3629 td->visible = FALSE;
3631 ShowWindow(td->w, SW_HIDE);
3638 case IDM_WINDOW_FONT_0:
3639 case IDM_WINDOW_FONT_1:
3640 case IDM_WINDOW_FONT_2:
3641 case IDM_WINDOW_FONT_3:
3642 case IDM_WINDOW_FONT_4:
3643 case IDM_WINDOW_FONT_5:
3644 case IDM_WINDOW_FONT_6:
3645 case IDM_WINDOW_FONT_7:
3647 i = wCmd - IDM_WINDOW_FONT_0;
3649 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3653 term_change_font(td);
3658 /* Window Z Position */
3659 case IDM_WINDOW_POS_1:
3660 case IDM_WINDOW_POS_2:
3661 case IDM_WINDOW_POS_3:
3662 case IDM_WINDOW_POS_4:
3663 case IDM_WINDOW_POS_5:
3664 case IDM_WINDOW_POS_6:
3665 case IDM_WINDOW_POS_7:
3667 i = wCmd - IDM_WINDOW_POS_0;
3669 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3673 if (!td->posfix && td->visible)
3676 term_window_pos(td, HWND_TOPMOST);
3681 term_window_pos(td, data[0].w);
3687 /* Bizarre Display */
3688 case IDM_WINDOW_BIZ_0:
3689 case IDM_WINDOW_BIZ_1:
3690 case IDM_WINDOW_BIZ_2:
3691 case IDM_WINDOW_BIZ_3:
3692 case IDM_WINDOW_BIZ_4:
3693 case IDM_WINDOW_BIZ_5:
3694 case IDM_WINDOW_BIZ_6:
3695 case IDM_WINDOW_BIZ_7:
3697 i = wCmd - IDM_WINDOW_BIZ_0;
3699 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3703 td->bizarre = !td->bizarre;
3707 term_window_resize(td);
3712 /* Increase Tile Width */
3713 case IDM_WINDOW_I_WID_0:
3714 case IDM_WINDOW_I_WID_1:
3715 case IDM_WINDOW_I_WID_2:
3716 case IDM_WINDOW_I_WID_3:
3717 case IDM_WINDOW_I_WID_4:
3718 case IDM_WINDOW_I_WID_5:
3719 case IDM_WINDOW_I_WID_6:
3720 case IDM_WINDOW_I_WID_7:
3722 i = wCmd - IDM_WINDOW_I_WID_0;
3724 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3732 term_window_resize(td);
3737 /* Decrease Tile Height */
3738 case IDM_WINDOW_D_WID_0:
3739 case IDM_WINDOW_D_WID_1:
3740 case IDM_WINDOW_D_WID_2:
3741 case IDM_WINDOW_D_WID_3:
3742 case IDM_WINDOW_D_WID_4:
3743 case IDM_WINDOW_D_WID_5:
3744 case IDM_WINDOW_D_WID_6:
3745 case IDM_WINDOW_D_WID_7:
3747 i = wCmd - IDM_WINDOW_D_WID_0;
3749 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3757 term_window_resize(td);
3762 /* Increase Tile Height */
3763 case IDM_WINDOW_I_HGT_0:
3764 case IDM_WINDOW_I_HGT_1:
3765 case IDM_WINDOW_I_HGT_2:
3766 case IDM_WINDOW_I_HGT_3:
3767 case IDM_WINDOW_I_HGT_4:
3768 case IDM_WINDOW_I_HGT_5:
3769 case IDM_WINDOW_I_HGT_6:
3770 case IDM_WINDOW_I_HGT_7:
3772 i = wCmd - IDM_WINDOW_I_HGT_0;
3774 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3782 term_window_resize(td);
3787 /* Decrease Tile Height */
3788 case IDM_WINDOW_D_HGT_0:
3789 case IDM_WINDOW_D_HGT_1:
3790 case IDM_WINDOW_D_HGT_2:
3791 case IDM_WINDOW_D_HGT_3:
3792 case IDM_WINDOW_D_HGT_4:
3793 case IDM_WINDOW_D_HGT_5:
3794 case IDM_WINDOW_D_HGT_6:
3795 case IDM_WINDOW_D_HGT_7:
3797 i = wCmd - IDM_WINDOW_D_HGT_0;
3799 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3807 term_window_resize(td);
3812 case IDM_OPTIONS_NO_GRAPHICS:
3817 plog("You may not do that right now.");
3821 /* Toggle "arg_graphics" */
3822 if (arg_graphics != GRAPHICS_NONE)
3824 arg_graphics = GRAPHICS_NONE;
3826 /* React to changes */
3827 Term_xtra_win_react();
3829 /* Hack -- Force redraw */
3830 Term_key_push(KTRL('R'));
3836 case IDM_OPTIONS_OLD_GRAPHICS:
3841 plog("You may not do that right now.");
3845 /* Toggle "arg_graphics" */
3846 if (arg_graphics != GRAPHICS_ORIGINAL)
3848 arg_graphics = GRAPHICS_ORIGINAL;
3850 /* React to changes */
3851 Term_xtra_win_react();
3853 /* Hack -- Force redraw */
3854 Term_key_push(KTRL('R'));
3860 case IDM_OPTIONS_NEW_GRAPHICS:
3865 plog("You may not do that right now.");
3869 /* Toggle "arg_graphics" */
3870 if (arg_graphics != GRAPHICS_ADAM_BOLT)
3872 arg_graphics = GRAPHICS_ADAM_BOLT;
3874 /* React to changes */
3875 Term_xtra_win_react();
3877 /* Hack -- Force redraw */
3878 Term_key_push(KTRL('R'));
3884 case IDM_OPTIONS_BIGTILE:
3886 term_data *td = &data[0];
3891 plog("You may not do that right now.");
3895 /* Toggle "arg_sound" */
3896 arg_bigtile = !arg_bigtile;
3899 Term_activate(&td->t);
3901 /* Resize the term */
3902 Term_resize(td->cols, td->rows);
3905 InvalidateRect(td->w, NULL, TRUE);
3910 case IDM_OPTIONS_SOUND:
3915 plog("You may not do that right now.");
3919 /* Toggle "arg_sound" */
3920 arg_sound = !arg_sound;
3922 /* React to changes */
3923 Term_xtra_win_react();
3925 /* Hack -- Force redraw */
3926 Term_key_push(KTRL('R'));
3932 case IDM_OPTIONS_BG:
3937 plog("You may not do that right now.");
3941 /* Toggle "use_bg" */
3946 /* React to changes */
3947 Term_xtra_win_react();
3949 /* Hack -- Force redraw */
3950 Term_key_push(KTRL('R'));
3956 case IDM_OPTIONS_OPEN_BG:
3961 plog("You may not do that right now.");
3966 memset(&ofn, 0, sizeof(ofn));
3967 ofn.lStructSize = sizeof(ofn);
3968 ofn.hwndOwner = data[0].w;
3969 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3970 ofn.nFilterIndex = 1;
3971 ofn.lpstrFile = bg_bitmap_file;
3972 ofn.nMaxFile = 1023;
3973 ofn.lpstrInitialDir = NULL;
3975 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
3977 ofn.lpstrTitle = "Choose wall paper.";
3979 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3981 if (GetOpenFileName(&ofn))
3983 /* Load 'savefile' */
3988 /* React to changes */
3989 Term_xtra_win_react();
3991 /* Hack -- Force redraw */
3992 Term_key_push(KTRL('R'));
3997 case IDM_DUMP_SCREEN_HTML:
3999 static char buf[1024] = "";
4000 memset(&ofn, 0, sizeof(ofn));
4001 ofn.lStructSize = sizeof(ofn);
4002 ofn.hwndOwner = data[0].w;
4003 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4004 ofn.nFilterIndex = 1;
4005 ofn.lpstrFile = buf;
4006 ofn.nMaxFile = 1023;
4007 ofn.lpstrDefExt = "html";
4008 ofn.lpstrInitialDir = NULL;
4010 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
4012 ofn.lpstrTitle = "Save screen dump as HTML.";
4014 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4016 if (GetSaveFileName(&ofn))
4018 do_cmd_save_screen_html_aux(buf, 0);
4025 case IDM_OPTIONS_SAVER:
4029 DestroyWindow(hwndSaver);
4034 /* Create a screen scaver window */
4035 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4036 "Angband Screensaver",
4037 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4038 0, 0, GetSystemMetrics(SM_CXSCREEN),
4039 GetSystemMetrics(SM_CYSCREEN),
4040 NULL, NULL, hInstance, NULL);
4044 /* Push the window to the bottom XXX XXX XXX */
4045 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4050 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
4052 plog("Failed to create saver window");
4062 case IDM_OPTIONS_MAP:
4068 case IDM_HELP_CONTENTS:
4072 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4073 if (check_file(tmp))
4075 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4080 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4081 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4083 plog_fmt("Cannot find help file: %s", tmp);
4084 plog("Use the online help files instead.");
4089 #else /* HTML_HELP */
4092 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4093 if (check_file(tmp))
4095 sprintf(buf, "winhelp.exe %s", tmp);
4096 WinExec(buf, SW_NORMAL);
4101 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4102 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4104 plog_fmt("Cannot find help file: %s", tmp);
4105 plog("Use the online help files instead.");
4110 #endif /* HTML_HELP */
4116 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4123 /* Extract the modifiers */
4124 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4125 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4126 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4128 Term_no_press = (ma) ? TRUE : FALSE;
4130 /* Handle "special" keys */
4131 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4133 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4134 bool numpad = FALSE;
4136 /* Begin the macro trigger */
4139 /* Send the modifiers */
4140 if (mc) Term_keypress('C');
4141 if (ms) Term_keypress('S');
4142 if (ma) Term_keypress('A');
4144 /* Extract "scan code" */
4145 i = LOBYTE(HIWORD(lParam));
4147 /* Introduce the scan code */
4150 /* Extended key bit */
4153 /* Numpad Enter and '/' are extended key */
4155 Term_no_press = TRUE;
4156 case VK_RETURN: /* Enter */
4159 /* Other extended keys are on full keyboard */
4175 Term_no_press = TRUE;
4179 case VK_PRIOR: /* Page Up */
4180 case VK_NEXT: /* Page Down */
4190 /* Special modifiers for keypad keys */
4191 if (numpad) Term_keypress('K');
4193 /* Encode the hexidecimal scan code */
4194 Term_keypress(hexsym[i/16]);
4195 Term_keypress(hexsym[i%16]);
4197 /* End the macro trigger */
4208 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4209 WPARAM wParam, LPARAM lParam);
4210 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4211 WPARAM wParam, LPARAM lParam)
4212 #else /* __MWERKS__ */
4213 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4214 WPARAM wParam, LPARAM lParam)
4215 #endif /* __MWERKS__ */
4221 MINMAXINFO FAR *lpmmi;
4227 /* Acquire proper "term_data" info */
4228 td = (term_data *)GetWindowLong(hWnd, 0);
4230 /* Handle message */
4236 SetWindowLong(hWnd, 0, (LONG)(my_td));
4246 case WM_GETMINMAXINFO:
4248 MINMAXINFO FAR *lpmmi;
4251 lpmmi = (MINMAXINFO FAR *)lParam;
4253 /* this message was sent before WM_NCCREATE */
4256 /* Minimum window size is 80x24 */
4257 rc.left = rc.top = 0;
4258 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4259 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4262 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4264 /* Save minimum size */
4265 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4266 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4273 BeginPaint(hWnd, &ps);
4274 if (td) term_data_redraw(td);
4275 EndPaint(hWnd, &ps);
4276 ValidateRect(hWnd, NULL);
4283 if (process_keydown(wParam, lParam))
4290 if (Term_no_press) Term_no_press = FALSE;
4291 else Term_keypress(wParam);
4303 if (game_in_progress && character_generated)
4308 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4310 plog("You may not do that right now.");
4315 /* Hack -- Forget messages */
4324 /* do_cmd_save_game(FALSE); */
4325 #else /* ZANGBAND */
4326 /* do_cmd_save_game(); */
4327 #endif /* ZANGBAND */
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 #ifdef USE_TRANSPARENCY
4879 if (infMask.hPalette) DeleteObject(infMask.hPalette);
4880 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
4881 #endif /* USE_TRANSPARENCY */
4883 #endif /* USE_GRAPHICS */
4885 /*** Free some other stuff ***/
4887 DeleteObject(hbrYellow);
4892 if (hPal) DeleteObject(hPal);
4894 UnregisterClass(AppName, hInstance);
4896 if (hIcon) DestroyIcon(hIcon);
4903 /*** Initialize ***/
4909 static void init_stuff(void)
4916 /* Get program name with full path */
4917 GetModuleFileName(hInstance, path, 512);
4919 /* Save the "program name" XXX XXX XXX */
4922 /* Get the name of the "*.ini" file */
4923 strcpy(path + strlen(path) - 4, ".INI");
4925 /* Save the the name of the ini-file */
4926 ini_file = string_make(path);
4928 /* Analyze the path */
4934 if (path[i] == '\\')
4941 /* Add "lib" to the path */
4942 strcpy(path + i + 1, "lib\\");
4944 /* Validate the path */
4945 validate_dir(path, TRUE);
4947 /* Init the file paths */
4948 init_file_paths(path);
4950 /* Hack -- Validate the paths */
4951 validate_dir(ANGBAND_DIR_APEX, FALSE);
4952 validate_dir(ANGBAND_DIR_BONE, FALSE);
4954 /* Allow missing 'edit' directory */
4955 if (!check_dir(ANGBAND_DIR_EDIT))
4957 /* Must have 'data'! */
4958 validate_dir(ANGBAND_DIR_DATA, TRUE);
4962 /* Don't need 'data' */
4963 validate_dir(ANGBAND_DIR_DATA, FALSE);
4966 validate_dir(ANGBAND_DIR_FILE, TRUE);
4967 validate_dir(ANGBAND_DIR_HELP, FALSE);
4968 validate_dir(ANGBAND_DIR_INFO, FALSE);
4969 validate_dir(ANGBAND_DIR_PREF, TRUE);
4970 validate_dir(ANGBAND_DIR_SAVE, FALSE);
4971 validate_dir(ANGBAND_DIR_USER, TRUE);
4972 validate_dir(ANGBAND_DIR_XTRA, TRUE);
4974 /* Build the filename */
4976 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
4978 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
4982 /* Hack -- Validate the "news.txt" file */
4983 validate_file(path);
4987 /* Build the "font" path */
4988 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
4990 /* Allocate the path */
4991 ANGBAND_DIR_XTRA_FONT = string_make(path);
4993 /* Validate the "font" directory */
4994 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
4996 /* Build the filename */
4997 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
4999 /* Hack -- Validate the basic font */
5000 validate_file(path);
5006 /* Build the "graf" path */
5007 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5009 /* Allocate the path */
5010 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5012 /* Validate the "graf" directory */
5013 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5015 #endif /* USE_GRAPHICS */
5020 /* Build the "sound" path */
5021 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5023 /* Allocate the path */
5024 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5026 /* Validate the "sound" directory */
5027 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5029 #endif /* USE_SOUND */
5033 /* Build the "music" path */
5034 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5036 /* Allocate the path */
5037 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5039 /* Validate the "music" directory */
5040 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5042 #endif /* USE_MUSIC */
5044 /* Build the "help" path */
5045 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5047 /* Allocate the path */
5048 ANGBAND_DIR_XTRA_HELP = string_make(path);
5050 /* Validate the "help" directory */
5051 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5055 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5056 LPSTR lpCmdLine, int nCmdShow)
5071 if (hPrevInst == NULL)
5073 wc.style = CS_CLASSDC;
5074 wc.lpfnWndProc = AngbandWndProc;
5076 wc.cbWndExtra = 4; /* one long pointer to term_data */
5077 wc.hInstance = hInst;
5078 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5079 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5080 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5081 wc.lpszMenuName = AppName;
5082 wc.lpszClassName = AppName;
5084 if (!RegisterClass(&wc)) exit(1);
5086 wc.lpfnWndProc = AngbandListProc;
5087 wc.lpszMenuName = NULL;
5088 wc.lpszClassName = AngList;
5090 if (!RegisterClass(&wc)) exit(2);
5094 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5095 wc.lpfnWndProc = AngbandSaverProc;
5097 wc.lpszMenuName = NULL;
5098 wc.lpszClassName = "WindowsScreenSaverClass";
5100 if (!RegisterClass(&wc)) exit(3);
5106 /* Temporary hooks */
5107 plog_aux = hack_plog;
5108 quit_aux = hack_quit;
5109 core_aux = hack_quit;
5111 /* Prepare the filepaths */
5114 /* Initialize the keypress analyzer */
5115 for (i = 0; special_key_list[i]; ++i)
5117 special_key[special_key_list[i]] = TRUE;
5119 /* Initialize the keypress analyzer */
5120 for (i = 0; ignore_key_list[i]; ++i)
5122 ignore_key[ignore_key_list[i]] = TRUE;
5125 /* Determine if display is 16/256/true color */
5127 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5128 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5129 ReleaseDC(NULL, hdc);
5131 /* Initialize the colors */
5132 for (i = 0; i < 256; i++)
5136 /* Extract desired values */
5137 rv = angband_color_table[i][1];
5138 gv = angband_color_table[i][2];
5139 bv = angband_color_table[i][3];
5141 /* Extract the "complex" code */
5142 win_clr[i] = PALETTERGB(rv, gv, bv);
5144 /* Save the "simple" code */
5145 angband_color_table[i][0] = win_pal[i];
5148 /* Prepare the windows */
5154 /* Activate hooks */
5155 plog_aux = hook_plog;
5156 quit_aux = hook_quit;
5157 core_aux = hook_quit;
5159 /* Set the system suffix */
5160 ANGBAND_SYS = "win";
5162 /* Set the keyboard suffix */
5163 if (7 != GetKeyboardType(0))
5164 ANGBAND_KEYBOARD = "0";
5167 /* Japanese keyboard */
5168 switch (GetKeyboardType(1))
5170 case 0x0D01: case 0x0D02:
5171 case 0x0D03: case 0x0D04:
5172 case 0x0D05: case 0x0D06:
5174 ANGBAND_KEYBOARD = "NEC98";
5178 ANGBAND_KEYBOARD = "JAPAN";
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 */