4 * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies.
13 * This file helps Angband work with Windows computers.
15 * To use this file, use an appropriate "Makefile" or "Project File",
16 * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
17 * make sure to obtain various extra files as described below.
19 * The official compilation uses the CodeWarrior Pro compiler, which
20 * includes a special project file and precompilable header file.
23 * See also "main-dos.c" and "main-ibm.c".
26 * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
27 * and/or color redefinitions.
29 * The "lib/user/font-win.prf" contains attr/char mappings for use with the
30 * normal "lib/xtra/font/*.fon" font files.
32 * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
33 * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
37 * Compiling this file, and using the resulting executable, requires
38 * several extra files not distributed with the standard Angband code.
39 * If "USE_GRAPHICS" is defined, then "readdib.h" and "readdib.c" must
40 * be placed into "src/", and the "8X8.BMP" bitmap file must be placed
41 * into "lib/xtra/graf". In any case, some "*.fon" files (including
42 * "8X13.FON" if nothing else) must be placed into "lib/xtra/font/".
43 * If "USE_SOUND" is defined, then some special library (for example,
44 * "winmm.lib") may need to be linked in, and desired "*.WAV" sound
45 * files must be placed into "lib/xtra/sound/". All of these extra
46 * files can be found in the "ext-win" archive.
49 * The "Term_xtra_win_clear()" function should probably do a low-level
50 * clear of the current window, and redraw the borders and other things,
51 * if only for efficiency. XXX XXX XXX
53 * A simpler method is needed for selecting the "tile size" for windows.
56 * The various "warning" messages assume the existance of the "screen.w"
57 * window, I think, and only a few calls actually check for its existance,
58 * this may be okay since "NULL" means "on top of all windows". (?) The
59 * user must never be allowed to "hide" the main window, or the "menubar"
60 * will disappear. XXX XXX XXX
62 * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
63 * use with the "winhelp.exe" program. These files *may* be available
64 * at the ftp site somewhere, but I have not seen them. XXX XXX XXX
67 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
69 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
71 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
72 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
84 * Extract the "WIN32" flag from the compiler
86 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
94 * Hack -- allow use of "screen saver" mode
100 * Menu constants -- see "ANGBAND.RC"
103 #define IDM_FILE_NEW 100
104 #define IDM_FILE_OPEN 101
105 #define IDM_FILE_SAVE 110
106 #define IDM_FILE_SCORE 120
107 #define IDM_FILE_MOVIE 121
108 #define IDM_FILE_EXIT 130
110 #define IDM_WINDOW_VIS_0 200
111 #define IDM_WINDOW_VIS_1 201
112 #define IDM_WINDOW_VIS_2 202
113 #define IDM_WINDOW_VIS_3 203
114 #define IDM_WINDOW_VIS_4 204
115 #define IDM_WINDOW_VIS_5 205
116 #define IDM_WINDOW_VIS_6 206
117 #define IDM_WINDOW_VIS_7 207
119 #define IDM_WINDOW_FONT_0 210
120 #define IDM_WINDOW_FONT_1 211
121 #define IDM_WINDOW_FONT_2 212
122 #define IDM_WINDOW_FONT_3 213
123 #define IDM_WINDOW_FONT_4 214
124 #define IDM_WINDOW_FONT_5 215
125 #define IDM_WINDOW_FONT_6 216
126 #define IDM_WINDOW_FONT_7 217
128 #define IDM_WINDOW_POS_0 220
129 #define IDM_WINDOW_POS_1 221
130 #define IDM_WINDOW_POS_2 222
131 #define IDM_WINDOW_POS_3 223
132 #define IDM_WINDOW_POS_4 224
133 #define IDM_WINDOW_POS_5 225
134 #define IDM_WINDOW_POS_6 226
135 #define IDM_WINDOW_POS_7 227
137 #define IDM_WINDOW_BIZ_0 230
138 #define IDM_WINDOW_BIZ_1 231
139 #define IDM_WINDOW_BIZ_2 232
140 #define IDM_WINDOW_BIZ_3 233
141 #define IDM_WINDOW_BIZ_4 234
142 #define IDM_WINDOW_BIZ_5 235
143 #define IDM_WINDOW_BIZ_6 236
144 #define IDM_WINDOW_BIZ_7 237
146 #define IDM_WINDOW_I_WID_0 240
147 #define IDM_WINDOW_I_WID_1 241
148 #define IDM_WINDOW_I_WID_2 242
149 #define IDM_WINDOW_I_WID_3 243
150 #define IDM_WINDOW_I_WID_4 244
151 #define IDM_WINDOW_I_WID_5 245
152 #define IDM_WINDOW_I_WID_6 246
153 #define IDM_WINDOW_I_WID_7 247
155 #define IDM_WINDOW_D_WID_0 250
156 #define IDM_WINDOW_D_WID_1 251
157 #define IDM_WINDOW_D_WID_2 252
158 #define IDM_WINDOW_D_WID_3 253
159 #define IDM_WINDOW_D_WID_4 254
160 #define IDM_WINDOW_D_WID_5 255
161 #define IDM_WINDOW_D_WID_6 256
162 #define IDM_WINDOW_D_WID_7 257
164 #define IDM_WINDOW_I_HGT_0 260
165 #define IDM_WINDOW_I_HGT_1 261
166 #define IDM_WINDOW_I_HGT_2 262
167 #define IDM_WINDOW_I_HGT_3 263
168 #define IDM_WINDOW_I_HGT_4 264
169 #define IDM_WINDOW_I_HGT_5 265
170 #define IDM_WINDOW_I_HGT_6 266
171 #define IDM_WINDOW_I_HGT_7 267
173 #define IDM_WINDOW_D_HGT_0 270
174 #define IDM_WINDOW_D_HGT_1 271
175 #define IDM_WINDOW_D_HGT_2 272
176 #define IDM_WINDOW_D_HGT_3 273
177 #define IDM_WINDOW_D_HGT_4 274
178 #define IDM_WINDOW_D_HGT_5 275
179 #define IDM_WINDOW_D_HGT_6 276
180 #define IDM_WINDOW_D_HGT_7 277
182 #define IDM_OPTIONS_NO_GRAPHICS 400
183 #define IDM_OPTIONS_OLD_GRAPHICS 401
184 #define IDM_OPTIONS_NEW_GRAPHICS 402
185 #define IDM_OPTIONS_NEW2_GRAPHICS 403
186 #define IDM_OPTIONS_BIGTILE 409
187 #define IDM_OPTIONS_SOUND 410
188 #define IDM_OPTIONS_MUSIC 411
189 #define IDM_OPTIONS_SAVER 420
190 #define IDM_OPTIONS_MAP 430
191 #define IDM_OPTIONS_BG 440
192 #define IDM_OPTIONS_OPEN_BG 441
194 #define IDM_DUMP_SCREEN_HTML 450
196 #define IDM_HELP_CONTENTS 901
201 * This may need to be removed for some compilers XXX XXX XXX
208 * Exclude parts of WINDOWS.H that are not needed
210 #define NOCOMM /* Comm driver APIs and definitions */
211 #define NOLOGERROR /* LogError() and related definitions */
212 #define NOPROFILER /* Profiler APIs */
213 #define NOLFILEIO /* _l* file I/O routines */
214 #define NOOPENFILE /* OpenFile and related definitions */
215 #define NORESOURCE /* Resource management */
216 #define NOATOM /* Atom management */
217 #define NOLANGUAGE /* Character test routines */
218 #define NOLSTRING /* lstr* string management routines */
219 #define NODBCS /* Double-byte character set routines */
220 #define NOKEYBOARDINFO /* Keyboard driver routines */
221 #define NOCOLOR /* COLOR_* color values */
222 #define NODRAWTEXT /* DrawText() and related definitions */
223 #define NOSCALABLEFONT /* Truetype scalable font support */
224 #define NOMETAFILE /* Metafile support */
225 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
226 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
227 #define NOKEYSTATES /* MK_* message key state flags */
228 #define NOWH /* SetWindowsHook and related WH_* definitions */
229 #define NOCLIPBOARD /* Clipboard APIs and definitions */
230 #define NOICONS /* IDI_* icon IDs */
231 #define NOMDI /* MDI support */
232 #define NOHELP /* Help support */
234 /* Not defined since it breaks Borland C++ 5.5 */
235 /* #define NOCTLMGR */ /* Control management and controls */
238 * Exclude parts of WINDOWS.H that are not needed (Win32)
240 #define WIN32_LEAN_AND_MEAN
241 #define NONLS /* All NLS defines and routines */
242 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
243 #define NOKANJI /* Kanji support stuff. */
244 #define NOMCX /* Modem Configuration Extensions */
247 * Include the "windows" support file
252 * Exclude parts of MMSYSTEM.H that are not needed
254 #define MMNODRV /* Installable driver support */
255 #define MMNOWAVE /* Waveform support */
256 #define MMNOMIDI /* MIDI support */
257 #define MMNOAUX /* Auxiliary audio support */
258 #define MMNOTIMER /* Timer support */
259 #define MMNOJOY /* Joystick support */
260 #define MMNOMCI /* MCI support */
261 #define MMNOMMIO /* Multimedia file I/O support */
262 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
265 * Include some more files. Note: the Cygnus Cygwin compiler
266 * doesn't use mmsystem.h instead it includes the winmm library
267 * which performs a similar function.
269 #include <mmsystem.h>
273 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
274 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
276 /* #define HTML_HELP */
279 #include <htmlhelp.h>
280 #endif /* HTML_HELP */
283 * Include the support for loading bitmaps
286 # include "readdib.h"
290 * Hack -- Fake declarations from "dos.h" XXX XXX XXX
293 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
295 #define FA_LABEL 0x08 /* Volume label */
296 #define FA_DIREC 0x10 /* Directory */
297 unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
301 * Silliness in WIN32 drawing routine
304 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
308 * Silliness for Windows 95
310 #ifndef WS_EX_TOOLWINDOW
311 # define WS_EX_TOOLWINDOW 0
315 * Foreground color bits (hard-coded by DOS)
317 #define VID_BLACK 0x00
318 #define VID_BLUE 0x01
319 #define VID_GREEN 0x02
320 #define VID_CYAN 0x03
322 #define VID_MAGENTA 0x05
323 #define VID_YELLOW 0x06
324 #define VID_WHITE 0x07
327 * Bright text (hard-coded by DOS)
329 #define VID_BRIGHT 0x08
332 * Background color bits (hard-coded by DOS)
334 #define VUD_BLACK 0x00
335 #define VUD_BLUE 0x10
336 #define VUD_GREEN 0x20
337 #define VUD_CYAN 0x30
339 #define VUD_MAGENTA 0x50
340 #define VUD_YELLOW 0x60
341 #define VUD_WHITE 0x70
344 * Blinking text (hard-coded by DOS)
346 #define VUD_BRIGHT 0x80
352 typedef struct _term_data term_data;
357 * Note the use of "font_want" for the names of the font file requested by
358 * the user, and the use of "font_file" for the currently active font file.
360 * The "font_file" is uppercased, and takes the form "8X13.FON", while
361 * "font_want" can be in almost any form as long as it could be construed
362 * as attempting to represent the name of a font.
377 uint rows; /* int -> uint */
413 #if 1 /* #ifdef JP */
428 * Maximum number of windows XXX XXX XXX
430 #define MAX_TERM_DATA 8
433 * An array of term_data's
435 static term_data data[MAX_TERM_DATA];
438 * Hack -- global "window creation" pointer
440 static term_data *my_td;
443 * Remember normal size of main window when maxmized
448 * was main window maximized on previous playing
450 bool win_maximized = FALSE;
455 bool game_in_progress = FALSE;
458 * note when "open"/"new" become valid
460 bool initialized = FALSE;
463 * screen paletted, i.e. 256 colors
465 bool paletted = FALSE;
468 * 16 colors screen, don't use RGB()
470 bool colors16 = FALSE;
473 * Saved instance handle
475 static HINSTANCE hInstance;
478 * Yellow brush for the cursor
480 static HBRUSH hbrYellow;
490 static HPALETTE hPal;
493 static HBITMAP hBG = NULL;
494 static int use_bg = 0;
495 static char bg_bitmap_file[1024] = "bg.bmp";
500 * The screen saver window
502 static HWND hwndSaver;
504 #endif /* USE_SAVER */
510 * Flag set once "graphics" has been initialized
512 static bool can_use_graphics = FALSE;
517 static DIBINIT infGraph;
520 * The global bitmap mask
522 static DIBINIT infMask;
524 #endif /* USE_GRAPHICS */
530 * Flag set once "sound" has been initialized
532 static bool can_use_sound = FALSE;
536 * An array of sound file names
538 static cptr sound_file[SOUND_MAX][SAMPLE_MAX];
540 #endif /* USE_SOUND */
546 #define SAMPLE_MUSIC_MAX 16
547 static cptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
548 static bool can_use_music = FALSE;
550 #endif /* USE_MUSIC */
554 * Full path to ANGBAND.INI
556 static cptr ini_file = NULL;
559 * Name of application
561 static cptr AppName = "ANGBAND";
564 * Name of sub-window type
566 static cptr AngList = "AngList";
571 static cptr ANGBAND_DIR_XTRA_GRAF;
572 static cptr ANGBAND_DIR_XTRA_SOUND;
573 static cptr ANGBAND_DIR_XTRA_MUSIC;
574 static cptr ANGBAND_DIR_XTRA_HELP;
575 #if 0 /* #ifndef JP */
576 static cptr ANGBAND_DIR_XTRA_FONT;
579 static cptr ANGBAND_DIR_XTRA_MUSIC;
584 * The "complex" color values
586 static COLORREF win_clr[256];
590 * Flag for macro trigger with dump ASCII
592 static bool Term_no_press = FALSE;
597 static bool mouse_down = FALSE;
598 static bool paint_rect = FALSE;
599 static int mousex = 0, mousey = 0;
600 static int oldx, oldy;
604 * The "simple" color values
606 * See "main-ibm.c" for original table information
608 * The entries below are taken from the "color bits" defined above.
610 * Note that many of the choices below suck, but so do crappy monitors.
612 static BYTE win_pal[256] =
614 VID_BLACK, /* Dark */
615 VID_WHITE, /* White */
616 VID_CYAN, /* Slate XXX */
617 VID_RED | VID_BRIGHT, /* Orange XXX */
619 VID_GREEN, /* Green */
621 VID_YELLOW, /* Umber XXX */
622 VID_BLACK | VID_BRIGHT, /* Light Dark */
623 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
624 VID_MAGENTA, /* Violet XXX */
625 VID_YELLOW | VID_BRIGHT, /* Yellow */
626 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
627 VID_GREEN | VID_BRIGHT, /* Light Green */
628 VID_BLUE | VID_BRIGHT, /* Light Blue */
629 VID_YELLOW /* Light Umber XXX */
634 * Hack -- define which keys are "special"
636 static bool special_key[256];
637 static bool ignore_key[256];
641 * Hack -- initialization list for "special_key"
643 static byte special_key_list[] = {
644 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
645 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
646 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
647 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
648 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
649 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
650 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
651 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
652 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
653 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
654 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
655 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
656 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
657 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
658 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
659 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
660 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
665 static byte ignore_key_list[] = {
666 VK_ESCAPE, VK_TAB, VK_SPACE,
667 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
668 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
669 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
675 * Hack -- initialization list for "special_key"
677 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
678 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
679 * catch the keypad keys (with and without numlock set, including keypad 5),
680 * the function keys (including the "menu" key which maps to F10), and the
681 * "pause" key (between scroll lock and numlock). We also catch a few odd
682 * keys which I do not recognize, but which are listed among keys which we
683 * do catch, so they should be harmless to catch.
685 static byte special_key_list[] =
687 VK_CLEAR, /* 0x0C (KP<5>) */
689 VK_PAUSE, /* 0x13 (pause) */
691 VK_PRIOR, /* 0x21 (KP<9>) */
692 VK_NEXT, /* 0x22 (KP<3>) */
693 VK_END, /* 0x23 (KP<1>) */
694 VK_HOME, /* 0x24 (KP<7>) */
695 VK_LEFT, /* 0x25 (KP<4>) */
696 VK_UP, /* 0x26 (KP<8>) */
697 VK_RIGHT, /* 0x27 (KP<6>) */
698 VK_DOWN, /* 0x28 (KP<2>) */
699 VK_SELECT, /* 0x29 (?????) */
700 VK_PRINT, /* 0x2A (?????) */
701 VK_EXECUTE, /* 0x2B (?????) */
702 VK_SNAPSHOT, /* 0x2C (?????) */
703 VK_INSERT, /* 0x2D (KP<0>) */
704 VK_DELETE, /* 0x2E (KP<.>) */
705 VK_HELP, /* 0x2F (?????) */
707 VK_NUMPAD0, /* 0x60 (KP<0>) */
708 VK_NUMPAD1, /* 0x61 (KP<1>) */
709 VK_NUMPAD2, /* 0x62 (KP<2>) */
710 VK_NUMPAD3, /* 0x63 (KP<3>) */
711 VK_NUMPAD4, /* 0x64 (KP<4>) */
712 VK_NUMPAD5, /* 0x65 (KP<5>) */
713 VK_NUMPAD6, /* 0x66 (KP<6>) */
714 VK_NUMPAD7, /* 0x67 (KP<7>) */
715 VK_NUMPAD8, /* 0x68 (KP<8>) */
716 VK_NUMPAD9, /* 0x69 (KP<9>) */
717 VK_MULTIPLY, /* 0x6A (KP<*>) */
718 VK_ADD, /* 0x6B (KP<+>) */
719 VK_SEPARATOR, /* 0x6C (?????) */
720 VK_SUBTRACT, /* 0x6D (KP<->) */
721 VK_DECIMAL, /* 0x6E (KP<.>) */
722 VK_DIVIDE, /* 0x6F (KP</>) */
753 static void delete_bg(void)
762 static int init_bg(void)
764 char * bmfile = bg_bitmap_file;
767 if (use_bg == 0) return 0;
769 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
772 plog_fmt("ÊÉ»æÍÑ¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
774 plog_fmt("Can't load the bitmap file '%s'.", bmfile);
780 HDC wnddc, dcimage, dcbg;
781 HBITMAP bmimage, bmimage_old, bmbg_old;
787 dcimage = CreateCompatibleDC(wnddc);
788 dcbg = CreateCompatibleDC(wnddc);
790 bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
791 if (!bmimage) quit("bg.bmp¤¬Æɤߤ³¤á¤Ê¤¤¡ª");
792 bmimage_old = SelectObject(dcimage, bmimage);
794 CreateCompatibleBitmap();
796 ReleaseDC(hwnd, wnddc);
802 static void DrawBG(HDC hdc, RECT *r)
807 int x = r->left, y = r->top;
808 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
814 GetObject(hBG, sizeof(bm), &bm);
815 swid = bm.bmWidth; shgt = bm.bmHeight;
817 hdcSrc = CreateCompatibleDC(hdc);
818 hOld = SelectObject(hdcSrc, hBG);
822 cwid = MIN(swid - sx, r->right - nx);
825 chgt = MIN(shgt - sy, r->bottom - ny);
826 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
828 } while (ny < r->bottom);
831 } while (nx < r->right);
833 SelectObject(hdcSrc, hOld);
839 * Hack -- given a pathname, point at the filename
841 static cptr extract_file_name(cptr s)
845 /* Start at the end */
846 p = s + strlen(s) - 1;
848 /* Back up to divider */
849 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
851 /* Return file name */
858 * Hack -- given a simple filename, extract the "font size" info
860 * Return a pointer to a static buffer holding the capitalized base name.
862 #if 0 /* #ifndef JP */
863 static char *analyze_font(char *path, int *wp, int *hp)
869 /* Start at the end */
870 p = path + strlen(path) - 1;
872 /* Back up to divider */
873 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
875 /* Advance to file name */
881 /* Capitalize (be paranoid) */
882 if (islower(*s)) *s = toupper(*s);
886 s = my_strchr(p, 'X');
888 /* Extract font width */
892 hgt = s ? atoi(s+1) : 0;
905 * Check for existance of a file
907 static bool check_file(cptr s)
927 attrib = GetFileAttributes(path);
929 /* Require valid filename */
930 if (attrib == INVALID_FILE_NAME) return (FALSE);
932 /* Prohibit directory */
933 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
937 /* Examine and verify */
938 if (_dos_getfileattr(path, &attrib)) return (FALSE);
940 /* Prohibit something */
941 if (attrib & FA_LABEL) return (FALSE);
943 /* Prohibit directory */
944 if (attrib & FA_DIREC) return (FALSE);
954 * Check for existance of a directory
956 static bool check_dir(cptr s)
978 /* Remove trailing backslash */
979 if (i && (path[i-1] == '\\')) path[--i] = '\0';
984 attrib = GetFileAttributes(path);
986 /* Require valid filename */
987 if (attrib == INVALID_FILE_NAME) return (FALSE);
989 /* Require directory */
990 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
994 /* Examine and verify */
995 if (_dos_getfileattr(path, &attrib)) return (FALSE);
997 /* Prohibit something */
998 if (attrib & FA_LABEL) return (FALSE);
1000 /* Require directory */
1001 if (!(attrib & FA_DIREC)) return (FALSE);
1013 static void validate_file(cptr s)
1015 /* Verify or fail */
1019 quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
1021 quit_fmt("Cannot find required file:\n%s", s);
1029 * Validate a directory
1031 static void validate_dir(cptr s, bool vital)
1033 /* Verify or fail */
1036 /* This directory contains needed data */
1040 quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
1042 quit_fmt("Cannot find required directory:\n%s", s);
1046 /* Attempt to create this directory */
1049 quit_fmt("Unable to create directory:\n%s", s);
1056 * Get the "size" for a window
1058 static void term_getsize(term_data *td)
1065 if (td->cols < 1) td->cols = 1;
1066 if (td->rows < 1) td->rows = 1;
1069 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1070 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1072 /* Fake window size */
1074 rc.right = rc.left + wid;
1076 rc.bottom = rc.top + hgt;
1079 /* rc.right += 1; */
1080 /* rc.bottom += 1; */
1083 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1086 td->size_wid = rc.right - rc.left;
1087 td->size_hgt = rc.bottom - rc.top;
1089 /* See CreateWindowEx */
1092 /* Extract actual location */
1093 GetWindowRect(td->w, &rc);
1095 /* Save the location */
1096 td->pos_x = rc.left;
1102 * Write the "prefs" for a single term
1104 static void save_prefs_aux(int i)
1106 term_data *td = &data[i];
1111 WINDOWPLACEMENT lpwndpl;
1116 /* Make section name */
1117 sprintf(sec_name, "Term-%d", i);
1122 strcpy(buf, td->visible ? "1" : "0");
1123 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1128 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1131 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1133 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1137 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1139 #if 1 /* #ifdef JP */
1140 wsprintf(buf, "%d", td->lf.lfWidth);
1141 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1142 wsprintf(buf, "%d", td->lf.lfHeight);
1143 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1144 wsprintf(buf, "%d", td->lf.lfWeight);
1145 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1148 strcpy(buf, td->bizarre ? "1" : "0");
1149 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1152 wsprintf(buf, "%d", td->tile_wid);
1153 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1156 wsprintf(buf, "%d", td->tile_hgt);
1157 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1159 /* Get window placement and dimensions */
1160 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1161 GetWindowPlacement(td->w, &lpwndpl);
1163 /* Acquire position in *normal* mode (not minimized) */
1164 rc = lpwndpl.rcNormalPosition;
1166 /* Window size (x) */
1167 if (i == 0) wsprintf(buf, "%d", normsize.x);
1168 else wsprintf(buf, "%d", td->cols);
1169 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1171 /* Window size (y) */
1172 if (i == 0) wsprintf(buf, "%d", normsize.y);
1173 else wsprintf(buf, "%d", td->rows);
1174 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1176 /* Maxmized (only main window) */
1179 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1180 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1183 /* Acquire position */
1184 GetWindowRect(td->w, &rc);
1186 /* Window position (x) */
1187 wsprintf(buf, "%d", rc.left);
1188 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1190 /* Window position (y) */
1191 wsprintf(buf, "%d", rc.top);
1192 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1194 /* Window Z position */
1197 strcpy(buf, td->posfix ? "1" : "0");
1198 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1206 * We assume that the windows have all been initialized
1208 static void save_prefs(void)
1214 /* Save the "arg_graphics" flag */
1215 sprintf(buf, "%d", arg_graphics);
1216 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1218 /* Save the "arg_bigtile" flag */
1219 strcpy(buf, arg_bigtile ? "1" : "0");
1220 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1222 /* Save the "arg_sound" flag */
1223 strcpy(buf, arg_sound ? "1" : "0");
1224 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1226 /* Save the "arg_sound" flag */
1227 strcpy(buf, arg_music ? "1" : "0");
1228 WritePrivateProfileString("Angband", "Music", buf, ini_file);
1231 strcpy(buf, use_bg ? "1" : "0");
1232 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1233 WritePrivateProfileString("Angband", "BackGroundBitmap",
1234 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1236 /* Save window prefs */
1237 for (i = 0; i < MAX_TERM_DATA; ++i)
1245 * Load the "prefs" for a single term
1247 static void load_prefs_aux(int i)
1249 term_data *td = &data[i];
1253 int wid, hgt, posx, posy;
1254 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1255 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1259 /* Make section name */
1260 sprintf(sec_name, "Term-%d", i);
1262 /* Make section name */
1263 sprintf(sec_name, "Term-%d", i);
1268 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1271 /* Desired font, with default */
1273 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1276 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1278 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1284 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1286 /* Analyze font, save desired font name */
1287 #if 1 /* #ifdef JP */
1288 td->font_want = string_make(tmp);
1290 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1291 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1292 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1294 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1299 #if 1 /* #ifdef JP */
1300 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1301 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1303 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1304 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1309 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1310 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1311 normsize.x = td->cols; normsize.y = td->rows;
1316 win_maximized = GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file);
1319 /* Window position */
1320 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1321 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1322 td->pos_x = MIN(MAX(0, posx), dispx-128);
1323 td->pos_y = MIN(MAX(0, posy), dispy-128);
1325 /* Window Z position */
1328 td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1336 static void load_prefs(void)
1340 /* Extract the "arg_graphics" flag */
1341 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1343 /* Extract the "arg_bigtile" flag */
1344 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1345 use_bigtile = arg_bigtile;
1347 /* Extract the "arg_sound" flag */
1348 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1350 /* Extract the "arg_sound" flag */
1351 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1354 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1355 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1357 /* Load window prefs */
1358 for (i = 0; i < MAX_TERM_DATA; ++i)
1364 #if defined(USE_SOUND) || defined(USE_MUSIC)
1367 * XXX XXX XXX - Taken from files.c.
1369 * Extract "tokens" from a buffer
1371 * This function uses "whitespace" as delimiters, and treats any amount of
1372 * whitespace as a single delimiter. We will never return any empty tokens.
1373 * When given an empty buffer, or a buffer containing only "whitespace", we
1374 * will return no tokens. We will never extract more than "num" tokens.
1376 * By running a token through the "text_to_ascii()" function, you can allow
1377 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1379 * We save pointers to the tokens in "tokens", and return the number found.
1381 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1393 /* Skip leading whitespace */
1394 for ( ; *s && iswspace(*s); ++s) /* loop */;
1399 /* Find next whitespace, if any */
1400 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1402 /* Nuke and advance (if necessary) */
1403 if (*t) *t++ = '\0';
1405 /* Save the token */
1416 #endif /* USE_SOUND || USE_MUSIC */
1420 static void load_sound_prefs(void)
1424 char ini_path[1024];
1425 char wav_path[1024];
1426 char *zz[SAMPLE_MAX];
1428 /* Access the sound.cfg */
1430 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1432 for (i = 0; i < SOUND_MAX; i++)
1434 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1436 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1438 for (j = 0; j < num; j++)
1440 /* Access the sound */
1441 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1443 /* Save the sound filename, if it exists */
1444 if (check_file(wav_path))
1445 sound_file[i][j] = string_make(zz[j]);
1450 #endif /* USE_SOUND */
1454 static void load_music_prefs(void)
1458 char ini_path[1024];
1459 char wav_path[1024];
1460 char *zz[SAMPLE_MAX];
1462 /* Access the music.cfg */
1464 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1466 for (i = 0; i < MUSIC_BASIC_MAX; i++)
1468 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1470 num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1472 for (j = 0; j < num; j++)
1474 /* Access the sound */
1475 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1477 /* Save the sound filename, if it exists */
1478 if (check_file(wav_path))
1479 music_file[i][j] = string_make(zz[j]);
1484 #endif /* USE_MUSIC */
1487 * Create the new global palette based on the bitmap palette
1488 * (if any), and the standard 16 entry palette derived from
1489 * "win_clr[]" which is used for the basic 16 Angband colors.
1491 * This function is never called before all windows are ready.
1493 * This function returns FALSE if the new palette could not be
1494 * prepared, which should normally be a fatal error. XXX XXX
1496 * Note that only some machines actually use a "palette".
1498 static int new_palette(void)
1506 LPLOGPALETTE pLogPal;
1507 LPPALETTEENTRY lppe;
1512 /* This makes no sense */
1513 if (!paletted) return (TRUE);
1523 /* Check the bitmap palette */
1524 hBmPal = infGraph.hPalette;
1526 /* Use the bitmap */
1529 lppeSize = 256 * sizeof(PALETTEENTRY);
1530 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1531 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1532 if ((nEntries == 0) || (nEntries > 220))
1536 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1538 plog("Please switch to high- or true-color mode.");
1543 rnfree(lppe, lppeSize);
1550 #endif /* USE_GRAPHICS */
1552 /* Size of palette */
1553 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1555 /* Allocate palette */
1556 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1559 pLogPal->palVersion = 0x300;
1561 /* Make room for bitmap and normal data */
1562 pLogPal->palNumEntries = nEntries + 16;
1564 /* Save the bitmap data */
1565 for (i = 0; i < nEntries; i++)
1567 pLogPal->palPalEntry[i] = lppe[i];
1570 /* Save the normal data */
1571 for (i = 0; i < 16; i++)
1575 /* Access the entry */
1576 p = &(pLogPal->palPalEntry[i+nEntries]);
1578 /* Save the colors */
1579 p->peRed = GetRValue(win_clr[i]);
1580 p->peGreen = GetGValue(win_clr[i]);
1581 p->peBlue = GetBValue(win_clr[i]);
1583 /* Save the flags */
1584 p->peFlags = PC_NOCOLLAPSE;
1587 /* Free something */
1588 if (lppe) rnfree(lppe, lppeSize);
1590 /* Create a new palette, or fail */
1591 hNewPal = CreatePalette(pLogPal);
1593 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1595 if (!hNewPal) quit("Cannot create palette!");
1599 /* Free the palette */
1600 rnfree(pLogPal, pLogPalSize);
1605 /* Realize the palette */
1607 SelectPalette(hdc, hNewPal, 0);
1608 i = RealizePalette(hdc);
1609 ReleaseDC(td->w, hdc);
1611 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1613 if (i == 0) quit("Cannot realize palette!");
1618 for (i = 1; i < MAX_TERM_DATA; i++)
1623 SelectPalette(hdc, hNewPal, 0);
1624 ReleaseDC(td->w, hdc);
1627 /* Delete old palette */
1628 if (hPal) DeleteObject(hPal);
1630 /* Save new palette */
1640 * Initialize graphics
1642 static bool init_graphics(void)
1644 /* Initialize once */
1645 /* if (can_use_graphics != arg_graphics) */
1651 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1658 ANGBAND_GRAF = "new";
1660 else if (arg_graphics == GRAPHICS_HENGBAND)
1667 ANGBAND_GRAF = "ne2";
1675 ANGBAND_GRAF = "old";
1678 /* Access the bitmap file */
1679 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1681 /* Load the bitmap or quit */
1682 if (!ReadDIB(data[0].w, buf, &infGraph))
1685 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1687 plog_fmt("Cannot read bitmap file '%s'", name);
1693 /* Save the new sizes */
1694 infGraph.CellWidth = wid;
1695 infGraph.CellHeight = hgt;
1697 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1699 /* Access the mask file */
1700 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1702 /* Load the bitmap or quit */
1703 if (!ReadDIB(data[0].w, buf, &infMask))
1705 plog_fmt("Cannot read bitmap file '%s'", buf);
1709 if (arg_graphics == GRAPHICS_HENGBAND)
1711 /* Access the mask file */
1712 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1714 /* Load the bitmap or quit */
1715 if (!ReadDIB(data[0].w, buf, &infMask))
1717 plog_fmt("Cannot read bitmap file '%s'", buf);
1722 /* Activate a palette */
1725 /* Free bitmap XXX XXX XXX */
1729 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1731 plog("Cannot activate palette!");
1737 /* Graphics available */
1738 can_use_graphics = arg_graphics;
1742 return (can_use_graphics);
1744 #endif /* USE_GRAPHICS */
1751 static bool init_music(void)
1753 /* Initialize once */
1756 /* Load the prefs */
1759 /* Sound available */
1760 can_use_music = TRUE;
1764 return (can_use_music);
1766 #endif /* USE_SOUND */
1772 static bool init_sound(void)
1774 /* Initialize once */
1777 /* Load the prefs */
1780 /* Sound available */
1781 can_use_sound = TRUE;
1785 return (can_use_sound);
1787 #endif /* USE_SOUND */
1793 static void term_window_resize(term_data *td)
1795 /* Require window */
1798 /* Resize the window */
1799 SetWindowPos(td->w, 0, 0, 0,
1800 td->size_wid, td->size_hgt,
1801 SWP_NOMOVE | SWP_NOZORDER);
1804 InvalidateRect(td->w, NULL, TRUE);
1809 * Force the use of a new "font file" for a term_data
1811 * This function may be called before the "window" is ready
1813 * This function returns zero only if everything succeeds.
1815 * Note that the "font name" must be capitalized!!!
1817 static errr term_force_font(term_data *td, cptr path)
1821 #if 0 /* #ifndef JP */
1827 /* Forget the old font (if needed) */
1828 if (td->font_id) DeleteObject(td->font_id);
1830 #if 1 /* #ifdef JP */
1834 /* Create the font (using the 'base' of the font file name!) */
1835 td->font_id = CreateFontIndirect(&(td->lf));
1836 wid = td->lf.lfWidth;
1837 hgt = td->lf.lfHeight;
1838 if (!td->font_id) return (1);
1840 /* Forget old font */
1846 for (i = 0; i < MAX_TERM_DATA; i++)
1848 /* Don't check when closing the application */
1851 /* Check "screen" */
1852 if ((td != &data[i]) &&
1853 (data[i].font_file) &&
1854 (streq(data[i].font_file, td->font_file)))
1860 /* Remove unused font resources */
1861 if (!used) RemoveFontResource(td->font_file);
1863 /* Free the old name */
1864 string_free(td->font_file);
1867 td->font_file = NULL;
1871 if (!path) return (1);
1876 /* Analyze font path */
1877 base = analyze_font(buf, &wid, &hgt);
1880 if (!suffix(base, ".FON")) return (1);
1883 if (!check_file(buf)) return (1);
1885 /* Load the new font */
1886 if (!AddFontResource(buf)) return (1);
1888 /* Save new font name */
1889 td->font_file = string_make(base);
1891 /* Remove the "suffix" */
1892 base[strlen(base)-4] = '\0';
1894 /* Create the font (using the 'base' of the font file name!) */
1895 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1896 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1897 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1898 FIXED_PITCH | FF_DONTCARE, base);
1901 /* Hack -- Unknown size */
1908 /* all this trouble to get the cell size */
1909 hdcDesktop = GetDC(HWND_DESKTOP);
1910 hfOld = SelectObject(hdcDesktop, td->font_id);
1911 GetTextMetrics(hdcDesktop, &tm);
1912 SelectObject(hdcDesktop, hfOld);
1913 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1915 /* Font size info */
1916 wid = tm.tmAveCharWidth;
1920 /* Save the size info */
1931 * Allow the user to change the font for this window.
1933 static void term_change_font(term_data *td)
1935 #if 1 /* #ifdef JP */
1938 memset(&cf, 0, sizeof(cf));
1939 cf.lStructSize = sizeof(cf);
1940 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1941 cf.lpLogFont = &(td->lf);
1943 if (ChooseFont(&cf))
1945 /* Force the font */
1946 term_force_font(td, NULL);
1948 /* Assume not bizarre */
1951 /* Reset the tile info */
1952 td->tile_wid = td->font_wid;
1953 td->tile_hgt = td->font_hgt;
1955 /* Analyze the font */
1958 /* Resize the window */
1959 term_window_resize(td);
1965 char tmp[1024] = "";
1967 /* Extract a default if possible */
1968 if (td->font_file) strcpy(tmp, td->font_file);
1970 /* Ask for a choice */
1971 memset(&ofn, 0, sizeof(ofn));
1972 ofn.lStructSize = sizeof(ofn);
1973 ofn.hwndOwner = data[0].w;
1974 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1975 ofn.nFilterIndex = 1;
1976 ofn.lpstrFile = tmp;
1978 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1979 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1980 ofn.lpstrDefExt = "fon";
1982 /* Force choice if legal */
1983 if (GetOpenFileName(&ofn))
1985 /* Force the font */
1986 if (term_force_font(td, tmp))
1988 /* Access the standard font file */
1989 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1991 /* Force the use of that font */
1992 (void)term_force_font(td, tmp);
1995 /* Assume not bizarre */
1996 td->bizarre = FALSE;
1998 /* Reset the tile info */
1999 td->tile_wid = td->font_wid;
2000 td->tile_hgt = td->font_hgt;
2002 /* Analyze the font */
2005 /* Resize the window */
2006 term_window_resize(td);
2013 * Allow the user to lock this window.
2015 static void term_window_pos(term_data *td, HWND hWnd)
2017 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
2018 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
2021 static void windows_map(void);
2024 * Hack -- redraw a term_data
2026 static void term_data_redraw(term_data *td)
2030 /* Redraw the map */
2035 /* Activate the term */
2036 Term_activate(&td->t);
2038 /* Redraw the contents */
2041 /* Restore the term */
2042 Term_activate(term_screen);
2047 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2051 HBRUSH myBrush, oldBrush;
2053 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2054 int tx = td->size_ow1 + x * td->tile_wid;
2055 int ty = td->size_oh1 + y * td->tile_hgt;
2056 int tw = w * td->tile_wid - 1;
2057 int th = h * td->tile_hgt - 1;
2060 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2061 oldBrush = SelectObject(hdc, myBrush);
2062 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2064 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2066 SelectObject(hdc, oldBrush);
2067 SelectObject(hdc, oldPen);
2072 /*** Function hooks needed by "Term" ***/
2078 * Initialize a new Term
2080 static void Term_init_win(term *t)
2089 static void Term_nuke_win(term *t)
2098 * Interact with the User
2100 static errr Term_user_win(int n)
2111 * React to global changes
2113 static errr Term_xtra_win_react(void)
2121 /* Save the default colors */
2122 for (i = 0; i < 256; i++)
2124 /* Simply accept the desired colors */
2125 win_pal[i] = angband_color_table[i][0];
2136 bool change = FALSE;
2138 /* Save the default colors */
2139 for (i = 0; i < 256; i++)
2141 /* Extract desired values */
2142 rv = angband_color_table[i][1];
2143 gv = angband_color_table[i][2];
2144 bv = angband_color_table[i][3];
2146 /* Extract a full color code */
2147 code = PALETTERGB(rv, gv, bv);
2149 /* Activate changes */
2150 if (win_clr[i] != code)
2152 /* Note the change */
2155 /* Apply the desired color */
2160 /* Activate the palette if needed */
2161 if (change) (void)new_palette();
2167 /* Handle "arg_sound" */
2168 if (use_sound != arg_sound)
2170 /* Initialize (if needed) */
2171 if (arg_sound && !init_sound())
2175 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
2177 plog("Cannot initialize sound!");
2185 /* Change setting */
2186 use_sound = arg_sound;
2193 /* Handle "arg_sound" */
2194 if (use_music != arg_music)
2196 /* Initialize (if needed) */
2197 if (arg_music && !init_music())
2201 plog("BGM¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
2203 plog("Cannot initialize BGM!");
2209 /* Change setting */
2210 use_music = arg_music;
2218 /* Handle "arg_graphics" */
2219 if (use_graphics != arg_graphics)
2221 /* Initialize (if needed) */
2222 if (arg_graphics && !init_graphics())
2226 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
2228 plog("Cannot initialize graphics!");
2233 arg_graphics = GRAPHICS_NONE;
2236 /* Change setting */
2237 use_graphics = arg_graphics;
2240 #ifdef ANGBAND_2_8_1
2242 #else /* ANGBAND_2_8_1 */
2243 reset_visuals(TRUE);
2244 #endif /* ANGBAND_2_8_1 */
2247 #endif /* USE_GRAPHICS */
2250 /* Clean up windows */
2251 for (i = 0; i < MAX_TERM_DATA; i++)
2255 term_data *td = &data[i];
2257 /* Update resized windows */
2258 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2261 Term_activate(&td->t);
2263 /* Hack -- Resize the term */
2264 Term_resize(td->cols, td->rows);
2266 /* Redraw the contents */
2281 * Process at least one event
2283 static errr Term_xtra_win_event(int v)
2287 /* Wait for an event */
2291 if (GetMessage(&msg, NULL, 0, 0))
2293 TranslateMessage(&msg);
2294 DispatchMessage(&msg);
2298 /* Check for an event */
2302 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2304 TranslateMessage(&msg);
2305 DispatchMessage(&msg);
2315 * Process all pending events
2317 static errr Term_xtra_win_flush(void)
2321 /* Process all pending events */
2322 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2324 TranslateMessage(&msg);
2325 DispatchMessage(&msg);
2334 * Hack -- clear the screen
2336 * Make this more efficient XXX XXX XXX
2338 static errr Term_xtra_win_clear(void)
2340 term_data *td = (term_data*)(Term->data);
2345 /* Rectangle to erase */
2346 rc.left = td->size_ow1;
2347 rc.right = rc.left + td->cols * td->tile_wid;
2348 rc.top = td->size_oh1;
2349 rc.bottom = rc.top + td->rows * td->tile_hgt;
2353 SetBkColor(hdc, RGB(0, 0, 0));
2354 SelectObject(hdc, td->font_id);
2355 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2360 rc.left = 0; rc.top = 0;
2363 ReleaseDC(td->w, hdc);
2371 * Hack -- make a noise
2373 static errr Term_xtra_win_noise(void)
2375 MessageBeep(MB_ICONASTERISK);
2381 * Hack -- make a sound
2383 static errr Term_xtra_win_sound(int v)
2388 #endif /* USE_SOUND */
2390 /* Sound disabled */
2391 if (!use_sound) return (1);
2394 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2398 /* Count the samples */
2399 for (i = 0; i < SAMPLE_MAX; i++)
2401 if (!sound_file[v][i])
2406 if (i == 0) return (1);
2408 /* Build the path */
2409 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2413 /* Play the sound, catch errors */
2414 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2418 /* Play the sound, catch errors */
2419 return (sndPlaySound(buf, SND_ASYNC));
2423 #else /* USE_SOUND */
2428 #endif /* USE_SOUND */
2432 * Hack -- play a music
2434 static errr Term_xtra_win_music(int v)
2439 static MCI_OPEN_PARMS mop;
2440 #endif /* USE_MUSIC */
2442 /* Sound disabled */
2443 if (!use_music) return (1);
2446 if ((v < 0) || (v >= MUSIC_BASIC_MAX)) return (1);
2450 /* Count the samples */
2451 for (i = 0; i < SAMPLE_MAX; i++)
2453 if (!music_file[v][i])
2458 if (i == 0) return (1);
2460 /* Build the path */
2461 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
2463 #endif /* USE_MUSIC */
2467 mop.lpstrDeviceType = "WaveAudio";
2468 mop.lpstrElementName = buf;
2469 mciSendCommand(NULL, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
2470 mciSendCommand(mop.wDeviceID,MCI_PLAY,0,0);
2473 #else /* USE_MUSIC */
2478 #endif /* USE_MUSIC */
2483 * Delay for "x" milliseconds
2485 static int Term_xtra_win_delay(int v)
2499 t = GetTickCount() + v;
2502 while (GetTickCount() < t)
2504 /* Handle messages */
2505 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2507 TranslateMessage(&msg);
2508 DispatchMessage(&msg);
2520 * Do a "special thing"
2522 static errr Term_xtra_win(int n, int v)
2524 /* Handle a subset of the legal requests */
2527 /* Make a bell sound */
2528 case TERM_XTRA_NOISE:
2530 return (Term_xtra_win_noise());
2534 case TERM_XTRA_MUSIC:
2536 return (Term_xtra_win_music(v));
2539 /* Make a special sound */
2540 case TERM_XTRA_SOUND:
2542 return (Term_xtra_win_sound(v));
2545 /* Process random events */
2546 case TERM_XTRA_BORED:
2548 return (Term_xtra_win_event(0));
2551 /* Process an event */
2552 case TERM_XTRA_EVENT:
2554 return (Term_xtra_win_event(v));
2557 /* Flush all events */
2558 case TERM_XTRA_FLUSH:
2560 return (Term_xtra_win_flush());
2563 /* Clear the screen */
2564 case TERM_XTRA_CLEAR:
2566 return (Term_xtra_win_clear());
2569 /* React to global changes */
2570 case TERM_XTRA_REACT:
2572 return (Term_xtra_win_react());
2575 /* Delay for some milliseconds */
2576 case TERM_XTRA_DELAY:
2578 return (Term_xtra_win_delay(v));
2589 * Low level graphics (Assumes valid input).
2591 * Draw a "cursor" at (x,y), using a "yellow box".
2593 static errr Term_curs_win(int x, int y)
2595 term_data *td = (term_data*)(Term->data);
2600 int tile_wid, tile_hgt;
2604 tile_wid = td->map_tile_wid;
2605 tile_hgt = td->map_tile_hgt;
2609 tile_wid = td->tile_wid;
2610 tile_hgt = td->tile_hgt;
2613 /* Frame the grid */
2614 rc.left = x * tile_wid + td->size_ow1;
2615 rc.right = rc.left + tile_wid;
2616 rc.top = y * tile_hgt + td->size_oh1;
2617 rc.bottom = rc.top + tile_hgt;
2619 /* Cursor is done as a yellow "box" */
2621 FrameRect(hdc, &rc, hbrYellow);
2622 ReleaseDC(td->w, hdc);
2630 * Low level graphics (Assumes valid input).
2632 * Draw a "big cursor" at (x,y), using a "yellow box".
2634 static errr Term_bigcurs_win(int x, int y)
2636 term_data *td = (term_data*)(Term->data);
2641 int tile_wid, tile_hgt;
2645 /* Normal cursor in map window */
2646 Term_curs_win(x, y);
2651 tile_wid = td->tile_wid;
2652 tile_hgt = td->tile_hgt;
2655 /* Frame the grid */
2656 rc.left = x * tile_wid + td->size_ow1;
2657 rc.right = rc.left + 2 * tile_wid;
2658 rc.top = y * tile_hgt + td->size_oh1;
2659 rc.bottom = rc.top + tile_hgt;
2661 /* Cursor is done as a yellow "box" */
2663 FrameRect(hdc, &rc, hbrYellow);
2664 ReleaseDC(td->w, hdc);
2672 * Low level graphics (Assumes valid input).
2674 * Erase a "block" of "n" characters starting at (x,y).
2676 static errr Term_wipe_win(int x, int y, int n)
2678 term_data *td = (term_data*)(Term->data);
2683 /* Rectangle to erase in client coords */
2684 rc.left = x * td->tile_wid + td->size_ow1;
2685 rc.right = rc.left + n * td->tile_wid;
2686 rc.top = y * td->tile_hgt + td->size_oh1;
2687 rc.bottom = rc.top + td->tile_hgt;
2690 SetBkColor(hdc, RGB(0, 0, 0));
2691 SelectObject(hdc, td->font_id);
2696 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2697 ReleaseDC(td->w, hdc);
2705 * Low level graphics. Assumes valid input.
2707 * Draw several ("n") chars, with an attr, at a given location.
2709 * All "graphic" data is handled by "Term_pict_win()", below.
2711 * One would think there is a more efficient method for telling a window
2712 * what color it should be using to draw with, but perhaps simply changing
2713 * it every time is not too inefficient. XXX XXX XXX
2715 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2717 term_data *td = (term_data*)(Term->data);
2721 #if 1 /* #ifdef JP */
2722 static HBITMAP WALL;
2723 static HBRUSH myBrush, oldBrush;
2725 static bool init_done = FALSE;
2728 WALL = LoadBitmap(hInstance, AppName);
2729 myBrush = CreatePatternBrush(WALL);
2734 /* Total rectangle */
2735 rc.left = x * td->tile_wid + td->size_ow1;
2736 rc.right = rc.left + n * td->tile_wid;
2737 rc.top = y * td->tile_hgt + td->size_oh1;
2738 rc.bottom = rc.top + td->tile_hgt;
2743 /* Background color */
2744 SetBkColor(hdc, RGB(0, 0, 0));
2746 /* Foreground color */
2749 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2753 SetTextColor(hdc, win_clr[a&0x0F]);
2757 SetTextColor(hdc, win_clr[a]);
2761 SelectObject(hdc, td->font_id);
2764 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2768 (td->tile_hgt != td->font_hgt) ||
2769 (td->tile_wid != td->font_wid))
2773 /* Erase complete rectangle */
2774 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2777 if (use_bg) DrawBG(hdc, &rc);
2780 rc.left += ((td->tile_wid - td->font_wid) / 2);
2781 rc.right = rc.left + td->font_wid;
2782 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2783 rc.bottom = rc.top + td->font_hgt;
2785 /* Dump each character */
2786 for (i = 0; i < n; i++)
2789 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2791 rc.right += td->font_wid;
2793 oldBrush = SelectObject(hdc, myBrush);
2794 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2797 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2799 SelectObject(hdc, oldBrush);
2800 SelectObject(hdc, oldPen);
2801 rc.right -= td->font_wid;
2805 rc.left += 2 * td->tile_wid;
2806 rc.right += 2 * td->tile_wid;
2808 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2810 rc.right += td->font_wid;
2812 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2814 rc.right -= td->font_wid;
2818 rc.left += 2 * td->tile_wid;
2819 rc.right += 2 * td->tile_wid;
2820 } else if (*(s+i)==127){
2821 oldBrush = SelectObject(hdc, myBrush);
2822 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2825 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2827 SelectObject(hdc, oldBrush);
2828 SelectObject(hdc, oldPen);
2831 rc.left += td->tile_wid;
2832 rc.right += td->tile_wid;
2835 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2838 rc.left += td->tile_wid;
2839 rc.right += td->tile_wid;
2844 oldBrush = SelectObject(hdc, myBrush);
2845 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2848 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2850 SelectObject(hdc, oldBrush);
2851 SelectObject(hdc, oldPen);
2854 rc.left += td->tile_wid;
2855 rc.right += td->tile_wid;
2858 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2862 rc.left += td->tile_wid;
2863 rc.right += td->tile_wid;
2867 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2871 rc.left += td->tile_wid;
2872 rc.right += td->tile_wid;
2883 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2888 ReleaseDC(td->w, hdc);
2896 * Low level graphics. Assumes valid input.
2898 * Draw an array of "special" attr/char pairs at the given location.
2900 * We use the "Term_pict_win()" function for "graphic" data, which are
2901 * encoded by setting the "high-bits" of both the "attr" and the "char"
2902 * data. We use the "attr" to represent the "row" of the main bitmap,
2903 * and the "char" to represent the "col" of the main bitmap. The use
2904 * of this function is induced by the "higher_pict" flag.
2906 * If "graphics" is not available, we simply "wipe" the given grids.
2908 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2910 term_data *td = (term_data*)(Term->data);
2916 int x2, y2, w2, h2, tw2;
2928 /* Erase the grids */
2929 return (Term_wipe_win(x, y, n));
2932 /* Size of bitmap cell */
2933 w1 = infGraph.CellWidth;
2934 h1 = infGraph.CellHeight;
2936 /* Size of window cell */
2939 w2 = td->map_tile_wid;
2940 h2 = td->map_tile_hgt;
2949 if (use_bigtile) tw2 *= 2;
2952 /* Location of window cell */
2953 x2 = x * w2 + td->size_ow1;
2954 y2 = y * h2 + td->size_oh1;
2960 hdcSrc = CreateCompatibleDC(hdc);
2961 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2963 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2965 hdcMask = CreateCompatibleDC(hdc);
2966 SelectObject(hdcMask, infMask.hBitmap);
2969 /* Draw attr/char pairs */
2970 for (i = 0; i < n; i++, x2 += w2)
2975 /* Extract picture */
2976 int row = (a & 0x7F);
2977 int col = (c & 0x7F);
2979 /* Location of bitmap cell */
2983 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2985 x3 = (tcp[i] & 0x7F) * w1;
2986 y3 = (tap[i] & 0x7F) * h1;
2989 if ((w1 == tw2) && (h1 == h2))
2991 /* Copy the terrain picture from the bitmap to the window */
2992 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2994 /* Mask out the tile */
2995 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2998 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
3001 /* Need to stretch */
3004 /* Set the correct mode for stretching the tiles */
3005 SetStretchBltMode(hdc, COLORONCOLOR);
3007 /* Copy the terrain picture from the bitmap to the window */
3008 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
3010 /* Only draw if terrain and overlay are different */
3011 if ((x1 != x3) || (y1 != y3))
3013 /* Mask out the tile */
3014 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
3017 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
3024 if ((w1 == tw2) && (h1 == h2))
3026 /* Copy the picture from the bitmap to the window */
3027 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
3030 /* Need to stretch */
3033 /* Set the correct mode for stretching the tiles */
3034 SetStretchBltMode(hdc, COLORONCOLOR);
3036 /* Copy the picture from the bitmap to the window */
3037 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
3043 SelectObject(hdcSrc, hbmSrcOld);
3046 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
3049 SelectObject(hdcMask, hbmSrcOld);
3054 ReleaseDC(td->w, hdc);
3056 #else /* USE_GRAPHICS */
3058 /* Just erase this grid */
3059 return (Term_wipe_win(x, y, n));
3061 #endif /* USE_GRAPHICS */
3068 static void windows_map(void)
3070 term_data *td = &data[0];
3072 int x, min_x, max_x;
3073 int y, min_y, max_y;
3077 /* Only in graphics mode */
3078 if (!use_graphics) return;
3081 Term_xtra_win_clear();
3083 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
3084 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
3085 td->map_active = TRUE;
3095 for (x = min_x; x < max_x; x++)
3097 for (y = min_y; y < max_y; y++)
3099 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
3101 /* Ignore non-graphics */
3102 if ((a & 0x80) && (c & 0x80))
3104 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
3109 /* Hilite the player */
3110 Term_curs_win(px - min_x, py - min_y);
3112 /* Wait for a keypress, flush key buffer */
3113 Term_inkey(&c, TRUE, TRUE);
3116 /* Switch off the map display */
3117 td->map_active = FALSE;
3119 /* Restore screen */
3120 Term_xtra_win_clear();
3125 /*** Other routines ***/
3129 * Create and initialize a "term_data" given a title
3131 static void term_data_link(term_data *td)
3135 /* Initialize the term */
3136 term_init(t, td->cols, td->rows, td->keys);
3138 /* Use a "software" cursor */
3139 t->soft_cursor = TRUE;
3141 /* Use "Term_pict" for "graphic" data */
3142 t->higher_pict = TRUE;
3144 /* Erase with "white space" */
3145 t->attr_blank = TERM_WHITE;
3146 t->char_blank = ' ';
3149 /* Prepare the init/nuke hooks */
3150 t->init_hook = Term_init_win;
3151 t->nuke_hook = Term_nuke_win;
3154 /* Prepare the template hooks */
3155 t->user_hook = Term_user_win;
3156 t->xtra_hook = Term_xtra_win;
3157 t->curs_hook = Term_curs_win;
3158 t->bigcurs_hook = Term_bigcurs_win;
3159 t->wipe_hook = Term_wipe_win;
3160 t->text_hook = Term_text_win;
3161 t->pict_hook = Term_pict_win;
3163 /* Remember where we came from */
3164 t->data = (vptr)(td);
3169 * Create the windows
3171 * First, instantiate the "default" values, then read the "ini_file"
3172 * to over-ride selected values, then create the windows, and fonts.
3174 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3175 * must make active to realize the palette. XXX XXX XXX
3177 static void init_windows(void)
3183 #if 0 /* #ifndef JP */
3189 WIPE(td, term_data);
3193 td->s = angband_term_name[0];
3207 #if 1 /* #ifdef JP */
3211 for (i = 1; i < MAX_TERM_DATA; i++)
3214 WIPE(td, term_data);
3215 td->s = angband_term_name[i];
3219 td->visible = FALSE;
3224 td->pos_x = (7 - i) * 30;
3225 td->pos_y = (7 - i) * 20;
3227 #if 1 /* #ifdef JP */
3237 /* Main window (need these before term_getsize gets called) */
3239 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3240 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3245 /* Sub windows (need these before term_getsize gets called) */
3246 for (i = 1; i < MAX_TERM_DATA; i++)
3249 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3250 td->dwExStyle = (WS_EX_TOOLWINDOW);
3255 for (i = 0; i < MAX_TERM_DATA; i++)
3259 #if 1 /* #ifdef JP */
3260 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3261 td->lf.lfCharSet = DEFAULT_CHARSET;
3262 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3263 /* Activate the chosen font */
3264 term_force_font(td, NULL);
3265 td->tile_wid = td->font_wid;
3266 td->tile_hgt = td->font_hgt;
3268 /* Access the standard font file */
3269 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3271 /* Activate the chosen font */
3272 if (term_force_font(td, buf))
3274 /* Access the standard font file */
3275 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3277 /* Force the use of that font */
3278 (void)term_force_font(td, buf);
3284 /* Assume not bizarre */
3285 td->bizarre = FALSE;
3290 /* Analyze the font */
3293 /* Resize the window */
3294 term_window_resize(td);
3298 /* Sub windows (reverse order) */
3299 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3304 td->w = CreateWindowEx(td->dwExStyle, AngList,
3306 td->pos_x, td->pos_y,
3307 td->size_wid, td->size_hgt,
3308 HWND_DESKTOP, NULL, hInstance, NULL);
3311 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3313 if (!td->w) quit("Failed to create sub-window");
3319 td->size_hack = TRUE;
3320 ShowWindow(td->w, SW_SHOW);
3321 td->size_hack = FALSE;
3325 angband_term[i] = &td->t;
3329 /* Activate the window */
3330 SetActiveWindow(td->w);
3335 term_window_pos(&data[i], HWND_TOPMOST);
3339 term_window_pos(&data[i], td->w);
3349 td->w = CreateWindowEx(td->dwExStyle, AppName,
3351 td->pos_x, td->pos_y,
3352 td->size_wid, td->size_hgt,
3353 HWND_DESKTOP, NULL, hInstance, NULL);
3356 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3358 if (!td->w) quit("Failed to create Angband window");
3363 angband_term[0] = &td->t;
3364 normsize.x = td->cols;
3365 normsize.y = td->rows;
3367 /* Activate the main window */
3368 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3369 else ShowWindow(td->w, SW_SHOW);
3371 /* Bring main window back to top */
3372 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3375 /* New palette XXX XXX XXX */
3376 (void)new_palette();
3379 /* Create a "brush" for drawing the "cursor" */
3380 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3383 /* Process pending messages */
3384 (void)Term_xtra_win_flush();
3392 static void setup_menus(void)
3396 HMENU hm = GetMenu(data[0].w);
3399 /* Menu "File", Disable all */
3400 EnableMenuItem(hm, IDM_FILE_NEW,
3401 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3402 EnableMenuItem(hm, IDM_FILE_OPEN,
3403 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3404 EnableMenuItem(hm, IDM_FILE_SAVE,
3405 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3406 EnableMenuItem(hm, IDM_FILE_EXIT,
3407 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3408 EnableMenuItem(hm, IDM_FILE_SCORE,
3409 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3412 /* No character available */
3413 if (!character_generated)
3415 /* Menu "File", Item "New" */
3416 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3418 /* Menu "File", Item "Open" */
3419 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3422 /* A character available */
3423 if (character_generated)
3425 /* Menu "File", Item "Save" */
3426 EnableMenuItem(hm, IDM_FILE_SAVE,
3427 MF_BYCOMMAND | MF_ENABLED);
3430 /* Menu "File", Item "Exit" */
3431 EnableMenuItem(hm, IDM_FILE_EXIT,
3432 MF_BYCOMMAND | MF_ENABLED);
3434 EnableMenuItem(hm, IDM_FILE_SCORE,
3435 MF_BYCOMMAND | MF_ENABLED);
3438 /* Menu "Window::Visibility" */
3439 for (i = 0; i < MAX_TERM_DATA; i++)
3441 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3442 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3444 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3445 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3447 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3448 MF_BYCOMMAND | MF_ENABLED);
3451 /* Menu "Window::Font" */
3452 for (i = 0; i < MAX_TERM_DATA; i++)
3454 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3455 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3457 if (data[i].visible)
3459 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3460 MF_BYCOMMAND | MF_ENABLED);
3464 /* Menu "Window::Window Position Fix" */
3465 for (i = 0; i < MAX_TERM_DATA; i++)
3467 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3468 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3470 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3471 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3473 if (data[i].visible)
3475 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3476 MF_BYCOMMAND | MF_ENABLED);
3480 /* Menu "Window::Bizarre Display" */
3481 for (i = 0; i < MAX_TERM_DATA; i++)
3483 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3484 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3486 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3487 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3489 if (data[i].visible)
3491 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3492 MF_BYCOMMAND | MF_ENABLED);
3497 /* Menu "Window::Increase Tile Width" */
3498 for (i = 0; i < MAX_TERM_DATA; i++)
3500 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3501 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3503 if (data[i].visible)
3505 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3506 MF_BYCOMMAND | MF_ENABLED);
3511 /* Menu "Window::Decrease Tile Width" */
3512 for (i = 0; i < MAX_TERM_DATA; i++)
3514 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3515 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3517 if (data[i].visible)
3519 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3520 MF_BYCOMMAND | MF_ENABLED);
3525 /* Menu "Window::Increase Tile Height" */
3526 for (i = 0; i < MAX_TERM_DATA; i++)
3528 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3529 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3531 if (data[i].visible)
3533 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3534 MF_BYCOMMAND | MF_ENABLED);
3539 /* Menu "Window::Decrease Tile Height" */
3540 for (i = 0; i < MAX_TERM_DATA; i++)
3542 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3543 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3545 if (data[i].visible)
3547 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3548 MF_BYCOMMAND | MF_ENABLED);
3553 /* Menu "Options", disable all */
3554 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3555 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3556 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3557 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3558 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3559 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3560 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3561 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3562 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3563 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3565 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3566 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3569 /* Menu "Options", Item "Map" */
3570 if (use_graphics != GRAPHICS_NONE)
3571 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3573 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3574 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3576 /* Menu "Options", update all */
3577 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3578 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3579 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3580 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3581 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3582 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3583 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3584 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3585 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3586 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3587 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
3588 (arg_music ? MF_CHECKED : MF_UNCHECKED));
3589 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3590 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3591 CheckMenuItem(hm, IDM_OPTIONS_BG,
3592 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3594 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3595 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3599 /* Menu "Options", Item "Graphics" */
3600 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3601 /* Menu "Options", Item "Graphics" */
3602 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3603 /* Menu "Options", Item "Graphics" */
3604 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3605 /* Menu "Options", Item "Graphics" */
3606 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3607 #endif /* USE_GRAPHICS */
3610 /* Menu "Options", Item "Sound" */
3611 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3612 #endif /* USE_SOUND */
3615 /* Menu "Options", Item "ScreenSaver" */
3616 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3617 MF_BYCOMMAND | MF_ENABLED);
3618 #endif /* USE_SAVER */
3623 * Check for double clicked (or dragged) savefile
3625 * Apparently, Windows copies the entire filename into the first
3626 * piece of the "command line string". Perhaps we should extract
3627 * the "basename" of that filename and append it to the "save" dir.
3629 static void check_for_save_file(LPSTR cmd_line)
3639 /* Extract filename */
3640 strcat(savefile, s);
3642 /* Validate the file */
3643 validate_file(savefile);
3645 /* Game in progress */
3646 game_in_progress = TRUE;
3654 * Process a menu command
3656 static void process_menus(WORD wCmd)
3673 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3675 plog("You cannot do that yet...");
3679 else if (game_in_progress)
3682 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3684 plog("You can't start a new game while you're still playing!");
3690 game_in_progress = TRUE;
3704 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3706 plog("You cannot do that yet...");
3710 else if (game_in_progress)
3713 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3715 plog("You can't open a new game while you're still playing!");
3721 memset(&ofn, 0, sizeof(ofn));
3722 ofn.lStructSize = sizeof(ofn);
3723 ofn.hwndOwner = data[0].w;
3724 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3725 ofn.nFilterIndex = 1;
3726 ofn.lpstrFile = savefile;
3727 ofn.nMaxFile = 1024;
3728 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3729 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3731 if (GetOpenFileName(&ofn))
3733 /* Load 'savefile' */
3734 validate_file(savefile);
3735 game_in_progress = TRUE;
3747 if (game_in_progress && character_generated)
3753 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3755 plog("You may not do that right now.");
3761 /* Hack -- Forget messages */
3766 do_cmd_save_game(FALSE);
3767 #else /* ZANGBAND */
3769 #endif /* ZANGBAND */
3774 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3776 plog("You may not do that right now.");
3786 if (game_in_progress && character_generated)
3792 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3794 plog("You may not do that right now.");
3800 /* Hack -- Forget messages */
3809 /* do_cmd_save_game(FALSE); */
3810 #else /* ZANGBAND */
3811 /* do_cmd_save_game(); */
3812 #endif /* ZANGBAND */
3813 Term_key_push(SPECIAL_KEY_QUIT);
3821 case IDM_FILE_SCORE:
3825 /* Build the filename */
3826 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3828 /* Open the binary high score file, for reading */
3829 highscore_fd = fd_open(buf, O_RDONLY);
3831 /* Paranoia -- No score file */
3832 if (highscore_fd < 0)
3834 msg_print("Score file unavailable.");
3844 /* Display the scores */
3845 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3847 /* Shut the high score file */
3848 (void)fd_close(highscore_fd);
3850 /* Forget the high score fd */
3856 /* Hack - Flush it */
3864 case IDM_FILE_MOVIE:
3869 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3871 plog("You cannot do that yet...");
3874 else if (game_in_progress)
3877 plog("¥×¥ì¥¤Ãæ¤Ï¥à¡¼¥Ó¡¼¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3879 plog("You can't open a movie while you're playing!");
3884 memset(&ofn, 0, sizeof(ofn));
3885 ofn.lStructSize = sizeof(ofn);
3886 ofn.hwndOwner = data[0].w;
3887 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3888 ofn.nFilterIndex = 1;
3889 ofn.lpstrFile = savefile;
3890 ofn.nMaxFile = 1024;
3891 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3892 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3894 if (GetOpenFileName(&ofn))
3896 /* Load 'savefile' */
3897 prepare_browse_movie_aux(savefile);
3907 case IDM_WINDOW_VIS_0:
3910 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3912 plog("You are not allowed to do that!");
3919 /* Window visibility */
3920 case IDM_WINDOW_VIS_1:
3921 case IDM_WINDOW_VIS_2:
3922 case IDM_WINDOW_VIS_3:
3923 case IDM_WINDOW_VIS_4:
3924 case IDM_WINDOW_VIS_5:
3925 case IDM_WINDOW_VIS_6:
3926 case IDM_WINDOW_VIS_7:
3928 i = wCmd - IDM_WINDOW_VIS_0;
3930 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3937 ShowWindow(td->w, SW_SHOW);
3938 term_data_redraw(td);
3942 td->visible = FALSE;
3944 ShowWindow(td->w, SW_HIDE);
3951 case IDM_WINDOW_FONT_0:
3952 case IDM_WINDOW_FONT_1:
3953 case IDM_WINDOW_FONT_2:
3954 case IDM_WINDOW_FONT_3:
3955 case IDM_WINDOW_FONT_4:
3956 case IDM_WINDOW_FONT_5:
3957 case IDM_WINDOW_FONT_6:
3958 case IDM_WINDOW_FONT_7:
3960 i = wCmd - IDM_WINDOW_FONT_0;
3962 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3966 term_change_font(td);
3971 /* Window Z Position */
3972 case IDM_WINDOW_POS_1:
3973 case IDM_WINDOW_POS_2:
3974 case IDM_WINDOW_POS_3:
3975 case IDM_WINDOW_POS_4:
3976 case IDM_WINDOW_POS_5:
3977 case IDM_WINDOW_POS_6:
3978 case IDM_WINDOW_POS_7:
3980 i = wCmd - IDM_WINDOW_POS_0;
3982 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3986 if (!td->posfix && td->visible)
3989 term_window_pos(td, HWND_TOPMOST);
3994 term_window_pos(td, data[0].w);
4000 /* Bizarre Display */
4001 case IDM_WINDOW_BIZ_0:
4002 case IDM_WINDOW_BIZ_1:
4003 case IDM_WINDOW_BIZ_2:
4004 case IDM_WINDOW_BIZ_3:
4005 case IDM_WINDOW_BIZ_4:
4006 case IDM_WINDOW_BIZ_5:
4007 case IDM_WINDOW_BIZ_6:
4008 case IDM_WINDOW_BIZ_7:
4010 i = wCmd - IDM_WINDOW_BIZ_0;
4012 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4016 td->bizarre = !td->bizarre;
4020 term_window_resize(td);
4025 /* Increase Tile Width */
4026 case IDM_WINDOW_I_WID_0:
4027 case IDM_WINDOW_I_WID_1:
4028 case IDM_WINDOW_I_WID_2:
4029 case IDM_WINDOW_I_WID_3:
4030 case IDM_WINDOW_I_WID_4:
4031 case IDM_WINDOW_I_WID_5:
4032 case IDM_WINDOW_I_WID_6:
4033 case IDM_WINDOW_I_WID_7:
4035 i = wCmd - IDM_WINDOW_I_WID_0;
4037 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4045 term_window_resize(td);
4050 /* Decrease Tile Height */
4051 case IDM_WINDOW_D_WID_0:
4052 case IDM_WINDOW_D_WID_1:
4053 case IDM_WINDOW_D_WID_2:
4054 case IDM_WINDOW_D_WID_3:
4055 case IDM_WINDOW_D_WID_4:
4056 case IDM_WINDOW_D_WID_5:
4057 case IDM_WINDOW_D_WID_6:
4058 case IDM_WINDOW_D_WID_7:
4060 i = wCmd - IDM_WINDOW_D_WID_0;
4062 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4070 term_window_resize(td);
4075 /* Increase Tile Height */
4076 case IDM_WINDOW_I_HGT_0:
4077 case IDM_WINDOW_I_HGT_1:
4078 case IDM_WINDOW_I_HGT_2:
4079 case IDM_WINDOW_I_HGT_3:
4080 case IDM_WINDOW_I_HGT_4:
4081 case IDM_WINDOW_I_HGT_5:
4082 case IDM_WINDOW_I_HGT_6:
4083 case IDM_WINDOW_I_HGT_7:
4085 i = wCmd - IDM_WINDOW_I_HGT_0;
4087 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4095 term_window_resize(td);
4100 /* Decrease Tile Height */
4101 case IDM_WINDOW_D_HGT_0:
4102 case IDM_WINDOW_D_HGT_1:
4103 case IDM_WINDOW_D_HGT_2:
4104 case IDM_WINDOW_D_HGT_3:
4105 case IDM_WINDOW_D_HGT_4:
4106 case IDM_WINDOW_D_HGT_5:
4107 case IDM_WINDOW_D_HGT_6:
4108 case IDM_WINDOW_D_HGT_7:
4110 i = wCmd - IDM_WINDOW_D_HGT_0;
4112 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4120 term_window_resize(td);
4125 case IDM_OPTIONS_NO_GRAPHICS:
4130 plog("You may not do that right now.");
4134 /* Toggle "arg_graphics" */
4135 if (arg_graphics != GRAPHICS_NONE)
4137 arg_graphics = GRAPHICS_NONE;
4139 /* React to changes */
4140 Term_xtra_win_react();
4142 /* Hack -- Force redraw */
4143 Term_key_push(KTRL('R'));
4149 case IDM_OPTIONS_OLD_GRAPHICS:
4154 plog("You may not do that right now.");
4158 /* Toggle "arg_graphics" */
4159 if (arg_graphics != GRAPHICS_ORIGINAL)
4161 arg_graphics = GRAPHICS_ORIGINAL;
4163 /* React to changes */
4164 Term_xtra_win_react();
4166 /* Hack -- Force redraw */
4167 Term_key_push(KTRL('R'));
4173 case IDM_OPTIONS_NEW_GRAPHICS:
4178 plog("You may not do that right now.");
4182 /* Toggle "arg_graphics" */
4183 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4185 arg_graphics = GRAPHICS_ADAM_BOLT;
4187 /* React to changes */
4188 Term_xtra_win_react();
4190 /* Hack -- Force redraw */
4191 Term_key_push(KTRL('R'));
4197 case IDM_OPTIONS_NEW2_GRAPHICS:
4202 plog("You may not do that right now.");
4206 /* Toggle "arg_graphics" */
4207 if (arg_graphics != GRAPHICS_HENGBAND)
4209 arg_graphics = GRAPHICS_HENGBAND;
4211 /* React to changes */
4212 Term_xtra_win_react();
4214 /* Hack -- Force redraw */
4215 Term_key_push(KTRL('R'));
4221 case IDM_OPTIONS_BIGTILE:
4223 term_data *td = &data[0];
4228 plog("You may not do that right now.");
4232 /* Toggle "arg_sound" */
4233 arg_bigtile = !arg_bigtile;
4236 Term_activate(&td->t);
4238 /* Resize the term */
4239 Term_resize(td->cols, td->rows);
4242 InvalidateRect(td->w, NULL, TRUE);
4247 case IDM_OPTIONS_MUSIC:
4252 plog("You may not do that right now.");
4256 /* Toggle "arg_sound" */
4257 arg_music = !arg_music;
4259 /* React to changes */
4260 Term_xtra_win_react();
4262 /* Hack -- Force redraw */
4263 Term_key_push(KTRL('R'));
4268 case IDM_OPTIONS_SOUND:
4273 plog("You may not do that right now.");
4277 /* Toggle "arg_sound" */
4278 arg_sound = !arg_sound;
4280 /* React to changes */
4281 Term_xtra_win_react();
4283 /* Hack -- Force redraw */
4284 Term_key_push(KTRL('R'));
4290 case IDM_OPTIONS_BG:
4295 plog("You may not do that right now.");
4299 /* Toggle "use_bg" */
4304 /* React to changes */
4305 Term_xtra_win_react();
4307 /* Hack -- Force redraw */
4308 Term_key_push(KTRL('R'));
4314 case IDM_OPTIONS_OPEN_BG:
4319 plog("You may not do that right now.");
4324 memset(&ofn, 0, sizeof(ofn));
4325 ofn.lStructSize = sizeof(ofn);
4326 ofn.hwndOwner = data[0].w;
4327 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4328 ofn.nFilterIndex = 1;
4329 ofn.lpstrFile = bg_bitmap_file;
4330 ofn.nMaxFile = 1023;
4331 ofn.lpstrInitialDir = NULL;
4333 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
4335 ofn.lpstrTitle = "Choose wall paper.";
4337 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4339 if (GetOpenFileName(&ofn))
4341 /* Load 'savefile' */
4346 /* React to changes */
4347 Term_xtra_win_react();
4349 /* Hack -- Force redraw */
4350 Term_key_push(KTRL('R'));
4355 case IDM_DUMP_SCREEN_HTML:
4357 static char buf[1024] = "";
4358 memset(&ofn, 0, sizeof(ofn));
4359 ofn.lStructSize = sizeof(ofn);
4360 ofn.hwndOwner = data[0].w;
4361 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4362 ofn.nFilterIndex = 1;
4363 ofn.lpstrFile = buf;
4364 ofn.nMaxFile = 1023;
4365 ofn.lpstrDefExt = "html";
4366 ofn.lpstrInitialDir = NULL;
4368 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
4370 ofn.lpstrTitle = "Save screen dump as HTML.";
4372 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4374 if (GetSaveFileName(&ofn))
4376 do_cmd_save_screen_html_aux(buf, 0);
4383 case IDM_OPTIONS_SAVER:
4387 DestroyWindow(hwndSaver);
4392 /* Create a screen scaver window */
4393 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4394 "Angband Screensaver",
4395 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4396 0, 0, GetSystemMetrics(SM_CXSCREEN),
4397 GetSystemMetrics(SM_CYSCREEN),
4398 NULL, NULL, hInstance, NULL);
4402 /* Push the window to the bottom XXX XXX XXX */
4403 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4408 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
4410 plog("Failed to create saver window");
4420 case IDM_OPTIONS_MAP:
4426 case IDM_HELP_CONTENTS:
4430 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4431 if (check_file(tmp))
4433 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4438 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4439 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4441 plog_fmt("Cannot find help file: %s", tmp);
4442 plog("Use the online help files instead.");
4447 #else /* HTML_HELP */
4450 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4451 if (check_file(tmp))
4453 sprintf(buf, "winhelp.exe %s", tmp);
4454 WinExec(buf, SW_NORMAL);
4459 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4460 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4462 plog_fmt("Cannot find help file: %s", tmp);
4463 plog("Use the online help files instead.");
4468 #endif /* HTML_HELP */
4474 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4481 /* Extract the modifiers */
4482 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4483 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4484 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4486 Term_no_press = (ma) ? TRUE : FALSE;
4488 /* Handle "special" keys */
4489 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4491 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4492 bool numpad = FALSE;
4494 /* Begin the macro trigger */
4497 /* Send the modifiers */
4498 if (mc) Term_keypress('C');
4499 if (ms) Term_keypress('S');
4500 if (ma) Term_keypress('A');
4502 /* Extract "scan code" */
4503 i = LOBYTE(HIWORD(lParam));
4505 /* Introduce the scan code */
4508 /* Extended key bit */
4511 /* Numpad Enter and '/' are extended key */
4513 Term_no_press = TRUE;
4514 case VK_RETURN: /* Enter */
4517 /* Other extended keys are on full keyboard */
4533 Term_no_press = TRUE;
4537 case VK_PRIOR: /* Page Up */
4538 case VK_NEXT: /* Page Down */
4548 /* Special modifiers for keypad keys */
4549 if (numpad) Term_keypress('K');
4551 /* Encode the hexidecimal scan code */
4552 Term_keypress(hexsym[i/16]);
4553 Term_keypress(hexsym[i%16]);
4555 /* End the macro trigger */
4566 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4567 WPARAM wParam, LPARAM lParam);
4568 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4569 WPARAM wParam, LPARAM lParam)
4570 #else /* __MWERKS__ */
4571 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4572 WPARAM wParam, LPARAM lParam)
4573 #endif /* __MWERKS__ */
4579 MINMAXINFO FAR *lpmmi;
4585 /* Acquire proper "term_data" info */
4586 td = (term_data *)GetWindowLong(hWnd, 0);
4588 /* Handle message */
4594 SetWindowLong(hWnd, 0, (LONG)(my_td));
4604 case WM_GETMINMAXINFO:
4606 MINMAXINFO FAR *lpmmi;
4609 lpmmi = (MINMAXINFO FAR *)lParam;
4611 /* this message was sent before WM_NCCREATE */
4614 /* Minimum window size is 80x24 */
4615 rc.left = rc.top = 0;
4616 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4617 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4620 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4622 /* Save minimum size */
4623 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4624 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4631 BeginPaint(hWnd, &ps);
4632 if (td) term_data_redraw(td);
4633 EndPaint(hWnd, &ps);
4634 ValidateRect(hWnd, NULL);
4641 if (process_keydown(wParam, lParam))
4648 if (Term_no_press) Term_no_press = FALSE;
4649 else Term_keypress(wParam);
4653 case WM_LBUTTONDOWN:
4655 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4656 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4668 int dx = abs(oldx - mousex) + 1;
4669 int dy = abs(oldy - mousey) + 1;
4670 int ox = (oldx > mousex) ? mousex : oldx;
4671 int oy = (oldy > mousey) ? mousey : oldy;
4681 hGlobal = GlobalAlloc(GHND, sz + 1);
4682 if (hGlobal == NULL) return 0;
4683 lpStr = (LPSTR)GlobalLock(hGlobal);
4685 for (i = 0; i < dy; i++)
4689 char **scr = data[0].t.scr->c;
4691 C_MAKE(s, (dx + 1), char);
4692 strncpy(s, &scr[oy + i][ox], dx);
4696 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4699 if (ox + dx < data[0].cols)
4701 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4704 for (j = 0; j < dx; j++)
4706 if (s[j] == 127) s[j] = '#';
4710 for (j = 0; j < dx; j++)
4712 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4722 GlobalUnlock(hGlobal);
4723 if (OpenClipboard(hWnd) == 0)
4725 GlobalFree(hGlobal);
4729 SetClipboardData(CF_TEXT, hGlobal);
4742 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4743 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4748 dx = abs(oldx - mousex) + 1;
4749 dy = abs(oldy - mousey) + 1;
4750 ox = (oldx > mousex) ? mousex : oldx;
4751 oy = (oldy > mousey) ? mousey : oldy;
4752 Term_inversed_area(hWnd, ox, oy, dx, dy);
4759 dx = abs(cx - mousex) + 1;
4760 dy = abs(cy - mousey) + 1;
4761 ox = (cx > mousex) ? mousex : cx;
4762 oy = (cy > mousey) ? mousey : cy;
4763 Term_inversed_area(hWnd, ox, oy, dx, dy);
4779 if (game_in_progress && character_generated)
4784 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4786 plog("You may not do that right now.");
4791 /* Hack -- Forget messages */
4800 /* do_cmd_save_game(FALSE); */
4801 #else /* ZANGBAND */
4802 /* do_cmd_save_game(); */
4803 #endif /* ZANGBAND */
4804 Term_key_push(SPECIAL_KEY_QUIT);
4811 case WM_QUERYENDSESSION:
4813 if (game_in_progress && character_generated)
4815 /* Hack -- Forget messages */
4818 /* Mega-Hack -- Delay death */
4819 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4822 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "----¥²¡¼¥àÃæÃÇ----");
4824 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "---- Save and Exit Game ----");
4827 /* Hardcode panic save */
4828 p_ptr->panic_save = 1;
4830 /* Forbid suspend */
4831 signals_ignore_tstp();
4833 /* Indicate panic save */
4835 (void)strcpy(p_ptr->died_from, "(¶ÛµÞ¥»¡¼¥Ö)");
4837 (void)strcpy(p_ptr->died_from, "(panic save)");
4841 (void)save_player();
4855 process_menus(LOWORD(wParam));
4861 /* this message was sent before WM_NCCREATE */
4864 /* it was sent from inside CreateWindowEx */
4865 if (!td->w) return 1;
4867 /* was sent from WM_SIZE */
4868 if (td->size_hack) return 1;
4872 case SIZE_MINIMIZED:
4874 /* Hide sub-windows */
4875 for (i = 1; i < MAX_TERM_DATA; i++)
4877 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4882 case SIZE_MAXIMIZED:
4884 /* fall through XXX XXX XXX */
4889 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4890 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4893 if ((td->cols != cols) || (td->rows != rows))
4895 /* Save the new size */
4899 if (!IsZoomed(td->w) && !IsIconic(td->w))
4901 normsize.x = td->cols;
4902 normsize.y = td->rows;
4906 Term_activate(&td->t);
4908 /* Resize the term */
4909 Term_resize(td->cols, td->rows);
4912 InvalidateRect(td->w, NULL, TRUE);
4915 td->size_hack = TRUE;
4917 /* Show sub-windows */
4918 for (i = 1; i < MAX_TERM_DATA; i++)
4920 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4923 td->size_hack = FALSE;
4931 case WM_PALETTECHANGED:
4933 /* Ignore if palette change caused by itself */
4934 if ((HWND)wParam == hWnd) return 0;
4936 /* Fall through... */
4939 case WM_QUERYNEWPALETTE:
4941 if (!paletted) return 0;
4945 SelectPalette(hdc, hPal, FALSE);
4947 i = RealizePalette(hdc);
4949 /* if any palette entries changed, repaint the window. */
4950 if (i) InvalidateRect(hWnd, NULL, TRUE);
4952 ReleaseDC(hWnd, hdc);
4959 if (wParam && !HIWORD(lParam))
4961 /* Do something to sub-windows */
4962 for (i = 1; i < MAX_TERM_DATA; i++)
4964 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4967 /* Focus on main window */
4976 case WM_ACTIVATEAPP:
4978 if (IsIconic(td->w)) break;
4980 for (i = 1; i < MAX_TERM_DATA; i++)
4986 ShowWindow(data[i].w, SW_SHOW);
4990 ShowWindow(data[i].w, SW_HIDE);
4997 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5002 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5003 WPARAM wParam, LPARAM lParam);
5004 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5005 WPARAM wParam, LPARAM lParam)
5006 #else /* __MWERKS__ */
5007 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
5008 WPARAM wParam, LPARAM lParam)
5009 #endif /* __MWERKS__ */
5013 MINMAXINFO FAR *lpmmi;
5021 /* Acquire proper "term_data" info */
5022 td = (term_data *)GetWindowLong(hWnd, 0);
5024 /* Process message */
5030 SetWindowLong(hWnd, 0, (LONG)(my_td));
5040 case WM_GETMINMAXINFO:
5042 MINMAXINFO FAR *lpmmi;
5045 lpmmi = (MINMAXINFO FAR *)lParam;
5047 /* this message was sent before WM_NCCREATE */
5050 /* Minimum window size is 80x24 */
5051 rc.left = rc.top = 0;
5052 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
5053 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
5056 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
5058 /* Save minimum size */
5059 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
5060 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
5070 /* this message was sent before WM_NCCREATE */
5073 /* it was sent from inside CreateWindowEx */
5074 if (!td->w) return 1;
5076 /* was sent from inside WM_SIZE */
5077 if (td->size_hack) return 1;
5079 td->size_hack = TRUE;
5081 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
5082 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
5085 if ((td->cols != cols) || (td->rows != rows))
5088 term *old_term = Term;
5090 /* Save the new size */
5095 Term_activate(&td->t);
5097 /* Resize the term */
5098 Term_resize(td->cols, td->rows);
5101 Term_activate(old_term);
5104 InvalidateRect(td->w, NULL, TRUE);
5106 /* HACK - Redraw all windows */
5107 p_ptr->window = 0xFFFFFFFF;
5111 td->size_hack = FALSE;
5118 BeginPaint(hWnd, &ps);
5119 if (td) term_data_redraw(td);
5120 EndPaint(hWnd, &ps);
5127 if (process_keydown(wParam, lParam))
5134 if (Term_no_press) Term_no_press = FALSE;
5135 else Term_keypress(wParam);
5139 case WM_PALETTECHANGED:
5141 /* ignore if palette change caused by itself */
5142 if ((HWND)wParam == hWnd) return FALSE;
5143 /* otherwise, fall through!!! */
5146 case WM_QUERYNEWPALETTE:
5148 if (!paletted) return 0;
5150 SelectPalette(hdc, hPal, FALSE);
5151 i = RealizePalette(hdc);
5152 /* if any palette entries changed, repaint the window. */
5153 if (i) InvalidateRect(hWnd, NULL, TRUE);
5154 ReleaseDC(hWnd, hdc);
5158 case WM_NCLBUTTONDOWN:
5162 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5163 #endif /* HTCLOSE */
5165 if (wParam == HTSYSMENU)
5169 td->visible = FALSE;
5170 ShowWindow(td->w, SW_HIDE);
5180 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5186 #define MOUSE_SENS 40
5189 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5190 WPARAM wParam, LPARAM lParam);
5191 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5192 WPARAM wParam, LPARAM lParam)
5193 #else /* __MWERKS__ */
5194 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5195 WPARAM wParam, LPARAM lParam)
5196 #endif /* __MWERKS__ */
5198 static int iMouse = 0;
5199 static WORD xMouse = 0;
5200 static WORD yMouse = 0;
5223 if (LOWORD(wParam) == WA_INACTIVE) break;
5225 /* else fall through */
5229 case WM_LBUTTONDOWN:
5230 case WM_MBUTTONDOWN:
5231 case WM_RBUTTONDOWN:
5234 SendMessage(hWnd, WM_CLOSE, 0, 0);
5242 dx = LOWORD(lParam) - xMouse;
5243 dy = HIWORD(lParam) - yMouse;
5245 if (dx < 0) dx = -dx;
5246 if (dy < 0) dy = -dy;
5248 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5250 SendMessage(hWnd, WM_CLOSE, 0, 0);
5254 /* Save last location */
5256 xMouse = LOWORD(lParam);
5257 yMouse = HIWORD(lParam);
5264 DestroyWindow(hwndSaver);
5271 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5274 #endif /* USE_SAVER */
5280 /*** Temporary Hooks ***/
5284 * Display warning message (see "z-util.c")
5286 static void hack_plog(cptr str)
5288 /* Give a warning */
5292 MessageBox(NULL, str, "·Ù¹ð¡ª",
5293 MB_ICONEXCLAMATION | MB_OK);
5295 MessageBox(NULL, str, "Warning",
5296 MB_ICONEXCLAMATION | MB_OK);
5304 * Display error message and quit (see "z-util.c")
5306 static void hack_quit(cptr str)
5308 /* Give a warning */
5312 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
5313 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5315 MessageBox(NULL, str, "Error",
5316 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5321 /* Unregister the classes */
5322 UnregisterClass(AppName, hInstance);
5324 /* Destroy the icon */
5325 if (hIcon) DestroyIcon(hIcon);
5333 /*** Various hooks ***/
5337 * Display warning message (see "z-util.c")
5339 static void hook_plog(cptr str)
5345 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
5346 MB_ICONEXCLAMATION | MB_OK);
5348 MessageBox(data[0].w, str, "Warning",
5349 MB_ICONEXCLAMATION | MB_OK);
5357 * Display error message and quit (see "z-util.c")
5359 static void hook_quit(cptr str)
5364 /* Give a warning */
5368 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
5369 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5371 MessageBox(data[0].w, str, "Error",
5372 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5378 /* Save the preferences */
5382 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
5384 /* Destroy all windows */
5385 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5387 term_force_font(&data[i], NULL);
5388 if (data[i].font_want) string_free(data[i].font_want);
5389 if (data[i].w) DestroyWindow(data[i].w);
5393 /* Free the bitmap stuff */
5395 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5396 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5398 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5399 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5401 #endif /* USE_GRAPHICS */
5403 /*** Free some other stuff ***/
5405 DeleteObject(hbrYellow);
5410 if (hPal) DeleteObject(hPal);
5412 UnregisterClass(AppName, hInstance);
5414 if (hIcon) DestroyIcon(hIcon);
5421 /*** Initialize ***/
5427 static void init_stuff(void)
5434 /* Get program name with full path */
5435 GetModuleFileName(hInstance, path, 512);
5437 /* Save the "program name" XXX XXX XXX */
5440 /* Get the name of the "*.ini" file */
5441 strcpy(path + strlen(path) - 4, ".INI");
5443 /* Save the the name of the ini-file */
5444 ini_file = string_make(path);
5446 /* Analyze the path */
5452 if (path[i] == '\\')
5459 /* Add "lib" to the path */
5460 strcpy(path + i + 1, "lib\\");
5462 /* Validate the path */
5463 validate_dir(path, TRUE);
5465 /* Init the file paths */
5466 init_file_paths(path);
5468 /* Hack -- Validate the paths */
5469 validate_dir(ANGBAND_DIR_APEX, FALSE);
5470 validate_dir(ANGBAND_DIR_BONE, FALSE);
5472 /* Allow missing 'edit' directory */
5473 if (!check_dir(ANGBAND_DIR_EDIT))
5475 /* Must have 'data'! */
5476 validate_dir(ANGBAND_DIR_DATA, TRUE);
5480 /* Don't need 'data' */
5481 validate_dir(ANGBAND_DIR_DATA, FALSE);
5484 validate_dir(ANGBAND_DIR_FILE, TRUE);
5485 validate_dir(ANGBAND_DIR_HELP, FALSE);
5486 validate_dir(ANGBAND_DIR_INFO, FALSE);
5487 validate_dir(ANGBAND_DIR_PREF, TRUE);
5488 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5489 validate_dir(ANGBAND_DIR_USER, TRUE);
5490 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5492 /* Build the filename */
5494 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
5496 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
5500 /* Hack -- Validate the "news.txt" file */
5501 validate_file(path);
5504 #if 0 /* #ifndef JP */
5505 /* Build the "font" path */
5506 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5508 /* Allocate the path */
5509 ANGBAND_DIR_XTRA_FONT = string_make(path);
5511 /* Validate the "font" directory */
5512 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5514 /* Build the filename */
5515 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5517 /* Hack -- Validate the basic font */
5518 validate_file(path);
5524 /* Build the "graf" path */
5525 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5527 /* Allocate the path */
5528 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5530 /* Validate the "graf" directory */
5531 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5533 #endif /* USE_GRAPHICS */
5538 /* Build the "sound" path */
5539 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5541 /* Allocate the path */
5542 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5544 /* Validate the "sound" directory */
5545 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5547 #endif /* USE_SOUND */
5551 /* Build the "music" path */
5552 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5554 /* Allocate the path */
5555 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5557 /* Validate the "music" directory */
5558 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5560 #endif /* USE_MUSIC */
5562 /* Build the "help" path */
5563 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5565 /* Allocate the path */
5566 ANGBAND_DIR_XTRA_HELP = string_make(path);
5568 /* Validate the "help" directory */
5569 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5572 bool is_already_running()
5574 bool result = FALSE;
5577 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5578 if (GetLastError() == ERROR_ALREADY_EXISTS)
5586 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5587 LPSTR lpCmdLine, int nCmdShow)
5595 setlocale( LC_ALL, "ja_JP" );
5604 /* Prevent multiple run */
5605 if (is_already_running())
5608 _("ÊѶòÈÚÅܤϤ¹¤Ç¤Ëµ¯Æ°¤·¤Æ¤¤¤Þ¤¹¡£", "Hengband is already running."),
5609 _("¥¨¥é¡¼¡ª", "Error") ,
5610 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5615 if (hPrevInst == NULL)
5617 wc.style = CS_CLASSDC;
5618 wc.lpfnWndProc = AngbandWndProc;
5620 wc.cbWndExtra = 4; /* one long pointer to term_data */
5621 wc.hInstance = hInst;
5622 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5623 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5624 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5625 wc.lpszMenuName = AppName;
5626 wc.lpszClassName = AppName;
5628 if (!RegisterClass(&wc)) exit(1);
5630 wc.lpfnWndProc = AngbandListProc;
5631 wc.lpszMenuName = NULL;
5632 wc.lpszClassName = AngList;
5634 if (!RegisterClass(&wc)) exit(2);
5638 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5639 wc.lpfnWndProc = AngbandSaverProc;
5641 wc.lpszMenuName = NULL;
5642 wc.lpszClassName = "WindowsScreenSaverClass";
5644 if (!RegisterClass(&wc)) exit(3);
5650 /* Temporary hooks */
5651 plog_aux = hack_plog;
5652 quit_aux = hack_quit;
5653 core_aux = hack_quit;
5655 /* Prepare the filepaths */
5658 /* Initialize the keypress analyzer */
5659 for (i = 0; special_key_list[i]; ++i)
5661 special_key[special_key_list[i]] = TRUE;
5663 /* Initialize the keypress analyzer */
5664 for (i = 0; ignore_key_list[i]; ++i)
5666 ignore_key[ignore_key_list[i]] = TRUE;
5669 /* Determine if display is 16/256/true color */
5671 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5672 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5673 ReleaseDC(NULL, hdc);
5675 /* Initialize the colors */
5676 for (i = 0; i < 256; i++)
5680 /* Extract desired values */
5681 rv = angband_color_table[i][1];
5682 gv = angband_color_table[i][2];
5683 bv = angband_color_table[i][3];
5685 /* Extract the "complex" code */
5686 win_clr[i] = PALETTERGB(rv, gv, bv);
5688 /* Save the "simple" code */
5689 angband_color_table[i][0] = win_pal[i];
5692 /* Prepare the windows */
5698 /* Activate hooks */
5699 plog_aux = hook_plog;
5700 quit_aux = hook_quit;
5701 core_aux = hook_quit;
5703 /* Set the system suffix */
5704 ANGBAND_SYS = "win";
5706 /* Set the keyboard suffix */
5707 if (7 != GetKeyboardType(0))
5708 ANGBAND_KEYBOARD = "0";
5711 /* Japanese keyboard */
5712 switch (GetKeyboardType(1))
5714 case 0x0D01: case 0x0D02:
5715 case 0x0D03: case 0x0D04:
5716 case 0x0D05: case 0x0D06:
5718 ANGBAND_KEYBOARD = "NEC98";
5722 ANGBAND_KEYBOARD = "JAPAN";
5726 /* Catch nasty signals */
5732 /* We are now initialized */
5735 if(lpCmdLine[0] == '-'){
5736 switch(lpCmdLine[1])
5741 if (!lpCmdLine[2]) break;
5742 chuukei_server = TRUE;
5743 if(connect_chuukei_server(&lpCmdLine[2])<0){
5744 msg_print("connect fail");
5747 msg_print("connect");
5755 if (!lpCmdLine[2]) break;
5756 chuukei_client = TRUE;
5757 connect_chuukei_server(&lpCmdLine[2]);
5765 if (!lpCmdLine[2]) break;
5766 prepare_browse_movie(&lpCmdLine[2]);
5776 /* Did the user double click on a save file? */
5777 if(!chuukei_server) check_for_save_file(lpCmdLine);
5779 /* Did the user double click on a save file? */
5780 check_for_save_file(lpCmdLine);
5783 /* Prompt the user */
5785 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5787 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5792 /* Process messages forever */
5793 while (GetMessage(&msg, NULL, 0, 0))
5795 TranslateMessage(&msg);
5796 DispatchMessage(&msg);
5807 #endif /* WINDOWS */