4 * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies.
13 * This file helps Angband work with Windows computers.
15 * To use this file, use an appropriate "Makefile" or "Project File",
16 * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
17 * make sure to obtain various extra files as described below.
19 * The official compilation uses the CodeWarrior Pro compiler, which
20 * includes a special project file and precompilable header file.
23 * See also "main-dos.c" and "main-ibm.c".
26 * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
27 * and/or color redefinitions.
29 * The "lib/user/font-win.prf" contains attr/char mappings for use with the
30 * normal "lib/xtra/font/*.fon" font files.
32 * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
33 * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
37 * Compiling this file, and using the resulting executable, requires
38 * several extra files not distributed with the standard Angband code.
39 * If "USE_GRAPHICS" is defined, then "readdib.h" and "readdib.c" must
40 * be placed into "src/", and the "8X8.BMP" bitmap file must be placed
41 * into "lib/xtra/graf". In any case, some "*.fon" files (including
42 * "8X13.FON" if nothing else) must be placed into "lib/xtra/font/".
43 * If "USE_SOUND" is defined, then some special library (for example,
44 * "winmm.lib") may need to be linked in, and desired "*.WAV" sound
45 * files must be placed into "lib/xtra/sound/". All of these extra
46 * files can be found in the "ext-win" archive.
49 * The "Term_xtra_win_clear()" function should probably do a low-level
50 * clear of the current window, and redraw the borders and other things,
51 * if only for efficiency. XXX XXX XXX
53 * A simpler method is needed for selecting the "tile size" for windows.
56 * The various "warning" messages assume the existance of the "screen.w"
57 * window, I think, and only a few calls actually check for its existance,
58 * this may be okay since "NULL" means "on top of all windows". (?) The
59 * user must never be allowed to "hide" the main window, or the "menubar"
60 * will disappear. XXX XXX XXX
62 * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
63 * use with the "winhelp.exe" program. These files *may* be available
64 * at the ftp site somewhere, but I have not seen them. XXX XXX XXX
67 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
69 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
71 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
72 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
83 * Extract the "WIN32" flag from the compiler
85 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
93 * Hack -- allow use of "screen saver" mode
99 * Menu constants -- see "ANGBAND.RC"
102 #define IDM_FILE_NEW 100
103 #define IDM_FILE_OPEN 101
104 #define IDM_FILE_SAVE 110
105 #define IDM_FILE_SCORE 120
106 #define IDM_FILE_EXIT 130
108 #define IDM_WINDOW_VIS_0 200
109 #define IDM_WINDOW_VIS_1 201
110 #define IDM_WINDOW_VIS_2 202
111 #define IDM_WINDOW_VIS_3 203
112 #define IDM_WINDOW_VIS_4 204
113 #define IDM_WINDOW_VIS_5 205
114 #define IDM_WINDOW_VIS_6 206
115 #define IDM_WINDOW_VIS_7 207
117 #define IDM_WINDOW_FONT_0 210
118 #define IDM_WINDOW_FONT_1 211
119 #define IDM_WINDOW_FONT_2 212
120 #define IDM_WINDOW_FONT_3 213
121 #define IDM_WINDOW_FONT_4 214
122 #define IDM_WINDOW_FONT_5 215
123 #define IDM_WINDOW_FONT_6 216
124 #define IDM_WINDOW_FONT_7 217
126 #define IDM_WINDOW_POS_0 220
127 #define IDM_WINDOW_POS_1 221
128 #define IDM_WINDOW_POS_2 222
129 #define IDM_WINDOW_POS_3 223
130 #define IDM_WINDOW_POS_4 224
131 #define IDM_WINDOW_POS_5 225
132 #define IDM_WINDOW_POS_6 226
133 #define IDM_WINDOW_POS_7 227
135 #define IDM_WINDOW_BIZ_0 230
136 #define IDM_WINDOW_BIZ_1 231
137 #define IDM_WINDOW_BIZ_2 232
138 #define IDM_WINDOW_BIZ_3 233
139 #define IDM_WINDOW_BIZ_4 234
140 #define IDM_WINDOW_BIZ_5 235
141 #define IDM_WINDOW_BIZ_6 236
142 #define IDM_WINDOW_BIZ_7 237
144 #define IDM_WINDOW_I_WID_0 240
145 #define IDM_WINDOW_I_WID_1 241
146 #define IDM_WINDOW_I_WID_2 242
147 #define IDM_WINDOW_I_WID_3 243
148 #define IDM_WINDOW_I_WID_4 244
149 #define IDM_WINDOW_I_WID_5 245
150 #define IDM_WINDOW_I_WID_6 246
151 #define IDM_WINDOW_I_WID_7 247
153 #define IDM_WINDOW_D_WID_0 250
154 #define IDM_WINDOW_D_WID_1 251
155 #define IDM_WINDOW_D_WID_2 252
156 #define IDM_WINDOW_D_WID_3 253
157 #define IDM_WINDOW_D_WID_4 254
158 #define IDM_WINDOW_D_WID_5 255
159 #define IDM_WINDOW_D_WID_6 256
160 #define IDM_WINDOW_D_WID_7 257
162 #define IDM_WINDOW_I_HGT_0 260
163 #define IDM_WINDOW_I_HGT_1 261
164 #define IDM_WINDOW_I_HGT_2 262
165 #define IDM_WINDOW_I_HGT_3 263
166 #define IDM_WINDOW_I_HGT_4 264
167 #define IDM_WINDOW_I_HGT_5 265
168 #define IDM_WINDOW_I_HGT_6 266
169 #define IDM_WINDOW_I_HGT_7 267
171 #define IDM_WINDOW_D_HGT_0 270
172 #define IDM_WINDOW_D_HGT_1 271
173 #define IDM_WINDOW_D_HGT_2 272
174 #define IDM_WINDOW_D_HGT_3 273
175 #define IDM_WINDOW_D_HGT_4 274
176 #define IDM_WINDOW_D_HGT_5 275
177 #define IDM_WINDOW_D_HGT_6 276
178 #define IDM_WINDOW_D_HGT_7 277
180 #define IDM_OPTIONS_NO_GRAPHICS 400
181 #define IDM_OPTIONS_OLD_GRAPHICS 401
182 #define IDM_OPTIONS_NEW_GRAPHICS 402
183 #define IDM_OPTIONS_BIGTILE 409
184 #define IDM_OPTIONS_SOUND 410
185 #define IDM_OPTIONS_SAVER 420
186 #define IDM_OPTIONS_MAP 430
187 #define IDM_OPTIONS_BG 440
188 #define IDM_OPTIONS_OPEN_BG 441
190 #define IDM_DUMP_SCREEN_HTML 450
192 #define IDM_HELP_CONTENTS 901
197 * This may need to be removed for some compilers XXX XXX XXX
202 * Exclude parts of WINDOWS.H that are not needed
204 #define NOCOMM /* Comm driver APIs and definitions */
205 #define NOLOGERROR /* LogError() and related definitions */
206 #define NOPROFILER /* Profiler APIs */
207 #define NOLFILEIO /* _l* file I/O routines */
208 #define NOOPENFILE /* OpenFile and related definitions */
209 #define NORESOURCE /* Resource management */
210 #define NOATOM /* Atom management */
211 #define NOLANGUAGE /* Character test routines */
212 #define NOLSTRING /* lstr* string management routines */
213 #define NODBCS /* Double-byte character set routines */
214 #define NOKEYBOARDINFO /* Keyboard driver routines */
215 #define NOCOLOR /* COLOR_* color values */
216 #define NODRAWTEXT /* DrawText() and related definitions */
217 #define NOSCALABLEFONT /* Truetype scalable font support */
218 #define NOMETAFILE /* Metafile support */
219 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
220 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
221 #define NOKEYSTATES /* MK_* message key state flags */
222 #define NOWH /* SetWindowsHook and related WH_* definitions */
223 #define NOCLIPBOARD /* Clipboard APIs and definitions */
224 #define NOICONS /* IDI_* icon IDs */
225 #define NOMDI /* MDI support */
226 #define NOHELP /* Help support */
228 /* Not defined since it breaks Borland C++ 5.5 */
229 /* #define NOCTLMGR */ /* Control management and controls */
232 * Exclude parts of WINDOWS.H that are not needed (Win32)
234 #define WIN32_LEAN_AND_MEAN
235 #define NONLS /* All NLS defines and routines */
236 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
237 #define NOKANJI /* Kanji support stuff. */
238 #define NOMCX /* Modem Configuration Extensions */
241 * Include the "windows" support file
246 * Exclude parts of MMSYSTEM.H that are not needed
248 #define MMNODRV /* Installable driver support */
249 #define MMNOWAVE /* Waveform support */
250 #define MMNOMIDI /* MIDI support */
251 #define MMNOAUX /* Auxiliary audio support */
252 #define MMNOTIMER /* Timer support */
253 #define MMNOJOY /* Joystick support */
254 #define MMNOMCI /* MCI support */
255 #define MMNOMMIO /* Multimedia file I/O support */
256 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
259 * Include some more files. Note: the Cygnus Cygwin compiler
260 * doesn't use mmsystem.h instead it includes the winmm library
261 * which performs a similar function.
263 #include <mmsystem.h>
267 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
268 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
270 /* #define HTML_HELP */
273 #include <htmlhelp.h>
274 #endif /* HTML_HELP */
277 * Include the support for loading bitmaps
280 # include "readdib.h"
284 * Hack -- Fake declarations from "dos.h" XXX XXX XXX
287 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
289 #define FA_LABEL 0x08 /* Volume label */
290 #define FA_DIREC 0x10 /* Directory */
291 unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
295 * Silliness in WIN32 drawing routine
298 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
302 * Silliness for Windows 95
304 #ifndef WS_EX_TOOLWINDOW
305 # define WS_EX_TOOLWINDOW 0
309 * Foreground color bits (hard-coded by DOS)
311 #define VID_BLACK 0x00
312 #define VID_BLUE 0x01
313 #define VID_GREEN 0x02
314 #define VID_CYAN 0x03
316 #define VID_MAGENTA 0x05
317 #define VID_YELLOW 0x06
318 #define VID_WHITE 0x07
321 * Bright text (hard-coded by DOS)
323 #define VID_BRIGHT 0x08
326 * Background color bits (hard-coded by DOS)
328 #define VUD_BLACK 0x00
329 #define VUD_BLUE 0x10
330 #define VUD_GREEN 0x20
331 #define VUD_CYAN 0x30
333 #define VUD_MAGENTA 0x50
334 #define VUD_YELLOW 0x60
335 #define VUD_WHITE 0x70
338 * Blinking text (hard-coded by DOS)
340 #define VUD_BRIGHT 0x80
346 typedef struct _term_data term_data;
351 * Note the use of "font_want" for the names of the font file requested by
352 * the user, and the use of "font_file" for the currently active font file.
354 * The "font_file" is uppercased, and takes the form "8X13.FON", while
355 * "font_want" can be in almost any form as long as it could be construed
356 * as attempting to represent the name of a font.
371 uint rows; /* int -> uint */
422 * Maximum number of windows XXX XXX XXX
424 #define MAX_TERM_DATA 8
427 * An array of term_data's
429 static term_data data[MAX_TERM_DATA];
432 * Hack -- global "window creation" pointer
434 static term_data *my_td;
439 bool game_in_progress = FALSE;
442 * note when "open"/"new" become valid
444 bool initialized = FALSE;
447 * screen paletted, i.e. 256 colors
449 bool paletted = FALSE;
452 * 16 colors screen, don't use RGB()
454 bool colors16 = FALSE;
457 * Saved instance handle
459 static HINSTANCE hInstance;
462 * Yellow brush for the cursor
464 static HBRUSH hbrYellow;
474 static HPALETTE hPal;
477 static HBITMAP hBG = NULL;
478 static int use_bg = 0;
479 static char bg_bitmap_file[1024] = "bg.bmp";
484 * The screen saver window
486 static HWND hwndSaver;
488 #endif /* USE_SAVER */
494 * Flag set once "graphics" has been initialized
496 static bool can_use_graphics = FALSE;
501 static DIBINIT infGraph;
503 #ifdef USE_TRANSPARENCY
506 * The global bitmap mask
508 static DIBINIT infMask;
510 #endif /* USE_TRANSPARENCY */
512 #endif /* USE_GRAPHICS */
518 * Flag set once "sound" has been initialized
520 static bool can_use_sound = FALSE;
523 * An array of sound file names
525 static cptr sound_file[SOUND_MAX];
527 #endif /* USE_SOUND */
531 * Full path to ANGBAND.INI
533 static cptr ini_file = NULL;
536 * Name of application
538 static cptr AppName = "ANGBAND";
541 * Name of sub-window type
543 static cptr AngList = "AngList";
548 static cptr ANGBAND_DIR_XTRA_FONT;
549 static cptr ANGBAND_DIR_XTRA_GRAF;
550 static cptr ANGBAND_DIR_XTRA_SOUND;
551 static cptr ANGBAND_DIR_XTRA_MUSIC;
552 static cptr ANGBAND_DIR_XTRA_HELP;
556 * The "complex" color values
558 static COLORREF win_clr[256];
562 * The "simple" color values
564 * See "main-ibm.c" for original table information
566 * The entries below are taken from the "color bits" defined above.
568 * Note that many of the choices below suck, but so do crappy monitors.
570 static BYTE win_pal[256] =
572 VID_BLACK, /* Dark */
573 VID_WHITE, /* White */
574 VID_CYAN, /* Slate XXX */
575 VID_RED | VID_BRIGHT, /* Orange XXX */
577 VID_GREEN, /* Green */
579 VID_YELLOW, /* Umber XXX */
580 VID_BLACK | VID_BRIGHT, /* Light Dark */
581 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
582 VID_MAGENTA, /* Violet XXX */
583 VID_YELLOW | VID_BRIGHT, /* Yellow */
584 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
585 VID_GREEN | VID_BRIGHT, /* Light Green */
586 VID_BLUE | VID_BRIGHT, /* Light Blue */
587 VID_YELLOW /* Light Umber XXX */
592 * Hack -- define which keys are "special"
594 static bool special_key[256];
595 static bool ignore_key[256];
599 * Hack -- initialization list for "special_key"
601 static byte special_key_list[] = {
602 VK_CLEAR,VK_PAUSE,VK_CAPITAL,VK_KANA,VK_JUNJA,VK_FINAL,VK_KANJI,
603 VK_CONVERT,VK_NONCONVERT,VK_ACCEPT,VK_MODECHANGE,
604 VK_PRIOR,VK_NEXT,VK_END,VK_HOME,VK_LEFT,VK_UP,VK_RIGHT,VK_DOWN,
605 VK_SELECT,VK_PRINT,VK_EXECUTE,VK_SNAPSHOT,VK_INSERT,VK_DELETE,
607 VK_F1,VK_F2,VK_F3,VK_F4,VK_F5,VK_F6,VK_F7,VK_F8,VK_F9,VK_F10,
608 VK_F11,VK_F12,VK_F13,VK_F14,VK_F15,VK_F16,VK_F17,VK_F18,VK_F19,VK_F20,
609 VK_F21,VK_F22,VK_F23,VK_F24,VK_NUMLOCK,VK_SCROLL,
610 VK_ATTN,VK_CRSEL,VK_EXSEL,VK_EREOF,VK_PLAY,VK_ZOOM,VK_NONAME,
614 static byte ignore_key_list[] = {
615 VK_ESCAPE,VK_TAB,VK_SPACE,
616 'F','W','O','H', /* these are menu characters.*/
617 VK_SHIFT,VK_CONTROL,VK_MENU,VK_LWIN,VK_RWIN,
618 VK_LSHIFT,VK_RSHIFT,VK_LCONTROL,VK_RCONTROL,VK_LMENU,VK_RMENU,0
623 * Hack -- initialization list for "special_key"
625 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
626 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
627 * catch the keypad keys (with and without numlock set, including keypad 5),
628 * the function keys (including the "menu" key which maps to F10), and the
629 * "pause" key (between scroll lock and numlock). We also catch a few odd
630 * keys which I do not recognize, but which are listed among keys which we
631 * do catch, so they should be harmless to catch.
633 static byte special_key_list[] =
635 VK_CLEAR, /* 0x0C (KP<5>) */
637 VK_PAUSE, /* 0x13 (pause) */
639 VK_PRIOR, /* 0x21 (KP<9>) */
640 VK_NEXT, /* 0x22 (KP<3>) */
641 VK_END, /* 0x23 (KP<1>) */
642 VK_HOME, /* 0x24 (KP<7>) */
643 VK_LEFT, /* 0x25 (KP<4>) */
644 VK_UP, /* 0x26 (KP<8>) */
645 VK_RIGHT, /* 0x27 (KP<6>) */
646 VK_DOWN, /* 0x28 (KP<2>) */
647 VK_SELECT, /* 0x29 (?????) */
648 VK_PRINT, /* 0x2A (?????) */
649 VK_EXECUTE, /* 0x2B (?????) */
650 VK_SNAPSHOT, /* 0x2C (?????) */
651 VK_INSERT, /* 0x2D (KP<0>) */
652 VK_DELETE, /* 0x2E (KP<.>) */
653 VK_HELP, /* 0x2F (?????) */
656 VK_NUMPAD0, /* 0x60 (KP<0>) */
657 VK_NUMPAD1, /* 0x61 (KP<1>) */
658 VK_NUMPAD2, /* 0x62 (KP<2>) */
659 VK_NUMPAD3, /* 0x63 (KP<3>) */
660 VK_NUMPAD4, /* 0x64 (KP<4>) */
661 VK_NUMPAD5, /* 0x65 (KP<5>) */
662 VK_NUMPAD6, /* 0x66 (KP<6>) */
663 VK_NUMPAD7, /* 0x67 (KP<7>) */
664 VK_NUMPAD8, /* 0x68 (KP<8>) */
665 VK_NUMPAD9, /* 0x69 (KP<9>) */
666 VK_MULTIPLY, /* 0x6A (KP<*>) */
667 VK_ADD, /* 0x6B (KP<+>) */
668 VK_SEPARATOR, /* 0x6C (?????) */
669 VK_SUBTRACT, /* 0x6D (KP<->) */
670 VK_DECIMAL, /* 0x6E (KP<.>) */
671 VK_DIVIDE, /* 0x6F (KP</>) */
704 static void delete_bg()
715 char * bmfile = bg_bitmap_file;
718 if (use_bg == 0) return 0;
720 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
722 plog_fmt("ÊÉ»æÍÑ¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
727 HDC wnddc, dcimage, dcbg;
728 HBITMAP bmimage, bmimage_old, bmbg_old;
734 dcimage = CreateCompatibleDC(wnddc);
735 dcbg = CreateCompatibleDC(wnddc);
737 bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
738 if (!bmimage) quit("bg.bmp¤¬Æɤߤ³¤á¤Ê¤¤¡ª");
739 bmimage_old = SelectObject(dcimage, bmimage);
741 CreateCompatibleBitmap();
743 ReleaseDC(hwnd, wnddc);
749 static void DrawBG(HDC hdc, RECT *r)
754 int x = r->left, y = r->top;
755 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
761 GetObject(hBG, sizeof(bm), &bm);
762 swid = bm.bmWidth; shgt = bm.bmHeight;
764 hdcSrc = CreateCompatibleDC(hdc);
765 hOld = SelectObject(hdcSrc, hBG);
769 cwid = MIN(swid - sx, r->right - nx);
772 chgt = MIN(shgt - sy, r->bottom - ny);
773 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
775 } while (ny < r->bottom);
778 } while (nx < r->right);
780 SelectObject(hdcSrc, hOld);
785 * Hack -- given a pathname, point at the filename
787 static cptr extract_file_name(cptr s)
791 /* Start at the end */
792 p = s + strlen(s) - 1;
794 /* Back up to divider */
795 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
797 /* Return file name */
803 * Hack -- given a simple filename, extract the "font size" info
805 * Return a pointer to a static buffer holding the capitalized base name.
808 static char *analyze_font(char *path, int *wp, int *hp)
814 /* Start at the end */
815 p = path + strlen(path) - 1;
817 /* Back up to divider */
818 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
820 /* Advance to file name */
826 /* Capitalize (be paranoid) */
827 if (islower(*s)) *s = toupper(*s);
833 /* Extract font width */
837 hgt = s ? atoi(s+1) : 0;
850 * Check for existance of a file
852 static bool check_file(cptr s)
872 attrib = GetFileAttributes(path);
874 /* Require valid filename */
875 if (attrib == INVALID_FILE_NAME) return (FALSE);
877 /* Prohibit directory */
878 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
882 /* Examine and verify */
883 if (_dos_getfileattr(path, &attrib)) return (FALSE);
885 /* Prohibit something */
886 if (attrib & FA_LABEL) return (FALSE);
888 /* Prohibit directory */
889 if (attrib & FA_DIREC) return (FALSE);
899 * Check for existance of a directory
901 static bool check_dir(cptr s)
923 /* Remove trailing backslash */
924 if (i && (path[i-1] == '\\')) path[--i] = '\0';
929 attrib = GetFileAttributes(path);
931 /* Require valid filename */
932 if (attrib == INVALID_FILE_NAME) return (FALSE);
934 /* Require directory */
935 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
939 /* Examine and verify */
940 if (_dos_getfileattr(path, &attrib)) return (FALSE);
942 /* Prohibit something */
943 if (attrib & FA_LABEL) return (FALSE);
945 /* Require directory */
946 if (!(attrib & FA_DIREC)) return (FALSE);
958 static void validate_file(cptr s)
964 quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
966 quit_fmt("Cannot find required file:\n%s", s);
974 * Validate a directory
976 static void validate_dir(cptr s, bool vital)
981 /* This directory contains needed data */
985 quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
987 quit_fmt("Cannot find required directory:\n%s", s);
991 /* Attempt to create this directory */
994 quit_fmt("Unable to create directory:\n%s", s);
1001 * Get the "size" for a window
1003 static void term_getsize(term_data *td)
1010 if (td->cols < 1) td->cols = 1;
1011 if (td->rows < 1) td->rows = 1;
1014 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1015 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1017 /* Fake window size */
1019 rc.right = rc.left + wid;
1021 rc.bottom = rc.top + hgt;
1024 /* rc.right += 1; */
1025 /* rc.bottom += 1; */
1028 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1031 td->size_wid = rc.right - rc.left;
1032 td->size_hgt = rc.bottom - rc.top;
1034 /* See CreateWindowEx */
1037 /* Extract actual location */
1038 GetWindowRect(td->w, &rc);
1040 /* Save the location */
1041 td->pos_x = rc.left;
1047 * Write the "prefs" for a single term
1049 static void save_prefs_aux(term_data *td, cptr sec_name)
1059 strcpy(buf, td->visible ? "1" : "0");
1060 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1064 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1066 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1069 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1072 wsprintf(buf, "%d", td->lf.lfWidth);
1073 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1074 wsprintf(buf, "%d", td->lf.lfHeight);
1075 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1076 wsprintf(buf, "%d", td->lf.lfWeight);
1077 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1080 strcpy(buf, td->bizarre ? "1" : "0");
1081 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1084 wsprintf(buf, "%d", td->tile_wid);
1085 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1088 wsprintf(buf, "%d", td->tile_hgt);
1089 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1091 /* Window size (x) */
1092 wsprintf(buf, "%d", td->cols);
1093 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1095 /* Window size (y) */
1096 wsprintf(buf, "%d", td->rows);
1097 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1099 /* Acquire position */
1100 GetWindowRect(td->w, &rc);
1102 /* Window position (x) */
1103 wsprintf(buf, "%d", rc.left);
1104 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1106 /* Window position (y) */
1107 wsprintf(buf, "%d", rc.top);
1108 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1110 /* Window Z position */
1111 strcpy(buf, td->posfix ? "1" : "0");
1112 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1119 * We assume that the windows have all been initialized
1121 static void save_prefs(void)
1127 /* Save the "arg_graphics" flag */
1128 sprintf(buf, "%d", arg_graphics);
1129 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1131 /* Save the "arg_bigtile" flag */
1132 strcpy(buf, arg_bigtile ? "1" : "0");
1133 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1135 /* Save the "arg_sound" flag */
1136 strcpy(buf, arg_sound ? "1" : "0");
1137 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1140 strcpy(buf, use_bg ? "1" : "0");
1141 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1142 WritePrivateProfileString("Angband", "BackGroundBitmap",
1143 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1145 /* Save window prefs */
1146 for (i = 0; i < MAX_TERM_DATA; ++i)
1148 term_data *td = &data[i];
1150 sprintf(buf, "Term-%d", i);
1152 save_prefs_aux(td, buf);
1158 * Load the "prefs" for a single term
1160 static void load_prefs_aux(term_data *td, cptr sec_name)
1167 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1169 /* Desired font, with default */
1171 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1173 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1178 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1180 /* Analyze font, save desired font name */
1182 td->font_want = string_make(tmp);
1184 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1185 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1186 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1188 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1194 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1195 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1197 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1198 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1203 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1204 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1206 /* Window position */
1207 td->pos_x = GetPrivateProfileInt(sec_name, "PositionX", td->pos_x, ini_file);
1208 td->pos_y = GetPrivateProfileInt(sec_name, "PositionY", td->pos_y, ini_file);
1210 /* Window Z position */
1211 td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1218 static void load_prefs(void)
1224 /* Extract the "arg_graphics" flag */
1225 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1227 /* Extract the "arg_bigtile" flag */
1228 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1229 use_bigtile = arg_bigtile;
1231 /* Extract the "arg_sound" flag */
1232 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1235 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1236 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1238 /* Load window prefs */
1239 for (i = 0; i < MAX_TERM_DATA; ++i)
1241 term_data *td = &data[i];
1243 sprintf(buf, "Term-%d", i);
1245 load_prefs_aux(td, buf);
1251 * Create the new global palette based on the bitmap palette
1252 * (if any), and the standard 16 entry palette derived from
1253 * "win_clr[]" which is used for the basic 16 Angband colors.
1255 * This function is never called before all windows are ready.
1257 * This function returns FALSE if the new palette could not be
1258 * prepared, which should normally be a fatal error. XXX XXX
1260 * Note that only some machines actually use a "palette".
1262 static int new_palette(void)
1270 LPLOGPALETTE pLogPal;
1271 LPPALETTEENTRY lppe;
1276 /* This makes no sense */
1277 if (!paletted) return (TRUE);
1287 /* Check the bitmap palette */
1288 hBmPal = infGraph.hPalette;
1290 /* Use the bitmap */
1293 lppeSize = 256 * sizeof(PALETTEENTRY);
1294 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1295 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1296 if ((nEntries == 0) || (nEntries > 220))
1300 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1302 plog("Please switch to high- or true-color mode.");
1307 rnfree(lppe, lppeSize);
1314 #endif /* USE_GRAPHICS */
1316 /* Size of palette */
1317 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1319 /* Allocate palette */
1320 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1323 pLogPal->palVersion = 0x300;
1325 /* Make room for bitmap and normal data */
1326 pLogPal->palNumEntries = nEntries + 16;
1328 /* Save the bitmap data */
1329 for (i = 0; i < nEntries; i++)
1331 pLogPal->palPalEntry[i] = lppe[i];
1334 /* Save the normal data */
1335 for (i = 0; i < 16; i++)
1339 /* Access the entry */
1340 p = &(pLogPal->palPalEntry[i+nEntries]);
1342 /* Save the colors */
1343 p->peRed = GetRValue(win_clr[i]);
1344 p->peGreen = GetGValue(win_clr[i]);
1345 p->peBlue = GetBValue(win_clr[i]);
1347 /* Save the flags */
1348 p->peFlags = PC_NOCOLLAPSE;
1351 /* Free something */
1352 if (lppe) rnfree(lppe, lppeSize);
1354 /* Create a new palette, or fail */
1355 hNewPal = CreatePalette(pLogPal);
1357 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1359 if (!hNewPal) quit("Cannot create palette!");
1363 /* Free the palette */
1364 rnfree(pLogPal, pLogPalSize);
1369 /* Realize the palette */
1371 SelectPalette(hdc, hNewPal, 0);
1372 i = RealizePalette(hdc);
1373 ReleaseDC(td->w, hdc);
1375 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1377 if (i == 0) quit("Cannot realize palette!");
1382 for (i = 1; i < MAX_TERM_DATA; i++)
1387 SelectPalette(hdc, hNewPal, 0);
1388 ReleaseDC(td->w, hdc);
1391 /* Delete old palette */
1392 if (hPal) DeleteObject(hPal);
1394 /* Save new palette */
1404 * Initialize graphics
1406 static bool init_graphics(void)
1408 /* Initialize once */
1409 /* if (can_use_graphics != arg_graphics) */
1415 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1422 ANGBAND_GRAF = "new";
1430 ANGBAND_GRAF = "old";
1433 /* Access the bitmap file */
1434 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1436 /* Load the bitmap or quit */
1437 if (!ReadDIB(data[0].w, buf, &infGraph))
1440 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1442 plog_fmt("Cannot read bitmap file '%s'", name);
1448 /* Save the new sizes */
1449 infGraph.CellWidth = wid;
1450 infGraph.CellHeight = hgt;
1452 #ifdef USE_TRANSPARENCY
1454 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1456 /* Access the mask file */
1457 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1459 /* Load the bitmap or quit */
1460 if (!ReadDIB(data[0].w, buf, &infMask))
1462 plog_fmt("Cannot read bitmap file '%s'", buf);
1467 #endif /* USE_TRANSPARENCY */
1469 /* Activate a palette */
1472 /* Free bitmap XXX XXX XXX */
1476 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1478 plog("Cannot activate palette!");
1484 /* Graphics available */
1485 can_use_graphics = arg_graphics;
1489 return (can_use_graphics);
1491 #endif /* USE_GRAPHICS */
1498 static bool init_sound(void)
1500 /* Initialize once */
1508 /* Prepare the sounds */
1509 for (i = 1; i < SOUND_MAX; i++)
1511 /* Extract name of sound file */
1512 sprintf(wav, "%s.wav", angband_sound_name[i]);
1514 /* Access the sound */
1515 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_SOUND, wav);
1517 /* Save the sound filename, if it exists */
1518 if (check_file(buf)) sound_file[i] = string_make(buf);
1521 /* Sound available */
1522 can_use_sound = TRUE;
1526 return (can_use_sound);
1528 #endif /* USE_SOUND */
1534 static void term_window_resize(term_data *td)
1536 /* Require window */
1539 /* Resize the window */
1540 SetWindowPos(td->w, 0, 0, 0,
1541 td->size_wid, td->size_hgt,
1542 SWP_NOMOVE | SWP_NOZORDER);
1545 InvalidateRect(td->w, NULL, TRUE);
1550 * Force the use of a new "font file" for a term_data
1552 * This function may be called before the "window" is ready
1554 * This function returns zero only if everything succeeds.
1556 * Note that the "font name" must be capitalized!!!
1558 static errr term_force_font(term_data *td, cptr path)
1568 /* Forget the old font (if needed) */
1569 if (td->font_id) DeleteObject(td->font_id);
1572 /* Forget old font */
1578 for (i = 0; i < MAX_TERM_DATA; i++)
1580 /* Don't check when closing the application */
1583 /* Check "screen" */
1584 if ((td != &data[i]) &&
1585 (data[i].font_file) &&
1586 (streq(data[i].font_file, td->font_file)))
1592 /* Remove unused font resources */
1593 if (!used) RemoveFontResource(td->font_file);
1595 /* Free the old name */
1596 string_free(td->font_file);
1599 td->font_file = NULL;
1604 if (!path) return (1);
1610 /* Analyze font path */
1611 base = analyze_font(buf, &wid, &hgt);
1614 if (!suffix(base, ".FON")) return (1);
1617 if (!check_file(buf)) return (1);
1619 /* Load the new font */
1620 if (!AddFontResource(buf)) return (1);
1622 /* Save new font name */
1623 td->font_file = string_make(base);
1625 /* Remove the "suffix" */
1626 base[strlen(base)-4] = '\0';
1629 /* Create the font (using the 'base' of the font file name!) */
1631 td->font_id = CreateFontIndirect(&(td->lf));
1632 wid = td->lf.lfWidth;
1633 hgt = td->lf.lfHeight;
1634 if (!td->font_id) return (1);
1636 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1637 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1638 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1639 FIXED_PITCH | FF_DONTCARE, base);
1643 /* Hack -- Unknown size */
1650 /* all this trouble to get the cell size */
1651 hdcDesktop = GetDC(HWND_DESKTOP);
1652 hfOld = SelectObject(hdcDesktop, td->font_id);
1653 GetTextMetrics(hdcDesktop, &tm);
1654 SelectObject(hdcDesktop, hfOld);
1655 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1657 /* Font size info */
1658 wid = tm.tmAveCharWidth;
1662 /* Save the size info */
1673 * Allow the user to change the font for this window.
1675 static void term_change_font(term_data *td)
1680 memset(&cf, 0, sizeof(cf));
1681 cf.lStructSize = sizeof(cf);
1682 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1683 cf.lpLogFont = &(td->lf);
1685 if (ChooseFont(&cf))
1687 /* Force the font */
1688 term_force_font(td, NULL);
1690 /* Assume not bizarre */
1693 /* Reset the tile info */
1694 td->tile_wid = td->font_wid;
1695 td->tile_hgt = td->font_hgt;
1697 /* Analyze the font */
1700 /* Resize the window */
1701 term_window_resize(td);
1707 char tmp[1024] = "";
1709 /* Extract a default if possible */
1710 if (td->font_file) strcpy(tmp, td->font_file);
1712 /* Ask for a choice */
1713 memset(&ofn, 0, sizeof(ofn));
1714 ofn.lStructSize = sizeof(ofn);
1715 ofn.hwndOwner = data[0].w;
1716 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1717 ofn.nFilterIndex = 1;
1718 ofn.lpstrFile = tmp;
1720 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1721 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1722 ofn.lpstrDefExt = "fon";
1724 /* Force choice if legal */
1725 if (GetOpenFileName(&ofn))
1727 /* Force the font */
1728 if (term_force_font(td, tmp))
1730 /* Access the standard font file */
1731 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1733 /* Force the use of that font */
1734 (void)term_force_font(td, tmp);
1737 /* Assume not bizarre */
1738 td->bizarre = FALSE;
1740 /* Reset the tile info */
1741 td->tile_wid = td->font_wid;
1742 td->tile_hgt = td->font_hgt;
1744 /* Analyze the font */
1747 /* Resize the window */
1748 term_window_resize(td);
1755 * Allow the user to lock this window.
1757 static void term_window_pos(term_data *td, HWND hWnd)
1759 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1760 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1763 static void windows_map(void);
1766 * Hack -- redraw a term_data
1768 static void term_data_redraw(term_data *td)
1772 /* Redraw the map */
1777 /* Activate the term */
1778 Term_activate(&td->t);
1780 /* Redraw the contents */
1783 /* Restore the term */
1784 Term_activate(term_screen);
1792 /*** Function hooks needed by "Term" ***/
1798 * Initialize a new Term
1800 static void Term_init_win(term *t)
1809 static void Term_nuke_win(term *t)
1818 * Interact with the User
1820 static errr Term_user_win(int n)
1828 * React to global changes
1830 static errr Term_xtra_win_react(void)
1838 /* Save the default colors */
1839 for (i = 0; i < 256; i++)
1841 /* Simply accept the desired colors */
1842 win_pal[i] = angband_color_table[i][0];
1853 bool change = FALSE;
1855 /* Save the default colors */
1856 for (i = 0; i < 256; i++)
1858 /* Extract desired values */
1859 rv = angband_color_table[i][1];
1860 gv = angband_color_table[i][2];
1861 bv = angband_color_table[i][3];
1863 /* Extract a full color code */
1864 code = PALETTERGB(rv, gv, bv);
1866 /* Activate changes */
1867 if (win_clr[i] != code)
1869 /* Note the change */
1872 /* Apply the desired color */
1877 /* Activate the palette if needed */
1878 if (change) (void)new_palette();
1884 /* Handle "arg_sound" */
1885 if (use_sound != arg_sound)
1887 /* Initialize (if needed) */
1888 if (arg_sound && !init_sound())
1892 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
1894 plog("Cannot initialize sound!");
1902 /* Change setting */
1903 use_sound = arg_sound;
1911 /* Handle "arg_graphics" */
1912 if (use_graphics != arg_graphics)
1914 /* Initialize (if needed) */
1915 if (arg_graphics && !init_graphics())
1919 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
1921 plog("Cannot initialize graphics!");
1926 arg_graphics = GRAPHICS_NONE;
1929 /* Change setting */
1930 use_graphics = arg_graphics;
1933 #ifdef ANGBAND_2_8_1
1935 #else /* ANGBAND_2_8_1 */
1936 reset_visuals(TRUE);
1937 #endif /* ANGBAND_2_8_1 */
1940 #endif /* USE_GRAPHICS */
1943 /* Clean up windows */
1944 for (i = 0; i < MAX_TERM_DATA; i++)
1948 term_data *td = &data[i];
1950 /* Update resized windows */
1951 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
1954 Term_activate(&td->t);
1956 /* Hack -- Resize the term */
1957 Term_resize(td->cols, td->rows);
1959 /* Redraw the contents */
1974 * Process at least one event
1976 static errr Term_xtra_win_event(int v)
1980 /* Wait for an event */
1984 if (GetMessage(&msg, NULL, 0, 0))
1986 TranslateMessage(&msg);
1987 DispatchMessage(&msg);
1991 /* Check for an event */
1995 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1997 TranslateMessage(&msg);
1998 DispatchMessage(&msg);
2008 * Process all pending events
2010 static errr Term_xtra_win_flush(void)
2014 /* Process all pending events */
2015 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2017 TranslateMessage(&msg);
2018 DispatchMessage(&msg);
2027 * Hack -- clear the screen
2029 * Make this more efficient XXX XXX XXX
2031 static errr Term_xtra_win_clear(void)
2033 term_data *td = (term_data*)(Term->data);
2038 /* Rectangle to erase */
2039 rc.left = td->size_ow1;
2040 rc.right = rc.left + td->cols * td->tile_wid;
2041 rc.top = td->size_oh1;
2042 rc.bottom = rc.top + td->rows * td->tile_hgt;
2046 SetBkColor(hdc, RGB(0, 0, 0));
2047 SelectObject(hdc, td->font_id);
2048 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2053 rc.left = 0; rc.top = 0;
2056 ReleaseDC(td->w, hdc);
2064 * Hack -- make a noise
2066 static errr Term_xtra_win_noise(void)
2068 MessageBeep(MB_ICONASTERISK);
2074 * Hack -- make a sound
2076 static errr Term_xtra_win_sound(int v)
2078 /* Sound disabled */
2079 if (!use_sound) return (1);
2082 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2087 if (!sound_file[v]) return (1);
2091 /* Play the sound, catch errors */
2092 return (PlaySound(sound_file[v], 0, SND_FILENAME | SND_ASYNC));
2096 /* Play the sound, catch errors */
2097 return (sndPlaySound(sound_file[v], SND_ASYNC));
2101 #else /* USE_SOUND */
2106 #endif /* USE_SOUND */
2111 * Delay for "x" milliseconds
2113 static int Term_xtra_win_delay(int v)
2127 t = GetTickCount() + v;
2130 while (GetTickCount() < t)
2132 /* Handle messages */
2133 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2135 TranslateMessage(&msg);
2136 DispatchMessage(&msg);
2148 * Do a "special thing"
2150 static errr Term_xtra_win(int n, int v)
2152 /* Handle a subset of the legal requests */
2155 /* Make a bell sound */
2156 case TERM_XTRA_NOISE:
2158 return (Term_xtra_win_noise());
2161 /* Make a special sound */
2162 case TERM_XTRA_SOUND:
2164 return (Term_xtra_win_sound(v));
2167 /* Process random events */
2168 case TERM_XTRA_BORED:
2170 return (Term_xtra_win_event(0));
2173 /* Process an event */
2174 case TERM_XTRA_EVENT:
2176 return (Term_xtra_win_event(v));
2179 /* Flush all events */
2180 case TERM_XTRA_FLUSH:
2182 return (Term_xtra_win_flush());
2185 /* Clear the screen */
2186 case TERM_XTRA_CLEAR:
2188 return (Term_xtra_win_clear());
2191 /* React to global changes */
2192 case TERM_XTRA_REACT:
2194 return (Term_xtra_win_react());
2197 /* Delay for some milliseconds */
2198 case TERM_XTRA_DELAY:
2200 return (Term_xtra_win_delay(v));
2211 * Low level graphics (Assumes valid input).
2213 * Draw a "cursor" at (x,y), using a "yellow box".
2215 static errr Term_curs_win(int x, int y)
2217 term_data *td = (term_data*)(Term->data);
2222 int tile_wid, tile_hgt;
2226 tile_wid = td->map_tile_wid;
2227 tile_hgt = td->map_tile_hgt;
2231 tile_wid = td->tile_wid;
2232 tile_hgt = td->tile_hgt;
2235 /* Frame the grid */
2236 rc.left = x * tile_wid + td->size_ow1;
2237 rc.right = rc.left + tile_wid;
2238 rc.top = y * tile_hgt + td->size_oh1;
2239 rc.bottom = rc.top + tile_hgt;
2241 /* Cursor is done as a yellow "box" */
2243 FrameRect(hdc, &rc, hbrYellow);
2244 ReleaseDC(td->w, hdc);
2252 * Low level graphics (Assumes valid input).
2254 * Draw a "big cursor" at (x,y), using a "yellow box".
2256 static errr Term_bigcurs_win(int x, int y)
2258 term_data *td = (term_data*)(Term->data);
2263 int tile_wid, tile_hgt;
2267 /* Normal cursor in map window */
2268 Term_curs_win(x, y);
2273 tile_wid = td->tile_wid;
2274 tile_hgt = td->tile_hgt;
2277 /* Frame the grid */
2278 rc.left = x * tile_wid + td->size_ow1;
2279 rc.right = rc.left + 2 * tile_wid;
2280 rc.top = y * tile_hgt + td->size_oh1;
2281 rc.bottom = rc.top + tile_hgt;
2283 /* Cursor is done as a yellow "box" */
2285 FrameRect(hdc, &rc, hbrYellow);
2286 ReleaseDC(td->w, hdc);
2294 * Low level graphics (Assumes valid input).
2296 * Erase a "block" of "n" characters starting at (x,y).
2298 static errr Term_wipe_win(int x, int y, int n)
2300 term_data *td = (term_data*)(Term->data);
2305 /* Rectangle to erase in client coords */
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;
2312 SetBkColor(hdc, RGB(0, 0, 0));
2313 SelectObject(hdc, td->font_id);
2318 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2319 ReleaseDC(td->w, hdc);
2327 * Low level graphics. Assumes valid input.
2329 * Draw several ("n") chars, with an attr, at a given location.
2331 * All "graphic" data is handled by "Term_pict_win()", below.
2333 * One would think there is a more efficient method for telling a window
2334 * what color it should be using to draw with, but perhaps simply changing
2335 * it every time is not too inefficient. XXX XXX XXX
2337 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2339 term_data *td = (term_data*)(Term->data);
2345 static HBITMAP WALL;
2346 static HBRUSH myBrush, oldBrush;
2348 static bool init_done = FALSE;
2351 WALL = LoadBitmap(hInstance, AppName);
2352 myBrush = CreatePatternBrush(WALL);
2357 /* Total rectangle */
2358 rc.left = x * td->tile_wid + td->size_ow1;
2359 rc.right = rc.left + n * td->tile_wid;
2360 rc.top = y * td->tile_hgt + td->size_oh1;
2361 rc.bottom = rc.top + td->tile_hgt;
2366 /* Background color */
2367 SetBkColor(hdc, RGB(0, 0, 0));
2369 /* Foreground color */
2372 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2376 SetTextColor(hdc, win_clr[a&0x0F]);
2380 SetTextColor(hdc, win_clr[a]);
2384 SelectObject(hdc, td->font_id);
2387 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2391 (td->tile_hgt != td->font_hgt) ||
2392 (td->tile_wid != td->font_wid))
2396 /* Erase complete rectangle */
2397 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2400 if (use_bg) DrawBG(hdc, &rc);
2403 rc.left += ((td->tile_wid - td->font_wid) / 2);
2404 rc.right = rc.left + td->font_wid;
2405 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2406 rc.bottom = rc.top + td->font_hgt;
2408 /* Dump each character */
2409 for (i = 0; i < n; i++)
2412 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2414 rc.right += td->font_wid;
2416 oldBrush = SelectObject(hdc, myBrush);
2417 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2420 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2422 SelectObject(hdc, oldBrush);
2423 SelectObject(hdc, oldPen);
2424 rc.right -= td->font_wid;
2428 rc.left += 2 * td->tile_wid;
2429 rc.right += 2 * td->tile_wid;
2431 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2433 rc.right += td->font_wid;
2435 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2437 rc.right -= td->font_wid;
2441 rc.left += 2 * td->tile_wid;
2442 rc.right += 2 * td->tile_wid;
2443 } else if (*(s+i)==127){
2444 oldBrush = SelectObject(hdc, myBrush);
2445 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2448 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2450 SelectObject(hdc, oldBrush);
2451 SelectObject(hdc, oldPen);
2454 rc.left += td->tile_wid;
2455 rc.right += td->tile_wid;
2458 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2462 rc.left += td->tile_wid;
2463 rc.right += td->tile_wid;
2467 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2471 rc.left += td->tile_wid;
2472 rc.right += td->tile_wid;
2482 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2487 ReleaseDC(td->w, hdc);
2495 * Low level graphics. Assumes valid input.
2497 * Draw an array of "special" attr/char pairs at the given location.
2499 * We use the "Term_pict_win()" function for "graphic" data, which are
2500 * encoded by setting the "high-bits" of both the "attr" and the "char"
2501 * data. We use the "attr" to represent the "row" of the main bitmap,
2502 * and the "char" to represent the "col" of the main bitmap. The use
2503 * of this function is induced by the "higher_pict" flag.
2505 * If "graphics" is not available, we simply "wipe" the given grids.
2507 # ifdef USE_TRANSPARENCY
2508 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2509 # else /* USE_TRANSPARENCY */
2510 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp)
2511 # endif /* USE_TRANSPARENCY */
2513 term_data *td = (term_data*)(Term->data);
2519 int x2, y2, w2, h2, tw2;
2521 # ifdef USE_TRANSPARENCY
2527 # endif /* USE_TRANSPARENCY */
2536 /* Erase the grids */
2537 return (Term_wipe_win(x, y, n));
2540 /* Size of bitmap cell */
2541 w1 = infGraph.CellWidth;
2542 h1 = infGraph.CellHeight;
2544 /* Size of window cell */
2547 w2 = td->map_tile_wid;
2548 h2 = td->map_tile_hgt;
2557 if (use_bigtile) tw2 *= 2;
2560 /* Location of window cell */
2561 x2 = x * w2 + td->size_ow1;
2562 y2 = y * h2 + td->size_oh1;
2568 hdcSrc = CreateCompatibleDC(hdc);
2569 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2571 # ifdef USE_TRANSPARENCY
2573 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2575 hdcMask = CreateCompatibleDC(hdc);
2576 SelectObject(hdcMask, infMask.hBitmap);
2579 # endif /* USE_TRANSPARENCY */
2581 /* Draw attr/char pairs */
2582 for (i = 0; i < n; i++, x2 += w2)
2587 /* Extract picture */
2588 int row = (a & 0x7F);
2589 int col = (c & 0x7F);
2591 /* Location of bitmap cell */
2595 # ifdef USE_TRANSPARENCY
2597 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2599 x3 = (tcp[i] & 0x7F) * w1;
2600 y3 = (tap[i] & 0x7F) * h1;
2603 if ((w1 == tw2) && (h1 == h2))
2605 /* Copy the terrain picture from the bitmap to the window */
2606 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2608 /* Mask out the tile */
2609 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2612 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2615 /* Need to stretch */
2618 /* Set the correct mode for stretching the tiles */
2619 SetStretchBltMode(hdc, COLORONCOLOR);
2621 /* Copy the terrain picture from the bitmap to the window */
2622 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
2624 /* Only draw if terrain and overlay are different */
2625 if ((x1 != x3) || (y1 != y3))
2627 /* Mask out the tile */
2628 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2631 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2637 # endif /* USE_TRANSPARENCY */
2641 if ((w1 == tw2) && (h1 == h2))
2643 /* Copy the picture from the bitmap to the window */
2644 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2647 /* Need to stretch */
2650 /* Set the correct mode for stretching the tiles */
2651 SetStretchBltMode(hdc, COLORONCOLOR);
2653 /* Copy the picture from the bitmap to the window */
2654 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2660 SelectObject(hdcSrc, hbmSrcOld);
2663 # ifdef USE_TRANSPARENCY
2665 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2668 SelectObject(hdcMask, hbmSrcOld);
2672 # endif /* USE_TRANSPARENCY */
2675 ReleaseDC(td->w, hdc);
2677 #else /* USE_GRAPHICS */
2679 /* Just erase this grid */
2680 return (Term_wipe_win(x, y, n));
2682 #endif /* USE_GRAPHICS */
2689 static void windows_map(void)
2691 term_data *td = &data[0];
2693 int x, min_x, max_x;
2694 int y, min_y, max_y;
2696 #ifdef USE_TRANSPARENCY
2700 /* Only in graphics mode */
2701 if (!use_graphics) return;
2704 Term_xtra_win_clear();
2706 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2707 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2708 td->map_active = TRUE;
2718 for (x = min_x; x < max_x; x++)
2720 for (y = min_y; y < max_y; y++)
2722 #ifdef USE_TRANSPARENCY
2723 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
2724 #else /* USE_TRANSPARENCY */
2725 map_info(y, x, &a, (char*)&c);
2726 #endif /* USE_TRANSPARENCY */
2728 /* Ignore non-graphics */
2729 if ((a & 0x80) && (c & 0x80))
2731 #ifdef USE_TRANSPARENCY
2732 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2733 #else /* USE_TRANSPARENCY */
2734 Term_pict_win(x - min_x, y - min_y, 1, &a, &c);
2735 #endif /* USE_TRANSPARENCY */
2740 /* Hilite the player */
2741 Term_curs_win(px - min_x, py - min_y);
2743 /* Wait for a keypress, flush key buffer */
2744 Term_inkey(&c, TRUE, TRUE);
2747 /* Switch off the map display */
2748 td->map_active = FALSE;
2750 /* Restore screen */
2751 Term_xtra_win_clear();
2756 /*** Other routines ***/
2760 * Create and initialize a "term_data" given a title
2762 static void term_data_link(term_data *td)
2766 /* Initialize the term */
2767 term_init(t, td->cols, td->rows, td->keys);
2769 /* Use a "software" cursor */
2770 t->soft_cursor = TRUE;
2772 /* Use "Term_pict" for "graphic" data */
2773 t->higher_pict = TRUE;
2775 /* Erase with "white space" */
2776 t->attr_blank = TERM_WHITE;
2777 t->char_blank = ' ';
2780 /* Prepare the init/nuke hooks */
2781 t->init_hook = Term_init_win;
2782 t->nuke_hook = Term_nuke_win;
2785 /* Prepare the template hooks */
2786 t->user_hook = Term_user_win;
2787 t->xtra_hook = Term_xtra_win;
2788 t->curs_hook = Term_curs_win;
2789 t->bigcurs_hook = Term_bigcurs_win;
2790 t->wipe_hook = Term_wipe_win;
2791 t->text_hook = Term_text_win;
2792 t->pict_hook = Term_pict_win;
2794 /* Remember where we came from */
2795 t->data = (vptr)(td);
2800 * Create the windows
2802 * First, instantiate the "default" values, then read the "ini_file"
2803 * to over-ride selected values, then create the windows, and fonts.
2805 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2806 * must make active to realize the palette. XXX XXX XXX
2808 static void init_windows(void)
2820 WIPE(td, term_data);
2824 td->s = angband_term_name[0];
2843 for (i = 1; i < MAX_TERM_DATA; i++)
2846 WIPE(td, term_data);
2847 td->s = angband_term_name[i];
2851 td->visible = FALSE;
2856 td->pos_x = (7 - i) * 30;
2857 td->pos_y = (7 - i) * 20;
2869 /* Main window (need these before term_getsize gets called) */
2871 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2872 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2877 /* Sub windows (need these before term_getsize gets called) */
2878 for (i = 1; i < MAX_TERM_DATA; i++)
2881 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2882 td->dwExStyle = (WS_EX_TOOLWINDOW);
2887 for (i = 0; i < MAX_TERM_DATA; i++)
2892 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2893 td->lf.lfHeight = td->tile_hgt;
2894 td->lf.lfWidth = td->tile_wid;
2895 td->lf.lfCharSet = SHIFTJIS_CHARSET;
2896 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2897 /* Activate the chosen font */
2898 term_force_font(td, NULL);
2899 td->tile_wid = td->font_wid;
2900 td->tile_hgt = td->font_hgt;
2902 /* Access the standard font file */
2903 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
2905 /* Activate the chosen font */
2906 if (term_force_font(td, buf))
2908 /* Access the standard font file */
2909 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2911 /* Force the use of that font */
2912 (void)term_force_font(td, buf);
2918 /* Assume not bizarre */
2919 td->bizarre = FALSE;
2924 /* Analyze the font */
2927 /* Resize the window */
2928 term_window_resize(td);
2932 /* Sub windows (reverse order) */
2933 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
2938 td->w = CreateWindowEx(td->dwExStyle, AngList,
2940 td->pos_x, td->pos_y,
2941 td->size_wid, td->size_hgt,
2942 HWND_DESKTOP, NULL, hInstance, NULL);
2945 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
2947 if (!td->w) quit("Failed to create sub-window");
2953 td->size_hack = TRUE;
2954 ShowWindow(td->w, SW_SHOW);
2955 td->size_hack = FALSE;
2959 angband_term[i] = &td->t;
2963 /* Activate the window */
2964 SetActiveWindow(td->w);
2969 term_window_pos(&data[i], HWND_TOPMOST);
2973 term_window_pos(&data[i], td->w);
2983 td->w = CreateWindowEx(td->dwExStyle, AppName,
2985 td->pos_x, td->pos_y,
2986 td->size_wid, td->size_hgt,
2987 HWND_DESKTOP, NULL, hInstance, NULL);
2990 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
2992 if (!td->w) quit("Failed to create Angband window");
2997 angband_term[0] = &td->t;
2999 /* Activate the main window */
3000 SetActiveWindow(td->w);
3002 /* Bring main window back to top */
3003 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3006 /* New palette XXX XXX XXX */
3007 (void)new_palette();
3010 /* Create a "brush" for drawing the "cursor" */
3011 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3014 /* Process pending messages */
3015 (void)Term_xtra_win_flush();
3023 static void setup_menus(void)
3027 HMENU hm = GetMenu(data[0].w);
3030 /* Menu "File", Disable all */
3031 EnableMenuItem(hm, IDM_FILE_NEW,
3032 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3033 EnableMenuItem(hm, IDM_FILE_OPEN,
3034 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3035 EnableMenuItem(hm, IDM_FILE_SAVE,
3036 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3037 EnableMenuItem(hm, IDM_FILE_EXIT,
3038 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3039 EnableMenuItem(hm, IDM_FILE_SCORE,
3040 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3043 /* No character available */
3044 if (!character_generated)
3046 /* Menu "File", Item "New" */
3047 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3049 /* Menu "File", Item "Open" */
3050 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3053 /* A character available */
3054 if (character_generated)
3056 /* Menu "File", Item "Save" */
3057 EnableMenuItem(hm, IDM_FILE_SAVE,
3058 MF_BYCOMMAND | MF_ENABLED);
3061 /* Menu "File", Item "Exit" */
3062 EnableMenuItem(hm, IDM_FILE_EXIT,
3063 MF_BYCOMMAND | MF_ENABLED);
3065 EnableMenuItem(hm, IDM_FILE_SCORE,
3066 MF_BYCOMMAND | MF_ENABLED);
3069 /* Menu "Window::Visibility" */
3070 for (i = 0; i < MAX_TERM_DATA; i++)
3072 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3073 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3075 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3076 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3078 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3079 MF_BYCOMMAND | MF_ENABLED);
3082 /* Menu "Window::Font" */
3083 for (i = 0; i < MAX_TERM_DATA; i++)
3085 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3086 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3088 if (data[i].visible)
3090 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3091 MF_BYCOMMAND | MF_ENABLED);
3095 /* Menu "Window::Window Position Fix" */
3096 for (i = 0; i < MAX_TERM_DATA; i++)
3098 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3099 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3101 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3102 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3104 if (data[i].visible)
3106 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3107 MF_BYCOMMAND | MF_ENABLED);
3111 /* Menu "Window::Bizarre Display" */
3112 for (i = 0; i < MAX_TERM_DATA; i++)
3114 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3115 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3117 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3118 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3120 if (data[i].visible)
3122 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3123 MF_BYCOMMAND | MF_ENABLED);
3128 /* Menu "Window::Increase Tile Width" */
3129 for (i = 0; i < MAX_TERM_DATA; i++)
3131 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3132 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3134 if (data[i].visible)
3136 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3137 MF_BYCOMMAND | MF_ENABLED);
3142 /* Menu "Window::Decrease Tile Width" */
3143 for (i = 0; i < MAX_TERM_DATA; i++)
3145 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3146 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3148 if (data[i].visible)
3150 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3151 MF_BYCOMMAND | MF_ENABLED);
3156 /* Menu "Window::Increase Tile Height" */
3157 for (i = 0; i < MAX_TERM_DATA; i++)
3159 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3160 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3162 if (data[i].visible)
3164 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3165 MF_BYCOMMAND | MF_ENABLED);
3170 /* Menu "Window::Decrease Tile Height" */
3171 for (i = 0; i < MAX_TERM_DATA; i++)
3173 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3174 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3176 if (data[i].visible)
3178 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3179 MF_BYCOMMAND | MF_ENABLED);
3184 /* Menu "Options", disable all */
3185 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3186 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3187 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3188 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3189 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3190 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3191 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3192 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3193 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3194 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3196 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3197 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3200 /* Menu "Options", Item "Map" */
3201 if (use_graphics != GRAPHICS_NONE)
3202 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3204 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3205 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3207 /* Menu "Options", update all */
3208 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3209 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3210 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3211 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3212 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3213 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3214 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3215 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3216 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3217 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3218 CheckMenuItem(hm, IDM_OPTIONS_BG,
3219 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3221 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3222 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3226 /* Menu "Options", Item "Graphics" */
3227 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3228 /* Menu "Options", Item "Graphics" */
3229 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3230 /* Menu "Options", Item "Graphics" */
3231 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3232 /* Menu "Options", Item "Graphics" */
3233 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3234 #endif /* USE_GRAPHICS */
3237 /* Menu "Options", Item "Sound" */
3238 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3239 #endif /* USE_SOUND */
3242 /* Menu "Options", Item "ScreenSaver" */
3243 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3244 MF_BYCOMMAND | MF_ENABLED);
3245 #endif /* USE_SAVER */
3250 * Check for double clicked (or dragged) savefile
3252 * Apparently, Windows copies the entire filename into the first
3253 * piece of the "command line string". Perhaps we should extract
3254 * the "basename" of that filename and append it to the "save" dir.
3256 static void check_for_save_file(LPSTR cmd_line)
3266 /* Extract filename */
3267 strcat(savefile, s);
3269 /* Validate the file */
3270 validate_file(savefile);
3272 /* Game in progress */
3273 game_in_progress = TRUE;
3281 * Process a menu command
3283 static void process_menus(WORD wCmd)
3300 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3302 plog("You cannot do that yet...");
3306 else if (game_in_progress)
3309 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3311 plog("You can't start a new game while you're still playing!");
3317 game_in_progress = TRUE;
3331 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3333 plog("You cannot do that yet...");
3337 else if (game_in_progress)
3340 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3342 plog("You can't open a new game while you're still playing!");
3348 memset(&ofn, 0, sizeof(ofn));
3349 ofn.lStructSize = sizeof(ofn);
3350 ofn.hwndOwner = data[0].w;
3351 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3352 ofn.nFilterIndex = 1;
3353 ofn.lpstrFile = savefile;
3354 ofn.nMaxFile = 1024;
3355 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3356 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3358 if (GetOpenFileName(&ofn))
3360 /* Load 'savefile' */
3361 validate_file(savefile);
3362 game_in_progress = TRUE;
3374 if (game_in_progress && character_generated)
3380 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3382 plog("You may not do that right now.");
3388 /* Hack -- Forget messages */
3393 do_cmd_save_game(FALSE);
3394 #else /* ZANGBAND */
3396 #endif /* ZANGBAND */
3401 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3403 plog("You may not do that right now.");
3413 if (game_in_progress && character_generated)
3419 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3421 plog("You may not do that right now.");
3427 /* Hack -- Forget messages */
3436 /* do_cmd_save_game(FALSE); */
3437 #else /* ZANGBAND */
3438 /* do_cmd_save_game(); */
3439 #endif /* ZANGBAND */
3440 Term_key_push(SPECIAL_KEY_QUIT);
3448 case IDM_FILE_SCORE:
3452 /* Build the filename */
3453 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3455 /* Open the binary high score file, for reading */
3456 highscore_fd = fd_open(buf, O_RDONLY);
3458 /* Paranoia -- No score file */
3459 if (highscore_fd < 0)
3461 msg_print("Score file unavailable.");
3471 /* Display the scores */
3472 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3474 /* Shut the high score file */
3475 (void)fd_close(highscore_fd);
3477 /* Forget the high score fd */
3483 /* Hack - Flush it */
3491 case IDM_WINDOW_VIS_0:
3494 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3496 plog("You are not allowed to do that!");
3503 /* Window visibility */
3504 case IDM_WINDOW_VIS_1:
3505 case IDM_WINDOW_VIS_2:
3506 case IDM_WINDOW_VIS_3:
3507 case IDM_WINDOW_VIS_4:
3508 case IDM_WINDOW_VIS_5:
3509 case IDM_WINDOW_VIS_6:
3510 case IDM_WINDOW_VIS_7:
3512 i = wCmd - IDM_WINDOW_VIS_0;
3514 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3521 ShowWindow(td->w, SW_SHOW);
3522 term_data_redraw(td);
3526 td->visible = FALSE;
3528 ShowWindow(td->w, SW_HIDE);
3535 case IDM_WINDOW_FONT_0:
3536 case IDM_WINDOW_FONT_1:
3537 case IDM_WINDOW_FONT_2:
3538 case IDM_WINDOW_FONT_3:
3539 case IDM_WINDOW_FONT_4:
3540 case IDM_WINDOW_FONT_5:
3541 case IDM_WINDOW_FONT_6:
3542 case IDM_WINDOW_FONT_7:
3544 i = wCmd - IDM_WINDOW_FONT_0;
3546 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3550 term_change_font(td);
3555 /* Window Z Position */
3556 case IDM_WINDOW_POS_1:
3557 case IDM_WINDOW_POS_2:
3558 case IDM_WINDOW_POS_3:
3559 case IDM_WINDOW_POS_4:
3560 case IDM_WINDOW_POS_5:
3561 case IDM_WINDOW_POS_6:
3562 case IDM_WINDOW_POS_7:
3564 i = wCmd - IDM_WINDOW_POS_0;
3566 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3570 if (!td->posfix && td->visible)
3573 term_window_pos(td, HWND_TOPMOST);
3578 term_window_pos(td, data[0].w);
3584 /* Bizarre Display */
3585 case IDM_WINDOW_BIZ_0:
3586 case IDM_WINDOW_BIZ_1:
3587 case IDM_WINDOW_BIZ_2:
3588 case IDM_WINDOW_BIZ_3:
3589 case IDM_WINDOW_BIZ_4:
3590 case IDM_WINDOW_BIZ_5:
3591 case IDM_WINDOW_BIZ_6:
3592 case IDM_WINDOW_BIZ_7:
3594 i = wCmd - IDM_WINDOW_BIZ_0;
3596 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3600 td->bizarre = !td->bizarre;
3604 term_window_resize(td);
3609 /* Increase Tile Width */
3610 case IDM_WINDOW_I_WID_0:
3611 case IDM_WINDOW_I_WID_1:
3612 case IDM_WINDOW_I_WID_2:
3613 case IDM_WINDOW_I_WID_3:
3614 case IDM_WINDOW_I_WID_4:
3615 case IDM_WINDOW_I_WID_5:
3616 case IDM_WINDOW_I_WID_6:
3617 case IDM_WINDOW_I_WID_7:
3619 i = wCmd - IDM_WINDOW_I_WID_0;
3621 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3629 term_window_resize(td);
3634 /* Decrease Tile Height */
3635 case IDM_WINDOW_D_WID_0:
3636 case IDM_WINDOW_D_WID_1:
3637 case IDM_WINDOW_D_WID_2:
3638 case IDM_WINDOW_D_WID_3:
3639 case IDM_WINDOW_D_WID_4:
3640 case IDM_WINDOW_D_WID_5:
3641 case IDM_WINDOW_D_WID_6:
3642 case IDM_WINDOW_D_WID_7:
3644 i = wCmd - IDM_WINDOW_D_WID_0;
3646 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3654 term_window_resize(td);
3659 /* Increase Tile Height */
3660 case IDM_WINDOW_I_HGT_0:
3661 case IDM_WINDOW_I_HGT_1:
3662 case IDM_WINDOW_I_HGT_2:
3663 case IDM_WINDOW_I_HGT_3:
3664 case IDM_WINDOW_I_HGT_4:
3665 case IDM_WINDOW_I_HGT_5:
3666 case IDM_WINDOW_I_HGT_6:
3667 case IDM_WINDOW_I_HGT_7:
3669 i = wCmd - IDM_WINDOW_I_HGT_0;
3671 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3679 term_window_resize(td);
3684 /* Decrease Tile Height */
3685 case IDM_WINDOW_D_HGT_0:
3686 case IDM_WINDOW_D_HGT_1:
3687 case IDM_WINDOW_D_HGT_2:
3688 case IDM_WINDOW_D_HGT_3:
3689 case IDM_WINDOW_D_HGT_4:
3690 case IDM_WINDOW_D_HGT_5:
3691 case IDM_WINDOW_D_HGT_6:
3692 case IDM_WINDOW_D_HGT_7:
3694 i = wCmd - IDM_WINDOW_D_HGT_0;
3696 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3704 term_window_resize(td);
3709 case IDM_OPTIONS_NO_GRAPHICS:
3714 plog("You may not do that right now.");
3718 /* Toggle "arg_graphics" */
3719 if (arg_graphics != GRAPHICS_NONE)
3721 arg_graphics = GRAPHICS_NONE;
3723 /* React to changes */
3724 Term_xtra_win_react();
3726 /* Hack -- Force redraw */
3727 Term_key_push(KTRL('R'));
3733 case IDM_OPTIONS_OLD_GRAPHICS:
3738 plog("You may not do that right now.");
3742 /* Toggle "arg_graphics" */
3743 if (arg_graphics != GRAPHICS_ORIGINAL)
3745 arg_graphics = GRAPHICS_ORIGINAL;
3747 /* React to changes */
3748 Term_xtra_win_react();
3750 /* Hack -- Force redraw */
3751 Term_key_push(KTRL('R'));
3757 case IDM_OPTIONS_NEW_GRAPHICS:
3762 plog("You may not do that right now.");
3766 /* Toggle "arg_graphics" */
3767 if (arg_graphics != GRAPHICS_ADAM_BOLT)
3769 arg_graphics = GRAPHICS_ADAM_BOLT;
3771 /* React to changes */
3772 Term_xtra_win_react();
3774 /* Hack -- Force redraw */
3775 Term_key_push(KTRL('R'));
3781 case IDM_OPTIONS_BIGTILE:
3783 term_data *td = &data[0];
3788 plog("You may not do that right now.");
3792 /* Toggle "arg_sound" */
3793 arg_bigtile = !arg_bigtile;
3796 Term_activate(&td->t);
3798 /* Resize the term */
3799 Term_resize(td->cols, td->rows);
3802 InvalidateRect(td->w, NULL, TRUE);
3807 case IDM_OPTIONS_SOUND:
3812 plog("You may not do that right now.");
3816 /* Toggle "arg_sound" */
3817 arg_sound = !arg_sound;
3819 /* React to changes */
3820 Term_xtra_win_react();
3822 /* Hack -- Force redraw */
3823 Term_key_push(KTRL('R'));
3829 case IDM_OPTIONS_BG:
3834 plog("You may not do that right now.");
3838 /* Toggle "use_bg" */
3843 /* React to changes */
3844 Term_xtra_win_react();
3846 /* Hack -- Force redraw */
3847 Term_key_push(KTRL('R'));
3853 case IDM_OPTIONS_OPEN_BG:
3858 plog("You may not do that right now.");
3863 memset(&ofn, 0, sizeof(ofn));
3864 ofn.lStructSize = sizeof(ofn);
3865 ofn.hwndOwner = data[0].w;
3866 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3867 ofn.nFilterIndex = 1;
3868 ofn.lpstrFile = bg_bitmap_file;
3869 ofn.nMaxFile = 1023;
3870 ofn.lpstrInitialDir = NULL;
3872 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
3874 ofn.lpstrTitle = "Choose wall paper.";
3876 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3878 if (GetOpenFileName(&ofn))
3880 /* Load 'savefile' */
3885 /* React to changes */
3886 Term_xtra_win_react();
3888 /* Hack -- Force redraw */
3889 Term_key_push(KTRL('R'));
3894 case IDM_DUMP_SCREEN_HTML:
3896 static char buf[1024] = "";
3897 memset(&ofn, 0, sizeof(ofn));
3898 ofn.lStructSize = sizeof(ofn);
3899 ofn.hwndOwner = data[0].w;
3900 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
3901 ofn.nFilterIndex = 1;
3902 ofn.lpstrFile = buf;
3903 ofn.nMaxFile = 1023;
3904 ofn.lpstrDefExt = "html";
3905 ofn.lpstrInitialDir = NULL;
3907 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
3909 ofn.lpstrTitle = "Save screen dump as HTML.";
3911 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
3913 if (GetSaveFileName(&ofn))
3915 do_cmd_save_screen_html_aux(buf, 0);
3922 case IDM_OPTIONS_SAVER:
3926 DestroyWindow(hwndSaver);
3931 /* Create a screen scaver window */
3932 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
3933 "Angband Screensaver",
3934 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
3935 0, 0, GetSystemMetrics(SM_CXSCREEN),
3936 GetSystemMetrics(SM_CYSCREEN),
3937 NULL, NULL, hInstance, NULL);
3941 /* Push the window to the bottom XXX XXX XXX */
3942 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3947 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
3949 plog("Failed to create saver window");
3959 case IDM_OPTIONS_MAP:
3965 case IDM_HELP_CONTENTS:
3969 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
3970 if (check_file(tmp))
3972 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
3977 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
3978 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
3980 plog_fmt("Cannot find help file: %s", tmp);
3981 plog("Use the online help files instead.");
3986 #else /* HTML_HELP */
3989 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
3990 if (check_file(tmp))
3992 sprintf(buf, "winhelp.exe %s", tmp);
3993 WinExec(buf, SW_NORMAL);
3998 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
3999 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4001 plog_fmt("Cannot find help file: %s", tmp);
4002 plog("Use the online help files instead.");
4007 #endif /* HTML_HELP */
4015 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4016 WPARAM wParam, LPARAM lParam);
4017 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4018 WPARAM wParam, LPARAM lParam)
4019 #else /* __MWERKS__ */
4020 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4021 WPARAM wParam, LPARAM lParam)
4022 #endif /* __MWERKS__ */
4028 MINMAXINFO FAR *lpmmi;
4034 /* Acquire proper "term_data" info */
4035 td = (term_data *)GetWindowLong(hWnd, 0);
4037 /* Handle message */
4043 SetWindowLong(hWnd, 0, (LONG)(my_td));
4053 case WM_GETMINMAXINFO:
4055 MINMAXINFO FAR *lpmmi;
4058 lpmmi = (MINMAXINFO FAR *)lParam;
4060 /* this message was sent before WM_NCCREATE */
4063 /* Minimum window size is 80x24 */
4064 rc.left = rc.top = 0;
4065 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4066 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4069 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4071 /* Save minimum size */
4072 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4073 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4080 BeginPaint(hWnd, &ps);
4081 if (td) term_data_redraw(td);
4082 EndPaint(hWnd, &ps);
4083 ValidateRect(hWnd, NULL);
4094 /* Extract the modifiers */
4095 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4096 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4097 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4099 /* Handle "special" keys */
4100 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4102 /* Begin the macro trigger */
4105 /* Send the modifiers */
4106 if (mc) Term_keypress('C');
4107 if (ms) Term_keypress('S');
4108 if (ma) Term_keypress('A');
4110 /* Extract "scan code" */
4111 i = LOBYTE(HIWORD(lParam));
4113 /* Introduce the scan code */
4116 /* Encode the hexidecimal scan code */
4117 Term_keypress(hexsym[i/16]);
4118 Term_keypress(hexsym[i%16]);
4120 /* End the macro trigger */
4131 Term_keypress(wParam);
4143 if (game_in_progress && character_generated)
4148 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4150 plog("You may not do that right now.");
4155 /* Hack -- Forget messages */
4164 /* do_cmd_save_game(FALSE); */
4165 #else /* ZANGBAND */
4166 /* do_cmd_save_game(); */
4167 #endif /* ZANGBAND */
4183 process_menus(LOWORD(wParam));
4189 /* this message was sent before WM_NCCREATE */
4192 /* it was sent from inside CreateWindowEx */
4193 if (!td->w) return 1;
4195 /* was sent from WM_SIZE */
4196 if (td->size_hack) return 1;
4200 case SIZE_MINIMIZED:
4202 /* Hide sub-windows */
4203 for (i = 1; i < MAX_TERM_DATA; i++)
4205 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4210 case SIZE_MAXIMIZED:
4212 /* fall through XXX XXX XXX */
4217 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4218 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4221 if ((td->cols != cols) || (td->rows != rows))
4223 /* Save the new size */
4228 Term_activate(&td->t);
4230 /* Resize the term */
4231 Term_resize(td->cols, td->rows);
4234 InvalidateRect(td->w, NULL, TRUE);
4237 td->size_hack = TRUE;
4239 /* Show sub-windows */
4240 for (i = 1; i < MAX_TERM_DATA; i++)
4242 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4245 td->size_hack = FALSE;
4253 case WM_PALETTECHANGED:
4255 /* Ignore if palette change caused by itself */
4256 if ((HWND)wParam == hWnd) return 0;
4258 /* Fall through... */
4261 case WM_QUERYNEWPALETTE:
4263 if (!paletted) return 0;
4267 SelectPalette(hdc, hPal, FALSE);
4269 i = RealizePalette(hdc);
4271 /* if any palette entries changed, repaint the window. */
4272 if (i) InvalidateRect(hWnd, NULL, TRUE);
4274 ReleaseDC(hWnd, hdc);
4281 if (wParam && !HIWORD(lParam))
4283 /* Do something to sub-windows */
4284 for (i = 1; i < MAX_TERM_DATA; i++)
4286 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4289 /* Focus on main window */
4298 case WM_ACTIVATEAPP:
4300 for (i = 1; i < MAX_TERM_DATA; i++)
4306 ShowWindow(data[i].w, SW_SHOW);
4310 ShowWindow(data[i].w, SW_HIDE);
4317 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4322 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4323 WPARAM wParam, LPARAM lParam);
4324 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4325 WPARAM wParam, LPARAM lParam)
4326 #else /* __MWERKS__ */
4327 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4328 WPARAM wParam, LPARAM lParam)
4329 #endif /* __MWERKS__ */
4333 MINMAXINFO FAR *lpmmi;
4341 /* Acquire proper "term_data" info */
4342 td = (term_data *)GetWindowLong(hWnd, 0);
4344 /* Process message */
4350 SetWindowLong(hWnd, 0, (LONG)(my_td));
4360 case WM_GETMINMAXINFO:
4362 MINMAXINFO FAR *lpmmi;
4365 lpmmi = (MINMAXINFO FAR *)lParam;
4367 /* this message was sent before WM_NCCREATE */
4370 /* Minimum window size is 80x24 */
4371 rc.left = rc.top = 0;
4372 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4373 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4376 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4378 /* Save minimum size */
4379 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4380 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4390 /* this message was sent before WM_NCCREATE */
4393 /* it was sent from inside CreateWindowEx */
4394 if (!td->w) return 1;
4396 /* was sent from inside WM_SIZE */
4397 if (td->size_hack) return 1;
4399 td->size_hack = TRUE;
4401 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4402 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4405 if ((td->cols != cols) || (td->rows != rows))
4408 term *old_term = Term;
4410 /* Save the new size */
4415 Term_activate(&td->t);
4417 /* Resize the term */
4418 Term_resize(td->cols, td->rows);
4421 Term_activate(old_term);
4424 InvalidateRect(td->w, NULL, TRUE);
4426 /* HACK - Redraw all windows */
4427 p_ptr->window = 0xFFFFFFFF;
4431 td->size_hack = FALSE;
4438 BeginPaint(hWnd, &ps);
4439 if (td) term_data_redraw(td);
4440 EndPaint(hWnd, &ps);
4451 /* Extract the modifiers */
4452 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4453 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4454 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4456 /* Handle "special" keys */
4457 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4459 /* Begin the macro trigger */
4462 /* Send the modifiers */
4463 if (mc) Term_keypress('C');
4464 if (ms) Term_keypress('S');
4465 if (ma) Term_keypress('A');
4467 /* Extract "scan code" */
4468 i = LOBYTE(HIWORD(lParam));
4470 /* Introduce the scan code */
4473 /* Encode the hexidecimal scan code */
4474 Term_keypress(hexsym[i/16]);
4475 Term_keypress(hexsym[i%16]);
4477 /* End the macro trigger */
4488 Term_keypress(wParam);
4492 case WM_PALETTECHANGED:
4494 /* ignore if palette change caused by itself */
4495 if ((HWND)wParam == hWnd) return FALSE;
4496 /* otherwise, fall through!!! */
4499 case WM_QUERYNEWPALETTE:
4501 if (!paletted) return 0;
4503 SelectPalette(hdc, hPal, FALSE);
4504 i = RealizePalette(hdc);
4505 /* if any palette entries changed, repaint the window. */
4506 if (i) InvalidateRect(hWnd, NULL, TRUE);
4507 ReleaseDC(hWnd, hdc);
4511 case WM_NCLBUTTONDOWN:
4515 if (wParam == HTCLOSE) wParam = HTSYSMENU;
4516 #endif /* HTCLOSE */
4518 if (wParam == HTSYSMENU)
4522 td->visible = FALSE;
4523 ShowWindow(td->w, SW_HIDE);
4533 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4539 #define MOUSE_SENS 40
4542 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4543 WPARAM wParam, LPARAM lParam);
4544 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4545 WPARAM wParam, LPARAM lParam)
4546 #else /* __MWERKS__ */
4547 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4548 WPARAM wParam, LPARAM lParam)
4549 #endif /* __MWERKS__ */
4551 static int iMouse = 0;
4552 static WORD xMouse = 0;
4553 static WORD yMouse = 0;
4576 if (LOWORD(wParam) == WA_INACTIVE) break;
4578 /* else fall through */
4582 case WM_LBUTTONDOWN:
4583 case WM_MBUTTONDOWN:
4584 case WM_RBUTTONDOWN:
4587 SendMessage(hWnd, WM_CLOSE, 0, 0);
4595 dx = LOWORD(lParam) - xMouse;
4596 dy = HIWORD(lParam) - yMouse;
4598 if (dx < 0) dx = -dx;
4599 if (dy < 0) dy = -dy;
4601 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
4603 SendMessage(hWnd, WM_CLOSE, 0, 0);
4607 /* Save last location */
4609 xMouse = LOWORD(lParam);
4610 yMouse = HIWORD(lParam);
4617 DestroyWindow(hwndSaver);
4624 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4627 #endif /* USE_SAVER */
4633 /*** Temporary Hooks ***/
4637 * Display warning message (see "z-util.c")
4639 static void hack_plog(cptr str)
4641 /* Give a warning */
4645 MessageBox(NULL, str, "·Ù¹ð¡ª",
4646 MB_ICONEXCLAMATION | MB_OK);
4648 MessageBox(NULL, str, "Warning",
4649 MB_ICONEXCLAMATION | MB_OK);
4657 * Display error message and quit (see "z-util.c")
4659 static void hack_quit(cptr str)
4661 /* Give a warning */
4665 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
4666 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4668 MessageBox(NULL, str, "Error",
4669 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4674 /* Unregister the classes */
4675 UnregisterClass(AppName, hInstance);
4677 /* Destroy the icon */
4678 if (hIcon) DestroyIcon(hIcon);
4686 /*** Various hooks ***/
4690 * Display warning message (see "z-util.c")
4692 static void hook_plog(cptr str)
4698 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
4699 MB_ICONEXCLAMATION | MB_OK);
4701 MessageBox(data[0].w, str, "Warning",
4702 MB_ICONEXCLAMATION | MB_OK);
4710 * Display error message and quit (see "z-util.c")
4712 static void hook_quit(cptr str)
4717 /* Give a warning */
4721 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
4722 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4724 MessageBox(data[0].w, str, "Error",
4725 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4731 /* Save the preferences */
4735 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
4737 /* Destroy all windows */
4738 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
4740 term_force_font(&data[i], NULL);
4741 if (data[i].font_want) string_free(data[i].font_want);
4742 if (data[i].w) DestroyWindow(data[i].w);
4746 /* Free the bitmap stuff */
4748 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
4749 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
4751 #ifdef USE_TRANSPARENCY
4752 if (infMask.hPalette) DeleteObject(infMask.hPalette);
4753 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
4754 #endif /* USE_TRANSPARENCY */
4756 #endif /* USE_GRAPHICS */
4758 /*** Free some other stuff ***/
4760 DeleteObject(hbrYellow);
4765 if (hPal) DeleteObject(hPal);
4767 UnregisterClass(AppName, hInstance);
4769 if (hIcon) DestroyIcon(hIcon);
4776 /*** Initialize ***/
4782 static void init_stuff(void)
4789 /* Get program name with full path */
4790 GetModuleFileName(hInstance, path, 512);
4792 /* Save the "program name" XXX XXX XXX */
4795 /* Get the name of the "*.ini" file */
4796 strcpy(path + strlen(path) - 4, ".INI");
4798 /* Save the the name of the ini-file */
4799 ini_file = string_make(path);
4801 /* Analyze the path */
4807 if (path[i] == '\\')
4814 /* Add "lib" to the path */
4815 strcpy(path + i + 1, "lib\\");
4817 /* Validate the path */
4818 validate_dir(path, TRUE);
4820 /* Init the file paths */
4821 init_file_paths(path);
4823 /* Hack -- Validate the paths */
4824 validate_dir(ANGBAND_DIR_APEX, FALSE);
4825 validate_dir(ANGBAND_DIR_BONE, FALSE);
4827 /* Allow missing 'edit' directory */
4828 if (!check_dir(ANGBAND_DIR_EDIT))
4830 /* Must have 'data'! */
4831 validate_dir(ANGBAND_DIR_DATA, TRUE);
4835 /* Don't need 'data' */
4836 validate_dir(ANGBAND_DIR_DATA, FALSE);
4839 validate_dir(ANGBAND_DIR_FILE, TRUE);
4840 validate_dir(ANGBAND_DIR_HELP, FALSE);
4841 validate_dir(ANGBAND_DIR_INFO, FALSE);
4842 validate_dir(ANGBAND_DIR_PREF, TRUE);
4843 validate_dir(ANGBAND_DIR_SAVE, FALSE);
4844 validate_dir(ANGBAND_DIR_USER, TRUE);
4845 validate_dir(ANGBAND_DIR_XTRA, TRUE);
4847 /* Build the filename */
4849 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
4851 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
4855 /* Hack -- Validate the "news.txt" file */
4856 validate_file(path);
4860 /* Build the "font" path */
4861 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
4863 /* Allocate the path */
4864 ANGBAND_DIR_XTRA_FONT = string_make(path);
4866 /* Validate the "font" directory */
4867 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
4869 /* Build the filename */
4870 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
4872 /* Hack -- Validate the basic font */
4873 validate_file(path);
4879 /* Build the "graf" path */
4880 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
4882 /* Allocate the path */
4883 ANGBAND_DIR_XTRA_GRAF = string_make(path);
4885 /* Validate the "graf" directory */
4886 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
4888 #endif /* USE_GRAPHICS */
4893 /* Build the "sound" path */
4894 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
4896 /* Allocate the path */
4897 ANGBAND_DIR_XTRA_SOUND = string_make(path);
4899 /* Validate the "sound" directory */
4900 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
4902 #endif /* USE_SOUND */
4906 /* Build the "music" path */
4907 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
4909 /* Allocate the path */
4910 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
4912 /* Validate the "music" directory */
4913 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
4915 #endif /* USE_MUSIC */
4917 /* Build the "help" path */
4918 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
4920 /* Allocate the path */
4921 ANGBAND_DIR_XTRA_HELP = string_make(path);
4923 /* Validate the "help" directory */
4924 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
4928 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
4929 LPSTR lpCmdLine, int nCmdShow)
4941 if (hPrevInst == NULL)
4943 wc.style = CS_CLASSDC;
4944 wc.lpfnWndProc = AngbandWndProc;
4946 wc.cbWndExtra = 4; /* one long pointer to term_data */
4947 wc.hInstance = hInst;
4948 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
4949 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
4950 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
4951 wc.lpszMenuName = AppName;
4952 wc.lpszClassName = AppName;
4954 if (!RegisterClass(&wc)) exit(1);
4956 wc.lpfnWndProc = AngbandListProc;
4957 wc.lpszMenuName = NULL;
4958 wc.lpszClassName = AngList;
4960 if (!RegisterClass(&wc)) exit(2);
4964 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
4965 wc.lpfnWndProc = AngbandSaverProc;
4967 wc.lpszMenuName = NULL;
4968 wc.lpszClassName = "WindowsScreenSaverClass";
4970 if (!RegisterClass(&wc)) exit(3);
4976 /* Temporary hooks */
4977 plog_aux = hack_plog;
4978 quit_aux = hack_quit;
4979 core_aux = hack_quit;
4981 /* Prepare the filepaths */
4984 /* Initialize the keypress analyzer */
4985 for (i = 0; special_key_list[i]; ++i)
4987 special_key[special_key_list[i]] = TRUE;
4989 /* Initialize the keypress analyzer */
4990 for (i = 0; ignore_key_list[i]; ++i)
4992 ignore_key[ignore_key_list[i]] = TRUE;
4995 /* Determine if display is 16/256/true color */
4997 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
4998 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
4999 ReleaseDC(NULL, hdc);
5001 /* Initialize the colors */
5002 for (i = 0; i < 256; i++)
5006 /* Extract desired values */
5007 rv = angband_color_table[i][1];
5008 gv = angband_color_table[i][2];
5009 bv = angband_color_table[i][3];
5011 /* Extract the "complex" code */
5012 win_clr[i] = PALETTERGB(rv, gv, bv);
5014 /* Save the "simple" code */
5015 angband_color_table[i][0] = win_pal[i];
5018 /* Prepare the windows */
5024 /* Activate hooks */
5025 plog_aux = hook_plog;
5026 quit_aux = hook_quit;
5027 core_aux = hook_quit;
5029 /* Set the system suffix */
5030 ANGBAND_SYS = "win";
5032 /* Set the keyboard suffix */
5033 if (7 != GetKeyboardType(0))
5034 ANGBAND_KEYBOARD = "0";
5037 /* Japanese keyboard */
5038 switch (GetKeyboardType(1))
5040 case 0x0D01: case 0x0D02:
5041 case 0x0D03: case 0x0D04:
5042 case 0x0D05: case 0x0D06:
5044 ANGBAND_KEYBOARD = "NEC98";
5048 ANGBAND_KEYBOARD = "JAPAN";
5056 /* We are now initialized */
5060 if(lpCmdLine[0] == '-'){
5061 switch(lpCmdLine[1])
5066 if (!lpCmdLine[2]) break;
5067 chuukei_server = TRUE;
5068 if(connect_chuukei_server(&lpCmdLine[2])<0){
5069 msg_print("connect fail");
5072 msg_print("connect");
5080 if (!lpCmdLine[2]) break;
5081 chuukei_client = TRUE;
5082 connect_chuukei_server(&lpCmdLine[2]);
5092 /* Did the user double click on a save file? */
5093 if(!chuukei_server) check_for_save_file(lpCmdLine);
5095 /* Did the user double click on a save file? */
5096 check_for_save_file(lpCmdLine);
5099 /* Prompt the user */
5101 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5103 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5108 /* Process messages forever */
5109 while (GetMessage(&msg, NULL, 0, 0))
5111 TranslateMessage(&msg);
5112 DispatchMessage(&msg);
5123 #endif /* WINDOWS */