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);
1771 #endif /* USE_SOUND */
1777 static bool init_sound(void)
1779 /* Initialize once */
1782 /* Load the prefs */
1785 /* Sound available */
1786 can_use_sound = TRUE;
1790 return (can_use_sound);
1792 #endif /* USE_SOUND */
1798 static void term_window_resize(term_data *td)
1800 /* Require window */
1803 /* Resize the window */
1804 SetWindowPos(td->w, 0, 0, 0,
1805 td->size_wid, td->size_hgt,
1806 SWP_NOMOVE | SWP_NOZORDER);
1809 InvalidateRect(td->w, NULL, TRUE);
1814 * Force the use of a new "font file" for a term_data
1816 * This function may be called before the "window" is ready
1818 * This function returns zero only if everything succeeds.
1820 * Note that the "font name" must be capitalized!!!
1822 static errr term_force_font(term_data *td, cptr path)
1826 #if 0 /* #ifndef JP */
1832 /* Forget the old font (if needed) */
1833 if (td->font_id) DeleteObject(td->font_id);
1835 #if 1 /* #ifdef JP */
1839 /* Create the font (using the 'base' of the font file name!) */
1840 td->font_id = CreateFontIndirect(&(td->lf));
1841 wid = td->lf.lfWidth;
1842 hgt = td->lf.lfHeight;
1843 if (!td->font_id) return (1);
1845 /* Forget old font */
1851 for (i = 0; i < MAX_TERM_DATA; i++)
1853 /* Don't check when closing the application */
1856 /* Check "screen" */
1857 if ((td != &data[i]) &&
1858 (data[i].font_file) &&
1859 (streq(data[i].font_file, td->font_file)))
1865 /* Remove unused font resources */
1866 if (!used) RemoveFontResource(td->font_file);
1868 /* Free the old name */
1869 string_free(td->font_file);
1872 td->font_file = NULL;
1876 if (!path) return (1);
1881 /* Analyze font path */
1882 base = analyze_font(buf, &wid, &hgt);
1885 if (!suffix(base, ".FON")) return (1);
1888 if (!check_file(buf)) return (1);
1890 /* Load the new font */
1891 if (!AddFontResource(buf)) return (1);
1893 /* Save new font name */
1894 td->font_file = string_make(base);
1896 /* Remove the "suffix" */
1897 base[strlen(base)-4] = '\0';
1899 /* Create the font (using the 'base' of the font file name!) */
1900 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1901 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1902 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1903 FIXED_PITCH | FF_DONTCARE, base);
1906 /* Hack -- Unknown size */
1913 /* all this trouble to get the cell size */
1914 hdcDesktop = GetDC(HWND_DESKTOP);
1915 hfOld = SelectObject(hdcDesktop, td->font_id);
1916 GetTextMetrics(hdcDesktop, &tm);
1917 SelectObject(hdcDesktop, hfOld);
1918 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1920 /* Font size info */
1921 wid = tm.tmAveCharWidth;
1925 /* Save the size info */
1936 * Allow the user to change the font for this window.
1938 static void term_change_font(term_data *td)
1940 #if 1 /* #ifdef JP */
1943 memset(&cf, 0, sizeof(cf));
1944 cf.lStructSize = sizeof(cf);
1945 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1946 cf.lpLogFont = &(td->lf);
1948 if (ChooseFont(&cf))
1950 /* Force the font */
1951 term_force_font(td, NULL);
1953 /* Assume not bizarre */
1956 /* Reset the tile info */
1957 td->tile_wid = td->font_wid;
1958 td->tile_hgt = td->font_hgt;
1960 /* Analyze the font */
1963 /* Resize the window */
1964 term_window_resize(td);
1970 char tmp[1024] = "";
1972 /* Extract a default if possible */
1973 if (td->font_file) strcpy(tmp, td->font_file);
1975 /* Ask for a choice */
1976 memset(&ofn, 0, sizeof(ofn));
1977 ofn.lStructSize = sizeof(ofn);
1978 ofn.hwndOwner = data[0].w;
1979 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1980 ofn.nFilterIndex = 1;
1981 ofn.lpstrFile = tmp;
1983 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1984 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1985 ofn.lpstrDefExt = "fon";
1987 /* Force choice if legal */
1988 if (GetOpenFileName(&ofn))
1990 /* Force the font */
1991 if (term_force_font(td, tmp))
1993 /* Access the standard font file */
1994 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1996 /* Force the use of that font */
1997 (void)term_force_font(td, tmp);
2000 /* Assume not bizarre */
2001 td->bizarre = FALSE;
2003 /* Reset the tile info */
2004 td->tile_wid = td->font_wid;
2005 td->tile_hgt = td->font_hgt;
2007 /* Analyze the font */
2010 /* Resize the window */
2011 term_window_resize(td);
2018 * Allow the user to lock this window.
2020 static void term_window_pos(term_data *td, HWND hWnd)
2022 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2023 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2026 static void windows_map(void);
2029 * Hack -- redraw a term_data
2031 static void term_data_redraw(term_data *td)
2035 /* Redraw the map */
2040 /* Activate the term */
2041 Term_activate(&td->t);
2043 /* Redraw the contents */
2046 /* Restore the term */
2047 Term_activate(term_screen);
2052 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2056 HBRUSH myBrush, oldBrush;
2058 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2059 int tx = td->size_ow1 + x * td->tile_wid;
2060 int ty = td->size_oh1 + y * td->tile_hgt;
2061 int tw = w * td->tile_wid - 1;
2062 int th = h * td->tile_hgt - 1;
2065 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2066 oldBrush = SelectObject(hdc, myBrush);
2067 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2069 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2071 SelectObject(hdc, oldBrush);
2072 SelectObject(hdc, oldPen);
2077 /*** Function hooks needed by "Term" ***/
2083 * Initialize a new Term
2085 static void Term_init_win(term *t)
2094 static void Term_nuke_win(term *t)
2103 * Interact with the User
2105 static errr Term_user_win(int n)
2116 * React to global changes
2118 static errr Term_xtra_win_react(void)
2126 /* Save the default colors */
2127 for (i = 0; i < 256; i++)
2129 /* Simply accept the desired colors */
2130 win_pal[i] = angband_color_table[i][0];
2141 bool change = FALSE;
2143 /* Save the default colors */
2144 for (i = 0; i < 256; i++)
2146 /* Extract desired values */
2147 rv = angband_color_table[i][1];
2148 gv = angband_color_table[i][2];
2149 bv = angband_color_table[i][3];
2151 /* Extract a full color code */
2152 code = PALETTERGB(rv, gv, bv);
2154 /* Activate changes */
2155 if (win_clr[i] != code)
2157 /* Note the change */
2160 /* Apply the desired color */
2165 /* Activate the palette if needed */
2166 if (change) (void)new_palette();
2172 /* Handle "arg_sound" */
2173 if (use_sound != arg_sound)
2175 /* Initialize (if needed) */
2176 if (arg_sound && !init_sound())
2180 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
2182 plog("Cannot initialize sound!");
2190 /* Change setting */
2191 use_sound = arg_sound;
2198 /* Handle "arg_sound" */
2199 if (use_music != arg_music)
2201 /* Initialize (if needed) */
2202 if (arg_music && !init_music())
2206 plog("BGM¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
2208 plog("Cannot initialize BGM!");
2214 /* Change setting */
2215 use_music = arg_music;
2223 /* Handle "arg_graphics" */
2224 if (use_graphics != arg_graphics)
2226 /* Initialize (if needed) */
2227 if (arg_graphics && !init_graphics())
2231 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
2233 plog("Cannot initialize graphics!");
2238 arg_graphics = GRAPHICS_NONE;
2241 /* Change setting */
2242 use_graphics = arg_graphics;
2245 #ifdef ANGBAND_2_8_1
2247 #else /* ANGBAND_2_8_1 */
2248 reset_visuals(TRUE);
2249 #endif /* ANGBAND_2_8_1 */
2252 #endif /* USE_GRAPHICS */
2255 /* Clean up windows */
2256 for (i = 0; i < MAX_TERM_DATA; i++)
2260 term_data *td = &data[i];
2262 /* Update resized windows */
2263 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2266 Term_activate(&td->t);
2268 /* Hack -- Resize the term */
2269 Term_resize(td->cols, td->rows);
2271 /* Redraw the contents */
2286 * Process at least one event
2288 static errr Term_xtra_win_event(int v)
2292 /* Wait for an event */
2296 if (GetMessage(&msg, NULL, 0, 0))
2298 TranslateMessage(&msg);
2299 DispatchMessage(&msg);
2303 /* Check for an event */
2307 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2309 TranslateMessage(&msg);
2310 DispatchMessage(&msg);
2320 * Process all pending events
2322 static errr Term_xtra_win_flush(void)
2326 /* Process all pending events */
2327 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2329 TranslateMessage(&msg);
2330 DispatchMessage(&msg);
2339 * Hack -- clear the screen
2341 * Make this more efficient XXX XXX XXX
2343 static errr Term_xtra_win_clear(void)
2345 term_data *td = (term_data*)(Term->data);
2350 /* Rectangle to erase */
2351 rc.left = td->size_ow1;
2352 rc.right = rc.left + td->cols * td->tile_wid;
2353 rc.top = td->size_oh1;
2354 rc.bottom = rc.top + td->rows * td->tile_hgt;
2358 SetBkColor(hdc, RGB(0, 0, 0));
2359 SelectObject(hdc, td->font_id);
2360 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2365 rc.left = 0; rc.top = 0;
2368 ReleaseDC(td->w, hdc);
2376 * Hack -- make a noise
2378 static errr Term_xtra_win_noise(void)
2380 MessageBeep(MB_ICONASTERISK);
2386 * Hack -- make a sound
2388 static errr Term_xtra_win_sound(int v)
2393 #endif /* USE_SOUND */
2395 /* Sound disabled */
2396 if (!use_sound) return (1);
2399 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2403 /* Count the samples */
2404 for (i = 0; i < SAMPLE_MAX; i++)
2406 if (!sound_file[v][i])
2411 if (i == 0) return (1);
2413 /* Build the path */
2414 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2418 /* Play the sound, catch errors */
2419 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2423 /* Play the sound, catch errors */
2424 return (sndPlaySound(buf, SND_ASYNC));
2428 #else /* USE_SOUND */
2433 #endif /* USE_SOUND */
2437 * Hack -- play a music
2439 static errr Term_xtra_win_music(int v)
2444 #endif /* USE_MUSIC */
2446 /* Sound disabled */
2447 if (!use_music) return (1);
2450 if ((v < 0) || (v >= MUSIC_BASIC_MAX)) return (1);
2454 /* Count the samples */
2455 for (i = 0; i < SAMPLE_MAX; i++)
2457 if (!music_file[v][i]) break;
2463 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2464 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2468 /* Build the path */
2469 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2471 #endif /* USE_MUSIC */
2475 mop.lpstrDeviceType = mci_device_type;
2476 mop.lpstrElementName = buf;
2477 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2478 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2479 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2480 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2481 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2484 #else /* USE_MUSIC */
2489 #endif /* USE_MUSIC */
2494 * Delay for "x" milliseconds
2496 static int Term_xtra_win_delay(int v)
2510 t = GetTickCount() + v;
2513 while (GetTickCount() < t)
2515 /* Handle messages */
2516 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2518 TranslateMessage(&msg);
2519 DispatchMessage(&msg);
2531 * Do a "special thing"
2533 static errr Term_xtra_win(int n, int v)
2535 /* Handle a subset of the legal requests */
2538 /* Make a bell sound */
2539 case TERM_XTRA_NOISE:
2541 return (Term_xtra_win_noise());
2545 case TERM_XTRA_MUSIC_BASIC:
2547 return (Term_xtra_win_music(v));
2550 /* Make a special sound */
2551 case TERM_XTRA_SOUND:
2553 return (Term_xtra_win_sound(v));
2556 /* Process random events */
2557 case TERM_XTRA_BORED:
2559 return (Term_xtra_win_event(0));
2562 /* Process an event */
2563 case TERM_XTRA_EVENT:
2565 return (Term_xtra_win_event(v));
2568 /* Flush all events */
2569 case TERM_XTRA_FLUSH:
2571 return (Term_xtra_win_flush());
2574 /* Clear the screen */
2575 case TERM_XTRA_CLEAR:
2577 return (Term_xtra_win_clear());
2580 /* React to global changes */
2581 case TERM_XTRA_REACT:
2583 return (Term_xtra_win_react());
2586 /* Delay for some milliseconds */
2587 case TERM_XTRA_DELAY:
2589 return (Term_xtra_win_delay(v));
2600 * Low level graphics (Assumes valid input).
2602 * Draw a "cursor" at (x,y), using a "yellow box".
2604 static errr Term_curs_win(int x, int y)
2606 term_data *td = (term_data*)(Term->data);
2611 int tile_wid, tile_hgt;
2615 tile_wid = td->map_tile_wid;
2616 tile_hgt = td->map_tile_hgt;
2620 tile_wid = td->tile_wid;
2621 tile_hgt = td->tile_hgt;
2624 /* Frame the grid */
2625 rc.left = x * tile_wid + td->size_ow1;
2626 rc.right = rc.left + tile_wid;
2627 rc.top = y * tile_hgt + td->size_oh1;
2628 rc.bottom = rc.top + tile_hgt;
2630 /* Cursor is done as a yellow "box" */
2632 FrameRect(hdc, &rc, hbrYellow);
2633 ReleaseDC(td->w, hdc);
2641 * Low level graphics (Assumes valid input).
2643 * Draw a "big cursor" at (x,y), using a "yellow box".
2645 static errr Term_bigcurs_win(int x, int y)
2647 term_data *td = (term_data*)(Term->data);
2652 int tile_wid, tile_hgt;
2656 /* Normal cursor in map window */
2657 Term_curs_win(x, y);
2662 tile_wid = td->tile_wid;
2663 tile_hgt = td->tile_hgt;
2666 /* Frame the grid */
2667 rc.left = x * tile_wid + td->size_ow1;
2668 rc.right = rc.left + 2 * tile_wid;
2669 rc.top = y * tile_hgt + td->size_oh1;
2670 rc.bottom = rc.top + tile_hgt;
2672 /* Cursor is done as a yellow "box" */
2674 FrameRect(hdc, &rc, hbrYellow);
2675 ReleaseDC(td->w, hdc);
2683 * Low level graphics (Assumes valid input).
2685 * Erase a "block" of "n" characters starting at (x,y).
2687 static errr Term_wipe_win(int x, int y, int n)
2689 term_data *td = (term_data*)(Term->data);
2694 /* Rectangle to erase in client coords */
2695 rc.left = x * td->tile_wid + td->size_ow1;
2696 rc.right = rc.left + n * td->tile_wid;
2697 rc.top = y * td->tile_hgt + td->size_oh1;
2698 rc.bottom = rc.top + td->tile_hgt;
2701 SetBkColor(hdc, RGB(0, 0, 0));
2702 SelectObject(hdc, td->font_id);
2707 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2708 ReleaseDC(td->w, hdc);
2716 * Low level graphics. Assumes valid input.
2718 * Draw several ("n") chars, with an attr, at a given location.
2720 * All "graphic" data is handled by "Term_pict_win()", below.
2722 * One would think there is a more efficient method for telling a window
2723 * what color it should be using to draw with, but perhaps simply changing
2724 * it every time is not too inefficient. XXX XXX XXX
2726 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2728 term_data *td = (term_data*)(Term->data);
2732 #if 1 /* #ifdef JP */
2733 static HBITMAP WALL;
2734 static HBRUSH myBrush, oldBrush;
2736 static bool init_done = FALSE;
2739 WALL = LoadBitmap(hInstance, AppName);
2740 myBrush = CreatePatternBrush(WALL);
2745 /* Total rectangle */
2746 rc.left = x * td->tile_wid + td->size_ow1;
2747 rc.right = rc.left + n * td->tile_wid;
2748 rc.top = y * td->tile_hgt + td->size_oh1;
2749 rc.bottom = rc.top + td->tile_hgt;
2754 /* Background color */
2755 SetBkColor(hdc, RGB(0, 0, 0));
2757 /* Foreground color */
2760 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2764 SetTextColor(hdc, win_clr[a&0x0F]);
2768 SetTextColor(hdc, win_clr[a]);
2772 SelectObject(hdc, td->font_id);
2775 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2779 (td->tile_hgt != td->font_hgt) ||
2780 (td->tile_wid != td->font_wid))
2784 /* Erase complete rectangle */
2785 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2788 if (use_bg) DrawBG(hdc, &rc);
2791 rc.left += ((td->tile_wid - td->font_wid) / 2);
2792 rc.right = rc.left + td->font_wid;
2793 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2794 rc.bottom = rc.top + td->font_hgt;
2796 /* Dump each character */
2797 for (i = 0; i < n; i++)
2800 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2802 rc.right += td->font_wid;
2804 oldBrush = SelectObject(hdc, myBrush);
2805 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2808 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2810 SelectObject(hdc, oldBrush);
2811 SelectObject(hdc, oldPen);
2812 rc.right -= td->font_wid;
2816 rc.left += 2 * td->tile_wid;
2817 rc.right += 2 * td->tile_wid;
2819 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2821 rc.right += td->font_wid;
2823 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2825 rc.right -= td->font_wid;
2829 rc.left += 2 * td->tile_wid;
2830 rc.right += 2 * td->tile_wid;
2831 } else if (*(s+i)==127){
2832 oldBrush = SelectObject(hdc, myBrush);
2833 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2836 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2838 SelectObject(hdc, oldBrush);
2839 SelectObject(hdc, oldPen);
2842 rc.left += td->tile_wid;
2843 rc.right += td->tile_wid;
2846 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2849 rc.left += td->tile_wid;
2850 rc.right += td->tile_wid;
2855 oldBrush = SelectObject(hdc, myBrush);
2856 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2859 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2861 SelectObject(hdc, oldBrush);
2862 SelectObject(hdc, oldPen);
2865 rc.left += td->tile_wid;
2866 rc.right += td->tile_wid;
2869 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2873 rc.left += td->tile_wid;
2874 rc.right += td->tile_wid;
2878 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2882 rc.left += td->tile_wid;
2883 rc.right += td->tile_wid;
2894 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2899 ReleaseDC(td->w, hdc);
2907 * Low level graphics. Assumes valid input.
2909 * Draw an array of "special" attr/char pairs at the given location.
2911 * We use the "Term_pict_win()" function for "graphic" data, which are
2912 * encoded by setting the "high-bits" of both the "attr" and the "char"
2913 * data. We use the "attr" to represent the "row" of the main bitmap,
2914 * and the "char" to represent the "col" of the main bitmap. The use
2915 * of this function is induced by the "higher_pict" flag.
2917 * If "graphics" is not available, we simply "wipe" the given grids.
2919 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2921 term_data *td = (term_data*)(Term->data);
2927 int x2, y2, w2, h2, tw2;
2939 /* Erase the grids */
2940 return (Term_wipe_win(x, y, n));
2943 /* Size of bitmap cell */
2944 w1 = infGraph.CellWidth;
2945 h1 = infGraph.CellHeight;
2947 /* Size of window cell */
2950 w2 = td->map_tile_wid;
2951 h2 = td->map_tile_hgt;
2960 if (use_bigtile) tw2 *= 2;
2963 /* Location of window cell */
2964 x2 = x * w2 + td->size_ow1;
2965 y2 = y * h2 + td->size_oh1;
2971 hdcSrc = CreateCompatibleDC(hdc);
2972 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2974 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2976 hdcMask = CreateCompatibleDC(hdc);
2977 SelectObject(hdcMask, infMask.hBitmap);
2980 /* Draw attr/char pairs */
2981 for (i = 0; i < n; i++, x2 += w2)
2986 /* Extract picture */
2987 int row = (a & 0x7F);
2988 int col = (c & 0x7F);
2990 /* Location of bitmap cell */
2994 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2996 x3 = (tcp[i] & 0x7F) * w1;
2997 y3 = (tap[i] & 0x7F) * h1;
3000 if ((w1 == tw2) && (h1 == h2))
3002 /* Copy the terrain picture from the bitmap to the window */
3003 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
3005 /* Mask out the tile */
3006 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3009 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3012 /* Need to stretch */
3015 /* Set the correct mode for stretching the tiles */
3016 SetStretchBltMode(hdc, COLORONCOLOR);
3018 /* Copy the terrain picture from the bitmap to the window */
3019 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
3021 /* Only draw if terrain and overlay are different */
3022 if ((x1 != x3) || (y1 != y3))
3024 /* Mask out the tile */
3025 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3028 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3035 if ((w1 == tw2) && (h1 == h2))
3037 /* Copy the picture from the bitmap to the window */
3038 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3041 /* Need to stretch */
3044 /* Set the correct mode for stretching the tiles */
3045 SetStretchBltMode(hdc, COLORONCOLOR);
3047 /* Copy the picture from the bitmap to the window */
3048 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3054 SelectObject(hdcSrc, hbmSrcOld);
3057 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3060 SelectObject(hdcMask, hbmSrcOld);
3065 ReleaseDC(td->w, hdc);
3067 #else /* USE_GRAPHICS */
3069 /* Just erase this grid */
3070 return (Term_wipe_win(x, y, n));
3072 #endif /* USE_GRAPHICS */
3079 static void windows_map(void)
3081 term_data *td = &data[0];
3083 int x, min_x, max_x;
3084 int y, min_y, max_y;
3088 /* Only in graphics mode */
3089 if (!use_graphics) return;
3092 Term_xtra_win_clear();
3094 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3095 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3096 td->map_active = TRUE;
3106 for (x = min_x; x < max_x; x++)
3108 for (y = min_y; y < max_y; y++)
3110 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3112 /* Ignore non-graphics */
3113 if ((a & 0x80) && (c & 0x80))
3115 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3120 /* Hilite the player */
3121 Term_curs_win(px - min_x, py - min_y);
3123 /* Wait for a keypress, flush key buffer */
3124 Term_inkey(&c, TRUE, TRUE);
3127 /* Switch off the map display */
3128 td->map_active = FALSE;
3130 /* Restore screen */
3131 Term_xtra_win_clear();
3136 /*** Other routines ***/
3140 * Create and initialize a "term_data" given a title
3142 static void term_data_link(term_data *td)
3146 /* Initialize the term */
3147 term_init(t, td->cols, td->rows, td->keys);
3149 /* Use a "software" cursor */
3150 t->soft_cursor = TRUE;
3152 /* Use "Term_pict" for "graphic" data */
3153 t->higher_pict = TRUE;
3155 /* Erase with "white space" */
3156 t->attr_blank = TERM_WHITE;
3157 t->char_blank = ' ';
3160 /* Prepare the init/nuke hooks */
3161 t->init_hook = Term_init_win;
3162 t->nuke_hook = Term_nuke_win;
3165 /* Prepare the template hooks */
3166 t->user_hook = Term_user_win;
3167 t->xtra_hook = Term_xtra_win;
3168 t->curs_hook = Term_curs_win;
3169 t->bigcurs_hook = Term_bigcurs_win;
3170 t->wipe_hook = Term_wipe_win;
3171 t->text_hook = Term_text_win;
3172 t->pict_hook = Term_pict_win;
3174 /* Remember where we came from */
3175 t->data = (vptr)(td);
3180 * Create the windows
3182 * First, instantiate the "default" values, then read the "ini_file"
3183 * to over-ride selected values, then create the windows, and fonts.
3185 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3186 * must make active to realize the palette. XXX XXX XXX
3188 static void init_windows(void)
3194 #if 0 /* #ifndef JP */
3200 WIPE(td, term_data);
3204 td->s = angband_term_name[0];
3218 #if 1 /* #ifdef JP */
3222 for (i = 1; i < MAX_TERM_DATA; i++)
3225 WIPE(td, term_data);
3226 td->s = angband_term_name[i];
3230 td->visible = FALSE;
3235 td->pos_x = (7 - i) * 30;
3236 td->pos_y = (7 - i) * 20;
3238 #if 1 /* #ifdef JP */
3248 /* Main window (need these before term_getsize gets called) */
3250 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3251 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3256 /* Sub windows (need these before term_getsize gets called) */
3257 for (i = 1; i < MAX_TERM_DATA; i++)
3260 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3261 td->dwExStyle = (WS_EX_TOOLWINDOW);
3266 for (i = 0; i < MAX_TERM_DATA; i++)
3270 #if 1 /* #ifdef JP */
3271 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3272 td->lf.lfCharSet = DEFAULT_CHARSET;
3273 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3274 /* Activate the chosen font */
3275 term_force_font(td, NULL);
3276 td->tile_wid = td->font_wid;
3277 td->tile_hgt = td->font_hgt;
3279 /* Access the standard font file */
3280 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3282 /* Activate the chosen font */
3283 if (term_force_font(td, buf))
3285 /* Access the standard font file */
3286 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3288 /* Force the use of that font */
3289 (void)term_force_font(td, buf);
3295 /* Assume not bizarre */
3296 td->bizarre = FALSE;
3301 /* Analyze the font */
3304 /* Resize the window */
3305 term_window_resize(td);
3309 /* Sub windows (reverse order) */
3310 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3315 td->w = CreateWindowEx(td->dwExStyle, AngList,
3317 td->pos_x, td->pos_y,
3318 td->size_wid, td->size_hgt,
3319 HWND_DESKTOP, NULL, hInstance, NULL);
3322 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3324 if (!td->w) quit("Failed to create sub-window");
3330 td->size_hack = TRUE;
3331 ShowWindow(td->w, SW_SHOW);
3332 td->size_hack = FALSE;
3336 angband_term[i] = &td->t;
3340 /* Activate the window */
3341 SetActiveWindow(td->w);
3346 term_window_pos(&data[i], HWND_TOPMOST);
3350 term_window_pos(&data[i], td->w);
3360 td->w = CreateWindowEx(td->dwExStyle, AppName,
3362 td->pos_x, td->pos_y,
3363 td->size_wid, td->size_hgt,
3364 HWND_DESKTOP, NULL, hInstance, NULL);
3367 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3369 if (!td->w) quit("Failed to create Angband window");
3374 angband_term[0] = &td->t;
3375 normsize.x = td->cols;
3376 normsize.y = td->rows;
3378 /* Activate the main window */
3379 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3380 else ShowWindow(td->w, SW_SHOW);
3382 /* Bring main window back to top */
3383 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3386 /* New palette XXX XXX XXX */
3387 (void)new_palette();
3390 /* Create a "brush" for drawing the "cursor" */
3391 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3394 /* Process pending messages */
3395 (void)Term_xtra_win_flush();
3403 static void setup_menus(void)
3407 HMENU hm = GetMenu(data[0].w);
3410 /* Menu "File", Disable all */
3411 EnableMenuItem(hm, IDM_FILE_NEW,
3412 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3413 EnableMenuItem(hm, IDM_FILE_OPEN,
3414 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3415 EnableMenuItem(hm, IDM_FILE_SAVE,
3416 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3417 EnableMenuItem(hm, IDM_FILE_EXIT,
3418 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3419 EnableMenuItem(hm, IDM_FILE_SCORE,
3420 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3423 /* No character available */
3424 if (!character_generated)
3426 /* Menu "File", Item "New" */
3427 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3429 /* Menu "File", Item "Open" */
3430 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3433 /* A character available */
3434 if (character_generated)
3436 /* Menu "File", Item "Save" */
3437 EnableMenuItem(hm, IDM_FILE_SAVE,
3438 MF_BYCOMMAND | MF_ENABLED);
3441 /* Menu "File", Item "Exit" */
3442 EnableMenuItem(hm, IDM_FILE_EXIT,
3443 MF_BYCOMMAND | MF_ENABLED);
3445 EnableMenuItem(hm, IDM_FILE_SCORE,
3446 MF_BYCOMMAND | MF_ENABLED);
3449 /* Menu "Window::Visibility" */
3450 for (i = 0; i < MAX_TERM_DATA; i++)
3452 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3453 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3455 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3456 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3458 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3459 MF_BYCOMMAND | MF_ENABLED);
3462 /* Menu "Window::Font" */
3463 for (i = 0; i < MAX_TERM_DATA; i++)
3465 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3466 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3468 if (data[i].visible)
3470 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3471 MF_BYCOMMAND | MF_ENABLED);
3475 /* Menu "Window::Window Position Fix" */
3476 for (i = 0; i < MAX_TERM_DATA; i++)
3478 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3479 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3481 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3482 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3484 if (data[i].visible)
3486 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3487 MF_BYCOMMAND | MF_ENABLED);
3491 /* Menu "Window::Bizarre Display" */
3492 for (i = 0; i < MAX_TERM_DATA; i++)
3494 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3495 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3497 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3498 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3500 if (data[i].visible)
3502 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3503 MF_BYCOMMAND | MF_ENABLED);
3508 /* Menu "Window::Increase Tile Width" */
3509 for (i = 0; i < MAX_TERM_DATA; i++)
3511 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3512 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3514 if (data[i].visible)
3516 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3517 MF_BYCOMMAND | MF_ENABLED);
3522 /* Menu "Window::Decrease Tile Width" */
3523 for (i = 0; i < MAX_TERM_DATA; i++)
3525 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3526 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3528 if (data[i].visible)
3530 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3531 MF_BYCOMMAND | MF_ENABLED);
3536 /* Menu "Window::Increase Tile Height" */
3537 for (i = 0; i < MAX_TERM_DATA; i++)
3539 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3540 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3542 if (data[i].visible)
3544 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3545 MF_BYCOMMAND | MF_ENABLED);
3550 /* Menu "Window::Decrease Tile Height" */
3551 for (i = 0; i < MAX_TERM_DATA; i++)
3553 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3554 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3556 if (data[i].visible)
3558 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3559 MF_BYCOMMAND | MF_ENABLED);
3564 /* Menu "Options", disable all */
3565 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3566 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3567 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3568 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3569 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3570 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3571 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3572 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3573 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3574 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3576 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3577 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3580 /* Menu "Options", Item "Map" */
3581 if (use_graphics != GRAPHICS_NONE)
3582 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3584 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3585 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3587 /* Menu "Options", update all */
3588 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3589 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3590 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3591 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3592 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3593 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3594 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3595 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3596 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3597 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3598 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3599 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3600 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3601 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3602 CheckMenuItem(hm, IDM_OPTIONS_BG,
3603 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3605 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3606 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3610 /* Menu "Options", Item "Graphics" */
3611 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3612 /* Menu "Options", Item "Graphics" */
3613 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3614 /* Menu "Options", Item "Graphics" */
3615 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3616 /* Menu "Options", Item "Graphics" */
3617 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3618 #endif /* USE_GRAPHICS */
3621 /* Menu "Options", Item "Sound" */
3622 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3623 #endif /* USE_SOUND */
3626 /* Menu "Options", Item "ScreenSaver" */
3627 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3628 MF_BYCOMMAND | MF_ENABLED);
3629 #endif /* USE_SAVER */
3634 * Check for double clicked (or dragged) savefile
3636 * Apparently, Windows copies the entire filename into the first
3637 * piece of the "command line string". Perhaps we should extract
3638 * the "basename" of that filename and append it to the "save" dir.
3640 static void check_for_save_file(LPSTR cmd_line)
3650 /* Extract filename */
3651 strcat(savefile, s);
3653 /* Validate the file */
3654 validate_file(savefile);
3656 /* Game in progress */
3657 game_in_progress = TRUE;
3665 * Process a menu command
3667 static void process_menus(WORD wCmd)
3684 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3686 plog("You cannot do that yet...");
3690 else if (game_in_progress)
3693 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3695 plog("You can't start a new game while you're still playing!");
3701 game_in_progress = TRUE;
3715 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3717 plog("You cannot do that yet...");
3721 else if (game_in_progress)
3724 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3726 plog("You can't open a new game while you're still playing!");
3732 memset(&ofn, 0, sizeof(ofn));
3733 ofn.lStructSize = sizeof(ofn);
3734 ofn.hwndOwner = data[0].w;
3735 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3736 ofn.nFilterIndex = 1;
3737 ofn.lpstrFile = savefile;
3738 ofn.nMaxFile = 1024;
3739 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3740 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3742 if (GetOpenFileName(&ofn))
3744 /* Load 'savefile' */
3745 validate_file(savefile);
3746 game_in_progress = TRUE;
3758 if (game_in_progress && character_generated)
3764 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3766 plog("You may not do that right now.");
3772 /* Hack -- Forget messages */
3777 do_cmd_save_game(FALSE);
3778 #else /* ZANGBAND */
3780 #endif /* ZANGBAND */
3785 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3787 plog("You may not do that right now.");
3797 if (game_in_progress && character_generated)
3803 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3805 plog("You may not do that right now.");
3811 /* Hack -- Forget messages */
3820 /* do_cmd_save_game(FALSE); */
3821 #else /* ZANGBAND */
3822 /* do_cmd_save_game(); */
3823 #endif /* ZANGBAND */
3824 Term_key_push(SPECIAL_KEY_QUIT);
3832 case IDM_FILE_SCORE:
3836 /* Build the filename */
3837 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3839 /* Open the binary high score file, for reading */
3840 highscore_fd = fd_open(buf, O_RDONLY);
3842 /* Paranoia -- No score file */
3843 if (highscore_fd < 0)
3845 msg_print("Score file unavailable.");
3855 /* Display the scores */
3856 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3858 /* Shut the high score file */
3859 (void)fd_close(highscore_fd);
3861 /* Forget the high score fd */
3867 /* Hack - Flush it */
3875 case IDM_FILE_MOVIE:
3880 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3882 plog("You cannot do that yet...");
3885 else if (game_in_progress)
3888 plog("¥×¥ì¥¤Ãæ¤Ï¥à¡¼¥Ó¡¼¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3890 plog("You can't open a movie while you're playing!");
3895 memset(&ofn, 0, sizeof(ofn));
3896 ofn.lStructSize = sizeof(ofn);
3897 ofn.hwndOwner = data[0].w;
3898 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3899 ofn.nFilterIndex = 1;
3900 ofn.lpstrFile = savefile;
3901 ofn.nMaxFile = 1024;
3902 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3903 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3905 if (GetOpenFileName(&ofn))
3907 /* Load 'savefile' */
3908 prepare_browse_movie_aux(savefile);
3918 case IDM_WINDOW_VIS_0:
3921 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3923 plog("You are not allowed to do that!");
3930 /* Window visibility */
3931 case IDM_WINDOW_VIS_1:
3932 case IDM_WINDOW_VIS_2:
3933 case IDM_WINDOW_VIS_3:
3934 case IDM_WINDOW_VIS_4:
3935 case IDM_WINDOW_VIS_5:
3936 case IDM_WINDOW_VIS_6:
3937 case IDM_WINDOW_VIS_7:
3939 i = wCmd - IDM_WINDOW_VIS_0;
3941 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3948 ShowWindow(td->w, SW_SHOW);
3949 term_data_redraw(td);
3953 td->visible = FALSE;
3955 ShowWindow(td->w, SW_HIDE);
3962 case IDM_WINDOW_FONT_0:
3963 case IDM_WINDOW_FONT_1:
3964 case IDM_WINDOW_FONT_2:
3965 case IDM_WINDOW_FONT_3:
3966 case IDM_WINDOW_FONT_4:
3967 case IDM_WINDOW_FONT_5:
3968 case IDM_WINDOW_FONT_6:
3969 case IDM_WINDOW_FONT_7:
3971 i = wCmd - IDM_WINDOW_FONT_0;
3973 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3977 term_change_font(td);
3982 /* Window Z Position */
3983 case IDM_WINDOW_POS_1:
3984 case IDM_WINDOW_POS_2:
3985 case IDM_WINDOW_POS_3:
3986 case IDM_WINDOW_POS_4:
3987 case IDM_WINDOW_POS_5:
3988 case IDM_WINDOW_POS_6:
3989 case IDM_WINDOW_POS_7:
3991 i = wCmd - IDM_WINDOW_POS_0;
3993 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3997 if (!td->posfix && td->visible)
4000 term_window_pos(td, HWND_TOPMOST);
4005 term_window_pos(td, data[0].w);
4011 /* Bizarre Display */
4012 case IDM_WINDOW_BIZ_0:
4013 case IDM_WINDOW_BIZ_1:
4014 case IDM_WINDOW_BIZ_2:
4015 case IDM_WINDOW_BIZ_3:
4016 case IDM_WINDOW_BIZ_4:
4017 case IDM_WINDOW_BIZ_5:
4018 case IDM_WINDOW_BIZ_6:
4019 case IDM_WINDOW_BIZ_7:
4021 i = wCmd - IDM_WINDOW_BIZ_0;
4023 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4027 td->bizarre = !td->bizarre;
4031 term_window_resize(td);
4036 /* Increase Tile Width */
4037 case IDM_WINDOW_I_WID_0:
4038 case IDM_WINDOW_I_WID_1:
4039 case IDM_WINDOW_I_WID_2:
4040 case IDM_WINDOW_I_WID_3:
4041 case IDM_WINDOW_I_WID_4:
4042 case IDM_WINDOW_I_WID_5:
4043 case IDM_WINDOW_I_WID_6:
4044 case IDM_WINDOW_I_WID_7:
4046 i = wCmd - IDM_WINDOW_I_WID_0;
4048 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4056 term_window_resize(td);
4061 /* Decrease Tile Height */
4062 case IDM_WINDOW_D_WID_0:
4063 case IDM_WINDOW_D_WID_1:
4064 case IDM_WINDOW_D_WID_2:
4065 case IDM_WINDOW_D_WID_3:
4066 case IDM_WINDOW_D_WID_4:
4067 case IDM_WINDOW_D_WID_5:
4068 case IDM_WINDOW_D_WID_6:
4069 case IDM_WINDOW_D_WID_7:
4071 i = wCmd - IDM_WINDOW_D_WID_0;
4073 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4081 term_window_resize(td);
4086 /* Increase Tile Height */
4087 case IDM_WINDOW_I_HGT_0:
4088 case IDM_WINDOW_I_HGT_1:
4089 case IDM_WINDOW_I_HGT_2:
4090 case IDM_WINDOW_I_HGT_3:
4091 case IDM_WINDOW_I_HGT_4:
4092 case IDM_WINDOW_I_HGT_5:
4093 case IDM_WINDOW_I_HGT_6:
4094 case IDM_WINDOW_I_HGT_7:
4096 i = wCmd - IDM_WINDOW_I_HGT_0;
4098 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4106 term_window_resize(td);
4111 /* Decrease Tile Height */
4112 case IDM_WINDOW_D_HGT_0:
4113 case IDM_WINDOW_D_HGT_1:
4114 case IDM_WINDOW_D_HGT_2:
4115 case IDM_WINDOW_D_HGT_3:
4116 case IDM_WINDOW_D_HGT_4:
4117 case IDM_WINDOW_D_HGT_5:
4118 case IDM_WINDOW_D_HGT_6:
4119 case IDM_WINDOW_D_HGT_7:
4121 i = wCmd - IDM_WINDOW_D_HGT_0;
4123 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4131 term_window_resize(td);
4136 case IDM_OPTIONS_NO_GRAPHICS:
4141 plog("You may not do that right now.");
4145 /* Toggle "arg_graphics" */
4146 if (arg_graphics != GRAPHICS_NONE)
4148 arg_graphics = GRAPHICS_NONE;
4150 /* React to changes */
4151 Term_xtra_win_react();
4153 /* Hack -- Force redraw */
4154 Term_key_push(KTRL('R'));
4160 case IDM_OPTIONS_OLD_GRAPHICS:
4165 plog("You may not do that right now.");
4169 /* Toggle "arg_graphics" */
4170 if (arg_graphics != GRAPHICS_ORIGINAL)
4172 arg_graphics = GRAPHICS_ORIGINAL;
4174 /* React to changes */
4175 Term_xtra_win_react();
4177 /* Hack -- Force redraw */
4178 Term_key_push(KTRL('R'));
4184 case IDM_OPTIONS_NEW_GRAPHICS:
4189 plog("You may not do that right now.");
4193 /* Toggle "arg_graphics" */
4194 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4196 arg_graphics = GRAPHICS_ADAM_BOLT;
4198 /* React to changes */
4199 Term_xtra_win_react();
4201 /* Hack -- Force redraw */
4202 Term_key_push(KTRL('R'));
4208 case IDM_OPTIONS_NEW2_GRAPHICS:
4213 plog("You may not do that right now.");
4217 /* Toggle "arg_graphics" */
4218 if (arg_graphics != GRAPHICS_HENGBAND)
4220 arg_graphics = GRAPHICS_HENGBAND;
4222 /* React to changes */
4223 Term_xtra_win_react();
4225 /* Hack -- Force redraw */
4226 Term_key_push(KTRL('R'));
4232 case IDM_OPTIONS_BIGTILE:
4234 term_data *td = &data[0];
4239 plog("You may not do that right now.");
4243 /* Toggle "arg_sound" */
4244 arg_bigtile = !arg_bigtile;
4247 Term_activate(&td->t);
4249 /* Resize the term */
4250 Term_resize(td->cols, td->rows);
4253 InvalidateRect(td->w, NULL, TRUE);
4258 case IDM_OPTIONS_MUSIC:
4263 plog("You may not do that right now.");
4267 /* Toggle "arg_sound" */
4268 arg_music = !arg_music;
4270 /* React to changes */
4271 Term_xtra_win_react();
4273 /* Hack -- Force redraw */
4274 Term_key_push(KTRL('R'));
4279 case IDM_OPTIONS_SOUND:
4284 plog("You may not do that right now.");
4288 /* Toggle "arg_sound" */
4289 arg_sound = !arg_sound;
4291 /* React to changes */
4292 Term_xtra_win_react();
4294 /* Hack -- Force redraw */
4295 Term_key_push(KTRL('R'));
4301 case IDM_OPTIONS_BG:
4306 plog("You may not do that right now.");
4310 /* Toggle "use_bg" */
4315 /* React to changes */
4316 Term_xtra_win_react();
4318 /* Hack -- Force redraw */
4319 Term_key_push(KTRL('R'));
4325 case IDM_OPTIONS_OPEN_BG:
4330 plog("You may not do that right now.");
4335 memset(&ofn, 0, sizeof(ofn));
4336 ofn.lStructSize = sizeof(ofn);
4337 ofn.hwndOwner = data[0].w;
4338 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4339 ofn.nFilterIndex = 1;
4340 ofn.lpstrFile = bg_bitmap_file;
4341 ofn.nMaxFile = 1023;
4342 ofn.lpstrInitialDir = NULL;
4344 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
4346 ofn.lpstrTitle = "Choose wall paper.";
4348 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4350 if (GetOpenFileName(&ofn))
4352 /* Load 'savefile' */
4357 /* React to changes */
4358 Term_xtra_win_react();
4360 /* Hack -- Force redraw */
4361 Term_key_push(KTRL('R'));
4366 case IDM_DUMP_SCREEN_HTML:
4368 static char buf[1024] = "";
4369 memset(&ofn, 0, sizeof(ofn));
4370 ofn.lStructSize = sizeof(ofn);
4371 ofn.hwndOwner = data[0].w;
4372 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4373 ofn.nFilterIndex = 1;
4374 ofn.lpstrFile = buf;
4375 ofn.nMaxFile = 1023;
4376 ofn.lpstrDefExt = "html";
4377 ofn.lpstrInitialDir = NULL;
4379 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
4381 ofn.lpstrTitle = "Save screen dump as HTML.";
4383 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4385 if (GetSaveFileName(&ofn))
4387 do_cmd_save_screen_html_aux(buf, 0);
4394 case IDM_OPTIONS_SAVER:
4398 DestroyWindow(hwndSaver);
4403 /* Create a screen scaver window */
4404 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4405 "Angband Screensaver",
4406 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4407 0, 0, GetSystemMetrics(SM_CXSCREEN),
4408 GetSystemMetrics(SM_CYSCREEN),
4409 NULL, NULL, hInstance, NULL);
4413 /* Push the window to the bottom XXX XXX XXX */
4414 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4419 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
4421 plog("Failed to create saver window");
4431 case IDM_OPTIONS_MAP:
4437 case IDM_HELP_CONTENTS:
4441 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4442 if (check_file(tmp))
4444 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4449 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4450 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4452 plog_fmt("Cannot find help file: %s", tmp);
4453 plog("Use the online help files instead.");
4458 #else /* HTML_HELP */
4461 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4462 if (check_file(tmp))
4464 sprintf(buf, "winhelp.exe %s", tmp);
4465 WinExec(buf, SW_NORMAL);
4470 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4471 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4473 plog_fmt("Cannot find help file: %s", tmp);
4474 plog("Use the online help files instead.");
4479 #endif /* HTML_HELP */
4485 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4492 /* Extract the modifiers */
4493 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4494 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4495 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4497 Term_no_press = (ma) ? TRUE : FALSE;
4499 /* Handle "special" keys */
4500 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4502 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4503 bool numpad = FALSE;
4505 /* Begin the macro trigger */
4508 /* Send the modifiers */
4509 if (mc) Term_keypress('C');
4510 if (ms) Term_keypress('S');
4511 if (ma) Term_keypress('A');
4513 /* Extract "scan code" */
4514 i = LOBYTE(HIWORD(lParam));
4516 /* Introduce the scan code */
4519 /* Extended key bit */
4522 /* Numpad Enter and '/' are extended key */
4524 Term_no_press = TRUE;
4525 case VK_RETURN: /* Enter */
4528 /* Other extended keys are on full keyboard */
4544 Term_no_press = TRUE;
4548 case VK_PRIOR: /* Page Up */
4549 case VK_NEXT: /* Page Down */
4559 /* Special modifiers for keypad keys */
4560 if (numpad) Term_keypress('K');
4562 /* Encode the hexidecimal scan code */
4563 Term_keypress(hexsym[i/16]);
4564 Term_keypress(hexsym[i%16]);
4566 /* End the macro trigger */
4577 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4578 WPARAM wParam, LPARAM lParam);
4579 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4580 WPARAM wParam, LPARAM lParam)
4581 #else /* __MWERKS__ */
4582 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4583 WPARAM wParam, LPARAM lParam)
4584 #endif /* __MWERKS__ */
4590 MINMAXINFO FAR *lpmmi;
4596 /* Acquire proper "term_data" info */
4597 td = (term_data *)GetWindowLong(hWnd, 0);
4599 /* Handle message */
4605 SetWindowLong(hWnd, 0, (LONG)(my_td));
4612 mop.dwCallback=(DWORD)hWnd;
4616 case WM_GETMINMAXINFO:
4618 MINMAXINFO FAR *lpmmi;
4621 lpmmi = (MINMAXINFO FAR *)lParam;
4623 /* this message was sent before WM_NCCREATE */
4626 /* Minimum window size is 80x24 */
4627 rc.left = rc.top = 0;
4628 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4629 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4632 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4634 /* Save minimum size */
4635 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4636 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4643 BeginPaint(hWnd, &ps);
4644 if (td) term_data_redraw(td);
4645 EndPaint(hWnd, &ps);
4646 ValidateRect(hWnd, NULL);
4653 if(wParam == MCI_NOTIFY_SUCCESSFUL)
4655 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4656 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4665 if (process_keydown(wParam, lParam))
4672 if (Term_no_press) Term_no_press = FALSE;
4673 else Term_keypress(wParam);
4677 case WM_LBUTTONDOWN:
4679 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4680 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4692 int dx = abs(oldx - mousex) + 1;
4693 int dy = abs(oldy - mousey) + 1;
4694 int ox = (oldx > mousex) ? mousex : oldx;
4695 int oy = (oldy > mousey) ? mousey : oldy;
4705 hGlobal = GlobalAlloc(GHND, sz + 1);
4706 if (hGlobal == NULL) return 0;
4707 lpStr = (LPSTR)GlobalLock(hGlobal);
4709 for (i = 0; i < dy; i++)
4713 char **scr = data[0].t.scr->c;
4715 C_MAKE(s, (dx + 1), char);
4716 strncpy(s, &scr[oy + i][ox], dx);
4720 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4723 if (ox + dx < data[0].cols)
4725 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4728 for (j = 0; j < dx; j++)
4730 if (s[j] == 127) s[j] = '#';
4734 for (j = 0; j < dx; j++)
4736 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4746 GlobalUnlock(hGlobal);
4747 if (OpenClipboard(hWnd) == 0)
4749 GlobalFree(hGlobal);
4753 SetClipboardData(CF_TEXT, hGlobal);
4766 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4767 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4772 dx = abs(oldx - mousex) + 1;
4773 dy = abs(oldy - mousey) + 1;
4774 ox = (oldx > mousex) ? mousex : oldx;
4775 oy = (oldy > mousey) ? mousey : oldy;
4776 Term_inversed_area(hWnd, ox, oy, dx, dy);
4783 dx = abs(cx - mousex) + 1;
4784 dy = abs(cy - mousey) + 1;
4785 ox = (cx > mousex) ? mousex : cx;
4786 oy = (cy > mousey) ? mousey : cy;
4787 Term_inversed_area(hWnd, ox, oy, dx, dy);
4803 if (game_in_progress && character_generated)
4808 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4810 plog("You may not do that right now.");
4815 /* Hack -- Forget messages */
4824 /* do_cmd_save_game(FALSE); */
4825 #else /* ZANGBAND */
4826 /* do_cmd_save_game(); */
4827 #endif /* ZANGBAND */
4828 Term_key_push(SPECIAL_KEY_QUIT);
4835 case WM_QUERYENDSESSION:
4837 if (game_in_progress && character_generated)
4839 /* Hack -- Forget messages */
4842 /* Mega-Hack -- Delay death */
4843 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4846 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "----¥²¡¼¥àÃæÃÇ----");
4848 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "---- Save and Exit Game ----");
4851 /* Hardcode panic save */
4852 p_ptr->panic_save = 1;
4854 /* Forbid suspend */
4855 signals_ignore_tstp();
4857 /* Indicate panic save */
4859 (void)strcpy(p_ptr->died_from, "(¶ÛµÞ¥»¡¼¥Ö)");
4861 (void)strcpy(p_ptr->died_from, "(panic save)");
4865 (void)save_player();
4879 process_menus(LOWORD(wParam));
4885 /* this message was sent before WM_NCCREATE */
4888 /* it was sent from inside CreateWindowEx */
4889 if (!td->w) return 1;
4891 /* was sent from WM_SIZE */
4892 if (td->size_hack) return 1;
4896 case SIZE_MINIMIZED:
4898 /* Hide sub-windows */
4899 for (i = 1; i < MAX_TERM_DATA; i++)
4901 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4906 case SIZE_MAXIMIZED:
4908 /* fall through XXX XXX XXX */
4913 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4914 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4917 if ((td->cols != cols) || (td->rows != rows))
4919 /* Save the new size */
4923 if (!IsZoomed(td->w) && !IsIconic(td->w))
4925 normsize.x = td->cols;
4926 normsize.y = td->rows;
4930 Term_activate(&td->t);
4932 /* Resize the term */
4933 Term_resize(td->cols, td->rows);
4936 InvalidateRect(td->w, NULL, TRUE);
4939 td->size_hack = TRUE;
4941 /* Show sub-windows */
4942 for (i = 1; i < MAX_TERM_DATA; i++)
4944 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4947 td->size_hack = FALSE;
4955 case WM_PALETTECHANGED:
4957 /* Ignore if palette change caused by itself */
4958 if ((HWND)wParam == hWnd) return 0;
4960 /* Fall through... */
4963 case WM_QUERYNEWPALETTE:
4965 if (!paletted) return 0;
4969 SelectPalette(hdc, hPal, FALSE);
4971 i = RealizePalette(hdc);
4973 /* if any palette entries changed, repaint the window. */
4974 if (i) InvalidateRect(hWnd, NULL, TRUE);
4976 ReleaseDC(hWnd, hdc);
4983 if (wParam && !HIWORD(lParam))
4985 /* Do something to sub-windows */
4986 for (i = 1; i < MAX_TERM_DATA; i++)
4988 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4991 /* Focus on main window */
5000 case WM_ACTIVATEAPP:
5002 if (IsIconic(td->w)) break;
5004 for (i = 1; i < MAX_TERM_DATA; i++)
5010 ShowWindow(data[i].w, SW_SHOW);
5014 ShowWindow(data[i].w, SW_HIDE);
5021 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5026 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5027 WPARAM wParam, LPARAM lParam);
5028 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5029 WPARAM wParam, LPARAM lParam)
5030 #else /* __MWERKS__ */
5031 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5032 WPARAM wParam, LPARAM lParam)
5033 #endif /* __MWERKS__ */
5037 MINMAXINFO FAR *lpmmi;
5045 /* Acquire proper "term_data" info */
5046 td = (term_data *)GetWindowLong(hWnd, 0);
5048 /* Process message */
5054 SetWindowLong(hWnd, 0, (LONG)(my_td));
5064 case WM_GETMINMAXINFO:
5066 MINMAXINFO FAR *lpmmi;
5069 lpmmi = (MINMAXINFO FAR *)lParam;
5071 /* this message was sent before WM_NCCREATE */
5074 /* Minimum window size is 80x24 */
5075 rc.left = rc.top = 0;
5076 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5077 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5080 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5082 /* Save minimum size */
5083 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5084 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5094 /* this message was sent before WM_NCCREATE */
5097 /* it was sent from inside CreateWindowEx */
5098 if (!td->w) return 1;
5100 /* was sent from inside WM_SIZE */
5101 if (td->size_hack) return 1;
5103 td->size_hack = TRUE;
5105 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5106 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5109 if ((td->cols != cols) || (td->rows != rows))
5112 term *old_term = Term;
5114 /* Save the new size */
5119 Term_activate(&td->t);
5121 /* Resize the term */
5122 Term_resize(td->cols, td->rows);
5125 Term_activate(old_term);
5128 InvalidateRect(td->w, NULL, TRUE);
5130 /* HACK - Redraw all windows */
5131 p_ptr->window = 0xFFFFFFFF;
5135 td->size_hack = FALSE;
5142 BeginPaint(hWnd, &ps);
5143 if (td) term_data_redraw(td);
5144 EndPaint(hWnd, &ps);
5151 if (process_keydown(wParam, lParam))
5158 if (Term_no_press) Term_no_press = FALSE;
5159 else Term_keypress(wParam);
5163 case WM_PALETTECHANGED:
5165 /* ignore if palette change caused by itself */
5166 if ((HWND)wParam == hWnd) return FALSE;
5167 /* otherwise, fall through!!! */
5170 case WM_QUERYNEWPALETTE:
5172 if (!paletted) return 0;
5174 SelectPalette(hdc, hPal, FALSE);
5175 i = RealizePalette(hdc);
5176 /* if any palette entries changed, repaint the window. */
5177 if (i) InvalidateRect(hWnd, NULL, TRUE);
5178 ReleaseDC(hWnd, hdc);
5182 case WM_NCLBUTTONDOWN:
5186 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5187 #endif /* HTCLOSE */
5189 if (wParam == HTSYSMENU)
5193 td->visible = FALSE;
5194 ShowWindow(td->w, SW_HIDE);
5204 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5210 #define MOUSE_SENS 40
5213 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5214 WPARAM wParam, LPARAM lParam);
5215 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5216 WPARAM wParam, LPARAM lParam)
5217 #else /* __MWERKS__ */
5218 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5219 WPARAM wParam, LPARAM lParam)
5220 #endif /* __MWERKS__ */
5222 static int iMouse = 0;
5223 static WORD xMouse = 0;
5224 static WORD yMouse = 0;
5247 if (LOWORD(wParam) == WA_INACTIVE) break;
5249 /* else fall through */
5253 case WM_LBUTTONDOWN:
5254 case WM_MBUTTONDOWN:
5255 case WM_RBUTTONDOWN:
5258 SendMessage(hWnd, WM_CLOSE, 0, 0);
5266 dx = LOWORD(lParam) - xMouse;
5267 dy = HIWORD(lParam) - yMouse;
5269 if (dx < 0) dx = -dx;
5270 if (dy < 0) dy = -dy;
5272 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5274 SendMessage(hWnd, WM_CLOSE, 0, 0);
5278 /* Save last location */
5280 xMouse = LOWORD(lParam);
5281 yMouse = HIWORD(lParam);
5288 DestroyWindow(hwndSaver);
5295 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5298 #endif /* USE_SAVER */
5304 /*** Temporary Hooks ***/
5308 * Display warning message (see "z-util.c")
5310 static void hack_plog(cptr str)
5312 /* Give a warning */
5316 MessageBox(NULL, str, "·Ù¹ð¡ª",
5317 MB_ICONEXCLAMATION | MB_OK);
5319 MessageBox(NULL, str, "Warning",
5320 MB_ICONEXCLAMATION | MB_OK);
5328 * Display error message and quit (see "z-util.c")
5330 static void hack_quit(cptr str)
5332 /* Give a warning */
5336 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
5337 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5339 MessageBox(NULL, str, "Error",
5340 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5345 /* Unregister the classes */
5346 UnregisterClass(AppName, hInstance);
5348 /* Destroy the icon */
5349 if (hIcon) DestroyIcon(hIcon);
5357 /*** Various hooks ***/
5361 * Display warning message (see "z-util.c")
5363 static void hook_plog(cptr str)
5369 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
5370 MB_ICONEXCLAMATION | MB_OK);
5372 MessageBox(data[0].w, str, "Warning",
5373 MB_ICONEXCLAMATION | MB_OK);
5381 * Display error message and quit (see "z-util.c")
5383 static void hook_quit(cptr str)
5388 /* Give a warning */
5392 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
5393 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5395 MessageBox(data[0].w, str, "Error",
5396 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5402 /* Save the preferences */
5406 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
5408 /* Destroy all windows */
5409 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5411 term_force_font(&data[i], NULL);
5412 if (data[i].font_want) string_free(data[i].font_want);
5413 if (data[i].w) DestroyWindow(data[i].w);
5417 /* Free the bitmap stuff */
5419 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5420 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5422 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5423 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5425 #endif /* USE_GRAPHICS */
5427 /*** Free some other stuff ***/
5429 DeleteObject(hbrYellow);
5434 if (hPal) DeleteObject(hPal);
5436 UnregisterClass(AppName, hInstance);
5438 if (hIcon) DestroyIcon(hIcon);
5445 /*** Initialize ***/
5451 static void init_stuff(void)
5458 /* Get program name with full path */
5459 GetModuleFileName(hInstance, path, 512);
5461 /* Save the "program name" XXX XXX XXX */
5464 /* Get the name of the "*.ini" file */
5465 strcpy(path + strlen(path) - 4, ".INI");
5467 /* Save the the name of the ini-file */
5468 ini_file = string_make(path);
5470 /* Analyze the path */
5476 if (path[i] == '\\')
5483 /* Add "lib" to the path */
5484 strcpy(path + i + 1, "lib\\");
5486 /* Validate the path */
5487 validate_dir(path, TRUE);
5489 /* Init the file paths */
5490 init_file_paths(path);
5492 /* Hack -- Validate the paths */
5493 validate_dir(ANGBAND_DIR_APEX, FALSE);
5494 validate_dir(ANGBAND_DIR_BONE, FALSE);
5496 /* Allow missing 'edit' directory */
5497 if (!check_dir(ANGBAND_DIR_EDIT))
5499 /* Must have 'data'! */
5500 validate_dir(ANGBAND_DIR_DATA, TRUE);
5504 /* Don't need 'data' */
5505 validate_dir(ANGBAND_DIR_DATA, FALSE);
5508 validate_dir(ANGBAND_DIR_FILE, TRUE);
5509 validate_dir(ANGBAND_DIR_HELP, FALSE);
5510 validate_dir(ANGBAND_DIR_INFO, FALSE);
5511 validate_dir(ANGBAND_DIR_PREF, TRUE);
5512 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5513 validate_dir(ANGBAND_DIR_USER, TRUE);
5514 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5516 /* Build the filename */
5518 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
5520 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
5524 /* Hack -- Validate the "news.txt" file */
5525 validate_file(path);
5528 #if 0 /* #ifndef JP */
5529 /* Build the "font" path */
5530 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5532 /* Allocate the path */
5533 ANGBAND_DIR_XTRA_FONT = string_make(path);
5535 /* Validate the "font" directory */
5536 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5538 /* Build the filename */
5539 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5541 /* Hack -- Validate the basic font */
5542 validate_file(path);
5548 /* Build the "graf" path */
5549 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5551 /* Allocate the path */
5552 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5554 /* Validate the "graf" directory */
5555 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5557 #endif /* USE_GRAPHICS */
5562 /* Build the "sound" path */
5563 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5565 /* Allocate the path */
5566 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5568 /* Validate the "sound" directory */
5569 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5571 #endif /* USE_SOUND */
5575 /* Build the "music" path */
5576 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5578 /* Allocate the path */
5579 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5581 /* Validate the "music" directory */
5582 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5584 #endif /* USE_MUSIC */
5586 /* Build the "help" path */
5587 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5589 /* Allocate the path */
5590 ANGBAND_DIR_XTRA_HELP = string_make(path);
5592 /* Validate the "help" directory */
5593 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5596 bool is_already_running()
5598 bool result = FALSE;
5601 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5602 if (GetLastError() == ERROR_ALREADY_EXISTS)
5610 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5611 LPSTR lpCmdLine, int nCmdShow)
5619 setlocale( LC_ALL, "ja_JP" );
5628 /* Prevent multiple run */
5629 if (is_already_running())
5632 _("ÊѶòÈÚÅܤϤ¹¤Ç¤Ëµ¯Æ°¤·¤Æ¤¤¤Þ¤¹¡£", "Hengband is already running."),
5633 _("¥¨¥é¡¼¡ª", "Error") ,
5634 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5639 if (hPrevInst == NULL)
5641 wc.style = CS_CLASSDC;
5642 wc.lpfnWndProc = AngbandWndProc;
5644 wc.cbWndExtra = 4; /* one long pointer to term_data */
5645 wc.hInstance = hInst;
5646 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5647 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5648 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5649 wc.lpszMenuName = AppName;
5650 wc.lpszClassName = AppName;
5652 if (!RegisterClass(&wc)) exit(1);
5654 wc.lpfnWndProc = AngbandListProc;
5655 wc.lpszMenuName = NULL;
5656 wc.lpszClassName = AngList;
5658 if (!RegisterClass(&wc)) exit(2);
5662 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5663 wc.lpfnWndProc = AngbandSaverProc;
5665 wc.lpszMenuName = NULL;
5666 wc.lpszClassName = "WindowsScreenSaverClass";
5668 if (!RegisterClass(&wc)) exit(3);
5674 /* Temporary hooks */
5675 plog_aux = hack_plog;
5676 quit_aux = hack_quit;
5677 core_aux = hack_quit;
5679 /* Prepare the filepaths */
5682 /* Initialize the keypress analyzer */
5683 for (i = 0; special_key_list[i]; ++i)
5685 special_key[special_key_list[i]] = TRUE;
5687 /* Initialize the keypress analyzer */
5688 for (i = 0; ignore_key_list[i]; ++i)
5690 ignore_key[ignore_key_list[i]] = TRUE;
5693 /* Determine if display is 16/256/true color */
5695 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5696 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5697 ReleaseDC(NULL, hdc);
5699 /* Initialize the colors */
5700 for (i = 0; i < 256; i++)
5704 /* Extract desired values */
5705 rv = angband_color_table[i][1];
5706 gv = angband_color_table[i][2];
5707 bv = angband_color_table[i][3];
5709 /* Extract the "complex" code */
5710 win_clr[i] = PALETTERGB(rv, gv, bv);
5712 /* Save the "simple" code */
5713 angband_color_table[i][0] = win_pal[i];
5716 /* Prepare the windows */
5722 /* Activate hooks */
5723 plog_aux = hook_plog;
5724 quit_aux = hook_quit;
5725 core_aux = hook_quit;
5727 /* Set the system suffix */
5728 ANGBAND_SYS = "win";
5730 /* Set the keyboard suffix */
5731 if (7 != GetKeyboardType(0))
5732 ANGBAND_KEYBOARD = "0";
5735 /* Japanese keyboard */
5736 switch (GetKeyboardType(1))
5738 case 0x0D01: case 0x0D02:
5739 case 0x0D03: case 0x0D04:
5740 case 0x0D05: case 0x0D06:
5742 ANGBAND_KEYBOARD = "NEC98";
5746 ANGBAND_KEYBOARD = "JAPAN";
5750 /* Catch nasty signals */
5756 /* We are now initialized */
5759 if(lpCmdLine[0] == '-'){
5760 switch(lpCmdLine[1])
5765 if (!lpCmdLine[2]) break;
5766 chuukei_server = TRUE;
5767 if(connect_chuukei_server(&lpCmdLine[2])<0){
5768 msg_print("connect fail");
5771 msg_print("connect");
5779 if (!lpCmdLine[2]) break;
5780 chuukei_client = TRUE;
5781 connect_chuukei_server(&lpCmdLine[2]);
5789 if (!lpCmdLine[2]) break;
5790 prepare_browse_movie(&lpCmdLine[2]);
5800 /* Did the user double click on a save file? */
5801 if(!chuukei_server) check_for_save_file(lpCmdLine);
5803 /* Did the user double click on a save file? */
5804 check_for_save_file(lpCmdLine);
5807 /* Prompt the user */
5809 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5811 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5816 /* Process messages forever */
5817 while (GetMessage(&msg, NULL, 0, 0))
5819 TranslateMessage(&msg);
5820 DispatchMessage(&msg);
5831 #endif /* WINDOWS */