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_SAVER 420
189 #define IDM_OPTIONS_MAP 430
190 #define IDM_OPTIONS_BG 440
191 #define IDM_OPTIONS_OPEN_BG 441
193 #define IDM_DUMP_SCREEN_HTML 450
195 #define IDM_HELP_CONTENTS 901
200 * This may need to be removed for some compilers XXX XXX XXX
207 * Exclude parts of WINDOWS.H that are not needed
209 #define NOCOMM /* Comm driver APIs and definitions */
210 #define NOLOGERROR /* LogError() and related definitions */
211 #define NOPROFILER /* Profiler APIs */
212 #define NOLFILEIO /* _l* file I/O routines */
213 #define NOOPENFILE /* OpenFile and related definitions */
214 #define NORESOURCE /* Resource management */
215 #define NOATOM /* Atom management */
216 #define NOLANGUAGE /* Character test routines */
217 #define NOLSTRING /* lstr* string management routines */
218 #define NODBCS /* Double-byte character set routines */
219 #define NOKEYBOARDINFO /* Keyboard driver routines */
220 #define NOCOLOR /* COLOR_* color values */
221 #define NODRAWTEXT /* DrawText() and related definitions */
222 #define NOSCALABLEFONT /* Truetype scalable font support */
223 #define NOMETAFILE /* Metafile support */
224 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
225 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
226 #define NOKEYSTATES /* MK_* message key state flags */
227 #define NOWH /* SetWindowsHook and related WH_* definitions */
228 #define NOCLIPBOARD /* Clipboard APIs and definitions */
229 #define NOICONS /* IDI_* icon IDs */
230 #define NOMDI /* MDI support */
231 #define NOHELP /* Help support */
233 /* Not defined since it breaks Borland C++ 5.5 */
234 /* #define NOCTLMGR */ /* Control management and controls */
237 * Exclude parts of WINDOWS.H that are not needed (Win32)
239 #define WIN32_LEAN_AND_MEAN
240 #define NONLS /* All NLS defines and routines */
241 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
242 #define NOKANJI /* Kanji support stuff. */
243 #define NOMCX /* Modem Configuration Extensions */
246 * Include the "windows" support file
251 * Exclude parts of MMSYSTEM.H that are not needed
253 #define MMNODRV /* Installable driver support */
254 #define MMNOWAVE /* Waveform support */
255 #define MMNOMIDI /* MIDI support */
256 #define MMNOAUX /* Auxiliary audio support */
257 #define MMNOTIMER /* Timer support */
258 #define MMNOJOY /* Joystick support */
259 #define MMNOMCI /* MCI support */
260 #define MMNOMMIO /* Multimedia file I/O support */
261 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
264 * Include some more files. Note: the Cygnus Cygwin compiler
265 * doesn't use mmsystem.h instead it includes the winmm library
266 * which performs a similar function.
268 #include <mmsystem.h>
272 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
273 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
275 /* #define HTML_HELP */
278 #include <htmlhelp.h>
279 #endif /* HTML_HELP */
282 * Include the support for loading bitmaps
285 # include "readdib.h"
289 * Hack -- Fake declarations from "dos.h" XXX XXX XXX
292 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
294 #define FA_LABEL 0x08 /* Volume label */
295 #define FA_DIREC 0x10 /* Directory */
296 unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
300 * Silliness in WIN32 drawing routine
303 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
307 * Silliness for Windows 95
309 #ifndef WS_EX_TOOLWINDOW
310 # define WS_EX_TOOLWINDOW 0
314 * Foreground color bits (hard-coded by DOS)
316 #define VID_BLACK 0x00
317 #define VID_BLUE 0x01
318 #define VID_GREEN 0x02
319 #define VID_CYAN 0x03
321 #define VID_MAGENTA 0x05
322 #define VID_YELLOW 0x06
323 #define VID_WHITE 0x07
326 * Bright text (hard-coded by DOS)
328 #define VID_BRIGHT 0x08
331 * Background color bits (hard-coded by DOS)
333 #define VUD_BLACK 0x00
334 #define VUD_BLUE 0x10
335 #define VUD_GREEN 0x20
336 #define VUD_CYAN 0x30
338 #define VUD_MAGENTA 0x50
339 #define VUD_YELLOW 0x60
340 #define VUD_WHITE 0x70
343 * Blinking text (hard-coded by DOS)
345 #define VUD_BRIGHT 0x80
351 typedef struct _term_data term_data;
356 * Note the use of "font_want" for the names of the font file requested by
357 * the user, and the use of "font_file" for the currently active font file.
359 * The "font_file" is uppercased, and takes the form "8X13.FON", while
360 * "font_want" can be in almost any form as long as it could be construed
361 * as attempting to represent the name of a font.
376 uint rows; /* int -> uint */
412 #if 1 /* #ifdef JP */
427 * Maximum number of windows XXX XXX XXX
429 #define MAX_TERM_DATA 8
432 * An array of term_data's
434 static term_data data[MAX_TERM_DATA];
437 * Hack -- global "window creation" pointer
439 static term_data *my_td;
442 * Remember normal size of main window when maxmized
447 * was main window maximized on previous playing
449 bool win_maximized = FALSE;
454 bool game_in_progress = FALSE;
457 * note when "open"/"new" become valid
459 bool initialized = FALSE;
462 * screen paletted, i.e. 256 colors
464 bool paletted = FALSE;
467 * 16 colors screen, don't use RGB()
469 bool colors16 = FALSE;
472 * Saved instance handle
474 static HINSTANCE hInstance;
477 * Yellow brush for the cursor
479 static HBRUSH hbrYellow;
489 static HPALETTE hPal;
492 static HBITMAP hBG = NULL;
493 static int use_bg = 0;
494 static char bg_bitmap_file[1024] = "bg.bmp";
499 * The screen saver window
501 static HWND hwndSaver;
503 #endif /* USE_SAVER */
509 * Flag set once "graphics" has been initialized
511 static bool can_use_graphics = FALSE;
516 static DIBINIT infGraph;
519 * The global bitmap mask
521 static DIBINIT infMask;
523 #endif /* USE_GRAPHICS */
529 * Flag set once "sound" has been initialized
531 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 */
544 * Full path to ANGBAND.INI
546 static cptr ini_file = NULL;
549 * Name of application
551 static cptr AppName = "ANGBAND";
554 * Name of sub-window type
556 static cptr AngList = "AngList";
561 static cptr ANGBAND_DIR_XTRA_GRAF;
562 static cptr ANGBAND_DIR_XTRA_SOUND;
563 static cptr ANGBAND_DIR_XTRA_MUSIC;
564 static cptr ANGBAND_DIR_XTRA_HELP;
565 #if 0 /* #ifndef JP */
566 static cptr ANGBAND_DIR_XTRA_FONT;
569 static cptr ANGBAND_DIR_XTRA_MUSIC;
574 * The "complex" color values
576 static COLORREF win_clr[256];
580 * Flag for macro trigger with dump ASCII
582 static bool Term_no_press = FALSE;
587 static bool mouse_down = FALSE;
588 static bool paint_rect = FALSE;
589 static int mousex = 0, mousey = 0;
590 static int oldx, oldy;
594 * The "simple" color values
596 * See "main-ibm.c" for original table information
598 * The entries below are taken from the "color bits" defined above.
600 * Note that many of the choices below suck, but so do crappy monitors.
602 static BYTE win_pal[256] =
604 VID_BLACK, /* Dark */
605 VID_WHITE, /* White */
606 VID_CYAN, /* Slate XXX */
607 VID_RED | VID_BRIGHT, /* Orange XXX */
609 VID_GREEN, /* Green */
611 VID_YELLOW, /* Umber XXX */
612 VID_BLACK | VID_BRIGHT, /* Light Dark */
613 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
614 VID_MAGENTA, /* Violet XXX */
615 VID_YELLOW | VID_BRIGHT, /* Yellow */
616 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
617 VID_GREEN | VID_BRIGHT, /* Light Green */
618 VID_BLUE | VID_BRIGHT, /* Light Blue */
619 VID_YELLOW /* Light Umber XXX */
624 * Hack -- define which keys are "special"
626 static bool special_key[256];
627 static bool ignore_key[256];
631 * Hack -- initialization list for "special_key"
633 static byte special_key_list[] = {
634 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
635 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
636 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
637 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
638 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
639 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
640 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
641 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
642 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
643 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
644 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
645 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
646 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
647 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
648 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
649 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
650 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
655 static byte ignore_key_list[] = {
656 VK_ESCAPE, VK_TAB, VK_SPACE,
657 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
658 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
659 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
665 * Hack -- initialization list for "special_key"
667 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
668 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
669 * catch the keypad keys (with and without numlock set, including keypad 5),
670 * the function keys (including the "menu" key which maps to F10), and the
671 * "pause" key (between scroll lock and numlock). We also catch a few odd
672 * keys which I do not recognize, but which are listed among keys which we
673 * do catch, so they should be harmless to catch.
675 static byte special_key_list[] =
677 VK_CLEAR, /* 0x0C (KP<5>) */
679 VK_PAUSE, /* 0x13 (pause) */
681 VK_PRIOR, /* 0x21 (KP<9>) */
682 VK_NEXT, /* 0x22 (KP<3>) */
683 VK_END, /* 0x23 (KP<1>) */
684 VK_HOME, /* 0x24 (KP<7>) */
685 VK_LEFT, /* 0x25 (KP<4>) */
686 VK_UP, /* 0x26 (KP<8>) */
687 VK_RIGHT, /* 0x27 (KP<6>) */
688 VK_DOWN, /* 0x28 (KP<2>) */
689 VK_SELECT, /* 0x29 (?????) */
690 VK_PRINT, /* 0x2A (?????) */
691 VK_EXECUTE, /* 0x2B (?????) */
692 VK_SNAPSHOT, /* 0x2C (?????) */
693 VK_INSERT, /* 0x2D (KP<0>) */
694 VK_DELETE, /* 0x2E (KP<.>) */
695 VK_HELP, /* 0x2F (?????) */
697 VK_NUMPAD0, /* 0x60 (KP<0>) */
698 VK_NUMPAD1, /* 0x61 (KP<1>) */
699 VK_NUMPAD2, /* 0x62 (KP<2>) */
700 VK_NUMPAD3, /* 0x63 (KP<3>) */
701 VK_NUMPAD4, /* 0x64 (KP<4>) */
702 VK_NUMPAD5, /* 0x65 (KP<5>) */
703 VK_NUMPAD6, /* 0x66 (KP<6>) */
704 VK_NUMPAD7, /* 0x67 (KP<7>) */
705 VK_NUMPAD8, /* 0x68 (KP<8>) */
706 VK_NUMPAD9, /* 0x69 (KP<9>) */
707 VK_MULTIPLY, /* 0x6A (KP<*>) */
708 VK_ADD, /* 0x6B (KP<+>) */
709 VK_SEPARATOR, /* 0x6C (?????) */
710 VK_SUBTRACT, /* 0x6D (KP<->) */
711 VK_DECIMAL, /* 0x6E (KP<.>) */
712 VK_DIVIDE, /* 0x6F (KP</>) */
743 static void delete_bg(void)
752 static int init_bg(void)
754 char * bmfile = bg_bitmap_file;
757 if (use_bg == 0) return 0;
759 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
762 plog_fmt("ÊÉ»æÍÑ¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
764 plog_fmt("Can't load the bitmap file '%s'.", bmfile);
770 HDC wnddc, dcimage, dcbg;
771 HBITMAP bmimage, bmimage_old, bmbg_old;
777 dcimage = CreateCompatibleDC(wnddc);
778 dcbg = CreateCompatibleDC(wnddc);
780 bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
781 if (!bmimage) quit("bg.bmp¤¬Æɤߤ³¤á¤Ê¤¤¡ª");
782 bmimage_old = SelectObject(dcimage, bmimage);
784 CreateCompatibleBitmap();
786 ReleaseDC(hwnd, wnddc);
792 static void DrawBG(HDC hdc, RECT *r)
797 int x = r->left, y = r->top;
798 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
804 GetObject(hBG, sizeof(bm), &bm);
805 swid = bm.bmWidth; shgt = bm.bmHeight;
807 hdcSrc = CreateCompatibleDC(hdc);
808 hOld = SelectObject(hdcSrc, hBG);
812 cwid = MIN(swid - sx, r->right - nx);
815 chgt = MIN(shgt - sy, r->bottom - ny);
816 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
818 } while (ny < r->bottom);
821 } while (nx < r->right);
823 SelectObject(hdcSrc, hOld);
829 * Hack -- given a pathname, point at the filename
831 static cptr extract_file_name(cptr s)
835 /* Start at the end */
836 p = s + strlen(s) - 1;
838 /* Back up to divider */
839 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
841 /* Return file name */
848 * Hack -- given a simple filename, extract the "font size" info
850 * Return a pointer to a static buffer holding the capitalized base name.
852 #if 0 /* #ifndef JP */
853 static char *analyze_font(char *path, int *wp, int *hp)
859 /* Start at the end */
860 p = path + strlen(path) - 1;
862 /* Back up to divider */
863 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
865 /* Advance to file name */
871 /* Capitalize (be paranoid) */
872 if (islower(*s)) *s = toupper(*s);
876 s = my_strchr(p, 'X');
878 /* Extract font width */
882 hgt = s ? atoi(s+1) : 0;
895 * Check for existance of a file
897 static bool check_file(cptr s)
917 attrib = GetFileAttributes(path);
919 /* Require valid filename */
920 if (attrib == INVALID_FILE_NAME) return (FALSE);
922 /* Prohibit directory */
923 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
927 /* Examine and verify */
928 if (_dos_getfileattr(path, &attrib)) return (FALSE);
930 /* Prohibit something */
931 if (attrib & FA_LABEL) return (FALSE);
933 /* Prohibit directory */
934 if (attrib & FA_DIREC) return (FALSE);
944 * Check for existance of a directory
946 static bool check_dir(cptr s)
968 /* Remove trailing backslash */
969 if (i && (path[i-1] == '\\')) path[--i] = '\0';
974 attrib = GetFileAttributes(path);
976 /* Require valid filename */
977 if (attrib == INVALID_FILE_NAME) return (FALSE);
979 /* Require directory */
980 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return (FALSE);
984 /* Examine and verify */
985 if (_dos_getfileattr(path, &attrib)) return (FALSE);
987 /* Prohibit something */
988 if (attrib & FA_LABEL) return (FALSE);
990 /* Require directory */
991 if (!(attrib & FA_DIREC)) return (FALSE);
1003 static void validate_file(cptr s)
1005 /* Verify or fail */
1009 quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
1011 quit_fmt("Cannot find required file:\n%s", s);
1019 * Validate a directory
1021 static void validate_dir(cptr s, bool vital)
1023 /* Verify or fail */
1026 /* This directory contains needed data */
1030 quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
1032 quit_fmt("Cannot find required directory:\n%s", s);
1036 /* Attempt to create this directory */
1039 quit_fmt("Unable to create directory:\n%s", s);
1046 * Get the "size" for a window
1048 static void term_getsize(term_data *td)
1055 if (td->cols < 1) td->cols = 1;
1056 if (td->rows < 1) td->rows = 1;
1059 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1060 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1062 /* Fake window size */
1064 rc.right = rc.left + wid;
1066 rc.bottom = rc.top + hgt;
1069 /* rc.right += 1; */
1070 /* rc.bottom += 1; */
1073 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1076 td->size_wid = rc.right - rc.left;
1077 td->size_hgt = rc.bottom - rc.top;
1079 /* See CreateWindowEx */
1082 /* Extract actual location */
1083 GetWindowRect(td->w, &rc);
1085 /* Save the location */
1086 td->pos_x = rc.left;
1092 * Write the "prefs" for a single term
1094 static void save_prefs_aux(int i)
1096 term_data *td = &data[i];
1101 WINDOWPLACEMENT lpwndpl;
1106 /* Make section name */
1107 sprintf(sec_name, "Term-%d", i);
1112 strcpy(buf, td->visible ? "1" : "0");
1113 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1118 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1121 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1123 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "Courier");
1127 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1129 #if 1 /* #ifdef JP */
1130 wsprintf(buf, "%d", td->lf.lfWidth);
1131 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1132 wsprintf(buf, "%d", td->lf.lfHeight);
1133 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1134 wsprintf(buf, "%d", td->lf.lfWeight);
1135 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1138 strcpy(buf, td->bizarre ? "1" : "0");
1139 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1142 wsprintf(buf, "%d", td->tile_wid);
1143 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1146 wsprintf(buf, "%d", td->tile_hgt);
1147 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1149 /* Get window placement and dimensions */
1150 lpwndpl.length = sizeof(WINDOWPLACEMENT);
1151 GetWindowPlacement(td->w, &lpwndpl);
1153 /* Acquire position in *normal* mode (not minimized) */
1154 rc = lpwndpl.rcNormalPosition;
1156 /* Window size (x) */
1157 if (i == 0) wsprintf(buf, "%d", normsize.x);
1158 else wsprintf(buf, "%d", td->cols);
1159 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1161 /* Window size (y) */
1162 if (i == 0) wsprintf(buf, "%d", normsize.y);
1163 else wsprintf(buf, "%d", td->rows);
1164 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1166 /* Maxmized (only main window) */
1169 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
1170 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
1173 /* Acquire position */
1174 GetWindowRect(td->w, &rc);
1176 /* Window position (x) */
1177 wsprintf(buf, "%d", rc.left);
1178 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1180 /* Window position (y) */
1181 wsprintf(buf, "%d", rc.top);
1182 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1184 /* Window Z position */
1187 strcpy(buf, td->posfix ? "1" : "0");
1188 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
1196 * We assume that the windows have all been initialized
1198 static void save_prefs(void)
1204 /* Save the "arg_graphics" flag */
1205 sprintf(buf, "%d", arg_graphics);
1206 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1208 /* Save the "arg_bigtile" flag */
1209 strcpy(buf, arg_bigtile ? "1" : "0");
1210 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
1212 /* Save the "arg_sound" flag */
1213 strcpy(buf, arg_sound ? "1" : "0");
1214 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1217 strcpy(buf, use_bg ? "1" : "0");
1218 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1219 WritePrivateProfileString("Angband", "BackGroundBitmap",
1220 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1222 /* Save window prefs */
1223 for (i = 0; i < MAX_TERM_DATA; ++i)
1231 * Load the "prefs" for a single term
1233 static void load_prefs_aux(int i)
1235 term_data *td = &data[i];
1239 int wid, hgt, posx, posy;
1240 int dispx = GetSystemMetrics( SM_CXVIRTUALSCREEN);
1241 int dispy = GetSystemMetrics( SM_CYVIRTUALSCREEN);
1245 /* Make section name */
1246 sprintf(sec_name, "Term-%d", i);
1248 /* Make section name */
1249 sprintf(sec_name, "Term-%d", i);
1254 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1257 /* Desired font, with default */
1259 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1262 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1264 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
1270 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1272 /* Analyze font, save desired font name */
1273 #if 1 /* #ifdef JP */
1274 td->font_want = string_make(tmp);
1276 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1277 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1278 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1280 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1285 #if 1 /* #ifdef JP */
1286 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1287 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1289 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1290 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1295 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1296 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1297 normsize.x = td->cols; normsize.y = td->rows;
1302 win_maximized = GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file);
1305 /* Window position */
1306 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1307 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1308 td->pos_x = MIN(MAX(0, posx), dispx-128);
1309 td->pos_y = MIN(MAX(0, posy), dispy-128);
1311 /* Window Z position */
1314 td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
1322 static void load_prefs(void)
1326 /* Extract the "arg_graphics" flag */
1327 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1329 /* Extract the "arg_bigtile" flag */
1330 arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file);
1331 use_bigtile = arg_bigtile;
1333 /* Extract the "arg_sound" flag */
1334 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1337 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1338 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1340 /* Load window prefs */
1341 for (i = 0; i < MAX_TERM_DATA; ++i)
1347 #if defined(USE_SOUND) || defined(USE_MUSIC)
1350 * XXX XXX XXX - Taken from files.c.
1352 * Extract "tokens" from a buffer
1354 * This function uses "whitespace" as delimiters, and treats any amount of
1355 * whitespace as a single delimiter. We will never return any empty tokens.
1356 * When given an empty buffer, or a buffer containing only "whitespace", we
1357 * will return no tokens. We will never extract more than "num" tokens.
1359 * By running a token through the "text_to_ascii()" function, you can allow
1360 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1362 * We save pointers to the tokens in "tokens", and return the number found.
1364 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1376 /* Skip leading whitespace */
1377 for ( ; *s && iswspace(*s); ++s) /* loop */;
1382 /* Find next whitespace, if any */
1383 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1385 /* Nuke and advance (if necessary) */
1386 if (*t) *t++ = '\0';
1388 /* Save the token */
1399 #endif /* USE_SOUND || USE_MUSIC */
1403 static void load_sound_prefs(void)
1407 char ini_path[1024];
1408 char wav_path[1024];
1409 char *zz[SAMPLE_MAX];
1411 /* Access the sound.cfg */
1413 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1415 for (i = 0; i < SOUND_MAX; i++)
1417 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1419 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1421 for (j = 0; j < num; j++)
1423 /* Access the sound */
1424 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1426 /* Save the sound filename, if it exists */
1427 if (check_file(wav_path))
1428 sound_file[i][j] = string_make(zz[j]);
1433 #endif /* USE_SOUND */
1437 static void load_music_prefs(void)
1441 char ini_path[1024];
1442 char wav_path[1024];
1443 char *zz[SAMPLE_MAX];
1445 /* Access the music.cfg */
1447 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1449 for (i = 0; i < SOUND_MAX; i++)
1451 GetPrivateProfileString("Music", angband_sound_name[i], "", tmp, 1024, ini_path);
1453 num = tokenize_whitespace(tmp, SAMPLE_MAX, zz);
1455 for (j = 0; j < num; j++)
1457 /* Access the sound */
1458 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1460 /* Save the sound filename, if it exists */
1461 if (check_file(wav_path))
1462 sound_file[i][j] = string_make(zz[j]);
1467 #endif /* USE_MUSIC */
1470 * Create the new global palette based on the bitmap palette
1471 * (if any), and the standard 16 entry palette derived from
1472 * "win_clr[]" which is used for the basic 16 Angband colors.
1474 * This function is never called before all windows are ready.
1476 * This function returns FALSE if the new palette could not be
1477 * prepared, which should normally be a fatal error. XXX XXX
1479 * Note that only some machines actually use a "palette".
1481 static int new_palette(void)
1489 LPLOGPALETTE pLogPal;
1490 LPPALETTEENTRY lppe;
1495 /* This makes no sense */
1496 if (!paletted) return (TRUE);
1506 /* Check the bitmap palette */
1507 hBmPal = infGraph.hPalette;
1509 /* Use the bitmap */
1512 lppeSize = 256 * sizeof(PALETTEENTRY);
1513 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1514 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1515 if ((nEntries == 0) || (nEntries > 220))
1519 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1521 plog("Please switch to high- or true-color mode.");
1526 rnfree(lppe, lppeSize);
1533 #endif /* USE_GRAPHICS */
1535 /* Size of palette */
1536 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1538 /* Allocate palette */
1539 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1542 pLogPal->palVersion = 0x300;
1544 /* Make room for bitmap and normal data */
1545 pLogPal->palNumEntries = nEntries + 16;
1547 /* Save the bitmap data */
1548 for (i = 0; i < nEntries; i++)
1550 pLogPal->palPalEntry[i] = lppe[i];
1553 /* Save the normal data */
1554 for (i = 0; i < 16; i++)
1558 /* Access the entry */
1559 p = &(pLogPal->palPalEntry[i+nEntries]);
1561 /* Save the colors */
1562 p->peRed = GetRValue(win_clr[i]);
1563 p->peGreen = GetGValue(win_clr[i]);
1564 p->peBlue = GetBValue(win_clr[i]);
1566 /* Save the flags */
1567 p->peFlags = PC_NOCOLLAPSE;
1570 /* Free something */
1571 if (lppe) rnfree(lppe, lppeSize);
1573 /* Create a new palette, or fail */
1574 hNewPal = CreatePalette(pLogPal);
1576 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1578 if (!hNewPal) quit("Cannot create palette!");
1582 /* Free the palette */
1583 rnfree(pLogPal, pLogPalSize);
1588 /* Realize the palette */
1590 SelectPalette(hdc, hNewPal, 0);
1591 i = RealizePalette(hdc);
1592 ReleaseDC(td->w, hdc);
1594 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1596 if (i == 0) quit("Cannot realize palette!");
1601 for (i = 1; i < MAX_TERM_DATA; i++)
1606 SelectPalette(hdc, hNewPal, 0);
1607 ReleaseDC(td->w, hdc);
1610 /* Delete old palette */
1611 if (hPal) DeleteObject(hPal);
1613 /* Save new palette */
1623 * Initialize graphics
1625 static bool init_graphics(void)
1627 /* Initialize once */
1628 /* if (can_use_graphics != arg_graphics) */
1634 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1641 ANGBAND_GRAF = "new";
1643 else if (arg_graphics == GRAPHICS_HENGBAND)
1650 ANGBAND_GRAF = "ne2";
1658 ANGBAND_GRAF = "old";
1661 /* Access the bitmap file */
1662 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1664 /* Load the bitmap or quit */
1665 if (!ReadDIB(data[0].w, buf, &infGraph))
1668 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1670 plog_fmt("Cannot read bitmap file '%s'", name);
1676 /* Save the new sizes */
1677 infGraph.CellWidth = wid;
1678 infGraph.CellHeight = hgt;
1680 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1682 /* Access the mask file */
1683 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1685 /* Load the bitmap or quit */
1686 if (!ReadDIB(data[0].w, buf, &infMask))
1688 plog_fmt("Cannot read bitmap file '%s'", buf);
1692 if (arg_graphics == GRAPHICS_HENGBAND)
1694 /* Access the mask file */
1695 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1697 /* Load the bitmap or quit */
1698 if (!ReadDIB(data[0].w, buf, &infMask))
1700 plog_fmt("Cannot read bitmap file '%s'", buf);
1705 /* Activate a palette */
1708 /* Free bitmap XXX XXX XXX */
1712 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1714 plog("Cannot activate palette!");
1720 /* Graphics available */
1721 can_use_graphics = arg_graphics;
1725 return (can_use_graphics);
1727 #endif /* USE_GRAPHICS */
1734 static bool init_sound(void)
1736 /* Initialize once */
1739 /* Load the prefs */
1742 /* Sound available */
1743 can_use_sound = TRUE;
1747 return (can_use_sound);
1749 #endif /* USE_SOUND */
1755 static void term_window_resize(term_data *td)
1757 /* Require window */
1760 /* Resize the window */
1761 SetWindowPos(td->w, 0, 0, 0,
1762 td->size_wid, td->size_hgt,
1763 SWP_NOMOVE | SWP_NOZORDER);
1766 InvalidateRect(td->w, NULL, TRUE);
1771 * Force the use of a new "font file" for a term_data
1773 * This function may be called before the "window" is ready
1775 * This function returns zero only if everything succeeds.
1777 * Note that the "font name" must be capitalized!!!
1779 static errr term_force_font(term_data *td, cptr path)
1783 #if 0 /* #ifndef JP */
1789 /* Forget the old font (if needed) */
1790 if (td->font_id) DeleteObject(td->font_id);
1792 #if 1 /* #ifdef JP */
1796 /* Create the font (using the 'base' of the font file name!) */
1797 td->font_id = CreateFontIndirect(&(td->lf));
1798 wid = td->lf.lfWidth;
1799 hgt = td->lf.lfHeight;
1800 if (!td->font_id) return (1);
1802 /* Forget old font */
1808 for (i = 0; i < MAX_TERM_DATA; i++)
1810 /* Don't check when closing the application */
1813 /* Check "screen" */
1814 if ((td != &data[i]) &&
1815 (data[i].font_file) &&
1816 (streq(data[i].font_file, td->font_file)))
1822 /* Remove unused font resources */
1823 if (!used) RemoveFontResource(td->font_file);
1825 /* Free the old name */
1826 string_free(td->font_file);
1829 td->font_file = NULL;
1833 if (!path) return (1);
1838 /* Analyze font path */
1839 base = analyze_font(buf, &wid, &hgt);
1842 if (!suffix(base, ".FON")) return (1);
1845 if (!check_file(buf)) return (1);
1847 /* Load the new font */
1848 if (!AddFontResource(buf)) return (1);
1850 /* Save new font name */
1851 td->font_file = string_make(base);
1853 /* Remove the "suffix" */
1854 base[strlen(base)-4] = '\0';
1856 /* Create the font (using the 'base' of the font file name!) */
1857 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1858 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1859 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1860 FIXED_PITCH | FF_DONTCARE, base);
1863 /* Hack -- Unknown size */
1870 /* all this trouble to get the cell size */
1871 hdcDesktop = GetDC(HWND_DESKTOP);
1872 hfOld = SelectObject(hdcDesktop, td->font_id);
1873 GetTextMetrics(hdcDesktop, &tm);
1874 SelectObject(hdcDesktop, hfOld);
1875 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1877 /* Font size info */
1878 wid = tm.tmAveCharWidth;
1882 /* Save the size info */
1893 * Allow the user to change the font for this window.
1895 static void term_change_font(term_data *td)
1897 #if 1 /* #ifdef JP */
1900 memset(&cf, 0, sizeof(cf));
1901 cf.lStructSize = sizeof(cf);
1902 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1903 cf.lpLogFont = &(td->lf);
1905 if (ChooseFont(&cf))
1907 /* Force the font */
1908 term_force_font(td, NULL);
1910 /* Assume not bizarre */
1913 /* Reset the tile info */
1914 td->tile_wid = td->font_wid;
1915 td->tile_hgt = td->font_hgt;
1917 /* Analyze the font */
1920 /* Resize the window */
1921 term_window_resize(td);
1927 char tmp[1024] = "";
1929 /* Extract a default if possible */
1930 if (td->font_file) strcpy(tmp, td->font_file);
1932 /* Ask for a choice */
1933 memset(&ofn, 0, sizeof(ofn));
1934 ofn.lStructSize = sizeof(ofn);
1935 ofn.hwndOwner = data[0].w;
1936 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1937 ofn.nFilterIndex = 1;
1938 ofn.lpstrFile = tmp;
1940 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1941 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1942 ofn.lpstrDefExt = "fon";
1944 /* Force choice if legal */
1945 if (GetOpenFileName(&ofn))
1947 /* Force the font */
1948 if (term_force_font(td, tmp))
1950 /* Access the standard font file */
1951 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1953 /* Force the use of that font */
1954 (void)term_force_font(td, tmp);
1957 /* Assume not bizarre */
1958 td->bizarre = FALSE;
1960 /* Reset the tile info */
1961 td->tile_wid = td->font_wid;
1962 td->tile_hgt = td->font_hgt;
1964 /* Analyze the font */
1967 /* Resize the window */
1968 term_window_resize(td);
1975 * Allow the user to lock this window.
1977 static void term_window_pos(term_data *td, HWND hWnd)
1979 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1980 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1983 static void windows_map(void);
1986 * Hack -- redraw a term_data
1988 static void term_data_redraw(term_data *td)
1992 /* Redraw the map */
1997 /* Activate the term */
1998 Term_activate(&td->t);
2000 /* Redraw the contents */
2003 /* Restore the term */
2004 Term_activate(term_screen);
2009 void Term_inversed_area(HWND hWnd, int x, int y, int w, int h)
2013 HBRUSH myBrush, oldBrush;
2015 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
2016 int tx = td->size_ow1 + x * td->tile_wid;
2017 int ty = td->size_oh1 + y * td->tile_hgt;
2018 int tw = w * td->tile_wid - 1;
2019 int th = h * td->tile_hgt - 1;
2022 myBrush = CreateSolidBrush(RGB(255, 255, 255));
2023 oldBrush = SelectObject(hdc, myBrush);
2024 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2026 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
2028 SelectObject(hdc, oldBrush);
2029 SelectObject(hdc, oldPen);
2034 /*** Function hooks needed by "Term" ***/
2040 * Initialize a new Term
2042 static void Term_init_win(term *t)
2051 static void Term_nuke_win(term *t)
2060 * Interact with the User
2062 static errr Term_user_win(int n)
2073 * React to global changes
2075 static errr Term_xtra_win_react(void)
2083 /* Save the default colors */
2084 for (i = 0; i < 256; i++)
2086 /* Simply accept the desired colors */
2087 win_pal[i] = angband_color_table[i][0];
2098 bool change = FALSE;
2100 /* Save the default colors */
2101 for (i = 0; i < 256; i++)
2103 /* Extract desired values */
2104 rv = angband_color_table[i][1];
2105 gv = angband_color_table[i][2];
2106 bv = angband_color_table[i][3];
2108 /* Extract a full color code */
2109 code = PALETTERGB(rv, gv, bv);
2111 /* Activate changes */
2112 if (win_clr[i] != code)
2114 /* Note the change */
2117 /* Apply the desired color */
2122 /* Activate the palette if needed */
2123 if (change) (void)new_palette();
2129 /* Handle "arg_sound" */
2130 if (use_sound != arg_sound)
2132 /* Initialize (if needed) */
2133 if (arg_sound && !init_sound())
2137 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
2139 plog("Cannot initialize sound!");
2147 /* Change setting */
2148 use_sound = arg_sound;
2156 /* Handle "arg_graphics" */
2157 if (use_graphics != arg_graphics)
2159 /* Initialize (if needed) */
2160 if (arg_graphics && !init_graphics())
2164 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
2166 plog("Cannot initialize graphics!");
2171 arg_graphics = GRAPHICS_NONE;
2174 /* Change setting */
2175 use_graphics = arg_graphics;
2178 #ifdef ANGBAND_2_8_1
2180 #else /* ANGBAND_2_8_1 */
2181 reset_visuals(TRUE);
2182 #endif /* ANGBAND_2_8_1 */
2185 #endif /* USE_GRAPHICS */
2188 /* Clean up windows */
2189 for (i = 0; i < MAX_TERM_DATA; i++)
2193 term_data *td = &data[i];
2195 /* Update resized windows */
2196 if ((td->cols != (uint)td->t.wid) || (td->rows != (uint)td->t.hgt))
2199 Term_activate(&td->t);
2201 /* Hack -- Resize the term */
2202 Term_resize(td->cols, td->rows);
2204 /* Redraw the contents */
2219 * Process at least one event
2221 static errr Term_xtra_win_event(int v)
2225 /* Wait for an event */
2229 if (GetMessage(&msg, NULL, 0, 0))
2231 TranslateMessage(&msg);
2232 DispatchMessage(&msg);
2236 /* Check for an event */
2240 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2242 TranslateMessage(&msg);
2243 DispatchMessage(&msg);
2253 * Process all pending events
2255 static errr Term_xtra_win_flush(void)
2259 /* Process all pending events */
2260 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2262 TranslateMessage(&msg);
2263 DispatchMessage(&msg);
2272 * Hack -- clear the screen
2274 * Make this more efficient XXX XXX XXX
2276 static errr Term_xtra_win_clear(void)
2278 term_data *td = (term_data*)(Term->data);
2283 /* Rectangle to erase */
2284 rc.left = td->size_ow1;
2285 rc.right = rc.left + td->cols * td->tile_wid;
2286 rc.top = td->size_oh1;
2287 rc.bottom = rc.top + td->rows * td->tile_hgt;
2291 SetBkColor(hdc, RGB(0, 0, 0));
2292 SelectObject(hdc, td->font_id);
2293 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2298 rc.left = 0; rc.top = 0;
2301 ReleaseDC(td->w, hdc);
2309 * Hack -- make a noise
2311 static errr Term_xtra_win_noise(void)
2313 MessageBeep(MB_ICONASTERISK);
2319 * Hack -- make a sound
2321 static errr Term_xtra_win_sound(int v)
2326 #endif /* USE_SOUND */
2328 /* Sound disabled */
2329 if (!use_sound) return (1);
2332 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2336 /* Count the samples */
2337 for (i = 0; i < SAMPLE_MAX; i++)
2339 if (!sound_file[v][i])
2344 if (i == 0) return (1);
2346 /* Build the path */
2347 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
2351 /* Play the sound, catch errors */
2352 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
2356 /* Play the sound, catch errors */
2357 return (sndPlaySound(buf, SND_ASYNC));
2361 #else /* USE_SOUND */
2366 #endif /* USE_SOUND */
2371 * Delay for "x" milliseconds
2373 static int Term_xtra_win_delay(int v)
2387 t = GetTickCount() + v;
2390 while (GetTickCount() < t)
2392 /* Handle messages */
2393 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2395 TranslateMessage(&msg);
2396 DispatchMessage(&msg);
2408 * Do a "special thing"
2410 static errr Term_xtra_win(int n, int v)
2412 /* Handle a subset of the legal requests */
2415 /* Make a bell sound */
2416 case TERM_XTRA_NOISE:
2418 return (Term_xtra_win_noise());
2421 /* Make a special sound */
2422 case TERM_XTRA_SOUND:
2424 return (Term_xtra_win_sound(v));
2427 /* Process random events */
2428 case TERM_XTRA_BORED:
2430 return (Term_xtra_win_event(0));
2433 /* Process an event */
2434 case TERM_XTRA_EVENT:
2436 return (Term_xtra_win_event(v));
2439 /* Flush all events */
2440 case TERM_XTRA_FLUSH:
2442 return (Term_xtra_win_flush());
2445 /* Clear the screen */
2446 case TERM_XTRA_CLEAR:
2448 return (Term_xtra_win_clear());
2451 /* React to global changes */
2452 case TERM_XTRA_REACT:
2454 return (Term_xtra_win_react());
2457 /* Delay for some milliseconds */
2458 case TERM_XTRA_DELAY:
2460 return (Term_xtra_win_delay(v));
2471 * Low level graphics (Assumes valid input).
2473 * Draw a "cursor" at (x,y), using a "yellow box".
2475 static errr Term_curs_win(int x, int y)
2477 term_data *td = (term_data*)(Term->data);
2482 int tile_wid, tile_hgt;
2486 tile_wid = td->map_tile_wid;
2487 tile_hgt = td->map_tile_hgt;
2491 tile_wid = td->tile_wid;
2492 tile_hgt = td->tile_hgt;
2495 /* Frame the grid */
2496 rc.left = x * tile_wid + td->size_ow1;
2497 rc.right = rc.left + tile_wid;
2498 rc.top = y * tile_hgt + td->size_oh1;
2499 rc.bottom = rc.top + tile_hgt;
2501 /* Cursor is done as a yellow "box" */
2503 FrameRect(hdc, &rc, hbrYellow);
2504 ReleaseDC(td->w, hdc);
2512 * Low level graphics (Assumes valid input).
2514 * Draw a "big cursor" at (x,y), using a "yellow box".
2516 static errr Term_bigcurs_win(int x, int y)
2518 term_data *td = (term_data*)(Term->data);
2523 int tile_wid, tile_hgt;
2527 /* Normal cursor in map window */
2528 Term_curs_win(x, y);
2533 tile_wid = td->tile_wid;
2534 tile_hgt = td->tile_hgt;
2537 /* Frame the grid */
2538 rc.left = x * tile_wid + td->size_ow1;
2539 rc.right = rc.left + 2 * tile_wid;
2540 rc.top = y * tile_hgt + td->size_oh1;
2541 rc.bottom = rc.top + tile_hgt;
2543 /* Cursor is done as a yellow "box" */
2545 FrameRect(hdc, &rc, hbrYellow);
2546 ReleaseDC(td->w, hdc);
2554 * Low level graphics (Assumes valid input).
2556 * Erase a "block" of "n" characters starting at (x,y).
2558 static errr Term_wipe_win(int x, int y, int n)
2560 term_data *td = (term_data*)(Term->data);
2565 /* Rectangle to erase in client coords */
2566 rc.left = x * td->tile_wid + td->size_ow1;
2567 rc.right = rc.left + n * td->tile_wid;
2568 rc.top = y * td->tile_hgt + td->size_oh1;
2569 rc.bottom = rc.top + td->tile_hgt;
2572 SetBkColor(hdc, RGB(0, 0, 0));
2573 SelectObject(hdc, td->font_id);
2578 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2579 ReleaseDC(td->w, hdc);
2587 * Low level graphics. Assumes valid input.
2589 * Draw several ("n") chars, with an attr, at a given location.
2591 * All "graphic" data is handled by "Term_pict_win()", below.
2593 * One would think there is a more efficient method for telling a window
2594 * what color it should be using to draw with, but perhaps simply changing
2595 * it every time is not too inefficient. XXX XXX XXX
2597 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2599 term_data *td = (term_data*)(Term->data);
2603 #if 1 /* #ifdef JP */
2604 static HBITMAP WALL;
2605 static HBRUSH myBrush, oldBrush;
2607 static bool init_done = FALSE;
2610 WALL = LoadBitmap(hInstance, AppName);
2611 myBrush = CreatePatternBrush(WALL);
2616 /* Total rectangle */
2617 rc.left = x * td->tile_wid + td->size_ow1;
2618 rc.right = rc.left + n * td->tile_wid;
2619 rc.top = y * td->tile_hgt + td->size_oh1;
2620 rc.bottom = rc.top + td->tile_hgt;
2625 /* Background color */
2626 SetBkColor(hdc, RGB(0, 0, 0));
2628 /* Foreground color */
2631 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2635 SetTextColor(hdc, win_clr[a&0x0F]);
2639 SetTextColor(hdc, win_clr[a]);
2643 SelectObject(hdc, td->font_id);
2646 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2650 (td->tile_hgt != td->font_hgt) ||
2651 (td->tile_wid != td->font_wid))
2655 /* Erase complete rectangle */
2656 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2659 if (use_bg) DrawBG(hdc, &rc);
2662 rc.left += ((td->tile_wid - td->font_wid) / 2);
2663 rc.right = rc.left + td->font_wid;
2664 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2665 rc.bottom = rc.top + td->font_hgt;
2667 /* Dump each character */
2668 for (i = 0; i < n; i++)
2671 if (use_bigtile && *(s+i)=="¢£"[0] && *(s+i+1)=="¢£"[1])
2673 rc.right += td->font_wid;
2675 oldBrush = SelectObject(hdc, myBrush);
2676 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2679 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2681 SelectObject(hdc, oldBrush);
2682 SelectObject(hdc, oldPen);
2683 rc.right -= td->font_wid;
2687 rc.left += 2 * td->tile_wid;
2688 rc.right += 2 * td->tile_wid;
2690 else if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2692 rc.right += td->font_wid;
2694 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2696 rc.right -= td->font_wid;
2700 rc.left += 2 * td->tile_wid;
2701 rc.right += 2 * td->tile_wid;
2702 } else if (*(s+i)==127){
2703 oldBrush = SelectObject(hdc, myBrush);
2704 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2707 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2709 SelectObject(hdc, oldBrush);
2710 SelectObject(hdc, oldPen);
2713 rc.left += td->tile_wid;
2714 rc.right += td->tile_wid;
2717 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s+i, 1, NULL);
2720 rc.left += td->tile_wid;
2721 rc.right += td->tile_wid;
2726 oldBrush = SelectObject(hdc, myBrush);
2727 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2730 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2732 SelectObject(hdc, oldBrush);
2733 SelectObject(hdc, oldPen);
2736 rc.left += td->tile_wid;
2737 rc.right += td->tile_wid;
2740 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2744 rc.left += td->tile_wid;
2745 rc.right += td->tile_wid;
2749 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2753 rc.left += td->tile_wid;
2754 rc.right += td->tile_wid;
2765 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2770 ReleaseDC(td->w, hdc);
2778 * Low level graphics. Assumes valid input.
2780 * Draw an array of "special" attr/char pairs at the given location.
2782 * We use the "Term_pict_win()" function for "graphic" data, which are
2783 * encoded by setting the "high-bits" of both the "attr" and the "char"
2784 * data. We use the "attr" to represent the "row" of the main bitmap,
2785 * and the "char" to represent the "col" of the main bitmap. The use
2786 * of this function is induced by the "higher_pict" flag.
2788 * If "graphics" is not available, we simply "wipe" the given grids.
2790 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2792 term_data *td = (term_data*)(Term->data);
2798 int x2, y2, w2, h2, tw2;
2810 /* Erase the grids */
2811 return (Term_wipe_win(x, y, n));
2814 /* Size of bitmap cell */
2815 w1 = infGraph.CellWidth;
2816 h1 = infGraph.CellHeight;
2818 /* Size of window cell */
2821 w2 = td->map_tile_wid;
2822 h2 = td->map_tile_hgt;
2831 if (use_bigtile) tw2 *= 2;
2834 /* Location of window cell */
2835 x2 = x * w2 + td->size_ow1;
2836 y2 = y * h2 + td->size_oh1;
2842 hdcSrc = CreateCompatibleDC(hdc);
2843 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2845 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2847 hdcMask = CreateCompatibleDC(hdc);
2848 SelectObject(hdcMask, infMask.hBitmap);
2851 /* Draw attr/char pairs */
2852 for (i = 0; i < n; i++, x2 += w2)
2857 /* Extract picture */
2858 int row = (a & 0x7F);
2859 int col = (c & 0x7F);
2861 /* Location of bitmap cell */
2865 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2867 x3 = (tcp[i] & 0x7F) * w1;
2868 y3 = (tap[i] & 0x7F) * h1;
2871 if ((w1 == tw2) && (h1 == h2))
2873 /* Copy the terrain picture from the bitmap to the window */
2874 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2876 /* Mask out the tile */
2877 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2880 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2883 /* Need to stretch */
2886 /* Set the correct mode for stretching the tiles */
2887 SetStretchBltMode(hdc, COLORONCOLOR);
2889 /* Copy the terrain picture from the bitmap to the window */
2890 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
2892 /* Only draw if terrain and overlay are different */
2893 if ((x1 != x3) || (y1 != y3))
2895 /* Mask out the tile */
2896 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2899 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2906 if ((w1 == tw2) && (h1 == h2))
2908 /* Copy the picture from the bitmap to the window */
2909 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2912 /* Need to stretch */
2915 /* Set the correct mode for stretching the tiles */
2916 SetStretchBltMode(hdc, COLORONCOLOR);
2918 /* Copy the picture from the bitmap to the window */
2919 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2925 SelectObject(hdcSrc, hbmSrcOld);
2928 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2931 SelectObject(hdcMask, hbmSrcOld);
2936 ReleaseDC(td->w, hdc);
2938 #else /* USE_GRAPHICS */
2940 /* Just erase this grid */
2941 return (Term_wipe_win(x, y, n));
2943 #endif /* USE_GRAPHICS */
2950 static void windows_map(void)
2952 term_data *td = &data[0];
2954 int x, min_x, max_x;
2955 int y, min_y, max_y;
2959 /* Only in graphics mode */
2960 if (!use_graphics) return;
2963 Term_xtra_win_clear();
2965 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2966 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2967 td->map_active = TRUE;
2977 for (x = min_x; x < max_x; x++)
2979 for (y = min_y; y < max_y; y++)
2981 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
2983 /* Ignore non-graphics */
2984 if ((a & 0x80) && (c & 0x80))
2986 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2991 /* Hilite the player */
2992 Term_curs_win(px - min_x, py - min_y);
2994 /* Wait for a keypress, flush key buffer */
2995 Term_inkey(&c, TRUE, TRUE);
2998 /* Switch off the map display */
2999 td->map_active = FALSE;
3001 /* Restore screen */
3002 Term_xtra_win_clear();
3007 /*** Other routines ***/
3011 * Create and initialize a "term_data" given a title
3013 static void term_data_link(term_data *td)
3017 /* Initialize the term */
3018 term_init(t, td->cols, td->rows, td->keys);
3020 /* Use a "software" cursor */
3021 t->soft_cursor = TRUE;
3023 /* Use "Term_pict" for "graphic" data */
3024 t->higher_pict = TRUE;
3026 /* Erase with "white space" */
3027 t->attr_blank = TERM_WHITE;
3028 t->char_blank = ' ';
3031 /* Prepare the init/nuke hooks */
3032 t->init_hook = Term_init_win;
3033 t->nuke_hook = Term_nuke_win;
3036 /* Prepare the template hooks */
3037 t->user_hook = Term_user_win;
3038 t->xtra_hook = Term_xtra_win;
3039 t->curs_hook = Term_curs_win;
3040 t->bigcurs_hook = Term_bigcurs_win;
3041 t->wipe_hook = Term_wipe_win;
3042 t->text_hook = Term_text_win;
3043 t->pict_hook = Term_pict_win;
3045 /* Remember where we came from */
3046 t->data = (vptr)(td);
3051 * Create the windows
3053 * First, instantiate the "default" values, then read the "ini_file"
3054 * to over-ride selected values, then create the windows, and fonts.
3056 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
3057 * must make active to realize the palette. XXX XXX XXX
3059 static void init_windows(void)
3065 #if 0 /* #ifndef JP */
3071 WIPE(td, term_data);
3075 td->s = angband_term_name[0];
3089 #if 1 /* #ifdef JP */
3093 for (i = 1; i < MAX_TERM_DATA; i++)
3096 WIPE(td, term_data);
3097 td->s = angband_term_name[i];
3101 td->visible = FALSE;
3106 td->pos_x = (7 - i) * 30;
3107 td->pos_y = (7 - i) * 20;
3109 #if 1 /* #ifdef JP */
3119 /* Main window (need these before term_getsize gets called) */
3121 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
3122 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
3127 /* Sub windows (need these before term_getsize gets called) */
3128 for (i = 1; i < MAX_TERM_DATA; i++)
3131 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
3132 td->dwExStyle = (WS_EX_TOOLWINDOW);
3137 for (i = 0; i < MAX_TERM_DATA; i++)
3141 #if 1 /* #ifdef JP */
3142 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
3143 td->lf.lfCharSet = DEFAULT_CHARSET;
3144 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
3145 /* Activate the chosen font */
3146 term_force_font(td, NULL);
3147 td->tile_wid = td->font_wid;
3148 td->tile_hgt = td->font_hgt;
3150 /* Access the standard font file */
3151 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, td->font_want);
3153 /* Activate the chosen font */
3154 if (term_force_font(td, buf))
3156 /* Access the standard font file */
3157 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
3159 /* Force the use of that font */
3160 (void)term_force_font(td, buf);
3166 /* Assume not bizarre */
3167 td->bizarre = FALSE;
3172 /* Analyze the font */
3175 /* Resize the window */
3176 term_window_resize(td);
3180 /* Sub windows (reverse order) */
3181 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
3186 td->w = CreateWindowEx(td->dwExStyle, AngList,
3188 td->pos_x, td->pos_y,
3189 td->size_wid, td->size_hgt,
3190 HWND_DESKTOP, NULL, hInstance, NULL);
3193 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3195 if (!td->w) quit("Failed to create sub-window");
3201 td->size_hack = TRUE;
3202 ShowWindow(td->w, SW_SHOW);
3203 td->size_hack = FALSE;
3207 angband_term[i] = &td->t;
3211 /* Activate the window */
3212 SetActiveWindow(td->w);
3217 term_window_pos(&data[i], HWND_TOPMOST);
3221 term_window_pos(&data[i], td->w);
3231 td->w = CreateWindowEx(td->dwExStyle, AppName,
3233 td->pos_x, td->pos_y,
3234 td->size_wid, td->size_hgt,
3235 HWND_DESKTOP, NULL, hInstance, NULL);
3238 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
3240 if (!td->w) quit("Failed to create Angband window");
3245 angband_term[0] = &td->t;
3246 normsize.x = td->cols;
3247 normsize.y = td->rows;
3249 /* Activate the main window */
3250 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
3251 else ShowWindow(td->w, SW_SHOW);
3253 /* Bring main window back to top */
3254 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3257 /* New palette XXX XXX XXX */
3258 (void)new_palette();
3261 /* Create a "brush" for drawing the "cursor" */
3262 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
3265 /* Process pending messages */
3266 (void)Term_xtra_win_flush();
3274 static void setup_menus(void)
3278 HMENU hm = GetMenu(data[0].w);
3281 /* Menu "File", Disable all */
3282 EnableMenuItem(hm, IDM_FILE_NEW,
3283 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3284 EnableMenuItem(hm, IDM_FILE_OPEN,
3285 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3286 EnableMenuItem(hm, IDM_FILE_SAVE,
3287 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3288 EnableMenuItem(hm, IDM_FILE_EXIT,
3289 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3290 EnableMenuItem(hm, IDM_FILE_SCORE,
3291 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3294 /* No character available */
3295 if (!character_generated)
3297 /* Menu "File", Item "New" */
3298 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
3300 /* Menu "File", Item "Open" */
3301 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
3304 /* A character available */
3305 if (character_generated)
3307 /* Menu "File", Item "Save" */
3308 EnableMenuItem(hm, IDM_FILE_SAVE,
3309 MF_BYCOMMAND | MF_ENABLED);
3312 /* Menu "File", Item "Exit" */
3313 EnableMenuItem(hm, IDM_FILE_EXIT,
3314 MF_BYCOMMAND | MF_ENABLED);
3316 EnableMenuItem(hm, IDM_FILE_SCORE,
3317 MF_BYCOMMAND | MF_ENABLED);
3320 /* Menu "Window::Visibility" */
3321 for (i = 0; i < MAX_TERM_DATA; i++)
3323 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3324 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3326 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3327 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
3329 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
3330 MF_BYCOMMAND | MF_ENABLED);
3333 /* Menu "Window::Font" */
3334 for (i = 0; i < MAX_TERM_DATA; i++)
3336 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3337 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3339 if (data[i].visible)
3341 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
3342 MF_BYCOMMAND | MF_ENABLED);
3346 /* Menu "Window::Window Position Fix" */
3347 for (i = 0; i < MAX_TERM_DATA; i++)
3349 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3350 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3352 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i,
3353 (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
3355 if (data[i].visible)
3357 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i,
3358 MF_BYCOMMAND | MF_ENABLED);
3362 /* Menu "Window::Bizarre Display" */
3363 for (i = 0; i < MAX_TERM_DATA; i++)
3365 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3366 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3368 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3369 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3371 if (data[i].visible)
3373 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3374 MF_BYCOMMAND | MF_ENABLED);
3379 /* Menu "Window::Increase Tile Width" */
3380 for (i = 0; i < MAX_TERM_DATA; i++)
3382 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3383 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3385 if (data[i].visible)
3387 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3388 MF_BYCOMMAND | MF_ENABLED);
3393 /* Menu "Window::Decrease Tile Width" */
3394 for (i = 0; i < MAX_TERM_DATA; i++)
3396 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3397 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3399 if (data[i].visible)
3401 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3402 MF_BYCOMMAND | MF_ENABLED);
3407 /* Menu "Window::Increase Tile Height" */
3408 for (i = 0; i < MAX_TERM_DATA; i++)
3410 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3411 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3413 if (data[i].visible)
3415 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3416 MF_BYCOMMAND | MF_ENABLED);
3421 /* Menu "Window::Decrease Tile Height" */
3422 for (i = 0; i < MAX_TERM_DATA; i++)
3424 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3425 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3427 if (data[i].visible)
3429 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3430 MF_BYCOMMAND | MF_ENABLED);
3435 /* Menu "Options", disable all */
3436 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3437 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3438 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3439 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3440 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3441 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3442 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE,
3443 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3444 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3445 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3447 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3448 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3451 /* Menu "Options", Item "Map" */
3452 if (use_graphics != GRAPHICS_NONE)
3453 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3455 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3456 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3458 /* Menu "Options", update all */
3459 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3460 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3461 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3462 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3463 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3464 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3465 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
3466 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
3467 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
3468 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
3469 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3470 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3471 CheckMenuItem(hm, IDM_OPTIONS_BG,
3472 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3474 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3475 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3479 /* Menu "Options", Item "Graphics" */
3480 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3481 /* Menu "Options", Item "Graphics" */
3482 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3483 /* Menu "Options", Item "Graphics" */
3484 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3485 /* Menu "Options", Item "Graphics" */
3486 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
3487 #endif /* USE_GRAPHICS */
3490 /* Menu "Options", Item "Sound" */
3491 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3492 #endif /* USE_SOUND */
3495 /* Menu "Options", Item "ScreenSaver" */
3496 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3497 MF_BYCOMMAND | MF_ENABLED);
3498 #endif /* USE_SAVER */
3503 * Check for double clicked (or dragged) savefile
3505 * Apparently, Windows copies the entire filename into the first
3506 * piece of the "command line string". Perhaps we should extract
3507 * the "basename" of that filename and append it to the "save" dir.
3509 static void check_for_save_file(LPSTR cmd_line)
3519 /* Extract filename */
3520 strcat(savefile, s);
3522 /* Validate the file */
3523 validate_file(savefile);
3525 /* Game in progress */
3526 game_in_progress = TRUE;
3534 * Process a menu command
3536 static void process_menus(WORD wCmd)
3553 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3555 plog("You cannot do that yet...");
3559 else if (game_in_progress)
3562 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3564 plog("You can't start a new game while you're still playing!");
3570 game_in_progress = TRUE;
3584 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3586 plog("You cannot do that yet...");
3590 else if (game_in_progress)
3593 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3595 plog("You can't open a new game while you're still playing!");
3601 memset(&ofn, 0, sizeof(ofn));
3602 ofn.lStructSize = sizeof(ofn);
3603 ofn.hwndOwner = data[0].w;
3604 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3605 ofn.nFilterIndex = 1;
3606 ofn.lpstrFile = savefile;
3607 ofn.nMaxFile = 1024;
3608 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3609 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3611 if (GetOpenFileName(&ofn))
3613 /* Load 'savefile' */
3614 validate_file(savefile);
3615 game_in_progress = TRUE;
3627 if (game_in_progress && character_generated)
3633 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3635 plog("You may not do that right now.");
3641 /* Hack -- Forget messages */
3646 do_cmd_save_game(FALSE);
3647 #else /* ZANGBAND */
3649 #endif /* ZANGBAND */
3654 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3656 plog("You may not do that right now.");
3666 if (game_in_progress && character_generated)
3672 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3674 plog("You may not do that right now.");
3680 /* Hack -- Forget messages */
3689 /* do_cmd_save_game(FALSE); */
3690 #else /* ZANGBAND */
3691 /* do_cmd_save_game(); */
3692 #endif /* ZANGBAND */
3693 Term_key_push(SPECIAL_KEY_QUIT);
3701 case IDM_FILE_SCORE:
3705 /* Build the filename */
3706 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
3708 /* Open the binary high score file, for reading */
3709 highscore_fd = fd_open(buf, O_RDONLY);
3711 /* Paranoia -- No score file */
3712 if (highscore_fd < 0)
3714 msg_print("Score file unavailable.");
3724 /* Display the scores */
3725 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3727 /* Shut the high score file */
3728 (void)fd_close(highscore_fd);
3730 /* Forget the high score fd */
3736 /* Hack - Flush it */
3744 case IDM_FILE_MOVIE:
3749 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3751 plog("You cannot do that yet...");
3754 else if (game_in_progress)
3757 plog("¥×¥ì¥¤Ãæ¤Ï¥à¡¼¥Ó¡¼¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3759 plog("You can't open a movie while you're playing!");
3764 memset(&ofn, 0, sizeof(ofn));
3765 ofn.lStructSize = sizeof(ofn);
3766 ofn.hwndOwner = data[0].w;
3767 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
3768 ofn.nFilterIndex = 1;
3769 ofn.lpstrFile = savefile;
3770 ofn.nMaxFile = 1024;
3771 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
3772 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
3774 if (GetOpenFileName(&ofn))
3776 /* Load 'savefile' */
3777 prepare_browse_movie_aux(savefile);
3787 case IDM_WINDOW_VIS_0:
3790 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3792 plog("You are not allowed to do that!");
3799 /* Window visibility */
3800 case IDM_WINDOW_VIS_1:
3801 case IDM_WINDOW_VIS_2:
3802 case IDM_WINDOW_VIS_3:
3803 case IDM_WINDOW_VIS_4:
3804 case IDM_WINDOW_VIS_5:
3805 case IDM_WINDOW_VIS_6:
3806 case IDM_WINDOW_VIS_7:
3808 i = wCmd - IDM_WINDOW_VIS_0;
3810 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3817 ShowWindow(td->w, SW_SHOW);
3818 term_data_redraw(td);
3822 td->visible = FALSE;
3824 ShowWindow(td->w, SW_HIDE);
3831 case IDM_WINDOW_FONT_0:
3832 case IDM_WINDOW_FONT_1:
3833 case IDM_WINDOW_FONT_2:
3834 case IDM_WINDOW_FONT_3:
3835 case IDM_WINDOW_FONT_4:
3836 case IDM_WINDOW_FONT_5:
3837 case IDM_WINDOW_FONT_6:
3838 case IDM_WINDOW_FONT_7:
3840 i = wCmd - IDM_WINDOW_FONT_0;
3842 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3846 term_change_font(td);
3851 /* Window Z Position */
3852 case IDM_WINDOW_POS_1:
3853 case IDM_WINDOW_POS_2:
3854 case IDM_WINDOW_POS_3:
3855 case IDM_WINDOW_POS_4:
3856 case IDM_WINDOW_POS_5:
3857 case IDM_WINDOW_POS_6:
3858 case IDM_WINDOW_POS_7:
3860 i = wCmd - IDM_WINDOW_POS_0;
3862 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3866 if (!td->posfix && td->visible)
3869 term_window_pos(td, HWND_TOPMOST);
3874 term_window_pos(td, data[0].w);
3880 /* Bizarre Display */
3881 case IDM_WINDOW_BIZ_0:
3882 case IDM_WINDOW_BIZ_1:
3883 case IDM_WINDOW_BIZ_2:
3884 case IDM_WINDOW_BIZ_3:
3885 case IDM_WINDOW_BIZ_4:
3886 case IDM_WINDOW_BIZ_5:
3887 case IDM_WINDOW_BIZ_6:
3888 case IDM_WINDOW_BIZ_7:
3890 i = wCmd - IDM_WINDOW_BIZ_0;
3892 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3896 td->bizarre = !td->bizarre;
3900 term_window_resize(td);
3905 /* Increase Tile Width */
3906 case IDM_WINDOW_I_WID_0:
3907 case IDM_WINDOW_I_WID_1:
3908 case IDM_WINDOW_I_WID_2:
3909 case IDM_WINDOW_I_WID_3:
3910 case IDM_WINDOW_I_WID_4:
3911 case IDM_WINDOW_I_WID_5:
3912 case IDM_WINDOW_I_WID_6:
3913 case IDM_WINDOW_I_WID_7:
3915 i = wCmd - IDM_WINDOW_I_WID_0;
3917 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3925 term_window_resize(td);
3930 /* Decrease Tile Height */
3931 case IDM_WINDOW_D_WID_0:
3932 case IDM_WINDOW_D_WID_1:
3933 case IDM_WINDOW_D_WID_2:
3934 case IDM_WINDOW_D_WID_3:
3935 case IDM_WINDOW_D_WID_4:
3936 case IDM_WINDOW_D_WID_5:
3937 case IDM_WINDOW_D_WID_6:
3938 case IDM_WINDOW_D_WID_7:
3940 i = wCmd - IDM_WINDOW_D_WID_0;
3942 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3950 term_window_resize(td);
3955 /* Increase Tile Height */
3956 case IDM_WINDOW_I_HGT_0:
3957 case IDM_WINDOW_I_HGT_1:
3958 case IDM_WINDOW_I_HGT_2:
3959 case IDM_WINDOW_I_HGT_3:
3960 case IDM_WINDOW_I_HGT_4:
3961 case IDM_WINDOW_I_HGT_5:
3962 case IDM_WINDOW_I_HGT_6:
3963 case IDM_WINDOW_I_HGT_7:
3965 i = wCmd - IDM_WINDOW_I_HGT_0;
3967 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3975 term_window_resize(td);
3980 /* Decrease Tile Height */
3981 case IDM_WINDOW_D_HGT_0:
3982 case IDM_WINDOW_D_HGT_1:
3983 case IDM_WINDOW_D_HGT_2:
3984 case IDM_WINDOW_D_HGT_3:
3985 case IDM_WINDOW_D_HGT_4:
3986 case IDM_WINDOW_D_HGT_5:
3987 case IDM_WINDOW_D_HGT_6:
3988 case IDM_WINDOW_D_HGT_7:
3990 i = wCmd - IDM_WINDOW_D_HGT_0;
3992 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
4000 term_window_resize(td);
4005 case IDM_OPTIONS_NO_GRAPHICS:
4010 plog("You may not do that right now.");
4014 /* Toggle "arg_graphics" */
4015 if (arg_graphics != GRAPHICS_NONE)
4017 arg_graphics = GRAPHICS_NONE;
4019 /* React to changes */
4020 Term_xtra_win_react();
4022 /* Hack -- Force redraw */
4023 Term_key_push(KTRL('R'));
4029 case IDM_OPTIONS_OLD_GRAPHICS:
4034 plog("You may not do that right now.");
4038 /* Toggle "arg_graphics" */
4039 if (arg_graphics != GRAPHICS_ORIGINAL)
4041 arg_graphics = GRAPHICS_ORIGINAL;
4043 /* React to changes */
4044 Term_xtra_win_react();
4046 /* Hack -- Force redraw */
4047 Term_key_push(KTRL('R'));
4053 case IDM_OPTIONS_NEW_GRAPHICS:
4058 plog("You may not do that right now.");
4062 /* Toggle "arg_graphics" */
4063 if (arg_graphics != GRAPHICS_ADAM_BOLT)
4065 arg_graphics = GRAPHICS_ADAM_BOLT;
4067 /* React to changes */
4068 Term_xtra_win_react();
4070 /* Hack -- Force redraw */
4071 Term_key_push(KTRL('R'));
4077 case IDM_OPTIONS_NEW2_GRAPHICS:
4082 plog("You may not do that right now.");
4086 /* Toggle "arg_graphics" */
4087 if (arg_graphics != GRAPHICS_HENGBAND)
4089 arg_graphics = GRAPHICS_HENGBAND;
4091 /* React to changes */
4092 Term_xtra_win_react();
4094 /* Hack -- Force redraw */
4095 Term_key_push(KTRL('R'));
4101 case IDM_OPTIONS_BIGTILE:
4103 term_data *td = &data[0];
4108 plog("You may not do that right now.");
4112 /* Toggle "arg_sound" */
4113 arg_bigtile = !arg_bigtile;
4116 Term_activate(&td->t);
4118 /* Resize the term */
4119 Term_resize(td->cols, td->rows);
4122 InvalidateRect(td->w, NULL, TRUE);
4127 case IDM_OPTIONS_SOUND:
4132 plog("You may not do that right now.");
4136 /* Toggle "arg_sound" */
4137 arg_sound = !arg_sound;
4139 /* React to changes */
4140 Term_xtra_win_react();
4142 /* Hack -- Force redraw */
4143 Term_key_push(KTRL('R'));
4149 case IDM_OPTIONS_BG:
4154 plog("You may not do that right now.");
4158 /* Toggle "use_bg" */
4163 /* React to changes */
4164 Term_xtra_win_react();
4166 /* Hack -- Force redraw */
4167 Term_key_push(KTRL('R'));
4173 case IDM_OPTIONS_OPEN_BG:
4178 plog("You may not do that right now.");
4183 memset(&ofn, 0, sizeof(ofn));
4184 ofn.lStructSize = sizeof(ofn);
4185 ofn.hwndOwner = data[0].w;
4186 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
4187 ofn.nFilterIndex = 1;
4188 ofn.lpstrFile = bg_bitmap_file;
4189 ofn.nMaxFile = 1023;
4190 ofn.lpstrInitialDir = NULL;
4192 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
4194 ofn.lpstrTitle = "Choose wall paper.";
4196 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
4198 if (GetOpenFileName(&ofn))
4200 /* Load 'savefile' */
4205 /* React to changes */
4206 Term_xtra_win_react();
4208 /* Hack -- Force redraw */
4209 Term_key_push(KTRL('R'));
4214 case IDM_DUMP_SCREEN_HTML:
4216 static char buf[1024] = "";
4217 memset(&ofn, 0, sizeof(ofn));
4218 ofn.lStructSize = sizeof(ofn);
4219 ofn.hwndOwner = data[0].w;
4220 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
4221 ofn.nFilterIndex = 1;
4222 ofn.lpstrFile = buf;
4223 ofn.nMaxFile = 1023;
4224 ofn.lpstrDefExt = "html";
4225 ofn.lpstrInitialDir = NULL;
4227 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
4229 ofn.lpstrTitle = "Save screen dump as HTML.";
4231 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
4233 if (GetSaveFileName(&ofn))
4235 do_cmd_save_screen_html_aux(buf, 0);
4242 case IDM_OPTIONS_SAVER:
4246 DestroyWindow(hwndSaver);
4251 /* Create a screen scaver window */
4252 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
4253 "Angband Screensaver",
4254 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
4255 0, 0, GetSystemMetrics(SM_CXSCREEN),
4256 GetSystemMetrics(SM_CYSCREEN),
4257 NULL, NULL, hInstance, NULL);
4261 /* Push the window to the bottom XXX XXX XXX */
4262 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
4267 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
4269 plog("Failed to create saver window");
4279 case IDM_OPTIONS_MAP:
4285 case IDM_HELP_CONTENTS:
4289 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.chm");
4290 if (check_file(tmp))
4292 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
4297 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4298 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4300 plog_fmt("Cannot find help file: %s", tmp);
4301 plog("Use the online help files instead.");
4306 #else /* HTML_HELP */
4309 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
4310 if (check_file(tmp))
4312 sprintf(buf, "winhelp.exe %s", tmp);
4313 WinExec(buf, SW_NORMAL);
4318 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
4319 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
4321 plog_fmt("Cannot find help file: %s", tmp);
4322 plog("Use the online help files instead.");
4327 #endif /* HTML_HELP */
4333 static bool process_keydown(WPARAM wParam, LPARAM lParam)
4340 /* Extract the modifiers */
4341 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4342 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4343 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4345 Term_no_press = (ma) ? TRUE : FALSE;
4347 /* Handle "special" keys */
4348 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4350 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
4351 bool numpad = FALSE;
4353 /* Begin the macro trigger */
4356 /* Send the modifiers */
4357 if (mc) Term_keypress('C');
4358 if (ms) Term_keypress('S');
4359 if (ma) Term_keypress('A');
4361 /* Extract "scan code" */
4362 i = LOBYTE(HIWORD(lParam));
4364 /* Introduce the scan code */
4367 /* Extended key bit */
4370 /* Numpad Enter and '/' are extended key */
4372 Term_no_press = TRUE;
4373 case VK_RETURN: /* Enter */
4376 /* Other extended keys are on full keyboard */
4392 Term_no_press = TRUE;
4396 case VK_PRIOR: /* Page Up */
4397 case VK_NEXT: /* Page Down */
4407 /* Special modifiers for keypad keys */
4408 if (numpad) Term_keypress('K');
4410 /* Encode the hexidecimal scan code */
4411 Term_keypress(hexsym[i/16]);
4412 Term_keypress(hexsym[i%16]);
4414 /* End the macro trigger */
4425 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4426 WPARAM wParam, LPARAM lParam);
4427 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4428 WPARAM wParam, LPARAM lParam)
4429 #else /* __MWERKS__ */
4430 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
4431 WPARAM wParam, LPARAM lParam)
4432 #endif /* __MWERKS__ */
4438 MINMAXINFO FAR *lpmmi;
4444 /* Acquire proper "term_data" info */
4445 td = (term_data *)GetWindowLong(hWnd, 0);
4447 /* Handle message */
4453 SetWindowLong(hWnd, 0, (LONG)(my_td));
4463 case WM_GETMINMAXINFO:
4465 MINMAXINFO FAR *lpmmi;
4468 lpmmi = (MINMAXINFO FAR *)lParam;
4470 /* this message was sent before WM_NCCREATE */
4473 /* Minimum window size is 80x24 */
4474 rc.left = rc.top = 0;
4475 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4476 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4479 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4481 /* Save minimum size */
4482 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4483 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4490 BeginPaint(hWnd, &ps);
4491 if (td) term_data_redraw(td);
4492 EndPaint(hWnd, &ps);
4493 ValidateRect(hWnd, NULL);
4500 if (process_keydown(wParam, lParam))
4507 if (Term_no_press) Term_no_press = FALSE;
4508 else Term_keypress(wParam);
4512 case WM_LBUTTONDOWN:
4514 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4515 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4527 int dx = abs(oldx - mousex) + 1;
4528 int dy = abs(oldy - mousey) + 1;
4529 int ox = (oldx > mousex) ? mousex : oldx;
4530 int oy = (oldy > mousey) ? mousey : oldy;
4540 hGlobal = GlobalAlloc(GHND, sz + 1);
4541 if (hGlobal == NULL) return 0;
4542 lpStr = (LPSTR)GlobalLock(hGlobal);
4544 for (i = 0; i < dy; i++)
4548 char **scr = data[0].t.scr->c;
4550 C_MAKE(s, (dx + 1), char);
4551 strncpy(s, &scr[oy + i][ox], dx);
4555 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
4558 if (ox + dx < data[0].cols)
4560 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
4563 for (j = 0; j < dx; j++)
4565 if (s[j] == 127) s[j] = '#';
4569 for (j = 0; j < dx; j++)
4571 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
4581 GlobalUnlock(hGlobal);
4582 if (OpenClipboard(hWnd) == 0)
4584 GlobalFree(hGlobal);
4588 SetClipboardData(CF_TEXT, hGlobal);
4601 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
4602 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
4607 dx = abs(oldx - mousex) + 1;
4608 dy = abs(oldy - mousey) + 1;
4609 ox = (oldx > mousex) ? mousex : oldx;
4610 oy = (oldy > mousey) ? mousey : oldy;
4611 Term_inversed_area(hWnd, ox, oy, dx, dy);
4618 dx = abs(cx - mousex) + 1;
4619 dy = abs(cy - mousey) + 1;
4620 ox = (cx > mousex) ? mousex : cx;
4621 oy = (cy > mousey) ? mousey : cy;
4622 Term_inversed_area(hWnd, ox, oy, dx, dy);
4638 if (game_in_progress && character_generated)
4643 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
4645 plog("You may not do that right now.");
4650 /* Hack -- Forget messages */
4659 /* do_cmd_save_game(FALSE); */
4660 #else /* ZANGBAND */
4661 /* do_cmd_save_game(); */
4662 #endif /* ZANGBAND */
4663 Term_key_push(SPECIAL_KEY_QUIT);
4670 case WM_QUERYENDSESSION:
4672 if (game_in_progress && character_generated)
4674 /* Hack -- Forget messages */
4677 /* Mega-Hack -- Delay death */
4678 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
4681 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "----¥²¡¼¥àÃæÃÇ----");
4683 do_cmd_write_nikki(NIKKI_GAMESTART, 0, "---- Save and Exit Game ----");
4686 /* Hardcode panic save */
4687 p_ptr->panic_save = 1;
4689 /* Forbid suspend */
4690 signals_ignore_tstp();
4692 /* Indicate panic save */
4694 (void)strcpy(p_ptr->died_from, "(¶ÛµÞ¥»¡¼¥Ö)");
4696 (void)strcpy(p_ptr->died_from, "(panic save)");
4700 (void)save_player();
4714 process_menus(LOWORD(wParam));
4720 /* this message was sent before WM_NCCREATE */
4723 /* it was sent from inside CreateWindowEx */
4724 if (!td->w) return 1;
4726 /* was sent from WM_SIZE */
4727 if (td->size_hack) return 1;
4731 case SIZE_MINIMIZED:
4733 /* Hide sub-windows */
4734 for (i = 1; i < MAX_TERM_DATA; i++)
4736 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4741 case SIZE_MAXIMIZED:
4743 /* fall through XXX XXX XXX */
4748 uint cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4749 uint rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4752 if ((td->cols != cols) || (td->rows != rows))
4754 /* Save the new size */
4758 if (!IsZoomed(td->w) && !IsIconic(td->w))
4760 normsize.x = td->cols;
4761 normsize.y = td->rows;
4765 Term_activate(&td->t);
4767 /* Resize the term */
4768 Term_resize(td->cols, td->rows);
4771 InvalidateRect(td->w, NULL, TRUE);
4774 td->size_hack = TRUE;
4776 /* Show sub-windows */
4777 for (i = 1; i < MAX_TERM_DATA; i++)
4779 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4782 td->size_hack = FALSE;
4790 case WM_PALETTECHANGED:
4792 /* Ignore if palette change caused by itself */
4793 if ((HWND)wParam == hWnd) return 0;
4795 /* Fall through... */
4798 case WM_QUERYNEWPALETTE:
4800 if (!paletted) return 0;
4804 SelectPalette(hdc, hPal, FALSE);
4806 i = RealizePalette(hdc);
4808 /* if any palette entries changed, repaint the window. */
4809 if (i) InvalidateRect(hWnd, NULL, TRUE);
4811 ReleaseDC(hWnd, hdc);
4818 if (wParam && !HIWORD(lParam))
4820 /* Do something to sub-windows */
4821 for (i = 1; i < MAX_TERM_DATA; i++)
4823 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
4826 /* Focus on main window */
4835 case WM_ACTIVATEAPP:
4837 if (IsIconic(td->w)) break;
4839 for (i = 1; i < MAX_TERM_DATA; i++)
4845 ShowWindow(data[i].w, SW_SHOW);
4849 ShowWindow(data[i].w, SW_HIDE);
4856 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4861 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4862 WPARAM wParam, LPARAM lParam);
4863 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4864 WPARAM wParam, LPARAM lParam)
4865 #else /* __MWERKS__ */
4866 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4867 WPARAM wParam, LPARAM lParam)
4868 #endif /* __MWERKS__ */
4872 MINMAXINFO FAR *lpmmi;
4880 /* Acquire proper "term_data" info */
4881 td = (term_data *)GetWindowLong(hWnd, 0);
4883 /* Process message */
4889 SetWindowLong(hWnd, 0, (LONG)(my_td));
4899 case WM_GETMINMAXINFO:
4901 MINMAXINFO FAR *lpmmi;
4904 lpmmi = (MINMAXINFO FAR *)lParam;
4906 /* this message was sent before WM_NCCREATE */
4909 /* Minimum window size is 80x24 */
4910 rc.left = rc.top = 0;
4911 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
4912 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
4915 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4917 /* Save minimum size */
4918 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4919 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4929 /* this message was sent before WM_NCCREATE */
4932 /* it was sent from inside CreateWindowEx */
4933 if (!td->w) return 1;
4935 /* was sent from inside WM_SIZE */
4936 if (td->size_hack) return 1;
4938 td->size_hack = TRUE;
4940 cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
4941 rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
4944 if ((td->cols != cols) || (td->rows != rows))
4947 term *old_term = Term;
4949 /* Save the new size */
4954 Term_activate(&td->t);
4956 /* Resize the term */
4957 Term_resize(td->cols, td->rows);
4960 Term_activate(old_term);
4963 InvalidateRect(td->w, NULL, TRUE);
4965 /* HACK - Redraw all windows */
4966 p_ptr->window = 0xFFFFFFFF;
4970 td->size_hack = FALSE;
4977 BeginPaint(hWnd, &ps);
4978 if (td) term_data_redraw(td);
4979 EndPaint(hWnd, &ps);
4986 if (process_keydown(wParam, lParam))
4993 if (Term_no_press) Term_no_press = FALSE;
4994 else Term_keypress(wParam);
4998 case WM_PALETTECHANGED:
5000 /* ignore if palette change caused by itself */
5001 if ((HWND)wParam == hWnd) return FALSE;
5002 /* otherwise, fall through!!! */
5005 case WM_QUERYNEWPALETTE:
5007 if (!paletted) return 0;
5009 SelectPalette(hdc, hPal, FALSE);
5010 i = RealizePalette(hdc);
5011 /* if any palette entries changed, repaint the window. */
5012 if (i) InvalidateRect(hWnd, NULL, TRUE);
5013 ReleaseDC(hWnd, hdc);
5017 case WM_NCLBUTTONDOWN:
5021 if (wParam == HTCLOSE) wParam = HTSYSMENU;
5022 #endif /* HTCLOSE */
5024 if (wParam == HTSYSMENU)
5028 td->visible = FALSE;
5029 ShowWindow(td->w, SW_HIDE);
5039 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5045 #define MOUSE_SENS 40
5048 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5049 WPARAM wParam, LPARAM lParam);
5050 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5051 WPARAM wParam, LPARAM lParam)
5052 #else /* __MWERKS__ */
5053 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
5054 WPARAM wParam, LPARAM lParam)
5055 #endif /* __MWERKS__ */
5057 static int iMouse = 0;
5058 static WORD xMouse = 0;
5059 static WORD yMouse = 0;
5082 if (LOWORD(wParam) == WA_INACTIVE) break;
5084 /* else fall through */
5088 case WM_LBUTTONDOWN:
5089 case WM_MBUTTONDOWN:
5090 case WM_RBUTTONDOWN:
5093 SendMessage(hWnd, WM_CLOSE, 0, 0);
5101 dx = LOWORD(lParam) - xMouse;
5102 dy = HIWORD(lParam) - yMouse;
5104 if (dx < 0) dx = -dx;
5105 if (dy < 0) dy = -dy;
5107 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
5109 SendMessage(hWnd, WM_CLOSE, 0, 0);
5113 /* Save last location */
5115 xMouse = LOWORD(lParam);
5116 yMouse = HIWORD(lParam);
5123 DestroyWindow(hwndSaver);
5130 return DefWindowProc(hWnd, uMsg, wParam, lParam);
5133 #endif /* USE_SAVER */
5139 /*** Temporary Hooks ***/
5143 * Display warning message (see "z-util.c")
5145 static void hack_plog(cptr str)
5147 /* Give a warning */
5151 MessageBox(NULL, str, "·Ù¹ð¡ª",
5152 MB_ICONEXCLAMATION | MB_OK);
5154 MessageBox(NULL, str, "Warning",
5155 MB_ICONEXCLAMATION | MB_OK);
5163 * Display error message and quit (see "z-util.c")
5165 static void hack_quit(cptr str)
5167 /* Give a warning */
5171 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
5172 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5174 MessageBox(NULL, str, "Error",
5175 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5180 /* Unregister the classes */
5181 UnregisterClass(AppName, hInstance);
5183 /* Destroy the icon */
5184 if (hIcon) DestroyIcon(hIcon);
5192 /*** Various hooks ***/
5196 * Display warning message (see "z-util.c")
5198 static void hook_plog(cptr str)
5204 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
5205 MB_ICONEXCLAMATION | MB_OK);
5207 MessageBox(data[0].w, str, "Warning",
5208 MB_ICONEXCLAMATION | MB_OK);
5216 * Display error message and quit (see "z-util.c")
5218 static void hook_quit(cptr str)
5223 /* Give a warning */
5227 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
5228 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5230 MessageBox(data[0].w, str, "Error",
5231 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5237 /* Save the preferences */
5241 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
5243 /* Destroy all windows */
5244 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
5246 term_force_font(&data[i], NULL);
5247 if (data[i].font_want) string_free(data[i].font_want);
5248 if (data[i].w) DestroyWindow(data[i].w);
5252 /* Free the bitmap stuff */
5254 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
5255 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
5257 if (infMask.hPalette) DeleteObject(infMask.hPalette);
5258 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
5260 #endif /* USE_GRAPHICS */
5262 /*** Free some other stuff ***/
5264 DeleteObject(hbrYellow);
5269 if (hPal) DeleteObject(hPal);
5271 UnregisterClass(AppName, hInstance);
5273 if (hIcon) DestroyIcon(hIcon);
5280 /*** Initialize ***/
5286 static void init_stuff(void)
5293 /* Get program name with full path */
5294 GetModuleFileName(hInstance, path, 512);
5296 /* Save the "program name" XXX XXX XXX */
5299 /* Get the name of the "*.ini" file */
5300 strcpy(path + strlen(path) - 4, ".INI");
5302 /* Save the the name of the ini-file */
5303 ini_file = string_make(path);
5305 /* Analyze the path */
5311 if (path[i] == '\\')
5318 /* Add "lib" to the path */
5319 strcpy(path + i + 1, "lib\\");
5321 /* Validate the path */
5322 validate_dir(path, TRUE);
5324 /* Init the file paths */
5325 init_file_paths(path);
5327 /* Hack -- Validate the paths */
5328 validate_dir(ANGBAND_DIR_APEX, FALSE);
5329 validate_dir(ANGBAND_DIR_BONE, FALSE);
5331 /* Allow missing 'edit' directory */
5332 if (!check_dir(ANGBAND_DIR_EDIT))
5334 /* Must have 'data'! */
5335 validate_dir(ANGBAND_DIR_DATA, TRUE);
5339 /* Don't need 'data' */
5340 validate_dir(ANGBAND_DIR_DATA, FALSE);
5343 validate_dir(ANGBAND_DIR_FILE, TRUE);
5344 validate_dir(ANGBAND_DIR_HELP, FALSE);
5345 validate_dir(ANGBAND_DIR_INFO, FALSE);
5346 validate_dir(ANGBAND_DIR_PREF, TRUE);
5347 validate_dir(ANGBAND_DIR_SAVE, FALSE);
5348 validate_dir(ANGBAND_DIR_USER, TRUE);
5349 validate_dir(ANGBAND_DIR_XTRA, TRUE);
5351 /* Build the filename */
5353 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt");
5355 path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt");
5359 /* Hack -- Validate the "news.txt" file */
5360 validate_file(path);
5363 #if 0 /* #ifndef JP */
5364 /* Build the "font" path */
5365 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "font");
5367 /* Allocate the path */
5368 ANGBAND_DIR_XTRA_FONT = string_make(path);
5370 /* Validate the "font" directory */
5371 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
5373 /* Build the filename */
5374 path_build(path, sizeof(path), ANGBAND_DIR_XTRA_FONT, "8X13.FON");
5376 /* Hack -- Validate the basic font */
5377 validate_file(path);
5383 /* Build the "graf" path */
5384 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
5386 /* Allocate the path */
5387 ANGBAND_DIR_XTRA_GRAF = string_make(path);
5389 /* Validate the "graf" directory */
5390 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
5392 #endif /* USE_GRAPHICS */
5397 /* Build the "sound" path */
5398 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
5400 /* Allocate the path */
5401 ANGBAND_DIR_XTRA_SOUND = string_make(path);
5403 /* Validate the "sound" directory */
5404 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
5406 #endif /* USE_SOUND */
5410 /* Build the "music" path */
5411 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
5413 /* Allocate the path */
5414 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
5416 /* Validate the "music" directory */
5417 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
5419 #endif /* USE_MUSIC */
5421 /* Build the "help" path */
5422 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
5424 /* Allocate the path */
5425 ANGBAND_DIR_XTRA_HELP = string_make(path);
5427 /* Validate the "help" directory */
5428 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
5431 bool is_already_running()
5433 bool result = FALSE;
5436 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
5437 if (GetLastError() == ERROR_ALREADY_EXISTS)
5445 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
5446 LPSTR lpCmdLine, int nCmdShow)
5454 setlocale( LC_ALL, "ja_JP" );
5463 /* Prevent multiple run */
5464 if (is_already_running())
5467 _("ÊѶòÈÚÅܤϤ¹¤Ç¤Ëµ¯Æ°¤·¤Æ¤¤¤Þ¤¹¡£", "Hengband is already running."),
5468 _("¥¨¥é¡¼¡ª", "Error") ,
5469 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
5474 if (hPrevInst == NULL)
5476 wc.style = CS_CLASSDC;
5477 wc.lpfnWndProc = AngbandWndProc;
5479 wc.cbWndExtra = 4; /* one long pointer to term_data */
5480 wc.hInstance = hInst;
5481 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
5482 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
5483 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
5484 wc.lpszMenuName = AppName;
5485 wc.lpszClassName = AppName;
5487 if (!RegisterClass(&wc)) exit(1);
5489 wc.lpfnWndProc = AngbandListProc;
5490 wc.lpszMenuName = NULL;
5491 wc.lpszClassName = AngList;
5493 if (!RegisterClass(&wc)) exit(2);
5497 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
5498 wc.lpfnWndProc = AngbandSaverProc;
5500 wc.lpszMenuName = NULL;
5501 wc.lpszClassName = "WindowsScreenSaverClass";
5503 if (!RegisterClass(&wc)) exit(3);
5509 /* Temporary hooks */
5510 plog_aux = hack_plog;
5511 quit_aux = hack_quit;
5512 core_aux = hack_quit;
5514 /* Prepare the filepaths */
5517 /* Initialize the keypress analyzer */
5518 for (i = 0; special_key_list[i]; ++i)
5520 special_key[special_key_list[i]] = TRUE;
5522 /* Initialize the keypress analyzer */
5523 for (i = 0; ignore_key_list[i]; ++i)
5525 ignore_key[ignore_key_list[i]] = TRUE;
5528 /* Determine if display is 16/256/true color */
5530 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
5531 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
5532 ReleaseDC(NULL, hdc);
5534 /* Initialize the colors */
5535 for (i = 0; i < 256; i++)
5539 /* Extract desired values */
5540 rv = angband_color_table[i][1];
5541 gv = angband_color_table[i][2];
5542 bv = angband_color_table[i][3];
5544 /* Extract the "complex" code */
5545 win_clr[i] = PALETTERGB(rv, gv, bv);
5547 /* Save the "simple" code */
5548 angband_color_table[i][0] = win_pal[i];
5551 /* Prepare the windows */
5557 /* Activate hooks */
5558 plog_aux = hook_plog;
5559 quit_aux = hook_quit;
5560 core_aux = hook_quit;
5562 /* Set the system suffix */
5563 ANGBAND_SYS = "win";
5565 /* Set the keyboard suffix */
5566 if (7 != GetKeyboardType(0))
5567 ANGBAND_KEYBOARD = "0";
5570 /* Japanese keyboard */
5571 switch (GetKeyboardType(1))
5573 case 0x0D01: case 0x0D02:
5574 case 0x0D03: case 0x0D04:
5575 case 0x0D05: case 0x0D06:
5577 ANGBAND_KEYBOARD = "NEC98";
5581 ANGBAND_KEYBOARD = "JAPAN";
5585 /* Catch nasty signals */
5591 /* We are now initialized */
5594 if(lpCmdLine[0] == '-'){
5595 switch(lpCmdLine[1])
5600 if (!lpCmdLine[2]) break;
5601 chuukei_server = TRUE;
5602 if(connect_chuukei_server(&lpCmdLine[2])<0){
5603 msg_print("connect fail");
5606 msg_print("connect");
5614 if (!lpCmdLine[2]) break;
5615 chuukei_client = TRUE;
5616 connect_chuukei_server(&lpCmdLine[2]);
5624 if (!lpCmdLine[2]) break;
5625 prepare_browse_movie(&lpCmdLine[2]);
5635 /* Did the user double click on a save file? */
5636 if(!chuukei_server) check_for_save_file(lpCmdLine);
5638 /* Did the user double click on a save file? */
5639 check_for_save_file(lpCmdLine);
5642 /* Prompt the user */
5644 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
5646 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
5651 /* Process messages forever */
5652 while (GetMessage(&msg, NULL, 0, 0))
5654 TranslateMessage(&msg);
5655 DispatchMessage(&msg);
5666 #endif /* WINDOWS */