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);
1660 /* Forget old font */
1666 for (i = 0; i < MAX_TERM_DATA; i++)
1668 /* Don't check when closing the application */
1671 /* Check "screen" */
1672 if ((td != &data[i]) &&
1673 (data[i].font_file) &&
1674 (streq(data[i].font_file, td->font_file)))
1680 /* Remove unused font resources */
1681 if (!used) RemoveFontResource(td->font_file);
1683 /* Free the old name */
1684 string_free(td->font_file);
1687 td->font_file = NULL;
1692 if (!path) return (1);
1698 /* Analyze font path */
1699 base = analyze_font(buf, &wid, &hgt);
1702 if (!suffix(base, ".FON")) return (1);
1705 if (!check_file(buf)) return (1);
1707 /* Load the new font */
1708 if (!AddFontResource(buf)) return (1);
1710 /* Save new font name */
1711 td->font_file = string_make(base);
1713 /* Remove the "suffix" */
1714 base[strlen(base)-4] = '\0';
1717 /* Create the font (using the 'base' of the font file name!) */
1719 td->font_id = CreateFontIndirect(&(td->lf));
1720 wid = td->lf.lfWidth;
1721 hgt = td->lf.lfHeight;
1722 if (!td->font_id) return (1);
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);
1731 /* Hack -- Unknown size */
1738 /* all this trouble to get the cell size */
1739 hdcDesktop = GetDC(HWND_DESKTOP);
1740 hfOld = SelectObject(hdcDesktop, td->font_id);
1741 GetTextMetrics(hdcDesktop, &tm);
1742 SelectObject(hdcDesktop, hfOld);
1743 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1745 /* Font size info */
1746 wid = tm.tmAveCharWidth;
1750 /* Save the size info */
1761 * Allow the user to change the font for this window.
1763 static void term_change_font(term_data *td)
1768 memset(&cf, 0, sizeof(cf));
1769 cf.lStructSize = sizeof(cf);
1770 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1771 cf.lpLogFont = &(td->lf);
1773 if (ChooseFont(&cf))
1775 /* Force the font */
1776 term_force_font(td, NULL);
1778 /* Assume not bizarre */
1781 /* Reset the tile info */
1782 td->tile_wid = td->font_wid;
1783 td->tile_hgt = td->font_hgt;
1785 /* Analyze the font */
1788 /* Resize the window */
1789 term_window_resize(td);
1795 char tmp[1024] = "";
1797 /* Extract a default if possible */
1798 if (td->font_file) strcpy(tmp, td->font_file);
1800 /* Ask for a choice */
1801 memset(&ofn, 0, sizeof(ofn));
1802 ofn.lStructSize = sizeof(ofn);
1803 ofn.hwndOwner = data[0].w;
1804 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1805 ofn.nFilterIndex = 1;
1806 ofn.lpstrFile = tmp;
1808 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1809 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1810 ofn.lpstrDefExt = "fon";
1812 /* Force choice if legal */
1813 if (GetOpenFileName(&ofn))
1815 /* Force the font */
1816 if (term_force_font(td, tmp))
1818 /* Access the standard font file */
1819 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1821 /* Force the use of that font */
1822 (void)term_force_font(td, tmp);
1825 /* Assume not bizarre */
1826 td->bizarre = FALSE;
1828 /* Reset the tile info */
1829 td->tile_wid = td->font_wid;
1830 td->tile_hgt = td->font_hgt;
1832 /* Analyze the font */
1835 /* Resize the window */
1836 term_window_resize(td);
1843 * Allow the user to lock this window.
1845 static void term_window_pos(term_data *td, HWND hWnd)
1847 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1848 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1851 static void windows_map(void);
1854 * Hack -- redraw a term_data
1856 static void term_data_redraw(term_data *td)
1860 /* Redraw the map */
1865 /* Activate the term */
1866 Term_activate(&td->t);
1868 /* Redraw the contents */
1871 /* Restore the term */
1872 Term_activate(term_screen);
1880 /*** Function hooks needed by "Term" ***/
1886 * Initialize a new Term
1888 static void Term_init_win(term *t)
1897 static void Term_nuke_win(term *t)
1906 * Interact with the User
1908 static errr Term_user_win(int n)
1916 * React to global changes
1918 static errr Term_xtra_win_react(void)
1926 /* Save the default colors */
1927 for (i = 0; i < 256; i++)
1929 /* Simply accept the desired colors */
1930 win_pal[i] = angband_color_table[i][0];
1941 bool change = FALSE;
1943 /* Save the default colors */
1944 for (i = 0; i < 256; i++)
1946 /* Extract desired values */
1947 rv = angband_color_table[i][1];
1948 gv = angband_color_table[i][2];
1949 bv = angband_color_table[i][3];
1951 /* Extract a full color code */
1952 code = PALETTERGB(rv, gv, bv);
1954 /* Activate changes */
1955 if (win_clr[i] != code)
1957 /* Note the change */
1960 /* Apply the desired color */
1965 /* Activate the palette if needed */
1966 if (change) (void)new_palette();
1972 /* Handle "arg_sound" */
1973 if (use_sound != arg_sound)
1975 /* Initialize (if needed) */
1976 if (arg_sound && !init_sound())
1980 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
1982 plog("Cannot initialize sound!");
1990 /* Change setting */
1991 use_sound = arg_sound;
1999 /* Handle "arg_graphics" */
2000 if (use_graphics != arg_graphics)
2002 /* Initialize (if needed) */
2003 if (arg_graphics && !init_graphics())
2007 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
2009 plog("Cannot initialize graphics!");
2014 arg_graphics = GRAPHICS_NONE;
2017 /* Change setting */
2018 use_graphics = arg_graphics;
2021 #ifdef ANGBAND_2_8_1
2023 #else /* ANGBAND_2_8_1 */
2024 reset_visuals(TRUE);
2025 #endif /* ANGBAND_2_8_1 */
2028 #endif /* USE_GRAPHICS */
2031 /* Clean up windows */
2032 for (i = 0; i < MAX_TERM_DATA; i++)
2036 term_data *td = &data[i];
2038 /* Update resized windows */
2039 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2042 Term_activate(&td->t);
2044 /* Hack -- Resize the term */
2045 Term_resize(td->cols, td->rows);
2047 /* Redraw the contents */
2062 * Process at least one event
2064 static errr Term_xtra_win_event(int v)
2068 /* Wait for an event */
2072 if (GetMessage(&msg, NULL, 0, 0))
2074 TranslateMessage(&msg);
2075 DispatchMessage(&msg);
2079 /* Check for an event */
2083 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2085 TranslateMessage(&msg);
2086 DispatchMessage(&msg);
2096 * Process all pending events
2098 static errr Term_xtra_win_flush(void)
2102 /* Process all pending events */
2103 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2105 TranslateMessage(&msg);
2106 DispatchMessage(&msg);
2115 * Hack -- clear the screen
2117 * Make this more efficient XXX XXX XXX
2119 static errr Term_xtra_win_clear(void)
2121 term_data *td = (term_data*)(Term->data);
2126 /* Rectangle to erase */
2127 rc.left = td->size_ow1;
2128 rc.right = rc.left + td->cols * td->tile_wid;
2129 rc.top = td->size_oh1;
2130 rc.bottom = rc.top + td->rows * td->tile_hgt;
2134 SetBkColor(hdc, RGB(0, 0, 0));
2135 SelectObject(hdc, td->font_id);
2136 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2141 rc.left = 0; rc.top = 0;
2144 ReleaseDC(td->w, hdc);
2152 * Hack -- make a noise
2154 static errr Term_xtra_win_noise(void)
2156 MessageBeep(MB_ICONASTERISK);
2162 * Hack -- make a sound
2164 static errr Term_xtra_win_sound(int v)
2169 #endif /* USE_SOUND */
2171 /* Sound disabled */
2172 if (!use_sound) return (1);
2175 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2179 /* Count the samples */
2180 for (i = 0; i < SAMPLE_MAX; i++)
2182 if (!sound_file[v][i])
2187 if (i == 0) return (1);
2189 /* Build the path */
2190 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_simple(i)]);
2194 /* Play the sound, catch errors */
2195 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2199 /* Play the sound, catch errors */
2200 return (sndPlaySound(buf, SND_ASYNC));
2204 #else /* USE_SOUND */
2209 #endif /* USE_SOUND */
2214 * Delay for "x" milliseconds
2216 static int Term_xtra_win_delay(int v)
2230 t = GetTickCount() + v;
2233 while (GetTickCount() < t)
2235 /* Handle messages */
2236 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2238 TranslateMessage(&msg);
2239 DispatchMessage(&msg);
2251 * Do a "special thing"
2253 static errr Term_xtra_win(int n, int v)
2255 /* Handle a subset of the legal requests */
2258 /* Make a bell sound */
2259 case TERM_XTRA_NOISE:
2261 return (Term_xtra_win_noise());
2264 /* Make a special sound */
2265 case TERM_XTRA_SOUND:
2267 return (Term_xtra_win_sound(v));
2270 /* Process random events */
2271 case TERM_XTRA_BORED:
2273 return (Term_xtra_win_event(0));
2276 /* Process an event */
2277 case TERM_XTRA_EVENT:
2279 return (Term_xtra_win_event(v));
2282 /* Flush all events */
2283 case TERM_XTRA_FLUSH:
2285 return (Term_xtra_win_flush());
2288 /* Clear the screen */
2289 case TERM_XTRA_CLEAR:
2291 return (Term_xtra_win_clear());
2294 /* React to global changes */
2295 case TERM_XTRA_REACT:
2297 return (Term_xtra_win_react());
2300 /* Delay for some milliseconds */
2301 case TERM_XTRA_DELAY:
2303 return (Term_xtra_win_delay(v));
2314 * Low level graphics (Assumes valid input).
2316 * Draw a "cursor" at (x,y), using a "yellow box".
2318 static errr Term_curs_win(int x, int y)
2320 term_data *td = (term_data*)(Term->data);
2325 int tile_wid, tile_hgt;
2329 tile_wid = td->map_tile_wid;
2330 tile_hgt = td->map_tile_hgt;
2334 tile_wid = td->tile_wid;
2335 tile_hgt = td->tile_hgt;
2338 /* Frame the grid */
2339 rc.left = x * tile_wid + td->size_ow1;
2340 rc.right = rc.left + tile_wid;
2341 rc.top = y * tile_hgt + td->size_oh1;
2342 rc.bottom = rc.top + tile_hgt;
2344 /* Cursor is done as a yellow "box" */
2346 FrameRect(hdc, &rc, hbrYellow);
2347 ReleaseDC(td->w, hdc);
2355 * Low level graphics (Assumes valid input).
2357 * Draw a "big cursor" at (x,y), using a "yellow box".
2359 static errr Term_bigcurs_win(int x, int y)
2361 term_data *td = (term_data*)(Term->data);
2366 int tile_wid, tile_hgt;
2370 /* Normal cursor in map window */
2371 Term_curs_win(x, y);
2376 tile_wid = td->tile_wid;
2377 tile_hgt = td->tile_hgt;
2380 /* Frame the grid */
2381 rc.left = x * tile_wid + td->size_ow1;
2382 rc.right = rc.left + 2 * tile_wid;
2383 rc.top = y * tile_hgt + td->size_oh1;
2384 rc.bottom = rc.top + tile_hgt;
2386 /* Cursor is done as a yellow "box" */
2388 FrameRect(hdc, &rc, hbrYellow);
2389 ReleaseDC(td->w, hdc);
2397 * Low level graphics (Assumes valid input).
2399 * Erase a "block" of "n" characters starting at (x,y).
2401 static errr Term_wipe_win(int x, int y, int n)
2403 term_data *td = (term_data*)(Term->data);
2408 /* Rectangle to erase in client coords */
2409 rc.left = x * td->tile_wid + td->size_ow1;
2410 rc.right = rc.left + n * td->tile_wid;
2411 rc.top = y * td->tile_hgt + td->size_oh1;
2412 rc.bottom = rc.top + td->tile_hgt;
2415 SetBkColor(hdc, RGB(0, 0, 0));
2416 SelectObject(hdc, td->font_id);
2421 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2422 ReleaseDC(td->w, hdc);
2430 * Low level graphics. Assumes valid input.
2432 * Draw several ("n") chars, with an attr, at a given location.
2434 * All "graphic" data is handled by "Term_pict_win()", below.
2436 * One would think there is a more efficient method for telling a window
2437 * what color it should be using to draw with, but perhaps simply changing
2438 * it every time is not too inefficient. XXX XXX XXX
2440 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2442 term_data *td = (term_data*)(Term->data);
2448 static HBITMAP WALL;
2449 static HBRUSH myBrush, oldBrush;
2451 static bool init_done = FALSE;
2454 WALL = LoadBitmap(hInstance, AppName);
2455 myBrush = CreatePatternBrush(WALL);
2460 /* Total rectangle */
2461 rc.left = x * td->tile_wid + td->size_ow1;
2462 rc.right = rc.left + n * td->tile_wid;
2463 rc.top = y * td->tile_hgt + td->size_oh1;
2464 rc.bottom = rc.top + td->tile_hgt;
2469 /* Background color */
2470 SetBkColor(hdc, RGB(0, 0, 0));
2472 /* Foreground color */
2475 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2479 SetTextColor(hdc, win_clr[a&0x0F]);
2483 SetTextColor(hdc, win_clr[a]);
2487 SelectObject(hdc, td->font_id);
2490 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2494 (td->tile_hgt != td->font_hgt) ||
2495 (td->tile_wid != td->font_wid))
2499 /* Erase complete rectangle */
2500 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2503 if (use_bg) DrawBG(hdc, &rc);
2506 rc.left += ((td->tile_wid - td->font_wid) / 2);
2507 rc.right = rc.left + td->font_wid;
2508 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2509 rc.bottom = rc.top + td->font_hgt;
2511 /* Dump each character */
2512 for (i = 0; i < n; i++)
2515 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2517 rc.right += td->font_wid;
2519 oldBrush = SelectObject(hdc, myBrush);
2520 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2523 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2525 SelectObject(hdc, oldBrush);
2526 SelectObject(hdc, oldPen);
2527 rc.right -= td->font_wid;
2531 rc.left += 2 * td->tile_wid;
2532 rc.right += 2 * td->tile_wid;
2534 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2536 rc.right += td->font_wid;
2538 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2540 rc.right -= td->font_wid;
2544 rc.left += 2 * td->tile_wid;
2545 rc.right += 2 * td->tile_wid;
2546 } else if (*(s+i)==127){
2547 oldBrush = SelectObject(hdc, myBrush);
2548 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2551 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2553 SelectObject(hdc, oldBrush);
2554 SelectObject(hdc, oldPen);
2557 rc.left += td->tile_wid;
2558 rc.right += td->tile_wid;
2561 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2565 rc.left += td->tile_wid;
2566 rc.right += td->tile_wid;
2570 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2574 rc.left += td->tile_wid;
2575 rc.right += td->tile_wid;
2585 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2590 ReleaseDC(td->w, hdc);
2598 * Low level graphics. Assumes valid input.
2600 * Draw an array of "special" attr/char pairs at the given location.
2602 * We use the "Term_pict_win()" function for "graphic" data, which are
2603 * encoded by setting the "high-bits" of both the "attr" and the "char"
2604 * data. We use the "attr" to represent the "row" of the main bitmap,
2605 * and the "char" to represent the "col" of the main bitmap. The use
2606 * of this function is induced by the "higher_pict" flag.
2608 * If "graphics" is not available, we simply "wipe" the given grids.
2610 # ifdef USE_TRANSPARENCY
2611 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2612 # else /* USE_TRANSPARENCY */
2613 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp)
2614 # endif /* USE_TRANSPARENCY */
2616 term_data *td = (term_data*)(Term->data);
2622 int x2, y2, w2, h2, tw2;
2624 # ifdef USE_TRANSPARENCY
2630 # endif /* USE_TRANSPARENCY */
2639 /* Erase the grids */
2640 return (Term_wipe_win(x, y, n));
2643 /* Size of bitmap cell */
2644 w1 = infGraph.CellWidth;
2645 h1 = infGraph.CellHeight;
2647 /* Size of window cell */
2650 w2 = td->map_tile_wid;
2651 h2 = td->map_tile_hgt;
2660 if (use_bigtile) tw2 *= 2;
2663 /* Location of window cell */
2664 x2 = x * w2 + td->size_ow1;
2665 y2 = y * h2 + td->size_oh1;
2671 hdcSrc = CreateCompatibleDC(hdc);
2672 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2674 # ifdef USE_TRANSPARENCY
2676 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2678 hdcMask = CreateCompatibleDC(hdc);
2679 SelectObject(hdcMask, infMask.hBitmap);
2682 # endif /* USE_TRANSPARENCY */
2684 /* Draw attr/char pairs */
2685 for (i = 0; i < n; i++, x2 += w2)
2690 /* Extract picture */
2691 int row = (a & 0x7F);
2692 int col = (c & 0x7F);
2694 /* Location of bitmap cell */
2698 # ifdef USE_TRANSPARENCY
2700 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2702 x3 = (tcp[i] & 0x7F) * w1;
2703 y3 = (tap[i] & 0x7F) * h1;
2706 if ((w1 == tw2) && (h1 == h2))
2708 /* Copy the terrain picture from the bitmap to the window */
2709 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2711 /* Mask out the tile */
2712 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2715 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2718 /* Need to stretch */
2721 /* Set the correct mode for stretching the tiles */
2722 SetStretchBltMode(hdc, COLORONCOLOR);
2724 /* Copy the terrain picture from the bitmap to the window */
2725 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
2727 /* Only draw if terrain and overlay are different */
2728 if ((x1 != x3) || (y1 != y3))
2730 /* Mask out the tile */
2731 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2734 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2740 # endif /* USE_TRANSPARENCY */
2744 if ((w1 == tw2) && (h1 == h2))
2746 /* Copy the picture from the bitmap to the window */
2747 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2750 /* Need to stretch */
2753 /* Set the correct mode for stretching the tiles */
2754 SetStretchBltMode(hdc, COLORONCOLOR);
2756 /* Copy the picture from the bitmap to the window */
2757 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2763 SelectObject(hdcSrc, hbmSrcOld);
2766 # ifdef USE_TRANSPARENCY
2768 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2771 SelectObject(hdcMask, hbmSrcOld);
2775 # endif /* USE_TRANSPARENCY */
2778 ReleaseDC(td->w, hdc);
2780 #else /* USE_GRAPHICS */
2782 /* Just erase this grid */
2783 return (Term_wipe_win(x, y, n));
2785 #endif /* USE_GRAPHICS */
2792 static void windows_map(void)
2794 term_data *td = &data[0];
2796 int x, min_x, max_x;
2797 int y, min_y, max_y;
2799 #ifdef USE_TRANSPARENCY
2803 /* Only in graphics mode */
2804 if (!use_graphics) return;
2807 Term_xtra_win_clear();
2809 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2810 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2811 td->map_active = TRUE;
2821 for (x = min_x; x < max_x; x++)
2823 for (y = min_y; y < max_y; y++)
2825 #ifdef USE_TRANSPARENCY
2826 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
2827 #else /* USE_TRANSPARENCY */
2828 map_info(y, x, &a, (char*)&c);
2829 #endif /* USE_TRANSPARENCY */
2831 /* Ignore non-graphics */
2832 if ((a & 0x80) && (c & 0x80))
2834 #ifdef USE_TRANSPARENCY
2835 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2836 #else /* USE_TRANSPARENCY */
2837 Term_pict_win(x - min_x, y - min_y, 1, &a, &c);
2838 #endif /* USE_TRANSPARENCY */
2843 /* Hilite the player */
2844 Term_curs_win(px - min_x, py - min_y);
2846 /* Wait for a keypress, flush key buffer */
2847 Term_inkey(&c, TRUE, TRUE);
2850 /* Switch off the map display */
2851 td->map_active = FALSE;
2853 /* Restore screen */
2854 Term_xtra_win_clear();
2859 /*** Other routines ***/
2863 * Create and initialize a "term_data" given a title
2865 static void term_data_link(term_data *td)
2869 /* Initialize the term */
2870 term_init(t, td->cols, td->rows, td->keys);
2872 /* Use a "software" cursor */
2873 t->soft_cursor = TRUE;
2875 /* Use "Term_pict" for "graphic" data */
2876 t->higher_pict = TRUE;
2878 /* Erase with "white space" */
2879 t->attr_blank = TERM_WHITE;
2880 t->char_blank = ' ';
2883 /* Prepare the init/nuke hooks */
2884 t->init_hook = Term_init_win;
2885 t->nuke_hook = Term_nuke_win;
2888 /* Prepare the template hooks */
2889 t->user_hook = Term_user_win;
2890 t->xtra_hook = Term_xtra_win;
2891 t->curs_hook = Term_curs_win;
2892 t->bigcurs_hook = Term_bigcurs_win;
2893 t->wipe_hook = Term_wipe_win;
2894 t->text_hook = Term_text_win;
2895 t->pict_hook = Term_pict_win;
2897 /* Remember where we came from */
2898 t->data = (vptr)(td);
2903 * Create the windows
2905 * First, instantiate the "default" values, then read the "ini_file"
2906 * to over-ride selected values, then create the windows, and fonts.
2908 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2909 * must make active to realize the palette. XXX XXX XXX
2911 static void init_windows(void)
2923 WIPE(td, term_data);
2927 td->s = angband_term_name[0];
2946 for (i = 1; i < MAX_TERM_DATA; i++)
2949 WIPE(td, term_data);
2950 td->s = angband_term_name[i];
2954 td->visible = FALSE;
2959 td->pos_x = (7 - i) * 30;
2960 td->pos_y = (7 - i) * 20;
2972 /* Main window (need these before term_getsize gets called) */
2974 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2975 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2980 /* Sub windows (need these before term_getsize gets called) */
2981 for (i = 1; i < MAX_TERM_DATA; i++)
2984 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2985 td->dwExStyle = (WS_EX_TOOLWINDOW);
2990 for (i = 0; i < MAX_TERM_DATA; i++)
2995 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2996 td->lf.lfCharSet = SHIFTJIS_CHARSET;
2997 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2998 /* Activate the chosen font */
2999 term_force_font(td, NULL);
3000 td->tile_wid = td->font_wid;
3001 td->tile_hgt = td->font_hgt;
3003 /* Access the standard font file */
3004 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3006 /* Activate the chosen font */
3007 if (term_force_font(td, buf))
3009 /* Access the standard font file */
3010 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3012 /* Force the use of that font */
3013 (void)term_force_font(td, buf);
3019 /* Assume not bizarre */
3020 td->bizarre = FALSE;
3025 /* Analyze the font */
3028 /* Resize the window */
3029 term_window_resize(td);
3033 /* Sub windows (reverse order) */
3034 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3039 td->w = CreateWindowEx(td->dwExStyle, AngList,
3041 td->pos_x, td->pos_y,
3042 td->size_wid, td->size_hgt,
3043 HWND_DESKTOP, NULL, hInstance, NULL);
3046 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3048 if (!td->w) quit("Failed to create sub-window");
3054 td->size_hack = TRUE;
3055 ShowWindow(td->w, SW_SHOW);
3056 td->size_hack = FALSE;
3060 angband_term[i] = &td->t;
3064 /* Activate the window */
3065 SetActiveWindow(td->w);
3070 term_window_pos(&data[i], HWND_TOPMOST);
3074 term_window_pos(&data[i], td->w);
3084 td->w = CreateWindowEx(td->dwExStyle, AppName,
3086 td->pos_x, td->pos_y,
3087 td->size_wid, td->size_hgt,
3088 HWND_DESKTOP, NULL, hInstance, NULL);
3091 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3093 if (!td->w) quit("Failed to create Angband window");
3098 angband_term[0] = &td->t;
3100 /* Activate the main window */
3101 SetActiveWindow(td->w);
3103 /* Bring main window back to top */
3104 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3107 /* New palette XXX XXX XXX */
3108 (void)new_palette();
3111 /* Create a "brush" for drawing the "cursor" */
3112 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3115 /* Process pending messages */
3116 (void)Term_xtra_win_flush();
3124 static void setup_menus(void)
3128 HMENU hm = GetMenu(data[0].w);
3131 /* Menu "File", Disable all */
3132 EnableMenuItem(hm, IDM_FILE_NEW,
3133 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3134 EnableMenuItem(hm, IDM_FILE_OPEN,
3135 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3136 EnableMenuItem(hm, IDM_FILE_SAVE,
3137 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3138 EnableMenuItem(hm, IDM_FILE_EXIT,
3139 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3140 EnableMenuItem(hm, IDM_FILE_SCORE,
3141 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3144 /* No character available */
3145 if (!character_generated)
3147 /* Menu "File", Item "New" */
3148 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3150 /* Menu "File", Item "Open" */
3151 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3154 /* A character available */
3155 if (character_generated)
3157 /* Menu "File", Item "Save" */
3158 EnableMenuItem(hm, IDM_FILE_SAVE,
3159 MF_BYCOMMAND | MF_ENABLED);
3162 /* Menu "File", Item "Exit" */
3163 EnableMenuItem(hm, IDM_FILE_EXIT,
3164 MF_BYCOMMAND | MF_ENABLED);
3166 EnableMenuItem(hm, IDM_FILE_SCORE,
3167 MF_BYCOMMAND | MF_ENABLED);
3170 /* Menu "Window::Visibility" */
3171 for (i = 0; i < MAX_TERM_DATA; i++)
3173 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3174 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3176 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3177 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3179 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3180 MF_BYCOMMAND | MF_ENABLED);
3183 /* Menu "Window::Font" */
3184 for (i = 0; i < MAX_TERM_DATA; i++)
3186 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3187 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3189 if (data[i].visible)
3191 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3192 MF_BYCOMMAND | MF_ENABLED);
3196 /* Menu "Window::Window Position Fix" */
3197 for (i = 0; i < MAX_TERM_DATA; i++)
3199 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3200 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3202 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3203 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3205 if (data[i].visible)
3207 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3208 MF_BYCOMMAND | MF_ENABLED);
3212 /* Menu "Window::Bizarre Display" */
3213 for (i = 0; i < MAX_TERM_DATA; i++)
3215 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3216 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3218 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3219 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3221 if (data[i].visible)
3223 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3224 MF_BYCOMMAND | MF_ENABLED);
3229 /* Menu "Window::Increase Tile Width" */
3230 for (i = 0; i < MAX_TERM_DATA; i++)
3232 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3233 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3235 if (data[i].visible)
3237 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3238 MF_BYCOMMAND | MF_ENABLED);
3243 /* Menu "Window::Decrease Tile Width" */
3244 for (i = 0; i < MAX_TERM_DATA; i++)
3246 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3247 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3249 if (data[i].visible)
3251 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3252 MF_BYCOMMAND | MF_ENABLED);
3257 /* Menu "Window::Increase Tile Height" */
3258 for (i = 0; i < MAX_TERM_DATA; i++)
3260 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3261 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3263 if (data[i].visible)
3265 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3266 MF_BYCOMMAND | MF_ENABLED);
3271 /* Menu "Window::Decrease Tile Height" */
3272 for (i = 0; i < MAX_TERM_DATA; i++)
3274 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3275 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3277 if (data[i].visible)
3279 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3280 MF_BYCOMMAND | MF_ENABLED);
3285 /* Menu "Options", disable all */
3286 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3287 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3288 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3289 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3290 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3291 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3292 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3293 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3294 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3295 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3297 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3298 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3301 /* Menu "Options", Item "Map" */
3302 if (use_graphics != GRAPHICS_NONE)
3303 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3305 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3306 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3308 /* Menu "Options", update all */
3309 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3310 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3311 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3312 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3313 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3314 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3315 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3316 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3317 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3318 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3319 CheckMenuItem(hm, IDM_OPTIONS_BG,
3320 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3322 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3323 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3327 /* Menu "Options", Item "Graphics" */
3328 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3329 /* Menu "Options", Item "Graphics" */
3330 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3331 /* Menu "Options", Item "Graphics" */
3332 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3333 /* Menu "Options", Item "Graphics" */
3334 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3335 #endif /* USE_GRAPHICS */
3338 /* Menu "Options", Item "Sound" */
3339 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3340 #endif /* USE_SOUND */
3343 /* Menu "Options", Item "ScreenSaver" */
3344 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3345 MF_BYCOMMAND | MF_ENABLED);
3346 #endif /* USE_SAVER */
3351 * Check for double clicked (or dragged) savefile
3353 * Apparently, Windows copies the entire filename into the first
3354 * piece of the "command line string". Perhaps we should extract
3355 * the "basename" of that filename and append it to the "save" dir.
3357 static void check_for_save_file(LPSTR cmd_line)
3367 /* Extract filename */
3368 strcat(savefile, s);
3370 /* Validate the file */
3371 validate_file(savefile);
3373 /* Game in progress */
3374 game_in_progress = TRUE;
3382 * Process a menu command
3384 static void process_menus(WORD wCmd)
3401 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3403 plog("You cannot do that yet...");
3407 else if (game_in_progress)
3410 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3412 plog("You can't start a new game while you're still playing!");
3418 game_in_progress = TRUE;
3432 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3434 plog("You cannot do that yet...");
3438 else if (game_in_progress)
3441 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3443 plog("You can't open a new game while you're still playing!");
3449 memset(&ofn, 0, sizeof(ofn));
3450 ofn.lStructSize = sizeof(ofn);
3451 ofn.hwndOwner = data[0].w;
3452 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3453 ofn.nFilterIndex = 1;
3454 ofn.lpstrFile = savefile;
3455 ofn.nMaxFile = 1024;
3456 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3457 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3459 if (GetOpenFileName(&ofn))
3461 /* Load 'savefile' */
3462 validate_file(savefile);
3463 game_in_progress = TRUE;
3475 if (game_in_progress && character_generated)
3481 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3483 plog("You may not do that right now.");
3489 /* Hack -- Forget messages */
3494 do_cmd_save_game(FALSE);
3495 #else /* ZANGBAND */
3497 #endif /* ZANGBAND */
3502 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3504 plog("You may not do that right now.");
3514 if (game_in_progress && character_generated)
3520 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3522 plog("You may not do that right now.");
3528 /* Hack -- Forget messages */
3537 /* do_cmd_save_game(FALSE); */
3538 #else /* ZANGBAND */
3539 /* do_cmd_save_game(); */
3540 #endif /* ZANGBAND */
3541 Term_key_push(SPECIAL_KEY_QUIT);
3549 case IDM_FILE_SCORE:
3553 /* Build the filename */
3554 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3556 /* Open the binary high score file, for reading */
3557 highscore_fd = fd_open(buf, O_RDONLY);
3559 /* Paranoia -- No score file */
3560 if (highscore_fd < 0)
3562 msg_print("Score file unavailable.");
3572 /* Display the scores */
3573 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3575 /* Shut the high score file */
3576 (void)fd_close(highscore_fd);
3578 /* Forget the high score fd */
3584 /* Hack - Flush it */
3592 case IDM_WINDOW_VIS_0:
3595 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3597 plog("You are not allowed to do that!");
3604 /* Window visibility */
3605 case IDM_WINDOW_VIS_1:
3606 case IDM_WINDOW_VIS_2:
3607 case IDM_WINDOW_VIS_3:
3608 case IDM_WINDOW_VIS_4:
3609 case IDM_WINDOW_VIS_5:
3610 case IDM_WINDOW_VIS_6:
3611 case IDM_WINDOW_VIS_7:
3613 i = wCmd - IDM_WINDOW_VIS_0;
3615 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3622 ShowWindow(td->w, SW_SHOW);
3623 term_data_redraw(td);
3627 td->visible = FALSE;
3629 ShowWindow(td->w, SW_HIDE);
3636 case IDM_WINDOW_FONT_0:
3637 case IDM_WINDOW_FONT_1:
3638 case IDM_WINDOW_FONT_2:
3639 case IDM_WINDOW_FONT_3:
3640 case IDM_WINDOW_FONT_4:
3641 case IDM_WINDOW_FONT_5:
3642 case IDM_WINDOW_FONT_6:
3643 case IDM_WINDOW_FONT_7:
3645 i = wCmd - IDM_WINDOW_FONT_0;
3647 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3651 term_change_font(td);
3656 /* Window Z Position */
3657 case IDM_WINDOW_POS_1:
3658 case IDM_WINDOW_POS_2:
3659 case IDM_WINDOW_POS_3:
3660 case IDM_WINDOW_POS_4:
3661 case IDM_WINDOW_POS_5:
3662 case IDM_WINDOW_POS_6:
3663 case IDM_WINDOW_POS_7:
3665 i = wCmd - IDM_WINDOW_POS_0;
3667 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3671 if (!td->posfix && td->visible)
3674 term_window_pos(td, HWND_TOPMOST);
3679 term_window_pos(td, data[0].w);
3685 /* Bizarre Display */
3686 case IDM_WINDOW_BIZ_0:
3687 case IDM_WINDOW_BIZ_1:
3688 case IDM_WINDOW_BIZ_2:
3689 case IDM_WINDOW_BIZ_3:
3690 case IDM_WINDOW_BIZ_4:
3691 case IDM_WINDOW_BIZ_5:
3692 case IDM_WINDOW_BIZ_6:
3693 case IDM_WINDOW_BIZ_7:
3695 i = wCmd - IDM_WINDOW_BIZ_0;
3697 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3701 td->bizarre = !td->bizarre;
3705 term_window_resize(td);
3710 /* Increase Tile Width */
3711 case IDM_WINDOW_I_WID_0:
3712 case IDM_WINDOW_I_WID_1:
3713 case IDM_WINDOW_I_WID_2:
3714 case IDM_WINDOW_I_WID_3:
3715 case IDM_WINDOW_I_WID_4:
3716 case IDM_WINDOW_I_WID_5:
3717 case IDM_WINDOW_I_WID_6:
3718 case IDM_WINDOW_I_WID_7:
3720 i = wCmd - IDM_WINDOW_I_WID_0;
3722 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3730 term_window_resize(td);
3735 /* Decrease Tile Height */
3736 case IDM_WINDOW_D_WID_0:
3737 case IDM_WINDOW_D_WID_1:
3738 case IDM_WINDOW_D_WID_2:
3739 case IDM_WINDOW_D_WID_3:
3740 case IDM_WINDOW_D_WID_4:
3741 case IDM_WINDOW_D_WID_5:
3742 case IDM_WINDOW_D_WID_6:
3743 case IDM_WINDOW_D_WID_7:
3745 i = wCmd - IDM_WINDOW_D_WID_0;
3747 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3755 term_window_resize(td);
3760 /* Increase Tile Height */
3761 case IDM_WINDOW_I_HGT_0:
3762 case IDM_WINDOW_I_HGT_1:
3763 case IDM_WINDOW_I_HGT_2:
3764 case IDM_WINDOW_I_HGT_3:
3765 case IDM_WINDOW_I_HGT_4:
3766 case IDM_WINDOW_I_HGT_5:
3767 case IDM_WINDOW_I_HGT_6:
3768 case IDM_WINDOW_I_HGT_7:
3770 i = wCmd - IDM_WINDOW_I_HGT_0;
3772 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3780 term_window_resize(td);
3785 /* Decrease Tile Height */
3786 case IDM_WINDOW_D_HGT_0:
3787 case IDM_WINDOW_D_HGT_1:
3788 case IDM_WINDOW_D_HGT_2:
3789 case IDM_WINDOW_D_HGT_3:
3790 case IDM_WINDOW_D_HGT_4:
3791 case IDM_WINDOW_D_HGT_5:
3792 case IDM_WINDOW_D_HGT_6:
3793 case IDM_WINDOW_D_HGT_7:
3795 i = wCmd - IDM_WINDOW_D_HGT_0;
3797 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3805 term_window_resize(td);
3810 case IDM_OPTIONS_NO_GRAPHICS:
3815 plog("You may not do that right now.");
3819 /* Toggle "arg_graphics" */
3820 if (arg_graphics != GRAPHICS_NONE)
3822 arg_graphics = GRAPHICS_NONE;
3824 /* React to changes */
3825 Term_xtra_win_react();
3827 /* Hack -- Force redraw */
3828 Term_key_push(KTRL('R'));
3834 case IDM_OPTIONS_OLD_GRAPHICS:
3839 plog("You may not do that right now.");
3843 /* Toggle "arg_graphics" */
3844 if (arg_graphics != GRAPHICS_ORIGINAL)
3846 arg_graphics = GRAPHICS_ORIGINAL;
3848 /* React to changes */
3849 Term_xtra_win_react();
3851 /* Hack -- Force redraw */
3852 Term_key_push(KTRL('R'));
3858 case IDM_OPTIONS_NEW_GRAPHICS:
3863 plog("You may not do that right now.");
3867 /* Toggle "arg_graphics" */
3868 if (arg_graphics != GRAPHICS_ADAM_BOLT)
3870 arg_graphics = GRAPHICS_ADAM_BOLT;
3872 /* React to changes */
3873 Term_xtra_win_react();
3875 /* Hack -- Force redraw */
3876 Term_key_push(KTRL('R'));
3882 case IDM_OPTIONS_BIGTILE:
3884 term_data *td = &data[0];
3889 plog("You may not do that right now.");
3893 /* Toggle "arg_sound" */
3894 arg_bigtile = !arg_bigtile;
3897 Term_activate(&td->t);
3899 /* Resize the term */
3900 Term_resize(td->cols, td->rows);
3903 InvalidateRect(td->w, NULL, TRUE);
3908 case IDM_OPTIONS_SOUND:
3913 plog("You may not do that right now.");
3917 /* Toggle "arg_sound" */
3918 arg_sound = !arg_sound;
3920 /* React to changes */
3921 Term_xtra_win_react();
3923 /* Hack -- Force redraw */
3924 Term_key_push(KTRL('R'));
3930 case IDM_OPTIONS_BG:
3935 plog("You may not do that right now.");
3939 /* Toggle "use_bg" */
3944 /* React to changes */
3945 Term_xtra_win_react();
3947 /* Hack -- Force redraw */
3948 Term_key_push(KTRL('R'));
3954 case IDM_OPTIONS_OPEN_BG:
3959 plog("You may not do that right now.");
3964 memset(&ofn, 0, sizeof(ofn));
3965 ofn.lStructSize = sizeof(ofn);
3966 ofn.hwndOwner = data[0].w;
3967 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3968 ofn.nFilterIndex = 1;
3969 ofn.lpstrFile = bg_bitmap_file;
3970 ofn.nMaxFile = 1023;
3971 ofn.lpstrInitialDir = NULL;
3973 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
3975 ofn.lpstrTitle = "Choose wall paper.";
3977 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3979 if (GetOpenFileName(&ofn))
3981 /* Load 'savefile' */
3986 /* React to changes */
3987 Term_xtra_win_react();
3989 /* Hack -- Force redraw */
3990 Term_key_push(KTRL('R'));
3995 case IDM_DUMP_SCREEN_HTML:
3997 static char buf[1024] = "";
3998 memset(&ofn, 0, sizeof(ofn));
3999 ofn.lStructSize = sizeof(ofn);
4000 ofn.hwndOwner = data[0].w;
4001 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4002 ofn.nFilterIndex = 1;
4003 ofn.lpstrFile = buf;
4004 ofn.nMaxFile = 1023;
4005 ofn.lpstrDefExt = "html";
4006 ofn.lpstrInitialDir = NULL;
4008 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
4010 ofn.lpstrTitle = "Save screen dump as HTML.";
4012 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4014 if (GetSaveFileName(&ofn))
4016 do_cmd_save_screen_html_aux(buf, 0);
4023 case IDM_OPTIONS_SAVER:
4027 DestroyWindow(hwndSaver);
4032 /* Create a screen scaver window */
4033 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4034 "Angband Screensaver",
4035 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4036 0, 0, GetSystemMetrics(SM_CXSCREEN),
4037 GetSystemMetrics(SM_CYSCREEN),
4038 NULL, NULL, hInstance, NULL);
4042 /* Push the window to the bottom XXX XXX XXX */
4043 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4048 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
4050 plog("Failed to create saver window");
4060 case IDM_OPTIONS_MAP:
4066 case IDM_HELP_CONTENTS:
4070 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4071 if (check_file(tmp))
4073 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4078 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4079 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4081 plog_fmt("Cannot find help file: %s", tmp);
4082 plog("Use the online help files instead.");
4087 #else /* HTML_HELP */
4090 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4091 if (check_file(tmp))
4093 sprintf(buf, "winhelp.exe %s", tmp);
4094 WinExec(buf, SW_NORMAL);
4099 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4100 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4102 plog_fmt("Cannot find help file: %s", tmp);
4103 plog("Use the online help files instead.");
4108 #endif /* HTML_HELP */
4114 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4121 /* Extract the modifiers */
4122 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4123 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4124 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4126 Term_no_press = (ma) ? TRUE : FALSE;
4128 /* Handle "special" keys */
4129 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4131 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4132 bool numpad = FALSE;
4134 /* Begin the macro trigger */
4137 /* Send the modifiers */
4138 if (mc) Term_keypress('C');
4139 if (ms) Term_keypress('S');
4140 if (ma) Term_keypress('A');
4142 /* Extract "scan code" */
4143 i = LOBYTE(HIWORD(lParam));
4145 /* Introduce the scan code */
4148 /* Extended key bit */
4151 /* Numpad Enter and '/' are extended key */
4153 Term_no_press = TRUE;
4154 case VK_RETURN: /* Enter */
4157 /* Other extended keys are on full keyboard */
4173 Term_no_press = TRUE;
4177 case VK_PRIOR: /* Page Up */
4178 case VK_NEXT: /* Page Down */
4188 /* Special modifiers for keypad keys */
4189 if (numpad) Term_keypress('K');
4191 /* Encode the hexidecimal scan code */
4192 Term_keypress(hexsym[i/16]);
4193 Term_keypress(hexsym[i%16]);
4195 /* End the macro trigger */
4206 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4207 WPARAM wParam, LPARAM lParam);
4208 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4209 WPARAM wParam, LPARAM lParam)
4210 #else /* __MWERKS__ */
4211 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4212 WPARAM wParam, LPARAM lParam)
4213 #endif /* __MWERKS__ */
4219 MINMAXINFO FAR *lpmmi;
4225 /* Acquire proper "term_data" info */
4226 td = (term_data *)GetWindowLong(hWnd, 0);
4228 /* Handle message */
4234 SetWindowLong(hWnd, 0, (LONG)(my_td));
4244 case WM_GETMINMAXINFO:
4246 MINMAXINFO FAR *lpmmi;
4249 lpmmi = (MINMAXINFO FAR *)lParam;
4251 /* this message was sent before WM_NCCREATE */
4254 /* Minimum window size is 80x24 */
4255 rc.left = rc.top = 0;
4256 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4257 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4260 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4262 /* Save minimum size */
4263 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4264 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4271 BeginPaint(hWnd, &ps);
4272 if (td) term_data_redraw(td);
4273 EndPaint(hWnd, &ps);
4274 ValidateRect(hWnd, NULL);
4281 if (process_keydown(wParam, lParam))
4288 if (Term_no_press) Term_no_press = FALSE;
4289 else Term_keypress(wParam);
4301 if (game_in_progress && character_generated)
4306 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4308 plog("You may not do that right now.");
4313 /* Hack -- Forget messages */
4322 /* do_cmd_save_game(FALSE); */
4323 #else /* ZANGBAND */
4324 /* do_cmd_save_game(); */
4325 #endif /* ZANGBAND */
4341 process_menus(LOWORD(wParam));
4347 /* this message was sent before WM_NCCREATE */
4350 /* it was sent from inside CreateWindowEx */
4351 if (!td->w) return 1;
4353 /* was sent from WM_SIZE */
4354 if (td->size_hack) return 1;
4358 case SIZE_MINIMIZED:
4360 /* Hide sub-windows */
4361 for (i = 1; i < MAX_TERM_DATA; i++)
4363 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4368 case SIZE_MAXIMIZED:
4370 /* fall through XXX XXX XXX */
4375 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4376 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4379 if ((td->cols != cols) || (td->rows != rows))
4381 /* Save the new size */
4386 Term_activate(&td->t);
4388 /* Resize the term */
4389 Term_resize(td->cols, td->rows);
4392 InvalidateRect(td->w, NULL, TRUE);
4395 td->size_hack = TRUE;
4397 /* Show sub-windows */
4398 for (i = 1; i < MAX_TERM_DATA; i++)
4400 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4403 td->size_hack = FALSE;
4411 case WM_PALETTECHANGED:
4413 /* Ignore if palette change caused by itself */
4414 if ((HWND)wParam == hWnd) return 0;
4416 /* Fall through... */
4419 case WM_QUERYNEWPALETTE:
4421 if (!paletted) return 0;
4425 SelectPalette(hdc, hPal, FALSE);
4427 i = RealizePalette(hdc);
4429 /* if any palette entries changed, repaint the window. */
4430 if (i) InvalidateRect(hWnd, NULL, TRUE);
4432 ReleaseDC(hWnd, hdc);
4439 if (wParam && !HIWORD(lParam))
4441 /* Do something to sub-windows */
4442 for (i = 1; i < MAX_TERM_DATA; i++)
4444 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4447 /* Focus on main window */
4456 case WM_ACTIVATEAPP:
4458 for (i = 1; i < MAX_TERM_DATA; i++)
4464 ShowWindow(data[i].w, SW_SHOW);
4468 ShowWindow(data[i].w, SW_HIDE);
4475 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4480 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4481 WPARAM wParam, LPARAM lParam);
4482 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4483 WPARAM wParam, LPARAM lParam)
4484 #else /* __MWERKS__ */
4485 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4486 WPARAM wParam, LPARAM lParam)
4487 #endif /* __MWERKS__ */
4491 MINMAXINFO FAR *lpmmi;
4499 /* Acquire proper "term_data" info */
4500 td = (term_data *)GetWindowLong(hWnd, 0);
4502 /* Process message */
4508 SetWindowLong(hWnd, 0, (LONG)(my_td));
4518 case WM_GETMINMAXINFO:
4520 MINMAXINFO FAR *lpmmi;
4523 lpmmi = (MINMAXINFO FAR *)lParam;
4525 /* this message was sent before WM_NCCREATE */
4528 /* Minimum window size is 80x24 */
4529 rc.left = rc.top = 0;
4530 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4531 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4534 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4536 /* Save minimum size */
4537 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4538 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4548 /* this message was sent before WM_NCCREATE */
4551 /* it was sent from inside CreateWindowEx */
4552 if (!td->w) return 1;
4554 /* was sent from inside WM_SIZE */
4555 if (td->size_hack) return 1;
4557 td->size_hack = TRUE;
4559 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4560 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4563 if ((td->cols != cols) || (td->rows != rows))
4566 term *old_term = Term;
4568 /* Save the new size */
4573 Term_activate(&td->t);
4575 /* Resize the term */
4576 Term_resize(td->cols, td->rows);
4579 Term_activate(old_term);
4582 InvalidateRect(td->w, NULL, TRUE);
4584 /* HACK - Redraw all windows */
4585 p_ptr->window = 0xFFFFFFFF;
4589 td->size_hack = FALSE;
4596 BeginPaint(hWnd, &ps);
4597 if (td) term_data_redraw(td);
4598 EndPaint(hWnd, &ps);
4605 if (process_keydown(wParam, lParam))
4612 if (Term_no_press) Term_no_press = FALSE;
4613 else Term_keypress(wParam);
4617 case WM_PALETTECHANGED:
4619 /* ignore if palette change caused by itself */
4620 if ((HWND)wParam == hWnd) return FALSE;
4621 /* otherwise, fall through!!! */
4624 case WM_QUERYNEWPALETTE:
4626 if (!paletted) return 0;
4628 SelectPalette(hdc, hPal, FALSE);
4629 i = RealizePalette(hdc);
4630 /* if any palette entries changed, repaint the window. */
4631 if (i) InvalidateRect(hWnd, NULL, TRUE);
4632 ReleaseDC(hWnd, hdc);
4636 case WM_NCLBUTTONDOWN:
4640 if (wParam == HTCLOSE) wParam = HTSYSMENU;
4641 #endif /* HTCLOSE */
4643 if (wParam == HTSYSMENU)
4647 td->visible = FALSE;
4648 ShowWindow(td->w, SW_HIDE);
4658 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4664 #define MOUSE_SENS 40
4667 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4668 WPARAM wParam, LPARAM lParam);
4669 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4670 WPARAM wParam, LPARAM lParam)
4671 #else /* __MWERKS__ */
4672 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4673 WPARAM wParam, LPARAM lParam)
4674 #endif /* __MWERKS__ */
4676 static int iMouse = 0;
4677 static WORD xMouse = 0;
4678 static WORD yMouse = 0;
4701 if (LOWORD(wParam) == WA_INACTIVE) break;
4703 /* else fall through */
4707 case WM_LBUTTONDOWN:
4708 case WM_MBUTTONDOWN:
4709 case WM_RBUTTONDOWN:
4712 SendMessage(hWnd, WM_CLOSE, 0, 0);
4720 dx = LOWORD(lParam) - xMouse;
4721 dy = HIWORD(lParam) - yMouse;
4723 if (dx < 0) dx = -dx;
4724 if (dy < 0) dy = -dy;
4726 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
4728 SendMessage(hWnd, WM_CLOSE, 0, 0);
4732 /* Save last location */
4734 xMouse = LOWORD(lParam);
4735 yMouse = HIWORD(lParam);
4742 DestroyWindow(hwndSaver);
4749 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4752 #endif /* USE_SAVER */
4758 /*** Temporary Hooks ***/
4762 * Display warning message (see "z-util.c")
4764 static void hack_plog(cptr str)
4766 /* Give a warning */
4770 MessageBox(NULL, str, "·Ù¹ð¡ª",
4771 MB_ICONEXCLAMATION | MB_OK);
4773 MessageBox(NULL, str, "Warning",
4774 MB_ICONEXCLAMATION | MB_OK);
4782 * Display error message and quit (see "z-util.c")
4784 static void hack_quit(cptr str)
4786 /* Give a warning */
4790 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
4791 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4793 MessageBox(NULL, str, "Error",
4794 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4799 /* Unregister the classes */
4800 UnregisterClass(AppName, hInstance);
4802 /* Destroy the icon */
4803 if (hIcon) DestroyIcon(hIcon);
4811 /*** Various hooks ***/
4815 * Display warning message (see "z-util.c")
4817 static void hook_plog(cptr str)
4823 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
4824 MB_ICONEXCLAMATION | MB_OK);
4826 MessageBox(data[0].w, str, "Warning",
4827 MB_ICONEXCLAMATION | MB_OK);
4835 * Display error message and quit (see "z-util.c")
4837 static void hook_quit(cptr str)
4842 /* Give a warning */
4846 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
4847 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4849 MessageBox(data[0].w, str, "Error",
4850 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4856 /* Save the preferences */
4860 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
4862 /* Destroy all windows */
4863 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
4865 term_force_font(&data[i], NULL);
4866 if (data[i].font_want) string_free(data[i].font_want);
4867 if (data[i].w) DestroyWindow(data[i].w);
4871 /* Free the bitmap stuff */
4873 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
4874 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
4876 #ifdef USE_TRANSPARENCY
4877 if (infMask.hPalette) DeleteObject(infMask.hPalette);
4878 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
4879 #endif /* USE_TRANSPARENCY */
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)
5066 if (hPrevInst == NULL)
5068 wc.style = CS_CLASSDC;
5069 wc.lpfnWndProc = AngbandWndProc;
5071 wc.cbWndExtra = 4; /* one long pointer to term_data */
5072 wc.hInstance = hInst;
5073 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5074 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5075 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5076 wc.lpszMenuName = AppName;
5077 wc.lpszClassName = AppName;
5079 if (!RegisterClass(&wc)) exit(1);
5081 wc.lpfnWndProc = AngbandListProc;
5082 wc.lpszMenuName = NULL;
5083 wc.lpszClassName = AngList;
5085 if (!RegisterClass(&wc)) exit(2);
5089 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5090 wc.lpfnWndProc = AngbandSaverProc;
5092 wc.lpszMenuName = NULL;
5093 wc.lpszClassName = "WindowsScreenSaverClass";
5095 if (!RegisterClass(&wc)) exit(3);
5101 /* Temporary hooks */
5102 plog_aux = hack_plog;
5103 quit_aux = hack_quit;
5104 core_aux = hack_quit;
5106 /* Prepare the filepaths */
5109 /* Initialize the keypress analyzer */
5110 for (i = 0; special_key_list[i]; ++i)
5112 special_key[special_key_list[i]] = TRUE;
5114 /* Initialize the keypress analyzer */
5115 for (i = 0; ignore_key_list[i]; ++i)
5117 ignore_key[ignore_key_list[i]] = TRUE;
5120 /* Determine if display is 16/256/true color */
5122 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5123 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5124 ReleaseDC(NULL, hdc);
5126 /* Initialize the colors */
5127 for (i = 0; i < 256; i++)
5131 /* Extract desired values */
5132 rv = angband_color_table[i][1];
5133 gv = angband_color_table[i][2];
5134 bv = angband_color_table[i][3];
5136 /* Extract the "complex" code */
5137 win_clr[i] = PALETTERGB(rv, gv, bv);
5139 /* Save the "simple" code */
5140 angband_color_table[i][0] = win_pal[i];
5143 /* Prepare the windows */
5149 /* Activate hooks */
5150 plog_aux = hook_plog;
5151 quit_aux = hook_quit;
5152 core_aux = hook_quit;
5154 /* Set the system suffix */
5155 ANGBAND_SYS = "win";
5157 /* Set the keyboard suffix */
5158 if (7 != GetKeyboardType(0))
5159 ANGBAND_KEYBOARD = "0";
5162 /* Japanese keyboard */
5163 switch (GetKeyboardType(1))
5165 case 0x0D01: case 0x0D02:
5166 case 0x0D03: case 0x0D04:
5167 case 0x0D05: case 0x0D06:
5169 ANGBAND_KEYBOARD = "NEC98";
5173 ANGBAND_KEYBOARD = "JAPAN";
5181 /* We are now initialized */
5185 if(lpCmdLine[0] == '-'){
5186 switch(lpCmdLine[1])
5191 if (!lpCmdLine[2]) break;
5192 chuukei_server = TRUE;
5193 if(connect_chuukei_server(&lpCmdLine[2])<0){
5194 msg_print("connect fail");
5197 msg_print("connect");
5205 if (!lpCmdLine[2]) break;
5206 chuukei_client = TRUE;
5207 connect_chuukei_server(&lpCmdLine[2]);
5217 /* Did the user double click on a save file? */
5218 if(!chuukei_server) check_for_save_file(lpCmdLine);
5220 /* Did the user double click on a save file? */
5221 check_for_save_file(lpCmdLine);
5224 /* Prompt the user */
5226 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5228 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5233 /* Process messages forever */
5234 while (GetMessage(&msg, NULL, 0, 0))
5236 TranslateMessage(&msg);
5237 DispatchMessage(&msg);
5248 #endif /* WINDOWS */