4 * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies.
13 * This file helps Angband work with Windows computers.
15 * To use this file, use an appropriate "Makefile" or "Project File",
16 * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
17 * make sure to obtain various extra files as described below.
19 * The official compilation uses the CodeWarrior Pro compiler, which
20 * includes a special project file and precompilable header file.
23 * See also "main-dos.c" and "main-ibm.c".
26 * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
27 * and/or color redefinitions.
29 * The "lib/user/font-win.prf" contains attr/char mappings for use with the
30 * normal "lib/xtra/font/*.fon" font files.
32 * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
33 * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
37 * Compiling this file, and using the resulting executable, requires
38 * several extra files not distributed with the standard Angband code.
39 * If "USE_GRAPHICS" is defined, then "readdib.h" and "readdib.c" must
40 * be placed into "src/", and the "8X8.BMP" bitmap file must be placed
41 * into "lib/xtra/graf". In any case, some "*.fon" files (including
42 * "8X13.FON" if nothing else) must be placed into "lib/xtra/font/".
43 * If "USE_SOUND" is defined, then some special library (for example,
44 * "winmm.lib") may need to be linked in, and desired "*.WAV" sound
45 * files must be placed into "lib/xtra/sound/". All of these extra
46 * files can be found in the "ext-win" archive.
49 * The "Term_xtra_win_clear()" function should probably do a low-level
50 * clear of the current window, and redraw the borders and other things,
51 * if only for efficiency. XXX XXX XXX
53 * A simpler method is needed for selecting the "tile size" for windows.
56 * The various "warning" messages assume the existance of the "screen.w"
57 * window, I think, and only a few calls actually check for its existance,
58 * this may be okay since "NULL" means "on top of all windows". (?) The
59 * user must never be allowed to "hide" the main window, or the "menubar"
60 * will disappear. XXX XXX XXX
62 * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
63 * use with the "winhelp.exe" program. These files *may* be available
64 * at the ftp site somewhere, but I have not seen them. XXX XXX XXX
67 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
69 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
71 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
72 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
84 * Extract the "WIN32" flag from the compiler
86 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
94 * Hack -- allow use of "screen saver" mode
100 * Menu constants -- see "ANGBAND.RC"
103 #define IDM_FILE_NEW 100
104 #define IDM_FILE_OPEN 101
105 #define IDM_FILE_SAVE 110
106 #define IDM_FILE_SCORE 120
107 #define IDM_FILE_MOVIE 121
108 #define IDM_FILE_EXIT 130
110 #define IDM_WINDOW_VIS_0 200
111 #define IDM_WINDOW_VIS_1 201
112 #define IDM_WINDOW_VIS_2 202
113 #define IDM_WINDOW_VIS_3 203
114 #define IDM_WINDOW_VIS_4 204
115 #define IDM_WINDOW_VIS_5 205
116 #define IDM_WINDOW_VIS_6 206
117 #define IDM_WINDOW_VIS_7 207
119 #define IDM_WINDOW_FONT_0 210
120 #define IDM_WINDOW_FONT_1 211
121 #define IDM_WINDOW_FONT_2 212
122 #define IDM_WINDOW_FONT_3 213
123 #define IDM_WINDOW_FONT_4 214
124 #define IDM_WINDOW_FONT_5 215
125 #define IDM_WINDOW_FONT_6 216
126 #define IDM_WINDOW_FONT_7 217
128 #define IDM_WINDOW_POS_0 220
129 #define IDM_WINDOW_POS_1 221
130 #define IDM_WINDOW_POS_2 222
131 #define IDM_WINDOW_POS_3 223
132 #define IDM_WINDOW_POS_4 224
133 #define IDM_WINDOW_POS_5 225
134 #define IDM_WINDOW_POS_6 226
135 #define IDM_WINDOW_POS_7 227
137 #define IDM_WINDOW_BIZ_0 230
138 #define IDM_WINDOW_BIZ_1 231
139 #define IDM_WINDOW_BIZ_2 232
140 #define IDM_WINDOW_BIZ_3 233
141 #define IDM_WINDOW_BIZ_4 234
142 #define IDM_WINDOW_BIZ_5 235
143 #define IDM_WINDOW_BIZ_6 236
144 #define IDM_WINDOW_BIZ_7 237
146 #define IDM_WINDOW_I_WID_0 240
147 #define IDM_WINDOW_I_WID_1 241
148 #define IDM_WINDOW_I_WID_2 242
149 #define IDM_WINDOW_I_WID_3 243
150 #define IDM_WINDOW_I_WID_4 244
151 #define IDM_WINDOW_I_WID_5 245
152 #define IDM_WINDOW_I_WID_6 246
153 #define IDM_WINDOW_I_WID_7 247
155 #define IDM_WINDOW_D_WID_0 250
156 #define IDM_WINDOW_D_WID_1 251
157 #define IDM_WINDOW_D_WID_2 252
158 #define IDM_WINDOW_D_WID_3 253
159 #define IDM_WINDOW_D_WID_4 254
160 #define IDM_WINDOW_D_WID_5 255
161 #define IDM_WINDOW_D_WID_6 256
162 #define IDM_WINDOW_D_WID_7 257
164 #define IDM_WINDOW_I_HGT_0 260
165 #define IDM_WINDOW_I_HGT_1 261
166 #define IDM_WINDOW_I_HGT_2 262
167 #define IDM_WINDOW_I_HGT_3 263
168 #define IDM_WINDOW_I_HGT_4 264
169 #define IDM_WINDOW_I_HGT_5 265
170 #define IDM_WINDOW_I_HGT_6 266
171 #define IDM_WINDOW_I_HGT_7 267
173 #define IDM_WINDOW_D_HGT_0 270
174 #define IDM_WINDOW_D_HGT_1 271
175 #define IDM_WINDOW_D_HGT_2 272
176 #define IDM_WINDOW_D_HGT_3 273
177 #define IDM_WINDOW_D_HGT_4 274
178 #define IDM_WINDOW_D_HGT_5 275
179 #define IDM_WINDOW_D_HGT_6 276
180 #define IDM_WINDOW_D_HGT_7 277
182 #define IDM_OPTIONS_NO_GRAPHICS 400
183 #define IDM_OPTIONS_OLD_GRAPHICS 401
184 #define IDM_OPTIONS_NEW_GRAPHICS 402
185 #define IDM_OPTIONS_NEW2_GRAPHICS 403
186 #define IDM_OPTIONS_BIGTILE 409
187 #define IDM_OPTIONS_SOUND 410
188 #define IDM_OPTIONS_MUSIC 411
189 #define IDM_OPTIONS_SAVER 420
190 #define IDM_OPTIONS_MAP 430
191 #define IDM_OPTIONS_BG 440
192 #define IDM_OPTIONS_OPEN_BG 441
194 #define IDM_DUMP_SCREEN_HTML 450
196 #define IDM_HELP_CONTENTS 901
201 * This may need to be removed for some compilers XXX XXX XXX
208 * Exclude parts of WINDOWS.H that are not needed
210 #define NOCOMM /* Comm driver APIs and definitions */
211 #define NOLOGERROR /* LogError() and related definitions */
212 #define NOPROFILER /* Profiler APIs */
213 #define NOLFILEIO /* _l* file I/O routines */
214 #define NOOPENFILE /* OpenFile and related definitions */
215 #define NORESOURCE /* Resource management */
216 #define NOATOM /* Atom management */
217 #define NOLANGUAGE /* Character test routines */
218 #define NOLSTRING /* lstr* string management routines */
219 #define NODBCS /* Double-byte character set routines */
220 #define NOKEYBOARDINFO /* Keyboard driver routines */
221 #define NOCOLOR /* COLOR_* color values */
222 #define NODRAWTEXT /* DrawText() and related definitions */
223 #define NOSCALABLEFONT /* Truetype scalable font support */
224 #define NOMETAFILE /* Metafile support */
225 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
226 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
227 #define NOKEYSTATES /* MK_* message key state flags */
228 #define NOWH /* SetWindowsHook and related WH_* definitions */
229 #define NOCLIPBOARD /* Clipboard APIs and definitions */
230 #define NOICONS /* IDI_* icon IDs */
231 #define NOMDI /* MDI support */
232 #define NOHELP /* Help support */
234 /* Not defined since it breaks Borland C++ 5.5 */
235 /* #define NOCTLMGR */ /* Control management and controls */
238 * Exclude parts of WINDOWS.H that are not needed (Win32)
240 #define WIN32_LEAN_AND_MEAN
241 #define NONLS /* All NLS defines and routines */
242 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
243 #define NOKANJI /* Kanji support stuff. */
244 #define NOMCX /* Modem Configuration Extensions */
247 * Include the "windows" support file
252 * Exclude parts of MMSYSTEM.H that are not needed
254 #define MMNODRV /* Installable driver support */
255 #define MMNOWAVE /* Waveform support */
256 #define MMNOMIDI /* MIDI support */
257 #define MMNOAUX /* Auxiliary audio support */
258 #define MMNOTIMER /* Timer support */
259 #define MMNOJOY /* Joystick support */
260 #define MMNOMCI /* MCI support */
261 #define MMNOMMIO /* Multimedia file I/O support */
262 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
265 * Include some more files. Note: the Cygnus Cygwin compiler
266 * doesn't use mmsystem.h instead it includes the winmm library
267 * which performs a similar function.
269 #include <mmsystem.h>
273 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
274 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
276 /* #define HTML_HELP */
279 #include <htmlhelp.h>
280 #endif /* HTML_HELP */
283 * Include the support for loading bitmaps
286 # include "readdib.h"
290 * Hack -- Fake declarations from "dos.h" XXX XXX XXX
293 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
295 #define FA_LABEL 0x08 /* Volume label */
296 #define FA_DIREC 0x10 /* Directory */
297 unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
301 * Silliness in WIN32 drawing routine
304 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
308 * Silliness for Windows 95
310 #ifndef WS_EX_TOOLWINDOW
311 # define WS_EX_TOOLWINDOW 0
315 * Foreground color bits (hard-coded by DOS)
317 #define VID_BLACK 0x00
318 #define VID_BLUE 0x01
319 #define VID_GREEN 0x02
320 #define VID_CYAN 0x03
322 #define VID_MAGENTA 0x05
323 #define VID_YELLOW 0x06
324 #define VID_WHITE 0x07
327 * Bright text (hard-coded by DOS)
329 #define VID_BRIGHT 0x08
332 * Background color bits (hard-coded by DOS)
334 #define VUD_BLACK 0x00
335 #define VUD_BLUE 0x10
336 #define VUD_GREEN 0x20
337 #define VUD_CYAN 0x30
339 #define VUD_MAGENTA 0x50
340 #define VUD_YELLOW 0x60
341 #define VUD_WHITE 0x70
344 * Blinking text (hard-coded by DOS)
346 #define VUD_BRIGHT 0x80
352 typedef struct _term_data term_data;
357 * Note the use of "font_want" for the names of the font file requested by
358 * the user, and the use of "font_file" for the currently active font file.
360 * The "font_file" is uppercased, and takes the form "8X13.FON", while
361 * "font_want" can be in almost any form as long as it could be construed
362 * as attempting to represent the name of a font.
377 uint rows; /* int -> uint */
413 #if 1 /* #ifdef JP */
428 * Maximum number of windows XXX XXX XXX
430 #define MAX_TERM_DATA 8
433 * An array of term_data's
435 static term_data data[MAX_TERM_DATA];
438 * Hack -- global "window creation" pointer
440 static term_data *my_td;
443 * Remember normal size of main window when maxmized
448 * was main window maximized on previous playing
450 bool win_maximized = FALSE;
455 bool game_in_progress = FALSE;
458 * note when "open"/"new" become valid
460 bool initialized = FALSE;
463 * screen paletted, i.e. 256 colors
465 bool paletted = FALSE;
468 * 16 colors screen, don't use RGB()
470 bool colors16 = FALSE;
473 * Saved instance handle
475 static HINSTANCE hInstance;
478 * Yellow brush for the cursor
480 static HBRUSH hbrYellow;
490 static HPALETTE hPal;
493 static HBITMAP hBG = NULL;
494 static int use_bg = 0;
495 static char bg_bitmap_file[1024] = "bg.bmp";
500 * The screen saver window
502 static HWND hwndSaver;
504 #endif /* USE_SAVER */
510 * Flag set once "graphics" has been initialized
512 static bool can_use_graphics = FALSE;
517 static DIBINIT infGraph;
520 * The global bitmap mask
522 static DIBINIT infMask;
524 #endif /* USE_GRAPHICS */
530 * Flag set once "sound" has been initialized
532 static bool can_use_sound = FALSE;
536 * An array of sound file names
538 static cptr sound_file[SOUND_MAX][SAMPLE_MAX];
540 #endif /* USE_SOUND */
546 #define SAMPLE_MUSIC_MAX 16
547 static cptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
548 static bool can_use_music = FALSE;
550 static MCI_OPEN_PARMS mop;
552 #endif /* USE_MUSIC */
556 * Full path to ANGBAND.INI
558 static cptr ini_file = NULL;
561 * Name of application
563 static cptr AppName = "ANGBAND";
566 * Name of sub-window type
568 static cptr AngList = "AngList";
573 static cptr ANGBAND_DIR_XTRA_GRAF;
574 static cptr ANGBAND_DIR_XTRA_SOUND;
575 static cptr ANGBAND_DIR_XTRA_MUSIC;
576 static cptr ANGBAND_DIR_XTRA_HELP;
577 #if 0 /* #ifndef JP */
578 static cptr ANGBAND_DIR_XTRA_FONT;
581 static cptr ANGBAND_DIR_XTRA_MUSIC;
586 * The "complex" color values
588 static COLORREF win_clr[256];
592 * Flag for macro trigger with dump ASCII
594 static bool Term_no_press = FALSE;
599 static bool mouse_down = FALSE;
600 static bool paint_rect = FALSE;
601 static int mousex = 0, mousey = 0;
602 static int oldx, oldy;
606 * The "simple" color values
608 * See "main-ibm.c" for original table information
610 * The entries below are taken from the "color bits" defined above.
612 * Note that many of the choices below suck, but so do crappy monitors.
614 static BYTE win_pal[256] =
616 VID_BLACK, /* Dark */
617 VID_WHITE, /* White */
618 VID_CYAN, /* Slate XXX */
619 VID_RED | VID_BRIGHT, /* Orange XXX */
621 VID_GREEN, /* Green */
623 VID_YELLOW, /* Umber XXX */
624 VID_BLACK | VID_BRIGHT, /* Light Dark */
625 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
626 VID_MAGENTA, /* Violet XXX */
627 VID_YELLOW | VID_BRIGHT, /* Yellow */
628 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
629 VID_GREEN | VID_BRIGHT, /* Light Green */
630 VID_BLUE | VID_BRIGHT, /* Light Blue */
631 VID_YELLOW /* Light Umber XXX */
636 * Hack -- define which keys are "special"
638 static bool special_key[256];
639 static bool ignore_key[256];
643 * Hack -- initialization list for "special_key"
645 static byte special_key_list[] = {
646 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
647 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
648 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
649 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
650 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
651 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
652 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
653 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
654 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
655 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
656 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
657 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
658 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
659 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
660 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
661 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
662 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
667 static byte ignore_key_list[] = {
668 VK_ESCAPE, VK_TAB, VK_SPACE,
669 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
670 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
671 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
677 * Hack -- initialization list for "special_key"
679 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
680 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
681 * catch the keypad keys (with and without numlock set, including keypad 5),
682 * the function keys (including the "menu" key which maps to F10), and the
683 * "pause" key (between scroll lock and numlock). We also catch a few odd
684 * keys which I do not recognize, but which are listed among keys which we
685 * do catch, so they should be harmless to catch.
687 static byte special_key_list[] =
689 VK_CLEAR, /* 0x0C (KP<5>) */
691 VK_PAUSE, /* 0x13 (pause) */
693 VK_PRIOR, /* 0x21 (KP<9>) */
694 VK_NEXT, /* 0x22 (KP<3>) */
695 VK_END, /* 0x23 (KP<1>) */
696 VK_HOME, /* 0x24 (KP<7>) */
697 VK_LEFT, /* 0x25 (KP<4>) */
698 VK_UP, /* 0x26 (KP<8>) */
699 VK_RIGHT, /* 0x27 (KP<6>) */
700 VK_DOWN, /* 0x28 (KP<2>) */
701 VK_SELECT, /* 0x29 (?????) */
702 VK_PRINT, /* 0x2A (?????) */
703 VK_EXECUTE, /* 0x2B (?????) */
704 VK_SNAPSHOT, /* 0x2C (?????) */
705 VK_INSERT, /* 0x2D (KP<0>) */
706 VK_DELETE, /* 0x2E (KP<.>) */
707 VK_HELP, /* 0x2F (?????) */
709 VK_NUMPAD0, /* 0x60 (KP<0>) */
710 VK_NUMPAD1, /* 0x61 (KP<1>) */
711 VK_NUMPAD2, /* 0x62 (KP<2>) */
712 VK_NUMPAD3, /* 0x63 (KP<3>) */
713 VK_NUMPAD4, /* 0x64 (KP<4>) */
714 VK_NUMPAD5, /* 0x65 (KP<5>) */
715 VK_NUMPAD6, /* 0x66 (KP<6>) */
716 VK_NUMPAD7, /* 0x67 (KP<7>) */
717 VK_NUMPAD8, /* 0x68 (KP<8>) */
718 VK_NUMPAD9, /* 0x69 (KP<9>) */
719 VK_MULTIPLY, /* 0x6A (KP<*>) */
720 VK_ADD, /* 0x6B (KP<+>) */
721 VK_SEPARATOR, /* 0x6C (?????) */
722 VK_SUBTRACT, /* 0x6D (KP<->) */
723 VK_DECIMAL, /* 0x6E (KP<.>) */
724 VK_DIVIDE, /* 0x6F (KP</>) */
755 static void delete_bg(void)
764 static int init_bg(void)
766 char * bmfile = bg_bitmap_file;
769 if (use_bg == 0) return 0;
771 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
774 plog_fmt("ÊÉ»æÍÑ¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
776 plog_fmt("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 */
1021 quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
1023 quit_fmt("Cannot find required file:\n%s", s);
1031 * Validate a directory
1033 static void validate_dir(cptr s, bool vital)
1035 /* Verify or fail */
1038 /* This directory contains needed data */
1042 quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
1044 quit_fmt("Cannot find required directory:\n%s", s);
1048 /* Attempt to create this directory */
1051 quit_fmt("Unable to create directory:\n%s", s);
1058 * Get the "size" for a window
1060 static void term_getsize(term_data *td)
1067 if (td->cols < 1) td->cols = 1;
1068 if (td->rows < 1) td->rows = 1;
1071 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1072 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1074 /* Fake window size */
1076 rc.right = rc.left + wid;
1078 rc.bottom = rc.top + hgt;
1081 /* rc.right += 1; */
1082 /* rc.bottom += 1; */
1085 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1088 td->size_wid = rc.right - rc.left;
1089 td->size_hgt = rc.bottom - rc.top;
1091 /* See CreateWindowEx */
1094 /* Extract actual location */
1095 GetWindowRect(td->w, &rc);
1097 /* Save the location */
1098 td->pos_x = rc.left;
1104 * Write the "prefs" for a single term
1106 static void save_prefs_aux(int i)
1108 term_data *td = &data[i];
1113 WINDOWPLACEMENT lpwndpl;
1118 /* Make section name */
1119 sprintf(sec_name, "Term-%d", i);
1124 strcpy(buf, td->visible ? "1" : "0");
1125 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1130 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1133 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1135 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1139 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1141 #if 1 /* #ifdef JP */
1142 wsprintf(buf, "%d", td->lf.lfWidth);
1143 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1144 wsprintf(buf, "%d", td->lf.lfHeight);
1145 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1146 wsprintf(buf, "%d", td->lf.lfWeight);
1147 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1150 strcpy(buf, td->bizarre ? "1" : "0");
1151 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1154 wsprintf(buf, "%d", td->tile_wid);
1155 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1158 wsprintf(buf, "%d", td->tile_hgt);
1159 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1161 /* Get window placement and dimensions */
1162 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1163 GetWindowPlacement(td->w, &lpwndpl);
1165 /* Acquire position in *normal* mode (not minimized) */
1166 rc = lpwndpl.rcNormalPosition;
1168 /* Window size (x) */
1169 if (i == 0) wsprintf(buf, "%d", normsize.x);
1170 else wsprintf(buf, "%d", td->cols);
1171 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1173 /* Window size (y) */
1174 if (i == 0) wsprintf(buf, "%d", normsize.y);
1175 else wsprintf(buf, "%d", td->rows);
1176 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1178 /* Maxmized (only main window) */
1181 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1182 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1185 /* Acquire position */
1186 GetWindowRect(td->w, &rc);
1188 /* Window position (x) */
1189 wsprintf(buf, "%d", rc.left);
1190 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1192 /* Window position (y) */
1193 wsprintf(buf, "%d", rc.top);
1194 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1196 /* Window Z position */
1199 strcpy(buf, td->posfix ? "1" : "0");
1200 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1208 * We assume that the windows have all been initialized
1210 static void save_prefs(void)
1216 /* Save the "arg_graphics" flag */
1217 sprintf(buf, "%d", arg_graphics);
1218 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1220 /* Save the "arg_bigtile" flag */
1221 strcpy(buf, arg_bigtile ? "1" : "0");
1222 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1224 /* Save the "arg_sound" flag */
1225 strcpy(buf, arg_sound ? "1" : "0");
1226 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1228 /* Save the "arg_sound" flag */
1229 strcpy(buf, arg_music ? "1" : "0");
1230 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1233 strcpy(buf, use_bg ? "1" : "0");
1234 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1235 WritePrivateProfileString("Angband", "BackGroundBitmap",
1236 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1238 /* Save window prefs */
1239 for (i = 0; i < MAX_TERM_DATA; ++i)
1247 * Load the "prefs" for a single term
1249 static void load_prefs_aux(int i)
1251 term_data *td = &data[i];
1255 int wid, hgt, posx, posy;
1256 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1257 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1261 /* Make section name */
1262 sprintf(sec_name, "Term-%d", i);
1264 /* Make section name */
1265 sprintf(sec_name, "Term-%d", i);
1270 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1273 /* Desired font, with default */
1275 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1278 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1280 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1286 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1288 /* Analyze font, save desired font name */
1289 #if 1 /* #ifdef JP */
1290 td->font_want = string_make(tmp);
1292 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1293 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1294 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1296 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1301 #if 1 /* #ifdef JP */
1302 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1303 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1305 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1306 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1311 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1312 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1313 normsize.x = td->cols; normsize.y = td->rows;
1318 win_maximized = GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file);
1321 /* Window position */
1322 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1323 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1324 td->pos_x = MIN(MAX(0, posx), dispx-128);
1325 td->pos_y = MIN(MAX(0, posy), dispy-128);
1327 /* Window Z position */
1330 td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1338 static void load_prefs(void)
1342 /* Extract the "arg_graphics" flag */
1343 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1345 /* Extract the "arg_bigtile" flag */
1346 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1347 use_bigtile = arg_bigtile;
1349 /* Extract the "arg_sound" flag */
1350 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1352 /* Extract the "arg_sound" flag */
1353 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1356 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1357 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1359 /* Load window prefs */
1360 for (i = 0; i < MAX_TERM_DATA; ++i)
1366 #if defined(USE_SOUND) || defined(USE_MUSIC)
1369 * XXX XXX XXX - Taken from files.c.
1371 * Extract "tokens" from a buffer
1373 * This function uses "whitespace" as delimiters, and treats any amount of
1374 * whitespace as a single delimiter. We will never return any empty tokens.
1375 * When given an empty buffer, or a buffer containing only "whitespace", we
1376 * will return no tokens. We will never extract more than "num" tokens.
1378 * By running a token through the "text_to_ascii()" function, you can allow
1379 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1381 * We save pointers to the tokens in "tokens", and return the number found.
1383 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1395 /* Skip leading whitespace */
1396 for ( ; *s && iswspace(*s); ++s) /* loop */;
1401 /* Find next whitespace, if any */
1402 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1404 /* Nuke and advance (if necessary) */
1405 if (*t) *t++ = '\0';
1407 /* Save the token */
1418 #endif /* USE_SOUND || USE_MUSIC */
1422 static void load_sound_prefs(void)
1426 char ini_path[1024];
1427 char wav_path[1024];
1428 char *zz[SAMPLE_MAX];
1430 /* Access the sound.cfg */
1432 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1434 for (i = 0; i < SOUND_MAX; i++)
1436 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1438 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1440 for (j = 0; j < num; j++)
1442 /* Access the sound */
1443 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1445 /* Save the sound filename, if it exists */
1446 if (check_file(wav_path))
1447 sound_file[i][j] = string_make(zz[j]);
1452 #endif /* USE_SOUND */
1456 static void load_music_prefs(void)
1460 char ini_path[1024];
1461 char wav_path[1024];
1462 char *zz[SAMPLE_MAX];
1464 /* Access the music.cfg */
1466 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1468 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1470 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1472 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1474 for (j = 0; j < num; j++)
1476 /* Access the sound */
1477 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1479 /* Save the sound filename, if it exists */
1480 if (check_file(wav_path))
1481 music_file[i][j] = string_make(zz[j]);
1486 #endif /* USE_MUSIC */
1489 * Create the new global palette based on the bitmap palette
1490 * (if any), and the standard 16 entry palette derived from
1491 * "win_clr[]" which is used for the basic 16 Angband colors.
1493 * This function is never called before all windows are ready.
1495 * This function returns FALSE if the new palette could not be
1496 * prepared, which should normally be a fatal error. XXX XXX
1498 * Note that only some machines actually use a "palette".
1500 static int new_palette(void)
1508 LPLOGPALETTE pLogPal;
1509 LPPALETTEENTRY lppe;
1514 /* This makes no sense */
1515 if (!paletted) return (TRUE);
1525 /* Check the bitmap palette */
1526 hBmPal = infGraph.hPalette;
1528 /* Use the bitmap */
1531 lppeSize = 256 * sizeof(PALETTEENTRY);
1532 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1533 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1534 if ((nEntries == 0) || (nEntries > 220))
1538 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1540 plog("Please switch to high- or true-color mode.");
1545 rnfree(lppe, lppeSize);
1552 #endif /* USE_GRAPHICS */
1554 /* Size of palette */
1555 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1557 /* Allocate palette */
1558 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1561 pLogPal->palVersion = 0x300;
1563 /* Make room for bitmap and normal data */
1564 pLogPal->palNumEntries = nEntries + 16;
1566 /* Save the bitmap data */
1567 for (i = 0; i < nEntries; i++)
1569 pLogPal->palPalEntry[i] = lppe[i];
1572 /* Save the normal data */
1573 for (i = 0; i < 16; i++)
1577 /* Access the entry */
1578 p = &(pLogPal->palPalEntry[i+nEntries]);
1580 /* Save the colors */
1581 p->peRed = GetRValue(win_clr[i]);
1582 p->peGreen = GetGValue(win_clr[i]);
1583 p->peBlue = GetBValue(win_clr[i]);
1585 /* Save the flags */
1586 p->peFlags = PC_NOCOLLAPSE;
1589 /* Free something */
1590 if (lppe) rnfree(lppe, lppeSize);
1592 /* Create a new palette, or fail */
1593 hNewPal = CreatePalette(pLogPal);
1595 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1597 if (!hNewPal) quit("Cannot create palette!");
1601 /* Free the palette */
1602 rnfree(pLogPal, pLogPalSize);
1607 /* Realize the palette */
1609 SelectPalette(hdc, hNewPal, 0);
1610 i = RealizePalette(hdc);
1611 ReleaseDC(td->w, hdc);
1613 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1615 if (i == 0) quit("Cannot realize palette!");
1620 for (i = 1; i < MAX_TERM_DATA; i++)
1625 SelectPalette(hdc, hNewPal, 0);
1626 ReleaseDC(td->w, hdc);
1629 /* Delete old palette */
1630 if (hPal) DeleteObject(hPal);
1632 /* Save new palette */
1642 * Initialize graphics
1644 static bool init_graphics(void)
1646 /* Initialize once */
1647 /* if (can_use_graphics != arg_graphics) */
1653 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1660 ANGBAND_GRAF = "new";
1662 else if (arg_graphics == GRAPHICS_HENGBAND)
1669 ANGBAND_GRAF = "ne2";
1677 ANGBAND_GRAF = "old";
1680 /* Access the bitmap file */
1681 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1683 /* Load the bitmap or quit */
1684 if (!ReadDIB(data[0].w, buf, &infGraph))
1687 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1689 plog_fmt("Cannot read bitmap file '%s'", name);
1695 /* Save the new sizes */
1696 infGraph.CellWidth = wid;
1697 infGraph.CellHeight = hgt;
1699 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1701 /* Access the mask file */
1702 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1704 /* Load the bitmap or quit */
1705 if (!ReadDIB(data[0].w, buf, &infMask))
1707 plog_fmt("Cannot read bitmap file '%s'", buf);
1711 if (arg_graphics == GRAPHICS_HENGBAND)
1713 /* Access the mask file */
1714 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1716 /* Load the bitmap or quit */
1717 if (!ReadDIB(data[0].w, buf, &infMask))
1719 plog_fmt("Cannot read bitmap file '%s'", buf);
1724 /* Activate a palette */
1727 /* Free bitmap XXX XXX XXX */
1731 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1733 plog("Cannot activate palette!");
1739 /* Graphics available */
1740 can_use_graphics = arg_graphics;
1744 return (can_use_graphics);
1746 #endif /* USE_GRAPHICS */
1753 static bool init_music(void)
1755 /* Initialize once */
1758 /* Load the prefs */
1761 /* Sound available */
1762 can_use_music = TRUE;
1766 return (can_use_music);
1768 #endif /* USE_SOUND */
1774 static bool init_sound(void)
1776 /* Initialize once */
1779 /* Load the prefs */
1782 /* Sound available */
1783 can_use_sound = TRUE;
1787 return (can_use_sound);
1789 #endif /* USE_SOUND */
1795 static void term_window_resize(term_data *td)
1797 /* Require window */
1800 /* Resize the window */
1801 SetWindowPos(td->w, 0, 0, 0,
1802 td->size_wid, td->size_hgt,
1803 SWP_NOMOVE | SWP_NOZORDER);
1806 InvalidateRect(td->w, NULL, TRUE);
1811 * Force the use of a new "font file" for a term_data
1813 * This function may be called before the "window" is ready
1815 * This function returns zero only if everything succeeds.
1817 * Note that the "font name" must be capitalized!!!
1819 static errr term_force_font(term_data *td, cptr path)
1823 #if 0 /* #ifndef JP */
1829 /* Forget the old font (if needed) */
1830 if (td->font_id) DeleteObject(td->font_id);
1832 #if 1 /* #ifdef JP */
1836 /* Create the font (using the 'base' of the font file name!) */
1837 td->font_id = CreateFontIndirect(&(td->lf));
1838 wid = td->lf.lfWidth;
1839 hgt = td->lf.lfHeight;
1840 if (!td->font_id) return (1);
1842 /* Forget old font */
1848 for (i = 0; i < MAX_TERM_DATA; i++)
1850 /* Don't check when closing the application */
1853 /* Check "screen" */
1854 if ((td != &data[i]) &&
1855 (data[i].font_file) &&
1856 (streq(data[i].font_file, td->font_file)))
1862 /* Remove unused font resources */
1863 if (!used) RemoveFontResource(td->font_file);
1865 /* Free the old name */
1866 string_free(td->font_file);
1869 td->font_file = NULL;
1873 if (!path) return (1);
1878 /* Analyze font path */
1879 base = analyze_font(buf, &wid, &hgt);
1882 if (!suffix(base, ".FON")) return (1);
1885 if (!check_file(buf)) return (1);
1887 /* Load the new font */
1888 if (!AddFontResource(buf)) return (1);
1890 /* Save new font name */
1891 td->font_file = string_make(base);
1893 /* Remove the "suffix" */
1894 base[strlen(base)-4] = '\0';
1896 /* Create the font (using the 'base' of the font file name!) */
1897 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1898 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1899 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1900 FIXED_PITCH | FF_DONTCARE, base);
1903 /* Hack -- Unknown size */
1910 /* all this trouble to get the cell size */
1911 hdcDesktop = GetDC(HWND_DESKTOP);
1912 hfOld = SelectObject(hdcDesktop, td->font_id);
1913 GetTextMetrics(hdcDesktop, &tm);
1914 SelectObject(hdcDesktop, hfOld);
1915 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1917 /* Font size info */
1918 wid = tm.tmAveCharWidth;
1922 /* Save the size info */
1933 * Allow the user to change the font for this window.
1935 static void term_change_font(term_data *td)
1937 #if 1 /* #ifdef JP */
1940 memset(&cf, 0, sizeof(cf));
1941 cf.lStructSize = sizeof(cf);
1942 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1943 cf.lpLogFont = &(td->lf);
1945 if (ChooseFont(&cf))
1947 /* Force the font */
1948 term_force_font(td, NULL);
1950 /* Assume not bizarre */
1953 /* Reset the tile info */
1954 td->tile_wid = td->font_wid;
1955 td->tile_hgt = td->font_hgt;
1957 /* Analyze the font */
1960 /* Resize the window */
1961 term_window_resize(td);
1967 char tmp[1024] = "";
1969 /* Extract a default if possible */
1970 if (td->font_file) strcpy(tmp, td->font_file);
1972 /* Ask for a choice */
1973 memset(&ofn, 0, sizeof(ofn));
1974 ofn.lStructSize = sizeof(ofn);
1975 ofn.hwndOwner = data[0].w;
1976 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1977 ofn.nFilterIndex = 1;
1978 ofn.lpstrFile = tmp;
1980 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1981 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1982 ofn.lpstrDefExt = "fon";
1984 /* Force choice if legal */
1985 if (GetOpenFileName(&ofn))
1987 /* Force the font */
1988 if (term_force_font(td, tmp))
1990 /* Access the standard font file */
1991 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1993 /* Force the use of that font */
1994 (void)term_force_font(td, tmp);
1997 /* Assume not bizarre */
1998 td->bizarre = FALSE;
2000 /* Reset the tile info */
2001 td->tile_wid = td->font_wid;
2002 td->tile_hgt = td->font_hgt;
2004 /* Analyze the font */
2007 /* Resize the window */
2008 term_window_resize(td);
2015 * Allow the user to lock this window.
2017 static void term_window_pos(term_data *td, HWND hWnd)
2019 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2020 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2023 static void windows_map(void);
2026 * Hack -- redraw a term_data
2028 static void term_data_redraw(term_data *td)
2032 /* Redraw the map */
2037 /* Activate the term */
2038 Term_activate(&td->t);
2040 /* Redraw the contents */
2043 /* Restore the term */
2044 Term_activate(term_screen);
2049 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2053 HBRUSH myBrush, oldBrush;
2055 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2056 int tx = td->size_ow1 + x * td->tile_wid;
2057 int ty = td->size_oh1 + y * td->tile_hgt;
2058 int tw = w * td->tile_wid - 1;
2059 int th = h * td->tile_hgt - 1;
2062 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2063 oldBrush = SelectObject(hdc, myBrush);
2064 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2066 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2068 SelectObject(hdc, oldBrush);
2069 SelectObject(hdc, oldPen);
2074 /*** Function hooks needed by "Term" ***/
2080 * Initialize a new Term
2082 static void Term_init_win(term *t)
2091 static void Term_nuke_win(term *t)
2100 * Interact with the User
2102 static errr Term_user_win(int n)
2113 * React to global changes
2115 static errr Term_xtra_win_react(void)
2123 /* Save the default colors */
2124 for (i = 0; i < 256; i++)
2126 /* Simply accept the desired colors */
2127 win_pal[i] = angband_color_table[i][0];
2138 bool change = FALSE;
2140 /* Save the default colors */
2141 for (i = 0; i < 256; i++)
2143 /* Extract desired values */
2144 rv = angband_color_table[i][1];
2145 gv = angband_color_table[i][2];
2146 bv = angband_color_table[i][3];
2148 /* Extract a full color code */
2149 code = PALETTERGB(rv, gv, bv);
2151 /* Activate changes */
2152 if (win_clr[i] != code)
2154 /* Note the change */
2157 /* Apply the desired color */
2162 /* Activate the palette if needed */
2163 if (change) (void)new_palette();
2169 /* Handle "arg_sound" */
2170 if (use_sound != arg_sound)
2172 /* Initialize (if needed) */
2173 if (arg_sound && !init_sound())
2177 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
2179 plog("Cannot initialize sound!");
2187 /* Change setting */
2188 use_sound = arg_sound;
2195 /* Handle "arg_sound" */
2196 if (use_music != arg_music)
2198 /* Initialize (if needed) */
2199 if (arg_music && !init_music())
2203 plog("BGM¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
2205 plog("Cannot initialize BGM!");
2211 /* Change setting */
2212 use_music = arg_music;
2220 /* Handle "arg_graphics" */
2221 if (use_graphics != arg_graphics)
2223 /* Initialize (if needed) */
2224 if (arg_graphics && !init_graphics())
2228 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
2230 plog("Cannot initialize graphics!");
2235 arg_graphics = GRAPHICS_NONE;
2238 /* Change setting */
2239 use_graphics = arg_graphics;
2242 #ifdef ANGBAND_2_8_1
2244 #else /* ANGBAND_2_8_1 */
2245 reset_visuals(TRUE);
2246 #endif /* ANGBAND_2_8_1 */
2249 #endif /* USE_GRAPHICS */
2252 /* Clean up windows */
2253 for (i = 0; i < MAX_TERM_DATA; i++)
2257 term_data *td = &data[i];
2259 /* Update resized windows */
2260 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2263 Term_activate(&td->t);
2265 /* Hack -- Resize the term */
2266 Term_resize(td->cols, td->rows);
2268 /* Redraw the contents */
2283 * Process at least one event
2285 static errr Term_xtra_win_event(int v)
2289 /* Wait for an event */
2293 if (GetMessage(&msg, NULL, 0, 0))
2295 TranslateMessage(&msg);
2296 DispatchMessage(&msg);
2300 /* Check for an event */
2304 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2306 TranslateMessage(&msg);
2307 DispatchMessage(&msg);
2317 * Process all pending events
2319 static errr Term_xtra_win_flush(void)
2323 /* Process all pending events */
2324 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2326 TranslateMessage(&msg);
2327 DispatchMessage(&msg);
2336 * Hack -- clear the screen
2338 * Make this more efficient XXX XXX XXX
2340 static errr Term_xtra_win_clear(void)
2342 term_data *td = (term_data*)(Term->data);
2347 /* Rectangle to erase */
2348 rc.left = td->size_ow1;
2349 rc.right = rc.left + td->cols * td->tile_wid;
2350 rc.top = td->size_oh1;
2351 rc.bottom = rc.top + td->rows * td->tile_hgt;
2355 SetBkColor(hdc, RGB(0, 0, 0));
2356 SelectObject(hdc, td->font_id);
2357 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2362 rc.left = 0; rc.top = 0;
2365 ReleaseDC(td->w, hdc);
2373 * Hack -- make a noise
2375 static errr Term_xtra_win_noise(void)
2377 MessageBeep(MB_ICONASTERISK);
2383 * Hack -- make a sound
2385 static errr Term_xtra_win_sound(int v)
2390 #endif /* USE_SOUND */
2392 /* Sound disabled */
2393 if (!use_sound) return (1);
2396 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2400 /* Count the samples */
2401 for (i = 0; i < SAMPLE_MAX; i++)
2403 if (!sound_file[v][i])
2408 if (i == 0) return (1);
2410 /* Build the path */
2411 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2415 /* Play the sound, catch errors */
2416 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2420 /* Play the sound, catch errors */
2421 return (sndPlaySound(buf, SND_ASYNC));
2425 #else /* USE_SOUND */
2430 #endif /* USE_SOUND */
2434 * Hack -- play a music
2436 static errr Term_xtra_win_music(int v)
2441 #endif /* USE_MUSIC */
2443 /* Sound disabled */
2444 if (!use_music) return (1);
2447 if ((v < 0) || (v >= MUSIC_BASIC_MAX)) return (1);
2451 /* Count the samples */
2452 for (i = 0; i < SAMPLE_MAX; i++)
2454 if (!music_file[v][i])
2459 if (i == 0) return (1);
2461 /* Build the path */
2462 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2464 #endif /* USE_MUSIC */
2468 mop.lpstrDeviceType = "WaveAudio";
2469 mop.lpstrElementName = buf;
2470 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2471 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2472 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2475 #else /* USE_MUSIC */
2480 #endif /* USE_MUSIC */
2485 * Delay for "x" milliseconds
2487 static int Term_xtra_win_delay(int v)
2501 t = GetTickCount() + v;
2504 while (GetTickCount() < t)
2506 /* Handle messages */
2507 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2509 TranslateMessage(&msg);
2510 DispatchMessage(&msg);
2522 * Do a "special thing"
2524 static errr Term_xtra_win(int n, int v)
2526 /* Handle a subset of the legal requests */
2529 /* Make a bell sound */
2530 case TERM_XTRA_NOISE:
2532 return (Term_xtra_win_noise());
2536 case TERM_XTRA_MUSIC:
2538 return (Term_xtra_win_music(v));
2541 /* Make a special sound */
2542 case TERM_XTRA_SOUND:
2544 return (Term_xtra_win_sound(v));
2547 /* Process random events */
2548 case TERM_XTRA_BORED:
2550 return (Term_xtra_win_event(0));
2553 /* Process an event */
2554 case TERM_XTRA_EVENT:
2556 return (Term_xtra_win_event(v));
2559 /* Flush all events */
2560 case TERM_XTRA_FLUSH:
2562 return (Term_xtra_win_flush());
2565 /* Clear the screen */
2566 case TERM_XTRA_CLEAR:
2568 return (Term_xtra_win_clear());
2571 /* React to global changes */
2572 case TERM_XTRA_REACT:
2574 return (Term_xtra_win_react());
2577 /* Delay for some milliseconds */
2578 case TERM_XTRA_DELAY:
2580 return (Term_xtra_win_delay(v));
2591 * Low level graphics (Assumes valid input).
2593 * Draw a "cursor" at (x,y), using a "yellow box".
2595 static errr Term_curs_win(int x, int y)
2597 term_data *td = (term_data*)(Term->data);
2602 int tile_wid, tile_hgt;
2606 tile_wid = td->map_tile_wid;
2607 tile_hgt = td->map_tile_hgt;
2611 tile_wid = td->tile_wid;
2612 tile_hgt = td->tile_hgt;
2615 /* Frame the grid */
2616 rc.left = x * tile_wid + td->size_ow1;
2617 rc.right = rc.left + tile_wid;
2618 rc.top = y * tile_hgt + td->size_oh1;
2619 rc.bottom = rc.top + tile_hgt;
2621 /* Cursor is done as a yellow "box" */
2623 FrameRect(hdc, &rc, hbrYellow);
2624 ReleaseDC(td->w, hdc);
2632 * Low level graphics (Assumes valid input).
2634 * Draw a "big cursor" at (x,y), using a "yellow box".
2636 static errr Term_bigcurs_win(int x, int y)
2638 term_data *td = (term_data*)(Term->data);
2643 int tile_wid, tile_hgt;
2647 /* Normal cursor in map window */
2648 Term_curs_win(x, y);
2653 tile_wid = td->tile_wid;
2654 tile_hgt = td->tile_hgt;
2657 /* Frame the grid */
2658 rc.left = x * tile_wid + td->size_ow1;
2659 rc.right = rc.left + 2 * tile_wid;
2660 rc.top = y * tile_hgt + td->size_oh1;
2661 rc.bottom = rc.top + tile_hgt;
2663 /* Cursor is done as a yellow "box" */
2665 FrameRect(hdc, &rc, hbrYellow);
2666 ReleaseDC(td->w, hdc);
2674 * Low level graphics (Assumes valid input).
2676 * Erase a "block" of "n" characters starting at (x,y).
2678 static errr Term_wipe_win(int x, int y, int n)
2680 term_data *td = (term_data*)(Term->data);
2685 /* Rectangle to erase in client coords */
2686 rc.left = x * td->tile_wid + td->size_ow1;
2687 rc.right = rc.left + n * td->tile_wid;
2688 rc.top = y * td->tile_hgt + td->size_oh1;
2689 rc.bottom = rc.top + td->tile_hgt;
2692 SetBkColor(hdc, RGB(0, 0, 0));
2693 SelectObject(hdc, td->font_id);
2698 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2699 ReleaseDC(td->w, hdc);
2707 * Low level graphics. Assumes valid input.
2709 * Draw several ("n") chars, with an attr, at a given location.
2711 * All "graphic" data is handled by "Term_pict_win()", below.
2713 * One would think there is a more efficient method for telling a window
2714 * what color it should be using to draw with, but perhaps simply changing
2715 * it every time is not too inefficient. XXX XXX XXX
2717 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2719 term_data *td = (term_data*)(Term->data);
2723 #if 1 /* #ifdef JP */
2724 static HBITMAP WALL;
2725 static HBRUSH myBrush, oldBrush;
2727 static bool init_done = FALSE;
2730 WALL = LoadBitmap(hInstance, AppName);
2731 myBrush = CreatePatternBrush(WALL);
2736 /* Total rectangle */
2737 rc.left = x * td->tile_wid + td->size_ow1;
2738 rc.right = rc.left + n * td->tile_wid;
2739 rc.top = y * td->tile_hgt + td->size_oh1;
2740 rc.bottom = rc.top + td->tile_hgt;
2745 /* Background color */
2746 SetBkColor(hdc, RGB(0, 0, 0));
2748 /* Foreground color */
2751 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2755 SetTextColor(hdc, win_clr[a&0x0F]);
2759 SetTextColor(hdc, win_clr[a]);
2763 SelectObject(hdc, td->font_id);
2766 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2770 (td->tile_hgt != td->font_hgt) ||
2771 (td->tile_wid != td->font_wid))
2775 /* Erase complete rectangle */
2776 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2779 if (use_bg) DrawBG(hdc, &rc);
2782 rc.left += ((td->tile_wid - td->font_wid) / 2);
2783 rc.right = rc.left + td->font_wid;
2784 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2785 rc.bottom = rc.top + td->font_hgt;
2787 /* Dump each character */
2788 for (i = 0; i < n; i++)
2791 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2793 rc.right += td->font_wid;
2795 oldBrush = SelectObject(hdc, myBrush);
2796 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2799 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2801 SelectObject(hdc, oldBrush);
2802 SelectObject(hdc, oldPen);
2803 rc.right -= td->font_wid;
2807 rc.left += 2 * td->tile_wid;
2808 rc.right += 2 * td->tile_wid;
2810 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2812 rc.right += td->font_wid;
2814 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2816 rc.right -= td->font_wid;
2820 rc.left += 2 * td->tile_wid;
2821 rc.right += 2 * td->tile_wid;
2822 } else if (*(s+i)==127){
2823 oldBrush = SelectObject(hdc, myBrush);
2824 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2827 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2829 SelectObject(hdc, oldBrush);
2830 SelectObject(hdc, oldPen);
2833 rc.left += td->tile_wid;
2834 rc.right += td->tile_wid;
2837 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2840 rc.left += td->tile_wid;
2841 rc.right += td->tile_wid;
2846 oldBrush = SelectObject(hdc, myBrush);
2847 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2850 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2852 SelectObject(hdc, oldBrush);
2853 SelectObject(hdc, oldPen);
2856 rc.left += td->tile_wid;
2857 rc.right += td->tile_wid;
2860 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2864 rc.left += td->tile_wid;
2865 rc.right += td->tile_wid;
2869 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2873 rc.left += td->tile_wid;
2874 rc.right += td->tile_wid;
2885 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2890 ReleaseDC(td->w, hdc);
2898 * Low level graphics. Assumes valid input.
2900 * Draw an array of "special" attr/char pairs at the given location.
2902 * We use the "Term_pict_win()" function for "graphic" data, which are
2903 * encoded by setting the "high-bits" of both the "attr" and the "char"
2904 * data. We use the "attr" to represent the "row" of the main bitmap,
2905 * and the "char" to represent the "col" of the main bitmap. The use
2906 * of this function is induced by the "higher_pict" flag.
2908 * If "graphics" is not available, we simply "wipe" the given grids.
2910 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2912 term_data *td = (term_data*)(Term->data);
2918 int x2, y2, w2, h2, tw2;
2930 /* Erase the grids */
2931 return (Term_wipe_win(x, y, n));
2934 /* Size of bitmap cell */
2935 w1 = infGraph.CellWidth;
2936 h1 = infGraph.CellHeight;
2938 /* Size of window cell */
2941 w2 = td->map_tile_wid;
2942 h2 = td->map_tile_hgt;
2951 if (use_bigtile) tw2 *= 2;
2954 /* Location of window cell */
2955 x2 = x * w2 + td->size_ow1;
2956 y2 = y * h2 + td->size_oh1;
2962 hdcSrc = CreateCompatibleDC(hdc);
2963 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2965 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2967 hdcMask = CreateCompatibleDC(hdc);
2968 SelectObject(hdcMask, infMask.hBitmap);
2971 /* Draw attr/char pairs */
2972 for (i = 0; i < n; i++, x2 += w2)
2977 /* Extract picture */
2978 int row = (a & 0x7F);
2979 int col = (c & 0x7F);
2981 /* Location of bitmap cell */
2985 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2987 x3 = (tcp[i] & 0x7F) * w1;
2988 y3 = (tap[i] & 0x7F) * h1;
2991 if ((w1 == tw2) && (h1 == h2))
2993 /* Copy the terrain picture from the bitmap to the window */
2994 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2996 /* Mask out the tile */
2997 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
3000 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3003 /* Need to stretch */
3006 /* Set the correct mode for stretching the tiles */
3007 SetStretchBltMode(hdc, COLORONCOLOR);
3009 /* Copy the terrain picture from the bitmap to the window */
3010 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
3012 /* Only draw if terrain and overlay are different */
3013 if ((x1 != x3) || (y1 != y3))
3015 /* Mask out the tile */
3016 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3019 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3026 if ((w1 == tw2) && (h1 == h2))
3028 /* Copy the picture from the bitmap to the window */
3029 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3032 /* Need to stretch */
3035 /* Set the correct mode for stretching the tiles */
3036 SetStretchBltMode(hdc, COLORONCOLOR);
3038 /* Copy the picture from the bitmap to the window */
3039 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3045 SelectObject(hdcSrc, hbmSrcOld);
3048 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3051 SelectObject(hdcMask, hbmSrcOld);
3056 ReleaseDC(td->w, hdc);
3058 #else /* USE_GRAPHICS */
3060 /* Just erase this grid */
3061 return (Term_wipe_win(x, y, n));
3063 #endif /* USE_GRAPHICS */
3070 static void windows_map(void)
3072 term_data *td = &data[0];
3074 int x, min_x, max_x;
3075 int y, min_y, max_y;
3079 /* Only in graphics mode */
3080 if (!use_graphics) return;
3083 Term_xtra_win_clear();
3085 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3086 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3087 td->map_active = TRUE;
3097 for (x = min_x; x < max_x; x++)
3099 for (y = min_y; y < max_y; y++)
3101 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3103 /* Ignore non-graphics */
3104 if ((a & 0x80) && (c & 0x80))
3106 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3111 /* Hilite the player */
3112 Term_curs_win(px - min_x, py - min_y);
3114 /* Wait for a keypress, flush key buffer */
3115 Term_inkey(&c, TRUE, TRUE);
3118 /* Switch off the map display */
3119 td->map_active = FALSE;
3121 /* Restore screen */
3122 Term_xtra_win_clear();
3127 /*** Other routines ***/
3131 * Create and initialize a "term_data" given a title
3133 static void term_data_link(term_data *td)
3137 /* Initialize the term */
3138 term_init(t, td->cols, td->rows, td->keys);
3140 /* Use a "software" cursor */
3141 t->soft_cursor = TRUE;
3143 /* Use "Term_pict" for "graphic" data */
3144 t->higher_pict = TRUE;
3146 /* Erase with "white space" */
3147 t->attr_blank = TERM_WHITE;
3148 t->char_blank = ' ';
3151 /* Prepare the init/nuke hooks */
3152 t->init_hook = Term_init_win;
3153 t->nuke_hook = Term_nuke_win;
3156 /* Prepare the template hooks */
3157 t->user_hook = Term_user_win;
3158 t->xtra_hook = Term_xtra_win;
3159 t->curs_hook = Term_curs_win;
3160 t->bigcurs_hook = Term_bigcurs_win;
3161 t->wipe_hook = Term_wipe_win;
3162 t->text_hook = Term_text_win;
3163 t->pict_hook = Term_pict_win;
3165 /* Remember where we came from */
3166 t->data = (vptr)(td);
3171 * Create the windows
3173 * First, instantiate the "default" values, then read the "ini_file"
3174 * to over-ride selected values, then create the windows, and fonts.
3176 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3177 * must make active to realize the palette. XXX XXX XXX
3179 static void init_windows(void)
3185 #if 0 /* #ifndef JP */
3191 WIPE(td, term_data);
3195 td->s = angband_term_name[0];
3209 #if 1 /* #ifdef JP */
3213 for (i = 1; i < MAX_TERM_DATA; i++)
3216 WIPE(td, term_data);
3217 td->s = angband_term_name[i];
3221 td->visible = FALSE;
3226 td->pos_x = (7 - i) * 30;
3227 td->pos_y = (7 - i) * 20;
3229 #if 1 /* #ifdef JP */
3239 /* Main window (need these before term_getsize gets called) */
3241 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3242 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3247 /* Sub windows (need these before term_getsize gets called) */
3248 for (i = 1; i < MAX_TERM_DATA; i++)
3251 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3252 td->dwExStyle = (WS_EX_TOOLWINDOW);
3257 for (i = 0; i < MAX_TERM_DATA; i++)
3261 #if 1 /* #ifdef JP */
3262 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3263 td->lf.lfCharSet = DEFAULT_CHARSET;
3264 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3265 /* Activate the chosen font */
3266 term_force_font(td, NULL);
3267 td->tile_wid = td->font_wid;
3268 td->tile_hgt = td->font_hgt;
3270 /* Access the standard font file */
3271 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3273 /* Activate the chosen font */
3274 if (term_force_font(td, buf))
3276 /* Access the standard font file */
3277 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3279 /* Force the use of that font */
3280 (void)term_force_font(td, buf);
3286 /* Assume not bizarre */
3287 td->bizarre = FALSE;
3292 /* Analyze the font */
3295 /* Resize the window */
3296 term_window_resize(td);
3300 /* Sub windows (reverse order) */
3301 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3306 td->w = CreateWindowEx(td->dwExStyle, AngList,
3308 td->pos_x, td->pos_y,
3309 td->size_wid, td->size_hgt,
3310 HWND_DESKTOP, NULL, hInstance, NULL);
3313 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3315 if (!td->w) quit("Failed to create sub-window");
3321 td->size_hack = TRUE;
3322 ShowWindow(td->w, SW_SHOW);
3323 td->size_hack = FALSE;
3327 angband_term[i] = &td->t;
3331 /* Activate the window */
3332 SetActiveWindow(td->w);
3337 term_window_pos(&data[i], HWND_TOPMOST);
3341 term_window_pos(&data[i], td->w);
3351 td->w = CreateWindowEx(td->dwExStyle, AppName,
3353 td->pos_x, td->pos_y,
3354 td->size_wid, td->size_hgt,
3355 HWND_DESKTOP, NULL, hInstance, NULL);
3358 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3360 if (!td->w) quit("Failed to create Angband window");
3365 angband_term[0] = &td->t;
3366 normsize.x = td->cols;
3367 normsize.y = td->rows;
3369 /* Activate the main window */
3370 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3371 else ShowWindow(td->w, SW_SHOW);
3373 /* Bring main window back to top */
3374 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3377 /* New palette XXX XXX XXX */
3378 (void)new_palette();
3381 /* Create a "brush" for drawing the "cursor" */
3382 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3385 /* Process pending messages */
3386 (void)Term_xtra_win_flush();
3394 static void setup_menus(void)
3398 HMENU hm = GetMenu(data[0].w);
3401 /* Menu "File", Disable all */
3402 EnableMenuItem(hm, IDM_FILE_NEW,
3403 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3404 EnableMenuItem(hm, IDM_FILE_OPEN,
3405 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3406 EnableMenuItem(hm, IDM_FILE_SAVE,
3407 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3408 EnableMenuItem(hm, IDM_FILE_EXIT,
3409 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3410 EnableMenuItem(hm, IDM_FILE_SCORE,
3411 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3414 /* No character available */
3415 if (!character_generated)
3417 /* Menu "File", Item "New" */
3418 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3420 /* Menu "File", Item "Open" */
3421 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3424 /* A character available */
3425 if (character_generated)
3427 /* Menu "File", Item "Save" */
3428 EnableMenuItem(hm, IDM_FILE_SAVE,
3429 MF_BYCOMMAND | MF_ENABLED);
3432 /* Menu "File", Item "Exit" */
3433 EnableMenuItem(hm, IDM_FILE_EXIT,
3434 MF_BYCOMMAND | MF_ENABLED);
3436 EnableMenuItem(hm, IDM_FILE_SCORE,
3437 MF_BYCOMMAND | MF_ENABLED);
3440 /* Menu "Window::Visibility" */
3441 for (i = 0; i < MAX_TERM_DATA; i++)
3443 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3444 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3446 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3447 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3449 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3450 MF_BYCOMMAND | MF_ENABLED);
3453 /* Menu "Window::Font" */
3454 for (i = 0; i < MAX_TERM_DATA; i++)
3456 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3457 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3459 if (data[i].visible)
3461 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3462 MF_BYCOMMAND | MF_ENABLED);
3466 /* Menu "Window::Window Position Fix" */
3467 for (i = 0; i < MAX_TERM_DATA; i++)
3469 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3470 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3472 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3473 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3475 if (data[i].visible)
3477 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3478 MF_BYCOMMAND | MF_ENABLED);
3482 /* Menu "Window::Bizarre Display" */
3483 for (i = 0; i < MAX_TERM_DATA; i++)
3485 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3486 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3488 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3489 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3491 if (data[i].visible)
3493 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3494 MF_BYCOMMAND | MF_ENABLED);
3499 /* Menu "Window::Increase Tile Width" */
3500 for (i = 0; i < MAX_TERM_DATA; i++)
3502 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3503 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3505 if (data[i].visible)
3507 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3508 MF_BYCOMMAND | MF_ENABLED);
3513 /* Menu "Window::Decrease Tile Width" */
3514 for (i = 0; i < MAX_TERM_DATA; i++)
3516 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3517 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3519 if (data[i].visible)
3521 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3522 MF_BYCOMMAND | MF_ENABLED);
3527 /* Menu "Window::Increase Tile Height" */
3528 for (i = 0; i < MAX_TERM_DATA; i++)
3530 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3531 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3533 if (data[i].visible)
3535 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3536 MF_BYCOMMAND | MF_ENABLED);
3541 /* Menu "Window::Decrease Tile Height" */
3542 for (i = 0; i < MAX_TERM_DATA; i++)
3544 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3545 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3547 if (data[i].visible)
3549 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3550 MF_BYCOMMAND | MF_ENABLED);
3555 /* Menu "Options", disable all */
3556 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3557 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3558 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3559 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3560 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3561 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3562 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3563 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3564 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3565 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3567 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3568 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3571 /* Menu "Options", Item "Map" */
3572 if (use_graphics != GRAPHICS_NONE)
3573 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3575 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3576 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3578 /* Menu "Options", update all */
3579 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3580 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3581 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3582 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3583 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3584 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3585 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3586 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3587 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3588 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3589 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3590 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3591 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3592 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3593 CheckMenuItem(hm, IDM_OPTIONS_BG,
3594 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3596 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3597 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3601 /* Menu "Options", Item "Graphics" */
3602 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3603 /* Menu "Options", Item "Graphics" */
3604 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3605 /* Menu "Options", Item "Graphics" */
3606 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3607 /* Menu "Options", Item "Graphics" */
3608 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3609 #endif /* USE_GRAPHICS */
3612 /* Menu "Options", Item "Sound" */
3613 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3614 #endif /* USE_SOUND */
3617 /* Menu "Options", Item "ScreenSaver" */
3618 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3619 MF_BYCOMMAND | MF_ENABLED);
3620 #endif /* USE_SAVER */
3625 * Check for double clicked (or dragged) savefile
3627 * Apparently, Windows copies the entire filename into the first
3628 * piece of the "command line string". Perhaps we should extract
3629 * the "basename" of that filename and append it to the "save" dir.
3631 static void check_for_save_file(LPSTR cmd_line)
3641 /* Extract filename */
3642 strcat(savefile, s);
3644 /* Validate the file */
3645 validate_file(savefile);
3647 /* Game in progress */
3648 game_in_progress = TRUE;
3656 * Process a menu command
3658 static void process_menus(WORD wCmd)
3675 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3677 plog("You cannot do that yet...");
3681 else if (game_in_progress)
3684 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3686 plog("You can't start a new game while you're still playing!");
3692 game_in_progress = TRUE;
3706 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3708 plog("You cannot do that yet...");
3712 else if (game_in_progress)
3715 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3717 plog("You can't open a new game while you're still playing!");
3723 memset(&ofn, 0, sizeof(ofn));
3724 ofn.lStructSize = sizeof(ofn);
3725 ofn.hwndOwner = data[0].w;
3726 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3727 ofn.nFilterIndex = 1;
3728 ofn.lpstrFile = savefile;
3729 ofn.nMaxFile = 1024;
3730 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3731 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3733 if (GetOpenFileName(&ofn))
3735 /* Load 'savefile' */
3736 validate_file(savefile);
3737 game_in_progress = TRUE;
3749 if (game_in_progress && character_generated)
3755 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3757 plog("You may not do that right now.");
3763 /* Hack -- Forget messages */
3768 do_cmd_save_game(FALSE);
3769 #else /* ZANGBAND */
3771 #endif /* ZANGBAND */
3776 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3778 plog("You may not do that right now.");
3788 if (game_in_progress && character_generated)
3794 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3796 plog("You may not do that right now.");
3802 /* Hack -- Forget messages */
3811 /* do_cmd_save_game(FALSE); */
3812 #else /* ZANGBAND */
3813 /* do_cmd_save_game(); */
3814 #endif /* ZANGBAND */
3815 Term_key_push(SPECIAL_KEY_QUIT);
3823 case IDM_FILE_SCORE:
3827 /* Build the filename */
3828 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3830 /* Open the binary high score file, for reading */
3831 highscore_fd = fd_open(buf, O_RDONLY);
3833 /* Paranoia -- No score file */
3834 if (highscore_fd < 0)
3836 msg_print("Score file unavailable.");
3846 /* Display the scores */
3847 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3849 /* Shut the high score file */
3850 (void)fd_close(highscore_fd);
3852 /* Forget the high score fd */
3858 /* Hack - Flush it */
3866 case IDM_FILE_MOVIE:
3871 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3873 plog("You cannot do that yet...");
3876 else if (game_in_progress)
3879 plog("¥×¥ì¥¤Ãæ¤Ï¥à¡¼¥Ó¡¼¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3881 plog("You can't open a movie while you're playing!");
3886 memset(&ofn, 0, sizeof(ofn));
3887 ofn.lStructSize = sizeof(ofn);
3888 ofn.hwndOwner = data[0].w;
3889 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3890 ofn.nFilterIndex = 1;
3891 ofn.lpstrFile = savefile;
3892 ofn.nMaxFile = 1024;
3893 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3894 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3896 if (GetOpenFileName(&ofn))
3898 /* Load 'savefile' */
3899 prepare_browse_movie_aux(savefile);
3909 case IDM_WINDOW_VIS_0:
3912 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3914 plog("You are not allowed to do that!");
3921 /* Window visibility */
3922 case IDM_WINDOW_VIS_1:
3923 case IDM_WINDOW_VIS_2:
3924 case IDM_WINDOW_VIS_3:
3925 case IDM_WINDOW_VIS_4:
3926 case IDM_WINDOW_VIS_5:
3927 case IDM_WINDOW_VIS_6:
3928 case IDM_WINDOW_VIS_7:
3930 i = wCmd - IDM_WINDOW_VIS_0;
3932 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3939 ShowWindow(td->w, SW_SHOW);
3940 term_data_redraw(td);
3944 td->visible = FALSE;
3946 ShowWindow(td->w, SW_HIDE);
3953 case IDM_WINDOW_FONT_0:
3954 case IDM_WINDOW_FONT_1:
3955 case IDM_WINDOW_FONT_2:
3956 case IDM_WINDOW_FONT_3:
3957 case IDM_WINDOW_FONT_4:
3958 case IDM_WINDOW_FONT_5:
3959 case IDM_WINDOW_FONT_6:
3960 case IDM_WINDOW_FONT_7:
3962 i = wCmd - IDM_WINDOW_FONT_0;
3964 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3968 term_change_font(td);
3973 /* Window Z Position */
3974 case IDM_WINDOW_POS_1:
3975 case IDM_WINDOW_POS_2:
3976 case IDM_WINDOW_POS_3:
3977 case IDM_WINDOW_POS_4:
3978 case IDM_WINDOW_POS_5:
3979 case IDM_WINDOW_POS_6:
3980 case IDM_WINDOW_POS_7:
3982 i = wCmd - IDM_WINDOW_POS_0;
3984 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3988 if (!td->posfix && td->visible)
3991 term_window_pos(td, HWND_TOPMOST);
3996 term_window_pos(td, data[0].w);
4002 /* Bizarre Display */
4003 case IDM_WINDOW_BIZ_0:
4004 case IDM_WINDOW_BIZ_1:
4005 case IDM_WINDOW_BIZ_2:
4006 case IDM_WINDOW_BIZ_3:
4007 case IDM_WINDOW_BIZ_4:
4008 case IDM_WINDOW_BIZ_5:
4009 case IDM_WINDOW_BIZ_6:
4010 case IDM_WINDOW_BIZ_7:
4012 i = wCmd - IDM_WINDOW_BIZ_0;
4014 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4018 td->bizarre = !td->bizarre;
4022 term_window_resize(td);
4027 /* Increase Tile Width */
4028 case IDM_WINDOW_I_WID_0:
4029 case IDM_WINDOW_I_WID_1:
4030 case IDM_WINDOW_I_WID_2:
4031 case IDM_WINDOW_I_WID_3:
4032 case IDM_WINDOW_I_WID_4:
4033 case IDM_WINDOW_I_WID_5:
4034 case IDM_WINDOW_I_WID_6:
4035 case IDM_WINDOW_I_WID_7:
4037 i = wCmd - IDM_WINDOW_I_WID_0;
4039 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4047 term_window_resize(td);
4052 /* Decrease Tile Height */
4053 case IDM_WINDOW_D_WID_0:
4054 case IDM_WINDOW_D_WID_1:
4055 case IDM_WINDOW_D_WID_2:
4056 case IDM_WINDOW_D_WID_3:
4057 case IDM_WINDOW_D_WID_4:
4058 case IDM_WINDOW_D_WID_5:
4059 case IDM_WINDOW_D_WID_6:
4060 case IDM_WINDOW_D_WID_7:
4062 i = wCmd - IDM_WINDOW_D_WID_0;
4064 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4072 term_window_resize(td);
4077 /* Increase Tile Height */
4078 case IDM_WINDOW_I_HGT_0:
4079 case IDM_WINDOW_I_HGT_1:
4080 case IDM_WINDOW_I_HGT_2:
4081 case IDM_WINDOW_I_HGT_3:
4082 case IDM_WINDOW_I_HGT_4:
4083 case IDM_WINDOW_I_HGT_5:
4084 case IDM_WINDOW_I_HGT_6:
4085 case IDM_WINDOW_I_HGT_7:
4087 i = wCmd - IDM_WINDOW_I_HGT_0;
4089 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4097 term_window_resize(td);
4102 /* Decrease Tile Height */
4103 case IDM_WINDOW_D_HGT_0:
4104 case IDM_WINDOW_D_HGT_1:
4105 case IDM_WINDOW_D_HGT_2:
4106 case IDM_WINDOW_D_HGT_3:
4107 case IDM_WINDOW_D_HGT_4:
4108 case IDM_WINDOW_D_HGT_5:
4109 case IDM_WINDOW_D_HGT_6:
4110 case IDM_WINDOW_D_HGT_7:
4112 i = wCmd - IDM_WINDOW_D_HGT_0;
4114 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4122 term_window_resize(td);
4127 case IDM_OPTIONS_NO_GRAPHICS:
4132 plog("You may not do that right now.");
4136 /* Toggle "arg_graphics" */
4137 if (arg_graphics != GRAPHICS_NONE)
4139 arg_graphics = GRAPHICS_NONE;
4141 /* React to changes */
4142 Term_xtra_win_react();
4144 /* Hack -- Force redraw */
4145 Term_key_push(KTRL('R'));
4151 case IDM_OPTIONS_OLD_GRAPHICS:
4156 plog("You may not do that right now.");
4160 /* Toggle "arg_graphics" */
4161 if (arg_graphics != GRAPHICS_ORIGINAL)
4163 arg_graphics = GRAPHICS_ORIGINAL;
4165 /* React to changes */
4166 Term_xtra_win_react();
4168 /* Hack -- Force redraw */
4169 Term_key_push(KTRL('R'));
4175 case IDM_OPTIONS_NEW_GRAPHICS:
4180 plog("You may not do that right now.");
4184 /* Toggle "arg_graphics" */
4185 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4187 arg_graphics = GRAPHICS_ADAM_BOLT;
4189 /* React to changes */
4190 Term_xtra_win_react();
4192 /* Hack -- Force redraw */
4193 Term_key_push(KTRL('R'));
4199 case IDM_OPTIONS_NEW2_GRAPHICS:
4204 plog("You may not do that right now.");
4208 /* Toggle "arg_graphics" */
4209 if (arg_graphics != GRAPHICS_HENGBAND)
4211 arg_graphics = GRAPHICS_HENGBAND;
4213 /* React to changes */
4214 Term_xtra_win_react();
4216 /* Hack -- Force redraw */
4217 Term_key_push(KTRL('R'));
4223 case IDM_OPTIONS_BIGTILE:
4225 term_data *td = &data[0];
4230 plog("You may not do that right now.");
4234 /* Toggle "arg_sound" */
4235 arg_bigtile = !arg_bigtile;
4238 Term_activate(&td->t);
4240 /* Resize the term */
4241 Term_resize(td->cols, td->rows);
4244 InvalidateRect(td->w, NULL, TRUE);
4249 case IDM_OPTIONS_MUSIC:
4254 plog("You may not do that right now.");
4258 /* Toggle "arg_sound" */
4259 arg_music = !arg_music;
4261 /* React to changes */
4262 Term_xtra_win_react();
4264 /* Hack -- Force redraw */
4265 Term_key_push(KTRL('R'));
4270 case IDM_OPTIONS_SOUND:
4275 plog("You may not do that right now.");
4279 /* Toggle "arg_sound" */
4280 arg_sound = !arg_sound;
4282 /* React to changes */
4283 Term_xtra_win_react();
4285 /* Hack -- Force redraw */
4286 Term_key_push(KTRL('R'));
4292 case IDM_OPTIONS_BG:
4297 plog("You may not do that right now.");
4301 /* Toggle "use_bg" */
4306 /* React to changes */
4307 Term_xtra_win_react();
4309 /* Hack -- Force redraw */
4310 Term_key_push(KTRL('R'));
4316 case IDM_OPTIONS_OPEN_BG:
4321 plog("You may not do that right now.");
4326 memset(&ofn, 0, sizeof(ofn));
4327 ofn.lStructSize = sizeof(ofn);
4328 ofn.hwndOwner = data[0].w;
4329 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4330 ofn.nFilterIndex = 1;
4331 ofn.lpstrFile = bg_bitmap_file;
4332 ofn.nMaxFile = 1023;
4333 ofn.lpstrInitialDir = NULL;
4335 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
4337 ofn.lpstrTitle = "Choose wall paper.";
4339 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4341 if (GetOpenFileName(&ofn))
4343 /* Load 'savefile' */
4348 /* React to changes */
4349 Term_xtra_win_react();
4351 /* Hack -- Force redraw */
4352 Term_key_push(KTRL('R'));
4357 case IDM_DUMP_SCREEN_HTML:
4359 static char buf[1024] = "";
4360 memset(&ofn, 0, sizeof(ofn));
4361 ofn.lStructSize = sizeof(ofn);
4362 ofn.hwndOwner = data[0].w;
4363 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4364 ofn.nFilterIndex = 1;
4365 ofn.lpstrFile = buf;
4366 ofn.nMaxFile = 1023;
4367 ofn.lpstrDefExt = "html";
4368 ofn.lpstrInitialDir = NULL;
4370 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
4372 ofn.lpstrTitle = "Save screen dump as HTML.";
4374 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4376 if (GetSaveFileName(&ofn))
4378 do_cmd_save_screen_html_aux(buf, 0);
4385 case IDM_OPTIONS_SAVER:
4389 DestroyWindow(hwndSaver);
4394 /* Create a screen scaver window */
4395 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4396 "Angband Screensaver",
4397 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4398 0, 0, GetSystemMetrics(SM_CXSCREEN),
4399 GetSystemMetrics(SM_CYSCREEN),
4400 NULL, NULL, hInstance, NULL);
4404 /* Push the window to the bottom XXX XXX XXX */
4405 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4410 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
4412 plog("Failed to create saver window");
4422 case IDM_OPTIONS_MAP:
4428 case IDM_HELP_CONTENTS:
4432 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4433 if (check_file(tmp))
4435 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4440 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4441 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4443 plog_fmt("Cannot find help file: %s", tmp);
4444 plog("Use the online help files instead.");
4449 #else /* HTML_HELP */
4452 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4453 if (check_file(tmp))
4455 sprintf(buf, "winhelp.exe %s", tmp);
4456 WinExec(buf, SW_NORMAL);
4461 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4462 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4464 plog_fmt("Cannot find help file: %s", tmp);
4465 plog("Use the online help files instead.");
4470 #endif /* HTML_HELP */
4476 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4483 /* Extract the modifiers */
4484 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4485 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4486 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4488 Term_no_press = (ma) ? TRUE : FALSE;
4490 /* Handle "special" keys */
4491 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4493 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4494 bool numpad = FALSE;
4496 /* Begin the macro trigger */
4499 /* Send the modifiers */
4500 if (mc) Term_keypress('C');
4501 if (ms) Term_keypress('S');
4502 if (ma) Term_keypress('A');
4504 /* Extract "scan code" */
4505 i = LOBYTE(HIWORD(lParam));
4507 /* Introduce the scan code */
4510 /* Extended key bit */
4513 /* Numpad Enter and '/' are extended key */
4515 Term_no_press = TRUE;
4516 case VK_RETURN: /* Enter */
4519 /* Other extended keys are on full keyboard */
4535 Term_no_press = TRUE;
4539 case VK_PRIOR: /* Page Up */
4540 case VK_NEXT: /* Page Down */
4550 /* Special modifiers for keypad keys */
4551 if (numpad) Term_keypress('K');
4553 /* Encode the hexidecimal scan code */
4554 Term_keypress(hexsym[i/16]);
4555 Term_keypress(hexsym[i%16]);
4557 /* End the macro trigger */
4568 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4569 WPARAM wParam, LPARAM lParam);
4570 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4571 WPARAM wParam, LPARAM lParam)
4572 #else /* __MWERKS__ */
4573 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4574 WPARAM wParam, LPARAM lParam)
4575 #endif /* __MWERKS__ */
4581 MINMAXINFO FAR *lpmmi;
4587 /* Acquire proper "term_data" info */
4588 td = (term_data *)GetWindowLong(hWnd, 0);
4590 /* Handle message */
4596 SetWindowLong(hWnd, 0, (LONG)(my_td));
4603 mop.dwCallback=(DWORD)hWnd;
4607 case WM_GETMINMAXINFO:
4609 MINMAXINFO FAR *lpmmi;
4612 lpmmi = (MINMAXINFO FAR *)lParam;
4614 /* this message was sent before WM_NCCREATE */
4617 /* Minimum window size is 80x24 */
4618 rc.left = rc.top = 0;
4619 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4620 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4623 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4625 /* Save minimum size */
4626 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4627 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4634 BeginPaint(hWnd, &ps);
4635 if (td) term_data_redraw(td);
4636 EndPaint(hWnd, &ps);
4637 ValidateRect(hWnd, NULL);
4644 if(wParam == MCI_NOTIFY_SUCCESSFUL)
4646 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
4647 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
4656 if (process_keydown(wParam, lParam))
4663 if (Term_no_press) Term_no_press = FALSE;
4664 else Term_keypress(wParam);
4668 case WM_LBUTTONDOWN:
4670 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4671 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4683 int dx = abs(oldx - mousex) + 1;
4684 int dy = abs(oldy - mousey) + 1;
4685 int ox = (oldx > mousex) ? mousex : oldx;
4686 int oy = (oldy > mousey) ? mousey : oldy;
4696 hGlobal = GlobalAlloc(GHND, sz + 1);
4697 if (hGlobal == NULL) return 0;
4698 lpStr = (LPSTR)GlobalLock(hGlobal);
4700 for (i = 0; i < dy; i++)
4704 char **scr = data[0].t.scr->c;
4706 C_MAKE(s, (dx + 1), char);
4707 strncpy(s, &scr[oy + i][ox], dx);
4711 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4714 if (ox + dx < data[0].cols)
4716 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4719 for (j = 0; j < dx; j++)
4721 if (s[j] == 127) s[j] = '#';
4725 for (j = 0; j < dx; j++)
4727 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4737 GlobalUnlock(hGlobal);
4738 if (OpenClipboard(hWnd) == 0)
4740 GlobalFree(hGlobal);
4744 SetClipboardData(CF_TEXT, hGlobal);
4757 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4758 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4763 dx = abs(oldx - mousex) + 1;
4764 dy = abs(oldy - mousey) + 1;
4765 ox = (oldx > mousex) ? mousex : oldx;
4766 oy = (oldy > mousey) ? mousey : oldy;
4767 Term_inversed_area(hWnd, ox, oy, dx, dy);
4774 dx = abs(cx - mousex) + 1;
4775 dy = abs(cy - mousey) + 1;
4776 ox = (cx > mousex) ? mousex : cx;
4777 oy = (cy > mousey) ? mousey : cy;
4778 Term_inversed_area(hWnd, ox, oy, dx, dy);
4794 if (game_in_progress && character_generated)
4799 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4801 plog("You may not do that right now.");
4806 /* Hack -- Forget messages */
4815 /* do_cmd_save_game(FALSE); */
4816 #else /* ZANGBAND */
4817 /* do_cmd_save_game(); */
4818 #endif /* ZANGBAND */
4819 Term_key_push(SPECIAL_KEY_QUIT);
4826 case WM_QUERYENDSESSION:
4828 if (game_in_progress && character_generated)
4830 /* Hack -- Forget messages */
4833 /* Mega-Hack -- Delay death */
4834 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4837 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "----¥²¡¼¥àÃæÃÇ----");
4839 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "---- Save and Exit Game ----");
4842 /* Hardcode panic save */
4843 p_ptr->panic_save = 1;
4845 /* Forbid suspend */
4846 signals_ignore_tstp();
4848 /* Indicate panic save */
4850 (void)strcpy(p_ptr->died_from, "(¶ÛµÞ¥»¡¼¥Ö)");
4852 (void)strcpy(p_ptr->died_from, "(panic save)");
4856 (void)save_player();
4870 process_menus(LOWORD(wParam));
4876 /* this message was sent before WM_NCCREATE */
4879 /* it was sent from inside CreateWindowEx */
4880 if (!td->w) return 1;
4882 /* was sent from WM_SIZE */
4883 if (td->size_hack) return 1;
4887 case SIZE_MINIMIZED:
4889 /* Hide sub-windows */
4890 for (i = 1; i < MAX_TERM_DATA; i++)
4892 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4897 case SIZE_MAXIMIZED:
4899 /* fall through XXX XXX XXX */
4904 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4905 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4908 if ((td->cols != cols) || (td->rows != rows))
4910 /* Save the new size */
4914 if (!IsZoomed(td->w) && !IsIconic(td->w))
4916 normsize.x = td->cols;
4917 normsize.y = td->rows;
4921 Term_activate(&td->t);
4923 /* Resize the term */
4924 Term_resize(td->cols, td->rows);
4927 InvalidateRect(td->w, NULL, TRUE);
4930 td->size_hack = TRUE;
4932 /* Show sub-windows */
4933 for (i = 1; i < MAX_TERM_DATA; i++)
4935 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4938 td->size_hack = FALSE;
4946 case WM_PALETTECHANGED:
4948 /* Ignore if palette change caused by itself */
4949 if ((HWND)wParam == hWnd) return 0;
4951 /* Fall through... */
4954 case WM_QUERYNEWPALETTE:
4956 if (!paletted) return 0;
4960 SelectPalette(hdc, hPal, FALSE);
4962 i = RealizePalette(hdc);
4964 /* if any palette entries changed, repaint the window. */
4965 if (i) InvalidateRect(hWnd, NULL, TRUE);
4967 ReleaseDC(hWnd, hdc);
4974 if (wParam && !HIWORD(lParam))
4976 /* Do something to sub-windows */
4977 for (i = 1; i < MAX_TERM_DATA; i++)
4979 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4982 /* Focus on main window */
4991 case WM_ACTIVATEAPP:
4993 if (IsIconic(td->w)) break;
4995 for (i = 1; i < MAX_TERM_DATA; i++)
5001 ShowWindow(data[i].w, SW_SHOW);
5005 ShowWindow(data[i].w, SW_HIDE);
5012 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5017 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5018 WPARAM wParam, LPARAM lParam);
5019 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5020 WPARAM wParam, LPARAM lParam)
5021 #else /* __MWERKS__ */
5022 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5023 WPARAM wParam, LPARAM lParam)
5024 #endif /* __MWERKS__ */
5028 MINMAXINFO FAR *lpmmi;
5036 /* Acquire proper "term_data" info */
5037 td = (term_data *)GetWindowLong(hWnd, 0);
5039 /* Process message */
5045 SetWindowLong(hWnd, 0, (LONG)(my_td));
5055 case WM_GETMINMAXINFO:
5057 MINMAXINFO FAR *lpmmi;
5060 lpmmi = (MINMAXINFO FAR *)lParam;
5062 /* this message was sent before WM_NCCREATE */
5065 /* Minimum window size is 80x24 */
5066 rc.left = rc.top = 0;
5067 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5068 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5071 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5073 /* Save minimum size */
5074 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5075 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5085 /* this message was sent before WM_NCCREATE */
5088 /* it was sent from inside CreateWindowEx */
5089 if (!td->w) return 1;
5091 /* was sent from inside WM_SIZE */
5092 if (td->size_hack) return 1;
5094 td->size_hack = TRUE;
5096 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5097 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5100 if ((td->cols != cols) || (td->rows != rows))
5103 term *old_term = Term;
5105 /* Save the new size */
5110 Term_activate(&td->t);
5112 /* Resize the term */
5113 Term_resize(td->cols, td->rows);
5116 Term_activate(old_term);
5119 InvalidateRect(td->w, NULL, TRUE);
5121 /* HACK - Redraw all windows */
5122 p_ptr->window = 0xFFFFFFFF;
5126 td->size_hack = FALSE;
5133 BeginPaint(hWnd, &ps);
5134 if (td) term_data_redraw(td);
5135 EndPaint(hWnd, &ps);
5142 if (process_keydown(wParam, lParam))
5149 if (Term_no_press) Term_no_press = FALSE;
5150 else Term_keypress(wParam);
5154 case WM_PALETTECHANGED:
5156 /* ignore if palette change caused by itself */
5157 if ((HWND)wParam == hWnd) return FALSE;
5158 /* otherwise, fall through!!! */
5161 case WM_QUERYNEWPALETTE:
5163 if (!paletted) return 0;
5165 SelectPalette(hdc, hPal, FALSE);
5166 i = RealizePalette(hdc);
5167 /* if any palette entries changed, repaint the window. */
5168 if (i) InvalidateRect(hWnd, NULL, TRUE);
5169 ReleaseDC(hWnd, hdc);
5173 case WM_NCLBUTTONDOWN:
5177 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5178 #endif /* HTCLOSE */
5180 if (wParam == HTSYSMENU)
5184 td->visible = FALSE;
5185 ShowWindow(td->w, SW_HIDE);
5195 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5201 #define MOUSE_SENS 40
5204 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5205 WPARAM wParam, LPARAM lParam);
5206 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5207 WPARAM wParam, LPARAM lParam)
5208 #else /* __MWERKS__ */
5209 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5210 WPARAM wParam, LPARAM lParam)
5211 #endif /* __MWERKS__ */
5213 static int iMouse = 0;
5214 static WORD xMouse = 0;
5215 static WORD yMouse = 0;
5238 if (LOWORD(wParam) == WA_INACTIVE) break;
5240 /* else fall through */
5244 case WM_LBUTTONDOWN:
5245 case WM_MBUTTONDOWN:
5246 case WM_RBUTTONDOWN:
5249 SendMessage(hWnd, WM_CLOSE, 0, 0);
5257 dx = LOWORD(lParam) - xMouse;
5258 dy = HIWORD(lParam) - yMouse;
5260 if (dx < 0) dx = -dx;
5261 if (dy < 0) dy = -dy;
5263 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5265 SendMessage(hWnd, WM_CLOSE, 0, 0);
5269 /* Save last location */
5271 xMouse = LOWORD(lParam);
5272 yMouse = HIWORD(lParam);
5279 DestroyWindow(hwndSaver);
5286 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5289 #endif /* USE_SAVER */
5295 /*** Temporary Hooks ***/
5299 * Display warning message (see "z-util.c")
5301 static void hack_plog(cptr str)
5303 /* Give a warning */
5307 MessageBox(NULL, str, "·Ù¹ð¡ª",
5308 MB_ICONEXCLAMATION | MB_OK);
5310 MessageBox(NULL, str, "Warning",
5311 MB_ICONEXCLAMATION | MB_OK);
5319 * Display error message and quit (see "z-util.c")
5321 static void hack_quit(cptr str)
5323 /* Give a warning */
5327 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
5328 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5330 MessageBox(NULL, str, "Error",
5331 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5336 /* Unregister the classes */
5337 UnregisterClass(AppName, hInstance);
5339 /* Destroy the icon */
5340 if (hIcon) DestroyIcon(hIcon);
5348 /*** Various hooks ***/
5352 * Display warning message (see "z-util.c")
5354 static void hook_plog(cptr str)
5360 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
5361 MB_ICONEXCLAMATION | MB_OK);
5363 MessageBox(data[0].w, str, "Warning",
5364 MB_ICONEXCLAMATION | MB_OK);
5372 * Display error message and quit (see "z-util.c")
5374 static void hook_quit(cptr str)
5379 /* Give a warning */
5383 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
5384 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5386 MessageBox(data[0].w, str, "Error",
5387 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5393 /* Save the preferences */
5397 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
5399 /* Destroy all windows */
5400 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5402 term_force_font(&data[i], NULL);
5403 if (data[i].font_want) string_free(data[i].font_want);
5404 if (data[i].w) DestroyWindow(data[i].w);
5408 /* Free the bitmap stuff */
5410 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5411 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5413 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5414 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5416 #endif /* USE_GRAPHICS */
5418 /*** Free some other stuff ***/
5420 DeleteObject(hbrYellow);
5425 if (hPal) DeleteObject(hPal);
5427 UnregisterClass(AppName, hInstance);
5429 if (hIcon) DestroyIcon(hIcon);
5436 /*** Initialize ***/
5442 static void init_stuff(void)
5449 /* Get program name with full path */
5450 GetModuleFileName(hInstance, path, 512);
5452 /* Save the "program name" XXX XXX XXX */
5455 /* Get the name of the "*.ini" file */
5456 strcpy(path + strlen(path) - 4, ".INI");
5458 /* Save the the name of the ini-file */
5459 ini_file = string_make(path);
5461 /* Analyze the path */
5467 if (path[i] == '\\')
5474 /* Add "lib" to the path */
5475 strcpy(path + i + 1, "lib\\");
5477 /* Validate the path */
5478 validate_dir(path, TRUE);
5480 /* Init the file paths */
5481 init_file_paths(path);
5483 /* Hack -- Validate the paths */
5484 validate_dir(ANGBAND_DIR_APEX, FALSE);
5485 validate_dir(ANGBAND_DIR_BONE, FALSE);
5487 /* Allow missing 'edit' directory */
5488 if (!check_dir(ANGBAND_DIR_EDIT))
5490 /* Must have 'data'! */
5491 validate_dir(ANGBAND_DIR_DATA, TRUE);
5495 /* Don't need 'data' */
5496 validate_dir(ANGBAND_DIR_DATA, FALSE);
5499 validate_dir(ANGBAND_DIR_FILE, TRUE);
5500 validate_dir(ANGBAND_DIR_HELP, FALSE);
5501 validate_dir(ANGBAND_DIR_INFO, FALSE);
5502 validate_dir(ANGBAND_DIR_PREF, TRUE);
5503 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5504 validate_dir(ANGBAND_DIR_USER, TRUE);
5505 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5507 /* Build the filename */
5509 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
5511 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
5515 /* Hack -- Validate the "news.txt" file */
5516 validate_file(path);
5519 #if 0 /* #ifndef JP */
5520 /* Build the "font" path */
5521 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5523 /* Allocate the path */
5524 ANGBAND_DIR_XTRA_FONT = string_make(path);
5526 /* Validate the "font" directory */
5527 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5529 /* Build the filename */
5530 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5532 /* Hack -- Validate the basic font */
5533 validate_file(path);
5539 /* Build the "graf" path */
5540 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5542 /* Allocate the path */
5543 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5545 /* Validate the "graf" directory */
5546 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5548 #endif /* USE_GRAPHICS */
5553 /* Build the "sound" path */
5554 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5556 /* Allocate the path */
5557 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5559 /* Validate the "sound" directory */
5560 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5562 #endif /* USE_SOUND */
5566 /* Build the "music" path */
5567 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5569 /* Allocate the path */
5570 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5572 /* Validate the "music" directory */
5573 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5575 #endif /* USE_MUSIC */
5577 /* Build the "help" path */
5578 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5580 /* Allocate the path */
5581 ANGBAND_DIR_XTRA_HELP = string_make(path);
5583 /* Validate the "help" directory */
5584 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5587 bool is_already_running()
5589 bool result = FALSE;
5592 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5593 if (GetLastError() == ERROR_ALREADY_EXISTS)
5601 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5602 LPSTR lpCmdLine, int nCmdShow)
5610 setlocale( LC_ALL, "ja_JP" );
5619 /* Prevent multiple run */
5620 if (is_already_running())
5623 _("ÊѶòÈÚÅܤϤ¹¤Ç¤Ëµ¯Æ°¤·¤Æ¤¤¤Þ¤¹¡£", "Hengband is already running."),
5624 _("¥¨¥é¡¼¡ª", "Error") ,
5625 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5630 if (hPrevInst == NULL)
5632 wc.style = CS_CLASSDC;
5633 wc.lpfnWndProc = AngbandWndProc;
5635 wc.cbWndExtra = 4; /* one long pointer to term_data */
5636 wc.hInstance = hInst;
5637 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5638 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5639 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5640 wc.lpszMenuName = AppName;
5641 wc.lpszClassName = AppName;
5643 if (!RegisterClass(&wc)) exit(1);
5645 wc.lpfnWndProc = AngbandListProc;
5646 wc.lpszMenuName = NULL;
5647 wc.lpszClassName = AngList;
5649 if (!RegisterClass(&wc)) exit(2);
5653 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5654 wc.lpfnWndProc = AngbandSaverProc;
5656 wc.lpszMenuName = NULL;
5657 wc.lpszClassName = "WindowsScreenSaverClass";
5659 if (!RegisterClass(&wc)) exit(3);
5665 /* Temporary hooks */
5666 plog_aux = hack_plog;
5667 quit_aux = hack_quit;
5668 core_aux = hack_quit;
5670 /* Prepare the filepaths */
5673 /* Initialize the keypress analyzer */
5674 for (i = 0; special_key_list[i]; ++i)
5676 special_key[special_key_list[i]] = TRUE;
5678 /* Initialize the keypress analyzer */
5679 for (i = 0; ignore_key_list[i]; ++i)
5681 ignore_key[ignore_key_list[i]] = TRUE;
5684 /* Determine if display is 16/256/true color */
5686 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5687 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5688 ReleaseDC(NULL, hdc);
5690 /* Initialize the colors */
5691 for (i = 0; i < 256; i++)
5695 /* Extract desired values */
5696 rv = angband_color_table[i][1];
5697 gv = angband_color_table[i][2];
5698 bv = angband_color_table[i][3];
5700 /* Extract the "complex" code */
5701 win_clr[i] = PALETTERGB(rv, gv, bv);
5703 /* Save the "simple" code */
5704 angband_color_table[i][0] = win_pal[i];
5707 /* Prepare the windows */
5713 /* Activate hooks */
5714 plog_aux = hook_plog;
5715 quit_aux = hook_quit;
5716 core_aux = hook_quit;
5718 /* Set the system suffix */
5719 ANGBAND_SYS = "win";
5721 /* Set the keyboard suffix */
5722 if (7 != GetKeyboardType(0))
5723 ANGBAND_KEYBOARD = "0";
5726 /* Japanese keyboard */
5727 switch (GetKeyboardType(1))
5729 case 0x0D01: case 0x0D02:
5730 case 0x0D03: case 0x0D04:
5731 case 0x0D05: case 0x0D06:
5733 ANGBAND_KEYBOARD = "NEC98";
5737 ANGBAND_KEYBOARD = "JAPAN";
5741 /* Catch nasty signals */
5747 /* We are now initialized */
5750 if(lpCmdLine[0] == '-'){
5751 switch(lpCmdLine[1])
5756 if (!lpCmdLine[2]) break;
5757 chuukei_server = TRUE;
5758 if(connect_chuukei_server(&lpCmdLine[2])<0){
5759 msg_print("connect fail");
5762 msg_print("connect");
5770 if (!lpCmdLine[2]) break;
5771 chuukei_client = TRUE;
5772 connect_chuukei_server(&lpCmdLine[2]);
5780 if (!lpCmdLine[2]) break;
5781 prepare_browse_movie(&lpCmdLine[2]);
5791 /* Did the user double click on a save file? */
5792 if(!chuukei_server) check_for_save_file(lpCmdLine);
5794 /* Did the user double click on a save file? */
5795 check_for_save_file(lpCmdLine);
5798 /* Prompt the user */
5800 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5802 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5807 /* Process messages forever */
5808 while (GetMessage(&msg, NULL, 0, 0))
5810 TranslateMessage(&msg);
5811 DispatchMessage(&msg);
5822 #endif /* WINDOWS */