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).
84 * Extract the "WIN32" flag from the compiler
86 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
94 * Hack -- allow use of "screen saver" mode
100 * Menu constants -- see "ANGBAND.RC"
103 #define IDM_FILE_NEW 100
104 #define IDM_FILE_OPEN 101
105 #define IDM_FILE_SAVE 110
106 #define IDM_FILE_SCORE 120
107 #define IDM_FILE_MOVIE 121
108 #define IDM_FILE_EXIT 130
110 #define IDM_WINDOW_VIS_0 200
111 #define IDM_WINDOW_VIS_1 201
112 #define IDM_WINDOW_VIS_2 202
113 #define IDM_WINDOW_VIS_3 203
114 #define IDM_WINDOW_VIS_4 204
115 #define IDM_WINDOW_VIS_5 205
116 #define IDM_WINDOW_VIS_6 206
117 #define IDM_WINDOW_VIS_7 207
119 #define IDM_WINDOW_FONT_0 210
120 #define IDM_WINDOW_FONT_1 211
121 #define IDM_WINDOW_FONT_2 212
122 #define IDM_WINDOW_FONT_3 213
123 #define IDM_WINDOW_FONT_4 214
124 #define IDM_WINDOW_FONT_5 215
125 #define IDM_WINDOW_FONT_6 216
126 #define IDM_WINDOW_FONT_7 217
128 #define IDM_WINDOW_POS_0 220
129 #define IDM_WINDOW_POS_1 221
130 #define IDM_WINDOW_POS_2 222
131 #define IDM_WINDOW_POS_3 223
132 #define IDM_WINDOW_POS_4 224
133 #define IDM_WINDOW_POS_5 225
134 #define IDM_WINDOW_POS_6 226
135 #define IDM_WINDOW_POS_7 227
137 #define IDM_WINDOW_BIZ_0 230
138 #define IDM_WINDOW_BIZ_1 231
139 #define IDM_WINDOW_BIZ_2 232
140 #define IDM_WINDOW_BIZ_3 233
141 #define IDM_WINDOW_BIZ_4 234
142 #define IDM_WINDOW_BIZ_5 235
143 #define IDM_WINDOW_BIZ_6 236
144 #define IDM_WINDOW_BIZ_7 237
146 #define IDM_WINDOW_I_WID_0 240
147 #define IDM_WINDOW_I_WID_1 241
148 #define IDM_WINDOW_I_WID_2 242
149 #define IDM_WINDOW_I_WID_3 243
150 #define IDM_WINDOW_I_WID_4 244
151 #define IDM_WINDOW_I_WID_5 245
152 #define IDM_WINDOW_I_WID_6 246
153 #define IDM_WINDOW_I_WID_7 247
155 #define IDM_WINDOW_D_WID_0 250
156 #define IDM_WINDOW_D_WID_1 251
157 #define IDM_WINDOW_D_WID_2 252
158 #define IDM_WINDOW_D_WID_3 253
159 #define IDM_WINDOW_D_WID_4 254
160 #define IDM_WINDOW_D_WID_5 255
161 #define IDM_WINDOW_D_WID_6 256
162 #define IDM_WINDOW_D_WID_7 257
164 #define IDM_WINDOW_I_HGT_0 260
165 #define IDM_WINDOW_I_HGT_1 261
166 #define IDM_WINDOW_I_HGT_2 262
167 #define IDM_WINDOW_I_HGT_3 263
168 #define IDM_WINDOW_I_HGT_4 264
169 #define IDM_WINDOW_I_HGT_5 265
170 #define IDM_WINDOW_I_HGT_6 266
171 #define IDM_WINDOW_I_HGT_7 267
173 #define IDM_WINDOW_D_HGT_0 270
174 #define IDM_WINDOW_D_HGT_1 271
175 #define IDM_WINDOW_D_HGT_2 272
176 #define IDM_WINDOW_D_HGT_3 273
177 #define IDM_WINDOW_D_HGT_4 274
178 #define IDM_WINDOW_D_HGT_5 275
179 #define IDM_WINDOW_D_HGT_6 276
180 #define IDM_WINDOW_D_HGT_7 277
182 #define IDM_OPTIONS_NO_GRAPHICS 400
183 #define IDM_OPTIONS_OLD_GRAPHICS 401
184 #define IDM_OPTIONS_NEW_GRAPHICS 402
185 #define IDM_OPTIONS_NEW2_GRAPHICS 403
186 #define IDM_OPTIONS_BIGTILE 409
187 #define IDM_OPTIONS_SOUND 410
188 #define IDM_OPTIONS_MUSIC 411
189 #define IDM_OPTIONS_SAVER 420
190 #define IDM_OPTIONS_MAP 430
191 #define IDM_OPTIONS_BG 440
192 #define IDM_OPTIONS_OPEN_BG 441
194 #define IDM_DUMP_SCREEN_HTML 450
196 #define IDM_HELP_CONTENTS 901
201 * This may need to be removed for some compilers XXX XXX XXX
208 * Exclude parts of WINDOWS.H that are not needed
210 #define NOCOMM /* Comm driver APIs and definitions */
211 #define NOLOGERROR /* LogError() and related definitions */
212 #define NOPROFILER /* Profiler APIs */
213 #define NOLFILEIO /* _l* file I/O routines */
214 #define NOOPENFILE /* OpenFile and related definitions */
215 #define NORESOURCE /* Resource management */
216 #define NOATOM /* Atom management */
217 #define NOLANGUAGE /* Character test routines */
218 #define NOLSTRING /* lstr* string management routines */
219 #define NODBCS /* Double-byte character set routines */
220 #define NOKEYBOARDINFO /* Keyboard driver routines */
221 #define NOCOLOR /* COLOR_* color values */
222 #define NODRAWTEXT /* DrawText() and related definitions */
223 #define NOSCALABLEFONT /* Truetype scalable font support */
224 #define NOMETAFILE /* Metafile support */
225 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
226 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
227 #define NOKEYSTATES /* MK_* message key state flags */
228 #define NOWH /* SetWindowsHook and related WH_* definitions */
229 #define NOCLIPBOARD /* Clipboard APIs and definitions */
230 #define NOICONS /* IDI_* icon IDs */
231 #define NOMDI /* MDI support */
232 #define NOHELP /* Help support */
234 /* Not defined since it breaks Borland C++ 5.5 */
235 /* #define NOCTLMGR */ /* Control management and controls */
238 * Exclude parts of WINDOWS.H that are not needed (Win32)
240 #define WIN32_LEAN_AND_MEAN
241 #define NONLS /* All NLS defines and routines */
242 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
243 #define NOKANJI /* Kanji support stuff. */
244 #define NOMCX /* Modem Configuration Extensions */
247 * Include the "windows" support file
252 * Exclude parts of MMSYSTEM.H that are not needed
254 #define MMNODRV /* Installable driver support */
255 #define MMNOWAVE /* Waveform support */
256 #define MMNOMIDI /* MIDI support */
257 #define MMNOAUX /* Auxiliary audio support */
258 #define MMNOTIMER /* Timer support */
259 #define MMNOJOY /* Joystick support */
260 #define MMNOMCI /* MCI support */
261 #define MMNOMMIO /* Multimedia file I/O support */
262 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
265 * Include some more files. Note: the Cygnus Cygwin compiler
266 * doesn't use mmsystem.h instead it includes the winmm library
267 * which performs a similar function.
269 #include <mmsystem.h>
273 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
274 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
276 /* #define HTML_HELP */
279 #include <htmlhelp.h>
280 #endif /* HTML_HELP */
283 * Include the support for loading bitmaps
286 # include "readdib.h"
290 * Hack -- Fake declarations from "dos.h" XXX XXX XXX
293 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
295 #define FA_LABEL 0x08 /* Volume label */
296 #define FA_DIREC 0x10 /* Directory */
297 unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
301 * Silliness in WIN32 drawing routine
304 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
308 * Silliness for Windows 95
310 #ifndef WS_EX_TOOLWINDOW
311 # define WS_EX_TOOLWINDOW 0
315 * Foreground color bits (hard-coded by DOS)
317 #define VID_BLACK 0x00
318 #define VID_BLUE 0x01
319 #define VID_GREEN 0x02
320 #define VID_CYAN 0x03
322 #define VID_MAGENTA 0x05
323 #define VID_YELLOW 0x06
324 #define VID_WHITE 0x07
327 * Bright text (hard-coded by DOS)
329 #define VID_BRIGHT 0x08
332 * Background color bits (hard-coded by DOS)
334 #define VUD_BLACK 0x00
335 #define VUD_BLUE 0x10
336 #define VUD_GREEN 0x20
337 #define VUD_CYAN 0x30
339 #define VUD_MAGENTA 0x50
340 #define VUD_YELLOW 0x60
341 #define VUD_WHITE 0x70
344 * Blinking text (hard-coded by DOS)
346 #define VUD_BRIGHT 0x80
352 typedef struct _term_data term_data;
357 * Note the use of "font_want" for the names of the font file requested by
358 * the user, and the use of "font_file" for the currently active font file.
360 * The "font_file" is uppercased, and takes the form "8X13.FON", while
361 * "font_want" can be in almost any form as long as it could be construed
362 * as attempting to represent the name of a font.
377 uint rows; /* int -> uint */
413 #if 1 /* #ifdef JP */
428 * Maximum number of windows XXX XXX XXX
430 #define MAX_TERM_DATA 8
433 * An array of term_data's
435 static term_data data[MAX_TERM_DATA];
438 * Hack -- global "window creation" pointer
440 static term_data *my_td;
443 * Remember normal size of main window when maxmized
448 * was main window maximized on previous playing
450 bool win_maximized = FALSE;
455 bool game_in_progress = FALSE;
458 * note when "open"/"new" become valid
460 bool initialized = FALSE;
463 * screen paletted, i.e. 256 colors
465 bool paletted = FALSE;
468 * 16 colors screen, don't use RGB()
470 bool colors16 = FALSE;
473 * Saved instance handle
475 static HINSTANCE hInstance;
478 * Yellow brush for the cursor
480 static HBRUSH hbrYellow;
490 static HPALETTE hPal;
493 static HBITMAP hBG = NULL;
494 static int use_bg = 0;
495 static char bg_bitmap_file[1024] = "bg.bmp";
500 * The screen saver window
502 static HWND hwndSaver;
504 #endif /* USE_SAVER */
510 * Flag set once "graphics" has been initialized
512 static bool can_use_graphics = FALSE;
517 static DIBINIT infGraph;
520 * The global bitmap mask
522 static DIBINIT infMask;
524 #endif /* USE_GRAPHICS */
530 * Flag set once "sound" has been initialized
532 static bool can_use_sound = FALSE;
536 * An array of sound file names
538 static cptr sound_file[SOUND_MAX][SAMPLE_MAX];
540 #endif /* USE_SOUND */
546 #define SAMPLE_MUSIC_MAX 16
547 static cptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
548 static cptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
549 static cptr town_music_file[1000][SAMPLE_MUSIC_MAX];
550 static cptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
551 static bool can_use_music = FALSE;
553 static MCI_OPEN_PARMS mop;
554 static char mci_device_type[256];
556 #endif /* USE_MUSIC */
560 * Full path to ANGBAND.INI
562 static cptr ini_file = NULL;
565 * Name of application
567 static cptr AppName = "ANGBAND";
570 * Name of sub-window type
572 static cptr AngList = "AngList";
577 static cptr ANGBAND_DIR_XTRA_GRAF;
578 static cptr ANGBAND_DIR_XTRA_SOUND;
579 static cptr ANGBAND_DIR_XTRA_MUSIC;
580 static cptr ANGBAND_DIR_XTRA_HELP;
581 #if 0 /* #ifndef JP */
582 static cptr ANGBAND_DIR_XTRA_FONT;
585 static cptr ANGBAND_DIR_XTRA_MUSIC;
590 * The "complex" color values
592 static COLORREF win_clr[256];
596 * Flag for macro trigger with dump ASCII
598 static bool Term_no_press = FALSE;
603 static bool mouse_down = FALSE;
604 static bool paint_rect = FALSE;
605 static int mousex = 0, mousey = 0;
606 static int oldx, oldy;
610 * The "simple" color values
612 * See "main-ibm.c" for original table information
614 * The entries below are taken from the "color bits" defined above.
616 * Note that many of the choices below suck, but so do crappy monitors.
618 static BYTE win_pal[256] =
620 VID_BLACK, /* Dark */
621 VID_WHITE, /* White */
622 VID_CYAN, /* Slate XXX */
623 VID_RED | VID_BRIGHT, /* Orange XXX */
625 VID_GREEN, /* Green */
627 VID_YELLOW, /* Umber XXX */
628 VID_BLACK | VID_BRIGHT, /* Light Dark */
629 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
630 VID_MAGENTA, /* Violet XXX */
631 VID_YELLOW | VID_BRIGHT, /* Yellow */
632 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
633 VID_GREEN | VID_BRIGHT, /* Light Green */
634 VID_BLUE | VID_BRIGHT, /* Light Blue */
635 VID_YELLOW /* Light Umber XXX */
640 * Hack -- define which keys are "special"
642 static bool special_key[256];
643 static bool ignore_key[256];
647 * Hack -- initialization list for "special_key"
649 static byte special_key_list[] = {
650 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
651 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
652 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
653 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
654 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
655 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
656 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
657 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
658 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
659 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
660 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
661 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
662 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
663 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
664 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
665 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
666 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
671 static byte ignore_key_list[] = {
672 VK_ESCAPE, VK_TAB, VK_SPACE,
673 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
674 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
675 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
681 * Hack -- initialization list for "special_key"
683 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
684 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
685 * catch the keypad keys (with and without numlock set, including keypad 5),
686 * the function keys (including the "menu" key which maps to F10), and the
687 * "pause" key (between scroll lock and numlock). We also catch a few odd
688 * keys which I do not recognize, but which are listed among keys which we
689 * do catch, so they should be harmless to catch.
691 static byte special_key_list[] =
693 VK_CLEAR, /* 0x0C (KP<5>) */
695 VK_PAUSE, /* 0x13 (pause) */
697 VK_PRIOR, /* 0x21 (KP<9>) */
698 VK_NEXT, /* 0x22 (KP<3>) */
699 VK_END, /* 0x23 (KP<1>) */
700 VK_HOME, /* 0x24 (KP<7>) */
701 VK_LEFT, /* 0x25 (KP<4>) */
702 VK_UP, /* 0x26 (KP<8>) */
703 VK_RIGHT, /* 0x27 (KP<6>) */
704 VK_DOWN, /* 0x28 (KP<2>) */
705 VK_SELECT, /* 0x29 (?????) */
706 VK_PRINT, /* 0x2A (?????) */
707 VK_EXECUTE, /* 0x2B (?????) */
708 VK_SNAPSHOT, /* 0x2C (?????) */
709 VK_INSERT, /* 0x2D (KP<0>) */
710 VK_DELETE, /* 0x2E (KP<.>) */
711 VK_HELP, /* 0x2F (?????) */
713 VK_NUMPAD0, /* 0x60 (KP<0>) */
714 VK_NUMPAD1, /* 0x61 (KP<1>) */
715 VK_NUMPAD2, /* 0x62 (KP<2>) */
716 VK_NUMPAD3, /* 0x63 (KP<3>) */
717 VK_NUMPAD4, /* 0x64 (KP<4>) */
718 VK_NUMPAD5, /* 0x65 (KP<5>) */
719 VK_NUMPAD6, /* 0x66 (KP<6>) */
720 VK_NUMPAD7, /* 0x67 (KP<7>) */
721 VK_NUMPAD8, /* 0x68 (KP<8>) */
722 VK_NUMPAD9, /* 0x69 (KP<9>) */
723 VK_MULTIPLY, /* 0x6A (KP<*>) */
724 VK_ADD, /* 0x6B (KP<+>) */
725 VK_SEPARATOR, /* 0x6C (?????) */
726 VK_SUBTRACT, /* 0x6D (KP<->) */
727 VK_DECIMAL, /* 0x6E (KP<.>) */
728 VK_DIVIDE, /* 0x6F (KP</>) */
759 static void delete_bg(void)
768 static int init_bg(void)
770 char * bmfile = bg_bitmap_file;
773 if (use_bg == 0) return 0;
775 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
778 plog_fmt("ÊÉ»æÍÑ¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
780 plog_fmt("Can't load the bitmap file '%s'.", bmfile);
786 HDC wnddc, dcimage, dcbg;
787 HBITMAP bmimage, bmimage_old, bmbg_old;
793 dcimage = CreateCompatibleDC(wnddc);
794 dcbg = CreateCompatibleDC(wnddc);
796 bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
797 if (!bmimage) quit("bg.bmp¤¬Æɤߤ³¤á¤Ê¤¤¡ª");
798 bmimage_old = SelectObject(dcimage, bmimage);
800 CreateCompatibleBitmap();
802 ReleaseDC(hwnd, wnddc);
808 static void DrawBG(HDC hdc, RECT *r)
813 int x = r->left, y = r->top;
814 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
820 GetObject(hBG, sizeof(bm), &bm);
821 swid = bm.bmWidth; shgt = bm.bmHeight;
823 hdcSrc = CreateCompatibleDC(hdc);
824 hOld = SelectObject(hdcSrc, hBG);
828 cwid = MIN(swid - sx, r->right - nx);
831 chgt = MIN(shgt - sy, r->bottom - ny);
832 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
834 } while (ny < r->bottom);
837 } while (nx < r->right);
839 SelectObject(hdcSrc, hOld);
845 * Hack -- given a pathname, point at the filename
847 static cptr extract_file_name(cptr s)
851 /* Start at the end */
852 p = s + strlen(s) - 1;
854 /* Back up to divider */
855 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
857 /* Return file name */
864 * Hack -- given a simple filename, extract the "font size" info
866 * Return a pointer to a static buffer holding the capitalized base name.
868 #if 0 /* #ifndef JP */
869 static char *analyze_font(char *path, int *wp, int *hp)
875 /* Start at the end */
876 p = path + strlen(path) - 1;
878 /* Back up to divider */
879 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
881 /* Advance to file name */
887 /* Capitalize (be paranoid) */
888 if (islower(*s)) *s = toupper(*s);
892 s = my_strchr(p, 'X');
894 /* Extract font width */
898 hgt = s ? atoi(s+1) : 0;
911 * Check for existance of a file
913 static bool check_file(cptr s)
933 attrib = GetFileAttributes(path);
935 /* Require valid filename */
936 if (attrib == INVALID_FILE_NAME) return (FALSE);
938 /* Prohibit directory */
939 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
943 /* Examine and verify */
944 if (_dos_getfileattr(path, &attrib)) return (FALSE);
946 /* Prohibit something */
947 if (attrib & FA_LABEL) return (FALSE);
949 /* Prohibit directory */
950 if (attrib & FA_DIREC) return (FALSE);
960 * Check for existance of a directory
962 static bool check_dir(cptr s)
984 /* Remove trailing backslash */
985 if (i && (path[i-1] == '\\')) path[--i] = '\0';
990 attrib = GetFileAttributes(path);
992 /* Require valid filename */
993 if (attrib == INVALID_FILE_NAME) return (FALSE);
995 /* Require directory */
996 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
1000 /* Examine and verify */
1001 if (_dos_getfileattr(path, &attrib)) return (FALSE);
1003 /* Prohibit something */
1004 if (attrib & FA_LABEL) return (FALSE);
1006 /* Require directory */
1007 if (!(attrib & FA_DIREC)) return (FALSE);
1019 static void validate_file(cptr s)
1021 /* Verify or fail */
1025 quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
1027 quit_fmt("Cannot find required file:\n%s", s);
1035 * Validate a directory
1037 static void validate_dir(cptr s, bool vital)
1039 /* Verify or fail */
1042 /* This directory contains needed data */
1046 quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
1048 quit_fmt("Cannot find required directory:\n%s", s);
1052 /* Attempt to create this directory */
1055 quit_fmt("Unable to create directory:\n%s", s);
1062 * Get the "size" for a window
1064 static void term_getsize(term_data *td)
1071 if (td->cols < 1) td->cols = 1;
1072 if (td->rows < 1) td->rows = 1;
1075 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1076 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1078 /* Fake window size */
1080 rc.right = rc.left + wid;
1082 rc.bottom = rc.top + hgt;
1085 /* rc.right += 1; */
1086 /* rc.bottom += 1; */
1089 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1092 td->size_wid = rc.right - rc.left;
1093 td->size_hgt = rc.bottom - rc.top;
1095 /* See CreateWindowEx */
1098 /* Extract actual location */
1099 GetWindowRect(td->w, &rc);
1101 /* Save the location */
1102 td->pos_x = rc.left;
1108 * Write the "prefs" for a single term
1110 static void save_prefs_aux(int i)
1112 term_data *td = &data[i];
1117 WINDOWPLACEMENT lpwndpl;
1122 /* Make section name */
1123 sprintf(sec_name, "Term-%d", i);
1128 strcpy(buf, td->visible ? "1" : "0");
1129 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1134 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1137 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1139 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1143 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1145 #if 1 /* #ifdef JP */
1146 wsprintf(buf, "%d", td->lf.lfWidth);
1147 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1148 wsprintf(buf, "%d", td->lf.lfHeight);
1149 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1150 wsprintf(buf, "%d", td->lf.lfWeight);
1151 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1154 strcpy(buf, td->bizarre ? "1" : "0");
1155 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1158 wsprintf(buf, "%d", td->tile_wid);
1159 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1162 wsprintf(buf, "%d", td->tile_hgt);
1163 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1165 /* Get window placement and dimensions */
1166 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1167 GetWindowPlacement(td->w, &lpwndpl);
1169 /* Acquire position in *normal* mode (not minimized) */
1170 rc = lpwndpl.rcNormalPosition;
1172 /* Window size (x) */
1173 if (i == 0) wsprintf(buf, "%d", normsize.x);
1174 else wsprintf(buf, "%d", td->cols);
1175 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1177 /* Window size (y) */
1178 if (i == 0) wsprintf(buf, "%d", normsize.y);
1179 else wsprintf(buf, "%d", td->rows);
1180 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1182 /* Maxmized (only main window) */
1185 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1186 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1189 /* Acquire position */
1190 GetWindowRect(td->w, &rc);
1192 /* Window position (x) */
1193 wsprintf(buf, "%d", rc.left);
1194 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1196 /* Window position (y) */
1197 wsprintf(buf, "%d", rc.top);
1198 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1200 /* Window Z position */
1203 strcpy(buf, td->posfix ? "1" : "0");
1204 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1212 * We assume that the windows have all been initialized
1214 static void save_prefs(void)
1220 /* Save the "arg_graphics" flag */
1221 sprintf(buf, "%d", arg_graphics);
1222 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1224 /* Save the "arg_bigtile" flag */
1225 strcpy(buf, arg_bigtile ? "1" : "0");
1226 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1228 /* Save the "arg_sound" flag */
1229 strcpy(buf, arg_sound ? "1" : "0");
1230 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1232 /* Save the "arg_sound" flag */
1233 strcpy(buf, arg_music ? "1" : "0");
1234 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1237 strcpy(buf, use_bg ? "1" : "0");
1238 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1239 WritePrivateProfileString("Angband", "BackGroundBitmap",
1240 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1242 /* Save window prefs */
1243 for (i = 0; i < MAX_TERM_DATA; ++i)
1251 * Load the "prefs" for a single term
1253 static void load_prefs_aux(int i)
1255 term_data *td = &data[i];
1259 int wid, hgt, posx, posy;
1260 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1261 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1265 /* Make section name */
1266 sprintf(sec_name, "Term-%d", i);
1268 /* Make section name */
1269 sprintf(sec_name, "Term-%d", i);
1274 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1277 /* Desired font, with default */
1279 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1282 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1284 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1290 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1292 /* Analyze font, save desired font name */
1293 #if 1 /* #ifdef JP */
1294 td->font_want = string_make(tmp);
1296 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1297 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1298 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1300 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1305 #if 1 /* #ifdef JP */
1306 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1307 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1309 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1310 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1315 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1316 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1317 normsize.x = td->cols; normsize.y = td->rows;
1322 win_maximized = GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file);
1325 /* Window position */
1326 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1327 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1328 td->pos_x = MIN(MAX(0, posx), dispx-128);
1329 td->pos_y = MIN(MAX(0, posy), dispy-128);
1331 /* Window Z position */
1334 td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1342 static void load_prefs(void)
1346 /* Extract the "arg_graphics" flag */
1347 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1349 /* Extract the "arg_bigtile" flag */
1350 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1351 use_bigtile = arg_bigtile;
1353 /* Extract the "arg_sound" flag */
1354 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1356 /* Extract the "arg_sound" flag */
1357 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1360 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1361 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1363 /* Load window prefs */
1364 for (i = 0; i < MAX_TERM_DATA; ++i)
1370 #if defined(USE_SOUND) || defined(USE_MUSIC)
1373 * XXX XXX XXX - Taken from files.c.
1375 * Extract "tokens" from a buffer
1377 * This function uses "whitespace" as delimiters, and treats any amount of
1378 * whitespace as a single delimiter. We will never return any empty tokens.
1379 * When given an empty buffer, or a buffer containing only "whitespace", we
1380 * will return no tokens. We will never extract more than "num" tokens.
1382 * By running a token through the "text_to_ascii()" function, you can allow
1383 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1385 * We save pointers to the tokens in "tokens", and return the number found.
1387 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1399 /* Skip leading whitespace */
1400 for ( ; *s && iswspace(*s); ++s) /* loop */;
1405 /* Find next whitespace, if any */
1406 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1408 /* Nuke and advance (if necessary) */
1409 if (*t) *t++ = '\0';
1411 /* Save the token */
1422 #endif /* USE_SOUND || USE_MUSIC */
1426 static void load_sound_prefs(void)
1430 char ini_path[1024];
1431 char wav_path[1024];
1432 char *zz[SAMPLE_MAX];
1434 /* Access the sound.cfg */
1436 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1438 for (i = 0; i < SOUND_MAX; i++)
1440 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1442 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1444 for (j = 0; j < num; j++)
1446 /* Access the sound */
1447 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1449 /* Save the sound filename, if it exists */
1450 if (check_file(wav_path))
1451 sound_file[i][j] = string_make(zz[j]);
1456 #endif /* USE_SOUND */
1460 static void load_music_prefs(void)
1464 char ini_path[1024];
1465 char wav_path[1024];
1466 char *zz[SAMPLE_MAX];
1469 /* Access the music.cfg */
1471 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1473 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1475 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1477 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1479 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1481 for (j = 0; j < num; j++)
1483 /* Access the sound */
1484 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1486 /* Save the sound filename, if it exists */
1487 if (check_file(wav_path))
1488 music_file[i][j] = string_make(zz[j]);
1492 for (i = 0; i < max_d_idx; i++)
1494 sprintf(key, "dungeon%03d", i);
1495 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1497 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1499 for (j = 0; j < num; j++)
1501 /* Access the sound */
1502 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1504 /* Save the sound filename, if it exists */
1505 if (check_file(wav_path))
1506 dungeon_music_file[i][j] = string_make(zz[j]);
1510 for (i = 0; i < 1000; i++) /*!< @todo ¥¯¥¨¥¹¥ÈºÇÂç¿ô»ØÄê */
1512 sprintf(key, "quest%03d", i);
1513 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1515 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1517 for (j = 0; j < num; j++)
1519 /* Access the sound */
1520 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1522 /* Save the sound filename, if it exists */
1523 if (check_file(wav_path))
1524 quest_music_file[i][j] = string_make(zz[j]);
1528 for (i = 0; i < 1000; i++) /*!< @todo Ä®ºÇÂç¿ô»ØÄê */
1530 sprintf(key, "town%03d", i);
1531 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1533 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1535 for (j = 0; j < num; j++)
1537 /* Access the sound */
1538 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1540 /* Save the sound filename, if it exists */
1541 if (check_file(wav_path))
1542 town_music_file[i][j] = string_make(zz[j]);
1549 #endif /* USE_MUSIC */
1552 * Create the new global palette based on the bitmap palette
1553 * (if any), and the standard 16 entry palette derived from
1554 * "win_clr[]" which is used for the basic 16 Angband colors.
1556 * This function is never called before all windows are ready.
1558 * This function returns FALSE if the new palette could not be
1559 * prepared, which should normally be a fatal error. XXX XXX
1561 * Note that only some machines actually use a "palette".
1563 static int new_palette(void)
1571 LPLOGPALETTE pLogPal;
1572 LPPALETTEENTRY lppe;
1577 /* This makes no sense */
1578 if (!paletted) return (TRUE);
1588 /* Check the bitmap palette */
1589 hBmPal = infGraph.hPalette;
1591 /* Use the bitmap */
1594 lppeSize = 256 * sizeof(PALETTEENTRY);
1595 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1596 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1597 if ((nEntries == 0) || (nEntries > 220))
1601 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1603 plog("Please switch to high- or true-color mode.");
1608 rnfree(lppe, lppeSize);
1615 #endif /* USE_GRAPHICS */
1617 /* Size of palette */
1618 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1620 /* Allocate palette */
1621 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1624 pLogPal->palVersion = 0x300;
1626 /* Make room for bitmap and normal data */
1627 pLogPal->palNumEntries = nEntries + 16;
1629 /* Save the bitmap data */
1630 for (i = 0; i < nEntries; i++)
1632 pLogPal->palPalEntry[i] = lppe[i];
1635 /* Save the normal data */
1636 for (i = 0; i < 16; i++)
1640 /* Access the entry */
1641 p = &(pLogPal->palPalEntry[i+nEntries]);
1643 /* Save the colors */
1644 p->peRed = GetRValue(win_clr[i]);
1645 p->peGreen = GetGValue(win_clr[i]);
1646 p->peBlue = GetBValue(win_clr[i]);
1648 /* Save the flags */
1649 p->peFlags = PC_NOCOLLAPSE;
1652 /* Free something */
1653 if (lppe) rnfree(lppe, lppeSize);
1655 /* Create a new palette, or fail */
1656 hNewPal = CreatePalette(pLogPal);
1658 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1660 if (!hNewPal) quit("Cannot create palette!");
1664 /* Free the palette */
1665 rnfree(pLogPal, pLogPalSize);
1670 /* Realize the palette */
1672 SelectPalette(hdc, hNewPal, 0);
1673 i = RealizePalette(hdc);
1674 ReleaseDC(td->w, hdc);
1676 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1678 if (i == 0) quit("Cannot realize palette!");
1683 for (i = 1; i < MAX_TERM_DATA; i++)
1688 SelectPalette(hdc, hNewPal, 0);
1689 ReleaseDC(td->w, hdc);
1692 /* Delete old palette */
1693 if (hPal) DeleteObject(hPal);
1695 /* Save new palette */
1705 * Initialize graphics
1707 static bool init_graphics(void)
1709 /* Initialize once */
1710 /* if (can_use_graphics != arg_graphics) */
1713 int wid, hgt, twid, thgt, ox, oy;
1716 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1726 ANGBAND_GRAF = "new";
1728 else if (arg_graphics == GRAPHICS_HENGBAND)
1748 ANGBAND_GRAF = "ne2";
1759 ANGBAND_GRAF = "old";
1762 /* Access the bitmap file */
1763 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1765 /* Load the bitmap or quit */
1766 if (!ReadDIB(data[0].w, buf, &infGraph))
1769 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1771 plog_fmt("Cannot read bitmap file '%s'", name);
1777 /* Save the new sizes */
1778 infGraph.CellWidth = wid;
1779 infGraph.CellHeight = hgt;
1780 infGraph.TileWidth = twid;
1781 infGraph.TileHeight = thgt;
1782 infGraph.OffsetX = ox;
1783 infGraph.OffsetY = oy;
1785 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1787 /* Access the mask file */
1788 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1790 /* Load the bitmap or quit */
1791 if (!ReadDIB(data[0].w, buf, &infMask))
1793 plog_fmt("Cannot read bitmap file '%s'", buf);
1797 if (arg_graphics == GRAPHICS_HENGBAND)
1799 /* Access the mask file */
1800 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1802 /* Load the bitmap or quit */
1803 if (!ReadDIB(data[0].w, buf, &infMask))
1805 plog_fmt("Cannot read bitmap file '%s'", buf);
1810 /* Activate a palette */
1813 /* Free bitmap XXX XXX XXX */
1817 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1819 plog("Cannot activate palette!");
1825 /* Graphics available */
1826 can_use_graphics = arg_graphics;
1830 return (can_use_graphics);
1832 #endif /* USE_GRAPHICS */
1839 static bool init_music(void)
1841 /* Initialize once */
1844 /* Load the prefs */
1847 /* Sound available */
1848 can_use_music = TRUE;
1852 return (can_use_music);
1856 * Hack -- Stop a music
1858 static void stop_music(void)
1860 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1861 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1864 #endif /* USE_MUSIC */
1870 static bool init_sound(void)
1872 /* Initialize once */
1875 /* Load the prefs */
1878 /* Sound available */
1879 can_use_sound = TRUE;
1883 return (can_use_sound);
1885 #endif /* USE_SOUND */
1891 static void term_window_resize(term_data *td)
1893 /* Require window */
1896 /* Resize the window */
1897 SetWindowPos(td->w, 0, 0, 0,
1898 td->size_wid, td->size_hgt,
1899 SWP_NOMOVE | SWP_NOZORDER);
1902 InvalidateRect(td->w, NULL, TRUE);
1907 * Force the use of a new "font file" for a term_data
1909 * This function may be called before the "window" is ready
1911 * This function returns zero only if everything succeeds.
1913 * Note that the "font name" must be capitalized!!!
1915 static errr term_force_font(term_data *td, cptr path)
1919 #if 0 /* #ifndef JP */
1925 /* Forget the old font (if needed) */
1926 if (td->font_id) DeleteObject(td->font_id);
1928 #if 1 /* #ifdef JP */
1932 /* Create the font (using the 'base' of the font file name!) */
1933 td->font_id = CreateFontIndirect(&(td->lf));
1934 wid = td->lf.lfWidth;
1935 hgt = td->lf.lfHeight;
1936 if (!td->font_id) return (1);
1938 /* Forget old font */
1944 for (i = 0; i < MAX_TERM_DATA; i++)
1946 /* Don't check when closing the application */
1949 /* Check "screen" */
1950 if ((td != &data[i]) &&
1951 (data[i].font_file) &&
1952 (streq(data[i].font_file, td->font_file)))
1958 /* Remove unused font resources */
1959 if (!used) RemoveFontResource(td->font_file);
1961 /* Free the old name */
1962 string_free(td->font_file);
1965 td->font_file = NULL;
1969 if (!path) return (1);
1974 /* Analyze font path */
1975 base = analyze_font(buf, &wid, &hgt);
1978 if (!suffix(base, ".FON")) return (1);
1981 if (!check_file(buf)) return (1);
1983 /* Load the new font */
1984 if (!AddFontResource(buf)) return (1);
1986 /* Save new font name */
1987 td->font_file = string_make(base);
1989 /* Remove the "suffix" */
1990 base[strlen(base)-4] = '\0';
1992 /* Create the font (using the 'base' of the font file name!) */
1993 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1994 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1995 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1996 FIXED_PITCH | FF_DONTCARE, base);
1999 /* Hack -- Unknown size */
2006 /* all this trouble to get the cell size */
2007 hdcDesktop = GetDC(HWND_DESKTOP);
2008 hfOld = SelectObject(hdcDesktop, td->font_id);
2009 GetTextMetrics(hdcDesktop, &tm);
2010 SelectObject(hdcDesktop, hfOld);
2011 ReleaseDC(HWND_DESKTOP, hdcDesktop);
2013 /* Font size info */
2014 wid = tm.tmAveCharWidth;
2018 /* Save the size info */
2029 * Allow the user to change the font for this window.
2031 static void term_change_font(term_data *td)
2033 #if 1 /* #ifdef JP */
2036 memset(&cf, 0, sizeof(cf));
2037 cf.lStructSize = sizeof(cf);
2038 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
2039 cf.lpLogFont = &(td->lf);
2041 if (ChooseFont(&cf))
2043 /* Force the font */
2044 term_force_font(td, NULL);
2046 /* Assume not bizarre */
2049 /* Reset the tile info */
2050 td->tile_wid = td->font_wid;
2051 td->tile_hgt = td->font_hgt;
2053 /* Analyze the font */
2056 /* Resize the window */
2057 term_window_resize(td);
2063 char tmp[1024] = "";
2065 /* Extract a default if possible */
2066 if (td->font_file) strcpy(tmp, td->font_file);
2068 /* Ask for a choice */
2069 memset(&ofn, 0, sizeof(ofn));
2070 ofn.lStructSize = sizeof(ofn);
2071 ofn.hwndOwner = data[0].w;
2072 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
2073 ofn.nFilterIndex = 1;
2074 ofn.lpstrFile = tmp;
2076 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
2077 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2078 ofn.lpstrDefExt = "fon";
2080 /* Force choice if legal */
2081 if (GetOpenFileName(&ofn))
2083 /* Force the font */
2084 if (term_force_font(td, tmp))
2086 /* Access the standard font file */
2087 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2089 /* Force the use of that font */
2090 (void)term_force_font(td, tmp);
2093 /* Assume not bizarre */
2094 td->bizarre = FALSE;
2096 /* Reset the tile info */
2097 td->tile_wid = td->font_wid;
2098 td->tile_hgt = td->font_hgt;
2100 /* Analyze the font */
2103 /* Resize the window */
2104 term_window_resize(td);
2111 * Allow the user to lock this window.
2113 static void term_window_pos(term_data *td, HWND hWnd)
2115 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2116 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2119 static void windows_map(void);
2122 * Hack -- redraw a term_data
2124 static void term_data_redraw(term_data *td)
2128 /* Redraw the map */
2133 /* Activate the term */
2134 Term_activate(&td->t);
2136 /* Redraw the contents */
2139 /* Restore the term */
2140 Term_activate(term_screen);
2145 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2149 HBRUSH myBrush, oldBrush;
2151 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2152 int tx = td->size_ow1 + x * td->tile_wid;
2153 int ty = td->size_oh1 + y * td->tile_hgt;
2154 int tw = w * td->tile_wid - 1;
2155 int th = h * td->tile_hgt - 1;
2158 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2159 oldBrush = SelectObject(hdc, myBrush);
2160 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2162 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2164 SelectObject(hdc, oldBrush);
2165 SelectObject(hdc, oldPen);
2170 /*** Function hooks needed by "Term" ***/
2176 * Initialize a new Term
2178 static void Term_init_win(term *t)
2187 static void Term_nuke_win(term *t)
2196 * Interact with the User
2198 static errr Term_user_win(int n)
2209 * React to global changes
2211 static errr Term_xtra_win_react(void)
2219 /* Save the default colors */
2220 for (i = 0; i < 256; i++)
2222 /* Simply accept the desired colors */
2223 win_pal[i] = angband_color_table[i][0];
2234 bool change = FALSE;
2236 /* Save the default colors */
2237 for (i = 0; i < 256; i++)
2239 /* Extract desired values */
2240 rv = angband_color_table[i][1];
2241 gv = angband_color_table[i][2];
2242 bv = angband_color_table[i][3];
2244 /* Extract a full color code */
2245 code = PALETTERGB(rv, gv, bv);
2247 /* Activate changes */
2248 if (win_clr[i] != code)
2250 /* Note the change */
2253 /* Apply the desired color */
2258 /* Activate the palette if needed */
2259 if (change) (void)new_palette();
2265 /* Handle "arg_sound" */
2266 if (use_sound != arg_sound)
2268 /* Initialize (if needed) */
2269 if (arg_sound && !init_sound())
2273 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
2275 plog("Cannot initialize sound!");
2283 /* Change setting */
2284 use_sound = arg_sound;
2291 /* Handle "arg_sound" */
2292 if (use_music != arg_music)
2294 /* Initialize (if needed) */
2295 if (arg_music && !init_music())
2299 plog("BGM¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
2301 plog("Cannot initialize BGM!");
2307 /* Change setting */
2308 use_music = arg_music;
2310 if(!arg_music) stop_music();
2311 else select_floor_music();
2320 /* Handle "arg_graphics" */
2321 if (use_graphics != arg_graphics)
2323 /* Initialize (if needed) */
2324 if (arg_graphics && !init_graphics())
2328 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
2330 plog("Cannot initialize graphics!");
2335 arg_graphics = GRAPHICS_NONE;
2338 /* Change setting */
2339 use_graphics = arg_graphics;
2342 #ifdef ANGBAND_2_8_1
2344 #else /* ANGBAND_2_8_1 */
2345 reset_visuals(TRUE);
2346 #endif /* ANGBAND_2_8_1 */
2349 #endif /* USE_GRAPHICS */
2352 /* Clean up windows */
2353 for (i = 0; i < MAX_TERM_DATA; i++)
2357 term_data *td = &data[i];
2359 /* Update resized windows */
2360 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2363 Term_activate(&td->t);
2365 /* Hack -- Resize the term */
2366 Term_resize(td->cols, td->rows);
2368 /* Redraw the contents */
2383 * Process at least one event
2385 static errr Term_xtra_win_event(int v)
2389 /* Wait for an event */
2393 if (GetMessage(&msg, NULL, 0, 0))
2395 TranslateMessage(&msg);
2396 DispatchMessage(&msg);
2400 /* Check for an event */
2404 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2406 TranslateMessage(&msg);
2407 DispatchMessage(&msg);
2417 * Process all pending events
2419 static errr Term_xtra_win_flush(void)
2423 /* Process all pending events */
2424 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2426 TranslateMessage(&msg);
2427 DispatchMessage(&msg);
2436 * Hack -- clear the screen
2438 * Make this more efficient XXX XXX XXX
2440 static errr Term_xtra_win_clear(void)
2442 term_data *td = (term_data*)(Term->data);
2447 /* Rectangle to erase */
2448 rc.left = td->size_ow1;
2449 rc.right = rc.left + td->cols * td->tile_wid;
2450 rc.top = td->size_oh1;
2451 rc.bottom = rc.top + td->rows * td->tile_hgt;
2455 SetBkColor(hdc, RGB(0, 0, 0));
2456 SelectObject(hdc, td->font_id);
2457 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2462 rc.left = 0; rc.top = 0;
2465 ReleaseDC(td->w, hdc);
2473 * Hack -- make a noise
2475 static errr Term_xtra_win_noise(void)
2477 MessageBeep(MB_ICONASTERISK);
2483 * Hack -- make a sound
2485 static errr Term_xtra_win_sound(int v)
2490 #endif /* USE_SOUND */
2492 /* Sound disabled */
2493 if (!use_sound) return (1);
2496 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2500 /* Count the samples */
2501 for (i = 0; i < SAMPLE_MAX; i++)
2503 if (!sound_file[v][i])
2508 if (i == 0) return (1);
2510 /* Build the path */
2511 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2515 /* Play the sound, catch errors */
2516 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2520 /* Play the sound, catch errors */
2521 return (sndPlaySound(buf, SND_ASYNC));
2525 #else /* USE_SOUND */
2530 #endif /* USE_SOUND */
2534 * Hack -- play a music
2536 static errr Term_xtra_win_music(int n, int v)
2541 #endif /* USE_MUSIC */
2543 /* Sound disabled */
2544 if(!use_music) return (1);
2547 if(n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return (1);
2548 else if(v < 0 || v >= 1000) return(1); /*!< TODO */
2554 case TERM_XTRA_MUSIC_BASIC:
2555 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2557 case TERM_XTRA_MUSIC_DUNGEON:
2558 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2560 case TERM_XTRA_MUSIC_QUEST:
2561 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2563 case TERM_XTRA_MUSIC_TOWN:
2564 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2571 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2572 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2578 case TERM_XTRA_MUSIC_BASIC:
2579 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2581 case TERM_XTRA_MUSIC_DUNGEON:
2582 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2584 case TERM_XTRA_MUSIC_QUEST:
2585 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2587 case TERM_XTRA_MUSIC_TOWN:
2588 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2595 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2596 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2602 case TERM_XTRA_MUSIC_BASIC:
2603 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2605 case TERM_XTRA_MUSIC_DUNGEON:
2606 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2608 case TERM_XTRA_MUSIC_QUEST:
2609 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2611 case TERM_XTRA_MUSIC_TOWN:
2612 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2617 #endif /* USE_MUSIC */
2621 mop.lpstrDeviceType = mci_device_type;
2622 mop.lpstrElementName = buf;
2623 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2624 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2625 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2626 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2627 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2630 #else /* USE_MUSIC */
2635 #endif /* USE_MUSIC */
2640 * Delay for "x" milliseconds
2642 static int Term_xtra_win_delay(int v)
2656 t = GetTickCount() + v;
2659 while (GetTickCount() < t)
2661 /* Handle messages */
2662 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2664 TranslateMessage(&msg);
2665 DispatchMessage(&msg);
2677 * Do a "special thing"
2679 static errr Term_xtra_win(int n, int v)
2681 /* Handle a subset of the legal requests */
2684 /* Make a bell sound */
2685 case TERM_XTRA_NOISE:
2687 return (Term_xtra_win_noise());
2691 case TERM_XTRA_MUSIC_BASIC:
2692 case TERM_XTRA_MUSIC_DUNGEON:
2693 case TERM_XTRA_MUSIC_QUEST:
2694 case TERM_XTRA_MUSIC_TOWN:
2696 return (Term_xtra_win_music(n, v));
2699 /* Make a special sound */
2700 case TERM_XTRA_SOUND:
2702 return (Term_xtra_win_sound(v));
2705 /* Process random events */
2706 case TERM_XTRA_BORED:
2708 return (Term_xtra_win_event(0));
2711 /* Process an event */
2712 case TERM_XTRA_EVENT:
2714 return (Term_xtra_win_event(v));
2717 /* Flush all events */
2718 case TERM_XTRA_FLUSH:
2720 return (Term_xtra_win_flush());
2723 /* Clear the screen */
2724 case TERM_XTRA_CLEAR:
2726 return (Term_xtra_win_clear());
2729 /* React to global changes */
2730 case TERM_XTRA_REACT:
2732 return (Term_xtra_win_react());
2735 /* Delay for some milliseconds */
2736 case TERM_XTRA_DELAY:
2738 return (Term_xtra_win_delay(v));
2749 * Low level graphics (Assumes valid input).
2751 * Draw a "cursor" at (x,y), using a "yellow box".
2753 static errr Term_curs_win(int x, int y)
2755 term_data *td = (term_data*)(Term->data);
2760 int tile_wid, tile_hgt;
2764 tile_wid = td->map_tile_wid;
2765 tile_hgt = td->map_tile_hgt;
2769 tile_wid = td->tile_wid;
2770 tile_hgt = td->tile_hgt;
2773 /* Frame the grid */
2774 rc.left = x * tile_wid + td->size_ow1;
2775 rc.right = rc.left + tile_wid;
2776 rc.top = y * tile_hgt + td->size_oh1;
2777 rc.bottom = rc.top + tile_hgt;
2779 /* Cursor is done as a yellow "box" */
2781 FrameRect(hdc, &rc, hbrYellow);
2782 ReleaseDC(td->w, hdc);
2790 * Low level graphics (Assumes valid input).
2792 * Draw a "big cursor" at (x,y), using a "yellow box".
2794 static errr Term_bigcurs_win(int x, int y)
2796 term_data *td = (term_data*)(Term->data);
2801 int tile_wid, tile_hgt;
2805 /* Normal cursor in map window */
2806 Term_curs_win(x, y);
2811 tile_wid = td->tile_wid;
2812 tile_hgt = td->tile_hgt;
2815 /* Frame the grid */
2816 rc.left = x * tile_wid + td->size_ow1;
2817 rc.right = rc.left + 2 * tile_wid;
2818 rc.top = y * tile_hgt + td->size_oh1;
2819 rc.bottom = rc.top + tile_hgt;
2821 /* Cursor is done as a yellow "box" */
2823 FrameRect(hdc, &rc, hbrYellow);
2824 ReleaseDC(td->w, hdc);
2832 * Low level graphics (Assumes valid input).
2834 * Erase a "block" of "n" characters starting at (x,y).
2836 static errr Term_wipe_win(int x, int y, int n)
2838 term_data *td = (term_data*)(Term->data);
2843 /* Rectangle to erase in client coords */
2844 rc.left = x * td->tile_wid + td->size_ow1;
2845 rc.right = rc.left + n * td->tile_wid;
2846 rc.top = y * td->tile_hgt + td->size_oh1;
2847 rc.bottom = rc.top + td->tile_hgt;
2850 SetBkColor(hdc, RGB(0, 0, 0));
2851 SelectObject(hdc, td->font_id);
2856 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2857 ReleaseDC(td->w, hdc);
2865 * Low level graphics. Assumes valid input.
2867 * Draw several ("n") chars, with an attr, at a given location.
2869 * All "graphic" data is handled by "Term_pict_win()", below.
2871 * One would think there is a more efficient method for telling a window
2872 * what color it should be using to draw with, but perhaps simply changing
2873 * it every time is not too inefficient. XXX XXX XXX
2875 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2877 term_data *td = (term_data*)(Term->data);
2881 #if 1 /* #ifdef JP */
2882 static HBITMAP WALL;
2883 static HBRUSH myBrush, oldBrush;
2885 static bool init_done = FALSE;
2888 WALL = LoadBitmap(hInstance, AppName);
2889 myBrush = CreatePatternBrush(WALL);
2894 /* Total rectangle */
2895 rc.left = x * td->tile_wid + td->size_ow1;
2896 rc.right = rc.left + n * td->tile_wid;
2897 rc.top = y * td->tile_hgt + td->size_oh1;
2898 rc.bottom = rc.top + td->tile_hgt;
2903 /* Background color */
2904 SetBkColor(hdc, RGB(0, 0, 0));
2906 /* Foreground color */
2909 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2913 SetTextColor(hdc, win_clr[a&0x0F]);
2917 SetTextColor(hdc, win_clr[a]);
2921 SelectObject(hdc, td->font_id);
2924 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2928 (td->tile_hgt != td->font_hgt) ||
2929 (td->tile_wid != td->font_wid))
2933 /* Erase complete rectangle */
2934 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2937 if (use_bg) DrawBG(hdc, &rc);
2940 rc.left += ((td->tile_wid - td->font_wid) / 2);
2941 rc.right = rc.left + td->font_wid;
2942 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2943 rc.bottom = rc.top + td->font_hgt;
2945 /* Dump each character */
2946 for (i = 0; i < n; i++)
2949 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2951 rc.right += td->font_wid;
2953 oldBrush = SelectObject(hdc, myBrush);
2954 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2957 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2959 SelectObject(hdc, oldBrush);
2960 SelectObject(hdc, oldPen);
2961 rc.right -= td->font_wid;
2965 rc.left += 2 * td->tile_wid;
2966 rc.right += 2 * td->tile_wid;
2968 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2970 rc.right += td->font_wid;
2972 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2974 rc.right -= td->font_wid;
2978 rc.left += 2 * td->tile_wid;
2979 rc.right += 2 * td->tile_wid;
2980 } else if (*(s+i)==127){
2981 oldBrush = SelectObject(hdc, myBrush);
2982 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2985 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2987 SelectObject(hdc, oldBrush);
2988 SelectObject(hdc, oldPen);
2991 rc.left += td->tile_wid;
2992 rc.right += td->tile_wid;
2995 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2998 rc.left += td->tile_wid;
2999 rc.right += td->tile_wid;
3004 oldBrush = SelectObject(hdc, myBrush);
3005 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
3008 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
3010 SelectObject(hdc, oldBrush);
3011 SelectObject(hdc, oldPen);
3014 rc.left += td->tile_wid;
3015 rc.right += td->tile_wid;
3018 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
3022 rc.left += td->tile_wid;
3023 rc.right += td->tile_wid;
3027 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
3031 rc.left += td->tile_wid;
3032 rc.right += td->tile_wid;
3043 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
3048 ReleaseDC(td->w, hdc);
3056 * Low level graphics. Assumes valid input.
3058 * Draw an array of "special" attr/char pairs at the given location.
3060 * We use the "Term_pict_win()" function for "graphic" data, which are
3061 * encoded by setting the "high-bits" of both the "attr" and the "char"
3062 * data. We use the "attr" to represent the "row" of the main bitmap,
3063 * and the "char" to represent the "col" of the main bitmap. The use
3064 * of this function is induced by the "higher_pict" flag.
3066 * If "graphics" is not available, we simply "wipe" the given grids.
3068 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
3070 term_data *td = (term_data*)(Term->data);
3075 int x1, y1, w1, h1, tw1, th1;
3076 int x2, y2, w2, h2, tw2;
3088 /* Erase the grids */
3089 return (Term_wipe_win(x, y, n));
3092 /* Size of bitmap cell */
3093 w1 = infGraph.CellWidth;
3094 h1 = infGraph.CellHeight;
3095 tw1 = infGraph.TileWidth;
3096 th1 = infGraph.TileHeight;
3098 /* Size of window cell */
3101 w2 = td->map_tile_wid;
3102 h2 = td->map_tile_hgt;
3111 if (use_bigtile) tw2 *= 2;
3114 /* Location of window cell */
3115 x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
3116 y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
3122 hdcSrc = CreateCompatibleDC(hdc);
3123 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
3125 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3127 hdcMask = CreateCompatibleDC(hdc);
3128 SelectObject(hdcMask, infMask.hBitmap);
3131 /* Draw attr/char pairs */
3132 for (i = 0; i < n; i++, x2 += w2)
3138 /* Extract picture */
3139 int row = (a & 0x7F);
3140 int col = (c & 0x7F);
3142 /* Location of bitmap cell */
3146 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3148 x3 = (tcp[i] & 0x7F) * w1;
3149 y3 = (tap[i] & 0x7F) * h1;
3150 tw2 = tw2 * w1 / tw1;
3154 if ((tw1 == tw2) && (th1 == h2))
3156 /* Copy the terrain picture from the bitmap to the window */
3157 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
3159 /* Mask out the tile */
3160 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3163 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3166 /* Need to stretch */
3169 /* Set the correct mode for stretching the tiles */
3170 SetStretchBltMode(hdc, COLORONCOLOR);
3172 /* Copy the terrain picture from the bitmap to the window */
3173 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
3175 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
3177 /* Only draw if terrain and overlay are different */
3178 if ((x1 != x3) || (y1 != y3))
3180 /* Mask out the tile */
3181 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3184 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3191 if ((w1 == tw2) && (h1 == h2))
3193 /* Copy the picture from the bitmap to the window */
3194 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3197 /* Need to stretch */
3200 /* Set the correct mode for stretching the tiles */
3201 SetStretchBltMode(hdc, COLORONCOLOR);
3203 /* Copy the picture from the bitmap to the window */
3204 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3210 SelectObject(hdcSrc, hbmSrcOld);
3213 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3216 SelectObject(hdcMask, hbmSrcOld);
3221 ReleaseDC(td->w, hdc);
3223 #else /* USE_GRAPHICS */
3225 /* Just erase this grid */
3226 return (Term_wipe_win(x, y, n));
3228 #endif /* USE_GRAPHICS */
3235 static void windows_map(void)
3237 term_data *td = &data[0];
3239 int x, min_x, max_x;
3240 int y, min_y, max_y;
3244 /* Only in graphics mode */
3245 if (!use_graphics) return;
3248 Term_xtra_win_clear();
3250 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3251 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3252 td->map_active = TRUE;
3262 for (x = min_x; x < max_x; x++)
3264 for (y = min_y; y < max_y; y++)
3266 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3268 /* Ignore non-graphics */
3269 if ((a & 0x80) && (c & 0x80))
3271 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3276 /* Hilite the player */
3277 Term_curs_win(px - min_x, py - min_y);
3279 /* Wait for a keypress, flush key buffer */
3280 Term_inkey(&c, TRUE, TRUE);
3283 /* Switch off the map display */
3284 td->map_active = FALSE;
3286 /* Restore screen */
3287 Term_xtra_win_clear();
3292 /*** Other routines ***/
3296 * Create and initialize a "term_data" given a title
3298 static void term_data_link(term_data *td)
3302 /* Initialize the term */
3303 term_init(t, td->cols, td->rows, td->keys);
3305 /* Use a "software" cursor */
3306 t->soft_cursor = TRUE;
3308 /* Use "Term_pict" for "graphic" data */
3309 t->higher_pict = TRUE;
3311 /* Erase with "white space" */
3312 t->attr_blank = TERM_WHITE;
3313 t->char_blank = ' ';
3316 /* Prepare the init/nuke hooks */
3317 t->init_hook = Term_init_win;
3318 t->nuke_hook = Term_nuke_win;
3321 /* Prepare the template hooks */
3322 t->user_hook = Term_user_win;
3323 t->xtra_hook = Term_xtra_win;
3324 t->curs_hook = Term_curs_win;
3325 t->bigcurs_hook = Term_bigcurs_win;
3326 t->wipe_hook = Term_wipe_win;
3327 t->text_hook = Term_text_win;
3328 t->pict_hook = Term_pict_win;
3330 /* Remember where we came from */
3331 t->data = (vptr)(td);
3336 * Create the windows
3338 * First, instantiate the "default" values, then read the "ini_file"
3339 * to over-ride selected values, then create the windows, and fonts.
3341 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3342 * must make active to realize the palette. XXX XXX XXX
3344 static void init_windows(void)
3350 #if 0 /* #ifndef JP */
3356 WIPE(td, term_data);
3360 td->s = angband_term_name[0];
3374 #if 1 /* #ifdef JP */
3378 for (i = 1; i < MAX_TERM_DATA; i++)
3381 WIPE(td, term_data);
3382 td->s = angband_term_name[i];
3386 td->visible = FALSE;
3391 td->pos_x = (7 - i) * 30;
3392 td->pos_y = (7 - i) * 20;
3394 #if 1 /* #ifdef JP */
3404 /* Main window (need these before term_getsize gets called) */
3406 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3407 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3412 /* Sub windows (need these before term_getsize gets called) */
3413 for (i = 1; i < MAX_TERM_DATA; i++)
3416 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3417 td->dwExStyle = (WS_EX_TOOLWINDOW);
3422 for (i = 0; i < MAX_TERM_DATA; i++)
3426 #if 1 /* #ifdef JP */
3427 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3428 td->lf.lfCharSet = DEFAULT_CHARSET;
3429 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3430 /* Activate the chosen font */
3431 term_force_font(td, NULL);
3432 td->tile_wid = td->font_wid;
3433 td->tile_hgt = td->font_hgt;
3435 /* Access the standard font file */
3436 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3438 /* Activate the chosen font */
3439 if (term_force_font(td, buf))
3441 /* Access the standard font file */
3442 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3444 /* Force the use of that font */
3445 (void)term_force_font(td, buf);
3451 /* Assume not bizarre */
3452 td->bizarre = FALSE;
3457 /* Analyze the font */
3460 /* Resize the window */
3461 term_window_resize(td);
3465 /* Sub windows (reverse order) */
3466 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3471 td->w = CreateWindowEx(td->dwExStyle, AngList,
3473 td->pos_x, td->pos_y,
3474 td->size_wid, td->size_hgt,
3475 HWND_DESKTOP, NULL, hInstance, NULL);
3478 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3480 if (!td->w) quit("Failed to create sub-window");
3486 td->size_hack = TRUE;
3487 ShowWindow(td->w, SW_SHOW);
3488 td->size_hack = FALSE;
3492 angband_term[i] = &td->t;
3496 /* Activate the window */
3497 SetActiveWindow(td->w);
3502 term_window_pos(&data[i], HWND_TOPMOST);
3506 term_window_pos(&data[i], td->w);
3516 td->w = CreateWindowEx(td->dwExStyle, AppName,
3518 td->pos_x, td->pos_y,
3519 td->size_wid, td->size_hgt,
3520 HWND_DESKTOP, NULL, hInstance, NULL);
3523 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3525 if (!td->w) quit("Failed to create Angband window");
3530 angband_term[0] = &td->t;
3531 normsize.x = td->cols;
3532 normsize.y = td->rows;
3534 /* Activate the main window */
3535 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3536 else ShowWindow(td->w, SW_SHOW);
3538 /* Bring main window back to top */
3539 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3542 /* New palette XXX XXX XXX */
3543 (void)new_palette();
3546 /* Create a "brush" for drawing the "cursor" */
3547 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3550 /* Process pending messages */
3551 (void)Term_xtra_win_flush();
3559 static void setup_menus(void)
3563 HMENU hm = GetMenu(data[0].w);
3566 /* Menu "File", Disable all */
3567 EnableMenuItem(hm, IDM_FILE_NEW,
3568 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3569 EnableMenuItem(hm, IDM_FILE_OPEN,
3570 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3571 EnableMenuItem(hm, IDM_FILE_SAVE,
3572 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3573 EnableMenuItem(hm, IDM_FILE_EXIT,
3574 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3575 EnableMenuItem(hm, IDM_FILE_SCORE,
3576 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3579 /* No character available */
3580 if (!character_generated)
3582 /* Menu "File", Item "New" */
3583 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3585 /* Menu "File", Item "Open" */
3586 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3589 /* A character available */
3590 if (character_generated)
3592 /* Menu "File", Item "Save" */
3593 EnableMenuItem(hm, IDM_FILE_SAVE,
3594 MF_BYCOMMAND | MF_ENABLED);
3597 /* Menu "File", Item "Exit" */
3598 EnableMenuItem(hm, IDM_FILE_EXIT,
3599 MF_BYCOMMAND | MF_ENABLED);
3601 EnableMenuItem(hm, IDM_FILE_SCORE,
3602 MF_BYCOMMAND | MF_ENABLED);
3605 /* Menu "Window::Visibility" */
3606 for (i = 0; i < MAX_TERM_DATA; i++)
3608 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3609 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3611 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3612 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3614 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3615 MF_BYCOMMAND | MF_ENABLED);
3618 /* Menu "Window::Font" */
3619 for (i = 0; i < MAX_TERM_DATA; i++)
3621 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3622 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3624 if (data[i].visible)
3626 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3627 MF_BYCOMMAND | MF_ENABLED);
3631 /* Menu "Window::Window Position Fix" */
3632 for (i = 0; i < MAX_TERM_DATA; i++)
3634 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3635 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3637 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3638 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3640 if (data[i].visible)
3642 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3643 MF_BYCOMMAND | MF_ENABLED);
3647 /* Menu "Window::Bizarre Display" */
3648 for (i = 0; i < MAX_TERM_DATA; i++)
3650 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3651 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3653 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3654 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3656 if (data[i].visible)
3658 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3659 MF_BYCOMMAND | MF_ENABLED);
3664 /* Menu "Window::Increase Tile Width" */
3665 for (i = 0; i < MAX_TERM_DATA; i++)
3667 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3668 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3670 if (data[i].visible)
3672 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3673 MF_BYCOMMAND | MF_ENABLED);
3678 /* Menu "Window::Decrease Tile Width" */
3679 for (i = 0; i < MAX_TERM_DATA; i++)
3681 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3682 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3684 if (data[i].visible)
3686 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3687 MF_BYCOMMAND | MF_ENABLED);
3692 /* Menu "Window::Increase Tile Height" */
3693 for (i = 0; i < MAX_TERM_DATA; i++)
3695 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3696 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3698 if (data[i].visible)
3700 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3701 MF_BYCOMMAND | MF_ENABLED);
3706 /* Menu "Window::Decrease Tile Height" */
3707 for (i = 0; i < MAX_TERM_DATA; i++)
3709 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3710 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3712 if (data[i].visible)
3714 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3715 MF_BYCOMMAND | MF_ENABLED);
3720 /* Menu "Options", disable all */
3721 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3722 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3723 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3724 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3725 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3726 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3727 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3728 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3729 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3730 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3732 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3733 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3736 /* Menu "Options", Item "Map" */
3737 if (use_graphics != GRAPHICS_NONE)
3738 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3740 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3741 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3743 /* Menu "Options", update all */
3744 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3745 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3746 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3747 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3748 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3749 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3750 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3751 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3752 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3753 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3754 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3755 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3756 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3757 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3758 CheckMenuItem(hm, IDM_OPTIONS_BG,
3759 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3761 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3762 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3766 /* Menu "Options", Item "Graphics" */
3767 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3768 /* Menu "Options", Item "Graphics" */
3769 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3770 /* Menu "Options", Item "Graphics" */
3771 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3772 /* Menu "Options", Item "Graphics" */
3773 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3774 #endif /* USE_GRAPHICS */
3777 /* Menu "Options", Item "Sound" */
3778 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3779 #endif /* USE_SOUND */
3782 /* Menu "Options", Item "ScreenSaver" */
3783 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3784 MF_BYCOMMAND | MF_ENABLED);
3785 #endif /* USE_SAVER */
3790 * Check for double clicked (or dragged) savefile
3792 * Apparently, Windows copies the entire filename into the first
3793 * piece of the "command line string". Perhaps we should extract
3794 * the "basename" of that filename and append it to the "save" dir.
3796 static void check_for_save_file(LPSTR cmd_line)
3806 /* Extract filename */
3807 strcat(savefile, s);
3809 /* Validate the file */
3810 validate_file(savefile);
3812 /* Game in progress */
3813 game_in_progress = TRUE;
3821 * Process a menu command
3823 static void process_menus(WORD wCmd)
3840 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3842 plog("You cannot do that yet...");
3846 else if (game_in_progress)
3849 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3851 plog("You can't start a new game while you're still playing!");
3857 game_in_progress = TRUE;
3871 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3873 plog("You cannot do that yet...");
3877 else if (game_in_progress)
3880 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3882 plog("You can't open a new game while you're still playing!");
3888 memset(&ofn, 0, sizeof(ofn));
3889 ofn.lStructSize = sizeof(ofn);
3890 ofn.hwndOwner = data[0].w;
3891 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3892 ofn.nFilterIndex = 1;
3893 ofn.lpstrFile = savefile;
3894 ofn.nMaxFile = 1024;
3895 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3896 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3898 if (GetOpenFileName(&ofn))
3900 /* Load 'savefile' */
3901 validate_file(savefile);
3902 game_in_progress = TRUE;
3914 if (game_in_progress && character_generated)
3920 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3922 plog("You may not do that right now.");
3928 /* Hack -- Forget messages */
3933 do_cmd_save_game(FALSE);
3934 #else /* ZANGBAND */
3936 #endif /* ZANGBAND */
3941 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3943 plog("You may not do that right now.");
3953 if (game_in_progress && character_generated)
3959 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3961 plog("You may not do that right now.");
3967 /* Hack -- Forget messages */
3976 /* do_cmd_save_game(FALSE); */
3977 #else /* ZANGBAND */
3978 /* do_cmd_save_game(); */
3979 #endif /* ZANGBAND */
3980 Term_key_push(SPECIAL_KEY_QUIT);
3988 case IDM_FILE_SCORE:
3992 /* Build the filename */
3993 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3995 /* Open the binary high score file, for reading */
3996 highscore_fd = fd_open(buf, O_RDONLY);
3998 /* Paranoia -- No score file */
3999 if (highscore_fd < 0)
4001 msg_print("Score file unavailable.");
4011 /* Display the scores */
4012 display_scores_aux(0, MAX_HISCORES, -1, NULL);
4014 /* Shut the high score file */
4015 (void)fd_close(highscore_fd);
4017 /* Forget the high score fd */
4023 /* Hack - Flush it */
4031 case IDM_FILE_MOVIE:
4036 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
4038 plog("You cannot do that yet...");
4041 else if (game_in_progress)
4044 plog("¥×¥ì¥¤Ãæ¤Ï¥à¡¼¥Ó¡¼¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
4046 plog("You can't open a movie while you're playing!");
4051 memset(&ofn, 0, sizeof(ofn));
4052 ofn.lStructSize = sizeof(ofn);
4053 ofn.hwndOwner = data[0].w;
4054 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
4055 ofn.nFilterIndex = 1;
4056 ofn.lpstrFile = savefile;
4057 ofn.nMaxFile = 1024;
4058 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
4059 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
4061 if (GetOpenFileName(&ofn))
4063 /* Load 'savefile' */
4064 prepare_browse_movie_aux(savefile);
4074 case IDM_WINDOW_VIS_0:
4077 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
4079 plog("You are not allowed to do that!");
4086 /* Window visibility */
4087 case IDM_WINDOW_VIS_1:
4088 case IDM_WINDOW_VIS_2:
4089 case IDM_WINDOW_VIS_3:
4090 case IDM_WINDOW_VIS_4:
4091 case IDM_WINDOW_VIS_5:
4092 case IDM_WINDOW_VIS_6:
4093 case IDM_WINDOW_VIS_7:
4095 i = wCmd - IDM_WINDOW_VIS_0;
4097 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4104 ShowWindow(td->w, SW_SHOW);
4105 term_data_redraw(td);
4109 td->visible = FALSE;
4111 ShowWindow(td->w, SW_HIDE);
4118 case IDM_WINDOW_FONT_0:
4119 case IDM_WINDOW_FONT_1:
4120 case IDM_WINDOW_FONT_2:
4121 case IDM_WINDOW_FONT_3:
4122 case IDM_WINDOW_FONT_4:
4123 case IDM_WINDOW_FONT_5:
4124 case IDM_WINDOW_FONT_6:
4125 case IDM_WINDOW_FONT_7:
4127 i = wCmd - IDM_WINDOW_FONT_0;
4129 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4133 term_change_font(td);
4138 /* Window Z Position */
4139 case IDM_WINDOW_POS_1:
4140 case IDM_WINDOW_POS_2:
4141 case IDM_WINDOW_POS_3:
4142 case IDM_WINDOW_POS_4:
4143 case IDM_WINDOW_POS_5:
4144 case IDM_WINDOW_POS_6:
4145 case IDM_WINDOW_POS_7:
4147 i = wCmd - IDM_WINDOW_POS_0;
4149 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4153 if (!td->posfix && td->visible)
4156 term_window_pos(td, HWND_TOPMOST);
4161 term_window_pos(td, data[0].w);
4167 /* Bizarre Display */
4168 case IDM_WINDOW_BIZ_0:
4169 case IDM_WINDOW_BIZ_1:
4170 case IDM_WINDOW_BIZ_2:
4171 case IDM_WINDOW_BIZ_3:
4172 case IDM_WINDOW_BIZ_4:
4173 case IDM_WINDOW_BIZ_5:
4174 case IDM_WINDOW_BIZ_6:
4175 case IDM_WINDOW_BIZ_7:
4177 i = wCmd - IDM_WINDOW_BIZ_0;
4179 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4183 td->bizarre = !td->bizarre;
4187 term_window_resize(td);
4192 /* Increase Tile Width */
4193 case IDM_WINDOW_I_WID_0:
4194 case IDM_WINDOW_I_WID_1:
4195 case IDM_WINDOW_I_WID_2:
4196 case IDM_WINDOW_I_WID_3:
4197 case IDM_WINDOW_I_WID_4:
4198 case IDM_WINDOW_I_WID_5:
4199 case IDM_WINDOW_I_WID_6:
4200 case IDM_WINDOW_I_WID_7:
4202 i = wCmd - IDM_WINDOW_I_WID_0;
4204 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4212 term_window_resize(td);
4217 /* Decrease Tile Height */
4218 case IDM_WINDOW_D_WID_0:
4219 case IDM_WINDOW_D_WID_1:
4220 case IDM_WINDOW_D_WID_2:
4221 case IDM_WINDOW_D_WID_3:
4222 case IDM_WINDOW_D_WID_4:
4223 case IDM_WINDOW_D_WID_5:
4224 case IDM_WINDOW_D_WID_6:
4225 case IDM_WINDOW_D_WID_7:
4227 i = wCmd - IDM_WINDOW_D_WID_0;
4229 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4237 term_window_resize(td);
4242 /* Increase Tile Height */
4243 case IDM_WINDOW_I_HGT_0:
4244 case IDM_WINDOW_I_HGT_1:
4245 case IDM_WINDOW_I_HGT_2:
4246 case IDM_WINDOW_I_HGT_3:
4247 case IDM_WINDOW_I_HGT_4:
4248 case IDM_WINDOW_I_HGT_5:
4249 case IDM_WINDOW_I_HGT_6:
4250 case IDM_WINDOW_I_HGT_7:
4252 i = wCmd - IDM_WINDOW_I_HGT_0;
4254 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4262 term_window_resize(td);
4267 /* Decrease Tile Height */
4268 case IDM_WINDOW_D_HGT_0:
4269 case IDM_WINDOW_D_HGT_1:
4270 case IDM_WINDOW_D_HGT_2:
4271 case IDM_WINDOW_D_HGT_3:
4272 case IDM_WINDOW_D_HGT_4:
4273 case IDM_WINDOW_D_HGT_5:
4274 case IDM_WINDOW_D_HGT_6:
4275 case IDM_WINDOW_D_HGT_7:
4277 i = wCmd - IDM_WINDOW_D_HGT_0;
4279 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4287 term_window_resize(td);
4292 case IDM_OPTIONS_NO_GRAPHICS:
4297 plog("You may not do that right now.");
4301 /* Toggle "arg_graphics" */
4302 if (arg_graphics != GRAPHICS_NONE)
4304 arg_graphics = GRAPHICS_NONE;
4306 /* React to changes */
4307 Term_xtra_win_react();
4309 /* Hack -- Force redraw */
4310 Term_key_push(KTRL('R'));
4316 case IDM_OPTIONS_OLD_GRAPHICS:
4321 plog("You may not do that right now.");
4325 /* Toggle "arg_graphics" */
4326 if (arg_graphics != GRAPHICS_ORIGINAL)
4328 arg_graphics = GRAPHICS_ORIGINAL;
4330 /* React to changes */
4331 Term_xtra_win_react();
4333 /* Hack -- Force redraw */
4334 Term_key_push(KTRL('R'));
4340 case IDM_OPTIONS_NEW_GRAPHICS:
4345 plog("You may not do that right now.");
4349 /* Toggle "arg_graphics" */
4350 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4352 arg_graphics = GRAPHICS_ADAM_BOLT;
4354 /* React to changes */
4355 Term_xtra_win_react();
4357 /* Hack -- Force redraw */
4358 Term_key_push(KTRL('R'));
4364 case IDM_OPTIONS_NEW2_GRAPHICS:
4369 plog("You may not do that right now.");
4373 /* Toggle "arg_graphics" */
4374 if (arg_graphics != GRAPHICS_HENGBAND)
4376 arg_graphics = GRAPHICS_HENGBAND;
4378 /* React to changes */
4379 Term_xtra_win_react();
4381 /* Hack -- Force redraw */
4382 Term_key_push(KTRL('R'));
4388 case IDM_OPTIONS_BIGTILE:
4390 term_data *td = &data[0];
4395 plog("You may not do that right now.");
4399 /* Toggle "arg_sound" */
4400 arg_bigtile = !arg_bigtile;
4403 Term_activate(&td->t);
4405 /* Resize the term */
4406 Term_resize(td->cols, td->rows);
4409 InvalidateRect(td->w, NULL, TRUE);
4414 case IDM_OPTIONS_MUSIC:
4419 plog("You may not do that right now.");
4423 /* Toggle "arg_sound" */
4424 arg_music = !arg_music;
4426 /* React to changes */
4427 Term_xtra_win_react();
4429 /* Hack -- Force redraw */
4430 Term_key_push(KTRL('R'));
4435 case IDM_OPTIONS_SOUND:
4440 plog("You may not do that right now.");
4444 /* Toggle "arg_sound" */
4445 arg_sound = !arg_sound;
4447 /* React to changes */
4448 Term_xtra_win_react();
4450 /* Hack -- Force redraw */
4451 Term_key_push(KTRL('R'));
4457 case IDM_OPTIONS_BG:
4462 plog("You may not do that right now.");
4466 /* Toggle "use_bg" */
4471 /* React to changes */
4472 Term_xtra_win_react();
4474 /* Hack -- Force redraw */
4475 Term_key_push(KTRL('R'));
4481 case IDM_OPTIONS_OPEN_BG:
4486 plog("You may not do that right now.");
4491 memset(&ofn, 0, sizeof(ofn));
4492 ofn.lStructSize = sizeof(ofn);
4493 ofn.hwndOwner = data[0].w;
4494 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4495 ofn.nFilterIndex = 1;
4496 ofn.lpstrFile = bg_bitmap_file;
4497 ofn.nMaxFile = 1023;
4498 ofn.lpstrInitialDir = NULL;
4500 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
4502 ofn.lpstrTitle = "Choose wall paper.";
4504 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4506 if (GetOpenFileName(&ofn))
4508 /* Load 'savefile' */
4513 /* React to changes */
4514 Term_xtra_win_react();
4516 /* Hack -- Force redraw */
4517 Term_key_push(KTRL('R'));
4522 case IDM_DUMP_SCREEN_HTML:
4524 static char buf[1024] = "";
4525 memset(&ofn, 0, sizeof(ofn));
4526 ofn.lStructSize = sizeof(ofn);
4527 ofn.hwndOwner = data[0].w;
4528 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4529 ofn.nFilterIndex = 1;
4530 ofn.lpstrFile = buf;
4531 ofn.nMaxFile = 1023;
4532 ofn.lpstrDefExt = "html";
4533 ofn.lpstrInitialDir = NULL;
4535 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
4537 ofn.lpstrTitle = "Save screen dump as HTML.";
4539 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4541 if (GetSaveFileName(&ofn))
4543 do_cmd_save_screen_html_aux(buf, 0);
4550 case IDM_OPTIONS_SAVER:
4554 DestroyWindow(hwndSaver);
4559 /* Create a screen scaver window */
4560 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4561 "Angband Screensaver",
4562 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4563 0, 0, GetSystemMetrics(SM_CXSCREEN),
4564 GetSystemMetrics(SM_CYSCREEN),
4565 NULL, NULL, hInstance, NULL);
4569 /* Push the window to the bottom XXX XXX XXX */
4570 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4575 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
4577 plog("Failed to create saver window");
4587 case IDM_OPTIONS_MAP:
4593 case IDM_HELP_CONTENTS:
4597 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4598 if (check_file(tmp))
4600 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4605 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4606 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4608 plog_fmt("Cannot find help file: %s", tmp);
4609 plog("Use the online help files instead.");
4614 #else /* HTML_HELP */
4617 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4618 if (check_file(tmp))
4620 sprintf(buf, "winhelp.exe %s", tmp);
4621 WinExec(buf, SW_NORMAL);
4626 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4627 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4629 plog_fmt("Cannot find help file: %s", tmp);
4630 plog("Use the online help files instead.");
4635 #endif /* HTML_HELP */
4641 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4648 /* Extract the modifiers */
4649 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4650 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4651 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4653 Term_no_press = (ma) ? TRUE : FALSE;
4655 /* Handle "special" keys */
4656 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4658 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4659 bool numpad = FALSE;
4661 /* Begin the macro trigger */
4664 /* Send the modifiers */
4665 if (mc) Term_keypress('C');
4666 if (ms) Term_keypress('S');
4667 if (ma) Term_keypress('A');
4669 /* Extract "scan code" */
4670 i = LOBYTE(HIWORD(lParam));
4672 /* Introduce the scan code */
4675 /* Extended key bit */
4678 /* Numpad Enter and '/' are extended key */
4680 Term_no_press = TRUE;
4681 case VK_RETURN: /* Enter */
4684 /* Other extended keys are on full keyboard */
4700 Term_no_press = TRUE;
4704 case VK_PRIOR: /* Page Up */
4705 case VK_NEXT: /* Page Down */
4715 /* Special modifiers for keypad keys */
4716 if (numpad) Term_keypress('K');
4718 /* Encode the hexidecimal scan code */
4719 Term_keypress(hexsym[i/16]);
4720 Term_keypress(hexsym[i%16]);
4722 /* End the macro trigger */
4733 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4734 WPARAM wParam, LPARAM lParam);
4735 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4736 WPARAM wParam, LPARAM lParam)
4737 #else /* __MWERKS__ */
4738 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4739 WPARAM wParam, LPARAM lParam)
4740 #endif /* __MWERKS__ */
4746 MINMAXINFO FAR *lpmmi;
4752 /* Acquire proper "term_data" info */
4753 td = (term_data *)GetWindowLong(hWnd, 0);
4755 /* Handle message */
4761 SetWindowLong(hWnd, 0, (LONG)(my_td));
4768 mop.dwCallback=(DWORD)hWnd;
4772 case WM_GETMINMAXINFO:
4774 MINMAXINFO FAR *lpmmi;
4777 lpmmi = (MINMAXINFO FAR *)lParam;
4779 /* this message was sent before WM_NCCREATE */
4782 /* Minimum window size is 80x24 */
4783 rc.left = rc.top = 0;
4784 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4785 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4788 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4790 /* Save minimum size */
4791 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4792 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4799 BeginPaint(hWnd, &ps);
4800 if (td) term_data_redraw(td);
4801 EndPaint(hWnd, &ps);
4802 ValidateRect(hWnd, NULL);
4809 if(wParam == MCI_NOTIFY_SUCCESSFUL)
4811 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4812 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4821 if (process_keydown(wParam, lParam))
4828 if (Term_no_press) Term_no_press = FALSE;
4829 else Term_keypress(wParam);
4833 case WM_LBUTTONDOWN:
4835 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4836 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4848 int dx = abs(oldx - mousex) + 1;
4849 int dy = abs(oldy - mousey) + 1;
4850 int ox = (oldx > mousex) ? mousex : oldx;
4851 int oy = (oldy > mousey) ? mousey : oldy;
4861 hGlobal = GlobalAlloc(GHND, sz + 1);
4862 if (hGlobal == NULL) return 0;
4863 lpStr = (LPSTR)GlobalLock(hGlobal);
4865 for (i = 0; i < dy; i++)
4869 char **scr = data[0].t.scr->c;
4871 C_MAKE(s, (dx + 1), char);
4872 strncpy(s, &scr[oy + i][ox], dx);
4876 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4879 if (ox + dx < data[0].cols)
4881 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4884 for (j = 0; j < dx; j++)
4886 if (s[j] == 127) s[j] = '#';
4890 for (j = 0; j < dx; j++)
4892 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4902 GlobalUnlock(hGlobal);
4903 if (OpenClipboard(hWnd) == 0)
4905 GlobalFree(hGlobal);
4909 SetClipboardData(CF_TEXT, hGlobal);
4922 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4923 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4928 dx = abs(oldx - mousex) + 1;
4929 dy = abs(oldy - mousey) + 1;
4930 ox = (oldx > mousex) ? mousex : oldx;
4931 oy = (oldy > mousey) ? mousey : oldy;
4932 Term_inversed_area(hWnd, ox, oy, dx, dy);
4939 dx = abs(cx - mousex) + 1;
4940 dy = abs(cy - mousey) + 1;
4941 ox = (cx > mousex) ? mousex : cx;
4942 oy = (cy > mousey) ? mousey : cy;
4943 Term_inversed_area(hWnd, ox, oy, dx, dy);
4959 if (game_in_progress && character_generated)
4964 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4966 plog("You may not do that right now.");
4971 /* Hack -- Forget messages */
4980 /* do_cmd_save_game(FALSE); */
4981 #else /* ZANGBAND */
4982 /* do_cmd_save_game(); */
4983 #endif /* ZANGBAND */
4984 Term_key_push(SPECIAL_KEY_QUIT);
4991 case WM_QUERYENDSESSION:
4993 if (game_in_progress && character_generated)
4995 /* Hack -- Forget messages */
4998 /* Mega-Hack -- Delay death */
4999 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
5002 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "----¥²¡¼¥àÃæÃÇ----");
5004 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "---- Save and Exit Game ----");
5007 /* Hardcode panic save */
5008 p_ptr->panic_save = 1;
5010 /* Forbid suspend */
5011 signals_ignore_tstp();
5013 /* Indicate panic save */
5015 (void)strcpy(p_ptr->died_from, "(¶ÛµÞ¥»¡¼¥Ö)");
5017 (void)strcpy(p_ptr->died_from, "(panic save)");
5021 (void)save_player();
5035 process_menus(LOWORD(wParam));
5041 /* this message was sent before WM_NCCREATE */
5044 /* it was sent from inside CreateWindowEx */
5045 if (!td->w) return 1;
5047 /* was sent from WM_SIZE */
5048 if (td->size_hack) return 1;
5052 case SIZE_MINIMIZED:
5054 /* Hide sub-windows */
5055 for (i = 1; i < MAX_TERM_DATA; i++)
5057 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
5062 case SIZE_MAXIMIZED:
5064 /* fall through XXX XXX XXX */
5069 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5070 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5073 if ((td->cols != cols) || (td->rows != rows))
5075 /* Save the new size */
5079 if (!IsZoomed(td->w) && !IsIconic(td->w))
5081 normsize.x = td->cols;
5082 normsize.y = td->rows;
5086 Term_activate(&td->t);
5088 /* Resize the term */
5089 Term_resize(td->cols, td->rows);
5092 InvalidateRect(td->w, NULL, TRUE);
5095 td->size_hack = TRUE;
5097 /* Show sub-windows */
5098 for (i = 1; i < MAX_TERM_DATA; i++)
5100 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
5103 td->size_hack = FALSE;
5111 case WM_PALETTECHANGED:
5113 /* Ignore if palette change caused by itself */
5114 if ((HWND)wParam == hWnd) return 0;
5116 /* Fall through... */
5119 case WM_QUERYNEWPALETTE:
5121 if (!paletted) return 0;
5125 SelectPalette(hdc, hPal, FALSE);
5127 i = RealizePalette(hdc);
5129 /* if any palette entries changed, repaint the window. */
5130 if (i) InvalidateRect(hWnd, NULL, TRUE);
5132 ReleaseDC(hWnd, hdc);
5139 if (wParam && !HIWORD(lParam))
5141 /* Do something to sub-windows */
5142 for (i = 1; i < MAX_TERM_DATA; i++)
5144 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
5147 /* Focus on main window */
5156 case WM_ACTIVATEAPP:
5158 if (IsIconic(td->w)) break;
5160 for (i = 1; i < MAX_TERM_DATA; i++)
5166 ShowWindow(data[i].w, SW_SHOW);
5170 ShowWindow(data[i].w, SW_HIDE);
5177 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5182 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5183 WPARAM wParam, LPARAM lParam);
5184 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5185 WPARAM wParam, LPARAM lParam)
5186 #else /* __MWERKS__ */
5187 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5188 WPARAM wParam, LPARAM lParam)
5189 #endif /* __MWERKS__ */
5193 MINMAXINFO FAR *lpmmi;
5201 /* Acquire proper "term_data" info */
5202 td = (term_data *)GetWindowLong(hWnd, 0);
5204 /* Process message */
5210 SetWindowLong(hWnd, 0, (LONG)(my_td));
5220 case WM_GETMINMAXINFO:
5222 MINMAXINFO FAR *lpmmi;
5225 lpmmi = (MINMAXINFO FAR *)lParam;
5227 /* this message was sent before WM_NCCREATE */
5230 /* Minimum window size is 80x24 */
5231 rc.left = rc.top = 0;
5232 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5233 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5236 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5238 /* Save minimum size */
5239 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5240 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5250 /* this message was sent before WM_NCCREATE */
5253 /* it was sent from inside CreateWindowEx */
5254 if (!td->w) return 1;
5256 /* was sent from inside WM_SIZE */
5257 if (td->size_hack) return 1;
5259 td->size_hack = TRUE;
5261 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5262 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5265 if ((td->cols != cols) || (td->rows != rows))
5268 term *old_term = Term;
5270 /* Save the new size */
5275 Term_activate(&td->t);
5277 /* Resize the term */
5278 Term_resize(td->cols, td->rows);
5281 Term_activate(old_term);
5284 InvalidateRect(td->w, NULL, TRUE);
5286 /* HACK - Redraw all windows */
5287 p_ptr->window = 0xFFFFFFFF;
5291 td->size_hack = FALSE;
5298 BeginPaint(hWnd, &ps);
5299 if (td) term_data_redraw(td);
5300 EndPaint(hWnd, &ps);
5307 if (process_keydown(wParam, lParam))
5314 if (Term_no_press) Term_no_press = FALSE;
5315 else Term_keypress(wParam);
5319 case WM_PALETTECHANGED:
5321 /* ignore if palette change caused by itself */
5322 if ((HWND)wParam == hWnd) return FALSE;
5323 /* otherwise, fall through!!! */
5326 case WM_QUERYNEWPALETTE:
5328 if (!paletted) return 0;
5330 SelectPalette(hdc, hPal, FALSE);
5331 i = RealizePalette(hdc);
5332 /* if any palette entries changed, repaint the window. */
5333 if (i) InvalidateRect(hWnd, NULL, TRUE);
5334 ReleaseDC(hWnd, hdc);
5338 case WM_NCLBUTTONDOWN:
5342 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5343 #endif /* HTCLOSE */
5345 if (wParam == HTSYSMENU)
5349 td->visible = FALSE;
5350 ShowWindow(td->w, SW_HIDE);
5360 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5366 #define MOUSE_SENS 40
5369 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5370 WPARAM wParam, LPARAM lParam);
5371 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5372 WPARAM wParam, LPARAM lParam)
5373 #else /* __MWERKS__ */
5374 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5375 WPARAM wParam, LPARAM lParam)
5376 #endif /* __MWERKS__ */
5378 static int iMouse = 0;
5379 static WORD xMouse = 0;
5380 static WORD yMouse = 0;
5403 if (LOWORD(wParam) == WA_INACTIVE) break;
5405 /* else fall through */
5409 case WM_LBUTTONDOWN:
5410 case WM_MBUTTONDOWN:
5411 case WM_RBUTTONDOWN:
5414 SendMessage(hWnd, WM_CLOSE, 0, 0);
5422 dx = LOWORD(lParam) - xMouse;
5423 dy = HIWORD(lParam) - yMouse;
5425 if (dx < 0) dx = -dx;
5426 if (dy < 0) dy = -dy;
5428 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5430 SendMessage(hWnd, WM_CLOSE, 0, 0);
5434 /* Save last location */
5436 xMouse = LOWORD(lParam);
5437 yMouse = HIWORD(lParam);
5444 DestroyWindow(hwndSaver);
5451 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5454 #endif /* USE_SAVER */
5460 /*** Temporary Hooks ***/
5464 * Display warning message (see "z-util.c")
5466 static void hack_plog(cptr str)
5468 /* Give a warning */
5472 MessageBox(NULL, str, "·Ù¹ð¡ª",
5473 MB_ICONEXCLAMATION | MB_OK);
5475 MessageBox(NULL, str, "Warning",
5476 MB_ICONEXCLAMATION | MB_OK);
5484 * Display error message and quit (see "z-util.c")
5486 static void hack_quit(cptr str)
5488 /* Give a warning */
5492 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
5493 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5495 MessageBox(NULL, str, "Error",
5496 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5501 /* Unregister the classes */
5502 UnregisterClass(AppName, hInstance);
5504 /* Destroy the icon */
5505 if (hIcon) DestroyIcon(hIcon);
5513 /*** Various hooks ***/
5517 * Display warning message (see "z-util.c")
5519 static void hook_plog(cptr str)
5525 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
5526 MB_ICONEXCLAMATION | MB_OK);
5528 MessageBox(data[0].w, str, "Warning",
5529 MB_ICONEXCLAMATION | MB_OK);
5537 * Display error message and quit (see "z-util.c")
5539 static void hook_quit(cptr str)
5544 /* Give a warning */
5548 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
5549 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5551 MessageBox(data[0].w, str, "Error",
5552 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5558 /* Save the preferences */
5562 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
5564 /* Destroy all windows */
5565 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5567 term_force_font(&data[i], NULL);
5568 if (data[i].font_want) string_free(data[i].font_want);
5569 if (data[i].w) DestroyWindow(data[i].w);
5573 /* Free the bitmap stuff */
5575 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5576 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5578 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5579 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5581 #endif /* USE_GRAPHICS */
5583 /*** Free some other stuff ***/
5585 DeleteObject(hbrYellow);
5590 if (hPal) DeleteObject(hPal);
5592 UnregisterClass(AppName, hInstance);
5594 if (hIcon) DestroyIcon(hIcon);
5601 /*** Initialize ***/
5607 static void init_stuff(void)
5614 /* Get program name with full path */
5615 GetModuleFileName(hInstance, path, 512);
5617 /* Save the "program name" XXX XXX XXX */
5620 /* Get the name of the "*.ini" file */
5621 strcpy(path + strlen(path) - 4, ".INI");
5623 /* Save the the name of the ini-file */
5624 ini_file = string_make(path);
5626 /* Analyze the path */
5632 if (path[i] == '\\')
5639 /* Add "lib" to the path */
5640 strcpy(path + i + 1, "lib\\");
5642 /* Validate the path */
5643 validate_dir(path, TRUE);
5645 /* Init the file paths */
5646 init_file_paths(path);
5648 /* Hack -- Validate the paths */
5649 validate_dir(ANGBAND_DIR_APEX, FALSE);
5650 validate_dir(ANGBAND_DIR_BONE, FALSE);
5652 /* Allow missing 'edit' directory */
5653 if (!check_dir(ANGBAND_DIR_EDIT))
5655 /* Must have 'data'! */
5656 validate_dir(ANGBAND_DIR_DATA, TRUE);
5660 /* Don't need 'data' */
5661 validate_dir(ANGBAND_DIR_DATA, FALSE);
5664 validate_dir(ANGBAND_DIR_FILE, TRUE);
5665 validate_dir(ANGBAND_DIR_HELP, FALSE);
5666 validate_dir(ANGBAND_DIR_INFO, FALSE);
5667 validate_dir(ANGBAND_DIR_PREF, TRUE);
5668 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5669 validate_dir(ANGBAND_DIR_USER, TRUE);
5670 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5672 /* Build the filename */
5674 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
5676 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
5680 /* Hack -- Validate the "news.txt" file */
5681 validate_file(path);
5684 #if 0 /* #ifndef JP */
5685 /* Build the "font" path */
5686 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5688 /* Allocate the path */
5689 ANGBAND_DIR_XTRA_FONT = string_make(path);
5691 /* Validate the "font" directory */
5692 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5694 /* Build the filename */
5695 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5697 /* Hack -- Validate the basic font */
5698 validate_file(path);
5704 /* Build the "graf" path */
5705 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5707 /* Allocate the path */
5708 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5710 /* Validate the "graf" directory */
5711 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5713 #endif /* USE_GRAPHICS */
5718 /* Build the "sound" path */
5719 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5721 /* Allocate the path */
5722 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5724 /* Validate the "sound" directory */
5725 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5727 #endif /* USE_SOUND */
5731 /* Build the "music" path */
5732 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5734 /* Allocate the path */
5735 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5737 /* Validate the "music" directory */
5738 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5740 #endif /* USE_MUSIC */
5742 /* Build the "help" path */
5743 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5745 /* Allocate the path */
5746 ANGBAND_DIR_XTRA_HELP = string_make(path);
5748 /* Validate the "help" directory */
5749 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5752 bool is_already_running()
5754 bool result = FALSE;
5757 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5758 if (GetLastError() == ERROR_ALREADY_EXISTS)
5766 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5767 LPSTR lpCmdLine, int nCmdShow)
5775 setlocale( LC_ALL, "ja_JP" );
5784 /* Prevent multiple run */
5785 if (is_already_running())
5788 _("ÊѶòÈÚÅܤϤ¹¤Ç¤Ëµ¯Æ°¤·¤Æ¤¤¤Þ¤¹¡£", "Hengband is already running."),
5789 _("¥¨¥é¡¼¡ª", "Error") ,
5790 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5795 if (hPrevInst == NULL)
5797 wc.style = CS_CLASSDC;
5798 wc.lpfnWndProc = AngbandWndProc;
5800 wc.cbWndExtra = 4; /* one long pointer to term_data */
5801 wc.hInstance = hInst;
5802 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5803 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5804 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5805 wc.lpszMenuName = AppName;
5806 wc.lpszClassName = AppName;
5808 if (!RegisterClass(&wc)) exit(1);
5810 wc.lpfnWndProc = AngbandListProc;
5811 wc.lpszMenuName = NULL;
5812 wc.lpszClassName = AngList;
5814 if (!RegisterClass(&wc)) exit(2);
5818 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5819 wc.lpfnWndProc = AngbandSaverProc;
5821 wc.lpszMenuName = NULL;
5822 wc.lpszClassName = "WindowsScreenSaverClass";
5824 if (!RegisterClass(&wc)) exit(3);
5830 /* Temporary hooks */
5831 plog_aux = hack_plog;
5832 quit_aux = hack_quit;
5833 core_aux = hack_quit;
5835 /* Prepare the filepaths */
5838 /* Initialize the keypress analyzer */
5839 for (i = 0; special_key_list[i]; ++i)
5841 special_key[special_key_list[i]] = TRUE;
5843 /* Initialize the keypress analyzer */
5844 for (i = 0; ignore_key_list[i]; ++i)
5846 ignore_key[ignore_key_list[i]] = TRUE;
5849 /* Determine if display is 16/256/true color */
5851 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5852 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5853 ReleaseDC(NULL, hdc);
5855 /* Initialize the colors */
5856 for (i = 0; i < 256; i++)
5860 /* Extract desired values */
5861 rv = angband_color_table[i][1];
5862 gv = angband_color_table[i][2];
5863 bv = angband_color_table[i][3];
5865 /* Extract the "complex" code */
5866 win_clr[i] = PALETTERGB(rv, gv, bv);
5868 /* Save the "simple" code */
5869 angband_color_table[i][0] = win_pal[i];
5872 /* Prepare the windows */
5878 /* Activate hooks */
5879 plog_aux = hook_plog;
5880 quit_aux = hook_quit;
5881 core_aux = hook_quit;
5883 /* Set the system suffix */
5884 ANGBAND_SYS = "win";
5886 /* Set the keyboard suffix */
5887 if (7 != GetKeyboardType(0))
5888 ANGBAND_KEYBOARD = "0";
5891 /* Japanese keyboard */
5892 switch (GetKeyboardType(1))
5894 case 0x0D01: case 0x0D02:
5895 case 0x0D03: case 0x0D04:
5896 case 0x0D05: case 0x0D06:
5898 ANGBAND_KEYBOARD = "NEC98";
5902 ANGBAND_KEYBOARD = "JAPAN";
5906 /* Catch nasty signals */
5912 /* We are now initialized */
5915 if(lpCmdLine[0] == '-'){
5916 switch(lpCmdLine[1])
5921 if (!lpCmdLine[2]) break;
5922 chuukei_server = TRUE;
5923 if(connect_chuukei_server(&lpCmdLine[2])<0){
5924 msg_print("connect fail");
5927 msg_print("connect");
5935 if (!lpCmdLine[2]) break;
5936 chuukei_client = TRUE;
5937 connect_chuukei_server(&lpCmdLine[2]);
5945 if (!lpCmdLine[2]) break;
5946 prepare_browse_movie(&lpCmdLine[2]);
5956 /* Did the user double click on a save file? */
5957 if(!chuukei_server) check_for_save_file(lpCmdLine);
5959 /* Did the user double click on a save file? */
5960 check_for_save_file(lpCmdLine);
5963 /* Prompt the user */
5965 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5967 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5972 /* Process messages forever */
5973 while (GetMessage(&msg, NULL, 0, 0))
5975 TranslateMessage(&msg);
5976 DispatchMessage(&msg);
5987 #endif /* WINDOWS */