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 * The "simple" color values
570 * See "main-ibm.c" for original table information
572 * The entries below are taken from the "color bits" defined above.
574 * Note that many of the choices below suck, but so do crappy monitors.
576 static BYTE win_pal[256] =
578 VID_BLACK, /* Dark */
579 VID_WHITE, /* White */
580 VID_CYAN, /* Slate XXX */
581 VID_RED | VID_BRIGHT, /* Orange XXX */
583 VID_GREEN, /* Green */
585 VID_YELLOW, /* Umber XXX */
586 VID_BLACK | VID_BRIGHT, /* Light Dark */
587 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
588 VID_MAGENTA, /* Violet XXX */
589 VID_YELLOW | VID_BRIGHT, /* Yellow */
590 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
591 VID_GREEN | VID_BRIGHT, /* Light Green */
592 VID_BLUE | VID_BRIGHT, /* Light Blue */
593 VID_YELLOW /* Light Umber XXX */
598 * Hack -- define which keys are "special"
600 static bool special_key[256];
601 static bool ignore_key[256];
605 * Hack -- initialization list for "special_key"
607 static byte special_key_list[] = {
608 VK_CLEAR,VK_PAUSE,VK_CAPITAL,VK_KANA,VK_JUNJA,VK_FINAL,VK_KANJI,
609 VK_CONVERT,VK_NONCONVERT,VK_ACCEPT,VK_MODECHANGE,
610 VK_PRIOR,VK_NEXT,VK_END,VK_HOME,VK_LEFT,VK_UP,VK_RIGHT,VK_DOWN,
611 VK_SELECT,VK_PRINT,VK_EXECUTE,VK_SNAPSHOT,VK_INSERT,VK_DELETE,
613 VK_F1,VK_F2,VK_F3,VK_F4,VK_F5,VK_F6,VK_F7,VK_F8,VK_F9,VK_F10,
614 VK_F11,VK_F12,VK_F13,VK_F14,VK_F15,VK_F16,VK_F17,VK_F18,VK_F19,VK_F20,
615 VK_F21,VK_F22,VK_F23,VK_F24,VK_NUMLOCK,VK_SCROLL,
616 VK_ATTN,VK_CRSEL,VK_EXSEL,VK_EREOF,VK_PLAY,VK_ZOOM,VK_NONAME,
620 static byte ignore_key_list[] = {
621 VK_ESCAPE,VK_TAB,VK_SPACE,
622 'F','W','O','H', /* these are menu characters.*/
623 VK_SHIFT,VK_CONTROL,VK_MENU,VK_LWIN,VK_RWIN,
624 VK_LSHIFT,VK_RSHIFT,VK_LCONTROL,VK_RCONTROL,VK_LMENU,VK_RMENU,0
629 * Hack -- initialization list for "special_key"
631 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
632 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
633 * catch the keypad keys (with and without numlock set, including keypad 5),
634 * the function keys (including the "menu" key which maps to F10), and the
635 * "pause" key (between scroll lock and numlock). We also catch a few odd
636 * keys which I do not recognize, but which are listed among keys which we
637 * do catch, so they should be harmless to catch.
639 static byte special_key_list[] =
641 VK_CLEAR, /* 0x0C (KP<5>) */
643 VK_PAUSE, /* 0x13 (pause) */
645 VK_PRIOR, /* 0x21 (KP<9>) */
646 VK_NEXT, /* 0x22 (KP<3>) */
647 VK_END, /* 0x23 (KP<1>) */
648 VK_HOME, /* 0x24 (KP<7>) */
649 VK_LEFT, /* 0x25 (KP<4>) */
650 VK_UP, /* 0x26 (KP<8>) */
651 VK_RIGHT, /* 0x27 (KP<6>) */
652 VK_DOWN, /* 0x28 (KP<2>) */
653 VK_SELECT, /* 0x29 (?????) */
654 VK_PRINT, /* 0x2A (?????) */
655 VK_EXECUTE, /* 0x2B (?????) */
656 VK_SNAPSHOT, /* 0x2C (?????) */
657 VK_INSERT, /* 0x2D (KP<0>) */
658 VK_DELETE, /* 0x2E (KP<.>) */
659 VK_HELP, /* 0x2F (?????) */
662 VK_NUMPAD0, /* 0x60 (KP<0>) */
663 VK_NUMPAD1, /* 0x61 (KP<1>) */
664 VK_NUMPAD2, /* 0x62 (KP<2>) */
665 VK_NUMPAD3, /* 0x63 (KP<3>) */
666 VK_NUMPAD4, /* 0x64 (KP<4>) */
667 VK_NUMPAD5, /* 0x65 (KP<5>) */
668 VK_NUMPAD6, /* 0x66 (KP<6>) */
669 VK_NUMPAD7, /* 0x67 (KP<7>) */
670 VK_NUMPAD8, /* 0x68 (KP<8>) */
671 VK_NUMPAD9, /* 0x69 (KP<9>) */
672 VK_MULTIPLY, /* 0x6A (KP<*>) */
673 VK_ADD, /* 0x6B (KP<+>) */
674 VK_SEPARATOR, /* 0x6C (?????) */
675 VK_SUBTRACT, /* 0x6D (KP<->) */
676 VK_DECIMAL, /* 0x6E (KP<.>) */
677 VK_DIVIDE, /* 0x6F (KP</>) */
710 static void delete_bg(void)
719 static int init_bg(void)
721 char * bmfile = bg_bitmap_file;
724 if (use_bg == 0) return 0;
726 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
729 plog_fmt("ÊÉ»æÍÑ¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
731 plog_fmt("Can't load the bitmap file '%s'.", bmfile);
737 HDC wnddc, dcimage, dcbg;
738 HBITMAP bmimage, bmimage_old, bmbg_old;
744 dcimage = CreateCompatibleDC(wnddc);
745 dcbg = CreateCompatibleDC(wnddc);
747 bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
748 if (!bmimage) quit("bg.bmp¤¬Æɤߤ³¤á¤Ê¤¤¡ª");
749 bmimage_old = SelectObject(dcimage, bmimage);
751 CreateCompatibleBitmap();
753 ReleaseDC(hwnd, wnddc);
759 static void DrawBG(HDC hdc, RECT *r)
764 int x = r->left, y = r->top;
765 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
771 GetObject(hBG, sizeof(bm), &bm);
772 swid = bm.bmWidth; shgt = bm.bmHeight;
774 hdcSrc = CreateCompatibleDC(hdc);
775 hOld = SelectObject(hdcSrc, hBG);
779 cwid = MIN(swid - sx, r->right - nx);
782 chgt = MIN(shgt - sy, r->bottom - ny);
783 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
785 } while (ny < r->bottom);
788 } while (nx < r->right);
790 SelectObject(hdcSrc, hOld);
796 * Hack -- given a pathname, point at the filename
798 static cptr extract_file_name(cptr s)
802 /* Start at the end */
803 p = s + strlen(s) - 1;
805 /* Back up to divider */
806 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
808 /* Return file name */
815 * Hack -- given a simple filename, extract the "font size" info
817 * Return a pointer to a static buffer holding the capitalized base name.
820 static char *analyze_font(char *path, int *wp, int *hp)
826 /* Start at the end */
827 p = path + strlen(path) - 1;
829 /* Back up to divider */
830 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
832 /* Advance to file name */
838 /* Capitalize (be paranoid) */
839 if (islower(*s)) *s = toupper(*s);
845 /* Extract font width */
849 hgt = s ? atoi(s+1) : 0;
862 * Check for existance of a file
864 static bool check_file(cptr s)
884 attrib = GetFileAttributes(path);
886 /* Require valid filename */
887 if (attrib == INVALID_FILE_NAME) return (FALSE);
889 /* Prohibit directory */
890 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
894 /* Examine and verify */
895 if (_dos_getfileattr(path, &attrib)) return (FALSE);
897 /* Prohibit something */
898 if (attrib & FA_LABEL) return (FALSE);
900 /* Prohibit directory */
901 if (attrib & FA_DIREC) return (FALSE);
911 * Check for existance of a directory
913 static bool check_dir(cptr s)
935 /* Remove trailing backslash */
936 if (i && (path[i-1] == '\\')) path[--i] = '\0';
941 attrib = GetFileAttributes(path);
943 /* Require valid filename */
944 if (attrib == INVALID_FILE_NAME) return (FALSE);
946 /* Require directory */
947 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
951 /* Examine and verify */
952 if (_dos_getfileattr(path, &attrib)) return (FALSE);
954 /* Prohibit something */
955 if (attrib & FA_LABEL) return (FALSE);
957 /* Require directory */
958 if (!(attrib & FA_DIREC)) return (FALSE);
970 static void validate_file(cptr s)
976 quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
978 quit_fmt("Cannot find required file:\n%s", s);
986 * Validate a directory
988 static void validate_dir(cptr s, bool vital)
993 /* This directory contains needed data */
997 quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
999 quit_fmt("Cannot find required directory:\n%s", s);
1003 /* Attempt to create this directory */
1006 quit_fmt("Unable to create directory:\n%s", s);
1013 * Get the "size" for a window
1015 static void term_getsize(term_data *td)
1022 if (td->cols < 1) td->cols = 1;
1023 if (td->rows < 1) td->rows = 1;
1026 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1027 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1029 /* Fake window size */
1031 rc.right = rc.left + wid;
1033 rc.bottom = rc.top + hgt;
1036 /* rc.right += 1; */
1037 /* rc.bottom += 1; */
1040 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1043 td->size_wid = rc.right - rc.left;
1044 td->size_hgt = rc.bottom - rc.top;
1046 /* See CreateWindowEx */
1049 /* Extract actual location */
1050 GetWindowRect(td->w, &rc);
1052 /* Save the location */
1053 td->pos_x = rc.left;
1059 * Write the "prefs" for a single term
1061 static void save_prefs_aux(term_data *td, cptr sec_name)
1071 strcpy(buf, td->visible ? "1" : "0");
1072 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1076 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1078 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1081 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1084 wsprintf(buf, "%d", td->lf.lfWidth);
1085 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1086 wsprintf(buf, "%d", td->lf.lfHeight);
1087 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1088 wsprintf(buf, "%d", td->lf.lfWeight);
1089 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1092 strcpy(buf, td->bizarre ? "1" : "0");
1093 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1096 wsprintf(buf, "%d", td->tile_wid);
1097 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1100 wsprintf(buf, "%d", td->tile_hgt);
1101 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1103 /* Window size (x) */
1104 wsprintf(buf, "%d", td->cols);
1105 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1107 /* Window size (y) */
1108 wsprintf(buf, "%d", td->rows);
1109 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1111 /* Acquire position */
1112 GetWindowRect(td->w, &rc);
1114 /* Window position (x) */
1115 wsprintf(buf, "%d", rc.left);
1116 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1118 /* Window position (y) */
1119 wsprintf(buf, "%d", rc.top);
1120 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1122 /* Window Z position */
1123 strcpy(buf, td->posfix ? "1" : "0");
1124 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1131 * We assume that the windows have all been initialized
1133 static void save_prefs(void)
1139 /* Save the "arg_graphics" flag */
1140 sprintf(buf, "%d", arg_graphics);
1141 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1143 /* Save the "arg_bigtile" flag */
1144 strcpy(buf, arg_bigtile ? "1" : "0");
1145 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1147 /* Save the "arg_sound" flag */
1148 strcpy(buf, arg_sound ? "1" : "0");
1149 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1152 strcpy(buf, use_bg ? "1" : "0");
1153 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1154 WritePrivateProfileString("Angband", "BackGroundBitmap",
1155 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1157 /* Save window prefs */
1158 for (i = 0; i < MAX_TERM_DATA; ++i)
1160 term_data *td = &data[i];
1162 sprintf(buf, "Term-%d", i);
1164 save_prefs_aux(td, buf);
1170 * Load the "prefs" for a single term
1172 static void load_prefs_aux(term_data *td, cptr sec_name)
1179 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1181 /* Desired font, with default */
1183 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1185 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1190 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1192 /* Analyze font, save desired font name */
1194 td->font_want = string_make(tmp);
1196 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1197 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1198 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1200 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1206 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1207 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1209 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1210 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1215 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1216 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1218 /* Window position */
1219 td->pos_x = GetPrivateProfileInt(sec_name, "PositionX", td->pos_x, ini_file);
1220 td->pos_y = GetPrivateProfileInt(sec_name, "PositionY", td->pos_y, ini_file);
1222 /* Window Z position */
1223 td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1230 static void load_prefs(void)
1236 /* Extract the "arg_graphics" flag */
1237 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1239 /* Extract the "arg_bigtile" flag */
1240 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1241 use_bigtile = arg_bigtile;
1243 /* Extract the "arg_sound" flag */
1244 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1247 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1248 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1250 /* Load window prefs */
1251 for (i = 0; i < MAX_TERM_DATA; ++i)
1253 term_data *td = &data[i];
1255 sprintf(buf, "Term-%d", i);
1257 load_prefs_aux(td, buf);
1264 * XXX XXX XXX - Taken from files.c.
1266 * Extract "tokens" from a buffer
1268 * This function uses "whitespace" as delimiters, and treats any amount of
1269 * whitespace as a single delimiter. We will never return any empty tokens.
1270 * When given an empty buffer, or a buffer containing only "whitespace", we
1271 * will return no tokens. We will never extract more than "num" tokens.
1273 * By running a token through the "text_to_ascii()" function, you can allow
1274 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1276 * We save pointers to the tokens in "tokens", and return the number found.
1278 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1290 /* Skip leading whitespace */
1291 for ( ; *s && isspace(*s); ++s) /* loop */;
1296 /* Find next whitespace, if any */
1297 for (t = s; *t && !isspace(*t); ++t) /* loop */;
1299 /* Nuke and advance (if necessary) */
1300 if (*t) *t++ = '\0';
1302 /* Save the token */
1313 static void load_sound_prefs(void)
1317 char ini_path[1024];
1318 char wav_path[1024];
1319 char *zz[SAMPLE_MAX];
1321 /* Access the sound.cfg */
1322 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1324 for (i = 0; i < SOUND_MAX; i++)
1326 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1328 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1330 for (j = 0; j < num; j++)
1332 /* Access the sound */
1333 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1335 /* Save the sound filename, if it exists */
1336 if (check_file(wav_path))
1337 sound_file[i][j] = string_make(zz[j]);
1342 #endif /* USE_SOUND */
1345 * Create the new global palette based on the bitmap palette
1346 * (if any), and the standard 16 entry palette derived from
1347 * "win_clr[]" which is used for the basic 16 Angband colors.
1349 * This function is never called before all windows are ready.
1351 * This function returns FALSE if the new palette could not be
1352 * prepared, which should normally be a fatal error. XXX XXX
1354 * Note that only some machines actually use a "palette".
1356 static int new_palette(void)
1364 LPLOGPALETTE pLogPal;
1365 LPPALETTEENTRY lppe;
1370 /* This makes no sense */
1371 if (!paletted) return (TRUE);
1381 /* Check the bitmap palette */
1382 hBmPal = infGraph.hPalette;
1384 /* Use the bitmap */
1387 lppeSize = 256 * sizeof(PALETTEENTRY);
1388 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1389 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1390 if ((nEntries == 0) || (nEntries > 220))
1394 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1396 plog("Please switch to high- or true-color mode.");
1401 rnfree(lppe, lppeSize);
1408 #endif /* USE_GRAPHICS */
1410 /* Size of palette */
1411 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1413 /* Allocate palette */
1414 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1417 pLogPal->palVersion = 0x300;
1419 /* Make room for bitmap and normal data */
1420 pLogPal->palNumEntries = nEntries + 16;
1422 /* Save the bitmap data */
1423 for (i = 0; i < nEntries; i++)
1425 pLogPal->palPalEntry[i] = lppe[i];
1428 /* Save the normal data */
1429 for (i = 0; i < 16; i++)
1433 /* Access the entry */
1434 p = &(pLogPal->palPalEntry[i+nEntries]);
1436 /* Save the colors */
1437 p->peRed = GetRValue(win_clr[i]);
1438 p->peGreen = GetGValue(win_clr[i]);
1439 p->peBlue = GetBValue(win_clr[i]);
1441 /* Save the flags */
1442 p->peFlags = PC_NOCOLLAPSE;
1445 /* Free something */
1446 if (lppe) rnfree(lppe, lppeSize);
1448 /* Create a new palette, or fail */
1449 hNewPal = CreatePalette(pLogPal);
1451 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1453 if (!hNewPal) quit("Cannot create palette!");
1457 /* Free the palette */
1458 rnfree(pLogPal, pLogPalSize);
1463 /* Realize the palette */
1465 SelectPalette(hdc, hNewPal, 0);
1466 i = RealizePalette(hdc);
1467 ReleaseDC(td->w, hdc);
1469 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1471 if (i == 0) quit("Cannot realize palette!");
1476 for (i = 1; i < MAX_TERM_DATA; i++)
1481 SelectPalette(hdc, hNewPal, 0);
1482 ReleaseDC(td->w, hdc);
1485 /* Delete old palette */
1486 if (hPal) DeleteObject(hPal);
1488 /* Save new palette */
1498 * Initialize graphics
1500 static bool init_graphics(void)
1502 /* Initialize once */
1503 /* if (can_use_graphics != arg_graphics) */
1509 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1516 ANGBAND_GRAF = "new";
1524 ANGBAND_GRAF = "old";
1527 /* Access the bitmap file */
1528 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1530 /* Load the bitmap or quit */
1531 if (!ReadDIB(data[0].w, buf, &infGraph))
1534 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1536 plog_fmt("Cannot read bitmap file '%s'", name);
1542 /* Save the new sizes */
1543 infGraph.CellWidth = wid;
1544 infGraph.CellHeight = hgt;
1546 #ifdef USE_TRANSPARENCY
1548 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1550 /* Access the mask file */
1551 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1553 /* Load the bitmap or quit */
1554 if (!ReadDIB(data[0].w, buf, &infMask))
1556 plog_fmt("Cannot read bitmap file '%s'", buf);
1561 #endif /* USE_TRANSPARENCY */
1563 /* Activate a palette */
1566 /* Free bitmap XXX XXX XXX */
1570 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1572 plog("Cannot activate palette!");
1578 /* Graphics available */
1579 can_use_graphics = arg_graphics;
1583 return (can_use_graphics);
1585 #endif /* USE_GRAPHICS */
1592 static bool init_sound(void)
1594 /* Initialize once */
1597 /* Load the prefs */
1600 /* Sound available */
1601 can_use_sound = TRUE;
1605 return (can_use_sound);
1607 #endif /* USE_SOUND */
1613 static void term_window_resize(term_data *td)
1615 /* Require window */
1618 /* Resize the window */
1619 SetWindowPos(td->w, 0, 0, 0,
1620 td->size_wid, td->size_hgt,
1621 SWP_NOMOVE | SWP_NOZORDER);
1624 InvalidateRect(td->w, NULL, TRUE);
1629 * Force the use of a new "font file" for a term_data
1631 * This function may be called before the "window" is ready
1633 * This function returns zero only if everything succeeds.
1635 * Note that the "font name" must be capitalized!!!
1637 static errr term_force_font(term_data *td, cptr path)
1647 /* Forget the old font (if needed) */
1648 if (td->font_id) DeleteObject(td->font_id);
1651 /* Forget old font */
1657 for (i = 0; i < MAX_TERM_DATA; i++)
1659 /* Don't check when closing the application */
1662 /* Check "screen" */
1663 if ((td != &data[i]) &&
1664 (data[i].font_file) &&
1665 (streq(data[i].font_file, td->font_file)))
1671 /* Remove unused font resources */
1672 if (!used) RemoveFontResource(td->font_file);
1674 /* Free the old name */
1675 string_free(td->font_file);
1678 td->font_file = NULL;
1683 if (!path) return (1);
1689 /* Analyze font path */
1690 base = analyze_font(buf, &wid, &hgt);
1693 if (!suffix(base, ".FON")) return (1);
1696 if (!check_file(buf)) return (1);
1698 /* Load the new font */
1699 if (!AddFontResource(buf)) return (1);
1701 /* Save new font name */
1702 td->font_file = string_make(base);
1704 /* Remove the "suffix" */
1705 base[strlen(base)-4] = '\0';
1708 /* Create the font (using the 'base' of the font file name!) */
1710 td->font_id = CreateFontIndirect(&(td->lf));
1711 wid = td->lf.lfWidth;
1712 hgt = td->lf.lfHeight;
1713 if (!td->font_id) return (1);
1715 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1716 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1717 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1718 FIXED_PITCH | FF_DONTCARE, base);
1722 /* Hack -- Unknown size */
1729 /* all this trouble to get the cell size */
1730 hdcDesktop = GetDC(HWND_DESKTOP);
1731 hfOld = SelectObject(hdcDesktop, td->font_id);
1732 GetTextMetrics(hdcDesktop, &tm);
1733 SelectObject(hdcDesktop, hfOld);
1734 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1736 /* Font size info */
1737 wid = tm.tmAveCharWidth;
1741 /* Save the size info */
1752 * Allow the user to change the font for this window.
1754 static void term_change_font(term_data *td)
1759 memset(&cf, 0, sizeof(cf));
1760 cf.lStructSize = sizeof(cf);
1761 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1762 cf.lpLogFont = &(td->lf);
1764 if (ChooseFont(&cf))
1766 /* Force the font */
1767 term_force_font(td, NULL);
1769 /* Assume not bizarre */
1772 /* Reset the tile info */
1773 td->tile_wid = td->font_wid;
1774 td->tile_hgt = td->font_hgt;
1776 /* Analyze the font */
1779 /* Resize the window */
1780 term_window_resize(td);
1786 char tmp[1024] = "";
1788 /* Extract a default if possible */
1789 if (td->font_file) strcpy(tmp, td->font_file);
1791 /* Ask for a choice */
1792 memset(&ofn, 0, sizeof(ofn));
1793 ofn.lStructSize = sizeof(ofn);
1794 ofn.hwndOwner = data[0].w;
1795 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1796 ofn.nFilterIndex = 1;
1797 ofn.lpstrFile = tmp;
1799 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1800 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1801 ofn.lpstrDefExt = "fon";
1803 /* Force choice if legal */
1804 if (GetOpenFileName(&ofn))
1806 /* Force the font */
1807 if (term_force_font(td, tmp))
1809 /* Access the standard font file */
1810 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1812 /* Force the use of that font */
1813 (void)term_force_font(td, tmp);
1816 /* Assume not bizarre */
1817 td->bizarre = FALSE;
1819 /* Reset the tile info */
1820 td->tile_wid = td->font_wid;
1821 td->tile_hgt = td->font_hgt;
1823 /* Analyze the font */
1826 /* Resize the window */
1827 term_window_resize(td);
1834 * Allow the user to lock this window.
1836 static void term_window_pos(term_data *td, HWND hWnd)
1838 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1839 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1842 static void windows_map(void);
1845 * Hack -- redraw a term_data
1847 static void term_data_redraw(term_data *td)
1851 /* Redraw the map */
1856 /* Activate the term */
1857 Term_activate(&td->t);
1859 /* Redraw the contents */
1862 /* Restore the term */
1863 Term_activate(term_screen);
1871 /*** Function hooks needed by "Term" ***/
1877 * Initialize a new Term
1879 static void Term_init_win(term *t)
1888 static void Term_nuke_win(term *t)
1897 * Interact with the User
1899 static errr Term_user_win(int n)
1907 * React to global changes
1909 static errr Term_xtra_win_react(void)
1917 /* Save the default colors */
1918 for (i = 0; i < 256; i++)
1920 /* Simply accept the desired colors */
1921 win_pal[i] = angband_color_table[i][0];
1932 bool change = FALSE;
1934 /* Save the default colors */
1935 for (i = 0; i < 256; i++)
1937 /* Extract desired values */
1938 rv = angband_color_table[i][1];
1939 gv = angband_color_table[i][2];
1940 bv = angband_color_table[i][3];
1942 /* Extract a full color code */
1943 code = PALETTERGB(rv, gv, bv);
1945 /* Activate changes */
1946 if (win_clr[i] != code)
1948 /* Note the change */
1951 /* Apply the desired color */
1956 /* Activate the palette if needed */
1957 if (change) (void)new_palette();
1963 /* Handle "arg_sound" */
1964 if (use_sound != arg_sound)
1966 /* Initialize (if needed) */
1967 if (arg_sound && !init_sound())
1971 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
1973 plog("Cannot initialize sound!");
1981 /* Change setting */
1982 use_sound = arg_sound;
1990 /* Handle "arg_graphics" */
1991 if (use_graphics != arg_graphics)
1993 /* Initialize (if needed) */
1994 if (arg_graphics && !init_graphics())
1998 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
2000 plog("Cannot initialize graphics!");
2005 arg_graphics = GRAPHICS_NONE;
2008 /* Change setting */
2009 use_graphics = arg_graphics;
2012 #ifdef ANGBAND_2_8_1
2014 #else /* ANGBAND_2_8_1 */
2015 reset_visuals(TRUE);
2016 #endif /* ANGBAND_2_8_1 */
2019 #endif /* USE_GRAPHICS */
2022 /* Clean up windows */
2023 for (i = 0; i < MAX_TERM_DATA; i++)
2027 term_data *td = &data[i];
2029 /* Update resized windows */
2030 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2033 Term_activate(&td->t);
2035 /* Hack -- Resize the term */
2036 Term_resize(td->cols, td->rows);
2038 /* Redraw the contents */
2053 * Process at least one event
2055 static errr Term_xtra_win_event(int v)
2059 /* Wait for an event */
2063 if (GetMessage(&msg, NULL, 0, 0))
2065 TranslateMessage(&msg);
2066 DispatchMessage(&msg);
2070 /* Check for an event */
2074 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2076 TranslateMessage(&msg);
2077 DispatchMessage(&msg);
2087 * Process all pending events
2089 static errr Term_xtra_win_flush(void)
2093 /* Process all pending events */
2094 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2096 TranslateMessage(&msg);
2097 DispatchMessage(&msg);
2106 * Hack -- clear the screen
2108 * Make this more efficient XXX XXX XXX
2110 static errr Term_xtra_win_clear(void)
2112 term_data *td = (term_data*)(Term->data);
2117 /* Rectangle to erase */
2118 rc.left = td->size_ow1;
2119 rc.right = rc.left + td->cols * td->tile_wid;
2120 rc.top = td->size_oh1;
2121 rc.bottom = rc.top + td->rows * td->tile_hgt;
2125 SetBkColor(hdc, RGB(0, 0, 0));
2126 SelectObject(hdc, td->font_id);
2127 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2132 rc.left = 0; rc.top = 0;
2135 ReleaseDC(td->w, hdc);
2143 * Hack -- make a noise
2145 static errr Term_xtra_win_noise(void)
2147 MessageBeep(MB_ICONASTERISK);
2153 * Hack -- make a sound
2155 static errr Term_xtra_win_sound(int v)
2160 #endif /* USE_SOUND */
2162 /* Sound disabled */
2163 if (!use_sound) return (1);
2166 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2170 /* Count the samples */
2171 for (i = 0; i < SAMPLE_MAX; i++)
2173 if (!sound_file[v][i])
2178 if (i == 0) return (1);
2180 /* Build the path */
2181 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_simple(i)]);
2185 /* Play the sound, catch errors */
2186 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2190 /* Play the sound, catch errors */
2191 return (sndPlaySound(buf, SND_ASYNC));
2195 #else /* USE_SOUND */
2200 #endif /* USE_SOUND */
2205 * Delay for "x" milliseconds
2207 static int Term_xtra_win_delay(int v)
2221 t = GetTickCount() + v;
2224 while (GetTickCount() < t)
2226 /* Handle messages */
2227 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2229 TranslateMessage(&msg);
2230 DispatchMessage(&msg);
2242 * Do a "special thing"
2244 static errr Term_xtra_win(int n, int v)
2246 /* Handle a subset of the legal requests */
2249 /* Make a bell sound */
2250 case TERM_XTRA_NOISE:
2252 return (Term_xtra_win_noise());
2255 /* Make a special sound */
2256 case TERM_XTRA_SOUND:
2258 return (Term_xtra_win_sound(v));
2261 /* Process random events */
2262 case TERM_XTRA_BORED:
2264 return (Term_xtra_win_event(0));
2267 /* Process an event */
2268 case TERM_XTRA_EVENT:
2270 return (Term_xtra_win_event(v));
2273 /* Flush all events */
2274 case TERM_XTRA_FLUSH:
2276 return (Term_xtra_win_flush());
2279 /* Clear the screen */
2280 case TERM_XTRA_CLEAR:
2282 return (Term_xtra_win_clear());
2285 /* React to global changes */
2286 case TERM_XTRA_REACT:
2288 return (Term_xtra_win_react());
2291 /* Delay for some milliseconds */
2292 case TERM_XTRA_DELAY:
2294 return (Term_xtra_win_delay(v));
2305 * Low level graphics (Assumes valid input).
2307 * Draw a "cursor" at (x,y), using a "yellow box".
2309 static errr Term_curs_win(int x, int y)
2311 term_data *td = (term_data*)(Term->data);
2316 int tile_wid, tile_hgt;
2320 tile_wid = td->map_tile_wid;
2321 tile_hgt = td->map_tile_hgt;
2325 tile_wid = td->tile_wid;
2326 tile_hgt = td->tile_hgt;
2329 /* Frame the grid */
2330 rc.left = x * tile_wid + td->size_ow1;
2331 rc.right = rc.left + tile_wid;
2332 rc.top = y * tile_hgt + td->size_oh1;
2333 rc.bottom = rc.top + tile_hgt;
2335 /* Cursor is done as a yellow "box" */
2337 FrameRect(hdc, &rc, hbrYellow);
2338 ReleaseDC(td->w, hdc);
2346 * Low level graphics (Assumes valid input).
2348 * Draw a "big cursor" at (x,y), using a "yellow box".
2350 static errr Term_bigcurs_win(int x, int y)
2352 term_data *td = (term_data*)(Term->data);
2357 int tile_wid, tile_hgt;
2361 /* Normal cursor in map window */
2362 Term_curs_win(x, y);
2367 tile_wid = td->tile_wid;
2368 tile_hgt = td->tile_hgt;
2371 /* Frame the grid */
2372 rc.left = x * tile_wid + td->size_ow1;
2373 rc.right = rc.left + 2 * tile_wid;
2374 rc.top = y * tile_hgt + td->size_oh1;
2375 rc.bottom = rc.top + tile_hgt;
2377 /* Cursor is done as a yellow "box" */
2379 FrameRect(hdc, &rc, hbrYellow);
2380 ReleaseDC(td->w, hdc);
2388 * Low level graphics (Assumes valid input).
2390 * Erase a "block" of "n" characters starting at (x,y).
2392 static errr Term_wipe_win(int x, int y, int n)
2394 term_data *td = (term_data*)(Term->data);
2399 /* Rectangle to erase in client coords */
2400 rc.left = x * td->tile_wid + td->size_ow1;
2401 rc.right = rc.left + n * td->tile_wid;
2402 rc.top = y * td->tile_hgt + td->size_oh1;
2403 rc.bottom = rc.top + td->tile_hgt;
2406 SetBkColor(hdc, RGB(0, 0, 0));
2407 SelectObject(hdc, td->font_id);
2412 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2413 ReleaseDC(td->w, hdc);
2421 * Low level graphics. Assumes valid input.
2423 * Draw several ("n") chars, with an attr, at a given location.
2425 * All "graphic" data is handled by "Term_pict_win()", below.
2427 * One would think there is a more efficient method for telling a window
2428 * what color it should be using to draw with, but perhaps simply changing
2429 * it every time is not too inefficient. XXX XXX XXX
2431 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2433 term_data *td = (term_data*)(Term->data);
2439 static HBITMAP WALL;
2440 static HBRUSH myBrush, oldBrush;
2442 static bool init_done = FALSE;
2445 WALL = LoadBitmap(hInstance, AppName);
2446 myBrush = CreatePatternBrush(WALL);
2451 /* Total rectangle */
2452 rc.left = x * td->tile_wid + td->size_ow1;
2453 rc.right = rc.left + n * td->tile_wid;
2454 rc.top = y * td->tile_hgt + td->size_oh1;
2455 rc.bottom = rc.top + td->tile_hgt;
2460 /* Background color */
2461 SetBkColor(hdc, RGB(0, 0, 0));
2463 /* Foreground color */
2466 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2470 SetTextColor(hdc, win_clr[a&0x0F]);
2474 SetTextColor(hdc, win_clr[a]);
2478 SelectObject(hdc, td->font_id);
2481 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2485 (td->tile_hgt != td->font_hgt) ||
2486 (td->tile_wid != td->font_wid))
2490 /* Erase complete rectangle */
2491 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2494 if (use_bg) DrawBG(hdc, &rc);
2497 rc.left += ((td->tile_wid - td->font_wid) / 2);
2498 rc.right = rc.left + td->font_wid;
2499 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2500 rc.bottom = rc.top + td->font_hgt;
2502 /* Dump each character */
2503 for (i = 0; i < n; i++)
2506 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2508 rc.right += td->font_wid;
2510 oldBrush = SelectObject(hdc, myBrush);
2511 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2514 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2516 SelectObject(hdc, oldBrush);
2517 SelectObject(hdc, oldPen);
2518 rc.right -= td->font_wid;
2522 rc.left += 2 * td->tile_wid;
2523 rc.right += 2 * td->tile_wid;
2525 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2527 rc.right += td->font_wid;
2529 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2531 rc.right -= td->font_wid;
2535 rc.left += 2 * td->tile_wid;
2536 rc.right += 2 * td->tile_wid;
2537 } else if (*(s+i)==127){
2538 oldBrush = SelectObject(hdc, myBrush);
2539 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2542 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2544 SelectObject(hdc, oldBrush);
2545 SelectObject(hdc, oldPen);
2548 rc.left += td->tile_wid;
2549 rc.right += td->tile_wid;
2552 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2556 rc.left += td->tile_wid;
2557 rc.right += td->tile_wid;
2561 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2565 rc.left += td->tile_wid;
2566 rc.right += td->tile_wid;
2576 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2581 ReleaseDC(td->w, hdc);
2589 * Low level graphics. Assumes valid input.
2591 * Draw an array of "special" attr/char pairs at the given location.
2593 * We use the "Term_pict_win()" function for "graphic" data, which are
2594 * encoded by setting the "high-bits" of both the "attr" and the "char"
2595 * data. We use the "attr" to represent the "row" of the main bitmap,
2596 * and the "char" to represent the "col" of the main bitmap. The use
2597 * of this function is induced by the "higher_pict" flag.
2599 * If "graphics" is not available, we simply "wipe" the given grids.
2601 # ifdef USE_TRANSPARENCY
2602 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2603 # else /* USE_TRANSPARENCY */
2604 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp)
2605 # endif /* USE_TRANSPARENCY */
2607 term_data *td = (term_data*)(Term->data);
2613 int x2, y2, w2, h2, tw2;
2615 # ifdef USE_TRANSPARENCY
2621 # endif /* USE_TRANSPARENCY */
2630 /* Erase the grids */
2631 return (Term_wipe_win(x, y, n));
2634 /* Size of bitmap cell */
2635 w1 = infGraph.CellWidth;
2636 h1 = infGraph.CellHeight;
2638 /* Size of window cell */
2641 w2 = td->map_tile_wid;
2642 h2 = td->map_tile_hgt;
2651 if (use_bigtile) tw2 *= 2;
2654 /* Location of window cell */
2655 x2 = x * w2 + td->size_ow1;
2656 y2 = y * h2 + td->size_oh1;
2662 hdcSrc = CreateCompatibleDC(hdc);
2663 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2665 # ifdef USE_TRANSPARENCY
2667 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2669 hdcMask = CreateCompatibleDC(hdc);
2670 SelectObject(hdcMask, infMask.hBitmap);
2673 # endif /* USE_TRANSPARENCY */
2675 /* Draw attr/char pairs */
2676 for (i = 0; i < n; i++, x2 += w2)
2681 /* Extract picture */
2682 int row = (a & 0x7F);
2683 int col = (c & 0x7F);
2685 /* Location of bitmap cell */
2689 # ifdef USE_TRANSPARENCY
2691 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2693 x3 = (tcp[i] & 0x7F) * w1;
2694 y3 = (tap[i] & 0x7F) * h1;
2697 if ((w1 == tw2) && (h1 == h2))
2699 /* Copy the terrain picture from the bitmap to the window */
2700 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2702 /* Mask out the tile */
2703 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2706 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2709 /* Need to stretch */
2712 /* Set the correct mode for stretching the tiles */
2713 SetStretchBltMode(hdc, COLORONCOLOR);
2715 /* Copy the terrain picture from the bitmap to the window */
2716 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
2718 /* Only draw if terrain and overlay are different */
2719 if ((x1 != x3) || (y1 != y3))
2721 /* Mask out the tile */
2722 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2725 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2731 # endif /* USE_TRANSPARENCY */
2735 if ((w1 == tw2) && (h1 == h2))
2737 /* Copy the picture from the bitmap to the window */
2738 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2741 /* Need to stretch */
2744 /* Set the correct mode for stretching the tiles */
2745 SetStretchBltMode(hdc, COLORONCOLOR);
2747 /* Copy the picture from the bitmap to the window */
2748 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2754 SelectObject(hdcSrc, hbmSrcOld);
2757 # ifdef USE_TRANSPARENCY
2759 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2762 SelectObject(hdcMask, hbmSrcOld);
2766 # endif /* USE_TRANSPARENCY */
2769 ReleaseDC(td->w, hdc);
2771 #else /* USE_GRAPHICS */
2773 /* Just erase this grid */
2774 return (Term_wipe_win(x, y, n));
2776 #endif /* USE_GRAPHICS */
2783 static void windows_map(void)
2785 term_data *td = &data[0];
2787 int x, min_x, max_x;
2788 int y, min_y, max_y;
2790 #ifdef USE_TRANSPARENCY
2794 /* Only in graphics mode */
2795 if (!use_graphics) return;
2798 Term_xtra_win_clear();
2800 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2801 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2802 td->map_active = TRUE;
2812 for (x = min_x; x < max_x; x++)
2814 for (y = min_y; y < max_y; y++)
2816 #ifdef USE_TRANSPARENCY
2817 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
2818 #else /* USE_TRANSPARENCY */
2819 map_info(y, x, &a, (char*)&c);
2820 #endif /* USE_TRANSPARENCY */
2822 /* Ignore non-graphics */
2823 if ((a & 0x80) && (c & 0x80))
2825 #ifdef USE_TRANSPARENCY
2826 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2827 #else /* USE_TRANSPARENCY */
2828 Term_pict_win(x - min_x, y - min_y, 1, &a, &c);
2829 #endif /* USE_TRANSPARENCY */
2834 /* Hilite the player */
2835 Term_curs_win(px - min_x, py - min_y);
2837 /* Wait for a keypress, flush key buffer */
2838 Term_inkey(&c, TRUE, TRUE);
2841 /* Switch off the map display */
2842 td->map_active = FALSE;
2844 /* Restore screen */
2845 Term_xtra_win_clear();
2850 /*** Other routines ***/
2854 * Create and initialize a "term_data" given a title
2856 static void term_data_link(term_data *td)
2860 /* Initialize the term */
2861 term_init(t, td->cols, td->rows, td->keys);
2863 /* Use a "software" cursor */
2864 t->soft_cursor = TRUE;
2866 /* Use "Term_pict" for "graphic" data */
2867 t->higher_pict = TRUE;
2869 /* Erase with "white space" */
2870 t->attr_blank = TERM_WHITE;
2871 t->char_blank = ' ';
2874 /* Prepare the init/nuke hooks */
2875 t->init_hook = Term_init_win;
2876 t->nuke_hook = Term_nuke_win;
2879 /* Prepare the template hooks */
2880 t->user_hook = Term_user_win;
2881 t->xtra_hook = Term_xtra_win;
2882 t->curs_hook = Term_curs_win;
2883 t->bigcurs_hook = Term_bigcurs_win;
2884 t->wipe_hook = Term_wipe_win;
2885 t->text_hook = Term_text_win;
2886 t->pict_hook = Term_pict_win;
2888 /* Remember where we came from */
2889 t->data = (vptr)(td);
2894 * Create the windows
2896 * First, instantiate the "default" values, then read the "ini_file"
2897 * to over-ride selected values, then create the windows, and fonts.
2899 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2900 * must make active to realize the palette. XXX XXX XXX
2902 static void init_windows(void)
2914 WIPE(td, term_data);
2918 td->s = angband_term_name[0];
2937 for (i = 1; i < MAX_TERM_DATA; i++)
2940 WIPE(td, term_data);
2941 td->s = angband_term_name[i];
2945 td->visible = FALSE;
2950 td->pos_x = (7 - i) * 30;
2951 td->pos_y = (7 - i) * 20;
2963 /* Main window (need these before term_getsize gets called) */
2965 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2966 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2971 /* Sub windows (need these before term_getsize gets called) */
2972 for (i = 1; i < MAX_TERM_DATA; i++)
2975 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2976 td->dwExStyle = (WS_EX_TOOLWINDOW);
2981 for (i = 0; i < MAX_TERM_DATA; i++)
2986 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2987 td->lf.lfCharSet = SHIFTJIS_CHARSET;
2988 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2989 /* Activate the chosen font */
2990 term_force_font(td, NULL);
2991 td->tile_wid = td->font_wid;
2992 td->tile_hgt = td->font_hgt;
2994 /* Access the standard font file */
2995 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
2997 /* Activate the chosen font */
2998 if (term_force_font(td, buf))
3000 /* Access the standard font file */
3001 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3003 /* Force the use of that font */
3004 (void)term_force_font(td, buf);
3010 /* Assume not bizarre */
3011 td->bizarre = FALSE;
3016 /* Analyze the font */
3019 /* Resize the window */
3020 term_window_resize(td);
3024 /* Sub windows (reverse order) */
3025 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3030 td->w = CreateWindowEx(td->dwExStyle, AngList,
3032 td->pos_x, td->pos_y,
3033 td->size_wid, td->size_hgt,
3034 HWND_DESKTOP, NULL, hInstance, NULL);
3037 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3039 if (!td->w) quit("Failed to create sub-window");
3045 td->size_hack = TRUE;
3046 ShowWindow(td->w, SW_SHOW);
3047 td->size_hack = FALSE;
3051 angband_term[i] = &td->t;
3055 /* Activate the window */
3056 SetActiveWindow(td->w);
3061 term_window_pos(&data[i], HWND_TOPMOST);
3065 term_window_pos(&data[i], td->w);
3075 td->w = CreateWindowEx(td->dwExStyle, AppName,
3077 td->pos_x, td->pos_y,
3078 td->size_wid, td->size_hgt,
3079 HWND_DESKTOP, NULL, hInstance, NULL);
3082 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3084 if (!td->w) quit("Failed to create Angband window");
3089 angband_term[0] = &td->t;
3091 /* Activate the main window */
3092 SetActiveWindow(td->w);
3094 /* Bring main window back to top */
3095 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3098 /* New palette XXX XXX XXX */
3099 (void)new_palette();
3102 /* Create a "brush" for drawing the "cursor" */
3103 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3106 /* Process pending messages */
3107 (void)Term_xtra_win_flush();
3115 static void setup_menus(void)
3119 HMENU hm = GetMenu(data[0].w);
3122 /* Menu "File", Disable all */
3123 EnableMenuItem(hm, IDM_FILE_NEW,
3124 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3125 EnableMenuItem(hm, IDM_FILE_OPEN,
3126 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3127 EnableMenuItem(hm, IDM_FILE_SAVE,
3128 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3129 EnableMenuItem(hm, IDM_FILE_EXIT,
3130 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3131 EnableMenuItem(hm, IDM_FILE_SCORE,
3132 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3135 /* No character available */
3136 if (!character_generated)
3138 /* Menu "File", Item "New" */
3139 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3141 /* Menu "File", Item "Open" */
3142 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3145 /* A character available */
3146 if (character_generated)
3148 /* Menu "File", Item "Save" */
3149 EnableMenuItem(hm, IDM_FILE_SAVE,
3150 MF_BYCOMMAND | MF_ENABLED);
3153 /* Menu "File", Item "Exit" */
3154 EnableMenuItem(hm, IDM_FILE_EXIT,
3155 MF_BYCOMMAND | MF_ENABLED);
3157 EnableMenuItem(hm, IDM_FILE_SCORE,
3158 MF_BYCOMMAND | MF_ENABLED);
3161 /* Menu "Window::Visibility" */
3162 for (i = 0; i < MAX_TERM_DATA; i++)
3164 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3165 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3167 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3168 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3170 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3171 MF_BYCOMMAND | MF_ENABLED);
3174 /* Menu "Window::Font" */
3175 for (i = 0; i < MAX_TERM_DATA; i++)
3177 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3178 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3180 if (data[i].visible)
3182 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3183 MF_BYCOMMAND | MF_ENABLED);
3187 /* Menu "Window::Window Position Fix" */
3188 for (i = 0; i < MAX_TERM_DATA; i++)
3190 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3191 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3193 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3194 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3196 if (data[i].visible)
3198 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3199 MF_BYCOMMAND | MF_ENABLED);
3203 /* Menu "Window::Bizarre Display" */
3204 for (i = 0; i < MAX_TERM_DATA; i++)
3206 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3207 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3209 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3210 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3212 if (data[i].visible)
3214 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3215 MF_BYCOMMAND | MF_ENABLED);
3220 /* Menu "Window::Increase Tile Width" */
3221 for (i = 0; i < MAX_TERM_DATA; i++)
3223 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3224 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3226 if (data[i].visible)
3228 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3229 MF_BYCOMMAND | MF_ENABLED);
3234 /* Menu "Window::Decrease Tile Width" */
3235 for (i = 0; i < MAX_TERM_DATA; i++)
3237 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3238 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3240 if (data[i].visible)
3242 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3243 MF_BYCOMMAND | MF_ENABLED);
3248 /* Menu "Window::Increase Tile Height" */
3249 for (i = 0; i < MAX_TERM_DATA; i++)
3251 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3252 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3254 if (data[i].visible)
3256 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3257 MF_BYCOMMAND | MF_ENABLED);
3262 /* Menu "Window::Decrease Tile Height" */
3263 for (i = 0; i < MAX_TERM_DATA; i++)
3265 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3266 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3268 if (data[i].visible)
3270 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3271 MF_BYCOMMAND | MF_ENABLED);
3276 /* Menu "Options", disable all */
3277 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3278 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3279 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3280 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3281 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3282 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3283 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3284 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3285 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3286 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3288 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3289 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3292 /* Menu "Options", Item "Map" */
3293 if (use_graphics != GRAPHICS_NONE)
3294 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3296 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3297 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3299 /* Menu "Options", update all */
3300 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3301 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3302 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3303 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3304 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3305 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3306 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3307 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3308 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3309 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3310 CheckMenuItem(hm, IDM_OPTIONS_BG,
3311 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3313 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3314 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3318 /* Menu "Options", Item "Graphics" */
3319 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3320 /* Menu "Options", Item "Graphics" */
3321 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3322 /* Menu "Options", Item "Graphics" */
3323 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3324 /* Menu "Options", Item "Graphics" */
3325 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3326 #endif /* USE_GRAPHICS */
3329 /* Menu "Options", Item "Sound" */
3330 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3331 #endif /* USE_SOUND */
3334 /* Menu "Options", Item "ScreenSaver" */
3335 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3336 MF_BYCOMMAND | MF_ENABLED);
3337 #endif /* USE_SAVER */
3342 * Check for double clicked (or dragged) savefile
3344 * Apparently, Windows copies the entire filename into the first
3345 * piece of the "command line string". Perhaps we should extract
3346 * the "basename" of that filename and append it to the "save" dir.
3348 static void check_for_save_file(LPSTR cmd_line)
3358 /* Extract filename */
3359 strcat(savefile, s);
3361 /* Validate the file */
3362 validate_file(savefile);
3364 /* Game in progress */
3365 game_in_progress = TRUE;
3373 * Process a menu command
3375 static void process_menus(WORD wCmd)
3392 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3394 plog("You cannot do that yet...");
3398 else if (game_in_progress)
3401 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3403 plog("You can't start a new game while you're still playing!");
3409 game_in_progress = TRUE;
3423 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3425 plog("You cannot do that yet...");
3429 else if (game_in_progress)
3432 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3434 plog("You can't open a new game while you're still playing!");
3440 memset(&ofn, 0, sizeof(ofn));
3441 ofn.lStructSize = sizeof(ofn);
3442 ofn.hwndOwner = data[0].w;
3443 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3444 ofn.nFilterIndex = 1;
3445 ofn.lpstrFile = savefile;
3446 ofn.nMaxFile = 1024;
3447 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3448 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3450 if (GetOpenFileName(&ofn))
3452 /* Load 'savefile' */
3453 validate_file(savefile);
3454 game_in_progress = TRUE;
3466 if (game_in_progress && character_generated)
3472 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3474 plog("You may not do that right now.");
3480 /* Hack -- Forget messages */
3485 do_cmd_save_game(FALSE);
3486 #else /* ZANGBAND */
3488 #endif /* ZANGBAND */
3493 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3495 plog("You may not do that right now.");
3505 if (game_in_progress && character_generated)
3511 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3513 plog("You may not do that right now.");
3519 /* Hack -- Forget messages */
3528 /* do_cmd_save_game(FALSE); */
3529 #else /* ZANGBAND */
3530 /* do_cmd_save_game(); */
3531 #endif /* ZANGBAND */
3532 Term_key_push(SPECIAL_KEY_QUIT);
3540 case IDM_FILE_SCORE:
3544 /* Build the filename */
3545 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3547 /* Open the binary high score file, for reading */
3548 highscore_fd = fd_open(buf, O_RDONLY);
3550 /* Paranoia -- No score file */
3551 if (highscore_fd < 0)
3553 msg_print("Score file unavailable.");
3563 /* Display the scores */
3564 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3566 /* Shut the high score file */
3567 (void)fd_close(highscore_fd);
3569 /* Forget the high score fd */
3575 /* Hack - Flush it */
3583 case IDM_WINDOW_VIS_0:
3586 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3588 plog("You are not allowed to do that!");
3595 /* Window visibility */
3596 case IDM_WINDOW_VIS_1:
3597 case IDM_WINDOW_VIS_2:
3598 case IDM_WINDOW_VIS_3:
3599 case IDM_WINDOW_VIS_4:
3600 case IDM_WINDOW_VIS_5:
3601 case IDM_WINDOW_VIS_6:
3602 case IDM_WINDOW_VIS_7:
3604 i = wCmd - IDM_WINDOW_VIS_0;
3606 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3613 ShowWindow(td->w, SW_SHOW);
3614 term_data_redraw(td);
3618 td->visible = FALSE;
3620 ShowWindow(td->w, SW_HIDE);
3627 case IDM_WINDOW_FONT_0:
3628 case IDM_WINDOW_FONT_1:
3629 case IDM_WINDOW_FONT_2:
3630 case IDM_WINDOW_FONT_3:
3631 case IDM_WINDOW_FONT_4:
3632 case IDM_WINDOW_FONT_5:
3633 case IDM_WINDOW_FONT_6:
3634 case IDM_WINDOW_FONT_7:
3636 i = wCmd - IDM_WINDOW_FONT_0;
3638 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3642 term_change_font(td);
3647 /* Window Z Position */
3648 case IDM_WINDOW_POS_1:
3649 case IDM_WINDOW_POS_2:
3650 case IDM_WINDOW_POS_3:
3651 case IDM_WINDOW_POS_4:
3652 case IDM_WINDOW_POS_5:
3653 case IDM_WINDOW_POS_6:
3654 case IDM_WINDOW_POS_7:
3656 i = wCmd - IDM_WINDOW_POS_0;
3658 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3662 if (!td->posfix && td->visible)
3665 term_window_pos(td, HWND_TOPMOST);
3670 term_window_pos(td, data[0].w);
3676 /* Bizarre Display */
3677 case IDM_WINDOW_BIZ_0:
3678 case IDM_WINDOW_BIZ_1:
3679 case IDM_WINDOW_BIZ_2:
3680 case IDM_WINDOW_BIZ_3:
3681 case IDM_WINDOW_BIZ_4:
3682 case IDM_WINDOW_BIZ_5:
3683 case IDM_WINDOW_BIZ_6:
3684 case IDM_WINDOW_BIZ_7:
3686 i = wCmd - IDM_WINDOW_BIZ_0;
3688 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3692 td->bizarre = !td->bizarre;
3696 term_window_resize(td);
3701 /* Increase Tile Width */
3702 case IDM_WINDOW_I_WID_0:
3703 case IDM_WINDOW_I_WID_1:
3704 case IDM_WINDOW_I_WID_2:
3705 case IDM_WINDOW_I_WID_3:
3706 case IDM_WINDOW_I_WID_4:
3707 case IDM_WINDOW_I_WID_5:
3708 case IDM_WINDOW_I_WID_6:
3709 case IDM_WINDOW_I_WID_7:
3711 i = wCmd - IDM_WINDOW_I_WID_0;
3713 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3721 term_window_resize(td);
3726 /* Decrease Tile Height */
3727 case IDM_WINDOW_D_WID_0:
3728 case IDM_WINDOW_D_WID_1:
3729 case IDM_WINDOW_D_WID_2:
3730 case IDM_WINDOW_D_WID_3:
3731 case IDM_WINDOW_D_WID_4:
3732 case IDM_WINDOW_D_WID_5:
3733 case IDM_WINDOW_D_WID_6:
3734 case IDM_WINDOW_D_WID_7:
3736 i = wCmd - IDM_WINDOW_D_WID_0;
3738 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3746 term_window_resize(td);
3751 /* Increase Tile Height */
3752 case IDM_WINDOW_I_HGT_0:
3753 case IDM_WINDOW_I_HGT_1:
3754 case IDM_WINDOW_I_HGT_2:
3755 case IDM_WINDOW_I_HGT_3:
3756 case IDM_WINDOW_I_HGT_4:
3757 case IDM_WINDOW_I_HGT_5:
3758 case IDM_WINDOW_I_HGT_6:
3759 case IDM_WINDOW_I_HGT_7:
3761 i = wCmd - IDM_WINDOW_I_HGT_0;
3763 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3771 term_window_resize(td);
3776 /* Decrease Tile Height */
3777 case IDM_WINDOW_D_HGT_0:
3778 case IDM_WINDOW_D_HGT_1:
3779 case IDM_WINDOW_D_HGT_2:
3780 case IDM_WINDOW_D_HGT_3:
3781 case IDM_WINDOW_D_HGT_4:
3782 case IDM_WINDOW_D_HGT_5:
3783 case IDM_WINDOW_D_HGT_6:
3784 case IDM_WINDOW_D_HGT_7:
3786 i = wCmd - IDM_WINDOW_D_HGT_0;
3788 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3796 term_window_resize(td);
3801 case IDM_OPTIONS_NO_GRAPHICS:
3806 plog("You may not do that right now.");
3810 /* Toggle "arg_graphics" */
3811 if (arg_graphics != GRAPHICS_NONE)
3813 arg_graphics = GRAPHICS_NONE;
3815 /* React to changes */
3816 Term_xtra_win_react();
3818 /* Hack -- Force redraw */
3819 Term_key_push(KTRL('R'));
3825 case IDM_OPTIONS_OLD_GRAPHICS:
3830 plog("You may not do that right now.");
3834 /* Toggle "arg_graphics" */
3835 if (arg_graphics != GRAPHICS_ORIGINAL)
3837 arg_graphics = GRAPHICS_ORIGINAL;
3839 /* React to changes */
3840 Term_xtra_win_react();
3842 /* Hack -- Force redraw */
3843 Term_key_push(KTRL('R'));
3849 case IDM_OPTIONS_NEW_GRAPHICS:
3854 plog("You may not do that right now.");
3858 /* Toggle "arg_graphics" */
3859 if (arg_graphics != GRAPHICS_ADAM_BOLT)
3861 arg_graphics = GRAPHICS_ADAM_BOLT;
3863 /* React to changes */
3864 Term_xtra_win_react();
3866 /* Hack -- Force redraw */
3867 Term_key_push(KTRL('R'));
3873 case IDM_OPTIONS_BIGTILE:
3875 term_data *td = &data[0];
3880 plog("You may not do that right now.");
3884 /* Toggle "arg_sound" */
3885 arg_bigtile = !arg_bigtile;
3888 Term_activate(&td->t);
3890 /* Resize the term */
3891 Term_resize(td->cols, td->rows);
3894 InvalidateRect(td->w, NULL, TRUE);
3899 case IDM_OPTIONS_SOUND:
3904 plog("You may not do that right now.");
3908 /* Toggle "arg_sound" */
3909 arg_sound = !arg_sound;
3911 /* React to changes */
3912 Term_xtra_win_react();
3914 /* Hack -- Force redraw */
3915 Term_key_push(KTRL('R'));
3921 case IDM_OPTIONS_BG:
3926 plog("You may not do that right now.");
3930 /* Toggle "use_bg" */
3935 /* React to changes */
3936 Term_xtra_win_react();
3938 /* Hack -- Force redraw */
3939 Term_key_push(KTRL('R'));
3945 case IDM_OPTIONS_OPEN_BG:
3950 plog("You may not do that right now.");
3955 memset(&ofn, 0, sizeof(ofn));
3956 ofn.lStructSize = sizeof(ofn);
3957 ofn.hwndOwner = data[0].w;
3958 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3959 ofn.nFilterIndex = 1;
3960 ofn.lpstrFile = bg_bitmap_file;
3961 ofn.nMaxFile = 1023;
3962 ofn.lpstrInitialDir = NULL;
3964 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
3966 ofn.lpstrTitle = "Choose wall paper.";
3968 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3970 if (GetOpenFileName(&ofn))
3972 /* Load 'savefile' */
3977 /* React to changes */
3978 Term_xtra_win_react();
3980 /* Hack -- Force redraw */
3981 Term_key_push(KTRL('R'));
3986 case IDM_DUMP_SCREEN_HTML:
3988 static char buf[1024] = "";
3989 memset(&ofn, 0, sizeof(ofn));
3990 ofn.lStructSize = sizeof(ofn);
3991 ofn.hwndOwner = data[0].w;
3992 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
3993 ofn.nFilterIndex = 1;
3994 ofn.lpstrFile = buf;
3995 ofn.nMaxFile = 1023;
3996 ofn.lpstrDefExt = "html";
3997 ofn.lpstrInitialDir = NULL;
3999 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
4001 ofn.lpstrTitle = "Save screen dump as HTML.";
4003 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4005 if (GetSaveFileName(&ofn))
4007 do_cmd_save_screen_html_aux(buf, 0);
4014 case IDM_OPTIONS_SAVER:
4018 DestroyWindow(hwndSaver);
4023 /* Create a screen scaver window */
4024 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4025 "Angband Screensaver",
4026 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4027 0, 0, GetSystemMetrics(SM_CXSCREEN),
4028 GetSystemMetrics(SM_CYSCREEN),
4029 NULL, NULL, hInstance, NULL);
4033 /* Push the window to the bottom XXX XXX XXX */
4034 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4039 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
4041 plog("Failed to create saver window");
4051 case IDM_OPTIONS_MAP:
4057 case IDM_HELP_CONTENTS:
4061 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4062 if (check_file(tmp))
4064 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4069 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4070 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4072 plog_fmt("Cannot find help file: %s", tmp);
4073 plog("Use the online help files instead.");
4078 #else /* HTML_HELP */
4081 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4082 if (check_file(tmp))
4084 sprintf(buf, "winhelp.exe %s", tmp);
4085 WinExec(buf, SW_NORMAL);
4090 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4091 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4093 plog_fmt("Cannot find help file: %s", tmp);
4094 plog("Use the online help files instead.");
4099 #endif /* HTML_HELP */
4107 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4108 WPARAM wParam, LPARAM lParam);
4109 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4110 WPARAM wParam, LPARAM lParam)
4111 #else /* __MWERKS__ */
4112 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4113 WPARAM wParam, LPARAM lParam)
4114 #endif /* __MWERKS__ */
4120 MINMAXINFO FAR *lpmmi;
4126 /* Acquire proper "term_data" info */
4127 td = (term_data *)GetWindowLong(hWnd, 0);
4129 /* Handle message */
4135 SetWindowLong(hWnd, 0, (LONG)(my_td));
4145 case WM_GETMINMAXINFO:
4147 MINMAXINFO FAR *lpmmi;
4150 lpmmi = (MINMAXINFO FAR *)lParam;
4152 /* this message was sent before WM_NCCREATE */
4155 /* Minimum window size is 80x24 */
4156 rc.left = rc.top = 0;
4157 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4158 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4161 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4163 /* Save minimum size */
4164 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4165 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4172 BeginPaint(hWnd, &ps);
4173 if (td) term_data_redraw(td);
4174 EndPaint(hWnd, &ps);
4175 ValidateRect(hWnd, NULL);
4186 /* Extract the modifiers */
4187 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4188 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4189 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4191 /* Handle "special" keys */
4192 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4194 /* Begin the macro trigger */
4197 /* Send the modifiers */
4198 if (mc) Term_keypress('C');
4199 if (ms) Term_keypress('S');
4200 if (ma) Term_keypress('A');
4202 /* Extract "scan code" */
4203 i = LOBYTE(HIWORD(lParam));
4205 /* Introduce the scan code */
4208 /* Encode the hexidecimal scan code */
4209 Term_keypress(hexsym[i/16]);
4210 Term_keypress(hexsym[i%16]);
4212 /* End the macro trigger */
4223 Term_keypress(wParam);
4235 if (game_in_progress && character_generated)
4240 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4242 plog("You may not do that right now.");
4247 /* Hack -- Forget messages */
4256 /* do_cmd_save_game(FALSE); */
4257 #else /* ZANGBAND */
4258 /* do_cmd_save_game(); */
4259 #endif /* ZANGBAND */
4267 case WM_QUERYENDSESSION:
4269 if (game_in_progress && character_generated)
4271 /* Hack -- Forget messages */
4274 /* Mega-Hack -- Delay death */
4275 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4278 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "----¥²¡¼¥àÃæÃÇ----");
4280 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "---- Save and Exit Game ----");
4283 /* Hardcode panic save */
4284 p_ptr->panic_save = 1;
4286 /* Forbid suspend */
4287 signals_ignore_tstp();
4289 /* Indicate panic save */
4291 (void)strcpy(p_ptr->died_from, "(¶ÛµÞ¥»¡¼¥Ö)");
4293 (void)strcpy(p_ptr->died_from, "(panic save)");
4297 (void)save_player();
4311 process_menus(LOWORD(wParam));
4317 /* this message was sent before WM_NCCREATE */
4320 /* it was sent from inside CreateWindowEx */
4321 if (!td->w) return 1;
4323 /* was sent from WM_SIZE */
4324 if (td->size_hack) return 1;
4328 case SIZE_MINIMIZED:
4330 /* Hide sub-windows */
4331 for (i = 1; i < MAX_TERM_DATA; i++)
4333 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4338 case SIZE_MAXIMIZED:
4340 /* fall through XXX XXX XXX */
4345 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4346 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4349 if ((td->cols != cols) || (td->rows != rows))
4351 /* Save the new size */
4356 Term_activate(&td->t);
4358 /* Resize the term */
4359 Term_resize(td->cols, td->rows);
4362 InvalidateRect(td->w, NULL, TRUE);
4365 td->size_hack = TRUE;
4367 /* Show sub-windows */
4368 for (i = 1; i < MAX_TERM_DATA; i++)
4370 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4373 td->size_hack = FALSE;
4381 case WM_PALETTECHANGED:
4383 /* Ignore if palette change caused by itself */
4384 if ((HWND)wParam == hWnd) return 0;
4386 /* Fall through... */
4389 case WM_QUERYNEWPALETTE:
4391 if (!paletted) return 0;
4395 SelectPalette(hdc, hPal, FALSE);
4397 i = RealizePalette(hdc);
4399 /* if any palette entries changed, repaint the window. */
4400 if (i) InvalidateRect(hWnd, NULL, TRUE);
4402 ReleaseDC(hWnd, hdc);
4409 if (wParam && !HIWORD(lParam))
4411 /* Do something to sub-windows */
4412 for (i = 1; i < MAX_TERM_DATA; i++)
4414 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4417 /* Focus on main window */
4426 case WM_ACTIVATEAPP:
4428 for (i = 1; i < MAX_TERM_DATA; i++)
4434 ShowWindow(data[i].w, SW_SHOW);
4438 ShowWindow(data[i].w, SW_HIDE);
4445 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4450 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4451 WPARAM wParam, LPARAM lParam);
4452 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4453 WPARAM wParam, LPARAM lParam)
4454 #else /* __MWERKS__ */
4455 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4456 WPARAM wParam, LPARAM lParam)
4457 #endif /* __MWERKS__ */
4461 MINMAXINFO FAR *lpmmi;
4469 /* Acquire proper "term_data" info */
4470 td = (term_data *)GetWindowLong(hWnd, 0);
4472 /* Process message */
4478 SetWindowLong(hWnd, 0, (LONG)(my_td));
4488 case WM_GETMINMAXINFO:
4490 MINMAXINFO FAR *lpmmi;
4493 lpmmi = (MINMAXINFO FAR *)lParam;
4495 /* this message was sent before WM_NCCREATE */
4498 /* Minimum window size is 80x24 */
4499 rc.left = rc.top = 0;
4500 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4501 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4504 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4506 /* Save minimum size */
4507 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4508 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4518 /* this message was sent before WM_NCCREATE */
4521 /* it was sent from inside CreateWindowEx */
4522 if (!td->w) return 1;
4524 /* was sent from inside WM_SIZE */
4525 if (td->size_hack) return 1;
4527 td->size_hack = TRUE;
4529 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4530 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4533 if ((td->cols != cols) || (td->rows != rows))
4536 term *old_term = Term;
4538 /* Save the new size */
4543 Term_activate(&td->t);
4545 /* Resize the term */
4546 Term_resize(td->cols, td->rows);
4549 Term_activate(old_term);
4552 InvalidateRect(td->w, NULL, TRUE);
4554 /* HACK - Redraw all windows */
4555 p_ptr->window = 0xFFFFFFFF;
4559 td->size_hack = FALSE;
4566 BeginPaint(hWnd, &ps);
4567 if (td) term_data_redraw(td);
4568 EndPaint(hWnd, &ps);
4579 /* Extract the modifiers */
4580 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4581 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4582 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4584 /* Handle "special" keys */
4585 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4587 /* Begin the macro trigger */
4590 /* Send the modifiers */
4591 if (mc) Term_keypress('C');
4592 if (ms) Term_keypress('S');
4593 if (ma) Term_keypress('A');
4595 /* Extract "scan code" */
4596 i = LOBYTE(HIWORD(lParam));
4598 /* Introduce the scan code */
4601 /* Encode the hexidecimal scan code */
4602 Term_keypress(hexsym[i/16]);
4603 Term_keypress(hexsym[i%16]);
4605 /* End the macro trigger */
4616 Term_keypress(wParam);
4620 case WM_PALETTECHANGED:
4622 /* ignore if palette change caused by itself */
4623 if ((HWND)wParam == hWnd) return FALSE;
4624 /* otherwise, fall through!!! */
4627 case WM_QUERYNEWPALETTE:
4629 if (!paletted) return 0;
4631 SelectPalette(hdc, hPal, FALSE);
4632 i = RealizePalette(hdc);
4633 /* if any palette entries changed, repaint the window. */
4634 if (i) InvalidateRect(hWnd, NULL, TRUE);
4635 ReleaseDC(hWnd, hdc);
4639 case WM_NCLBUTTONDOWN:
4643 if (wParam == HTCLOSE) wParam = HTSYSMENU;
4644 #endif /* HTCLOSE */
4646 if (wParam == HTSYSMENU)
4650 td->visible = FALSE;
4651 ShowWindow(td->w, SW_HIDE);
4661 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4667 #define MOUSE_SENS 40
4670 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4671 WPARAM wParam, LPARAM lParam);
4672 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4673 WPARAM wParam, LPARAM lParam)
4674 #else /* __MWERKS__ */
4675 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4676 WPARAM wParam, LPARAM lParam)
4677 #endif /* __MWERKS__ */
4679 static int iMouse = 0;
4680 static WORD xMouse = 0;
4681 static WORD yMouse = 0;
4704 if (LOWORD(wParam) == WA_INACTIVE) break;
4706 /* else fall through */
4710 case WM_LBUTTONDOWN:
4711 case WM_MBUTTONDOWN:
4712 case WM_RBUTTONDOWN:
4715 SendMessage(hWnd, WM_CLOSE, 0, 0);
4723 dx = LOWORD(lParam) - xMouse;
4724 dy = HIWORD(lParam) - yMouse;
4726 if (dx < 0) dx = -dx;
4727 if (dy < 0) dy = -dy;
4729 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
4731 SendMessage(hWnd, WM_CLOSE, 0, 0);
4735 /* Save last location */
4737 xMouse = LOWORD(lParam);
4738 yMouse = HIWORD(lParam);
4745 DestroyWindow(hwndSaver);
4752 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4755 #endif /* USE_SAVER */
4761 /*** Temporary Hooks ***/
4765 * Display warning message (see "z-util.c")
4767 static void hack_plog(cptr str)
4769 /* Give a warning */
4773 MessageBox(NULL, str, "·Ù¹ð¡ª",
4774 MB_ICONEXCLAMATION | MB_OK);
4776 MessageBox(NULL, str, "Warning",
4777 MB_ICONEXCLAMATION | MB_OK);
4785 * Display error message and quit (see "z-util.c")
4787 static void hack_quit(cptr str)
4789 /* Give a warning */
4793 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
4794 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4796 MessageBox(NULL, str, "Error",
4797 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4802 /* Unregister the classes */
4803 UnregisterClass(AppName, hInstance);
4805 /* Destroy the icon */
4806 if (hIcon) DestroyIcon(hIcon);
4814 /*** Various hooks ***/
4818 * Display warning message (see "z-util.c")
4820 static void hook_plog(cptr str)
4826 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
4827 MB_ICONEXCLAMATION | MB_OK);
4829 MessageBox(data[0].w, str, "Warning",
4830 MB_ICONEXCLAMATION | MB_OK);
4838 * Display error message and quit (see "z-util.c")
4840 static void hook_quit(cptr str)
4845 /* Give a warning */
4849 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
4850 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4852 MessageBox(data[0].w, str, "Error",
4853 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4859 /* Save the preferences */
4863 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
4865 /* Destroy all windows */
4866 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
4868 term_force_font(&data[i], NULL);
4869 if (data[i].font_want) string_free(data[i].font_want);
4870 if (data[i].w) DestroyWindow(data[i].w);
4874 /* Free the bitmap stuff */
4876 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
4877 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
4879 #ifdef USE_TRANSPARENCY
4880 if (infMask.hPalette) DeleteObject(infMask.hPalette);
4881 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
4882 #endif /* USE_TRANSPARENCY */
4884 #endif /* USE_GRAPHICS */
4886 /*** Free some other stuff ***/
4888 DeleteObject(hbrYellow);
4893 if (hPal) DeleteObject(hPal);
4895 UnregisterClass(AppName, hInstance);
4897 if (hIcon) DestroyIcon(hIcon);
4904 /*** Initialize ***/
4910 static void init_stuff(void)
4917 /* Get program name with full path */
4918 GetModuleFileName(hInstance, path, 512);
4920 /* Save the "program name" XXX XXX XXX */
4923 /* Get the name of the "*.ini" file */
4924 strcpy(path + strlen(path) - 4, ".INI");
4926 /* Save the the name of the ini-file */
4927 ini_file = string_make(path);
4929 /* Analyze the path */
4935 if (path[i] == '\\')
4942 /* Add "lib" to the path */
4943 strcpy(path + i + 1, "lib\\");
4945 /* Validate the path */
4946 validate_dir(path, TRUE);
4948 /* Init the file paths */
4949 init_file_paths(path);
4951 /* Hack -- Validate the paths */
4952 validate_dir(ANGBAND_DIR_APEX, FALSE);
4953 validate_dir(ANGBAND_DIR_BONE, FALSE);
4955 /* Allow missing 'edit' directory */
4956 if (!check_dir(ANGBAND_DIR_EDIT))
4958 /* Must have 'data'! */
4959 validate_dir(ANGBAND_DIR_DATA, TRUE);
4963 /* Don't need 'data' */
4964 validate_dir(ANGBAND_DIR_DATA, FALSE);
4967 validate_dir(ANGBAND_DIR_FILE, TRUE);
4968 validate_dir(ANGBAND_DIR_HELP, FALSE);
4969 validate_dir(ANGBAND_DIR_INFO, FALSE);
4970 validate_dir(ANGBAND_DIR_PREF, TRUE);
4971 validate_dir(ANGBAND_DIR_SAVE, FALSE);
4972 validate_dir(ANGBAND_DIR_USER, TRUE);
4973 validate_dir(ANGBAND_DIR_XTRA, TRUE);
4975 /* Build the filename */
4977 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
4979 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
4983 /* Hack -- Validate the "news.txt" file */
4984 validate_file(path);
4988 /* Build the "font" path */
4989 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
4991 /* Allocate the path */
4992 ANGBAND_DIR_XTRA_FONT = string_make(path);
4994 /* Validate the "font" directory */
4995 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
4997 /* Build the filename */
4998 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5000 /* Hack -- Validate the basic font */
5001 validate_file(path);
5007 /* Build the "graf" path */
5008 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5010 /* Allocate the path */
5011 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5013 /* Validate the "graf" directory */
5014 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5016 #endif /* USE_GRAPHICS */
5021 /* Build the "sound" path */
5022 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5024 /* Allocate the path */
5025 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5027 /* Validate the "sound" directory */
5028 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5030 #endif /* USE_SOUND */
5034 /* Build the "music" path */
5035 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5037 /* Allocate the path */
5038 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5040 /* Validate the "music" directory */
5041 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5043 #endif /* USE_MUSIC */
5045 /* Build the "help" path */
5046 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5048 /* Allocate the path */
5049 ANGBAND_DIR_XTRA_HELP = string_make(path);
5051 /* Validate the "help" directory */
5052 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5056 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5057 LPSTR lpCmdLine, int nCmdShow)
5069 if (hPrevInst == NULL)
5071 wc.style = CS_CLASSDC;
5072 wc.lpfnWndProc = AngbandWndProc;
5074 wc.cbWndExtra = 4; /* one long pointer to term_data */
5075 wc.hInstance = hInst;
5076 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5077 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5078 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5079 wc.lpszMenuName = AppName;
5080 wc.lpszClassName = AppName;
5082 if (!RegisterClass(&wc)) exit(1);
5084 wc.lpfnWndProc = AngbandListProc;
5085 wc.lpszMenuName = NULL;
5086 wc.lpszClassName = AngList;
5088 if (!RegisterClass(&wc)) exit(2);
5092 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5093 wc.lpfnWndProc = AngbandSaverProc;
5095 wc.lpszMenuName = NULL;
5096 wc.lpszClassName = "WindowsScreenSaverClass";
5098 if (!RegisterClass(&wc)) exit(3);
5104 /* Temporary hooks */
5105 plog_aux = hack_plog;
5106 quit_aux = hack_quit;
5107 core_aux = hack_quit;
5109 /* Prepare the filepaths */
5112 /* Initialize the keypress analyzer */
5113 for (i = 0; special_key_list[i]; ++i)
5115 special_key[special_key_list[i]] = TRUE;
5117 /* Initialize the keypress analyzer */
5118 for (i = 0; ignore_key_list[i]; ++i)
5120 ignore_key[ignore_key_list[i]] = TRUE;
5123 /* Determine if display is 16/256/true color */
5125 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5126 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5127 ReleaseDC(NULL, hdc);
5129 /* Initialize the colors */
5130 for (i = 0; i < 256; i++)
5134 /* Extract desired values */
5135 rv = angband_color_table[i][1];
5136 gv = angband_color_table[i][2];
5137 bv = angband_color_table[i][3];
5139 /* Extract the "complex" code */
5140 win_clr[i] = PALETTERGB(rv, gv, bv);
5142 /* Save the "simple" code */
5143 angband_color_table[i][0] = win_pal[i];
5146 /* Prepare the windows */
5152 /* Activate hooks */
5153 plog_aux = hook_plog;
5154 quit_aux = hook_quit;
5155 core_aux = hook_quit;
5157 /* Set the system suffix */
5158 ANGBAND_SYS = "win";
5160 /* Set the keyboard suffix */
5161 if (7 != GetKeyboardType(0))
5162 ANGBAND_KEYBOARD = "0";
5165 /* Japanese keyboard */
5166 switch (GetKeyboardType(1))
5168 case 0x0D01: case 0x0D02:
5169 case 0x0D03: case 0x0D04:
5170 case 0x0D05: case 0x0D06:
5172 ANGBAND_KEYBOARD = "NEC98";
5176 ANGBAND_KEYBOARD = "JAPAN";
5180 /* Catch nasty signals */
5186 /* We are now initialized */
5190 if(lpCmdLine[0] == '-'){
5191 switch(lpCmdLine[1])
5196 if (!lpCmdLine[2]) break;
5197 chuukei_server = TRUE;
5198 if(connect_chuukei_server(&lpCmdLine[2])<0){
5199 msg_print("connect fail");
5202 msg_print("connect");
5210 if (!lpCmdLine[2]) break;
5211 chuukei_client = TRUE;
5212 connect_chuukei_server(&lpCmdLine[2]);
5222 /* Did the user double click on a save file? */
5223 if(!chuukei_server) check_for_save_file(lpCmdLine);
5225 /* Did the user double click on a save file? */
5226 check_for_save_file(lpCmdLine);
5229 /* Prompt the user */
5231 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5233 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5238 /* Process messages forever */
5239 while (GetMessage(&msg, NULL, 0, 0))
5241 TranslateMessage(&msg);
5242 DispatchMessage(&msg);
5253 #endif /* WINDOWS */