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_BIZ_0 230
127 #define IDM_WINDOW_BIZ_1 231
128 #define IDM_WINDOW_BIZ_2 232
129 #define IDM_WINDOW_BIZ_3 233
130 #define IDM_WINDOW_BIZ_4 234
131 #define IDM_WINDOW_BIZ_5 235
132 #define IDM_WINDOW_BIZ_6 236
133 #define IDM_WINDOW_BIZ_7 237
135 #define IDM_WINDOW_I_WID_0 240
136 #define IDM_WINDOW_I_WID_1 241
137 #define IDM_WINDOW_I_WID_2 242
138 #define IDM_WINDOW_I_WID_3 243
139 #define IDM_WINDOW_I_WID_4 244
140 #define IDM_WINDOW_I_WID_5 245
141 #define IDM_WINDOW_I_WID_6 246
142 #define IDM_WINDOW_I_WID_7 247
144 #define IDM_WINDOW_D_WID_0 250
145 #define IDM_WINDOW_D_WID_1 251
146 #define IDM_WINDOW_D_WID_2 252
147 #define IDM_WINDOW_D_WID_3 253
148 #define IDM_WINDOW_D_WID_4 254
149 #define IDM_WINDOW_D_WID_5 255
150 #define IDM_WINDOW_D_WID_6 256
151 #define IDM_WINDOW_D_WID_7 257
153 #define IDM_WINDOW_I_HGT_0 260
154 #define IDM_WINDOW_I_HGT_1 261
155 #define IDM_WINDOW_I_HGT_2 262
156 #define IDM_WINDOW_I_HGT_3 263
157 #define IDM_WINDOW_I_HGT_4 264
158 #define IDM_WINDOW_I_HGT_5 265
159 #define IDM_WINDOW_I_HGT_6 266
160 #define IDM_WINDOW_I_HGT_7 267
162 #define IDM_WINDOW_D_HGT_0 270
163 #define IDM_WINDOW_D_HGT_1 271
164 #define IDM_WINDOW_D_HGT_2 272
165 #define IDM_WINDOW_D_HGT_3 273
166 #define IDM_WINDOW_D_HGT_4 274
167 #define IDM_WINDOW_D_HGT_5 275
168 #define IDM_WINDOW_D_HGT_6 276
169 #define IDM_WINDOW_D_HGT_7 277
171 #define IDM_OPTIONS_NO_GRAPHICS 400
172 #define IDM_OPTIONS_OLD_GRAPHICS 401
173 #define IDM_OPTIONS_NEW_GRAPHICS 402
174 #define IDM_OPTIONS_BIGTILE 409
175 #define IDM_OPTIONS_SOUND 410
176 #define IDM_OPTIONS_SAVER 420
177 #define IDM_OPTIONS_MAP 430
178 #define IDM_OPTIONS_BG 440
179 #define IDM_OPTIONS_OPEN_BG 441
181 #define IDM_DUMP_SCREEN_HTML 450
183 #define IDM_HELP_CONTENTS 901
188 * This may need to be removed for some compilers XXX XXX XXX
193 * Exclude parts of WINDOWS.H that are not needed
195 #define NOCOMM /* Comm driver APIs and definitions */
196 #define NOLOGERROR /* LogError() and related definitions */
197 #define NOPROFILER /* Profiler APIs */
198 #define NOLFILEIO /* _l* file I/O routines */
199 #define NOOPENFILE /* OpenFile and related definitions */
200 #define NORESOURCE /* Resource management */
201 #define NOATOM /* Atom management */
202 #define NOLANGUAGE /* Character test routines */
203 #define NOLSTRING /* lstr* string management routines */
204 #define NODBCS /* Double-byte character set routines */
205 #define NOKEYBOARDINFO /* Keyboard driver routines */
206 #define NOCOLOR /* COLOR_* color values */
207 #define NODRAWTEXT /* DrawText() and related definitions */
208 #define NOSCALABLEFONT /* Truetype scalable font support */
209 #define NOMETAFILE /* Metafile support */
210 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
211 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
212 #define NOKEYSTATES /* MK_* message key state flags */
213 #define NOWH /* SetWindowsHook and related WH_* definitions */
214 #define NOCLIPBOARD /* Clipboard APIs and definitions */
215 #define NOICONS /* IDI_* icon IDs */
216 #define NOMDI /* MDI support */
217 #define NOHELP /* Help support */
219 /* Not defined since it breaks Borland C++ 5.5 */
220 /* #define NOCTLMGR */ /* Control management and controls */
223 * Exclude parts of WINDOWS.H that are not needed (Win32)
225 #define WIN32_LEAN_AND_MEAN
226 #define NONLS /* All NLS defines and routines */
227 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
228 #define NOKANJI /* Kanji support stuff. */
229 #define NOMCX /* Modem Configuration Extensions */
232 * Include the "windows" support file
237 * Exclude parts of MMSYSTEM.H that are not needed
239 #define MMNODRV /* Installable driver support */
240 #define MMNOWAVE /* Waveform support */
241 #define MMNOMIDI /* MIDI support */
242 #define MMNOAUX /* Auxiliary audio support */
243 #define MMNOTIMER /* Timer support */
244 #define MMNOJOY /* Joystick support */
245 #define MMNOMCI /* MCI support */
246 #define MMNOMMIO /* Multimedia file I/O support */
247 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
250 * Include some more files. Note: the Cygnus Cygwin compiler
251 * doesn't use mmsystem.h instead it includes the winmm library
252 * which performs a similar function.
254 #include <mmsystem.h>
258 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
259 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
261 /* #define HTML_HELP */
264 #include <htmlhelp.h>
265 #endif /* HTML_HELP */
268 * Include the support for loading bitmaps
271 # include "readdib.h"
275 * Hack -- Fake declarations from "dos.h" XXX XXX XXX
278 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
280 #define FA_LABEL 0x08 /* Volume label */
281 #define FA_DIREC 0x10 /* Directory */
282 unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
286 * Silliness in WIN32 drawing routine
289 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
293 * Silliness for Windows 95
295 #ifndef WS_EX_TOOLWINDOW
296 # define WS_EX_TOOLWINDOW 0
300 * Foreground color bits (hard-coded by DOS)
302 #define VID_BLACK 0x00
303 #define VID_BLUE 0x01
304 #define VID_GREEN 0x02
305 #define VID_CYAN 0x03
307 #define VID_MAGENTA 0x05
308 #define VID_YELLOW 0x06
309 #define VID_WHITE 0x07
312 * Bright text (hard-coded by DOS)
314 #define VID_BRIGHT 0x08
317 * Background color bits (hard-coded by DOS)
319 #define VUD_BLACK 0x00
320 #define VUD_BLUE 0x10
321 #define VUD_GREEN 0x20
322 #define VUD_CYAN 0x30
324 #define VUD_MAGENTA 0x50
325 #define VUD_YELLOW 0x60
326 #define VUD_WHITE 0x70
329 * Blinking text (hard-coded by DOS)
331 #define VUD_BRIGHT 0x80
337 typedef struct _term_data term_data;
342 * Note the use of "font_want" for the names of the font file requested by
343 * the user, and the use of "font_file" for the currently active font file.
345 * The "font_file" is uppercased, and takes the form "8X13.FON", while
346 * "font_want" can be in almost any form as long as it could be construed
347 * as attempting to represent the name of a font.
362 uint rows; /* int -> uint */
411 * Maximum number of windows XXX XXX XXX
413 #define MAX_TERM_DATA 8
416 * An array of term_data's
418 static term_data data[MAX_TERM_DATA];
421 * Hack -- global "window creation" pointer
423 static term_data *my_td;
428 bool game_in_progress = FALSE;
431 * note when "open"/"new" become valid
433 bool initialized = FALSE;
436 * screen paletted, i.e. 256 colors
438 bool paletted = FALSE;
441 * 16 colors screen, don't use RGB()
443 bool colors16 = FALSE;
446 * Saved instance handle
448 static HINSTANCE hInstance;
451 * Yellow brush for the cursor
453 static HBRUSH hbrYellow;
463 static HPALETTE hPal;
466 static HBITMAP hBG = NULL;
467 static int use_bg = 0;
468 static char bg_bitmap_file[1024] = "bg.bmp";
473 * The screen saver window
475 static HWND hwndSaver;
477 #endif /* USE_SAVER */
483 * Flag set once "graphics" has been initialized
485 static bool can_use_graphics = FALSE;
490 static DIBINIT infGraph;
492 #ifdef USE_TRANSPARENCY
495 * The global bitmap mask
497 static DIBINIT infMask;
499 #endif /* USE_TRANSPARENCY */
501 #endif /* USE_GRAPHICS */
507 * Flag set once "sound" has been initialized
509 static bool can_use_sound = FALSE;
512 * An array of sound file names
514 static cptr sound_file[SOUND_MAX];
516 #endif /* USE_SOUND */
520 * Full path to ANGBAND.INI
522 static cptr ini_file = NULL;
525 * Name of application
527 static cptr AppName = "ANGBAND";
530 * Name of sub-window type
532 static cptr AngList = "AngList";
537 static cptr ANGBAND_DIR_XTRA_FONT;
538 static cptr ANGBAND_DIR_XTRA_GRAF;
539 static cptr ANGBAND_DIR_XTRA_SOUND;
540 static cptr ANGBAND_DIR_XTRA_MUSIC;
541 static cptr ANGBAND_DIR_XTRA_HELP;
545 * The "complex" color values
547 static COLORREF win_clr[256];
551 * The "simple" color values
553 * See "main-ibm.c" for original table information
555 * The entries below are taken from the "color bits" defined above.
557 * Note that many of the choices below suck, but so do crappy monitors.
559 static BYTE win_pal[256] =
561 VID_BLACK, /* Dark */
562 VID_WHITE, /* White */
563 VID_CYAN, /* Slate XXX */
564 VID_RED | VID_BRIGHT, /* Orange XXX */
566 VID_GREEN, /* Green */
568 VID_YELLOW, /* Umber XXX */
569 VID_BLACK | VID_BRIGHT, /* Light Dark */
570 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
571 VID_MAGENTA, /* Violet XXX */
572 VID_YELLOW | VID_BRIGHT, /* Yellow */
573 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
574 VID_GREEN | VID_BRIGHT, /* Light Green */
575 VID_BLUE | VID_BRIGHT, /* Light Blue */
576 VID_YELLOW /* Light Umber XXX */
581 * Hack -- define which keys are "special"
583 static bool special_key[256];
584 static bool ignore_key[256];
588 * Hack -- initialization list for "special_key"
590 static byte special_key_list[] = {
591 VK_CLEAR,VK_PAUSE,VK_CAPITAL,VK_KANA,VK_JUNJA,VK_FINAL,VK_KANJI,
592 VK_CONVERT,VK_NONCONVERT,VK_ACCEPT,VK_MODECHANGE,
593 VK_PRIOR,VK_NEXT,VK_END,VK_HOME,VK_LEFT,VK_UP,VK_RIGHT,VK_DOWN,
594 VK_SELECT,VK_PRINT,VK_EXECUTE,VK_SNAPSHOT,VK_INSERT,VK_DELETE,
596 VK_F1,VK_F2,VK_F3,VK_F4,VK_F5,VK_F6,VK_F7,VK_F8,VK_F9,VK_F10,
597 VK_F11,VK_F12,VK_F13,VK_F14,VK_F15,VK_F16,VK_F17,VK_F18,VK_F19,VK_F20,
598 VK_F21,VK_F22,VK_F23,VK_F24,VK_NUMLOCK,VK_SCROLL,
599 VK_ATTN,VK_CRSEL,VK_EXSEL,VK_EREOF,VK_PLAY,VK_ZOOM,VK_NONAME,
603 static byte ignore_key_list[] = {
604 VK_ESCAPE,VK_TAB,VK_SPACE,
605 'F','W','O','H', /* these are menu characters.*/
606 VK_SHIFT,VK_CONTROL,VK_MENU,VK_LWIN,VK_RWIN,
607 VK_LSHIFT,VK_RSHIFT,VK_LCONTROL,VK_RCONTROL,VK_LMENU,VK_RMENU,0
612 * Hack -- initialization list for "special_key"
614 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
615 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
616 * catch the keypad keys (with and without numlock set, including keypad 5),
617 * the function keys (including the "menu" key which maps to F10), and the
618 * "pause" key (between scroll lock and numlock). We also catch a few odd
619 * keys which I do not recognize, but which are listed among keys which we
620 * do catch, so they should be harmless to catch.
622 static byte special_key_list[] =
624 VK_CLEAR, /* 0x0C (KP<5>) */
626 VK_PAUSE, /* 0x13 (pause) */
628 VK_PRIOR, /* 0x21 (KP<9>) */
629 VK_NEXT, /* 0x22 (KP<3>) */
630 VK_END, /* 0x23 (KP<1>) */
631 VK_HOME, /* 0x24 (KP<7>) */
632 VK_LEFT, /* 0x25 (KP<4>) */
633 VK_UP, /* 0x26 (KP<8>) */
634 VK_RIGHT, /* 0x27 (KP<6>) */
635 VK_DOWN, /* 0x28 (KP<2>) */
636 VK_SELECT, /* 0x29 (?????) */
637 VK_PRINT, /* 0x2A (?????) */
638 VK_EXECUTE, /* 0x2B (?????) */
639 VK_SNAPSHOT, /* 0x2C (?????) */
640 VK_INSERT, /* 0x2D (KP<0>) */
641 VK_DELETE, /* 0x2E (KP<.>) */
642 VK_HELP, /* 0x2F (?????) */
645 VK_NUMPAD0, /* 0x60 (KP<0>) */
646 VK_NUMPAD1, /* 0x61 (KP<1>) */
647 VK_NUMPAD2, /* 0x62 (KP<2>) */
648 VK_NUMPAD3, /* 0x63 (KP<3>) */
649 VK_NUMPAD4, /* 0x64 (KP<4>) */
650 VK_NUMPAD5, /* 0x65 (KP<5>) */
651 VK_NUMPAD6, /* 0x66 (KP<6>) */
652 VK_NUMPAD7, /* 0x67 (KP<7>) */
653 VK_NUMPAD8, /* 0x68 (KP<8>) */
654 VK_NUMPAD9, /* 0x69 (KP<9>) */
655 VK_MULTIPLY, /* 0x6A (KP<*>) */
656 VK_ADD, /* 0x6B (KP<+>) */
657 VK_SEPARATOR, /* 0x6C (?????) */
658 VK_SUBTRACT, /* 0x6D (KP<->) */
659 VK_DECIMAL, /* 0x6E (KP<.>) */
660 VK_DIVIDE, /* 0x6F (KP</>) */
693 static void delete_bg()
704 char * bmfile = bg_bitmap_file;
707 if (use_bg == 0) return 0;
709 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
711 plog_fmt("ÊÉ»æÍÑ¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
716 HDC wnddc, dcimage, dcbg;
717 HBITMAP bmimage, bmimage_old, bmbg_old;
723 dcimage = CreateCompatibleDC(wnddc);
724 dcbg = CreateCompatibleDC(wnddc);
726 bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
727 if (!bmimage) quit("bg.bmp¤¬Æɤߤ³¤á¤Ê¤¤¡ª");
728 bmimage_old = SelectObject(dcimage, bmimage);
730 CreateCompatibleBitmap();
732 ReleaseDC(hwnd, wnddc);
738 static void DrawBG(HDC hdc, RECT *r)
743 int x = r->left, y = r->top;
744 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
750 GetObject(hBG, sizeof(bm), &bm);
751 swid = bm.bmWidth; shgt = bm.bmHeight;
753 hdcSrc = CreateCompatibleDC(hdc);
754 hOld = SelectObject(hdcSrc, hBG);
758 cwid = MIN(swid - sx, r->right - nx);
761 chgt = MIN(shgt - sy, r->bottom - ny);
762 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
764 } while (ny < r->bottom);
767 } while (nx < r->right);
769 SelectObject(hdcSrc, hOld);
774 * Hack -- given a pathname, point at the filename
776 static cptr extract_file_name(cptr s)
780 /* Start at the end */
781 p = s + strlen(s) - 1;
783 /* Back up to divider */
784 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
786 /* Return file name */
792 * Hack -- given a simple filename, extract the "font size" info
794 * Return a pointer to a static buffer holding the capitalized base name.
797 static char *analyze_font(char *path, int *wp, int *hp)
803 /* Start at the end */
804 p = path + strlen(path) - 1;
806 /* Back up to divider */
807 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
809 /* Advance to file name */
815 /* Capitalize (be paranoid) */
816 if (islower(*s)) *s = toupper(*s);
822 /* Extract font width */
826 hgt = s ? atoi(s+1) : 0;
839 * Check for existance of a file
841 static bool check_file(cptr s)
861 attrib = GetFileAttributes(path);
863 /* Require valid filename */
864 if (attrib == INVALID_FILE_NAME) return (FALSE);
866 /* Prohibit directory */
867 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
871 /* Examine and verify */
872 if (_dos_getfileattr(path, &attrib)) return (FALSE);
874 /* Prohibit something */
875 if (attrib & FA_LABEL) return (FALSE);
877 /* Prohibit directory */
878 if (attrib & FA_DIREC) return (FALSE);
888 * Check for existance of a directory
890 static bool check_dir(cptr s)
912 /* Remove trailing backslash */
913 if (i && (path[i-1] == '\\')) path[--i] = '\0';
918 attrib = GetFileAttributes(path);
920 /* Require valid filename */
921 if (attrib == INVALID_FILE_NAME) return (FALSE);
923 /* Require directory */
924 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
928 /* Examine and verify */
929 if (_dos_getfileattr(path, &attrib)) return (FALSE);
931 /* Prohibit something */
932 if (attrib & FA_LABEL) return (FALSE);
934 /* Require directory */
935 if (!(attrib & FA_DIREC)) return (FALSE);
947 static void validate_file(cptr s)
953 quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
955 quit_fmt("Cannot find required file:\n%s", s);
963 * Validate a directory
965 static void validate_dir(cptr s, bool vital)
970 /* This directory contains needed data */
974 quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
976 quit_fmt("Cannot find required directory:\n%s", s);
980 /* Attempt to create this directory */
983 quit_fmt("Unable to create directory:\n%s", s);
990 * Get the "size" for a window
992 static void term_getsize(term_data *td)
999 if (td->cols < 1) td->cols = 1;
1000 if (td->rows < 1) td->rows = 1;
1004 if (td->cols > 80) td->cols = 80;
1005 if (td->rows > 24) td->rows = 24;
1009 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1010 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1012 /* Fake window size */
1014 rc.right = rc.left + wid;
1016 rc.bottom = rc.top + hgt;
1019 /* rc.right += 1; */
1020 /* rc.bottom += 1; */
1023 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1026 td->size_wid = rc.right - rc.left;
1027 td->size_hgt = rc.bottom - rc.top;
1029 /* See CreateWindowEx */
1032 /* Extract actual location */
1033 GetWindowRect(td->w, &rc);
1035 /* Save the location */
1036 td->pos_x = rc.left;
1042 * Write the "prefs" for a single term
1044 static void save_prefs_aux(term_data *td, cptr sec_name)
1054 strcpy(buf, td->visible ? "1" : "0");
1055 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1059 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1061 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1064 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1067 wsprintf(buf, "%d", td->lf.lfWidth);
1068 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1069 wsprintf(buf, "%d", td->lf.lfHeight);
1070 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1071 wsprintf(buf, "%d", td->lf.lfWeight);
1072 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1075 strcpy(buf, td->bizarre ? "1" : "0");
1076 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1079 wsprintf(buf, "%d", td->tile_wid);
1080 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1083 wsprintf(buf, "%d", td->tile_hgt);
1084 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1086 /* Window size (x) */
1087 wsprintf(buf, "%d", td->cols);
1088 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1090 /* Window size (y) */
1091 wsprintf(buf, "%d", td->rows);
1092 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1094 /* Acquire position */
1095 GetWindowRect(td->w, &rc);
1097 /* Window position (x) */
1098 wsprintf(buf, "%d", rc.left);
1099 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1101 /* Window position (y) */
1102 wsprintf(buf, "%d", rc.top);
1103 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1110 * We assume that the windows have all been initialized
1112 static void save_prefs(void)
1118 /* Save the "arg_graphics" flag */
1119 sprintf(buf, "%d", arg_graphics);
1120 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1122 /* Save the "arg_bigtile" flag */
1123 strcpy(buf, arg_bigtile ? "1" : "0");
1124 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1126 /* Save the "arg_sound" flag */
1127 strcpy(buf, arg_sound ? "1" : "0");
1128 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1131 strcpy(buf, use_bg ? "1" : "0");
1132 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1133 WritePrivateProfileString("Angband", "BackGroundBitmap",
1134 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1136 /* Save window prefs */
1137 for (i = 0; i < MAX_TERM_DATA; ++i)
1139 term_data *td = &data[i];
1141 sprintf(buf, "Term-%d", i);
1143 save_prefs_aux(td, buf);
1149 * Load the "prefs" for a single term
1151 static void load_prefs_aux(term_data *td, cptr sec_name)
1158 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1160 /* Desired font, with default */
1162 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1164 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1169 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1171 /* Analyze font, save desired font name */
1173 td->font_want = string_make(tmp);
1175 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1176 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1177 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1179 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1185 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1186 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1188 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1189 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1194 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1195 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1197 /* Window position */
1198 td->pos_x = GetPrivateProfileInt(sec_name, "PositionX", td->pos_x, ini_file);
1199 td->pos_y = GetPrivateProfileInt(sec_name, "PositionY", td->pos_y, ini_file);
1206 static void load_prefs(void)
1212 /* Extract the "arg_graphics" flag */
1213 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1215 /* Extract the "arg_bigtile" flag */
1216 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1217 use_bigtile = arg_bigtile;
1219 /* Extract the "arg_sound" flag */
1220 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1223 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1224 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1226 /* Load window prefs */
1227 for (i = 0; i < MAX_TERM_DATA; ++i)
1229 term_data *td = &data[i];
1231 sprintf(buf, "Term-%d", i);
1233 load_prefs_aux(td, buf);
1239 * Create the new global palette based on the bitmap palette
1240 * (if any), and the standard 16 entry palette derived from
1241 * "win_clr[]" which is used for the basic 16 Angband colors.
1243 * This function is never called before all windows are ready.
1245 * This function returns FALSE if the new palette could not be
1246 * prepared, which should normally be a fatal error. XXX XXX
1248 * Note that only some machines actually use a "palette".
1250 static int new_palette(void)
1258 LPLOGPALETTE pLogPal;
1259 LPPALETTEENTRY lppe;
1264 /* This makes no sense */
1265 if (!paletted) return (TRUE);
1275 /* Check the bitmap palette */
1276 hBmPal = infGraph.hPalette;
1278 /* Use the bitmap */
1281 lppeSize = 256 * sizeof(PALETTEENTRY);
1282 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1283 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1284 if ((nEntries == 0) || (nEntries > 220))
1288 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1290 plog("Please switch to high- or true-color mode.");
1295 rnfree(lppe, lppeSize);
1302 #endif /* USE_GRAPHICS */
1304 /* Size of palette */
1305 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1307 /* Allocate palette */
1308 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1311 pLogPal->palVersion = 0x300;
1313 /* Make room for bitmap and normal data */
1314 pLogPal->palNumEntries = nEntries + 16;
1316 /* Save the bitmap data */
1317 for (i = 0; i < nEntries; i++)
1319 pLogPal->palPalEntry[i] = lppe[i];
1322 /* Save the normal data */
1323 for (i = 0; i < 16; i++)
1327 /* Access the entry */
1328 p = &(pLogPal->palPalEntry[i+nEntries]);
1330 /* Save the colors */
1331 p->peRed = GetRValue(win_clr[i]);
1332 p->peGreen = GetGValue(win_clr[i]);
1333 p->peBlue = GetBValue(win_clr[i]);
1335 /* Save the flags */
1336 p->peFlags = PC_NOCOLLAPSE;
1339 /* Free something */
1340 if (lppe) rnfree(lppe, lppeSize);
1342 /* Create a new palette, or fail */
1343 hNewPal = CreatePalette(pLogPal);
1345 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1347 if (!hNewPal) quit("Cannot create palette!");
1351 /* Free the palette */
1352 rnfree(pLogPal, pLogPalSize);
1357 /* Realize the palette */
1359 SelectPalette(hdc, hNewPal, 0);
1360 i = RealizePalette(hdc);
1361 ReleaseDC(td->w, hdc);
1363 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1365 if (i == 0) quit("Cannot realize palette!");
1370 for (i = 1; i < MAX_TERM_DATA; i++)
1375 SelectPalette(hdc, hNewPal, 0);
1376 ReleaseDC(td->w, hdc);
1379 /* Delete old palette */
1380 if (hPal) DeleteObject(hPal);
1382 /* Save new palette */
1392 * Initialize graphics
1394 static bool init_graphics(void)
1396 /* Initialize once */
1397 /* if (can_use_graphics != arg_graphics) */
1403 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1410 ANGBAND_GRAF = "new";
1418 ANGBAND_GRAF = "old";
1421 /* Access the bitmap file */
1422 path_build(buf, 1024, ANGBAND_DIR_XTRA_GRAF, name);
1424 /* Load the bitmap or quit */
1425 if (!ReadDIB(data[0].w, buf, &infGraph))
1428 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1430 plog_fmt("Cannot read bitmap file '%s'", name);
1436 /* Save the new sizes */
1437 infGraph.CellWidth = wid;
1438 infGraph.CellHeight = hgt;
1440 #ifdef USE_TRANSPARENCY
1442 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1444 /* Access the mask file */
1445 path_build(buf, 1024, ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1447 /* Load the bitmap or quit */
1448 if (!ReadDIB(data[0].w, buf, &infMask))
1450 plog_fmt("Cannot read bitmap file '%s'", buf);
1455 #endif /* USE_TRANSPARENCY */
1457 /* Activate a palette */
1460 /* Free bitmap XXX XXX XXX */
1464 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1466 plog("Cannot activate palette!");
1472 /* Graphics available */
1473 can_use_graphics = arg_graphics;
1477 return (can_use_graphics);
1479 #endif /* USE_GRAPHICS */
1486 static bool init_sound(void)
1488 /* Initialize once */
1496 /* Prepare the sounds */
1497 for (i = 1; i < SOUND_MAX; i++)
1499 /* Extract name of sound file */
1500 sprintf(wav, "%s.wav", angband_sound_name[i]);
1502 /* Access the sound */
1503 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, wav);
1505 /* Save the sound filename, if it exists */
1506 if (check_file(buf)) sound_file[i] = string_make(buf);
1509 /* Sound available */
1510 can_use_sound = TRUE;
1514 return (can_use_sound);
1516 #endif /* USE_SOUND */
1522 static void term_window_resize(term_data *td)
1524 /* Require window */
1527 /* Resize the window */
1528 SetWindowPos(td->w, 0, 0, 0,
1529 td->size_wid, td->size_hgt,
1530 SWP_NOMOVE | SWP_NOZORDER);
1533 InvalidateRect(td->w, NULL, TRUE);
1538 * Force the use of a new "font file" for a term_data
1540 * This function may be called before the "window" is ready
1542 * This function returns zero only if everything succeeds.
1544 * Note that the "font name" must be capitalized!!!
1546 static errr term_force_font(term_data *td, cptr path)
1556 /* Forget the old font (if needed) */
1557 if (td->font_id) DeleteObject(td->font_id);
1560 /* Forget old font */
1566 for (i = 0; i < MAX_TERM_DATA; i++)
1568 /* Don't check when closing the application */
1571 /* Check "screen" */
1572 if ((td != &data[i]) &&
1573 (data[i].font_file) &&
1574 (streq(data[i].font_file, td->font_file)))
1580 /* Remove unused font resources */
1581 if (!used) RemoveFontResource(td->font_file);
1583 /* Free the old name */
1584 string_free(td->font_file);
1587 td->font_file = NULL;
1592 if (!path) return (1);
1598 /* Analyze font path */
1599 base = analyze_font(buf, &wid, &hgt);
1602 if (!suffix(base, ".FON")) return (1);
1605 if (!check_file(buf)) return (1);
1607 /* Load the new font */
1608 if (!AddFontResource(buf)) return (1);
1610 /* Save new font name */
1611 td->font_file = string_make(base);
1613 /* Remove the "suffix" */
1614 base[strlen(base)-4] = '\0';
1617 /* Create the font (using the 'base' of the font file name!) */
1619 td->font_id = CreateFontIndirect(&(td->lf));
1620 wid = td->lf.lfWidth;
1621 hgt = td->lf.lfHeight;
1622 if (!td->font_id) return (1);
1624 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1625 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1626 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1627 FIXED_PITCH | FF_DONTCARE, base);
1631 /* Hack -- Unknown size */
1638 /* all this trouble to get the cell size */
1639 hdcDesktop = GetDC(HWND_DESKTOP);
1640 hfOld = SelectObject(hdcDesktop, td->font_id);
1641 GetTextMetrics(hdcDesktop, &tm);
1642 SelectObject(hdcDesktop, hfOld);
1643 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1645 /* Font size info */
1646 wid = tm.tmAveCharWidth;
1650 /* Save the size info */
1661 * Allow the user to change the font for this window.
1663 static void term_change_font(term_data *td)
1668 memset(&cf, 0, sizeof(cf));
1669 cf.lStructSize = sizeof(cf);
1670 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1671 cf.lpLogFont = &(td->lf);
1673 if (ChooseFont(&cf))
1675 /* Force the font */
1676 term_force_font(td, NULL);
1678 /* Assume not bizarre */
1681 /* Reset the tile info */
1682 td->tile_wid = td->font_wid;
1683 td->tile_hgt = td->font_hgt;
1685 /* Analyze the font */
1688 /* Resize the window */
1689 term_window_resize(td);
1695 char tmp[1024] = "";
1697 /* Extract a default if possible */
1698 if (td->font_file) strcpy(tmp, td->font_file);
1700 /* Ask for a choice */
1701 memset(&ofn, 0, sizeof(ofn));
1702 ofn.lStructSize = sizeof(ofn);
1703 ofn.hwndOwner = data[0].w;
1704 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1705 ofn.nFilterIndex = 1;
1706 ofn.lpstrFile = tmp;
1708 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1709 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1710 ofn.lpstrDefExt = "fon";
1712 /* Force choice if legal */
1713 if (GetOpenFileName(&ofn))
1715 /* Force the font */
1716 if (term_force_font(td, tmp))
1718 /* Access the standard font file */
1719 path_build(tmp, 1024, ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1721 /* Force the use of that font */
1722 (void)term_force_font(td, tmp);
1725 /* Assume not bizarre */
1726 td->bizarre = FALSE;
1728 /* Reset the tile info */
1729 td->tile_wid = td->font_wid;
1730 td->tile_hgt = td->font_hgt;
1732 /* Analyze the font */
1735 /* Resize the window */
1736 term_window_resize(td);
1744 static void windows_map(void);
1747 * Hack -- redraw a term_data
1749 static void term_data_redraw(term_data *td)
1753 /* Redraw the map */
1758 /* Activate the term */
1759 Term_activate(&td->t);
1761 /* Redraw the contents */
1764 /* Restore the term */
1765 Term_activate(term_screen);
1773 /*** Function hooks needed by "Term" ***/
1779 * Initialize a new Term
1781 static void Term_init_win(term *t)
1790 static void Term_nuke_win(term *t)
1799 * Interact with the User
1801 static errr Term_user_win(int n)
1809 * React to global changes
1811 static errr Term_xtra_win_react(void)
1819 /* Save the default colors */
1820 for (i = 0; i < 256; i++)
1822 /* Simply accept the desired colors */
1823 win_pal[i] = angband_color_table[i][0];
1834 bool change = FALSE;
1836 /* Save the default colors */
1837 for (i = 0; i < 256; i++)
1839 /* Extract desired values */
1840 rv = angband_color_table[i][1];
1841 gv = angband_color_table[i][2];
1842 bv = angband_color_table[i][3];
1844 /* Extract a full color code */
1845 code = PALETTERGB(rv, gv, bv);
1847 /* Activate changes */
1848 if (win_clr[i] != code)
1850 /* Note the change */
1853 /* Apply the desired color */
1858 /* Activate the palette if needed */
1859 if (change) (void)new_palette();
1865 /* Handle "arg_sound" */
1866 if (use_sound != arg_sound)
1868 /* Initialize (if needed) */
1869 if (arg_sound && !init_sound())
1873 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
1875 plog("Cannot initialize sound!");
1883 /* Change setting */
1884 use_sound = arg_sound;
1892 /* Handle "arg_graphics" */
1893 if (use_graphics != arg_graphics)
1895 /* Initialize (if needed) */
1896 if (arg_graphics && !init_graphics())
1900 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
1902 plog("Cannot initialize graphics!");
1907 arg_graphics = GRAPHICS_NONE;
1910 /* Change setting */
1911 use_graphics = arg_graphics;
1914 #ifdef ANGBAND_2_8_1
1916 #else /* ANGBAND_2_8_1 */
1917 reset_visuals(TRUE);
1918 #endif /* ANGBAND_2_8_1 */
1921 #endif /* USE_GRAPHICS */
1924 /* Clean up windows */
1925 for (i = 0; i < MAX_TERM_DATA; i++)
1929 term_data *td = &data[i];
1931 /* Update resized windows */
1932 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
1935 Term_activate(&td->t);
1937 /* Hack -- Resize the term */
1938 Term_resize(td->cols, td->rows);
1940 /* Redraw the contents */
1955 * Process at least one event
1957 static errr Term_xtra_win_event(int v)
1961 /* Wait for an event */
1965 if (GetMessage(&msg, NULL, 0, 0))
1967 TranslateMessage(&msg);
1968 DispatchMessage(&msg);
1972 /* Check for an event */
1976 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1978 TranslateMessage(&msg);
1979 DispatchMessage(&msg);
1989 * Process all pending events
1991 static errr Term_xtra_win_flush(void)
1995 /* Process all pending events */
1996 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1998 TranslateMessage(&msg);
1999 DispatchMessage(&msg);
2008 * Hack -- clear the screen
2010 * Make this more efficient XXX XXX XXX
2012 static errr Term_xtra_win_clear(void)
2014 term_data *td = (term_data*)(Term->data);
2019 /* Rectangle to erase */
2020 rc.left = td->size_ow1;
2021 rc.right = rc.left + td->cols * td->tile_wid;
2022 rc.top = td->size_oh1;
2023 rc.bottom = rc.top + td->rows * td->tile_hgt;
2027 SetBkColor(hdc, RGB(0, 0, 0));
2028 SelectObject(hdc, td->font_id);
2029 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2034 rc.left = 0; rc.top = 0;
2037 ReleaseDC(td->w, hdc);
2045 * Hack -- make a noise
2047 static errr Term_xtra_win_noise(void)
2049 MessageBeep(MB_ICONASTERISK);
2055 * Hack -- make a sound
2057 static errr Term_xtra_win_sound(int v)
2059 /* Sound disabled */
2060 if (!use_sound) return (1);
2063 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2068 if (!sound_file[v]) return (1);
2072 /* Play the sound, catch errors */
2073 return (PlaySound(sound_file[v], 0, SND_FILENAME | SND_ASYNC));
2077 /* Play the sound, catch errors */
2078 return (sndPlaySound(sound_file[v], SND_ASYNC));
2082 #else /* USE_SOUND */
2087 #endif /* USE_SOUND */
2092 * Delay for "x" milliseconds
2094 static int Term_xtra_win_delay(int v)
2108 t = GetTickCount() + v;
2111 while (GetTickCount() < t)
2113 /* Handle messages */
2114 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2116 TranslateMessage(&msg);
2117 DispatchMessage(&msg);
2129 * Do a "special thing"
2131 static errr Term_xtra_win(int n, int v)
2133 /* Handle a subset of the legal requests */
2136 /* Make a bell sound */
2137 case TERM_XTRA_NOISE:
2139 return (Term_xtra_win_noise());
2142 /* Make a special sound */
2143 case TERM_XTRA_SOUND:
2145 return (Term_xtra_win_sound(v));
2148 /* Process random events */
2149 case TERM_XTRA_BORED:
2151 return (Term_xtra_win_event(0));
2154 /* Process an event */
2155 case TERM_XTRA_EVENT:
2157 return (Term_xtra_win_event(v));
2160 /* Flush all events */
2161 case TERM_XTRA_FLUSH:
2163 return (Term_xtra_win_flush());
2166 /* Clear the screen */
2167 case TERM_XTRA_CLEAR:
2169 return (Term_xtra_win_clear());
2172 /* React to global changes */
2173 case TERM_XTRA_REACT:
2175 return (Term_xtra_win_react());
2178 /* Delay for some milliseconds */
2179 case TERM_XTRA_DELAY:
2181 return (Term_xtra_win_delay(v));
2192 * Low level graphics (Assumes valid input).
2194 * Draw a "cursor" at (x,y), using a "yellow box".
2196 static errr Term_curs_win(int x, int y)
2198 term_data *td = (term_data*)(Term->data);
2203 int tile_wid, tile_hgt;
2207 tile_wid = td->map_tile_wid;
2208 tile_hgt = td->map_tile_hgt;
2212 tile_wid = td->tile_wid;
2213 tile_hgt = td->tile_hgt;
2216 /* Frame the grid */
2217 rc.left = x * tile_wid + td->size_ow1;
2218 rc.right = rc.left + tile_wid;
2219 rc.top = y * tile_hgt + td->size_oh1;
2220 rc.bottom = rc.top + tile_hgt;
2223 if (x + 1 < Term->wid &&
2224 ((use_bigtile && Term->old->a[y][x+1] == 255)
2225 || (iskanji(Term->old->c[y][x]) && !(Term->old->a[y][x] & 0x80))))
2227 if (use_bigtile && x + 1 < Term->wid && Term->old->a[y][x+1] == 255)
2229 rc.right += tile_wid;
2231 /* Cursor is done as a yellow "box" */
2233 FrameRect(hdc, &rc, hbrYellow);
2234 ReleaseDC(td->w, hdc);
2242 * Low level graphics (Assumes valid input).
2244 * Erase a "block" of "n" characters starting at (x,y).
2246 static errr Term_wipe_win(int x, int y, int n)
2248 term_data *td = (term_data*)(Term->data);
2253 /* Rectangle to erase in client coords */
2254 rc.left = x * td->tile_wid + td->size_ow1;
2255 rc.right = rc.left + n * td->tile_wid;
2256 rc.top = y * td->tile_hgt + td->size_oh1;
2257 rc.bottom = rc.top + td->tile_hgt;
2260 SetBkColor(hdc, RGB(0, 0, 0));
2261 SelectObject(hdc, td->font_id);
2266 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2267 ReleaseDC(td->w, hdc);
2275 * Low level graphics. Assumes valid input.
2277 * Draw several ("n") chars, with an attr, at a given location.
2279 * All "graphic" data is handled by "Term_pict_win()", below.
2281 * One would think there is a more efficient method for telling a window
2282 * what color it should be using to draw with, but perhaps simply changing
2283 * it every time is not too inefficient. XXX XXX XXX
2285 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2287 term_data *td = (term_data*)(Term->data);
2293 static HBITMAP WALL;
2294 static HBRUSH myBrush, oldBrush;
2296 static bool init_done = FALSE;
2299 WALL = LoadBitmap(hInstance, AppName);
2300 myBrush = CreatePatternBrush(WALL);
2305 /* Total rectangle */
2306 rc.left = x * td->tile_wid + td->size_ow1;
2307 rc.right = rc.left + n * td->tile_wid;
2308 rc.top = y * td->tile_hgt + td->size_oh1;
2309 rc.bottom = rc.top + td->tile_hgt;
2314 /* Background color */
2315 SetBkColor(hdc, RGB(0, 0, 0));
2317 /* Foreground color */
2320 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2324 SetTextColor(hdc, win_clr[a&0x0F]);
2328 SetTextColor(hdc, win_clr[a]);
2332 SelectObject(hdc, td->font_id);
2335 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2339 (td->tile_hgt != td->font_hgt) ||
2340 (td->tile_wid != td->font_wid))
2344 /* Erase complete rectangle */
2345 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2348 if (use_bg) DrawBG(hdc, &rc);
2351 rc.left += ((td->tile_wid - td->font_wid) / 2);
2352 rc.right = rc.left + td->font_wid;
2353 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2354 rc.bottom = rc.top + td->font_hgt;
2356 /* Dump each character */
2357 for (i = 0; i < n; i++)
2360 if (use_bigtile && *(s+i)=="¢ò"[0] && *(s+i+1)=="¢ò"[1])
2362 rc.right += td->font_wid;
2364 oldBrush = SelectObject(hdc, myBrush);
2365 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2368 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2370 SelectObject(hdc, oldBrush);
2371 SelectObject(hdc, oldPen);
2372 rc.right -= td->font_wid;
2376 rc.left += 2 * td->tile_wid;
2377 rc.right += 2 * td->tile_wid;
2379 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2381 rc.right += td->font_wid;
2383 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2385 rc.right -= td->font_wid;
2389 rc.left += 2 * td->tile_wid;
2390 rc.right += 2 * td->tile_wid;
2391 } else if (*(s+i)==127){
2392 oldBrush = SelectObject(hdc, myBrush);
2393 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2396 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2398 SelectObject(hdc, oldBrush);
2399 SelectObject(hdc, oldPen);
2402 rc.left += td->tile_wid;
2403 rc.right += td->tile_wid;
2406 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2410 rc.left += td->tile_wid;
2411 rc.right += td->tile_wid;
2415 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2419 rc.left += td->tile_wid;
2420 rc.right += td->tile_wid;
2430 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2435 ReleaseDC(td->w, hdc);
2443 * Low level graphics. Assumes valid input.
2445 * Draw an array of "special" attr/char pairs at the given location.
2447 * We use the "Term_pict_win()" function for "graphic" data, which are
2448 * encoded by setting the "high-bits" of both the "attr" and the "char"
2449 * data. We use the "attr" to represent the "row" of the main bitmap,
2450 * and the "char" to represent the "col" of the main bitmap. The use
2451 * of this function is induced by the "higher_pict" flag.
2453 * If "graphics" is not available, we simply "wipe" the given grids.
2455 # ifdef USE_TRANSPARENCY
2456 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2457 # else /* USE_TRANSPARENCY */
2458 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp)
2459 # endif /* USE_TRANSPARENCY */
2461 term_data *td = (term_data*)(Term->data);
2467 int x2, y2, w2, h2, tw2;
2469 # ifdef USE_TRANSPARENCY
2475 # endif /* USE_TRANSPARENCY */
2484 /* Erase the grids */
2485 return (Term_wipe_win(x, y, n));
2488 /* Size of bitmap cell */
2489 w1 = infGraph.CellWidth;
2490 h1 = infGraph.CellHeight;
2492 /* Size of window cell */
2495 w2 = td->map_tile_wid;
2496 h2 = td->map_tile_hgt;
2505 if (use_bigtile) tw2 *= 2;
2508 /* Location of window cell */
2509 x2 = x * w2 + td->size_ow1;
2510 y2 = y * h2 + td->size_oh1;
2516 hdcSrc = CreateCompatibleDC(hdc);
2517 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2519 # ifdef USE_TRANSPARENCY
2521 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2523 hdcMask = CreateCompatibleDC(hdc);
2524 SelectObject(hdcMask, infMask.hBitmap);
2527 # endif /* USE_TRANSPARENCY */
2529 /* Draw attr/char pairs */
2530 for (i = 0; i < n; i++, x2 += w2)
2535 /* Extract picture */
2536 int row = (a & 0x7F);
2537 int col = (c & 0x7F);
2539 /* Location of bitmap cell */
2543 # ifdef USE_TRANSPARENCY
2545 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2547 x3 = (tcp[i] & 0x7F) * w1;
2548 y3 = (tap[i] & 0x7F) * h1;
2551 if ((w1 == tw2) && (h1 == h2))
2553 /* Copy the terrain picture from the bitmap to the window */
2554 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2556 /* Mask out the tile */
2557 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2560 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2563 /* Need to stretch */
2566 /* Set the correct mode for stretching the tiles */
2567 SetStretchBltMode(hdc, COLORONCOLOR);
2569 /* Copy the terrain picture from the bitmap to the window */
2570 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
2572 /* Only draw if terrain and overlay are different */
2573 if ((x1 != x3) || (y1 != y3))
2575 /* Mask out the tile */
2576 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2579 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2585 # endif /* USE_TRANSPARENCY */
2589 if ((w1 == tw2) && (h1 == h2))
2591 /* Copy the picture from the bitmap to the window */
2592 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2595 /* Need to stretch */
2598 /* Set the correct mode for stretching the tiles */
2599 SetStretchBltMode(hdc, COLORONCOLOR);
2601 /* Copy the picture from the bitmap to the window */
2602 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2608 SelectObject(hdcSrc, hbmSrcOld);
2611 # ifdef USE_TRANSPARENCY
2613 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2616 SelectObject(hdcMask, hbmSrcOld);
2620 # endif /* USE_TRANSPARENCY */
2623 ReleaseDC(td->w, hdc);
2625 #else /* USE_GRAPHICS */
2627 /* Just erase this grid */
2628 return (Term_wipe_win(x, y, n));
2630 #endif /* USE_GRAPHICS */
2637 #ifdef USE_TRANSPARENCY
2638 extern void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp);
2639 #else /* USE_TRANSPARENCY */
2640 extern void map_info(int y, int x, byte *ap, char *cp);
2641 #endif /* USE_TRANSPARENCY */
2644 static void windows_map(void)
2646 term_data *td = &data[0];
2648 int x, min_x, max_x;
2649 int y, min_y, max_y;
2651 #ifdef USE_TRANSPARENCY
2655 /* Only in graphics mode */
2656 if (!use_graphics) return;
2659 Term_xtra_win_clear();
2661 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2662 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2663 td->map_active = TRUE;
2673 for (x = min_x; x < max_x; x++)
2675 for (y = min_y; y < max_y; y++)
2677 #ifdef USE_TRANSPARENCY
2678 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
2679 #else /* USE_TRANSPARENCY */
2680 map_info(y, x, &a, (char*)&c);
2681 #endif /* USE_TRANSPARENCY */
2683 /* Ignore non-graphics */
2684 if ((a & 0x80) && (c & 0x80))
2686 #ifdef USE_TRANSPARENCY
2687 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2688 #else /* USE_TRANSPARENCY */
2689 Term_pict_win(x - min_x, y - min_y, 1, &a, &c);
2690 #endif /* USE_TRANSPARENCY */
2695 /* Hilite the player */
2696 Term_curs_win(px - min_x, py - min_y);
2698 /* Wait for a keypress, flush key buffer */
2699 Term_inkey(&c, TRUE, TRUE);
2702 /* Switch off the map display */
2703 td->map_active = FALSE;
2705 /* Restore screen */
2706 Term_xtra_win_clear();
2711 /*** Other routines ***/
2715 * Create and initialize a "term_data" given a title
2717 static void term_data_link(term_data *td)
2721 /* Initialize the term */
2722 term_init(t, td->cols, td->rows, td->keys);
2724 /* Use a "software" cursor */
2725 t->soft_cursor = TRUE;
2727 /* Use "Term_pict" for "graphic" data */
2728 t->higher_pict = TRUE;
2730 /* Erase with "white space" */
2731 t->attr_blank = TERM_WHITE;
2732 t->char_blank = ' ';
2735 /* Prepare the init/nuke hooks */
2736 t->init_hook = Term_init_win;
2737 t->nuke_hook = Term_nuke_win;
2740 /* Prepare the template hooks */
2741 t->user_hook = Term_user_win;
2742 t->xtra_hook = Term_xtra_win;
2743 t->curs_hook = Term_curs_win;
2744 t->wipe_hook = Term_wipe_win;
2745 t->text_hook = Term_text_win;
2746 t->pict_hook = Term_pict_win;
2748 /* Remember where we came from */
2749 t->data = (vptr)(td);
2754 * Create the windows
2756 * First, instantiate the "default" values, then read the "ini_file"
2757 * to over-ride selected values, then create the windows, and fonts.
2759 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2760 * must make active to realize the palette. XXX XXX XXX
2762 static void init_windows(void)
2774 WIPE(td, term_data);
2778 td->s = angband_term_name[0];
2796 for (i = 1; i < MAX_TERM_DATA; i++)
2799 WIPE(td, term_data);
2800 td->s = angband_term_name[i];
2804 td->visible = FALSE;
2809 td->pos_x = (7 - i) * 30;
2810 td->pos_y = (7 - i) * 20;
2821 /* Main window (need these before term_getsize gets called) */
2823 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2824 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2829 /* Sub windows (need these before term_getsize gets called) */
2830 for (i = 1; i < MAX_TERM_DATA; i++)
2833 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2834 td->dwExStyle = (WS_EX_TOOLWINDOW);
2839 for (i = 0; i < MAX_TERM_DATA; i++)
2844 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2845 td->lf.lfHeight = td->tile_hgt;
2846 td->lf.lfWidth = td->tile_wid;
2847 td->lf.lfCharSet = SHIFTJIS_CHARSET;
2848 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2849 /* Activate the chosen font */
2850 term_force_font(td, NULL);
2851 td->tile_wid = td->font_wid;
2852 td->tile_hgt = td->font_hgt;
2854 /* Access the standard font file */
2855 path_build(buf, 1024, ANGBAND_DIR_XTRA_FONT, td->font_want);
2857 /* Activate the chosen font */
2858 if (term_force_font(td, buf))
2860 /* Access the standard font file */
2861 path_build(buf, 1024, ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2863 /* Force the use of that font */
2864 (void)term_force_font(td, buf);
2870 /* Assume not bizarre */
2871 td->bizarre = FALSE;
2876 /* Analyze the font */
2879 /* Resize the window */
2880 term_window_resize(td);
2884 /* Sub windows (reverse order) */
2885 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
2890 td->w = CreateWindowEx(td->dwExStyle, AngList,
2892 td->pos_x, td->pos_y,
2893 td->size_wid, td->size_hgt,
2894 HWND_DESKTOP, NULL, hInstance, NULL);
2897 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
2899 if (!td->w) quit("Failed to create sub-window");
2905 td->size_hack = TRUE;
2906 ShowWindow(td->w, SW_SHOW);
2907 td->size_hack = FALSE;
2911 angband_term[i] = &td->t;
2915 /* Activate the window */
2916 SetActiveWindow(td->w);
2918 /* Bring window to top */
2919 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2929 td->w = CreateWindowEx(td->dwExStyle, AppName,
2931 td->pos_x, td->pos_y,
2932 td->size_wid, td->size_hgt,
2933 HWND_DESKTOP, NULL, hInstance, NULL);
2936 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
2938 if (!td->w) quit("Failed to create Angband window");
2943 angband_term[0] = &td->t;
2945 /* Activate the main window */
2946 SetActiveWindow(td->w);
2948 /* Bring main window back to top */
2949 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2952 /* New palette XXX XXX XXX */
2953 (void)new_palette();
2956 /* Create a "brush" for drawing the "cursor" */
2957 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
2960 /* Process pending messages */
2961 (void)Term_xtra_win_flush();
2969 static void setup_menus(void)
2973 HMENU hm = GetMenu(data[0].w);
2976 /* Menu "File", Disable all */
2977 EnableMenuItem(hm, IDM_FILE_NEW,
2978 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2979 EnableMenuItem(hm, IDM_FILE_OPEN,
2980 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2981 EnableMenuItem(hm, IDM_FILE_SAVE,
2982 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2983 EnableMenuItem(hm, IDM_FILE_EXIT,
2984 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2985 EnableMenuItem(hm, IDM_FILE_SCORE,
2986 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2989 /* No character available */
2990 if (!character_generated)
2992 /* Menu "File", Item "New" */
2993 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
2995 /* Menu "File", Item "Open" */
2996 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
2999 /* A character available */
3000 if (character_generated)
3002 /* Menu "File", Item "Save" */
3003 EnableMenuItem(hm, IDM_FILE_SAVE,
3004 MF_BYCOMMAND | MF_ENABLED);
3007 /* Menu "File", Item "Exit" */
3008 EnableMenuItem(hm, IDM_FILE_EXIT,
3009 MF_BYCOMMAND | MF_ENABLED);
3011 EnableMenuItem(hm, IDM_FILE_SCORE,
3012 MF_BYCOMMAND | MF_ENABLED);
3015 /* Menu "Window::Visibility" */
3016 for (i = 0; i < MAX_TERM_DATA; i++)
3018 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3019 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3021 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3022 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3024 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3025 MF_BYCOMMAND | MF_ENABLED);
3028 /* Menu "Window::Font" */
3029 for (i = 0; i < MAX_TERM_DATA; i++)
3031 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3032 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3034 if (data[i].visible)
3036 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3037 MF_BYCOMMAND | MF_ENABLED);
3041 /* Menu "Window::Bizarre Display" */
3042 for (i = 0; i < MAX_TERM_DATA; i++)
3044 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3045 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3047 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3048 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3050 if (data[i].visible)
3052 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3053 MF_BYCOMMAND | MF_ENABLED);
3058 /* Menu "Window::Increase Tile Width" */
3059 for (i = 0; i < MAX_TERM_DATA; i++)
3061 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3062 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3064 if (data[i].visible)
3066 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3067 MF_BYCOMMAND | MF_ENABLED);
3072 /* Menu "Window::Decrease Tile Width" */
3073 for (i = 0; i < MAX_TERM_DATA; i++)
3075 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3076 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3078 if (data[i].visible)
3080 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3081 MF_BYCOMMAND | MF_ENABLED);
3086 /* Menu "Window::Increase Tile Height" */
3087 for (i = 0; i < MAX_TERM_DATA; i++)
3089 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3090 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3092 if (data[i].visible)
3094 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3095 MF_BYCOMMAND | MF_ENABLED);
3100 /* Menu "Window::Decrease Tile Height" */
3101 for (i = 0; i < MAX_TERM_DATA; i++)
3103 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3104 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3106 if (data[i].visible)
3108 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3109 MF_BYCOMMAND | MF_ENABLED);
3114 /* Menu "Options", disable all */
3115 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3116 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3117 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3118 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3119 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3120 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3121 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3122 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3123 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3124 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3126 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3127 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3130 /* Menu "Options", Item "Map" */
3131 if (use_graphics != GRAPHICS_NONE)
3132 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3134 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3135 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3137 /* Menu "Options", update all */
3138 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3139 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3140 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3141 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3142 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3143 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3144 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3145 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3146 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3147 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3148 CheckMenuItem(hm, IDM_OPTIONS_BG,
3149 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3151 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3152 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3156 /* Menu "Options", Item "Graphics" */
3157 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3158 /* Menu "Options", Item "Graphics" */
3159 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3160 /* Menu "Options", Item "Graphics" */
3161 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3162 /* Menu "Options", Item "Graphics" */
3163 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3164 #endif /* USE_GRAPHICS */
3167 /* Menu "Options", Item "Sound" */
3168 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3169 #endif /* USE_SOUND */
3172 /* Menu "Options", Item "ScreenSaver" */
3173 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3174 MF_BYCOMMAND | MF_ENABLED);
3175 #endif /* USE_SAVER */
3180 * Check for double clicked (or dragged) savefile
3182 * Apparently, Windows copies the entire filename into the first
3183 * piece of the "command line string". Perhaps we should extract
3184 * the "basename" of that filename and append it to the "save" dir.
3186 static void check_for_save_file(LPSTR cmd_line)
3196 /* Extract filename */
3197 strcat(savefile, s);
3199 /* Validate the file */
3200 validate_file(savefile);
3202 /* Game in progress */
3203 game_in_progress = TRUE;
3211 * Process a menu command
3213 static void process_menus(WORD wCmd)
3230 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3232 plog("You cannot do that yet...");
3236 else if (game_in_progress)
3239 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3241 plog("You can't start a new game while you're still playing!");
3247 game_in_progress = TRUE;
3261 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3263 plog("You cannot do that yet...");
3267 else if (game_in_progress)
3270 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3272 plog("You can't open a new game while you're still playing!");
3278 memset(&ofn, 0, sizeof(ofn));
3279 ofn.lStructSize = sizeof(ofn);
3280 ofn.hwndOwner = data[0].w;
3281 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3282 ofn.nFilterIndex = 1;
3283 ofn.lpstrFile = savefile;
3284 ofn.nMaxFile = 1024;
3285 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3286 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3288 if (GetOpenFileName(&ofn))
3290 /* Load 'savefile' */
3291 validate_file(savefile);
3292 game_in_progress = TRUE;
3304 if (game_in_progress && character_generated)
3310 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3312 plog("You may not do that right now.");
3318 /* Hack -- Forget messages */
3323 do_cmd_save_game(FALSE);
3324 #else /* ZANGBAND */
3326 #endif /* ZANGBAND */
3331 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3333 plog("You may not do that right now.");
3343 if (game_in_progress && character_generated)
3349 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3351 plog("You may not do that right now.");
3357 /* Hack -- Forget messages */
3366 do_cmd_save_game(FALSE);
3367 #else /* ZANGBAND */
3369 #endif /* ZANGBAND */
3376 case IDM_FILE_SCORE:
3380 /* Build the filename */
3381 path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw");
3383 /* Open the binary high score file, for reading */
3384 highscore_fd = fd_open(buf, O_RDONLY);
3386 /* Paranoia -- No score file */
3387 if (highscore_fd < 0)
3389 msg_print("Score file unavailable.");
3399 /* Display the scores */
3400 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3402 /* Shut the high score file */
3403 (void)fd_close(highscore_fd);
3405 /* Forget the high score fd */
3411 /* Hack - Flush it */
3419 case IDM_WINDOW_VIS_0:
3422 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3424 plog("You are not allowed to do that!");
3431 /* Window visibility */
3432 case IDM_WINDOW_VIS_1:
3433 case IDM_WINDOW_VIS_2:
3434 case IDM_WINDOW_VIS_3:
3435 case IDM_WINDOW_VIS_4:
3436 case IDM_WINDOW_VIS_5:
3437 case IDM_WINDOW_VIS_6:
3438 case IDM_WINDOW_VIS_7:
3440 i = wCmd - IDM_WINDOW_VIS_0;
3442 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3449 ShowWindow(td->w, SW_SHOW);
3450 term_data_redraw(td);
3454 td->visible = FALSE;
3455 ShowWindow(td->w, SW_HIDE);
3462 case IDM_WINDOW_FONT_0:
3463 case IDM_WINDOW_FONT_1:
3464 case IDM_WINDOW_FONT_2:
3465 case IDM_WINDOW_FONT_3:
3466 case IDM_WINDOW_FONT_4:
3467 case IDM_WINDOW_FONT_5:
3468 case IDM_WINDOW_FONT_6:
3469 case IDM_WINDOW_FONT_7:
3471 i = wCmd - IDM_WINDOW_FONT_0;
3473 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3477 term_change_font(td);
3482 /* Bizarre Display */
3483 case IDM_WINDOW_BIZ_0:
3484 case IDM_WINDOW_BIZ_1:
3485 case IDM_WINDOW_BIZ_2:
3486 case IDM_WINDOW_BIZ_3:
3487 case IDM_WINDOW_BIZ_4:
3488 case IDM_WINDOW_BIZ_5:
3489 case IDM_WINDOW_BIZ_6:
3490 case IDM_WINDOW_BIZ_7:
3492 i = wCmd - IDM_WINDOW_BIZ_0;
3494 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3498 td->bizarre = !td->bizarre;
3502 term_window_resize(td);
3507 /* Increase Tile Width */
3508 case IDM_WINDOW_I_WID_0:
3509 case IDM_WINDOW_I_WID_1:
3510 case IDM_WINDOW_I_WID_2:
3511 case IDM_WINDOW_I_WID_3:
3512 case IDM_WINDOW_I_WID_4:
3513 case IDM_WINDOW_I_WID_5:
3514 case IDM_WINDOW_I_WID_6:
3515 case IDM_WINDOW_I_WID_7:
3517 i = wCmd - IDM_WINDOW_I_WID_0;
3519 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3527 term_window_resize(td);
3532 /* Decrease Tile Height */
3533 case IDM_WINDOW_D_WID_0:
3534 case IDM_WINDOW_D_WID_1:
3535 case IDM_WINDOW_D_WID_2:
3536 case IDM_WINDOW_D_WID_3:
3537 case IDM_WINDOW_D_WID_4:
3538 case IDM_WINDOW_D_WID_5:
3539 case IDM_WINDOW_D_WID_6:
3540 case IDM_WINDOW_D_WID_7:
3542 i = wCmd - IDM_WINDOW_D_WID_0;
3544 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3552 term_window_resize(td);
3557 /* Increase Tile Height */
3558 case IDM_WINDOW_I_HGT_0:
3559 case IDM_WINDOW_I_HGT_1:
3560 case IDM_WINDOW_I_HGT_2:
3561 case IDM_WINDOW_I_HGT_3:
3562 case IDM_WINDOW_I_HGT_4:
3563 case IDM_WINDOW_I_HGT_5:
3564 case IDM_WINDOW_I_HGT_6:
3565 case IDM_WINDOW_I_HGT_7:
3567 i = wCmd - IDM_WINDOW_I_HGT_0;
3569 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3577 term_window_resize(td);
3582 /* Decrease Tile Height */
3583 case IDM_WINDOW_D_HGT_0:
3584 case IDM_WINDOW_D_HGT_1:
3585 case IDM_WINDOW_D_HGT_2:
3586 case IDM_WINDOW_D_HGT_3:
3587 case IDM_WINDOW_D_HGT_4:
3588 case IDM_WINDOW_D_HGT_5:
3589 case IDM_WINDOW_D_HGT_6:
3590 case IDM_WINDOW_D_HGT_7:
3592 i = wCmd - IDM_WINDOW_D_HGT_0;
3594 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3602 term_window_resize(td);
3607 case IDM_OPTIONS_NO_GRAPHICS:
3612 plog("You may not do that right now.");
3616 /* Toggle "arg_graphics" */
3617 if (arg_graphics != GRAPHICS_NONE)
3619 arg_graphics = GRAPHICS_NONE;
3621 /* React to changes */
3622 Term_xtra_win_react();
3624 /* Hack -- Force redraw */
3625 Term_key_push(KTRL('R'));
3631 case IDM_OPTIONS_OLD_GRAPHICS:
3636 plog("You may not do that right now.");
3640 /* Toggle "arg_graphics" */
3641 if (arg_graphics != GRAPHICS_ORIGINAL)
3643 arg_graphics = GRAPHICS_ORIGINAL;
3645 /* React to changes */
3646 Term_xtra_win_react();
3648 /* Hack -- Force redraw */
3649 Term_key_push(KTRL('R'));
3655 case IDM_OPTIONS_NEW_GRAPHICS:
3660 plog("You may not do that right now.");
3664 /* Toggle "arg_graphics" */
3665 if (arg_graphics != GRAPHICS_ADAM_BOLT)
3667 arg_graphics = GRAPHICS_ADAM_BOLT;
3669 /* React to changes */
3670 Term_xtra_win_react();
3672 /* Hack -- Force redraw */
3673 Term_key_push(KTRL('R'));
3679 case IDM_OPTIONS_BIGTILE:
3681 term_data *td = &data[0];
3686 plog("You may not do that right now.");
3690 /* Toggle "arg_sound" */
3691 arg_bigtile = !arg_bigtile;
3694 Term_activate(&td->t);
3696 /* Resize the term */
3697 Term_resize(td->cols, td->rows);
3700 InvalidateRect(td->w, NULL, TRUE);
3705 case IDM_OPTIONS_SOUND:
3710 plog("You may not do that right now.");
3714 /* Toggle "arg_sound" */
3715 arg_sound = !arg_sound;
3717 /* React to changes */
3718 Term_xtra_win_react();
3720 /* Hack -- Force redraw */
3721 Term_key_push(KTRL('R'));
3727 case IDM_OPTIONS_BG:
3732 plog("You may not do that right now.");
3736 /* Toggle "use_bg" */
3741 /* React to changes */
3742 Term_xtra_win_react();
3744 /* Hack -- Force redraw */
3745 Term_key_push(KTRL('R'));
3751 case IDM_OPTIONS_OPEN_BG:
3756 plog("You may not do that right now.");
3761 memset(&ofn, 0, sizeof(ofn));
3762 ofn.lStructSize = sizeof(ofn);
3763 ofn.hwndOwner = data[0].w;
3764 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3765 ofn.nFilterIndex = 1;
3766 ofn.lpstrFile = bg_bitmap_file;
3767 ofn.nMaxFile = 1023;
3768 ofn.lpstrInitialDir = NULL;
3770 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
3772 ofn.lpstrTitle = "Choose wall paper.";
3774 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3776 if (GetOpenFileName(&ofn))
3778 /* Load 'savefile' */
3783 /* React to changes */
3784 Term_xtra_win_react();
3786 /* Hack -- Force redraw */
3787 Term_key_push(KTRL('R'));
3792 case IDM_DUMP_SCREEN_HTML:
3794 static char buf[1024] = "";
3795 memset(&ofn, 0, sizeof(ofn));
3796 ofn.lStructSize = sizeof(ofn);
3797 ofn.hwndOwner = data[0].w;
3798 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
3799 ofn.nFilterIndex = 1;
3800 ofn.lpstrFile = buf;
3801 ofn.nMaxFile = 1023;
3802 ofn.lpstrDefExt = "html";
3803 ofn.lpstrInitialDir = NULL;
3805 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
3807 ofn.lpstrTitle = "Save screen dump as HTML.";
3809 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
3811 if (GetSaveFileName(&ofn))
3813 extern void do_cmd_save_screen_html_aux(char *filename, int message);
3814 do_cmd_save_screen_html_aux(buf, 0);
3821 case IDM_OPTIONS_SAVER:
3825 DestroyWindow(hwndSaver);
3830 /* Create a screen scaver window */
3831 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
3832 "Angband Screensaver",
3833 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
3834 0, 0, GetSystemMetrics(SM_CXSCREEN),
3835 GetSystemMetrics(SM_CYSCREEN),
3836 NULL, NULL, hInstance, NULL);
3840 /* Push the window to the bottom XXX XXX XXX */
3841 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3846 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
3848 plog("Failed to create saver window");
3858 case IDM_OPTIONS_MAP:
3864 case IDM_HELP_CONTENTS:
3868 path_build(tmp, 1024, ANGBAND_DIR_XTRA_HELP, "zangband.chm");
3869 if (check_file(tmp))
3871 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
3876 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
3877 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
3879 plog_fmt("Cannot find help file: %s", tmp);
3880 plog("Use the online help files instead.");
3885 #else /* HTML_HELP */
3888 path_build(tmp, 1024, ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
3889 if (check_file(tmp))
3891 sprintf(buf, "winhelp.exe %s", tmp);
3892 WinExec(buf, SW_NORMAL);
3897 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
3898 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
3900 plog_fmt("Cannot find help file: %s", tmp);
3901 plog("Use the online help files instead.");
3906 #endif /* HTML_HELP */
3914 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
3915 WPARAM wParam, LPARAM lParam);
3916 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
3917 WPARAM wParam, LPARAM lParam)
3918 #else /* __MWERKS__ */
3919 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
3920 WPARAM wParam, LPARAM lParam)
3921 #endif /* __MWERKS__ */
3927 MINMAXINFO FAR *lpmmi;
3933 /* Acquire proper "term_data" info */
3934 td = (term_data *)GetWindowLong(hWnd, 0);
3936 /* Handle message */
3942 SetWindowLong(hWnd, 0, (LONG)(my_td));
3952 case WM_GETMINMAXINFO:
3954 MINMAXINFO FAR *lpmmi;
3957 lpmmi = (MINMAXINFO FAR *)lParam;
3959 /* this message was sent before WM_NCCREATE */
3962 /* Minimum window size is 80x24 */
3963 rc.left = rc.top = 0;
3964 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
3965 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
3968 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3970 /* Save minimum size */
3971 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
3972 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
3979 BeginPaint(hWnd, &ps);
3980 if (td) term_data_redraw(td);
3981 EndPaint(hWnd, &ps);
3982 ValidateRect(hWnd, NULL);
3993 /* Extract the modifiers */
3994 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
3995 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
3996 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
3998 /* Handle "special" keys */
3999 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4001 /* Begin the macro trigger */
4004 /* Send the modifiers */
4005 if (mc) Term_keypress('C');
4006 if (ms) Term_keypress('S');
4007 if (ma) Term_keypress('A');
4009 /* Extract "scan code" */
4010 i = LOBYTE(HIWORD(lParam));
4012 /* Introduce the scan code */
4015 /* Encode the hexidecimal scan code */
4016 Term_keypress(hexsym[i/16]);
4017 Term_keypress(hexsym[i%16]);
4019 /* End the macro trigger */
4030 Term_keypress(wParam);
4042 if (game_in_progress && character_generated)
4046 plog("You may not do that right now.");
4050 /* Hack -- Forget messages */
4059 do_cmd_save_game(FALSE);
4060 #else /* ZANGBAND */
4062 #endif /* ZANGBAND */
4076 process_menus(LOWORD(wParam));
4082 /* this message was sent before WM_NCCREATE */
4085 /* it was sent from inside CreateWindowEx */
4086 if (!td->w) return 1;
4088 /* was sent from WM_SIZE */
4089 if (td->size_hack) return 1;
4093 case SIZE_MINIMIZED:
4095 /* Hide sub-windows */
4096 for (i = 1; i < MAX_TERM_DATA; i++)
4098 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4103 case SIZE_MAXIMIZED:
4105 /* fall through XXX XXX XXX */
4110 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4111 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4114 if ((td->cols != cols) || (td->rows != rows))
4116 /* Save the new size */
4121 Term_activate(&td->t);
4123 /* Resize the term */
4124 Term_resize(td->cols, td->rows);
4127 InvalidateRect(td->w, NULL, TRUE);
4130 td->size_hack = TRUE;
4132 /* Show sub-windows */
4133 for (i = 1; i < MAX_TERM_DATA; i++)
4135 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4138 td->size_hack = FALSE;
4146 case WM_PALETTECHANGED:
4148 /* Ignore if palette change caused by itself */
4149 if ((HWND)wParam == hWnd) return 0;
4151 /* Fall through... */
4154 case WM_QUERYNEWPALETTE:
4156 if (!paletted) return 0;
4160 SelectPalette(hdc, hPal, FALSE);
4162 i = RealizePalette(hdc);
4164 /* if any palette entries changed, repaint the window. */
4165 if (i) InvalidateRect(hWnd, NULL, TRUE);
4167 ReleaseDC(hWnd, hdc);
4174 if (wParam && !HIWORD(lParam))
4176 /* Do something to sub-windows */
4177 for (i = 1; i < MAX_TERM_DATA; i++)
4179 SetWindowPos(data[i].w, hWnd, 0, 0, 0, 0,
4180 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
4183 /* Focus on main window */
4193 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4198 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4199 WPARAM wParam, LPARAM lParam);
4200 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4201 WPARAM wParam, LPARAM lParam)
4202 #else /* __MWERKS__ */
4203 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4204 WPARAM wParam, LPARAM lParam)
4205 #endif /* __MWERKS__ */
4209 MINMAXINFO FAR *lpmmi;
4217 /* Acquire proper "term_data" info */
4218 td = (term_data *)GetWindowLong(hWnd, 0);
4220 /* Process message */
4226 SetWindowLong(hWnd, 0, (LONG)(my_td));
4236 case WM_GETMINMAXINFO:
4238 MINMAXINFO FAR *lpmmi;
4241 lpmmi = (MINMAXINFO FAR *)lParam;
4243 /* this message was sent before WM_NCCREATE */
4246 /* Minimum window size is 80x24 */
4247 rc.left = rc.top = 0;
4248 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4249 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4252 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4254 /* Save minimum size */
4255 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4256 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4266 /* this message was sent before WM_NCCREATE */
4269 /* it was sent from inside CreateWindowEx */
4270 if (!td->w) return 1;
4272 /* was sent from inside WM_SIZE */
4273 if (td->size_hack) return 1;
4275 td->size_hack = TRUE;
4277 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4278 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4281 if ((td->cols != cols) || (td->rows != rows))
4284 term *old_term = Term;
4286 /* Save the new size */
4291 Term_activate(&td->t);
4293 /* Resize the term */
4294 Term_resize(td->cols, td->rows);
4297 Term_activate(old_term);
4300 InvalidateRect(td->w, NULL, TRUE);
4302 /* HACK - Redraw all windows */
4303 p_ptr->window = 0xFFFFFFFF;
4307 td->size_hack = FALSE;
4314 BeginPaint(hWnd, &ps);
4315 if (td) term_data_redraw(td);
4316 EndPaint(hWnd, &ps);
4327 /* Extract the modifiers */
4328 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4329 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4330 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4332 /* Handle "special" keys */
4333 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4335 /* Begin the macro trigger */
4338 /* Send the modifiers */
4339 if (mc) Term_keypress('C');
4340 if (ms) Term_keypress('S');
4341 if (ma) Term_keypress('A');
4343 /* Extract "scan code" */
4344 i = LOBYTE(HIWORD(lParam));
4346 /* Introduce the scan code */
4349 /* Encode the hexidecimal scan code */
4350 Term_keypress(hexsym[i/16]);
4351 Term_keypress(hexsym[i%16]);
4353 /* End the macro trigger */
4364 Term_keypress(wParam);
4368 case WM_PALETTECHANGED:
4370 /* ignore if palette change caused by itself */
4371 if ((HWND)wParam == hWnd) return FALSE;
4372 /* otherwise, fall through!!! */
4375 case WM_QUERYNEWPALETTE:
4377 if (!paletted) return 0;
4379 SelectPalette(hdc, hPal, FALSE);
4380 i = RealizePalette(hdc);
4381 /* if any palette entries changed, repaint the window. */
4382 if (i) InvalidateRect(hWnd, NULL, TRUE);
4383 ReleaseDC(hWnd, hdc);
4387 case WM_NCLBUTTONDOWN:
4391 if (wParam == HTCLOSE) wParam = HTSYSMENU;
4392 #endif /* HTCLOSE */
4394 if (wParam == HTSYSMENU)
4398 td->visible = FALSE;
4399 ShowWindow(td->w, SW_HIDE);
4409 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4415 #define MOUSE_SENS 40
4418 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4419 WPARAM wParam, LPARAM lParam);
4420 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4421 WPARAM wParam, LPARAM lParam)
4422 #else /* __MWERKS__ */
4423 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4424 WPARAM wParam, LPARAM lParam)
4425 #endif /* __MWERKS__ */
4427 static int iMouse = 0;
4428 static WORD xMouse = 0;
4429 static WORD yMouse = 0;
4452 if (LOWORD(wParam) == WA_INACTIVE) break;
4454 /* else fall through */
4458 case WM_LBUTTONDOWN:
4459 case WM_MBUTTONDOWN:
4460 case WM_RBUTTONDOWN:
4463 SendMessage(hWnd, WM_CLOSE, 0, 0);
4471 dx = LOWORD(lParam) - xMouse;
4472 dy = HIWORD(lParam) - yMouse;
4474 if (dx < 0) dx = -dx;
4475 if (dy < 0) dy = -dy;
4477 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
4479 SendMessage(hWnd, WM_CLOSE, 0, 0);
4483 /* Save last location */
4485 xMouse = LOWORD(lParam);
4486 yMouse = HIWORD(lParam);
4493 DestroyWindow(hwndSaver);
4500 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4503 #endif /* USE_SAVER */
4509 /*** Temporary Hooks ***/
4513 * Display warning message (see "z-util.c")
4515 static void hack_plog(cptr str)
4517 /* Give a warning */
4521 MessageBox(NULL, str, "·Ù¹ð¡ª",
4522 MB_ICONEXCLAMATION | MB_OK);
4524 MessageBox(NULL, str, "Warning",
4525 MB_ICONEXCLAMATION | MB_OK);
4533 * Display error message and quit (see "z-util.c")
4535 static void hack_quit(cptr str)
4537 /* Give a warning */
4541 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
4542 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4544 MessageBox(NULL, str, "Error",
4545 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4550 /* Unregister the classes */
4551 UnregisterClass(AppName, hInstance);
4553 /* Destroy the icon */
4554 if (hIcon) DestroyIcon(hIcon);
4562 /*** Various hooks ***/
4566 * Display warning message (see "z-util.c")
4568 static void hook_plog(cptr str)
4574 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
4575 MB_ICONEXCLAMATION | MB_OK);
4577 MessageBox(data[0].w, str, "Warning",
4578 MB_ICONEXCLAMATION | MB_OK);
4586 * Display error message and quit (see "z-util.c")
4588 static void hook_quit(cptr str)
4593 /* Give a warning */
4597 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
4598 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4600 MessageBox(data[0].w, str, "Error",
4601 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4607 /* Save the preferences */
4611 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
4613 /* Destroy all windows */
4614 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
4616 term_force_font(&data[i], NULL);
4617 if (data[i].font_want) string_free(data[i].font_want);
4618 if (data[i].w) DestroyWindow(data[i].w);
4622 /* Free the bitmap stuff */
4624 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
4625 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
4627 #ifdef USE_TRANSPARENCY
4628 if (infMask.hPalette) DeleteObject(infMask.hPalette);
4629 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
4630 #endif /* USE_TRANSPARENCY */
4632 #endif /* USE_GRAPHICS */
4634 /*** Free some other stuff ***/
4636 DeleteObject(hbrYellow);
4641 if (hPal) DeleteObject(hPal);
4643 UnregisterClass(AppName, hInstance);
4645 if (hIcon) DestroyIcon(hIcon);
4652 /*** Initialize ***/
4658 static void init_stuff(void)
4665 /* Get program name with full path */
4666 GetModuleFileName(hInstance, path, 512);
4668 /* Save the "program name" XXX XXX XXX */
4671 /* Get the name of the "*.ini" file */
4672 strcpy(path + strlen(path) - 4, ".INI");
4674 /* Save the the name of the ini-file */
4675 ini_file = string_make(path);
4677 /* Analyze the path */
4683 if (path[i] == '\\')
4690 /* Add "lib" to the path */
4691 strcpy(path + i + 1, "lib\\");
4693 /* Validate the path */
4694 validate_dir(path, TRUE);
4696 /* Init the file paths */
4697 init_file_paths(path);
4699 /* Hack -- Validate the paths */
4700 validate_dir(ANGBAND_DIR_APEX, FALSE);
4701 validate_dir(ANGBAND_DIR_BONE, FALSE);
4703 /* Allow missing 'edit' directory */
4704 if (!check_dir(ANGBAND_DIR_EDIT))
4706 /* Must have 'data'! */
4707 validate_dir(ANGBAND_DIR_DATA, TRUE);
4711 /* Don't need 'data' */
4712 validate_dir(ANGBAND_DIR_DATA, FALSE);
4715 validate_dir(ANGBAND_DIR_FILE, TRUE);
4716 validate_dir(ANGBAND_DIR_HELP, FALSE);
4717 validate_dir(ANGBAND_DIR_INFO, FALSE);
4718 validate_dir(ANGBAND_DIR_PREF, TRUE);
4719 validate_dir(ANGBAND_DIR_SAVE, FALSE);
4720 validate_dir(ANGBAND_DIR_USER, TRUE);
4721 validate_dir(ANGBAND_DIR_XTRA, TRUE);
4723 /* Build the filename */
4725 path_build(path, 1024, ANGBAND_DIR_FILE, "news_j.txt");
4727 path_build(path, 1024, ANGBAND_DIR_FILE, "news.txt");
4731 /* Hack -- Validate the "news.txt" file */
4732 validate_file(path);
4736 /* Build the "font" path */
4737 path_build(path, 1024, ANGBAND_DIR_XTRA, "font");
4739 /* Allocate the path */
4740 ANGBAND_DIR_XTRA_FONT = string_make(path);
4742 /* Validate the "font" directory */
4743 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
4745 /* Build the filename */
4746 path_build(path, 1024, ANGBAND_DIR_XTRA_FONT, "8X13.FON");
4748 /* Hack -- Validate the basic font */
4749 validate_file(path);
4755 /* Build the "graf" path */
4756 path_build(path, 1024, ANGBAND_DIR_XTRA, "graf");
4758 /* Allocate the path */
4759 ANGBAND_DIR_XTRA_GRAF = string_make(path);
4761 /* Validate the "graf" directory */
4762 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
4764 #endif /* USE_GRAPHICS */
4769 /* Build the "sound" path */
4770 path_build(path, 1024, ANGBAND_DIR_XTRA, "sound");
4772 /* Allocate the path */
4773 ANGBAND_DIR_XTRA_SOUND = string_make(path);
4775 /* Validate the "sound" directory */
4776 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
4778 #endif /* USE_SOUND */
4782 /* Build the "music" path */
4783 path_build(path, 1024, ANGBAND_DIR_XTRA, "music");
4785 /* Allocate the path */
4786 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
4788 /* Validate the "music" directory */
4789 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
4791 #endif /* USE_MUSIC */
4793 /* Build the "help" path */
4794 path_build(path, 1024, ANGBAND_DIR_XTRA, "help");
4796 /* Allocate the path */
4797 ANGBAND_DIR_XTRA_HELP = string_make(path);
4799 /* Validate the "help" directory */
4800 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
4804 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
4805 LPSTR lpCmdLine, int nCmdShow)
4817 if (hPrevInst == NULL)
4819 wc.style = CS_CLASSDC;
4820 wc.lpfnWndProc = AngbandWndProc;
4822 wc.cbWndExtra = 4; /* one long pointer to term_data */
4823 wc.hInstance = hInst;
4824 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
4825 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
4826 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
4827 wc.lpszMenuName = AppName;
4828 wc.lpszClassName = AppName;
4830 if (!RegisterClass(&wc)) exit(1);
4832 wc.lpfnWndProc = AngbandListProc;
4833 wc.lpszMenuName = NULL;
4834 wc.lpszClassName = AngList;
4836 if (!RegisterClass(&wc)) exit(2);
4840 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
4841 wc.lpfnWndProc = AngbandSaverProc;
4843 wc.lpszMenuName = NULL;
4844 wc.lpszClassName = "WindowsScreenSaverClass";
4846 if (!RegisterClass(&wc)) exit(3);
4852 /* Temporary hooks */
4853 plog_aux = hack_plog;
4854 quit_aux = hack_quit;
4855 core_aux = hack_quit;
4857 /* Prepare the filepaths */
4860 /* Initialize the keypress analyzer */
4861 for (i = 0; special_key_list[i]; ++i)
4863 special_key[special_key_list[i]] = TRUE;
4865 /* Initialize the keypress analyzer */
4866 for (i = 0; ignore_key_list[i]; ++i)
4868 ignore_key[ignore_key_list[i]] = TRUE;
4871 /* Determine if display is 16/256/true color */
4873 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
4874 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
4875 ReleaseDC(NULL, hdc);
4877 /* Initialize the colors */
4878 for (i = 0; i < 256; i++)
4882 /* Extract desired values */
4883 rv = angband_color_table[i][1];
4884 gv = angband_color_table[i][2];
4885 bv = angband_color_table[i][3];
4887 /* Extract the "complex" code */
4888 win_clr[i] = PALETTERGB(rv, gv, bv);
4890 /* Save the "simple" code */
4891 angband_color_table[i][0] = win_pal[i];
4894 /* Prepare the windows */
4900 /* Activate hooks */
4901 plog_aux = hook_plog;
4902 quit_aux = hook_quit;
4903 core_aux = hook_quit;
4905 /* Set the system suffix */
4906 ANGBAND_SYS = "win";
4908 /* Set the keyboard suffix */
4909 if (7 != GetKeyboardType(0))
4910 ANGBAND_KEYBOARD = "0";
4913 /* Japanese keyboard */
4914 switch (GetKeyboardType(1))
4916 case 0x0D01: case 0x0D02:
4917 case 0x0D03: case 0x0D04:
4918 case 0x0D05: case 0x0D06:
4920 ANGBAND_KEYBOARD = "NEC98";
4924 ANGBAND_KEYBOARD = "JAPAN";
4932 /* We are now initialized */
4936 if(lpCmdLine[0] == '-'){
4937 switch(lpCmdLine[1])
4941 if (!lpCmdLine[2]) break;
4942 chuukei_server = TRUE;
4943 if(connect_chuukei_server(&lpCmdLine[2])<0){
4944 msg_print("connect fail");
4947 msg_print("connect");
4954 if (!lpCmdLine[2]) break;
4955 chuukei_client = TRUE;
4956 connect_chuukei_server(&lpCmdLine[2]);
4966 /* Did the user double click on a save file? */
4967 if(!chuukei_server) check_for_save_file(lpCmdLine);
4969 /* Did the user double click on a save file? */
4970 check_for_save_file(lpCmdLine);
4973 /* Prompt the user */
4975 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
4977 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
4982 /* Process messages forever */
4983 while (GetMessage(&msg, NULL, 0, 0))
4985 TranslateMessage(&msg);
4986 DispatchMessage(&msg);
4997 #endif /* WINDOWS */