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_BIGTILE 409
186 #define IDM_OPTIONS_SOUND 410
187 #define IDM_OPTIONS_SAVER 420
188 #define IDM_OPTIONS_MAP 430
189 #define IDM_OPTIONS_BG 440
190 #define IDM_OPTIONS_OPEN_BG 441
192 #define IDM_DUMP_SCREEN_HTML 450
194 #define IDM_HELP_CONTENTS 901
199 * This may need to be removed for some compilers XXX XXX XXX
206 * Exclude parts of WINDOWS.H that are not needed
208 #define NOCOMM /* Comm driver APIs and definitions */
209 #define NOLOGERROR /* LogError() and related definitions */
210 #define NOPROFILER /* Profiler APIs */
211 #define NOLFILEIO /* _l* file I/O routines */
212 #define NOOPENFILE /* OpenFile and related definitions */
213 #define NORESOURCE /* Resource management */
214 #define NOATOM /* Atom management */
215 #define NOLANGUAGE /* Character test routines */
216 #define NOLSTRING /* lstr* string management routines */
217 #define NODBCS /* Double-byte character set routines */
218 #define NOKEYBOARDINFO /* Keyboard driver routines */
219 #define NOCOLOR /* COLOR_* color values */
220 #define NODRAWTEXT /* DrawText() and related definitions */
221 #define NOSCALABLEFONT /* Truetype scalable font support */
222 #define NOMETAFILE /* Metafile support */
223 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
224 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
225 #define NOKEYSTATES /* MK_* message key state flags */
226 #define NOWH /* SetWindowsHook and related WH_* definitions */
227 #define NOCLIPBOARD /* Clipboard APIs and definitions */
228 #define NOICONS /* IDI_* icon IDs */
229 #define NOMDI /* MDI support */
230 #define NOHELP /* Help support */
232 /* Not defined since it breaks Borland C++ 5.5 */
233 /* #define NOCTLMGR */ /* Control management and controls */
236 * Exclude parts of WINDOWS.H that are not needed (Win32)
238 #define WIN32_LEAN_AND_MEAN
239 #define NONLS /* All NLS defines and routines */
240 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
241 #define NOKANJI /* Kanji support stuff. */
242 #define NOMCX /* Modem Configuration Extensions */
245 * Include the "windows" support file
250 * Exclude parts of MMSYSTEM.H that are not needed
252 #define MMNODRV /* Installable driver support */
253 #define MMNOWAVE /* Waveform support */
254 #define MMNOMIDI /* MIDI support */
255 #define MMNOAUX /* Auxiliary audio support */
256 #define MMNOTIMER /* Timer support */
257 #define MMNOJOY /* Joystick support */
258 #define MMNOMCI /* MCI support */
259 #define MMNOMMIO /* Multimedia file I/O support */
260 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
263 * Include some more files. Note: the Cygnus Cygwin compiler
264 * doesn't use mmsystem.h instead it includes the winmm library
265 * which performs a similar function.
267 #include <mmsystem.h>
271 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
272 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
274 /* #define HTML_HELP */
277 #include <htmlhelp.h>
278 #endif /* HTML_HELP */
281 * Include the support for loading bitmaps
284 # include "readdib.h"
288 * Hack -- Fake declarations from "dos.h" XXX XXX XXX
291 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
293 #define FA_LABEL 0x08 /* Volume label */
294 #define FA_DIREC 0x10 /* Directory */
295 unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
299 * Silliness in WIN32 drawing routine
302 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
306 * Silliness for Windows 95
308 #ifndef WS_EX_TOOLWINDOW
309 # define WS_EX_TOOLWINDOW 0
313 * Foreground color bits (hard-coded by DOS)
315 #define VID_BLACK 0x00
316 #define VID_BLUE 0x01
317 #define VID_GREEN 0x02
318 #define VID_CYAN 0x03
320 #define VID_MAGENTA 0x05
321 #define VID_YELLOW 0x06
322 #define VID_WHITE 0x07
325 * Bright text (hard-coded by DOS)
327 #define VID_BRIGHT 0x08
330 * Background color bits (hard-coded by DOS)
332 #define VUD_BLACK 0x00
333 #define VUD_BLUE 0x10
334 #define VUD_GREEN 0x20
335 #define VUD_CYAN 0x30
337 #define VUD_MAGENTA 0x50
338 #define VUD_YELLOW 0x60
339 #define VUD_WHITE 0x70
342 * Blinking text (hard-coded by DOS)
344 #define VUD_BRIGHT 0x80
350 typedef struct _term_data term_data;
355 * Note the use of "font_want" for the names of the font file requested by
356 * the user, and the use of "font_file" for the currently active font file.
358 * The "font_file" is uppercased, and takes the form "8X13.FON", while
359 * "font_want" can be in almost any form as long as it could be construed
360 * as attempting to represent the name of a font.
375 uint rows; /* int -> uint */
411 #if 1 /* #ifdef JP */
426 * Maximum number of windows XXX XXX XXX
428 #define MAX_TERM_DATA 8
431 * An array of term_data's
433 static term_data data[MAX_TERM_DATA];
436 * Hack -- global "window creation" pointer
438 static term_data *my_td;
441 * Remember normal size of main window when maxmized
446 * was main window maximized on previous playing
448 bool win_maximized = FALSE;
453 bool game_in_progress = FALSE;
456 * note when "open"/"new" become valid
458 bool initialized = FALSE;
461 * screen paletted, i.e. 256 colors
463 bool paletted = FALSE;
466 * 16 colors screen, don't use RGB()
468 bool colors16 = FALSE;
471 * Saved instance handle
473 static HINSTANCE hInstance;
476 * Yellow brush for the cursor
478 static HBRUSH hbrYellow;
488 static HPALETTE hPal;
491 static HBITMAP hBG = NULL;
492 static int use_bg = 0;
493 static char bg_bitmap_file[1024] = "bg.bmp";
498 * The screen saver window
500 static HWND hwndSaver;
502 #endif /* USE_SAVER */
508 * Flag set once "graphics" has been initialized
510 static bool can_use_graphics = FALSE;
515 static DIBINIT infGraph;
518 * The global bitmap mask
520 static DIBINIT infMask;
522 #endif /* USE_GRAPHICS */
528 * Flag set once "sound" has been initialized
530 static bool can_use_sound = FALSE;
535 * An array of sound file names
537 static cptr sound_file[SOUND_MAX][SAMPLE_MAX];
539 #endif /* USE_SOUND */
543 * Full path to ANGBAND.INI
545 static cptr ini_file = NULL;
548 * Name of application
550 static cptr AppName = "ANGBAND";
553 * Name of sub-window type
555 static cptr AngList = "AngList";
560 static cptr ANGBAND_DIR_XTRA_GRAF;
561 static cptr ANGBAND_DIR_XTRA_SOUND;
562 static cptr ANGBAND_DIR_XTRA_HELP;
563 #if 0 /* #ifndef JP */
564 static cptr ANGBAND_DIR_XTRA_FONT;
567 static cptr ANGBAND_DIR_XTRA_MUSIC;
572 * The "complex" color values
574 static COLORREF win_clr[256];
578 * Flag for macro trigger with dump ASCII
580 static bool Term_no_press = FALSE;
585 static bool mouse_down = FALSE;
586 static bool paint_rect = FALSE;
587 static int mousex = 0, mousey = 0;
588 static int oldx, oldy;
592 * The "simple" color values
594 * See "main-ibm.c" for original table information
596 * The entries below are taken from the "color bits" defined above.
598 * Note that many of the choices below suck, but so do crappy monitors.
600 static BYTE win_pal[256] =
602 VID_BLACK, /* Dark */
603 VID_WHITE, /* White */
604 VID_CYAN, /* Slate XXX */
605 VID_RED | VID_BRIGHT, /* Orange XXX */
607 VID_GREEN, /* Green */
609 VID_YELLOW, /* Umber XXX */
610 VID_BLACK | VID_BRIGHT, /* Light Dark */
611 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
612 VID_MAGENTA, /* Violet XXX */
613 VID_YELLOW | VID_BRIGHT, /* Yellow */
614 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
615 VID_GREEN | VID_BRIGHT, /* Light Green */
616 VID_BLUE | VID_BRIGHT, /* Light Blue */
617 VID_YELLOW /* Light Umber XXX */
622 * Hack -- define which keys are "special"
624 static bool special_key[256];
625 static bool ignore_key[256];
629 * Hack -- initialization list for "special_key"
631 static byte special_key_list[] = {
632 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
633 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
634 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
635 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
636 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
637 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
638 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
639 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
640 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
641 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
642 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
643 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
644 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
645 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
646 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
647 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
648 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
653 static byte ignore_key_list[] = {
654 VK_ESCAPE, VK_TAB, VK_SPACE,
655 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
656 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
657 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
663 * Hack -- initialization list for "special_key"
665 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
666 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
667 * catch the keypad keys (with and without numlock set, including keypad 5),
668 * the function keys (including the "menu" key which maps to F10), and the
669 * "pause" key (between scroll lock and numlock). We also catch a few odd
670 * keys which I do not recognize, but which are listed among keys which we
671 * do catch, so they should be harmless to catch.
673 static byte special_key_list[] =
675 VK_CLEAR, /* 0x0C (KP<5>) */
677 VK_PAUSE, /* 0x13 (pause) */
679 VK_PRIOR, /* 0x21 (KP<9>) */
680 VK_NEXT, /* 0x22 (KP<3>) */
681 VK_END, /* 0x23 (KP<1>) */
682 VK_HOME, /* 0x24 (KP<7>) */
683 VK_LEFT, /* 0x25 (KP<4>) */
684 VK_UP, /* 0x26 (KP<8>) */
685 VK_RIGHT, /* 0x27 (KP<6>) */
686 VK_DOWN, /* 0x28 (KP<2>) */
687 VK_SELECT, /* 0x29 (?????) */
688 VK_PRINT, /* 0x2A (?????) */
689 VK_EXECUTE, /* 0x2B (?????) */
690 VK_SNAPSHOT, /* 0x2C (?????) */
691 VK_INSERT, /* 0x2D (KP<0>) */
692 VK_DELETE, /* 0x2E (KP<.>) */
693 VK_HELP, /* 0x2F (?????) */
695 VK_NUMPAD0, /* 0x60 (KP<0>) */
696 VK_NUMPAD1, /* 0x61 (KP<1>) */
697 VK_NUMPAD2, /* 0x62 (KP<2>) */
698 VK_NUMPAD3, /* 0x63 (KP<3>) */
699 VK_NUMPAD4, /* 0x64 (KP<4>) */
700 VK_NUMPAD5, /* 0x65 (KP<5>) */
701 VK_NUMPAD6, /* 0x66 (KP<6>) */
702 VK_NUMPAD7, /* 0x67 (KP<7>) */
703 VK_NUMPAD8, /* 0x68 (KP<8>) */
704 VK_NUMPAD9, /* 0x69 (KP<9>) */
705 VK_MULTIPLY, /* 0x6A (KP<*>) */
706 VK_ADD, /* 0x6B (KP<+>) */
707 VK_SEPARATOR, /* 0x6C (?????) */
708 VK_SUBTRACT, /* 0x6D (KP<->) */
709 VK_DECIMAL, /* 0x6E (KP<.>) */
710 VK_DIVIDE, /* 0x6F (KP</>) */
741 static void delete_bg(void)
750 static int init_bg(void)
752 char * bmfile = bg_bitmap_file;
755 if (use_bg == 0) return 0;
757 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
760 plog_fmt("ÊÉ»æÍÑ¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
762 plog_fmt("Can't load the bitmap file '%s'.", bmfile);
768 HDC wnddc, dcimage, dcbg;
769 HBITMAP bmimage, bmimage_old, bmbg_old;
775 dcimage = CreateCompatibleDC(wnddc);
776 dcbg = CreateCompatibleDC(wnddc);
778 bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
779 if (!bmimage) quit("bg.bmp¤¬Æɤߤ³¤á¤Ê¤¤¡ª");
780 bmimage_old = SelectObject(dcimage, bmimage);
782 CreateCompatibleBitmap();
784 ReleaseDC(hwnd, wnddc);
790 static void DrawBG(HDC hdc, RECT *r)
795 int x = r->left, y = r->top;
796 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
802 GetObject(hBG, sizeof(bm), &bm);
803 swid = bm.bmWidth; shgt = bm.bmHeight;
805 hdcSrc = CreateCompatibleDC(hdc);
806 hOld = SelectObject(hdcSrc, hBG);
810 cwid = MIN(swid - sx, r->right - nx);
813 chgt = MIN(shgt - sy, r->bottom - ny);
814 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
816 } while (ny < r->bottom);
819 } while (nx < r->right);
821 SelectObject(hdcSrc, hOld);
827 * Hack -- given a pathname, point at the filename
829 static cptr extract_file_name(cptr s)
833 /* Start at the end */
834 p = s + strlen(s) - 1;
836 /* Back up to divider */
837 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
839 /* Return file name */
846 * Hack -- given a simple filename, extract the "font size" info
848 * Return a pointer to a static buffer holding the capitalized base name.
850 #if 0 /* #ifndef JP */
851 static char *analyze_font(char *path, int *wp, int *hp)
857 /* Start at the end */
858 p = path + strlen(path) - 1;
860 /* Back up to divider */
861 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
863 /* Advance to file name */
869 /* Capitalize (be paranoid) */
870 if (islower(*s)) *s = toupper(*s);
874 s = my_strchr(p, 'X');
876 /* Extract font width */
880 hgt = s ? atoi(s+1) : 0;
893 * Check for existance of a file
895 static bool check_file(cptr s)
915 attrib = GetFileAttributes(path);
917 /* Require valid filename */
918 if (attrib == INVALID_FILE_NAME) return (FALSE);
920 /* Prohibit directory */
921 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
925 /* Examine and verify */
926 if (_dos_getfileattr(path, &attrib)) return (FALSE);
928 /* Prohibit something */
929 if (attrib & FA_LABEL) return (FALSE);
931 /* Prohibit directory */
932 if (attrib & FA_DIREC) return (FALSE);
942 * Check for existance of a directory
944 static bool check_dir(cptr s)
966 /* Remove trailing backslash */
967 if (i && (path[i-1] == '\\')) path[--i] = '\0';
972 attrib = GetFileAttributes(path);
974 /* Require valid filename */
975 if (attrib == INVALID_FILE_NAME) return (FALSE);
977 /* Require directory */
978 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
982 /* Examine and verify */
983 if (_dos_getfileattr(path, &attrib)) return (FALSE);
985 /* Prohibit something */
986 if (attrib & FA_LABEL) return (FALSE);
988 /* Require directory */
989 if (!(attrib & FA_DIREC)) return (FALSE);
1001 static void validate_file(cptr s)
1003 /* Verify or fail */
1007 quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
1009 quit_fmt("Cannot find required file:\n%s", s);
1017 * Validate a directory
1019 static void validate_dir(cptr s, bool vital)
1021 /* Verify or fail */
1024 /* This directory contains needed data */
1028 quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
1030 quit_fmt("Cannot find required directory:\n%s", s);
1034 /* Attempt to create this directory */
1037 quit_fmt("Unable to create directory:\n%s", s);
1044 * Get the "size" for a window
1046 static void term_getsize(term_data *td)
1053 if (td->cols < 1) td->cols = 1;
1054 if (td->rows < 1) td->rows = 1;
1057 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1058 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1060 /* Fake window size */
1062 rc.right = rc.left + wid;
1064 rc.bottom = rc.top + hgt;
1067 /* rc.right += 1; */
1068 /* rc.bottom += 1; */
1071 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1074 td->size_wid = rc.right - rc.left;
1075 td->size_hgt = rc.bottom - rc.top;
1077 /* See CreateWindowEx */
1080 /* Extract actual location */
1081 GetWindowRect(td->w, &rc);
1083 /* Save the location */
1084 td->pos_x = rc.left;
1090 * Write the "prefs" for a single term
1092 static void save_prefs_aux(int i)
1094 term_data *td = &data[i];
1099 WINDOWPLACEMENT lpwndpl;
1104 /* Make section name */
1105 sprintf(sec_name, "Term-%d", i);
1110 strcpy(buf, td->visible ? "1" : "0");
1111 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1116 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1119 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1121 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1125 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1127 #if 1 /* #ifdef JP */
1128 wsprintf(buf, "%d", td->lf.lfWidth);
1129 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1130 wsprintf(buf, "%d", td->lf.lfHeight);
1131 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1132 wsprintf(buf, "%d", td->lf.lfWeight);
1133 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1136 strcpy(buf, td->bizarre ? "1" : "0");
1137 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1140 wsprintf(buf, "%d", td->tile_wid);
1141 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1144 wsprintf(buf, "%d", td->tile_hgt);
1145 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1147 /* Get window placement and dimensions */
1148 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1149 GetWindowPlacement(td->w, &lpwndpl);
1151 /* Acquire position in *normal* mode (not minimized) */
1152 rc = lpwndpl.rcNormalPosition;
1154 /* Window size (x) */
1155 if (i == 0) wsprintf(buf, "%d", normsize.x);
1156 else wsprintf(buf, "%d", td->cols);
1157 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1159 /* Window size (y) */
1160 if (i == 0) wsprintf(buf, "%d", normsize.y);
1161 else wsprintf(buf, "%d", td->rows);
1162 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1164 /* Maxmized (only main window) */
1167 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1168 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1171 /* Acquire position */
1172 GetWindowRect(td->w, &rc);
1174 /* Window position (x) */
1175 wsprintf(buf, "%d", rc.left);
1176 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1178 /* Window position (y) */
1179 wsprintf(buf, "%d", rc.top);
1180 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1182 /* Window Z position */
1185 strcpy(buf, td->posfix ? "1" : "0");
1186 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1194 * We assume that the windows have all been initialized
1196 static void save_prefs(void)
1202 /* Save the "arg_graphics" flag */
1203 sprintf(buf, "%d", arg_graphics);
1204 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1206 /* Save the "arg_bigtile" flag */
1207 strcpy(buf, arg_bigtile ? "1" : "0");
1208 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1210 /* Save the "arg_sound" flag */
1211 strcpy(buf, arg_sound ? "1" : "0");
1212 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1215 strcpy(buf, use_bg ? "1" : "0");
1216 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1217 WritePrivateProfileString("Angband", "BackGroundBitmap",
1218 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1220 /* Save window prefs */
1221 for (i = 0; i < MAX_TERM_DATA; ++i)
1229 * Load the "prefs" for a single term
1231 static void load_prefs_aux(int i)
1233 term_data *td = &data[i];
1237 int wid, hgt, posx, posy;
1238 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1239 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1243 /* Make section name */
1244 sprintf(sec_name, "Term-%d", i);
1246 /* Make section name */
1247 sprintf(sec_name, "Term-%d", i);
1252 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1255 /* Desired font, with default */
1257 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1260 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1262 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1268 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1270 /* Analyze font, save desired font name */
1271 #if 1 /* #ifdef JP */
1272 td->font_want = string_make(tmp);
1274 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1275 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1276 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1278 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1283 #if 1 /* #ifdef JP */
1284 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1285 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1287 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1288 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1293 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1294 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1295 normsize.x = td->cols; normsize.y = td->rows;
1300 win_maximized = GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file);
1303 /* Window position */
1304 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1305 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1306 td->pos_x = MIN(MAX(0, posx), dispx-128);
1307 td->pos_y = MIN(MAX(0, posy), dispy-128);
1309 /* Window Z position */
1312 td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1320 static void load_prefs(void)
1324 /* Extract the "arg_graphics" flag */
1325 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1327 /* Extract the "arg_bigtile" flag */
1328 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1329 use_bigtile = arg_bigtile;
1331 /* Extract the "arg_sound" flag */
1332 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1335 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1336 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1338 /* Load window prefs */
1339 for (i = 0; i < MAX_TERM_DATA; ++i)
1348 * XXX XXX XXX - Taken from files.c.
1350 * Extract "tokens" from a buffer
1352 * This function uses "whitespace" as delimiters, and treats any amount of
1353 * whitespace as a single delimiter. We will never return any empty tokens.
1354 * When given an empty buffer, or a buffer containing only "whitespace", we
1355 * will return no tokens. We will never extract more than "num" tokens.
1357 * By running a token through the "text_to_ascii()" function, you can allow
1358 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1360 * We save pointers to the tokens in "tokens", and return the number found.
1362 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1374 /* Skip leading whitespace */
1375 for ( ; *s && iswspace(*s); ++s) /* loop */;
1380 /* Find next whitespace, if any */
1381 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1383 /* Nuke and advance (if necessary) */
1384 if (*t) *t++ = '\0';
1386 /* Save the token */
1397 static void load_sound_prefs(void)
1401 char ini_path[1024];
1402 char wav_path[1024];
1403 char *zz[SAMPLE_MAX];
1405 /* Access the sound.cfg */
1406 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1408 for (i = 0; i < SOUND_MAX; i++)
1410 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1412 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1414 for (j = 0; j < num; j++)
1416 /* Access the sound */
1417 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1419 /* Save the sound filename, if it exists */
1420 if (check_file(wav_path))
1421 sound_file[i][j] = string_make(zz[j]);
1426 #endif /* USE_SOUND */
1429 * Create the new global palette based on the bitmap palette
1430 * (if any), and the standard 16 entry palette derived from
1431 * "win_clr[]" which is used for the basic 16 Angband colors.
1433 * This function is never called before all windows are ready.
1435 * This function returns FALSE if the new palette could not be
1436 * prepared, which should normally be a fatal error. XXX XXX
1438 * Note that only some machines actually use a "palette".
1440 static int new_palette(void)
1448 LPLOGPALETTE pLogPal;
1449 LPPALETTEENTRY lppe;
1454 /* This makes no sense */
1455 if (!paletted) return (TRUE);
1465 /* Check the bitmap palette */
1466 hBmPal = infGraph.hPalette;
1468 /* Use the bitmap */
1471 lppeSize = 256 * sizeof(PALETTEENTRY);
1472 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1473 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1474 if ((nEntries == 0) || (nEntries > 220))
1478 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1480 plog("Please switch to high- or true-color mode.");
1485 rnfree(lppe, lppeSize);
1492 #endif /* USE_GRAPHICS */
1494 /* Size of palette */
1495 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1497 /* Allocate palette */
1498 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1501 pLogPal->palVersion = 0x300;
1503 /* Make room for bitmap and normal data */
1504 pLogPal->palNumEntries = nEntries + 16;
1506 /* Save the bitmap data */
1507 for (i = 0; i < nEntries; i++)
1509 pLogPal->palPalEntry[i] = lppe[i];
1512 /* Save the normal data */
1513 for (i = 0; i < 16; i++)
1517 /* Access the entry */
1518 p = &(pLogPal->palPalEntry[i+nEntries]);
1520 /* Save the colors */
1521 p->peRed = GetRValue(win_clr[i]);
1522 p->peGreen = GetGValue(win_clr[i]);
1523 p->peBlue = GetBValue(win_clr[i]);
1525 /* Save the flags */
1526 p->peFlags = PC_NOCOLLAPSE;
1529 /* Free something */
1530 if (lppe) rnfree(lppe, lppeSize);
1532 /* Create a new palette, or fail */
1533 hNewPal = CreatePalette(pLogPal);
1535 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1537 if (!hNewPal) quit("Cannot create palette!");
1541 /* Free the palette */
1542 rnfree(pLogPal, pLogPalSize);
1547 /* Realize the palette */
1549 SelectPalette(hdc, hNewPal, 0);
1550 i = RealizePalette(hdc);
1551 ReleaseDC(td->w, hdc);
1553 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1555 if (i == 0) quit("Cannot realize palette!");
1560 for (i = 1; i < MAX_TERM_DATA; i++)
1565 SelectPalette(hdc, hNewPal, 0);
1566 ReleaseDC(td->w, hdc);
1569 /* Delete old palette */
1570 if (hPal) DeleteObject(hPal);
1572 /* Save new palette */
1582 * Initialize graphics
1584 static bool init_graphics(void)
1586 /* Initialize once */
1587 /* if (can_use_graphics != arg_graphics) */
1593 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1600 ANGBAND_GRAF = "new";
1608 ANGBAND_GRAF = "old";
1611 /* Access the bitmap file */
1612 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1614 /* Load the bitmap or quit */
1615 if (!ReadDIB(data[0].w, buf, &infGraph))
1618 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1620 plog_fmt("Cannot read bitmap file '%s'", name);
1626 /* Save the new sizes */
1627 infGraph.CellWidth = wid;
1628 infGraph.CellHeight = hgt;
1630 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1632 /* Access the mask file */
1633 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1635 /* Load the bitmap or quit */
1636 if (!ReadDIB(data[0].w, buf, &infMask))
1638 plog_fmt("Cannot read bitmap file '%s'", buf);
1643 /* Activate a palette */
1646 /* Free bitmap XXX XXX XXX */
1650 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1652 plog("Cannot activate palette!");
1658 /* Graphics available */
1659 can_use_graphics = arg_graphics;
1663 return (can_use_graphics);
1665 #endif /* USE_GRAPHICS */
1672 static bool init_sound(void)
1674 /* Initialize once */
1677 /* Load the prefs */
1680 /* Sound available */
1681 can_use_sound = TRUE;
1685 return (can_use_sound);
1687 #endif /* USE_SOUND */
1693 static void term_window_resize(term_data *td)
1695 /* Require window */
1698 /* Resize the window */
1699 SetWindowPos(td->w, 0, 0, 0,
1700 td->size_wid, td->size_hgt,
1701 SWP_NOMOVE | SWP_NOZORDER);
1704 InvalidateRect(td->w, NULL, TRUE);
1709 * Force the use of a new "font file" for a term_data
1711 * This function may be called before the "window" is ready
1713 * This function returns zero only if everything succeeds.
1715 * Note that the "font name" must be capitalized!!!
1717 static errr term_force_font(term_data *td, cptr path)
1721 #if 0 /* #ifndef JP */
1727 /* Forget the old font (if needed) */
1728 if (td->font_id) DeleteObject(td->font_id);
1730 #if 1 /* #ifdef JP */
1734 /* Create the font (using the 'base' of the font file name!) */
1735 td->font_id = CreateFontIndirect(&(td->lf));
1736 wid = td->lf.lfWidth;
1737 hgt = td->lf.lfHeight;
1738 if (!td->font_id) return (1);
1740 /* Forget old font */
1746 for (i = 0; i < MAX_TERM_DATA; i++)
1748 /* Don't check when closing the application */
1751 /* Check "screen" */
1752 if ((td != &data[i]) &&
1753 (data[i].font_file) &&
1754 (streq(data[i].font_file, td->font_file)))
1760 /* Remove unused font resources */
1761 if (!used) RemoveFontResource(td->font_file);
1763 /* Free the old name */
1764 string_free(td->font_file);
1767 td->font_file = NULL;
1771 if (!path) return (1);
1776 /* Analyze font path */
1777 base = analyze_font(buf, &wid, &hgt);
1780 if (!suffix(base, ".FON")) return (1);
1783 if (!check_file(buf)) return (1);
1785 /* Load the new font */
1786 if (!AddFontResource(buf)) return (1);
1788 /* Save new font name */
1789 td->font_file = string_make(base);
1791 /* Remove the "suffix" */
1792 base[strlen(base)-4] = '\0';
1794 /* Create the font (using the 'base' of the font file name!) */
1795 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1796 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1797 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1798 FIXED_PITCH | FF_DONTCARE, base);
1801 /* Hack -- Unknown size */
1808 /* all this trouble to get the cell size */
1809 hdcDesktop = GetDC(HWND_DESKTOP);
1810 hfOld = SelectObject(hdcDesktop, td->font_id);
1811 GetTextMetrics(hdcDesktop, &tm);
1812 SelectObject(hdcDesktop, hfOld);
1813 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1815 /* Font size info */
1816 wid = tm.tmAveCharWidth;
1820 /* Save the size info */
1831 * Allow the user to change the font for this window.
1833 static void term_change_font(term_data *td)
1835 #if 1 /* #ifdef JP */
1838 memset(&cf, 0, sizeof(cf));
1839 cf.lStructSize = sizeof(cf);
1840 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1841 cf.lpLogFont = &(td->lf);
1843 if (ChooseFont(&cf))
1845 /* Force the font */
1846 term_force_font(td, NULL);
1848 /* Assume not bizarre */
1851 /* Reset the tile info */
1852 td->tile_wid = td->font_wid;
1853 td->tile_hgt = td->font_hgt;
1855 /* Analyze the font */
1858 /* Resize the window */
1859 term_window_resize(td);
1865 char tmp[1024] = "";
1867 /* Extract a default if possible */
1868 if (td->font_file) strcpy(tmp, td->font_file);
1870 /* Ask for a choice */
1871 memset(&ofn, 0, sizeof(ofn));
1872 ofn.lStructSize = sizeof(ofn);
1873 ofn.hwndOwner = data[0].w;
1874 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1875 ofn.nFilterIndex = 1;
1876 ofn.lpstrFile = tmp;
1878 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1879 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1880 ofn.lpstrDefExt = "fon";
1882 /* Force choice if legal */
1883 if (GetOpenFileName(&ofn))
1885 /* Force the font */
1886 if (term_force_font(td, tmp))
1888 /* Access the standard font file */
1889 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1891 /* Force the use of that font */
1892 (void)term_force_font(td, tmp);
1895 /* Assume not bizarre */
1896 td->bizarre = FALSE;
1898 /* Reset the tile info */
1899 td->tile_wid = td->font_wid;
1900 td->tile_hgt = td->font_hgt;
1902 /* Analyze the font */
1905 /* Resize the window */
1906 term_window_resize(td);
1913 * Allow the user to lock this window.
1915 static void term_window_pos(term_data *td, HWND hWnd)
1917 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1918 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1921 static void windows_map(void);
1924 * Hack -- redraw a term_data
1926 static void term_data_redraw(term_data *td)
1930 /* Redraw the map */
1935 /* Activate the term */
1936 Term_activate(&td->t);
1938 /* Redraw the contents */
1941 /* Restore the term */
1942 Term_activate(term_screen);
1947 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
1951 HBRUSH myBrush, oldBrush;
1953 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
1954 int tx = td->size_ow1 + x * td->tile_wid;
1955 int ty = td->size_oh1 + y * td->tile_hgt;
1956 int tw = w * td->tile_wid - 1;
1957 int th = h * td->tile_hgt - 1;
1960 myBrush = CreateSolidBrush(RGB(255, 255, 255));
1961 oldBrush = SelectObject(hdc, myBrush);
1962 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
1964 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
1966 SelectObject(hdc, oldBrush);
1967 SelectObject(hdc, oldPen);
1972 /*** Function hooks needed by "Term" ***/
1978 * Initialize a new Term
1980 static void Term_init_win(term *t)
1989 static void Term_nuke_win(term *t)
1998 * Interact with the User
2000 static errr Term_user_win(int n)
2011 * React to global changes
2013 static errr Term_xtra_win_react(void)
2021 /* Save the default colors */
2022 for (i = 0; i < 256; i++)
2024 /* Simply accept the desired colors */
2025 win_pal[i] = angband_color_table[i][0];
2036 bool change = FALSE;
2038 /* Save the default colors */
2039 for (i = 0; i < 256; i++)
2041 /* Extract desired values */
2042 rv = angband_color_table[i][1];
2043 gv = angband_color_table[i][2];
2044 bv = angband_color_table[i][3];
2046 /* Extract a full color code */
2047 code = PALETTERGB(rv, gv, bv);
2049 /* Activate changes */
2050 if (win_clr[i] != code)
2052 /* Note the change */
2055 /* Apply the desired color */
2060 /* Activate the palette if needed */
2061 if (change) (void)new_palette();
2067 /* Handle "arg_sound" */
2068 if (use_sound != arg_sound)
2070 /* Initialize (if needed) */
2071 if (arg_sound && !init_sound())
2075 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
2077 plog("Cannot initialize sound!");
2085 /* Change setting */
2086 use_sound = arg_sound;
2094 /* Handle "arg_graphics" */
2095 if (use_graphics != arg_graphics)
2097 /* Initialize (if needed) */
2098 if (arg_graphics && !init_graphics())
2102 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
2104 plog("Cannot initialize graphics!");
2109 arg_graphics = GRAPHICS_NONE;
2112 /* Change setting */
2113 use_graphics = arg_graphics;
2116 #ifdef ANGBAND_2_8_1
2118 #else /* ANGBAND_2_8_1 */
2119 reset_visuals(TRUE);
2120 #endif /* ANGBAND_2_8_1 */
2123 #endif /* USE_GRAPHICS */
2126 /* Clean up windows */
2127 for (i = 0; i < MAX_TERM_DATA; i++)
2131 term_data *td = &data[i];
2133 /* Update resized windows */
2134 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2137 Term_activate(&td->t);
2139 /* Hack -- Resize the term */
2140 Term_resize(td->cols, td->rows);
2142 /* Redraw the contents */
2157 * Process at least one event
2159 static errr Term_xtra_win_event(int v)
2163 /* Wait for an event */
2167 if (GetMessage(&msg, NULL, 0, 0))
2169 TranslateMessage(&msg);
2170 DispatchMessage(&msg);
2174 /* Check for an event */
2178 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2180 TranslateMessage(&msg);
2181 DispatchMessage(&msg);
2191 * Process all pending events
2193 static errr Term_xtra_win_flush(void)
2197 /* Process all pending events */
2198 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2200 TranslateMessage(&msg);
2201 DispatchMessage(&msg);
2210 * Hack -- clear the screen
2212 * Make this more efficient XXX XXX XXX
2214 static errr Term_xtra_win_clear(void)
2216 term_data *td = (term_data*)(Term->data);
2221 /* Rectangle to erase */
2222 rc.left = td->size_ow1;
2223 rc.right = rc.left + td->cols * td->tile_wid;
2224 rc.top = td->size_oh1;
2225 rc.bottom = rc.top + td->rows * td->tile_hgt;
2229 SetBkColor(hdc, RGB(0, 0, 0));
2230 SelectObject(hdc, td->font_id);
2231 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2236 rc.left = 0; rc.top = 0;
2239 ReleaseDC(td->w, hdc);
2247 * Hack -- make a noise
2249 static errr Term_xtra_win_noise(void)
2251 MessageBeep(MB_ICONASTERISK);
2257 * Hack -- make a sound
2259 static errr Term_xtra_win_sound(int v)
2264 #endif /* USE_SOUND */
2266 /* Sound disabled */
2267 if (!use_sound) return (1);
2270 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2274 /* Count the samples */
2275 for (i = 0; i < SAMPLE_MAX; i++)
2277 if (!sound_file[v][i])
2282 if (i == 0) return (1);
2284 /* Build the path */
2285 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2289 /* Play the sound, catch errors */
2290 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2294 /* Play the sound, catch errors */
2295 return (sndPlaySound(buf, SND_ASYNC));
2299 #else /* USE_SOUND */
2304 #endif /* USE_SOUND */
2309 * Delay for "x" milliseconds
2311 static int Term_xtra_win_delay(int v)
2325 t = GetTickCount() + v;
2328 while (GetTickCount() < t)
2330 /* Handle messages */
2331 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2333 TranslateMessage(&msg);
2334 DispatchMessage(&msg);
2346 * Do a "special thing"
2348 static errr Term_xtra_win(int n, int v)
2350 /* Handle a subset of the legal requests */
2353 /* Make a bell sound */
2354 case TERM_XTRA_NOISE:
2356 return (Term_xtra_win_noise());
2359 /* Make a special sound */
2360 case TERM_XTRA_SOUND:
2362 return (Term_xtra_win_sound(v));
2365 /* Process random events */
2366 case TERM_XTRA_BORED:
2368 return (Term_xtra_win_event(0));
2371 /* Process an event */
2372 case TERM_XTRA_EVENT:
2374 return (Term_xtra_win_event(v));
2377 /* Flush all events */
2378 case TERM_XTRA_FLUSH:
2380 return (Term_xtra_win_flush());
2383 /* Clear the screen */
2384 case TERM_XTRA_CLEAR:
2386 return (Term_xtra_win_clear());
2389 /* React to global changes */
2390 case TERM_XTRA_REACT:
2392 return (Term_xtra_win_react());
2395 /* Delay for some milliseconds */
2396 case TERM_XTRA_DELAY:
2398 return (Term_xtra_win_delay(v));
2409 * Low level graphics (Assumes valid input).
2411 * Draw a "cursor" at (x,y), using a "yellow box".
2413 static errr Term_curs_win(int x, int y)
2415 term_data *td = (term_data*)(Term->data);
2420 int tile_wid, tile_hgt;
2424 tile_wid = td->map_tile_wid;
2425 tile_hgt = td->map_tile_hgt;
2429 tile_wid = td->tile_wid;
2430 tile_hgt = td->tile_hgt;
2433 /* Frame the grid */
2434 rc.left = x * tile_wid + td->size_ow1;
2435 rc.right = rc.left + tile_wid;
2436 rc.top = y * tile_hgt + td->size_oh1;
2437 rc.bottom = rc.top + tile_hgt;
2439 /* Cursor is done as a yellow "box" */
2441 FrameRect(hdc, &rc, hbrYellow);
2442 ReleaseDC(td->w, hdc);
2450 * Low level graphics (Assumes valid input).
2452 * Draw a "big cursor" at (x,y), using a "yellow box".
2454 static errr Term_bigcurs_win(int x, int y)
2456 term_data *td = (term_data*)(Term->data);
2461 int tile_wid, tile_hgt;
2465 /* Normal cursor in map window */
2466 Term_curs_win(x, y);
2471 tile_wid = td->tile_wid;
2472 tile_hgt = td->tile_hgt;
2475 /* Frame the grid */
2476 rc.left = x * tile_wid + td->size_ow1;
2477 rc.right = rc.left + 2 * tile_wid;
2478 rc.top = y * tile_hgt + td->size_oh1;
2479 rc.bottom = rc.top + tile_hgt;
2481 /* Cursor is done as a yellow "box" */
2483 FrameRect(hdc, &rc, hbrYellow);
2484 ReleaseDC(td->w, hdc);
2492 * Low level graphics (Assumes valid input).
2494 * Erase a "block" of "n" characters starting at (x,y).
2496 static errr Term_wipe_win(int x, int y, int n)
2498 term_data *td = (term_data*)(Term->data);
2503 /* Rectangle to erase in client coords */
2504 rc.left = x * td->tile_wid + td->size_ow1;
2505 rc.right = rc.left + n * td->tile_wid;
2506 rc.top = y * td->tile_hgt + td->size_oh1;
2507 rc.bottom = rc.top + td->tile_hgt;
2510 SetBkColor(hdc, RGB(0, 0, 0));
2511 SelectObject(hdc, td->font_id);
2516 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2517 ReleaseDC(td->w, hdc);
2525 * Low level graphics. Assumes valid input.
2527 * Draw several ("n") chars, with an attr, at a given location.
2529 * All "graphic" data is handled by "Term_pict_win()", below.
2531 * One would think there is a more efficient method for telling a window
2532 * what color it should be using to draw with, but perhaps simply changing
2533 * it every time is not too inefficient. XXX XXX XXX
2535 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2537 term_data *td = (term_data*)(Term->data);
2541 #if 1 /* #ifdef JP */
2542 static HBITMAP WALL;
2543 static HBRUSH myBrush, oldBrush;
2545 static bool init_done = FALSE;
2548 WALL = LoadBitmap(hInstance, AppName);
2549 myBrush = CreatePatternBrush(WALL);
2554 /* Total rectangle */
2555 rc.left = x * td->tile_wid + td->size_ow1;
2556 rc.right = rc.left + n * td->tile_wid;
2557 rc.top = y * td->tile_hgt + td->size_oh1;
2558 rc.bottom = rc.top + td->tile_hgt;
2563 /* Background color */
2564 SetBkColor(hdc, RGB(0, 0, 0));
2566 /* Foreground color */
2569 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2573 SetTextColor(hdc, win_clr[a&0x0F]);
2577 SetTextColor(hdc, win_clr[a]);
2581 SelectObject(hdc, td->font_id);
2584 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2588 (td->tile_hgt != td->font_hgt) ||
2589 (td->tile_wid != td->font_wid))
2593 /* Erase complete rectangle */
2594 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2597 if (use_bg) DrawBG(hdc, &rc);
2600 rc.left += ((td->tile_wid - td->font_wid) / 2);
2601 rc.right = rc.left + td->font_wid;
2602 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2603 rc.bottom = rc.top + td->font_hgt;
2605 /* Dump each character */
2606 for (i = 0; i < n; i++)
2609 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2611 rc.right += td->font_wid;
2613 oldBrush = SelectObject(hdc, myBrush);
2614 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2617 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2619 SelectObject(hdc, oldBrush);
2620 SelectObject(hdc, oldPen);
2621 rc.right -= td->font_wid;
2625 rc.left += 2 * td->tile_wid;
2626 rc.right += 2 * td->tile_wid;
2628 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2630 rc.right += td->font_wid;
2632 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2634 rc.right -= td->font_wid;
2638 rc.left += 2 * td->tile_wid;
2639 rc.right += 2 * td->tile_wid;
2640 } else if (*(s+i)==127){
2641 oldBrush = SelectObject(hdc, myBrush);
2642 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2645 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2647 SelectObject(hdc, oldBrush);
2648 SelectObject(hdc, oldPen);
2651 rc.left += td->tile_wid;
2652 rc.right += td->tile_wid;
2655 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2658 rc.left += td->tile_wid;
2659 rc.right += td->tile_wid;
2664 oldBrush = SelectObject(hdc, myBrush);
2665 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2668 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2670 SelectObject(hdc, oldBrush);
2671 SelectObject(hdc, oldPen);
2674 rc.left += td->tile_wid;
2675 rc.right += td->tile_wid;
2678 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2682 rc.left += td->tile_wid;
2683 rc.right += td->tile_wid;
2687 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2691 rc.left += td->tile_wid;
2692 rc.right += td->tile_wid;
2703 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2708 ReleaseDC(td->w, hdc);
2716 * Low level graphics. Assumes valid input.
2718 * Draw an array of "special" attr/char pairs at the given location.
2720 * We use the "Term_pict_win()" function for "graphic" data, which are
2721 * encoded by setting the "high-bits" of both the "attr" and the "char"
2722 * data. We use the "attr" to represent the "row" of the main bitmap,
2723 * and the "char" to represent the "col" of the main bitmap. The use
2724 * of this function is induced by the "higher_pict" flag.
2726 * If "graphics" is not available, we simply "wipe" the given grids.
2728 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2730 term_data *td = (term_data*)(Term->data);
2736 int x2, y2, w2, h2, tw2;
2748 /* Erase the grids */
2749 return (Term_wipe_win(x, y, n));
2752 /* Size of bitmap cell */
2753 w1 = infGraph.CellWidth;
2754 h1 = infGraph.CellHeight;
2756 /* Size of window cell */
2759 w2 = td->map_tile_wid;
2760 h2 = td->map_tile_hgt;
2769 if (use_bigtile) tw2 *= 2;
2772 /* Location of window cell */
2773 x2 = x * w2 + td->size_ow1;
2774 y2 = y * h2 + td->size_oh1;
2780 hdcSrc = CreateCompatibleDC(hdc);
2781 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2783 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2785 hdcMask = CreateCompatibleDC(hdc);
2786 SelectObject(hdcMask, infMask.hBitmap);
2789 /* Draw attr/char pairs */
2790 for (i = 0; i < n; i++, x2 += w2)
2795 /* Extract picture */
2796 int row = (a & 0x7F);
2797 int col = (c & 0x7F);
2799 /* Location of bitmap cell */
2803 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2805 x3 = (tcp[i] & 0x7F) * w1;
2806 y3 = (tap[i] & 0x7F) * h1;
2809 if ((w1 == tw2) && (h1 == h2))
2811 /* Copy the terrain picture from the bitmap to the window */
2812 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2814 /* Mask out the tile */
2815 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2818 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2821 /* Need to stretch */
2824 /* Set the correct mode for stretching the tiles */
2825 SetStretchBltMode(hdc, COLORONCOLOR);
2827 /* Copy the terrain picture from the bitmap to the window */
2828 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
2830 /* Only draw if terrain and overlay are different */
2831 if ((x1 != x3) || (y1 != y3))
2833 /* Mask out the tile */
2834 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2837 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2844 if ((w1 == tw2) && (h1 == h2))
2846 /* Copy the picture from the bitmap to the window */
2847 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2850 /* Need to stretch */
2853 /* Set the correct mode for stretching the tiles */
2854 SetStretchBltMode(hdc, COLORONCOLOR);
2856 /* Copy the picture from the bitmap to the window */
2857 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2863 SelectObject(hdcSrc, hbmSrcOld);
2866 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2869 SelectObject(hdcMask, hbmSrcOld);
2874 ReleaseDC(td->w, hdc);
2876 #else /* USE_GRAPHICS */
2878 /* Just erase this grid */
2879 return (Term_wipe_win(x, y, n));
2881 #endif /* USE_GRAPHICS */
2888 static void windows_map(void)
2890 term_data *td = &data[0];
2892 int x, min_x, max_x;
2893 int y, min_y, max_y;
2897 /* Only in graphics mode */
2898 if (!use_graphics) return;
2901 Term_xtra_win_clear();
2903 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2904 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2905 td->map_active = TRUE;
2915 for (x = min_x; x < max_x; x++)
2917 for (y = min_y; y < max_y; y++)
2919 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
2921 /* Ignore non-graphics */
2922 if ((a & 0x80) && (c & 0x80))
2924 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2929 /* Hilite the player */
2930 Term_curs_win(px - min_x, py - min_y);
2932 /* Wait for a keypress, flush key buffer */
2933 Term_inkey(&c, TRUE, TRUE);
2936 /* Switch off the map display */
2937 td->map_active = FALSE;
2939 /* Restore screen */
2940 Term_xtra_win_clear();
2945 /*** Other routines ***/
2949 * Create and initialize a "term_data" given a title
2951 static void term_data_link(term_data *td)
2955 /* Initialize the term */
2956 term_init(t, td->cols, td->rows, td->keys);
2958 /* Use a "software" cursor */
2959 t->soft_cursor = TRUE;
2961 /* Use "Term_pict" for "graphic" data */
2962 t->higher_pict = TRUE;
2964 /* Erase with "white space" */
2965 t->attr_blank = TERM_WHITE;
2966 t->char_blank = ' ';
2969 /* Prepare the init/nuke hooks */
2970 t->init_hook = Term_init_win;
2971 t->nuke_hook = Term_nuke_win;
2974 /* Prepare the template hooks */
2975 t->user_hook = Term_user_win;
2976 t->xtra_hook = Term_xtra_win;
2977 t->curs_hook = Term_curs_win;
2978 t->bigcurs_hook = Term_bigcurs_win;
2979 t->wipe_hook = Term_wipe_win;
2980 t->text_hook = Term_text_win;
2981 t->pict_hook = Term_pict_win;
2983 /* Remember where we came from */
2984 t->data = (vptr)(td);
2989 * Create the windows
2991 * First, instantiate the "default" values, then read the "ini_file"
2992 * to over-ride selected values, then create the windows, and fonts.
2994 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2995 * must make active to realize the palette. XXX XXX XXX
2997 static void init_windows(void)
3003 #if 0 /* #ifndef JP */
3009 WIPE(td, term_data);
3013 td->s = angband_term_name[0];
3027 #if 1 /* #ifdef JP */
3031 for (i = 1; i < MAX_TERM_DATA; i++)
3034 WIPE(td, term_data);
3035 td->s = angband_term_name[i];
3039 td->visible = FALSE;
3044 td->pos_x = (7 - i) * 30;
3045 td->pos_y = (7 - i) * 20;
3047 #if 1 /* #ifdef JP */
3057 /* Main window (need these before term_getsize gets called) */
3059 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3060 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3065 /* Sub windows (need these before term_getsize gets called) */
3066 for (i = 1; i < MAX_TERM_DATA; i++)
3069 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3070 td->dwExStyle = (WS_EX_TOOLWINDOW);
3075 for (i = 0; i < MAX_TERM_DATA; i++)
3079 #if 1 /* #ifdef JP */
3080 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3081 td->lf.lfCharSet = DEFAULT_CHARSET;
3082 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3083 /* Activate the chosen font */
3084 term_force_font(td, NULL);
3085 td->tile_wid = td->font_wid;
3086 td->tile_hgt = td->font_hgt;
3088 /* Access the standard font file */
3089 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3091 /* Activate the chosen font */
3092 if (term_force_font(td, buf))
3094 /* Access the standard font file */
3095 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3097 /* Force the use of that font */
3098 (void)term_force_font(td, buf);
3104 /* Assume not bizarre */
3105 td->bizarre = FALSE;
3110 /* Analyze the font */
3113 /* Resize the window */
3114 term_window_resize(td);
3118 /* Sub windows (reverse order) */
3119 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3124 td->w = CreateWindowEx(td->dwExStyle, AngList,
3126 td->pos_x, td->pos_y,
3127 td->size_wid, td->size_hgt,
3128 HWND_DESKTOP, NULL, hInstance, NULL);
3131 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3133 if (!td->w) quit("Failed to create sub-window");
3139 td->size_hack = TRUE;
3140 ShowWindow(td->w, SW_SHOW);
3141 td->size_hack = FALSE;
3145 angband_term[i] = &td->t;
3149 /* Activate the window */
3150 SetActiveWindow(td->w);
3155 term_window_pos(&data[i], HWND_TOPMOST);
3159 term_window_pos(&data[i], td->w);
3169 td->w = CreateWindowEx(td->dwExStyle, AppName,
3171 td->pos_x, td->pos_y,
3172 td->size_wid, td->size_hgt,
3173 HWND_DESKTOP, NULL, hInstance, NULL);
3176 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3178 if (!td->w) quit("Failed to create Angband window");
3183 angband_term[0] = &td->t;
3184 normsize.x = td->cols;
3185 normsize.y = td->rows;
3187 /* Activate the main window */
3188 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3189 else ShowWindow(td->w, SW_SHOW);
3191 /* Bring main window back to top */
3192 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3195 /* New palette XXX XXX XXX */
3196 (void)new_palette();
3199 /* Create a "brush" for drawing the "cursor" */
3200 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3203 /* Process pending messages */
3204 (void)Term_xtra_win_flush();
3212 static void setup_menus(void)
3216 HMENU hm = GetMenu(data[0].w);
3219 /* Menu "File", Disable all */
3220 EnableMenuItem(hm, IDM_FILE_NEW,
3221 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3222 EnableMenuItem(hm, IDM_FILE_OPEN,
3223 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3224 EnableMenuItem(hm, IDM_FILE_SAVE,
3225 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3226 EnableMenuItem(hm, IDM_FILE_EXIT,
3227 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3228 EnableMenuItem(hm, IDM_FILE_SCORE,
3229 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3232 /* No character available */
3233 if (!character_generated)
3235 /* Menu "File", Item "New" */
3236 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3238 /* Menu "File", Item "Open" */
3239 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3242 /* A character available */
3243 if (character_generated)
3245 /* Menu "File", Item "Save" */
3246 EnableMenuItem(hm, IDM_FILE_SAVE,
3247 MF_BYCOMMAND | MF_ENABLED);
3250 /* Menu "File", Item "Exit" */
3251 EnableMenuItem(hm, IDM_FILE_EXIT,
3252 MF_BYCOMMAND | MF_ENABLED);
3254 EnableMenuItem(hm, IDM_FILE_SCORE,
3255 MF_BYCOMMAND | MF_ENABLED);
3258 /* Menu "Window::Visibility" */
3259 for (i = 0; i < MAX_TERM_DATA; i++)
3261 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3262 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3264 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3265 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3267 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3268 MF_BYCOMMAND | MF_ENABLED);
3271 /* Menu "Window::Font" */
3272 for (i = 0; i < MAX_TERM_DATA; i++)
3274 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3275 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3277 if (data[i].visible)
3279 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3280 MF_BYCOMMAND | MF_ENABLED);
3284 /* Menu "Window::Window Position Fix" */
3285 for (i = 0; i < MAX_TERM_DATA; i++)
3287 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3288 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3290 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3291 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3293 if (data[i].visible)
3295 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3296 MF_BYCOMMAND | MF_ENABLED);
3300 /* Menu "Window::Bizarre Display" */
3301 for (i = 0; i < MAX_TERM_DATA; i++)
3303 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3304 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3306 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3307 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3309 if (data[i].visible)
3311 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3312 MF_BYCOMMAND | MF_ENABLED);
3317 /* Menu "Window::Increase Tile Width" */
3318 for (i = 0; i < MAX_TERM_DATA; i++)
3320 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3321 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3323 if (data[i].visible)
3325 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3326 MF_BYCOMMAND | MF_ENABLED);
3331 /* Menu "Window::Decrease Tile Width" */
3332 for (i = 0; i < MAX_TERM_DATA; i++)
3334 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3335 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3337 if (data[i].visible)
3339 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3340 MF_BYCOMMAND | MF_ENABLED);
3345 /* Menu "Window::Increase Tile Height" */
3346 for (i = 0; i < MAX_TERM_DATA; i++)
3348 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3349 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3351 if (data[i].visible)
3353 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3354 MF_BYCOMMAND | MF_ENABLED);
3359 /* Menu "Window::Decrease Tile Height" */
3360 for (i = 0; i < MAX_TERM_DATA; i++)
3362 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3363 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3365 if (data[i].visible)
3367 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3368 MF_BYCOMMAND | MF_ENABLED);
3373 /* Menu "Options", disable all */
3374 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3375 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3376 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3377 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3378 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3379 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3380 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3381 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3382 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3383 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3385 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3386 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3389 /* Menu "Options", Item "Map" */
3390 if (use_graphics != GRAPHICS_NONE)
3391 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3393 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3394 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3396 /* Menu "Options", update all */
3397 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3398 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3399 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3400 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3401 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3402 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3403 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3404 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3405 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3406 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3407 CheckMenuItem(hm, IDM_OPTIONS_BG,
3408 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3410 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3411 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3415 /* Menu "Options", Item "Graphics" */
3416 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3417 /* Menu "Options", Item "Graphics" */
3418 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3419 /* Menu "Options", Item "Graphics" */
3420 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3421 /* Menu "Options", Item "Graphics" */
3422 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3423 #endif /* USE_GRAPHICS */
3426 /* Menu "Options", Item "Sound" */
3427 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3428 #endif /* USE_SOUND */
3431 /* Menu "Options", Item "ScreenSaver" */
3432 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3433 MF_BYCOMMAND | MF_ENABLED);
3434 #endif /* USE_SAVER */
3439 * Check for double clicked (or dragged) savefile
3441 * Apparently, Windows copies the entire filename into the first
3442 * piece of the "command line string". Perhaps we should extract
3443 * the "basename" of that filename and append it to the "save" dir.
3445 static void check_for_save_file(LPSTR cmd_line)
3455 /* Extract filename */
3456 strcat(savefile, s);
3458 /* Validate the file */
3459 validate_file(savefile);
3461 /* Game in progress */
3462 game_in_progress = TRUE;
3470 * Process a menu command
3472 static void process_menus(WORD wCmd)
3489 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3491 plog("You cannot do that yet...");
3495 else if (game_in_progress)
3498 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3500 plog("You can't start a new game while you're still playing!");
3506 game_in_progress = TRUE;
3520 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3522 plog("You cannot do that yet...");
3526 else if (game_in_progress)
3529 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3531 plog("You can't open a new game while you're still playing!");
3537 memset(&ofn, 0, sizeof(ofn));
3538 ofn.lStructSize = sizeof(ofn);
3539 ofn.hwndOwner = data[0].w;
3540 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3541 ofn.nFilterIndex = 1;
3542 ofn.lpstrFile = savefile;
3543 ofn.nMaxFile = 1024;
3544 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3545 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3547 if (GetOpenFileName(&ofn))
3549 /* Load 'savefile' */
3550 validate_file(savefile);
3551 game_in_progress = TRUE;
3563 if (game_in_progress && character_generated)
3569 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3571 plog("You may not do that right now.");
3577 /* Hack -- Forget messages */
3582 do_cmd_save_game(FALSE);
3583 #else /* ZANGBAND */
3585 #endif /* ZANGBAND */
3590 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3592 plog("You may not do that right now.");
3602 if (game_in_progress && character_generated)
3608 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3610 plog("You may not do that right now.");
3616 /* Hack -- Forget messages */
3625 /* do_cmd_save_game(FALSE); */
3626 #else /* ZANGBAND */
3627 /* do_cmd_save_game(); */
3628 #endif /* ZANGBAND */
3629 Term_key_push(SPECIAL_KEY_QUIT);
3637 case IDM_FILE_SCORE:
3641 /* Build the filename */
3642 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3644 /* Open the binary high score file, for reading */
3645 highscore_fd = fd_open(buf, O_RDONLY);
3647 /* Paranoia -- No score file */
3648 if (highscore_fd < 0)
3650 msg_print("Score file unavailable.");
3660 /* Display the scores */
3661 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3663 /* Shut the high score file */
3664 (void)fd_close(highscore_fd);
3666 /* Forget the high score fd */
3672 /* Hack - Flush it */
3680 case IDM_FILE_MOVIE:
3685 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3687 plog("You cannot do that yet...");
3690 else if (game_in_progress)
3693 plog("¥×¥ì¥¤Ãæ¤Ï¥à¡¼¥Ó¡¼¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3695 plog("You can't open a movie while you're playing!");
3700 memset(&ofn, 0, sizeof(ofn));
3701 ofn.lStructSize = sizeof(ofn);
3702 ofn.hwndOwner = data[0].w;
3703 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3704 ofn.nFilterIndex = 1;
3705 ofn.lpstrFile = savefile;
3706 ofn.nMaxFile = 1024;
3707 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3708 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3710 if (GetOpenFileName(&ofn))
3712 /* Load 'savefile' */
3713 prepare_browse_movie_aux(savefile);
3723 case IDM_WINDOW_VIS_0:
3726 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3728 plog("You are not allowed to do that!");
3735 /* Window visibility */
3736 case IDM_WINDOW_VIS_1:
3737 case IDM_WINDOW_VIS_2:
3738 case IDM_WINDOW_VIS_3:
3739 case IDM_WINDOW_VIS_4:
3740 case IDM_WINDOW_VIS_5:
3741 case IDM_WINDOW_VIS_6:
3742 case IDM_WINDOW_VIS_7:
3744 i = wCmd - IDM_WINDOW_VIS_0;
3746 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3753 ShowWindow(td->w, SW_SHOW);
3754 term_data_redraw(td);
3758 td->visible = FALSE;
3760 ShowWindow(td->w, SW_HIDE);
3767 case IDM_WINDOW_FONT_0:
3768 case IDM_WINDOW_FONT_1:
3769 case IDM_WINDOW_FONT_2:
3770 case IDM_WINDOW_FONT_3:
3771 case IDM_WINDOW_FONT_4:
3772 case IDM_WINDOW_FONT_5:
3773 case IDM_WINDOW_FONT_6:
3774 case IDM_WINDOW_FONT_7:
3776 i = wCmd - IDM_WINDOW_FONT_0;
3778 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3782 term_change_font(td);
3787 /* Window Z Position */
3788 case IDM_WINDOW_POS_1:
3789 case IDM_WINDOW_POS_2:
3790 case IDM_WINDOW_POS_3:
3791 case IDM_WINDOW_POS_4:
3792 case IDM_WINDOW_POS_5:
3793 case IDM_WINDOW_POS_6:
3794 case IDM_WINDOW_POS_7:
3796 i = wCmd - IDM_WINDOW_POS_0;
3798 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3802 if (!td->posfix && td->visible)
3805 term_window_pos(td, HWND_TOPMOST);
3810 term_window_pos(td, data[0].w);
3816 /* Bizarre Display */
3817 case IDM_WINDOW_BIZ_0:
3818 case IDM_WINDOW_BIZ_1:
3819 case IDM_WINDOW_BIZ_2:
3820 case IDM_WINDOW_BIZ_3:
3821 case IDM_WINDOW_BIZ_4:
3822 case IDM_WINDOW_BIZ_5:
3823 case IDM_WINDOW_BIZ_6:
3824 case IDM_WINDOW_BIZ_7:
3826 i = wCmd - IDM_WINDOW_BIZ_0;
3828 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3832 td->bizarre = !td->bizarre;
3836 term_window_resize(td);
3841 /* Increase Tile Width */
3842 case IDM_WINDOW_I_WID_0:
3843 case IDM_WINDOW_I_WID_1:
3844 case IDM_WINDOW_I_WID_2:
3845 case IDM_WINDOW_I_WID_3:
3846 case IDM_WINDOW_I_WID_4:
3847 case IDM_WINDOW_I_WID_5:
3848 case IDM_WINDOW_I_WID_6:
3849 case IDM_WINDOW_I_WID_7:
3851 i = wCmd - IDM_WINDOW_I_WID_0;
3853 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3861 term_window_resize(td);
3866 /* Decrease Tile Height */
3867 case IDM_WINDOW_D_WID_0:
3868 case IDM_WINDOW_D_WID_1:
3869 case IDM_WINDOW_D_WID_2:
3870 case IDM_WINDOW_D_WID_3:
3871 case IDM_WINDOW_D_WID_4:
3872 case IDM_WINDOW_D_WID_5:
3873 case IDM_WINDOW_D_WID_6:
3874 case IDM_WINDOW_D_WID_7:
3876 i = wCmd - IDM_WINDOW_D_WID_0;
3878 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3886 term_window_resize(td);
3891 /* Increase Tile Height */
3892 case IDM_WINDOW_I_HGT_0:
3893 case IDM_WINDOW_I_HGT_1:
3894 case IDM_WINDOW_I_HGT_2:
3895 case IDM_WINDOW_I_HGT_3:
3896 case IDM_WINDOW_I_HGT_4:
3897 case IDM_WINDOW_I_HGT_5:
3898 case IDM_WINDOW_I_HGT_6:
3899 case IDM_WINDOW_I_HGT_7:
3901 i = wCmd - IDM_WINDOW_I_HGT_0;
3903 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3911 term_window_resize(td);
3916 /* Decrease Tile Height */
3917 case IDM_WINDOW_D_HGT_0:
3918 case IDM_WINDOW_D_HGT_1:
3919 case IDM_WINDOW_D_HGT_2:
3920 case IDM_WINDOW_D_HGT_3:
3921 case IDM_WINDOW_D_HGT_4:
3922 case IDM_WINDOW_D_HGT_5:
3923 case IDM_WINDOW_D_HGT_6:
3924 case IDM_WINDOW_D_HGT_7:
3926 i = wCmd - IDM_WINDOW_D_HGT_0;
3928 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3936 term_window_resize(td);
3941 case IDM_OPTIONS_NO_GRAPHICS:
3946 plog("You may not do that right now.");
3950 /* Toggle "arg_graphics" */
3951 if (arg_graphics != GRAPHICS_NONE)
3953 arg_graphics = GRAPHICS_NONE;
3955 /* React to changes */
3956 Term_xtra_win_react();
3958 /* Hack -- Force redraw */
3959 Term_key_push(KTRL('R'));
3965 case IDM_OPTIONS_OLD_GRAPHICS:
3970 plog("You may not do that right now.");
3974 /* Toggle "arg_graphics" */
3975 if (arg_graphics != GRAPHICS_ORIGINAL)
3977 arg_graphics = GRAPHICS_ORIGINAL;
3979 /* React to changes */
3980 Term_xtra_win_react();
3982 /* Hack -- Force redraw */
3983 Term_key_push(KTRL('R'));
3989 case IDM_OPTIONS_NEW_GRAPHICS:
3994 plog("You may not do that right now.");
3998 /* Toggle "arg_graphics" */
3999 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4001 arg_graphics = GRAPHICS_ADAM_BOLT;
4003 /* React to changes */
4004 Term_xtra_win_react();
4006 /* Hack -- Force redraw */
4007 Term_key_push(KTRL('R'));
4013 case IDM_OPTIONS_BIGTILE:
4015 term_data *td = &data[0];
4020 plog("You may not do that right now.");
4024 /* Toggle "arg_sound" */
4025 arg_bigtile = !arg_bigtile;
4028 Term_activate(&td->t);
4030 /* Resize the term */
4031 Term_resize(td->cols, td->rows);
4034 InvalidateRect(td->w, NULL, TRUE);
4039 case IDM_OPTIONS_SOUND:
4044 plog("You may not do that right now.");
4048 /* Toggle "arg_sound" */
4049 arg_sound = !arg_sound;
4051 /* React to changes */
4052 Term_xtra_win_react();
4054 /* Hack -- Force redraw */
4055 Term_key_push(KTRL('R'));
4061 case IDM_OPTIONS_BG:
4066 plog("You may not do that right now.");
4070 /* Toggle "use_bg" */
4075 /* React to changes */
4076 Term_xtra_win_react();
4078 /* Hack -- Force redraw */
4079 Term_key_push(KTRL('R'));
4085 case IDM_OPTIONS_OPEN_BG:
4090 plog("You may not do that right now.");
4095 memset(&ofn, 0, sizeof(ofn));
4096 ofn.lStructSize = sizeof(ofn);
4097 ofn.hwndOwner = data[0].w;
4098 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4099 ofn.nFilterIndex = 1;
4100 ofn.lpstrFile = bg_bitmap_file;
4101 ofn.nMaxFile = 1023;
4102 ofn.lpstrInitialDir = NULL;
4104 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
4106 ofn.lpstrTitle = "Choose wall paper.";
4108 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4110 if (GetOpenFileName(&ofn))
4112 /* Load 'savefile' */
4117 /* React to changes */
4118 Term_xtra_win_react();
4120 /* Hack -- Force redraw */
4121 Term_key_push(KTRL('R'));
4126 case IDM_DUMP_SCREEN_HTML:
4128 static char buf[1024] = "";
4129 memset(&ofn, 0, sizeof(ofn));
4130 ofn.lStructSize = sizeof(ofn);
4131 ofn.hwndOwner = data[0].w;
4132 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4133 ofn.nFilterIndex = 1;
4134 ofn.lpstrFile = buf;
4135 ofn.nMaxFile = 1023;
4136 ofn.lpstrDefExt = "html";
4137 ofn.lpstrInitialDir = NULL;
4139 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
4141 ofn.lpstrTitle = "Save screen dump as HTML.";
4143 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4145 if (GetSaveFileName(&ofn))
4147 do_cmd_save_screen_html_aux(buf, 0);
4154 case IDM_OPTIONS_SAVER:
4158 DestroyWindow(hwndSaver);
4163 /* Create a screen scaver window */
4164 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4165 "Angband Screensaver",
4166 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4167 0, 0, GetSystemMetrics(SM_CXSCREEN),
4168 GetSystemMetrics(SM_CYSCREEN),
4169 NULL, NULL, hInstance, NULL);
4173 /* Push the window to the bottom XXX XXX XXX */
4174 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4179 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
4181 plog("Failed to create saver window");
4191 case IDM_OPTIONS_MAP:
4197 case IDM_HELP_CONTENTS:
4201 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4202 if (check_file(tmp))
4204 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4209 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4210 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4212 plog_fmt("Cannot find help file: %s", tmp);
4213 plog("Use the online help files instead.");
4218 #else /* HTML_HELP */
4221 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4222 if (check_file(tmp))
4224 sprintf(buf, "winhelp.exe %s", tmp);
4225 WinExec(buf, SW_NORMAL);
4230 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4231 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4233 plog_fmt("Cannot find help file: %s", tmp);
4234 plog("Use the online help files instead.");
4239 #endif /* HTML_HELP */
4245 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4252 /* Extract the modifiers */
4253 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4254 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4255 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4257 Term_no_press = (ma) ? TRUE : FALSE;
4259 /* Handle "special" keys */
4260 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4262 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4263 bool numpad = FALSE;
4265 /* Begin the macro trigger */
4268 /* Send the modifiers */
4269 if (mc) Term_keypress('C');
4270 if (ms) Term_keypress('S');
4271 if (ma) Term_keypress('A');
4273 /* Extract "scan code" */
4274 i = LOBYTE(HIWORD(lParam));
4276 /* Introduce the scan code */
4279 /* Extended key bit */
4282 /* Numpad Enter and '/' are extended key */
4284 Term_no_press = TRUE;
4285 case VK_RETURN: /* Enter */
4288 /* Other extended keys are on full keyboard */
4304 Term_no_press = TRUE;
4308 case VK_PRIOR: /* Page Up */
4309 case VK_NEXT: /* Page Down */
4319 /* Special modifiers for keypad keys */
4320 if (numpad) Term_keypress('K');
4322 /* Encode the hexidecimal scan code */
4323 Term_keypress(hexsym[i/16]);
4324 Term_keypress(hexsym[i%16]);
4326 /* End the macro trigger */
4337 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4338 WPARAM wParam, LPARAM lParam);
4339 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4340 WPARAM wParam, LPARAM lParam)
4341 #else /* __MWERKS__ */
4342 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4343 WPARAM wParam, LPARAM lParam)
4344 #endif /* __MWERKS__ */
4350 MINMAXINFO FAR *lpmmi;
4356 /* Acquire proper "term_data" info */
4357 td = (term_data *)GetWindowLong(hWnd, 0);
4359 /* Handle message */
4365 SetWindowLong(hWnd, 0, (LONG)(my_td));
4375 case WM_GETMINMAXINFO:
4377 MINMAXINFO FAR *lpmmi;
4380 lpmmi = (MINMAXINFO FAR *)lParam;
4382 /* this message was sent before WM_NCCREATE */
4385 /* Minimum window size is 80x24 */
4386 rc.left = rc.top = 0;
4387 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4388 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4391 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4393 /* Save minimum size */
4394 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4395 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4402 BeginPaint(hWnd, &ps);
4403 if (td) term_data_redraw(td);
4404 EndPaint(hWnd, &ps);
4405 ValidateRect(hWnd, NULL);
4412 if (process_keydown(wParam, lParam))
4419 if (Term_no_press) Term_no_press = FALSE;
4420 else Term_keypress(wParam);
4424 case WM_LBUTTONDOWN:
4426 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4427 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4439 int dx = abs(oldx - mousex) + 1;
4440 int dy = abs(oldy - mousey) + 1;
4441 int ox = (oldx > mousex) ? mousex : oldx;
4442 int oy = (oldy > mousey) ? mousey : oldy;
4452 hGlobal = GlobalAlloc(GHND, sz + 1);
4453 if (hGlobal == NULL) return 0;
4454 lpStr = (LPSTR)GlobalLock(hGlobal);
4456 for (i = 0; i < dy; i++)
4460 char **scr = data[0].t.scr->c;
4462 C_MAKE(s, (dx + 1), char);
4463 strncpy(s, &scr[oy + i][ox], dx);
4467 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4470 if (ox + dx < data[0].cols)
4472 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4475 for (j = 0; j < dx; j++)
4477 if (s[j] == 127) s[j] = '#';
4481 for (j = 0; j < dx; j++)
4483 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4493 GlobalUnlock(hGlobal);
4494 if (OpenClipboard(hWnd) == 0)
4496 GlobalFree(hGlobal);
4500 SetClipboardData(CF_TEXT, hGlobal);
4513 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4514 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4519 dx = abs(oldx - mousex) + 1;
4520 dy = abs(oldy - mousey) + 1;
4521 ox = (oldx > mousex) ? mousex : oldx;
4522 oy = (oldy > mousey) ? mousey : oldy;
4523 Term_inversed_area(hWnd, ox, oy, dx, dy);
4530 dx = abs(cx - mousex) + 1;
4531 dy = abs(cy - mousey) + 1;
4532 ox = (cx > mousex) ? mousex : cx;
4533 oy = (cy > mousey) ? mousey : cy;
4534 Term_inversed_area(hWnd, ox, oy, dx, dy);
4550 if (game_in_progress && character_generated)
4555 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4557 plog("You may not do that right now.");
4562 /* Hack -- Forget messages */
4571 /* do_cmd_save_game(FALSE); */
4572 #else /* ZANGBAND */
4573 /* do_cmd_save_game(); */
4574 #endif /* ZANGBAND */
4575 Term_key_push(SPECIAL_KEY_QUIT);
4582 case WM_QUERYENDSESSION:
4584 if (game_in_progress && character_generated)
4586 /* Hack -- Forget messages */
4589 /* Mega-Hack -- Delay death */
4590 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4593 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "----¥²¡¼¥àÃæÃÇ----");
4595 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "---- Save and Exit Game ----");
4598 /* Hardcode panic save */
4599 p_ptr->panic_save = 1;
4601 /* Forbid suspend */
4602 signals_ignore_tstp();
4604 /* Indicate panic save */
4606 (void)strcpy(p_ptr->died_from, "(¶ÛµÞ¥»¡¼¥Ö)");
4608 (void)strcpy(p_ptr->died_from, "(panic save)");
4612 (void)save_player();
4626 process_menus(LOWORD(wParam));
4632 /* this message was sent before WM_NCCREATE */
4635 /* it was sent from inside CreateWindowEx */
4636 if (!td->w) return 1;
4638 /* was sent from WM_SIZE */
4639 if (td->size_hack) return 1;
4643 case SIZE_MINIMIZED:
4645 /* Hide sub-windows */
4646 for (i = 1; i < MAX_TERM_DATA; i++)
4648 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4653 case SIZE_MAXIMIZED:
4655 /* fall through XXX XXX XXX */
4660 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4661 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4664 if ((td->cols != cols) || (td->rows != rows))
4666 /* Save the new size */
4670 if (!IsZoomed(td->w) && !IsIconic(td->w))
4672 normsize.x = td->cols;
4673 normsize.y = td->rows;
4677 Term_activate(&td->t);
4679 /* Resize the term */
4680 Term_resize(td->cols, td->rows);
4683 InvalidateRect(td->w, NULL, TRUE);
4686 td->size_hack = TRUE;
4688 /* Show sub-windows */
4689 for (i = 1; i < MAX_TERM_DATA; i++)
4691 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4694 td->size_hack = FALSE;
4702 case WM_PALETTECHANGED:
4704 /* Ignore if palette change caused by itself */
4705 if ((HWND)wParam == hWnd) return 0;
4707 /* Fall through... */
4710 case WM_QUERYNEWPALETTE:
4712 if (!paletted) return 0;
4716 SelectPalette(hdc, hPal, FALSE);
4718 i = RealizePalette(hdc);
4720 /* if any palette entries changed, repaint the window. */
4721 if (i) InvalidateRect(hWnd, NULL, TRUE);
4723 ReleaseDC(hWnd, hdc);
4730 if (wParam && !HIWORD(lParam))
4732 /* Do something to sub-windows */
4733 for (i = 1; i < MAX_TERM_DATA; i++)
4735 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4738 /* Focus on main window */
4747 case WM_ACTIVATEAPP:
4749 if (IsIconic(td->w)) break;
4751 for (i = 1; i < MAX_TERM_DATA; i++)
4757 ShowWindow(data[i].w, SW_SHOW);
4761 ShowWindow(data[i].w, SW_HIDE);
4768 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4773 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4774 WPARAM wParam, LPARAM lParam);
4775 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4776 WPARAM wParam, LPARAM lParam)
4777 #else /* __MWERKS__ */
4778 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4779 WPARAM wParam, LPARAM lParam)
4780 #endif /* __MWERKS__ */
4784 MINMAXINFO FAR *lpmmi;
4792 /* Acquire proper "term_data" info */
4793 td = (term_data *)GetWindowLong(hWnd, 0);
4795 /* Process message */
4801 SetWindowLong(hWnd, 0, (LONG)(my_td));
4811 case WM_GETMINMAXINFO:
4813 MINMAXINFO FAR *lpmmi;
4816 lpmmi = (MINMAXINFO FAR *)lParam;
4818 /* this message was sent before WM_NCCREATE */
4821 /* Minimum window size is 80x24 */
4822 rc.left = rc.top = 0;
4823 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4824 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4827 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4829 /* Save minimum size */
4830 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4831 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4841 /* this message was sent before WM_NCCREATE */
4844 /* it was sent from inside CreateWindowEx */
4845 if (!td->w) return 1;
4847 /* was sent from inside WM_SIZE */
4848 if (td->size_hack) return 1;
4850 td->size_hack = TRUE;
4852 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4853 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4856 if ((td->cols != cols) || (td->rows != rows))
4859 term *old_term = Term;
4861 /* Save the new size */
4866 Term_activate(&td->t);
4868 /* Resize the term */
4869 Term_resize(td->cols, td->rows);
4872 Term_activate(old_term);
4875 InvalidateRect(td->w, NULL, TRUE);
4877 /* HACK - Redraw all windows */
4878 p_ptr->window = 0xFFFFFFFF;
4882 td->size_hack = FALSE;
4889 BeginPaint(hWnd, &ps);
4890 if (td) term_data_redraw(td);
4891 EndPaint(hWnd, &ps);
4898 if (process_keydown(wParam, lParam))
4905 if (Term_no_press) Term_no_press = FALSE;
4906 else Term_keypress(wParam);
4910 case WM_PALETTECHANGED:
4912 /* ignore if palette change caused by itself */
4913 if ((HWND)wParam == hWnd) return FALSE;
4914 /* otherwise, fall through!!! */
4917 case WM_QUERYNEWPALETTE:
4919 if (!paletted) return 0;
4921 SelectPalette(hdc, hPal, FALSE);
4922 i = RealizePalette(hdc);
4923 /* if any palette entries changed, repaint the window. */
4924 if (i) InvalidateRect(hWnd, NULL, TRUE);
4925 ReleaseDC(hWnd, hdc);
4929 case WM_NCLBUTTONDOWN:
4933 if (wParam == HTCLOSE) wParam = HTSYSMENU;
4934 #endif /* HTCLOSE */
4936 if (wParam == HTSYSMENU)
4940 td->visible = FALSE;
4941 ShowWindow(td->w, SW_HIDE);
4951 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4957 #define MOUSE_SENS 40
4960 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4961 WPARAM wParam, LPARAM lParam);
4962 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4963 WPARAM wParam, LPARAM lParam)
4964 #else /* __MWERKS__ */
4965 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4966 WPARAM wParam, LPARAM lParam)
4967 #endif /* __MWERKS__ */
4969 static int iMouse = 0;
4970 static WORD xMouse = 0;
4971 static WORD yMouse = 0;
4994 if (LOWORD(wParam) == WA_INACTIVE) break;
4996 /* else fall through */
5000 case WM_LBUTTONDOWN:
5001 case WM_MBUTTONDOWN:
5002 case WM_RBUTTONDOWN:
5005 SendMessage(hWnd, WM_CLOSE, 0, 0);
5013 dx = LOWORD(lParam) - xMouse;
5014 dy = HIWORD(lParam) - yMouse;
5016 if (dx < 0) dx = -dx;
5017 if (dy < 0) dy = -dy;
5019 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5021 SendMessage(hWnd, WM_CLOSE, 0, 0);
5025 /* Save last location */
5027 xMouse = LOWORD(lParam);
5028 yMouse = HIWORD(lParam);
5035 DestroyWindow(hwndSaver);
5042 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5045 #endif /* USE_SAVER */
5051 /*** Temporary Hooks ***/
5055 * Display warning message (see "z-util.c")
5057 static void hack_plog(cptr str)
5059 /* Give a warning */
5063 MessageBox(NULL, str, "·Ù¹ð¡ª",
5064 MB_ICONEXCLAMATION | MB_OK);
5066 MessageBox(NULL, str, "Warning",
5067 MB_ICONEXCLAMATION | MB_OK);
5075 * Display error message and quit (see "z-util.c")
5077 static void hack_quit(cptr str)
5079 /* Give a warning */
5083 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
5084 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5086 MessageBox(NULL, str, "Error",
5087 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5092 /* Unregister the classes */
5093 UnregisterClass(AppName, hInstance);
5095 /* Destroy the icon */
5096 if (hIcon) DestroyIcon(hIcon);
5104 /*** Various hooks ***/
5108 * Display warning message (see "z-util.c")
5110 static void hook_plog(cptr str)
5116 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
5117 MB_ICONEXCLAMATION | MB_OK);
5119 MessageBox(data[0].w, str, "Warning",
5120 MB_ICONEXCLAMATION | MB_OK);
5128 * Display error message and quit (see "z-util.c")
5130 static void hook_quit(cptr str)
5135 /* Give a warning */
5139 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
5140 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5142 MessageBox(data[0].w, str, "Error",
5143 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5149 /* Save the preferences */
5153 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
5155 /* Destroy all windows */
5156 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5158 term_force_font(&data[i], NULL);
5159 if (data[i].font_want) string_free(data[i].font_want);
5160 if (data[i].w) DestroyWindow(data[i].w);
5164 /* Free the bitmap stuff */
5166 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5167 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5169 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5170 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5172 #endif /* USE_GRAPHICS */
5174 /*** Free some other stuff ***/
5176 DeleteObject(hbrYellow);
5181 if (hPal) DeleteObject(hPal);
5183 UnregisterClass(AppName, hInstance);
5185 if (hIcon) DestroyIcon(hIcon);
5192 /*** Initialize ***/
5198 static void init_stuff(void)
5205 /* Get program name with full path */
5206 GetModuleFileName(hInstance, path, 512);
5208 /* Save the "program name" XXX XXX XXX */
5211 /* Get the name of the "*.ini" file */
5212 strcpy(path + strlen(path) - 4, ".INI");
5214 /* Save the the name of the ini-file */
5215 ini_file = string_make(path);
5217 /* Analyze the path */
5223 if (path[i] == '\\')
5230 /* Add "lib" to the path */
5231 strcpy(path + i + 1, "lib\\");
5233 /* Validate the path */
5234 validate_dir(path, TRUE);
5236 /* Init the file paths */
5237 init_file_paths(path);
5239 /* Hack -- Validate the paths */
5240 validate_dir(ANGBAND_DIR_APEX, FALSE);
5241 validate_dir(ANGBAND_DIR_BONE, FALSE);
5243 /* Allow missing 'edit' directory */
5244 if (!check_dir(ANGBAND_DIR_EDIT))
5246 /* Must have 'data'! */
5247 validate_dir(ANGBAND_DIR_DATA, TRUE);
5251 /* Don't need 'data' */
5252 validate_dir(ANGBAND_DIR_DATA, FALSE);
5255 validate_dir(ANGBAND_DIR_FILE, TRUE);
5256 validate_dir(ANGBAND_DIR_HELP, FALSE);
5257 validate_dir(ANGBAND_DIR_INFO, FALSE);
5258 validate_dir(ANGBAND_DIR_PREF, TRUE);
5259 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5260 validate_dir(ANGBAND_DIR_USER, TRUE);
5261 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5263 /* Build the filename */
5265 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
5267 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
5271 /* Hack -- Validate the "news.txt" file */
5272 validate_file(path);
5275 #if 0 /* #ifndef JP */
5276 /* Build the "font" path */
5277 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5279 /* Allocate the path */
5280 ANGBAND_DIR_XTRA_FONT = string_make(path);
5282 /* Validate the "font" directory */
5283 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5285 /* Build the filename */
5286 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5288 /* Hack -- Validate the basic font */
5289 validate_file(path);
5295 /* Build the "graf" path */
5296 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5298 /* Allocate the path */
5299 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5301 /* Validate the "graf" directory */
5302 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5304 #endif /* USE_GRAPHICS */
5309 /* Build the "sound" path */
5310 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5312 /* Allocate the path */
5313 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5315 /* Validate the "sound" directory */
5316 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5318 #endif /* USE_SOUND */
5322 /* Build the "music" path */
5323 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5325 /* Allocate the path */
5326 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5328 /* Validate the "music" directory */
5329 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5331 #endif /* USE_MUSIC */
5333 /* Build the "help" path */
5334 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5336 /* Allocate the path */
5337 ANGBAND_DIR_XTRA_HELP = string_make(path);
5339 /* Validate the "help" directory */
5340 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5343 bool is_already_running()
5345 bool result = FALSE;
5348 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5349 if (GetLastError() == ERROR_ALREADY_EXISTS)
5357 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5358 LPSTR lpCmdLine, int nCmdShow)
5366 setlocale( LC_ALL, "ja_JP" );
5375 /* Prevent multiple run */
5376 if (is_already_running())
5379 _("ÊѶòÈÚÅܤϤ¹¤Ç¤Ëµ¯Æ°¤·¤Æ¤¤¤Þ¤¹¡£", "Hengband is already running."),
5380 _("¥¨¥é¡¼¡ª", "Error") ,
5381 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5386 if (hPrevInst == NULL)
5388 wc.style = CS_CLASSDC;
5389 wc.lpfnWndProc = AngbandWndProc;
5391 wc.cbWndExtra = 4; /* one long pointer to term_data */
5392 wc.hInstance = hInst;
5393 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5394 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5395 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5396 wc.lpszMenuName = AppName;
5397 wc.lpszClassName = AppName;
5399 if (!RegisterClass(&wc)) exit(1);
5401 wc.lpfnWndProc = AngbandListProc;
5402 wc.lpszMenuName = NULL;
5403 wc.lpszClassName = AngList;
5405 if (!RegisterClass(&wc)) exit(2);
5409 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5410 wc.lpfnWndProc = AngbandSaverProc;
5412 wc.lpszMenuName = NULL;
5413 wc.lpszClassName = "WindowsScreenSaverClass";
5415 if (!RegisterClass(&wc)) exit(3);
5421 /* Temporary hooks */
5422 plog_aux = hack_plog;
5423 quit_aux = hack_quit;
5424 core_aux = hack_quit;
5426 /* Prepare the filepaths */
5429 /* Initialize the keypress analyzer */
5430 for (i = 0; special_key_list[i]; ++i)
5432 special_key[special_key_list[i]] = TRUE;
5434 /* Initialize the keypress analyzer */
5435 for (i = 0; ignore_key_list[i]; ++i)
5437 ignore_key[ignore_key_list[i]] = TRUE;
5440 /* Determine if display is 16/256/true color */
5442 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5443 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5444 ReleaseDC(NULL, hdc);
5446 /* Initialize the colors */
5447 for (i = 0; i < 256; i++)
5451 /* Extract desired values */
5452 rv = angband_color_table[i][1];
5453 gv = angband_color_table[i][2];
5454 bv = angband_color_table[i][3];
5456 /* Extract the "complex" code */
5457 win_clr[i] = PALETTERGB(rv, gv, bv);
5459 /* Save the "simple" code */
5460 angband_color_table[i][0] = win_pal[i];
5463 /* Prepare the windows */
5469 /* Activate hooks */
5470 plog_aux = hook_plog;
5471 quit_aux = hook_quit;
5472 core_aux = hook_quit;
5474 /* Set the system suffix */
5475 ANGBAND_SYS = "win";
5477 /* Set the keyboard suffix */
5478 if (7 != GetKeyboardType(0))
5479 ANGBAND_KEYBOARD = "0";
5482 /* Japanese keyboard */
5483 switch (GetKeyboardType(1))
5485 case 0x0D01: case 0x0D02:
5486 case 0x0D03: case 0x0D04:
5487 case 0x0D05: case 0x0D06:
5489 ANGBAND_KEYBOARD = "NEC98";
5493 ANGBAND_KEYBOARD = "JAPAN";
5497 /* Catch nasty signals */
5503 /* We are now initialized */
5506 if(lpCmdLine[0] == '-'){
5507 switch(lpCmdLine[1])
5512 if (!lpCmdLine[2]) break;
5513 chuukei_server = TRUE;
5514 if(connect_chuukei_server(&lpCmdLine[2])<0){
5515 msg_print("connect fail");
5518 msg_print("connect");
5526 if (!lpCmdLine[2]) break;
5527 chuukei_client = TRUE;
5528 connect_chuukei_server(&lpCmdLine[2]);
5536 if (!lpCmdLine[2]) break;
5537 prepare_browse_movie(&lpCmdLine[2]);
5547 /* Did the user double click on a save file? */
5548 if(!chuukei_server) check_for_save_file(lpCmdLine);
5550 /* Did the user double click on a save file? */
5551 check_for_save_file(lpCmdLine);
5554 /* Prompt the user */
5556 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5558 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5563 /* Process messages forever */
5564 while (GetMessage(&msg, NULL, 0, 0))
5566 TranslateMessage(&msg);
5567 DispatchMessage(&msg);
5578 #endif /* WINDOWS */