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).
83 * Extract the "WIN32" flag from the compiler
85 #if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
93 * Hack -- allow use of "screen saver" mode
99 * Menu constants -- see "ANGBAND.RC"
102 #define IDM_FILE_NEW 100
103 #define IDM_FILE_OPEN 101
104 #define IDM_FILE_SAVE 110
105 #define IDM_FILE_SCORE 120
106 #define IDM_FILE_EXIT 130
108 #define IDM_WINDOW_VIS_0 200
109 #define IDM_WINDOW_VIS_1 201
110 #define IDM_WINDOW_VIS_2 202
111 #define IDM_WINDOW_VIS_3 203
112 #define IDM_WINDOW_VIS_4 204
113 #define IDM_WINDOW_VIS_5 205
114 #define IDM_WINDOW_VIS_6 206
115 #define IDM_WINDOW_VIS_7 207
117 #define IDM_WINDOW_FONT_0 210
118 #define IDM_WINDOW_FONT_1 211
119 #define IDM_WINDOW_FONT_2 212
120 #define IDM_WINDOW_FONT_3 213
121 #define IDM_WINDOW_FONT_4 214
122 #define IDM_WINDOW_FONT_5 215
123 #define IDM_WINDOW_FONT_6 216
124 #define IDM_WINDOW_FONT_7 217
126 #define IDM_WINDOW_BIZ_0 230
127 #define IDM_WINDOW_BIZ_1 231
128 #define IDM_WINDOW_BIZ_2 232
129 #define IDM_WINDOW_BIZ_3 233
130 #define IDM_WINDOW_BIZ_4 234
131 #define IDM_WINDOW_BIZ_5 235
132 #define IDM_WINDOW_BIZ_6 236
133 #define IDM_WINDOW_BIZ_7 237
135 #define IDM_WINDOW_I_WID_0 240
136 #define IDM_WINDOW_I_WID_1 241
137 #define IDM_WINDOW_I_WID_2 242
138 #define IDM_WINDOW_I_WID_3 243
139 #define IDM_WINDOW_I_WID_4 244
140 #define IDM_WINDOW_I_WID_5 245
141 #define IDM_WINDOW_I_WID_6 246
142 #define IDM_WINDOW_I_WID_7 247
144 #define IDM_WINDOW_D_WID_0 250
145 #define IDM_WINDOW_D_WID_1 251
146 #define IDM_WINDOW_D_WID_2 252
147 #define IDM_WINDOW_D_WID_3 253
148 #define IDM_WINDOW_D_WID_4 254
149 #define IDM_WINDOW_D_WID_5 255
150 #define IDM_WINDOW_D_WID_6 256
151 #define IDM_WINDOW_D_WID_7 257
153 #define IDM_WINDOW_I_HGT_0 260
154 #define IDM_WINDOW_I_HGT_1 261
155 #define IDM_WINDOW_I_HGT_2 262
156 #define IDM_WINDOW_I_HGT_3 263
157 #define IDM_WINDOW_I_HGT_4 264
158 #define IDM_WINDOW_I_HGT_5 265
159 #define IDM_WINDOW_I_HGT_6 266
160 #define IDM_WINDOW_I_HGT_7 267
162 #define IDM_WINDOW_D_HGT_0 270
163 #define IDM_WINDOW_D_HGT_1 271
164 #define IDM_WINDOW_D_HGT_2 272
165 #define IDM_WINDOW_D_HGT_3 273
166 #define IDM_WINDOW_D_HGT_4 274
167 #define IDM_WINDOW_D_HGT_5 275
168 #define IDM_WINDOW_D_HGT_6 276
169 #define IDM_WINDOW_D_HGT_7 277
171 #define IDM_OPTIONS_NO_GRAPHICS 400
172 #define IDM_OPTIONS_OLD_GRAPHICS 401
173 #define IDM_OPTIONS_NEW_GRAPHICS 402
174 #define IDM_OPTIONS_SOUND 410
175 #define IDM_OPTIONS_SAVER 420
176 #define IDM_OPTIONS_MAP 430
177 #define IDM_OPTIONS_BG 440
178 #define IDM_OPTIONS_OPEN_BG 441
180 #define IDM_DUMP_SCREEN_HTML 450
182 #define IDM_HELP_CONTENTS 901
187 * This may need to be removed for some compilers XXX XXX XXX
192 * Exclude parts of WINDOWS.H that are not needed
194 #define NOCOMM /* Comm driver APIs and definitions */
195 #define NOLOGERROR /* LogError() and related definitions */
196 #define NOPROFILER /* Profiler APIs */
197 #define NOLFILEIO /* _l* file I/O routines */
198 #define NOOPENFILE /* OpenFile and related definitions */
199 #define NORESOURCE /* Resource management */
200 #define NOATOM /* Atom management */
201 #define NOLANGUAGE /* Character test routines */
202 #define NOLSTRING /* lstr* string management routines */
203 #define NODBCS /* Double-byte character set routines */
204 #define NOKEYBOARDINFO /* Keyboard driver routines */
205 #define NOCOLOR /* COLOR_* color values */
206 #define NODRAWTEXT /* DrawText() and related definitions */
207 #define NOSCALABLEFONT /* Truetype scalable font support */
208 #define NOMETAFILE /* Metafile support */
209 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
210 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
211 #define NOKEYSTATES /* MK_* message key state flags */
212 #define NOWH /* SetWindowsHook and related WH_* definitions */
213 #define NOCLIPBOARD /* Clipboard APIs and definitions */
214 #define NOICONS /* IDI_* icon IDs */
215 #define NOMDI /* MDI support */
216 #define NOHELP /* Help support */
218 /* Not defined since it breaks Borland C++ 5.5 */
219 /* #define NOCTLMGR */ /* Control management and controls */
222 * Exclude parts of WINDOWS.H that are not needed (Win32)
224 #define WIN32_LEAN_AND_MEAN
225 #define NONLS /* All NLS defines and routines */
226 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
227 #define NOKANJI /* Kanji support stuff. */
228 #define NOMCX /* Modem Configuration Extensions */
231 * Include the "windows" support file
236 * Exclude parts of MMSYSTEM.H that are not needed
238 #define MMNODRV /* Installable driver support */
239 #define MMNOWAVE /* Waveform support */
240 #define MMNOMIDI /* MIDI support */
241 #define MMNOAUX /* Auxiliary audio support */
242 #define MMNOTIMER /* Timer support */
243 #define MMNOJOY /* Joystick support */
244 #define MMNOMCI /* MCI support */
245 #define MMNOMMIO /* Multimedia file I/O support */
246 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
249 * Include some more files. Note: the Cygnus Cygwin compiler
250 * doesn't use mmsystem.h instead it includes the winmm library
251 * which performs a similar function.
253 #include <mmsystem.h>
257 * HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
258 * HTML Workshop < http://msdn.microsoft.com/workshop/author/htmlhelp/ >.
260 /* #define HTML_HELP */
263 #include <htmlhelp.h>
264 #endif /* HTML_HELP */
267 * Include the support for loading bitmaps
270 # include "readdib.h"
274 * Hack -- Fake declarations from "dos.h" XXX XXX XXX
277 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
279 #define FA_LABEL 0x08 /* Volume label */
280 #define FA_DIREC 0x10 /* Directory */
281 unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
285 * Silliness in WIN32 drawing routine
288 # define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
292 * Silliness for Windows 95
294 #ifndef WS_EX_TOOLWINDOW
295 # define WS_EX_TOOLWINDOW 0
299 * Foreground color bits (hard-coded by DOS)
301 #define VID_BLACK 0x00
302 #define VID_BLUE 0x01
303 #define VID_GREEN 0x02
304 #define VID_CYAN 0x03
306 #define VID_MAGENTA 0x05
307 #define VID_YELLOW 0x06
308 #define VID_WHITE 0x07
311 * Bright text (hard-coded by DOS)
313 #define VID_BRIGHT 0x08
316 * Background color bits (hard-coded by DOS)
318 #define VUD_BLACK 0x00
319 #define VUD_BLUE 0x10
320 #define VUD_GREEN 0x20
321 #define VUD_CYAN 0x30
323 #define VUD_MAGENTA 0x50
324 #define VUD_YELLOW 0x60
325 #define VUD_WHITE 0x70
328 * Blinking text (hard-coded by DOS)
330 #define VUD_BRIGHT 0x80
336 typedef struct _term_data term_data;
341 * Note the use of "font_want" for the names of the font file requested by
342 * the user, and the use of "font_file" for the currently active font file.
344 * The "font_file" is uppercased, and takes the form "8X13.FON", while
345 * "font_want" can be in almost any form as long as it could be construed
346 * as attempting to represent the name of a font.
410 * Maximum number of windows XXX XXX XXX
412 #define MAX_TERM_DATA 8
415 * An array of term_data's
417 static term_data data[MAX_TERM_DATA];
420 * Hack -- global "window creation" pointer
422 static term_data *my_td;
427 bool game_in_progress = FALSE;
430 * note when "open"/"new" become valid
432 bool initialized = FALSE;
435 * screen paletted, i.e. 256 colors
437 bool paletted = FALSE;
440 * 16 colors screen, don't use RGB()
442 bool colors16 = FALSE;
445 * Saved instance handle
447 static HINSTANCE hInstance;
450 * Yellow brush for the cursor
452 static HBRUSH hbrYellow;
462 static HPALETTE hPal;
465 static HBITMAP hBG = NULL;
466 static int use_bg = 0;
467 static char bg_bitmap_file[1024] = "bg.bmp";
472 * The screen saver window
474 static HWND hwndSaver;
476 #endif /* USE_SAVER */
482 * Flag set once "graphics" has been initialized
484 static bool can_use_graphics = FALSE;
489 static DIBINIT infGraph;
491 #ifdef USE_TRANSPARENCY
494 * The global bitmap mask
496 static DIBINIT infMask;
498 #endif /* USE_TRANSPARENCY */
500 #endif /* USE_GRAPHICS */
506 * Flag set once "sound" has been initialized
508 static bool can_use_sound = FALSE;
511 * An array of sound file names
513 static cptr sound_file[SOUND_MAX];
515 #endif /* USE_SOUND */
519 * Full path to ANGBAND.INI
521 static cptr ini_file = NULL;
524 * Name of application
526 static cptr AppName = "ANGBAND";
529 * Name of sub-window type
531 static cptr AngList = "AngList";
536 static cptr ANGBAND_DIR_XTRA_FONT;
537 static cptr ANGBAND_DIR_XTRA_GRAF;
538 static cptr ANGBAND_DIR_XTRA_SOUND;
539 static cptr ANGBAND_DIR_XTRA_MUSIC;
540 static cptr ANGBAND_DIR_XTRA_HELP;
544 * The "complex" color values
546 static COLORREF win_clr[256];
550 * The "simple" color values
552 * See "main-ibm.c" for original table information
554 * The entries below are taken from the "color bits" defined above.
556 * Note that many of the choices below suck, but so do crappy monitors.
558 static BYTE win_pal[256] =
560 VID_BLACK, /* Dark */
561 VID_WHITE, /* White */
562 VID_CYAN, /* Slate XXX */
563 VID_RED | VID_BRIGHT, /* Orange XXX */
565 VID_GREEN, /* Green */
567 VID_YELLOW, /* Umber XXX */
568 VID_BLACK | VID_BRIGHT, /* Light Dark */
569 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
570 VID_MAGENTA, /* Violet XXX */
571 VID_YELLOW | VID_BRIGHT, /* Yellow */
572 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
573 VID_GREEN | VID_BRIGHT, /* Light Green */
574 VID_BLUE | VID_BRIGHT, /* Light Blue */
575 VID_YELLOW /* Light Umber XXX */
580 * Hack -- define which keys are "special"
582 static bool special_key[256];
583 static bool ignore_key[256];
587 * Hack -- initialization list for "special_key"
589 static byte special_key_list[] = {
590 VK_CLEAR,VK_PAUSE,VK_CAPITAL,VK_KANA,VK_JUNJA,VK_FINAL,VK_KANJI,
591 VK_CONVERT,VK_NONCONVERT,VK_ACCEPT,VK_MODECHANGE,
592 VK_PRIOR,VK_NEXT,VK_END,VK_HOME,VK_LEFT,VK_UP,VK_RIGHT,VK_DOWN,
593 VK_SELECT,VK_PRINT,VK_EXECUTE,VK_SNAPSHOT,VK_INSERT,VK_DELETE,
595 VK_F1,VK_F2,VK_F3,VK_F4,VK_F5,VK_F6,VK_F7,VK_F8,VK_F9,VK_F10,
596 VK_F11,VK_F12,VK_F13,VK_F14,VK_F15,VK_F16,VK_F17,VK_F18,VK_F19,VK_F20,
597 VK_F21,VK_F22,VK_F23,VK_F24,VK_NUMLOCK,VK_SCROLL,
598 VK_ATTN,VK_CRSEL,VK_EXSEL,VK_EREOF,VK_PLAY,VK_ZOOM,VK_NONAME,
602 static byte ignore_key_list[] = {
603 VK_ESCAPE,VK_TAB,VK_SPACE,
604 'F','W','O','H', /* these are menu characters.*/
605 VK_SHIFT,VK_CONTROL,VK_MENU,VK_LWIN,VK_RWIN,
606 VK_LSHIFT,VK_RSHIFT,VK_LCONTROL,VK_RCONTROL,VK_LMENU,VK_RMENU,0
611 * Hack -- initialization list for "special_key"
613 * We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
614 * and the normal keys (escape, tab, return, letters, numbers, etc), but we
615 * catch the keypad keys (with and without numlock set, including keypad 5),
616 * the function keys (including the "menu" key which maps to F10), and the
617 * "pause" key (between scroll lock and numlock). We also catch a few odd
618 * keys which I do not recognize, but which are listed among keys which we
619 * do catch, so they should be harmless to catch.
621 static byte special_key_list[] =
623 VK_CLEAR, /* 0x0C (KP<5>) */
625 VK_PAUSE, /* 0x13 (pause) */
627 VK_PRIOR, /* 0x21 (KP<9>) */
628 VK_NEXT, /* 0x22 (KP<3>) */
629 VK_END, /* 0x23 (KP<1>) */
630 VK_HOME, /* 0x24 (KP<7>) */
631 VK_LEFT, /* 0x25 (KP<4>) */
632 VK_UP, /* 0x26 (KP<8>) */
633 VK_RIGHT, /* 0x27 (KP<6>) */
634 VK_DOWN, /* 0x28 (KP<2>) */
635 VK_SELECT, /* 0x29 (?????) */
636 VK_PRINT, /* 0x2A (?????) */
637 VK_EXECUTE, /* 0x2B (?????) */
638 VK_SNAPSHOT, /* 0x2C (?????) */
639 VK_INSERT, /* 0x2D (KP<0>) */
640 VK_DELETE, /* 0x2E (KP<.>) */
641 VK_HELP, /* 0x2F (?????) */
644 VK_NUMPAD0, /* 0x60 (KP<0>) */
645 VK_NUMPAD1, /* 0x61 (KP<1>) */
646 VK_NUMPAD2, /* 0x62 (KP<2>) */
647 VK_NUMPAD3, /* 0x63 (KP<3>) */
648 VK_NUMPAD4, /* 0x64 (KP<4>) */
649 VK_NUMPAD5, /* 0x65 (KP<5>) */
650 VK_NUMPAD6, /* 0x66 (KP<6>) */
651 VK_NUMPAD7, /* 0x67 (KP<7>) */
652 VK_NUMPAD8, /* 0x68 (KP<8>) */
653 VK_NUMPAD9, /* 0x69 (KP<9>) */
654 VK_MULTIPLY, /* 0x6A (KP<*>) */
655 VK_ADD, /* 0x6B (KP<+>) */
656 VK_SEPARATOR, /* 0x6C (?????) */
657 VK_SUBTRACT, /* 0x6D (KP<->) */
658 VK_DECIMAL, /* 0x6E (KP<.>) */
659 VK_DIVIDE, /* 0x6F (KP</>) */
692 static void delete_bg()
703 char * bmfile = bg_bitmap_file;
706 if (use_bg == 0) return 0;
708 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
710 plog_fmt("ÊÉ»æÍÑ¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", bmfile);
715 HDC wnddc, dcimage, dcbg;
716 HBITMAP bmimage, bmimage_old, bmbg_old;
722 dcimage = CreateCompatibleDC(wnddc);
723 dcbg = CreateCompatibleDC(wnddc);
725 bmimage = LoadImage(NULL, "bg.bmp", LR_LOADFROMFILE, 0, 0, 0);
726 if (!bmimage) quit("bg.bmp¤¬Æɤߤ³¤á¤Ê¤¤¡ª");
727 bmimage_old = SelectObject(dcimage, bmimage);
729 CreateCompatibleBitmap();
731 ReleaseDC(hwnd, wnddc);
737 static void DrawBG(HDC hdc, RECT *r)
742 int x = r->left, y = r->top;
743 int nx, ny, sx, sy, swid, shgt, cwid, chgt;
749 GetObject(hBG, sizeof(bm), &bm);
750 swid = bm.bmWidth; shgt = bm.bmHeight;
752 hdcSrc = CreateCompatibleDC(hdc);
753 hOld = SelectObject(hdcSrc, hBG);
757 cwid = MIN(swid - sx, r->right - nx);
760 chgt = MIN(shgt - sy, r->bottom - ny);
761 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
763 } while (ny < r->bottom);
766 } while (nx < r->right);
768 SelectObject(hdcSrc, hOld);
773 * Hack -- given a pathname, point at the filename
775 static cptr extract_file_name(cptr s)
779 /* Start at the end */
780 p = s + strlen(s) - 1;
782 /* Back up to divider */
783 while ((p >= s) && (*p != ':') && (*p != '\\')) p--;
785 /* Return file name */
791 * Hack -- given a simple filename, extract the "font size" info
793 * Return a pointer to a static buffer holding the capitalized base name.
796 static char *analyze_font(char *path, int *wp, int *hp)
802 /* Start at the end */
803 p = path + strlen(path) - 1;
805 /* Back up to divider */
806 while ((p >= path) && (*p != ':') && (*p != '\\')) --p;
808 /* Advance to file name */
814 /* Capitalize (be paranoid) */
815 if (islower(*s)) *s = toupper(*s);
821 /* Extract font width */
825 hgt = s ? atoi(s+1) : 0;
838 * Check for existance of a file
840 static bool check_file(cptr s)
860 attrib = GetFileAttributes(path);
862 /* Require valid filename */
863 if (attrib == INVALID_FILE_NAME) return (FALSE);
865 /* Prohibit directory */
866 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return (FALSE);
870 /* Examine and verify */
871 if (_dos_getfileattr(path, &attrib)) return (FALSE);
873 /* Prohibit something */
874 if (attrib & FA_LABEL) return (FALSE);
876 /* Prohibit directory */
877 if (attrib & FA_DIREC) return (FALSE);
887 * Check for existance of a directory
889 static bool check_dir(cptr s)
911 /* Remove trailing backslash */
912 if (i && (path[i-1] == '\\')) path[--i] = '\0';
917 attrib = GetFileAttributes(path);
919 /* Require valid filename */
920 if (attrib == INVALID_FILE_NAME) return (FALSE);
922 /* Require 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 /* Require directory */
934 if (!(attrib & FA_DIREC)) return (FALSE);
946 static void validate_file(cptr s)
952 quit_fmt("ɬÍפʥե¡¥¤¥ë[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
954 quit_fmt("Cannot find required file:\n%s", s);
962 * Validate a directory
964 static void validate_dir(cptr s, bool vital)
969 /* This directory contains needed data */
973 quit_fmt("ɬÍפʥǥ£¥ì¥¯¥È¥ê[%s]¤¬¸«¤¢¤¿¤ê¤Þ¤»¤ó¡£", s);
975 quit_fmt("Cannot find required directory:\n%s", s);
979 /* Attempt to create this directory */
982 quit_fmt("Unable to create directory:\n%s", s);
989 * Get the "size" for a window
991 static void term_getsize(term_data *td)
998 if (td->cols < 1) td->cols = 1;
999 if (td->rows < 1) td->rows = 1;
1002 if (td->cols > 80) td->cols = 80;
1003 if (td->rows > 24) td->rows = 24;
1006 wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
1007 hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
1009 /* Fake window size */
1011 rc.right = rc.left + wid;
1013 rc.bottom = rc.top + hgt;
1016 /* rc.right += 1; */
1017 /* rc.bottom += 1; */
1020 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
1023 td->size_wid = rc.right - rc.left;
1024 td->size_hgt = rc.bottom - rc.top;
1026 /* See CreateWindowEx */
1029 /* Extract actual location */
1030 GetWindowRect(td->w, &rc);
1032 /* Save the location */
1033 td->pos_x = rc.left;
1039 * Write the "prefs" for a single term
1041 static void save_prefs_aux(term_data *td, cptr sec_name)
1051 strcpy(buf, td->visible ? "1" : "0");
1052 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
1056 strcpy(buf, td->lf.lfFaceName[0]!='\0' ? td->lf.lfFaceName : "£Í£Ó ¥´¥·¥Ã¥¯");
1058 strcpy(buf, td->font_file ? td->font_file : "8X13.FON");
1061 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
1064 wsprintf(buf, "%d", td->lf.lfWidth);
1065 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
1066 wsprintf(buf, "%d", td->lf.lfHeight);
1067 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
1068 wsprintf(buf, "%d", td->lf.lfWeight);
1069 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
1072 strcpy(buf, td->bizarre ? "1" : "0");
1073 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
1076 wsprintf(buf, "%d", td->tile_wid);
1077 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
1080 wsprintf(buf, "%d", td->tile_hgt);
1081 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
1083 /* Window size (x) */
1084 wsprintf(buf, "%d", td->cols);
1085 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
1087 /* Window size (y) */
1088 wsprintf(buf, "%d", td->rows);
1089 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
1091 /* Acquire position */
1092 GetWindowRect(td->w, &rc);
1094 /* Window position (x) */
1095 wsprintf(buf, "%d", rc.left);
1096 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
1098 /* Window position (y) */
1099 wsprintf(buf, "%d", rc.top);
1100 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
1107 * We assume that the windows have all been initialized
1109 static void save_prefs(void)
1115 /* Save the "arg_graphics" flag */
1116 sprintf(buf, "%d", arg_graphics);
1117 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
1119 /* Save the "arg_sound" flag */
1120 strcpy(buf, arg_sound ? "1" : "0");
1121 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
1124 strcpy(buf, use_bg ? "1" : "0");
1125 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
1126 WritePrivateProfileString("Angband", "BackGroundBitmap",
1127 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
1129 /* Save window prefs */
1130 for (i = 0; i < MAX_TERM_DATA; ++i)
1132 term_data *td = &data[i];
1134 sprintf(buf, "Term-%d", i);
1136 save_prefs_aux(td, buf);
1142 * Load the "prefs" for a single term
1144 static void load_prefs_aux(term_data *td, cptr sec_name)
1151 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
1153 /* Desired font, with default */
1155 GetPrivateProfileString(sec_name, "Font", "£Í£Ó ¥´¥·¥Ã¥¯", tmp, 127, ini_file);
1157 GetPrivateProfileString(sec_name, "Font", "8X13.FON", tmp, 127, ini_file);
1162 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
1164 /* Analyze font, save desired font name */
1166 td->font_want = string_make(tmp);
1168 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
1169 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
1170 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
1172 td->font_want = string_make(analyze_font(tmp, &wid, &hgt));
1178 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
1179 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1181 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file);
1182 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", hgt, ini_file);
1187 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1188 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1190 /* Window position */
1191 td->pos_x = GetPrivateProfileInt(sec_name, "PositionX", td->pos_x, ini_file);
1192 td->pos_y = GetPrivateProfileInt(sec_name, "PositionY", td->pos_y, ini_file);
1199 static void load_prefs(void)
1205 /* Extract the "arg_graphics" flag */
1206 arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1208 /* Extract the "arg_sound" flag */
1209 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1212 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1213 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1215 /* Load window prefs */
1216 for (i = 0; i < MAX_TERM_DATA; ++i)
1218 term_data *td = &data[i];
1220 sprintf(buf, "Term-%d", i);
1222 load_prefs_aux(td, buf);
1228 * Create the new global palette based on the bitmap palette
1229 * (if any), and the standard 16 entry palette derived from
1230 * "win_clr[]" which is used for the basic 16 Angband colors.
1232 * This function is never called before all windows are ready.
1234 * This function returns FALSE if the new palette could not be
1235 * prepared, which should normally be a fatal error. XXX XXX
1237 * Note that only some machines actually use a "palette".
1239 static int new_palette(void)
1247 LPLOGPALETTE pLogPal;
1248 LPPALETTEENTRY lppe;
1253 /* This makes no sense */
1254 if (!paletted) return (TRUE);
1264 /* Check the bitmap palette */
1265 hBmPal = infGraph.hPalette;
1267 /* Use the bitmap */
1270 lppeSize = 256 * sizeof(PALETTEENTRY);
1271 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1272 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1273 if ((nEntries == 0) || (nEntries > 220))
1277 plog("²èÌ̤ò16¥Ó¥Ã¥È¤«24¥Ó¥Ã¥È¥«¥é¡¼¥â¡¼¥É¤Ë¤·¤Æ²¼¤µ¤¤¡£");
1279 plog("Please switch to high- or true-color mode.");
1284 rnfree(lppe, lppeSize);
1291 #endif /* USE_GRAPHICS */
1293 /* Size of palette */
1294 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1296 /* Allocate palette */
1297 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1300 pLogPal->palVersion = 0x300;
1302 /* Make room for bitmap and normal data */
1303 pLogPal->palNumEntries = nEntries + 16;
1305 /* Save the bitmap data */
1306 for (i = 0; i < nEntries; i++)
1308 pLogPal->palPalEntry[i] = lppe[i];
1311 /* Save the normal data */
1312 for (i = 0; i < 16; i++)
1316 /* Access the entry */
1317 p = &(pLogPal->palPalEntry[i+nEntries]);
1319 /* Save the colors */
1320 p->peRed = GetRValue(win_clr[i]);
1321 p->peGreen = GetGValue(win_clr[i]);
1322 p->peBlue = GetBValue(win_clr[i]);
1324 /* Save the flags */
1325 p->peFlags = PC_NOCOLLAPSE;
1328 /* Free something */
1329 if (lppe) rnfree(lppe, lppeSize);
1331 /* Create a new palette, or fail */
1332 hNewPal = CreatePalette(pLogPal);
1334 if (!hNewPal) quit("¥Ñ¥ì¥Ã¥È¤òºîÀ®¤Ç¤¤Þ¤»¤ó¡ª");
1336 if (!hNewPal) quit("Cannot create palette!");
1340 /* Free the palette */
1341 rnfree(pLogPal, pLogPalSize);
1346 /* Realize the palette */
1348 SelectPalette(hdc, hNewPal, 0);
1349 i = RealizePalette(hdc);
1350 ReleaseDC(td->w, hdc);
1352 if (i == 0) quit("¥Ñ¥ì¥Ã¥È¤ò¥·¥¹¥Æ¥à¥¨¥ó¥È¥ê¤Ë¥Þ¥Ã¥×¤Ç¤¤Þ¤»¤ó¡ª");
1354 if (i == 0) quit("Cannot realize palette!");
1359 for (i = 1; i < MAX_TERM_DATA; i++)
1364 SelectPalette(hdc, hNewPal, 0);
1365 ReleaseDC(td->w, hdc);
1368 /* Delete old palette */
1369 if (hPal) DeleteObject(hPal);
1371 /* Save new palette */
1381 * Initialize graphics
1383 static bool init_graphics(void)
1385 /* Initialize once */
1386 /* if (can_use_graphics != arg_graphics) */
1392 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1399 ANGBAND_GRAF = "new";
1401 use_transparency = TRUE;
1409 ANGBAND_GRAF = "old";
1412 /* Access the bitmap file */
1413 path_build(buf, 1024, ANGBAND_DIR_XTRA_GRAF, name);
1415 /* Load the bitmap or quit */
1416 if (!ReadDIB(data[0].w, buf, &infGraph))
1419 plog_fmt("¥Ó¥Ã¥È¥Þ¥Ã¥× '%s' ¤òÆɤ߹þ¤á¤Þ¤»¤ó¡£", name);
1421 plog_fmt("Cannot read bitmap file '%s'", name);
1427 /* Save the new sizes */
1428 infGraph.CellWidth = wid;
1429 infGraph.CellHeight = hgt;
1431 #ifdef USE_TRANSPARENCY
1433 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1435 /* Access the mask file */
1436 path_build(buf, 1024, ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1438 /* Load the bitmap or quit */
1439 if (!ReadDIB(data[0].w, buf, &infMask))
1441 plog_fmt("Cannot read bitmap file '%s'", buf);
1446 #endif /* USE_TRANSPARENCY */
1448 /* Activate a palette */
1451 /* Free bitmap XXX XXX XXX */
1455 plog("¥Ñ¥ì¥Ã¥È¤ò¼Â¸½¤Ç¤¤Þ¤»¤ó¡ª");
1457 plog("Cannot activate palette!");
1463 /* Graphics available */
1464 can_use_graphics = arg_graphics;
1468 return (can_use_graphics);
1470 #endif /* USE_GRAPHICS */
1477 static bool init_sound(void)
1479 /* Initialize once */
1487 /* Prepare the sounds */
1488 for (i = 1; i < SOUND_MAX; i++)
1490 /* Extract name of sound file */
1491 sprintf(wav, "%s.wav", angband_sound_name[i]);
1493 /* Access the sound */
1494 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, wav);
1496 /* Save the sound filename, if it exists */
1497 if (check_file(buf)) sound_file[i] = string_make(buf);
1500 /* Sound available */
1501 can_use_sound = TRUE;
1505 return (can_use_sound);
1507 #endif /* USE_SOUND */
1513 static void term_window_resize(term_data *td)
1515 /* Require window */
1518 /* Resize the window */
1519 SetWindowPos(td->w, 0, 0, 0,
1520 td->size_wid, td->size_hgt,
1521 SWP_NOMOVE | SWP_NOZORDER);
1524 InvalidateRect(td->w, NULL, TRUE);
1529 * Force the use of a new "font file" for a term_data
1531 * This function may be called before the "window" is ready
1533 * This function returns zero only if everything succeeds.
1535 * Note that the "font name" must be capitalized!!!
1537 static errr term_force_font(term_data *td, cptr path)
1547 /* Forget the old font (if needed) */
1548 if (td->font_id) DeleteObject(td->font_id);
1551 /* Forget old font */
1557 for (i = 0; i < MAX_TERM_DATA; i++)
1559 /* Don't check when closing the application */
1562 /* Check "screen" */
1563 if ((td != &data[i]) &&
1564 (data[i].font_file) &&
1565 (streq(data[i].font_file, td->font_file)))
1571 /* Remove unused font resources */
1572 if (!used) RemoveFontResource(td->font_file);
1574 /* Free the old name */
1575 string_free(td->font_file);
1578 td->font_file = NULL;
1583 if (!path) return (1);
1589 /* Analyze font path */
1590 base = analyze_font(buf, &wid, &hgt);
1593 if (!suffix(base, ".FON")) return (1);
1596 if (!check_file(buf)) return (1);
1598 /* Load the new font */
1599 if (!AddFontResource(buf)) return (1);
1601 /* Save new font name */
1602 td->font_file = string_make(base);
1604 /* Remove the "suffix" */
1605 base[strlen(base)-4] = '\0';
1608 /* Create the font (using the 'base' of the font file name!) */
1610 td->font_id = CreateFontIndirect(&(td->lf));
1611 wid = td->lf.lfWidth;
1612 hgt = td->lf.lfHeight;
1613 if (!td->font_id) return (1);
1615 td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0,
1616 ANSI_CHARSET, OUT_DEFAULT_PRECIS,
1617 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
1618 FIXED_PITCH | FF_DONTCARE, base);
1622 /* Hack -- Unknown size */
1629 /* all this trouble to get the cell size */
1630 hdcDesktop = GetDC(HWND_DESKTOP);
1631 hfOld = SelectObject(hdcDesktop, td->font_id);
1632 GetTextMetrics(hdcDesktop, &tm);
1633 SelectObject(hdcDesktop, hfOld);
1634 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1636 /* Font size info */
1637 wid = tm.tmAveCharWidth;
1641 /* Save the size info */
1652 * Allow the user to change the font for this window.
1654 static void term_change_font(term_data *td)
1659 memset(&cf, 0, sizeof(cf));
1660 cf.lStructSize = sizeof(cf);
1661 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1662 cf.lpLogFont = &(td->lf);
1664 if (ChooseFont(&cf))
1666 /* Force the font */
1667 term_force_font(td, NULL);
1669 /* Assume not bizarre */
1672 /* Reset the tile info */
1673 td->tile_wid = td->font_wid;
1674 td->tile_hgt = td->font_hgt;
1676 /* Analyze the font */
1679 /* Resize the window */
1680 term_window_resize(td);
1686 char tmp[1024] = "";
1688 /* Extract a default if possible */
1689 if (td->font_file) strcpy(tmp, td->font_file);
1691 /* Ask for a choice */
1692 memset(&ofn, 0, sizeof(ofn));
1693 ofn.lStructSize = sizeof(ofn);
1694 ofn.hwndOwner = data[0].w;
1695 ofn.lpstrFilter = "Angband Font Files (*.fon)\0*.fon\0";
1696 ofn.nFilterIndex = 1;
1697 ofn.lpstrFile = tmp;
1699 ofn.lpstrInitialDir = ANGBAND_DIR_XTRA_FONT;
1700 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
1701 ofn.lpstrDefExt = "fon";
1703 /* Force choice if legal */
1704 if (GetOpenFileName(&ofn))
1706 /* Force the font */
1707 if (term_force_font(td, tmp))
1709 /* Access the standard font file */
1710 path_build(tmp, 1024, ANGBAND_DIR_XTRA_FONT, "8X13.FON");
1712 /* Force the use of that font */
1713 (void)term_force_font(td, tmp);
1716 /* Assume not bizarre */
1717 td->bizarre = FALSE;
1719 /* Reset the tile info */
1720 td->tile_wid = td->font_wid;
1721 td->tile_hgt = td->font_hgt;
1723 /* Analyze the font */
1726 /* Resize the window */
1727 term_window_resize(td);
1735 static void windows_map(void);
1738 * Hack -- redraw a term_data
1740 static void term_data_redraw(term_data *td)
1744 /* Redraw the map */
1749 /* Activate the term */
1750 Term_activate(&td->t);
1752 /* Redraw the contents */
1755 /* Restore the term */
1756 Term_activate(term_screen);
1764 /*** Function hooks needed by "Term" ***/
1770 * Initialize a new Term
1772 static void Term_init_win(term *t)
1781 static void Term_nuke_win(term *t)
1790 * Interact with the User
1792 static errr Term_user_win(int n)
1800 * React to global changes
1802 static errr Term_xtra_win_react(void)
1810 /* Save the default colors */
1811 for (i = 0; i < 256; i++)
1813 /* Simply accept the desired colors */
1814 win_pal[i] = angband_color_table[i][0];
1825 bool change = FALSE;
1827 /* Save the default colors */
1828 for (i = 0; i < 256; i++)
1830 /* Extract desired values */
1831 rv = angband_color_table[i][1];
1832 gv = angband_color_table[i][2];
1833 bv = angband_color_table[i][3];
1835 /* Extract a full color code */
1836 code = PALETTERGB(rv, gv, bv);
1838 /* Activate changes */
1839 if (win_clr[i] != code)
1841 /* Note the change */
1844 /* Apply the desired color */
1849 /* Activate the palette if needed */
1850 if (change) (void)new_palette();
1856 /* Handle "arg_sound" */
1857 if (use_sound != arg_sound)
1859 /* Initialize (if needed) */
1860 if (arg_sound && !init_sound())
1864 plog("¥µ¥¦¥ó¥É¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó¡ª");
1866 plog("Cannot initialize sound!");
1874 /* Change setting */
1875 use_sound = arg_sound;
1883 /* Handle "arg_graphics" */
1884 if (use_graphics != arg_graphics)
1886 /* Switch off transparency */
1887 use_transparency = FALSE;
1889 /* Initialize (if needed) */
1890 if (arg_graphics && !init_graphics())
1894 plog("¥°¥é¥Õ¥£¥Ã¥¯¥¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó!");
1896 plog("Cannot initialize graphics!");
1901 arg_graphics = GRAPHICS_NONE;
1904 /* Change setting */
1905 use_graphics = arg_graphics;
1908 #ifdef ANGBAND_2_8_1
1910 #else /* ANGBAND_2_8_1 */
1911 reset_visuals(TRUE);
1912 #endif /* ANGBAND_2_8_1 */
1915 #endif /* USE_GRAPHICS */
1918 /* Clean up windows */
1919 for (i = 0; i < MAX_TERM_DATA; i++)
1923 term_data *td = &data[i];
1925 /* Update resized windows */
1926 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
1929 Term_activate(&td->t);
1931 /* Hack -- Resize the term */
1932 Term_resize(td->cols, td->rows);
1934 /* Redraw the contents */
1949 * Process at least one event
1951 static errr Term_xtra_win_event(int v)
1955 /* Wait for an event */
1959 if (GetMessage(&msg, NULL, 0, 0))
1961 TranslateMessage(&msg);
1962 DispatchMessage(&msg);
1966 /* Check for an event */
1970 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1972 TranslateMessage(&msg);
1973 DispatchMessage(&msg);
1983 * Process all pending events
1985 static errr Term_xtra_win_flush(void)
1989 /* Process all pending events */
1990 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1992 TranslateMessage(&msg);
1993 DispatchMessage(&msg);
2002 * Hack -- clear the screen
2004 * Make this more efficient XXX XXX XXX
2006 static errr Term_xtra_win_clear(void)
2008 term_data *td = (term_data*)(Term->data);
2013 /* Rectangle to erase */
2014 rc.left = td->size_ow1;
2015 rc.right = rc.left + td->cols * td->tile_wid;
2016 rc.top = td->size_oh1;
2017 rc.bottom = rc.top + td->rows * td->tile_hgt;
2021 SetBkColor(hdc, RGB(0, 0, 0));
2022 SelectObject(hdc, td->font_id);
2023 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2028 rc.left = 0; rc.top = 0;
2031 ReleaseDC(td->w, hdc);
2039 * Hack -- make a noise
2041 static errr Term_xtra_win_noise(void)
2043 MessageBeep(MB_ICONASTERISK);
2049 * Hack -- make a sound
2051 static errr Term_xtra_win_sound(int v)
2053 /* Sound disabled */
2054 if (!use_sound) return (1);
2057 if ((v < 0) || (v >= SOUND_MAX)) return (1);
2062 if (!sound_file[v]) return (1);
2066 /* Play the sound, catch errors */
2067 return (PlaySound(sound_file[v], 0, SND_FILENAME | SND_ASYNC));
2071 /* Play the sound, catch errors */
2072 return (sndPlaySound(sound_file[v], SND_ASYNC));
2076 #else /* USE_SOUND */
2081 #endif /* USE_SOUND */
2086 * Delay for "x" milliseconds
2088 static int Term_xtra_win_delay(int v)
2102 t = GetTickCount() + v;
2105 while (GetTickCount() < t)
2107 /* Handle messages */
2108 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2110 TranslateMessage(&msg);
2111 DispatchMessage(&msg);
2123 * Do a "special thing"
2125 static errr Term_xtra_win(int n, int v)
2127 /* Handle a subset of the legal requests */
2130 /* Make a bell sound */
2131 case TERM_XTRA_NOISE:
2133 return (Term_xtra_win_noise());
2136 /* Make a special sound */
2137 case TERM_XTRA_SOUND:
2139 return (Term_xtra_win_sound(v));
2142 /* Process random events */
2143 case TERM_XTRA_BORED:
2145 return (Term_xtra_win_event(0));
2148 /* Process an event */
2149 case TERM_XTRA_EVENT:
2151 return (Term_xtra_win_event(v));
2154 /* Flush all events */
2155 case TERM_XTRA_FLUSH:
2157 return (Term_xtra_win_flush());
2160 /* Clear the screen */
2161 case TERM_XTRA_CLEAR:
2163 return (Term_xtra_win_clear());
2166 /* React to global changes */
2167 case TERM_XTRA_REACT:
2169 return (Term_xtra_win_react());
2172 /* Delay for some milliseconds */
2173 case TERM_XTRA_DELAY:
2175 return (Term_xtra_win_delay(v));
2186 * Low level graphics (Assumes valid input).
2188 * Draw a "cursor" at (x,y), using a "yellow box".
2190 static errr Term_curs_win(int x, int y)
2192 term_data *td = (term_data*)(Term->data);
2197 int tile_wid, tile_hgt;
2201 tile_wid = td->map_tile_wid;
2202 tile_hgt = td->map_tile_hgt;
2206 tile_wid = td->tile_wid;
2207 tile_hgt = td->tile_hgt;
2210 /* Frame the grid */
2211 rc.left = x * tile_wid + td->size_ow1;
2212 rc.right = rc.left + tile_wid;
2213 rc.top = y * tile_hgt + td->size_oh1;
2214 rc.bottom = rc.top + tile_hgt;
2216 /* Cursor is done as a yellow "box" */
2218 FrameRect(hdc, &rc, hbrYellow);
2219 ReleaseDC(td->w, hdc);
2227 * Low level graphics (Assumes valid input).
2229 * Erase a "block" of "n" characters starting at (x,y).
2231 static errr Term_wipe_win(int x, int y, int n)
2233 term_data *td = (term_data*)(Term->data);
2238 /* Rectangle to erase in client coords */
2239 rc.left = x * td->tile_wid + td->size_ow1;
2240 rc.right = rc.left + n * td->tile_wid;
2241 rc.top = y * td->tile_hgt + td->size_oh1;
2242 rc.bottom = rc.top + td->tile_hgt;
2245 SetBkColor(hdc, RGB(0, 0, 0));
2246 SelectObject(hdc, td->font_id);
2251 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2252 ReleaseDC(td->w, hdc);
2260 * Low level graphics. Assumes valid input.
2262 * Draw several ("n") chars, with an attr, at a given location.
2264 * All "graphic" data is handled by "Term_pict_win()", below.
2266 * One would think there is a more efficient method for telling a window
2267 * what color it should be using to draw with, but perhaps simply changing
2268 * it every time is not too inefficient. XXX XXX XXX
2270 static errr Term_text_win(int x, int y, int n, byte a, const char *s)
2272 term_data *td = (term_data*)(Term->data);
2278 static HBITMAP WALL;
2279 static HBRUSH myBrush, oldBrush;
2281 static bool init_done = FALSE;
2284 WALL = LoadBitmap(hInstance, AppName);
2285 myBrush = CreatePatternBrush(WALL);
2290 /* Total rectangle */
2291 rc.left = x * td->tile_wid + td->size_ow1;
2292 rc.right = rc.left + n * td->tile_wid;
2293 rc.top = y * td->tile_hgt + td->size_oh1;
2294 rc.bottom = rc.top + td->tile_hgt;
2299 /* Background color */
2300 SetBkColor(hdc, RGB(0, 0, 0));
2302 /* Foreground color */
2305 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
2309 SetTextColor(hdc, win_clr[a&0x0F]);
2313 SetTextColor(hdc, win_clr[a]);
2317 SelectObject(hdc, td->font_id);
2320 if (use_bg) SetBkMode(hdc, TRANSPARENT);
2324 (td->tile_hgt != td->font_hgt) ||
2325 (td->tile_wid != td->font_wid))
2329 /* Erase complete rectangle */
2330 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
2333 if (use_bg) DrawBG(hdc, &rc);
2336 rc.left += ((td->tile_wid - td->font_wid) / 2);
2337 rc.right = rc.left + td->font_wid;
2338 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
2339 rc.bottom = rc.top + td->font_hgt;
2341 /* Dump each character */
2342 for (i = 0; i < n; i++)
2345 if ( iskanji(*(s+i)) ) /* £²¥Ð¥¤¥Èʸ»ú */
2347 rc.right += td->font_wid;
2349 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2354 rc.left += 2 * td->tile_wid;
2355 rc.right += 2 * td->tile_wid;
2356 } else if (*(s+i)==127){
2357 oldBrush = SelectObject(hdc, myBrush);
2358 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) );
2361 Rectangle(hdc, rc.left, rc.top, rc.right+1, rc.bottom+1);
2363 SelectObject(hdc, oldBrush);
2364 SelectObject(hdc, oldPen);
2367 rc.left += td->tile_wid;
2368 rc.right += td->tile_wid;
2371 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2375 rc.left += td->tile_wid;
2376 rc.right += td->tile_wid;
2380 ExtTextOut(hdc, rc.left, rc.top, 0, &rc,
2384 rc.left += td->tile_wid;
2385 rc.right += td->tile_wid;
2395 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
2400 ReleaseDC(td->w, hdc);
2408 * Low level graphics. Assumes valid input.
2410 * Draw an array of "special" attr/char pairs at the given location.
2412 * We use the "Term_pict_win()" function for "graphic" data, which are
2413 * encoded by setting the "high-bits" of both the "attr" and the "char"
2414 * data. We use the "attr" to represent the "row" of the main bitmap,
2415 * and the "char" to represent the "col" of the main bitmap. The use
2416 * of this function is induced by the "higher_pict" flag.
2418 * If "graphics" is not available, we simply "wipe" the given grids.
2420 # ifdef USE_TRANSPARENCY
2421 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
2422 # else /* USE_TRANSPARENCY */
2423 static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp)
2424 # endif /* USE_TRANSPARENCY */
2426 term_data *td = (term_data*)(Term->data);
2434 # ifdef USE_TRANSPARENCY
2440 # endif /* USE_TRANSPARENCY */
2449 /* Erase the grids */
2450 return (Term_wipe_win(x, y, n));
2453 /* Size of bitmap cell */
2454 w1 = infGraph.CellWidth;
2455 h1 = infGraph.CellHeight;
2457 /* Size of window cell */
2460 w2 = td->map_tile_wid;
2461 h2 = td->map_tile_hgt;
2469 /* Location of window cell */
2470 x2 = x * w2 + td->size_ow1;
2471 y2 = y * h2 + td->size_oh1;
2477 hdcSrc = CreateCompatibleDC(hdc);
2478 hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2480 # ifdef USE_TRANSPARENCY
2482 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2484 hdcMask = CreateCompatibleDC(hdc);
2485 SelectObject(hdcMask, infMask.hBitmap);
2488 # endif /* USE_TRANSPARENCY */
2490 /* Draw attr/char pairs */
2491 for (i = 0; i < n; i++, x2 += w2)
2496 /* Extract picture */
2497 int row = (a & 0x7F);
2498 int col = (c & 0x7F);
2500 /* Location of bitmap cell */
2504 # ifdef USE_TRANSPARENCY
2506 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2508 x3 = (tcp[i] & 0x7F) * w1;
2509 y3 = (tap[i] & 0x7F) * h1;
2512 if ((w1 == w2) && (h1 == h2))
2514 /* Copy the terrain picture from the bitmap to the window */
2515 BitBlt(hdc, x2, y2, w2, h2, hdcSrc, x3, y3, SRCCOPY);
2517 /* Mask out the tile */
2518 BitBlt(hdc, x2, y2, w2, h2, hdcMask, x1, y1, SRCAND);
2521 BitBlt(hdc, x2, y2, w2, h2, hdcSrc, x1, y1, SRCPAINT);
2524 /* Need to stretch */
2527 /* Set the correct mode for stretching the tiles */
2528 SetStretchBltMode(hdc, COLORONCOLOR);
2530 /* Copy the terrain picture from the bitmap to the window */
2531 StretchBlt(hdc, x2, y2, w2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY);
2533 /* Only draw if terrain and overlay are different */
2534 if ((x1 != x3) || (y1 != y3))
2536 /* Mask out the tile */
2537 StretchBlt(hdc, x2, y2, w2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2540 StretchBlt(hdc, x2, y2, w2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2546 # endif /* USE_TRANSPARENCY */
2550 if ((w1 == w2) && (h1 == h2))
2552 /* Copy the picture from the bitmap to the window */
2553 BitBlt(hdc, x2, y2, w2, h2, hdcSrc, x1, y1, SRCCOPY);
2556 /* Need to stretch */
2559 /* Set the correct mode for stretching the tiles */
2560 SetStretchBltMode(hdc, COLORONCOLOR);
2562 /* Copy the picture from the bitmap to the window */
2563 StretchBlt(hdc, x2, y2, w2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2569 SelectObject(hdcSrc, hbmSrcOld);
2572 # ifdef USE_TRANSPARENCY
2574 if (arg_graphics == GRAPHICS_ADAM_BOLT)
2577 SelectObject(hdcMask, hbmSrcOld);
2581 # endif /* USE_TRANSPARENCY */
2584 ReleaseDC(td->w, hdc);
2586 #else /* USE_GRAPHICS */
2588 /* Just erase this grid */
2589 return (Term_wipe_win(x, y, n));
2591 #endif /* USE_GRAPHICS */
2598 #ifdef USE_TRANSPARENCY
2599 extern void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp);
2600 #else /* USE_TRANSPARENCY */
2601 extern void map_info(int y, int x, byte *ap, char *cp);
2602 #endif /* USE_TRANSPARENCY */
2605 static void windows_map(void)
2607 term_data *td = &data[0];
2609 int x, min_x, max_x;
2610 int y, min_y, max_y;
2612 #ifdef USE_TRANSPARENCY
2616 /* Only in graphics mode */
2617 if (!use_graphics) return;
2620 Term_xtra_win_clear();
2622 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2623 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2624 td->map_active = TRUE;
2634 for (x = min_x; x < max_x; x++)
2636 for (y = min_y; y < max_y; y++)
2638 #ifdef USE_TRANSPARENCY
2639 map_info(y, x, &a, (char*)&c, &ta, (char*)&tc);
2640 #else /* USE_TRANSPARENCY */
2641 map_info(y, x, &a, (char*)&c);
2642 #endif /* USE_TRANSPARENCY */
2644 /* Ignore non-graphics */
2645 if ((a & 0x80) && (c & 0x80))
2647 #ifdef USE_TRANSPARENCY
2648 Term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2649 #else /* USE_TRANSPARENCY */
2650 Term_pict_win(x - min_x, y - min_y, 1, &a, &c);
2651 #endif /* USE_TRANSPARENCY */
2656 /* Hilite the player */
2657 Term_curs_win(px - min_x, py - min_y);
2659 /* Wait for a keypress, flush key buffer */
2660 Term_inkey(&c, TRUE, TRUE);
2663 /* Switch off the map display */
2664 td->map_active = FALSE;
2666 /* Restore screen */
2667 Term_xtra_win_clear();
2672 /*** Other routines ***/
2676 * Create and initialize a "term_data" given a title
2678 static void term_data_link(term_data *td)
2682 /* Initialize the term */
2683 term_init(t, td->cols, td->rows, td->keys);
2685 /* Use a "software" cursor */
2686 t->soft_cursor = TRUE;
2688 /* Use "Term_pict" for "graphic" data */
2689 t->higher_pict = TRUE;
2691 /* Erase with "white space" */
2692 t->attr_blank = TERM_WHITE;
2693 t->char_blank = ' ';
2696 /* Prepare the init/nuke hooks */
2697 t->init_hook = Term_init_win;
2698 t->nuke_hook = Term_nuke_win;
2701 /* Prepare the template hooks */
2702 t->user_hook = Term_user_win;
2703 t->xtra_hook = Term_xtra_win;
2704 t->curs_hook = Term_curs_win;
2705 t->wipe_hook = Term_wipe_win;
2706 t->text_hook = Term_text_win;
2707 t->pict_hook = Term_pict_win;
2709 /* Remember where we came from */
2710 t->data = (vptr)(td);
2715 * Create the windows
2717 * First, instantiate the "default" values, then read the "ini_file"
2718 * to over-ride selected values, then create the windows, and fonts.
2720 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2721 * must make active to realize the palette. XXX XXX XXX
2723 static void init_windows(void)
2735 WIPE(td, term_data);
2739 td->s = angband_term_name[0];
2757 for (i = 1; i < MAX_TERM_DATA; i++)
2760 WIPE(td, term_data);
2761 td->s = angband_term_name[i];
2765 td->visible = FALSE;
2770 td->pos_x = (7 - i) * 30;
2771 td->pos_y = (7 - i) * 20;
2782 /* Main window (need these before term_getsize gets called) */
2784 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2785 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2790 /* Sub windows (need these before term_getsize gets called) */
2791 for (i = 1; i < MAX_TERM_DATA; i++)
2794 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2795 td->dwExStyle = (WS_EX_TOOLWINDOW);
2800 for (i = 0; i < MAX_TERM_DATA; i++)
2805 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2806 td->lf.lfHeight = td->tile_hgt;
2807 td->lf.lfWidth = td->tile_wid;
2808 td->lf.lfCharSet = SHIFTJIS_CHARSET;
2809 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2810 /* Activate the chosen font */
2811 term_force_font(td, NULL);
2812 td->tile_wid = td->font_wid;
2813 td->tile_hgt = td->font_hgt;
2815 /* Access the standard font file */
2816 path_build(buf, 1024, ANGBAND_DIR_XTRA_FONT, td->font_want);
2818 /* Activate the chosen font */
2819 if (term_force_font(td, buf))
2821 /* Access the standard font file */
2822 path_build(buf, 1024, ANGBAND_DIR_XTRA_FONT, "8X13.FON");
2824 /* Force the use of that font */
2825 (void)term_force_font(td, buf);
2831 /* Assume not bizarre */
2832 td->bizarre = FALSE;
2837 /* Analyze the font */
2840 /* Resize the window */
2841 term_window_resize(td);
2845 /* Sub windows (reverse order) */
2846 for (i = MAX_TERM_DATA - 1; i >= 1; --i)
2851 td->w = CreateWindowEx(td->dwExStyle, AngList,
2853 td->pos_x, td->pos_y,
2854 td->size_wid, td->size_hgt,
2855 HWND_DESKTOP, NULL, hInstance, NULL);
2858 if (!td->w) quit("¥µ¥Ö¥¦¥£¥ó¥É¥¦¤ËºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
2860 if (!td->w) quit("Failed to create sub-window");
2866 td->size_hack = TRUE;
2867 ShowWindow(td->w, SW_SHOW);
2868 td->size_hack = FALSE;
2872 angband_term[i] = &td->t;
2876 /* Activate the window */
2877 SetActiveWindow(td->w);
2879 /* Bring window to top */
2880 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2890 td->w = CreateWindowEx(td->dwExStyle, AppName,
2892 td->pos_x, td->pos_y,
2893 td->size_wid, td->size_hgt,
2894 HWND_DESKTOP, NULL, hInstance, NULL);
2897 if (!td->w) quit("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿");
2899 if (!td->w) quit("Failed to create Angband window");
2904 angband_term[0] = &td->t;
2906 /* Activate the main window */
2907 SetActiveWindow(td->w);
2909 /* Bring main window back to top */
2910 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2913 /* New palette XXX XXX XXX */
2914 (void)new_palette();
2917 /* Create a "brush" for drawing the "cursor" */
2918 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
2921 /* Process pending messages */
2922 (void)Term_xtra_win_flush();
2930 static void setup_menus(void)
2934 HMENU hm = GetMenu(data[0].w);
2937 /* Menu "File", Disable all */
2938 EnableMenuItem(hm, IDM_FILE_NEW,
2939 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2940 EnableMenuItem(hm, IDM_FILE_OPEN,
2941 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2942 EnableMenuItem(hm, IDM_FILE_SAVE,
2943 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2944 EnableMenuItem(hm, IDM_FILE_EXIT,
2945 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2946 EnableMenuItem(hm, IDM_FILE_SCORE,
2947 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2950 /* No character available */
2951 if (!character_generated)
2953 /* Menu "File", Item "New" */
2954 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
2956 /* Menu "File", Item "Open" */
2957 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
2960 /* A character available */
2961 if (character_generated)
2963 /* Menu "File", Item "Save" */
2964 EnableMenuItem(hm, IDM_FILE_SAVE,
2965 MF_BYCOMMAND | MF_ENABLED);
2968 /* Menu "File", Item "Exit" */
2969 EnableMenuItem(hm, IDM_FILE_EXIT,
2970 MF_BYCOMMAND | MF_ENABLED);
2972 EnableMenuItem(hm, IDM_FILE_SCORE,
2973 MF_BYCOMMAND | MF_ENABLED);
2976 /* Menu "Window::Visibility" */
2977 for (i = 0; i < MAX_TERM_DATA; i++)
2979 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
2980 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2982 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i,
2983 (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
2985 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i,
2986 MF_BYCOMMAND | MF_ENABLED);
2989 /* Menu "Window::Font" */
2990 for (i = 0; i < MAX_TERM_DATA; i++)
2992 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
2993 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2995 if (data[i].visible)
2997 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i,
2998 MF_BYCOMMAND | MF_ENABLED);
3002 /* Menu "Window::Bizarre Display" */
3003 for (i = 0; i < MAX_TERM_DATA; i++)
3005 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3006 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3008 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3009 (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
3011 if (data[i].visible)
3013 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i,
3014 MF_BYCOMMAND | MF_ENABLED);
3019 /* Menu "Window::Increase Tile Width" */
3020 for (i = 0; i < MAX_TERM_DATA; i++)
3022 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3023 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3025 if (data[i].visible)
3027 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i,
3028 MF_BYCOMMAND | MF_ENABLED);
3033 /* Menu "Window::Decrease Tile Width" */
3034 for (i = 0; i < MAX_TERM_DATA; i++)
3036 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3037 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3039 if (data[i].visible)
3041 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i,
3042 MF_BYCOMMAND | MF_ENABLED);
3047 /* Menu "Window::Increase Tile Height" */
3048 for (i = 0; i < MAX_TERM_DATA; i++)
3050 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3051 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3053 if (data[i].visible)
3055 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i,
3056 MF_BYCOMMAND | MF_ENABLED);
3061 /* Menu "Window::Decrease Tile Height" */
3062 for (i = 0; i < MAX_TERM_DATA; i++)
3064 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3065 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3067 if (data[i].visible)
3069 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i,
3070 MF_BYCOMMAND | MF_ENABLED);
3075 /* Menu "Options", disable all */
3076 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3077 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3078 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3079 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3080 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3081 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3082 EnableMenuItem(hm, IDM_OPTIONS_SOUND,
3083 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3085 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3086 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3089 /* Menu "Options", Item "Map" */
3090 if (use_graphics != GRAPHICS_NONE)
3091 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
3093 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP,
3094 MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
3096 /* Menu "Options", update all */
3097 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
3098 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
3099 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
3100 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
3101 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
3102 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
3103 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
3104 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
3105 CheckMenuItem(hm, IDM_OPTIONS_BG,
3106 (use_bg ? MF_CHECKED : MF_UNCHECKED));
3108 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
3109 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
3113 /* Menu "Options", Item "Graphics" */
3114 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
3115 /* Menu "Options", Item "Graphics" */
3116 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
3117 /* Menu "Options", Item "Graphics" */
3118 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
3119 #endif /* USE_GRAPHICS */
3122 /* Menu "Options", Item "Sound" */
3123 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
3124 #endif /* USE_SOUND */
3127 /* Menu "Options", Item "ScreenSaver" */
3128 EnableMenuItem(hm, IDM_OPTIONS_SAVER,
3129 MF_BYCOMMAND | MF_ENABLED);
3130 #endif /* USE_SAVER */
3135 * Check for double clicked (or dragged) savefile
3137 * Apparently, Windows copies the entire filename into the first
3138 * piece of the "command line string". Perhaps we should extract
3139 * the "basename" of that filename and append it to the "save" dir.
3141 static void check_for_save_file(LPSTR cmd_line)
3151 /* Extract filename */
3152 strcat(savefile, s);
3154 /* Validate the file */
3155 validate_file(savefile);
3157 /* Game in progress */
3158 game_in_progress = TRUE;
3166 * Process a menu command
3168 static void process_menus(WORD wCmd)
3185 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3187 plog("You cannot do that yet...");
3191 else if (game_in_progress)
3194 plog("¥×¥ì¥¤Ãæ¤Ï¿·¤·¤¤¥²¡¼¥à¤ò»Ï¤á¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3196 plog("You can't start a new game while you're still playing!");
3202 game_in_progress = TRUE;
3216 plog("¤Þ¤À½é´ü²½Ãæ¤Ç¤¹...");
3218 plog("You cannot do that yet...");
3222 else if (game_in_progress)
3225 plog("¥×¥ì¥¤Ãæ¤Ï¥²¡¼¥à¤ò¥í¡¼¥É¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¡ª");
3227 plog("You can't open a new game while you're still playing!");
3233 memset(&ofn, 0, sizeof(ofn));
3234 ofn.lStructSize = sizeof(ofn);
3235 ofn.hwndOwner = data[0].w;
3236 ofn.lpstrFilter = "Save Files (*.)\0*\0";
3237 ofn.nFilterIndex = 1;
3238 ofn.lpstrFile = savefile;
3239 ofn.nMaxFile = 1024;
3240 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
3241 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
3243 if (GetOpenFileName(&ofn))
3245 /* Load 'savefile' */
3246 validate_file(savefile);
3247 game_in_progress = TRUE;
3259 if (game_in_progress && character_generated)
3265 plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3267 plog("You may not do that right now.");
3273 /* Hack -- Forget messages */
3278 do_cmd_save_game(FALSE);
3279 #else /* ZANGBAND */
3281 #endif /* ZANGBAND */
3286 plog("º£¡¢¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£");
3288 plog("You may not do that right now.");
3298 if (game_in_progress && character_generated)
3304 plog("º£¤Ï½ªÎ»¤Ç¤¤Þ¤»¤ó¡£");
3306 plog("You may not do that right now.");
3312 /* Hack -- Forget messages */
3321 do_cmd_save_game(FALSE);
3322 #else /* ZANGBAND */
3324 #endif /* ZANGBAND */
3331 case IDM_FILE_SCORE:
3335 /* Build the filename */
3336 path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw");
3338 /* Open the binary high score file, for reading */
3339 highscore_fd = fd_open(buf, O_RDONLY);
3341 /* Paranoia -- No score file */
3342 if (highscore_fd < 0)
3344 msg_print("Score file unavailable.");
3354 /* Display the scores */
3355 display_scores_aux(0, MAX_HISCORES, -1, NULL);
3357 /* Shut the high score file */
3358 (void)fd_close(highscore_fd);
3360 /* Forget the high score fd */
3366 /* Hack - Flush it */
3374 case IDM_WINDOW_VIS_0:
3377 plog("¥á¥¤¥ó¥¦¥£¥ó¥É¥¦¤ÏÈóɽ¼¨¤Ë¤Ç¤¤Þ¤»¤ó¡ª");
3379 plog("You are not allowed to do that!");
3386 /* Window visibility */
3387 case IDM_WINDOW_VIS_1:
3388 case IDM_WINDOW_VIS_2:
3389 case IDM_WINDOW_VIS_3:
3390 case IDM_WINDOW_VIS_4:
3391 case IDM_WINDOW_VIS_5:
3392 case IDM_WINDOW_VIS_6:
3393 case IDM_WINDOW_VIS_7:
3395 i = wCmd - IDM_WINDOW_VIS_0;
3397 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3404 ShowWindow(td->w, SW_SHOW);
3405 term_data_redraw(td);
3409 td->visible = FALSE;
3410 ShowWindow(td->w, SW_HIDE);
3417 case IDM_WINDOW_FONT_0:
3418 case IDM_WINDOW_FONT_1:
3419 case IDM_WINDOW_FONT_2:
3420 case IDM_WINDOW_FONT_3:
3421 case IDM_WINDOW_FONT_4:
3422 case IDM_WINDOW_FONT_5:
3423 case IDM_WINDOW_FONT_6:
3424 case IDM_WINDOW_FONT_7:
3426 i = wCmd - IDM_WINDOW_FONT_0;
3428 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3432 term_change_font(td);
3437 /* Bizarre Display */
3438 case IDM_WINDOW_BIZ_0:
3439 case IDM_WINDOW_BIZ_1:
3440 case IDM_WINDOW_BIZ_2:
3441 case IDM_WINDOW_BIZ_3:
3442 case IDM_WINDOW_BIZ_4:
3443 case IDM_WINDOW_BIZ_5:
3444 case IDM_WINDOW_BIZ_6:
3445 case IDM_WINDOW_BIZ_7:
3447 i = wCmd - IDM_WINDOW_BIZ_0;
3449 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3453 td->bizarre = !td->bizarre;
3457 term_window_resize(td);
3462 /* Increase Tile Width */
3463 case IDM_WINDOW_I_WID_0:
3464 case IDM_WINDOW_I_WID_1:
3465 case IDM_WINDOW_I_WID_2:
3466 case IDM_WINDOW_I_WID_3:
3467 case IDM_WINDOW_I_WID_4:
3468 case IDM_WINDOW_I_WID_5:
3469 case IDM_WINDOW_I_WID_6:
3470 case IDM_WINDOW_I_WID_7:
3472 i = wCmd - IDM_WINDOW_I_WID_0;
3474 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3482 term_window_resize(td);
3487 /* Decrease Tile Height */
3488 case IDM_WINDOW_D_WID_0:
3489 case IDM_WINDOW_D_WID_1:
3490 case IDM_WINDOW_D_WID_2:
3491 case IDM_WINDOW_D_WID_3:
3492 case IDM_WINDOW_D_WID_4:
3493 case IDM_WINDOW_D_WID_5:
3494 case IDM_WINDOW_D_WID_6:
3495 case IDM_WINDOW_D_WID_7:
3497 i = wCmd - IDM_WINDOW_D_WID_0;
3499 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3507 term_window_resize(td);
3512 /* Increase Tile Height */
3513 case IDM_WINDOW_I_HGT_0:
3514 case IDM_WINDOW_I_HGT_1:
3515 case IDM_WINDOW_I_HGT_2:
3516 case IDM_WINDOW_I_HGT_3:
3517 case IDM_WINDOW_I_HGT_4:
3518 case IDM_WINDOW_I_HGT_5:
3519 case IDM_WINDOW_I_HGT_6:
3520 case IDM_WINDOW_I_HGT_7:
3522 i = wCmd - IDM_WINDOW_I_HGT_0;
3524 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3532 term_window_resize(td);
3537 /* Decrease Tile Height */
3538 case IDM_WINDOW_D_HGT_0:
3539 case IDM_WINDOW_D_HGT_1:
3540 case IDM_WINDOW_D_HGT_2:
3541 case IDM_WINDOW_D_HGT_3:
3542 case IDM_WINDOW_D_HGT_4:
3543 case IDM_WINDOW_D_HGT_5:
3544 case IDM_WINDOW_D_HGT_6:
3545 case IDM_WINDOW_D_HGT_7:
3547 i = wCmd - IDM_WINDOW_D_HGT_0;
3549 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
3557 term_window_resize(td);
3562 case IDM_OPTIONS_NO_GRAPHICS:
3567 plog("You may not do that right now.");
3571 /* Toggle "arg_graphics" */
3572 if (arg_graphics != GRAPHICS_NONE)
3574 arg_graphics = GRAPHICS_NONE;
3576 /* React to changes */
3577 Term_xtra_win_react();
3579 /* Hack -- Force redraw */
3580 Term_key_push(KTRL('R'));
3586 case IDM_OPTIONS_OLD_GRAPHICS:
3591 plog("You may not do that right now.");
3595 /* Toggle "arg_graphics" */
3596 if (arg_graphics != GRAPHICS_ORIGINAL)
3598 arg_graphics = GRAPHICS_ORIGINAL;
3600 /* React to changes */
3601 Term_xtra_win_react();
3603 /* Hack -- Force redraw */
3604 Term_key_push(KTRL('R'));
3610 case IDM_OPTIONS_NEW_GRAPHICS:
3615 plog("You may not do that right now.");
3619 /* Toggle "arg_graphics" */
3620 if (arg_graphics != GRAPHICS_ADAM_BOLT)
3622 arg_graphics = GRAPHICS_ADAM_BOLT;
3624 /* React to changes */
3625 Term_xtra_win_react();
3627 /* Hack -- Force redraw */
3628 Term_key_push(KTRL('R'));
3634 case IDM_OPTIONS_SOUND:
3639 plog("You may not do that right now.");
3643 /* Toggle "arg_sound" */
3644 arg_sound = !arg_sound;
3646 /* React to changes */
3647 Term_xtra_win_react();
3649 /* Hack -- Force redraw */
3650 Term_key_push(KTRL('R'));
3656 case IDM_OPTIONS_BG:
3661 plog("You may not do that right now.");
3665 /* Toggle "use_bg" */
3670 /* React to changes */
3671 Term_xtra_win_react();
3673 /* Hack -- Force redraw */
3674 Term_key_push(KTRL('R'));
3680 case IDM_OPTIONS_OPEN_BG:
3685 plog("You may not do that right now.");
3690 memset(&ofn, 0, sizeof(ofn));
3691 ofn.lStructSize = sizeof(ofn);
3692 ofn.hwndOwner = data[0].w;
3693 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3694 ofn.nFilterIndex = 1;
3695 ofn.lpstrFile = bg_bitmap_file;
3696 ofn.nMaxFile = 1023;
3697 ofn.lpstrInitialDir = NULL;
3699 ofn.lpstrTitle = "ÊÉ»æ¤òÁª¤ó¤Ç¤Í¡£";
3701 ofn.lpstrTitle = "Choose wall paper.";
3703 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3705 if (GetOpenFileName(&ofn))
3707 /* Load 'savefile' */
3712 /* React to changes */
3713 Term_xtra_win_react();
3715 /* Hack -- Force redraw */
3716 Term_key_push(KTRL('R'));
3721 case IDM_DUMP_SCREEN_HTML:
3723 static char buf[1024] = "";
3724 memset(&ofn, 0, sizeof(ofn));
3725 ofn.lStructSize = sizeof(ofn);
3726 ofn.hwndOwner = data[0].w;
3727 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
3728 ofn.nFilterIndex = 1;
3729 ofn.lpstrFile = buf;
3730 ofn.nMaxFile = 1023;
3731 ofn.lpstrDefExt = "html";
3732 ofn.lpstrInitialDir = NULL;
3734 ofn.lpstrTitle = "HTML¤Ç¥¹¥¯¥ê¡¼¥ó¥À¥ó¥×¤òÊݸ";
3736 ofn.lpstrTitle = "Save screen dump as HTML.";
3738 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
3740 if (GetSaveFileName(&ofn))
3742 extern void do_cmd_save_screen_html_aux(char *filename, int message);
3743 do_cmd_save_screen_html_aux(buf, 0);
3750 case IDM_OPTIONS_SAVER:
3754 DestroyWindow(hwndSaver);
3759 /* Create a screen scaver window */
3760 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
3761 "Angband Screensaver",
3762 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
3763 0, 0, GetSystemMetrics(SM_CXSCREEN),
3764 GetSystemMetrics(SM_CYSCREEN),
3765 NULL, NULL, hInstance, NULL);
3769 /* Push the window to the bottom XXX XXX XXX */
3770 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3775 plog("¥¦¥£¥ó¥É¥¦¤òºîÀ®½ÐÍè¤Þ¤»¤ó");
3777 plog("Failed to create saver window");
3787 case IDM_OPTIONS_MAP:
3793 case IDM_HELP_CONTENTS:
3797 path_build(tmp, 1024, ANGBAND_DIR_XTRA_HELP, "zangband.chm");
3798 if (check_file(tmp))
3800 HtmlHelp(data[0].w, tmp, HH_DISPLAY_TOPIC, 0);
3805 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
3806 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
3808 plog_fmt("Cannot find help file: %s", tmp);
3809 plog("Use the online help files instead.");
3814 #else /* HTML_HELP */
3817 path_build(tmp, 1024, ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
3818 if (check_file(tmp))
3820 sprintf(buf, "winhelp.exe %s", tmp);
3821 WinExec(buf, SW_NORMAL);
3826 plog_fmt("¥Ø¥ë¥×¥Õ¥¡¥¤¥ë[%s]¤¬¸«ÉÕ¤«¤ê¤Þ¤»¤ó¡£", tmp);
3827 plog("Âå¤ï¤ê¤Ë¥ª¥ó¥é¥¤¥ó¥Ø¥ë¥×¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£");
3829 plog_fmt("Cannot find help file: %s", tmp);
3830 plog("Use the online help files instead.");
3835 #endif /* HTML_HELP */
3843 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
3844 WPARAM wParam, LPARAM lParam);
3845 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
3846 WPARAM wParam, LPARAM lParam)
3847 #else /* __MWERKS__ */
3848 LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
3849 WPARAM wParam, LPARAM lParam)
3850 #endif /* __MWERKS__ */
3856 MINMAXINFO FAR *lpmmi;
3862 /* Acquire proper "term_data" info */
3863 td = (term_data *)GetWindowLong(hWnd, 0);
3865 /* Handle message */
3871 SetWindowLong(hWnd, 0, (LONG)(my_td));
3881 case WM_GETMINMAXINFO:
3884 lpmmi = (MINMAXINFO FAR *)lParam;
3886 /* this message was sent before WM_NCCREATE */
3889 /* Minimum window size is 8x2 */
3890 rc.left = rc.top = 0;
3891 rc.right = rc.left + 8 * td->tile_wid + td->size_ow1 + td->size_ow2;
3892 rc.bottom = rc.top + 2 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
3895 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3897 /* Save minimum size */
3898 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
3899 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
3901 /* Maximum window size */
3902 rc.left = rc.top = 0;
3903 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
3904 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2;
3907 rc.right += (td->tile_wid - 1);
3908 rc.bottom += (td->tile_hgt - 1);
3911 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3913 /* Save maximum size */
3914 lpmmi->ptMaxSize.x = rc.right - rc.left;
3915 lpmmi->ptMaxSize.y = rc.bottom - rc.top;
3917 /* Save maximum size */
3918 lpmmi->ptMaxTrackSize.x = rc.right - rc.left;
3919 lpmmi->ptMaxTrackSize.y = rc.bottom - rc.top;
3926 BeginPaint(hWnd, &ps);
3927 if (td) term_data_redraw(td);
3928 EndPaint(hWnd, &ps);
3929 ValidateRect(hWnd, NULL);
3940 /* Extract the modifiers */
3941 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
3942 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
3943 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
3945 /* Handle "special" keys */
3946 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
3948 /* Begin the macro trigger */
3951 /* Send the modifiers */
3952 if (mc) Term_keypress('C');
3953 if (ms) Term_keypress('S');
3954 if (ma) Term_keypress('A');
3956 /* Extract "scan code" */
3957 i = LOBYTE(HIWORD(lParam));
3959 /* Introduce the scan code */
3962 /* Encode the hexidecimal scan code */
3963 Term_keypress(hexsym[i/16]);
3964 Term_keypress(hexsym[i%16]);
3966 /* End the macro trigger */
3977 Term_keypress(wParam);
3989 if (game_in_progress && character_generated)
3993 plog("You may not do that right now.");
3997 /* Hack -- Forget messages */
4006 do_cmd_save_game(FALSE);
4007 #else /* ZANGBAND */
4009 #endif /* ZANGBAND */
4023 process_menus(LOWORD(wParam));
4029 /* this message was sent before WM_NCCREATE */
4032 /* it was sent from inside CreateWindowEx */
4033 if (!td->w) return 1;
4035 /* was sent from WM_SIZE */
4036 if (td->size_hack) return 1;
4040 case SIZE_MINIMIZED:
4042 /* Hide sub-windows */
4043 for (i = 1; i < MAX_TERM_DATA; i++)
4045 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
4050 case SIZE_MAXIMIZED:
4052 /* fall through XXX XXX XXX */
4057 uint old_tile_wid = td->tile_wid;
4058 uint old_tile_hgt = td->tile_hgt;
4060 td->size_hack = TRUE;
4062 td->tile_wid = LOWORD(lParam) / td->cols;
4063 td->tile_hgt = HIWORD(lParam) / td->rows;
4065 if ((td->tile_wid != old_tile_wid) ||
4066 (td->tile_hgt != old_tile_hgt))
4071 InvalidateRect(td->w, NULL, TRUE);
4074 /* Show sub-windows */
4075 for (i = 1; i < MAX_TERM_DATA; i++)
4077 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
4080 td->size_hack = FALSE;
4088 case WM_PALETTECHANGED:
4090 /* Ignore if palette change caused by itself */
4091 if ((HWND)wParam == hWnd) return 0;
4093 /* Fall through... */
4096 case WM_QUERYNEWPALETTE:
4098 if (!paletted) return 0;
4102 SelectPalette(hdc, hPal, FALSE);
4104 i = RealizePalette(hdc);
4106 /* if any palette entries changed, repaint the window. */
4107 if (i) InvalidateRect(hWnd, NULL, TRUE);
4109 ReleaseDC(hWnd, hdc);
4116 if (wParam && !HIWORD(lParam))
4118 /* Do something to sub-windows */
4119 for (i = 1; i < MAX_TERM_DATA; i++)
4121 SetWindowPos(data[i].w, hWnd, 0, 0, 0, 0,
4122 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
4125 /* Focus on main window */
4135 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4140 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4141 WPARAM wParam, LPARAM lParam);
4142 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4143 WPARAM wParam, LPARAM lParam)
4144 #else /* __MWERKS__ */
4145 LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg,
4146 WPARAM wParam, LPARAM lParam)
4147 #endif /* __MWERKS__ */
4151 MINMAXINFO FAR *lpmmi;
4159 /* Acquire proper "term_data" info */
4160 td = (term_data *)GetWindowLong(hWnd, 0);
4162 /* Process message */
4168 SetWindowLong(hWnd, 0, (LONG)(my_td));
4178 case WM_GETMINMAXINFO:
4181 /* this message was sent before WM_NCCREATE */
4184 lpmmi = (MINMAXINFO FAR *)lParam;
4187 rc.left = rc.top = 0;
4188 rc.right = rc.left + 8 * td->tile_wid + td->size_ow1 + td->size_ow2;
4189 rc.bottom = rc.top + 2 * td->tile_hgt + td->size_oh1 + td->size_oh2;
4192 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4194 /* Save the minimum size */
4195 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
4196 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
4198 /* Maximum window size */
4199 rc.left = rc.top = 0;
4200 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
4201 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2;
4204 rc.right += (td->tile_wid - 1);
4205 rc.bottom += (td->tile_hgt - 1);
4208 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
4210 /* Save maximum size */
4211 lpmmi->ptMaxSize.x = rc.right - rc.left;
4212 lpmmi->ptMaxSize.y = rc.bottom - rc.top;
4214 /* Save the maximum size */
4215 lpmmi->ptMaxTrackSize.x = rc.right - rc.left;
4216 lpmmi->ptMaxTrackSize.y = rc.bottom - rc.top;
4223 uint old_tile_wid = td->tile_wid;
4224 uint old_tile_hgt = td->tile_hgt;
4226 /* this message was sent before WM_NCCREATE */
4229 /* it was sent from inside CreateWindowEx */
4230 if (!td->w) return 1;
4232 /* was sent from inside WM_SIZE */
4233 if (td->size_hack) return 1;
4235 td->size_hack = TRUE;
4237 td->tile_wid = LOWORD(lParam) / td->cols;
4238 td->tile_hgt = HIWORD(lParam) / td->rows;
4240 if ((td->tile_wid != old_tile_wid) ||
4241 (td->tile_hgt != old_tile_hgt))
4243 if (((td->tile_wid < td->font_wid) ||
4244 (td->tile_hgt < td->font_hgt)) ||
4245 ((td->cols < 80) || (td->rows < 24)))
4247 td->tile_wid = td->font_wid;
4248 td->tile_hgt = td->font_hgt;
4250 td->cols = (LOWORD(lParam) - td->size_ow1 - td->size_ow2) / td->tile_wid;
4251 td->rows = (HIWORD(lParam) - td->size_oh1 - td->size_oh2) / td->tile_hgt;
4256 MoveWindow(hWnd, td->pos_x, td->pos_y, td->size_wid, td->size_hgt, TRUE);
4259 InvalidateRect(td->w, NULL, TRUE);
4262 td->size_hack = FALSE;
4269 BeginPaint(hWnd, &ps);
4270 if (td) term_data_redraw(td);
4271 EndPaint(hWnd, &ps);
4282 /* Extract the modifiers */
4283 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
4284 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
4285 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
4287 /* Handle "special" keys */
4288 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
4290 /* Begin the macro trigger */
4293 /* Send the modifiers */
4294 if (mc) Term_keypress('C');
4295 if (ms) Term_keypress('S');
4296 if (ma) Term_keypress('A');
4298 /* Extract "scan code" */
4299 i = LOBYTE(HIWORD(lParam));
4301 /* Introduce the scan code */
4304 /* Encode the hexidecimal scan code */
4305 Term_keypress(hexsym[i/16]);
4306 Term_keypress(hexsym[i%16]);
4308 /* End the macro trigger */
4319 Term_keypress(wParam);
4323 case WM_PALETTECHANGED:
4325 /* ignore if palette change caused by itself */
4326 if ((HWND)wParam == hWnd) return FALSE;
4327 /* otherwise, fall through!!! */
4330 case WM_QUERYNEWPALETTE:
4332 if (!paletted) return 0;
4334 SelectPalette(hdc, hPal, FALSE);
4335 i = RealizePalette(hdc);
4336 /* if any palette entries changed, repaint the window. */
4337 if (i) InvalidateRect(hWnd, NULL, TRUE);
4338 ReleaseDC(hWnd, hdc);
4342 case WM_NCLBUTTONDOWN:
4346 if (wParam == HTCLOSE) wParam = HTSYSMENU;
4347 #endif /* HTCLOSE */
4349 if (wParam == HTSYSMENU)
4353 td->visible = FALSE;
4354 ShowWindow(td->w, SW_HIDE);
4364 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4370 #define MOUSE_SENS 40
4373 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4374 WPARAM wParam, LPARAM lParam);
4375 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4376 WPARAM wParam, LPARAM lParam)
4377 #else /* __MWERKS__ */
4378 LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg,
4379 WPARAM wParam, LPARAM lParam)
4380 #endif /* __MWERKS__ */
4382 static int iMouse = 0;
4383 static WORD xMouse = 0;
4384 static WORD yMouse = 0;
4407 if (LOWORD(wParam) == WA_INACTIVE) break;
4409 /* else fall through */
4413 case WM_LBUTTONDOWN:
4414 case WM_MBUTTONDOWN:
4415 case WM_RBUTTONDOWN:
4418 SendMessage(hWnd, WM_CLOSE, 0, 0);
4426 dx = LOWORD(lParam) - xMouse;
4427 dy = HIWORD(lParam) - yMouse;
4429 if (dx < 0) dx = -dx;
4430 if (dy < 0) dy = -dy;
4432 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
4434 SendMessage(hWnd, WM_CLOSE, 0, 0);
4438 /* Save last location */
4440 xMouse = LOWORD(lParam);
4441 yMouse = HIWORD(lParam);
4448 DestroyWindow(hwndSaver);
4455 return DefWindowProc(hWnd, uMsg, wParam, lParam);
4458 #endif /* USE_SAVER */
4464 /*** Temporary Hooks ***/
4468 * Display warning message (see "z-util.c")
4470 static void hack_plog(cptr str)
4472 /* Give a warning */
4476 MessageBox(NULL, str, "·Ù¹ð¡ª",
4477 MB_ICONEXCLAMATION | MB_OK);
4479 MessageBox(NULL, str, "Warning",
4480 MB_ICONEXCLAMATION | MB_OK);
4488 * Display error message and quit (see "z-util.c")
4490 static void hack_quit(cptr str)
4492 /* Give a warning */
4496 MessageBox(NULL, str, "¥¨¥é¡¼¡ª",
4497 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4499 MessageBox(NULL, str, "Error",
4500 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4505 /* Unregister the classes */
4506 UnregisterClass(AppName, hInstance);
4508 /* Destroy the icon */
4509 if (hIcon) DestroyIcon(hIcon);
4517 /*** Various hooks ***/
4521 * Display warning message (see "z-util.c")
4523 static void hook_plog(cptr str)
4529 MessageBox(data[0].w, str, "·Ù¹ð¡ª",
4530 MB_ICONEXCLAMATION | MB_OK);
4532 MessageBox(data[0].w, str, "Warning",
4533 MB_ICONEXCLAMATION | MB_OK);
4541 * Display error message and quit (see "z-util.c")
4543 static void hook_quit(cptr str)
4548 /* Give a warning */
4552 MessageBox(data[0].w, str, "¥¨¥é¡¼¡ª",
4553 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4555 MessageBox(data[0].w, str, "Error",
4556 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
4562 /* Save the preferences */
4566 /*** Could use 'Term_nuke_win()' XXX XXX XXX */
4568 /* Destroy all windows */
4569 for (i = MAX_TERM_DATA - 1; i >= 0; --i)
4571 term_force_font(&data[i], NULL);
4572 if (data[i].font_want) string_free(data[i].font_want);
4573 if (data[i].w) DestroyWindow(data[i].w);
4577 /* Free the bitmap stuff */
4579 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
4580 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
4582 #ifdef USE_TRANSPARENCY
4583 if (infMask.hPalette) DeleteObject(infMask.hPalette);
4584 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
4585 #endif /* USE_TRANSPARENCY */
4587 #endif /* USE_GRAPHICS */
4589 /*** Free some other stuff ***/
4591 DeleteObject(hbrYellow);
4596 if (hPal) DeleteObject(hPal);
4598 UnregisterClass(AppName, hInstance);
4600 if (hIcon) DestroyIcon(hIcon);
4607 /*** Initialize ***/
4613 static void init_stuff(void)
4620 /* Get program name with full path */
4621 GetModuleFileName(hInstance, path, 512);
4623 /* Save the "program name" XXX XXX XXX */
4626 /* Get the name of the "*.ini" file */
4627 strcpy(path + strlen(path) - 4, ".INI");
4629 /* Save the the name of the ini-file */
4630 ini_file = string_make(path);
4632 /* Analyze the path */
4638 if (path[i] == '\\')
4645 /* Add "lib" to the path */
4646 strcpy(path + i + 1, "lib\\");
4648 /* Validate the path */
4649 validate_dir(path, TRUE);
4651 /* Init the file paths */
4652 init_file_paths(path);
4654 /* Hack -- Validate the paths */
4655 validate_dir(ANGBAND_DIR_APEX, FALSE);
4656 validate_dir(ANGBAND_DIR_BONE, FALSE);
4658 /* Allow missing 'edit' directory */
4659 if (!check_dir(ANGBAND_DIR_EDIT))
4661 /* Must have 'data'! */
4662 validate_dir(ANGBAND_DIR_DATA, TRUE);
4666 /* Don't need 'data' */
4667 validate_dir(ANGBAND_DIR_DATA, FALSE);
4671 validate_dir(ANGBAND_DIR_SCRIPT, TRUE);
4672 #endif /* USE_SCRIPT */
4673 validate_dir(ANGBAND_DIR_FILE, TRUE);
4674 validate_dir(ANGBAND_DIR_HELP, FALSE);
4675 validate_dir(ANGBAND_DIR_INFO, FALSE);
4676 validate_dir(ANGBAND_DIR_PREF, TRUE);
4677 validate_dir(ANGBAND_DIR_SAVE, FALSE);
4678 validate_dir(ANGBAND_DIR_USER, TRUE);
4679 validate_dir(ANGBAND_DIR_XTRA, TRUE);
4681 /* Build the filename */
4683 path_build(path, 1024, ANGBAND_DIR_FILE, "news_j.txt");
4685 path_build(path, 1024, ANGBAND_DIR_FILE, "news.txt");
4689 /* Hack -- Validate the "news.txt" file */
4690 validate_file(path);
4694 /* Build the "font" path */
4695 path_build(path, 1024, ANGBAND_DIR_XTRA, "font");
4697 /* Allocate the path */
4698 ANGBAND_DIR_XTRA_FONT = string_make(path);
4700 /* Validate the "font" directory */
4701 validate_dir(ANGBAND_DIR_XTRA_FONT, TRUE);
4703 /* Build the filename */
4704 path_build(path, 1024, ANGBAND_DIR_XTRA_FONT, "8X13.FON");
4706 /* Hack -- Validate the basic font */
4707 validate_file(path);
4713 /* Build the "graf" path */
4714 path_build(path, 1024, ANGBAND_DIR_XTRA, "graf");
4716 /* Allocate the path */
4717 ANGBAND_DIR_XTRA_GRAF = string_make(path);
4719 /* Validate the "graf" directory */
4720 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
4722 #endif /* USE_GRAPHICS */
4727 /* Build the "sound" path */
4728 path_build(path, 1024, ANGBAND_DIR_XTRA, "sound");
4730 /* Allocate the path */
4731 ANGBAND_DIR_XTRA_SOUND = string_make(path);
4733 /* Validate the "sound" directory */
4734 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
4736 #endif /* USE_SOUND */
4740 /* Build the "music" path */
4741 path_build(path, 1024, ANGBAND_DIR_XTRA, "music");
4743 /* Allocate the path */
4744 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
4746 /* Validate the "music" directory */
4747 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
4749 #endif /* USE_MUSIC */
4751 /* Build the "help" path */
4752 path_build(path, 1024, ANGBAND_DIR_XTRA, "help");
4754 /* Allocate the path */
4755 ANGBAND_DIR_XTRA_HELP = string_make(path);
4757 /* Validate the "help" directory */
4758 /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
4762 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
4763 LPSTR lpCmdLine, int nCmdShow)
4775 if (hPrevInst == NULL)
4777 wc.style = CS_CLASSDC;
4778 wc.lpfnWndProc = AngbandWndProc;
4780 wc.cbWndExtra = 4; /* one long pointer to term_data */
4781 wc.hInstance = hInst;
4782 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
4783 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
4784 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
4785 wc.lpszMenuName = AppName;
4786 wc.lpszClassName = AppName;
4788 if (!RegisterClass(&wc)) exit(1);
4790 wc.lpfnWndProc = AngbandListProc;
4791 wc.lpszMenuName = NULL;
4792 wc.lpszClassName = AngList;
4794 if (!RegisterClass(&wc)) exit(2);
4798 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
4799 wc.lpfnWndProc = AngbandSaverProc;
4801 wc.lpszMenuName = NULL;
4802 wc.lpszClassName = "WindowsScreenSaverClass";
4804 if (!RegisterClass(&wc)) exit(3);
4810 /* Temporary hooks */
4811 plog_aux = hack_plog;
4812 quit_aux = hack_quit;
4813 core_aux = hack_quit;
4815 /* Prepare the filepaths */
4818 /* Initialize the keypress analyzer */
4819 for (i = 0; special_key_list[i]; ++i)
4821 special_key[special_key_list[i]] = TRUE;
4823 /* Initialize the keypress analyzer */
4824 for (i = 0; ignore_key_list[i]; ++i)
4826 ignore_key[ignore_key_list[i]] = TRUE;
4829 /* Determine if display is 16/256/true color */
4831 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
4832 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
4833 ReleaseDC(NULL, hdc);
4835 /* Initialize the colors */
4836 for (i = 0; i < 256; i++)
4840 /* Extract desired values */
4841 rv = angband_color_table[i][1];
4842 gv = angband_color_table[i][2];
4843 bv = angband_color_table[i][3];
4845 /* Extract the "complex" code */
4846 win_clr[i] = PALETTERGB(rv, gv, bv);
4848 /* Save the "simple" code */
4849 angband_color_table[i][0] = win_pal[i];
4852 /* Prepare the windows */
4858 /* Activate hooks */
4859 plog_aux = hook_plog;
4860 quit_aux = hook_quit;
4861 core_aux = hook_quit;
4863 /* Set the system suffix */
4864 ANGBAND_SYS = "win";
4866 /* Set the keyboard suffix */
4867 if (7 != GetKeyboardType(0))
4868 ANGBAND_KEYBOARD = "0";
4871 /* Japanese keyboard */
4872 switch (GetKeyboardType(1))
4874 case 0x0D01: case 0x0D02:
4875 case 0x0D03: case 0x0D04:
4876 case 0x0D05: case 0x0D06:
4878 ANGBAND_KEYBOARD = "NEC98";
4882 ANGBAND_KEYBOARD = "JAPAN";
4890 /* We are now initialized */
4894 if(lpCmdLine[0] == '-'){
4895 switch(lpCmdLine[1])
4899 if (!lpCmdLine[2]) break;
4900 chuukei_server = TRUE;
4901 if(connect_chuukei_server(&lpCmdLine[2])<0){
4902 msg_print("connect fail");
4905 msg_print("connect");
4912 if (!lpCmdLine[2]) break;
4913 chuukei_client = TRUE;
4914 connect_chuukei_server(&lpCmdLine[2]);
4924 /* Did the user double click on a save file? */
4925 if(!chuukei_server) check_for_save_file(lpCmdLine);
4927 /* Did the user double click on a save file? */
4928 check_for_save_file(lpCmdLine);
4931 /* Prompt the user */
4933 prt("[¥Õ¥¡¥¤¥ë] ¥á¥Ë¥å¡¼¤Î [¿·µ¬] ¤Þ¤¿¤Ï [³«¤¯] ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 8);
4935 prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 17);
4940 /* Process messages forever */
4941 while (GetMessage(&msg, NULL, 0, 0))
4943 TranslateMessage(&msg);
4944 DispatchMessage(&msg);
4955 #endif /* WINDOWS */