1 /* File: main-win.c */
4 * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies.
13 * This file helps Angband work with Windows computers.
15 * To use this file, use an appropriate "Makefile" or "Project File",
16 * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
17 * make sure to obtain various extra files as described below.
19 * The official compilation uses the CodeWarrior Pro compiler, which
20 * includes a special project file and precompilable header file.
23 * See also "main-dos.c" and "main-ibm.c".
26 * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
27 * and/or color redefinitions.
29 * The "lib/user/font-win.prf" contains attr/char mappings for use with the
30 * normal "lib/xtra/font/*.fon" font files.
32 * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
33 * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
37 * Compiling this file, and using the resulting executable, requires
38 * several extra files not distributed with the standard Angband code.
39 * If "USE_GRAPHICS" is defined, then "readdib.h" and "readdib.c" must
40 * be placed into "src/", and the "8X8.BMP" bitmap file must be placed
41 * into "lib/xtra/graf". In any case, some "*.fon" files (including
42 * "8X13.FON" if nothing else) must be placed into "lib/xtra/font/".
43 * If "USE_SOUND" is defined, then some special library (for example,
44 * "winmm.lib") may need to be linked in, and desired "*.WAV" sound
45 * files must be placed into "lib/xtra/sound/". All of these extra
46 * files can be found in the "ext-win" archive.
49 * The "Term_xtra_win_clear()" function should probably do a low-level
50 * clear of the current window, and redraw the borders and other things,
51 * if only for efficiency. XXX XXX XXX
53 * A simpler method is needed for selecting the "tile size" for windows.
56 * The various "warning" messages assume the existance of the "screen.w"
57 * window, I think, and only a few calls actually check for its existance,
58 * this may be okay since "NULL" means "on top of all windows". (?) The
59 * user must never be allowed to "hide" the main window, or the "menubar"
60 * will disappear. XXX XXX XXX
62 * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
63 * use with the "winhelp.exe" program. These files *may* be available
64 * at the ftp site somewhere, but I have not seen them. XXX XXX XXX
67 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
69 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
71 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
72 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
84 * Extract the "WIN32" flag from the compiler
86 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
94 * Hack -- allow use of "screen saver" mode
100 * Menu constants -- see "ANGBAND.RC"
103 #define IDM_FILE_NEW 100
104 #define IDM_FILE_OPEN 101
105 #define IDM_FILE_SAVE 110
106 #define IDM_FILE_SCORE 120
107 #define IDM_FILE_MOVIE 121
108 #define IDM_FILE_EXIT 130
110 #define IDM_WINDOW_VIS_0 200
111 #define IDM_WINDOW_VIS_1 201
112 #define IDM_WINDOW_VIS_2 202
113 #define IDM_WINDOW_VIS_3 203
114 #define IDM_WINDOW_VIS_4 204
115 #define IDM_WINDOW_VIS_5 205
116 #define IDM_WINDOW_VIS_6 206
117 #define IDM_WINDOW_VIS_7 207
119 #define IDM_WINDOW_FONT_0 210
120 #define IDM_WINDOW_FONT_1 211
121 #define IDM_WINDOW_FONT_2 212
122 #define IDM_WINDOW_FONT_3 213
123 #define IDM_WINDOW_FONT_4 214
124 #define IDM_WINDOW_FONT_5 215
125 #define IDM_WINDOW_FONT_6 216
126 #define IDM_WINDOW_FONT_7 217
128 #define IDM_WINDOW_POS_0 220
129 #define IDM_WINDOW_POS_1 221
130 #define IDM_WINDOW_POS_2 222
131 #define IDM_WINDOW_POS_3 223
132 #define IDM_WINDOW_POS_4 224
133 #define IDM_WINDOW_POS_5 225
134 #define IDM_WINDOW_POS_6 226
135 #define IDM_WINDOW_POS_7 227
137 #define IDM_WINDOW_BIZ_0 230
138 #define IDM_WINDOW_BIZ_1 231
139 #define IDM_WINDOW_BIZ_2 232
140 #define IDM_WINDOW_BIZ_3 233
141 #define IDM_WINDOW_BIZ_4 234
142 #define IDM_WINDOW_BIZ_5 235
143 #define IDM_WINDOW_BIZ_6 236
144 #define IDM_WINDOW_BIZ_7 237
146 #define IDM_WINDOW_I_WID_0 240
147 #define IDM_WINDOW_I_WID_1 241
148 #define IDM_WINDOW_I_WID_2 242
149 #define IDM_WINDOW_I_WID_3 243
150 #define IDM_WINDOW_I_WID_4 244
151 #define IDM_WINDOW_I_WID_5 245
152 #define IDM_WINDOW_I_WID_6 246
153 #define IDM_WINDOW_I_WID_7 247
155 #define IDM_WINDOW_D_WID_0 250
156 #define IDM_WINDOW_D_WID_1 251
157 #define IDM_WINDOW_D_WID_2 252
158 #define IDM_WINDOW_D_WID_3 253
159 #define IDM_WINDOW_D_WID_4 254
160 #define IDM_WINDOW_D_WID_5 255
161 #define IDM_WINDOW_D_WID_6 256
162 #define IDM_WINDOW_D_WID_7 257
164 #define IDM_WINDOW_I_HGT_0 260
165 #define IDM_WINDOW_I_HGT_1 261
166 #define IDM_WINDOW_I_HGT_2 262
167 #define IDM_WINDOW_I_HGT_3 263
168 #define IDM_WINDOW_I_HGT_4 264
169 #define IDM_WINDOW_I_HGT_5 265
170 #define IDM_WINDOW_I_HGT_6 266
171 #define IDM_WINDOW_I_HGT_7 267
173 #define IDM_WINDOW_D_HGT_0 270
174 #define IDM_WINDOW_D_HGT_1 271
175 #define IDM_WINDOW_D_HGT_2 272
176 #define IDM_WINDOW_D_HGT_3 273
177 #define IDM_WINDOW_D_HGT_4 274
178 #define IDM_WINDOW_D_HGT_5 275
179 #define IDM_WINDOW_D_HGT_6 276
180 #define IDM_WINDOW_D_HGT_7 277
182 #define IDM_OPTIONS_NO_GRAPHICS 400
183 #define IDM_OPTIONS_OLD_GRAPHICS 401
184 #define IDM_OPTIONS_NEW_GRAPHICS 402
185 #define IDM_OPTIONS_NEW2_GRAPHICS 403
186 #define IDM_OPTIONS_BIGTILE 409
187 #define IDM_OPTIONS_SOUND 410
188 #define IDM_OPTIONS_MUSIC 411
189 #define IDM_OPTIONS_SAVER 420
190 #define IDM_OPTIONS_MAP 430
191 #define IDM_OPTIONS_BG 440
192 #define IDM_OPTIONS_OPEN_BG 441
194 #define IDM_DUMP_SCREEN_HTML 450
196 #define IDM_HELP_CONTENTS 901
201 * This may need to be removed for some compilers XXX XXX XXX
208 * Exclude parts of WINDOWS.H that are not needed
210 #define NOCOMM /* Comm driver APIs and definitions */
211 #define NOLOGERROR /* LogError() and related definitions */
212 #define NOPROFILER /* Profiler APIs */
213 #define NOLFILEIO /* _l* file I/O routines */
214 #define NOOPENFILE /* OpenFile and related definitions */
215 #define NORESOURCE /* Resource management */
216 #define NOATOM /* Atom management */
217 #define NOLANGUAGE /* Character test routines */
218 #define NOLSTRING /* lstr* string management routines */
219 #define NODBCS /* Double-byte character set routines */
220 #define NOKEYBOARDINFO /* Keyboard driver routines */
221 #define NOCOLOR /* COLOR_* color values */
222 #define NODRAWTEXT /* DrawText() and related definitions */
223 #define NOSCALABLEFONT /* Truetype scalable font support */
224 #define NOMETAFILE /* Metafile support */
225 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
226 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
227 #define NOKEYSTATES /* MK_* message key state flags */
228 #define NOWH /* SetWindowsHook and related WH_* definitions */
229 #define NOCLIPBOARD /* Clipboard APIs and definitions */
230 #define NOICONS /* IDI_* icon IDs */
231 #define NOMDI /* MDI support */
232 #define NOHELP /* Help support */
234 /* Not defined since it breaks Borland C++ 5.5 */
235 /* #define NOCTLMGR */ /* Control management and controls */
238 * Exclude parts of WINDOWS.H that are not needed (Win32)
240 #define WIN32_LEAN_AND_MEAN
241 #define NONLS /* All NLS defines and routines */
242 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
243 #define NOKANJI /* Kanji support stuff. */
244 #define NOMCX /* Modem Configuration Extensions */
247 * Include the "windows" support file
252 * Exclude parts of MMSYSTEM.H that are not needed
254 #define MMNODRV /* Installable driver support */
255 #define MMNOWAVE /* Waveform support */
256 #define MMNOMIDI /* MIDI support */
257 #define MMNOAUX /* Auxiliary audio support */
258 #define MMNOTIMER /* Timer support */
259 #define MMNOJOY /* Joystick support */
260 #define MMNOMCI /* MCI support */
261 #define MMNOMMIO /* Multimedia file I/O support */
262 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
265 * Include some more files. Note: the Cygnus Cygwin compiler
266 * doesn't use mmsystem.h instead it includes the winmm library
267 * which performs a similar function.
269 #include <mmsystem.h>
273 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
274 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
276 /* #define HTML_HELP */
279 #include <htmlhelp.h>
280 #endif /* HTML_HELP */
283 * Include the support for loading bitmaps
286 # include "readdib.h"
290 * Hack -- Fake declarations from "dos.h" XXX XXX XXX
293 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
295 #define FA_LABEL 0x08 /* Volume label */
296 #define FA_DIREC 0x10 /* Directory */
297 unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
301 * Silliness in WIN32 drawing routine
304 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
308 * Silliness for Windows 95
310 #ifndef WS_EX_TOOLWINDOW
311 # define WS_EX_TOOLWINDOW 0
315 * Foreground color bits (hard-coded by DOS)
317 #define VID_BLACK 0x00
318 #define VID_BLUE 0x01
319 #define VID_GREEN 0x02
320 #define VID_CYAN 0x03
322 #define VID_MAGENTA 0x05
323 #define VID_YELLOW 0x06
324 #define VID_WHITE 0x07
327 * Bright text (hard-coded by DOS)
329 #define VID_BRIGHT 0x08
332 * Background color bits (hard-coded by DOS)
334 #define VUD_BLACK 0x00
335 #define VUD_BLUE 0x10
336 #define VUD_GREEN 0x20
337 #define VUD_CYAN 0x30
339 #define VUD_MAGENTA 0x50
340 #define VUD_YELLOW 0x60
341 #define VUD_WHITE 0x70
344 * Blinking text (hard-coded by DOS)
346 #define VUD_BRIGHT 0x80
352 typedef struct _term_data term_data;
357 * Note the use of "font_want" for the names of the font file requested by
358 * the user, and the use of "font_file" for the currently active font file.
360 * The "font_file" is uppercased, and takes the form "8X13.FON", while
361 * "font_want" can be in almost any form as long as it could be construed
362 * as attempting to represent the name of a font.
377 uint rows; /* int -> uint */
413 #if 1 /* #ifdef JP */
428 * Maximum number of windows XXX XXX XXX
430 #define MAX_TERM_DATA 8
433 * An array of term_data's
435 static term_data data[MAX_TERM_DATA];
438 * Hack -- global "window creation" pointer
440 static term_data *my_td;
443 * Remember normal size of main window when maxmized
448 * was main window maximized on previous playing
450 bool win_maximized = FALSE;
455 bool game_in_progress = FALSE;
458 * note when "open"/"new" become valid
460 bool initialized = FALSE;
463 * screen paletted, i.e. 256 colors
465 bool paletted = FALSE;
468 * 16 colors screen, don't use RGB()
470 bool colors16 = FALSE;
473 * Saved instance handle
475 static HINSTANCE hInstance;
478 * Yellow brush for the cursor
480 static HBRUSH hbrYellow;
490 static HPALETTE hPal;
493 static HBITMAP hBG = NULL;
494 static int use_bg = 0;
495 static char bg_bitmap_file[1024] = "bg.bmp";
500 * The screen saver window
502 static HWND hwndSaver;
504 #endif /* USE_SAVER */
510 * Flag set once "graphics" has been initialized
512 static bool can_use_graphics = FALSE;
517 static DIBINIT infGraph;
520 * The global bitmap mask
522 static DIBINIT infMask;
524 #endif /* USE_GRAPHICS */
530 * Flag set once "sound" has been initialized
532 static bool can_use_sound = FALSE;
536 * An array of sound file names
538 static cptr sound_file[SOUND_MAX][SAMPLE_MAX];
540 #endif /* USE_SOUND */
546 #define SAMPLE_MUSIC_MAX 16
547 static cptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
548 static cptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
549 static cptr town_music_file[1000][SAMPLE_MUSIC_MAX];
550 static cptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
551 static bool can_use_music = FALSE;
553 static MCI_OPEN_PARMS mop;
554 static char mci_device_type[256];
556 #endif /* USE_MUSIC */
560 * Full path to ANGBAND.INI
562 static cptr ini_file = NULL;
565 * Name of application
567 static cptr AppName = "ANGBAND";
570 * Name of sub-window type
572 static cptr AngList = "AngList";
577 static cptr ANGBAND_DIR_XTRA_GRAF;
578 static cptr ANGBAND_DIR_XTRA_SOUND;
579 static cptr ANGBAND_DIR_XTRA_MUSIC;
580 static cptr ANGBAND_DIR_XTRA_HELP;
581 #if 0 /* #ifndef JP */
582 static cptr ANGBAND_DIR_XTRA_FONT;
585 static cptr ANGBAND_DIR_XTRA_MUSIC;
590 * The "complex" color values
592 static COLORREF win_clr[256];
596 * Flag for macro trigger with dump ASCII
598 static bool Term_no_press = FALSE;
603 static bool mouse_down = FALSE;
604 static bool paint_rect = FALSE;
605 static int mousex = 0, mousey = 0;
606 static int oldx, oldy;
610 * The "simple" color values
612 * See "main-ibm.c" for original table information
614 * The entries below are taken from the "color bits" defined above.
616 * Note that many of the choices below suck, but so do crappy monitors.
618 static BYTE win_pal[256] =
620 VID_BLACK, /* Dark */
621 VID_WHITE, /* White */
622 VID_CYAN, /* Slate XXX */
623 VID_RED | VID_BRIGHT, /* Orange XXX */
625 VID_GREEN, /* Green */
627 VID_YELLOW, /* Umber XXX */
628 VID_BLACK | VID_BRIGHT, /* Light Dark */
629 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
630 VID_MAGENTA, /* Violet XXX */
631 VID_YELLOW | VID_BRIGHT, /* Yellow */
632 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
633 VID_GREEN | VID_BRIGHT, /* Light Green */
634 VID_BLUE | VID_BRIGHT, /* Light Blue */
635 VID_YELLOW /* Light Umber XXX */
640 * Hack -- define which keys are "special"
642 static bool special_key[256];
643 static bool ignore_key[256];
647 * Hack -- initialization list for "special_key"
649 static byte special_key_list[] = {
650 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
651 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
652 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
653 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
654 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
655 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
656 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
657 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
658 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
659 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
660 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
661 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
662 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
663 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
664 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
665 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
666 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
671 static byte ignore_key_list[] = {
672 VK_ESCAPE, VK_TAB, VK_SPACE,
673 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
674 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
675 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
681 * Hack -- initialization list for "special_key"
683 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
684 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
685 * catch the keypad keys (with and without numlock set, including keypad 5),
686 * the function keys (including the "menu" key which maps to F10), and the
687 * "pause" key (between scroll lock and numlock). We also catch a few odd
688 * keys which I do not recognize, but which are listed among keys which we
689 * do catch, so they should be harmless to catch.
691 static byte special_key_list[] =
693 VK_CLEAR, /* 0x0C (KP<5>) */
695 VK_PAUSE, /* 0x13 (pause) */
697 VK_PRIOR, /* 0x21 (KP<9>) */
698 VK_NEXT, /* 0x22 (KP<3>) */
699 VK_END, /* 0x23 (KP<1>) */
700 VK_HOME, /* 0x24 (KP<7>) */
701 VK_LEFT, /* 0x25 (KP<4>) */
702 VK_UP, /* 0x26 (KP<8>) */
703 VK_RIGHT, /* 0x27 (KP<6>) */
704 VK_DOWN, /* 0x28 (KP<2>) */
705 VK_SELECT, /* 0x29 (?????) */
706 VK_PRINT, /* 0x2A (?????) */
707 VK_EXECUTE, /* 0x2B (?????) */
708 VK_SNAPSHOT, /* 0x2C (?????) */
709 VK_INSERT, /* 0x2D (KP<0>) */
710 VK_DELETE, /* 0x2E (KP<.>) */
711 VK_HELP, /* 0x2F (?????) */
713 VK_NUMPAD0, /* 0x60 (KP<0>) */
714 VK_NUMPAD1, /* 0x61 (KP<1>) */
715 VK_NUMPAD2, /* 0x62 (KP<2>) */
716 VK_NUMPAD3, /* 0x63 (KP<3>) */
717 VK_NUMPAD4, /* 0x64 (KP<4>) */
718 VK_NUMPAD5, /* 0x65 (KP<5>) */
719 VK_NUMPAD6, /* 0x66 (KP<6>) */
720 VK_NUMPAD7, /* 0x67 (KP<7>) */
721 VK_NUMPAD8, /* 0x68 (KP<8>) */
722 VK_NUMPAD9, /* 0x69 (KP<9>) */
723 VK_MULTIPLY, /* 0x6A (KP<*>) */
724 VK_ADD, /* 0x6B (KP<+>) */
725 VK_SEPARATOR, /* 0x6C (?????) */
726 VK_SUBTRACT, /* 0x6D (KP<->) */
727 VK_DECIMAL, /* 0x6E (KP<.>) */
728 VK_DIVIDE, /* 0x6F (KP</>) */
759 static void delete_bg(void)
768 static int init_bg(void)
770 char * bmfile = bg_bitmap_file;
773 if (use_bg == 0) return 0;
775 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
777 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
782 HDC wnddc, dcimage, dcbg;
783 HBITMAP bmimage, bmimage_old, bmbg_old;
789 dcimage = CreateCompatibleDC(wnddc);
790 dcbg = CreateCompatibleDC(wnddc);
792 bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
793 if (!bmimage) quit("bg.bmpが読みこめない!");
794 bmimage_old = SelectObject(dcimage, bmimage);
796 CreateCompatibleBitmap();
798 ReleaseDC(hwnd, wnddc);
804 static void DrawBG(HDC hdc, RECT *r)
809 int x = r->left, y = r->top;
810 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
816 GetObject(hBG, sizeof(bm), &bm);
817 swid = bm.bmWidth; shgt = bm.bmHeight;
819 hdcSrc = CreateCompatibleDC(hdc);
820 hOld = SelectObject(hdcSrc, hBG);
824 cwid = MIN(swid - sx, r->right - nx);
827 chgt = MIN(shgt - sy, r->bottom - ny);
828 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
830 } while (ny < r->bottom);
833 } while (nx < r->right);
835 SelectObject(hdcSrc, hOld);
841 * Hack -- given a pathname, point at the filename
843 static cptr extract_file_name(cptr s)
847 /* Start at the end */
848 p = s + strlen(s) - 1;
850 /* Back up to divider */
851 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
853 /* Return file name */
860 * Hack -- given a simple filename, extract the "font size" info
862 * Return a pointer to a static buffer holding the capitalized base name.
864 #if 0 /* #ifndef JP */
865 static char *analyze_font(char *path, int *wp, int *hp)
871 /* Start at the end */
872 p = path + strlen(path) - 1;
874 /* Back up to divider */
875 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
877 /* Advance to file name */
883 /* Capitalize (be paranoid) */
884 if (islower(*s)) *s = toupper(*s);
888 s = my_strchr(p, 'X');
890 /* Extract font width */
894 hgt = s ? atoi(s+1) : 0;
907 * Check for existance of a file
909 static bool check_file(cptr s)
929 attrib = GetFileAttributes(path);
931 /* Require valid filename */
932 if (attrib == INVALID_FILE_NAME) return (FALSE);
934 /* Prohibit directory */
935 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
939 /* Examine and verify */
940 if (_dos_getfileattr(path, &attrib)) return (FALSE);
942 /* Prohibit something */
943 if (attrib & FA_LABEL) return (FALSE);
945 /* Prohibit directory */
946 if (attrib & FA_DIREC) return (FALSE);
956 * Check for existance of a directory
958 static bool check_dir(cptr s)
980 /* Remove trailing backslash */
981 if (i && (path[i-1] == '\\')) path[--i] = '\0';
986 attrib = GetFileAttributes(path);
988 /* Require valid filename */
989 if (attrib == INVALID_FILE_NAME) return (FALSE);
991 /* Require directory */
992 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
996 /* Examine and verify */
997 if (_dos_getfileattr(path, &attrib)) return (FALSE);
999 /* Prohibit something */
1000 if (attrib & FA_LABEL) return (FALSE);
1002 /* Require directory */
1003 if (!(attrib & FA_DIREC)) return (FALSE);
1015 static void validate_file(cptr s)
1017 /* Verify or fail */
1020 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
1026 * Validate a directory
1028 static void validate_dir(cptr s, bool vital)
1030 /* Verify or fail */
1033 /* This directory contains needed data */
1036 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
1038 /* Attempt to create this directory */
1041 quit_fmt("Unable to create directory:\n%s", s);
1048 * Get the "size" for a window
1050 static void term_getsize(term_data *td)
1057 if (td->cols < 1) td->cols = 1;
1058 if (td->rows < 1) td->rows = 1;
1061 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1062 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1064 /* Fake window size */
1066 rc.right = rc.left + wid;
1068 rc.bottom = rc.top + hgt;
1071 /* rc.right += 1; */
1072 /* rc.bottom += 1; */
1075 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1078 td->size_wid = rc.right - rc.left;
1079 td->size_hgt = rc.bottom - rc.top;
1081 /* See CreateWindowEx */
1084 /* Extract actual location */
1085 GetWindowRect(td->w, &rc);
1087 /* Save the location */
1088 td->pos_x = rc.left;
1094 * Write the "prefs" for a single term
1096 static void save_prefs_aux(int i)
1098 term_data *td = &data[i];
1103 WINDOWPLACEMENT lpwndpl;
1108 /* Make section name */
1109 sprintf(sec_name, "Term-%d", i);
1114 strcpy(buf, td->visible ? "1" : "0");
1115 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1120 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "MS ゴシック");
1123 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1125 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1129 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1131 #if 1 /* #ifdef JP */
1132 wsprintf(buf, "%d", td->lf.lfWidth);
1133 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1134 wsprintf(buf, "%d", td->lf.lfHeight);
1135 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1136 wsprintf(buf, "%d", td->lf.lfWeight);
1137 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1140 strcpy(buf, td->bizarre ? "1" : "0");
1141 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1144 wsprintf(buf, "%d", td->tile_wid);
1145 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1148 wsprintf(buf, "%d", td->tile_hgt);
1149 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1151 /* Get window placement and dimensions */
1152 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1153 GetWindowPlacement(td->w, &lpwndpl);
1155 /* Acquire position in *normal* mode (not minimized) */
1156 rc = lpwndpl.rcNormalPosition;
1158 /* Window size (x) */
1159 if (i == 0) wsprintf(buf, "%d", normsize.x);
1160 else wsprintf(buf, "%d", td->cols);
1161 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1163 /* Window size (y) */
1164 if (i == 0) wsprintf(buf, "%d", normsize.y);
1165 else wsprintf(buf, "%d", td->rows);
1166 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1168 /* Maxmized (only main window) */
1171 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1172 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1175 /* Acquire position */
1176 GetWindowRect(td->w, &rc);
1178 /* Window position (x) */
1179 wsprintf(buf, "%d", rc.left);
1180 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1182 /* Window position (y) */
1183 wsprintf(buf, "%d", rc.top);
1184 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1186 /* Window Z position */
1189 strcpy(buf, td->posfix ? "1" : "0");
1190 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1198 * We assume that the windows have all been initialized
1200 static void save_prefs(void)
1206 /* Save the "arg_graphics" flag */
1207 sprintf(buf, "%d", arg_graphics);
1208 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1210 /* Save the "arg_bigtile" flag */
1211 strcpy(buf, arg_bigtile ? "1" : "0");
1212 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1214 /* Save the "arg_sound" flag */
1215 strcpy(buf, arg_sound ? "1" : "0");
1216 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1218 /* Save the "arg_sound" flag */
1219 strcpy(buf, arg_music ? "1" : "0");
1220 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1223 strcpy(buf, use_bg ? "1" : "0");
1224 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1225 WritePrivateProfileString("Angband", "BackGroundBitmap",
1226 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1228 /* Save window prefs */
1229 for (i = 0; i < MAX_TERM_DATA; ++i)
1237 * Load the "prefs" for a single term
1239 static void load_prefs_aux(int i)
1241 term_data *td = &data[i];
1245 int wid, hgt, posx, posy;
1246 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1247 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1251 /* Make section name */
1252 sprintf(sec_name, "Term-%d", i);
1254 /* Make section name */
1255 sprintf(sec_name, "Term-%d", i);
1260 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1263 /* Desired font, with default */
1265 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
1268 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1270 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1276 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1278 /* Analyze font, save desired font name */
1279 #if 1 /* #ifdef JP */
1280 td->font_want = string_make(tmp);
1282 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1283 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1284 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1286 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1291 #if 1 /* #ifdef JP */
1292 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1293 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1295 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1296 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1301 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1302 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1303 normsize.x = td->cols; normsize.y = td->rows;
1308 win_maximized = GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file);
1311 /* Window position */
1312 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1313 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1314 td->pos_x = MIN(MAX(0, posx), dispx-128);
1315 td->pos_y = MIN(MAX(0, posy), dispy-128);
1317 /* Window Z position */
1320 td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1328 static void load_prefs(void)
1332 /* Extract the "arg_graphics" flag */
1333 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1335 /* Extract the "arg_bigtile" flag */
1336 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1337 use_bigtile = arg_bigtile;
1339 /* Extract the "arg_sound" flag */
1340 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1342 /* Extract the "arg_sound" flag */
1343 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1346 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1347 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1349 /* Load window prefs */
1350 for (i = 0; i < MAX_TERM_DATA; ++i)
1356 #if defined(USE_SOUND) || defined(USE_MUSIC)
1359 * XXX XXX XXX - Taken from files.c.
1361 * Extract "tokens" from a buffer
1363 * This function uses "whitespace" as delimiters, and treats any amount of
1364 * whitespace as a single delimiter. We will never return any empty tokens.
1365 * When given an empty buffer, or a buffer containing only "whitespace", we
1366 * will return no tokens. We will never extract more than "num" tokens.
1368 * By running a token through the "text_to_ascii()" function, you can allow
1369 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1371 * We save pointers to the tokens in "tokens", and return the number found.
1373 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1385 /* Skip leading whitespace */
1386 for ( ; *s && iswspace(*s); ++s) /* loop */;
1391 /* Find next whitespace, if any */
1392 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1394 /* Nuke and advance (if necessary) */
1395 if (*t) *t++ = '\0';
1397 /* Save the token */
1408 #endif /* USE_SOUND || USE_MUSIC */
1412 static void load_sound_prefs(void)
1416 char ini_path[1024];
1417 char wav_path[1024];
1418 char *zz[SAMPLE_MAX];
1420 /* Access the sound.cfg */
1422 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1424 for (i = 0; i < SOUND_MAX; i++)
1426 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1428 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1430 for (j = 0; j < num; j++)
1432 /* Access the sound */
1433 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1435 /* Save the sound filename, if it exists */
1436 if (check_file(wav_path))
1437 sound_file[i][j] = string_make(zz[j]);
1442 #endif /* USE_SOUND */
1446 static void load_music_prefs(void)
1450 char ini_path[1024];
1451 char wav_path[1024];
1452 char *zz[SAMPLE_MAX];
1455 /* Access the music.cfg */
1457 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1459 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1461 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1463 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1465 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1467 for (j = 0; j < num; j++)
1469 /* Access the sound */
1470 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1472 /* Save the sound filename, if it exists */
1473 if (check_file(wav_path))
1474 music_file[i][j] = string_make(zz[j]);
1478 for (i = 0; i < max_d_idx; i++)
1480 sprintf(key, "dungeon%03d", i);
1481 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1483 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1485 for (j = 0; j < num; j++)
1487 /* Access the sound */
1488 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1490 /* Save the sound filename, if it exists */
1491 if (check_file(wav_path))
1492 dungeon_music_file[i][j] = string_make(zz[j]);
1496 for (i = 0; i < 1000; i++) /*!< @todo クエスト最大数指定 */
1498 sprintf(key, "quest%03d", i);
1499 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1501 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1503 for (j = 0; j < num; j++)
1505 /* Access the sound */
1506 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1508 /* Save the sound filename, if it exists */
1509 if (check_file(wav_path))
1510 quest_music_file[i][j] = string_make(zz[j]);
1514 for (i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1516 sprintf(key, "town%03d", i);
1517 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1519 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1521 for (j = 0; j < num; j++)
1523 /* Access the sound */
1524 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1526 /* Save the sound filename, if it exists */
1527 if (check_file(wav_path))
1528 town_music_file[i][j] = string_make(zz[j]);
1535 #endif /* USE_MUSIC */
1538 * Create the new global palette based on the bitmap palette
1539 * (if any), and the standard 16 entry palette derived from
1540 * "win_clr[]" which is used for the basic 16 Angband colors.
1542 * This function is never called before all windows are ready.
1544 * This function returns FALSE if the new palette could not be
1545 * prepared, which should normally be a fatal error. XXX XXX
1547 * Note that only some machines actually use a "palette".
1549 static int new_palette(void)
1557 LPLOGPALETTE pLogPal;
1558 LPPALETTEENTRY lppe;
1563 /* This makes no sense */
1564 if (!paletted) return (TRUE);
1574 /* Check the bitmap palette */
1575 hBmPal = infGraph.hPalette;
1577 /* Use the bitmap */
1580 lppeSize = 256 * sizeof(PALETTEENTRY);
1581 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1582 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1583 if ((nEntries == 0) || (nEntries > 220))
1586 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1589 rnfree(lppe, lppeSize);
1596 #endif /* USE_GRAPHICS */
1598 /* Size of palette */
1599 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1601 /* Allocate palette */
1602 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1605 pLogPal->palVersion = 0x300;
1607 /* Make room for bitmap and normal data */
1608 pLogPal->palNumEntries = nEntries + 16;
1610 /* Save the bitmap data */
1611 for (i = 0; i < nEntries; i++)
1613 pLogPal->palPalEntry[i] = lppe[i];
1616 /* Save the normal data */
1617 for (i = 0; i < 16; i++)
1621 /* Access the entry */
1622 p = &(pLogPal->palPalEntry[i+nEntries]);
1624 /* Save the colors */
1625 p->peRed = GetRValue(win_clr[i]);
1626 p->peGreen = GetGValue(win_clr[i]);
1627 p->peBlue = GetBValue(win_clr[i]);
1629 /* Save the flags */
1630 p->peFlags = PC_NOCOLLAPSE;
1633 /* Free something */
1634 if (lppe) rnfree(lppe, lppeSize);
1636 /* Create a new palette, or fail */
1637 hNewPal = CreatePalette(pLogPal);
1638 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1640 /* Free the palette */
1641 rnfree(pLogPal, pLogPalSize);
1646 /* Realize the palette */
1648 SelectPalette(hdc, hNewPal, 0);
1649 i = RealizePalette(hdc);
1650 ReleaseDC(td->w, hdc);
1651 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1655 for (i = 1; i < MAX_TERM_DATA; i++)
1660 SelectPalette(hdc, hNewPal, 0);
1661 ReleaseDC(td->w, hdc);
1664 /* Delete old palette */
1665 if (hPal) DeleteObject(hPal);
1667 /* Save new palette */
1677 * Initialize graphics
1679 static bool init_graphics(void)
1681 /* Initialize once */
1682 /* if (can_use_graphics != arg_graphics) */
1685 int wid, hgt, twid, thgt, ox, oy;
1688 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1698 ANGBAND_GRAF = "new";
1700 else if (arg_graphics == GRAPHICS_HENGBAND)
1720 ANGBAND_GRAF = "ne2";
1731 ANGBAND_GRAF = "old";
1734 /* Access the bitmap file */
1735 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1737 /* Load the bitmap or quit */
1738 if (!ReadDIB(data[0].w, buf, &infGraph))
1740 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1744 /* Save the new sizes */
1745 infGraph.CellWidth = wid;
1746 infGraph.CellHeight = hgt;
1747 infGraph.TileWidth = twid;
1748 infGraph.TileHeight = thgt;
1749 infGraph.OffsetX = ox;
1750 infGraph.OffsetY = oy;
1752 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1754 /* Access the mask file */
1755 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1757 /* Load the bitmap or quit */
1758 if (!ReadDIB(data[0].w, buf, &infMask))
1760 plog_fmt("Cannot read bitmap file '%s'", buf);
1764 if (arg_graphics == GRAPHICS_HENGBAND)
1766 /* Access the mask file */
1767 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1769 /* Load the bitmap or quit */
1770 if (!ReadDIB(data[0].w, buf, &infMask))
1772 plog_fmt("Cannot read bitmap file '%s'", buf);
1777 /* Activate a palette */
1780 /* Free bitmap XXX XXX XXX */
1783 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1787 /* Graphics available */
1788 can_use_graphics = arg_graphics;
1792 return (can_use_graphics);
1794 #endif /* USE_GRAPHICS */
1801 static bool init_music(void)
1803 /* Initialize once */
1806 /* Load the prefs */
1809 /* Sound available */
1810 can_use_music = TRUE;
1814 return (can_use_music);
1818 * Hack -- Stop a music
1820 static void stop_music(void)
1822 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1823 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1826 #endif /* USE_MUSIC */
1832 static bool init_sound(void)
1834 /* Initialize once */
1837 /* Load the prefs */
1840 /* Sound available */
1841 can_use_sound = TRUE;
1845 return (can_use_sound);
1847 #endif /* USE_SOUND */
1853 static void term_window_resize(term_data *td)
1855 /* Require window */
1858 /* Resize the window */
1859 SetWindowPos(td->w, 0, 0, 0,
1860 td->size_wid, td->size_hgt,
1861 SWP_NOMOVE | SWP_NOZORDER);
1864 InvalidateRect(td->w, NULL, TRUE);
1869 * Force the use of a new "font file" for a term_data
1871 * This function may be called before the "window" is ready
1873 * This function returns zero only if everything succeeds.
1875 * Note that the "font name" must be capitalized!!!
1877 static errr term_force_font(term_data *td, cptr path)
1881 #if 0 /* #ifndef JP */
1887 /* Forget the old font (if needed) */
1888 if (td->font_id) DeleteObject(td->font_id);
1890 #if 1 /* #ifdef JP */
1894 /* Create the font (using the 'base' of the font file name!) */
1895 td->font_id = CreateFontIndirect(&(td->lf));
1896 wid = td->lf.lfWidth;
1897 hgt = td->lf.lfHeight;
1898 if (!td->font_id) return (1);
1900 /* Forget old font */
1906 for (i = 0; i < MAX_TERM_DATA; i++)
1908 /* Don't check when closing the application */
1911 /* Check "screen" */
1912 if ((td != &data[i]) &&
1913 (data[i].font_file) &&
1914 (streq(data[i].font_file, td->font_file)))
1920 /* Remove unused font resources */
1921 if (!used) RemoveFontResource(td->font_file);
1923 /* Free the old name */
1924 string_free(td->font_file);
1927 td->font_file = NULL;
1931 if (!path) return (1);
1936 /* Analyze font path */
1937 base = analyze_font(buf, &wid, &hgt);
1940 if (!suffix(base, ".FON")) return (1);
1943 if (!check_file(buf)) return (1);
1945 /* Load the new font */
1946 if (!AddFontResource(buf)) return (1);
1948 /* Save new font name */
1949 td->font_file = string_make(base);
1951 /* Remove the "suffix" */
1952 base[strlen(base)-4] = '\0';
1954 /* Create the font (using the 'base' of the font file name!) */
1955 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1956 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1957 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1958 FIXED_PITCH | FF_DONTCARE, base);
1961 /* Hack -- Unknown size */
1968 /* all this trouble to get the cell size */
1969 hdcDesktop = GetDC(HWND_DESKTOP);
1970 hfOld = SelectObject(hdcDesktop, td->font_id);
1971 GetTextMetrics(hdcDesktop, &tm);
1972 SelectObject(hdcDesktop, hfOld);
1973 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1975 /* Font size info */
1976 wid = tm.tmAveCharWidth;
1980 /* Save the size info */
1991 * Allow the user to change the font for this window.
1993 static void term_change_font(term_data *td)
1995 #if 1 /* #ifdef JP */
1998 memset(&cf, 0, sizeof(cf));
1999 cf.lStructSize = sizeof(cf);
2000 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
2001 cf.lpLogFont = &(td->lf);
2003 if (ChooseFont(&cf))
2005 /* Force the font */
2006 term_force_font(td, NULL);
2008 /* Assume not bizarre */
2011 /* Reset the tile info */
2012 td->tile_wid = td->font_wid;
2013 td->tile_hgt = td->font_hgt;
2015 /* Analyze the font */
2018 /* Resize the window */
2019 term_window_resize(td);
2025 char tmp[1024] = "";
2027 /* Extract a default if possible */
2028 if (td->font_file) strcpy(tmp, td->font_file);
2030 /* Ask for a choice */
2031 memset(&ofn, 0, sizeof(ofn));
2032 ofn.lStructSize = sizeof(ofn);
2033 ofn.hwndOwner = data[0].w;
2034 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
2035 ofn.nFilterIndex = 1;
2036 ofn.lpstrFile = tmp;
2038 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
2039 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2040 ofn.lpstrDefExt = "fon";
2042 /* Force choice if legal */
2043 if (GetOpenFileName(&ofn))
2045 /* Force the font */
2046 if (term_force_font(td, tmp))
2048 /* Access the standard font file */
2049 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2051 /* Force the use of that font */
2052 (void)term_force_font(td, tmp);
2055 /* Assume not bizarre */
2056 td->bizarre = FALSE;
2058 /* Reset the tile info */
2059 td->tile_wid = td->font_wid;
2060 td->tile_hgt = td->font_hgt;
2062 /* Analyze the font */
2065 /* Resize the window */
2066 term_window_resize(td);
2073 * Allow the user to lock this window.
2075 static void term_window_pos(term_data *td, HWND hWnd)
2077 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2078 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2081 static void windows_map(void);
2084 * Hack -- redraw a term_data
2086 static void term_data_redraw(term_data *td)
2090 /* Redraw the map */
2095 /* Activate the term */
2096 Term_activate(&td->t);
2098 /* Redraw the contents */
2101 /* Restore the term */
2102 Term_activate(term_screen);
2107 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2111 HBRUSH myBrush, oldBrush;
2113 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2114 int tx = td->size_ow1 + x * td->tile_wid;
2115 int ty = td->size_oh1 + y * td->tile_hgt;
2116 int tw = w * td->tile_wid - 1;
2117 int th = h * td->tile_hgt - 1;
2120 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2121 oldBrush = SelectObject(hdc, myBrush);
2122 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2124 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2126 SelectObject(hdc, oldBrush);
2127 SelectObject(hdc, oldPen);
2132 /*** Function hooks needed by "Term" ***/
2138 * Initialize a new Term
2140 static void Term_init_win(term *t)
2149 static void Term_nuke_win(term *t)
2158 * Interact with the User
2160 static errr Term_user_win(int n)
2171 * React to global changes
2173 static errr Term_xtra_win_react(void)
2181 /* Save the default colors */
2182 for (i = 0; i < 256; i++)
2184 /* Simply accept the desired colors */
2185 win_pal[i] = angband_color_table[i][0];
2196 bool change = FALSE;
2198 /* Save the default colors */
2199 for (i = 0; i < 256; i++)
2201 /* Extract desired values */
2202 rv = angband_color_table[i][1];
2203 gv = angband_color_table[i][2];
2204 bv = angband_color_table[i][3];
2206 /* Extract a full color code */
2207 code = PALETTERGB(rv, gv, bv);
2209 /* Activate changes */
2210 if (win_clr[i] != code)
2212 /* Note the change */
2215 /* Apply the desired color */
2220 /* Activate the palette if needed */
2221 if (change) (void)new_palette();
2227 /* Handle "arg_sound" */
2228 if (use_sound != arg_sound)
2230 /* Initialize (if needed) */
2231 if (arg_sound && !init_sound())
2234 plog(_("サウンドを初期化できません!", "Cannot initialize sound!"));
2240 /* Change setting */
2241 use_sound = arg_sound;
2248 /* Handle "arg_sound" */
2249 if (use_music != arg_music)
2251 /* Initialize (if needed) */
2252 if (arg_music && !init_music())
2255 plog(_("BGMを初期化できません!", "Cannot initialize BGM!"));
2260 /* Change setting */
2261 use_music = arg_music;
2263 if(!arg_music) stop_music();
2264 else select_floor_music();
2273 /* Handle "arg_graphics" */
2274 if (use_graphics != arg_graphics)
2276 /* Initialize (if needed) */
2277 if (arg_graphics && !init_graphics())
2280 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
2283 arg_graphics = GRAPHICS_NONE;
2286 /* Change setting */
2287 use_graphics = arg_graphics;
2290 #ifdef ANGBAND_2_8_1
2292 #else /* ANGBAND_2_8_1 */
2293 reset_visuals(TRUE);
2294 #endif /* ANGBAND_2_8_1 */
2297 #endif /* USE_GRAPHICS */
2300 /* Clean up windows */
2301 for (i = 0; i < MAX_TERM_DATA; i++)
2305 term_data *td = &data[i];
2307 /* Update resized windows */
2308 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2311 Term_activate(&td->t);
2313 /* Hack -- Resize the term */
2314 Term_resize(td->cols, td->rows);
2316 /* Redraw the contents */
2331 * Process at least one event
2333 static errr Term_xtra_win_event(int v)
2337 /* Wait for an event */
2341 if (GetMessage(&msg, NULL, 0, 0))
2343 TranslateMessage(&msg);
2344 DispatchMessage(&msg);
2348 /* Check for an event */
2352 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2354 TranslateMessage(&msg);
2355 DispatchMessage(&msg);
2365 * Process all pending events
2367 static errr Term_xtra_win_flush(void)
2371 /* Process all pending events */
2372 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2374 TranslateMessage(&msg);
2375 DispatchMessage(&msg);
2384 * Hack -- clear the screen
2386 * Make this more efficient XXX XXX XXX
2388 static errr Term_xtra_win_clear(void)
2390 term_data *td = (term_data*)(Term->data);
2395 /* Rectangle to erase */
2396 rc.left = td->size_ow1;
2397 rc.right = rc.left + td->cols * td->tile_wid;
2398 rc.top = td->size_oh1;
2399 rc.bottom = rc.top + td->rows * td->tile_hgt;
2403 SetBkColor(hdc, RGB(0, 0, 0));
2404 SelectObject(hdc, td->font_id);
2405 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2410 rc.left = 0; rc.top = 0;
2413 ReleaseDC(td->w, hdc);
2421 * Hack -- make a noise
2423 static errr Term_xtra_win_noise(void)
2425 MessageBeep(MB_ICONASTERISK);
2431 * Hack -- make a sound
2433 static errr Term_xtra_win_sound(int v)
2438 #endif /* USE_SOUND */
2440 /* Sound disabled */
2441 if (!use_sound) return (1);
2444 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2448 /* Count the samples */
2449 for (i = 0; i < SAMPLE_MAX; i++)
2451 if (!sound_file[v][i])
2456 if (i == 0) return (1);
2458 /* Build the path */
2459 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2463 /* Play the sound, catch errors */
2464 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2468 /* Play the sound, catch errors */
2469 return (sndPlaySound(buf, SND_ASYNC));
2473 #else /* USE_SOUND */
2478 #endif /* USE_SOUND */
2482 * Hack -- play a music
2484 static errr Term_xtra_win_music(int n, int v)
2489 #endif /* USE_MUSIC */
2491 /* Sound disabled */
2492 if(!use_music) return (1);
2495 if(n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return (1);
2496 else if(v < 0 || v >= 1000) return(1); /*!< TODO */
2502 case TERM_XTRA_MUSIC_BASIC:
2503 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2505 case TERM_XTRA_MUSIC_DUNGEON:
2506 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2508 case TERM_XTRA_MUSIC_QUEST:
2509 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2511 case TERM_XTRA_MUSIC_TOWN:
2512 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2519 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2520 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2526 case TERM_XTRA_MUSIC_BASIC:
2527 for (i = 0; i < SAMPLE_MAX; i++) if(!music_file[v][i]) break;
2529 case TERM_XTRA_MUSIC_DUNGEON:
2530 for (i = 0; i < SAMPLE_MAX; i++) if(!dungeon_music_file[v][i]) break;
2532 case TERM_XTRA_MUSIC_QUEST:
2533 for (i = 0; i < SAMPLE_MAX; i++) if(!quest_music_file[v][i]) break;
2535 case TERM_XTRA_MUSIC_TOWN:
2536 for (i = 0; i < SAMPLE_MAX; i++) if(!town_music_file[v][i]) break;
2543 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2544 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2550 case TERM_XTRA_MUSIC_BASIC:
2551 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2553 case TERM_XTRA_MUSIC_DUNGEON:
2554 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
2556 case TERM_XTRA_MUSIC_QUEST:
2557 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
2559 case TERM_XTRA_MUSIC_TOWN:
2560 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
2566 mop.lpstrDeviceType = mci_device_type;
2567 mop.lpstrElementName = buf;
2568 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
2569 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
2570 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2571 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2572 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2577 #else /* USE_MUSIC */
2581 #endif /* USE_MUSIC */
2587 * Delay for "x" milliseconds
2589 static int Term_xtra_win_delay(int v)
2603 t = GetTickCount() + v;
2606 while (GetTickCount() < t)
2608 /* Handle messages */
2609 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2611 TranslateMessage(&msg);
2612 DispatchMessage(&msg);
2624 * Do a "special thing"
2626 static errr Term_xtra_win(int n, int v)
2628 /* Handle a subset of the legal requests */
2631 /* Make a bell sound */
2632 case TERM_XTRA_NOISE:
2634 return (Term_xtra_win_noise());
2638 case TERM_XTRA_MUSIC_BASIC:
2639 case TERM_XTRA_MUSIC_DUNGEON:
2640 case TERM_XTRA_MUSIC_QUEST:
2641 case TERM_XTRA_MUSIC_TOWN:
2643 return (Term_xtra_win_music(n, v));
2646 /* Make a special sound */
2647 case TERM_XTRA_SOUND:
2649 return (Term_xtra_win_sound(v));
2652 /* Process random events */
2653 case TERM_XTRA_BORED:
2655 return (Term_xtra_win_event(0));
2658 /* Process an event */
2659 case TERM_XTRA_EVENT:
2661 return (Term_xtra_win_event(v));
2664 /* Flush all events */
2665 case TERM_XTRA_FLUSH:
2667 return (Term_xtra_win_flush());
2670 /* Clear the screen */
2671 case TERM_XTRA_CLEAR:
2673 return (Term_xtra_win_clear());
2676 /* React to global changes */
2677 case TERM_XTRA_REACT:
2679 return (Term_xtra_win_react());
2682 /* Delay for some milliseconds */
2683 case TERM_XTRA_DELAY:
2685 return (Term_xtra_win_delay(v));
2696 * Low level graphics (Assumes valid input).
2698 * Draw a "cursor" at (x,y), using a "yellow box".
2700 static errr Term_curs_win(int x, int y)
2702 term_data *td = (term_data*)(Term->data);
2707 int tile_wid, tile_hgt;
2711 tile_wid = td->map_tile_wid;
2712 tile_hgt = td->map_tile_hgt;
2716 tile_wid = td->tile_wid;
2717 tile_hgt = td->tile_hgt;
2720 /* Frame the grid */
2721 rc.left = x * tile_wid + td->size_ow1;
2722 rc.right = rc.left + tile_wid;
2723 rc.top = y * tile_hgt + td->size_oh1;
2724 rc.bottom = rc.top + tile_hgt;
2726 /* Cursor is done as a yellow "box" */
2728 FrameRect(hdc, &rc, hbrYellow);
2729 ReleaseDC(td->w, hdc);
2737 * Low level graphics (Assumes valid input).
2739 * Draw a "big cursor" at (x,y), using a "yellow box".
2741 static errr Term_bigcurs_win(int x, int y)
2743 term_data *td = (term_data*)(Term->data);
2748 int tile_wid, tile_hgt;
2752 /* Normal cursor in map window */
2753 Term_curs_win(x, y);
2758 tile_wid = td->tile_wid;
2759 tile_hgt = td->tile_hgt;
2762 /* Frame the grid */
2763 rc.left = x * tile_wid + td->size_ow1;
2764 rc.right = rc.left + 2 * tile_wid;
2765 rc.top = y * tile_hgt + td->size_oh1;
2766 rc.bottom = rc.top + tile_hgt;
2768 /* Cursor is done as a yellow "box" */
2770 FrameRect(hdc, &rc, hbrYellow);
2771 ReleaseDC(td->w, hdc);
2779 * Low level graphics (Assumes valid input).
2781 * Erase a "block" of "n" characters starting at (x,y).
2783 static errr Term_wipe_win(int x, int y, int n)
2785 term_data *td = (term_data*)(Term->data);
2790 /* Rectangle to erase in client coords */
2791 rc.left = x * td->tile_wid + td->size_ow1;
2792 rc.right = rc.left + n * td->tile_wid;
2793 rc.top = y * td->tile_hgt + td->size_oh1;
2794 rc.bottom = rc.top + td->tile_hgt;
2797 SetBkColor(hdc, RGB(0, 0, 0));
2798 SelectObject(hdc, td->font_id);
2803 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2804 ReleaseDC(td->w, hdc);
2812 * Low level graphics. Assumes valid input.
2814 * Draw several ("n") chars, with an attr, at a given location.
2816 * All "graphic" data is handled by "Term_pict_win()", below.
2818 * One would think there is a more efficient method for telling a window
2819 * what color it should be using to draw with, but perhaps simply changing
2820 * it every time is not too inefficient. XXX XXX XXX
2822 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2824 term_data *td = (term_data*)(Term->data);
2828 #if 1 /* #ifdef JP */
2829 static HBITMAP WALL;
2830 static HBRUSH myBrush, oldBrush;
2832 static bool init_done = FALSE;
2835 WALL = LoadBitmap(hInstance, AppName);
2836 myBrush = CreatePatternBrush(WALL);
2841 /* Total rectangle */
2842 rc.left = x * td->tile_wid + td->size_ow1;
2843 rc.right = rc.left + n * td->tile_wid;
2844 rc.top = y * td->tile_hgt + td->size_oh1;
2845 rc.bottom = rc.top + td->tile_hgt;
2850 /* Background color */
2851 SetBkColor(hdc, RGB(0, 0, 0));
2853 /* Foreground color */
2856 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2860 SetTextColor(hdc, win_clr[a&0x0F]);
2864 SetTextColor(hdc, win_clr[a]);
2868 SelectObject(hdc, td->font_id);
2871 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2875 (td->tile_hgt != td->font_hgt) ||
2876 (td->tile_wid != td->font_wid))
2880 /* Erase complete rectangle */
2881 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2884 if (use_bg) DrawBG(hdc, &rc);
2887 rc.left += ((td->tile_wid - td->font_wid) / 2);
2888 rc.right = rc.left + td->font_wid;
2889 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2890 rc.bottom = rc.top + td->font_hgt;
2892 /* Dump each character */
2893 for (i = 0; i < n; i++)
2896 if (use_bigtile && *(s+i)=="■"[0] && *(s+i+1)=="■"[1])
2898 rc.right += td->font_wid;
2900 oldBrush = SelectObject(hdc, myBrush);
2901 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2904 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2906 SelectObject(hdc, oldBrush);
2907 SelectObject(hdc, oldPen);
2908 rc.right -= td->font_wid;
2912 rc.left += 2 * td->tile_wid;
2913 rc.right += 2 * td->tile_wid;
2915 else if ( iskanji(*(s+i)) ) /* 2バイト文字 */
2917 rc.right += td->font_wid;
2919 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2921 rc.right -= td->font_wid;
2925 rc.left += 2 * td->tile_wid;
2926 rc.right += 2 * td->tile_wid;
2927 } else if (*(s+i)==127){
2928 oldBrush = SelectObject(hdc, myBrush);
2929 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2932 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2934 SelectObject(hdc, oldBrush);
2935 SelectObject(hdc, oldPen);
2938 rc.left += td->tile_wid;
2939 rc.right += td->tile_wid;
2942 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2945 rc.left += td->tile_wid;
2946 rc.right += td->tile_wid;
2951 oldBrush = SelectObject(hdc, myBrush);
2952 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2955 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2957 SelectObject(hdc, oldBrush);
2958 SelectObject(hdc, oldPen);
2961 rc.left += td->tile_wid;
2962 rc.right += td->tile_wid;
2965 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2969 rc.left += td->tile_wid;
2970 rc.right += td->tile_wid;
2974 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2978 rc.left += td->tile_wid;
2979 rc.right += td->tile_wid;
2990 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2995 ReleaseDC(td->w, hdc);
3003 * Low level graphics. Assumes valid input.
3005 * Draw an array of "special" attr/char pairs at the given location.
3007 * We use the "Term_pict_win()" function for "graphic" data, which are
3008 * encoded by setting the "high-bits" of both the "attr" and the "char"
3009 * data. We use the "attr" to represent the "row" of the main bitmap,
3010 * and the "char" to represent the "col" of the main bitmap. The use
3011 * of this function is induced by the "higher_pict" flag.
3013 * If "graphics" is not available, we simply "wipe" the given grids.
3015 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
3017 term_data *td = (term_data*)(Term->data);
3022 int x1, y1, w1, h1, tw1, th1;
3023 int x2, y2, w2, h2, tw2 = 0;
3035 /* Erase the grids */
3036 return (Term_wipe_win(x, y, n));
3039 /* Size of bitmap cell */
3040 w1 = infGraph.CellWidth;
3041 h1 = infGraph.CellHeight;
3042 tw1 = infGraph.TileWidth;
3043 th1 = infGraph.TileHeight;
3045 /* Size of window cell */
3048 w2 = td->map_tile_wid;
3049 h2 = td->map_tile_hgt;
3058 if (use_bigtile) tw2 *= 2;
3061 /* Location of window cell */
3062 x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
3063 y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
3069 hdcSrc = CreateCompatibleDC(hdc);
3070 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
3072 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3074 hdcMask = CreateCompatibleDC(hdc);
3075 SelectObject(hdcMask, infMask.hBitmap);
3078 /* Draw attr/char pairs */
3079 for (i = 0; i < n; i++, x2 += w2)
3085 /* Extract picture */
3086 int row = (a & 0x7F);
3087 int col = (c & 0x7F);
3089 /* Location of bitmap cell */
3093 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3095 x3 = (tcp[i] & 0x7F) * w1;
3096 y3 = (tap[i] & 0x7F) * h1;
3097 tw2 = tw2 * w1 / tw1;
3101 if ((tw1 == tw2) && (th1 == h2))
3103 /* Copy the terrain picture from the bitmap to the window */
3104 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
3106 /* Mask out the tile */
3107 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3110 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3113 /* Need to stretch */
3116 /* Set the correct mode for stretching the tiles */
3117 SetStretchBltMode(hdc, COLORONCOLOR);
3119 /* Copy the terrain picture from the bitmap to the window */
3120 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
3122 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
3124 /* Only draw if terrain and overlay are different */
3125 if ((x1 != x3) || (y1 != y3))
3127 /* Mask out the tile */
3128 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3131 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3138 if ((w1 == tw2) && (h1 == h2))
3140 /* Copy the picture from the bitmap to the window */
3141 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3144 /* Need to stretch */
3147 /* Set the correct mode for stretching the tiles */
3148 SetStretchBltMode(hdc, COLORONCOLOR);
3150 /* Copy the picture from the bitmap to the window */
3151 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3157 SelectObject(hdcSrc, hbmSrcOld);
3160 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3163 SelectObject(hdcMask, hbmSrcOld);
3168 ReleaseDC(td->w, hdc);
3170 #else /* USE_GRAPHICS */
3172 /* Just erase this grid */
3173 return (Term_wipe_win(x, y, n));
3175 #endif /* USE_GRAPHICS */
3182 static void windows_map(void)
3184 term_data *td = &data[0];
3186 int x, min_x, max_x;
3187 int y, min_y, max_y;
3191 /* Only in graphics mode */
3192 if (!use_graphics) return;
3195 Term_xtra_win_clear();
3197 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3198 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3199 td->map_active = TRUE;
3209 for (x = min_x; x < max_x; x++)
3211 for (y = min_y; y < max_y; y++)
3213 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3215 /* Ignore non-graphics */
3216 if ((a & 0x80) && (c & 0x80))
3218 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3223 /* Hilite the player */
3224 Term_curs_win(p_ptr->x - min_x, p_ptr->y - min_y);
3226 /* Wait for a keypress, flush key buffer */
3227 Term_inkey(&c, TRUE, TRUE);
3230 /* Switch off the map display */
3231 td->map_active = FALSE;
3233 /* Restore screen */
3234 Term_xtra_win_clear();
3239 /*** Other routines ***/
3243 * Create and initialize a "term_data" given a title
3245 static void term_data_link(term_data *td)
3249 /* Initialize the term */
3250 term_init(t, td->cols, td->rows, td->keys);
3252 /* Use a "software" cursor */
3253 t->soft_cursor = TRUE;
3255 /* Use "Term_pict" for "graphic" data */
3256 t->higher_pict = TRUE;
3258 /* Erase with "white space" */
3259 t->attr_blank = TERM_WHITE;
3260 t->char_blank = ' ';
3263 /* Prepare the init/nuke hooks */
3264 t->init_hook = Term_init_win;
3265 t->nuke_hook = Term_nuke_win;
3268 /* Prepare the template hooks */
3269 t->user_hook = Term_user_win;
3270 t->xtra_hook = Term_xtra_win;
3271 t->curs_hook = Term_curs_win;
3272 t->bigcurs_hook = Term_bigcurs_win;
3273 t->wipe_hook = Term_wipe_win;
3274 t->text_hook = Term_text_win;
3275 t->pict_hook = Term_pict_win;
3277 /* Remember where we came from */
3278 t->data = (vptr)(td);
3283 * Create the windows
3285 * First, instantiate the "default" values, then read the "ini_file"
3286 * to over-ride selected values, then create the windows, and fonts.
3288 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3289 * must make active to realize the palette. XXX XXX XXX
3291 static void init_windows(void)
3297 #if 0 /* #ifndef JP */
3303 WIPE(td, term_data);
3307 td->s = angband_term_name[0];
3321 #if 1 /* #ifdef JP */
3325 for (i = 1; i < MAX_TERM_DATA; i++)
3328 WIPE(td, term_data);
3329 td->s = angband_term_name[i];
3333 td->visible = FALSE;
3338 td->pos_x = (7 - i) * 30;
3339 td->pos_y = (7 - i) * 20;
3341 #if 1 /* #ifdef JP */
3351 /* Main window (need these before term_getsize gets called) */
3353 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3354 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3359 /* Sub windows (need these before term_getsize gets called) */
3360 for (i = 1; i < MAX_TERM_DATA; i++)
3363 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3364 td->dwExStyle = (WS_EX_TOOLWINDOW);
3369 for (i = 0; i < MAX_TERM_DATA; i++)
3373 #if 1 /* #ifdef JP */
3374 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3375 td->lf.lfCharSet = DEFAULT_CHARSET;
3376 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3377 /* Activate the chosen font */
3378 term_force_font(td, NULL);
3379 if(!td->tile_wid) td->tile_wid = td->font_wid;
3380 if(!td->tile_hgt) td->tile_hgt = td->font_hgt;
3382 /* Access the standard font file */
3383 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3385 /* Activate the chosen font */
3386 if (term_force_font(td, buf))
3388 /* Access the standard font file */
3389 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3391 /* Force the use of that font */
3392 (void)term_force_font(td, buf);
3398 /* Assume not bizarre */
3399 td->bizarre = FALSE;
3404 /* Analyze the font */
3407 /* Resize the window */
3408 term_window_resize(td);
3412 /* Sub windows (reverse order) */
3413 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3418 td->w = CreateWindowEx(td->dwExStyle, AngList,
3420 td->pos_x, td->pos_y,
3421 td->size_wid, td->size_hgt,
3422 HWND_DESKTOP, NULL, hInstance, NULL);
3424 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
3428 td->size_hack = TRUE;
3429 ShowWindow(td->w, SW_SHOW);
3430 td->size_hack = FALSE;
3434 angband_term[i] = &td->t;
3438 /* Activate the window */
3439 SetActiveWindow(td->w);
3444 term_window_pos(&data[i], HWND_TOPMOST);
3448 term_window_pos(&data[i], td->w);
3458 td->w = CreateWindowEx(td->dwExStyle, AppName,
3460 td->pos_x, td->pos_y,
3461 td->size_wid, td->size_hgt,
3462 HWND_DESKTOP, NULL, hInstance, NULL);
3464 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
3467 angband_term[0] = &td->t;
3468 normsize.x = td->cols;
3469 normsize.y = td->rows;
3471 /* Activate the main window */
3472 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3473 else ShowWindow(td->w, SW_SHOW);
3475 /* Bring main window back to top */
3476 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3479 /* New palette XXX XXX XXX */
3480 (void)new_palette();
3483 /* Create a "brush" for drawing the "cursor" */
3484 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3487 /* Process pending messages */
3488 (void)Term_xtra_win_flush();
3496 static void setup_menus(void)
3500 HMENU hm = GetMenu(data[0].w);
3503 /* Menu "File", Disable all */
3504 EnableMenuItem(hm, IDM_FILE_NEW,
3505 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3506 EnableMenuItem(hm, IDM_FILE_OPEN,
3507 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3508 EnableMenuItem(hm, IDM_FILE_SAVE,
3509 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3510 EnableMenuItem(hm, IDM_FILE_EXIT,
3511 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3512 EnableMenuItem(hm, IDM_FILE_SCORE,
3513 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3516 /* No character available */
3517 if (!character_generated)
3519 /* Menu "File", Item "New" */
3520 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3522 /* Menu "File", Item "Open" */
3523 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3526 /* A character available */
3527 if (character_generated)
3529 /* Menu "File", Item "Save" */
3530 EnableMenuItem(hm, IDM_FILE_SAVE,
3531 MF_BYCOMMAND | MF_ENABLED);
3534 /* Menu "File", Item "Exit" */
3535 EnableMenuItem(hm, IDM_FILE_EXIT,
3536 MF_BYCOMMAND | MF_ENABLED);
3538 EnableMenuItem(hm, IDM_FILE_SCORE,
3539 MF_BYCOMMAND | MF_ENABLED);
3542 /* Menu "Window::Visibility" */
3543 for (i = 0; i < MAX_TERM_DATA; i++)
3545 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3546 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3548 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3549 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3551 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3552 MF_BYCOMMAND | MF_ENABLED);
3555 /* Menu "Window::Font" */
3556 for (i = 0; i < MAX_TERM_DATA; i++)
3558 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3559 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3561 if (data[i].visible)
3563 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3564 MF_BYCOMMAND | MF_ENABLED);
3568 /* Menu "Window::Window Position Fix" */
3569 for (i = 0; i < MAX_TERM_DATA; i++)
3571 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3572 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3574 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3575 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3577 if (data[i].visible)
3579 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3580 MF_BYCOMMAND | MF_ENABLED);
3584 /* Menu "Window::Bizarre Display" */
3585 for (i = 0; i < MAX_TERM_DATA; i++)
3587 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3588 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3590 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3591 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3593 if (data[i].visible)
3595 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3596 MF_BYCOMMAND | MF_ENABLED);
3601 /* Menu "Window::Increase Tile Width" */
3602 for (i = 0; i < MAX_TERM_DATA; i++)
3604 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3605 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3607 if (data[i].visible)
3609 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3610 MF_BYCOMMAND | MF_ENABLED);
3615 /* Menu "Window::Decrease Tile Width" */
3616 for (i = 0; i < MAX_TERM_DATA; i++)
3618 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3619 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3621 if (data[i].visible)
3623 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3624 MF_BYCOMMAND | MF_ENABLED);
3629 /* Menu "Window::Increase Tile Height" */
3630 for (i = 0; i < MAX_TERM_DATA; i++)
3632 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3633 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3635 if (data[i].visible)
3637 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3638 MF_BYCOMMAND | MF_ENABLED);
3643 /* Menu "Window::Decrease Tile Height" */
3644 for (i = 0; i < MAX_TERM_DATA; i++)
3646 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3647 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3649 if (data[i].visible)
3651 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3652 MF_BYCOMMAND | MF_ENABLED);
3657 /* Menu "Options", disable all */
3658 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3659 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3660 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3661 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3662 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3663 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3664 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3665 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3666 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3667 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3669 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3670 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3673 /* Menu "Options", Item "Map" */
3674 if (use_graphics != GRAPHICS_NONE)
3675 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3677 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3678 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3680 /* Menu "Options", update all */
3681 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3682 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3683 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3684 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3685 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3686 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3687 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3688 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3689 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3690 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3691 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3692 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3693 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3694 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3695 CheckMenuItem(hm, IDM_OPTIONS_BG,
3696 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3698 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3699 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3703 /* Menu "Options", Item "Graphics" */
3704 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3705 /* Menu "Options", Item "Graphics" */
3706 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3707 /* Menu "Options", Item "Graphics" */
3708 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3709 /* Menu "Options", Item "Graphics" */
3710 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3711 #endif /* USE_GRAPHICS */
3714 /* Menu "Options", Item "Sound" */
3715 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3716 #endif /* USE_SOUND */
3719 /* Menu "Options", Item "ScreenSaver" */
3720 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3721 MF_BYCOMMAND | MF_ENABLED);
3722 #endif /* USE_SAVER */
3727 * Check for double clicked (or dragged) savefile
3729 * Apparently, Windows copies the entire filename into the first
3730 * piece of the "command line string". Perhaps we should extract
3731 * the "basename" of that filename and append it to the "save" dir.
3733 static void check_for_save_file(LPSTR cmd_line)
3743 /* Extract filename */
3744 strcat(savefile, s);
3746 /* Validate the file */
3747 validate_file(savefile);
3749 /* Game in progress */
3750 game_in_progress = TRUE;
3758 * Process a menu command
3760 static void process_menus(WORD wCmd)
3776 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3778 else if (game_in_progress)
3780 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
3784 game_in_progress = TRUE;
3797 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3799 else if (game_in_progress)
3801 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
3805 memset(&ofn, 0, sizeof(ofn));
3806 ofn.lStructSize = sizeof(ofn);
3807 ofn.hwndOwner = data[0].w;
3808 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3809 ofn.nFilterIndex = 1;
3810 ofn.lpstrFile = savefile;
3811 ofn.nMaxFile = 1024;
3812 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3813 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3815 if (GetOpenFileName(&ofn))
3817 /* Load 'savefile' */
3818 validate_file(savefile);
3819 game_in_progress = TRUE;
3831 if (game_in_progress && character_generated)
3836 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
3840 /* Hack -- Forget messages */
3845 do_cmd_save_game(FALSE);
3846 #else /* ZANGBAND */
3848 #endif /* ZANGBAND */
3852 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
3860 if (game_in_progress && character_generated)
3865 plog(_("今は終了できません。", "You may not do that right now."));
3869 /* Hack -- Forget messages */
3878 /* do_cmd_save_game(FALSE); */
3879 #else /* ZANGBAND */
3880 /* do_cmd_save_game(); */
3881 #endif /* ZANGBAND */
3882 Term_key_push(SPECIAL_KEY_QUIT);
3890 case IDM_FILE_SCORE:
3894 /* Build the filename */
3895 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3897 /* Open the binary high score file, for reading */
3898 highscore_fd = fd_open(buf, O_RDONLY);
3900 /* Paranoia -- No score file */
3901 if (highscore_fd < 0)
3903 msg_print("Score file unavailable.");
3913 /* Display the scores */
3914 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3916 /* Shut the high score file */
3917 (void)fd_close(highscore_fd);
3919 /* Forget the high score fd */
3925 /* Hack - Flush it */
3933 case IDM_FILE_MOVIE:
3937 plog(_("まだ初期化中です...", "You cannot do that yet..."));
3939 else if (game_in_progress)
3941 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
3945 memset(&ofn, 0, sizeof(ofn));
3946 ofn.lStructSize = sizeof(ofn);
3947 ofn.hwndOwner = data[0].w;
3948 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3949 ofn.nFilterIndex = 1;
3950 ofn.lpstrFile = savefile;
3951 ofn.nMaxFile = 1024;
3952 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3953 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3955 if (GetOpenFileName(&ofn))
3957 /* Load 'savefile' */
3958 prepare_browse_movie_aux(savefile);
3968 case IDM_WINDOW_VIS_0:
3970 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
3974 /* Window visibility */
3975 case IDM_WINDOW_VIS_1:
3976 case IDM_WINDOW_VIS_2:
3977 case IDM_WINDOW_VIS_3:
3978 case IDM_WINDOW_VIS_4:
3979 case IDM_WINDOW_VIS_5:
3980 case IDM_WINDOW_VIS_6:
3981 case IDM_WINDOW_VIS_7:
3983 i = wCmd - IDM_WINDOW_VIS_0;
3985 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3992 ShowWindow(td->w, SW_SHOW);
3993 term_data_redraw(td);
3997 td->visible = FALSE;
3999 ShowWindow(td->w, SW_HIDE);
4006 case IDM_WINDOW_FONT_0:
4007 case IDM_WINDOW_FONT_1:
4008 case IDM_WINDOW_FONT_2:
4009 case IDM_WINDOW_FONT_3:
4010 case IDM_WINDOW_FONT_4:
4011 case IDM_WINDOW_FONT_5:
4012 case IDM_WINDOW_FONT_6:
4013 case IDM_WINDOW_FONT_7:
4015 i = wCmd - IDM_WINDOW_FONT_0;
4017 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4021 term_change_font(td);
4026 /* Window Z Position */
4027 case IDM_WINDOW_POS_1:
4028 case IDM_WINDOW_POS_2:
4029 case IDM_WINDOW_POS_3:
4030 case IDM_WINDOW_POS_4:
4031 case IDM_WINDOW_POS_5:
4032 case IDM_WINDOW_POS_6:
4033 case IDM_WINDOW_POS_7:
4035 i = wCmd - IDM_WINDOW_POS_0;
4037 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4041 if (!td->posfix && td->visible)
4044 term_window_pos(td, HWND_TOPMOST);
4049 term_window_pos(td, data[0].w);
4055 /* Bizarre Display */
4056 case IDM_WINDOW_BIZ_0:
4057 case IDM_WINDOW_BIZ_1:
4058 case IDM_WINDOW_BIZ_2:
4059 case IDM_WINDOW_BIZ_3:
4060 case IDM_WINDOW_BIZ_4:
4061 case IDM_WINDOW_BIZ_5:
4062 case IDM_WINDOW_BIZ_6:
4063 case IDM_WINDOW_BIZ_7:
4065 i = wCmd - IDM_WINDOW_BIZ_0;
4067 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4071 td->bizarre = !td->bizarre;
4075 term_window_resize(td);
4080 /* Increase Tile Width */
4081 case IDM_WINDOW_I_WID_0:
4082 case IDM_WINDOW_I_WID_1:
4083 case IDM_WINDOW_I_WID_2:
4084 case IDM_WINDOW_I_WID_3:
4085 case IDM_WINDOW_I_WID_4:
4086 case IDM_WINDOW_I_WID_5:
4087 case IDM_WINDOW_I_WID_6:
4088 case IDM_WINDOW_I_WID_7:
4090 i = wCmd - IDM_WINDOW_I_WID_0;
4092 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4100 term_window_resize(td);
4105 /* Decrease Tile Height */
4106 case IDM_WINDOW_D_WID_0:
4107 case IDM_WINDOW_D_WID_1:
4108 case IDM_WINDOW_D_WID_2:
4109 case IDM_WINDOW_D_WID_3:
4110 case IDM_WINDOW_D_WID_4:
4111 case IDM_WINDOW_D_WID_5:
4112 case IDM_WINDOW_D_WID_6:
4113 case IDM_WINDOW_D_WID_7:
4115 i = wCmd - IDM_WINDOW_D_WID_0;
4117 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4125 term_window_resize(td);
4130 /* Increase Tile Height */
4131 case IDM_WINDOW_I_HGT_0:
4132 case IDM_WINDOW_I_HGT_1:
4133 case IDM_WINDOW_I_HGT_2:
4134 case IDM_WINDOW_I_HGT_3:
4135 case IDM_WINDOW_I_HGT_4:
4136 case IDM_WINDOW_I_HGT_5:
4137 case IDM_WINDOW_I_HGT_6:
4138 case IDM_WINDOW_I_HGT_7:
4140 i = wCmd - IDM_WINDOW_I_HGT_0;
4142 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4150 term_window_resize(td);
4155 /* Decrease Tile Height */
4156 case IDM_WINDOW_D_HGT_0:
4157 case IDM_WINDOW_D_HGT_1:
4158 case IDM_WINDOW_D_HGT_2:
4159 case IDM_WINDOW_D_HGT_3:
4160 case IDM_WINDOW_D_HGT_4:
4161 case IDM_WINDOW_D_HGT_5:
4162 case IDM_WINDOW_D_HGT_6:
4163 case IDM_WINDOW_D_HGT_7:
4165 i = wCmd - IDM_WINDOW_D_HGT_0;
4167 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4175 term_window_resize(td);
4180 case IDM_OPTIONS_NO_GRAPHICS:
4185 plog("You may not do that right now.");
4189 /* Toggle "arg_graphics" */
4190 if (arg_graphics != GRAPHICS_NONE)
4192 arg_graphics = GRAPHICS_NONE;
4194 /* React to changes */
4195 Term_xtra_win_react();
4197 /* Hack -- Force redraw */
4198 Term_key_push(KTRL('R'));
4204 case IDM_OPTIONS_OLD_GRAPHICS:
4209 plog("You may not do that right now.");
4213 /* Toggle "arg_graphics" */
4214 if (arg_graphics != GRAPHICS_ORIGINAL)
4216 arg_graphics = GRAPHICS_ORIGINAL;
4218 /* React to changes */
4219 Term_xtra_win_react();
4221 /* Hack -- Force redraw */
4222 Term_key_push(KTRL('R'));
4228 case IDM_OPTIONS_NEW_GRAPHICS:
4233 plog("You may not do that right now.");
4237 /* Toggle "arg_graphics" */
4238 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4240 arg_graphics = GRAPHICS_ADAM_BOLT;
4242 /* React to changes */
4243 Term_xtra_win_react();
4245 /* Hack -- Force redraw */
4246 Term_key_push(KTRL('R'));
4252 case IDM_OPTIONS_NEW2_GRAPHICS:
4257 plog("You may not do that right now.");
4261 /* Toggle "arg_graphics" */
4262 if (arg_graphics != GRAPHICS_HENGBAND)
4264 arg_graphics = GRAPHICS_HENGBAND;
4266 /* React to changes */
4267 Term_xtra_win_react();
4269 /* Hack -- Force redraw */
4270 Term_key_push(KTRL('R'));
4276 case IDM_OPTIONS_BIGTILE:
4278 term_data *td = &data[0];
4283 plog("You may not do that right now.");
4287 /* Toggle "arg_sound" */
4288 arg_bigtile = !arg_bigtile;
4291 Term_activate(&td->t);
4293 /* Resize the term */
4294 Term_resize(td->cols, td->rows);
4297 InvalidateRect(td->w, NULL, TRUE);
4302 case IDM_OPTIONS_MUSIC:
4307 plog("You may not do that right now.");
4311 /* Toggle "arg_sound" */
4312 arg_music = !arg_music;
4314 /* React to changes */
4315 Term_xtra_win_react();
4317 /* Hack -- Force redraw */
4318 Term_key_push(KTRL('R'));
4323 case IDM_OPTIONS_SOUND:
4328 plog("You may not do that right now.");
4332 /* Toggle "arg_sound" */
4333 arg_sound = !arg_sound;
4335 /* React to changes */
4336 Term_xtra_win_react();
4338 /* Hack -- Force redraw */
4339 Term_key_push(KTRL('R'));
4345 case IDM_OPTIONS_BG:
4350 plog("You may not do that right now.");
4354 /* Toggle "use_bg" */
4359 /* React to changes */
4360 Term_xtra_win_react();
4362 /* Hack -- Force redraw */
4363 Term_key_push(KTRL('R'));
4369 case IDM_OPTIONS_OPEN_BG:
4374 plog("You may not do that right now.");
4379 memset(&ofn, 0, sizeof(ofn));
4380 ofn.lStructSize = sizeof(ofn);
4381 ofn.hwndOwner = data[0].w;
4382 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4383 ofn.nFilterIndex = 1;
4384 ofn.lpstrFile = bg_bitmap_file;
4385 ofn.nMaxFile = 1023;
4386 ofn.lpstrInitialDir = NULL;
4387 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
4388 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4390 if (GetOpenFileName(&ofn))
4392 /* Load 'savefile' */
4397 /* React to changes */
4398 Term_xtra_win_react();
4400 /* Hack -- Force redraw */
4401 Term_key_push(KTRL('R'));
4406 case IDM_DUMP_SCREEN_HTML:
4408 static char buf[1024] = "";
4409 memset(&ofn, 0, sizeof(ofn));
4410 ofn.lStructSize = sizeof(ofn);
4411 ofn.hwndOwner = data[0].w;
4412 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4413 ofn.nFilterIndex = 1;
4414 ofn.lpstrFile = buf;
4415 ofn.nMaxFile = 1023;
4416 ofn.lpstrDefExt = "html";
4417 ofn.lpstrInitialDir = NULL;
4418 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
4419 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4421 if (GetSaveFileName(&ofn))
4423 do_cmd_save_screen_html_aux(buf, 0);
4430 case IDM_OPTIONS_SAVER:
4434 DestroyWindow(hwndSaver);
4439 /* Create a screen scaver window */
4440 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4441 "Angband Screensaver",
4442 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4443 0, 0, GetSystemMetrics(SM_CXSCREEN),
4444 GetSystemMetrics(SM_CYSCREEN),
4445 NULL, NULL, hInstance, NULL);
4449 /* Push the window to the bottom XXX XXX XXX */
4450 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4454 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
4462 case IDM_OPTIONS_MAP:
4468 case IDM_HELP_CONTENTS:
4472 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4473 if (check_file(tmp))
4475 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4480 plog_fmt("ヘルプファイル[%s]が見付かりません。", tmp);
4481 plog("代わりにオンラインヘルプを使用してください。");
4483 plog_fmt("Cannot find help file: %s", tmp);
4484 plog("Use the online help files instead.");
4489 #else /* HTML_HELP */
4492 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4493 if (check_file(tmp))
4495 sprintf(buf, "winhelp.exe %s", tmp);
4496 WinExec(buf, SW_NORMAL);
4501 plog_fmt("ヘルプファイル[%s]が見付かりません。", tmp);
4502 plog("代わりにオンラインヘルプを使用してください。");
4504 plog_fmt("Cannot find help file: %s", tmp);
4505 plog("Use the online help files instead.");
4510 #endif /* HTML_HELP */
4516 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4523 /* Extract the modifiers */
4524 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4525 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4526 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4528 Term_no_press = (ma) ? TRUE : FALSE;
4530 /* Handle "special" keys */
4531 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4533 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4534 bool numpad = FALSE;
4536 /* Begin the macro trigger */
4539 /* Send the modifiers */
4540 if (mc) Term_keypress('C');
4541 if (ms) Term_keypress('S');
4542 if (ma) Term_keypress('A');
4544 /* Extract "scan code" */
4545 i = LOBYTE(HIWORD(lParam));
4547 /* Introduce the scan code */
4550 /* Extended key bit */
4553 /* Numpad Enter and '/' are extended key */
4555 Term_no_press = TRUE;
4556 case VK_RETURN: /* Enter */
4559 /* Other extended keys are on full keyboard */
4575 Term_no_press = TRUE;
4579 case VK_PRIOR: /* Page Up */
4580 case VK_NEXT: /* Page Down */
4590 /* Special modifiers for keypad keys */
4591 if (numpad) Term_keypress('K');
4593 /* Encode the hexidecimal scan code */
4594 Term_keypress(hexsym[i/16]);
4595 Term_keypress(hexsym[i%16]);
4597 /* End the macro trigger */
4608 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4609 WPARAM wParam, LPARAM lParam);
4610 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4611 WPARAM wParam, LPARAM lParam)
4612 #else /* __MWERKS__ */
4613 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4614 WPARAM wParam, LPARAM lParam)
4615 #endif /* __MWERKS__ */
4621 MINMAXINFO FAR *lpmmi;
4627 /* Acquire proper "term_data" info */
4628 td = (term_data *)GetWindowLong(hWnd, 0);
4630 /* Handle message */
4636 SetWindowLong(hWnd, 0, (LONG)(my_td));
4644 mop.dwCallback=(DWORD)hWnd;
4649 case WM_GETMINMAXINFO:
4651 MINMAXINFO FAR *lpmmi;
4654 lpmmi = (MINMAXINFO FAR *)lParam;
4656 /* this message was sent before WM_NCCREATE */
4659 /* Minimum window size is 80x24 */
4660 rc.left = rc.top = 0;
4661 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4662 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4665 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4667 /* Save minimum size */
4668 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4669 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4676 BeginPaint(hWnd, &ps);
4677 if (td) term_data_redraw(td);
4678 EndPaint(hWnd, &ps);
4679 ValidateRect(hWnd, NULL);
4686 if(wParam == MCI_NOTIFY_SUCCESSFUL)
4688 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4689 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4698 if (process_keydown(wParam, lParam))
4705 if (Term_no_press) Term_no_press = FALSE;
4706 else Term_keypress(wParam);
4710 case WM_LBUTTONDOWN:
4712 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4713 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4725 int dx = abs(oldx - mousex) + 1;
4726 int dy = abs(oldy - mousey) + 1;
4727 int ox = (oldx > mousex) ? mousex : oldx;
4728 int oy = (oldy > mousey) ? mousey : oldy;
4738 hGlobal = GlobalAlloc(GHND, sz + 1);
4739 if (hGlobal == NULL) return 0;
4740 lpStr = (LPSTR)GlobalLock(hGlobal);
4742 for (i = 0; i < dy; i++)
4746 char **scr = data[0].t.scr->c;
4748 C_MAKE(s, (dx + 1), char);
4749 strncpy(s, &scr[oy + i][ox], dx);
4753 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4756 if (ox + dx < data[0].cols)
4758 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4761 for (j = 0; j < dx; j++)
4763 if (s[j] == 127) s[j] = '#';
4767 for (j = 0; j < dx; j++)
4769 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4779 GlobalUnlock(hGlobal);
4780 if (OpenClipboard(hWnd) == 0)
4782 GlobalFree(hGlobal);
4786 SetClipboardData(CF_TEXT, hGlobal);
4799 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4800 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4805 dx = abs(oldx - mousex) + 1;
4806 dy = abs(oldy - mousey) + 1;
4807 ox = (oldx > mousex) ? mousex : oldx;
4808 oy = (oldy > mousey) ? mousey : oldy;
4809 Term_inversed_area(hWnd, ox, oy, dx, dy);
4816 dx = abs(cx - mousex) + 1;
4817 dy = abs(cy - mousey) + 1;
4818 ox = (cx > mousex) ? mousex : cx;
4819 oy = (cy > mousey) ? mousey : cy;
4820 Term_inversed_area(hWnd, ox, oy, dx, dy);
4836 if (game_in_progress && character_generated)
4840 plog(_("今は終了できません。", "You may not do that right now."));
4844 /* Hack -- Forget messages */
4853 /* do_cmd_save_game(FALSE); */
4854 #else /* ZANGBAND */
4855 /* do_cmd_save_game(); */
4856 #endif /* ZANGBAND */
4857 Term_key_push(SPECIAL_KEY_QUIT);
4864 case WM_QUERYENDSESSION:
4866 if (game_in_progress && character_generated)
4868 /* Hack -- Forget messages */
4871 /* Mega-Hack -- Delay death */
4872 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4873 do_cmd_write_nikki(NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
4875 /* Hardcode panic save */
4876 p_ptr->panic_save = 1;
4878 /* Forbid suspend */
4879 signals_ignore_tstp();
4881 /* Indicate panic save */
4882 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
4885 (void)save_player();
4899 process_menus(LOWORD(wParam));
4905 /* this message was sent before WM_NCCREATE */
4908 /* it was sent from inside CreateWindowEx */
4909 if (!td->w) return 1;
4911 /* was sent from WM_SIZE */
4912 if (td->size_hack) return 1;
4916 case SIZE_MINIMIZED:
4918 /* Hide sub-windows */
4919 for (i = 1; i < MAX_TERM_DATA; i++)
4921 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4926 case SIZE_MAXIMIZED:
4928 /* fall through XXX XXX XXX */
4933 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4934 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4937 if ((td->cols != cols) || (td->rows != rows))
4939 /* Save the new size */
4943 if (!IsZoomed(td->w) && !IsIconic(td->w))
4945 normsize.x = td->cols;
4946 normsize.y = td->rows;
4950 Term_activate(&td->t);
4952 /* Resize the term */
4953 Term_resize(td->cols, td->rows);
4956 InvalidateRect(td->w, NULL, TRUE);
4959 td->size_hack = TRUE;
4961 /* Show sub-windows */
4962 for (i = 1; i < MAX_TERM_DATA; i++)
4964 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4967 td->size_hack = FALSE;
4975 case WM_PALETTECHANGED:
4977 /* Ignore if palette change caused by itself */
4978 if ((HWND)wParam == hWnd) return 0;
4980 /* Fall through... */
4983 case WM_QUERYNEWPALETTE:
4985 if (!paletted) return 0;
4989 SelectPalette(hdc, hPal, FALSE);
4991 i = RealizePalette(hdc);
4993 /* if any palette entries changed, repaint the window. */
4994 if (i) InvalidateRect(hWnd, NULL, TRUE);
4996 ReleaseDC(hWnd, hdc);
5003 if (wParam && !HIWORD(lParam))
5005 /* Do something to sub-windows */
5006 for (i = 1; i < MAX_TERM_DATA; i++)
5008 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
5011 /* Focus on main window */
5020 case WM_ACTIVATEAPP:
5022 if (IsIconic(td->w)) break;
5024 for (i = 1; i < MAX_TERM_DATA; i++)
5030 ShowWindow(data[i].w, SW_SHOW);
5034 ShowWindow(data[i].w, SW_HIDE);
5041 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5046 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5047 WPARAM wParam, LPARAM lParam);
5048 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5049 WPARAM wParam, LPARAM lParam)
5050 #else /* __MWERKS__ */
5051 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5052 WPARAM wParam, LPARAM lParam)
5053 #endif /* __MWERKS__ */
5057 MINMAXINFO FAR *lpmmi;
5065 /* Acquire proper "term_data" info */
5066 td = (term_data *)GetWindowLong(hWnd, 0);
5068 /* Process message */
5074 SetWindowLong(hWnd, 0, (LONG)(my_td));
5084 case WM_GETMINMAXINFO:
5086 MINMAXINFO FAR *lpmmi;
5089 lpmmi = (MINMAXINFO FAR *)lParam;
5091 /* this message was sent before WM_NCCREATE */
5094 /* Minimum window size is 80x24 */
5095 rc.left = rc.top = 0;
5096 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5097 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5100 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5102 /* Save minimum size */
5103 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5104 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5114 /* this message was sent before WM_NCCREATE */
5117 /* it was sent from inside CreateWindowEx */
5118 if (!td->w) return 1;
5120 /* was sent from inside WM_SIZE */
5121 if (td->size_hack) return 1;
5123 td->size_hack = TRUE;
5125 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5126 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5129 if ((td->cols != cols) || (td->rows != rows))
5132 term *old_term = Term;
5134 /* Save the new size */
5139 Term_activate(&td->t);
5141 /* Resize the term */
5142 Term_resize(td->cols, td->rows);
5145 Term_activate(old_term);
5148 InvalidateRect(td->w, NULL, TRUE);
5150 /* HACK - Redraw all windows */
5151 p_ptr->window = 0xFFFFFFFF;
5155 td->size_hack = FALSE;
5162 BeginPaint(hWnd, &ps);
5163 if (td) term_data_redraw(td);
5164 EndPaint(hWnd, &ps);
5171 if (process_keydown(wParam, lParam))
5178 if (Term_no_press) Term_no_press = FALSE;
5179 else Term_keypress(wParam);
5183 case WM_PALETTECHANGED:
5185 /* ignore if palette change caused by itself */
5186 if ((HWND)wParam == hWnd) return FALSE;
5187 /* otherwise, fall through!!! */
5190 case WM_QUERYNEWPALETTE:
5192 if (!paletted) return 0;
5194 SelectPalette(hdc, hPal, FALSE);
5195 i = RealizePalette(hdc);
5196 /* if any palette entries changed, repaint the window. */
5197 if (i) InvalidateRect(hWnd, NULL, TRUE);
5198 ReleaseDC(hWnd, hdc);
5202 case WM_NCLBUTTONDOWN:
5206 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5207 #endif /* HTCLOSE */
5209 if (wParam == HTSYSMENU)
5213 td->visible = FALSE;
5214 ShowWindow(td->w, SW_HIDE);
5224 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5230 #define MOUSE_SENS 40
5233 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5234 WPARAM wParam, LPARAM lParam);
5235 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5236 WPARAM wParam, LPARAM lParam)
5237 #else /* __MWERKS__ */
5238 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5239 WPARAM wParam, LPARAM lParam)
5240 #endif /* __MWERKS__ */
5242 static int iMouse = 0;
5243 static WORD xMouse = 0;
5244 static WORD yMouse = 0;
5267 if (LOWORD(wParam) == WA_INACTIVE) break;
5269 /* else fall through */
5273 case WM_LBUTTONDOWN:
5274 case WM_MBUTTONDOWN:
5275 case WM_RBUTTONDOWN:
5278 SendMessage(hWnd, WM_CLOSE, 0, 0);
5286 dx = LOWORD(lParam) - xMouse;
5287 dy = HIWORD(lParam) - yMouse;
5289 if (dx < 0) dx = -dx;
5290 if (dy < 0) dy = -dy;
5292 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5294 SendMessage(hWnd, WM_CLOSE, 0, 0);
5298 /* Save last location */
5300 xMouse = LOWORD(lParam);
5301 yMouse = HIWORD(lParam);
5308 DestroyWindow(hwndSaver);
5315 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5318 #endif /* USE_SAVER */
5324 /*** Temporary Hooks ***/
5328 * Display warning message (see "z-util.c")
5330 static void hack_plog(cptr str)
5332 /* Give a warning */
5336 MessageBox(NULL, str, "警告!",
5337 MB_ICONEXCLAMATION | MB_OK);
5339 MessageBox(NULL, str, "Warning",
5340 MB_ICONEXCLAMATION | MB_OK);
5348 * Display error message and quit (see "z-util.c")
5350 static void hack_quit(cptr str)
5352 /* Give a warning */
5356 MessageBox(NULL, str, "エラー!",
5357 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5359 MessageBox(NULL, str, "Error",
5360 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5365 /* Unregister the classes */
5366 UnregisterClass(AppName, hInstance);
5368 /* Destroy the icon */
5369 if (hIcon) DestroyIcon(hIcon);
5377 /*** Various hooks ***/
5381 * Display warning message (see "z-util.c")
5383 static void hook_plog(cptr str)
5389 MessageBox(data[0].w, str, "警告!",
5390 MB_ICONEXCLAMATION | MB_OK);
5392 MessageBox(data[0].w, str, "Warning",
5393 MB_ICONEXCLAMATION | MB_OK);
5401 * Display error message and quit (see "z-util.c")
5403 static void hook_quit(cptr str)
5408 /* Give a warning */
5412 MessageBox(data[0].w, str, "エラー!",
5413 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5415 MessageBox(data[0].w, str, "Error",
5416 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5422 /* Save the preferences */
5426 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
5428 /* Destroy all windows */
5429 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5431 term_force_font(&data[i], NULL);
5432 if (data[i].font_want) string_free(data[i].font_want);
5433 if (data[i].w) DestroyWindow(data[i].w);
5437 /* Free the bitmap stuff */
5439 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5440 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5442 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5443 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5445 #endif /* USE_GRAPHICS */
5447 /*** Free some other stuff ***/
5449 DeleteObject(hbrYellow);
5454 if (hPal) DeleteObject(hPal);
5456 UnregisterClass(AppName, hInstance);
5458 if (hIcon) DestroyIcon(hIcon);
5465 /*** Initialize ***/
5471 static void init_stuff(void)
5478 /* Get program name with full path */
5479 GetModuleFileName(hInstance, path, 512);
5481 /* Save the "program name" XXX XXX XXX */
5484 /* Get the name of the "*.ini" file */
5485 strcpy(path + strlen(path) - 4, ".INI");
5487 /* Save the the name of the ini-file */
5488 ini_file = string_make(path);
5490 /* Analyze the path */
5496 if (path[i] == '\\')
5503 /* Add "lib" to the path */
5504 strcpy(path + i + 1, "lib\\");
5506 /* Validate the path */
5507 validate_dir(path, TRUE);
5509 /* Init the file paths */
5510 init_file_paths(path);
5512 /* Hack -- Validate the paths */
5513 validate_dir(ANGBAND_DIR_APEX, FALSE);
5514 validate_dir(ANGBAND_DIR_BONE, FALSE);
5516 /* Allow missing 'edit' directory */
5517 if (!check_dir(ANGBAND_DIR_EDIT))
5519 /* Must have 'data'! */
5520 validate_dir(ANGBAND_DIR_DATA, TRUE);
5524 /* Don't need 'data' */
5525 validate_dir(ANGBAND_DIR_DATA, FALSE);
5528 validate_dir(ANGBAND_DIR_FILE, TRUE);
5529 validate_dir(ANGBAND_DIR_HELP, FALSE);
5530 validate_dir(ANGBAND_DIR_INFO, FALSE);
5531 validate_dir(ANGBAND_DIR_PREF, TRUE);
5532 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5533 validate_dir(ANGBAND_DIR_USER, TRUE);
5534 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5536 /* Build the filename */
5537 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
5539 /* Hack -- Validate the "news.txt" file */
5540 validate_file(path);
5543 #if 0 /* #ifndef JP */
5544 /* Build the "font" path */
5545 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5547 /* Allocate the path */
5548 ANGBAND_DIR_XTRA_FONT = string_make(path);
5550 /* Validate the "font" directory */
5551 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5553 /* Build the filename */
5554 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5556 /* Hack -- Validate the basic font */
5557 validate_file(path);
5563 /* Build the "graf" path */
5564 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5566 /* Allocate the path */
5567 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5569 /* Validate the "graf" directory */
5570 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5572 #endif /* USE_GRAPHICS */
5577 /* Build the "sound" path */
5578 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5580 /* Allocate the path */
5581 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5583 /* Validate the "sound" directory */
5584 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5586 #endif /* USE_SOUND */
5590 /* Build the "music" path */
5591 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5593 /* Allocate the path */
5594 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5596 /* Validate the "music" directory */
5597 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5599 #endif /* USE_MUSIC */
5601 /* Build the "help" path */
5602 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5604 /* Allocate the path */
5605 ANGBAND_DIR_XTRA_HELP = string_make(path);
5607 /* Validate the "help" directory */
5608 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5611 bool is_already_running()
5613 bool result = FALSE;
5616 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5617 if (GetLastError() == ERROR_ALREADY_EXISTS)
5625 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5626 LPSTR lpCmdLine, int nCmdShow)
5634 setlocale( LC_ALL, "ja_JP" );
5643 /* Prevent multiple run */
5644 if (is_already_running())
5647 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
5648 _("エラー!", "Error") ,
5649 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5654 if (hPrevInst == NULL)
5656 wc.style = CS_CLASSDC;
5657 wc.lpfnWndProc = AngbandWndProc;
5659 wc.cbWndExtra = 4; /* one long pointer to term_data */
5660 wc.hInstance = hInst;
5661 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5662 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5663 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5664 wc.lpszMenuName = AppName;
5665 wc.lpszClassName = AppName;
5667 if (!RegisterClass(&wc)) exit(1);
5669 wc.lpfnWndProc = AngbandListProc;
5670 wc.lpszMenuName = NULL;
5671 wc.lpszClassName = AngList;
5673 if (!RegisterClass(&wc)) exit(2);
5677 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5678 wc.lpfnWndProc = AngbandSaverProc;
5680 wc.lpszMenuName = NULL;
5681 wc.lpszClassName = "WindowsScreenSaverClass";
5683 if (!RegisterClass(&wc)) exit(3);
5689 /* Temporary hooks */
5690 plog_aux = hack_plog;
5691 quit_aux = hack_quit;
5692 core_aux = hack_quit;
5694 /* Prepare the filepaths */
5697 /* Initialize the keypress analyzer */
5698 for (i = 0; special_key_list[i]; ++i)
5700 special_key[special_key_list[i]] = TRUE;
5702 /* Initialize the keypress analyzer */
5703 for (i = 0; ignore_key_list[i]; ++i)
5705 ignore_key[ignore_key_list[i]] = TRUE;
5708 /* Determine if display is 16/256/true color */
5710 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5711 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5712 ReleaseDC(NULL, hdc);
5714 /* Initialize the colors */
5715 for (i = 0; i < 256; i++)
5719 /* Extract desired values */
5720 rv = angband_color_table[i][1];
5721 gv = angband_color_table[i][2];
5722 bv = angband_color_table[i][3];
5724 /* Extract the "complex" code */
5725 win_clr[i] = PALETTERGB(rv, gv, bv);
5727 /* Save the "simple" code */
5728 angband_color_table[i][0] = win_pal[i];
5731 /* Prepare the windows */
5737 /* Activate hooks */
5738 plog_aux = hook_plog;
5739 quit_aux = hook_quit;
5740 core_aux = hook_quit;
5742 /* Set the system suffix */
5743 ANGBAND_SYS = "win";
5745 /* Set the keyboard suffix */
5746 if (7 != GetKeyboardType(0))
5747 ANGBAND_KEYBOARD = "0";
5750 /* Japanese keyboard */
5751 switch (GetKeyboardType(1))
5753 case 0x0D01: case 0x0D02:
5754 case 0x0D03: case 0x0D04:
5755 case 0x0D05: case 0x0D06:
5757 ANGBAND_KEYBOARD = "NEC98";
5761 ANGBAND_KEYBOARD = "JAPAN";
5765 /* Catch nasty signals */
5771 /* We are now initialized */
5774 if(lpCmdLine[0] == '-'){
5775 switch(lpCmdLine[1])
5780 if (!lpCmdLine[2]) break;
5781 chuukei_server = TRUE;
5782 if(connect_chuukei_server(&lpCmdLine[2])<0){
5783 msg_print("connect fail");
5786 msg_print("connect");
5794 if (!lpCmdLine[2]) break;
5795 chuukei_client = TRUE;
5796 connect_chuukei_server(&lpCmdLine[2]);
5804 if (!lpCmdLine[2]) break;
5805 prepare_browse_movie(&lpCmdLine[2]);
5815 /* Did the user double click on a save file? */
5816 if(!chuukei_server) check_for_save_file(lpCmdLine);
5818 /* Did the user double click on a save file? */
5819 check_for_save_file(lpCmdLine);
5822 /* Prompt the user */
5823 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
5827 /* Process messages forever */
5828 while (GetMessage(&msg, NULL, 0, 0))
5830 TranslateMessage(&msg);
5831 DispatchMessage(&msg);
5842 #endif /* WINDOWS */