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,VK_KANA,VK_JUNJA,VK_FINAL,VK_KANJI,
615 VK_CONVERT,VK_NONCONVERT,VK_ACCEPT,VK_MODECHANGE,
616 VK_PRIOR,VK_NEXT,VK_END,VK_HOME,VK_LEFT,VK_UP,VK_RIGHT,VK_DOWN,
617 VK_SELECT,VK_PRINT,VK_EXECUTE,VK_SNAPSHOT,VK_INSERT,VK_DELETE,
619 VK_MULTIPLY,VK_ADD,VK_SEPARATOR,VK_SUBTRACT,VK_DIVIDE,
620 VK_F1,VK_F2,VK_F3,VK_F4,VK_F5,VK_F6,VK_F7,VK_F8,VK_F9,VK_F10,
621 VK_F11,VK_F12,VK_F13,VK_F14,VK_F15,VK_F16,VK_F17,VK_F18,VK_F19,VK_F20,
622 VK_F21,VK_F22,VK_F23,VK_F24,VK_NUMLOCK,VK_SCROLL,
623 VK_ATTN,VK_CRSEL,VK_EXSEL,VK_EREOF,VK_PLAY,VK_ZOOM,VK_NONAME,
627 static byte ignore_key_list[] = {
628 VK_ESCAPE,VK_TAB,VK_SPACE,
629 'F','W','O','H', /* these are menu characters.*/
630 VK_SHIFT,VK_CONTROL,VK_MENU,VK_LWIN,VK_RWIN,
631 VK_LSHIFT,VK_RSHIFT,VK_LCONTROL,VK_RCONTROL,VK_LMENU,VK_RMENU,0
636 * Hack -- initialization list for "special_key"
638 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
639 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
640 * catch the keypad keys (with and without numlock set, including keypad 5),
641 * the function keys (including the "menu" key which maps to F10), and the
642 * "pause" key (between scroll lock and numlock). We also catch a few odd
643 * keys which I do not recognize, but which are listed among keys which we
644 * do catch, so they should be harmless to catch.
646 static byte special_key_list[] =
648 VK_CLEAR, /* 0x0C (KP<5>) */
650 VK_PAUSE, /* 0x13 (pause) */
652 VK_PRIOR, /* 0x21 (KP<9>) */
653 VK_NEXT, /* 0x22 (KP<3>) */
654 VK_END, /* 0x23 (KP<1>) */
655 VK_HOME, /* 0x24 (KP<7>) */
656 VK_LEFT, /* 0x25 (KP<4>) */
657 VK_UP, /* 0x26 (KP<8>) */
658 VK_RIGHT, /* 0x27 (KP<6>) */
659 VK_DOWN, /* 0x28 (KP<2>) */
660 VK_SELECT, /* 0x29 (?????) */
661 VK_PRINT, /* 0x2A (?????) */
662 VK_EXECUTE, /* 0x2B (?????) */
663 VK_SNAPSHOT, /* 0x2C (?????) */
664 VK_INSERT, /* 0x2D (KP<0>) */
665 VK_DELETE, /* 0x2E (KP<.>) */
666 VK_HELP, /* 0x2F (?????) */
669 VK_NUMPAD0, /* 0x60 (KP<0>) */
670 VK_NUMPAD1, /* 0x61 (KP<1>) */
671 VK_NUMPAD2, /* 0x62 (KP<2>) */
672 VK_NUMPAD3, /* 0x63 (KP<3>) */
673 VK_NUMPAD4, /* 0x64 (KP<4>) */
674 VK_NUMPAD5, /* 0x65 (KP<5>) */
675 VK_NUMPAD6, /* 0x66 (KP<6>) */
676 VK_NUMPAD7, /* 0x67 (KP<7>) */
677 VK_NUMPAD8, /* 0x68 (KP<8>) */
678 VK_NUMPAD9, /* 0x69 (KP<9>) */
679 VK_MULTIPLY, /* 0x6A (KP<*>) */
680 VK_ADD, /* 0x6B (KP<+>) */
681 VK_SEPARATOR, /* 0x6C (?????) */
682 VK_SUBTRACT, /* 0x6D (KP<->) */
683 VK_DECIMAL, /* 0x6E (KP<.>) */
684 VK_DIVIDE, /* 0x6F (KP</>) */
717 static void delete_bg(void)
726 static int init_bg(void)
728 char * bmfile = bg_bitmap_file;
731 if (use_bg == 0) return 0;
733 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
735 plog_fmt("ÊÉ»æÍÑ¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
740 HDC wnddc, dcimage, dcbg;
741 HBITMAP bmimage, bmimage_old, bmbg_old;
747 dcimage = CreateCompatibleDC(wnddc);
748 dcbg = CreateCompatibleDC(wnddc);
750 bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
751 if (!bmimage) quit("bg.bmp¤¬Æɤߤ³¤á¤Ê¤¤¡ª");
752 bmimage_old = SelectObject(dcimage, bmimage);
754 CreateCompatibleBitmap();
756 ReleaseDC(hwnd, wnddc);
762 static void DrawBG(HDC hdc, RECT *r)
767 int x = r->left, y = r->top;
768 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
774 GetObject(hBG, sizeof(bm), &bm);
775 swid = bm.bmWidth; shgt = bm.bmHeight;
777 hdcSrc = CreateCompatibleDC(hdc);
778 hOld = SelectObject(hdcSrc, hBG);
782 cwid = MIN(swid - sx, r->right - nx);
785 chgt = MIN(shgt - sy, r->bottom - ny);
786 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
788 } while (ny < r->bottom);
791 } while (nx < r->right);
793 SelectObject(hdcSrc, hOld);
799 * Hack -- given a pathname, point at the filename
801 static cptr extract_file_name(cptr s)
805 /* Start at the end */
806 p = s + strlen(s) - 1;
808 /* Back up to divider */
809 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
811 /* Return file name */
818 * Hack -- given a simple filename, extract the "font size" info
820 * Return a pointer to a static buffer holding the capitalized base name.
823 static char *analyze_font(char *path, int *wp, int *hp)
829 /* Start at the end */
830 p = path + strlen(path) - 1;
832 /* Back up to divider */
833 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
835 /* Advance to file name */
841 /* Capitalize (be paranoid) */
842 if (islower(*s)) *s = toupper(*s);
848 /* Extract font width */
852 hgt = s ? atoi(s+1) : 0;
865 * Check for existance of a file
867 static bool check_file(cptr s)
887 attrib = GetFileAttributes(path);
889 /* Require valid filename */
890 if (attrib == INVALID_FILE_NAME) return (FALSE);
892 /* Prohibit directory */
893 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
897 /* Examine and verify */
898 if (_dos_getfileattr(path, &attrib)) return (FALSE);
900 /* Prohibit something */
901 if (attrib & FA_LABEL) return (FALSE);
903 /* Prohibit directory */
904 if (attrib & FA_DIREC) return (FALSE);
914 * Check for existance of a directory
916 static bool check_dir(cptr s)
938 /* Remove trailing backslash */
939 if (i && (path[i-1] == '\\')) path[--i] = '\0';
944 attrib = GetFileAttributes(path);
946 /* Require valid filename */
947 if (attrib == INVALID_FILE_NAME) return (FALSE);
949 /* Require directory */
950 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
954 /* Examine and verify */
955 if (_dos_getfileattr(path, &attrib)) return (FALSE);
957 /* Prohibit something */
958 if (attrib & FA_LABEL) return (FALSE);
960 /* Require directory */
961 if (!(attrib & FA_DIREC)) return (FALSE);
973 static void validate_file(cptr s)
979 quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
981 quit_fmt("Cannot find required file:\n%s", s);
989 * Validate a directory
991 static void validate_dir(cptr s, bool vital)
996 /* This directory contains needed data */
1000 quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
1002 quit_fmt("Cannot find required directory:\n%s", s);
1006 /* Attempt to create this directory */
1009 quit_fmt("Unable to create directory:\n%s", s);
1016 * Get the "size" for a window
1018 static void term_getsize(term_data *td)
1025 if (td->cols < 1) td->cols = 1;
1026 if (td->rows < 1) td->rows = 1;
1029 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1030 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1032 /* Fake window size */
1034 rc.right = rc.left + wid;
1036 rc.bottom = rc.top + hgt;
1039 /* rc.right += 1; */
1040 /* rc.bottom += 1; */
1043 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1046 td->size_wid = rc.right - rc.left;
1047 td->size_hgt = rc.bottom - rc.top;
1049 /* See CreateWindowEx */
1052 /* Extract actual location */
1053 GetWindowRect(td->w, &rc);
1055 /* Save the location */
1056 td->pos_x = rc.left;
1062 * Write the "prefs" for a single term
1064 static void save_prefs_aux(term_data *td, cptr sec_name)
1074 strcpy(buf, td->visible ? "1" : "0");
1075 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1079 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1081 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1084 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1087 wsprintf(buf, "%d", td->lf.lfWidth);
1088 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1089 wsprintf(buf, "%d", td->lf.lfHeight);
1090 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1091 wsprintf(buf, "%d", td->lf.lfWeight);
1092 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1095 strcpy(buf, td->bizarre ? "1" : "0");
1096 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1099 wsprintf(buf, "%d", td->tile_wid);
1100 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1103 wsprintf(buf, "%d", td->tile_hgt);
1104 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1106 /* Window size (x) */
1107 wsprintf(buf, "%d", td->cols);
1108 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1110 /* Window size (y) */
1111 wsprintf(buf, "%d", td->rows);
1112 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1114 /* Acquire position */
1115 GetWindowRect(td->w, &rc);
1117 /* Window position (x) */
1118 wsprintf(buf, "%d", rc.left);
1119 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1121 /* Window position (y) */
1122 wsprintf(buf, "%d", rc.top);
1123 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1125 /* Window Z position */
1126 strcpy(buf, td->posfix ? "1" : "0");
1127 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1134 * We assume that the windows have all been initialized
1136 static void save_prefs(void)
1142 /* Save the "arg_graphics" flag */
1143 sprintf(buf, "%d", arg_graphics);
1144 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1146 /* Save the "arg_bigtile" flag */
1147 strcpy(buf, arg_bigtile ? "1" : "0");
1148 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1150 /* Save the "arg_sound" flag */
1151 strcpy(buf, arg_sound ? "1" : "0");
1152 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1155 strcpy(buf, use_bg ? "1" : "0");
1156 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1157 WritePrivateProfileString("Angband", "BackGroundBitmap",
1158 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1160 /* Save window prefs */
1161 for (i = 0; i < MAX_TERM_DATA; ++i)
1163 term_data *td = &data[i];
1165 sprintf(buf, "Term-%d", i);
1167 save_prefs_aux(td, buf);
1173 * Load the "prefs" for a single term
1175 static void load_prefs_aux(term_data *td, cptr sec_name)
1182 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1184 /* Desired font, with default */
1186 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1188 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1193 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1195 /* Analyze font, save desired font name */
1197 td->font_want = string_make(tmp);
1199 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1200 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1201 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1203 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1209 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1210 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1212 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1213 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1218 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1219 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1221 /* Window position */
1222 td->pos_x = GetPrivateProfileInt(sec_name, "PositionX", td->pos_x, ini_file);
1223 td->pos_y = GetPrivateProfileInt(sec_name, "PositionY", td->pos_y, ini_file);
1225 /* Window Z position */
1226 td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1233 static void load_prefs(void)
1239 /* Extract the "arg_graphics" flag */
1240 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1242 /* Extract the "arg_bigtile" flag */
1243 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1244 use_bigtile = arg_bigtile;
1246 /* Extract the "arg_sound" flag */
1247 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1250 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1251 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1253 /* Load window prefs */
1254 for (i = 0; i < MAX_TERM_DATA; ++i)
1256 term_data *td = &data[i];
1258 sprintf(buf, "Term-%d", i);
1260 load_prefs_aux(td, buf);
1267 * XXX XXX XXX - Taken from files.c.
1269 * Extract "tokens" from a buffer
1271 * This function uses "whitespace" as delimiters, and treats any amount of
1272 * whitespace as a single delimiter. We will never return any empty tokens.
1273 * When given an empty buffer, or a buffer containing only "whitespace", we
1274 * will return no tokens. We will never extract more than "num" tokens.
1276 * By running a token through the "text_to_ascii()" function, you can allow
1277 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1279 * We save pointers to the tokens in "tokens", and return the number found.
1281 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1293 /* Skip leading whitespace */
1294 for ( ; *s && isspace(*s); ++s) /* loop */;
1299 /* Find next whitespace, if any */
1300 for (t = s; *t && !isspace(*t); ++t) /* loop */;
1302 /* Nuke and advance (if necessary) */
1303 if (*t) *t++ = '\0';
1305 /* Save the token */
1316 static void load_sound_prefs(void)
1320 char ini_path[1024];
1321 char wav_path[1024];
1322 char *zz[SAMPLE_MAX];
1324 /* Access the sound.cfg */
1325 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1327 for (i = 0; i < SOUND_MAX; i++)
1329 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1331 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1333 for (j = 0; j < num; j++)
1335 /* Access the sound */
1336 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1338 /* Save the sound filename, if it exists */
1339 if (check_file(wav_path))
1340 sound_file[i][j] = string_make(zz[j]);
1345 #endif /* USE_SOUND */
1348 * Create the new global palette based on the bitmap palette
1349 * (if any), and the standard 16 entry palette derived from
1350 * "win_clr[]" which is used for the basic 16 Angband colors.
1352 * This function is never called before all windows are ready.
1354 * This function returns FALSE if the new palette could not be
1355 * prepared, which should normally be a fatal error. XXX XXX
1357 * Note that only some machines actually use a "palette".
1359 static int new_palette(void)
1367 LPLOGPALETTE pLogPal;
1368 LPPALETTEENTRY lppe;
1373 /* This makes no sense */
1374 if (!paletted) return (TRUE);
1384 /* Check the bitmap palette */
1385 hBmPal = infGraph.hPalette;
1387 /* Use the bitmap */
1390 lppeSize = 256 * sizeof(PALETTEENTRY);
1391 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1392 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1393 if ((nEntries == 0) || (nEntries > 220))
1397 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1399 plog("Please switch to high- or true-color mode.");
1404 rnfree(lppe, lppeSize);
1411 #endif /* USE_GRAPHICS */
1413 /* Size of palette */
1414 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1416 /* Allocate palette */
1417 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1420 pLogPal->palVersion = 0x300;
1422 /* Make room for bitmap and normal data */
1423 pLogPal->palNumEntries = nEntries + 16;
1425 /* Save the bitmap data */
1426 for (i = 0; i < nEntries; i++)
1428 pLogPal->palPalEntry[i] = lppe[i];
1431 /* Save the normal data */
1432 for (i = 0; i < 16; i++)
1436 /* Access the entry */
1437 p = &(pLogPal->palPalEntry[i+nEntries]);
1439 /* Save the colors */
1440 p->peRed = GetRValue(win_clr[i]);
1441 p->peGreen = GetGValue(win_clr[i]);
1442 p->peBlue = GetBValue(win_clr[i]);
1444 /* Save the flags */
1445 p->peFlags = PC_NOCOLLAPSE;
1448 /* Free something */
1449 if (lppe) rnfree(lppe, lppeSize);
1451 /* Create a new palette, or fail */
1452 hNewPal = CreatePalette(pLogPal);
1454 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1456 if (!hNewPal) quit("Cannot create palette!");
1460 /* Free the palette */
1461 rnfree(pLogPal, pLogPalSize);
1466 /* Realize the palette */
1468 SelectPalette(hdc, hNewPal, 0);
1469 i = RealizePalette(hdc);
1470 ReleaseDC(td->w, hdc);
1472 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1474 if (i == 0) quit("Cannot realize palette!");
1479 for (i = 1; i < MAX_TERM_DATA; i++)
1484 SelectPalette(hdc, hNewPal, 0);
1485 ReleaseDC(td->w, hdc);
1488 /* Delete old palette */
1489 if (hPal) DeleteObject(hPal);
1491 /* Save new palette */
1501 * Initialize graphics
1503 static bool init_graphics(void)
1505 /* Initialize once */
1506 /* if (can_use_graphics != arg_graphics) */
1512 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1519 ANGBAND_GRAF = "new";
1527 ANGBAND_GRAF = "old";
1530 /* Access the bitmap file */
1531 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1533 /* Load the bitmap or quit */
1534 if (!ReadDIB(data[0].w, buf, &infGraph))
1537 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1539 plog_fmt("Cannot read bitmap file '%s'", name);
1545 /* Save the new sizes */
1546 infGraph.CellWidth = wid;
1547 infGraph.CellHeight = hgt;
1549 #ifdef USE_TRANSPARENCY
1551 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1553 /* Access the mask file */
1554 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1556 /* Load the bitmap or quit */
1557 if (!ReadDIB(data[0].w, buf, &infMask))
1559 plog_fmt("Cannot read bitmap file '%s'", buf);
1564 #endif /* USE_TRANSPARENCY */
1566 /* Activate a palette */
1569 /* Free bitmap XXX XXX XXX */
1573 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1575 plog("Cannot activate palette!");
1581 /* Graphics available */
1582 can_use_graphics = arg_graphics;
1586 return (can_use_graphics);
1588 #endif /* USE_GRAPHICS */
1595 static bool init_sound(void)
1597 /* Initialize once */
1600 /* Load the prefs */
1603 /* Sound available */
1604 can_use_sound = TRUE;
1608 return (can_use_sound);
1610 #endif /* USE_SOUND */
1616 static void term_window_resize(term_data *td)
1618 /* Require window */
1621 /* Resize the window */
1622 SetWindowPos(td->w, 0, 0, 0,
1623 td->size_wid, td->size_hgt,
1624 SWP_NOMOVE | SWP_NOZORDER);
1627 InvalidateRect(td->w, NULL, TRUE);
1632 * Force the use of a new "font file" for a term_data
1634 * This function may be called before the "window" is ready
1636 * This function returns zero only if everything succeeds.
1638 * Note that the "font name" must be capitalized!!!
1640 static errr term_force_font(term_data *td, cptr path)
1650 /* Forget the old font (if needed) */
1651 if (td->font_id) DeleteObject(td->font_id);
1654 /* Forget old font */
1660 for (i = 0; i < MAX_TERM_DATA; i++)
1662 /* Don't check when closing the application */
1665 /* Check "screen" */
1666 if ((td != &data[i]) &&
1667 (data[i].font_file) &&
1668 (streq(data[i].font_file, td->font_file)))
1674 /* Remove unused font resources */
1675 if (!used) RemoveFontResource(td->font_file);
1677 /* Free the old name */
1678 string_free(td->font_file);
1681 td->font_file = NULL;
1686 if (!path) return (1);
1692 /* Analyze font path */
1693 base = analyze_font(buf, &wid, &hgt);
1696 if (!suffix(base, ".FON")) return (1);
1699 if (!check_file(buf)) return (1);
1701 /* Load the new font */
1702 if (!AddFontResource(buf)) return (1);
1704 /* Save new font name */
1705 td->font_file = string_make(base);
1707 /* Remove the "suffix" */
1708 base[strlen(base)-4] = '\0';
1711 /* Create the font (using the 'base' of the font file name!) */
1713 td->font_id = CreateFontIndirect(&(td->lf));
1714 wid = td->lf.lfWidth;
1715 hgt = td->lf.lfHeight;
1716 if (!td->font_id) return (1);
1718 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1719 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1720 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1721 FIXED_PITCH | FF_DONTCARE, base);
1725 /* Hack -- Unknown size */
1732 /* all this trouble to get the cell size */
1733 hdcDesktop = GetDC(HWND_DESKTOP);
1734 hfOld = SelectObject(hdcDesktop, td->font_id);
1735 GetTextMetrics(hdcDesktop, &tm);
1736 SelectObject(hdcDesktop, hfOld);
1737 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1739 /* Font size info */
1740 wid = tm.tmAveCharWidth;
1744 /* Save the size info */
1755 * Allow the user to change the font for this window.
1757 static void term_change_font(term_data *td)
1762 memset(&cf, 0, sizeof(cf));
1763 cf.lStructSize = sizeof(cf);
1764 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1765 cf.lpLogFont = &(td->lf);
1767 if (ChooseFont(&cf))
1769 /* Force the font */
1770 term_force_font(td, NULL);
1772 /* Assume not bizarre */
1775 /* Reset the tile info */
1776 td->tile_wid = td->font_wid;
1777 td->tile_hgt = td->font_hgt;
1779 /* Analyze the font */
1782 /* Resize the window */
1783 term_window_resize(td);
1789 char tmp[1024] = "";
1791 /* Extract a default if possible */
1792 if (td->font_file) strcpy(tmp, td->font_file);
1794 /* Ask for a choice */
1795 memset(&ofn, 0, sizeof(ofn));
1796 ofn.lStructSize = sizeof(ofn);
1797 ofn.hwndOwner = data[0].w;
1798 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1799 ofn.nFilterIndex = 1;
1800 ofn.lpstrFile = tmp;
1802 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1803 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1804 ofn.lpstrDefExt = "fon";
1806 /* Force choice if legal */
1807 if (GetOpenFileName(&ofn))
1809 /* Force the font */
1810 if (term_force_font(td, tmp))
1812 /* Access the standard font file */
1813 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1815 /* Force the use of that font */
1816 (void)term_force_font(td, tmp);
1819 /* Assume not bizarre */
1820 td->bizarre = FALSE;
1822 /* Reset the tile info */
1823 td->tile_wid = td->font_wid;
1824 td->tile_hgt = td->font_hgt;
1826 /* Analyze the font */
1829 /* Resize the window */
1830 term_window_resize(td);
1837 * Allow the user to lock this window.
1839 static void term_window_pos(term_data *td, HWND hWnd)
1841 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1842 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1845 static void windows_map(void);
1848 * Hack -- redraw a term_data
1850 static void term_data_redraw(term_data *td)
1854 /* Redraw the map */
1859 /* Activate the term */
1860 Term_activate(&td->t);
1862 /* Redraw the contents */
1865 /* Restore the term */
1866 Term_activate(term_screen);
1874 /*** Function hooks needed by "Term" ***/
1880 * Initialize a new Term
1882 static void Term_init_win(term *t)
1891 static void Term_nuke_win(term *t)
1900 * Interact with the User
1902 static errr Term_user_win(int n)
1910 * React to global changes
1912 static errr Term_xtra_win_react(void)
1920 /* Save the default colors */
1921 for (i = 0; i < 256; i++)
1923 /* Simply accept the desired colors */
1924 win_pal[i] = angband_color_table[i][0];
1935 bool change = FALSE;
1937 /* Save the default colors */
1938 for (i = 0; i < 256; i++)
1940 /* Extract desired values */
1941 rv = angband_color_table[i][1];
1942 gv = angband_color_table[i][2];
1943 bv = angband_color_table[i][3];
1945 /* Extract a full color code */
1946 code = PALETTERGB(rv, gv, bv);
1948 /* Activate changes */
1949 if (win_clr[i] != code)
1951 /* Note the change */
1954 /* Apply the desired color */
1959 /* Activate the palette if needed */
1960 if (change) (void)new_palette();
1966 /* Handle "arg_sound" */
1967 if (use_sound != arg_sound)
1969 /* Initialize (if needed) */
1970 if (arg_sound && !init_sound())
1974 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
1976 plog("Cannot initialize sound!");
1984 /* Change setting */
1985 use_sound = arg_sound;
1993 /* Handle "arg_graphics" */
1994 if (use_graphics != arg_graphics)
1996 /* Initialize (if needed) */
1997 if (arg_graphics && !init_graphics())
2001 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
2003 plog("Cannot initialize graphics!");
2008 arg_graphics = GRAPHICS_NONE;
2011 /* Change setting */
2012 use_graphics = arg_graphics;
2015 #ifdef ANGBAND_2_8_1
2017 #else /* ANGBAND_2_8_1 */
2018 reset_visuals(TRUE);
2019 #endif /* ANGBAND_2_8_1 */
2022 #endif /* USE_GRAPHICS */
2025 /* Clean up windows */
2026 for (i = 0; i < MAX_TERM_DATA; i++)
2030 term_data *td = &data[i];
2032 /* Update resized windows */
2033 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2036 Term_activate(&td->t);
2038 /* Hack -- Resize the term */
2039 Term_resize(td->cols, td->rows);
2041 /* Redraw the contents */
2056 * Process at least one event
2058 static errr Term_xtra_win_event(int v)
2062 /* Wait for an event */
2066 if (GetMessage(&msg, NULL, 0, 0))
2068 TranslateMessage(&msg);
2069 DispatchMessage(&msg);
2073 /* Check for an event */
2077 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2079 TranslateMessage(&msg);
2080 DispatchMessage(&msg);
2090 * Process all pending events
2092 static errr Term_xtra_win_flush(void)
2096 /* Process all pending events */
2097 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2099 TranslateMessage(&msg);
2100 DispatchMessage(&msg);
2109 * Hack -- clear the screen
2111 * Make this more efficient XXX XXX XXX
2113 static errr Term_xtra_win_clear(void)
2115 term_data *td = (term_data*)(Term->data);
2120 /* Rectangle to erase */
2121 rc.left = td->size_ow1;
2122 rc.right = rc.left + td->cols * td->tile_wid;
2123 rc.top = td->size_oh1;
2124 rc.bottom = rc.top + td->rows * td->tile_hgt;
2128 SetBkColor(hdc, RGB(0, 0, 0));
2129 SelectObject(hdc, td->font_id);
2130 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2135 rc.left = 0; rc.top = 0;
2138 ReleaseDC(td->w, hdc);
2146 * Hack -- make a noise
2148 static errr Term_xtra_win_noise(void)
2150 MessageBeep(MB_ICONASTERISK);
2156 * Hack -- make a sound
2158 static errr Term_xtra_win_sound(int v)
2163 #endif /* USE_SOUND */
2165 /* Sound disabled */
2166 if (!use_sound) return (1);
2169 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2173 /* Count the samples */
2174 for (i = 0; i < SAMPLE_MAX; i++)
2176 if (!sound_file[v][i])
2181 if (i == 0) return (1);
2183 /* Build the path */
2184 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_simple(i)]);
2188 /* Play the sound, catch errors */
2189 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2193 /* Play the sound, catch errors */
2194 return (sndPlaySound(buf, SND_ASYNC));
2198 #else /* USE_SOUND */
2203 #endif /* USE_SOUND */
2208 * Delay for "x" milliseconds
2210 static int Term_xtra_win_delay(int v)
2224 t = GetTickCount() + v;
2227 while (GetTickCount() < t)
2229 /* Handle messages */
2230 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2232 TranslateMessage(&msg);
2233 DispatchMessage(&msg);
2245 * Do a "special thing"
2247 static errr Term_xtra_win(int n, int v)
2249 /* Handle a subset of the legal requests */
2252 /* Make a bell sound */
2253 case TERM_XTRA_NOISE:
2255 return (Term_xtra_win_noise());
2258 /* Make a special sound */
2259 case TERM_XTRA_SOUND:
2261 return (Term_xtra_win_sound(v));
2264 /* Process random events */
2265 case TERM_XTRA_BORED:
2267 return (Term_xtra_win_event(0));
2270 /* Process an event */
2271 case TERM_XTRA_EVENT:
2273 return (Term_xtra_win_event(v));
2276 /* Flush all events */
2277 case TERM_XTRA_FLUSH:
2279 return (Term_xtra_win_flush());
2282 /* Clear the screen */
2283 case TERM_XTRA_CLEAR:
2285 return (Term_xtra_win_clear());
2288 /* React to global changes */
2289 case TERM_XTRA_REACT:
2291 return (Term_xtra_win_react());
2294 /* Delay for some milliseconds */
2295 case TERM_XTRA_DELAY:
2297 return (Term_xtra_win_delay(v));
2308 * Low level graphics (Assumes valid input).
2310 * Draw a "cursor" at (x,y), using a "yellow box".
2312 static errr Term_curs_win(int x, int y)
2314 term_data *td = (term_data*)(Term->data);
2319 int tile_wid, tile_hgt;
2323 tile_wid = td->map_tile_wid;
2324 tile_hgt = td->map_tile_hgt;
2328 tile_wid = td->tile_wid;
2329 tile_hgt = td->tile_hgt;
2332 /* Frame the grid */
2333 rc.left = x * tile_wid + td->size_ow1;
2334 rc.right = rc.left + tile_wid;
2335 rc.top = y * tile_hgt + td->size_oh1;
2336 rc.bottom = rc.top + tile_hgt;
2338 /* Cursor is done as a yellow "box" */
2340 FrameRect(hdc, &rc, hbrYellow);
2341 ReleaseDC(td->w, hdc);
2349 * Low level graphics (Assumes valid input).
2351 * Draw a "big cursor" at (x,y), using a "yellow box".
2353 static errr Term_bigcurs_win(int x, int y)
2355 term_data *td = (term_data*)(Term->data);
2360 int tile_wid, tile_hgt;
2364 /* Normal cursor in map window */
2365 Term_curs_win(x, y);
2370 tile_wid = td->tile_wid;
2371 tile_hgt = td->tile_hgt;
2374 /* Frame the grid */
2375 rc.left = x * tile_wid + td->size_ow1;
2376 rc.right = rc.left + 2 * tile_wid;
2377 rc.top = y * tile_hgt + td->size_oh1;
2378 rc.bottom = rc.top + tile_hgt;
2380 /* Cursor is done as a yellow "box" */
2382 FrameRect(hdc, &rc, hbrYellow);
2383 ReleaseDC(td->w, hdc);
2391 * Low level graphics (Assumes valid input).
2393 * Erase a "block" of "n" characters starting at (x,y).
2395 static errr Term_wipe_win(int x, int y, int n)
2397 term_data *td = (term_data*)(Term->data);
2402 /* Rectangle to erase in client coords */
2403 rc.left = x * td->tile_wid + td->size_ow1;
2404 rc.right = rc.left + n * td->tile_wid;
2405 rc.top = y * td->tile_hgt + td->size_oh1;
2406 rc.bottom = rc.top + td->tile_hgt;
2409 SetBkColor(hdc, RGB(0, 0, 0));
2410 SelectObject(hdc, td->font_id);
2415 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2416 ReleaseDC(td->w, hdc);
2424 * Low level graphics. Assumes valid input.
2426 * Draw several ("n") chars, with an attr, at a given location.
2428 * All "graphic" data is handled by "Term_pict_win()", below.
2430 * One would think there is a more efficient method for telling a window
2431 * what color it should be using to draw with, but perhaps simply changing
2432 * it every time is not too inefficient. XXX XXX XXX
2434 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2436 term_data *td = (term_data*)(Term->data);
2442 static HBITMAP WALL;
2443 static HBRUSH myBrush, oldBrush;
2445 static bool init_done = FALSE;
2448 WALL = LoadBitmap(hInstance, AppName);
2449 myBrush = CreatePatternBrush(WALL);
2454 /* Total rectangle */
2455 rc.left = x * td->tile_wid + td->size_ow1;
2456 rc.right = rc.left + n * td->tile_wid;
2457 rc.top = y * td->tile_hgt + td->size_oh1;
2458 rc.bottom = rc.top + td->tile_hgt;
2463 /* Background color */
2464 SetBkColor(hdc, RGB(0, 0, 0));
2466 /* Foreground color */
2469 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2473 SetTextColor(hdc, win_clr[a&0x0F]);
2477 SetTextColor(hdc, win_clr[a]);
2481 SelectObject(hdc, td->font_id);
2484 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2488 (td->tile_hgt != td->font_hgt) ||
2489 (td->tile_wid != td->font_wid))
2493 /* Erase complete rectangle */
2494 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2497 if (use_bg) DrawBG(hdc, &rc);
2500 rc.left += ((td->tile_wid - td->font_wid) / 2);
2501 rc.right = rc.left + td->font_wid;
2502 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2503 rc.bottom = rc.top + td->font_hgt;
2505 /* Dump each character */
2506 for (i = 0; i < n; i++)
2509 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2511 rc.right += td->font_wid;
2513 oldBrush = SelectObject(hdc, myBrush);
2514 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2517 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2519 SelectObject(hdc, oldBrush);
2520 SelectObject(hdc, oldPen);
2521 rc.right -= td->font_wid;
2525 rc.left += 2 * td->tile_wid;
2526 rc.right += 2 * td->tile_wid;
2528 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2530 rc.right += td->font_wid;
2532 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2534 rc.right -= td->font_wid;
2538 rc.left += 2 * td->tile_wid;
2539 rc.right += 2 * td->tile_wid;
2540 } else if (*(s+i)==127){
2541 oldBrush = SelectObject(hdc, myBrush);
2542 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2545 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2547 SelectObject(hdc, oldBrush);
2548 SelectObject(hdc, oldPen);
2551 rc.left += td->tile_wid;
2552 rc.right += td->tile_wid;
2555 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2559 rc.left += td->tile_wid;
2560 rc.right += td->tile_wid;
2564 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2568 rc.left += td->tile_wid;
2569 rc.right += td->tile_wid;
2579 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2584 ReleaseDC(td->w, hdc);
2592 * Low level graphics. Assumes valid input.
2594 * Draw an array of "special" attr/char pairs at the given location.
2596 * We use the "Term_pict_win()" function for "graphic" data, which are
2597 * encoded by setting the "high-bits" of both the "attr" and the "char"
2598 * data. We use the "attr" to represent the "row" of the main bitmap,
2599 * and the "char" to represent the "col" of the main bitmap. The use
2600 * of this function is induced by the "higher_pict" flag.
2602 * If "graphics" is not available, we simply "wipe" the given grids.
2604 # ifdef USE_TRANSPARENCY
2605 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2606 # else /* USE_TRANSPARENCY */
2607 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp)
2608 # endif /* USE_TRANSPARENCY */
2610 term_data *td = (term_data*)(Term->data);
2616 int x2, y2, w2, h2, tw2;
2618 # ifdef USE_TRANSPARENCY
2624 # endif /* USE_TRANSPARENCY */
2633 /* Erase the grids */
2634 return (Term_wipe_win(x, y, n));
2637 /* Size of bitmap cell */
2638 w1 = infGraph.CellWidth;
2639 h1 = infGraph.CellHeight;
2641 /* Size of window cell */
2644 w2 = td->map_tile_wid;
2645 h2 = td->map_tile_hgt;
2654 if (use_bigtile) tw2 *= 2;
2657 /* Location of window cell */
2658 x2 = x * w2 + td->size_ow1;
2659 y2 = y * h2 + td->size_oh1;
2665 hdcSrc = CreateCompatibleDC(hdc);
2666 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2668 # ifdef USE_TRANSPARENCY
2670 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2672 hdcMask = CreateCompatibleDC(hdc);
2673 SelectObject(hdcMask, infMask.hBitmap);
2676 # endif /* USE_TRANSPARENCY */
2678 /* Draw attr/char pairs */
2679 for (i = 0; i < n; i++, x2 += w2)
2684 /* Extract picture */
2685 int row = (a & 0x7F);
2686 int col = (c & 0x7F);
2688 /* Location of bitmap cell */
2692 # ifdef USE_TRANSPARENCY
2694 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2696 x3 = (tcp[i] & 0x7F) * w1;
2697 y3 = (tap[i] & 0x7F) * h1;
2700 if ((w1 == tw2) && (h1 == h2))
2702 /* Copy the terrain picture from the bitmap to the window */
2703 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2705 /* Mask out the tile */
2706 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2709 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2712 /* Need to stretch */
2715 /* Set the correct mode for stretching the tiles */
2716 SetStretchBltMode(hdc, COLORONCOLOR);
2718 /* Copy the terrain picture from the bitmap to the window */
2719 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
2721 /* Only draw if terrain and overlay are different */
2722 if ((x1 != x3) || (y1 != y3))
2724 /* Mask out the tile */
2725 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2728 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2734 # endif /* USE_TRANSPARENCY */
2738 if ((w1 == tw2) && (h1 == h2))
2740 /* Copy the picture from the bitmap to the window */
2741 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2744 /* Need to stretch */
2747 /* Set the correct mode for stretching the tiles */
2748 SetStretchBltMode(hdc, COLORONCOLOR);
2750 /* Copy the picture from the bitmap to the window */
2751 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2757 SelectObject(hdcSrc, hbmSrcOld);
2760 # ifdef USE_TRANSPARENCY
2762 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2765 SelectObject(hdcMask, hbmSrcOld);
2769 # endif /* USE_TRANSPARENCY */
2772 ReleaseDC(td->w, hdc);
2774 #else /* USE_GRAPHICS */
2776 /* Just erase this grid */
2777 return (Term_wipe_win(x, y, n));
2779 #endif /* USE_GRAPHICS */
2786 static void windows_map(void)
2788 term_data *td = &data[0];
2790 int x, min_x, max_x;
2791 int y, min_y, max_y;
2793 #ifdef USE_TRANSPARENCY
2797 /* Only in graphics mode */
2798 if (!use_graphics) return;
2801 Term_xtra_win_clear();
2803 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2804 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2805 td->map_active = TRUE;
2815 for (x = min_x; x < max_x; x++)
2817 for (y = min_y; y < max_y; y++)
2819 #ifdef USE_TRANSPARENCY
2820 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
2821 #else /* USE_TRANSPARENCY */
2822 map_info(y, x, &a, (char*)&c);
2823 #endif /* USE_TRANSPARENCY */
2825 /* Ignore non-graphics */
2826 if ((a & 0x80) && (c & 0x80))
2828 #ifdef USE_TRANSPARENCY
2829 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2830 #else /* USE_TRANSPARENCY */
2831 Term_pict_win(x - min_x, y - min_y, 1, &a, &c);
2832 #endif /* USE_TRANSPARENCY */
2837 /* Hilite the player */
2838 Term_curs_win(px - min_x, py - min_y);
2840 /* Wait for a keypress, flush key buffer */
2841 Term_inkey(&c, TRUE, TRUE);
2844 /* Switch off the map display */
2845 td->map_active = FALSE;
2847 /* Restore screen */
2848 Term_xtra_win_clear();
2853 /*** Other routines ***/
2857 * Create and initialize a "term_data" given a title
2859 static void term_data_link(term_data *td)
2863 /* Initialize the term */
2864 term_init(t, td->cols, td->rows, td->keys);
2866 /* Use a "software" cursor */
2867 t->soft_cursor = TRUE;
2869 /* Use "Term_pict" for "graphic" data */
2870 t->higher_pict = TRUE;
2872 /* Erase with "white space" */
2873 t->attr_blank = TERM_WHITE;
2874 t->char_blank = ' ';
2877 /* Prepare the init/nuke hooks */
2878 t->init_hook = Term_init_win;
2879 t->nuke_hook = Term_nuke_win;
2882 /* Prepare the template hooks */
2883 t->user_hook = Term_user_win;
2884 t->xtra_hook = Term_xtra_win;
2885 t->curs_hook = Term_curs_win;
2886 t->bigcurs_hook = Term_bigcurs_win;
2887 t->wipe_hook = Term_wipe_win;
2888 t->text_hook = Term_text_win;
2889 t->pict_hook = Term_pict_win;
2891 /* Remember where we came from */
2892 t->data = (vptr)(td);
2897 * Create the windows
2899 * First, instantiate the "default" values, then read the "ini_file"
2900 * to over-ride selected values, then create the windows, and fonts.
2902 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2903 * must make active to realize the palette. XXX XXX XXX
2905 static void init_windows(void)
2917 WIPE(td, term_data);
2921 td->s = angband_term_name[0];
2940 for (i = 1; i < MAX_TERM_DATA; i++)
2943 WIPE(td, term_data);
2944 td->s = angband_term_name[i];
2948 td->visible = FALSE;
2953 td->pos_x = (7 - i) * 30;
2954 td->pos_y = (7 - i) * 20;
2966 /* Main window (need these before term_getsize gets called) */
2968 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2969 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2974 /* Sub windows (need these before term_getsize gets called) */
2975 for (i = 1; i < MAX_TERM_DATA; i++)
2978 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2979 td->dwExStyle = (WS_EX_TOOLWINDOW);
2984 for (i = 0; i < MAX_TERM_DATA; i++)
2989 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2990 td->lf.lfCharSet = SHIFTJIS_CHARSET;
2991 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2992 /* Activate the chosen font */
2993 term_force_font(td, NULL);
2994 td->tile_wid = td->font_wid;
2995 td->tile_hgt = td->font_hgt;
2997 /* Access the standard font file */
2998 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3000 /* Activate the chosen font */
3001 if (term_force_font(td, buf))
3003 /* Access the standard font file */
3004 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3006 /* Force the use of that font */
3007 (void)term_force_font(td, buf);
3013 /* Assume not bizarre */
3014 td->bizarre = FALSE;
3019 /* Analyze the font */
3022 /* Resize the window */
3023 term_window_resize(td);
3027 /* Sub windows (reverse order) */
3028 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3033 td->w = CreateWindowEx(td->dwExStyle, AngList,
3035 td->pos_x, td->pos_y,
3036 td->size_wid, td->size_hgt,
3037 HWND_DESKTOP, NULL, hInstance, NULL);
3040 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3042 if (!td->w) quit("Failed to create sub-window");
3048 td->size_hack = TRUE;
3049 ShowWindow(td->w, SW_SHOW);
3050 td->size_hack = FALSE;
3054 angband_term[i] = &td->t;
3058 /* Activate the window */
3059 SetActiveWindow(td->w);
3064 term_window_pos(&data[i], HWND_TOPMOST);
3068 term_window_pos(&data[i], td->w);
3078 td->w = CreateWindowEx(td->dwExStyle, AppName,
3080 td->pos_x, td->pos_y,
3081 td->size_wid, td->size_hgt,
3082 HWND_DESKTOP, NULL, hInstance, NULL);
3085 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3087 if (!td->w) quit("Failed to create Angband window");
3092 angband_term[0] = &td->t;
3094 /* Activate the main window */
3095 SetActiveWindow(td->w);
3097 /* Bring main window back to top */
3098 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3101 /* New palette XXX XXX XXX */
3102 (void)new_palette();
3105 /* Create a "brush" for drawing the "cursor" */
3106 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3109 /* Process pending messages */
3110 (void)Term_xtra_win_flush();
3118 static void setup_menus(void)
3122 HMENU hm = GetMenu(data[0].w);
3125 /* Menu "File", Disable all */
3126 EnableMenuItem(hm, IDM_FILE_NEW,
3127 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3128 EnableMenuItem(hm, IDM_FILE_OPEN,
3129 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3130 EnableMenuItem(hm, IDM_FILE_SAVE,
3131 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3132 EnableMenuItem(hm, IDM_FILE_EXIT,
3133 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3134 EnableMenuItem(hm, IDM_FILE_SCORE,
3135 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3138 /* No character available */
3139 if (!character_generated)
3141 /* Menu "File", Item "New" */
3142 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3144 /* Menu "File", Item "Open" */
3145 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3148 /* A character available */
3149 if (character_generated)
3151 /* Menu "File", Item "Save" */
3152 EnableMenuItem(hm, IDM_FILE_SAVE,
3153 MF_BYCOMMAND | MF_ENABLED);
3156 /* Menu "File", Item "Exit" */
3157 EnableMenuItem(hm, IDM_FILE_EXIT,
3158 MF_BYCOMMAND | MF_ENABLED);
3160 EnableMenuItem(hm, IDM_FILE_SCORE,
3161 MF_BYCOMMAND | MF_ENABLED);
3164 /* Menu "Window::Visibility" */
3165 for (i = 0; i < MAX_TERM_DATA; i++)
3167 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3168 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3170 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3171 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3173 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3174 MF_BYCOMMAND | MF_ENABLED);
3177 /* Menu "Window::Font" */
3178 for (i = 0; i < MAX_TERM_DATA; i++)
3180 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3181 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3183 if (data[i].visible)
3185 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3186 MF_BYCOMMAND | MF_ENABLED);
3190 /* Menu "Window::Window Position Fix" */
3191 for (i = 0; i < MAX_TERM_DATA; i++)
3193 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3194 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3196 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3197 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3199 if (data[i].visible)
3201 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3202 MF_BYCOMMAND | MF_ENABLED);
3206 /* Menu "Window::Bizarre Display" */
3207 for (i = 0; i < MAX_TERM_DATA; i++)
3209 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3210 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3212 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3213 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3215 if (data[i].visible)
3217 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3218 MF_BYCOMMAND | MF_ENABLED);
3223 /* Menu "Window::Increase Tile Width" */
3224 for (i = 0; i < MAX_TERM_DATA; i++)
3226 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3227 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3229 if (data[i].visible)
3231 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3232 MF_BYCOMMAND | MF_ENABLED);
3237 /* Menu "Window::Decrease Tile Width" */
3238 for (i = 0; i < MAX_TERM_DATA; i++)
3240 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3241 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3243 if (data[i].visible)
3245 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3246 MF_BYCOMMAND | MF_ENABLED);
3251 /* Menu "Window::Increase Tile Height" */
3252 for (i = 0; i < MAX_TERM_DATA; i++)
3254 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3255 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3257 if (data[i].visible)
3259 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3260 MF_BYCOMMAND | MF_ENABLED);
3265 /* Menu "Window::Decrease Tile Height" */
3266 for (i = 0; i < MAX_TERM_DATA; i++)
3268 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3269 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3271 if (data[i].visible)
3273 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3274 MF_BYCOMMAND | MF_ENABLED);
3279 /* Menu "Options", disable all */
3280 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3281 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3282 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3283 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3284 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3285 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3286 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3287 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3288 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3289 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3291 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3292 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3295 /* Menu "Options", Item "Map" */
3296 if (use_graphics != GRAPHICS_NONE)
3297 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3299 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3300 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3302 /* Menu "Options", update all */
3303 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3304 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3305 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3306 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3307 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3308 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3309 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3310 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3311 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3312 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3313 CheckMenuItem(hm, IDM_OPTIONS_BG,
3314 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3316 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3317 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3321 /* Menu "Options", Item "Graphics" */
3322 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3323 /* Menu "Options", Item "Graphics" */
3324 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3325 /* Menu "Options", Item "Graphics" */
3326 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3327 /* Menu "Options", Item "Graphics" */
3328 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3329 #endif /* USE_GRAPHICS */
3332 /* Menu "Options", Item "Sound" */
3333 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3334 #endif /* USE_SOUND */
3337 /* Menu "Options", Item "ScreenSaver" */
3338 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3339 MF_BYCOMMAND | MF_ENABLED);
3340 #endif /* USE_SAVER */
3345 * Check for double clicked (or dragged) savefile
3347 * Apparently, Windows copies the entire filename into the first
3348 * piece of the "command line string". Perhaps we should extract
3349 * the "basename" of that filename and append it to the "save" dir.
3351 static void check_for_save_file(LPSTR cmd_line)
3361 /* Extract filename */
3362 strcat(savefile, s);
3364 /* Validate the file */
3365 validate_file(savefile);
3367 /* Game in progress */
3368 game_in_progress = TRUE;
3376 * Process a menu command
3378 static void process_menus(WORD wCmd)
3395 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3397 plog("You cannot do that yet...");
3401 else if (game_in_progress)
3404 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3406 plog("You can't start a new game while you're still playing!");
3412 game_in_progress = TRUE;
3426 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3428 plog("You cannot do that yet...");
3432 else if (game_in_progress)
3435 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3437 plog("You can't open a new game while you're still playing!");
3443 memset(&ofn, 0, sizeof(ofn));
3444 ofn.lStructSize = sizeof(ofn);
3445 ofn.hwndOwner = data[0].w;
3446 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3447 ofn.nFilterIndex = 1;
3448 ofn.lpstrFile = savefile;
3449 ofn.nMaxFile = 1024;
3450 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3451 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3453 if (GetOpenFileName(&ofn))
3455 /* Load 'savefile' */
3456 validate_file(savefile);
3457 game_in_progress = TRUE;
3469 if (game_in_progress && character_generated)
3475 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3477 plog("You may not do that right now.");
3483 /* Hack -- Forget messages */
3488 do_cmd_save_game(FALSE);
3489 #else /* ZANGBAND */
3491 #endif /* ZANGBAND */
3496 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3498 plog("You may not do that right now.");
3508 if (game_in_progress && character_generated)
3514 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3516 plog("You may not do that right now.");
3522 /* Hack -- Forget messages */
3531 /* do_cmd_save_game(FALSE); */
3532 #else /* ZANGBAND */
3533 /* do_cmd_save_game(); */
3534 #endif /* ZANGBAND */
3535 Term_key_push(SPECIAL_KEY_QUIT);
3543 case IDM_FILE_SCORE:
3547 /* Build the filename */
3548 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3550 /* Open the binary high score file, for reading */
3551 highscore_fd = fd_open(buf, O_RDONLY);
3553 /* Paranoia -- No score file */
3554 if (highscore_fd < 0)
3556 msg_print("Score file unavailable.");
3566 /* Display the scores */
3567 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3569 /* Shut the high score file */
3570 (void)fd_close(highscore_fd);
3572 /* Forget the high score fd */
3578 /* Hack - Flush it */
3586 case IDM_WINDOW_VIS_0:
3589 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3591 plog("You are not allowed to do that!");
3598 /* Window visibility */
3599 case IDM_WINDOW_VIS_1:
3600 case IDM_WINDOW_VIS_2:
3601 case IDM_WINDOW_VIS_3:
3602 case IDM_WINDOW_VIS_4:
3603 case IDM_WINDOW_VIS_5:
3604 case IDM_WINDOW_VIS_6:
3605 case IDM_WINDOW_VIS_7:
3607 i = wCmd - IDM_WINDOW_VIS_0;
3609 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3616 ShowWindow(td->w, SW_SHOW);
3617 term_data_redraw(td);
3621 td->visible = FALSE;
3623 ShowWindow(td->w, SW_HIDE);
3630 case IDM_WINDOW_FONT_0:
3631 case IDM_WINDOW_FONT_1:
3632 case IDM_WINDOW_FONT_2:
3633 case IDM_WINDOW_FONT_3:
3634 case IDM_WINDOW_FONT_4:
3635 case IDM_WINDOW_FONT_5:
3636 case IDM_WINDOW_FONT_6:
3637 case IDM_WINDOW_FONT_7:
3639 i = wCmd - IDM_WINDOW_FONT_0;
3641 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3645 term_change_font(td);
3650 /* Window Z Position */
3651 case IDM_WINDOW_POS_1:
3652 case IDM_WINDOW_POS_2:
3653 case IDM_WINDOW_POS_3:
3654 case IDM_WINDOW_POS_4:
3655 case IDM_WINDOW_POS_5:
3656 case IDM_WINDOW_POS_6:
3657 case IDM_WINDOW_POS_7:
3659 i = wCmd - IDM_WINDOW_POS_0;
3661 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3665 if (!td->posfix && td->visible)
3668 term_window_pos(td, HWND_TOPMOST);
3673 term_window_pos(td, data[0].w);
3679 /* Bizarre Display */
3680 case IDM_WINDOW_BIZ_0:
3681 case IDM_WINDOW_BIZ_1:
3682 case IDM_WINDOW_BIZ_2:
3683 case IDM_WINDOW_BIZ_3:
3684 case IDM_WINDOW_BIZ_4:
3685 case IDM_WINDOW_BIZ_5:
3686 case IDM_WINDOW_BIZ_6:
3687 case IDM_WINDOW_BIZ_7:
3689 i = wCmd - IDM_WINDOW_BIZ_0;
3691 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3695 td->bizarre = !td->bizarre;
3699 term_window_resize(td);
3704 /* Increase Tile Width */
3705 case IDM_WINDOW_I_WID_0:
3706 case IDM_WINDOW_I_WID_1:
3707 case IDM_WINDOW_I_WID_2:
3708 case IDM_WINDOW_I_WID_3:
3709 case IDM_WINDOW_I_WID_4:
3710 case IDM_WINDOW_I_WID_5:
3711 case IDM_WINDOW_I_WID_6:
3712 case IDM_WINDOW_I_WID_7:
3714 i = wCmd - IDM_WINDOW_I_WID_0;
3716 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3724 term_window_resize(td);
3729 /* Decrease Tile Height */
3730 case IDM_WINDOW_D_WID_0:
3731 case IDM_WINDOW_D_WID_1:
3732 case IDM_WINDOW_D_WID_2:
3733 case IDM_WINDOW_D_WID_3:
3734 case IDM_WINDOW_D_WID_4:
3735 case IDM_WINDOW_D_WID_5:
3736 case IDM_WINDOW_D_WID_6:
3737 case IDM_WINDOW_D_WID_7:
3739 i = wCmd - IDM_WINDOW_D_WID_0;
3741 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3749 term_window_resize(td);
3754 /* Increase Tile Height */
3755 case IDM_WINDOW_I_HGT_0:
3756 case IDM_WINDOW_I_HGT_1:
3757 case IDM_WINDOW_I_HGT_2:
3758 case IDM_WINDOW_I_HGT_3:
3759 case IDM_WINDOW_I_HGT_4:
3760 case IDM_WINDOW_I_HGT_5:
3761 case IDM_WINDOW_I_HGT_6:
3762 case IDM_WINDOW_I_HGT_7:
3764 i = wCmd - IDM_WINDOW_I_HGT_0;
3766 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3774 term_window_resize(td);
3779 /* Decrease Tile Height */
3780 case IDM_WINDOW_D_HGT_0:
3781 case IDM_WINDOW_D_HGT_1:
3782 case IDM_WINDOW_D_HGT_2:
3783 case IDM_WINDOW_D_HGT_3:
3784 case IDM_WINDOW_D_HGT_4:
3785 case IDM_WINDOW_D_HGT_5:
3786 case IDM_WINDOW_D_HGT_6:
3787 case IDM_WINDOW_D_HGT_7:
3789 i = wCmd - IDM_WINDOW_D_HGT_0;
3791 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3799 term_window_resize(td);
3804 case IDM_OPTIONS_NO_GRAPHICS:
3809 plog("You may not do that right now.");
3813 /* Toggle "arg_graphics" */
3814 if (arg_graphics != GRAPHICS_NONE)
3816 arg_graphics = GRAPHICS_NONE;
3818 /* React to changes */
3819 Term_xtra_win_react();
3821 /* Hack -- Force redraw */
3822 Term_key_push(KTRL('R'));
3828 case IDM_OPTIONS_OLD_GRAPHICS:
3833 plog("You may not do that right now.");
3837 /* Toggle "arg_graphics" */
3838 if (arg_graphics != GRAPHICS_ORIGINAL)
3840 arg_graphics = GRAPHICS_ORIGINAL;
3842 /* React to changes */
3843 Term_xtra_win_react();
3845 /* Hack -- Force redraw */
3846 Term_key_push(KTRL('R'));
3852 case IDM_OPTIONS_NEW_GRAPHICS:
3857 plog("You may not do that right now.");
3861 /* Toggle "arg_graphics" */
3862 if (arg_graphics != GRAPHICS_ADAM_BOLT)
3864 arg_graphics = GRAPHICS_ADAM_BOLT;
3866 /* React to changes */
3867 Term_xtra_win_react();
3869 /* Hack -- Force redraw */
3870 Term_key_push(KTRL('R'));
3876 case IDM_OPTIONS_BIGTILE:
3878 term_data *td = &data[0];
3883 plog("You may not do that right now.");
3887 /* Toggle "arg_sound" */
3888 arg_bigtile = !arg_bigtile;
3891 Term_activate(&td->t);
3893 /* Resize the term */
3894 Term_resize(td->cols, td->rows);
3897 InvalidateRect(td->w, NULL, TRUE);
3902 case IDM_OPTIONS_SOUND:
3907 plog("You may not do that right now.");
3911 /* Toggle "arg_sound" */
3912 arg_sound = !arg_sound;
3914 /* React to changes */
3915 Term_xtra_win_react();
3917 /* Hack -- Force redraw */
3918 Term_key_push(KTRL('R'));
3924 case IDM_OPTIONS_BG:
3929 plog("You may not do that right now.");
3933 /* Toggle "use_bg" */
3938 /* React to changes */
3939 Term_xtra_win_react();
3941 /* Hack -- Force redraw */
3942 Term_key_push(KTRL('R'));
3948 case IDM_OPTIONS_OPEN_BG:
3953 plog("You may not do that right now.");
3958 memset(&ofn, 0, sizeof(ofn));
3959 ofn.lStructSize = sizeof(ofn);
3960 ofn.hwndOwner = data[0].w;
3961 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3962 ofn.nFilterIndex = 1;
3963 ofn.lpstrFile = bg_bitmap_file;
3964 ofn.nMaxFile = 1023;
3965 ofn.lpstrInitialDir = NULL;
3967 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
3969 ofn.lpstrTitle = "Choose wall paper.";
3971 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3973 if (GetOpenFileName(&ofn))
3975 /* Load 'savefile' */
3980 /* React to changes */
3981 Term_xtra_win_react();
3983 /* Hack -- Force redraw */
3984 Term_key_push(KTRL('R'));
3989 case IDM_DUMP_SCREEN_HTML:
3991 static char buf[1024] = "";
3992 memset(&ofn, 0, sizeof(ofn));
3993 ofn.lStructSize = sizeof(ofn);
3994 ofn.hwndOwner = data[0].w;
3995 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
3996 ofn.nFilterIndex = 1;
3997 ofn.lpstrFile = buf;
3998 ofn.nMaxFile = 1023;
3999 ofn.lpstrDefExt = "html";
4000 ofn.lpstrInitialDir = NULL;
4002 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
4004 ofn.lpstrTitle = "Save screen dump as HTML.";
4006 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4008 if (GetSaveFileName(&ofn))
4010 do_cmd_save_screen_html_aux(buf, 0);
4017 case IDM_OPTIONS_SAVER:
4021 DestroyWindow(hwndSaver);
4026 /* Create a screen scaver window */
4027 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4028 "Angband Screensaver",
4029 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4030 0, 0, GetSystemMetrics(SM_CXSCREEN),
4031 GetSystemMetrics(SM_CYSCREEN),
4032 NULL, NULL, hInstance, NULL);
4036 /* Push the window to the bottom XXX XXX XXX */
4037 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4042 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
4044 plog("Failed to create saver window");
4054 case IDM_OPTIONS_MAP:
4060 case IDM_HELP_CONTENTS:
4064 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4065 if (check_file(tmp))
4067 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4072 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4073 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4075 plog_fmt("Cannot find help file: %s", tmp);
4076 plog("Use the online help files instead.");
4081 #else /* HTML_HELP */
4084 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4085 if (check_file(tmp))
4087 sprintf(buf, "winhelp.exe %s", tmp);
4088 WinExec(buf, SW_NORMAL);
4093 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4094 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4096 plog_fmt("Cannot find help file: %s", tmp);
4097 plog("Use the online help files instead.");
4102 #endif /* HTML_HELP */
4110 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4111 WPARAM wParam, LPARAM lParam);
4112 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4113 WPARAM wParam, LPARAM lParam)
4114 #else /* __MWERKS__ */
4115 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4116 WPARAM wParam, LPARAM lParam)
4117 #endif /* __MWERKS__ */
4123 MINMAXINFO FAR *lpmmi;
4129 /* Acquire proper "term_data" info */
4130 td = (term_data *)GetWindowLong(hWnd, 0);
4132 /* Handle message */
4138 SetWindowLong(hWnd, 0, (LONG)(my_td));
4148 case WM_GETMINMAXINFO:
4150 MINMAXINFO FAR *lpmmi;
4153 lpmmi = (MINMAXINFO FAR *)lParam;
4155 /* this message was sent before WM_NCCREATE */
4158 /* Minimum window size is 80x24 */
4159 rc.left = rc.top = 0;
4160 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4161 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4164 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4166 /* Save minimum size */
4167 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4168 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4175 BeginPaint(hWnd, &ps);
4176 if (td) term_data_redraw(td);
4177 EndPaint(hWnd, &ps);
4178 ValidateRect(hWnd, NULL);
4189 /* Extract the modifiers */
4190 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4191 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4192 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4194 /* Handle "special" keys */
4195 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4197 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4198 bool numpad = FALSE;
4200 /* Begin the macro trigger */
4203 /* Send the modifiers */
4204 if (mc) Term_keypress('C');
4205 if (ms) Term_keypress('S');
4206 if (ma) Term_keypress('A');
4208 /* Extract "scan code" */
4209 i = LOBYTE(HIWORD(lParam));
4211 /* Introduce the scan code */
4214 /* Extended key bit */
4218 Term_no_press = TRUE;
4220 /* Numpad Enter and '/' are extended key */
4227 Term_no_press = TRUE;
4229 /* Other extended keys are on full keyboard */
4233 /* Special modifiers for keypad keys */
4234 if (numpad) Term_keypress('K');
4236 /* Encode the hexidecimal scan code */
4237 Term_keypress(hexsym[i/16]);
4238 Term_keypress(hexsym[i%16]);
4240 /* End the macro trigger */
4251 if (Term_no_press) Term_no_press = FALSE;
4252 else Term_keypress(wParam);
4264 if (game_in_progress && character_generated)
4269 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4271 plog("You may not do that right now.");
4276 /* Hack -- Forget messages */
4285 /* do_cmd_save_game(FALSE); */
4286 #else /* ZANGBAND */
4287 /* do_cmd_save_game(); */
4288 #endif /* ZANGBAND */
4304 process_menus(LOWORD(wParam));
4310 /* this message was sent before WM_NCCREATE */
4313 /* it was sent from inside CreateWindowEx */
4314 if (!td->w) return 1;
4316 /* was sent from WM_SIZE */
4317 if (td->size_hack) return 1;
4321 case SIZE_MINIMIZED:
4323 /* Hide sub-windows */
4324 for (i = 1; i < MAX_TERM_DATA; i++)
4326 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4331 case SIZE_MAXIMIZED:
4333 /* fall through XXX XXX XXX */
4338 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4339 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4342 if ((td->cols != cols) || (td->rows != rows))
4344 /* Save the new size */
4349 Term_activate(&td->t);
4351 /* Resize the term */
4352 Term_resize(td->cols, td->rows);
4355 InvalidateRect(td->w, NULL, TRUE);
4358 td->size_hack = TRUE;
4360 /* Show sub-windows */
4361 for (i = 1; i < MAX_TERM_DATA; i++)
4363 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4366 td->size_hack = FALSE;
4374 case WM_PALETTECHANGED:
4376 /* Ignore if palette change caused by itself */
4377 if ((HWND)wParam == hWnd) return 0;
4379 /* Fall through... */
4382 case WM_QUERYNEWPALETTE:
4384 if (!paletted) return 0;
4388 SelectPalette(hdc, hPal, FALSE);
4390 i = RealizePalette(hdc);
4392 /* if any palette entries changed, repaint the window. */
4393 if (i) InvalidateRect(hWnd, NULL, TRUE);
4395 ReleaseDC(hWnd, hdc);
4402 if (wParam && !HIWORD(lParam))
4404 /* Do something to sub-windows */
4405 for (i = 1; i < MAX_TERM_DATA; i++)
4407 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4410 /* Focus on main window */
4419 case WM_ACTIVATEAPP:
4421 for (i = 1; i < MAX_TERM_DATA; i++)
4427 ShowWindow(data[i].w, SW_SHOW);
4431 ShowWindow(data[i].w, SW_HIDE);
4438 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4443 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4444 WPARAM wParam, LPARAM lParam);
4445 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4446 WPARAM wParam, LPARAM lParam)
4447 #else /* __MWERKS__ */
4448 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4449 WPARAM wParam, LPARAM lParam)
4450 #endif /* __MWERKS__ */
4454 MINMAXINFO FAR *lpmmi;
4462 /* Acquire proper "term_data" info */
4463 td = (term_data *)GetWindowLong(hWnd, 0);
4465 /* Process message */
4471 SetWindowLong(hWnd, 0, (LONG)(my_td));
4481 case WM_GETMINMAXINFO:
4483 MINMAXINFO FAR *lpmmi;
4486 lpmmi = (MINMAXINFO FAR *)lParam;
4488 /* this message was sent before WM_NCCREATE */
4491 /* Minimum window size is 80x24 */
4492 rc.left = rc.top = 0;
4493 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4494 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4497 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4499 /* Save minimum size */
4500 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4501 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4511 /* this message was sent before WM_NCCREATE */
4514 /* it was sent from inside CreateWindowEx */
4515 if (!td->w) return 1;
4517 /* was sent from inside WM_SIZE */
4518 if (td->size_hack) return 1;
4520 td->size_hack = TRUE;
4522 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4523 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4526 if ((td->cols != cols) || (td->rows != rows))
4529 term *old_term = Term;
4531 /* Save the new size */
4536 Term_activate(&td->t);
4538 /* Resize the term */
4539 Term_resize(td->cols, td->rows);
4542 Term_activate(old_term);
4545 InvalidateRect(td->w, NULL, TRUE);
4547 /* HACK - Redraw all windows */
4548 p_ptr->window = 0xFFFFFFFF;
4552 td->size_hack = FALSE;
4559 BeginPaint(hWnd, &ps);
4560 if (td) term_data_redraw(td);
4561 EndPaint(hWnd, &ps);
4572 /* Extract the modifiers */
4573 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4574 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4575 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4577 /* Handle "special" keys */
4578 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4580 /* Begin the macro trigger */
4583 /* Send the modifiers */
4584 if (mc) Term_keypress('C');
4585 if (ms) Term_keypress('S');
4586 if (ma) Term_keypress('A');
4588 /* Extract "scan code" */
4589 i = LOBYTE(HIWORD(lParam));
4591 /* Introduce the scan code */
4594 /* Encode the hexidecimal scan code */
4595 Term_keypress(hexsym[i/16]);
4596 Term_keypress(hexsym[i%16]);
4598 /* End the macro trigger */
4609 Term_keypress(wParam);
4613 case WM_PALETTECHANGED:
4615 /* ignore if palette change caused by itself */
4616 if ((HWND)wParam == hWnd) return FALSE;
4617 /* otherwise, fall through!!! */
4620 case WM_QUERYNEWPALETTE:
4622 if (!paletted) return 0;
4624 SelectPalette(hdc, hPal, FALSE);
4625 i = RealizePalette(hdc);
4626 /* if any palette entries changed, repaint the window. */
4627 if (i) InvalidateRect(hWnd, NULL, TRUE);
4628 ReleaseDC(hWnd, hdc);
4632 case WM_NCLBUTTONDOWN:
4636 if (wParam == HTCLOSE) wParam = HTSYSMENU;
4637 #endif /* HTCLOSE */
4639 if (wParam == HTSYSMENU)
4643 td->visible = FALSE;
4644 ShowWindow(td->w, SW_HIDE);
4654 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4660 #define MOUSE_SENS 40
4663 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4664 WPARAM wParam, LPARAM lParam);
4665 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4666 WPARAM wParam, LPARAM lParam)
4667 #else /* __MWERKS__ */
4668 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4669 WPARAM wParam, LPARAM lParam)
4670 #endif /* __MWERKS__ */
4672 static int iMouse = 0;
4673 static WORD xMouse = 0;
4674 static WORD yMouse = 0;
4697 if (LOWORD(wParam) == WA_INACTIVE) break;
4699 /* else fall through */
4703 case WM_LBUTTONDOWN:
4704 case WM_MBUTTONDOWN:
4705 case WM_RBUTTONDOWN:
4708 SendMessage(hWnd, WM_CLOSE, 0, 0);
4716 dx = LOWORD(lParam) - xMouse;
4717 dy = HIWORD(lParam) - yMouse;
4719 if (dx < 0) dx = -dx;
4720 if (dy < 0) dy = -dy;
4722 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
4724 SendMessage(hWnd, WM_CLOSE, 0, 0);
4728 /* Save last location */
4730 xMouse = LOWORD(lParam);
4731 yMouse = HIWORD(lParam);
4738 DestroyWindow(hwndSaver);
4745 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4748 #endif /* USE_SAVER */
4754 /*** Temporary Hooks ***/
4758 * Display warning message (see "z-util.c")
4760 static void hack_plog(cptr str)
4762 /* Give a warning */
4766 MessageBox(NULL, str, "·Ù¹ð¡ª",
4767 MB_ICONEXCLAMATION | MB_OK);
4769 MessageBox(NULL, str, "Warning",
4770 MB_ICONEXCLAMATION | MB_OK);
4778 * Display error message and quit (see "z-util.c")
4780 static void hack_quit(cptr str)
4782 /* Give a warning */
4786 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
4787 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4789 MessageBox(NULL, str, "Error",
4790 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4795 /* Unregister the classes */
4796 UnregisterClass(AppName, hInstance);
4798 /* Destroy the icon */
4799 if (hIcon) DestroyIcon(hIcon);
4807 /*** Various hooks ***/
4811 * Display warning message (see "z-util.c")
4813 static void hook_plog(cptr str)
4819 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
4820 MB_ICONEXCLAMATION | MB_OK);
4822 MessageBox(data[0].w, str, "Warning",
4823 MB_ICONEXCLAMATION | MB_OK);
4831 * Display error message and quit (see "z-util.c")
4833 static void hook_quit(cptr str)
4838 /* Give a warning */
4842 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
4843 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4845 MessageBox(data[0].w, str, "Error",
4846 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4852 /* Save the preferences */
4856 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
4858 /* Destroy all windows */
4859 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
4861 term_force_font(&data[i], NULL);
4862 if (data[i].font_want) string_free(data[i].font_want);
4863 if (data[i].w) DestroyWindow(data[i].w);
4867 /* Free the bitmap stuff */
4869 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
4870 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
4872 #ifdef USE_TRANSPARENCY
4873 if (infMask.hPalette) DeleteObject(infMask.hPalette);
4874 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
4875 #endif /* USE_TRANSPARENCY */
4877 #endif /* USE_GRAPHICS */
4879 /*** Free some other stuff ***/
4881 DeleteObject(hbrYellow);
4886 if (hPal) DeleteObject(hPal);
4888 UnregisterClass(AppName, hInstance);
4890 if (hIcon) DestroyIcon(hIcon);
4897 /*** Initialize ***/
4903 static void init_stuff(void)
4910 /* Get program name with full path */
4911 GetModuleFileName(hInstance, path, 512);
4913 /* Save the "program name" XXX XXX XXX */
4916 /* Get the name of the "*.ini" file */
4917 strcpy(path + strlen(path) - 4, ".INI");
4919 /* Save the the name of the ini-file */
4920 ini_file = string_make(path);
4922 /* Analyze the path */
4928 if (path[i] == '\\')
4935 /* Add "lib" to the path */
4936 strcpy(path + i + 1, "lib\\");
4938 /* Validate the path */
4939 validate_dir(path, TRUE);
4941 /* Init the file paths */
4942 init_file_paths(path);
4944 /* Hack -- Validate the paths */
4945 validate_dir(ANGBAND_DIR_APEX, FALSE);
4946 validate_dir(ANGBAND_DIR_BONE, FALSE);
4948 /* Allow missing 'edit' directory */
4949 if (!check_dir(ANGBAND_DIR_EDIT))
4951 /* Must have 'data'! */
4952 validate_dir(ANGBAND_DIR_DATA, TRUE);
4956 /* Don't need 'data' */
4957 validate_dir(ANGBAND_DIR_DATA, FALSE);
4960 validate_dir(ANGBAND_DIR_FILE, TRUE);
4961 validate_dir(ANGBAND_DIR_HELP, FALSE);
4962 validate_dir(ANGBAND_DIR_INFO, FALSE);
4963 validate_dir(ANGBAND_DIR_PREF, TRUE);
4964 validate_dir(ANGBAND_DIR_SAVE, FALSE);
4965 validate_dir(ANGBAND_DIR_USER, TRUE);
4966 validate_dir(ANGBAND_DIR_XTRA, TRUE);
4968 /* Build the filename */
4970 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
4972 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
4976 /* Hack -- Validate the "news.txt" file */
4977 validate_file(path);
4981 /* Build the "font" path */
4982 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
4984 /* Allocate the path */
4985 ANGBAND_DIR_XTRA_FONT = string_make(path);
4987 /* Validate the "font" directory */
4988 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
4990 /* Build the filename */
4991 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
4993 /* Hack -- Validate the basic font */
4994 validate_file(path);
5000 /* Build the "graf" path */
5001 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5003 /* Allocate the path */
5004 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5006 /* Validate the "graf" directory */
5007 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5009 #endif /* USE_GRAPHICS */
5014 /* Build the "sound" path */
5015 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5017 /* Allocate the path */
5018 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5020 /* Validate the "sound" directory */
5021 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5023 #endif /* USE_SOUND */
5027 /* Build the "music" path */
5028 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5030 /* Allocate the path */
5031 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5033 /* Validate the "music" directory */
5034 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5036 #endif /* USE_MUSIC */
5038 /* Build the "help" path */
5039 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5041 /* Allocate the path */
5042 ANGBAND_DIR_XTRA_HELP = string_make(path);
5044 /* Validate the "help" directory */
5045 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5049 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5050 LPSTR lpCmdLine, int nCmdShow)
5062 if (hPrevInst == NULL)
5064 wc.style = CS_CLASSDC;
5065 wc.lpfnWndProc = AngbandWndProc;
5067 wc.cbWndExtra = 4; /* one long pointer to term_data */
5068 wc.hInstance = hInst;
5069 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5070 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5071 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5072 wc.lpszMenuName = AppName;
5073 wc.lpszClassName = AppName;
5075 if (!RegisterClass(&wc)) exit(1);
5077 wc.lpfnWndProc = AngbandListProc;
5078 wc.lpszMenuName = NULL;
5079 wc.lpszClassName = AngList;
5081 if (!RegisterClass(&wc)) exit(2);
5085 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5086 wc.lpfnWndProc = AngbandSaverProc;
5088 wc.lpszMenuName = NULL;
5089 wc.lpszClassName = "WindowsScreenSaverClass";
5091 if (!RegisterClass(&wc)) exit(3);
5097 /* Temporary hooks */
5098 plog_aux = hack_plog;
5099 quit_aux = hack_quit;
5100 core_aux = hack_quit;
5102 /* Prepare the filepaths */
5105 /* Initialize the keypress analyzer */
5106 for (i = 0; special_key_list[i]; ++i)
5108 special_key[special_key_list[i]] = TRUE;
5110 /* Initialize the keypress analyzer */
5111 for (i = 0; ignore_key_list[i]; ++i)
5113 ignore_key[ignore_key_list[i]] = TRUE;
5116 /* Determine if display is 16/256/true color */
5118 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5119 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5120 ReleaseDC(NULL, hdc);
5122 /* Initialize the colors */
5123 for (i = 0; i < 256; i++)
5127 /* Extract desired values */
5128 rv = angband_color_table[i][1];
5129 gv = angband_color_table[i][2];
5130 bv = angband_color_table[i][3];
5132 /* Extract the "complex" code */
5133 win_clr[i] = PALETTERGB(rv, gv, bv);
5135 /* Save the "simple" code */
5136 angband_color_table[i][0] = win_pal[i];
5139 /* Prepare the windows */
5145 /* Activate hooks */
5146 plog_aux = hook_plog;
5147 quit_aux = hook_quit;
5148 core_aux = hook_quit;
5150 /* Set the system suffix */
5151 ANGBAND_SYS = "win";
5153 /* Set the keyboard suffix */
5154 if (7 != GetKeyboardType(0))
5155 ANGBAND_KEYBOARD = "0";
5158 /* Japanese keyboard */
5159 switch (GetKeyboardType(1))
5161 case 0x0D01: case 0x0D02:
5162 case 0x0D03: case 0x0D04:
5163 case 0x0D05: case 0x0D06:
5165 ANGBAND_KEYBOARD = "NEC98";
5169 ANGBAND_KEYBOARD = "JAPAN";
5177 /* We are now initialized */
5181 if(lpCmdLine[0] == '-'){
5182 switch(lpCmdLine[1])
5187 if (!lpCmdLine[2]) break;
5188 chuukei_server = TRUE;
5189 if(connect_chuukei_server(&lpCmdLine[2])<0){
5190 msg_print("connect fail");
5193 msg_print("connect");
5201 if (!lpCmdLine[2]) break;
5202 chuukei_client = TRUE;
5203 connect_chuukei_server(&lpCmdLine[2]);
5213 /* Did the user double click on a save file? */
5214 if(!chuukei_server) check_for_save_file(lpCmdLine);
5216 /* Did the user double click on a save file? */
5217 check_for_save_file(lpCmdLine);
5220 /* Prompt the user */
5222 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5224 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5229 /* Process messages forever */
5230 while (GetMessage(&msg, NULL, 0, 0))
5232 TranslateMessage(&msg);
5233 DispatchMessage(&msg);
5244 #endif /* WINDOWS */