4 * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies.
13 * This file helps Angband work with Windows computers.
15 * To use this file, use an appropriate "Makefile" or "Project File",
16 * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
17 * make sure to obtain various extra files as described below.
19 * The official compilation uses the CodeWarrior Pro compiler, which
20 * includes a special project file and precompilable header file.
23 * See also "main-dos.c" and "main-ibm.c".
26 * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
27 * and/or color redefinitions.
29 * The "lib/user/font-win.prf" contains attr/char mappings for use with the
30 * normal "lib/xtra/font/*.fon" font files.
32 * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
33 * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
37 * Compiling this file, and using the resulting executable, requires
38 * several extra files not distributed with the standard Angband code.
39 * If "USE_GRAPHICS" is defined, then "readdib.h" and "readdib.c" must
40 * be placed into "src/", and the "8X8.BMP" bitmap file must be placed
41 * into "lib/xtra/graf". In any case, some "*.fon" files (including
42 * "8X13.FON" if nothing else) must be placed into "lib/xtra/font/".
43 * If "USE_SOUND" is defined, then some special library (for example,
44 * "winmm.lib") may need to be linked in, and desired "*.WAV" sound
45 * files must be placed into "lib/xtra/sound/". All of these extra
46 * files can be found in the "ext-win" archive.
49 * The "Term_xtra_win_clear()" function should probably do a low-level
50 * clear of the current window, and redraw the borders and other things,
51 * if only for efficiency. XXX XXX XXX
53 * A simpler method is needed for selecting the "tile size" for windows.
56 * The various "warning" messages assume the existance of the "screen.w"
57 * window, I think, and only a few calls actually check for its existance,
58 * this may be okay since "NULL" means "on top of all windows". (?) The
59 * user must never be allowed to "hide" the main window, or the "menubar"
60 * will disappear. XXX XXX XXX
62 * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
63 * use with the "winhelp.exe" program. These files *may* be available
64 * at the ftp site somewhere, but I have not seen them. XXX XXX XXX
67 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
69 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
71 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
72 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
84 * Extract the "WIN32" flag from the compiler
86 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
94 * Hack -- allow use of "screen saver" mode
100 * Menu constants -- see "ANGBAND.RC"
103 #define IDM_FILE_NEW 100
104 #define IDM_FILE_OPEN 101
105 #define IDM_FILE_SAVE 110
106 #define IDM_FILE_SCORE 120
107 #define IDM_FILE_MOVIE 121
108 #define IDM_FILE_EXIT 130
110 #define IDM_WINDOW_VIS_0 200
111 #define IDM_WINDOW_VIS_1 201
112 #define IDM_WINDOW_VIS_2 202
113 #define IDM_WINDOW_VIS_3 203
114 #define IDM_WINDOW_VIS_4 204
115 #define IDM_WINDOW_VIS_5 205
116 #define IDM_WINDOW_VIS_6 206
117 #define IDM_WINDOW_VIS_7 207
119 #define IDM_WINDOW_FONT_0 210
120 #define IDM_WINDOW_FONT_1 211
121 #define IDM_WINDOW_FONT_2 212
122 #define IDM_WINDOW_FONT_3 213
123 #define IDM_WINDOW_FONT_4 214
124 #define IDM_WINDOW_FONT_5 215
125 #define IDM_WINDOW_FONT_6 216
126 #define IDM_WINDOW_FONT_7 217
128 #define IDM_WINDOW_POS_0 220
129 #define IDM_WINDOW_POS_1 221
130 #define IDM_WINDOW_POS_2 222
131 #define IDM_WINDOW_POS_3 223
132 #define IDM_WINDOW_POS_4 224
133 #define IDM_WINDOW_POS_5 225
134 #define IDM_WINDOW_POS_6 226
135 #define IDM_WINDOW_POS_7 227
137 #define IDM_WINDOW_BIZ_0 230
138 #define IDM_WINDOW_BIZ_1 231
139 #define IDM_WINDOW_BIZ_2 232
140 #define IDM_WINDOW_BIZ_3 233
141 #define IDM_WINDOW_BIZ_4 234
142 #define IDM_WINDOW_BIZ_5 235
143 #define IDM_WINDOW_BIZ_6 236
144 #define IDM_WINDOW_BIZ_7 237
146 #define IDM_WINDOW_I_WID_0 240
147 #define IDM_WINDOW_I_WID_1 241
148 #define IDM_WINDOW_I_WID_2 242
149 #define IDM_WINDOW_I_WID_3 243
150 #define IDM_WINDOW_I_WID_4 244
151 #define IDM_WINDOW_I_WID_5 245
152 #define IDM_WINDOW_I_WID_6 246
153 #define IDM_WINDOW_I_WID_7 247
155 #define IDM_WINDOW_D_WID_0 250
156 #define IDM_WINDOW_D_WID_1 251
157 #define IDM_WINDOW_D_WID_2 252
158 #define IDM_WINDOW_D_WID_3 253
159 #define IDM_WINDOW_D_WID_4 254
160 #define IDM_WINDOW_D_WID_5 255
161 #define IDM_WINDOW_D_WID_6 256
162 #define IDM_WINDOW_D_WID_7 257
164 #define IDM_WINDOW_I_HGT_0 260
165 #define IDM_WINDOW_I_HGT_1 261
166 #define IDM_WINDOW_I_HGT_2 262
167 #define IDM_WINDOW_I_HGT_3 263
168 #define IDM_WINDOW_I_HGT_4 264
169 #define IDM_WINDOW_I_HGT_5 265
170 #define IDM_WINDOW_I_HGT_6 266
171 #define IDM_WINDOW_I_HGT_7 267
173 #define IDM_WINDOW_D_HGT_0 270
174 #define IDM_WINDOW_D_HGT_1 271
175 #define IDM_WINDOW_D_HGT_2 272
176 #define IDM_WINDOW_D_HGT_3 273
177 #define IDM_WINDOW_D_HGT_4 274
178 #define IDM_WINDOW_D_HGT_5 275
179 #define IDM_WINDOW_D_HGT_6 276
180 #define IDM_WINDOW_D_HGT_7 277
182 #define IDM_OPTIONS_NO_GRAPHICS 400
183 #define IDM_OPTIONS_OLD_GRAPHICS 401
184 #define IDM_OPTIONS_NEW_GRAPHICS 402
185 #define IDM_OPTIONS_NEW2_GRAPHICS 403
186 #define IDM_OPTIONS_BIGTILE 409
187 #define IDM_OPTIONS_SOUND 410
188 #define IDM_OPTIONS_MUSIC 411
189 #define IDM_OPTIONS_SAVER 420
190 #define IDM_OPTIONS_MAP 430
191 #define IDM_OPTIONS_BG 440
192 #define IDM_OPTIONS_OPEN_BG 441
194 #define IDM_DUMP_SCREEN_HTML 450
196 #define IDM_HELP_CONTENTS 901
201 * This may need to be removed for some compilers XXX XXX XXX
208 * Exclude parts of WINDOWS.H that are not needed
210 #define NOCOMM /* Comm driver APIs and definitions */
211 #define NOLOGERROR /* LogError() and related definitions */
212 #define NOPROFILER /* Profiler APIs */
213 #define NOLFILEIO /* _l* file I/O routines */
214 #define NOOPENFILE /* OpenFile and related definitions */
215 #define NORESOURCE /* Resource management */
216 #define NOATOM /* Atom management */
217 #define NOLANGUAGE /* Character test routines */
218 #define NOLSTRING /* lstr* string management routines */
219 #define NODBCS /* Double-byte character set routines */
220 #define NOKEYBOARDINFO /* Keyboard driver routines */
221 #define NOCOLOR /* COLOR_* color values */
222 #define NODRAWTEXT /* DrawText() and related definitions */
223 #define NOSCALABLEFONT /* Truetype scalable font support */
224 #define NOMETAFILE /* Metafile support */
225 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
226 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
227 #define NOKEYSTATES /* MK_* message key state flags */
228 #define NOWH /* SetWindowsHook and related WH_* definitions */
229 #define NOCLIPBOARD /* Clipboard APIs and definitions */
230 #define NOICONS /* IDI_* icon IDs */
231 #define NOMDI /* MDI support */
232 #define NOHELP /* Help support */
234 /* Not defined since it breaks Borland C++ 5.5 */
235 /* #define NOCTLMGR */ /* Control management and controls */
238 * Exclude parts of WINDOWS.H that are not needed (Win32)
240 #define WIN32_LEAN_AND_MEAN
241 #define NONLS /* All NLS defines and routines */
242 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
243 #define NOKANJI /* Kanji support stuff. */
244 #define NOMCX /* Modem Configuration Extensions */
247 * Include the "windows" support file
252 * Exclude parts of MMSYSTEM.H that are not needed
254 #define MMNODRV /* Installable driver support */
255 #define MMNOWAVE /* Waveform support */
256 #define MMNOMIDI /* MIDI support */
257 #define MMNOAUX /* Auxiliary audio support */
258 #define MMNOTIMER /* Timer support */
259 #define MMNOJOY /* Joystick support */
260 #define MMNOMCI /* MCI support */
261 #define MMNOMMIO /* Multimedia file I/O support */
262 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
265 * Include some more files. Note: the Cygnus Cygwin compiler
266 * doesn't use mmsystem.h instead it includes the winmm library
267 * which performs a similar function.
269 #include <mmsystem.h>
273 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
274 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
276 /* #define HTML_HELP */
279 #include <htmlhelp.h>
280 #endif /* HTML_HELP */
283 * Include the support for loading bitmaps
286 # include "readdib.h"
290 * Hack -- Fake declarations from "dos.h" XXX XXX XXX
293 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
295 #define FA_LABEL 0x08 /* Volume label */
296 #define FA_DIREC 0x10 /* Directory */
297 unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
301 * Silliness in WIN32 drawing routine
304 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
308 * Silliness for Windows 95
310 #ifndef WS_EX_TOOLWINDOW
311 # define WS_EX_TOOLWINDOW 0
315 * Foreground color bits (hard-coded by DOS)
317 #define VID_BLACK 0x00
318 #define VID_BLUE 0x01
319 #define VID_GREEN 0x02
320 #define VID_CYAN 0x03
322 #define VID_MAGENTA 0x05
323 #define VID_YELLOW 0x06
324 #define VID_WHITE 0x07
327 * Bright text (hard-coded by DOS)
329 #define VID_BRIGHT 0x08
332 * Background color bits (hard-coded by DOS)
334 #define VUD_BLACK 0x00
335 #define VUD_BLUE 0x10
336 #define VUD_GREEN 0x20
337 #define VUD_CYAN 0x30
339 #define VUD_MAGENTA 0x50
340 #define VUD_YELLOW 0x60
341 #define VUD_WHITE 0x70
344 * Blinking text (hard-coded by DOS)
346 #define VUD_BRIGHT 0x80
352 typedef struct _term_data term_data;
357 * Note the use of "font_want" for the names of the font file requested by
358 * the user, and the use of "font_file" for the currently active font file.
360 * The "font_file" is uppercased, and takes the form "8X13.FON", while
361 * "font_want" can be in almost any form as long as it could be construed
362 * as attempting to represent the name of a font.
377 uint rows; /* int -> uint */
413 #if 1 /* #ifdef JP */
428 * Maximum number of windows XXX XXX XXX
430 #define MAX_TERM_DATA 8
433 * An array of term_data's
435 static term_data data[MAX_TERM_DATA];
438 * Hack -- global "window creation" pointer
440 static term_data *my_td;
443 * Remember normal size of main window when maxmized
448 * was main window maximized on previous playing
450 bool win_maximized = FALSE;
455 bool game_in_progress = FALSE;
458 * note when "open"/"new" become valid
460 bool initialized = FALSE;
463 * screen paletted, i.e. 256 colors
465 bool paletted = FALSE;
468 * 16 colors screen, don't use RGB()
470 bool colors16 = FALSE;
473 * Saved instance handle
475 static HINSTANCE hInstance;
478 * Yellow brush for the cursor
480 static HBRUSH hbrYellow;
490 static HPALETTE hPal;
493 static HBITMAP hBG = NULL;
494 static int use_bg = 0;
495 static char bg_bitmap_file[1024] = "bg.bmp";
500 * The screen saver window
502 static HWND hwndSaver;
504 #endif /* USE_SAVER */
510 * Flag set once "graphics" has been initialized
512 static bool can_use_graphics = FALSE;
517 static DIBINIT infGraph;
520 * The global bitmap mask
522 static DIBINIT infMask;
524 #endif /* USE_GRAPHICS */
530 * Flag set once "sound" has been initialized
532 static bool can_use_sound = FALSE;
537 * An array of sound file names
539 static cptr sound_file[SOUND_MAX][SAMPLE_MAX];
541 #endif /* USE_SOUND */
545 static bool can_use_music = FALSE;
547 #endif /* USE_MUSIC */
551 * Full path to ANGBAND.INI
553 static cptr ini_file = NULL;
556 * Name of application
558 static cptr AppName = "ANGBAND";
561 * Name of sub-window type
563 static cptr AngList = "AngList";
568 static cptr ANGBAND_DIR_XTRA_GRAF;
569 static cptr ANGBAND_DIR_XTRA_SOUND;
570 static cptr ANGBAND_DIR_XTRA_MUSIC;
571 static cptr ANGBAND_DIR_XTRA_HELP;
572 #if 0 /* #ifndef JP */
573 static cptr ANGBAND_DIR_XTRA_FONT;
576 static cptr ANGBAND_DIR_XTRA_MUSIC;
581 * The "complex" color values
583 static COLORREF win_clr[256];
587 * Flag for macro trigger with dump ASCII
589 static bool Term_no_press = FALSE;
594 static bool mouse_down = FALSE;
595 static bool paint_rect = FALSE;
596 static int mousex = 0, mousey = 0;
597 static int oldx, oldy;
601 * The "simple" color values
603 * See "main-ibm.c" for original table information
605 * The entries below are taken from the "color bits" defined above.
607 * Note that many of the choices below suck, but so do crappy monitors.
609 static BYTE win_pal[256] =
611 VID_BLACK, /* Dark */
612 VID_WHITE, /* White */
613 VID_CYAN, /* Slate XXX */
614 VID_RED | VID_BRIGHT, /* Orange XXX */
616 VID_GREEN, /* Green */
618 VID_YELLOW, /* Umber XXX */
619 VID_BLACK | VID_BRIGHT, /* Light Dark */
620 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
621 VID_MAGENTA, /* Violet XXX */
622 VID_YELLOW | VID_BRIGHT, /* Yellow */
623 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
624 VID_GREEN | VID_BRIGHT, /* Light Green */
625 VID_BLUE | VID_BRIGHT, /* Light Blue */
626 VID_YELLOW /* Light Umber XXX */
631 * Hack -- define which keys are "special"
633 static bool special_key[256];
634 static bool ignore_key[256];
638 * Hack -- initialization list for "special_key"
640 static byte special_key_list[] = {
641 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
642 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
643 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
644 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
645 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
646 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
647 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
648 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
649 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
650 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
651 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
652 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
653 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
654 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
655 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
656 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
657 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
662 static byte ignore_key_list[] = {
663 VK_ESCAPE, VK_TAB, VK_SPACE,
664 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
665 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
666 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
672 * Hack -- initialization list for "special_key"
674 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
675 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
676 * catch the keypad keys (with and without numlock set, including keypad 5),
677 * the function keys (including the "menu" key which maps to F10), and the
678 * "pause" key (between scroll lock and numlock). We also catch a few odd
679 * keys which I do not recognize, but which are listed among keys which we
680 * do catch, so they should be harmless to catch.
682 static byte special_key_list[] =
684 VK_CLEAR, /* 0x0C (KP<5>) */
686 VK_PAUSE, /* 0x13 (pause) */
688 VK_PRIOR, /* 0x21 (KP<9>) */
689 VK_NEXT, /* 0x22 (KP<3>) */
690 VK_END, /* 0x23 (KP<1>) */
691 VK_HOME, /* 0x24 (KP<7>) */
692 VK_LEFT, /* 0x25 (KP<4>) */
693 VK_UP, /* 0x26 (KP<8>) */
694 VK_RIGHT, /* 0x27 (KP<6>) */
695 VK_DOWN, /* 0x28 (KP<2>) */
696 VK_SELECT, /* 0x29 (?????) */
697 VK_PRINT, /* 0x2A (?????) */
698 VK_EXECUTE, /* 0x2B (?????) */
699 VK_SNAPSHOT, /* 0x2C (?????) */
700 VK_INSERT, /* 0x2D (KP<0>) */
701 VK_DELETE, /* 0x2E (KP<.>) */
702 VK_HELP, /* 0x2F (?????) */
704 VK_NUMPAD0, /* 0x60 (KP<0>) */
705 VK_NUMPAD1, /* 0x61 (KP<1>) */
706 VK_NUMPAD2, /* 0x62 (KP<2>) */
707 VK_NUMPAD3, /* 0x63 (KP<3>) */
708 VK_NUMPAD4, /* 0x64 (KP<4>) */
709 VK_NUMPAD5, /* 0x65 (KP<5>) */
710 VK_NUMPAD6, /* 0x66 (KP<6>) */
711 VK_NUMPAD7, /* 0x67 (KP<7>) */
712 VK_NUMPAD8, /* 0x68 (KP<8>) */
713 VK_NUMPAD9, /* 0x69 (KP<9>) */
714 VK_MULTIPLY, /* 0x6A (KP<*>) */
715 VK_ADD, /* 0x6B (KP<+>) */
716 VK_SEPARATOR, /* 0x6C (?????) */
717 VK_SUBTRACT, /* 0x6D (KP<->) */
718 VK_DECIMAL, /* 0x6E (KP<.>) */
719 VK_DIVIDE, /* 0x6F (KP</>) */
750 static void delete_bg(void)
759 static int init_bg(void)
761 char * bmfile = bg_bitmap_file;
764 if (use_bg == 0) return 0;
766 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
769 plog_fmt("ÊÉ»æÍÑ¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
771 plog_fmt("Can't load the bitmap file '%s'.", bmfile);
777 HDC wnddc, dcimage, dcbg;
778 HBITMAP bmimage, bmimage_old, bmbg_old;
784 dcimage = CreateCompatibleDC(wnddc);
785 dcbg = CreateCompatibleDC(wnddc);
787 bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
788 if (!bmimage) quit("bg.bmp¤¬Æɤߤ³¤á¤Ê¤¤¡ª");
789 bmimage_old = SelectObject(dcimage, bmimage);
791 CreateCompatibleBitmap();
793 ReleaseDC(hwnd, wnddc);
799 static void DrawBG(HDC hdc, RECT *r)
804 int x = r->left, y = r->top;
805 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
811 GetObject(hBG, sizeof(bm), &bm);
812 swid = bm.bmWidth; shgt = bm.bmHeight;
814 hdcSrc = CreateCompatibleDC(hdc);
815 hOld = SelectObject(hdcSrc, hBG);
819 cwid = MIN(swid - sx, r->right - nx);
822 chgt = MIN(shgt - sy, r->bottom - ny);
823 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
825 } while (ny < r->bottom);
828 } while (nx < r->right);
830 SelectObject(hdcSrc, hOld);
836 * Hack -- given a pathname, point at the filename
838 static cptr extract_file_name(cptr s)
842 /* Start at the end */
843 p = s + strlen(s) - 1;
845 /* Back up to divider */
846 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
848 /* Return file name */
855 * Hack -- given a simple filename, extract the "font size" info
857 * Return a pointer to a static buffer holding the capitalized base name.
859 #if 0 /* #ifndef JP */
860 static char *analyze_font(char *path, int *wp, int *hp)
866 /* Start at the end */
867 p = path + strlen(path) - 1;
869 /* Back up to divider */
870 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
872 /* Advance to file name */
878 /* Capitalize (be paranoid) */
879 if (islower(*s)) *s = toupper(*s);
883 s = my_strchr(p, 'X');
885 /* Extract font width */
889 hgt = s ? atoi(s+1) : 0;
902 * Check for existance of a file
904 static bool check_file(cptr s)
924 attrib = GetFileAttributes(path);
926 /* Require valid filename */
927 if (attrib == INVALID_FILE_NAME) return (FALSE);
929 /* Prohibit directory */
930 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
934 /* Examine and verify */
935 if (_dos_getfileattr(path, &attrib)) return (FALSE);
937 /* Prohibit something */
938 if (attrib & FA_LABEL) return (FALSE);
940 /* Prohibit directory */
941 if (attrib & FA_DIREC) return (FALSE);
951 * Check for existance of a directory
953 static bool check_dir(cptr s)
975 /* Remove trailing backslash */
976 if (i && (path[i-1] == '\\')) path[--i] = '\0';
981 attrib = GetFileAttributes(path);
983 /* Require valid filename */
984 if (attrib == INVALID_FILE_NAME) return (FALSE);
986 /* Require directory */
987 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
991 /* Examine and verify */
992 if (_dos_getfileattr(path, &attrib)) return (FALSE);
994 /* Prohibit something */
995 if (attrib & FA_LABEL) return (FALSE);
997 /* Require directory */
998 if (!(attrib & FA_DIREC)) return (FALSE);
1010 static void validate_file(cptr s)
1012 /* Verify or fail */
1016 quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
1018 quit_fmt("Cannot find required file:\n%s", s);
1026 * Validate a directory
1028 static void validate_dir(cptr s, bool vital)
1030 /* Verify or fail */
1033 /* This directory contains needed data */
1037 quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
1039 quit_fmt("Cannot find required directory:\n%s", s);
1043 /* Attempt to create this directory */
1046 quit_fmt("Unable to create directory:\n%s", s);
1053 * Get the "size" for a window
1055 static void term_getsize(term_data *td)
1062 if (td->cols < 1) td->cols = 1;
1063 if (td->rows < 1) td->rows = 1;
1066 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1067 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1069 /* Fake window size */
1071 rc.right = rc.left + wid;
1073 rc.bottom = rc.top + hgt;
1076 /* rc.right += 1; */
1077 /* rc.bottom += 1; */
1080 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1083 td->size_wid = rc.right - rc.left;
1084 td->size_hgt = rc.bottom - rc.top;
1086 /* See CreateWindowEx */
1089 /* Extract actual location */
1090 GetWindowRect(td->w, &rc);
1092 /* Save the location */
1093 td->pos_x = rc.left;
1099 * Write the "prefs" for a single term
1101 static void save_prefs_aux(int i)
1103 term_data *td = &data[i];
1108 WINDOWPLACEMENT lpwndpl;
1113 /* Make section name */
1114 sprintf(sec_name, "Term-%d", i);
1119 strcpy(buf, td->visible ? "1" : "0");
1120 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1125 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1128 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1130 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1134 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1136 #if 1 /* #ifdef JP */
1137 wsprintf(buf, "%d", td->lf.lfWidth);
1138 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1139 wsprintf(buf, "%d", td->lf.lfHeight);
1140 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1141 wsprintf(buf, "%d", td->lf.lfWeight);
1142 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1145 strcpy(buf, td->bizarre ? "1" : "0");
1146 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1149 wsprintf(buf, "%d", td->tile_wid);
1150 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1153 wsprintf(buf, "%d", td->tile_hgt);
1154 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1156 /* Get window placement and dimensions */
1157 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1158 GetWindowPlacement(td->w, &lpwndpl);
1160 /* Acquire position in *normal* mode (not minimized) */
1161 rc = lpwndpl.rcNormalPosition;
1163 /* Window size (x) */
1164 if (i == 0) wsprintf(buf, "%d", normsize.x);
1165 else wsprintf(buf, "%d", td->cols);
1166 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1168 /* Window size (y) */
1169 if (i == 0) wsprintf(buf, "%d", normsize.y);
1170 else wsprintf(buf, "%d", td->rows);
1171 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1173 /* Maxmized (only main window) */
1176 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1177 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1180 /* Acquire position */
1181 GetWindowRect(td->w, &rc);
1183 /* Window position (x) */
1184 wsprintf(buf, "%d", rc.left);
1185 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1187 /* Window position (y) */
1188 wsprintf(buf, "%d", rc.top);
1189 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1191 /* Window Z position */
1194 strcpy(buf, td->posfix ? "1" : "0");
1195 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1203 * We assume that the windows have all been initialized
1205 static void save_prefs(void)
1211 /* Save the "arg_graphics" flag */
1212 sprintf(buf, "%d", arg_graphics);
1213 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1215 /* Save the "arg_bigtile" flag */
1216 strcpy(buf, arg_bigtile ? "1" : "0");
1217 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1219 /* Save the "arg_sound" flag */
1220 strcpy(buf, arg_sound ? "1" : "0");
1221 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1223 /* Save the "arg_sound" flag */
1224 strcpy(buf, arg_music ? "1" : "0");
1225 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1228 strcpy(buf, use_bg ? "1" : "0");
1229 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1230 WritePrivateProfileString("Angband", "BackGroundBitmap",
1231 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1233 /* Save window prefs */
1234 for (i = 0; i < MAX_TERM_DATA; ++i)
1242 * Load the "prefs" for a single term
1244 static void load_prefs_aux(int i)
1246 term_data *td = &data[i];
1250 int wid, hgt, posx, posy;
1251 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1252 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1256 /* Make section name */
1257 sprintf(sec_name, "Term-%d", i);
1259 /* Make section name */
1260 sprintf(sec_name, "Term-%d", i);
1265 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1268 /* Desired font, with default */
1270 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1273 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1275 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1281 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1283 /* Analyze font, save desired font name */
1284 #if 1 /* #ifdef JP */
1285 td->font_want = string_make(tmp);
1287 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1288 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1289 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1291 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1296 #if 1 /* #ifdef JP */
1297 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1298 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1300 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1301 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1306 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1307 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1308 normsize.x = td->cols; normsize.y = td->rows;
1313 win_maximized = GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file);
1316 /* Window position */
1317 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1318 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1319 td->pos_x = MIN(MAX(0, posx), dispx-128);
1320 td->pos_y = MIN(MAX(0, posy), dispy-128);
1322 /* Window Z position */
1325 td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1333 static void load_prefs(void)
1337 /* Extract the "arg_graphics" flag */
1338 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1340 /* Extract the "arg_bigtile" flag */
1341 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1342 use_bigtile = arg_bigtile;
1344 /* Extract the "arg_sound" flag */
1345 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1347 /* Extract the "arg_sound" flag */
1348 arg_sound = (GetPrivateProfileInt("Music", "Music", 0, ini_file) != 0);
1351 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1352 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1354 /* Load window prefs */
1355 for (i = 0; i < MAX_TERM_DATA; ++i)
1361 #if defined(USE_SOUND) || defined(USE_MUSIC)
1364 * XXX XXX XXX - Taken from files.c.
1366 * Extract "tokens" from a buffer
1368 * This function uses "whitespace" as delimiters, and treats any amount of
1369 * whitespace as a single delimiter. We will never return any empty tokens.
1370 * When given an empty buffer, or a buffer containing only "whitespace", we
1371 * will return no tokens. We will never extract more than "num" tokens.
1373 * By running a token through the "text_to_ascii()" function, you can allow
1374 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1376 * We save pointers to the tokens in "tokens", and return the number found.
1378 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1390 /* Skip leading whitespace */
1391 for ( ; *s && iswspace(*s); ++s) /* loop */;
1396 /* Find next whitespace, if any */
1397 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1399 /* Nuke and advance (if necessary) */
1400 if (*t) *t++ = '\0';
1402 /* Save the token */
1413 #endif /* USE_SOUND || USE_MUSIC */
1417 static void load_sound_prefs(void)
1421 char ini_path[1024];
1422 char wav_path[1024];
1423 char *zz[SAMPLE_MAX];
1425 /* Access the sound.cfg */
1427 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1429 for (i = 0; i < SOUND_MAX; i++)
1431 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1433 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1435 for (j = 0; j < num; j++)
1437 /* Access the sound */
1438 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1440 /* Save the sound filename, if it exists */
1441 if (check_file(wav_path))
1442 sound_file[i][j] = string_make(zz[j]);
1447 #endif /* USE_SOUND */
1451 static void load_music_prefs(void)
1455 char ini_path[1024];
1456 char wav_path[1024];
1457 char *zz[SAMPLE_MAX];
1459 /* Access the music.cfg */
1461 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1463 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1465 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1467 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1469 for (j = 0; j < num; j++)
1471 /* Access the sound */
1472 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1474 /* Save the sound filename, if it exists */
1475 if (check_file(wav_path))
1476 sound_file[i][j] = string_make(zz[j]);
1481 #endif /* USE_MUSIC */
1484 * Create the new global palette based on the bitmap palette
1485 * (if any), and the standard 16 entry palette derived from
1486 * "win_clr[]" which is used for the basic 16 Angband colors.
1488 * This function is never called before all windows are ready.
1490 * This function returns FALSE if the new palette could not be
1491 * prepared, which should normally be a fatal error. XXX XXX
1493 * Note that only some machines actually use a "palette".
1495 static int new_palette(void)
1503 LPLOGPALETTE pLogPal;
1504 LPPALETTEENTRY lppe;
1509 /* This makes no sense */
1510 if (!paletted) return (TRUE);
1520 /* Check the bitmap palette */
1521 hBmPal = infGraph.hPalette;
1523 /* Use the bitmap */
1526 lppeSize = 256 * sizeof(PALETTEENTRY);
1527 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1528 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1529 if ((nEntries == 0) || (nEntries > 220))
1533 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1535 plog("Please switch to high- or true-color mode.");
1540 rnfree(lppe, lppeSize);
1547 #endif /* USE_GRAPHICS */
1549 /* Size of palette */
1550 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1552 /* Allocate palette */
1553 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1556 pLogPal->palVersion = 0x300;
1558 /* Make room for bitmap and normal data */
1559 pLogPal->palNumEntries = nEntries + 16;
1561 /* Save the bitmap data */
1562 for (i = 0; i < nEntries; i++)
1564 pLogPal->palPalEntry[i] = lppe[i];
1567 /* Save the normal data */
1568 for (i = 0; i < 16; i++)
1572 /* Access the entry */
1573 p = &(pLogPal->palPalEntry[i+nEntries]);
1575 /* Save the colors */
1576 p->peRed = GetRValue(win_clr[i]);
1577 p->peGreen = GetGValue(win_clr[i]);
1578 p->peBlue = GetBValue(win_clr[i]);
1580 /* Save the flags */
1581 p->peFlags = PC_NOCOLLAPSE;
1584 /* Free something */
1585 if (lppe) rnfree(lppe, lppeSize);
1587 /* Create a new palette, or fail */
1588 hNewPal = CreatePalette(pLogPal);
1590 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1592 if (!hNewPal) quit("Cannot create palette!");
1596 /* Free the palette */
1597 rnfree(pLogPal, pLogPalSize);
1602 /* Realize the palette */
1604 SelectPalette(hdc, hNewPal, 0);
1605 i = RealizePalette(hdc);
1606 ReleaseDC(td->w, hdc);
1608 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1610 if (i == 0) quit("Cannot realize palette!");
1615 for (i = 1; i < MAX_TERM_DATA; i++)
1620 SelectPalette(hdc, hNewPal, 0);
1621 ReleaseDC(td->w, hdc);
1624 /* Delete old palette */
1625 if (hPal) DeleteObject(hPal);
1627 /* Save new palette */
1637 * Initialize graphics
1639 static bool init_graphics(void)
1641 /* Initialize once */
1642 /* if (can_use_graphics != arg_graphics) */
1648 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1655 ANGBAND_GRAF = "new";
1657 else if (arg_graphics == GRAPHICS_HENGBAND)
1664 ANGBAND_GRAF = "ne2";
1672 ANGBAND_GRAF = "old";
1675 /* Access the bitmap file */
1676 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1678 /* Load the bitmap or quit */
1679 if (!ReadDIB(data[0].w, buf, &infGraph))
1682 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1684 plog_fmt("Cannot read bitmap file '%s'", name);
1690 /* Save the new sizes */
1691 infGraph.CellWidth = wid;
1692 infGraph.CellHeight = hgt;
1694 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1696 /* Access the mask file */
1697 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1699 /* Load the bitmap or quit */
1700 if (!ReadDIB(data[0].w, buf, &infMask))
1702 plog_fmt("Cannot read bitmap file '%s'", buf);
1706 if (arg_graphics == GRAPHICS_HENGBAND)
1708 /* Access the mask file */
1709 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1711 /* Load the bitmap or quit */
1712 if (!ReadDIB(data[0].w, buf, &infMask))
1714 plog_fmt("Cannot read bitmap file '%s'", buf);
1719 /* Activate a palette */
1722 /* Free bitmap XXX XXX XXX */
1726 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1728 plog("Cannot activate palette!");
1734 /* Graphics available */
1735 can_use_graphics = arg_graphics;
1739 return (can_use_graphics);
1741 #endif /* USE_GRAPHICS */
1748 static bool init_music(void)
1750 /* Initialize once */
1753 /* Load the prefs */
1756 /* Sound available */
1757 can_use_music = TRUE;
1761 return (can_use_music);
1763 #endif /* USE_SOUND */
1769 static bool init_sound(void)
1771 /* Initialize once */
1774 /* Load the prefs */
1777 /* Sound available */
1778 can_use_sound = TRUE;
1782 return (can_use_sound);
1784 #endif /* USE_SOUND */
1790 static void term_window_resize(term_data *td)
1792 /* Require window */
1795 /* Resize the window */
1796 SetWindowPos(td->w, 0, 0, 0,
1797 td->size_wid, td->size_hgt,
1798 SWP_NOMOVE | SWP_NOZORDER);
1801 InvalidateRect(td->w, NULL, TRUE);
1806 * Force the use of a new "font file" for a term_data
1808 * This function may be called before the "window" is ready
1810 * This function returns zero only if everything succeeds.
1812 * Note that the "font name" must be capitalized!!!
1814 static errr term_force_font(term_data *td, cptr path)
1818 #if 0 /* #ifndef JP */
1824 /* Forget the old font (if needed) */
1825 if (td->font_id) DeleteObject(td->font_id);
1827 #if 1 /* #ifdef JP */
1831 /* Create the font (using the 'base' of the font file name!) */
1832 td->font_id = CreateFontIndirect(&(td->lf));
1833 wid = td->lf.lfWidth;
1834 hgt = td->lf.lfHeight;
1835 if (!td->font_id) return (1);
1837 /* Forget old font */
1843 for (i = 0; i < MAX_TERM_DATA; i++)
1845 /* Don't check when closing the application */
1848 /* Check "screen" */
1849 if ((td != &data[i]) &&
1850 (data[i].font_file) &&
1851 (streq(data[i].font_file, td->font_file)))
1857 /* Remove unused font resources */
1858 if (!used) RemoveFontResource(td->font_file);
1860 /* Free the old name */
1861 string_free(td->font_file);
1864 td->font_file = NULL;
1868 if (!path) return (1);
1873 /* Analyze font path */
1874 base = analyze_font(buf, &wid, &hgt);
1877 if (!suffix(base, ".FON")) return (1);
1880 if (!check_file(buf)) return (1);
1882 /* Load the new font */
1883 if (!AddFontResource(buf)) return (1);
1885 /* Save new font name */
1886 td->font_file = string_make(base);
1888 /* Remove the "suffix" */
1889 base[strlen(base)-4] = '\0';
1891 /* Create the font (using the 'base' of the font file name!) */
1892 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1893 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1894 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1895 FIXED_PITCH | FF_DONTCARE, base);
1898 /* Hack -- Unknown size */
1905 /* all this trouble to get the cell size */
1906 hdcDesktop = GetDC(HWND_DESKTOP);
1907 hfOld = SelectObject(hdcDesktop, td->font_id);
1908 GetTextMetrics(hdcDesktop, &tm);
1909 SelectObject(hdcDesktop, hfOld);
1910 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1912 /* Font size info */
1913 wid = tm.tmAveCharWidth;
1917 /* Save the size info */
1928 * Allow the user to change the font for this window.
1930 static void term_change_font(term_data *td)
1932 #if 1 /* #ifdef JP */
1935 memset(&cf, 0, sizeof(cf));
1936 cf.lStructSize = sizeof(cf);
1937 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1938 cf.lpLogFont = &(td->lf);
1940 if (ChooseFont(&cf))
1942 /* Force the font */
1943 term_force_font(td, NULL);
1945 /* Assume not bizarre */
1948 /* Reset the tile info */
1949 td->tile_wid = td->font_wid;
1950 td->tile_hgt = td->font_hgt;
1952 /* Analyze the font */
1955 /* Resize the window */
1956 term_window_resize(td);
1962 char tmp[1024] = "";
1964 /* Extract a default if possible */
1965 if (td->font_file) strcpy(tmp, td->font_file);
1967 /* Ask for a choice */
1968 memset(&ofn, 0, sizeof(ofn));
1969 ofn.lStructSize = sizeof(ofn);
1970 ofn.hwndOwner = data[0].w;
1971 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1972 ofn.nFilterIndex = 1;
1973 ofn.lpstrFile = tmp;
1975 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1976 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1977 ofn.lpstrDefExt = "fon";
1979 /* Force choice if legal */
1980 if (GetOpenFileName(&ofn))
1982 /* Force the font */
1983 if (term_force_font(td, tmp))
1985 /* Access the standard font file */
1986 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1988 /* Force the use of that font */
1989 (void)term_force_font(td, tmp);
1992 /* Assume not bizarre */
1993 td->bizarre = FALSE;
1995 /* Reset the tile info */
1996 td->tile_wid = td->font_wid;
1997 td->tile_hgt = td->font_hgt;
1999 /* Analyze the font */
2002 /* Resize the window */
2003 term_window_resize(td);
2010 * Allow the user to lock this window.
2012 static void term_window_pos(term_data *td, HWND hWnd)
2014 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2015 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2018 static void windows_map(void);
2021 * Hack -- redraw a term_data
2023 static void term_data_redraw(term_data *td)
2027 /* Redraw the map */
2032 /* Activate the term */
2033 Term_activate(&td->t);
2035 /* Redraw the contents */
2038 /* Restore the term */
2039 Term_activate(term_screen);
2044 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2048 HBRUSH myBrush, oldBrush;
2050 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2051 int tx = td->size_ow1 + x * td->tile_wid;
2052 int ty = td->size_oh1 + y * td->tile_hgt;
2053 int tw = w * td->tile_wid - 1;
2054 int th = h * td->tile_hgt - 1;
2057 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2058 oldBrush = SelectObject(hdc, myBrush);
2059 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2061 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2063 SelectObject(hdc, oldBrush);
2064 SelectObject(hdc, oldPen);
2069 /*** Function hooks needed by "Term" ***/
2075 * Initialize a new Term
2077 static void Term_init_win(term *t)
2086 static void Term_nuke_win(term *t)
2095 * Interact with the User
2097 static errr Term_user_win(int n)
2108 * React to global changes
2110 static errr Term_xtra_win_react(void)
2118 /* Save the default colors */
2119 for (i = 0; i < 256; i++)
2121 /* Simply accept the desired colors */
2122 win_pal[i] = angband_color_table[i][0];
2133 bool change = FALSE;
2135 /* Save the default colors */
2136 for (i = 0; i < 256; i++)
2138 /* Extract desired values */
2139 rv = angband_color_table[i][1];
2140 gv = angband_color_table[i][2];
2141 bv = angband_color_table[i][3];
2143 /* Extract a full color code */
2144 code = PALETTERGB(rv, gv, bv);
2146 /* Activate changes */
2147 if (win_clr[i] != code)
2149 /* Note the change */
2152 /* Apply the desired color */
2157 /* Activate the palette if needed */
2158 if (change) (void)new_palette();
2164 /* Handle "arg_sound" */
2165 if (use_sound != arg_sound)
2167 /* Initialize (if needed) */
2168 if (arg_sound && !init_sound())
2172 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
2174 plog("Cannot initialize sound!");
2182 /* Change setting */
2183 use_sound = arg_sound;
2190 /* Handle "arg_sound" */
2191 if (use_music != arg_music)
2193 /* Initialize (if needed) */
2194 if (arg_music && !init_music())
2198 plog("BGM¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
2200 plog("Cannot initialize BGM!");
2206 /* Change setting */
2207 use_music = arg_music;
2215 /* Handle "arg_graphics" */
2216 if (use_graphics != arg_graphics)
2218 /* Initialize (if needed) */
2219 if (arg_graphics && !init_graphics())
2223 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
2225 plog("Cannot initialize graphics!");
2230 arg_graphics = GRAPHICS_NONE;
2233 /* Change setting */
2234 use_graphics = arg_graphics;
2237 #ifdef ANGBAND_2_8_1
2239 #else /* ANGBAND_2_8_1 */
2240 reset_visuals(TRUE);
2241 #endif /* ANGBAND_2_8_1 */
2244 #endif /* USE_GRAPHICS */
2247 /* Clean up windows */
2248 for (i = 0; i < MAX_TERM_DATA; i++)
2252 term_data *td = &data[i];
2254 /* Update resized windows */
2255 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2258 Term_activate(&td->t);
2260 /* Hack -- Resize the term */
2261 Term_resize(td->cols, td->rows);
2263 /* Redraw the contents */
2278 * Process at least one event
2280 static errr Term_xtra_win_event(int v)
2284 /* Wait for an event */
2288 if (GetMessage(&msg, NULL, 0, 0))
2290 TranslateMessage(&msg);
2291 DispatchMessage(&msg);
2295 /* Check for an event */
2299 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2301 TranslateMessage(&msg);
2302 DispatchMessage(&msg);
2312 * Process all pending events
2314 static errr Term_xtra_win_flush(void)
2318 /* Process all pending events */
2319 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2321 TranslateMessage(&msg);
2322 DispatchMessage(&msg);
2331 * Hack -- clear the screen
2333 * Make this more efficient XXX XXX XXX
2335 static errr Term_xtra_win_clear(void)
2337 term_data *td = (term_data*)(Term->data);
2342 /* Rectangle to erase */
2343 rc.left = td->size_ow1;
2344 rc.right = rc.left + td->cols * td->tile_wid;
2345 rc.top = td->size_oh1;
2346 rc.bottom = rc.top + td->rows * td->tile_hgt;
2350 SetBkColor(hdc, RGB(0, 0, 0));
2351 SelectObject(hdc, td->font_id);
2352 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2357 rc.left = 0; rc.top = 0;
2360 ReleaseDC(td->w, hdc);
2368 * Hack -- make a noise
2370 static errr Term_xtra_win_noise(void)
2372 MessageBeep(MB_ICONASTERISK);
2378 * Hack -- make a sound
2380 static errr Term_xtra_win_sound(int v)
2385 #endif /* USE_SOUND */
2387 /* Sound disabled */
2388 if (!use_sound) return (1);
2391 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2395 /* Count the samples */
2396 for (i = 0; i < SAMPLE_MAX; i++)
2398 if (!sound_file[v][i])
2403 if (i == 0) return (1);
2405 /* Build the path */
2406 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2410 /* Play the sound, catch errors */
2411 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2415 /* Play the sound, catch errors */
2416 return (sndPlaySound(buf, SND_ASYNC));
2420 #else /* USE_SOUND */
2425 #endif /* USE_SOUND */
2429 * Hack -- play a music
2431 static errr Term_xtra_win_music(int v)
2436 #endif /* USE_MUSIC */
2438 /* Sound disabled */
2439 if (!use_music) return (1);
2442 if ((v < 0) || (v >= MUSIC_BASIC_MAX)) return (1);
2446 /* Count the samples */
2447 for (i = 0; i < SAMPLE_MAX; i++)
2449 if (!sound_file[v][i])
2454 if (i == 0) return (1);
2456 /* Build the path */
2457 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2461 /* Play the sound, catch errors */
2462 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2466 /* Play the sound, catch errors */
2467 return (sndPlaySound(buf, SND_ASYNC));
2471 #else /* USE_MUSIC */
2476 #endif /* USE_MUSIC */
2481 * Delay for "x" milliseconds
2483 static int Term_xtra_win_delay(int v)
2497 t = GetTickCount() + v;
2500 while (GetTickCount() < t)
2502 /* Handle messages */
2503 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2505 TranslateMessage(&msg);
2506 DispatchMessage(&msg);
2518 * Do a "special thing"
2520 static errr Term_xtra_win(int n, int v)
2522 /* Handle a subset of the legal requests */
2525 /* Make a bell sound */
2526 case TERM_XTRA_NOISE:
2528 return (Term_xtra_win_noise());
2532 case TERM_XTRA_MUSIC:
2534 return (Term_xtra_win_music(v));
2537 /* Make a special sound */
2538 case TERM_XTRA_SOUND:
2540 return (Term_xtra_win_sound(v));
2543 /* Process random events */
2544 case TERM_XTRA_BORED:
2546 return (Term_xtra_win_event(0));
2549 /* Process an event */
2550 case TERM_XTRA_EVENT:
2552 return (Term_xtra_win_event(v));
2555 /* Flush all events */
2556 case TERM_XTRA_FLUSH:
2558 return (Term_xtra_win_flush());
2561 /* Clear the screen */
2562 case TERM_XTRA_CLEAR:
2564 return (Term_xtra_win_clear());
2567 /* React to global changes */
2568 case TERM_XTRA_REACT:
2570 return (Term_xtra_win_react());
2573 /* Delay for some milliseconds */
2574 case TERM_XTRA_DELAY:
2576 return (Term_xtra_win_delay(v));
2587 * Low level graphics (Assumes valid input).
2589 * Draw a "cursor" at (x,y), using a "yellow box".
2591 static errr Term_curs_win(int x, int y)
2593 term_data *td = (term_data*)(Term->data);
2598 int tile_wid, tile_hgt;
2602 tile_wid = td->map_tile_wid;
2603 tile_hgt = td->map_tile_hgt;
2607 tile_wid = td->tile_wid;
2608 tile_hgt = td->tile_hgt;
2611 /* Frame the grid */
2612 rc.left = x * tile_wid + td->size_ow1;
2613 rc.right = rc.left + tile_wid;
2614 rc.top = y * tile_hgt + td->size_oh1;
2615 rc.bottom = rc.top + tile_hgt;
2617 /* Cursor is done as a yellow "box" */
2619 FrameRect(hdc, &rc, hbrYellow);
2620 ReleaseDC(td->w, hdc);
2628 * Low level graphics (Assumes valid input).
2630 * Draw a "big cursor" at (x,y), using a "yellow box".
2632 static errr Term_bigcurs_win(int x, int y)
2634 term_data *td = (term_data*)(Term->data);
2639 int tile_wid, tile_hgt;
2643 /* Normal cursor in map window */
2644 Term_curs_win(x, y);
2649 tile_wid = td->tile_wid;
2650 tile_hgt = td->tile_hgt;
2653 /* Frame the grid */
2654 rc.left = x * tile_wid + td->size_ow1;
2655 rc.right = rc.left + 2 * tile_wid;
2656 rc.top = y * tile_hgt + td->size_oh1;
2657 rc.bottom = rc.top + tile_hgt;
2659 /* Cursor is done as a yellow "box" */
2661 FrameRect(hdc, &rc, hbrYellow);
2662 ReleaseDC(td->w, hdc);
2670 * Low level graphics (Assumes valid input).
2672 * Erase a "block" of "n" characters starting at (x,y).
2674 static errr Term_wipe_win(int x, int y, int n)
2676 term_data *td = (term_data*)(Term->data);
2681 /* Rectangle to erase in client coords */
2682 rc.left = x * td->tile_wid + td->size_ow1;
2683 rc.right = rc.left + n * td->tile_wid;
2684 rc.top = y * td->tile_hgt + td->size_oh1;
2685 rc.bottom = rc.top + td->tile_hgt;
2688 SetBkColor(hdc, RGB(0, 0, 0));
2689 SelectObject(hdc, td->font_id);
2694 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2695 ReleaseDC(td->w, hdc);
2703 * Low level graphics. Assumes valid input.
2705 * Draw several ("n") chars, with an attr, at a given location.
2707 * All "graphic" data is handled by "Term_pict_win()", below.
2709 * One would think there is a more efficient method for telling a window
2710 * what color it should be using to draw with, but perhaps simply changing
2711 * it every time is not too inefficient. XXX XXX XXX
2713 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2715 term_data *td = (term_data*)(Term->data);
2719 #if 1 /* #ifdef JP */
2720 static HBITMAP WALL;
2721 static HBRUSH myBrush, oldBrush;
2723 static bool init_done = FALSE;
2726 WALL = LoadBitmap(hInstance, AppName);
2727 myBrush = CreatePatternBrush(WALL);
2732 /* Total rectangle */
2733 rc.left = x * td->tile_wid + td->size_ow1;
2734 rc.right = rc.left + n * td->tile_wid;
2735 rc.top = y * td->tile_hgt + td->size_oh1;
2736 rc.bottom = rc.top + td->tile_hgt;
2741 /* Background color */
2742 SetBkColor(hdc, RGB(0, 0, 0));
2744 /* Foreground color */
2747 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2751 SetTextColor(hdc, win_clr[a&0x0F]);
2755 SetTextColor(hdc, win_clr[a]);
2759 SelectObject(hdc, td->font_id);
2762 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2766 (td->tile_hgt != td->font_hgt) ||
2767 (td->tile_wid != td->font_wid))
2771 /* Erase complete rectangle */
2772 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2775 if (use_bg) DrawBG(hdc, &rc);
2778 rc.left += ((td->tile_wid - td->font_wid) / 2);
2779 rc.right = rc.left + td->font_wid;
2780 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2781 rc.bottom = rc.top + td->font_hgt;
2783 /* Dump each character */
2784 for (i = 0; i < n; i++)
2787 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2789 rc.right += td->font_wid;
2791 oldBrush = SelectObject(hdc, myBrush);
2792 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2795 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2797 SelectObject(hdc, oldBrush);
2798 SelectObject(hdc, oldPen);
2799 rc.right -= td->font_wid;
2803 rc.left += 2 * td->tile_wid;
2804 rc.right += 2 * td->tile_wid;
2806 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2808 rc.right += td->font_wid;
2810 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2812 rc.right -= td->font_wid;
2816 rc.left += 2 * td->tile_wid;
2817 rc.right += 2 * td->tile_wid;
2818 } else if (*(s+i)==127){
2819 oldBrush = SelectObject(hdc, myBrush);
2820 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2823 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2825 SelectObject(hdc, oldBrush);
2826 SelectObject(hdc, oldPen);
2829 rc.left += td->tile_wid;
2830 rc.right += td->tile_wid;
2833 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2836 rc.left += td->tile_wid;
2837 rc.right += td->tile_wid;
2842 oldBrush = SelectObject(hdc, myBrush);
2843 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2846 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2848 SelectObject(hdc, oldBrush);
2849 SelectObject(hdc, oldPen);
2852 rc.left += td->tile_wid;
2853 rc.right += td->tile_wid;
2856 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2860 rc.left += td->tile_wid;
2861 rc.right += td->tile_wid;
2865 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2869 rc.left += td->tile_wid;
2870 rc.right += td->tile_wid;
2881 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2886 ReleaseDC(td->w, hdc);
2894 * Low level graphics. Assumes valid input.
2896 * Draw an array of "special" attr/char pairs at the given location.
2898 * We use the "Term_pict_win()" function for "graphic" data, which are
2899 * encoded by setting the "high-bits" of both the "attr" and the "char"
2900 * data. We use the "attr" to represent the "row" of the main bitmap,
2901 * and the "char" to represent the "col" of the main bitmap. The use
2902 * of this function is induced by the "higher_pict" flag.
2904 * If "graphics" is not available, we simply "wipe" the given grids.
2906 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2908 term_data *td = (term_data*)(Term->data);
2914 int x2, y2, w2, h2, tw2;
2926 /* Erase the grids */
2927 return (Term_wipe_win(x, y, n));
2930 /* Size of bitmap cell */
2931 w1 = infGraph.CellWidth;
2932 h1 = infGraph.CellHeight;
2934 /* Size of window cell */
2937 w2 = td->map_tile_wid;
2938 h2 = td->map_tile_hgt;
2947 if (use_bigtile) tw2 *= 2;
2950 /* Location of window cell */
2951 x2 = x * w2 + td->size_ow1;
2952 y2 = y * h2 + td->size_oh1;
2958 hdcSrc = CreateCompatibleDC(hdc);
2959 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2961 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2963 hdcMask = CreateCompatibleDC(hdc);
2964 SelectObject(hdcMask, infMask.hBitmap);
2967 /* Draw attr/char pairs */
2968 for (i = 0; i < n; i++, x2 += w2)
2973 /* Extract picture */
2974 int row = (a & 0x7F);
2975 int col = (c & 0x7F);
2977 /* Location of bitmap cell */
2981 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2983 x3 = (tcp[i] & 0x7F) * w1;
2984 y3 = (tap[i] & 0x7F) * h1;
2987 if ((w1 == tw2) && (h1 == h2))
2989 /* Copy the terrain picture from the bitmap to the window */
2990 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2992 /* Mask out the tile */
2993 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2996 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2999 /* Need to stretch */
3002 /* Set the correct mode for stretching the tiles */
3003 SetStretchBltMode(hdc, COLORONCOLOR);
3005 /* Copy the terrain picture from the bitmap to the window */
3006 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
3008 /* Only draw if terrain and overlay are different */
3009 if ((x1 != x3) || (y1 != y3))
3011 /* Mask out the tile */
3012 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3015 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3022 if ((w1 == tw2) && (h1 == h2))
3024 /* Copy the picture from the bitmap to the window */
3025 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3028 /* Need to stretch */
3031 /* Set the correct mode for stretching the tiles */
3032 SetStretchBltMode(hdc, COLORONCOLOR);
3034 /* Copy the picture from the bitmap to the window */
3035 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3041 SelectObject(hdcSrc, hbmSrcOld);
3044 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3047 SelectObject(hdcMask, hbmSrcOld);
3052 ReleaseDC(td->w, hdc);
3054 #else /* USE_GRAPHICS */
3056 /* Just erase this grid */
3057 return (Term_wipe_win(x, y, n));
3059 #endif /* USE_GRAPHICS */
3066 static void windows_map(void)
3068 term_data *td = &data[0];
3070 int x, min_x, max_x;
3071 int y, min_y, max_y;
3075 /* Only in graphics mode */
3076 if (!use_graphics) return;
3079 Term_xtra_win_clear();
3081 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3082 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3083 td->map_active = TRUE;
3093 for (x = min_x; x < max_x; x++)
3095 for (y = min_y; y < max_y; y++)
3097 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3099 /* Ignore non-graphics */
3100 if ((a & 0x80) && (c & 0x80))
3102 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3107 /* Hilite the player */
3108 Term_curs_win(px - min_x, py - min_y);
3110 /* Wait for a keypress, flush key buffer */
3111 Term_inkey(&c, TRUE, TRUE);
3114 /* Switch off the map display */
3115 td->map_active = FALSE;
3117 /* Restore screen */
3118 Term_xtra_win_clear();
3123 /*** Other routines ***/
3127 * Create and initialize a "term_data" given a title
3129 static void term_data_link(term_data *td)
3133 /* Initialize the term */
3134 term_init(t, td->cols, td->rows, td->keys);
3136 /* Use a "software" cursor */
3137 t->soft_cursor = TRUE;
3139 /* Use "Term_pict" for "graphic" data */
3140 t->higher_pict = TRUE;
3142 /* Erase with "white space" */
3143 t->attr_blank = TERM_WHITE;
3144 t->char_blank = ' ';
3147 /* Prepare the init/nuke hooks */
3148 t->init_hook = Term_init_win;
3149 t->nuke_hook = Term_nuke_win;
3152 /* Prepare the template hooks */
3153 t->user_hook = Term_user_win;
3154 t->xtra_hook = Term_xtra_win;
3155 t->curs_hook = Term_curs_win;
3156 t->bigcurs_hook = Term_bigcurs_win;
3157 t->wipe_hook = Term_wipe_win;
3158 t->text_hook = Term_text_win;
3159 t->pict_hook = Term_pict_win;
3161 /* Remember where we came from */
3162 t->data = (vptr)(td);
3167 * Create the windows
3169 * First, instantiate the "default" values, then read the "ini_file"
3170 * to over-ride selected values, then create the windows, and fonts.
3172 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3173 * must make active to realize the palette. XXX XXX XXX
3175 static void init_windows(void)
3181 #if 0 /* #ifndef JP */
3187 WIPE(td, term_data);
3191 td->s = angband_term_name[0];
3205 #if 1 /* #ifdef JP */
3209 for (i = 1; i < MAX_TERM_DATA; i++)
3212 WIPE(td, term_data);
3213 td->s = angband_term_name[i];
3217 td->visible = FALSE;
3222 td->pos_x = (7 - i) * 30;
3223 td->pos_y = (7 - i) * 20;
3225 #if 1 /* #ifdef JP */
3235 /* Main window (need these before term_getsize gets called) */
3237 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3238 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3243 /* Sub windows (need these before term_getsize gets called) */
3244 for (i = 1; i < MAX_TERM_DATA; i++)
3247 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3248 td->dwExStyle = (WS_EX_TOOLWINDOW);
3253 for (i = 0; i < MAX_TERM_DATA; i++)
3257 #if 1 /* #ifdef JP */
3258 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3259 td->lf.lfCharSet = DEFAULT_CHARSET;
3260 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3261 /* Activate the chosen font */
3262 term_force_font(td, NULL);
3263 td->tile_wid = td->font_wid;
3264 td->tile_hgt = td->font_hgt;
3266 /* Access the standard font file */
3267 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3269 /* Activate the chosen font */
3270 if (term_force_font(td, buf))
3272 /* Access the standard font file */
3273 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3275 /* Force the use of that font */
3276 (void)term_force_font(td, buf);
3282 /* Assume not bizarre */
3283 td->bizarre = FALSE;
3288 /* Analyze the font */
3291 /* Resize the window */
3292 term_window_resize(td);
3296 /* Sub windows (reverse order) */
3297 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3302 td->w = CreateWindowEx(td->dwExStyle, AngList,
3304 td->pos_x, td->pos_y,
3305 td->size_wid, td->size_hgt,
3306 HWND_DESKTOP, NULL, hInstance, NULL);
3309 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3311 if (!td->w) quit("Failed to create sub-window");
3317 td->size_hack = TRUE;
3318 ShowWindow(td->w, SW_SHOW);
3319 td->size_hack = FALSE;
3323 angband_term[i] = &td->t;
3327 /* Activate the window */
3328 SetActiveWindow(td->w);
3333 term_window_pos(&data[i], HWND_TOPMOST);
3337 term_window_pos(&data[i], td->w);
3347 td->w = CreateWindowEx(td->dwExStyle, AppName,
3349 td->pos_x, td->pos_y,
3350 td->size_wid, td->size_hgt,
3351 HWND_DESKTOP, NULL, hInstance, NULL);
3354 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3356 if (!td->w) quit("Failed to create Angband window");
3361 angband_term[0] = &td->t;
3362 normsize.x = td->cols;
3363 normsize.y = td->rows;
3365 /* Activate the main window */
3366 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3367 else ShowWindow(td->w, SW_SHOW);
3369 /* Bring main window back to top */
3370 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3373 /* New palette XXX XXX XXX */
3374 (void)new_palette();
3377 /* Create a "brush" for drawing the "cursor" */
3378 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3381 /* Process pending messages */
3382 (void)Term_xtra_win_flush();
3390 static void setup_menus(void)
3394 HMENU hm = GetMenu(data[0].w);
3397 /* Menu "File", Disable all */
3398 EnableMenuItem(hm, IDM_FILE_NEW,
3399 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3400 EnableMenuItem(hm, IDM_FILE_OPEN,
3401 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3402 EnableMenuItem(hm, IDM_FILE_SAVE,
3403 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3404 EnableMenuItem(hm, IDM_FILE_EXIT,
3405 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3406 EnableMenuItem(hm, IDM_FILE_SCORE,
3407 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3410 /* No character available */
3411 if (!character_generated)
3413 /* Menu "File", Item "New" */
3414 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3416 /* Menu "File", Item "Open" */
3417 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3420 /* A character available */
3421 if (character_generated)
3423 /* Menu "File", Item "Save" */
3424 EnableMenuItem(hm, IDM_FILE_SAVE,
3425 MF_BYCOMMAND | MF_ENABLED);
3428 /* Menu "File", Item "Exit" */
3429 EnableMenuItem(hm, IDM_FILE_EXIT,
3430 MF_BYCOMMAND | MF_ENABLED);
3432 EnableMenuItem(hm, IDM_FILE_SCORE,
3433 MF_BYCOMMAND | MF_ENABLED);
3436 /* Menu "Window::Visibility" */
3437 for (i = 0; i < MAX_TERM_DATA; i++)
3439 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3440 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3442 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3443 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3445 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3446 MF_BYCOMMAND | MF_ENABLED);
3449 /* Menu "Window::Font" */
3450 for (i = 0; i < MAX_TERM_DATA; i++)
3452 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3453 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3455 if (data[i].visible)
3457 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3458 MF_BYCOMMAND | MF_ENABLED);
3462 /* Menu "Window::Window Position Fix" */
3463 for (i = 0; i < MAX_TERM_DATA; i++)
3465 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3466 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3468 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3469 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3471 if (data[i].visible)
3473 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3474 MF_BYCOMMAND | MF_ENABLED);
3478 /* Menu "Window::Bizarre Display" */
3479 for (i = 0; i < MAX_TERM_DATA; i++)
3481 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3482 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3484 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3485 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3487 if (data[i].visible)
3489 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3490 MF_BYCOMMAND | MF_ENABLED);
3495 /* Menu "Window::Increase Tile Width" */
3496 for (i = 0; i < MAX_TERM_DATA; i++)
3498 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3499 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3501 if (data[i].visible)
3503 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3504 MF_BYCOMMAND | MF_ENABLED);
3509 /* Menu "Window::Decrease Tile Width" */
3510 for (i = 0; i < MAX_TERM_DATA; i++)
3512 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3513 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3515 if (data[i].visible)
3517 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3518 MF_BYCOMMAND | MF_ENABLED);
3523 /* Menu "Window::Increase Tile Height" */
3524 for (i = 0; i < MAX_TERM_DATA; i++)
3526 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3527 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3529 if (data[i].visible)
3531 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3532 MF_BYCOMMAND | MF_ENABLED);
3537 /* Menu "Window::Decrease Tile Height" */
3538 for (i = 0; i < MAX_TERM_DATA; i++)
3540 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3541 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3543 if (data[i].visible)
3545 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3546 MF_BYCOMMAND | MF_ENABLED);
3551 /* Menu "Options", disable all */
3552 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3553 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3554 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3555 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3556 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3557 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3558 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3559 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3560 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3561 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3563 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3564 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3567 /* Menu "Options", Item "Map" */
3568 if (use_graphics != GRAPHICS_NONE)
3569 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3571 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3572 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3574 /* Menu "Options", update all */
3575 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3576 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3577 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3578 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3579 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3580 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3581 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3582 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3583 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3584 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3585 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3586 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3587 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3588 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3589 CheckMenuItem(hm, IDM_OPTIONS_BG,
3590 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3592 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3593 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3597 /* Menu "Options", Item "Graphics" */
3598 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3599 /* Menu "Options", Item "Graphics" */
3600 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3601 /* Menu "Options", Item "Graphics" */
3602 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3603 /* Menu "Options", Item "Graphics" */
3604 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3605 #endif /* USE_GRAPHICS */
3608 /* Menu "Options", Item "Sound" */
3609 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3610 #endif /* USE_SOUND */
3613 /* Menu "Options", Item "ScreenSaver" */
3614 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3615 MF_BYCOMMAND | MF_ENABLED);
3616 #endif /* USE_SAVER */
3621 * Check for double clicked (or dragged) savefile
3623 * Apparently, Windows copies the entire filename into the first
3624 * piece of the "command line string". Perhaps we should extract
3625 * the "basename" of that filename and append it to the "save" dir.
3627 static void check_for_save_file(LPSTR cmd_line)
3637 /* Extract filename */
3638 strcat(savefile, s);
3640 /* Validate the file */
3641 validate_file(savefile);
3643 /* Game in progress */
3644 game_in_progress = TRUE;
3652 * Process a menu command
3654 static void process_menus(WORD wCmd)
3671 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3673 plog("You cannot do that yet...");
3677 else if (game_in_progress)
3680 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3682 plog("You can't start a new game while you're still playing!");
3688 game_in_progress = TRUE;
3702 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3704 plog("You cannot do that yet...");
3708 else if (game_in_progress)
3711 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3713 plog("You can't open a new game while you're still playing!");
3719 memset(&ofn, 0, sizeof(ofn));
3720 ofn.lStructSize = sizeof(ofn);
3721 ofn.hwndOwner = data[0].w;
3722 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3723 ofn.nFilterIndex = 1;
3724 ofn.lpstrFile = savefile;
3725 ofn.nMaxFile = 1024;
3726 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3727 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3729 if (GetOpenFileName(&ofn))
3731 /* Load 'savefile' */
3732 validate_file(savefile);
3733 game_in_progress = TRUE;
3745 if (game_in_progress && character_generated)
3751 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3753 plog("You may not do that right now.");
3759 /* Hack -- Forget messages */
3764 do_cmd_save_game(FALSE);
3765 #else /* ZANGBAND */
3767 #endif /* ZANGBAND */
3772 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3774 plog("You may not do that right now.");
3784 if (game_in_progress && character_generated)
3790 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3792 plog("You may not do that right now.");
3798 /* Hack -- Forget messages */
3807 /* do_cmd_save_game(FALSE); */
3808 #else /* ZANGBAND */
3809 /* do_cmd_save_game(); */
3810 #endif /* ZANGBAND */
3811 Term_key_push(SPECIAL_KEY_QUIT);
3819 case IDM_FILE_SCORE:
3823 /* Build the filename */
3824 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3826 /* Open the binary high score file, for reading */
3827 highscore_fd = fd_open(buf, O_RDONLY);
3829 /* Paranoia -- No score file */
3830 if (highscore_fd < 0)
3832 msg_print("Score file unavailable.");
3842 /* Display the scores */
3843 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3845 /* Shut the high score file */
3846 (void)fd_close(highscore_fd);
3848 /* Forget the high score fd */
3854 /* Hack - Flush it */
3862 case IDM_FILE_MOVIE:
3867 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3869 plog("You cannot do that yet...");
3872 else if (game_in_progress)
3875 plog("¥×¥ì¥¤Ãæ¤Ï¥à¡¼¥Ó¡¼¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3877 plog("You can't open a movie while you're playing!");
3882 memset(&ofn, 0, sizeof(ofn));
3883 ofn.lStructSize = sizeof(ofn);
3884 ofn.hwndOwner = data[0].w;
3885 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3886 ofn.nFilterIndex = 1;
3887 ofn.lpstrFile = savefile;
3888 ofn.nMaxFile = 1024;
3889 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3890 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3892 if (GetOpenFileName(&ofn))
3894 /* Load 'savefile' */
3895 prepare_browse_movie_aux(savefile);
3905 case IDM_WINDOW_VIS_0:
3908 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3910 plog("You are not allowed to do that!");
3917 /* Window visibility */
3918 case IDM_WINDOW_VIS_1:
3919 case IDM_WINDOW_VIS_2:
3920 case IDM_WINDOW_VIS_3:
3921 case IDM_WINDOW_VIS_4:
3922 case IDM_WINDOW_VIS_5:
3923 case IDM_WINDOW_VIS_6:
3924 case IDM_WINDOW_VIS_7:
3926 i = wCmd - IDM_WINDOW_VIS_0;
3928 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3935 ShowWindow(td->w, SW_SHOW);
3936 term_data_redraw(td);
3940 td->visible = FALSE;
3942 ShowWindow(td->w, SW_HIDE);
3949 case IDM_WINDOW_FONT_0:
3950 case IDM_WINDOW_FONT_1:
3951 case IDM_WINDOW_FONT_2:
3952 case IDM_WINDOW_FONT_3:
3953 case IDM_WINDOW_FONT_4:
3954 case IDM_WINDOW_FONT_5:
3955 case IDM_WINDOW_FONT_6:
3956 case IDM_WINDOW_FONT_7:
3958 i = wCmd - IDM_WINDOW_FONT_0;
3960 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3964 term_change_font(td);
3969 /* Window Z Position */
3970 case IDM_WINDOW_POS_1:
3971 case IDM_WINDOW_POS_2:
3972 case IDM_WINDOW_POS_3:
3973 case IDM_WINDOW_POS_4:
3974 case IDM_WINDOW_POS_5:
3975 case IDM_WINDOW_POS_6:
3976 case IDM_WINDOW_POS_7:
3978 i = wCmd - IDM_WINDOW_POS_0;
3980 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3984 if (!td->posfix && td->visible)
3987 term_window_pos(td, HWND_TOPMOST);
3992 term_window_pos(td, data[0].w);
3998 /* Bizarre Display */
3999 case IDM_WINDOW_BIZ_0:
4000 case IDM_WINDOW_BIZ_1:
4001 case IDM_WINDOW_BIZ_2:
4002 case IDM_WINDOW_BIZ_3:
4003 case IDM_WINDOW_BIZ_4:
4004 case IDM_WINDOW_BIZ_5:
4005 case IDM_WINDOW_BIZ_6:
4006 case IDM_WINDOW_BIZ_7:
4008 i = wCmd - IDM_WINDOW_BIZ_0;
4010 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4014 td->bizarre = !td->bizarre;
4018 term_window_resize(td);
4023 /* Increase Tile Width */
4024 case IDM_WINDOW_I_WID_0:
4025 case IDM_WINDOW_I_WID_1:
4026 case IDM_WINDOW_I_WID_2:
4027 case IDM_WINDOW_I_WID_3:
4028 case IDM_WINDOW_I_WID_4:
4029 case IDM_WINDOW_I_WID_5:
4030 case IDM_WINDOW_I_WID_6:
4031 case IDM_WINDOW_I_WID_7:
4033 i = wCmd - IDM_WINDOW_I_WID_0;
4035 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4043 term_window_resize(td);
4048 /* Decrease Tile Height */
4049 case IDM_WINDOW_D_WID_0:
4050 case IDM_WINDOW_D_WID_1:
4051 case IDM_WINDOW_D_WID_2:
4052 case IDM_WINDOW_D_WID_3:
4053 case IDM_WINDOW_D_WID_4:
4054 case IDM_WINDOW_D_WID_5:
4055 case IDM_WINDOW_D_WID_6:
4056 case IDM_WINDOW_D_WID_7:
4058 i = wCmd - IDM_WINDOW_D_WID_0;
4060 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4068 term_window_resize(td);
4073 /* Increase Tile Height */
4074 case IDM_WINDOW_I_HGT_0:
4075 case IDM_WINDOW_I_HGT_1:
4076 case IDM_WINDOW_I_HGT_2:
4077 case IDM_WINDOW_I_HGT_3:
4078 case IDM_WINDOW_I_HGT_4:
4079 case IDM_WINDOW_I_HGT_5:
4080 case IDM_WINDOW_I_HGT_6:
4081 case IDM_WINDOW_I_HGT_7:
4083 i = wCmd - IDM_WINDOW_I_HGT_0;
4085 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4093 term_window_resize(td);
4098 /* Decrease Tile Height */
4099 case IDM_WINDOW_D_HGT_0:
4100 case IDM_WINDOW_D_HGT_1:
4101 case IDM_WINDOW_D_HGT_2:
4102 case IDM_WINDOW_D_HGT_3:
4103 case IDM_WINDOW_D_HGT_4:
4104 case IDM_WINDOW_D_HGT_5:
4105 case IDM_WINDOW_D_HGT_6:
4106 case IDM_WINDOW_D_HGT_7:
4108 i = wCmd - IDM_WINDOW_D_HGT_0;
4110 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4118 term_window_resize(td);
4123 case IDM_OPTIONS_NO_GRAPHICS:
4128 plog("You may not do that right now.");
4132 /* Toggle "arg_graphics" */
4133 if (arg_graphics != GRAPHICS_NONE)
4135 arg_graphics = GRAPHICS_NONE;
4137 /* React to changes */
4138 Term_xtra_win_react();
4140 /* Hack -- Force redraw */
4141 Term_key_push(KTRL('R'));
4147 case IDM_OPTIONS_OLD_GRAPHICS:
4152 plog("You may not do that right now.");
4156 /* Toggle "arg_graphics" */
4157 if (arg_graphics != GRAPHICS_ORIGINAL)
4159 arg_graphics = GRAPHICS_ORIGINAL;
4161 /* React to changes */
4162 Term_xtra_win_react();
4164 /* Hack -- Force redraw */
4165 Term_key_push(KTRL('R'));
4171 case IDM_OPTIONS_NEW_GRAPHICS:
4176 plog("You may not do that right now.");
4180 /* Toggle "arg_graphics" */
4181 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4183 arg_graphics = GRAPHICS_ADAM_BOLT;
4185 /* React to changes */
4186 Term_xtra_win_react();
4188 /* Hack -- Force redraw */
4189 Term_key_push(KTRL('R'));
4195 case IDM_OPTIONS_NEW2_GRAPHICS:
4200 plog("You may not do that right now.");
4204 /* Toggle "arg_graphics" */
4205 if (arg_graphics != GRAPHICS_HENGBAND)
4207 arg_graphics = GRAPHICS_HENGBAND;
4209 /* React to changes */
4210 Term_xtra_win_react();
4212 /* Hack -- Force redraw */
4213 Term_key_push(KTRL('R'));
4219 case IDM_OPTIONS_BIGTILE:
4221 term_data *td = &data[0];
4226 plog("You may not do that right now.");
4230 /* Toggle "arg_sound" */
4231 arg_bigtile = !arg_bigtile;
4234 Term_activate(&td->t);
4236 /* Resize the term */
4237 Term_resize(td->cols, td->rows);
4240 InvalidateRect(td->w, NULL, TRUE);
4245 case IDM_OPTIONS_SOUND:
4250 plog("You may not do that right now.");
4254 /* Toggle "arg_sound" */
4255 arg_sound = !arg_sound;
4257 /* React to changes */
4258 Term_xtra_win_react();
4260 /* Hack -- Force redraw */
4261 Term_key_push(KTRL('R'));
4267 case IDM_OPTIONS_BG:
4272 plog("You may not do that right now.");
4276 /* Toggle "use_bg" */
4281 /* React to changes */
4282 Term_xtra_win_react();
4284 /* Hack -- Force redraw */
4285 Term_key_push(KTRL('R'));
4291 case IDM_OPTIONS_OPEN_BG:
4296 plog("You may not do that right now.");
4301 memset(&ofn, 0, sizeof(ofn));
4302 ofn.lStructSize = sizeof(ofn);
4303 ofn.hwndOwner = data[0].w;
4304 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4305 ofn.nFilterIndex = 1;
4306 ofn.lpstrFile = bg_bitmap_file;
4307 ofn.nMaxFile = 1023;
4308 ofn.lpstrInitialDir = NULL;
4310 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
4312 ofn.lpstrTitle = "Choose wall paper.";
4314 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4316 if (GetOpenFileName(&ofn))
4318 /* Load 'savefile' */
4323 /* React to changes */
4324 Term_xtra_win_react();
4326 /* Hack -- Force redraw */
4327 Term_key_push(KTRL('R'));
4332 case IDM_DUMP_SCREEN_HTML:
4334 static char buf[1024] = "";
4335 memset(&ofn, 0, sizeof(ofn));
4336 ofn.lStructSize = sizeof(ofn);
4337 ofn.hwndOwner = data[0].w;
4338 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4339 ofn.nFilterIndex = 1;
4340 ofn.lpstrFile = buf;
4341 ofn.nMaxFile = 1023;
4342 ofn.lpstrDefExt = "html";
4343 ofn.lpstrInitialDir = NULL;
4345 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
4347 ofn.lpstrTitle = "Save screen dump as HTML.";
4349 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4351 if (GetSaveFileName(&ofn))
4353 do_cmd_save_screen_html_aux(buf, 0);
4360 case IDM_OPTIONS_SAVER:
4364 DestroyWindow(hwndSaver);
4369 /* Create a screen scaver window */
4370 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4371 "Angband Screensaver",
4372 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4373 0, 0, GetSystemMetrics(SM_CXSCREEN),
4374 GetSystemMetrics(SM_CYSCREEN),
4375 NULL, NULL, hInstance, NULL);
4379 /* Push the window to the bottom XXX XXX XXX */
4380 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4385 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
4387 plog("Failed to create saver window");
4397 case IDM_OPTIONS_MAP:
4403 case IDM_HELP_CONTENTS:
4407 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4408 if (check_file(tmp))
4410 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4415 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4416 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4418 plog_fmt("Cannot find help file: %s", tmp);
4419 plog("Use the online help files instead.");
4424 #else /* HTML_HELP */
4427 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4428 if (check_file(tmp))
4430 sprintf(buf, "winhelp.exe %s", tmp);
4431 WinExec(buf, SW_NORMAL);
4436 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4437 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4439 plog_fmt("Cannot find help file: %s", tmp);
4440 plog("Use the online help files instead.");
4445 #endif /* HTML_HELP */
4451 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4458 /* Extract the modifiers */
4459 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4460 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4461 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4463 Term_no_press = (ma) ? TRUE : FALSE;
4465 /* Handle "special" keys */
4466 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4468 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4469 bool numpad = FALSE;
4471 /* Begin the macro trigger */
4474 /* Send the modifiers */
4475 if (mc) Term_keypress('C');
4476 if (ms) Term_keypress('S');
4477 if (ma) Term_keypress('A');
4479 /* Extract "scan code" */
4480 i = LOBYTE(HIWORD(lParam));
4482 /* Introduce the scan code */
4485 /* Extended key bit */
4488 /* Numpad Enter and '/' are extended key */
4490 Term_no_press = TRUE;
4491 case VK_RETURN: /* Enter */
4494 /* Other extended keys are on full keyboard */
4510 Term_no_press = TRUE;
4514 case VK_PRIOR: /* Page Up */
4515 case VK_NEXT: /* Page Down */
4525 /* Special modifiers for keypad keys */
4526 if (numpad) Term_keypress('K');
4528 /* Encode the hexidecimal scan code */
4529 Term_keypress(hexsym[i/16]);
4530 Term_keypress(hexsym[i%16]);
4532 /* End the macro trigger */
4543 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4544 WPARAM wParam, LPARAM lParam);
4545 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4546 WPARAM wParam, LPARAM lParam)
4547 #else /* __MWERKS__ */
4548 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4549 WPARAM wParam, LPARAM lParam)
4550 #endif /* __MWERKS__ */
4556 MINMAXINFO FAR *lpmmi;
4562 /* Acquire proper "term_data" info */
4563 td = (term_data *)GetWindowLong(hWnd, 0);
4565 /* Handle message */
4571 SetWindowLong(hWnd, 0, (LONG)(my_td));
4581 case WM_GETMINMAXINFO:
4583 MINMAXINFO FAR *lpmmi;
4586 lpmmi = (MINMAXINFO FAR *)lParam;
4588 /* this message was sent before WM_NCCREATE */
4591 /* Minimum window size is 80x24 */
4592 rc.left = rc.top = 0;
4593 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4594 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4597 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4599 /* Save minimum size */
4600 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4601 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4608 BeginPaint(hWnd, &ps);
4609 if (td) term_data_redraw(td);
4610 EndPaint(hWnd, &ps);
4611 ValidateRect(hWnd, NULL);
4618 if (process_keydown(wParam, lParam))
4625 if (Term_no_press) Term_no_press = FALSE;
4626 else Term_keypress(wParam);
4630 case WM_LBUTTONDOWN:
4632 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4633 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4645 int dx = abs(oldx - mousex) + 1;
4646 int dy = abs(oldy - mousey) + 1;
4647 int ox = (oldx > mousex) ? mousex : oldx;
4648 int oy = (oldy > mousey) ? mousey : oldy;
4658 hGlobal = GlobalAlloc(GHND, sz + 1);
4659 if (hGlobal == NULL) return 0;
4660 lpStr = (LPSTR)GlobalLock(hGlobal);
4662 for (i = 0; i < dy; i++)
4666 char **scr = data[0].t.scr->c;
4668 C_MAKE(s, (dx + 1), char);
4669 strncpy(s, &scr[oy + i][ox], dx);
4673 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4676 if (ox + dx < data[0].cols)
4678 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4681 for (j = 0; j < dx; j++)
4683 if (s[j] == 127) s[j] = '#';
4687 for (j = 0; j < dx; j++)
4689 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4699 GlobalUnlock(hGlobal);
4700 if (OpenClipboard(hWnd) == 0)
4702 GlobalFree(hGlobal);
4706 SetClipboardData(CF_TEXT, hGlobal);
4719 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4720 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4725 dx = abs(oldx - mousex) + 1;
4726 dy = abs(oldy - mousey) + 1;
4727 ox = (oldx > mousex) ? mousex : oldx;
4728 oy = (oldy > mousey) ? mousey : oldy;
4729 Term_inversed_area(hWnd, ox, oy, dx, dy);
4736 dx = abs(cx - mousex) + 1;
4737 dy = abs(cy - mousey) + 1;
4738 ox = (cx > mousex) ? mousex : cx;
4739 oy = (cy > mousey) ? mousey : cy;
4740 Term_inversed_area(hWnd, ox, oy, dx, dy);
4756 if (game_in_progress && character_generated)
4761 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4763 plog("You may not do that right now.");
4768 /* Hack -- Forget messages */
4777 /* do_cmd_save_game(FALSE); */
4778 #else /* ZANGBAND */
4779 /* do_cmd_save_game(); */
4780 #endif /* ZANGBAND */
4781 Term_key_push(SPECIAL_KEY_QUIT);
4788 case WM_QUERYENDSESSION:
4790 if (game_in_progress && character_generated)
4792 /* Hack -- Forget messages */
4795 /* Mega-Hack -- Delay death */
4796 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4799 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "----¥²¡¼¥àÃæÃÇ----");
4801 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "---- Save and Exit Game ----");
4804 /* Hardcode panic save */
4805 p_ptr->panic_save = 1;
4807 /* Forbid suspend */
4808 signals_ignore_tstp();
4810 /* Indicate panic save */
4812 (void)strcpy(p_ptr->died_from, "(¶ÛµÞ¥»¡¼¥Ö)");
4814 (void)strcpy(p_ptr->died_from, "(panic save)");
4818 (void)save_player();
4832 process_menus(LOWORD(wParam));
4838 /* this message was sent before WM_NCCREATE */
4841 /* it was sent from inside CreateWindowEx */
4842 if (!td->w) return 1;
4844 /* was sent from WM_SIZE */
4845 if (td->size_hack) return 1;
4849 case SIZE_MINIMIZED:
4851 /* Hide sub-windows */
4852 for (i = 1; i < MAX_TERM_DATA; i++)
4854 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4859 case SIZE_MAXIMIZED:
4861 /* fall through XXX XXX XXX */
4866 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4867 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4870 if ((td->cols != cols) || (td->rows != rows))
4872 /* Save the new size */
4876 if (!IsZoomed(td->w) && !IsIconic(td->w))
4878 normsize.x = td->cols;
4879 normsize.y = td->rows;
4883 Term_activate(&td->t);
4885 /* Resize the term */
4886 Term_resize(td->cols, td->rows);
4889 InvalidateRect(td->w, NULL, TRUE);
4892 td->size_hack = TRUE;
4894 /* Show sub-windows */
4895 for (i = 1; i < MAX_TERM_DATA; i++)
4897 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4900 td->size_hack = FALSE;
4908 case WM_PALETTECHANGED:
4910 /* Ignore if palette change caused by itself */
4911 if ((HWND)wParam == hWnd) return 0;
4913 /* Fall through... */
4916 case WM_QUERYNEWPALETTE:
4918 if (!paletted) return 0;
4922 SelectPalette(hdc, hPal, FALSE);
4924 i = RealizePalette(hdc);
4926 /* if any palette entries changed, repaint the window. */
4927 if (i) InvalidateRect(hWnd, NULL, TRUE);
4929 ReleaseDC(hWnd, hdc);
4936 if (wParam && !HIWORD(lParam))
4938 /* Do something to sub-windows */
4939 for (i = 1; i < MAX_TERM_DATA; i++)
4941 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4944 /* Focus on main window */
4953 case WM_ACTIVATEAPP:
4955 if (IsIconic(td->w)) break;
4957 for (i = 1; i < MAX_TERM_DATA; i++)
4963 ShowWindow(data[i].w, SW_SHOW);
4967 ShowWindow(data[i].w, SW_HIDE);
4974 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4979 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4980 WPARAM wParam, LPARAM lParam);
4981 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4982 WPARAM wParam, LPARAM lParam)
4983 #else /* __MWERKS__ */
4984 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4985 WPARAM wParam, LPARAM lParam)
4986 #endif /* __MWERKS__ */
4990 MINMAXINFO FAR *lpmmi;
4998 /* Acquire proper "term_data" info */
4999 td = (term_data *)GetWindowLong(hWnd, 0);
5001 /* Process message */
5007 SetWindowLong(hWnd, 0, (LONG)(my_td));
5017 case WM_GETMINMAXINFO:
5019 MINMAXINFO FAR *lpmmi;
5022 lpmmi = (MINMAXINFO FAR *)lParam;
5024 /* this message was sent before WM_NCCREATE */
5027 /* Minimum window size is 80x24 */
5028 rc.left = rc.top = 0;
5029 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5030 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5033 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5035 /* Save minimum size */
5036 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5037 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5047 /* this message was sent before WM_NCCREATE */
5050 /* it was sent from inside CreateWindowEx */
5051 if (!td->w) return 1;
5053 /* was sent from inside WM_SIZE */
5054 if (td->size_hack) return 1;
5056 td->size_hack = TRUE;
5058 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5059 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5062 if ((td->cols != cols) || (td->rows != rows))
5065 term *old_term = Term;
5067 /* Save the new size */
5072 Term_activate(&td->t);
5074 /* Resize the term */
5075 Term_resize(td->cols, td->rows);
5078 Term_activate(old_term);
5081 InvalidateRect(td->w, NULL, TRUE);
5083 /* HACK - Redraw all windows */
5084 p_ptr->window = 0xFFFFFFFF;
5088 td->size_hack = FALSE;
5095 BeginPaint(hWnd, &ps);
5096 if (td) term_data_redraw(td);
5097 EndPaint(hWnd, &ps);
5104 if (process_keydown(wParam, lParam))
5111 if (Term_no_press) Term_no_press = FALSE;
5112 else Term_keypress(wParam);
5116 case WM_PALETTECHANGED:
5118 /* ignore if palette change caused by itself */
5119 if ((HWND)wParam == hWnd) return FALSE;
5120 /* otherwise, fall through!!! */
5123 case WM_QUERYNEWPALETTE:
5125 if (!paletted) return 0;
5127 SelectPalette(hdc, hPal, FALSE);
5128 i = RealizePalette(hdc);
5129 /* if any palette entries changed, repaint the window. */
5130 if (i) InvalidateRect(hWnd, NULL, TRUE);
5131 ReleaseDC(hWnd, hdc);
5135 case WM_NCLBUTTONDOWN:
5139 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5140 #endif /* HTCLOSE */
5142 if (wParam == HTSYSMENU)
5146 td->visible = FALSE;
5147 ShowWindow(td->w, SW_HIDE);
5157 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5163 #define MOUSE_SENS 40
5166 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5167 WPARAM wParam, LPARAM lParam);
5168 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5169 WPARAM wParam, LPARAM lParam)
5170 #else /* __MWERKS__ */
5171 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5172 WPARAM wParam, LPARAM lParam)
5173 #endif /* __MWERKS__ */
5175 static int iMouse = 0;
5176 static WORD xMouse = 0;
5177 static WORD yMouse = 0;
5200 if (LOWORD(wParam) == WA_INACTIVE) break;
5202 /* else fall through */
5206 case WM_LBUTTONDOWN:
5207 case WM_MBUTTONDOWN:
5208 case WM_RBUTTONDOWN:
5211 SendMessage(hWnd, WM_CLOSE, 0, 0);
5219 dx = LOWORD(lParam) - xMouse;
5220 dy = HIWORD(lParam) - yMouse;
5222 if (dx < 0) dx = -dx;
5223 if (dy < 0) dy = -dy;
5225 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5227 SendMessage(hWnd, WM_CLOSE, 0, 0);
5231 /* Save last location */
5233 xMouse = LOWORD(lParam);
5234 yMouse = HIWORD(lParam);
5241 DestroyWindow(hwndSaver);
5248 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5251 #endif /* USE_SAVER */
5257 /*** Temporary Hooks ***/
5261 * Display warning message (see "z-util.c")
5263 static void hack_plog(cptr str)
5265 /* Give a warning */
5269 MessageBox(NULL, str, "·Ù¹ð¡ª",
5270 MB_ICONEXCLAMATION | MB_OK);
5272 MessageBox(NULL, str, "Warning",
5273 MB_ICONEXCLAMATION | MB_OK);
5281 * Display error message and quit (see "z-util.c")
5283 static void hack_quit(cptr str)
5285 /* Give a warning */
5289 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
5290 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5292 MessageBox(NULL, str, "Error",
5293 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5298 /* Unregister the classes */
5299 UnregisterClass(AppName, hInstance);
5301 /* Destroy the icon */
5302 if (hIcon) DestroyIcon(hIcon);
5310 /*** Various hooks ***/
5314 * Display warning message (see "z-util.c")
5316 static void hook_plog(cptr str)
5322 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
5323 MB_ICONEXCLAMATION | MB_OK);
5325 MessageBox(data[0].w, str, "Warning",
5326 MB_ICONEXCLAMATION | MB_OK);
5334 * Display error message and quit (see "z-util.c")
5336 static void hook_quit(cptr str)
5341 /* Give a warning */
5345 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
5346 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5348 MessageBox(data[0].w, str, "Error",
5349 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5355 /* Save the preferences */
5359 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
5361 /* Destroy all windows */
5362 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5364 term_force_font(&data[i], NULL);
5365 if (data[i].font_want) string_free(data[i].font_want);
5366 if (data[i].w) DestroyWindow(data[i].w);
5370 /* Free the bitmap stuff */
5372 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5373 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5375 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5376 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5378 #endif /* USE_GRAPHICS */
5380 /*** Free some other stuff ***/
5382 DeleteObject(hbrYellow);
5387 if (hPal) DeleteObject(hPal);
5389 UnregisterClass(AppName, hInstance);
5391 if (hIcon) DestroyIcon(hIcon);
5398 /*** Initialize ***/
5404 static void init_stuff(void)
5411 /* Get program name with full path */
5412 GetModuleFileName(hInstance, path, 512);
5414 /* Save the "program name" XXX XXX XXX */
5417 /* Get the name of the "*.ini" file */
5418 strcpy(path + strlen(path) - 4, ".INI");
5420 /* Save the the name of the ini-file */
5421 ini_file = string_make(path);
5423 /* Analyze the path */
5429 if (path[i] == '\\')
5436 /* Add "lib" to the path */
5437 strcpy(path + i + 1, "lib\\");
5439 /* Validate the path */
5440 validate_dir(path, TRUE);
5442 /* Init the file paths */
5443 init_file_paths(path);
5445 /* Hack -- Validate the paths */
5446 validate_dir(ANGBAND_DIR_APEX, FALSE);
5447 validate_dir(ANGBAND_DIR_BONE, FALSE);
5449 /* Allow missing 'edit' directory */
5450 if (!check_dir(ANGBAND_DIR_EDIT))
5452 /* Must have 'data'! */
5453 validate_dir(ANGBAND_DIR_DATA, TRUE);
5457 /* Don't need 'data' */
5458 validate_dir(ANGBAND_DIR_DATA, FALSE);
5461 validate_dir(ANGBAND_DIR_FILE, TRUE);
5462 validate_dir(ANGBAND_DIR_HELP, FALSE);
5463 validate_dir(ANGBAND_DIR_INFO, FALSE);
5464 validate_dir(ANGBAND_DIR_PREF, TRUE);
5465 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5466 validate_dir(ANGBAND_DIR_USER, TRUE);
5467 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5469 /* Build the filename */
5471 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
5473 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
5477 /* Hack -- Validate the "news.txt" file */
5478 validate_file(path);
5481 #if 0 /* #ifndef JP */
5482 /* Build the "font" path */
5483 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5485 /* Allocate the path */
5486 ANGBAND_DIR_XTRA_FONT = string_make(path);
5488 /* Validate the "font" directory */
5489 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5491 /* Build the filename */
5492 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5494 /* Hack -- Validate the basic font */
5495 validate_file(path);
5501 /* Build the "graf" path */
5502 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5504 /* Allocate the path */
5505 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5507 /* Validate the "graf" directory */
5508 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5510 #endif /* USE_GRAPHICS */
5515 /* Build the "sound" path */
5516 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5518 /* Allocate the path */
5519 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5521 /* Validate the "sound" directory */
5522 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5524 #endif /* USE_SOUND */
5528 /* Build the "music" path */
5529 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5531 /* Allocate the path */
5532 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5534 /* Validate the "music" directory */
5535 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5537 #endif /* USE_MUSIC */
5539 /* Build the "help" path */
5540 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5542 /* Allocate the path */
5543 ANGBAND_DIR_XTRA_HELP = string_make(path);
5545 /* Validate the "help" directory */
5546 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5549 bool is_already_running()
5551 bool result = FALSE;
5554 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5555 if (GetLastError() == ERROR_ALREADY_EXISTS)
5563 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5564 LPSTR lpCmdLine, int nCmdShow)
5572 setlocale( LC_ALL, "ja_JP" );
5581 /* Prevent multiple run */
5582 if (is_already_running())
5585 _("ÊѶòÈÚÅܤϤ¹¤Ç¤Ëµ¯Æ°¤·¤Æ¤¤¤Þ¤¹¡£", "Hengband is already running."),
5586 _("¥¨¥é¡¼¡ª", "Error") ,
5587 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5592 if (hPrevInst == NULL)
5594 wc.style = CS_CLASSDC;
5595 wc.lpfnWndProc = AngbandWndProc;
5597 wc.cbWndExtra = 4; /* one long pointer to term_data */
5598 wc.hInstance = hInst;
5599 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5600 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5601 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5602 wc.lpszMenuName = AppName;
5603 wc.lpszClassName = AppName;
5605 if (!RegisterClass(&wc)) exit(1);
5607 wc.lpfnWndProc = AngbandListProc;
5608 wc.lpszMenuName = NULL;
5609 wc.lpszClassName = AngList;
5611 if (!RegisterClass(&wc)) exit(2);
5615 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5616 wc.lpfnWndProc = AngbandSaverProc;
5618 wc.lpszMenuName = NULL;
5619 wc.lpszClassName = "WindowsScreenSaverClass";
5621 if (!RegisterClass(&wc)) exit(3);
5627 /* Temporary hooks */
5628 plog_aux = hack_plog;
5629 quit_aux = hack_quit;
5630 core_aux = hack_quit;
5632 /* Prepare the filepaths */
5635 /* Initialize the keypress analyzer */
5636 for (i = 0; special_key_list[i]; ++i)
5638 special_key[special_key_list[i]] = TRUE;
5640 /* Initialize the keypress analyzer */
5641 for (i = 0; ignore_key_list[i]; ++i)
5643 ignore_key[ignore_key_list[i]] = TRUE;
5646 /* Determine if display is 16/256/true color */
5648 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5649 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5650 ReleaseDC(NULL, hdc);
5652 /* Initialize the colors */
5653 for (i = 0; i < 256; i++)
5657 /* Extract desired values */
5658 rv = angband_color_table[i][1];
5659 gv = angband_color_table[i][2];
5660 bv = angband_color_table[i][3];
5662 /* Extract the "complex" code */
5663 win_clr[i] = PALETTERGB(rv, gv, bv);
5665 /* Save the "simple" code */
5666 angband_color_table[i][0] = win_pal[i];
5669 /* Prepare the windows */
5675 /* Activate hooks */
5676 plog_aux = hook_plog;
5677 quit_aux = hook_quit;
5678 core_aux = hook_quit;
5680 /* Set the system suffix */
5681 ANGBAND_SYS = "win";
5683 /* Set the keyboard suffix */
5684 if (7 != GetKeyboardType(0))
5685 ANGBAND_KEYBOARD = "0";
5688 /* Japanese keyboard */
5689 switch (GetKeyboardType(1))
5691 case 0x0D01: case 0x0D02:
5692 case 0x0D03: case 0x0D04:
5693 case 0x0D05: case 0x0D06:
5695 ANGBAND_KEYBOARD = "NEC98";
5699 ANGBAND_KEYBOARD = "JAPAN";
5703 /* Catch nasty signals */
5709 /* We are now initialized */
5712 if(lpCmdLine[0] == '-'){
5713 switch(lpCmdLine[1])
5718 if (!lpCmdLine[2]) break;
5719 chuukei_server = TRUE;
5720 if(connect_chuukei_server(&lpCmdLine[2])<0){
5721 msg_print("connect fail");
5724 msg_print("connect");
5732 if (!lpCmdLine[2]) break;
5733 chuukei_client = TRUE;
5734 connect_chuukei_server(&lpCmdLine[2]);
5742 if (!lpCmdLine[2]) break;
5743 prepare_browse_movie(&lpCmdLine[2]);
5753 /* Did the user double click on a save file? */
5754 if(!chuukei_server) check_for_save_file(lpCmdLine);
5756 /* Did the user double click on a save file? */
5757 check_for_save_file(lpCmdLine);
5760 /* Prompt the user */
5762 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5764 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5769 /* Process messages forever */
5770 while (GetMessage(&msg, NULL, 0, 0))
5772 TranslateMessage(&msg);
5773 DispatchMessage(&msg);
5784 #endif /* WINDOWS */