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.
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;
1003 if (td->cols > 80) td->cols = 80;
1004 if (td->rows > 24) td->rows = 24;
1007 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1008 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1010 /* Fake window size */
1012 rc.right = rc.left + wid;
1014 rc.bottom = rc.top + hgt;
1017 /* rc.right += 1; */
1018 /* rc.bottom += 1; */
1021 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1024 td->size_wid = rc.right - rc.left;
1025 td->size_hgt = rc.bottom - rc.top;
1027 /* See CreateWindowEx */
1030 /* Extract actual location */
1031 GetWindowRect(td->w, &rc);
1033 /* Save the location */
1034 td->pos_x = rc.left;
1040 * Write the "prefs" for a single term
1042 static void save_prefs_aux(term_data *td, cptr sec_name)
1052 strcpy(buf, td->visible ? "1" : "0");
1053 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1057 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1059 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1062 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1065 wsprintf(buf, "%d", td->lf.lfWidth);
1066 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1067 wsprintf(buf, "%d", td->lf.lfHeight);
1068 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1069 wsprintf(buf, "%d", td->lf.lfWeight);
1070 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1073 strcpy(buf, td->bizarre ? "1" : "0");
1074 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1077 wsprintf(buf, "%d", td->tile_wid);
1078 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1081 wsprintf(buf, "%d", td->tile_hgt);
1082 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1084 /* Window size (x) */
1085 wsprintf(buf, "%d", td->cols);
1086 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1088 /* Window size (y) */
1089 wsprintf(buf, "%d", td->rows);
1090 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1092 /* Acquire position */
1093 GetWindowRect(td->w, &rc);
1095 /* Window position (x) */
1096 wsprintf(buf, "%d", rc.left);
1097 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1099 /* Window position (y) */
1100 wsprintf(buf, "%d", rc.top);
1101 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1108 * We assume that the windows have all been initialized
1110 static void save_prefs(void)
1116 /* Save the "arg_graphics" flag */
1117 sprintf(buf, "%d", arg_graphics);
1118 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1120 /* Save the "arg_bigtile" flag */
1121 strcpy(buf, arg_bigtile ? "1" : "0");
1122 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1124 /* Save the "arg_sound" flag */
1125 strcpy(buf, arg_sound ? "1" : "0");
1126 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1129 strcpy(buf, use_bg ? "1" : "0");
1130 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1131 WritePrivateProfileString("Angband", "BackGroundBitmap",
1132 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1134 /* Save window prefs */
1135 for (i = 0; i < MAX_TERM_DATA; ++i)
1137 term_data *td = &data[i];
1139 sprintf(buf, "Term-%d", i);
1141 save_prefs_aux(td, buf);
1147 * Load the "prefs" for a single term
1149 static void load_prefs_aux(term_data *td, cptr sec_name)
1156 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1158 /* Desired font, with default */
1160 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1162 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1167 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1169 /* Analyze font, save desired font name */
1171 td->font_want = string_make(tmp);
1173 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1174 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1175 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1177 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1183 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1184 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1186 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1187 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1192 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1193 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1195 /* Window position */
1196 td->pos_x = GetPrivateProfileInt(sec_name, "PositionX", td->pos_x, ini_file);
1197 td->pos_y = GetPrivateProfileInt(sec_name, "PositionY", td->pos_y, ini_file);
1204 static void load_prefs(void)
1210 /* Extract the "arg_graphics" flag */
1211 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1213 /* Extract the "arg_bigtile" flag */
1214 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1215 use_bigtile = arg_bigtile;
1217 /* Extract the "arg_sound" flag */
1218 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1221 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1222 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1224 /* Load window prefs */
1225 for (i = 0; i < MAX_TERM_DATA; ++i)
1227 term_data *td = &data[i];
1229 sprintf(buf, "Term-%d", i);
1231 load_prefs_aux(td, buf);
1237 * Create the new global palette based on the bitmap palette
1238 * (if any), and the standard 16 entry palette derived from
1239 * "win_clr[]" which is used for the basic 16 Angband colors.
1241 * This function is never called before all windows are ready.
1243 * This function returns FALSE if the new palette could not be
1244 * prepared, which should normally be a fatal error. XXX XXX
1246 * Note that only some machines actually use a "palette".
1248 static int new_palette(void)
1256 LPLOGPALETTE pLogPal;
1257 LPPALETTEENTRY lppe;
1262 /* This makes no sense */
1263 if (!paletted) return (TRUE);
1273 /* Check the bitmap palette */
1274 hBmPal = infGraph.hPalette;
1276 /* Use the bitmap */
1279 lppeSize = 256 * sizeof(PALETTEENTRY);
1280 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1281 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1282 if ((nEntries == 0) || (nEntries > 220))
1286 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1288 plog("Please switch to high- or true-color mode.");
1293 rnfree(lppe, lppeSize);
1300 #endif /* USE_GRAPHICS */
1302 /* Size of palette */
1303 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1305 /* Allocate palette */
1306 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1309 pLogPal->palVersion = 0x300;
1311 /* Make room for bitmap and normal data */
1312 pLogPal->palNumEntries = nEntries + 16;
1314 /* Save the bitmap data */
1315 for (i = 0; i < nEntries; i++)
1317 pLogPal->palPalEntry[i] = lppe[i];
1320 /* Save the normal data */
1321 for (i = 0; i < 16; i++)
1325 /* Access the entry */
1326 p = &(pLogPal->palPalEntry[i+nEntries]);
1328 /* Save the colors */
1329 p->peRed = GetRValue(win_clr[i]);
1330 p->peGreen = GetGValue(win_clr[i]);
1331 p->peBlue = GetBValue(win_clr[i]);
1333 /* Save the flags */
1334 p->peFlags = PC_NOCOLLAPSE;
1337 /* Free something */
1338 if (lppe) rnfree(lppe, lppeSize);
1340 /* Create a new palette, or fail */
1341 hNewPal = CreatePalette(pLogPal);
1343 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1345 if (!hNewPal) quit("Cannot create palette!");
1349 /* Free the palette */
1350 rnfree(pLogPal, pLogPalSize);
1355 /* Realize the palette */
1357 SelectPalette(hdc, hNewPal, 0);
1358 i = RealizePalette(hdc);
1359 ReleaseDC(td->w, hdc);
1361 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1363 if (i == 0) quit("Cannot realize palette!");
1368 for (i = 1; i < MAX_TERM_DATA; i++)
1373 SelectPalette(hdc, hNewPal, 0);
1374 ReleaseDC(td->w, hdc);
1377 /* Delete old palette */
1378 if (hPal) DeleteObject(hPal);
1380 /* Save new palette */
1390 * Initialize graphics
1392 static bool init_graphics(void)
1394 /* Initialize once */
1395 /* if (can_use_graphics != arg_graphics) */
1401 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1408 ANGBAND_GRAF = "new";
1416 ANGBAND_GRAF = "old";
1419 /* Access the bitmap file */
1420 path_build(buf, 1024, ANGBAND_DIR_XTRA_GRAF, name);
1422 /* Load the bitmap or quit */
1423 if (!ReadDIB(data[0].w, buf, &infGraph))
1426 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1428 plog_fmt("Cannot read bitmap file '%s'", name);
1434 /* Save the new sizes */
1435 infGraph.CellWidth = wid;
1436 infGraph.CellHeight = hgt;
1438 #ifdef USE_TRANSPARENCY
1440 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1442 /* Access the mask file */
1443 path_build(buf, 1024, ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1445 /* Load the bitmap or quit */
1446 if (!ReadDIB(data[0].w, buf, &infMask))
1448 plog_fmt("Cannot read bitmap file '%s'", buf);
1453 #endif /* USE_TRANSPARENCY */
1455 /* Activate a palette */
1458 /* Free bitmap XXX XXX XXX */
1462 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1464 plog("Cannot activate palette!");
1470 /* Graphics available */
1471 can_use_graphics = arg_graphics;
1475 return (can_use_graphics);
1477 #endif /* USE_GRAPHICS */
1484 static bool init_sound(void)
1486 /* Initialize once */
1494 /* Prepare the sounds */
1495 for (i = 1; i < SOUND_MAX; i++)
1497 /* Extract name of sound file */
1498 sprintf(wav, "%s.wav", angband_sound_name[i]);
1500 /* Access the sound */
1501 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, wav);
1503 /* Save the sound filename, if it exists */
1504 if (check_file(buf)) sound_file[i] = string_make(buf);
1507 /* Sound available */
1508 can_use_sound = TRUE;
1512 return (can_use_sound);
1514 #endif /* USE_SOUND */
1520 static void term_window_resize(term_data *td)
1522 /* Require window */
1525 /* Resize the window */
1526 SetWindowPos(td->w, 0, 0, 0,
1527 td->size_wid, td->size_hgt,
1528 SWP_NOMOVE | SWP_NOZORDER);
1531 InvalidateRect(td->w, NULL, TRUE);
1536 * Force the use of a new "font file" for a term_data
1538 * This function may be called before the "window" is ready
1540 * This function returns zero only if everything succeeds.
1542 * Note that the "font name" must be capitalized!!!
1544 static errr term_force_font(term_data *td, cptr path)
1554 /* Forget the old font (if needed) */
1555 if (td->font_id) DeleteObject(td->font_id);
1558 /* Forget old font */
1564 for (i = 0; i < MAX_TERM_DATA; i++)
1566 /* Don't check when closing the application */
1569 /* Check "screen" */
1570 if ((td != &data[i]) &&
1571 (data[i].font_file) &&
1572 (streq(data[i].font_file, td->font_file)))
1578 /* Remove unused font resources */
1579 if (!used) RemoveFontResource(td->font_file);
1581 /* Free the old name */
1582 string_free(td->font_file);
1585 td->font_file = NULL;
1590 if (!path) return (1);
1596 /* Analyze font path */
1597 base = analyze_font(buf, &wid, &hgt);
1600 if (!suffix(base, ".FON")) return (1);
1603 if (!check_file(buf)) return (1);
1605 /* Load the new font */
1606 if (!AddFontResource(buf)) return (1);
1608 /* Save new font name */
1609 td->font_file = string_make(base);
1611 /* Remove the "suffix" */
1612 base[strlen(base)-4] = '\0';
1615 /* Create the font (using the 'base' of the font file name!) */
1617 td->font_id = CreateFontIndirect(&(td->lf));
1618 wid = td->lf.lfWidth;
1619 hgt = td->lf.lfHeight;
1620 if (!td->font_id) return (1);
1622 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1623 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1624 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1625 FIXED_PITCH | FF_DONTCARE, base);
1629 /* Hack -- Unknown size */
1636 /* all this trouble to get the cell size */
1637 hdcDesktop = GetDC(HWND_DESKTOP);
1638 hfOld = SelectObject(hdcDesktop, td->font_id);
1639 GetTextMetrics(hdcDesktop, &tm);
1640 SelectObject(hdcDesktop, hfOld);
1641 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1643 /* Font size info */
1644 wid = tm.tmAveCharWidth;
1648 /* Save the size info */
1659 * Allow the user to change the font for this window.
1661 static void term_change_font(term_data *td)
1666 memset(&cf, 0, sizeof(cf));
1667 cf.lStructSize = sizeof(cf);
1668 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1669 cf.lpLogFont = &(td->lf);
1671 if (ChooseFont(&cf))
1673 /* Force the font */
1674 term_force_font(td, NULL);
1676 /* Assume not bizarre */
1679 /* Reset the tile info */
1680 td->tile_wid = td->font_wid;
1681 td->tile_hgt = td->font_hgt;
1683 /* Analyze the font */
1686 /* Resize the window */
1687 term_window_resize(td);
1693 char tmp[1024] = "";
1695 /* Extract a default if possible */
1696 if (td->font_file) strcpy(tmp, td->font_file);
1698 /* Ask for a choice */
1699 memset(&ofn, 0, sizeof(ofn));
1700 ofn.lStructSize = sizeof(ofn);
1701 ofn.hwndOwner = data[0].w;
1702 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1703 ofn.nFilterIndex = 1;
1704 ofn.lpstrFile = tmp;
1706 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1707 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1708 ofn.lpstrDefExt = "fon";
1710 /* Force choice if legal */
1711 if (GetOpenFileName(&ofn))
1713 /* Force the font */
1714 if (term_force_font(td, tmp))
1716 /* Access the standard font file */
1717 path_build(tmp, 1024, ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1719 /* Force the use of that font */
1720 (void)term_force_font(td, tmp);
1723 /* Assume not bizarre */
1724 td->bizarre = FALSE;
1726 /* Reset the tile info */
1727 td->tile_wid = td->font_wid;
1728 td->tile_hgt = td->font_hgt;
1730 /* Analyze the font */
1733 /* Resize the window */
1734 term_window_resize(td);
1742 static void windows_map(void);
1745 * Hack -- redraw a term_data
1747 static void term_data_redraw(term_data *td)
1751 /* Redraw the map */
1756 /* Activate the term */
1757 Term_activate(&td->t);
1759 /* Redraw the contents */
1762 /* Restore the term */
1763 Term_activate(term_screen);
1771 /*** Function hooks needed by "Term" ***/
1777 * Initialize a new Term
1779 static void Term_init_win(term *t)
1788 static void Term_nuke_win(term *t)
1797 * Interact with the User
1799 static errr Term_user_win(int n)
1807 * React to global changes
1809 static errr Term_xtra_win_react(void)
1817 /* Save the default colors */
1818 for (i = 0; i < 256; i++)
1820 /* Simply accept the desired colors */
1821 win_pal[i] = angband_color_table[i][0];
1832 bool change = FALSE;
1834 /* Save the default colors */
1835 for (i = 0; i < 256; i++)
1837 /* Extract desired values */
1838 rv = angband_color_table[i][1];
1839 gv = angband_color_table[i][2];
1840 bv = angband_color_table[i][3];
1842 /* Extract a full color code */
1843 code = PALETTERGB(rv, gv, bv);
1845 /* Activate changes */
1846 if (win_clr[i] != code)
1848 /* Note the change */
1851 /* Apply the desired color */
1856 /* Activate the palette if needed */
1857 if (change) (void)new_palette();
1863 /* Handle "arg_sound" */
1864 if (use_sound != arg_sound)
1866 /* Initialize (if needed) */
1867 if (arg_sound && !init_sound())
1871 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
1873 plog("Cannot initialize sound!");
1881 /* Change setting */
1882 use_sound = arg_sound;
1890 /* Handle "arg_graphics" */
1891 if (use_graphics != arg_graphics)
1893 /* Initialize (if needed) */
1894 if (arg_graphics && !init_graphics())
1898 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
1900 plog("Cannot initialize graphics!");
1905 arg_graphics = GRAPHICS_NONE;
1908 /* Change setting */
1909 use_graphics = arg_graphics;
1912 #ifdef ANGBAND_2_8_1
1914 #else /* ANGBAND_2_8_1 */
1915 reset_visuals(TRUE);
1916 #endif /* ANGBAND_2_8_1 */
1919 #endif /* USE_GRAPHICS */
1922 /* Clean up windows */
1923 for (i = 0; i < MAX_TERM_DATA; i++)
1927 term_data *td = &data[i];
1929 /* Update resized windows */
1930 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
1933 Term_activate(&td->t);
1935 /* Hack -- Resize the term */
1936 Term_resize(td->cols, td->rows);
1938 /* Redraw the contents */
1953 * Process at least one event
1955 static errr Term_xtra_win_event(int v)
1959 /* Wait for an event */
1963 if (GetMessage(&msg, NULL, 0, 0))
1965 TranslateMessage(&msg);
1966 DispatchMessage(&msg);
1970 /* Check for an event */
1974 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1976 TranslateMessage(&msg);
1977 DispatchMessage(&msg);
1987 * Process all pending events
1989 static errr Term_xtra_win_flush(void)
1993 /* Process all pending events */
1994 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1996 TranslateMessage(&msg);
1997 DispatchMessage(&msg);
2006 * Hack -- clear the screen
2008 * Make this more efficient XXX XXX XXX
2010 static errr Term_xtra_win_clear(void)
2012 term_data *td = (term_data*)(Term->data);
2017 /* Rectangle to erase */
2018 rc.left = td->size_ow1;
2019 rc.right = rc.left + td->cols * td->tile_wid;
2020 rc.top = td->size_oh1;
2021 rc.bottom = rc.top + td->rows * td->tile_hgt;
2025 SetBkColor(hdc, RGB(0, 0, 0));
2026 SelectObject(hdc, td->font_id);
2027 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2032 rc.left = 0; rc.top = 0;
2035 ReleaseDC(td->w, hdc);
2043 * Hack -- make a noise
2045 static errr Term_xtra_win_noise(void)
2047 MessageBeep(MB_ICONASTERISK);
2053 * Hack -- make a sound
2055 static errr Term_xtra_win_sound(int v)
2057 /* Sound disabled */
2058 if (!use_sound) return (1);
2061 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2066 if (!sound_file[v]) return (1);
2070 /* Play the sound, catch errors */
2071 return (PlaySound(sound_file[v], 0, SND_FILENAME | SND_ASYNC));
2075 /* Play the sound, catch errors */
2076 return (sndPlaySound(sound_file[v], SND_ASYNC));
2080 #else /* USE_SOUND */
2085 #endif /* USE_SOUND */
2090 * Delay for "x" milliseconds
2092 static int Term_xtra_win_delay(int v)
2106 t = GetTickCount() + v;
2109 while (GetTickCount() < t)
2111 /* Handle messages */
2112 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2114 TranslateMessage(&msg);
2115 DispatchMessage(&msg);
2127 * Do a "special thing"
2129 static errr Term_xtra_win(int n, int v)
2131 /* Handle a subset of the legal requests */
2134 /* Make a bell sound */
2135 case TERM_XTRA_NOISE:
2137 return (Term_xtra_win_noise());
2140 /* Make a special sound */
2141 case TERM_XTRA_SOUND:
2143 return (Term_xtra_win_sound(v));
2146 /* Process random events */
2147 case TERM_XTRA_BORED:
2149 return (Term_xtra_win_event(0));
2152 /* Process an event */
2153 case TERM_XTRA_EVENT:
2155 return (Term_xtra_win_event(v));
2158 /* Flush all events */
2159 case TERM_XTRA_FLUSH:
2161 return (Term_xtra_win_flush());
2164 /* Clear the screen */
2165 case TERM_XTRA_CLEAR:
2167 return (Term_xtra_win_clear());
2170 /* React to global changes */
2171 case TERM_XTRA_REACT:
2173 return (Term_xtra_win_react());
2176 /* Delay for some milliseconds */
2177 case TERM_XTRA_DELAY:
2179 return (Term_xtra_win_delay(v));
2190 * Low level graphics (Assumes valid input).
2192 * Draw a "cursor" at (x,y), using a "yellow box".
2194 static errr Term_curs_win(int x, int y)
2196 term_data *td = (term_data*)(Term->data);
2201 int tile_wid, tile_hgt;
2205 tile_wid = td->map_tile_wid;
2206 tile_hgt = td->map_tile_hgt;
2210 tile_wid = td->tile_wid;
2211 tile_hgt = td->tile_hgt;
2214 /* Frame the grid */
2215 rc.left = x * tile_wid + td->size_ow1;
2216 rc.right = rc.left + tile_wid;
2217 rc.top = y * tile_hgt + td->size_oh1;
2218 rc.bottom = rc.top + tile_hgt;
2221 if (use_bigtile && x + 1 < Term->wid && (Term->old->a[y][x+1] == 255 || (iskanji(Term->old->c[y][x]) && !(Term->old->a[y][x] & 0x80))))
2223 if (use_bigtile && x + 1 < Term->wid && Term->old->a[y][x+1] == 255)
2225 rc.right += tile_wid;
2227 /* Cursor is done as a yellow "box" */
2229 FrameRect(hdc, &rc, hbrYellow);
2230 ReleaseDC(td->w, hdc);
2238 * Low level graphics (Assumes valid input).
2240 * Erase a "block" of "n" characters starting at (x,y).
2242 static errr Term_wipe_win(int x, int y, int n)
2244 term_data *td = (term_data*)(Term->data);
2249 /* Rectangle to erase in client coords */
2250 rc.left = x * td->tile_wid + td->size_ow1;
2251 rc.right = rc.left + n * td->tile_wid;
2252 rc.top = y * td->tile_hgt + td->size_oh1;
2253 rc.bottom = rc.top + td->tile_hgt;
2256 SetBkColor(hdc, RGB(0, 0, 0));
2257 SelectObject(hdc, td->font_id);
2262 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2263 ReleaseDC(td->w, hdc);
2271 * Low level graphics. Assumes valid input.
2273 * Draw several ("n") chars, with an attr, at a given location.
2275 * All "graphic" data is handled by "Term_pict_win()", below.
2277 * One would think there is a more efficient method for telling a window
2278 * what color it should be using to draw with, but perhaps simply changing
2279 * it every time is not too inefficient. XXX XXX XXX
2281 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2283 term_data *td = (term_data*)(Term->data);
2289 static HBITMAP WALL;
2290 static HBRUSH myBrush, oldBrush;
2292 static bool init_done = FALSE;
2295 WALL = LoadBitmap(hInstance, AppName);
2296 myBrush = CreatePatternBrush(WALL);
2301 /* Total rectangle */
2302 rc.left = x * td->tile_wid + td->size_ow1;
2303 rc.right = rc.left + n * td->tile_wid;
2304 rc.top = y * td->tile_hgt + td->size_oh1;
2305 rc.bottom = rc.top + td->tile_hgt;
2310 /* Background color */
2311 SetBkColor(hdc, RGB(0, 0, 0));
2313 /* Foreground color */
2316 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2320 SetTextColor(hdc, win_clr[a&0x0F]);
2324 SetTextColor(hdc, win_clr[a]);
2328 SelectObject(hdc, td->font_id);
2331 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2335 (td->tile_hgt != td->font_hgt) ||
2336 (td->tile_wid != td->font_wid))
2340 /* Erase complete rectangle */
2341 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2344 if (use_bg) DrawBG(hdc, &rc);
2347 rc.left += ((td->tile_wid - td->font_wid) / 2);
2348 rc.right = rc.left + td->font_wid;
2349 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2350 rc.bottom = rc.top + td->font_hgt;
2352 /* Dump each character */
2353 for (i = 0; i < n; i++)
2356 if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2358 rc.right += td->font_wid;
2360 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2365 rc.left += 2 * td->tile_wid;
2366 rc.right += 2 * td->tile_wid;
2367 } else if (*(s+i)==127){
2368 oldBrush = SelectObject(hdc, myBrush);
2369 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2372 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2374 SelectObject(hdc, oldBrush);
2375 SelectObject(hdc, oldPen);
2378 rc.left += td->tile_wid;
2379 rc.right += td->tile_wid;
2382 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2386 rc.left += td->tile_wid;
2387 rc.right += td->tile_wid;
2391 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2395 rc.left += td->tile_wid;
2396 rc.right += td->tile_wid;
2406 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2411 ReleaseDC(td->w, hdc);
2419 * Low level graphics. Assumes valid input.
2421 * Draw an array of "special" attr/char pairs at the given location.
2423 * We use the "Term_pict_win()" function for "graphic" data, which are
2424 * encoded by setting the "high-bits" of both the "attr" and the "char"
2425 * data. We use the "attr" to represent the "row" of the main bitmap,
2426 * and the "char" to represent the "col" of the main bitmap. The use
2427 * of this function is induced by the "higher_pict" flag.
2429 * If "graphics" is not available, we simply "wipe" the given grids.
2431 # ifdef USE_TRANSPARENCY
2432 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2433 # else /* USE_TRANSPARENCY */
2434 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp)
2435 # endif /* USE_TRANSPARENCY */
2437 term_data *td = (term_data*)(Term->data);
2443 int x2, y2, w2, h2, tw2;
2445 # ifdef USE_TRANSPARENCY
2451 # endif /* USE_TRANSPARENCY */
2460 /* Erase the grids */
2461 return (Term_wipe_win(x, y, n));
2464 /* Size of bitmap cell */
2465 w1 = infGraph.CellWidth;
2466 h1 = infGraph.CellHeight;
2468 /* Size of window cell */
2471 w2 = td->map_tile_wid;
2472 h2 = td->map_tile_hgt;
2481 if (use_bigtile) tw2 *= 2;
2484 /* Location of window cell */
2485 x2 = x * w2 + td->size_ow1;
2486 y2 = y * h2 + td->size_oh1;
2492 hdcSrc = CreateCompatibleDC(hdc);
2493 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2495 # ifdef USE_TRANSPARENCY
2497 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2499 hdcMask = CreateCompatibleDC(hdc);
2500 SelectObject(hdcMask, infMask.hBitmap);
2503 # endif /* USE_TRANSPARENCY */
2505 /* Draw attr/char pairs */
2506 for (i = 0; i < n; i++, x2 += w2)
2511 /* Extract picture */
2512 int row = (a & 0x7F);
2513 int col = (c & 0x7F);
2515 /* Location of bitmap cell */
2519 # ifdef USE_TRANSPARENCY
2521 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2523 x3 = (tcp[i] & 0x7F) * w1;
2524 y3 = (tap[i] & 0x7F) * h1;
2527 if ((w1 == tw2) && (h1 == h2))
2529 /* Copy the terrain picture from the bitmap to the window */
2530 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2532 /* Mask out the tile */
2533 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2536 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2539 /* Need to stretch */
2542 /* Set the correct mode for stretching the tiles */
2543 SetStretchBltMode(hdc, COLORONCOLOR);
2545 /* Copy the terrain picture from the bitmap to the window */
2546 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
2548 /* Only draw if terrain and overlay are different */
2549 if ((x1 != x3) || (y1 != y3))
2551 /* Mask out the tile */
2552 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2555 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2561 # endif /* USE_TRANSPARENCY */
2565 if ((w1 == tw2) && (h1 == h2))
2567 /* Copy the picture from the bitmap to the window */
2568 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2571 /* Need to stretch */
2574 /* Set the correct mode for stretching the tiles */
2575 SetStretchBltMode(hdc, COLORONCOLOR);
2577 /* Copy the picture from the bitmap to the window */
2578 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2584 SelectObject(hdcSrc, hbmSrcOld);
2587 # ifdef USE_TRANSPARENCY
2589 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2592 SelectObject(hdcMask, hbmSrcOld);
2596 # endif /* USE_TRANSPARENCY */
2599 ReleaseDC(td->w, hdc);
2601 #else /* USE_GRAPHICS */
2603 /* Just erase this grid */
2604 return (Term_wipe_win(x, y, n));
2606 #endif /* USE_GRAPHICS */
2613 #ifdef USE_TRANSPARENCY
2614 extern void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp);
2615 #else /* USE_TRANSPARENCY */
2616 extern void map_info(int y, int x, byte *ap, char *cp);
2617 #endif /* USE_TRANSPARENCY */
2620 static void windows_map(void)
2622 term_data *td = &data[0];
2624 int x, min_x, max_x;
2625 int y, min_y, max_y;
2627 #ifdef USE_TRANSPARENCY
2631 /* Only in graphics mode */
2632 if (!use_graphics) return;
2635 Term_xtra_win_clear();
2637 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2638 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2639 td->map_active = TRUE;
2649 for (x = min_x; x < max_x; x++)
2651 for (y = min_y; y < max_y; y++)
2653 #ifdef USE_TRANSPARENCY
2654 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
2655 #else /* USE_TRANSPARENCY */
2656 map_info(y, x, &a, (char*)&c);
2657 #endif /* USE_TRANSPARENCY */
2659 /* Ignore non-graphics */
2660 if ((a & 0x80) && (c & 0x80))
2662 #ifdef USE_TRANSPARENCY
2663 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2664 #else /* USE_TRANSPARENCY */
2665 Term_pict_win(x - min_x, y - min_y, 1, &a, &c);
2666 #endif /* USE_TRANSPARENCY */
2671 /* Hilite the player */
2672 Term_curs_win(px - min_x, py - min_y);
2674 /* Wait for a keypress, flush key buffer */
2675 Term_inkey(&c, TRUE, TRUE);
2678 /* Switch off the map display */
2679 td->map_active = FALSE;
2681 /* Restore screen */
2682 Term_xtra_win_clear();
2687 /*** Other routines ***/
2691 * Create and initialize a "term_data" given a title
2693 static void term_data_link(term_data *td)
2697 /* Initialize the term */
2698 term_init(t, td->cols, td->rows, td->keys);
2700 /* Use a "software" cursor */
2701 t->soft_cursor = TRUE;
2703 /* Use "Term_pict" for "graphic" data */
2704 t->higher_pict = TRUE;
2706 /* Erase with "white space" */
2707 t->attr_blank = TERM_WHITE;
2708 t->char_blank = ' ';
2711 /* Prepare the init/nuke hooks */
2712 t->init_hook = Term_init_win;
2713 t->nuke_hook = Term_nuke_win;
2716 /* Prepare the template hooks */
2717 t->user_hook = Term_user_win;
2718 t->xtra_hook = Term_xtra_win;
2719 t->curs_hook = Term_curs_win;
2720 t->wipe_hook = Term_wipe_win;
2721 t->text_hook = Term_text_win;
2722 t->pict_hook = Term_pict_win;
2724 /* Remember where we came from */
2725 t->data = (vptr)(td);
2730 * Create the windows
2732 * First, instantiate the "default" values, then read the "ini_file"
2733 * to over-ride selected values, then create the windows, and fonts.
2735 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2736 * must make active to realize the palette. XXX XXX XXX
2738 static void init_windows(void)
2750 WIPE(td, term_data);
2754 td->s = angband_term_name[0];
2772 for (i = 1; i < MAX_TERM_DATA; i++)
2775 WIPE(td, term_data);
2776 td->s = angband_term_name[i];
2780 td->visible = FALSE;
2785 td->pos_x = (7 - i) * 30;
2786 td->pos_y = (7 - i) * 20;
2797 /* Main window (need these before term_getsize gets called) */
2799 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2800 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2805 /* Sub windows (need these before term_getsize gets called) */
2806 for (i = 1; i < MAX_TERM_DATA; i++)
2809 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2810 td->dwExStyle = (WS_EX_TOOLWINDOW);
2815 for (i = 0; i < MAX_TERM_DATA; i++)
2820 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2821 td->lf.lfHeight = td->tile_hgt;
2822 td->lf.lfWidth = td->tile_wid;
2823 td->lf.lfCharSet = SHIFTJIS_CHARSET;
2824 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2825 /* Activate the chosen font */
2826 term_force_font(td, NULL);
2827 td->tile_wid = td->font_wid;
2828 td->tile_hgt = td->font_hgt;
2830 /* Access the standard font file */
2831 path_build(buf, 1024, ANGBAND_DIR_XTRA_FONT, td->font_want);
2833 /* Activate the chosen font */
2834 if (term_force_font(td, buf))
2836 /* Access the standard font file */
2837 path_build(buf, 1024, ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2839 /* Force the use of that font */
2840 (void)term_force_font(td, buf);
2846 /* Assume not bizarre */
2847 td->bizarre = FALSE;
2852 /* Analyze the font */
2855 /* Resize the window */
2856 term_window_resize(td);
2860 /* Sub windows (reverse order) */
2861 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
2866 td->w = CreateWindowEx(td->dwExStyle, AngList,
2868 td->pos_x, td->pos_y,
2869 td->size_wid, td->size_hgt,
2870 HWND_DESKTOP, NULL, hInstance, NULL);
2873 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
2875 if (!td->w) quit("Failed to create sub-window");
2881 td->size_hack = TRUE;
2882 ShowWindow(td->w, SW_SHOW);
2883 td->size_hack = FALSE;
2887 angband_term[i] = &td->t;
2891 /* Activate the window */
2892 SetActiveWindow(td->w);
2894 /* Bring window to top */
2895 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2905 td->w = CreateWindowEx(td->dwExStyle, AppName,
2907 td->pos_x, td->pos_y,
2908 td->size_wid, td->size_hgt,
2909 HWND_DESKTOP, NULL, hInstance, NULL);
2912 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
2914 if (!td->w) quit("Failed to create Angband window");
2919 angband_term[0] = &td->t;
2921 /* Activate the main window */
2922 SetActiveWindow(td->w);
2924 /* Bring main window back to top */
2925 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2928 /* New palette XXX XXX XXX */
2929 (void)new_palette();
2932 /* Create a "brush" for drawing the "cursor" */
2933 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
2936 /* Process pending messages */
2937 (void)Term_xtra_win_flush();
2945 static void setup_menus(void)
2949 HMENU hm = GetMenu(data[0].w);
2952 /* Menu "File", Disable all */
2953 EnableMenuItem(hm, IDM_FILE_NEW,
2954 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2955 EnableMenuItem(hm, IDM_FILE_OPEN,
2956 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2957 EnableMenuItem(hm, IDM_FILE_SAVE,
2958 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2959 EnableMenuItem(hm, IDM_FILE_EXIT,
2960 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2961 EnableMenuItem(hm, IDM_FILE_SCORE,
2962 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2965 /* No character available */
2966 if (!character_generated)
2968 /* Menu "File", Item "New" */
2969 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
2971 /* Menu "File", Item "Open" */
2972 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
2975 /* A character available */
2976 if (character_generated)
2978 /* Menu "File", Item "Save" */
2979 EnableMenuItem(hm, IDM_FILE_SAVE,
2980 MF_BYCOMMAND | MF_ENABLED);
2983 /* Menu "File", Item "Exit" */
2984 EnableMenuItem(hm, IDM_FILE_EXIT,
2985 MF_BYCOMMAND | MF_ENABLED);
2987 EnableMenuItem(hm, IDM_FILE_SCORE,
2988 MF_BYCOMMAND | MF_ENABLED);
2991 /* Menu "Window::Visibility" */
2992 for (i = 0; i < MAX_TERM_DATA; i++)
2994 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
2995 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2997 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
2998 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3000 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3001 MF_BYCOMMAND | MF_ENABLED);
3004 /* Menu "Window::Font" */
3005 for (i = 0; i < MAX_TERM_DATA; i++)
3007 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3008 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3010 if (data[i].visible)
3012 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3013 MF_BYCOMMAND | MF_ENABLED);
3017 /* Menu "Window::Bizarre Display" */
3018 for (i = 0; i < MAX_TERM_DATA; i++)
3020 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3021 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3023 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3024 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3026 if (data[i].visible)
3028 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3029 MF_BYCOMMAND | MF_ENABLED);
3034 /* Menu "Window::Increase Tile Width" */
3035 for (i = 0; i < MAX_TERM_DATA; i++)
3037 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3038 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3040 if (data[i].visible)
3042 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3043 MF_BYCOMMAND | MF_ENABLED);
3048 /* Menu "Window::Decrease Tile Width" */
3049 for (i = 0; i < MAX_TERM_DATA; i++)
3051 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3052 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3054 if (data[i].visible)
3056 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3057 MF_BYCOMMAND | MF_ENABLED);
3062 /* Menu "Window::Increase Tile Height" */
3063 for (i = 0; i < MAX_TERM_DATA; i++)
3065 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3066 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3068 if (data[i].visible)
3070 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3071 MF_BYCOMMAND | MF_ENABLED);
3076 /* Menu "Window::Decrease Tile Height" */
3077 for (i = 0; i < MAX_TERM_DATA; i++)
3079 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3080 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3082 if (data[i].visible)
3084 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3085 MF_BYCOMMAND | MF_ENABLED);
3090 /* Menu "Options", disable all */
3091 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3092 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3093 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3094 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3095 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3096 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3097 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3098 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3099 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3100 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3102 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3103 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3106 /* Menu "Options", Item "Map" */
3107 if (use_graphics != GRAPHICS_NONE)
3108 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3110 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3111 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3113 /* Menu "Options", update all */
3114 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3115 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3116 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3117 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3118 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3119 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3120 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3121 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3122 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3123 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3124 CheckMenuItem(hm, IDM_OPTIONS_BG,
3125 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3127 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3128 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3132 /* Menu "Options", Item "Graphics" */
3133 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3134 /* Menu "Options", Item "Graphics" */
3135 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3136 /* Menu "Options", Item "Graphics" */
3137 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3138 /* Menu "Options", Item "Graphics" */
3139 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3140 #endif /* USE_GRAPHICS */
3143 /* Menu "Options", Item "Sound" */
3144 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3145 #endif /* USE_SOUND */
3148 /* Menu "Options", Item "ScreenSaver" */
3149 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3150 MF_BYCOMMAND | MF_ENABLED);
3151 #endif /* USE_SAVER */
3156 * Check for double clicked (or dragged) savefile
3158 * Apparently, Windows copies the entire filename into the first
3159 * piece of the "command line string". Perhaps we should extract
3160 * the "basename" of that filename and append it to the "save" dir.
3162 static void check_for_save_file(LPSTR cmd_line)
3172 /* Extract filename */
3173 strcat(savefile, s);
3175 /* Validate the file */
3176 validate_file(savefile);
3178 /* Game in progress */
3179 game_in_progress = TRUE;
3187 * Process a menu command
3189 static void process_menus(WORD wCmd)
3206 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3208 plog("You cannot do that yet...");
3212 else if (game_in_progress)
3215 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3217 plog("You can't start a new game while you're still playing!");
3223 game_in_progress = TRUE;
3237 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3239 plog("You cannot do that yet...");
3243 else if (game_in_progress)
3246 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3248 plog("You can't open a new game while you're still playing!");
3254 memset(&ofn, 0, sizeof(ofn));
3255 ofn.lStructSize = sizeof(ofn);
3256 ofn.hwndOwner = data[0].w;
3257 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3258 ofn.nFilterIndex = 1;
3259 ofn.lpstrFile = savefile;
3260 ofn.nMaxFile = 1024;
3261 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3262 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3264 if (GetOpenFileName(&ofn))
3266 /* Load 'savefile' */
3267 validate_file(savefile);
3268 game_in_progress = TRUE;
3280 if (game_in_progress && character_generated)
3286 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3288 plog("You may not do that right now.");
3294 /* Hack -- Forget messages */
3299 do_cmd_save_game(FALSE);
3300 #else /* ZANGBAND */
3302 #endif /* ZANGBAND */
3307 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3309 plog("You may not do that right now.");
3319 if (game_in_progress && character_generated)
3325 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3327 plog("You may not do that right now.");
3333 /* Hack -- Forget messages */
3342 do_cmd_save_game(FALSE);
3343 #else /* ZANGBAND */
3345 #endif /* ZANGBAND */
3352 case IDM_FILE_SCORE:
3356 /* Build the filename */
3357 path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw");
3359 /* Open the binary high score file, for reading */
3360 highscore_fd = fd_open(buf, O_RDONLY);
3362 /* Paranoia -- No score file */
3363 if (highscore_fd < 0)
3365 msg_print("Score file unavailable.");
3375 /* Display the scores */
3376 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3378 /* Shut the high score file */
3379 (void)fd_close(highscore_fd);
3381 /* Forget the high score fd */
3387 /* Hack - Flush it */
3395 case IDM_WINDOW_VIS_0:
3398 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3400 plog("You are not allowed to do that!");
3407 /* Window visibility */
3408 case IDM_WINDOW_VIS_1:
3409 case IDM_WINDOW_VIS_2:
3410 case IDM_WINDOW_VIS_3:
3411 case IDM_WINDOW_VIS_4:
3412 case IDM_WINDOW_VIS_5:
3413 case IDM_WINDOW_VIS_6:
3414 case IDM_WINDOW_VIS_7:
3416 i = wCmd - IDM_WINDOW_VIS_0;
3418 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3425 ShowWindow(td->w, SW_SHOW);
3426 term_data_redraw(td);
3430 td->visible = FALSE;
3431 ShowWindow(td->w, SW_HIDE);
3438 case IDM_WINDOW_FONT_0:
3439 case IDM_WINDOW_FONT_1:
3440 case IDM_WINDOW_FONT_2:
3441 case IDM_WINDOW_FONT_3:
3442 case IDM_WINDOW_FONT_4:
3443 case IDM_WINDOW_FONT_5:
3444 case IDM_WINDOW_FONT_6:
3445 case IDM_WINDOW_FONT_7:
3447 i = wCmd - IDM_WINDOW_FONT_0;
3449 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3453 term_change_font(td);
3458 /* Bizarre Display */
3459 case IDM_WINDOW_BIZ_0:
3460 case IDM_WINDOW_BIZ_1:
3461 case IDM_WINDOW_BIZ_2:
3462 case IDM_WINDOW_BIZ_3:
3463 case IDM_WINDOW_BIZ_4:
3464 case IDM_WINDOW_BIZ_5:
3465 case IDM_WINDOW_BIZ_6:
3466 case IDM_WINDOW_BIZ_7:
3468 i = wCmd - IDM_WINDOW_BIZ_0;
3470 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3474 td->bizarre = !td->bizarre;
3478 term_window_resize(td);
3483 /* Increase Tile Width */
3484 case IDM_WINDOW_I_WID_0:
3485 case IDM_WINDOW_I_WID_1:
3486 case IDM_WINDOW_I_WID_2:
3487 case IDM_WINDOW_I_WID_3:
3488 case IDM_WINDOW_I_WID_4:
3489 case IDM_WINDOW_I_WID_5:
3490 case IDM_WINDOW_I_WID_6:
3491 case IDM_WINDOW_I_WID_7:
3493 i = wCmd - IDM_WINDOW_I_WID_0;
3495 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3503 term_window_resize(td);
3508 /* Decrease Tile Height */
3509 case IDM_WINDOW_D_WID_0:
3510 case IDM_WINDOW_D_WID_1:
3511 case IDM_WINDOW_D_WID_2:
3512 case IDM_WINDOW_D_WID_3:
3513 case IDM_WINDOW_D_WID_4:
3514 case IDM_WINDOW_D_WID_5:
3515 case IDM_WINDOW_D_WID_6:
3516 case IDM_WINDOW_D_WID_7:
3518 i = wCmd - IDM_WINDOW_D_WID_0;
3520 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3528 term_window_resize(td);
3533 /* Increase Tile Height */
3534 case IDM_WINDOW_I_HGT_0:
3535 case IDM_WINDOW_I_HGT_1:
3536 case IDM_WINDOW_I_HGT_2:
3537 case IDM_WINDOW_I_HGT_3:
3538 case IDM_WINDOW_I_HGT_4:
3539 case IDM_WINDOW_I_HGT_5:
3540 case IDM_WINDOW_I_HGT_6:
3541 case IDM_WINDOW_I_HGT_7:
3543 i = wCmd - IDM_WINDOW_I_HGT_0;
3545 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3553 term_window_resize(td);
3558 /* Decrease Tile Height */
3559 case IDM_WINDOW_D_HGT_0:
3560 case IDM_WINDOW_D_HGT_1:
3561 case IDM_WINDOW_D_HGT_2:
3562 case IDM_WINDOW_D_HGT_3:
3563 case IDM_WINDOW_D_HGT_4:
3564 case IDM_WINDOW_D_HGT_5:
3565 case IDM_WINDOW_D_HGT_6:
3566 case IDM_WINDOW_D_HGT_7:
3568 i = wCmd - IDM_WINDOW_D_HGT_0;
3570 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3578 term_window_resize(td);
3583 case IDM_OPTIONS_NO_GRAPHICS:
3588 plog("You may not do that right now.");
3592 /* Toggle "arg_graphics" */
3593 if (arg_graphics != GRAPHICS_NONE)
3595 arg_graphics = GRAPHICS_NONE;
3597 /* React to changes */
3598 Term_xtra_win_react();
3600 /* Hack -- Force redraw */
3601 Term_key_push(KTRL('R'));
3607 case IDM_OPTIONS_OLD_GRAPHICS:
3612 plog("You may not do that right now.");
3616 /* Toggle "arg_graphics" */
3617 if (arg_graphics != GRAPHICS_ORIGINAL)
3619 arg_graphics = GRAPHICS_ORIGINAL;
3621 /* React to changes */
3622 Term_xtra_win_react();
3624 /* Hack -- Force redraw */
3625 Term_key_push(KTRL('R'));
3631 case IDM_OPTIONS_NEW_GRAPHICS:
3636 plog("You may not do that right now.");
3640 /* Toggle "arg_graphics" */
3641 if (arg_graphics != GRAPHICS_ADAM_BOLT)
3643 arg_graphics = GRAPHICS_ADAM_BOLT;
3645 /* React to changes */
3646 Term_xtra_win_react();
3648 /* Hack -- Force redraw */
3649 Term_key_push(KTRL('R'));
3655 case IDM_OPTIONS_BIGTILE:
3657 term_data *td = &data[0];
3662 plog("You may not do that right now.");
3666 /* Toggle "arg_sound" */
3667 arg_bigtile = !arg_bigtile;
3670 Term_activate(&td->t);
3672 /* Resize the term */
3673 Term_resize(td->cols, td->rows);
3676 InvalidateRect(td->w, NULL, TRUE);
3681 case IDM_OPTIONS_SOUND:
3686 plog("You may not do that right now.");
3690 /* Toggle "arg_sound" */
3691 arg_sound = !arg_sound;
3693 /* React to changes */
3694 Term_xtra_win_react();
3696 /* Hack -- Force redraw */
3697 Term_key_push(KTRL('R'));
3703 case IDM_OPTIONS_BG:
3708 plog("You may not do that right now.");
3712 /* Toggle "use_bg" */
3717 /* React to changes */
3718 Term_xtra_win_react();
3720 /* Hack -- Force redraw */
3721 Term_key_push(KTRL('R'));
3727 case IDM_OPTIONS_OPEN_BG:
3732 plog("You may not do that right now.");
3737 memset(&ofn, 0, sizeof(ofn));
3738 ofn.lStructSize = sizeof(ofn);
3739 ofn.hwndOwner = data[0].w;
3740 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3741 ofn.nFilterIndex = 1;
3742 ofn.lpstrFile = bg_bitmap_file;
3743 ofn.nMaxFile = 1023;
3744 ofn.lpstrInitialDir = NULL;
3746 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
3748 ofn.lpstrTitle = "Choose wall paper.";
3750 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3752 if (GetOpenFileName(&ofn))
3754 /* Load 'savefile' */
3759 /* React to changes */
3760 Term_xtra_win_react();
3762 /* Hack -- Force redraw */
3763 Term_key_push(KTRL('R'));
3768 case IDM_DUMP_SCREEN_HTML:
3770 static char buf[1024] = "";
3771 memset(&ofn, 0, sizeof(ofn));
3772 ofn.lStructSize = sizeof(ofn);
3773 ofn.hwndOwner = data[0].w;
3774 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
3775 ofn.nFilterIndex = 1;
3776 ofn.lpstrFile = buf;
3777 ofn.nMaxFile = 1023;
3778 ofn.lpstrDefExt = "html";
3779 ofn.lpstrInitialDir = NULL;
3781 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
3783 ofn.lpstrTitle = "Save screen dump as HTML.";
3785 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
3787 if (GetSaveFileName(&ofn))
3789 extern void do_cmd_save_screen_html_aux(char *filename, int message);
3790 do_cmd_save_screen_html_aux(buf, 0);
3797 case IDM_OPTIONS_SAVER:
3801 DestroyWindow(hwndSaver);
3806 /* Create a screen scaver window */
3807 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
3808 "Angband Screensaver",
3809 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
3810 0, 0, GetSystemMetrics(SM_CXSCREEN),
3811 GetSystemMetrics(SM_CYSCREEN),
3812 NULL, NULL, hInstance, NULL);
3816 /* Push the window to the bottom XXX XXX XXX */
3817 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3822 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
3824 plog("Failed to create saver window");
3834 case IDM_OPTIONS_MAP:
3840 case IDM_HELP_CONTENTS:
3844 path_build(tmp, 1024, ANGBAND_DIR_XTRA_HELP, "zangband.chm");
3845 if (check_file(tmp))
3847 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
3852 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
3853 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
3855 plog_fmt("Cannot find help file: %s", tmp);
3856 plog("Use the online help files instead.");
3861 #else /* HTML_HELP */
3864 path_build(tmp, 1024, ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
3865 if (check_file(tmp))
3867 sprintf(buf, "winhelp.exe %s", tmp);
3868 WinExec(buf, SW_NORMAL);
3873 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
3874 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
3876 plog_fmt("Cannot find help file: %s", tmp);
3877 plog("Use the online help files instead.");
3882 #endif /* HTML_HELP */
3890 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
3891 WPARAM wParam, LPARAM lParam);
3892 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
3893 WPARAM wParam, LPARAM lParam)
3894 #else /* __MWERKS__ */
3895 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
3896 WPARAM wParam, LPARAM lParam)
3897 #endif /* __MWERKS__ */
3903 MINMAXINFO FAR *lpmmi;
3909 /* Acquire proper "term_data" info */
3910 td = (term_data *)GetWindowLong(hWnd, 0);
3912 /* Handle message */
3918 SetWindowLong(hWnd, 0, (LONG)(my_td));
3928 case WM_GETMINMAXINFO:
3931 lpmmi = (MINMAXINFO FAR *)lParam;
3933 /* this message was sent before WM_NCCREATE */
3936 /* Minimum window size is 8x2 */
3937 rc.left = rc.top = 0;
3938 rc.right = rc.left + 8 * td->tile_wid + td->size_ow1 + td->size_ow2;
3939 rc.bottom = rc.top + 2 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
3942 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3944 /* Save minimum size */
3945 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
3946 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
3948 /* Maximum window size */
3949 rc.left = rc.top = 0;
3950 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
3951 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2;
3954 rc.right += (td->tile_wid - 1);
3955 rc.bottom += (td->tile_hgt - 1);
3958 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3960 /* Save maximum size */
3961 lpmmi->ptMaxSize.x = rc.right - rc.left;
3962 lpmmi->ptMaxSize.y = rc.bottom - rc.top;
3964 /* Save maximum size */
3965 lpmmi->ptMaxTrackSize.x = rc.right - rc.left;
3966 lpmmi->ptMaxTrackSize.y = rc.bottom - rc.top;
3973 BeginPaint(hWnd, &ps);
3974 if (td) term_data_redraw(td);
3975 EndPaint(hWnd, &ps);
3976 ValidateRect(hWnd, NULL);
3987 /* Extract the modifiers */
3988 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
3989 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
3990 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
3992 /* Handle "special" keys */
3993 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
3995 /* Begin the macro trigger */
3998 /* Send the modifiers */
3999 if (mc) Term_keypress('C');
4000 if (ms) Term_keypress('S');
4001 if (ma) Term_keypress('A');
4003 /* Extract "scan code" */
4004 i = LOBYTE(HIWORD(lParam));
4006 /* Introduce the scan code */
4009 /* Encode the hexidecimal scan code */
4010 Term_keypress(hexsym[i/16]);
4011 Term_keypress(hexsym[i%16]);
4013 /* End the macro trigger */
4024 Term_keypress(wParam);
4036 if (game_in_progress && character_generated)
4040 plog("You may not do that right now.");
4044 /* Hack -- Forget messages */
4053 do_cmd_save_game(FALSE);
4054 #else /* ZANGBAND */
4056 #endif /* ZANGBAND */
4070 process_menus(LOWORD(wParam));
4076 /* this message was sent before WM_NCCREATE */
4079 /* it was sent from inside CreateWindowEx */
4080 if (!td->w) return 1;
4082 /* was sent from WM_SIZE */
4083 if (td->size_hack) return 1;
4087 case SIZE_MINIMIZED:
4089 /* Hide sub-windows */
4090 for (i = 1; i < MAX_TERM_DATA; i++)
4092 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4097 case SIZE_MAXIMIZED:
4099 /* fall through XXX XXX XXX */
4104 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4105 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4108 if ((td->cols != cols) || (td->rows != rows))
4110 /* Save the new size */
4115 Term_activate(&td->t);
4117 /* Resize the term */
4118 Term_resize(td->cols, td->rows);
4121 InvalidateRect(td->w, NULL, TRUE);
4124 td->size_hack = TRUE;
4126 /* Show sub-windows */
4127 for (i = 1; i < MAX_TERM_DATA; i++)
4129 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4132 td->size_hack = FALSE;
4140 case WM_PALETTECHANGED:
4142 /* Ignore if palette change caused by itself */
4143 if ((HWND)wParam == hWnd) return 0;
4145 /* Fall through... */
4148 case WM_QUERYNEWPALETTE:
4150 if (!paletted) return 0;
4154 SelectPalette(hdc, hPal, FALSE);
4156 i = RealizePalette(hdc);
4158 /* if any palette entries changed, repaint the window. */
4159 if (i) InvalidateRect(hWnd, NULL, TRUE);
4161 ReleaseDC(hWnd, hdc);
4168 if (wParam && !HIWORD(lParam))
4170 /* Do something to sub-windows */
4171 for (i = 1; i < MAX_TERM_DATA; i++)
4173 SetWindowPos(data[i].w, hWnd, 0, 0, 0, 0,
4174 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
4177 /* Focus on main window */
4187 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4192 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4193 WPARAM wParam, LPARAM lParam);
4194 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4195 WPARAM wParam, LPARAM lParam)
4196 #else /* __MWERKS__ */
4197 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4198 WPARAM wParam, LPARAM lParam)
4199 #endif /* __MWERKS__ */
4203 MINMAXINFO FAR *lpmmi;
4211 /* Acquire proper "term_data" info */
4212 td = (term_data *)GetWindowLong(hWnd, 0);
4214 /* Process message */
4220 SetWindowLong(hWnd, 0, (LONG)(my_td));
4230 case WM_GETMINMAXINFO:
4233 /* this message was sent before WM_NCCREATE */
4236 lpmmi = (MINMAXINFO FAR *)lParam;
4239 rc.left = rc.top = 0;
4240 rc.right = rc.left + 8 * td->tile_wid + td->size_ow1 + td->size_ow2;
4241 rc.bottom = rc.top + 2 * td->tile_hgt + td->size_oh1 + td->size_oh2;
4244 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4246 /* Save the minimum size */
4247 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4248 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4250 /* Maximum window size */
4251 rc.left = rc.top = 0;
4252 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4253 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2;
4256 rc.right += (td->tile_wid - 1);
4257 rc.bottom += (td->tile_hgt - 1);
4260 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4262 /* Save maximum size */
4263 lpmmi->ptMaxSize.x = rc.right - rc.left;
4264 lpmmi->ptMaxSize.y = rc.bottom - rc.top;
4266 /* Save the maximum size */
4267 lpmmi->ptMaxTrackSize.x = rc.right - rc.left;
4268 lpmmi->ptMaxTrackSize.y = rc.bottom - rc.top;
4278 /* this message was sent before WM_NCCREATE */
4281 /* it was sent from inside CreateWindowEx */
4282 if (!td->w) return 1;
4284 /* was sent from inside WM_SIZE */
4285 if (td->size_hack) return 1;
4287 td->size_hack = TRUE;
4289 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4290 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4293 if ((td->cols != cols) || (td->rows != rows))
4296 term *old_term = Term;
4298 /* Save the new size */
4303 Term_activate(&td->t);
4305 /* Resize the term */
4306 Term_resize(td->cols, td->rows);
4309 Term_activate(old_term);
4312 InvalidateRect(td->w, NULL, TRUE);
4314 /* HACK - Redraw all windows */
4315 p_ptr->window = 0xFFFFFFFF;
4319 td->size_hack = FALSE;
4326 BeginPaint(hWnd, &ps);
4327 if (td) term_data_redraw(td);
4328 EndPaint(hWnd, &ps);
4339 /* Extract the modifiers */
4340 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4341 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4342 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4344 /* Handle "special" keys */
4345 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4347 /* Begin the macro trigger */
4350 /* Send the modifiers */
4351 if (mc) Term_keypress('C');
4352 if (ms) Term_keypress('S');
4353 if (ma) Term_keypress('A');
4355 /* Extract "scan code" */
4356 i = LOBYTE(HIWORD(lParam));
4358 /* Introduce the scan code */
4361 /* Encode the hexidecimal scan code */
4362 Term_keypress(hexsym[i/16]);
4363 Term_keypress(hexsym[i%16]);
4365 /* End the macro trigger */
4376 Term_keypress(wParam);
4380 case WM_PALETTECHANGED:
4382 /* ignore if palette change caused by itself */
4383 if ((HWND)wParam == hWnd) return FALSE;
4384 /* otherwise, fall through!!! */
4387 case WM_QUERYNEWPALETTE:
4389 if (!paletted) return 0;
4391 SelectPalette(hdc, hPal, FALSE);
4392 i = RealizePalette(hdc);
4393 /* if any palette entries changed, repaint the window. */
4394 if (i) InvalidateRect(hWnd, NULL, TRUE);
4395 ReleaseDC(hWnd, hdc);
4399 case WM_NCLBUTTONDOWN:
4403 if (wParam == HTCLOSE) wParam = HTSYSMENU;
4404 #endif /* HTCLOSE */
4406 if (wParam == HTSYSMENU)
4410 td->visible = FALSE;
4411 ShowWindow(td->w, SW_HIDE);
4421 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4427 #define MOUSE_SENS 40
4430 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4431 WPARAM wParam, LPARAM lParam);
4432 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4433 WPARAM wParam, LPARAM lParam)
4434 #else /* __MWERKS__ */
4435 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4436 WPARAM wParam, LPARAM lParam)
4437 #endif /* __MWERKS__ */
4439 static int iMouse = 0;
4440 static WORD xMouse = 0;
4441 static WORD yMouse = 0;
4464 if (LOWORD(wParam) == WA_INACTIVE) break;
4466 /* else fall through */
4470 case WM_LBUTTONDOWN:
4471 case WM_MBUTTONDOWN:
4472 case WM_RBUTTONDOWN:
4475 SendMessage(hWnd, WM_CLOSE, 0, 0);
4483 dx = LOWORD(lParam) - xMouse;
4484 dy = HIWORD(lParam) - yMouse;
4486 if (dx < 0) dx = -dx;
4487 if (dy < 0) dy = -dy;
4489 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
4491 SendMessage(hWnd, WM_CLOSE, 0, 0);
4495 /* Save last location */
4497 xMouse = LOWORD(lParam);
4498 yMouse = HIWORD(lParam);
4505 DestroyWindow(hwndSaver);
4512 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4515 #endif /* USE_SAVER */
4521 /*** Temporary Hooks ***/
4525 * Display warning message (see "z-util.c")
4527 static void hack_plog(cptr str)
4529 /* Give a warning */
4533 MessageBox(NULL, str, "·Ù¹ð¡ª",
4534 MB_ICONEXCLAMATION | MB_OK);
4536 MessageBox(NULL, str, "Warning",
4537 MB_ICONEXCLAMATION | MB_OK);
4545 * Display error message and quit (see "z-util.c")
4547 static void hack_quit(cptr str)
4549 /* Give a warning */
4553 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
4554 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4556 MessageBox(NULL, str, "Error",
4557 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4562 /* Unregister the classes */
4563 UnregisterClass(AppName, hInstance);
4565 /* Destroy the icon */
4566 if (hIcon) DestroyIcon(hIcon);
4574 /*** Various hooks ***/
4578 * Display warning message (see "z-util.c")
4580 static void hook_plog(cptr str)
4586 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
4587 MB_ICONEXCLAMATION | MB_OK);
4589 MessageBox(data[0].w, str, "Warning",
4590 MB_ICONEXCLAMATION | MB_OK);
4598 * Display error message and quit (see "z-util.c")
4600 static void hook_quit(cptr str)
4605 /* Give a warning */
4609 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
4610 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4612 MessageBox(data[0].w, str, "Error",
4613 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4619 /* Save the preferences */
4623 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
4625 /* Destroy all windows */
4626 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
4628 term_force_font(&data[i], NULL);
4629 if (data[i].font_want) string_free(data[i].font_want);
4630 if (data[i].w) DestroyWindow(data[i].w);
4634 /* Free the bitmap stuff */
4636 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
4637 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
4639 #ifdef USE_TRANSPARENCY
4640 if (infMask.hPalette) DeleteObject(infMask.hPalette);
4641 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
4642 #endif /* USE_TRANSPARENCY */
4644 #endif /* USE_GRAPHICS */
4646 /*** Free some other stuff ***/
4648 DeleteObject(hbrYellow);
4653 if (hPal) DeleteObject(hPal);
4655 UnregisterClass(AppName, hInstance);
4657 if (hIcon) DestroyIcon(hIcon);
4664 /*** Initialize ***/
4670 static void init_stuff(void)
4677 /* Get program name with full path */
4678 GetModuleFileName(hInstance, path, 512);
4680 /* Save the "program name" XXX XXX XXX */
4683 /* Get the name of the "*.ini" file */
4684 strcpy(path + strlen(path) - 4, ".INI");
4686 /* Save the the name of the ini-file */
4687 ini_file = string_make(path);
4689 /* Analyze the path */
4695 if (path[i] == '\\')
4702 /* Add "lib" to the path */
4703 strcpy(path + i + 1, "lib\\");
4705 /* Validate the path */
4706 validate_dir(path, TRUE);
4708 /* Init the file paths */
4709 init_file_paths(path);
4711 /* Hack -- Validate the paths */
4712 validate_dir(ANGBAND_DIR_APEX, FALSE);
4713 validate_dir(ANGBAND_DIR_BONE, FALSE);
4715 /* Allow missing 'edit' directory */
4716 if (!check_dir(ANGBAND_DIR_EDIT))
4718 /* Must have 'data'! */
4719 validate_dir(ANGBAND_DIR_DATA, TRUE);
4723 /* Don't need 'data' */
4724 validate_dir(ANGBAND_DIR_DATA, FALSE);
4727 validate_dir(ANGBAND_DIR_FILE, TRUE);
4728 validate_dir(ANGBAND_DIR_HELP, FALSE);
4729 validate_dir(ANGBAND_DIR_INFO, FALSE);
4730 validate_dir(ANGBAND_DIR_PREF, TRUE);
4731 validate_dir(ANGBAND_DIR_SAVE, FALSE);
4732 validate_dir(ANGBAND_DIR_USER, TRUE);
4733 validate_dir(ANGBAND_DIR_XTRA, TRUE);
4735 /* Build the filename */
4737 path_build(path, 1024, ANGBAND_DIR_FILE, "news_j.txt");
4739 path_build(path, 1024, ANGBAND_DIR_FILE, "news.txt");
4743 /* Hack -- Validate the "news.txt" file */
4744 validate_file(path);
4748 /* Build the "font" path */
4749 path_build(path, 1024, ANGBAND_DIR_XTRA, "font");
4751 /* Allocate the path */
4752 ANGBAND_DIR_XTRA_FONT = string_make(path);
4754 /* Validate the "font" directory */
4755 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
4757 /* Build the filename */
4758 path_build(path, 1024, ANGBAND_DIR_XTRA_FONT, "8X13.FON");
4760 /* Hack -- Validate the basic font */
4761 validate_file(path);
4767 /* Build the "graf" path */
4768 path_build(path, 1024, ANGBAND_DIR_XTRA, "graf");
4770 /* Allocate the path */
4771 ANGBAND_DIR_XTRA_GRAF = string_make(path);
4773 /* Validate the "graf" directory */
4774 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
4776 #endif /* USE_GRAPHICS */
4781 /* Build the "sound" path */
4782 path_build(path, 1024, ANGBAND_DIR_XTRA, "sound");
4784 /* Allocate the path */
4785 ANGBAND_DIR_XTRA_SOUND = string_make(path);
4787 /* Validate the "sound" directory */
4788 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
4790 #endif /* USE_SOUND */
4794 /* Build the "music" path */
4795 path_build(path, 1024, ANGBAND_DIR_XTRA, "music");
4797 /* Allocate the path */
4798 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
4800 /* Validate the "music" directory */
4801 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
4803 #endif /* USE_MUSIC */
4805 /* Build the "help" path */
4806 path_build(path, 1024, ANGBAND_DIR_XTRA, "help");
4808 /* Allocate the path */
4809 ANGBAND_DIR_XTRA_HELP = string_make(path);
4811 /* Validate the "help" directory */
4812 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
4816 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
4817 LPSTR lpCmdLine, int nCmdShow)
4829 if (hPrevInst == NULL)
4831 wc.style = CS_CLASSDC;
4832 wc.lpfnWndProc = AngbandWndProc;
4834 wc.cbWndExtra = 4; /* one long pointer to term_data */
4835 wc.hInstance = hInst;
4836 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
4837 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
4838 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
4839 wc.lpszMenuName = AppName;
4840 wc.lpszClassName = AppName;
4842 if (!RegisterClass(&wc)) exit(1);
4844 wc.lpfnWndProc = AngbandListProc;
4845 wc.lpszMenuName = NULL;
4846 wc.lpszClassName = AngList;
4848 if (!RegisterClass(&wc)) exit(2);
4852 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
4853 wc.lpfnWndProc = AngbandSaverProc;
4855 wc.lpszMenuName = NULL;
4856 wc.lpszClassName = "WindowsScreenSaverClass";
4858 if (!RegisterClass(&wc)) exit(3);
4864 /* Temporary hooks */
4865 plog_aux = hack_plog;
4866 quit_aux = hack_quit;
4867 core_aux = hack_quit;
4869 /* Prepare the filepaths */
4872 /* Initialize the keypress analyzer */
4873 for (i = 0; special_key_list[i]; ++i)
4875 special_key[special_key_list[i]] = TRUE;
4877 /* Initialize the keypress analyzer */
4878 for (i = 0; ignore_key_list[i]; ++i)
4880 ignore_key[ignore_key_list[i]] = TRUE;
4883 /* Determine if display is 16/256/true color */
4885 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
4886 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
4887 ReleaseDC(NULL, hdc);
4889 /* Initialize the colors */
4890 for (i = 0; i < 256; i++)
4894 /* Extract desired values */
4895 rv = angband_color_table[i][1];
4896 gv = angband_color_table[i][2];
4897 bv = angband_color_table[i][3];
4899 /* Extract the "complex" code */
4900 win_clr[i] = PALETTERGB(rv, gv, bv);
4902 /* Save the "simple" code */
4903 angband_color_table[i][0] = win_pal[i];
4906 /* Prepare the windows */
4912 /* Activate hooks */
4913 plog_aux = hook_plog;
4914 quit_aux = hook_quit;
4915 core_aux = hook_quit;
4917 /* Set the system suffix */
4918 ANGBAND_SYS = "win";
4920 /* Set the keyboard suffix */
4921 if (7 != GetKeyboardType(0))
4922 ANGBAND_KEYBOARD = "0";
4925 /* Japanese keyboard */
4926 switch (GetKeyboardType(1))
4928 case 0x0D01: case 0x0D02:
4929 case 0x0D03: case 0x0D04:
4930 case 0x0D05: case 0x0D06:
4932 ANGBAND_KEYBOARD = "NEC98";
4936 ANGBAND_KEYBOARD = "JAPAN";
4944 /* We are now initialized */
4948 if(lpCmdLine[0] == '-'){
4949 switch(lpCmdLine[1])
4953 if (!lpCmdLine[2]) break;
4954 chuukei_server = TRUE;
4955 if(connect_chuukei_server(&lpCmdLine[2])<0){
4956 msg_print("connect fail");
4959 msg_print("connect");
4966 if (!lpCmdLine[2]) break;
4967 chuukei_client = TRUE;
4968 connect_chuukei_server(&lpCmdLine[2]);
4978 /* Did the user double click on a save file? */
4979 if(!chuukei_server) check_for_save_file(lpCmdLine);
4981 /* Did the user double click on a save file? */
4982 check_for_save_file(lpCmdLine);
4985 /* Prompt the user */
4987 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
4989 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
4994 /* Process messages forever */
4995 while (GetMessage(&msg, NULL, 0, 0))
4997 TranslateMessage(&msg);
4998 DispatchMessage(&msg);
5009 #endif /* WINDOWS */