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;
523 * An array of sound file names
525 static cptr sound_file[SOUND_MAX];
527 #endif /* USE_SOUND */
531 * Full path to ANGBAND.INI
533 static cptr ini_file = NULL;
536 * Name of application
538 static cptr AppName = "ANGBAND";
541 * Name of sub-window type
543 static cptr AngList = "AngList";
548 static cptr ANGBAND_DIR_XTRA_GRAF;
549 static cptr ANGBAND_DIR_XTRA_SOUND;
550 static cptr ANGBAND_DIR_XTRA_HELP;
552 static cptr ANGBAND_DIR_XTRA_FONT;
555 static cptr ANGBAND_DIR_XTRA_MUSIC;
560 * The "complex" color values
562 static COLORREF win_clr[256];
566 * The "simple" color values
568 * See "main-ibm.c" for original table information
570 * The entries below are taken from the "color bits" defined above.
572 * Note that many of the choices below suck, but so do crappy monitors.
574 static BYTE win_pal[256] =
576 VID_BLACK, /* Dark */
577 VID_WHITE, /* White */
578 VID_CYAN, /* Slate XXX */
579 VID_RED | VID_BRIGHT, /* Orange XXX */
581 VID_GREEN, /* Green */
583 VID_YELLOW, /* Umber XXX */
584 VID_BLACK | VID_BRIGHT, /* Light Dark */
585 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
586 VID_MAGENTA, /* Violet XXX */
587 VID_YELLOW | VID_BRIGHT, /* Yellow */
588 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
589 VID_GREEN | VID_BRIGHT, /* Light Green */
590 VID_BLUE | VID_BRIGHT, /* Light Blue */
591 VID_YELLOW /* Light Umber XXX */
596 * Hack -- define which keys are "special"
598 static bool special_key[256];
599 static bool ignore_key[256];
603 * Hack -- initialization list for "special_key"
605 static byte special_key_list[] = {
606 VK_CLEAR,VK_PAUSE,VK_CAPITAL,VK_KANA,VK_JUNJA,VK_FINAL,VK_KANJI,
607 VK_CONVERT,VK_NONCONVERT,VK_ACCEPT,VK_MODECHANGE,
608 VK_PRIOR,VK_NEXT,VK_END,VK_HOME,VK_LEFT,VK_UP,VK_RIGHT,VK_DOWN,
609 VK_SELECT,VK_PRINT,VK_EXECUTE,VK_SNAPSHOT,VK_INSERT,VK_DELETE,
611 VK_F1,VK_F2,VK_F3,VK_F4,VK_F5,VK_F6,VK_F7,VK_F8,VK_F9,VK_F10,
612 VK_F11,VK_F12,VK_F13,VK_F14,VK_F15,VK_F16,VK_F17,VK_F18,VK_F19,VK_F20,
613 VK_F21,VK_F22,VK_F23,VK_F24,VK_NUMLOCK,VK_SCROLL,
614 VK_ATTN,VK_CRSEL,VK_EXSEL,VK_EREOF,VK_PLAY,VK_ZOOM,VK_NONAME,
618 static byte ignore_key_list[] = {
619 VK_ESCAPE,VK_TAB,VK_SPACE,
620 'F','W','O','H', /* these are menu characters.*/
621 VK_SHIFT,VK_CONTROL,VK_MENU,VK_LWIN,VK_RWIN,
622 VK_LSHIFT,VK_RSHIFT,VK_LCONTROL,VK_RCONTROL,VK_LMENU,VK_RMENU,0
627 * Hack -- initialization list for "special_key"
629 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
630 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
631 * catch the keypad keys (with and without numlock set, including keypad 5),
632 * the function keys (including the "menu" key which maps to F10), and the
633 * "pause" key (between scroll lock and numlock). We also catch a few odd
634 * keys which I do not recognize, but which are listed among keys which we
635 * do catch, so they should be harmless to catch.
637 static byte special_key_list[] =
639 VK_CLEAR, /* 0x0C (KP<5>) */
641 VK_PAUSE, /* 0x13 (pause) */
643 VK_PRIOR, /* 0x21 (KP<9>) */
644 VK_NEXT, /* 0x22 (KP<3>) */
645 VK_END, /* 0x23 (KP<1>) */
646 VK_HOME, /* 0x24 (KP<7>) */
647 VK_LEFT, /* 0x25 (KP<4>) */
648 VK_UP, /* 0x26 (KP<8>) */
649 VK_RIGHT, /* 0x27 (KP<6>) */
650 VK_DOWN, /* 0x28 (KP<2>) */
651 VK_SELECT, /* 0x29 (?????) */
652 VK_PRINT, /* 0x2A (?????) */
653 VK_EXECUTE, /* 0x2B (?????) */
654 VK_SNAPSHOT, /* 0x2C (?????) */
655 VK_INSERT, /* 0x2D (KP<0>) */
656 VK_DELETE, /* 0x2E (KP<.>) */
657 VK_HELP, /* 0x2F (?????) */
660 VK_NUMPAD0, /* 0x60 (KP<0>) */
661 VK_NUMPAD1, /* 0x61 (KP<1>) */
662 VK_NUMPAD2, /* 0x62 (KP<2>) */
663 VK_NUMPAD3, /* 0x63 (KP<3>) */
664 VK_NUMPAD4, /* 0x64 (KP<4>) */
665 VK_NUMPAD5, /* 0x65 (KP<5>) */
666 VK_NUMPAD6, /* 0x66 (KP<6>) */
667 VK_NUMPAD7, /* 0x67 (KP<7>) */
668 VK_NUMPAD8, /* 0x68 (KP<8>) */
669 VK_NUMPAD9, /* 0x69 (KP<9>) */
670 VK_MULTIPLY, /* 0x6A (KP<*>) */
671 VK_ADD, /* 0x6B (KP<+>) */
672 VK_SEPARATOR, /* 0x6C (?????) */
673 VK_SUBTRACT, /* 0x6D (KP<->) */
674 VK_DECIMAL, /* 0x6E (KP<.>) */
675 VK_DIVIDE, /* 0x6F (KP</>) */
708 static void delete_bg(void)
717 static int init_bg(void)
719 char * bmfile = bg_bitmap_file;
722 if (use_bg == 0) return 0;
724 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
726 plog_fmt("ÊÉ»æÍÑ¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
731 HDC wnddc, dcimage, dcbg;
732 HBITMAP bmimage, bmimage_old, bmbg_old;
738 dcimage = CreateCompatibleDC(wnddc);
739 dcbg = CreateCompatibleDC(wnddc);
741 bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
742 if (!bmimage) quit("bg.bmp¤¬Æɤߤ³¤á¤Ê¤¤¡ª");
743 bmimage_old = SelectObject(dcimage, bmimage);
745 CreateCompatibleBitmap();
747 ReleaseDC(hwnd, wnddc);
753 static void DrawBG(HDC hdc, RECT *r)
758 int x = r->left, y = r->top;
759 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
765 GetObject(hBG, sizeof(bm), &bm);
766 swid = bm.bmWidth; shgt = bm.bmHeight;
768 hdcSrc = CreateCompatibleDC(hdc);
769 hOld = SelectObject(hdcSrc, hBG);
773 cwid = MIN(swid - sx, r->right - nx);
776 chgt = MIN(shgt - sy, r->bottom - ny);
777 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
779 } while (ny < r->bottom);
782 } while (nx < r->right);
784 SelectObject(hdcSrc, hOld);
790 * Hack -- given a pathname, point at the filename
792 static cptr extract_file_name(cptr s)
796 /* Start at the end */
797 p = s + strlen(s) - 1;
799 /* Back up to divider */
800 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
802 /* Return file name */
809 * Hack -- given a simple filename, extract the "font size" info
811 * Return a pointer to a static buffer holding the capitalized base name.
814 static char *analyze_font(char *path, int *wp, int *hp)
820 /* Start at the end */
821 p = path + strlen(path) - 1;
823 /* Back up to divider */
824 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
826 /* Advance to file name */
832 /* Capitalize (be paranoid) */
833 if (islower(*s)) *s = toupper(*s);
839 /* Extract font width */
843 hgt = s ? atoi(s+1) : 0;
856 * Check for existance of a file
858 static bool check_file(cptr s)
878 attrib = GetFileAttributes(path);
880 /* Require valid filename */
881 if (attrib == INVALID_FILE_NAME) return (FALSE);
883 /* Prohibit directory */
884 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
888 /* Examine and verify */
889 if (_dos_getfileattr(path, &attrib)) return (FALSE);
891 /* Prohibit something */
892 if (attrib & FA_LABEL) return (FALSE);
894 /* Prohibit directory */
895 if (attrib & FA_DIREC) return (FALSE);
905 * Check for existance of a directory
907 static bool check_dir(cptr s)
929 /* Remove trailing backslash */
930 if (i && (path[i-1] == '\\')) path[--i] = '\0';
935 attrib = GetFileAttributes(path);
937 /* Require valid filename */
938 if (attrib == INVALID_FILE_NAME) return (FALSE);
940 /* Require directory */
941 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
945 /* Examine and verify */
946 if (_dos_getfileattr(path, &attrib)) return (FALSE);
948 /* Prohibit something */
949 if (attrib & FA_LABEL) return (FALSE);
951 /* Require directory */
952 if (!(attrib & FA_DIREC)) return (FALSE);
964 static void validate_file(cptr s)
970 quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
972 quit_fmt("Cannot find required file:\n%s", s);
980 * Validate a directory
982 static void validate_dir(cptr s, bool vital)
987 /* This directory contains needed data */
991 quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
993 quit_fmt("Cannot find required directory:\n%s", s);
997 /* Attempt to create this directory */
1000 quit_fmt("Unable to create directory:\n%s", s);
1007 * Get the "size" for a window
1009 static void term_getsize(term_data *td)
1016 if (td->cols < 1) td->cols = 1;
1017 if (td->rows < 1) td->rows = 1;
1020 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1021 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1023 /* Fake window size */
1025 rc.right = rc.left + wid;
1027 rc.bottom = rc.top + hgt;
1030 /* rc.right += 1; */
1031 /* rc.bottom += 1; */
1034 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1037 td->size_wid = rc.right - rc.left;
1038 td->size_hgt = rc.bottom - rc.top;
1040 /* See CreateWindowEx */
1043 /* Extract actual location */
1044 GetWindowRect(td->w, &rc);
1046 /* Save the location */
1047 td->pos_x = rc.left;
1053 * Write the "prefs" for a single term
1055 static void save_prefs_aux(term_data *td, cptr sec_name)
1065 strcpy(buf, td->visible ? "1" : "0");
1066 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1070 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1072 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1075 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1078 wsprintf(buf, "%d", td->lf.lfWidth);
1079 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1080 wsprintf(buf, "%d", td->lf.lfHeight);
1081 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1082 wsprintf(buf, "%d", td->lf.lfWeight);
1083 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1086 strcpy(buf, td->bizarre ? "1" : "0");
1087 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1090 wsprintf(buf, "%d", td->tile_wid);
1091 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1094 wsprintf(buf, "%d", td->tile_hgt);
1095 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1097 /* Window size (x) */
1098 wsprintf(buf, "%d", td->cols);
1099 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1101 /* Window size (y) */
1102 wsprintf(buf, "%d", td->rows);
1103 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1105 /* Acquire position */
1106 GetWindowRect(td->w, &rc);
1108 /* Window position (x) */
1109 wsprintf(buf, "%d", rc.left);
1110 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1112 /* Window position (y) */
1113 wsprintf(buf, "%d", rc.top);
1114 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1116 /* Window Z position */
1117 strcpy(buf, td->posfix ? "1" : "0");
1118 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1125 * We assume that the windows have all been initialized
1127 static void save_prefs(void)
1133 /* Save the "arg_graphics" flag */
1134 sprintf(buf, "%d", arg_graphics);
1135 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1137 /* Save the "arg_bigtile" flag */
1138 strcpy(buf, arg_bigtile ? "1" : "0");
1139 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1141 /* Save the "arg_sound" flag */
1142 strcpy(buf, arg_sound ? "1" : "0");
1143 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1146 strcpy(buf, use_bg ? "1" : "0");
1147 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1148 WritePrivateProfileString("Angband", "BackGroundBitmap",
1149 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1151 /* Save window prefs */
1152 for (i = 0; i < MAX_TERM_DATA; ++i)
1154 term_data *td = &data[i];
1156 sprintf(buf, "Term-%d", i);
1158 save_prefs_aux(td, buf);
1164 * Load the "prefs" for a single term
1166 static void load_prefs_aux(term_data *td, cptr sec_name)
1173 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1175 /* Desired font, with default */
1177 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1179 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1184 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1186 /* Analyze font, save desired font name */
1188 td->font_want = string_make(tmp);
1190 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1191 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1192 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1194 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1200 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1201 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1203 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1204 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1209 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1210 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1212 /* Window position */
1213 td->pos_x = GetPrivateProfileInt(sec_name, "PositionX", td->pos_x, ini_file);
1214 td->pos_y = GetPrivateProfileInt(sec_name, "PositionY", td->pos_y, ini_file);
1216 /* Window Z position */
1217 td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1224 static void load_prefs(void)
1230 /* Extract the "arg_graphics" flag */
1231 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1233 /* Extract the "arg_bigtile" flag */
1234 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1235 use_bigtile = arg_bigtile;
1237 /* Extract the "arg_sound" flag */
1238 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1241 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1242 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1244 /* Load window prefs */
1245 for (i = 0; i < MAX_TERM_DATA; ++i)
1247 term_data *td = &data[i];
1249 sprintf(buf, "Term-%d", i);
1251 load_prefs_aux(td, buf);
1257 * Create the new global palette based on the bitmap palette
1258 * (if any), and the standard 16 entry palette derived from
1259 * "win_clr[]" which is used for the basic 16 Angband colors.
1261 * This function is never called before all windows are ready.
1263 * This function returns FALSE if the new palette could not be
1264 * prepared, which should normally be a fatal error. XXX XXX
1266 * Note that only some machines actually use a "palette".
1268 static int new_palette(void)
1276 LPLOGPALETTE pLogPal;
1277 LPPALETTEENTRY lppe;
1282 /* This makes no sense */
1283 if (!paletted) return (TRUE);
1293 /* Check the bitmap palette */
1294 hBmPal = infGraph.hPalette;
1296 /* Use the bitmap */
1299 lppeSize = 256 * sizeof(PALETTEENTRY);
1300 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1301 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1302 if ((nEntries == 0) || (nEntries > 220))
1306 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1308 plog("Please switch to high- or true-color mode.");
1313 rnfree(lppe, lppeSize);
1320 #endif /* USE_GRAPHICS */
1322 /* Size of palette */
1323 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1325 /* Allocate palette */
1326 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1329 pLogPal->palVersion = 0x300;
1331 /* Make room for bitmap and normal data */
1332 pLogPal->palNumEntries = nEntries + 16;
1334 /* Save the bitmap data */
1335 for (i = 0; i < nEntries; i++)
1337 pLogPal->palPalEntry[i] = lppe[i];
1340 /* Save the normal data */
1341 for (i = 0; i < 16; i++)
1345 /* Access the entry */
1346 p = &(pLogPal->palPalEntry[i+nEntries]);
1348 /* Save the colors */
1349 p->peRed = GetRValue(win_clr[i]);
1350 p->peGreen = GetGValue(win_clr[i]);
1351 p->peBlue = GetBValue(win_clr[i]);
1353 /* Save the flags */
1354 p->peFlags = PC_NOCOLLAPSE;
1357 /* Free something */
1358 if (lppe) rnfree(lppe, lppeSize);
1360 /* Create a new palette, or fail */
1361 hNewPal = CreatePalette(pLogPal);
1363 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1365 if (!hNewPal) quit("Cannot create palette!");
1369 /* Free the palette */
1370 rnfree(pLogPal, pLogPalSize);
1375 /* Realize the palette */
1377 SelectPalette(hdc, hNewPal, 0);
1378 i = RealizePalette(hdc);
1379 ReleaseDC(td->w, hdc);
1381 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1383 if (i == 0) quit("Cannot realize palette!");
1388 for (i = 1; i < MAX_TERM_DATA; i++)
1393 SelectPalette(hdc, hNewPal, 0);
1394 ReleaseDC(td->w, hdc);
1397 /* Delete old palette */
1398 if (hPal) DeleteObject(hPal);
1400 /* Save new palette */
1410 * Initialize graphics
1412 static bool init_graphics(void)
1414 /* Initialize once */
1415 /* if (can_use_graphics != arg_graphics) */
1421 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1428 ANGBAND_GRAF = "new";
1436 ANGBAND_GRAF = "old";
1439 /* Access the bitmap file */
1440 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1442 /* Load the bitmap or quit */
1443 if (!ReadDIB(data[0].w, buf, &infGraph))
1446 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1448 plog_fmt("Cannot read bitmap file '%s'", name);
1454 /* Save the new sizes */
1455 infGraph.CellWidth = wid;
1456 infGraph.CellHeight = hgt;
1458 #ifdef USE_TRANSPARENCY
1460 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1462 /* Access the mask file */
1463 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1465 /* Load the bitmap or quit */
1466 if (!ReadDIB(data[0].w, buf, &infMask))
1468 plog_fmt("Cannot read bitmap file '%s'", buf);
1473 #endif /* USE_TRANSPARENCY */
1475 /* Activate a palette */
1478 /* Free bitmap XXX XXX XXX */
1482 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1484 plog("Cannot activate palette!");
1490 /* Graphics available */
1491 can_use_graphics = arg_graphics;
1495 return (can_use_graphics);
1497 #endif /* USE_GRAPHICS */
1504 static bool init_sound(void)
1506 /* Initialize once */
1514 /* Prepare the sounds */
1515 for (i = 1; i < SOUND_MAX; i++)
1517 /* Extract name of sound file */
1518 sprintf(wav, "%s.wav", angband_sound_name[i]);
1520 /* Access the sound */
1521 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_SOUND, wav);
1523 /* Save the sound filename, if it exists */
1524 if (check_file(buf)) sound_file[i] = string_make(buf);
1527 /* Sound available */
1528 can_use_sound = TRUE;
1532 return (can_use_sound);
1534 #endif /* USE_SOUND */
1540 static void term_window_resize(term_data *td)
1542 /* Require window */
1545 /* Resize the window */
1546 SetWindowPos(td->w, 0, 0, 0,
1547 td->size_wid, td->size_hgt,
1548 SWP_NOMOVE | SWP_NOZORDER);
1551 InvalidateRect(td->w, NULL, TRUE);
1556 * Force the use of a new "font file" for a term_data
1558 * This function may be called before the "window" is ready
1560 * This function returns zero only if everything succeeds.
1562 * Note that the "font name" must be capitalized!!!
1564 static errr term_force_font(term_data *td, cptr path)
1574 /* Forget the old font (if needed) */
1575 if (td->font_id) DeleteObject(td->font_id);
1578 /* Forget old font */
1584 for (i = 0; i < MAX_TERM_DATA; i++)
1586 /* Don't check when closing the application */
1589 /* Check "screen" */
1590 if ((td != &data[i]) &&
1591 (data[i].font_file) &&
1592 (streq(data[i].font_file, td->font_file)))
1598 /* Remove unused font resources */
1599 if (!used) RemoveFontResource(td->font_file);
1601 /* Free the old name */
1602 string_free(td->font_file);
1605 td->font_file = NULL;
1610 if (!path) return (1);
1616 /* Analyze font path */
1617 base = analyze_font(buf, &wid, &hgt);
1620 if (!suffix(base, ".FON")) return (1);
1623 if (!check_file(buf)) return (1);
1625 /* Load the new font */
1626 if (!AddFontResource(buf)) return (1);
1628 /* Save new font name */
1629 td->font_file = string_make(base);
1631 /* Remove the "suffix" */
1632 base[strlen(base)-4] = '\0';
1635 /* Create the font (using the 'base' of the font file name!) */
1637 td->font_id = CreateFontIndirect(&(td->lf));
1638 wid = td->lf.lfWidth;
1639 hgt = td->lf.lfHeight;
1640 if (!td->font_id) return (1);
1642 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1643 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1644 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1645 FIXED_PITCH | FF_DONTCARE, base);
1649 /* Hack -- Unknown size */
1656 /* all this trouble to get the cell size */
1657 hdcDesktop = GetDC(HWND_DESKTOP);
1658 hfOld = SelectObject(hdcDesktop, td->font_id);
1659 GetTextMetrics(hdcDesktop, &tm);
1660 SelectObject(hdcDesktop, hfOld);
1661 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1663 /* Font size info */
1664 wid = tm.tmAveCharWidth;
1668 /* Save the size info */
1679 * Allow the user to change the font for this window.
1681 static void term_change_font(term_data *td)
1686 memset(&cf, 0, sizeof(cf));
1687 cf.lStructSize = sizeof(cf);
1688 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1689 cf.lpLogFont = &(td->lf);
1691 if (ChooseFont(&cf))
1693 /* Force the font */
1694 term_force_font(td, NULL);
1696 /* Assume not bizarre */
1699 /* Reset the tile info */
1700 td->tile_wid = td->font_wid;
1701 td->tile_hgt = td->font_hgt;
1703 /* Analyze the font */
1706 /* Resize the window */
1707 term_window_resize(td);
1713 char tmp[1024] = "";
1715 /* Extract a default if possible */
1716 if (td->font_file) strcpy(tmp, td->font_file);
1718 /* Ask for a choice */
1719 memset(&ofn, 0, sizeof(ofn));
1720 ofn.lStructSize = sizeof(ofn);
1721 ofn.hwndOwner = data[0].w;
1722 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1723 ofn.nFilterIndex = 1;
1724 ofn.lpstrFile = tmp;
1726 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1727 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1728 ofn.lpstrDefExt = "fon";
1730 /* Force choice if legal */
1731 if (GetOpenFileName(&ofn))
1733 /* Force the font */
1734 if (term_force_font(td, tmp))
1736 /* Access the standard font file */
1737 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1739 /* Force the use of that font */
1740 (void)term_force_font(td, tmp);
1743 /* Assume not bizarre */
1744 td->bizarre = FALSE;
1746 /* Reset the tile info */
1747 td->tile_wid = td->font_wid;
1748 td->tile_hgt = td->font_hgt;
1750 /* Analyze the font */
1753 /* Resize the window */
1754 term_window_resize(td);
1761 * Allow the user to lock this window.
1763 static void term_window_pos(term_data *td, HWND hWnd)
1765 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1766 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1769 static void windows_map(void);
1772 * Hack -- redraw a term_data
1774 static void term_data_redraw(term_data *td)
1778 /* Redraw the map */
1783 /* Activate the term */
1784 Term_activate(&td->t);
1786 /* Redraw the contents */
1789 /* Restore the term */
1790 Term_activate(term_screen);
1798 /*** Function hooks needed by "Term" ***/
1804 * Initialize a new Term
1806 static void Term_init_win(term *t)
1815 static void Term_nuke_win(term *t)
1824 * Interact with the User
1826 static errr Term_user_win(int n)
1834 * React to global changes
1836 static errr Term_xtra_win_react(void)
1844 /* Save the default colors */
1845 for (i = 0; i < 256; i++)
1847 /* Simply accept the desired colors */
1848 win_pal[i] = angband_color_table[i][0];
1859 bool change = FALSE;
1861 /* Save the default colors */
1862 for (i = 0; i < 256; i++)
1864 /* Extract desired values */
1865 rv = angband_color_table[i][1];
1866 gv = angband_color_table[i][2];
1867 bv = angband_color_table[i][3];
1869 /* Extract a full color code */
1870 code = PALETTERGB(rv, gv, bv);
1872 /* Activate changes */
1873 if (win_clr[i] != code)
1875 /* Note the change */
1878 /* Apply the desired color */
1883 /* Activate the palette if needed */
1884 if (change) (void)new_palette();
1890 /* Handle "arg_sound" */
1891 if (use_sound != arg_sound)
1893 /* Initialize (if needed) */
1894 if (arg_sound && !init_sound())
1898 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
1900 plog("Cannot initialize sound!");
1908 /* Change setting */
1909 use_sound = arg_sound;
1917 /* Handle "arg_graphics" */
1918 if (use_graphics != arg_graphics)
1920 /* Initialize (if needed) */
1921 if (arg_graphics && !init_graphics())
1925 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
1927 plog("Cannot initialize graphics!");
1932 arg_graphics = GRAPHICS_NONE;
1935 /* Change setting */
1936 use_graphics = arg_graphics;
1939 #ifdef ANGBAND_2_8_1
1941 #else /* ANGBAND_2_8_1 */
1942 reset_visuals(TRUE);
1943 #endif /* ANGBAND_2_8_1 */
1946 #endif /* USE_GRAPHICS */
1949 /* Clean up windows */
1950 for (i = 0; i < MAX_TERM_DATA; i++)
1954 term_data *td = &data[i];
1956 /* Update resized windows */
1957 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
1960 Term_activate(&td->t);
1962 /* Hack -- Resize the term */
1963 Term_resize(td->cols, td->rows);
1965 /* Redraw the contents */
1980 * Process at least one event
1982 static errr Term_xtra_win_event(int v)
1986 /* Wait for an event */
1990 if (GetMessage(&msg, NULL, 0, 0))
1992 TranslateMessage(&msg);
1993 DispatchMessage(&msg);
1997 /* Check for an event */
2001 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2003 TranslateMessage(&msg);
2004 DispatchMessage(&msg);
2014 * Process all pending events
2016 static errr Term_xtra_win_flush(void)
2020 /* Process all pending events */
2021 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2023 TranslateMessage(&msg);
2024 DispatchMessage(&msg);
2033 * Hack -- clear the screen
2035 * Make this more efficient XXX XXX XXX
2037 static errr Term_xtra_win_clear(void)
2039 term_data *td = (term_data*)(Term->data);
2044 /* Rectangle to erase */
2045 rc.left = td->size_ow1;
2046 rc.right = rc.left + td->cols * td->tile_wid;
2047 rc.top = td->size_oh1;
2048 rc.bottom = rc.top + td->rows * td->tile_hgt;
2052 SetBkColor(hdc, RGB(0, 0, 0));
2053 SelectObject(hdc, td->font_id);
2054 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2059 rc.left = 0; rc.top = 0;
2062 ReleaseDC(td->w, hdc);
2070 * Hack -- make a noise
2072 static errr Term_xtra_win_noise(void)
2074 MessageBeep(MB_ICONASTERISK);
2080 * Hack -- make a sound
2082 static errr Term_xtra_win_sound(int v)
2084 /* Sound disabled */
2085 if (!use_sound) return (1);
2088 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2093 if (!sound_file[v]) return (1);
2097 /* Play the sound, catch errors */
2098 return (PlaySound(sound_file[v], 0, SND_FILENAME | SND_ASYNC));
2102 /* Play the sound, catch errors */
2103 return (sndPlaySound(sound_file[v], SND_ASYNC));
2107 #else /* USE_SOUND */
2112 #endif /* USE_SOUND */
2117 * Delay for "x" milliseconds
2119 static int Term_xtra_win_delay(int v)
2133 t = GetTickCount() + v;
2136 while (GetTickCount() < t)
2138 /* Handle messages */
2139 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2141 TranslateMessage(&msg);
2142 DispatchMessage(&msg);
2154 * Do a "special thing"
2156 static errr Term_xtra_win(int n, int v)
2158 /* Handle a subset of the legal requests */
2161 /* Make a bell sound */
2162 case TERM_XTRA_NOISE:
2164 return (Term_xtra_win_noise());
2167 /* Make a special sound */
2168 case TERM_XTRA_SOUND:
2170 return (Term_xtra_win_sound(v));
2173 /* Process random events */
2174 case TERM_XTRA_BORED:
2176 return (Term_xtra_win_event(0));
2179 /* Process an event */
2180 case TERM_XTRA_EVENT:
2182 return (Term_xtra_win_event(v));
2185 /* Flush all events */
2186 case TERM_XTRA_FLUSH:
2188 return (Term_xtra_win_flush());
2191 /* Clear the screen */
2192 case TERM_XTRA_CLEAR:
2194 return (Term_xtra_win_clear());
2197 /* React to global changes */
2198 case TERM_XTRA_REACT:
2200 return (Term_xtra_win_react());
2203 /* Delay for some milliseconds */
2204 case TERM_XTRA_DELAY:
2206 return (Term_xtra_win_delay(v));
2217 * Low level graphics (Assumes valid input).
2219 * Draw a "cursor" at (x,y), using a "yellow box".
2221 static errr Term_curs_win(int x, int y)
2223 term_data *td = (term_data*)(Term->data);
2228 int tile_wid, tile_hgt;
2232 tile_wid = td->map_tile_wid;
2233 tile_hgt = td->map_tile_hgt;
2237 tile_wid = td->tile_wid;
2238 tile_hgt = td->tile_hgt;
2241 /* Frame the grid */
2242 rc.left = x * tile_wid + td->size_ow1;
2243 rc.right = rc.left + tile_wid;
2244 rc.top = y * tile_hgt + td->size_oh1;
2245 rc.bottom = rc.top + tile_hgt;
2247 /* Cursor is done as a yellow "box" */
2249 FrameRect(hdc, &rc, hbrYellow);
2250 ReleaseDC(td->w, hdc);
2258 * Low level graphics (Assumes valid input).
2260 * Draw a "big cursor" at (x,y), using a "yellow box".
2262 static errr Term_bigcurs_win(int x, int y)
2264 term_data *td = (term_data*)(Term->data);
2269 int tile_wid, tile_hgt;
2273 /* Normal cursor in map window */
2274 Term_curs_win(x, y);
2279 tile_wid = td->tile_wid;
2280 tile_hgt = td->tile_hgt;
2283 /* Frame the grid */
2284 rc.left = x * tile_wid + td->size_ow1;
2285 rc.right = rc.left + 2 * tile_wid;
2286 rc.top = y * tile_hgt + td->size_oh1;
2287 rc.bottom = rc.top + tile_hgt;
2289 /* Cursor is done as a yellow "box" */
2291 FrameRect(hdc, &rc, hbrYellow);
2292 ReleaseDC(td->w, hdc);
2300 * Low level graphics (Assumes valid input).
2302 * Erase a "block" of "n" characters starting at (x,y).
2304 static errr Term_wipe_win(int x, int y, int n)
2306 term_data *td = (term_data*)(Term->data);
2311 /* Rectangle to erase in client coords */
2312 rc.left = x * td->tile_wid + td->size_ow1;
2313 rc.right = rc.left + n * td->tile_wid;
2314 rc.top = y * td->tile_hgt + td->size_oh1;
2315 rc.bottom = rc.top + td->tile_hgt;
2318 SetBkColor(hdc, RGB(0, 0, 0));
2319 SelectObject(hdc, td->font_id);
2324 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2325 ReleaseDC(td->w, hdc);
2333 * Low level graphics. Assumes valid input.
2335 * Draw several ("n") chars, with an attr, at a given location.
2337 * All "graphic" data is handled by "Term_pict_win()", below.
2339 * One would think there is a more efficient method for telling a window
2340 * what color it should be using to draw with, but perhaps simply changing
2341 * it every time is not too inefficient. XXX XXX XXX
2343 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2345 term_data *td = (term_data*)(Term->data);
2351 static HBITMAP WALL;
2352 static HBRUSH myBrush, oldBrush;
2354 static bool init_done = FALSE;
2357 WALL = LoadBitmap(hInstance, AppName);
2358 myBrush = CreatePatternBrush(WALL);
2363 /* Total rectangle */
2364 rc.left = x * td->tile_wid + td->size_ow1;
2365 rc.right = rc.left + n * td->tile_wid;
2366 rc.top = y * td->tile_hgt + td->size_oh1;
2367 rc.bottom = rc.top + td->tile_hgt;
2372 /* Background color */
2373 SetBkColor(hdc, RGB(0, 0, 0));
2375 /* Foreground color */
2378 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2382 SetTextColor(hdc, win_clr[a&0x0F]);
2386 SetTextColor(hdc, win_clr[a]);
2390 SelectObject(hdc, td->font_id);
2393 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2397 (td->tile_hgt != td->font_hgt) ||
2398 (td->tile_wid != td->font_wid))
2402 /* Erase complete rectangle */
2403 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2406 if (use_bg) DrawBG(hdc, &rc);
2409 rc.left += ((td->tile_wid - td->font_wid) / 2);
2410 rc.right = rc.left + td->font_wid;
2411 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2412 rc.bottom = rc.top + td->font_hgt;
2414 /* Dump each character */
2415 for (i = 0; i < n; i++)
2418 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2420 rc.right += td->font_wid;
2422 oldBrush = SelectObject(hdc, myBrush);
2423 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2426 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2428 SelectObject(hdc, oldBrush);
2429 SelectObject(hdc, oldPen);
2430 rc.right -= td->font_wid;
2434 rc.left += 2 * td->tile_wid;
2435 rc.right += 2 * td->tile_wid;
2437 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2439 rc.right += td->font_wid;
2441 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2443 rc.right -= td->font_wid;
2447 rc.left += 2 * td->tile_wid;
2448 rc.right += 2 * td->tile_wid;
2449 } else if (*(s+i)==127){
2450 oldBrush = SelectObject(hdc, myBrush);
2451 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2454 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2456 SelectObject(hdc, oldBrush);
2457 SelectObject(hdc, oldPen);
2460 rc.left += td->tile_wid;
2461 rc.right += td->tile_wid;
2464 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2468 rc.left += td->tile_wid;
2469 rc.right += td->tile_wid;
2473 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2477 rc.left += td->tile_wid;
2478 rc.right += td->tile_wid;
2488 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2493 ReleaseDC(td->w, hdc);
2501 * Low level graphics. Assumes valid input.
2503 * Draw an array of "special" attr/char pairs at the given location.
2505 * We use the "Term_pict_win()" function for "graphic" data, which are
2506 * encoded by setting the "high-bits" of both the "attr" and the "char"
2507 * data. We use the "attr" to represent the "row" of the main bitmap,
2508 * and the "char" to represent the "col" of the main bitmap. The use
2509 * of this function is induced by the "higher_pict" flag.
2511 * If "graphics" is not available, we simply "wipe" the given grids.
2513 # ifdef USE_TRANSPARENCY
2514 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2515 # else /* USE_TRANSPARENCY */
2516 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp)
2517 # endif /* USE_TRANSPARENCY */
2519 term_data *td = (term_data*)(Term->data);
2525 int x2, y2, w2, h2, tw2;
2527 # ifdef USE_TRANSPARENCY
2533 # endif /* USE_TRANSPARENCY */
2542 /* Erase the grids */
2543 return (Term_wipe_win(x, y, n));
2546 /* Size of bitmap cell */
2547 w1 = infGraph.CellWidth;
2548 h1 = infGraph.CellHeight;
2550 /* Size of window cell */
2553 w2 = td->map_tile_wid;
2554 h2 = td->map_tile_hgt;
2563 if (use_bigtile) tw2 *= 2;
2566 /* Location of window cell */
2567 x2 = x * w2 + td->size_ow1;
2568 y2 = y * h2 + td->size_oh1;
2574 hdcSrc = CreateCompatibleDC(hdc);
2575 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2577 # ifdef USE_TRANSPARENCY
2579 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2581 hdcMask = CreateCompatibleDC(hdc);
2582 SelectObject(hdcMask, infMask.hBitmap);
2585 # endif /* USE_TRANSPARENCY */
2587 /* Draw attr/char pairs */
2588 for (i = 0; i < n; i++, x2 += w2)
2593 /* Extract picture */
2594 int row = (a & 0x7F);
2595 int col = (c & 0x7F);
2597 /* Location of bitmap cell */
2601 # ifdef USE_TRANSPARENCY
2603 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2605 x3 = (tcp[i] & 0x7F) * w1;
2606 y3 = (tap[i] & 0x7F) * h1;
2609 if ((w1 == tw2) && (h1 == h2))
2611 /* Copy the terrain picture from the bitmap to the window */
2612 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2614 /* Mask out the tile */
2615 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2618 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2621 /* Need to stretch */
2624 /* Set the correct mode for stretching the tiles */
2625 SetStretchBltMode(hdc, COLORONCOLOR);
2627 /* Copy the terrain picture from the bitmap to the window */
2628 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
2630 /* Only draw if terrain and overlay are different */
2631 if ((x1 != x3) || (y1 != y3))
2633 /* Mask out the tile */
2634 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2637 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2643 # endif /* USE_TRANSPARENCY */
2647 if ((w1 == tw2) && (h1 == h2))
2649 /* Copy the picture from the bitmap to the window */
2650 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2653 /* Need to stretch */
2656 /* Set the correct mode for stretching the tiles */
2657 SetStretchBltMode(hdc, COLORONCOLOR);
2659 /* Copy the picture from the bitmap to the window */
2660 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2666 SelectObject(hdcSrc, hbmSrcOld);
2669 # ifdef USE_TRANSPARENCY
2671 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2674 SelectObject(hdcMask, hbmSrcOld);
2678 # endif /* USE_TRANSPARENCY */
2681 ReleaseDC(td->w, hdc);
2683 #else /* USE_GRAPHICS */
2685 /* Just erase this grid */
2686 return (Term_wipe_win(x, y, n));
2688 #endif /* USE_GRAPHICS */
2695 static void windows_map(void)
2697 term_data *td = &data[0];
2699 int x, min_x, max_x;
2700 int y, min_y, max_y;
2702 #ifdef USE_TRANSPARENCY
2706 /* Only in graphics mode */
2707 if (!use_graphics) return;
2710 Term_xtra_win_clear();
2712 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2713 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2714 td->map_active = TRUE;
2724 for (x = min_x; x < max_x; x++)
2726 for (y = min_y; y < max_y; y++)
2728 #ifdef USE_TRANSPARENCY
2729 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
2730 #else /* USE_TRANSPARENCY */
2731 map_info(y, x, &a, (char*)&c);
2732 #endif /* USE_TRANSPARENCY */
2734 /* Ignore non-graphics */
2735 if ((a & 0x80) && (c & 0x80))
2737 #ifdef USE_TRANSPARENCY
2738 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2739 #else /* USE_TRANSPARENCY */
2740 Term_pict_win(x - min_x, y - min_y, 1, &a, &c);
2741 #endif /* USE_TRANSPARENCY */
2746 /* Hilite the player */
2747 Term_curs_win(px - min_x, py - min_y);
2749 /* Wait for a keypress, flush key buffer */
2750 Term_inkey(&c, TRUE, TRUE);
2753 /* Switch off the map display */
2754 td->map_active = FALSE;
2756 /* Restore screen */
2757 Term_xtra_win_clear();
2762 /*** Other routines ***/
2766 * Create and initialize a "term_data" given a title
2768 static void term_data_link(term_data *td)
2772 /* Initialize the term */
2773 term_init(t, td->cols, td->rows, td->keys);
2775 /* Use a "software" cursor */
2776 t->soft_cursor = TRUE;
2778 /* Use "Term_pict" for "graphic" data */
2779 t->higher_pict = TRUE;
2781 /* Erase with "white space" */
2782 t->attr_blank = TERM_WHITE;
2783 t->char_blank = ' ';
2786 /* Prepare the init/nuke hooks */
2787 t->init_hook = Term_init_win;
2788 t->nuke_hook = Term_nuke_win;
2791 /* Prepare the template hooks */
2792 t->user_hook = Term_user_win;
2793 t->xtra_hook = Term_xtra_win;
2794 t->curs_hook = Term_curs_win;
2795 t->bigcurs_hook = Term_bigcurs_win;
2796 t->wipe_hook = Term_wipe_win;
2797 t->text_hook = Term_text_win;
2798 t->pict_hook = Term_pict_win;
2800 /* Remember where we came from */
2801 t->data = (vptr)(td);
2806 * Create the windows
2808 * First, instantiate the "default" values, then read the "ini_file"
2809 * to over-ride selected values, then create the windows, and fonts.
2811 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2812 * must make active to realize the palette. XXX XXX XXX
2814 static void init_windows(void)
2826 WIPE(td, term_data);
2830 td->s = angband_term_name[0];
2849 for (i = 1; i < MAX_TERM_DATA; i++)
2852 WIPE(td, term_data);
2853 td->s = angband_term_name[i];
2857 td->visible = FALSE;
2862 td->pos_x = (7 - i) * 30;
2863 td->pos_y = (7 - i) * 20;
2875 /* Main window (need these before term_getsize gets called) */
2877 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2878 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2883 /* Sub windows (need these before term_getsize gets called) */
2884 for (i = 1; i < MAX_TERM_DATA; i++)
2887 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2888 td->dwExStyle = (WS_EX_TOOLWINDOW);
2893 for (i = 0; i < MAX_TERM_DATA; i++)
2898 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2899 td->lf.lfCharSet = SHIFTJIS_CHARSET;
2900 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2901 /* Activate the chosen font */
2902 term_force_font(td, NULL);
2903 td->tile_wid = td->font_wid;
2904 td->tile_hgt = td->font_hgt;
2906 /* Access the standard font file */
2907 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
2909 /* Activate the chosen font */
2910 if (term_force_font(td, buf))
2912 /* Access the standard font file */
2913 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2915 /* Force the use of that font */
2916 (void)term_force_font(td, buf);
2922 /* Assume not bizarre */
2923 td->bizarre = FALSE;
2928 /* Analyze the font */
2931 /* Resize the window */
2932 term_window_resize(td);
2936 /* Sub windows (reverse order) */
2937 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
2942 td->w = CreateWindowEx(td->dwExStyle, AngList,
2944 td->pos_x, td->pos_y,
2945 td->size_wid, td->size_hgt,
2946 HWND_DESKTOP, NULL, hInstance, NULL);
2949 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
2951 if (!td->w) quit("Failed to create sub-window");
2957 td->size_hack = TRUE;
2958 ShowWindow(td->w, SW_SHOW);
2959 td->size_hack = FALSE;
2963 angband_term[i] = &td->t;
2967 /* Activate the window */
2968 SetActiveWindow(td->w);
2973 term_window_pos(&data[i], HWND_TOPMOST);
2977 term_window_pos(&data[i], td->w);
2987 td->w = CreateWindowEx(td->dwExStyle, AppName,
2989 td->pos_x, td->pos_y,
2990 td->size_wid, td->size_hgt,
2991 HWND_DESKTOP, NULL, hInstance, NULL);
2994 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
2996 if (!td->w) quit("Failed to create Angband window");
3001 angband_term[0] = &td->t;
3003 /* Activate the main window */
3004 SetActiveWindow(td->w);
3006 /* Bring main window back to top */
3007 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3010 /* New palette XXX XXX XXX */
3011 (void)new_palette();
3014 /* Create a "brush" for drawing the "cursor" */
3015 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3018 /* Process pending messages */
3019 (void)Term_xtra_win_flush();
3027 static void setup_menus(void)
3031 HMENU hm = GetMenu(data[0].w);
3034 /* Menu "File", Disable all */
3035 EnableMenuItem(hm, IDM_FILE_NEW,
3036 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3037 EnableMenuItem(hm, IDM_FILE_OPEN,
3038 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3039 EnableMenuItem(hm, IDM_FILE_SAVE,
3040 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3041 EnableMenuItem(hm, IDM_FILE_EXIT,
3042 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3043 EnableMenuItem(hm, IDM_FILE_SCORE,
3044 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3047 /* No character available */
3048 if (!character_generated)
3050 /* Menu "File", Item "New" */
3051 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3053 /* Menu "File", Item "Open" */
3054 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3057 /* A character available */
3058 if (character_generated)
3060 /* Menu "File", Item "Save" */
3061 EnableMenuItem(hm, IDM_FILE_SAVE,
3062 MF_BYCOMMAND | MF_ENABLED);
3065 /* Menu "File", Item "Exit" */
3066 EnableMenuItem(hm, IDM_FILE_EXIT,
3067 MF_BYCOMMAND | MF_ENABLED);
3069 EnableMenuItem(hm, IDM_FILE_SCORE,
3070 MF_BYCOMMAND | MF_ENABLED);
3073 /* Menu "Window::Visibility" */
3074 for (i = 0; i < MAX_TERM_DATA; i++)
3076 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3077 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3079 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3080 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3082 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3083 MF_BYCOMMAND | MF_ENABLED);
3086 /* Menu "Window::Font" */
3087 for (i = 0; i < MAX_TERM_DATA; i++)
3089 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3090 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3092 if (data[i].visible)
3094 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3095 MF_BYCOMMAND | MF_ENABLED);
3099 /* Menu "Window::Window Position Fix" */
3100 for (i = 0; i < MAX_TERM_DATA; i++)
3102 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3103 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3105 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3106 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3108 if (data[i].visible)
3110 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3111 MF_BYCOMMAND | MF_ENABLED);
3115 /* Menu "Window::Bizarre Display" */
3116 for (i = 0; i < MAX_TERM_DATA; i++)
3118 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3119 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3121 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3122 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3124 if (data[i].visible)
3126 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3127 MF_BYCOMMAND | MF_ENABLED);
3132 /* Menu "Window::Increase Tile Width" */
3133 for (i = 0; i < MAX_TERM_DATA; i++)
3135 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3136 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3138 if (data[i].visible)
3140 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3141 MF_BYCOMMAND | MF_ENABLED);
3146 /* Menu "Window::Decrease Tile Width" */
3147 for (i = 0; i < MAX_TERM_DATA; i++)
3149 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3150 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3152 if (data[i].visible)
3154 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3155 MF_BYCOMMAND | MF_ENABLED);
3160 /* Menu "Window::Increase Tile Height" */
3161 for (i = 0; i < MAX_TERM_DATA; i++)
3163 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3164 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3166 if (data[i].visible)
3168 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3169 MF_BYCOMMAND | MF_ENABLED);
3174 /* Menu "Window::Decrease Tile Height" */
3175 for (i = 0; i < MAX_TERM_DATA; i++)
3177 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3178 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3180 if (data[i].visible)
3182 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3183 MF_BYCOMMAND | MF_ENABLED);
3188 /* Menu "Options", disable all */
3189 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3190 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3191 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3192 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3193 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3194 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3195 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3196 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3197 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3198 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3200 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3201 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3204 /* Menu "Options", Item "Map" */
3205 if (use_graphics != GRAPHICS_NONE)
3206 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3208 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3209 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3211 /* Menu "Options", update all */
3212 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3213 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3214 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3215 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3216 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3217 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3218 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3219 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3220 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3221 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3222 CheckMenuItem(hm, IDM_OPTIONS_BG,
3223 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3225 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3226 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3230 /* Menu "Options", Item "Graphics" */
3231 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3232 /* Menu "Options", Item "Graphics" */
3233 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3234 /* Menu "Options", Item "Graphics" */
3235 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3236 /* Menu "Options", Item "Graphics" */
3237 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3238 #endif /* USE_GRAPHICS */
3241 /* Menu "Options", Item "Sound" */
3242 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3243 #endif /* USE_SOUND */
3246 /* Menu "Options", Item "ScreenSaver" */
3247 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3248 MF_BYCOMMAND | MF_ENABLED);
3249 #endif /* USE_SAVER */
3254 * Check for double clicked (or dragged) savefile
3256 * Apparently, Windows copies the entire filename into the first
3257 * piece of the "command line string". Perhaps we should extract
3258 * the "basename" of that filename and append it to the "save" dir.
3260 static void check_for_save_file(LPSTR cmd_line)
3270 /* Extract filename */
3271 strcat(savefile, s);
3273 /* Validate the file */
3274 validate_file(savefile);
3276 /* Game in progress */
3277 game_in_progress = TRUE;
3285 * Process a menu command
3287 static void process_menus(WORD wCmd)
3304 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3306 plog("You cannot do that yet...");
3310 else if (game_in_progress)
3313 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3315 plog("You can't start a new game while you're still playing!");
3321 game_in_progress = TRUE;
3335 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3337 plog("You cannot do that yet...");
3341 else if (game_in_progress)
3344 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3346 plog("You can't open a new game while you're still playing!");
3352 memset(&ofn, 0, sizeof(ofn));
3353 ofn.lStructSize = sizeof(ofn);
3354 ofn.hwndOwner = data[0].w;
3355 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3356 ofn.nFilterIndex = 1;
3357 ofn.lpstrFile = savefile;
3358 ofn.nMaxFile = 1024;
3359 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3360 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3362 if (GetOpenFileName(&ofn))
3364 /* Load 'savefile' */
3365 validate_file(savefile);
3366 game_in_progress = TRUE;
3378 if (game_in_progress && character_generated)
3384 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3386 plog("You may not do that right now.");
3392 /* Hack -- Forget messages */
3397 do_cmd_save_game(FALSE);
3398 #else /* ZANGBAND */
3400 #endif /* ZANGBAND */
3405 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3407 plog("You may not do that right now.");
3417 if (game_in_progress && character_generated)
3423 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3425 plog("You may not do that right now.");
3431 /* Hack -- Forget messages */
3440 /* do_cmd_save_game(FALSE); */
3441 #else /* ZANGBAND */
3442 /* do_cmd_save_game(); */
3443 #endif /* ZANGBAND */
3444 Term_key_push(SPECIAL_KEY_QUIT);
3452 case IDM_FILE_SCORE:
3456 /* Build the filename */
3457 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3459 /* Open the binary high score file, for reading */
3460 highscore_fd = fd_open(buf, O_RDONLY);
3462 /* Paranoia -- No score file */
3463 if (highscore_fd < 0)
3465 msg_print("Score file unavailable.");
3475 /* Display the scores */
3476 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3478 /* Shut the high score file */
3479 (void)fd_close(highscore_fd);
3481 /* Forget the high score fd */
3487 /* Hack - Flush it */
3495 case IDM_WINDOW_VIS_0:
3498 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3500 plog("You are not allowed to do that!");
3507 /* Window visibility */
3508 case IDM_WINDOW_VIS_1:
3509 case IDM_WINDOW_VIS_2:
3510 case IDM_WINDOW_VIS_3:
3511 case IDM_WINDOW_VIS_4:
3512 case IDM_WINDOW_VIS_5:
3513 case IDM_WINDOW_VIS_6:
3514 case IDM_WINDOW_VIS_7:
3516 i = wCmd - IDM_WINDOW_VIS_0;
3518 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3525 ShowWindow(td->w, SW_SHOW);
3526 term_data_redraw(td);
3530 td->visible = FALSE;
3532 ShowWindow(td->w, SW_HIDE);
3539 case IDM_WINDOW_FONT_0:
3540 case IDM_WINDOW_FONT_1:
3541 case IDM_WINDOW_FONT_2:
3542 case IDM_WINDOW_FONT_3:
3543 case IDM_WINDOW_FONT_4:
3544 case IDM_WINDOW_FONT_5:
3545 case IDM_WINDOW_FONT_6:
3546 case IDM_WINDOW_FONT_7:
3548 i = wCmd - IDM_WINDOW_FONT_0;
3550 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3554 term_change_font(td);
3559 /* Window Z Position */
3560 case IDM_WINDOW_POS_1:
3561 case IDM_WINDOW_POS_2:
3562 case IDM_WINDOW_POS_3:
3563 case IDM_WINDOW_POS_4:
3564 case IDM_WINDOW_POS_5:
3565 case IDM_WINDOW_POS_6:
3566 case IDM_WINDOW_POS_7:
3568 i = wCmd - IDM_WINDOW_POS_0;
3570 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3574 if (!td->posfix && td->visible)
3577 term_window_pos(td, HWND_TOPMOST);
3582 term_window_pos(td, data[0].w);
3588 /* Bizarre Display */
3589 case IDM_WINDOW_BIZ_0:
3590 case IDM_WINDOW_BIZ_1:
3591 case IDM_WINDOW_BIZ_2:
3592 case IDM_WINDOW_BIZ_3:
3593 case IDM_WINDOW_BIZ_4:
3594 case IDM_WINDOW_BIZ_5:
3595 case IDM_WINDOW_BIZ_6:
3596 case IDM_WINDOW_BIZ_7:
3598 i = wCmd - IDM_WINDOW_BIZ_0;
3600 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3604 td->bizarre = !td->bizarre;
3608 term_window_resize(td);
3613 /* Increase Tile Width */
3614 case IDM_WINDOW_I_WID_0:
3615 case IDM_WINDOW_I_WID_1:
3616 case IDM_WINDOW_I_WID_2:
3617 case IDM_WINDOW_I_WID_3:
3618 case IDM_WINDOW_I_WID_4:
3619 case IDM_WINDOW_I_WID_5:
3620 case IDM_WINDOW_I_WID_6:
3621 case IDM_WINDOW_I_WID_7:
3623 i = wCmd - IDM_WINDOW_I_WID_0;
3625 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3633 term_window_resize(td);
3638 /* Decrease Tile Height */
3639 case IDM_WINDOW_D_WID_0:
3640 case IDM_WINDOW_D_WID_1:
3641 case IDM_WINDOW_D_WID_2:
3642 case IDM_WINDOW_D_WID_3:
3643 case IDM_WINDOW_D_WID_4:
3644 case IDM_WINDOW_D_WID_5:
3645 case IDM_WINDOW_D_WID_6:
3646 case IDM_WINDOW_D_WID_7:
3648 i = wCmd - IDM_WINDOW_D_WID_0;
3650 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3658 term_window_resize(td);
3663 /* Increase Tile Height */
3664 case IDM_WINDOW_I_HGT_0:
3665 case IDM_WINDOW_I_HGT_1:
3666 case IDM_WINDOW_I_HGT_2:
3667 case IDM_WINDOW_I_HGT_3:
3668 case IDM_WINDOW_I_HGT_4:
3669 case IDM_WINDOW_I_HGT_5:
3670 case IDM_WINDOW_I_HGT_6:
3671 case IDM_WINDOW_I_HGT_7:
3673 i = wCmd - IDM_WINDOW_I_HGT_0;
3675 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3683 term_window_resize(td);
3688 /* Decrease Tile Height */
3689 case IDM_WINDOW_D_HGT_0:
3690 case IDM_WINDOW_D_HGT_1:
3691 case IDM_WINDOW_D_HGT_2:
3692 case IDM_WINDOW_D_HGT_3:
3693 case IDM_WINDOW_D_HGT_4:
3694 case IDM_WINDOW_D_HGT_5:
3695 case IDM_WINDOW_D_HGT_6:
3696 case IDM_WINDOW_D_HGT_7:
3698 i = wCmd - IDM_WINDOW_D_HGT_0;
3700 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3708 term_window_resize(td);
3713 case IDM_OPTIONS_NO_GRAPHICS:
3718 plog("You may not do that right now.");
3722 /* Toggle "arg_graphics" */
3723 if (arg_graphics != GRAPHICS_NONE)
3725 arg_graphics = GRAPHICS_NONE;
3727 /* React to changes */
3728 Term_xtra_win_react();
3730 /* Hack -- Force redraw */
3731 Term_key_push(KTRL('R'));
3737 case IDM_OPTIONS_OLD_GRAPHICS:
3742 plog("You may not do that right now.");
3746 /* Toggle "arg_graphics" */
3747 if (arg_graphics != GRAPHICS_ORIGINAL)
3749 arg_graphics = GRAPHICS_ORIGINAL;
3751 /* React to changes */
3752 Term_xtra_win_react();
3754 /* Hack -- Force redraw */
3755 Term_key_push(KTRL('R'));
3761 case IDM_OPTIONS_NEW_GRAPHICS:
3766 plog("You may not do that right now.");
3770 /* Toggle "arg_graphics" */
3771 if (arg_graphics != GRAPHICS_ADAM_BOLT)
3773 arg_graphics = GRAPHICS_ADAM_BOLT;
3775 /* React to changes */
3776 Term_xtra_win_react();
3778 /* Hack -- Force redraw */
3779 Term_key_push(KTRL('R'));
3785 case IDM_OPTIONS_BIGTILE:
3787 term_data *td = &data[0];
3792 plog("You may not do that right now.");
3796 /* Toggle "arg_sound" */
3797 arg_bigtile = !arg_bigtile;
3800 Term_activate(&td->t);
3802 /* Resize the term */
3803 Term_resize(td->cols, td->rows);
3806 InvalidateRect(td->w, NULL, TRUE);
3811 case IDM_OPTIONS_SOUND:
3816 plog("You may not do that right now.");
3820 /* Toggle "arg_sound" */
3821 arg_sound = !arg_sound;
3823 /* React to changes */
3824 Term_xtra_win_react();
3826 /* Hack -- Force redraw */
3827 Term_key_push(KTRL('R'));
3833 case IDM_OPTIONS_BG:
3838 plog("You may not do that right now.");
3842 /* Toggle "use_bg" */
3847 /* React to changes */
3848 Term_xtra_win_react();
3850 /* Hack -- Force redraw */
3851 Term_key_push(KTRL('R'));
3857 case IDM_OPTIONS_OPEN_BG:
3862 plog("You may not do that right now.");
3867 memset(&ofn, 0, sizeof(ofn));
3868 ofn.lStructSize = sizeof(ofn);
3869 ofn.hwndOwner = data[0].w;
3870 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3871 ofn.nFilterIndex = 1;
3872 ofn.lpstrFile = bg_bitmap_file;
3873 ofn.nMaxFile = 1023;
3874 ofn.lpstrInitialDir = NULL;
3876 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
3878 ofn.lpstrTitle = "Choose wall paper.";
3880 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3882 if (GetOpenFileName(&ofn))
3884 /* Load 'savefile' */
3889 /* React to changes */
3890 Term_xtra_win_react();
3892 /* Hack -- Force redraw */
3893 Term_key_push(KTRL('R'));
3898 case IDM_DUMP_SCREEN_HTML:
3900 static char buf[1024] = "";
3901 memset(&ofn, 0, sizeof(ofn));
3902 ofn.lStructSize = sizeof(ofn);
3903 ofn.hwndOwner = data[0].w;
3904 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
3905 ofn.nFilterIndex = 1;
3906 ofn.lpstrFile = buf;
3907 ofn.nMaxFile = 1023;
3908 ofn.lpstrDefExt = "html";
3909 ofn.lpstrInitialDir = NULL;
3911 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
3913 ofn.lpstrTitle = "Save screen dump as HTML.";
3915 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
3917 if (GetSaveFileName(&ofn))
3919 do_cmd_save_screen_html_aux(buf, 0);
3926 case IDM_OPTIONS_SAVER:
3930 DestroyWindow(hwndSaver);
3935 /* Create a screen scaver window */
3936 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
3937 "Angband Screensaver",
3938 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
3939 0, 0, GetSystemMetrics(SM_CXSCREEN),
3940 GetSystemMetrics(SM_CYSCREEN),
3941 NULL, NULL, hInstance, NULL);
3945 /* Push the window to the bottom XXX XXX XXX */
3946 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3951 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
3953 plog("Failed to create saver window");
3963 case IDM_OPTIONS_MAP:
3969 case IDM_HELP_CONTENTS:
3973 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
3974 if (check_file(tmp))
3976 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
3981 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
3982 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
3984 plog_fmt("Cannot find help file: %s", tmp);
3985 plog("Use the online help files instead.");
3990 #else /* HTML_HELP */
3993 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
3994 if (check_file(tmp))
3996 sprintf(buf, "winhelp.exe %s", tmp);
3997 WinExec(buf, SW_NORMAL);
4002 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4003 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4005 plog_fmt("Cannot find help file: %s", tmp);
4006 plog("Use the online help files instead.");
4011 #endif /* HTML_HELP */
4019 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4020 WPARAM wParam, LPARAM lParam);
4021 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4022 WPARAM wParam, LPARAM lParam)
4023 #else /* __MWERKS__ */
4024 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4025 WPARAM wParam, LPARAM lParam)
4026 #endif /* __MWERKS__ */
4032 MINMAXINFO FAR *lpmmi;
4038 /* Acquire proper "term_data" info */
4039 td = (term_data *)GetWindowLong(hWnd, 0);
4041 /* Handle message */
4047 SetWindowLong(hWnd, 0, (LONG)(my_td));
4057 case WM_GETMINMAXINFO:
4059 MINMAXINFO FAR *lpmmi;
4062 lpmmi = (MINMAXINFO FAR *)lParam;
4064 /* this message was sent before WM_NCCREATE */
4067 /* Minimum window size is 80x24 */
4068 rc.left = rc.top = 0;
4069 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4070 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4073 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4075 /* Save minimum size */
4076 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4077 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4084 BeginPaint(hWnd, &ps);
4085 if (td) term_data_redraw(td);
4086 EndPaint(hWnd, &ps);
4087 ValidateRect(hWnd, NULL);
4098 /* Extract the modifiers */
4099 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4100 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4101 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4103 /* Handle "special" keys */
4104 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4106 /* Begin the macro trigger */
4109 /* Send the modifiers */
4110 if (mc) Term_keypress('C');
4111 if (ms) Term_keypress('S');
4112 if (ma) Term_keypress('A');
4114 /* Extract "scan code" */
4115 i = LOBYTE(HIWORD(lParam));
4117 /* Introduce the scan code */
4120 /* Encode the hexidecimal scan code */
4121 Term_keypress(hexsym[i/16]);
4122 Term_keypress(hexsym[i%16]);
4124 /* End the macro trigger */
4135 Term_keypress(wParam);
4147 if (game_in_progress && character_generated)
4152 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4154 plog("You may not do that right now.");
4159 /* Hack -- Forget messages */
4168 /* do_cmd_save_game(FALSE); */
4169 #else /* ZANGBAND */
4170 /* do_cmd_save_game(); */
4171 #endif /* ZANGBAND */
4187 process_menus(LOWORD(wParam));
4193 /* this message was sent before WM_NCCREATE */
4196 /* it was sent from inside CreateWindowEx */
4197 if (!td->w) return 1;
4199 /* was sent from WM_SIZE */
4200 if (td->size_hack) return 1;
4204 case SIZE_MINIMIZED:
4206 /* Hide sub-windows */
4207 for (i = 1; i < MAX_TERM_DATA; i++)
4209 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4214 case SIZE_MAXIMIZED:
4216 /* fall through XXX XXX XXX */
4221 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4222 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4225 if ((td->cols != cols) || (td->rows != rows))
4227 /* Save the new size */
4232 Term_activate(&td->t);
4234 /* Resize the term */
4235 Term_resize(td->cols, td->rows);
4238 InvalidateRect(td->w, NULL, TRUE);
4241 td->size_hack = TRUE;
4243 /* Show sub-windows */
4244 for (i = 1; i < MAX_TERM_DATA; i++)
4246 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4249 td->size_hack = FALSE;
4257 case WM_PALETTECHANGED:
4259 /* Ignore if palette change caused by itself */
4260 if ((HWND)wParam == hWnd) return 0;
4262 /* Fall through... */
4265 case WM_QUERYNEWPALETTE:
4267 if (!paletted) return 0;
4271 SelectPalette(hdc, hPal, FALSE);
4273 i = RealizePalette(hdc);
4275 /* if any palette entries changed, repaint the window. */
4276 if (i) InvalidateRect(hWnd, NULL, TRUE);
4278 ReleaseDC(hWnd, hdc);
4285 if (wParam && !HIWORD(lParam))
4287 /* Do something to sub-windows */
4288 for (i = 1; i < MAX_TERM_DATA; i++)
4290 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4293 /* Focus on main window */
4302 case WM_ACTIVATEAPP:
4304 for (i = 1; i < MAX_TERM_DATA; i++)
4310 ShowWindow(data[i].w, SW_SHOW);
4314 ShowWindow(data[i].w, SW_HIDE);
4321 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4326 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4327 WPARAM wParam, LPARAM lParam);
4328 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4329 WPARAM wParam, LPARAM lParam)
4330 #else /* __MWERKS__ */
4331 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4332 WPARAM wParam, LPARAM lParam)
4333 #endif /* __MWERKS__ */
4337 MINMAXINFO FAR *lpmmi;
4345 /* Acquire proper "term_data" info */
4346 td = (term_data *)GetWindowLong(hWnd, 0);
4348 /* Process message */
4354 SetWindowLong(hWnd, 0, (LONG)(my_td));
4364 case WM_GETMINMAXINFO:
4366 MINMAXINFO FAR *lpmmi;
4369 lpmmi = (MINMAXINFO FAR *)lParam;
4371 /* this message was sent before WM_NCCREATE */
4374 /* Minimum window size is 80x24 */
4375 rc.left = rc.top = 0;
4376 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4377 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4380 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4382 /* Save minimum size */
4383 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4384 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4394 /* this message was sent before WM_NCCREATE */
4397 /* it was sent from inside CreateWindowEx */
4398 if (!td->w) return 1;
4400 /* was sent from inside WM_SIZE */
4401 if (td->size_hack) return 1;
4403 td->size_hack = TRUE;
4405 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4406 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4409 if ((td->cols != cols) || (td->rows != rows))
4412 term *old_term = Term;
4414 /* Save the new size */
4419 Term_activate(&td->t);
4421 /* Resize the term */
4422 Term_resize(td->cols, td->rows);
4425 Term_activate(old_term);
4428 InvalidateRect(td->w, NULL, TRUE);
4430 /* HACK - Redraw all windows */
4431 p_ptr->window = 0xFFFFFFFF;
4435 td->size_hack = FALSE;
4442 BeginPaint(hWnd, &ps);
4443 if (td) term_data_redraw(td);
4444 EndPaint(hWnd, &ps);
4455 /* Extract the modifiers */
4456 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4457 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4458 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4460 /* Handle "special" keys */
4461 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4463 /* Begin the macro trigger */
4466 /* Send the modifiers */
4467 if (mc) Term_keypress('C');
4468 if (ms) Term_keypress('S');
4469 if (ma) Term_keypress('A');
4471 /* Extract "scan code" */
4472 i = LOBYTE(HIWORD(lParam));
4474 /* Introduce the scan code */
4477 /* Encode the hexidecimal scan code */
4478 Term_keypress(hexsym[i/16]);
4479 Term_keypress(hexsym[i%16]);
4481 /* End the macro trigger */
4492 Term_keypress(wParam);
4496 case WM_PALETTECHANGED:
4498 /* ignore if palette change caused by itself */
4499 if ((HWND)wParam == hWnd) return FALSE;
4500 /* otherwise, fall through!!! */
4503 case WM_QUERYNEWPALETTE:
4505 if (!paletted) return 0;
4507 SelectPalette(hdc, hPal, FALSE);
4508 i = RealizePalette(hdc);
4509 /* if any palette entries changed, repaint the window. */
4510 if (i) InvalidateRect(hWnd, NULL, TRUE);
4511 ReleaseDC(hWnd, hdc);
4515 case WM_NCLBUTTONDOWN:
4519 if (wParam == HTCLOSE) wParam = HTSYSMENU;
4520 #endif /* HTCLOSE */
4522 if (wParam == HTSYSMENU)
4526 td->visible = FALSE;
4527 ShowWindow(td->w, SW_HIDE);
4537 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4543 #define MOUSE_SENS 40
4546 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4547 WPARAM wParam, LPARAM lParam);
4548 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4549 WPARAM wParam, LPARAM lParam)
4550 #else /* __MWERKS__ */
4551 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4552 WPARAM wParam, LPARAM lParam)
4553 #endif /* __MWERKS__ */
4555 static int iMouse = 0;
4556 static WORD xMouse = 0;
4557 static WORD yMouse = 0;
4580 if (LOWORD(wParam) == WA_INACTIVE) break;
4582 /* else fall through */
4586 case WM_LBUTTONDOWN:
4587 case WM_MBUTTONDOWN:
4588 case WM_RBUTTONDOWN:
4591 SendMessage(hWnd, WM_CLOSE, 0, 0);
4599 dx = LOWORD(lParam) - xMouse;
4600 dy = HIWORD(lParam) - yMouse;
4602 if (dx < 0) dx = -dx;
4603 if (dy < 0) dy = -dy;
4605 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
4607 SendMessage(hWnd, WM_CLOSE, 0, 0);
4611 /* Save last location */
4613 xMouse = LOWORD(lParam);
4614 yMouse = HIWORD(lParam);
4621 DestroyWindow(hwndSaver);
4628 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4631 #endif /* USE_SAVER */
4637 /*** Temporary Hooks ***/
4641 * Display warning message (see "z-util.c")
4643 static void hack_plog(cptr str)
4645 /* Give a warning */
4649 MessageBox(NULL, str, "·Ù¹ð¡ª",
4650 MB_ICONEXCLAMATION | MB_OK);
4652 MessageBox(NULL, str, "Warning",
4653 MB_ICONEXCLAMATION | MB_OK);
4661 * Display error message and quit (see "z-util.c")
4663 static void hack_quit(cptr str)
4665 /* Give a warning */
4669 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
4670 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4672 MessageBox(NULL, str, "Error",
4673 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4678 /* Unregister the classes */
4679 UnregisterClass(AppName, hInstance);
4681 /* Destroy the icon */
4682 if (hIcon) DestroyIcon(hIcon);
4690 /*** Various hooks ***/
4694 * Display warning message (see "z-util.c")
4696 static void hook_plog(cptr str)
4702 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
4703 MB_ICONEXCLAMATION | MB_OK);
4705 MessageBox(data[0].w, str, "Warning",
4706 MB_ICONEXCLAMATION | MB_OK);
4714 * Display error message and quit (see "z-util.c")
4716 static void hook_quit(cptr str)
4721 /* Give a warning */
4725 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
4726 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4728 MessageBox(data[0].w, str, "Error",
4729 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4735 /* Save the preferences */
4739 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
4741 /* Destroy all windows */
4742 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
4744 term_force_font(&data[i], NULL);
4745 if (data[i].font_want) string_free(data[i].font_want);
4746 if (data[i].w) DestroyWindow(data[i].w);
4750 /* Free the bitmap stuff */
4752 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
4753 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
4755 #ifdef USE_TRANSPARENCY
4756 if (infMask.hPalette) DeleteObject(infMask.hPalette);
4757 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
4758 #endif /* USE_TRANSPARENCY */
4760 #endif /* USE_GRAPHICS */
4762 /*** Free some other stuff ***/
4764 DeleteObject(hbrYellow);
4769 if (hPal) DeleteObject(hPal);
4771 UnregisterClass(AppName, hInstance);
4773 if (hIcon) DestroyIcon(hIcon);
4780 /*** Initialize ***/
4786 static void init_stuff(void)
4793 /* Get program name with full path */
4794 GetModuleFileName(hInstance, path, 512);
4796 /* Save the "program name" XXX XXX XXX */
4799 /* Get the name of the "*.ini" file */
4800 strcpy(path + strlen(path) - 4, ".INI");
4802 /* Save the the name of the ini-file */
4803 ini_file = string_make(path);
4805 /* Analyze the path */
4811 if (path[i] == '\\')
4818 /* Add "lib" to the path */
4819 strcpy(path + i + 1, "lib\\");
4821 /* Validate the path */
4822 validate_dir(path, TRUE);
4824 /* Init the file paths */
4825 init_file_paths(path);
4827 /* Hack -- Validate the paths */
4828 validate_dir(ANGBAND_DIR_APEX, FALSE);
4829 validate_dir(ANGBAND_DIR_BONE, FALSE);
4831 /* Allow missing 'edit' directory */
4832 if (!check_dir(ANGBAND_DIR_EDIT))
4834 /* Must have 'data'! */
4835 validate_dir(ANGBAND_DIR_DATA, TRUE);
4839 /* Don't need 'data' */
4840 validate_dir(ANGBAND_DIR_DATA, FALSE);
4843 validate_dir(ANGBAND_DIR_FILE, TRUE);
4844 validate_dir(ANGBAND_DIR_HELP, FALSE);
4845 validate_dir(ANGBAND_DIR_INFO, FALSE);
4846 validate_dir(ANGBAND_DIR_PREF, TRUE);
4847 validate_dir(ANGBAND_DIR_SAVE, FALSE);
4848 validate_dir(ANGBAND_DIR_USER, TRUE);
4849 validate_dir(ANGBAND_DIR_XTRA, TRUE);
4851 /* Build the filename */
4853 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
4855 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
4859 /* Hack -- Validate the "news.txt" file */
4860 validate_file(path);
4864 /* Build the "font" path */
4865 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
4867 /* Allocate the path */
4868 ANGBAND_DIR_XTRA_FONT = string_make(path);
4870 /* Validate the "font" directory */
4871 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
4873 /* Build the filename */
4874 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
4876 /* Hack -- Validate the basic font */
4877 validate_file(path);
4883 /* Build the "graf" path */
4884 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
4886 /* Allocate the path */
4887 ANGBAND_DIR_XTRA_GRAF = string_make(path);
4889 /* Validate the "graf" directory */
4890 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
4892 #endif /* USE_GRAPHICS */
4897 /* Build the "sound" path */
4898 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
4900 /* Allocate the path */
4901 ANGBAND_DIR_XTRA_SOUND = string_make(path);
4903 /* Validate the "sound" directory */
4904 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
4906 #endif /* USE_SOUND */
4910 /* Build the "music" path */
4911 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
4913 /* Allocate the path */
4914 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
4916 /* Validate the "music" directory */
4917 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
4919 #endif /* USE_MUSIC */
4921 /* Build the "help" path */
4922 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
4924 /* Allocate the path */
4925 ANGBAND_DIR_XTRA_HELP = string_make(path);
4927 /* Validate the "help" directory */
4928 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
4932 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
4933 LPSTR lpCmdLine, int nCmdShow)
4945 if (hPrevInst == NULL)
4947 wc.style = CS_CLASSDC;
4948 wc.lpfnWndProc = AngbandWndProc;
4950 wc.cbWndExtra = 4; /* one long pointer to term_data */
4951 wc.hInstance = hInst;
4952 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
4953 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
4954 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
4955 wc.lpszMenuName = AppName;
4956 wc.lpszClassName = AppName;
4958 if (!RegisterClass(&wc)) exit(1);
4960 wc.lpfnWndProc = AngbandListProc;
4961 wc.lpszMenuName = NULL;
4962 wc.lpszClassName = AngList;
4964 if (!RegisterClass(&wc)) exit(2);
4968 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
4969 wc.lpfnWndProc = AngbandSaverProc;
4971 wc.lpszMenuName = NULL;
4972 wc.lpszClassName = "WindowsScreenSaverClass";
4974 if (!RegisterClass(&wc)) exit(3);
4980 /* Temporary hooks */
4981 plog_aux = hack_plog;
4982 quit_aux = hack_quit;
4983 core_aux = hack_quit;
4985 /* Prepare the filepaths */
4988 /* Initialize the keypress analyzer */
4989 for (i = 0; special_key_list[i]; ++i)
4991 special_key[special_key_list[i]] = TRUE;
4993 /* Initialize the keypress analyzer */
4994 for (i = 0; ignore_key_list[i]; ++i)
4996 ignore_key[ignore_key_list[i]] = TRUE;
4999 /* Determine if display is 16/256/true color */
5001 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5002 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5003 ReleaseDC(NULL, hdc);
5005 /* Initialize the colors */
5006 for (i = 0; i < 256; i++)
5010 /* Extract desired values */
5011 rv = angband_color_table[i][1];
5012 gv = angband_color_table[i][2];
5013 bv = angband_color_table[i][3];
5015 /* Extract the "complex" code */
5016 win_clr[i] = PALETTERGB(rv, gv, bv);
5018 /* Save the "simple" code */
5019 angband_color_table[i][0] = win_pal[i];
5022 /* Prepare the windows */
5028 /* Activate hooks */
5029 plog_aux = hook_plog;
5030 quit_aux = hook_quit;
5031 core_aux = hook_quit;
5033 /* Set the system suffix */
5034 ANGBAND_SYS = "win";
5036 /* Set the keyboard suffix */
5037 if (7 != GetKeyboardType(0))
5038 ANGBAND_KEYBOARD = "0";
5041 /* Japanese keyboard */
5042 switch (GetKeyboardType(1))
5044 case 0x0D01: case 0x0D02:
5045 case 0x0D03: case 0x0D04:
5046 case 0x0D05: case 0x0D06:
5048 ANGBAND_KEYBOARD = "NEC98";
5052 ANGBAND_KEYBOARD = "JAPAN";
5060 /* We are now initialized */
5064 if(lpCmdLine[0] == '-'){
5065 switch(lpCmdLine[1])
5070 if (!lpCmdLine[2]) break;
5071 chuukei_server = TRUE;
5072 if(connect_chuukei_server(&lpCmdLine[2])<0){
5073 msg_print("connect fail");
5076 msg_print("connect");
5084 if (!lpCmdLine[2]) break;
5085 chuukei_client = TRUE;
5086 connect_chuukei_server(&lpCmdLine[2]);
5096 /* Did the user double click on a save file? */
5097 if(!chuukei_server) check_for_save_file(lpCmdLine);
5099 /* Did the user double click on a save file? */
5100 check_for_save_file(lpCmdLine);
5103 /* Prompt the user */
5105 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5107 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5112 /* Process messages forever */
5113 while (GetMessage(&msg, NULL, 0, 0))
5115 TranslateMessage(&msg);
5116 DispatchMessage(&msg);
5127 #endif /* WINDOWS */