2 * todo main関数を含むファイルの割に長過ぎる。main-win-utils.cなどといった形で分割したい
4 * @brief Windows版固有実装(メインエントリポイント含む)
6 * @author Hengband Team
10 * Windows98かその前後の頃を起点としたAPI実装。
12 * DirectXといった昨今描画に標準的となったライブラリも用いていない。
13 * タイルの描画処理などについては、現在動作の詳細を検証中。
17 * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
19 * This software may be copied and distributed for educational, research,
20 * and not for profit purposes provided that this copyright and statement
21 * are included in all such copies.
24 * This file helps Angband work with Windows computers.
26 * To use this file, use an appropriate "Makefile" or "Project File",
27 * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
28 * make sure to obtain various extra files as described below.
30 * The official compilation uses the CodeWarrior Pro compiler, which
31 * includes a special project file and precompilable header file.
35 * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
36 * and/or color redefinitions.
40 * The "lib/user/font-win.prf" contains attr/char mappings for use with the
41 * normal "lib/xtra/font/*.fon" font files.
45 * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
46 * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
51 * Compiling this file, and using the resulting executable, requires
52 * several extra files not distributed with the standard Angband code.
53 * In any case, some "*.fon" files (including "8X13.FON" if nothing else)
54 * must be placed into "lib/xtra/font/". All of these extra files can be found
55 * in the "ext-win" archive.
59 * The "term_xtra_win_clear()" function should probably do a low-level
60 * clear of the current window, and redraw the borders and other things,
61 * if only for efficiency.
65 * A simpler method is needed for selecting the "tile size" for windows.
69 * The various "warning" messages assume the existance of the "screen.w"
70 * window, I think, and only a few calls actually check for its existance,
71 * this may be okay since "NULL" means "on top of all windows". (?) The
72 * user must never be allowed to "hide" the main window, or the "menubar"
77 * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
78 * use with the "winhelp.exe" program. These files *may* be available
79 * at the ftp site somewhere, but I have not seen them.
83 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
85 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
87 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
88 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
93 #include "signal-handlers.h"
98 #include "io/write-diary.h"
99 #include "cmd/cmd-dump.h"
100 #include "cmd/cmd-save.h"
101 #include "view-mainwindow.h"
103 #include "floor-events.h"
122 * Available graphic modes
124 #define GRAPHICS_NONE 0
125 #define GRAPHICS_ORIGINAL 1
126 #define GRAPHICS_ADAM_BOLT 2
127 #define GRAPHICS_HENGBAND 3
130 * Menu constants -- see "ANGBAND.RC"
132 #define IDM_FILE_NEW 100
133 #define IDM_FILE_OPEN 101
134 #define IDM_FILE_SAVE 110
135 #define IDM_FILE_SCORE 120
136 #define IDM_FILE_MOVIE 121
137 #define IDM_FILE_EXIT 130
139 #define IDM_WINDOW_VIS_0 200
140 #define IDM_WINDOW_VIS_1 201
141 #define IDM_WINDOW_VIS_2 202
142 #define IDM_WINDOW_VIS_3 203
143 #define IDM_WINDOW_VIS_4 204
144 #define IDM_WINDOW_VIS_5 205
145 #define IDM_WINDOW_VIS_6 206
146 #define IDM_WINDOW_VIS_7 207
148 #define IDM_WINDOW_FONT_0 210
149 #define IDM_WINDOW_FONT_1 211
150 #define IDM_WINDOW_FONT_2 212
151 #define IDM_WINDOW_FONT_3 213
152 #define IDM_WINDOW_FONT_4 214
153 #define IDM_WINDOW_FONT_5 215
154 #define IDM_WINDOW_FONT_6 216
155 #define IDM_WINDOW_FONT_7 217
157 #define IDM_WINDOW_POS_0 220
158 #define IDM_WINDOW_POS_1 221
159 #define IDM_WINDOW_POS_2 222
160 #define IDM_WINDOW_POS_3 223
161 #define IDM_WINDOW_POS_4 224
162 #define IDM_WINDOW_POS_5 225
163 #define IDM_WINDOW_POS_6 226
164 #define IDM_WINDOW_POS_7 227
166 #define IDM_WINDOW_BIZ_0 230
167 #define IDM_WINDOW_BIZ_1 231
168 #define IDM_WINDOW_BIZ_2 232
169 #define IDM_WINDOW_BIZ_3 233
170 #define IDM_WINDOW_BIZ_4 234
171 #define IDM_WINDOW_BIZ_5 235
172 #define IDM_WINDOW_BIZ_6 236
173 #define IDM_WINDOW_BIZ_7 237
175 #define IDM_WINDOW_I_WID_0 240
176 #define IDM_WINDOW_I_WID_1 241
177 #define IDM_WINDOW_I_WID_2 242
178 #define IDM_WINDOW_I_WID_3 243
179 #define IDM_WINDOW_I_WID_4 244
180 #define IDM_WINDOW_I_WID_5 245
181 #define IDM_WINDOW_I_WID_6 246
182 #define IDM_WINDOW_I_WID_7 247
184 #define IDM_WINDOW_D_WID_0 250
185 #define IDM_WINDOW_D_WID_1 251
186 #define IDM_WINDOW_D_WID_2 252
187 #define IDM_WINDOW_D_WID_3 253
188 #define IDM_WINDOW_D_WID_4 254
189 #define IDM_WINDOW_D_WID_5 255
190 #define IDM_WINDOW_D_WID_6 256
191 #define IDM_WINDOW_D_WID_7 257
193 #define IDM_WINDOW_I_HGT_0 260
194 #define IDM_WINDOW_I_HGT_1 261
195 #define IDM_WINDOW_I_HGT_2 262
196 #define IDM_WINDOW_I_HGT_3 263
197 #define IDM_WINDOW_I_HGT_4 264
198 #define IDM_WINDOW_I_HGT_5 265
199 #define IDM_WINDOW_I_HGT_6 266
200 #define IDM_WINDOW_I_HGT_7 267
202 #define IDM_WINDOW_D_HGT_0 270
203 #define IDM_WINDOW_D_HGT_1 271
204 #define IDM_WINDOW_D_HGT_2 272
205 #define IDM_WINDOW_D_HGT_3 273
206 #define IDM_WINDOW_D_HGT_4 274
207 #define IDM_WINDOW_D_HGT_5 275
208 #define IDM_WINDOW_D_HGT_6 276
209 #define IDM_WINDOW_D_HGT_7 277
211 #define IDM_OPTIONS_NO_GRAPHICS 400
212 #define IDM_OPTIONS_OLD_GRAPHICS 401
213 #define IDM_OPTIONS_NEW_GRAPHICS 402
214 #define IDM_OPTIONS_NEW2_GRAPHICS 403
215 #define IDM_OPTIONS_BIGTILE 409
216 #define IDM_OPTIONS_SOUND 410
217 #define IDM_OPTIONS_MUSIC 411
218 #define IDM_OPTIONS_SAVER 420
219 #define IDM_OPTIONS_MAP 430
220 #define IDM_OPTIONS_BG 440
221 #define IDM_OPTIONS_OPEN_BG 441
223 #define IDM_DUMP_SCREEN_HTML 450
225 #define IDM_HELP_CONTENTS 901
228 * Exclude parts of WINDOWS.H that are not needed
230 #define NOCOMM /* Comm driver APIs and definitions */
231 #define NOLOGERROR /* LogError() and related definitions */
232 #define NOPROFILER /* Profiler APIs */
233 #define NOLFILEIO /* _l* file I/O routines */
234 #define NOOPENFILE /* OpenFile and related definitions */
235 #define NORESOURCE /* Resource management */
236 #define NOATOM /* Atom management */
237 #define NOLANGUAGE /* Character test routines */
238 #define NOLSTRING /* lstr* string management routines */
239 #define NODBCS /* Double-byte character set routines */
240 #define NOKEYBOARDINFO /* Keyboard driver routines */
241 #define NOCOLOR /* COLOR_* color values */
242 #define NODRAWTEXT /* DrawText() and related definitions */
243 #define NOSCALABLEFONT /* Truetype scalable font support */
244 #define NOMETAFILE /* Metafile support */
245 #define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
246 #define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
247 #define NOKEYSTATES /* MK_* message key state flags */
248 #define NOWH /* SetWindowsHook and related WH_* definitions */
249 #define NOCLIPBOARD /* Clipboard APIs and definitions */
250 #define NOICONS /* IDI_* icon IDs */
251 #define NOMDI /* MDI support */
252 #define NOHELP /* Help support */
254 /* Not defined since it breaks Borland C++ 5.5 */
255 /* #define NOCTLMGR */ /* Control management and controls */
258 * Exclude parts of WINDOWS.H that are not needed (Win32)
260 #define WIN32_LEAN_AND_MEAN
261 #define NONLS /* All NLS defines and routines */
262 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
263 #define NOKANJI /* Kanji support stuff. */
264 #define NOMCX /* Modem Configuration Extensions */
267 * Include the "windows" support file
272 * Exclude parts of MMSYSTEM.H that are not needed
274 #define MMNODRV /* Installable driver support */
275 #define MMNOWAVE /* Waveform support */
276 #define MMNOMIDI /* MIDI support */
277 #define MMNOAUX /* Auxiliary audio support */
278 #define MMNOTIMER /* Timer support */
279 #define MMNOJOY /* Joystick support */
280 #define MMNOMCI /* MCI support */
281 #define MMNOMMIO /* Multimedia file I/O support */
282 #define MMNOMMSYSTEM /* General MMSYSTEM functions */
284 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
285 #define MOUSE_SENS 40
288 * Standard sound names
290 const concptr angband_sound_name[SOUND_MAX] =
362 * Standard music names
364 const concptr angband_music_basic_name[MUSIC_BASIC_MAX] =
390 * Include some more files. Note: the Cygnus Cygwin compiler
391 * doesn't use mmsystem.h instead it includes the winmm library
392 * which performs a similar function.
394 #include <mmsystem.h>
398 * Include the support for loading bitmaps
402 #define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
405 * Foreground color bits
407 #define VID_BLACK 0x00
408 #define VID_BLUE 0x01
409 #define VID_GREEN 0x02
410 #define VID_CYAN 0x03
412 #define VID_MAGENTA 0x05
413 #define VID_YELLOW 0x06
414 #define VID_WHITE 0x07
419 #define VID_BRIGHT 0x08
423 * @brief ターム情報構造体 / Extra "term" data
426 * pos_x / pos_y は各タームの左上点座標を指す。
429 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
430 * 1ドットずつ調整するステータスを指す。
431 * また、フォントを変更すると都度自動調整される。
434 * Note the use of "font_want" for the names of the font file requested by
435 * the user, and the use of "font_file" for the currently active font file.
437 * The "font_file" is uppercased, and takes the form "8X13.FON", while
438 * "font_want" can be in almost any form as long as it could be construed
439 * as attempting to represent the name of a font.
451 TERM_LEN rows; /* int -> uint */
454 uint pos_x; //!< タームの左上X座標
455 uint pos_y; //!< タームの左上Y座標
470 int font_wid; //!< フォント横幅
471 int font_hgt; //!< フォント縦幅
472 int tile_wid; //!< タイル横幅
473 int tile_hgt; //!< タイル縦幅
484 #define MAX_TERM_DATA 8 //!< Maximum number of windows
486 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
487 static term_data *my_td; //!< Hack -- global "window creation" pointer
488 POINT normsize; //!< Remember normal size of main window when maxmized
491 * was main window maximized on previous playing
493 bool win_maximized = FALSE;
498 bool game_in_progress = FALSE;
501 * note when "open"/"new" become valid
503 bool initialized = FALSE;
506 * screen paletted, i.e. 256 colors
508 bool paletted = FALSE;
511 * 16 colors screen, don't use RGB()
513 bool colors16 = FALSE;
516 * Saved instance handle
518 static HINSTANCE hInstance;
521 * Yellow brush for the cursor
523 static HBRUSH hbrYellow;
533 static HPALETTE hPal;
536 static HBITMAP hBG = NULL;
537 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
538 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
541 * The screen saver window
543 static HWND hwndSaver;
546 * 現在使用中のタイルID(0ならば未使用)
547 * Flag set once "graphics" has been initialized
549 static byte current_graphics_mode = 0;
554 static DIBINIT infGraph;
557 * The global bitmap mask
559 static DIBINIT infMask;
562 * Flag set once "sound" has been initialized
564 static bool can_use_sound = FALSE;
566 #define SAMPLE_SOUND_MAX 16
568 * An array of sound file names
570 static concptr sound_file[SOUND_MAX][SAMPLE_SOUND_MAX];
572 #define SAMPLE_MUSIC_MAX 16
573 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
574 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
575 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
576 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
577 static bool can_use_music = FALSE;
579 static MCI_OPEN_PARMS mop;
580 static char mci_device_type[256];
582 int current_music_type = 0;
583 int current_music_id = 0;
586 * Full path to ANGBAND.INI
588 static concptr ini_file = NULL;
591 * Name of application
593 static concptr AppName = "ANGBAND";
596 * Name of sub-window type
598 static concptr AngList = "AngList";
603 static concptr ANGBAND_DIR_XTRA_GRAF;
604 static concptr ANGBAND_DIR_XTRA_SOUND;
605 static concptr ANGBAND_DIR_XTRA_MUSIC;
606 static concptr ANGBAND_DIR_XTRA_HELP;
607 static concptr ANGBAND_DIR_XTRA_MUSIC;
610 * The "complex" color values
612 static COLORREF win_clr[256];
616 * Flag for macro trigger with dump ASCII
618 static bool term_no_press = FALSE;
623 static bool mouse_down = FALSE;
624 static bool paint_rect = FALSE;
625 static TERM_LEN mousex = 0, mousey = 0;
626 static TERM_LEN oldx, oldy;
629 * @brief The "simple" color values
631 * See "main-ibm.c" for original table information
632 * The entries below are taken from the "color bits" defined above.
633 * Note that many of the choices below suck, but so do crappy monitors.
635 static BYTE win_pal[256] =
637 VID_BLACK, /* Dark */
638 VID_WHITE, /* White */
639 VID_CYAN, /* Slate XXX */
640 VID_RED | VID_BRIGHT, /* Orange XXX */
642 VID_GREEN, /* Green */
644 VID_YELLOW, /* Umber XXX */
645 VID_BLACK | VID_BRIGHT, /* Light Dark */
646 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
647 VID_MAGENTA, /* Violet XXX */
648 VID_YELLOW | VID_BRIGHT, /* Yellow */
649 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
650 VID_GREEN | VID_BRIGHT, /* Light Green */
651 VID_BLUE | VID_BRIGHT, /* Light Blue */
652 VID_YELLOW /* Light Umber XXX */
656 * Hack -- define which keys are "special"
658 static bool special_key[256];
659 static bool ignore_key[256];
662 * Hack -- initialization list for "special_key"
664 static byte special_key_list[] = {
665 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
666 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
667 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
668 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
669 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
670 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
671 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
672 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
673 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
674 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
675 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
676 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
677 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
678 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
679 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
680 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
681 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
686 static byte ignore_key_list[] = {
687 VK_ESCAPE, VK_TAB, VK_SPACE,
688 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
689 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
690 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
695 /* Function prototype */
697 static bool is_already_running(void);
700 static void delete_bg(void)
710 static int init_bg(void)
712 char * bmfile = bg_bitmap_file;
714 if (use_bg == 0) return 0;
716 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
718 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
728 static void DrawBG(HDC hdc, RECT *r)
733 int x = r->left, y = r->top;
737 GetObject(hBG, sizeof(bm), &bm);
738 int swid = bm.bmWidth;
739 int shgt = bm.bmHeight;
741 HDC hdcSrc = CreateCompatibleDC(hdc);
742 HBITMAP hOld = SelectObject(hdcSrc, hBG);
746 int cwid = MIN(swid - sx, r->right - nx);
749 int chgt = MIN(shgt - sy, r->bottom - ny);
750 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
752 } while (ny < r->bottom);
756 } while (nx < r->right);
758 SelectObject(hdcSrc, hOld);
764 * Check for existance of a file
766 static bool check_file(concptr s)
770 DWORD attrib = GetFileAttributes(path);
771 if (attrib == INVALID_FILE_NAME) return FALSE;
772 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return FALSE;
779 * Check for existance of a directory
781 static bool check_dir(concptr s)
785 int i = strlen(path);
786 if (i && (path[i - 1] == '\\')) path[--i] = '\0';
788 DWORD attrib = GetFileAttributes(path);
789 if (attrib == INVALID_FILE_NAME) return FALSE;
790 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return FALSE;
799 static void validate_file(concptr s)
801 if (check_file(s)) return;
803 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
808 * Validate a directory
810 static void validate_dir(concptr s, bool vital)
812 if (check_dir(s)) return;
816 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
820 quit_fmt("Unable to create directory:\n%s", s);
826 * @brief (Windows版固有実装)Get the "size" for a window
828 static void term_getsize(term_data *td)
830 if (td->cols < 1) td->cols = 1;
831 if (td->rows < 1) td->rows = 1;
833 TERM_LEN wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
834 TERM_LEN hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
838 rc.right = rc.left + wid;
840 rc.bottom = rc.top + hgt;
842 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
843 td->size_wid = rc.right - rc.left;
844 td->size_hgt = rc.bottom - rc.top;
847 GetWindowRect(td->w, &rc);
854 * Write the "prefs" for a single term
856 static void save_prefs_aux(int i)
858 term_data *td = &data[i];
859 GAME_TEXT sec_name[128];
864 sprintf(sec_name, "Term-%d", i);
868 strcpy(buf, td->visible ? "1" : "0");
869 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
873 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "MS ゴシック");
875 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "Courier");
878 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
880 wsprintf(buf, "%d", td->lf.lfWidth);
881 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
882 wsprintf(buf, "%d", td->lf.lfHeight);
883 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
884 wsprintf(buf, "%d", td->lf.lfWeight);
885 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
887 strcpy(buf, td->bizarre ? "1" : "0");
888 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
890 wsprintf(buf, "%d", td->tile_wid);
891 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
893 wsprintf(buf, "%d", td->tile_hgt);
894 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
896 WINDOWPLACEMENT lpwndpl;
897 lpwndpl.length = sizeof(WINDOWPLACEMENT);
898 GetWindowPlacement(td->w, &lpwndpl);
900 RECT rc = lpwndpl.rcNormalPosition;
901 if (i == 0) wsprintf(buf, "%d", normsize.x);
902 else wsprintf(buf, "%d", td->cols);
904 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
906 if (i == 0) wsprintf(buf, "%d", normsize.y);
907 else wsprintf(buf, "%d", td->rows);
909 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
912 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
913 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
916 GetWindowRect(td->w, &rc);
917 wsprintf(buf, "%d", rc.left);
918 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
920 wsprintf(buf, "%d", rc.top);
921 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
924 strcpy(buf, td->posfix ? "1" : "0");
925 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
932 * We assume that the windows have all been initialized
934 static void save_prefs(void)
937 sprintf(buf, "%d", arg_graphics);
938 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
940 strcpy(buf, arg_bigtile ? "1" : "0");
941 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
943 strcpy(buf, arg_sound ? "1" : "0");
944 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
946 strcpy(buf, arg_music ? "1" : "0");
947 WritePrivateProfileString("Angband", "Music", buf, ini_file);
949 strcpy(buf, use_bg ? "1" : "0");
950 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
951 WritePrivateProfileString("Angband", "BackGroundBitmap",
952 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
954 for (int i = 0; i < MAX_TERM_DATA; ++i)
962 * Load the "prefs" for a single term
964 static void load_prefs_aux(int i)
966 term_data *td = &data[i];
967 GAME_TEXT sec_name[128];
970 int dispx = GetSystemMetrics(SM_CXVIRTUALSCREEN);
971 int dispy = GetSystemMetrics(SM_CYVIRTUALSCREEN);
975 sprintf(sec_name, "Term-%d", i);
976 sprintf(sec_name, "Term-%d", i);
979 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
983 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
985 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
988 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
990 td->font_want = string_make(tmp);
993 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
994 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
995 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
997 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
998 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
1000 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
1001 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
1002 normsize.x = td->cols; normsize.y = td->rows;
1006 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
1009 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
1010 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
1011 td->pos_x = MIN(MAX(0, posx), dispx - 128);
1012 td->pos_y = MIN(MAX(0, posy), dispy - 128);
1016 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
1024 static void load_prefs(void)
1026 arg_graphics = (byte)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
1027 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
1028 use_bigtile = arg_bigtile;
1029 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
1030 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
1031 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
1032 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
1033 for (int i = 0; i < MAX_TERM_DATA; ++i)
1041 * - Taken from files.c.
1043 * Extract "tokens" from a buffer
1045 * This function uses "whitespace" as delimiters, and treats any amount of
1046 * whitespace as a single delimiter. We will never return any empty tokens.
1047 * When given an empty buffer, or a buffer containing only "whitespace", we
1048 * will return no tokens. We will never extract more than "num" tokens.
1050 * By running a token through the "text_to_ascii()" function, you can allow
1051 * that token to include (encoded) whitespace, using "\s" to encode spaces.
1053 * We save pointers to the tokens in "tokens", and return the number found.
1055 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
1063 for (; *s && iswspace(*s); ++s) /* loop */;
1067 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
1069 if (*t) *t++ = '\0';
1079 static void load_sound_prefs(void)
1082 char ini_path[1024];
1083 char wav_path[1024];
1084 char *zz[SAMPLE_SOUND_MAX];
1086 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
1087 for (int i = 0; i < SOUND_MAX; i++)
1089 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
1090 int num = tokenize_whitespace(tmp, SAMPLE_SOUND_MAX, zz);
1091 for (int j = 0; j < num; j++)
1093 /* Access the sound */
1094 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
1096 /* Save the sound filename, if it exists */
1097 if (check_file(wav_path))
1098 sound_file[i][j] = string_make(zz[j]);
1104 static void load_music_prefs(void)
1107 char ini_path[1024];
1108 char wav_path[1024];
1109 char *zz[SAMPLE_MUSIC_MAX];
1112 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1113 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1114 for (int i = 0; i < MUSIC_BASIC_MAX; i++)
1116 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1117 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1118 for (int j = 0; j < num; j++)
1120 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1121 if (check_file(wav_path))
1122 music_file[i][j] = string_make(zz[j]);
1126 for (int i = 0; i < current_world_ptr->max_d_idx; i++)
1128 sprintf(key, "dungeon%03d", i);
1129 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1130 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1131 for (int j = 0; j < num; j++)
1133 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1134 if (check_file(wav_path))
1135 dungeon_music_file[i][j] = string_make(zz[j]);
1139 for (int i = 0; i < max_q_idx; i++)
1141 sprintf(key, "quest%03d", i);
1142 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1143 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1144 for (int j = 0; j < num; j++)
1146 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1147 if (check_file(wav_path))
1148 quest_music_file[i][j] = string_make(zz[j]);
1152 for (int i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1154 sprintf(key, "town%03d", i);
1155 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1156 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1157 for (int j = 0; j < num; j++)
1159 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1160 if (check_file(wav_path))
1161 town_music_file[i][j] = string_make(zz[j]);
1168 * Create the new global palette based on the bitmap palette
1169 * (if any), and the standard 16 entry palette derived from
1170 * "win_clr[]" which is used for the basic 16 Angband colors.
1172 * This function is never called before all windows are ready.
1174 * This function returns FALSE if the new palette could not be
1175 * prepared, which should normally be a fatal error. XXX XXX
1177 * Note that only some machines actually use a "palette".
1179 static int new_palette(void)
1184 LPLOGPALETTE pLogPal;
1185 LPPALETTEENTRY lppe;
1187 if (!paletted) return TRUE;
1193 HPALETTE hBmPal = infGraph.hPalette;
1196 lppeSize = 256 * sizeof(PALETTEENTRY);
1197 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1198 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1199 if ((nEntries == 0) || (nEntries > 220))
1201 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1202 rnfree(lppe, lppeSize);
1207 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1208 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1209 pLogPal->palVersion = 0x300;
1210 pLogPal->palNumEntries = nEntries + 16;
1211 for (i = 0; i < nEntries; i++)
1213 pLogPal->palPalEntry[i] = lppe[i];
1216 for (i = 0; i < 16; i++)
1219 p = &(pLogPal->palPalEntry[i + nEntries]);
1220 p->peRed = GetRValue(win_clr[i]);
1221 p->peGreen = GetGValue(win_clr[i]);
1222 p->peBlue = GetBValue(win_clr[i]);
1223 p->peFlags = PC_NOCOLLAPSE;
1226 if (lppe) rnfree(lppe, lppeSize);
1228 HPALETTE hNewPal = CreatePalette(pLogPal);
1229 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1231 rnfree(pLogPal, pLogPalSize);
1233 HDC hdc = GetDC(td->w);
1234 SelectPalette(hdc, hNewPal, 0);
1235 i = RealizePalette(hdc);
1236 ReleaseDC(td->w, hdc);
1237 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1239 for (i = 1; i < MAX_TERM_DATA; i++)
1243 SelectPalette(hdc, hNewPal, 0);
1244 ReleaseDC(td->w, hdc);
1247 if (hPal) DeleteObject(hPal);
1255 * @brief グラフィクスを初期化する / Initialize graphics
1258 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1259 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1262 static bool init_graphics(void)
1265 BYTE wid, hgt, twid, thgt, ox, oy;
1268 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1278 ANGBAND_GRAF = "new";
1280 else if (arg_graphics == GRAPHICS_HENGBAND)
1290 ANGBAND_GRAF = "ne2";
1301 ANGBAND_GRAF = "old";
1304 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1305 if (!ReadDIB(data[0].w, buf, &infGraph))
1307 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1311 infGraph.CellWidth = wid;
1312 infGraph.CellHeight = hgt;
1313 infGraph.TileWidth = twid;
1314 infGraph.TileHeight = thgt;
1315 infGraph.OffsetX = ox;
1316 infGraph.OffsetY = oy;
1318 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1320 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1321 if (!ReadDIB(data[0].w, buf, &infMask))
1323 plog_fmt("Cannot read bitmap file '%s'", buf);
1328 if (arg_graphics == GRAPHICS_HENGBAND)
1330 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1331 if (!ReadDIB(data[0].w, buf, &infMask))
1333 plog_fmt("Cannot read bitmap file '%s'", buf);
1340 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1344 current_graphics_mode = arg_graphics;
1345 return (current_graphics_mode);
1352 static void init_music(void)
1357 can_use_music = TRUE;
1362 * Hack -- Stop a music
1364 static void stop_music(void)
1366 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1367 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1374 static void init_sound(void)
1379 can_use_sound = TRUE;
1387 static void term_window_resize(term_data *td)
1391 SetWindowPos(td->w, 0, 0, 0,
1392 td->size_wid, td->size_hgt,
1393 SWP_NOMOVE | SWP_NOZORDER);
1394 InvalidateRect(td->w, NULL, TRUE);
1400 * Force the use of a new "font file" for a term_data.
1401 * This function may be called before the "window" is ready.
1402 * This function returns zero only if everything succeeds.
1403 * Note that the "font name" must be capitalized!!!
1405 static errr term_force_font(term_data *td, concptr path)
1407 if (td->font_id) DeleteObject(td->font_id);
1410 td->font_id = CreateFontIndirect(&(td->lf));
1411 int wid = td->lf.lfWidth;
1412 int hgt = td->lf.lfHeight;
1413 if (!td->font_id) return 1;
1421 hdcDesktop = GetDC(HWND_DESKTOP);
1422 hfOld = SelectObject(hdcDesktop, td->font_id);
1423 GetTextMetrics(hdcDesktop, &tm);
1424 SelectObject(hdcDesktop, hfOld);
1425 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1427 wid = tm.tmAveCharWidth;
1440 * Allow the user to change the font for this window.
1442 static void term_change_font(term_data *td)
1445 memset(&cf, 0, sizeof(cf));
1446 cf.lStructSize = sizeof(cf);
1447 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1448 cf.lpLogFont = &(td->lf);
1450 if (!ChooseFont(&cf)) return;
1452 term_force_font(td, NULL);
1454 td->tile_wid = td->font_wid;
1455 td->tile_hgt = td->font_hgt;
1457 term_window_resize(td);
1462 * Allow the user to lock this window.
1464 static void term_window_pos(term_data *td, HWND hWnd)
1466 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1467 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1470 static void windows_map(player_type *player_ptr);
1473 * Hack -- redraw a term_data
1475 static void term_data_redraw(player_type *player_ptr, term_data *td)
1479 windows_map(player_ptr);
1483 Term_activate(&td->t);
1485 Term_activate(term_screen);
1489 void term_inversed_area(HWND hWnd, int x, int y, int w, int h)
1491 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
1492 int tx = td->size_ow1 + x * td->tile_wid;
1493 int ty = td->size_oh1 + y * td->tile_hgt;
1494 int tw = w * td->tile_wid - 1;
1495 int th = h * td->tile_hgt - 1;
1497 HDC hdc = GetDC(hWnd);
1498 HBRUSH myBrush = CreateSolidBrush(RGB(255, 255, 255));
1499 HBRUSH oldBrush = SelectObject(hdc, myBrush);
1500 HPEN oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1502 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
1504 SelectObject(hdc, oldBrush);
1505 SelectObject(hdc, oldPen);
1510 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
1512 static errr term_user_win(int n)
1520 * React to global changes
1522 static errr term_xtra_win_react(player_type *player_ptr)
1526 for (int i = 0; i < 256; i++)
1528 win_pal[i] = angband_color_table[i][0];
1535 bool change = FALSE;
1536 for (int i = 0; i < 256; i++)
1538 rv = angband_color_table[i][1];
1539 gv = angband_color_table[i][2];
1540 bv = angband_color_table[i][3];
1541 code = PALETTERGB(rv, gv, bv);
1542 if (win_clr[i] != code)
1549 if (change) (void)new_palette();
1552 if (use_sound != arg_sound)
1555 use_sound = arg_sound;
1558 if (use_music != arg_music)
1561 use_music = arg_music;
1562 if (!arg_music) stop_music();
1563 else select_floor_music(player_ptr);
1566 if (use_graphics != arg_graphics)
1568 if (arg_graphics && !init_graphics())
1570 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
1571 arg_graphics = GRAPHICS_NONE;
1574 use_graphics = arg_graphics;
1575 reset_visuals(player_ptr);
1578 for (int i = 0; i < MAX_TERM_DATA; i++)
1581 term_data *td = &data[i];
1582 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
1584 Term_activate(&td->t);
1585 Term_resize(td->cols, td->rows);
1596 * Process at least one event
1598 static errr term_xtra_win_event(int v)
1603 if (GetMessage(&msg, NULL, 0, 0))
1605 TranslateMessage(&msg);
1606 DispatchMessage(&msg);
1611 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1613 TranslateMessage(&msg);
1614 DispatchMessage(&msg);
1623 * Process all pending events
1625 static errr term_xtra_win_flush(void)
1628 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1630 TranslateMessage(&msg);
1631 DispatchMessage(&msg);
1639 * Hack -- clear the screen
1641 * Make this more efficient
1643 static errr term_xtra_win_clear(void)
1645 term_data *td = (term_data*)(Term->data);
1648 rc.left = td->size_ow1;
1649 rc.right = rc.left + td->cols * td->tile_wid;
1650 rc.top = td->size_oh1;
1651 rc.bottom = rc.top + td->rows * td->tile_hgt;
1653 HDC hdc = GetDC(td->w);
1654 SetBkColor(hdc, RGB(0, 0, 0));
1655 SelectObject(hdc, td->font_id);
1656 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1660 rc.left = 0; rc.top = 0;
1664 ReleaseDC(td->w, hdc);
1670 * Hack -- make a noise
1672 static errr term_xtra_win_noise(void)
1674 MessageBeep(MB_ICONASTERISK);
1680 * Hack -- make a sound
1682 static errr term_xtra_win_sound(int v)
1685 if (!use_sound) return 1;
1686 if ((v < 0) || (v >= SOUND_MAX)) return 1;
1689 for (i = 0; i < SAMPLE_SOUND_MAX; i++)
1691 if (!sound_file[v][i])
1695 if (i == 0) return 1;
1697 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
1698 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
1702 * Hack -- play a music
1704 static errr term_xtra_win_music(int n, int v)
1708 if (n == TERM_XTRA_MUSIC_MUTE)
1710 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1711 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1714 if (!use_music) return 1;
1716 if (n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return 1;
1717 else if (v < 0 || v >= 1000) return(1); /*!< TODO */
1721 case TERM_XTRA_MUSIC_BASIC:
1722 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!music_file[v][i]) break;
1724 case TERM_XTRA_MUSIC_DUNGEON:
1725 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!dungeon_music_file[v][i]) break;
1727 case TERM_XTRA_MUSIC_QUEST:
1728 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!quest_music_file[v][i]) break;
1730 case TERM_XTRA_MUSIC_TOWN:
1731 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!town_music_file[v][i]) break;
1742 case TERM_XTRA_MUSIC_BASIC:
1743 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
1745 case TERM_XTRA_MUSIC_DUNGEON:
1746 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
1748 case TERM_XTRA_MUSIC_QUEST:
1749 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
1751 case TERM_XTRA_MUSIC_TOWN:
1752 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
1756 if (current_music_type == n && current_music_id == v)
1760 current_music_type = n;
1761 current_music_id = v;
1763 mop.lpstrDeviceType = mci_device_type;
1764 mop.lpstrElementName = buf;
1765 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1766 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1767 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
1768 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
1769 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
1775 * Delay for "x" milliseconds
1777 static int term_xtra_win_delay(int v)
1785 * todo z-termに影響があるのでplayer_typeの追加は保留
1786 * Do a "special thing"
1788 static errr term_xtra_win(int n, int v)
1792 case TERM_XTRA_NOISE:
1794 return (term_xtra_win_noise());
1796 case TERM_XTRA_MUSIC_BASIC:
1797 case TERM_XTRA_MUSIC_DUNGEON:
1798 case TERM_XTRA_MUSIC_QUEST:
1799 case TERM_XTRA_MUSIC_TOWN:
1801 return (term_xtra_win_music(n, v));
1803 case TERM_XTRA_SOUND:
1805 return (term_xtra_win_sound(v));
1807 case TERM_XTRA_BORED:
1809 return (term_xtra_win_event(0));
1811 case TERM_XTRA_EVENT:
1813 return (term_xtra_win_event(v));
1815 case TERM_XTRA_FLUSH:
1817 return (term_xtra_win_flush());
1819 case TERM_XTRA_CLEAR:
1821 return (term_xtra_win_clear());
1823 case TERM_XTRA_REACT:
1825 return (term_xtra_win_react(p_ptr));
1827 case TERM_XTRA_DELAY:
1829 return (term_xtra_win_delay(v));
1838 * Low level graphics (Assumes valid input).
1840 * Draw a "cursor" at (x,y), using a "yellow box".
1842 static errr term_curs_win(int x, int y)
1844 term_data *td = (term_data*)(Term->data);
1845 int tile_wid, tile_hgt;
1848 tile_wid = td->map_tile_wid;
1849 tile_hgt = td->map_tile_hgt;
1853 tile_wid = td->tile_wid;
1854 tile_hgt = td->tile_hgt;
1858 rc.left = x * tile_wid + td->size_ow1;
1859 rc.right = rc.left + tile_wid;
1860 rc.top = y * tile_hgt + td->size_oh1;
1861 rc.bottom = rc.top + tile_hgt;
1863 HDC hdc = GetDC(td->w);
1864 FrameRect(hdc, &rc, hbrYellow);
1865 ReleaseDC(td->w, hdc);
1871 * Low level graphics (Assumes valid input).
1873 * Draw a "big cursor" at (x,y), using a "yellow box".
1875 static errr term_bigcurs_win(int x, int y)
1877 term_data *td = (term_data*)(Term->data);
1878 int tile_wid, tile_hgt;
1881 term_curs_win(x, y);
1886 tile_wid = td->tile_wid;
1887 tile_hgt = td->tile_hgt;
1891 rc.left = x * tile_wid + td->size_ow1;
1892 rc.right = rc.left + 2 * tile_wid;
1893 rc.top = y * tile_hgt + td->size_oh1;
1894 rc.bottom = rc.top + tile_hgt;
1896 HDC hdc = GetDC(td->w);
1897 FrameRect(hdc, &rc, hbrYellow);
1898 ReleaseDC(td->w, hdc);
1904 * Low level graphics (Assumes valid input).
1906 * Erase a "block" of "n" characters starting at (x,y).
1908 static errr term_wipe_win(int x, int y, int n)
1910 term_data *td = (term_data*)(Term->data);
1912 rc.left = x * td->tile_wid + td->size_ow1;
1913 rc.right = rc.left + n * td->tile_wid;
1914 rc.top = y * td->tile_hgt + td->size_oh1;
1915 rc.bottom = rc.top + td->tile_hgt;
1917 HDC hdc = GetDC(td->w);
1918 SetBkColor(hdc, RGB(0, 0, 0));
1919 SelectObject(hdc, td->font_id);
1923 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1925 ReleaseDC(td->w, hdc);
1931 * Low level graphics. Assumes valid input.
1933 * Draw several ("n") chars, with an attr, at a given location.
1935 * All "graphic" data is handled by "term_pict_win()", below.
1937 * One would think there is a more efficient method for telling a window
1938 * what color it should be using to draw with, but perhaps simply changing
1939 * it every time is not too inefficient.
1941 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
1943 term_data *td = (term_data*)(Term->data);
1944 static HBITMAP WALL;
1945 static HBRUSH myBrush, oldBrush;
1947 static bool init_done = FALSE;
1950 WALL = LoadBitmap(hInstance, AppName);
1951 myBrush = CreatePatternBrush(WALL);
1956 rc.left = x * td->tile_wid + td->size_ow1;
1957 rc.right = rc.left + n * td->tile_wid;
1958 rc.top = y * td->tile_hgt + td->size_oh1;
1959 rc.bottom = rc.top + td->tile_hgt;
1961 HDC hdc = GetDC(td->w);
1962 SetBkColor(hdc, RGB(0, 0, 0));
1965 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
1969 SetTextColor(hdc, win_clr[a & 0x0F]);
1973 SetTextColor(hdc, win_clr[a]);
1976 SelectObject(hdc, td->font_id);
1977 if (use_bg) SetBkMode(hdc, TRANSPARENT);
1980 (td->tile_hgt != td->font_hgt) ||
1981 (td->tile_wid != td->font_wid))
1983 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1984 if (use_bg) DrawBG(hdc, &rc);
1986 rc.left += ((td->tile_wid - td->font_wid) / 2);
1987 rc.right = rc.left + td->font_wid;
1988 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
1989 rc.bottom = rc.top + td->font_hgt;
1991 for (int i = 0; i < n; i++)
1994 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1])
1996 rc.right += td->font_wid;
1997 oldBrush = SelectObject(hdc, myBrush);
1998 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1999 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2000 SelectObject(hdc, oldBrush);
2001 SelectObject(hdc, oldPen);
2002 rc.right -= td->font_wid;
2004 rc.left += 2 * td->tile_wid;
2005 rc.right += 2 * td->tile_wid;
2007 else if (iskanji(*(s + i))) /* 2バイト文字 */
2009 rc.right += td->font_wid;
2010 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
2012 rc.right -= td->font_wid;
2014 rc.left += 2 * td->tile_wid;
2015 rc.right += 2 * td->tile_wid;
2017 else if (*(s + i) == 127) {
2018 oldBrush = SelectObject(hdc, myBrush);
2019 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
2020 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2021 SelectObject(hdc, oldBrush);
2022 SelectObject(hdc, oldPen);
2023 rc.left += td->tile_wid;
2024 rc.right += td->tile_wid;
2028 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
2029 rc.left += td->tile_wid;
2030 rc.right += td->tile_wid;
2033 if (*(s + i) == 127)
2035 oldBrush = SelectObject(hdc, myBrush);
2036 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
2037 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2038 SelectObject(hdc, oldBrush);
2039 SelectObject(hdc, oldPen);
2040 rc.left += td->tile_wid;
2041 rc.right += td->tile_wid;
2045 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
2046 rc.left += td->tile_wid;
2047 rc.right += td->tile_wid;
2054 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc, s, n, NULL);
2057 ReleaseDC(td->w, hdc);
2063 * Low level graphics. Assumes valid input.
2065 * Draw an array of "special" attr/char pairs at the given location.
2067 * We use the "term_pict_win()" function for "graphic" data, which are
2068 * encoded by setting the "high-bits" of both the "attr" and the "char"
2069 * data. We use the "attr" to represent the "row" of the main bitmap,
2070 * and the "char" to represent the "col" of the main bitmap. The use
2071 * of this function is induced by the "higher_pict" flag.
2073 * If "graphics" is not available, we simply "wipe" the given grids.
2075 static errr term_pict_win(TERM_LEN x, TERM_LEN y, int n, const TERM_COLOR *ap, concptr cp, const TERM_COLOR *tap, concptr tcp)
2077 term_data *td = (term_data*)(Term->data);
2082 return (term_wipe_win(x, y, n));
2085 TERM_LEN w1 = infGraph.CellWidth;
2086 TERM_LEN h1 = infGraph.CellHeight;
2087 TERM_LEN tw1 = infGraph.TileWidth;
2088 TERM_LEN th1 = infGraph.TileHeight;
2089 TERM_LEN w2, h2, tw2 = 0;
2092 w2 = td->map_tile_wid;
2093 h2 = td->map_tile_hgt;
2100 if (use_bigtile) tw2 *= 2;
2103 TERM_LEN x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
2104 TERM_LEN y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
2105 HDC hdc = GetDC(td->w);
2106 HDC hdcSrc = CreateCompatibleDC(hdc);
2107 HBITMAP hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2109 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2111 hdcMask = CreateCompatibleDC(hdc);
2112 SelectObject(hdcMask, infMask.hBitmap);
2115 for (i = 0; i < n; i++, x2 += w2)
2117 TERM_COLOR a = ap[i];
2119 int row = (a & 0x7F);
2120 int col = (c & 0x7F);
2121 TERM_LEN x1 = col * w1;
2122 TERM_LEN y1 = row * h1;
2124 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2126 TERM_LEN x3 = (tcp[i] & 0x7F) * w1;
2127 TERM_LEN y3 = (tap[i] & 0x7F) * h1;
2128 tw2 = tw2 * w1 / tw1;
2130 if ((tw1 == tw2) && (th1 == h2))
2132 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2133 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2134 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2138 SetStretchBltMode(hdc, COLORONCOLOR);
2139 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
2140 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
2141 if ((x1 != x3) || (y1 != y3))
2143 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2144 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2150 if ((w1 == tw2) && (h1 == h2))
2152 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2156 SetStretchBltMode(hdc, COLORONCOLOR);
2157 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2160 SelectObject(hdcSrc, hbmSrcOld);
2162 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2164 SelectObject(hdcMask, hbmSrcOld);
2168 ReleaseDC(td->w, hdc);
2173 static void windows_map(player_type *player_ptr)
2175 term_data *td = &data[0];
2177 if (!use_graphics) return;
2179 term_xtra_win_clear();
2180 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2181 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2182 td->map_active = TRUE;
2186 TERM_LEN max_x = player_ptr->current_floor_ptr->width;
2187 TERM_LEN max_y = player_ptr->current_floor_ptr->height;
2190 for (TERM_LEN x = min_x; x < max_x; x++)
2192 for (TERM_LEN y = min_y; y < max_y; y++)
2196 map_info(player_ptr, y, x, &a, (char*)&c, &ta, (char*)&tc);
2197 if ((a & 0x80) && (c & 0x80))
2199 term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2204 term_curs_win(player_ptr->x - min_x, player_ptr->y - min_y);
2205 Term_inkey(&c, TRUE, TRUE);
2207 td->map_active = FALSE;
2208 term_xtra_win_clear();
2214 * Create and initialize a "term_data" given a title
2216 static void term_data_link(term_data *td)
2219 term_init(t, td->cols, td->rows, td->keys);
2220 t->soft_cursor = TRUE;
2221 t->higher_pict = TRUE;
2222 t->attr_blank = TERM_WHITE;
2223 t->char_blank = ' ';
2224 t->user_hook = term_user_win;
2225 t->xtra_hook = term_xtra_win;
2226 t->curs_hook = term_curs_win;
2227 t->bigcurs_hook = term_bigcurs_win;
2228 t->wipe_hook = term_wipe_win;
2229 t->text_hook = term_text_win;
2230 t->pict_hook = term_pict_win;
2231 t->data = (vptr)(td);
2236 * Create the windows
2238 * First, instantiate the "default" values, then read the "ini_file"
2239 * to over-ride selected values, then create the windows, and fonts.
2241 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2242 * must make active to realize the palette.
2244 static void init_windows(void)
2248 WIPE(td, term_data);
2252 td->s = angband_term_name[0];
2268 for (int i = 1; i < MAX_TERM_DATA; i++)
2271 WIPE(td, term_data);
2272 td->s = angband_term_name[i];
2276 td->visible = FALSE;
2281 td->pos_x = (7 - i) * 30;
2282 td->pos_y = (7 - i) * 20;
2289 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2290 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2295 for (int i = 1; i < MAX_TERM_DATA; i++)
2298 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2299 td->dwExStyle = (WS_EX_TOOLWINDOW);
2302 for (int i = 0; i < MAX_TERM_DATA; i++)
2305 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2306 td->lf.lfCharSet = DEFAULT_CHARSET;
2307 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2308 term_force_font(td, NULL);
2309 if (!td->tile_wid) td->tile_wid = td->font_wid;
2310 if (!td->tile_hgt) td->tile_hgt = td->font_hgt;
2313 term_window_resize(td);
2316 for (int i = MAX_TERM_DATA - 1; i >= 1; --i)
2321 td->w = CreateWindowEx(td->dwExStyle, AngList,
2323 td->pos_x, td->pos_y,
2324 td->size_wid, td->size_hgt,
2325 HWND_DESKTOP, NULL, hInstance, NULL);
2327 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
2331 td->size_hack = TRUE;
2332 ShowWindow(td->w, SW_SHOW);
2333 td->size_hack = FALSE;
2337 angband_term[i] = &td->t;
2341 /* Activate the window */
2342 SetActiveWindow(td->w);
2347 term_window_pos(&data[i], HWND_TOPMOST);
2351 term_window_pos(&data[i], td->w);
2357 td->w = CreateWindowEx(td->dwExStyle, AppName,
2359 td->pos_x, td->pos_y,
2360 td->size_wid, td->size_hgt,
2361 HWND_DESKTOP, NULL, hInstance, NULL);
2363 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
2366 angband_term[0] = &td->t;
2367 normsize.x = td->cols;
2368 normsize.y = td->rows;
2370 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
2371 else ShowWindow(td->w, SW_SHOW);
2373 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2374 (void)new_palette();
2375 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
2376 (void)term_xtra_win_flush();
2383 static void setup_menus(void)
2385 HMENU hm = GetMenu(data[0].w);
2386 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2387 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2388 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2389 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2390 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2392 if (!current_world_ptr->character_generated)
2394 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
2395 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
2398 if (current_world_ptr->character_generated)
2400 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_ENABLED);
2403 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_ENABLED);
2404 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_ENABLED);
2406 for (int i = 0; i < MAX_TERM_DATA; i++)
2408 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2409 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i, (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
2410 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_ENABLED);
2413 for (int i = 0; i < MAX_TERM_DATA; i++)
2415 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2417 if (data[i].visible)
2419 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2423 for (int i = 0; i < MAX_TERM_DATA; i++)
2425 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2426 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i, (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
2427 if (data[i].visible)
2429 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_ENABLED);
2433 for (int i = 0; i < MAX_TERM_DATA; i++)
2435 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2436 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i, (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
2437 if (data[i].visible)
2439 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_ENABLED);
2444 for (int i = 0; i < MAX_TERM_DATA; i++)
2446 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2447 if (data[i].visible)
2449 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
2453 for (int i = 0; i < MAX_TERM_DATA; i++)
2455 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2456 if (data[i].visible)
2458 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
2462 for (int i = 0; i < MAX_TERM_DATA; i++)
2464 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2465 if (data[i].visible)
2467 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2471 for (int i = 0; i < MAX_TERM_DATA; i++)
2473 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2475 if (data[i].visible)
2477 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2481 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2482 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2483 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2484 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2485 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2488 EnableMenuItem(hm, IDM_OPTIONS_SAVER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2491 if (use_graphics != GRAPHICS_NONE)
2492 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
2494 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2496 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
2497 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
2498 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
2499 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
2500 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
2501 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
2502 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
2503 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
2504 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
2505 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
2506 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
2507 (arg_music ? MF_CHECKED : MF_UNCHECKED));
2508 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
2509 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
2510 CheckMenuItem(hm, IDM_OPTIONS_BG,
2511 (use_bg ? MF_CHECKED : MF_UNCHECKED));
2514 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
2515 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
2517 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
2518 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
2519 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
2520 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
2521 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
2522 EnableMenuItem(hm, IDM_OPTIONS_SAVER, MF_BYCOMMAND | MF_ENABLED);
2527 * Check for double clicked (or dragged) savefile
2529 * Apparently, Windows copies the entire filename into the first
2530 * piece of the "command line string". Perhaps we should extract
2531 * the "basename" of that filename and append it to the "save" dir.
2533 static void check_for_save_file(player_type *player_ptr, LPSTR cmd_line)
2539 strcat(savefile, s);
2540 validate_file(savefile);
2541 game_in_progress = TRUE;
2542 play_game(player_ptr, FALSE);
2547 * Process a menu command
2549 static void process_menus(player_type *player_ptr, WORD wCmd)
2559 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2561 else if (game_in_progress)
2563 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
2567 game_in_progress = TRUE;
2569 play_game(player_ptr, TRUE);
2579 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2581 else if (game_in_progress)
2583 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
2587 memset(&ofn, 0, sizeof(ofn));
2588 ofn.lStructSize = sizeof(ofn);
2589 ofn.hwndOwner = data[0].w;
2590 ofn.lpstrFilter = "Save Files (*.)\0*\0";
2591 ofn.nFilterIndex = 1;
2592 ofn.lpstrFile = savefile;
2593 ofn.nMaxFile = 1024;
2594 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
2595 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
2597 if (GetOpenFileName(&ofn))
2599 validate_file(savefile);
2600 game_in_progress = TRUE;
2602 play_game(player_ptr, FALSE);
2611 if (game_in_progress && current_world_ptr->character_generated)
2615 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
2620 do_cmd_save_game(player_ptr, FALSE);
2624 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
2631 if (game_in_progress && current_world_ptr->character_generated)
2635 plog(_("今は終了できません。", "You may not do that right now."));
2640 forget_lite(player_ptr->current_floor_ptr);
2641 forget_view(player_ptr->current_floor_ptr);
2642 clear_mon_lite(player_ptr->current_floor_ptr);
2644 Term_key_push(SPECIAL_KEY_QUIT);
2651 case IDM_FILE_SCORE:
2654 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
2655 highscore_fd = fd_open(buf, O_RDONLY);
2656 if (highscore_fd < 0)
2658 msg_print("Score file unavailable.");
2664 display_scores_aux(0, MAX_HISCORES, -1, NULL);
2665 (void)fd_close(highscore_fd);
2673 case IDM_FILE_MOVIE:
2677 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2679 else if (game_in_progress)
2681 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
2685 memset(&ofn, 0, sizeof(ofn));
2686 ofn.lStructSize = sizeof(ofn);
2687 ofn.hwndOwner = data[0].w;
2688 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
2689 ofn.nFilterIndex = 1;
2690 ofn.lpstrFile = savefile;
2691 ofn.nMaxFile = 1024;
2692 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
2693 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2695 if (GetOpenFileName(&ofn))
2697 prepare_browse_movie_aux(savefile);
2698 play_game(player_ptr, FALSE);
2706 case IDM_WINDOW_VIS_0:
2708 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
2711 case IDM_WINDOW_VIS_1:
2712 case IDM_WINDOW_VIS_2:
2713 case IDM_WINDOW_VIS_3:
2714 case IDM_WINDOW_VIS_4:
2715 case IDM_WINDOW_VIS_5:
2716 case IDM_WINDOW_VIS_6:
2717 case IDM_WINDOW_VIS_7:
2719 int i = wCmd - IDM_WINDOW_VIS_0;
2720 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2726 ShowWindow(td->w, SW_SHOW);
2727 term_data_redraw(player_ptr, td);
2731 td->visible = FALSE;
2733 ShowWindow(td->w, SW_HIDE);
2738 case IDM_WINDOW_FONT_0:
2739 case IDM_WINDOW_FONT_1:
2740 case IDM_WINDOW_FONT_2:
2741 case IDM_WINDOW_FONT_3:
2742 case IDM_WINDOW_FONT_4:
2743 case IDM_WINDOW_FONT_5:
2744 case IDM_WINDOW_FONT_6:
2745 case IDM_WINDOW_FONT_7:
2747 int i = wCmd - IDM_WINDOW_FONT_0;
2748 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2751 term_change_font(td);
2754 case IDM_WINDOW_POS_1:
2755 case IDM_WINDOW_POS_2:
2756 case IDM_WINDOW_POS_3:
2757 case IDM_WINDOW_POS_4:
2758 case IDM_WINDOW_POS_5:
2759 case IDM_WINDOW_POS_6:
2760 case IDM_WINDOW_POS_7:
2762 int i = wCmd - IDM_WINDOW_POS_0;
2763 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2766 if (!td->posfix && td->visible)
2769 term_window_pos(td, HWND_TOPMOST);
2774 term_window_pos(td, data[0].w);
2779 case IDM_WINDOW_BIZ_0:
2780 case IDM_WINDOW_BIZ_1:
2781 case IDM_WINDOW_BIZ_2:
2782 case IDM_WINDOW_BIZ_3:
2783 case IDM_WINDOW_BIZ_4:
2784 case IDM_WINDOW_BIZ_5:
2785 case IDM_WINDOW_BIZ_6:
2786 case IDM_WINDOW_BIZ_7:
2788 int i = wCmd - IDM_WINDOW_BIZ_0;
2789 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2792 td->bizarre = !td->bizarre;
2794 term_window_resize(td);
2797 case IDM_WINDOW_I_WID_0:
2798 case IDM_WINDOW_I_WID_1:
2799 case IDM_WINDOW_I_WID_2:
2800 case IDM_WINDOW_I_WID_3:
2801 case IDM_WINDOW_I_WID_4:
2802 case IDM_WINDOW_I_WID_5:
2803 case IDM_WINDOW_I_WID_6:
2804 case IDM_WINDOW_I_WID_7:
2806 int i = wCmd - IDM_WINDOW_I_WID_0;
2807 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2812 term_window_resize(td);
2815 case IDM_WINDOW_D_WID_0:
2816 case IDM_WINDOW_D_WID_1:
2817 case IDM_WINDOW_D_WID_2:
2818 case IDM_WINDOW_D_WID_3:
2819 case IDM_WINDOW_D_WID_4:
2820 case IDM_WINDOW_D_WID_5:
2821 case IDM_WINDOW_D_WID_6:
2822 case IDM_WINDOW_D_WID_7:
2824 int i = wCmd - IDM_WINDOW_D_WID_0;
2825 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2830 term_window_resize(td);
2833 case IDM_WINDOW_I_HGT_0:
2834 case IDM_WINDOW_I_HGT_1:
2835 case IDM_WINDOW_I_HGT_2:
2836 case IDM_WINDOW_I_HGT_3:
2837 case IDM_WINDOW_I_HGT_4:
2838 case IDM_WINDOW_I_HGT_5:
2839 case IDM_WINDOW_I_HGT_6:
2840 case IDM_WINDOW_I_HGT_7:
2842 int i = wCmd - IDM_WINDOW_I_HGT_0;
2843 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2848 term_window_resize(td);
2851 case IDM_WINDOW_D_HGT_0:
2852 case IDM_WINDOW_D_HGT_1:
2853 case IDM_WINDOW_D_HGT_2:
2854 case IDM_WINDOW_D_HGT_3:
2855 case IDM_WINDOW_D_HGT_4:
2856 case IDM_WINDOW_D_HGT_5:
2857 case IDM_WINDOW_D_HGT_6:
2858 case IDM_WINDOW_D_HGT_7:
2860 int i = wCmd - IDM_WINDOW_D_HGT_0;
2861 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2866 term_window_resize(td);
2869 case IDM_OPTIONS_NO_GRAPHICS:
2873 plog("You may not do that right now.");
2877 if (arg_graphics != GRAPHICS_NONE)
2879 arg_graphics = GRAPHICS_NONE;
2880 term_xtra_win_react(player_ptr);
2881 Term_key_push(KTRL('R'));
2886 case IDM_OPTIONS_OLD_GRAPHICS:
2890 plog("You may not do that right now.");
2894 if (arg_graphics != GRAPHICS_ORIGINAL)
2896 arg_graphics = GRAPHICS_ORIGINAL;
2897 term_xtra_win_react(player_ptr);
2898 Term_key_push(KTRL('R'));
2903 case IDM_OPTIONS_NEW_GRAPHICS:
2907 plog("You may not do that right now.");
2911 if (arg_graphics != GRAPHICS_ADAM_BOLT)
2913 arg_graphics = GRAPHICS_ADAM_BOLT;
2914 term_xtra_win_react(player_ptr);
2915 Term_key_push(KTRL('R'));
2920 case IDM_OPTIONS_NEW2_GRAPHICS:
2924 plog("You may not do that right now.");
2928 if (arg_graphics != GRAPHICS_HENGBAND)
2930 arg_graphics = GRAPHICS_HENGBAND;
2931 term_xtra_win_react(player_ptr);
2932 Term_key_push(KTRL('R'));
2937 case IDM_OPTIONS_BIGTILE:
2942 plog("You may not do that right now.");
2946 arg_bigtile = !arg_bigtile;
2947 Term_activate(&td->t);
2948 Term_resize(td->cols, td->rows);
2949 InvalidateRect(td->w, NULL, TRUE);
2952 case IDM_OPTIONS_MUSIC:
2956 plog("You may not do that right now.");
2960 arg_music = !arg_music;
2961 term_xtra_win_react(player_ptr);
2962 Term_key_push(KTRL('R'));
2965 case IDM_OPTIONS_SOUND:
2969 plog("You may not do that right now.");
2973 arg_sound = !arg_sound;
2974 term_xtra_win_react(player_ptr);
2975 Term_key_push(KTRL('R'));
2978 case IDM_OPTIONS_BG:
2982 plog("You may not do that right now.");
2988 term_xtra_win_react(player_ptr);
2989 Term_key_push(KTRL('R'));
2992 case IDM_OPTIONS_OPEN_BG:
2996 plog("You may not do that right now.");
3000 memset(&ofn, 0, sizeof(ofn));
3001 ofn.lStructSize = sizeof(ofn);
3002 ofn.hwndOwner = data[0].w;
3003 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
3004 ofn.nFilterIndex = 1;
3005 ofn.lpstrFile = bg_bitmap_file;
3006 ofn.nMaxFile = 1023;
3007 ofn.lpstrInitialDir = NULL;
3008 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
3009 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
3011 if (GetOpenFileName(&ofn))
3017 term_xtra_win_react(player_ptr);
3018 Term_key_push(KTRL('R'));
3021 case IDM_DUMP_SCREEN_HTML:
3023 static char buf[1024] = "";
3024 memset(&ofn, 0, sizeof(ofn));
3025 ofn.lStructSize = sizeof(ofn);
3026 ofn.hwndOwner = data[0].w;
3027 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
3028 ofn.nFilterIndex = 1;
3029 ofn.lpstrFile = buf;
3030 ofn.nMaxFile = 1023;
3031 ofn.lpstrDefExt = "html";
3032 ofn.lpstrInitialDir = NULL;
3033 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
3034 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
3036 if (GetSaveFileName(&ofn))
3038 do_cmd_save_screen_html_aux(buf, 0);
3043 case IDM_OPTIONS_SAVER:
3047 DestroyWindow(hwndSaver);
3052 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
3053 "Angband Screensaver",
3054 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
3055 0, 0, GetSystemMetrics(SM_CXSCREEN),
3056 GetSystemMetrics(SM_CYSCREEN),
3057 NULL, NULL, hInstance, NULL);
3061 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
3065 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
3070 case IDM_OPTIONS_MAP:
3072 windows_map(player_ptr);
3076 case IDM_HELP_CONTENTS:
3080 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
3081 if (check_file(tmp))
3083 sprintf(buf, "winhelp.exe %s", tmp);
3084 WinExec(buf, SW_NORMAL);
3088 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
3089 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
3096 static bool process_keydown(WPARAM wParam, LPARAM lParam)
3102 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
3103 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
3104 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
3106 term_no_press = (ma) ? TRUE : FALSE;
3107 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]))
3109 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
3110 bool numpad = FALSE;
3113 if (mc) Term_keypress('C');
3114 if (ms) Term_keypress('S');
3115 if (ma) Term_keypress('A');
3117 int i = LOBYTE(HIWORD(lParam));
3122 term_no_press = TRUE;
3141 term_no_press = TRUE;
3156 if (numpad) Term_keypress('K');
3158 Term_keypress(hexsym[i / 16]);
3159 Term_keypress(hexsym[i % 16]);
3170 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
3172 LRESULT PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3176 td = (term_data *)GetWindowLong(hWnd, 0);
3182 SetWindowLong(hWnd, 0, (LONG)(my_td));
3187 mop.dwCallback = (DWORD)hWnd;
3190 case WM_GETMINMAXINFO:
3195 lpmmi = (MINMAXINFO*)lParam;
3198 rc.left = rc.top = 0;
3199 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
3200 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
3202 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3204 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
3205 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
3211 BeginPaint(hWnd, &ps);
3212 if (td) term_data_redraw(p_ptr, td);
3213 EndPaint(hWnd, &ps);
3214 ValidateRect(hWnd, NULL);
3219 if (wParam == MCI_NOTIFY_SUCCESSFUL)
3221 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
3222 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
3230 if (process_keydown(wParam, lParam))
3236 if (term_no_press) term_no_press = FALSE;
3237 else Term_keypress(wParam);
3240 case WM_LBUTTONDOWN:
3242 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
3243 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
3253 TERM_LEN dx = abs(oldx - mousex) + 1;
3254 TERM_LEN dy = abs(oldy - mousey) + 1;
3255 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
3256 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
3262 int sz = (dx + 3) * dy;
3264 int sz = (dx + 2) * dy;
3266 hGlobal = GlobalAlloc(GHND, sz + 1);
3267 if (hGlobal == NULL) return 0;
3268 lpStr = (LPSTR)GlobalLock(hGlobal);
3270 for (int i = 0; i < dy; i++)
3274 char **scr = data[0].t.scr->c;
3276 C_MAKE(s, (dx + 1), char);
3277 strncpy(s, &scr[oy + i][ox], dx);
3281 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
3284 if (ox + dx < data[0].cols)
3286 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
3289 for (int j = 0; j < dx; j++)
3291 if (s[j] == 127) s[j] = '#';
3295 for (int j = 0; j < dx; j++)
3297 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
3307 GlobalUnlock(hGlobal);
3308 if (OpenClipboard(hWnd) == 0)
3310 GlobalFree(hGlobal);
3315 SetClipboardData(CF_TEXT, hGlobal);
3322 if (!mouse_down) return 0;
3325 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
3326 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
3331 dx = abs(oldx - mousex) + 1;
3332 dy = abs(oldy - mousey) + 1;
3333 ox = (oldx > mousex) ? mousex : oldx;
3334 oy = (oldy > mousey) ? mousey : oldy;
3335 term_inversed_area(hWnd, ox, oy, dx, dy);
3342 dx = abs(cx - mousex) + 1;
3343 dy = abs(cy - mousey) + 1;
3344 ox = (cx > mousex) ? mousex : cx;
3345 oy = (cy > mousey) ? mousey : cy;
3346 term_inversed_area(hWnd, ox, oy, dx, dy);
3359 if (!game_in_progress || !current_world_ptr->character_generated)
3367 plog(_("今は終了できません。", "You may not do that right now."));
3372 forget_lite(p_ptr->current_floor_ptr);
3373 forget_view(p_ptr->current_floor_ptr);
3374 clear_mon_lite(p_ptr->current_floor_ptr);
3375 Term_key_push(SPECIAL_KEY_QUIT);
3378 case WM_QUERYENDSESSION:
3380 if (!game_in_progress || !current_world_ptr->character_generated)
3387 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
3388 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
3390 p_ptr->panic_save = 1;
3391 signals_ignore_tstp();
3392 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
3393 (void)save_player(p_ptr);
3404 process_menus(p_ptr, LOWORD(wParam));
3410 if (!td->w) return 1;
3411 if (td->size_hack) return 1;
3413 // todo 二重のswitch文。後で分割する.
3416 case SIZE_MINIMIZED:
3418 for (int i = 1; i < MAX_TERM_DATA; i++)
3420 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
3425 case SIZE_MAXIMIZED:
3428 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
3429 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
3430 if ((td->cols != cols) || (td->rows != rows))
3434 if (!IsZoomed(td->w) && !IsIconic(td->w))
3436 normsize.x = td->cols;
3437 normsize.y = td->rows;
3440 Term_activate(&td->t);
3441 Term_resize(td->cols, td->rows);
3442 InvalidateRect(td->w, NULL, TRUE);
3445 td->size_hack = TRUE;
3446 for (int i = 1; i < MAX_TERM_DATA; i++)
3448 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
3451 td->size_hack = FALSE;
3459 case WM_PALETTECHANGED:
3461 if ((HWND)wParam == hWnd) return 0;
3463 case WM_QUERYNEWPALETTE:
3465 if (!paletted) return 0;
3467 HDC hdc = GetDC(hWnd);
3468 SelectPalette(hdc, hPal, FALSE);
3469 int i = RealizePalette(hdc);
3470 if (i) InvalidateRect(hWnd, NULL, TRUE);
3472 ReleaseDC(hWnd, hdc);
3477 if (!wParam || HIWORD(lParam)) break;
3479 for (int i = 1; i < MAX_TERM_DATA; i++)
3481 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
3487 case WM_ACTIVATEAPP:
3489 if (IsIconic(td->w)) break;
3491 for (int i = 1; i < MAX_TERM_DATA; i++)
3493 if (data[i].visible)
3497 ShowWindow(data[i].w, SW_SHOW);
3501 ShowWindow(data[i].w, SW_HIDE);
3508 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3513 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
3515 LRESULT PASCAL AngbandListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3519 td = (term_data *)GetWindowLong(hWnd, 0);
3525 SetWindowLong(hWnd, 0, (LONG)(my_td));
3532 case WM_GETMINMAXINFO:
3537 lpmmi = (MINMAXINFO*)lParam;
3540 rc.left = rc.top = 0;
3541 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
3542 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
3544 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3545 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
3546 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
3552 if (!td->w) return 1;
3553 if (td->size_hack) return 1;
3555 td->size_hack = TRUE;
3557 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
3558 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
3559 if ((td->cols != cols) || (td->rows != rows))
3561 term *old_term = Term;
3564 Term_activate(&td->t);
3565 Term_resize(td->cols, td->rows);
3566 Term_activate(old_term);
3567 InvalidateRect(td->w, NULL, TRUE);
3568 p_ptr->window = 0xFFFFFFFF;
3569 handle_stuff(p_ptr);
3572 td->size_hack = FALSE;
3577 BeginPaint(hWnd, &ps);
3578 if (td) term_data_redraw(p_ptr, td);
3579 EndPaint(hWnd, &ps);
3585 if (process_keydown(wParam, lParam))
3592 if (term_no_press) term_no_press = FALSE;
3593 else Term_keypress(wParam);
3596 case WM_PALETTECHANGED:
3598 if ((HWND)wParam == hWnd) return FALSE;
3600 case WM_QUERYNEWPALETTE:
3602 if (!paletted) return 0;
3604 HDC hdc = GetDC(hWnd);
3605 SelectPalette(hdc, hPal, FALSE);
3606 int i = RealizePalette(hdc);
3607 if (i) InvalidateRect(hWnd, NULL, TRUE);
3609 ReleaseDC(hWnd, hdc);
3612 case WM_NCLBUTTONDOWN:
3615 if (wParam == HTCLOSE) wParam = HTSYSMENU;
3616 #endif /* HTCLOSE */
3618 if (wParam == HTSYSMENU)
3622 td->visible = FALSE;
3623 ShowWindow(td->w, SW_HIDE);
3633 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3637 LRESULT PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3639 static int iMouse = 0;
3640 static WORD xMouse = 0;
3641 static WORD yMouse = 0;
3656 case WM_LBUTTONDOWN:
3657 case WM_MBUTTONDOWN:
3658 case WM_RBUTTONDOWN:
3661 SendMessage(hWnd, WM_CLOSE, 0, 0);
3668 int dx = LOWORD(lParam) - xMouse;
3669 int dy = HIWORD(lParam) - yMouse;
3671 if (dx < 0) dx = -dx;
3672 if (dy < 0) dy = -dy;
3674 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
3676 SendMessage(hWnd, WM_CLOSE, 0, 0);
3681 xMouse = LOWORD(lParam);
3682 yMouse = HIWORD(lParam);
3688 DestroyWindow(hwndSaver);
3694 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3699 * Display warning message (see "z-util.c")
3701 static void hack_plog(concptr str)
3706 MessageBox(NULL, str, "警告!",
3707 MB_ICONEXCLAMATION | MB_OK);
3709 MessageBox(NULL, str, "Warning",
3710 MB_ICONEXCLAMATION | MB_OK);
3718 * Display error message and quit (see "z-util.c")
3720 static void hack_quit(concptr str)
3725 MessageBox(NULL, str, "エラー!",
3726 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3728 MessageBox(NULL, str, "Error",
3729 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3734 UnregisterClass(AppName, hInstance);
3735 if (hIcon) DestroyIcon(hIcon);
3742 * Display warning message (see "z-util.c")
3744 static void hook_plog(concptr str)
3749 MessageBox(data[0].w, str, "警告!",
3750 MB_ICONEXCLAMATION | MB_OK);
3752 MessageBox(data[0].w, str, "Warning",
3753 MB_ICONEXCLAMATION | MB_OK);
3761 * Display error message and quit (see "z-util.c")
3763 static void hook_quit(concptr str)
3768 MessageBox(data[0].w, str, "エラー!",
3769 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3771 MessageBox(data[0].w, str, "Error",
3772 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3777 for (int i = MAX_TERM_DATA - 1; i >= 0; --i)
3779 term_force_font(&data[i], NULL);
3780 if (data[i].font_want) string_free(data[i].font_want);
3781 if (data[i].w) DestroyWindow(data[i].w);
3785 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
3786 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
3787 if (infMask.hPalette) DeleteObject(infMask.hPalette);
3788 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
3790 DeleteObject(hbrYellow);
3793 if (hPal) DeleteObject(hPal);
3795 UnregisterClass(AppName, hInstance);
3796 if (hIcon) DestroyIcon(hIcon);
3805 static void init_stuff(void)
3808 GetModuleFileName(hInstance, path, 512);
3810 strcpy(path + strlen(path) - 4, ".INI");
3811 ini_file = string_make(path);
3812 int i = strlen(path);
3816 if (path[i] == '\\')
3822 strcpy(path + i + 1, "lib\\");
3823 validate_dir(path, TRUE);
3824 init_file_paths(path);
3825 validate_dir(ANGBAND_DIR_APEX, FALSE);
3826 validate_dir(ANGBAND_DIR_BONE, FALSE);
3827 if (!check_dir(ANGBAND_DIR_EDIT))
3829 validate_dir(ANGBAND_DIR_DATA, TRUE);
3833 validate_dir(ANGBAND_DIR_DATA, FALSE);
3836 validate_dir(ANGBAND_DIR_FILE, TRUE);
3837 validate_dir(ANGBAND_DIR_HELP, FALSE);
3838 validate_dir(ANGBAND_DIR_INFO, FALSE);
3839 validate_dir(ANGBAND_DIR_PREF, TRUE);
3840 validate_dir(ANGBAND_DIR_SAVE, FALSE);
3841 validate_dir(ANGBAND_DIR_USER, TRUE);
3842 validate_dir(ANGBAND_DIR_XTRA, TRUE);
3843 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
3845 validate_file(path);
3846 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
3847 ANGBAND_DIR_XTRA_GRAF = string_make(path);
3848 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
3850 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
3851 ANGBAND_DIR_XTRA_SOUND = string_make(path);
3852 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
3854 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
3855 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
3856 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
3858 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
3859 ANGBAND_DIR_XTRA_HELP = string_make(path);
3864 * todo よく見るとhMutexはちゃんと使われていない……?
3865 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
3867 static bool is_already_running(void)
3870 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
3871 if (GetLastError() == ERROR_ALREADY_EXISTS)
3881 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
3883 int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
3889 setlocale(LC_ALL, "ja_JP");
3892 if (is_already_running())
3895 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
3897 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3901 if (hPrevInst == NULL)
3903 wc.style = CS_CLASSDC;
3904 wc.lpfnWndProc = AngbandWndProc;
3907 wc.hInstance = hInst;
3908 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
3909 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
3910 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
3911 wc.lpszMenuName = AppName;
3912 wc.lpszClassName = AppName;
3914 if (!RegisterClass(&wc)) exit(1);
3916 wc.lpfnWndProc = AngbandListProc;
3917 wc.lpszMenuName = NULL;
3918 wc.lpszClassName = AngList;
3920 if (!RegisterClass(&wc)) exit(2);
3922 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
3923 wc.lpfnWndProc = AngbandSaverProc;
3925 wc.lpszMenuName = NULL;
3926 wc.lpszClassName = "WindowsScreenSaverClass";
3928 if (!RegisterClass(&wc)) exit(3);
3931 plog_aux = hack_plog;
3932 quit_aux = hack_quit;
3933 core_aux = hack_quit;
3936 for (int i = 0; special_key_list[i]; ++i)
3938 special_key[special_key_list[i]] = TRUE;
3941 for (int i = 0; ignore_key_list[i]; ++i)
3943 ignore_key[ignore_key_list[i]] = TRUE;
3947 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
3948 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
3949 ReleaseDC(NULL, hdc);
3951 for (int i = 0; i < 256; i++)
3953 byte rv = angband_color_table[i][1];
3954 byte gv = angband_color_table[i][2];
3955 byte bv = angband_color_table[i][3];
3956 win_clr[i] = PALETTERGB(rv, gv, bv);
3957 angband_color_table[i][0] = win_pal[i];
3963 plog_aux = hook_plog;
3964 quit_aux = hook_quit;
3965 core_aux = hook_quit;
3967 ANGBAND_SYS = "win";
3968 if (7 != GetKeyboardType(0))
3969 ANGBAND_KEYBOARD = "0";
3972 switch (GetKeyboardType(1))
3974 case 0x0D01: case 0x0D02:
3975 case 0x0D03: case 0x0D04:
3976 case 0x0D05: case 0x0D06:
3978 ANGBAND_KEYBOARD = "NEC98";
3982 ANGBAND_KEYBOARD = "JAPAN";
3987 Term_activate(term_screen);
3988 init_angband(p_ptr);
3991 if (lpCmdLine[0] == '-') {
3992 switch (lpCmdLine[1])
3997 if (!lpCmdLine[2]) break;
3998 chuukei_server = TRUE;
3999 if (connect_chuukei_server(&lpCmdLine[2]) < 0) {
4000 msg_print("connect fail");
4003 msg_print("connect");
4011 if (!lpCmdLine[2]) break;
4012 chuukei_client = TRUE;
4013 connect_chuukei_server(&lpCmdLine[2]);
4014 play_game(player_ptr, FALSE);
4021 if (!lpCmdLine[2]) break;
4022 prepare_browse_movie(&lpCmdLine[2]);
4023 play_game(player_ptr, FALSE);
4032 if (!chuukei_server) check_for_save_file(lpCmdLine);
4034 check_for_save_file(p_ptr, lpCmdLine);
4037 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
4039 while (GetMessage(&msg, NULL, 0, 0))
4041 TranslateMessage(&msg);
4042 DispatchMessage(&msg);
4048 #endif /* WINDOWS */