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);
728 plog_fmt("ÊÉ»æÍÑ¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
733 HDC wnddc, dcimage, dcbg;
734 HBITMAP bmimage, bmimage_old, bmbg_old;
740 dcimage = CreateCompatibleDC(wnddc);
741 dcbg = CreateCompatibleDC(wnddc);
743 bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
744 if (!bmimage) quit("bg.bmp¤¬Æɤߤ³¤á¤Ê¤¤¡ª");
745 bmimage_old = SelectObject(dcimage, bmimage);
747 CreateCompatibleBitmap();
749 ReleaseDC(hwnd, wnddc);
755 static void DrawBG(HDC hdc, RECT *r)
760 int x = r->left, y = r->top;
761 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
767 GetObject(hBG, sizeof(bm), &bm);
768 swid = bm.bmWidth; shgt = bm.bmHeight;
770 hdcSrc = CreateCompatibleDC(hdc);
771 hOld = SelectObject(hdcSrc, hBG);
775 cwid = MIN(swid - sx, r->right - nx);
778 chgt = MIN(shgt - sy, r->bottom - ny);
779 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
781 } while (ny < r->bottom);
784 } while (nx < r->right);
786 SelectObject(hdcSrc, hOld);
792 * Hack -- given a pathname, point at the filename
794 static cptr extract_file_name(cptr s)
798 /* Start at the end */
799 p = s + strlen(s) - 1;
801 /* Back up to divider */
802 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
804 /* Return file name */
811 * Hack -- given a simple filename, extract the "font size" info
813 * Return a pointer to a static buffer holding the capitalized base name.
816 static char *analyze_font(char *path, int *wp, int *hp)
822 /* Start at the end */
823 p = path + strlen(path) - 1;
825 /* Back up to divider */
826 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
828 /* Advance to file name */
834 /* Capitalize (be paranoid) */
835 if (islower(*s)) *s = toupper(*s);
841 /* Extract font width */
845 hgt = s ? atoi(s+1) : 0;
858 * Check for existance of a file
860 static bool check_file(cptr s)
880 attrib = GetFileAttributes(path);
882 /* Require valid filename */
883 if (attrib == INVALID_FILE_NAME) return (FALSE);
885 /* Prohibit directory */
886 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
890 /* Examine and verify */
891 if (_dos_getfileattr(path, &attrib)) return (FALSE);
893 /* Prohibit something */
894 if (attrib & FA_LABEL) return (FALSE);
896 /* Prohibit directory */
897 if (attrib & FA_DIREC) return (FALSE);
907 * Check for existance of a directory
909 static bool check_dir(cptr s)
931 /* Remove trailing backslash */
932 if (i && (path[i-1] == '\\')) path[--i] = '\0';
937 attrib = GetFileAttributes(path);
939 /* Require valid filename */
940 if (attrib == INVALID_FILE_NAME) return (FALSE);
942 /* Require directory */
943 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
947 /* Examine and verify */
948 if (_dos_getfileattr(path, &attrib)) return (FALSE);
950 /* Prohibit something */
951 if (attrib & FA_LABEL) return (FALSE);
953 /* Require directory */
954 if (!(attrib & FA_DIREC)) return (FALSE);
966 static void validate_file(cptr s)
972 quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
974 quit_fmt("Cannot find required file:\n%s", s);
982 * Validate a directory
984 static void validate_dir(cptr s, bool vital)
989 /* This directory contains needed data */
993 quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
995 quit_fmt("Cannot find required directory:\n%s", s);
999 /* Attempt to create this directory */
1002 quit_fmt("Unable to create directory:\n%s", s);
1009 * Get the "size" for a window
1011 static void term_getsize(term_data *td)
1018 if (td->cols < 1) td->cols = 1;
1019 if (td->rows < 1) td->rows = 1;
1022 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1023 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1025 /* Fake window size */
1027 rc.right = rc.left + wid;
1029 rc.bottom = rc.top + hgt;
1032 /* rc.right += 1; */
1033 /* rc.bottom += 1; */
1036 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1039 td->size_wid = rc.right - rc.left;
1040 td->size_hgt = rc.bottom - rc.top;
1042 /* See CreateWindowEx */
1045 /* Extract actual location */
1046 GetWindowRect(td->w, &rc);
1048 /* Save the location */
1049 td->pos_x = rc.left;
1055 * Write the "prefs" for a single term
1057 static void save_prefs_aux(term_data *td, cptr sec_name)
1067 strcpy(buf, td->visible ? "1" : "0");
1068 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1072 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1074 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1077 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1080 wsprintf(buf, "%d", td->lf.lfWidth);
1081 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1082 wsprintf(buf, "%d", td->lf.lfHeight);
1083 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1084 wsprintf(buf, "%d", td->lf.lfWeight);
1085 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1088 strcpy(buf, td->bizarre ? "1" : "0");
1089 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1092 wsprintf(buf, "%d", td->tile_wid);
1093 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1096 wsprintf(buf, "%d", td->tile_hgt);
1097 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1099 /* Window size (x) */
1100 wsprintf(buf, "%d", td->cols);
1101 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1103 /* Window size (y) */
1104 wsprintf(buf, "%d", td->rows);
1105 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1107 /* Acquire position */
1108 GetWindowRect(td->w, &rc);
1110 /* Window position (x) */
1111 wsprintf(buf, "%d", rc.left);
1112 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1114 /* Window position (y) */
1115 wsprintf(buf, "%d", rc.top);
1116 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1118 /* Window Z position */
1119 strcpy(buf, td->posfix ? "1" : "0");
1120 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1127 * We assume that the windows have all been initialized
1129 static void save_prefs(void)
1135 /* Save the "arg_graphics" flag */
1136 sprintf(buf, "%d", arg_graphics);
1137 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1139 /* Save the "arg_bigtile" flag */
1140 strcpy(buf, arg_bigtile ? "1" : "0");
1141 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1143 /* Save the "arg_sound" flag */
1144 strcpy(buf, arg_sound ? "1" : "0");
1145 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1148 strcpy(buf, use_bg ? "1" : "0");
1149 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1150 WritePrivateProfileString("Angband", "BackGroundBitmap",
1151 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1153 /* Save window prefs */
1154 for (i = 0; i < MAX_TERM_DATA; ++i)
1156 term_data *td = &data[i];
1158 sprintf(buf, "Term-%d", i);
1160 save_prefs_aux(td, buf);
1166 * Load the "prefs" for a single term
1168 static void load_prefs_aux(term_data *td, cptr sec_name)
1175 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1177 /* Desired font, with default */
1179 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1181 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1186 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1188 /* Analyze font, save desired font name */
1190 td->font_want = string_make(tmp);
1192 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1193 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1194 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1196 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1202 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1203 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1205 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1206 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1211 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1212 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1214 /* Window position */
1215 td->pos_x = GetPrivateProfileInt(sec_name, "PositionX", td->pos_x, ini_file);
1216 td->pos_y = GetPrivateProfileInt(sec_name, "PositionY", td->pos_y, ini_file);
1218 /* Window Z position */
1219 td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1226 static void load_prefs(void)
1232 /* Extract the "arg_graphics" flag */
1233 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1235 /* Extract the "arg_bigtile" flag */
1236 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1237 use_bigtile = arg_bigtile;
1239 /* Extract the "arg_sound" flag */
1240 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1243 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1244 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1246 /* Load window prefs */
1247 for (i = 0; i < MAX_TERM_DATA; ++i)
1249 term_data *td = &data[i];
1251 sprintf(buf, "Term-%d", i);
1253 load_prefs_aux(td, buf);
1260 * XXX XXX XXX - Taken from files.c.
1262 * Extract "tokens" from a buffer
1264 * This function uses "whitespace" as delimiters, and treats any amount of
1265 * whitespace as a single delimiter. We will never return any empty tokens.
1266 * When given an empty buffer, or a buffer containing only "whitespace", we
1267 * will return no tokens. We will never extract more than "num" tokens.
1269 * By running a token through the "text_to_ascii()" function, you can allow
1270 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1272 * We save pointers to the tokens in "tokens", and return the number found.
1274 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1286 /* Skip leading whitespace */
1287 for ( ; *s && isspace(*s); ++s) /* loop */;
1292 /* Find next whitespace, if any */
1293 for (t = s; *t && !isspace(*t); ++t) /* loop */;
1295 /* Nuke and advance (if necessary) */
1296 if (*t) *t++ = '\0';
1298 /* Save the token */
1309 static void load_sound_prefs(void)
1313 char ini_path[1024];
1314 char wav_path[1024];
1315 char *zz[SAMPLE_MAX];
1317 /* Access the sound.cfg */
1318 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1320 for (i = 0; i < SOUND_MAX; i++)
1322 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1324 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1326 for (j = 0; j < num; j++)
1328 /* Access the sound */
1329 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1331 /* Save the sound filename, if it exists */
1332 if (check_file(wav_path))
1333 sound_file[i][j] = string_make(zz[j]);
1338 #endif /* USE_SOUND */
1341 * Create the new global palette based on the bitmap palette
1342 * (if any), and the standard 16 entry palette derived from
1343 * "win_clr[]" which is used for the basic 16 Angband colors.
1345 * This function is never called before all windows are ready.
1347 * This function returns FALSE if the new palette could not be
1348 * prepared, which should normally be a fatal error. XXX XXX
1350 * Note that only some machines actually use a "palette".
1352 static int new_palette(void)
1360 LPLOGPALETTE pLogPal;
1361 LPPALETTEENTRY lppe;
1366 /* This makes no sense */
1367 if (!paletted) return (TRUE);
1377 /* Check the bitmap palette */
1378 hBmPal = infGraph.hPalette;
1380 /* Use the bitmap */
1383 lppeSize = 256 * sizeof(PALETTEENTRY);
1384 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1385 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1386 if ((nEntries == 0) || (nEntries > 220))
1390 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1392 plog("Please switch to high- or true-color mode.");
1397 rnfree(lppe, lppeSize);
1404 #endif /* USE_GRAPHICS */
1406 /* Size of palette */
1407 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1409 /* Allocate palette */
1410 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1413 pLogPal->palVersion = 0x300;
1415 /* Make room for bitmap and normal data */
1416 pLogPal->palNumEntries = nEntries + 16;
1418 /* Save the bitmap data */
1419 for (i = 0; i < nEntries; i++)
1421 pLogPal->palPalEntry[i] = lppe[i];
1424 /* Save the normal data */
1425 for (i = 0; i < 16; i++)
1429 /* Access the entry */
1430 p = &(pLogPal->palPalEntry[i+nEntries]);
1432 /* Save the colors */
1433 p->peRed = GetRValue(win_clr[i]);
1434 p->peGreen = GetGValue(win_clr[i]);
1435 p->peBlue = GetBValue(win_clr[i]);
1437 /* Save the flags */
1438 p->peFlags = PC_NOCOLLAPSE;
1441 /* Free something */
1442 if (lppe) rnfree(lppe, lppeSize);
1444 /* Create a new palette, or fail */
1445 hNewPal = CreatePalette(pLogPal);
1447 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1449 if (!hNewPal) quit("Cannot create palette!");
1453 /* Free the palette */
1454 rnfree(pLogPal, pLogPalSize);
1459 /* Realize the palette */
1461 SelectPalette(hdc, hNewPal, 0);
1462 i = RealizePalette(hdc);
1463 ReleaseDC(td->w, hdc);
1465 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1467 if (i == 0) quit("Cannot realize palette!");
1472 for (i = 1; i < MAX_TERM_DATA; i++)
1477 SelectPalette(hdc, hNewPal, 0);
1478 ReleaseDC(td->w, hdc);
1481 /* Delete old palette */
1482 if (hPal) DeleteObject(hPal);
1484 /* Save new palette */
1494 * Initialize graphics
1496 static bool init_graphics(void)
1498 /* Initialize once */
1499 /* if (can_use_graphics != arg_graphics) */
1505 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1512 ANGBAND_GRAF = "new";
1520 ANGBAND_GRAF = "old";
1523 /* Access the bitmap file */
1524 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1526 /* Load the bitmap or quit */
1527 if (!ReadDIB(data[0].w, buf, &infGraph))
1530 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1532 plog_fmt("Cannot read bitmap file '%s'", name);
1538 /* Save the new sizes */
1539 infGraph.CellWidth = wid;
1540 infGraph.CellHeight = hgt;
1542 #ifdef USE_TRANSPARENCY
1544 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1546 /* Access the mask file */
1547 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1549 /* Load the bitmap or quit */
1550 if (!ReadDIB(data[0].w, buf, &infMask))
1552 plog_fmt("Cannot read bitmap file '%s'", buf);
1557 #endif /* USE_TRANSPARENCY */
1559 /* Activate a palette */
1562 /* Free bitmap XXX XXX XXX */
1566 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1568 plog("Cannot activate palette!");
1574 /* Graphics available */
1575 can_use_graphics = arg_graphics;
1579 return (can_use_graphics);
1581 #endif /* USE_GRAPHICS */
1588 static bool init_sound(void)
1590 /* Initialize once */
1593 /* Load the prefs */
1596 /* Sound available */
1597 can_use_sound = TRUE;
1601 return (can_use_sound);
1603 #endif /* USE_SOUND */
1609 static void term_window_resize(term_data *td)
1611 /* Require window */
1614 /* Resize the window */
1615 SetWindowPos(td->w, 0, 0, 0,
1616 td->size_wid, td->size_hgt,
1617 SWP_NOMOVE | SWP_NOZORDER);
1620 InvalidateRect(td->w, NULL, TRUE);
1625 * Force the use of a new "font file" for a term_data
1627 * This function may be called before the "window" is ready
1629 * This function returns zero only if everything succeeds.
1631 * Note that the "font name" must be capitalized!!!
1633 static errr term_force_font(term_data *td, cptr path)
1643 /* Forget the old font (if needed) */
1644 if (td->font_id) DeleteObject(td->font_id);
1647 /* Forget old font */
1653 for (i = 0; i < MAX_TERM_DATA; i++)
1655 /* Don't check when closing the application */
1658 /* Check "screen" */
1659 if ((td != &data[i]) &&
1660 (data[i].font_file) &&
1661 (streq(data[i].font_file, td->font_file)))
1667 /* Remove unused font resources */
1668 if (!used) RemoveFontResource(td->font_file);
1670 /* Free the old name */
1671 string_free(td->font_file);
1674 td->font_file = NULL;
1679 if (!path) return (1);
1685 /* Analyze font path */
1686 base = analyze_font(buf, &wid, &hgt);
1689 if (!suffix(base, ".FON")) return (1);
1692 if (!check_file(buf)) return (1);
1694 /* Load the new font */
1695 if (!AddFontResource(buf)) return (1);
1697 /* Save new font name */
1698 td->font_file = string_make(base);
1700 /* Remove the "suffix" */
1701 base[strlen(base)-4] = '\0';
1704 /* Create the font (using the 'base' of the font file name!) */
1706 td->font_id = CreateFontIndirect(&(td->lf));
1707 wid = td->lf.lfWidth;
1708 hgt = td->lf.lfHeight;
1709 if (!td->font_id) return (1);
1711 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1712 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1713 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1714 FIXED_PITCH | FF_DONTCARE, base);
1718 /* Hack -- Unknown size */
1725 /* all this trouble to get the cell size */
1726 hdcDesktop = GetDC(HWND_DESKTOP);
1727 hfOld = SelectObject(hdcDesktop, td->font_id);
1728 GetTextMetrics(hdcDesktop, &tm);
1729 SelectObject(hdcDesktop, hfOld);
1730 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1732 /* Font size info */
1733 wid = tm.tmAveCharWidth;
1737 /* Save the size info */
1748 * Allow the user to change the font for this window.
1750 static void term_change_font(term_data *td)
1755 memset(&cf, 0, sizeof(cf));
1756 cf.lStructSize = sizeof(cf);
1757 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1758 cf.lpLogFont = &(td->lf);
1760 if (ChooseFont(&cf))
1762 /* Force the font */
1763 term_force_font(td, NULL);
1765 /* Assume not bizarre */
1768 /* Reset the tile info */
1769 td->tile_wid = td->font_wid;
1770 td->tile_hgt = td->font_hgt;
1772 /* Analyze the font */
1775 /* Resize the window */
1776 term_window_resize(td);
1782 char tmp[1024] = "";
1784 /* Extract a default if possible */
1785 if (td->font_file) strcpy(tmp, td->font_file);
1787 /* Ask for a choice */
1788 memset(&ofn, 0, sizeof(ofn));
1789 ofn.lStructSize = sizeof(ofn);
1790 ofn.hwndOwner = data[0].w;
1791 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1792 ofn.nFilterIndex = 1;
1793 ofn.lpstrFile = tmp;
1795 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1796 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1797 ofn.lpstrDefExt = "fon";
1799 /* Force choice if legal */
1800 if (GetOpenFileName(&ofn))
1802 /* Force the font */
1803 if (term_force_font(td, tmp))
1805 /* Access the standard font file */
1806 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1808 /* Force the use of that font */
1809 (void)term_force_font(td, tmp);
1812 /* Assume not bizarre */
1813 td->bizarre = FALSE;
1815 /* Reset the tile info */
1816 td->tile_wid = td->font_wid;
1817 td->tile_hgt = td->font_hgt;
1819 /* Analyze the font */
1822 /* Resize the window */
1823 term_window_resize(td);
1830 * Allow the user to lock this window.
1832 static void term_window_pos(term_data *td, HWND hWnd)
1834 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1835 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1838 static void windows_map(void);
1841 * Hack -- redraw a term_data
1843 static void term_data_redraw(term_data *td)
1847 /* Redraw the map */
1852 /* Activate the term */
1853 Term_activate(&td->t);
1855 /* Redraw the contents */
1858 /* Restore the term */
1859 Term_activate(term_screen);
1867 /*** Function hooks needed by "Term" ***/
1873 * Initialize a new Term
1875 static void Term_init_win(term *t)
1884 static void Term_nuke_win(term *t)
1893 * Interact with the User
1895 static errr Term_user_win(int n)
1903 * React to global changes
1905 static errr Term_xtra_win_react(void)
1913 /* Save the default colors */
1914 for (i = 0; i < 256; i++)
1916 /* Simply accept the desired colors */
1917 win_pal[i] = angband_color_table[i][0];
1928 bool change = FALSE;
1930 /* Save the default colors */
1931 for (i = 0; i < 256; i++)
1933 /* Extract desired values */
1934 rv = angband_color_table[i][1];
1935 gv = angband_color_table[i][2];
1936 bv = angband_color_table[i][3];
1938 /* Extract a full color code */
1939 code = PALETTERGB(rv, gv, bv);
1941 /* Activate changes */
1942 if (win_clr[i] != code)
1944 /* Note the change */
1947 /* Apply the desired color */
1952 /* Activate the palette if needed */
1953 if (change) (void)new_palette();
1959 /* Handle "arg_sound" */
1960 if (use_sound != arg_sound)
1962 /* Initialize (if needed) */
1963 if (arg_sound && !init_sound())
1967 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
1969 plog("Cannot initialize sound!");
1977 /* Change setting */
1978 use_sound = arg_sound;
1986 /* Handle "arg_graphics" */
1987 if (use_graphics != arg_graphics)
1989 /* Initialize (if needed) */
1990 if (arg_graphics && !init_graphics())
1994 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
1996 plog("Cannot initialize graphics!");
2001 arg_graphics = GRAPHICS_NONE;
2004 /* Change setting */
2005 use_graphics = arg_graphics;
2008 #ifdef ANGBAND_2_8_1
2010 #else /* ANGBAND_2_8_1 */
2011 reset_visuals(TRUE);
2012 #endif /* ANGBAND_2_8_1 */
2015 #endif /* USE_GRAPHICS */
2018 /* Clean up windows */
2019 for (i = 0; i < MAX_TERM_DATA; i++)
2023 term_data *td = &data[i];
2025 /* Update resized windows */
2026 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2029 Term_activate(&td->t);
2031 /* Hack -- Resize the term */
2032 Term_resize(td->cols, td->rows);
2034 /* Redraw the contents */
2049 * Process at least one event
2051 static errr Term_xtra_win_event(int v)
2055 /* Wait for an event */
2059 if (GetMessage(&msg, NULL, 0, 0))
2061 TranslateMessage(&msg);
2062 DispatchMessage(&msg);
2066 /* Check for an event */
2070 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2072 TranslateMessage(&msg);
2073 DispatchMessage(&msg);
2083 * Process all pending events
2085 static errr Term_xtra_win_flush(void)
2089 /* Process all pending events */
2090 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2092 TranslateMessage(&msg);
2093 DispatchMessage(&msg);
2102 * Hack -- clear the screen
2104 * Make this more efficient XXX XXX XXX
2106 static errr Term_xtra_win_clear(void)
2108 term_data *td = (term_data*)(Term->data);
2113 /* Rectangle to erase */
2114 rc.left = td->size_ow1;
2115 rc.right = rc.left + td->cols * td->tile_wid;
2116 rc.top = td->size_oh1;
2117 rc.bottom = rc.top + td->rows * td->tile_hgt;
2121 SetBkColor(hdc, RGB(0, 0, 0));
2122 SelectObject(hdc, td->font_id);
2123 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2128 rc.left = 0; rc.top = 0;
2131 ReleaseDC(td->w, hdc);
2139 * Hack -- make a noise
2141 static errr Term_xtra_win_noise(void)
2143 MessageBeep(MB_ICONASTERISK);
2149 * Hack -- make a sound
2151 static errr Term_xtra_win_sound(int v)
2156 #endif /* USE_SOUND */
2158 /* Sound disabled */
2159 if (!use_sound) return (1);
2162 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2166 /* Count the samples */
2167 for (i = 0; i < SAMPLE_MAX; i++)
2169 if (!sound_file[v][i])
2174 if (i == 0) return (1);
2176 /* Build the path */
2177 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_simple(i)]);
2181 /* Play the sound, catch errors */
2182 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2186 /* Play the sound, catch errors */
2187 return (sndPlaySound(buf, SND_ASYNC));
2191 #else /* USE_SOUND */
2196 #endif /* USE_SOUND */
2201 * Delay for "x" milliseconds
2203 static int Term_xtra_win_delay(int v)
2217 t = GetTickCount() + v;
2220 while (GetTickCount() < t)
2222 /* Handle messages */
2223 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2225 TranslateMessage(&msg);
2226 DispatchMessage(&msg);
2238 * Do a "special thing"
2240 static errr Term_xtra_win(int n, int v)
2242 /* Handle a subset of the legal requests */
2245 /* Make a bell sound */
2246 case TERM_XTRA_NOISE:
2248 return (Term_xtra_win_noise());
2251 /* Make a special sound */
2252 case TERM_XTRA_SOUND:
2254 return (Term_xtra_win_sound(v));
2257 /* Process random events */
2258 case TERM_XTRA_BORED:
2260 return (Term_xtra_win_event(0));
2263 /* Process an event */
2264 case TERM_XTRA_EVENT:
2266 return (Term_xtra_win_event(v));
2269 /* Flush all events */
2270 case TERM_XTRA_FLUSH:
2272 return (Term_xtra_win_flush());
2275 /* Clear the screen */
2276 case TERM_XTRA_CLEAR:
2278 return (Term_xtra_win_clear());
2281 /* React to global changes */
2282 case TERM_XTRA_REACT:
2284 return (Term_xtra_win_react());
2287 /* Delay for some milliseconds */
2288 case TERM_XTRA_DELAY:
2290 return (Term_xtra_win_delay(v));
2301 * Low level graphics (Assumes valid input).
2303 * Draw a "cursor" at (x,y), using a "yellow box".
2305 static errr Term_curs_win(int x, int y)
2307 term_data *td = (term_data*)(Term->data);
2312 int tile_wid, tile_hgt;
2316 tile_wid = td->map_tile_wid;
2317 tile_hgt = td->map_tile_hgt;
2321 tile_wid = td->tile_wid;
2322 tile_hgt = td->tile_hgt;
2325 /* Frame the grid */
2326 rc.left = x * tile_wid + td->size_ow1;
2327 rc.right = rc.left + tile_wid;
2328 rc.top = y * tile_hgt + td->size_oh1;
2329 rc.bottom = rc.top + tile_hgt;
2331 /* Cursor is done as a yellow "box" */
2333 FrameRect(hdc, &rc, hbrYellow);
2334 ReleaseDC(td->w, hdc);
2342 * Low level graphics (Assumes valid input).
2344 * Draw a "big cursor" at (x,y), using a "yellow box".
2346 static errr Term_bigcurs_win(int x, int y)
2348 term_data *td = (term_data*)(Term->data);
2353 int tile_wid, tile_hgt;
2357 /* Normal cursor in map window */
2358 Term_curs_win(x, y);
2363 tile_wid = td->tile_wid;
2364 tile_hgt = td->tile_hgt;
2367 /* Frame the grid */
2368 rc.left = x * tile_wid + td->size_ow1;
2369 rc.right = rc.left + 2 * tile_wid;
2370 rc.top = y * tile_hgt + td->size_oh1;
2371 rc.bottom = rc.top + tile_hgt;
2373 /* Cursor is done as a yellow "box" */
2375 FrameRect(hdc, &rc, hbrYellow);
2376 ReleaseDC(td->w, hdc);
2384 * Low level graphics (Assumes valid input).
2386 * Erase a "block" of "n" characters starting at (x,y).
2388 static errr Term_wipe_win(int x, int y, int n)
2390 term_data *td = (term_data*)(Term->data);
2395 /* Rectangle to erase in client coords */
2396 rc.left = x * td->tile_wid + td->size_ow1;
2397 rc.right = rc.left + n * td->tile_wid;
2398 rc.top = y * td->tile_hgt + td->size_oh1;
2399 rc.bottom = rc.top + td->tile_hgt;
2402 SetBkColor(hdc, RGB(0, 0, 0));
2403 SelectObject(hdc, td->font_id);
2408 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2409 ReleaseDC(td->w, hdc);
2417 * Low level graphics. Assumes valid input.
2419 * Draw several ("n") chars, with an attr, at a given location.
2421 * All "graphic" data is handled by "Term_pict_win()", below.
2423 * One would think there is a more efficient method for telling a window
2424 * what color it should be using to draw with, but perhaps simply changing
2425 * it every time is not too inefficient. XXX XXX XXX
2427 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2429 term_data *td = (term_data*)(Term->data);
2435 static HBITMAP WALL;
2436 static HBRUSH myBrush, oldBrush;
2438 static bool init_done = FALSE;
2441 WALL = LoadBitmap(hInstance, AppName);
2442 myBrush = CreatePatternBrush(WALL);
2447 /* Total rectangle */
2448 rc.left = x * td->tile_wid + td->size_ow1;
2449 rc.right = rc.left + n * td->tile_wid;
2450 rc.top = y * td->tile_hgt + td->size_oh1;
2451 rc.bottom = rc.top + td->tile_hgt;
2456 /* Background color */
2457 SetBkColor(hdc, RGB(0, 0, 0));
2459 /* Foreground color */
2462 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2466 SetTextColor(hdc, win_clr[a&0x0F]);
2470 SetTextColor(hdc, win_clr[a]);
2474 SelectObject(hdc, td->font_id);
2477 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2481 (td->tile_hgt != td->font_hgt) ||
2482 (td->tile_wid != td->font_wid))
2486 /* Erase complete rectangle */
2487 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2490 if (use_bg) DrawBG(hdc, &rc);
2493 rc.left += ((td->tile_wid - td->font_wid) / 2);
2494 rc.right = rc.left + td->font_wid;
2495 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2496 rc.bottom = rc.top + td->font_hgt;
2498 /* Dump each character */
2499 for (i = 0; i < n; i++)
2502 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2504 rc.right += td->font_wid;
2506 oldBrush = SelectObject(hdc, myBrush);
2507 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2510 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2512 SelectObject(hdc, oldBrush);
2513 SelectObject(hdc, oldPen);
2514 rc.right -= td->font_wid;
2518 rc.left += 2 * td->tile_wid;
2519 rc.right += 2 * td->tile_wid;
2521 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2523 rc.right += td->font_wid;
2525 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2527 rc.right -= td->font_wid;
2531 rc.left += 2 * td->tile_wid;
2532 rc.right += 2 * td->tile_wid;
2533 } else if (*(s+i)==127){
2534 oldBrush = SelectObject(hdc, myBrush);
2535 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2538 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2540 SelectObject(hdc, oldBrush);
2541 SelectObject(hdc, oldPen);
2544 rc.left += td->tile_wid;
2545 rc.right += td->tile_wid;
2548 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2552 rc.left += td->tile_wid;
2553 rc.right += td->tile_wid;
2557 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2561 rc.left += td->tile_wid;
2562 rc.right += td->tile_wid;
2572 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2577 ReleaseDC(td->w, hdc);
2585 * Low level graphics. Assumes valid input.
2587 * Draw an array of "special" attr/char pairs at the given location.
2589 * We use the "Term_pict_win()" function for "graphic" data, which are
2590 * encoded by setting the "high-bits" of both the "attr" and the "char"
2591 * data. We use the "attr" to represent the "row" of the main bitmap,
2592 * and the "char" to represent the "col" of the main bitmap. The use
2593 * of this function is induced by the "higher_pict" flag.
2595 * If "graphics" is not available, we simply "wipe" the given grids.
2597 # ifdef USE_TRANSPARENCY
2598 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2599 # else /* USE_TRANSPARENCY */
2600 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp)
2601 # endif /* USE_TRANSPARENCY */
2603 term_data *td = (term_data*)(Term->data);
2609 int x2, y2, w2, h2, tw2;
2611 # ifdef USE_TRANSPARENCY
2617 # endif /* USE_TRANSPARENCY */
2626 /* Erase the grids */
2627 return (Term_wipe_win(x, y, n));
2630 /* Size of bitmap cell */
2631 w1 = infGraph.CellWidth;
2632 h1 = infGraph.CellHeight;
2634 /* Size of window cell */
2637 w2 = td->map_tile_wid;
2638 h2 = td->map_tile_hgt;
2647 if (use_bigtile) tw2 *= 2;
2650 /* Location of window cell */
2651 x2 = x * w2 + td->size_ow1;
2652 y2 = y * h2 + td->size_oh1;
2658 hdcSrc = CreateCompatibleDC(hdc);
2659 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2661 # ifdef USE_TRANSPARENCY
2663 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2665 hdcMask = CreateCompatibleDC(hdc);
2666 SelectObject(hdcMask, infMask.hBitmap);
2669 # endif /* USE_TRANSPARENCY */
2671 /* Draw attr/char pairs */
2672 for (i = 0; i < n; i++, x2 += w2)
2677 /* Extract picture */
2678 int row = (a & 0x7F);
2679 int col = (c & 0x7F);
2681 /* Location of bitmap cell */
2685 # ifdef USE_TRANSPARENCY
2687 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2689 x3 = (tcp[i] & 0x7F) * w1;
2690 y3 = (tap[i] & 0x7F) * h1;
2693 if ((w1 == tw2) && (h1 == h2))
2695 /* Copy the terrain picture from the bitmap to the window */
2696 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2698 /* Mask out the tile */
2699 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2702 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2705 /* Need to stretch */
2708 /* Set the correct mode for stretching the tiles */
2709 SetStretchBltMode(hdc, COLORONCOLOR);
2711 /* Copy the terrain picture from the bitmap to the window */
2712 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
2714 /* Only draw if terrain and overlay are different */
2715 if ((x1 != x3) || (y1 != y3))
2717 /* Mask out the tile */
2718 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2721 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2727 # endif /* USE_TRANSPARENCY */
2731 if ((w1 == tw2) && (h1 == h2))
2733 /* Copy the picture from the bitmap to the window */
2734 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2737 /* Need to stretch */
2740 /* Set the correct mode for stretching the tiles */
2741 SetStretchBltMode(hdc, COLORONCOLOR);
2743 /* Copy the picture from the bitmap to the window */
2744 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2750 SelectObject(hdcSrc, hbmSrcOld);
2753 # ifdef USE_TRANSPARENCY
2755 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2758 SelectObject(hdcMask, hbmSrcOld);
2762 # endif /* USE_TRANSPARENCY */
2765 ReleaseDC(td->w, hdc);
2767 #else /* USE_GRAPHICS */
2769 /* Just erase this grid */
2770 return (Term_wipe_win(x, y, n));
2772 #endif /* USE_GRAPHICS */
2779 static void windows_map(void)
2781 term_data *td = &data[0];
2783 int x, min_x, max_x;
2784 int y, min_y, max_y;
2786 #ifdef USE_TRANSPARENCY
2790 /* Only in graphics mode */
2791 if (!use_graphics) return;
2794 Term_xtra_win_clear();
2796 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2797 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2798 td->map_active = TRUE;
2808 for (x = min_x; x < max_x; x++)
2810 for (y = min_y; y < max_y; y++)
2812 #ifdef USE_TRANSPARENCY
2813 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
2814 #else /* USE_TRANSPARENCY */
2815 map_info(y, x, &a, (char*)&c);
2816 #endif /* USE_TRANSPARENCY */
2818 /* Ignore non-graphics */
2819 if ((a & 0x80) && (c & 0x80))
2821 #ifdef USE_TRANSPARENCY
2822 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2823 #else /* USE_TRANSPARENCY */
2824 Term_pict_win(x - min_x, y - min_y, 1, &a, &c);
2825 #endif /* USE_TRANSPARENCY */
2830 /* Hilite the player */
2831 Term_curs_win(px - min_x, py - min_y);
2833 /* Wait for a keypress, flush key buffer */
2834 Term_inkey(&c, TRUE, TRUE);
2837 /* Switch off the map display */
2838 td->map_active = FALSE;
2840 /* Restore screen */
2841 Term_xtra_win_clear();
2846 /*** Other routines ***/
2850 * Create and initialize a "term_data" given a title
2852 static void term_data_link(term_data *td)
2856 /* Initialize the term */
2857 term_init(t, td->cols, td->rows, td->keys);
2859 /* Use a "software" cursor */
2860 t->soft_cursor = TRUE;
2862 /* Use "Term_pict" for "graphic" data */
2863 t->higher_pict = TRUE;
2865 /* Erase with "white space" */
2866 t->attr_blank = TERM_WHITE;
2867 t->char_blank = ' ';
2870 /* Prepare the init/nuke hooks */
2871 t->init_hook = Term_init_win;
2872 t->nuke_hook = Term_nuke_win;
2875 /* Prepare the template hooks */
2876 t->user_hook = Term_user_win;
2877 t->xtra_hook = Term_xtra_win;
2878 t->curs_hook = Term_curs_win;
2879 t->bigcurs_hook = Term_bigcurs_win;
2880 t->wipe_hook = Term_wipe_win;
2881 t->text_hook = Term_text_win;
2882 t->pict_hook = Term_pict_win;
2884 /* Remember where we came from */
2885 t->data = (vptr)(td);
2890 * Create the windows
2892 * First, instantiate the "default" values, then read the "ini_file"
2893 * to over-ride selected values, then create the windows, and fonts.
2895 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2896 * must make active to realize the palette. XXX XXX XXX
2898 static void init_windows(void)
2910 WIPE(td, term_data);
2914 td->s = angband_term_name[0];
2933 for (i = 1; i < MAX_TERM_DATA; i++)
2936 WIPE(td, term_data);
2937 td->s = angband_term_name[i];
2941 td->visible = FALSE;
2946 td->pos_x = (7 - i) * 30;
2947 td->pos_y = (7 - i) * 20;
2959 /* Main window (need these before term_getsize gets called) */
2961 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2962 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2967 /* Sub windows (need these before term_getsize gets called) */
2968 for (i = 1; i < MAX_TERM_DATA; i++)
2971 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2972 td->dwExStyle = (WS_EX_TOOLWINDOW);
2977 for (i = 0; i < MAX_TERM_DATA; i++)
2982 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2983 td->lf.lfCharSet = SHIFTJIS_CHARSET;
2984 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2985 /* Activate the chosen font */
2986 term_force_font(td, NULL);
2987 td->tile_wid = td->font_wid;
2988 td->tile_hgt = td->font_hgt;
2990 /* Access the standard font file */
2991 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
2993 /* Activate the chosen font */
2994 if (term_force_font(td, buf))
2996 /* Access the standard font file */
2997 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2999 /* Force the use of that font */
3000 (void)term_force_font(td, buf);
3006 /* Assume not bizarre */
3007 td->bizarre = FALSE;
3012 /* Analyze the font */
3015 /* Resize the window */
3016 term_window_resize(td);
3020 /* Sub windows (reverse order) */
3021 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3026 td->w = CreateWindowEx(td->dwExStyle, AngList,
3028 td->pos_x, td->pos_y,
3029 td->size_wid, td->size_hgt,
3030 HWND_DESKTOP, NULL, hInstance, NULL);
3033 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3035 if (!td->w) quit("Failed to create sub-window");
3041 td->size_hack = TRUE;
3042 ShowWindow(td->w, SW_SHOW);
3043 td->size_hack = FALSE;
3047 angband_term[i] = &td->t;
3051 /* Activate the window */
3052 SetActiveWindow(td->w);
3057 term_window_pos(&data[i], HWND_TOPMOST);
3061 term_window_pos(&data[i], td->w);
3071 td->w = CreateWindowEx(td->dwExStyle, AppName,
3073 td->pos_x, td->pos_y,
3074 td->size_wid, td->size_hgt,
3075 HWND_DESKTOP, NULL, hInstance, NULL);
3078 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3080 if (!td->w) quit("Failed to create Angband window");
3085 angband_term[0] = &td->t;
3087 /* Activate the main window */
3088 SetActiveWindow(td->w);
3090 /* Bring main window back to top */
3091 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3094 /* New palette XXX XXX XXX */
3095 (void)new_palette();
3098 /* Create a "brush" for drawing the "cursor" */
3099 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3102 /* Process pending messages */
3103 (void)Term_xtra_win_flush();
3111 static void setup_menus(void)
3115 HMENU hm = GetMenu(data[0].w);
3118 /* Menu "File", Disable all */
3119 EnableMenuItem(hm, IDM_FILE_NEW,
3120 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3121 EnableMenuItem(hm, IDM_FILE_OPEN,
3122 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3123 EnableMenuItem(hm, IDM_FILE_SAVE,
3124 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3125 EnableMenuItem(hm, IDM_FILE_EXIT,
3126 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3127 EnableMenuItem(hm, IDM_FILE_SCORE,
3128 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3131 /* No character available */
3132 if (!character_generated)
3134 /* Menu "File", Item "New" */
3135 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3137 /* Menu "File", Item "Open" */
3138 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3141 /* A character available */
3142 if (character_generated)
3144 /* Menu "File", Item "Save" */
3145 EnableMenuItem(hm, IDM_FILE_SAVE,
3146 MF_BYCOMMAND | MF_ENABLED);
3149 /* Menu "File", Item "Exit" */
3150 EnableMenuItem(hm, IDM_FILE_EXIT,
3151 MF_BYCOMMAND | MF_ENABLED);
3153 EnableMenuItem(hm, IDM_FILE_SCORE,
3154 MF_BYCOMMAND | MF_ENABLED);
3157 /* Menu "Window::Visibility" */
3158 for (i = 0; i < MAX_TERM_DATA; i++)
3160 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3161 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3163 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3164 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3166 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3167 MF_BYCOMMAND | MF_ENABLED);
3170 /* Menu "Window::Font" */
3171 for (i = 0; i < MAX_TERM_DATA; i++)
3173 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3174 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3176 if (data[i].visible)
3178 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3179 MF_BYCOMMAND | MF_ENABLED);
3183 /* Menu "Window::Window Position Fix" */
3184 for (i = 0; i < MAX_TERM_DATA; i++)
3186 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3187 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3189 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3190 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3192 if (data[i].visible)
3194 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3195 MF_BYCOMMAND | MF_ENABLED);
3199 /* Menu "Window::Bizarre Display" */
3200 for (i = 0; i < MAX_TERM_DATA; i++)
3202 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3203 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3205 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3206 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3208 if (data[i].visible)
3210 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3211 MF_BYCOMMAND | MF_ENABLED);
3216 /* Menu "Window::Increase Tile Width" */
3217 for (i = 0; i < MAX_TERM_DATA; i++)
3219 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3220 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3222 if (data[i].visible)
3224 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3225 MF_BYCOMMAND | MF_ENABLED);
3230 /* Menu "Window::Decrease Tile Width" */
3231 for (i = 0; i < MAX_TERM_DATA; i++)
3233 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3234 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3236 if (data[i].visible)
3238 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3239 MF_BYCOMMAND | MF_ENABLED);
3244 /* Menu "Window::Increase Tile Height" */
3245 for (i = 0; i < MAX_TERM_DATA; i++)
3247 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3248 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3250 if (data[i].visible)
3252 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3253 MF_BYCOMMAND | MF_ENABLED);
3258 /* Menu "Window::Decrease Tile Height" */
3259 for (i = 0; i < MAX_TERM_DATA; i++)
3261 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3262 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3264 if (data[i].visible)
3266 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3267 MF_BYCOMMAND | MF_ENABLED);
3272 /* Menu "Options", disable all */
3273 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3274 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3275 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3276 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3277 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3278 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3279 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3280 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3281 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3282 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3284 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3285 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3288 /* Menu "Options", Item "Map" */
3289 if (use_graphics != GRAPHICS_NONE)
3290 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3292 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3293 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3295 /* Menu "Options", update all */
3296 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3297 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3298 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3299 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3300 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3301 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3302 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3303 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3304 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3305 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3306 CheckMenuItem(hm, IDM_OPTIONS_BG,
3307 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3309 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3310 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3314 /* Menu "Options", Item "Graphics" */
3315 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3316 /* Menu "Options", Item "Graphics" */
3317 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3318 /* Menu "Options", Item "Graphics" */
3319 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3320 /* Menu "Options", Item "Graphics" */
3321 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3322 #endif /* USE_GRAPHICS */
3325 /* Menu "Options", Item "Sound" */
3326 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3327 #endif /* USE_SOUND */
3330 /* Menu "Options", Item "ScreenSaver" */
3331 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3332 MF_BYCOMMAND | MF_ENABLED);
3333 #endif /* USE_SAVER */
3338 * Check for double clicked (or dragged) savefile
3340 * Apparently, Windows copies the entire filename into the first
3341 * piece of the "command line string". Perhaps we should extract
3342 * the "basename" of that filename and append it to the "save" dir.
3344 static void check_for_save_file(LPSTR cmd_line)
3354 /* Extract filename */
3355 strcat(savefile, s);
3357 /* Validate the file */
3358 validate_file(savefile);
3360 /* Game in progress */
3361 game_in_progress = TRUE;
3369 * Process a menu command
3371 static void process_menus(WORD wCmd)
3388 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3390 plog("You cannot do that yet...");
3394 else if (game_in_progress)
3397 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3399 plog("You can't start a new game while you're still playing!");
3405 game_in_progress = TRUE;
3419 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3421 plog("You cannot do that yet...");
3425 else if (game_in_progress)
3428 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3430 plog("You can't open a new game while you're still playing!");
3436 memset(&ofn, 0, sizeof(ofn));
3437 ofn.lStructSize = sizeof(ofn);
3438 ofn.hwndOwner = data[0].w;
3439 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3440 ofn.nFilterIndex = 1;
3441 ofn.lpstrFile = savefile;
3442 ofn.nMaxFile = 1024;
3443 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3444 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3446 if (GetOpenFileName(&ofn))
3448 /* Load 'savefile' */
3449 validate_file(savefile);
3450 game_in_progress = TRUE;
3462 if (game_in_progress && character_generated)
3468 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3470 plog("You may not do that right now.");
3476 /* Hack -- Forget messages */
3481 do_cmd_save_game(FALSE);
3482 #else /* ZANGBAND */
3484 #endif /* ZANGBAND */
3489 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3491 plog("You may not do that right now.");
3501 if (game_in_progress && character_generated)
3507 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3509 plog("You may not do that right now.");
3515 /* Hack -- Forget messages */
3524 /* do_cmd_save_game(FALSE); */
3525 #else /* ZANGBAND */
3526 /* do_cmd_save_game(); */
3527 #endif /* ZANGBAND */
3528 Term_key_push(SPECIAL_KEY_QUIT);
3536 case IDM_FILE_SCORE:
3540 /* Build the filename */
3541 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3543 /* Open the binary high score file, for reading */
3544 highscore_fd = fd_open(buf, O_RDONLY);
3546 /* Paranoia -- No score file */
3547 if (highscore_fd < 0)
3549 msg_print("Score file unavailable.");
3559 /* Display the scores */
3560 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3562 /* Shut the high score file */
3563 (void)fd_close(highscore_fd);
3565 /* Forget the high score fd */
3571 /* Hack - Flush it */
3579 case IDM_WINDOW_VIS_0:
3582 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3584 plog("You are not allowed to do that!");
3591 /* Window visibility */
3592 case IDM_WINDOW_VIS_1:
3593 case IDM_WINDOW_VIS_2:
3594 case IDM_WINDOW_VIS_3:
3595 case IDM_WINDOW_VIS_4:
3596 case IDM_WINDOW_VIS_5:
3597 case IDM_WINDOW_VIS_6:
3598 case IDM_WINDOW_VIS_7:
3600 i = wCmd - IDM_WINDOW_VIS_0;
3602 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3609 ShowWindow(td->w, SW_SHOW);
3610 term_data_redraw(td);
3614 td->visible = FALSE;
3616 ShowWindow(td->w, SW_HIDE);
3623 case IDM_WINDOW_FONT_0:
3624 case IDM_WINDOW_FONT_1:
3625 case IDM_WINDOW_FONT_2:
3626 case IDM_WINDOW_FONT_3:
3627 case IDM_WINDOW_FONT_4:
3628 case IDM_WINDOW_FONT_5:
3629 case IDM_WINDOW_FONT_6:
3630 case IDM_WINDOW_FONT_7:
3632 i = wCmd - IDM_WINDOW_FONT_0;
3634 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3638 term_change_font(td);
3643 /* Window Z Position */
3644 case IDM_WINDOW_POS_1:
3645 case IDM_WINDOW_POS_2:
3646 case IDM_WINDOW_POS_3:
3647 case IDM_WINDOW_POS_4:
3648 case IDM_WINDOW_POS_5:
3649 case IDM_WINDOW_POS_6:
3650 case IDM_WINDOW_POS_7:
3652 i = wCmd - IDM_WINDOW_POS_0;
3654 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3658 if (!td->posfix && td->visible)
3661 term_window_pos(td, HWND_TOPMOST);
3666 term_window_pos(td, data[0].w);
3672 /* Bizarre Display */
3673 case IDM_WINDOW_BIZ_0:
3674 case IDM_WINDOW_BIZ_1:
3675 case IDM_WINDOW_BIZ_2:
3676 case IDM_WINDOW_BIZ_3:
3677 case IDM_WINDOW_BIZ_4:
3678 case IDM_WINDOW_BIZ_5:
3679 case IDM_WINDOW_BIZ_6:
3680 case IDM_WINDOW_BIZ_7:
3682 i = wCmd - IDM_WINDOW_BIZ_0;
3684 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3688 td->bizarre = !td->bizarre;
3692 term_window_resize(td);
3697 /* Increase Tile Width */
3698 case IDM_WINDOW_I_WID_0:
3699 case IDM_WINDOW_I_WID_1:
3700 case IDM_WINDOW_I_WID_2:
3701 case IDM_WINDOW_I_WID_3:
3702 case IDM_WINDOW_I_WID_4:
3703 case IDM_WINDOW_I_WID_5:
3704 case IDM_WINDOW_I_WID_6:
3705 case IDM_WINDOW_I_WID_7:
3707 i = wCmd - IDM_WINDOW_I_WID_0;
3709 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3717 term_window_resize(td);
3722 /* Decrease Tile Height */
3723 case IDM_WINDOW_D_WID_0:
3724 case IDM_WINDOW_D_WID_1:
3725 case IDM_WINDOW_D_WID_2:
3726 case IDM_WINDOW_D_WID_3:
3727 case IDM_WINDOW_D_WID_4:
3728 case IDM_WINDOW_D_WID_5:
3729 case IDM_WINDOW_D_WID_6:
3730 case IDM_WINDOW_D_WID_7:
3732 i = wCmd - IDM_WINDOW_D_WID_0;
3734 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3742 term_window_resize(td);
3747 /* Increase Tile Height */
3748 case IDM_WINDOW_I_HGT_0:
3749 case IDM_WINDOW_I_HGT_1:
3750 case IDM_WINDOW_I_HGT_2:
3751 case IDM_WINDOW_I_HGT_3:
3752 case IDM_WINDOW_I_HGT_4:
3753 case IDM_WINDOW_I_HGT_5:
3754 case IDM_WINDOW_I_HGT_6:
3755 case IDM_WINDOW_I_HGT_7:
3757 i = wCmd - IDM_WINDOW_I_HGT_0;
3759 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3767 term_window_resize(td);
3772 /* Decrease Tile Height */
3773 case IDM_WINDOW_D_HGT_0:
3774 case IDM_WINDOW_D_HGT_1:
3775 case IDM_WINDOW_D_HGT_2:
3776 case IDM_WINDOW_D_HGT_3:
3777 case IDM_WINDOW_D_HGT_4:
3778 case IDM_WINDOW_D_HGT_5:
3779 case IDM_WINDOW_D_HGT_6:
3780 case IDM_WINDOW_D_HGT_7:
3782 i = wCmd - IDM_WINDOW_D_HGT_0;
3784 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3792 term_window_resize(td);
3797 case IDM_OPTIONS_NO_GRAPHICS:
3802 plog("You may not do that right now.");
3806 /* Toggle "arg_graphics" */
3807 if (arg_graphics != GRAPHICS_NONE)
3809 arg_graphics = GRAPHICS_NONE;
3811 /* React to changes */
3812 Term_xtra_win_react();
3814 /* Hack -- Force redraw */
3815 Term_key_push(KTRL('R'));
3821 case IDM_OPTIONS_OLD_GRAPHICS:
3826 plog("You may not do that right now.");
3830 /* Toggle "arg_graphics" */
3831 if (arg_graphics != GRAPHICS_ORIGINAL)
3833 arg_graphics = GRAPHICS_ORIGINAL;
3835 /* React to changes */
3836 Term_xtra_win_react();
3838 /* Hack -- Force redraw */
3839 Term_key_push(KTRL('R'));
3845 case IDM_OPTIONS_NEW_GRAPHICS:
3850 plog("You may not do that right now.");
3854 /* Toggle "arg_graphics" */
3855 if (arg_graphics != GRAPHICS_ADAM_BOLT)
3857 arg_graphics = GRAPHICS_ADAM_BOLT;
3859 /* React to changes */
3860 Term_xtra_win_react();
3862 /* Hack -- Force redraw */
3863 Term_key_push(KTRL('R'));
3869 case IDM_OPTIONS_BIGTILE:
3871 term_data *td = &data[0];
3876 plog("You may not do that right now.");
3880 /* Toggle "arg_sound" */
3881 arg_bigtile = !arg_bigtile;
3884 Term_activate(&td->t);
3886 /* Resize the term */
3887 Term_resize(td->cols, td->rows);
3890 InvalidateRect(td->w, NULL, TRUE);
3895 case IDM_OPTIONS_SOUND:
3900 plog("You may not do that right now.");
3904 /* Toggle "arg_sound" */
3905 arg_sound = !arg_sound;
3907 /* React to changes */
3908 Term_xtra_win_react();
3910 /* Hack -- Force redraw */
3911 Term_key_push(KTRL('R'));
3917 case IDM_OPTIONS_BG:
3922 plog("You may not do that right now.");
3926 /* Toggle "use_bg" */
3931 /* React to changes */
3932 Term_xtra_win_react();
3934 /* Hack -- Force redraw */
3935 Term_key_push(KTRL('R'));
3941 case IDM_OPTIONS_OPEN_BG:
3946 plog("You may not do that right now.");
3951 memset(&ofn, 0, sizeof(ofn));
3952 ofn.lStructSize = sizeof(ofn);
3953 ofn.hwndOwner = data[0].w;
3954 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3955 ofn.nFilterIndex = 1;
3956 ofn.lpstrFile = bg_bitmap_file;
3957 ofn.nMaxFile = 1023;
3958 ofn.lpstrInitialDir = NULL;
3960 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
3962 ofn.lpstrTitle = "Choose wall paper.";
3964 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3966 if (GetOpenFileName(&ofn))
3968 /* Load 'savefile' */
3973 /* React to changes */
3974 Term_xtra_win_react();
3976 /* Hack -- Force redraw */
3977 Term_key_push(KTRL('R'));
3982 case IDM_DUMP_SCREEN_HTML:
3984 static char buf[1024] = "";
3985 memset(&ofn, 0, sizeof(ofn));
3986 ofn.lStructSize = sizeof(ofn);
3987 ofn.hwndOwner = data[0].w;
3988 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
3989 ofn.nFilterIndex = 1;
3990 ofn.lpstrFile = buf;
3991 ofn.nMaxFile = 1023;
3992 ofn.lpstrDefExt = "html";
3993 ofn.lpstrInitialDir = NULL;
3995 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
3997 ofn.lpstrTitle = "Save screen dump as HTML.";
3999 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4001 if (GetSaveFileName(&ofn))
4003 do_cmd_save_screen_html_aux(buf, 0);
4010 case IDM_OPTIONS_SAVER:
4014 DestroyWindow(hwndSaver);
4019 /* Create a screen scaver window */
4020 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4021 "Angband Screensaver",
4022 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4023 0, 0, GetSystemMetrics(SM_CXSCREEN),
4024 GetSystemMetrics(SM_CYSCREEN),
4025 NULL, NULL, hInstance, NULL);
4029 /* Push the window to the bottom XXX XXX XXX */
4030 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4035 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
4037 plog("Failed to create saver window");
4047 case IDM_OPTIONS_MAP:
4053 case IDM_HELP_CONTENTS:
4057 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4058 if (check_file(tmp))
4060 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4065 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4066 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4068 plog_fmt("Cannot find help file: %s", tmp);
4069 plog("Use the online help files instead.");
4074 #else /* HTML_HELP */
4077 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4078 if (check_file(tmp))
4080 sprintf(buf, "winhelp.exe %s", tmp);
4081 WinExec(buf, SW_NORMAL);
4086 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4087 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4089 plog_fmt("Cannot find help file: %s", tmp);
4090 plog("Use the online help files instead.");
4095 #endif /* HTML_HELP */
4103 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4104 WPARAM wParam, LPARAM lParam);
4105 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4106 WPARAM wParam, LPARAM lParam)
4107 #else /* __MWERKS__ */
4108 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4109 WPARAM wParam, LPARAM lParam)
4110 #endif /* __MWERKS__ */
4116 MINMAXINFO FAR *lpmmi;
4122 /* Acquire proper "term_data" info */
4123 td = (term_data *)GetWindowLong(hWnd, 0);
4125 /* Handle message */
4131 SetWindowLong(hWnd, 0, (LONG)(my_td));
4141 case WM_GETMINMAXINFO:
4143 MINMAXINFO FAR *lpmmi;
4146 lpmmi = (MINMAXINFO FAR *)lParam;
4148 /* this message was sent before WM_NCCREATE */
4151 /* Minimum window size is 80x24 */
4152 rc.left = rc.top = 0;
4153 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4154 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4157 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4159 /* Save minimum size */
4160 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4161 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4168 BeginPaint(hWnd, &ps);
4169 if (td) term_data_redraw(td);
4170 EndPaint(hWnd, &ps);
4171 ValidateRect(hWnd, NULL);
4182 /* Extract the modifiers */
4183 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4184 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4185 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4187 /* Handle "special" keys */
4188 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4190 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4191 bool numpad = FALSE;
4193 /* Begin the macro trigger */
4196 /* Send the modifiers */
4197 if (mc) Term_keypress('C');
4198 if (ms) Term_keypress('S');
4199 if (ma) Term_keypress('A');
4201 /* Extract "scan code" */
4202 i = LOBYTE(HIWORD(lParam));
4204 /* Introduce the scan code */
4207 /* Extended key bit */
4212 /* Numpad Enter and '/' are extended key */
4215 /* Other extended keys are on full keyboard */
4219 /* Special modifiers for keypad keys */
4220 if (numpad) Term_keypress('K');
4222 /* Encode the hexidecimal scan code */
4223 Term_keypress(hexsym[i/16]);
4224 Term_keypress(hexsym[i%16]);
4226 /* End the macro trigger */
4237 Term_keypress(wParam);
4249 if (game_in_progress && character_generated)
4254 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4256 plog("You may not do that right now.");
4261 /* Hack -- Forget messages */
4270 /* do_cmd_save_game(FALSE); */
4271 #else /* ZANGBAND */
4272 /* do_cmd_save_game(); */
4273 #endif /* ZANGBAND */
4289 process_menus(LOWORD(wParam));
4295 /* this message was sent before WM_NCCREATE */
4298 /* it was sent from inside CreateWindowEx */
4299 if (!td->w) return 1;
4301 /* was sent from WM_SIZE */
4302 if (td->size_hack) return 1;
4306 case SIZE_MINIMIZED:
4308 /* Hide sub-windows */
4309 for (i = 1; i < MAX_TERM_DATA; i++)
4311 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4316 case SIZE_MAXIMIZED:
4318 /* fall through XXX XXX XXX */
4323 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4324 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4327 if ((td->cols != cols) || (td->rows != rows))
4329 /* Save the new size */
4334 Term_activate(&td->t);
4336 /* Resize the term */
4337 Term_resize(td->cols, td->rows);
4340 InvalidateRect(td->w, NULL, TRUE);
4343 td->size_hack = TRUE;
4345 /* Show sub-windows */
4346 for (i = 1; i < MAX_TERM_DATA; i++)
4348 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4351 td->size_hack = FALSE;
4359 case WM_PALETTECHANGED:
4361 /* Ignore if palette change caused by itself */
4362 if ((HWND)wParam == hWnd) return 0;
4364 /* Fall through... */
4367 case WM_QUERYNEWPALETTE:
4369 if (!paletted) return 0;
4373 SelectPalette(hdc, hPal, FALSE);
4375 i = RealizePalette(hdc);
4377 /* if any palette entries changed, repaint the window. */
4378 if (i) InvalidateRect(hWnd, NULL, TRUE);
4380 ReleaseDC(hWnd, hdc);
4387 if (wParam && !HIWORD(lParam))
4389 /* Do something to sub-windows */
4390 for (i = 1; i < MAX_TERM_DATA; i++)
4392 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4395 /* Focus on main window */
4404 case WM_ACTIVATEAPP:
4406 for (i = 1; i < MAX_TERM_DATA; i++)
4412 ShowWindow(data[i].w, SW_SHOW);
4416 ShowWindow(data[i].w, SW_HIDE);
4423 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4428 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4429 WPARAM wParam, LPARAM lParam);
4430 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4431 WPARAM wParam, LPARAM lParam)
4432 #else /* __MWERKS__ */
4433 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4434 WPARAM wParam, LPARAM lParam)
4435 #endif /* __MWERKS__ */
4439 MINMAXINFO FAR *lpmmi;
4447 /* Acquire proper "term_data" info */
4448 td = (term_data *)GetWindowLong(hWnd, 0);
4450 /* Process message */
4456 SetWindowLong(hWnd, 0, (LONG)(my_td));
4466 case WM_GETMINMAXINFO:
4468 MINMAXINFO FAR *lpmmi;
4471 lpmmi = (MINMAXINFO FAR *)lParam;
4473 /* this message was sent before WM_NCCREATE */
4476 /* Minimum window size is 80x24 */
4477 rc.left = rc.top = 0;
4478 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4479 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4482 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4484 /* Save minimum size */
4485 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4486 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4496 /* this message was sent before WM_NCCREATE */
4499 /* it was sent from inside CreateWindowEx */
4500 if (!td->w) return 1;
4502 /* was sent from inside WM_SIZE */
4503 if (td->size_hack) return 1;
4505 td->size_hack = TRUE;
4507 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4508 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4511 if ((td->cols != cols) || (td->rows != rows))
4514 term *old_term = Term;
4516 /* Save the new size */
4521 Term_activate(&td->t);
4523 /* Resize the term */
4524 Term_resize(td->cols, td->rows);
4527 Term_activate(old_term);
4530 InvalidateRect(td->w, NULL, TRUE);
4532 /* HACK - Redraw all windows */
4533 p_ptr->window = 0xFFFFFFFF;
4537 td->size_hack = FALSE;
4544 BeginPaint(hWnd, &ps);
4545 if (td) term_data_redraw(td);
4546 EndPaint(hWnd, &ps);
4557 /* Extract the modifiers */
4558 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4559 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4560 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4562 /* Handle "special" keys */
4563 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4565 /* Begin the macro trigger */
4568 /* Send the modifiers */
4569 if (mc) Term_keypress('C');
4570 if (ms) Term_keypress('S');
4571 if (ma) Term_keypress('A');
4573 /* Extract "scan code" */
4574 i = LOBYTE(HIWORD(lParam));
4576 /* Introduce the scan code */
4579 /* Encode the hexidecimal scan code */
4580 Term_keypress(hexsym[i/16]);
4581 Term_keypress(hexsym[i%16]);
4583 /* End the macro trigger */
4594 Term_keypress(wParam);
4598 case WM_PALETTECHANGED:
4600 /* ignore if palette change caused by itself */
4601 if ((HWND)wParam == hWnd) return FALSE;
4602 /* otherwise, fall through!!! */
4605 case WM_QUERYNEWPALETTE:
4607 if (!paletted) return 0;
4609 SelectPalette(hdc, hPal, FALSE);
4610 i = RealizePalette(hdc);
4611 /* if any palette entries changed, repaint the window. */
4612 if (i) InvalidateRect(hWnd, NULL, TRUE);
4613 ReleaseDC(hWnd, hdc);
4617 case WM_NCLBUTTONDOWN:
4621 if (wParam == HTCLOSE) wParam = HTSYSMENU;
4622 #endif /* HTCLOSE */
4624 if (wParam == HTSYSMENU)
4628 td->visible = FALSE;
4629 ShowWindow(td->w, SW_HIDE);
4639 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4645 #define MOUSE_SENS 40
4648 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4649 WPARAM wParam, LPARAM lParam);
4650 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4651 WPARAM wParam, LPARAM lParam)
4652 #else /* __MWERKS__ */
4653 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4654 WPARAM wParam, LPARAM lParam)
4655 #endif /* __MWERKS__ */
4657 static int iMouse = 0;
4658 static WORD xMouse = 0;
4659 static WORD yMouse = 0;
4682 if (LOWORD(wParam) == WA_INACTIVE) break;
4684 /* else fall through */
4688 case WM_LBUTTONDOWN:
4689 case WM_MBUTTONDOWN:
4690 case WM_RBUTTONDOWN:
4693 SendMessage(hWnd, WM_CLOSE, 0, 0);
4701 dx = LOWORD(lParam) - xMouse;
4702 dy = HIWORD(lParam) - yMouse;
4704 if (dx < 0) dx = -dx;
4705 if (dy < 0) dy = -dy;
4707 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
4709 SendMessage(hWnd, WM_CLOSE, 0, 0);
4713 /* Save last location */
4715 xMouse = LOWORD(lParam);
4716 yMouse = HIWORD(lParam);
4723 DestroyWindow(hwndSaver);
4730 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4733 #endif /* USE_SAVER */
4739 /*** Temporary Hooks ***/
4743 * Display warning message (see "z-util.c")
4745 static void hack_plog(cptr str)
4747 /* Give a warning */
4751 MessageBox(NULL, str, "·Ù¹ð¡ª",
4752 MB_ICONEXCLAMATION | MB_OK);
4754 MessageBox(NULL, str, "Warning",
4755 MB_ICONEXCLAMATION | MB_OK);
4763 * Display error message and quit (see "z-util.c")
4765 static void hack_quit(cptr str)
4767 /* Give a warning */
4771 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
4772 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4774 MessageBox(NULL, str, "Error",
4775 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4780 /* Unregister the classes */
4781 UnregisterClass(AppName, hInstance);
4783 /* Destroy the icon */
4784 if (hIcon) DestroyIcon(hIcon);
4792 /*** Various hooks ***/
4796 * Display warning message (see "z-util.c")
4798 static void hook_plog(cptr str)
4804 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
4805 MB_ICONEXCLAMATION | MB_OK);
4807 MessageBox(data[0].w, str, "Warning",
4808 MB_ICONEXCLAMATION | MB_OK);
4816 * Display error message and quit (see "z-util.c")
4818 static void hook_quit(cptr str)
4823 /* Give a warning */
4827 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
4828 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4830 MessageBox(data[0].w, str, "Error",
4831 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4837 /* Save the preferences */
4841 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
4843 /* Destroy all windows */
4844 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
4846 term_force_font(&data[i], NULL);
4847 if (data[i].font_want) string_free(data[i].font_want);
4848 if (data[i].w) DestroyWindow(data[i].w);
4852 /* Free the bitmap stuff */
4854 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
4855 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
4857 #ifdef USE_TRANSPARENCY
4858 if (infMask.hPalette) DeleteObject(infMask.hPalette);
4859 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
4860 #endif /* USE_TRANSPARENCY */
4862 #endif /* USE_GRAPHICS */
4864 /*** Free some other stuff ***/
4866 DeleteObject(hbrYellow);
4871 if (hPal) DeleteObject(hPal);
4873 UnregisterClass(AppName, hInstance);
4875 if (hIcon) DestroyIcon(hIcon);
4882 /*** Initialize ***/
4888 static void init_stuff(void)
4895 /* Get program name with full path */
4896 GetModuleFileName(hInstance, path, 512);
4898 /* Save the "program name" XXX XXX XXX */
4901 /* Get the name of the "*.ini" file */
4902 strcpy(path + strlen(path) - 4, ".INI");
4904 /* Save the the name of the ini-file */
4905 ini_file = string_make(path);
4907 /* Analyze the path */
4913 if (path[i] == '\\')
4920 /* Add "lib" to the path */
4921 strcpy(path + i + 1, "lib\\");
4923 /* Validate the path */
4924 validate_dir(path, TRUE);
4926 /* Init the file paths */
4927 init_file_paths(path);
4929 /* Hack -- Validate the paths */
4930 validate_dir(ANGBAND_DIR_APEX, FALSE);
4931 validate_dir(ANGBAND_DIR_BONE, FALSE);
4933 /* Allow missing 'edit' directory */
4934 if (!check_dir(ANGBAND_DIR_EDIT))
4936 /* Must have 'data'! */
4937 validate_dir(ANGBAND_DIR_DATA, TRUE);
4941 /* Don't need 'data' */
4942 validate_dir(ANGBAND_DIR_DATA, FALSE);
4945 validate_dir(ANGBAND_DIR_FILE, TRUE);
4946 validate_dir(ANGBAND_DIR_HELP, FALSE);
4947 validate_dir(ANGBAND_DIR_INFO, FALSE);
4948 validate_dir(ANGBAND_DIR_PREF, TRUE);
4949 validate_dir(ANGBAND_DIR_SAVE, FALSE);
4950 validate_dir(ANGBAND_DIR_USER, TRUE);
4951 validate_dir(ANGBAND_DIR_XTRA, TRUE);
4953 /* Build the filename */
4955 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
4957 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
4961 /* Hack -- Validate the "news.txt" file */
4962 validate_file(path);
4966 /* Build the "font" path */
4967 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
4969 /* Allocate the path */
4970 ANGBAND_DIR_XTRA_FONT = string_make(path);
4972 /* Validate the "font" directory */
4973 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
4975 /* Build the filename */
4976 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
4978 /* Hack -- Validate the basic font */
4979 validate_file(path);
4985 /* Build the "graf" path */
4986 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
4988 /* Allocate the path */
4989 ANGBAND_DIR_XTRA_GRAF = string_make(path);
4991 /* Validate the "graf" directory */
4992 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
4994 #endif /* USE_GRAPHICS */
4999 /* Build the "sound" path */
5000 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5002 /* Allocate the path */
5003 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5005 /* Validate the "sound" directory */
5006 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5008 #endif /* USE_SOUND */
5012 /* Build the "music" path */
5013 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5015 /* Allocate the path */
5016 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5018 /* Validate the "music" directory */
5019 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5021 #endif /* USE_MUSIC */
5023 /* Build the "help" path */
5024 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5026 /* Allocate the path */
5027 ANGBAND_DIR_XTRA_HELP = string_make(path);
5029 /* Validate the "help" directory */
5030 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5034 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5035 LPSTR lpCmdLine, int nCmdShow)
5047 if (hPrevInst == NULL)
5049 wc.style = CS_CLASSDC;
5050 wc.lpfnWndProc = AngbandWndProc;
5052 wc.cbWndExtra = 4; /* one long pointer to term_data */
5053 wc.hInstance = hInst;
5054 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5055 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5056 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5057 wc.lpszMenuName = AppName;
5058 wc.lpszClassName = AppName;
5060 if (!RegisterClass(&wc)) exit(1);
5062 wc.lpfnWndProc = AngbandListProc;
5063 wc.lpszMenuName = NULL;
5064 wc.lpszClassName = AngList;
5066 if (!RegisterClass(&wc)) exit(2);
5070 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5071 wc.lpfnWndProc = AngbandSaverProc;
5073 wc.lpszMenuName = NULL;
5074 wc.lpszClassName = "WindowsScreenSaverClass";
5076 if (!RegisterClass(&wc)) exit(3);
5082 /* Temporary hooks */
5083 plog_aux = hack_plog;
5084 quit_aux = hack_quit;
5085 core_aux = hack_quit;
5087 /* Prepare the filepaths */
5090 /* Initialize the keypress analyzer */
5091 for (i = 0; special_key_list[i]; ++i)
5093 special_key[special_key_list[i]] = TRUE;
5095 /* Initialize the keypress analyzer */
5096 for (i = 0; ignore_key_list[i]; ++i)
5098 ignore_key[ignore_key_list[i]] = TRUE;
5101 /* Determine if display is 16/256/true color */
5103 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5104 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5105 ReleaseDC(NULL, hdc);
5107 /* Initialize the colors */
5108 for (i = 0; i < 256; i++)
5112 /* Extract desired values */
5113 rv = angband_color_table[i][1];
5114 gv = angband_color_table[i][2];
5115 bv = angband_color_table[i][3];
5117 /* Extract the "complex" code */
5118 win_clr[i] = PALETTERGB(rv, gv, bv);
5120 /* Save the "simple" code */
5121 angband_color_table[i][0] = win_pal[i];
5124 /* Prepare the windows */
5130 /* Activate hooks */
5131 plog_aux = hook_plog;
5132 quit_aux = hook_quit;
5133 core_aux = hook_quit;
5135 /* Set the system suffix */
5136 ANGBAND_SYS = "win";
5138 /* Set the keyboard suffix */
5139 if (7 != GetKeyboardType(0))
5140 ANGBAND_KEYBOARD = "0";
5143 /* Japanese keyboard */
5144 switch (GetKeyboardType(1))
5146 case 0x0D01: case 0x0D02:
5147 case 0x0D03: case 0x0D04:
5148 case 0x0D05: case 0x0D06:
5150 ANGBAND_KEYBOARD = "NEC98";
5154 ANGBAND_KEYBOARD = "JAPAN";
5162 /* We are now initialized */
5166 if(lpCmdLine[0] == '-'){
5167 switch(lpCmdLine[1])
5172 if (!lpCmdLine[2]) break;
5173 chuukei_server = TRUE;
5174 if(connect_chuukei_server(&lpCmdLine[2])<0){
5175 msg_print("connect fail");
5178 msg_print("connect");
5186 if (!lpCmdLine[2]) break;
5187 chuukei_client = TRUE;
5188 connect_chuukei_server(&lpCmdLine[2]);
5198 /* Did the user double click on a save file? */
5199 if(!chuukei_server) check_for_save_file(lpCmdLine);
5201 /* Did the user double click on a save file? */
5202 check_for_save_file(lpCmdLine);
5205 /* Prompt the user */
5207 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5209 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5214 /* Process messages forever */
5215 while (GetMessage(&msg, NULL, 0, 0))
5217 TranslateMessage(&msg);
5218 DispatchMessage(&msg);
5229 #endif /* WINDOWS */