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 bool can_use_music = FALSE;
550 static MCI_OPEN_PARMS mop;
551 static char mci_device_type[256];
553 #endif /* USE_MUSIC */
557 * Full path to ANGBAND.INI
559 static cptr ini_file = NULL;
562 * Name of application
564 static cptr AppName = "ANGBAND";
567 * Name of sub-window type
569 static cptr AngList = "AngList";
574 static cptr ANGBAND_DIR_XTRA_GRAF;
575 static cptr ANGBAND_DIR_XTRA_SOUND;
576 static cptr ANGBAND_DIR_XTRA_MUSIC;
577 static cptr ANGBAND_DIR_XTRA_HELP;
578 #if 0 /* #ifndef JP */
579 static cptr ANGBAND_DIR_XTRA_FONT;
582 static cptr ANGBAND_DIR_XTRA_MUSIC;
587 * The "complex" color values
589 static COLORREF win_clr[256];
593 * Flag for macro trigger with dump ASCII
595 static bool Term_no_press = FALSE;
600 static bool mouse_down = FALSE;
601 static bool paint_rect = FALSE;
602 static int mousex = 0, mousey = 0;
603 static int oldx, oldy;
607 * The "simple" color values
609 * See "main-ibm.c" for original table information
611 * The entries below are taken from the "color bits" defined above.
613 * Note that many of the choices below suck, but so do crappy monitors.
615 static BYTE win_pal[256] =
617 VID_BLACK, /* Dark */
618 VID_WHITE, /* White */
619 VID_CYAN, /* Slate XXX */
620 VID_RED | VID_BRIGHT, /* Orange XXX */
622 VID_GREEN, /* Green */
624 VID_YELLOW, /* Umber XXX */
625 VID_BLACK | VID_BRIGHT, /* Light Dark */
626 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
627 VID_MAGENTA, /* Violet XXX */
628 VID_YELLOW | VID_BRIGHT, /* Yellow */
629 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
630 VID_GREEN | VID_BRIGHT, /* Light Green */
631 VID_BLUE | VID_BRIGHT, /* Light Blue */
632 VID_YELLOW /* Light Umber XXX */
637 * Hack -- define which keys are "special"
639 static bool special_key[256];
640 static bool ignore_key[256];
644 * Hack -- initialization list for "special_key"
646 static byte special_key_list[] = {
647 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
648 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
649 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
650 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
651 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
652 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
653 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
654 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
655 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
656 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
657 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
658 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
659 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
660 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
661 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
662 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
663 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
668 static byte ignore_key_list[] = {
669 VK_ESCAPE, VK_TAB, VK_SPACE,
670 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
671 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
672 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
678 * Hack -- initialization list for "special_key"
680 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
681 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
682 * catch the keypad keys (with and without numlock set, including keypad 5),
683 * the function keys (including the "menu" key which maps to F10), and the
684 * "pause" key (between scroll lock and numlock). We also catch a few odd
685 * keys which I do not recognize, but which are listed among keys which we
686 * do catch, so they should be harmless to catch.
688 static byte special_key_list[] =
690 VK_CLEAR, /* 0x0C (KP<5>) */
692 VK_PAUSE, /* 0x13 (pause) */
694 VK_PRIOR, /* 0x21 (KP<9>) */
695 VK_NEXT, /* 0x22 (KP<3>) */
696 VK_END, /* 0x23 (KP<1>) */
697 VK_HOME, /* 0x24 (KP<7>) */
698 VK_LEFT, /* 0x25 (KP<4>) */
699 VK_UP, /* 0x26 (KP<8>) */
700 VK_RIGHT, /* 0x27 (KP<6>) */
701 VK_DOWN, /* 0x28 (KP<2>) */
702 VK_SELECT, /* 0x29 (?????) */
703 VK_PRINT, /* 0x2A (?????) */
704 VK_EXECUTE, /* 0x2B (?????) */
705 VK_SNAPSHOT, /* 0x2C (?????) */
706 VK_INSERT, /* 0x2D (KP<0>) */
707 VK_DELETE, /* 0x2E (KP<.>) */
708 VK_HELP, /* 0x2F (?????) */
710 VK_NUMPAD0, /* 0x60 (KP<0>) */
711 VK_NUMPAD1, /* 0x61 (KP<1>) */
712 VK_NUMPAD2, /* 0x62 (KP<2>) */
713 VK_NUMPAD3, /* 0x63 (KP<3>) */
714 VK_NUMPAD4, /* 0x64 (KP<4>) */
715 VK_NUMPAD5, /* 0x65 (KP<5>) */
716 VK_NUMPAD6, /* 0x66 (KP<6>) */
717 VK_NUMPAD7, /* 0x67 (KP<7>) */
718 VK_NUMPAD8, /* 0x68 (KP<8>) */
719 VK_NUMPAD9, /* 0x69 (KP<9>) */
720 VK_MULTIPLY, /* 0x6A (KP<*>) */
721 VK_ADD, /* 0x6B (KP<+>) */
722 VK_SEPARATOR, /* 0x6C (?????) */
723 VK_SUBTRACT, /* 0x6D (KP<->) */
724 VK_DECIMAL, /* 0x6E (KP<.>) */
725 VK_DIVIDE, /* 0x6F (KP</>) */
756 static void delete_bg(void)
765 static int init_bg(void)
767 char * bmfile = bg_bitmap_file;
770 if (use_bg == 0) return 0;
772 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
775 plog_fmt("ÊÉ»æÍÑ¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
777 plog_fmt("Can't load the bitmap file '%s'.", bmfile);
783 HDC wnddc, dcimage, dcbg;
784 HBITMAP bmimage, bmimage_old, bmbg_old;
790 dcimage = CreateCompatibleDC(wnddc);
791 dcbg = CreateCompatibleDC(wnddc);
793 bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
794 if (!bmimage) quit("bg.bmp¤¬Æɤߤ³¤á¤Ê¤¤¡ª");
795 bmimage_old = SelectObject(dcimage, bmimage);
797 CreateCompatibleBitmap();
799 ReleaseDC(hwnd, wnddc);
805 static void DrawBG(HDC hdc, RECT *r)
810 int x = r->left, y = r->top;
811 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
817 GetObject(hBG, sizeof(bm), &bm);
818 swid = bm.bmWidth; shgt = bm.bmHeight;
820 hdcSrc = CreateCompatibleDC(hdc);
821 hOld = SelectObject(hdcSrc, hBG);
825 cwid = MIN(swid - sx, r->right - nx);
828 chgt = MIN(shgt - sy, r->bottom - ny);
829 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
831 } while (ny < r->bottom);
834 } while (nx < r->right);
836 SelectObject(hdcSrc, hOld);
842 * Hack -- given a pathname, point at the filename
844 static cptr extract_file_name(cptr s)
848 /* Start at the end */
849 p = s + strlen(s) - 1;
851 /* Back up to divider */
852 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
854 /* Return file name */
861 * Hack -- given a simple filename, extract the "font size" info
863 * Return a pointer to a static buffer holding the capitalized base name.
865 #if 0 /* #ifndef JP */
866 static char *analyze_font(char *path, int *wp, int *hp)
872 /* Start at the end */
873 p = path + strlen(path) - 1;
875 /* Back up to divider */
876 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
878 /* Advance to file name */
884 /* Capitalize (be paranoid) */
885 if (islower(*s)) *s = toupper(*s);
889 s = my_strchr(p, 'X');
891 /* Extract font width */
895 hgt = s ? atoi(s+1) : 0;
908 * Check for existance of a file
910 static bool check_file(cptr s)
930 attrib = GetFileAttributes(path);
932 /* Require valid filename */
933 if (attrib == INVALID_FILE_NAME) return (FALSE);
935 /* Prohibit directory */
936 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
940 /* Examine and verify */
941 if (_dos_getfileattr(path, &attrib)) return (FALSE);
943 /* Prohibit something */
944 if (attrib & FA_LABEL) return (FALSE);
946 /* Prohibit directory */
947 if (attrib & FA_DIREC) return (FALSE);
957 * Check for existance of a directory
959 static bool check_dir(cptr s)
981 /* Remove trailing backslash */
982 if (i && (path[i-1] == '\\')) path[--i] = '\0';
987 attrib = GetFileAttributes(path);
989 /* Require valid filename */
990 if (attrib == INVALID_FILE_NAME) return (FALSE);
992 /* Require directory */
993 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
997 /* Examine and verify */
998 if (_dos_getfileattr(path, &attrib)) return (FALSE);
1000 /* Prohibit something */
1001 if (attrib & FA_LABEL) return (FALSE);
1003 /* Require directory */
1004 if (!(attrib & FA_DIREC)) return (FALSE);
1016 static void validate_file(cptr s)
1018 /* Verify or fail */
1022 quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
1024 quit_fmt("Cannot find required file:\n%s", s);
1032 * Validate a directory
1034 static void validate_dir(cptr s, bool vital)
1036 /* Verify or fail */
1039 /* This directory contains needed data */
1043 quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
1045 quit_fmt("Cannot find required directory:\n%s", s);
1049 /* Attempt to create this directory */
1052 quit_fmt("Unable to create directory:\n%s", s);
1059 * Get the "size" for a window
1061 static void term_getsize(term_data *td)
1068 if (td->cols < 1) td->cols = 1;
1069 if (td->rows < 1) td->rows = 1;
1072 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1073 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1075 /* Fake window size */
1077 rc.right = rc.left + wid;
1079 rc.bottom = rc.top + hgt;
1082 /* rc.right += 1; */
1083 /* rc.bottom += 1; */
1086 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1089 td->size_wid = rc.right - rc.left;
1090 td->size_hgt = rc.bottom - rc.top;
1092 /* See CreateWindowEx */
1095 /* Extract actual location */
1096 GetWindowRect(td->w, &rc);
1098 /* Save the location */
1099 td->pos_x = rc.left;
1105 * Write the "prefs" for a single term
1107 static void save_prefs_aux(int i)
1109 term_data *td = &data[i];
1114 WINDOWPLACEMENT lpwndpl;
1119 /* Make section name */
1120 sprintf(sec_name, "Term-%d", i);
1125 strcpy(buf, td->visible ? "1" : "0");
1126 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1131 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1134 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1136 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1140 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1142 #if 1 /* #ifdef JP */
1143 wsprintf(buf, "%d", td->lf.lfWidth);
1144 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1145 wsprintf(buf, "%d", td->lf.lfHeight);
1146 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1147 wsprintf(buf, "%d", td->lf.lfWeight);
1148 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1151 strcpy(buf, td->bizarre ? "1" : "0");
1152 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1155 wsprintf(buf, "%d", td->tile_wid);
1156 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1159 wsprintf(buf, "%d", td->tile_hgt);
1160 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1162 /* Get window placement and dimensions */
1163 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1164 GetWindowPlacement(td->w, &lpwndpl);
1166 /* Acquire position in *normal* mode (not minimized) */
1167 rc = lpwndpl.rcNormalPosition;
1169 /* Window size (x) */
1170 if (i == 0) wsprintf(buf, "%d", normsize.x);
1171 else wsprintf(buf, "%d", td->cols);
1172 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1174 /* Window size (y) */
1175 if (i == 0) wsprintf(buf, "%d", normsize.y);
1176 else wsprintf(buf, "%d", td->rows);
1177 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1179 /* Maxmized (only main window) */
1182 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1183 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1186 /* Acquire position */
1187 GetWindowRect(td->w, &rc);
1189 /* Window position (x) */
1190 wsprintf(buf, "%d", rc.left);
1191 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1193 /* Window position (y) */
1194 wsprintf(buf, "%d", rc.top);
1195 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1197 /* Window Z position */
1200 strcpy(buf, td->posfix ? "1" : "0");
1201 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1209 * We assume that the windows have all been initialized
1211 static void save_prefs(void)
1217 /* Save the "arg_graphics" flag */
1218 sprintf(buf, "%d", arg_graphics);
1219 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1221 /* Save the "arg_bigtile" flag */
1222 strcpy(buf, arg_bigtile ? "1" : "0");
1223 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1225 /* Save the "arg_sound" flag */
1226 strcpy(buf, arg_sound ? "1" : "0");
1227 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1229 /* Save the "arg_sound" flag */
1230 strcpy(buf, arg_music ? "1" : "0");
1231 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1234 strcpy(buf, use_bg ? "1" : "0");
1235 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1236 WritePrivateProfileString("Angband", "BackGroundBitmap",
1237 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1239 /* Save window prefs */
1240 for (i = 0; i < MAX_TERM_DATA; ++i)
1248 * Load the "prefs" for a single term
1250 static void load_prefs_aux(int i)
1252 term_data *td = &data[i];
1256 int wid, hgt, posx, posy;
1257 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1258 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1262 /* Make section name */
1263 sprintf(sec_name, "Term-%d", i);
1265 /* Make section name */
1266 sprintf(sec_name, "Term-%d", i);
1271 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1274 /* Desired font, with default */
1276 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1279 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1281 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1287 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1289 /* Analyze font, save desired font name */
1290 #if 1 /* #ifdef JP */
1291 td->font_want = string_make(tmp);
1293 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1294 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1295 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1297 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1302 #if 1 /* #ifdef JP */
1303 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1304 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1306 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1307 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1312 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1313 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1314 normsize.x = td->cols; normsize.y = td->rows;
1319 win_maximized = GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file);
1322 /* Window position */
1323 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1324 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1325 td->pos_x = MIN(MAX(0, posx), dispx-128);
1326 td->pos_y = MIN(MAX(0, posy), dispy-128);
1328 /* Window Z position */
1331 td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1339 static void load_prefs(void)
1343 /* Extract the "arg_graphics" flag */
1344 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1346 /* Extract the "arg_bigtile" flag */
1347 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1348 use_bigtile = arg_bigtile;
1350 /* Extract the "arg_sound" flag */
1351 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1353 /* Extract the "arg_sound" flag */
1354 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1357 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1358 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1360 /* Load window prefs */
1361 for (i = 0; i < MAX_TERM_DATA; ++i)
1367 #if defined(USE_SOUND) || defined(USE_MUSIC)
1370 * XXX XXX XXX - Taken from files.c.
1372 * Extract "tokens" from a buffer
1374 * This function uses "whitespace" as delimiters, and treats any amount of
1375 * whitespace as a single delimiter. We will never return any empty tokens.
1376 * When given an empty buffer, or a buffer containing only "whitespace", we
1377 * will return no tokens. We will never extract more than "num" tokens.
1379 * By running a token through the "text_to_ascii()" function, you can allow
1380 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1382 * We save pointers to the tokens in "tokens", and return the number found.
1384 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1396 /* Skip leading whitespace */
1397 for ( ; *s && iswspace(*s); ++s) /* loop */;
1402 /* Find next whitespace, if any */
1403 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1405 /* Nuke and advance (if necessary) */
1406 if (*t) *t++ = '\0';
1408 /* Save the token */
1419 #endif /* USE_SOUND || USE_MUSIC */
1423 static void load_sound_prefs(void)
1427 char ini_path[1024];
1428 char wav_path[1024];
1429 char *zz[SAMPLE_MAX];
1431 /* Access the sound.cfg */
1433 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1435 for (i = 0; i < SOUND_MAX; i++)
1437 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1439 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1441 for (j = 0; j < num; j++)
1443 /* Access the sound */
1444 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1446 /* Save the sound filename, if it exists */
1447 if (check_file(wav_path))
1448 sound_file[i][j] = string_make(zz[j]);
1453 #endif /* USE_SOUND */
1457 static void load_music_prefs(void)
1461 char ini_path[1024];
1462 char wav_path[1024];
1463 char *zz[SAMPLE_MAX];
1465 /* Access the music.cfg */
1467 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1469 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1471 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1473 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1475 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1477 for (j = 0; j < num; j++)
1479 /* Access the sound */
1480 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1482 /* Save the sound filename, if it exists */
1483 if (check_file(wav_path))
1484 music_file[i][j] = string_make(zz[j]);
1489 #endif /* USE_MUSIC */
1492 * Create the new global palette based on the bitmap palette
1493 * (if any), and the standard 16 entry palette derived from
1494 * "win_clr[]" which is used for the basic 16 Angband colors.
1496 * This function is never called before all windows are ready.
1498 * This function returns FALSE if the new palette could not be
1499 * prepared, which should normally be a fatal error. XXX XXX
1501 * Note that only some machines actually use a "palette".
1503 static int new_palette(void)
1511 LPLOGPALETTE pLogPal;
1512 LPPALETTEENTRY lppe;
1517 /* This makes no sense */
1518 if (!paletted) return (TRUE);
1528 /* Check the bitmap palette */
1529 hBmPal = infGraph.hPalette;
1531 /* Use the bitmap */
1534 lppeSize = 256 * sizeof(PALETTEENTRY);
1535 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1536 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1537 if ((nEntries == 0) || (nEntries > 220))
1541 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1543 plog("Please switch to high- or true-color mode.");
1548 rnfree(lppe, lppeSize);
1555 #endif /* USE_GRAPHICS */
1557 /* Size of palette */
1558 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1560 /* Allocate palette */
1561 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1564 pLogPal->palVersion = 0x300;
1566 /* Make room for bitmap and normal data */
1567 pLogPal->palNumEntries = nEntries + 16;
1569 /* Save the bitmap data */
1570 for (i = 0; i < nEntries; i++)
1572 pLogPal->palPalEntry[i] = lppe[i];
1575 /* Save the normal data */
1576 for (i = 0; i < 16; i++)
1580 /* Access the entry */
1581 p = &(pLogPal->palPalEntry[i+nEntries]);
1583 /* Save the colors */
1584 p->peRed = GetRValue(win_clr[i]);
1585 p->peGreen = GetGValue(win_clr[i]);
1586 p->peBlue = GetBValue(win_clr[i]);
1588 /* Save the flags */
1589 p->peFlags = PC_NOCOLLAPSE;
1592 /* Free something */
1593 if (lppe) rnfree(lppe, lppeSize);
1595 /* Create a new palette, or fail */
1596 hNewPal = CreatePalette(pLogPal);
1598 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1600 if (!hNewPal) quit("Cannot create palette!");
1604 /* Free the palette */
1605 rnfree(pLogPal, pLogPalSize);
1610 /* Realize the palette */
1612 SelectPalette(hdc, hNewPal, 0);
1613 i = RealizePalette(hdc);
1614 ReleaseDC(td->w, hdc);
1616 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1618 if (i == 0) quit("Cannot realize palette!");
1623 for (i = 1; i < MAX_TERM_DATA; i++)
1628 SelectPalette(hdc, hNewPal, 0);
1629 ReleaseDC(td->w, hdc);
1632 /* Delete old palette */
1633 if (hPal) DeleteObject(hPal);
1635 /* Save new palette */
1645 * Initialize graphics
1647 static bool init_graphics(void)
1649 /* Initialize once */
1650 /* if (can_use_graphics != arg_graphics) */
1656 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1663 ANGBAND_GRAF = "new";
1665 else if (arg_graphics == GRAPHICS_HENGBAND)
1672 ANGBAND_GRAF = "ne2";
1680 ANGBAND_GRAF = "old";
1683 /* Access the bitmap file */
1684 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1686 /* Load the bitmap or quit */
1687 if (!ReadDIB(data[0].w, buf, &infGraph))
1690 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1692 plog_fmt("Cannot read bitmap file '%s'", name);
1698 /* Save the new sizes */
1699 infGraph.CellWidth = wid;
1700 infGraph.CellHeight = hgt;
1702 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1704 /* Access the mask file */
1705 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1707 /* Load the bitmap or quit */
1708 if (!ReadDIB(data[0].w, buf, &infMask))
1710 plog_fmt("Cannot read bitmap file '%s'", buf);
1714 if (arg_graphics == GRAPHICS_HENGBAND)
1716 /* Access the mask file */
1717 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1719 /* Load the bitmap or quit */
1720 if (!ReadDIB(data[0].w, buf, &infMask))
1722 plog_fmt("Cannot read bitmap file '%s'", buf);
1727 /* Activate a palette */
1730 /* Free bitmap XXX XXX XXX */
1734 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1736 plog("Cannot activate palette!");
1742 /* Graphics available */
1743 can_use_graphics = arg_graphics;
1747 return (can_use_graphics);
1749 #endif /* USE_GRAPHICS */
1756 static bool init_music(void)
1758 /* Initialize once */
1761 /* Load the prefs */
1764 /* Sound available */
1765 can_use_music = TRUE;
1769 return (can_use_music);
1773 * Hack -- Stop a music
1775 static void stop_music(void)
1777 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1778 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1781 #endif /* USE_MUSIC */
1787 static bool init_sound(void)
1789 /* Initialize once */
1792 /* Load the prefs */
1795 /* Sound available */
1796 can_use_sound = TRUE;
1800 return (can_use_sound);
1802 #endif /* USE_SOUND */
1808 static void term_window_resize(term_data *td)
1810 /* Require window */
1813 /* Resize the window */
1814 SetWindowPos(td->w, 0, 0, 0,
1815 td->size_wid, td->size_hgt,
1816 SWP_NOMOVE | SWP_NOZORDER);
1819 InvalidateRect(td->w, NULL, TRUE);
1824 * Force the use of a new "font file" for a term_data
1826 * This function may be called before the "window" is ready
1828 * This function returns zero only if everything succeeds.
1830 * Note that the "font name" must be capitalized!!!
1832 static errr term_force_font(term_data *td, cptr path)
1836 #if 0 /* #ifndef JP */
1842 /* Forget the old font (if needed) */
1843 if (td->font_id) DeleteObject(td->font_id);
1845 #if 1 /* #ifdef JP */
1849 /* Create the font (using the 'base' of the font file name!) */
1850 td->font_id = CreateFontIndirect(&(td->lf));
1851 wid = td->lf.lfWidth;
1852 hgt = td->lf.lfHeight;
1853 if (!td->font_id) return (1);
1855 /* Forget old font */
1861 for (i = 0; i < MAX_TERM_DATA; i++)
1863 /* Don't check when closing the application */
1866 /* Check "screen" */
1867 if ((td != &data[i]) &&
1868 (data[i].font_file) &&
1869 (streq(data[i].font_file, td->font_file)))
1875 /* Remove unused font resources */
1876 if (!used) RemoveFontResource(td->font_file);
1878 /* Free the old name */
1879 string_free(td->font_file);
1882 td->font_file = NULL;
1886 if (!path) return (1);
1891 /* Analyze font path */
1892 base = analyze_font(buf, &wid, &hgt);
1895 if (!suffix(base, ".FON")) return (1);
1898 if (!check_file(buf)) return (1);
1900 /* Load the new font */
1901 if (!AddFontResource(buf)) return (1);
1903 /* Save new font name */
1904 td->font_file = string_make(base);
1906 /* Remove the "suffix" */
1907 base[strlen(base)-4] = '\0';
1909 /* Create the font (using the 'base' of the font file name!) */
1910 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1911 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1912 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1913 FIXED_PITCH | FF_DONTCARE, base);
1916 /* Hack -- Unknown size */
1923 /* all this trouble to get the cell size */
1924 hdcDesktop = GetDC(HWND_DESKTOP);
1925 hfOld = SelectObject(hdcDesktop, td->font_id);
1926 GetTextMetrics(hdcDesktop, &tm);
1927 SelectObject(hdcDesktop, hfOld);
1928 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1930 /* Font size info */
1931 wid = tm.tmAveCharWidth;
1935 /* Save the size info */
1946 * Allow the user to change the font for this window.
1948 static void term_change_font(term_data *td)
1950 #if 1 /* #ifdef JP */
1953 memset(&cf, 0, sizeof(cf));
1954 cf.lStructSize = sizeof(cf);
1955 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1956 cf.lpLogFont = &(td->lf);
1958 if (ChooseFont(&cf))
1960 /* Force the font */
1961 term_force_font(td, NULL);
1963 /* Assume not bizarre */
1966 /* Reset the tile info */
1967 td->tile_wid = td->font_wid;
1968 td->tile_hgt = td->font_hgt;
1970 /* Analyze the font */
1973 /* Resize the window */
1974 term_window_resize(td);
1980 char tmp[1024] = "";
1982 /* Extract a default if possible */
1983 if (td->font_file) strcpy(tmp, td->font_file);
1985 /* Ask for a choice */
1986 memset(&ofn, 0, sizeof(ofn));
1987 ofn.lStructSize = sizeof(ofn);
1988 ofn.hwndOwner = data[0].w;
1989 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1990 ofn.nFilterIndex = 1;
1991 ofn.lpstrFile = tmp;
1993 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1994 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1995 ofn.lpstrDefExt = "fon";
1997 /* Force choice if legal */
1998 if (GetOpenFileName(&ofn))
2000 /* Force the font */
2001 if (term_force_font(td, tmp))
2003 /* Access the standard font file */
2004 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2006 /* Force the use of that font */
2007 (void)term_force_font(td, tmp);
2010 /* Assume not bizarre */
2011 td->bizarre = FALSE;
2013 /* Reset the tile info */
2014 td->tile_wid = td->font_wid;
2015 td->tile_hgt = td->font_hgt;
2017 /* Analyze the font */
2020 /* Resize the window */
2021 term_window_resize(td);
2028 * Allow the user to lock this window.
2030 static void term_window_pos(term_data *td, HWND hWnd)
2032 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2033 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2036 static void windows_map(void);
2039 * Hack -- redraw a term_data
2041 static void term_data_redraw(term_data *td)
2045 /* Redraw the map */
2050 /* Activate the term */
2051 Term_activate(&td->t);
2053 /* Redraw the contents */
2056 /* Restore the term */
2057 Term_activate(term_screen);
2062 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2066 HBRUSH myBrush, oldBrush;
2068 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2069 int tx = td->size_ow1 + x * td->tile_wid;
2070 int ty = td->size_oh1 + y * td->tile_hgt;
2071 int tw = w * td->tile_wid - 1;
2072 int th = h * td->tile_hgt - 1;
2075 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2076 oldBrush = SelectObject(hdc, myBrush);
2077 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2079 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2081 SelectObject(hdc, oldBrush);
2082 SelectObject(hdc, oldPen);
2087 /*** Function hooks needed by "Term" ***/
2093 * Initialize a new Term
2095 static void Term_init_win(term *t)
2104 static void Term_nuke_win(term *t)
2113 * Interact with the User
2115 static errr Term_user_win(int n)
2126 * React to global changes
2128 static errr Term_xtra_win_react(void)
2136 /* Save the default colors */
2137 for (i = 0; i < 256; i++)
2139 /* Simply accept the desired colors */
2140 win_pal[i] = angband_color_table[i][0];
2151 bool change = FALSE;
2153 /* Save the default colors */
2154 for (i = 0; i < 256; i++)
2156 /* Extract desired values */
2157 rv = angband_color_table[i][1];
2158 gv = angband_color_table[i][2];
2159 bv = angband_color_table[i][3];
2161 /* Extract a full color code */
2162 code = PALETTERGB(rv, gv, bv);
2164 /* Activate changes */
2165 if (win_clr[i] != code)
2167 /* Note the change */
2170 /* Apply the desired color */
2175 /* Activate the palette if needed */
2176 if (change) (void)new_palette();
2182 /* Handle "arg_sound" */
2183 if (use_sound != arg_sound)
2185 /* Initialize (if needed) */
2186 if (arg_sound && !init_sound())
2190 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
2192 plog("Cannot initialize sound!");
2200 /* Change setting */
2201 use_sound = arg_sound;
2208 /* Handle "arg_sound" */
2209 if (use_music != arg_music)
2211 /* Initialize (if needed) */
2212 if (arg_music && !init_music())
2216 plog("BGM¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
2218 plog("Cannot initialize BGM!");
2224 /* Change setting */
2225 use_music = arg_music;
2227 if(!arg_music) stop_music();
2228 else select_floor_music();
2237 /* Handle "arg_graphics" */
2238 if (use_graphics != arg_graphics)
2240 /* Initialize (if needed) */
2241 if (arg_graphics && !init_graphics())
2245 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
2247 plog("Cannot initialize graphics!");
2252 arg_graphics = GRAPHICS_NONE;
2255 /* Change setting */
2256 use_graphics = arg_graphics;
2259 #ifdef ANGBAND_2_8_1
2261 #else /* ANGBAND_2_8_1 */
2262 reset_visuals(TRUE);
2263 #endif /* ANGBAND_2_8_1 */
2266 #endif /* USE_GRAPHICS */
2269 /* Clean up windows */
2270 for (i = 0; i < MAX_TERM_DATA; i++)
2274 term_data *td = &data[i];
2276 /* Update resized windows */
2277 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2280 Term_activate(&td->t);
2282 /* Hack -- Resize the term */
2283 Term_resize(td->cols, td->rows);
2285 /* Redraw the contents */
2300 * Process at least one event
2302 static errr Term_xtra_win_event(int v)
2306 /* Wait for an event */
2310 if (GetMessage(&msg, NULL, 0, 0))
2312 TranslateMessage(&msg);
2313 DispatchMessage(&msg);
2317 /* Check for an event */
2321 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2323 TranslateMessage(&msg);
2324 DispatchMessage(&msg);
2334 * Process all pending events
2336 static errr Term_xtra_win_flush(void)
2340 /* Process all pending events */
2341 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2343 TranslateMessage(&msg);
2344 DispatchMessage(&msg);
2353 * Hack -- clear the screen
2355 * Make this more efficient XXX XXX XXX
2357 static errr Term_xtra_win_clear(void)
2359 term_data *td = (term_data*)(Term->data);
2364 /* Rectangle to erase */
2365 rc.left = td->size_ow1;
2366 rc.right = rc.left + td->cols * td->tile_wid;
2367 rc.top = td->size_oh1;
2368 rc.bottom = rc.top + td->rows * td->tile_hgt;
2372 SetBkColor(hdc, RGB(0, 0, 0));
2373 SelectObject(hdc, td->font_id);
2374 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2379 rc.left = 0; rc.top = 0;
2382 ReleaseDC(td->w, hdc);
2390 * Hack -- make a noise
2392 static errr Term_xtra_win_noise(void)
2394 MessageBeep(MB_ICONASTERISK);
2400 * Hack -- make a sound
2402 static errr Term_xtra_win_sound(int v)
2407 #endif /* USE_SOUND */
2409 /* Sound disabled */
2410 if (!use_sound) return (1);
2413 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2417 /* Count the samples */
2418 for (i = 0; i < SAMPLE_MAX; i++)
2420 if (!sound_file[v][i])
2425 if (i == 0) return (1);
2427 /* Build the path */
2428 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2432 /* Play the sound, catch errors */
2433 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2437 /* Play the sound, catch errors */
2438 return (sndPlaySound(buf, SND_ASYNC));
2442 #else /* USE_SOUND */
2447 #endif /* USE_SOUND */
2451 * Hack -- play a music
2453 static errr Term_xtra_win_music(int v)
2458 #endif /* USE_MUSIC */
2460 /* Sound disabled */
2461 if (!use_music) return (1);
2464 if ((v < 0) || (v >= MUSIC_BASIC_MAX)) return (1);
2468 /* Count the samples */
2469 for (i = 0; i < SAMPLE_MAX; i++)
2471 if (!music_file[v][i]) break;
2477 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2478 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2482 /* Build the path */
2483 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2485 #endif /* USE_MUSIC */
2489 mop.lpstrDeviceType = mci_device_type;
2490 mop.lpstrElementName = buf;
2491 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2492 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2493 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2494 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2495 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2498 #else /* USE_MUSIC */
2503 #endif /* USE_MUSIC */
2508 * Delay for "x" milliseconds
2510 static int Term_xtra_win_delay(int v)
2524 t = GetTickCount() + v;
2527 while (GetTickCount() < t)
2529 /* Handle messages */
2530 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2532 TranslateMessage(&msg);
2533 DispatchMessage(&msg);
2545 * Do a "special thing"
2547 static errr Term_xtra_win(int n, int v)
2549 /* Handle a subset of the legal requests */
2552 /* Make a bell sound */
2553 case TERM_XTRA_NOISE:
2555 return (Term_xtra_win_noise());
2559 case TERM_XTRA_MUSIC_BASIC:
2561 return (Term_xtra_win_music(v));
2564 /* Make a special sound */
2565 case TERM_XTRA_SOUND:
2567 return (Term_xtra_win_sound(v));
2570 /* Process random events */
2571 case TERM_XTRA_BORED:
2573 return (Term_xtra_win_event(0));
2576 /* Process an event */
2577 case TERM_XTRA_EVENT:
2579 return (Term_xtra_win_event(v));
2582 /* Flush all events */
2583 case TERM_XTRA_FLUSH:
2585 return (Term_xtra_win_flush());
2588 /* Clear the screen */
2589 case TERM_XTRA_CLEAR:
2591 return (Term_xtra_win_clear());
2594 /* React to global changes */
2595 case TERM_XTRA_REACT:
2597 return (Term_xtra_win_react());
2600 /* Delay for some milliseconds */
2601 case TERM_XTRA_DELAY:
2603 return (Term_xtra_win_delay(v));
2614 * Low level graphics (Assumes valid input).
2616 * Draw a "cursor" at (x,y), using a "yellow box".
2618 static errr Term_curs_win(int x, int y)
2620 term_data *td = (term_data*)(Term->data);
2625 int tile_wid, tile_hgt;
2629 tile_wid = td->map_tile_wid;
2630 tile_hgt = td->map_tile_hgt;
2634 tile_wid = td->tile_wid;
2635 tile_hgt = td->tile_hgt;
2638 /* Frame the grid */
2639 rc.left = x * tile_wid + td->size_ow1;
2640 rc.right = rc.left + tile_wid;
2641 rc.top = y * tile_hgt + td->size_oh1;
2642 rc.bottom = rc.top + tile_hgt;
2644 /* Cursor is done as a yellow "box" */
2646 FrameRect(hdc, &rc, hbrYellow);
2647 ReleaseDC(td->w, hdc);
2655 * Low level graphics (Assumes valid input).
2657 * Draw a "big cursor" at (x,y), using a "yellow box".
2659 static errr Term_bigcurs_win(int x, int y)
2661 term_data *td = (term_data*)(Term->data);
2666 int tile_wid, tile_hgt;
2670 /* Normal cursor in map window */
2671 Term_curs_win(x, y);
2676 tile_wid = td->tile_wid;
2677 tile_hgt = td->tile_hgt;
2680 /* Frame the grid */
2681 rc.left = x * tile_wid + td->size_ow1;
2682 rc.right = rc.left + 2 * tile_wid;
2683 rc.top = y * tile_hgt + td->size_oh1;
2684 rc.bottom = rc.top + tile_hgt;
2686 /* Cursor is done as a yellow "box" */
2688 FrameRect(hdc, &rc, hbrYellow);
2689 ReleaseDC(td->w, hdc);
2697 * Low level graphics (Assumes valid input).
2699 * Erase a "block" of "n" characters starting at (x,y).
2701 static errr Term_wipe_win(int x, int y, int n)
2703 term_data *td = (term_data*)(Term->data);
2708 /* Rectangle to erase in client coords */
2709 rc.left = x * td->tile_wid + td->size_ow1;
2710 rc.right = rc.left + n * td->tile_wid;
2711 rc.top = y * td->tile_hgt + td->size_oh1;
2712 rc.bottom = rc.top + td->tile_hgt;
2715 SetBkColor(hdc, RGB(0, 0, 0));
2716 SelectObject(hdc, td->font_id);
2721 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2722 ReleaseDC(td->w, hdc);
2730 * Low level graphics. Assumes valid input.
2732 * Draw several ("n") chars, with an attr, at a given location.
2734 * All "graphic" data is handled by "Term_pict_win()", below.
2736 * One would think there is a more efficient method for telling a window
2737 * what color it should be using to draw with, but perhaps simply changing
2738 * it every time is not too inefficient. XXX XXX XXX
2740 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2742 term_data *td = (term_data*)(Term->data);
2746 #if 1 /* #ifdef JP */
2747 static HBITMAP WALL;
2748 static HBRUSH myBrush, oldBrush;
2750 static bool init_done = FALSE;
2753 WALL = LoadBitmap(hInstance, AppName);
2754 myBrush = CreatePatternBrush(WALL);
2759 /* Total rectangle */
2760 rc.left = x * td->tile_wid + td->size_ow1;
2761 rc.right = rc.left + n * td->tile_wid;
2762 rc.top = y * td->tile_hgt + td->size_oh1;
2763 rc.bottom = rc.top + td->tile_hgt;
2768 /* Background color */
2769 SetBkColor(hdc, RGB(0, 0, 0));
2771 /* Foreground color */
2774 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2778 SetTextColor(hdc, win_clr[a&0x0F]);
2782 SetTextColor(hdc, win_clr[a]);
2786 SelectObject(hdc, td->font_id);
2789 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2793 (td->tile_hgt != td->font_hgt) ||
2794 (td->tile_wid != td->font_wid))
2798 /* Erase complete rectangle */
2799 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2802 if (use_bg) DrawBG(hdc, &rc);
2805 rc.left += ((td->tile_wid - td->font_wid) / 2);
2806 rc.right = rc.left + td->font_wid;
2807 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2808 rc.bottom = rc.top + td->font_hgt;
2810 /* Dump each character */
2811 for (i = 0; i < n; i++)
2814 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2816 rc.right += td->font_wid;
2818 oldBrush = SelectObject(hdc, myBrush);
2819 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2822 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2824 SelectObject(hdc, oldBrush);
2825 SelectObject(hdc, oldPen);
2826 rc.right -= td->font_wid;
2830 rc.left += 2 * td->tile_wid;
2831 rc.right += 2 * td->tile_wid;
2833 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2835 rc.right += td->font_wid;
2837 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2839 rc.right -= td->font_wid;
2843 rc.left += 2 * td->tile_wid;
2844 rc.right += 2 * td->tile_wid;
2845 } else if (*(s+i)==127){
2846 oldBrush = SelectObject(hdc, myBrush);
2847 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2850 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2852 SelectObject(hdc, oldBrush);
2853 SelectObject(hdc, oldPen);
2856 rc.left += td->tile_wid;
2857 rc.right += td->tile_wid;
2860 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2863 rc.left += td->tile_wid;
2864 rc.right += td->tile_wid;
2869 oldBrush = SelectObject(hdc, myBrush);
2870 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2873 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2875 SelectObject(hdc, oldBrush);
2876 SelectObject(hdc, oldPen);
2879 rc.left += td->tile_wid;
2880 rc.right += td->tile_wid;
2883 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2887 rc.left += td->tile_wid;
2888 rc.right += td->tile_wid;
2892 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2896 rc.left += td->tile_wid;
2897 rc.right += td->tile_wid;
2908 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2913 ReleaseDC(td->w, hdc);
2921 * Low level graphics. Assumes valid input.
2923 * Draw an array of "special" attr/char pairs at the given location.
2925 * We use the "Term_pict_win()" function for "graphic" data, which are
2926 * encoded by setting the "high-bits" of both the "attr" and the "char"
2927 * data. We use the "attr" to represent the "row" of the main bitmap,
2928 * and the "char" to represent the "col" of the main bitmap. The use
2929 * of this function is induced by the "higher_pict" flag.
2931 * If "graphics" is not available, we simply "wipe" the given grids.
2933 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2935 term_data *td = (term_data*)(Term->data);
2941 int x2, y2, w2, h2, tw2;
2953 /* Erase the grids */
2954 return (Term_wipe_win(x, y, n));
2957 /* Size of bitmap cell */
2958 w1 = infGraph.CellWidth;
2959 h1 = infGraph.CellHeight;
2961 /* Size of window cell */
2964 w2 = td->map_tile_wid;
2965 h2 = td->map_tile_hgt;
2974 if (use_bigtile) tw2 *= 2;
2977 /* Location of window cell */
2978 x2 = x * w2 + td->size_ow1;
2979 y2 = y * h2 + td->size_oh1;
2985 hdcSrc = CreateCompatibleDC(hdc);
2986 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2988 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2990 hdcMask = CreateCompatibleDC(hdc);
2991 SelectObject(hdcMask, infMask.hBitmap);
2994 /* Draw attr/char pairs */
2995 for (i = 0; i < n; i++, x2 += w2)
3000 /* Extract picture */
3001 int row = (a & 0x7F);
3002 int col = (c & 0x7F);
3004 /* Location of bitmap cell */
3008 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3010 x3 = (tcp[i] & 0x7F) * w1;
3011 y3 = (tap[i] & 0x7F) * h1;
3014 if ((w1 == tw2) && (h1 == h2))
3016 /* Copy the terrain picture from the bitmap to the window */
3017 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
3019 /* Mask out the tile */
3020 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3023 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3026 /* Need to stretch */
3029 /* Set the correct mode for stretching the tiles */
3030 SetStretchBltMode(hdc, COLORONCOLOR);
3032 /* Copy the terrain picture from the bitmap to the window */
3033 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
3035 /* Only draw if terrain and overlay are different */
3036 if ((x1 != x3) || (y1 != y3))
3038 /* Mask out the tile */
3039 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3042 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3049 if ((w1 == tw2) && (h1 == h2))
3051 /* Copy the picture from the bitmap to the window */
3052 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3055 /* Need to stretch */
3058 /* Set the correct mode for stretching the tiles */
3059 SetStretchBltMode(hdc, COLORONCOLOR);
3061 /* Copy the picture from the bitmap to the window */
3062 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3068 SelectObject(hdcSrc, hbmSrcOld);
3071 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3074 SelectObject(hdcMask, hbmSrcOld);
3079 ReleaseDC(td->w, hdc);
3081 #else /* USE_GRAPHICS */
3083 /* Just erase this grid */
3084 return (Term_wipe_win(x, y, n));
3086 #endif /* USE_GRAPHICS */
3093 static void windows_map(void)
3095 term_data *td = &data[0];
3097 int x, min_x, max_x;
3098 int y, min_y, max_y;
3102 /* Only in graphics mode */
3103 if (!use_graphics) return;
3106 Term_xtra_win_clear();
3108 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3109 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3110 td->map_active = TRUE;
3120 for (x = min_x; x < max_x; x++)
3122 for (y = min_y; y < max_y; y++)
3124 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3126 /* Ignore non-graphics */
3127 if ((a & 0x80) && (c & 0x80))
3129 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3134 /* Hilite the player */
3135 Term_curs_win(px - min_x, py - min_y);
3137 /* Wait for a keypress, flush key buffer */
3138 Term_inkey(&c, TRUE, TRUE);
3141 /* Switch off the map display */
3142 td->map_active = FALSE;
3144 /* Restore screen */
3145 Term_xtra_win_clear();
3150 /*** Other routines ***/
3154 * Create and initialize a "term_data" given a title
3156 static void term_data_link(term_data *td)
3160 /* Initialize the term */
3161 term_init(t, td->cols, td->rows, td->keys);
3163 /* Use a "software" cursor */
3164 t->soft_cursor = TRUE;
3166 /* Use "Term_pict" for "graphic" data */
3167 t->higher_pict = TRUE;
3169 /* Erase with "white space" */
3170 t->attr_blank = TERM_WHITE;
3171 t->char_blank = ' ';
3174 /* Prepare the init/nuke hooks */
3175 t->init_hook = Term_init_win;
3176 t->nuke_hook = Term_nuke_win;
3179 /* Prepare the template hooks */
3180 t->user_hook = Term_user_win;
3181 t->xtra_hook = Term_xtra_win;
3182 t->curs_hook = Term_curs_win;
3183 t->bigcurs_hook = Term_bigcurs_win;
3184 t->wipe_hook = Term_wipe_win;
3185 t->text_hook = Term_text_win;
3186 t->pict_hook = Term_pict_win;
3188 /* Remember where we came from */
3189 t->data = (vptr)(td);
3194 * Create the windows
3196 * First, instantiate the "default" values, then read the "ini_file"
3197 * to over-ride selected values, then create the windows, and fonts.
3199 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3200 * must make active to realize the palette. XXX XXX XXX
3202 static void init_windows(void)
3208 #if 0 /* #ifndef JP */
3214 WIPE(td, term_data);
3218 td->s = angband_term_name[0];
3232 #if 1 /* #ifdef JP */
3236 for (i = 1; i < MAX_TERM_DATA; i++)
3239 WIPE(td, term_data);
3240 td->s = angband_term_name[i];
3244 td->visible = FALSE;
3249 td->pos_x = (7 - i) * 30;
3250 td->pos_y = (7 - i) * 20;
3252 #if 1 /* #ifdef JP */
3262 /* Main window (need these before term_getsize gets called) */
3264 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3265 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3270 /* Sub windows (need these before term_getsize gets called) */
3271 for (i = 1; i < MAX_TERM_DATA; i++)
3274 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3275 td->dwExStyle = (WS_EX_TOOLWINDOW);
3280 for (i = 0; i < MAX_TERM_DATA; i++)
3284 #if 1 /* #ifdef JP */
3285 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3286 td->lf.lfCharSet = DEFAULT_CHARSET;
3287 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3288 /* Activate the chosen font */
3289 term_force_font(td, NULL);
3290 td->tile_wid = td->font_wid;
3291 td->tile_hgt = td->font_hgt;
3293 /* Access the standard font file */
3294 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3296 /* Activate the chosen font */
3297 if (term_force_font(td, buf))
3299 /* Access the standard font file */
3300 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3302 /* Force the use of that font */
3303 (void)term_force_font(td, buf);
3309 /* Assume not bizarre */
3310 td->bizarre = FALSE;
3315 /* Analyze the font */
3318 /* Resize the window */
3319 term_window_resize(td);
3323 /* Sub windows (reverse order) */
3324 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3329 td->w = CreateWindowEx(td->dwExStyle, AngList,
3331 td->pos_x, td->pos_y,
3332 td->size_wid, td->size_hgt,
3333 HWND_DESKTOP, NULL, hInstance, NULL);
3336 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3338 if (!td->w) quit("Failed to create sub-window");
3344 td->size_hack = TRUE;
3345 ShowWindow(td->w, SW_SHOW);
3346 td->size_hack = FALSE;
3350 angband_term[i] = &td->t;
3354 /* Activate the window */
3355 SetActiveWindow(td->w);
3360 term_window_pos(&data[i], HWND_TOPMOST);
3364 term_window_pos(&data[i], td->w);
3374 td->w = CreateWindowEx(td->dwExStyle, AppName,
3376 td->pos_x, td->pos_y,
3377 td->size_wid, td->size_hgt,
3378 HWND_DESKTOP, NULL, hInstance, NULL);
3381 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3383 if (!td->w) quit("Failed to create Angband window");
3388 angband_term[0] = &td->t;
3389 normsize.x = td->cols;
3390 normsize.y = td->rows;
3392 /* Activate the main window */
3393 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3394 else ShowWindow(td->w, SW_SHOW);
3396 /* Bring main window back to top */
3397 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3400 /* New palette XXX XXX XXX */
3401 (void)new_palette();
3404 /* Create a "brush" for drawing the "cursor" */
3405 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3408 /* Process pending messages */
3409 (void)Term_xtra_win_flush();
3417 static void setup_menus(void)
3421 HMENU hm = GetMenu(data[0].w);
3424 /* Menu "File", Disable all */
3425 EnableMenuItem(hm, IDM_FILE_NEW,
3426 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3427 EnableMenuItem(hm, IDM_FILE_OPEN,
3428 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3429 EnableMenuItem(hm, IDM_FILE_SAVE,
3430 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3431 EnableMenuItem(hm, IDM_FILE_EXIT,
3432 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3433 EnableMenuItem(hm, IDM_FILE_SCORE,
3434 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3437 /* No character available */
3438 if (!character_generated)
3440 /* Menu "File", Item "New" */
3441 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3443 /* Menu "File", Item "Open" */
3444 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3447 /* A character available */
3448 if (character_generated)
3450 /* Menu "File", Item "Save" */
3451 EnableMenuItem(hm, IDM_FILE_SAVE,
3452 MF_BYCOMMAND | MF_ENABLED);
3455 /* Menu "File", Item "Exit" */
3456 EnableMenuItem(hm, IDM_FILE_EXIT,
3457 MF_BYCOMMAND | MF_ENABLED);
3459 EnableMenuItem(hm, IDM_FILE_SCORE,
3460 MF_BYCOMMAND | MF_ENABLED);
3463 /* Menu "Window::Visibility" */
3464 for (i = 0; i < MAX_TERM_DATA; i++)
3466 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3467 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3469 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3470 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3472 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3473 MF_BYCOMMAND | MF_ENABLED);
3476 /* Menu "Window::Font" */
3477 for (i = 0; i < MAX_TERM_DATA; i++)
3479 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3480 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3482 if (data[i].visible)
3484 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3485 MF_BYCOMMAND | MF_ENABLED);
3489 /* Menu "Window::Window Position Fix" */
3490 for (i = 0; i < MAX_TERM_DATA; i++)
3492 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3493 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3495 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3496 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3498 if (data[i].visible)
3500 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3501 MF_BYCOMMAND | MF_ENABLED);
3505 /* Menu "Window::Bizarre Display" */
3506 for (i = 0; i < MAX_TERM_DATA; i++)
3508 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3509 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3511 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3512 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3514 if (data[i].visible)
3516 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3517 MF_BYCOMMAND | MF_ENABLED);
3522 /* Menu "Window::Increase Tile Width" */
3523 for (i = 0; i < MAX_TERM_DATA; i++)
3525 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3526 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3528 if (data[i].visible)
3530 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3531 MF_BYCOMMAND | MF_ENABLED);
3536 /* Menu "Window::Decrease Tile Width" */
3537 for (i = 0; i < MAX_TERM_DATA; i++)
3539 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3540 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3542 if (data[i].visible)
3544 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3545 MF_BYCOMMAND | MF_ENABLED);
3550 /* Menu "Window::Increase Tile Height" */
3551 for (i = 0; i < MAX_TERM_DATA; i++)
3553 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3554 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3556 if (data[i].visible)
3558 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3559 MF_BYCOMMAND | MF_ENABLED);
3564 /* Menu "Window::Decrease Tile Height" */
3565 for (i = 0; i < MAX_TERM_DATA; i++)
3567 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3568 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3570 if (data[i].visible)
3572 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3573 MF_BYCOMMAND | MF_ENABLED);
3578 /* Menu "Options", disable all */
3579 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3580 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3581 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3582 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3583 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3584 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3585 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3586 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3587 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3588 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3590 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3591 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3594 /* Menu "Options", Item "Map" */
3595 if (use_graphics != GRAPHICS_NONE)
3596 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3598 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3599 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3601 /* Menu "Options", update all */
3602 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3603 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3604 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3605 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3606 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3607 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3608 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3609 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3610 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3611 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3612 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3613 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3614 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3615 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3616 CheckMenuItem(hm, IDM_OPTIONS_BG,
3617 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3619 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3620 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3624 /* Menu "Options", Item "Graphics" */
3625 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3626 /* Menu "Options", Item "Graphics" */
3627 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3628 /* Menu "Options", Item "Graphics" */
3629 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3630 /* Menu "Options", Item "Graphics" */
3631 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3632 #endif /* USE_GRAPHICS */
3635 /* Menu "Options", Item "Sound" */
3636 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3637 #endif /* USE_SOUND */
3640 /* Menu "Options", Item "ScreenSaver" */
3641 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3642 MF_BYCOMMAND | MF_ENABLED);
3643 #endif /* USE_SAVER */
3648 * Check for double clicked (or dragged) savefile
3650 * Apparently, Windows copies the entire filename into the first
3651 * piece of the "command line string". Perhaps we should extract
3652 * the "basename" of that filename and append it to the "save" dir.
3654 static void check_for_save_file(LPSTR cmd_line)
3664 /* Extract filename */
3665 strcat(savefile, s);
3667 /* Validate the file */
3668 validate_file(savefile);
3670 /* Game in progress */
3671 game_in_progress = TRUE;
3679 * Process a menu command
3681 static void process_menus(WORD wCmd)
3698 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3700 plog("You cannot do that yet...");
3704 else if (game_in_progress)
3707 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3709 plog("You can't start a new game while you're still playing!");
3715 game_in_progress = TRUE;
3729 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3731 plog("You cannot do that yet...");
3735 else if (game_in_progress)
3738 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3740 plog("You can't open a new game while you're still playing!");
3746 memset(&ofn, 0, sizeof(ofn));
3747 ofn.lStructSize = sizeof(ofn);
3748 ofn.hwndOwner = data[0].w;
3749 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3750 ofn.nFilterIndex = 1;
3751 ofn.lpstrFile = savefile;
3752 ofn.nMaxFile = 1024;
3753 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3754 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3756 if (GetOpenFileName(&ofn))
3758 /* Load 'savefile' */
3759 validate_file(savefile);
3760 game_in_progress = TRUE;
3772 if (game_in_progress && character_generated)
3778 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3780 plog("You may not do that right now.");
3786 /* Hack -- Forget messages */
3791 do_cmd_save_game(FALSE);
3792 #else /* ZANGBAND */
3794 #endif /* ZANGBAND */
3799 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3801 plog("You may not do that right now.");
3811 if (game_in_progress && character_generated)
3817 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3819 plog("You may not do that right now.");
3825 /* Hack -- Forget messages */
3834 /* do_cmd_save_game(FALSE); */
3835 #else /* ZANGBAND */
3836 /* do_cmd_save_game(); */
3837 #endif /* ZANGBAND */
3838 Term_key_push(SPECIAL_KEY_QUIT);
3846 case IDM_FILE_SCORE:
3850 /* Build the filename */
3851 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3853 /* Open the binary high score file, for reading */
3854 highscore_fd = fd_open(buf, O_RDONLY);
3856 /* Paranoia -- No score file */
3857 if (highscore_fd < 0)
3859 msg_print("Score file unavailable.");
3869 /* Display the scores */
3870 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3872 /* Shut the high score file */
3873 (void)fd_close(highscore_fd);
3875 /* Forget the high score fd */
3881 /* Hack - Flush it */
3889 case IDM_FILE_MOVIE:
3894 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3896 plog("You cannot do that yet...");
3899 else if (game_in_progress)
3902 plog("¥×¥ì¥¤Ãæ¤Ï¥à¡¼¥Ó¡¼¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3904 plog("You can't open a movie while you're playing!");
3909 memset(&ofn, 0, sizeof(ofn));
3910 ofn.lStructSize = sizeof(ofn);
3911 ofn.hwndOwner = data[0].w;
3912 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3913 ofn.nFilterIndex = 1;
3914 ofn.lpstrFile = savefile;
3915 ofn.nMaxFile = 1024;
3916 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3917 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3919 if (GetOpenFileName(&ofn))
3921 /* Load 'savefile' */
3922 prepare_browse_movie_aux(savefile);
3932 case IDM_WINDOW_VIS_0:
3935 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3937 plog("You are not allowed to do that!");
3944 /* Window visibility */
3945 case IDM_WINDOW_VIS_1:
3946 case IDM_WINDOW_VIS_2:
3947 case IDM_WINDOW_VIS_3:
3948 case IDM_WINDOW_VIS_4:
3949 case IDM_WINDOW_VIS_5:
3950 case IDM_WINDOW_VIS_6:
3951 case IDM_WINDOW_VIS_7:
3953 i = wCmd - IDM_WINDOW_VIS_0;
3955 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3962 ShowWindow(td->w, SW_SHOW);
3963 term_data_redraw(td);
3967 td->visible = FALSE;
3969 ShowWindow(td->w, SW_HIDE);
3976 case IDM_WINDOW_FONT_0:
3977 case IDM_WINDOW_FONT_1:
3978 case IDM_WINDOW_FONT_2:
3979 case IDM_WINDOW_FONT_3:
3980 case IDM_WINDOW_FONT_4:
3981 case IDM_WINDOW_FONT_5:
3982 case IDM_WINDOW_FONT_6:
3983 case IDM_WINDOW_FONT_7:
3985 i = wCmd - IDM_WINDOW_FONT_0;
3987 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3991 term_change_font(td);
3996 /* Window Z Position */
3997 case IDM_WINDOW_POS_1:
3998 case IDM_WINDOW_POS_2:
3999 case IDM_WINDOW_POS_3:
4000 case IDM_WINDOW_POS_4:
4001 case IDM_WINDOW_POS_5:
4002 case IDM_WINDOW_POS_6:
4003 case IDM_WINDOW_POS_7:
4005 i = wCmd - IDM_WINDOW_POS_0;
4007 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4011 if (!td->posfix && td->visible)
4014 term_window_pos(td, HWND_TOPMOST);
4019 term_window_pos(td, data[0].w);
4025 /* Bizarre Display */
4026 case IDM_WINDOW_BIZ_0:
4027 case IDM_WINDOW_BIZ_1:
4028 case IDM_WINDOW_BIZ_2:
4029 case IDM_WINDOW_BIZ_3:
4030 case IDM_WINDOW_BIZ_4:
4031 case IDM_WINDOW_BIZ_5:
4032 case IDM_WINDOW_BIZ_6:
4033 case IDM_WINDOW_BIZ_7:
4035 i = wCmd - IDM_WINDOW_BIZ_0;
4037 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4041 td->bizarre = !td->bizarre;
4045 term_window_resize(td);
4050 /* Increase Tile Width */
4051 case IDM_WINDOW_I_WID_0:
4052 case IDM_WINDOW_I_WID_1:
4053 case IDM_WINDOW_I_WID_2:
4054 case IDM_WINDOW_I_WID_3:
4055 case IDM_WINDOW_I_WID_4:
4056 case IDM_WINDOW_I_WID_5:
4057 case IDM_WINDOW_I_WID_6:
4058 case IDM_WINDOW_I_WID_7:
4060 i = wCmd - IDM_WINDOW_I_WID_0;
4062 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4070 term_window_resize(td);
4075 /* Decrease Tile Height */
4076 case IDM_WINDOW_D_WID_0:
4077 case IDM_WINDOW_D_WID_1:
4078 case IDM_WINDOW_D_WID_2:
4079 case IDM_WINDOW_D_WID_3:
4080 case IDM_WINDOW_D_WID_4:
4081 case IDM_WINDOW_D_WID_5:
4082 case IDM_WINDOW_D_WID_6:
4083 case IDM_WINDOW_D_WID_7:
4085 i = wCmd - IDM_WINDOW_D_WID_0;
4087 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4095 term_window_resize(td);
4100 /* Increase Tile Height */
4101 case IDM_WINDOW_I_HGT_0:
4102 case IDM_WINDOW_I_HGT_1:
4103 case IDM_WINDOW_I_HGT_2:
4104 case IDM_WINDOW_I_HGT_3:
4105 case IDM_WINDOW_I_HGT_4:
4106 case IDM_WINDOW_I_HGT_5:
4107 case IDM_WINDOW_I_HGT_6:
4108 case IDM_WINDOW_I_HGT_7:
4110 i = wCmd - IDM_WINDOW_I_HGT_0;
4112 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4120 term_window_resize(td);
4125 /* Decrease Tile Height */
4126 case IDM_WINDOW_D_HGT_0:
4127 case IDM_WINDOW_D_HGT_1:
4128 case IDM_WINDOW_D_HGT_2:
4129 case IDM_WINDOW_D_HGT_3:
4130 case IDM_WINDOW_D_HGT_4:
4131 case IDM_WINDOW_D_HGT_5:
4132 case IDM_WINDOW_D_HGT_6:
4133 case IDM_WINDOW_D_HGT_7:
4135 i = wCmd - IDM_WINDOW_D_HGT_0;
4137 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4145 term_window_resize(td);
4150 case IDM_OPTIONS_NO_GRAPHICS:
4155 plog("You may not do that right now.");
4159 /* Toggle "arg_graphics" */
4160 if (arg_graphics != GRAPHICS_NONE)
4162 arg_graphics = GRAPHICS_NONE;
4164 /* React to changes */
4165 Term_xtra_win_react();
4167 /* Hack -- Force redraw */
4168 Term_key_push(KTRL('R'));
4174 case IDM_OPTIONS_OLD_GRAPHICS:
4179 plog("You may not do that right now.");
4183 /* Toggle "arg_graphics" */
4184 if (arg_graphics != GRAPHICS_ORIGINAL)
4186 arg_graphics = GRAPHICS_ORIGINAL;
4188 /* React to changes */
4189 Term_xtra_win_react();
4191 /* Hack -- Force redraw */
4192 Term_key_push(KTRL('R'));
4198 case IDM_OPTIONS_NEW_GRAPHICS:
4203 plog("You may not do that right now.");
4207 /* Toggle "arg_graphics" */
4208 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4210 arg_graphics = GRAPHICS_ADAM_BOLT;
4212 /* React to changes */
4213 Term_xtra_win_react();
4215 /* Hack -- Force redraw */
4216 Term_key_push(KTRL('R'));
4222 case IDM_OPTIONS_NEW2_GRAPHICS:
4227 plog("You may not do that right now.");
4231 /* Toggle "arg_graphics" */
4232 if (arg_graphics != GRAPHICS_HENGBAND)
4234 arg_graphics = GRAPHICS_HENGBAND;
4236 /* React to changes */
4237 Term_xtra_win_react();
4239 /* Hack -- Force redraw */
4240 Term_key_push(KTRL('R'));
4246 case IDM_OPTIONS_BIGTILE:
4248 term_data *td = &data[0];
4253 plog("You may not do that right now.");
4257 /* Toggle "arg_sound" */
4258 arg_bigtile = !arg_bigtile;
4261 Term_activate(&td->t);
4263 /* Resize the term */
4264 Term_resize(td->cols, td->rows);
4267 InvalidateRect(td->w, NULL, TRUE);
4272 case IDM_OPTIONS_MUSIC:
4277 plog("You may not do that right now.");
4281 /* Toggle "arg_sound" */
4282 arg_music = !arg_music;
4284 /* React to changes */
4285 Term_xtra_win_react();
4287 /* Hack -- Force redraw */
4288 Term_key_push(KTRL('R'));
4293 case IDM_OPTIONS_SOUND:
4298 plog("You may not do that right now.");
4302 /* Toggle "arg_sound" */
4303 arg_sound = !arg_sound;
4305 /* React to changes */
4306 Term_xtra_win_react();
4308 /* Hack -- Force redraw */
4309 Term_key_push(KTRL('R'));
4315 case IDM_OPTIONS_BG:
4320 plog("You may not do that right now.");
4324 /* Toggle "use_bg" */
4329 /* React to changes */
4330 Term_xtra_win_react();
4332 /* Hack -- Force redraw */
4333 Term_key_push(KTRL('R'));
4339 case IDM_OPTIONS_OPEN_BG:
4344 plog("You may not do that right now.");
4349 memset(&ofn, 0, sizeof(ofn));
4350 ofn.lStructSize = sizeof(ofn);
4351 ofn.hwndOwner = data[0].w;
4352 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4353 ofn.nFilterIndex = 1;
4354 ofn.lpstrFile = bg_bitmap_file;
4355 ofn.nMaxFile = 1023;
4356 ofn.lpstrInitialDir = NULL;
4358 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
4360 ofn.lpstrTitle = "Choose wall paper.";
4362 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4364 if (GetOpenFileName(&ofn))
4366 /* Load 'savefile' */
4371 /* React to changes */
4372 Term_xtra_win_react();
4374 /* Hack -- Force redraw */
4375 Term_key_push(KTRL('R'));
4380 case IDM_DUMP_SCREEN_HTML:
4382 static char buf[1024] = "";
4383 memset(&ofn, 0, sizeof(ofn));
4384 ofn.lStructSize = sizeof(ofn);
4385 ofn.hwndOwner = data[0].w;
4386 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4387 ofn.nFilterIndex = 1;
4388 ofn.lpstrFile = buf;
4389 ofn.nMaxFile = 1023;
4390 ofn.lpstrDefExt = "html";
4391 ofn.lpstrInitialDir = NULL;
4393 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
4395 ofn.lpstrTitle = "Save screen dump as HTML.";
4397 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4399 if (GetSaveFileName(&ofn))
4401 do_cmd_save_screen_html_aux(buf, 0);
4408 case IDM_OPTIONS_SAVER:
4412 DestroyWindow(hwndSaver);
4417 /* Create a screen scaver window */
4418 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4419 "Angband Screensaver",
4420 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4421 0, 0, GetSystemMetrics(SM_CXSCREEN),
4422 GetSystemMetrics(SM_CYSCREEN),
4423 NULL, NULL, hInstance, NULL);
4427 /* Push the window to the bottom XXX XXX XXX */
4428 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4433 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
4435 plog("Failed to create saver window");
4445 case IDM_OPTIONS_MAP:
4451 case IDM_HELP_CONTENTS:
4455 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4456 if (check_file(tmp))
4458 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4463 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4464 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4466 plog_fmt("Cannot find help file: %s", tmp);
4467 plog("Use the online help files instead.");
4472 #else /* HTML_HELP */
4475 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4476 if (check_file(tmp))
4478 sprintf(buf, "winhelp.exe %s", tmp);
4479 WinExec(buf, SW_NORMAL);
4484 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4485 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4487 plog_fmt("Cannot find help file: %s", tmp);
4488 plog("Use the online help files instead.");
4493 #endif /* HTML_HELP */
4499 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4506 /* Extract the modifiers */
4507 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4508 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4509 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4511 Term_no_press = (ma) ? TRUE : FALSE;
4513 /* Handle "special" keys */
4514 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4516 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4517 bool numpad = FALSE;
4519 /* Begin the macro trigger */
4522 /* Send the modifiers */
4523 if (mc) Term_keypress('C');
4524 if (ms) Term_keypress('S');
4525 if (ma) Term_keypress('A');
4527 /* Extract "scan code" */
4528 i = LOBYTE(HIWORD(lParam));
4530 /* Introduce the scan code */
4533 /* Extended key bit */
4536 /* Numpad Enter and '/' are extended key */
4538 Term_no_press = TRUE;
4539 case VK_RETURN: /* Enter */
4542 /* Other extended keys are on full keyboard */
4558 Term_no_press = TRUE;
4562 case VK_PRIOR: /* Page Up */
4563 case VK_NEXT: /* Page Down */
4573 /* Special modifiers for keypad keys */
4574 if (numpad) Term_keypress('K');
4576 /* Encode the hexidecimal scan code */
4577 Term_keypress(hexsym[i/16]);
4578 Term_keypress(hexsym[i%16]);
4580 /* End the macro trigger */
4591 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4592 WPARAM wParam, LPARAM lParam);
4593 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4594 WPARAM wParam, LPARAM lParam)
4595 #else /* __MWERKS__ */
4596 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4597 WPARAM wParam, LPARAM lParam)
4598 #endif /* __MWERKS__ */
4604 MINMAXINFO FAR *lpmmi;
4610 /* Acquire proper "term_data" info */
4611 td = (term_data *)GetWindowLong(hWnd, 0);
4613 /* Handle message */
4619 SetWindowLong(hWnd, 0, (LONG)(my_td));
4626 mop.dwCallback=(DWORD)hWnd;
4630 case WM_GETMINMAXINFO:
4632 MINMAXINFO FAR *lpmmi;
4635 lpmmi = (MINMAXINFO FAR *)lParam;
4637 /* this message was sent before WM_NCCREATE */
4640 /* Minimum window size is 80x24 */
4641 rc.left = rc.top = 0;
4642 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4643 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4646 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4648 /* Save minimum size */
4649 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4650 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4657 BeginPaint(hWnd, &ps);
4658 if (td) term_data_redraw(td);
4659 EndPaint(hWnd, &ps);
4660 ValidateRect(hWnd, NULL);
4667 if(wParam == MCI_NOTIFY_SUCCESSFUL)
4669 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4670 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4679 if (process_keydown(wParam, lParam))
4686 if (Term_no_press) Term_no_press = FALSE;
4687 else Term_keypress(wParam);
4691 case WM_LBUTTONDOWN:
4693 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4694 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4706 int dx = abs(oldx - mousex) + 1;
4707 int dy = abs(oldy - mousey) + 1;
4708 int ox = (oldx > mousex) ? mousex : oldx;
4709 int oy = (oldy > mousey) ? mousey : oldy;
4719 hGlobal = GlobalAlloc(GHND, sz + 1);
4720 if (hGlobal == NULL) return 0;
4721 lpStr = (LPSTR)GlobalLock(hGlobal);
4723 for (i = 0; i < dy; i++)
4727 char **scr = data[0].t.scr->c;
4729 C_MAKE(s, (dx + 1), char);
4730 strncpy(s, &scr[oy + i][ox], dx);
4734 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4737 if (ox + dx < data[0].cols)
4739 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4742 for (j = 0; j < dx; j++)
4744 if (s[j] == 127) s[j] = '#';
4748 for (j = 0; j < dx; j++)
4750 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4760 GlobalUnlock(hGlobal);
4761 if (OpenClipboard(hWnd) == 0)
4763 GlobalFree(hGlobal);
4767 SetClipboardData(CF_TEXT, hGlobal);
4780 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4781 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4786 dx = abs(oldx - mousex) + 1;
4787 dy = abs(oldy - mousey) + 1;
4788 ox = (oldx > mousex) ? mousex : oldx;
4789 oy = (oldy > mousey) ? mousey : oldy;
4790 Term_inversed_area(hWnd, ox, oy, dx, dy);
4797 dx = abs(cx - mousex) + 1;
4798 dy = abs(cy - mousey) + 1;
4799 ox = (cx > mousex) ? mousex : cx;
4800 oy = (cy > mousey) ? mousey : cy;
4801 Term_inversed_area(hWnd, ox, oy, dx, dy);
4817 if (game_in_progress && character_generated)
4822 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4824 plog("You may not do that right now.");
4829 /* Hack -- Forget messages */
4838 /* do_cmd_save_game(FALSE); */
4839 #else /* ZANGBAND */
4840 /* do_cmd_save_game(); */
4841 #endif /* ZANGBAND */
4842 Term_key_push(SPECIAL_KEY_QUIT);
4849 case WM_QUERYENDSESSION:
4851 if (game_in_progress && character_generated)
4853 /* Hack -- Forget messages */
4856 /* Mega-Hack -- Delay death */
4857 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4860 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "----¥²¡¼¥àÃæÃÇ----");
4862 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "---- Save and Exit Game ----");
4865 /* Hardcode panic save */
4866 p_ptr->panic_save = 1;
4868 /* Forbid suspend */
4869 signals_ignore_tstp();
4871 /* Indicate panic save */
4873 (void)strcpy(p_ptr->died_from, "(¶ÛµÞ¥»¡¼¥Ö)");
4875 (void)strcpy(p_ptr->died_from, "(panic save)");
4879 (void)save_player();
4893 process_menus(LOWORD(wParam));
4899 /* this message was sent before WM_NCCREATE */
4902 /* it was sent from inside CreateWindowEx */
4903 if (!td->w) return 1;
4905 /* was sent from WM_SIZE */
4906 if (td->size_hack) return 1;
4910 case SIZE_MINIMIZED:
4912 /* Hide sub-windows */
4913 for (i = 1; i < MAX_TERM_DATA; i++)
4915 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4920 case SIZE_MAXIMIZED:
4922 /* fall through XXX XXX XXX */
4927 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4928 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4931 if ((td->cols != cols) || (td->rows != rows))
4933 /* Save the new size */
4937 if (!IsZoomed(td->w) && !IsIconic(td->w))
4939 normsize.x = td->cols;
4940 normsize.y = td->rows;
4944 Term_activate(&td->t);
4946 /* Resize the term */
4947 Term_resize(td->cols, td->rows);
4950 InvalidateRect(td->w, NULL, TRUE);
4953 td->size_hack = TRUE;
4955 /* Show sub-windows */
4956 for (i = 1; i < MAX_TERM_DATA; i++)
4958 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4961 td->size_hack = FALSE;
4969 case WM_PALETTECHANGED:
4971 /* Ignore if palette change caused by itself */
4972 if ((HWND)wParam == hWnd) return 0;
4974 /* Fall through... */
4977 case WM_QUERYNEWPALETTE:
4979 if (!paletted) return 0;
4983 SelectPalette(hdc, hPal, FALSE);
4985 i = RealizePalette(hdc);
4987 /* if any palette entries changed, repaint the window. */
4988 if (i) InvalidateRect(hWnd, NULL, TRUE);
4990 ReleaseDC(hWnd, hdc);
4997 if (wParam && !HIWORD(lParam))
4999 /* Do something to sub-windows */
5000 for (i = 1; i < MAX_TERM_DATA; i++)
5002 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
5005 /* Focus on main window */
5014 case WM_ACTIVATEAPP:
5016 if (IsIconic(td->w)) break;
5018 for (i = 1; i < MAX_TERM_DATA; i++)
5024 ShowWindow(data[i].w, SW_SHOW);
5028 ShowWindow(data[i].w, SW_HIDE);
5035 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5040 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5041 WPARAM wParam, LPARAM lParam);
5042 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5043 WPARAM wParam, LPARAM lParam)
5044 #else /* __MWERKS__ */
5045 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5046 WPARAM wParam, LPARAM lParam)
5047 #endif /* __MWERKS__ */
5051 MINMAXINFO FAR *lpmmi;
5059 /* Acquire proper "term_data" info */
5060 td = (term_data *)GetWindowLong(hWnd, 0);
5062 /* Process message */
5068 SetWindowLong(hWnd, 0, (LONG)(my_td));
5078 case WM_GETMINMAXINFO:
5080 MINMAXINFO FAR *lpmmi;
5083 lpmmi = (MINMAXINFO FAR *)lParam;
5085 /* this message was sent before WM_NCCREATE */
5088 /* Minimum window size is 80x24 */
5089 rc.left = rc.top = 0;
5090 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5091 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5094 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5096 /* Save minimum size */
5097 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5098 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5108 /* this message was sent before WM_NCCREATE */
5111 /* it was sent from inside CreateWindowEx */
5112 if (!td->w) return 1;
5114 /* was sent from inside WM_SIZE */
5115 if (td->size_hack) return 1;
5117 td->size_hack = TRUE;
5119 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5120 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5123 if ((td->cols != cols) || (td->rows != rows))
5126 term *old_term = Term;
5128 /* Save the new size */
5133 Term_activate(&td->t);
5135 /* Resize the term */
5136 Term_resize(td->cols, td->rows);
5139 Term_activate(old_term);
5142 InvalidateRect(td->w, NULL, TRUE);
5144 /* HACK - Redraw all windows */
5145 p_ptr->window = 0xFFFFFFFF;
5149 td->size_hack = FALSE;
5156 BeginPaint(hWnd, &ps);
5157 if (td) term_data_redraw(td);
5158 EndPaint(hWnd, &ps);
5165 if (process_keydown(wParam, lParam))
5172 if (Term_no_press) Term_no_press = FALSE;
5173 else Term_keypress(wParam);
5177 case WM_PALETTECHANGED:
5179 /* ignore if palette change caused by itself */
5180 if ((HWND)wParam == hWnd) return FALSE;
5181 /* otherwise, fall through!!! */
5184 case WM_QUERYNEWPALETTE:
5186 if (!paletted) return 0;
5188 SelectPalette(hdc, hPal, FALSE);
5189 i = RealizePalette(hdc);
5190 /* if any palette entries changed, repaint the window. */
5191 if (i) InvalidateRect(hWnd, NULL, TRUE);
5192 ReleaseDC(hWnd, hdc);
5196 case WM_NCLBUTTONDOWN:
5200 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5201 #endif /* HTCLOSE */
5203 if (wParam == HTSYSMENU)
5207 td->visible = FALSE;
5208 ShowWindow(td->w, SW_HIDE);
5218 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5224 #define MOUSE_SENS 40
5227 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5228 WPARAM wParam, LPARAM lParam);
5229 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5230 WPARAM wParam, LPARAM lParam)
5231 #else /* __MWERKS__ */
5232 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5233 WPARAM wParam, LPARAM lParam)
5234 #endif /* __MWERKS__ */
5236 static int iMouse = 0;
5237 static WORD xMouse = 0;
5238 static WORD yMouse = 0;
5261 if (LOWORD(wParam) == WA_INACTIVE) break;
5263 /* else fall through */
5267 case WM_LBUTTONDOWN:
5268 case WM_MBUTTONDOWN:
5269 case WM_RBUTTONDOWN:
5272 SendMessage(hWnd, WM_CLOSE, 0, 0);
5280 dx = LOWORD(lParam) - xMouse;
5281 dy = HIWORD(lParam) - yMouse;
5283 if (dx < 0) dx = -dx;
5284 if (dy < 0) dy = -dy;
5286 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5288 SendMessage(hWnd, WM_CLOSE, 0, 0);
5292 /* Save last location */
5294 xMouse = LOWORD(lParam);
5295 yMouse = HIWORD(lParam);
5302 DestroyWindow(hwndSaver);
5309 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5312 #endif /* USE_SAVER */
5318 /*** Temporary Hooks ***/
5322 * Display warning message (see "z-util.c")
5324 static void hack_plog(cptr str)
5326 /* Give a warning */
5330 MessageBox(NULL, str, "·Ù¹ð¡ª",
5331 MB_ICONEXCLAMATION | MB_OK);
5333 MessageBox(NULL, str, "Warning",
5334 MB_ICONEXCLAMATION | MB_OK);
5342 * Display error message and quit (see "z-util.c")
5344 static void hack_quit(cptr str)
5346 /* Give a warning */
5350 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
5351 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5353 MessageBox(NULL, str, "Error",
5354 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5359 /* Unregister the classes */
5360 UnregisterClass(AppName, hInstance);
5362 /* Destroy the icon */
5363 if (hIcon) DestroyIcon(hIcon);
5371 /*** Various hooks ***/
5375 * Display warning message (see "z-util.c")
5377 static void hook_plog(cptr str)
5383 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
5384 MB_ICONEXCLAMATION | MB_OK);
5386 MessageBox(data[0].w, str, "Warning",
5387 MB_ICONEXCLAMATION | MB_OK);
5395 * Display error message and quit (see "z-util.c")
5397 static void hook_quit(cptr str)
5402 /* Give a warning */
5406 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
5407 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5409 MessageBox(data[0].w, str, "Error",
5410 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5416 /* Save the preferences */
5420 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
5422 /* Destroy all windows */
5423 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5425 term_force_font(&data[i], NULL);
5426 if (data[i].font_want) string_free(data[i].font_want);
5427 if (data[i].w) DestroyWindow(data[i].w);
5431 /* Free the bitmap stuff */
5433 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5434 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5436 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5437 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5439 #endif /* USE_GRAPHICS */
5441 /*** Free some other stuff ***/
5443 DeleteObject(hbrYellow);
5448 if (hPal) DeleteObject(hPal);
5450 UnregisterClass(AppName, hInstance);
5452 if (hIcon) DestroyIcon(hIcon);
5459 /*** Initialize ***/
5465 static void init_stuff(void)
5472 /* Get program name with full path */
5473 GetModuleFileName(hInstance, path, 512);
5475 /* Save the "program name" XXX XXX XXX */
5478 /* Get the name of the "*.ini" file */
5479 strcpy(path + strlen(path) - 4, ".INI");
5481 /* Save the the name of the ini-file */
5482 ini_file = string_make(path);
5484 /* Analyze the path */
5490 if (path[i] == '\\')
5497 /* Add "lib" to the path */
5498 strcpy(path + i + 1, "lib\\");
5500 /* Validate the path */
5501 validate_dir(path, TRUE);
5503 /* Init the file paths */
5504 init_file_paths(path);
5506 /* Hack -- Validate the paths */
5507 validate_dir(ANGBAND_DIR_APEX, FALSE);
5508 validate_dir(ANGBAND_DIR_BONE, FALSE);
5510 /* Allow missing 'edit' directory */
5511 if (!check_dir(ANGBAND_DIR_EDIT))
5513 /* Must have 'data'! */
5514 validate_dir(ANGBAND_DIR_DATA, TRUE);
5518 /* Don't need 'data' */
5519 validate_dir(ANGBAND_DIR_DATA, FALSE);
5522 validate_dir(ANGBAND_DIR_FILE, TRUE);
5523 validate_dir(ANGBAND_DIR_HELP, FALSE);
5524 validate_dir(ANGBAND_DIR_INFO, FALSE);
5525 validate_dir(ANGBAND_DIR_PREF, TRUE);
5526 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5527 validate_dir(ANGBAND_DIR_USER, TRUE);
5528 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5530 /* Build the filename */
5532 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
5534 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
5538 /* Hack -- Validate the "news.txt" file */
5539 validate_file(path);
5542 #if 0 /* #ifndef JP */
5543 /* Build the "font" path */
5544 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5546 /* Allocate the path */
5547 ANGBAND_DIR_XTRA_FONT = string_make(path);
5549 /* Validate the "font" directory */
5550 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5552 /* Build the filename */
5553 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5555 /* Hack -- Validate the basic font */
5556 validate_file(path);
5562 /* Build the "graf" path */
5563 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5565 /* Allocate the path */
5566 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5568 /* Validate the "graf" directory */
5569 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5571 #endif /* USE_GRAPHICS */
5576 /* Build the "sound" path */
5577 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5579 /* Allocate the path */
5580 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5582 /* Validate the "sound" directory */
5583 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5585 #endif /* USE_SOUND */
5589 /* Build the "music" path */
5590 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5592 /* Allocate the path */
5593 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5595 /* Validate the "music" directory */
5596 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5598 #endif /* USE_MUSIC */
5600 /* Build the "help" path */
5601 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5603 /* Allocate the path */
5604 ANGBAND_DIR_XTRA_HELP = string_make(path);
5606 /* Validate the "help" directory */
5607 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5610 bool is_already_running()
5612 bool result = FALSE;
5615 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5616 if (GetLastError() == ERROR_ALREADY_EXISTS)
5624 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5625 LPSTR lpCmdLine, int nCmdShow)
5633 setlocale( LC_ALL, "ja_JP" );
5642 /* Prevent multiple run */
5643 if (is_already_running())
5646 _("ÊѶòÈÚÅܤϤ¹¤Ç¤Ëµ¯Æ°¤·¤Æ¤¤¤Þ¤¹¡£", "Hengband is already running."),
5647 _("¥¨¥é¡¼¡ª", "Error") ,
5648 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5653 if (hPrevInst == NULL)
5655 wc.style = CS_CLASSDC;
5656 wc.lpfnWndProc = AngbandWndProc;
5658 wc.cbWndExtra = 4; /* one long pointer to term_data */
5659 wc.hInstance = hInst;
5660 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5661 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5662 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5663 wc.lpszMenuName = AppName;
5664 wc.lpszClassName = AppName;
5666 if (!RegisterClass(&wc)) exit(1);
5668 wc.lpfnWndProc = AngbandListProc;
5669 wc.lpszMenuName = NULL;
5670 wc.lpszClassName = AngList;
5672 if (!RegisterClass(&wc)) exit(2);
5676 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5677 wc.lpfnWndProc = AngbandSaverProc;
5679 wc.lpszMenuName = NULL;
5680 wc.lpszClassName = "WindowsScreenSaverClass";
5682 if (!RegisterClass(&wc)) exit(3);
5688 /* Temporary hooks */
5689 plog_aux = hack_plog;
5690 quit_aux = hack_quit;
5691 core_aux = hack_quit;
5693 /* Prepare the filepaths */
5696 /* Initialize the keypress analyzer */
5697 for (i = 0; special_key_list[i]; ++i)
5699 special_key[special_key_list[i]] = TRUE;
5701 /* Initialize the keypress analyzer */
5702 for (i = 0; ignore_key_list[i]; ++i)
5704 ignore_key[ignore_key_list[i]] = TRUE;
5707 /* Determine if display is 16/256/true color */
5709 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5710 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5711 ReleaseDC(NULL, hdc);
5713 /* Initialize the colors */
5714 for (i = 0; i < 256; i++)
5718 /* Extract desired values */
5719 rv = angband_color_table[i][1];
5720 gv = angband_color_table[i][2];
5721 bv = angband_color_table[i][3];
5723 /* Extract the "complex" code */
5724 win_clr[i] = PALETTERGB(rv, gv, bv);
5726 /* Save the "simple" code */
5727 angband_color_table[i][0] = win_pal[i];
5730 /* Prepare the windows */
5736 /* Activate hooks */
5737 plog_aux = hook_plog;
5738 quit_aux = hook_quit;
5739 core_aux = hook_quit;
5741 /* Set the system suffix */
5742 ANGBAND_SYS = "win";
5744 /* Set the keyboard suffix */
5745 if (7 != GetKeyboardType(0))
5746 ANGBAND_KEYBOARD = "0";
5749 /* Japanese keyboard */
5750 switch (GetKeyboardType(1))
5752 case 0x0D01: case 0x0D02:
5753 case 0x0D03: case 0x0D04:
5754 case 0x0D05: case 0x0D06:
5756 ANGBAND_KEYBOARD = "NEC98";
5760 ANGBAND_KEYBOARD = "JAPAN";
5764 /* Catch nasty signals */
5770 /* We are now initialized */
5773 if(lpCmdLine[0] == '-'){
5774 switch(lpCmdLine[1])
5779 if (!lpCmdLine[2]) break;
5780 chuukei_server = TRUE;
5781 if(connect_chuukei_server(&lpCmdLine[2])<0){
5782 msg_print("connect fail");
5785 msg_print("connect");
5793 if (!lpCmdLine[2]) break;
5794 chuukei_client = TRUE;
5795 connect_chuukei_server(&lpCmdLine[2]);
5803 if (!lpCmdLine[2]) break;
5804 prepare_browse_movie(&lpCmdLine[2]);
5814 /* Did the user double click on a save file? */
5815 if(!chuukei_server) check_for_save_file(lpCmdLine);
5817 /* Did the user double click on a save file? */
5818 check_for_save_file(lpCmdLine);
5821 /* Prompt the user */
5823 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5825 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5830 /* Process messages forever */
5831 while (GetMessage(&msg, NULL, 0, 0))
5833 TranslateMessage(&msg);
5834 DispatchMessage(&msg);
5845 #endif /* WINDOWS */