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).
92 #include "autopick/autopick-pref-processor.h"
93 #include "cmd-io/cmd-process-screen.h"
94 #include "cmd-io/cmd-save.h"
95 #include "core/game-play.h"
96 #include "core/player-processor.h"
97 #include "core/scores.h"
98 #include "core/special-internal-keys.h"
99 #include "core/stuff-handler.h"
100 #include "core/visuals-reseter.h"
101 #include "dungeon/quest.h"
102 #include "floor/floor-events.h"
103 #include "floor/floor.h"
104 #include "game-option/runtime-arguments.h"
105 #include "game-option/special-options.h"
106 #include "io/chuukei.h"
107 #include "io/files-util.h"
109 #include "io/signal-handlers.h"
110 #include "io/write-diary.h"
111 #include "main/init.h"
112 #include "main/music-definitions-table.h"
113 #include "main/sound-definitions-table.h"
114 #include "main/sound-of-music.h"
115 #include "system/angband-version.h"
116 #include "system/angband.h"
117 #include "system/system-variables.h"
118 #include "term/gameterm.h"
119 #include "term/term-color-types.h"
120 #include "util/angband-files.h"
121 #include "util/string-processor.h"
122 #include "view/display-main-window.h"
123 #include "world/world.h"
129 #include "term/z-term.h"
131 #include "dungeon/dungeon.h"
134 * Available graphic modes
136 #define GRAPHICS_NONE 0
137 #define GRAPHICS_ORIGINAL 1
138 #define GRAPHICS_ADAM_BOLT 2
139 #define GRAPHICS_HENGBAND 3
142 * Menu constants -- see "ANGBAND.RC"
144 #define IDM_FILE_NEW 100
145 #define IDM_FILE_OPEN 101
146 #define IDM_FILE_SAVE 110
147 #define IDM_FILE_SCORE 120
148 #define IDM_FILE_MOVIE 121
149 #define IDM_FILE_EXIT 130
151 #define IDM_WINDOW_VIS_0 200
152 #define IDM_WINDOW_VIS_1 201
153 #define IDM_WINDOW_VIS_2 202
154 #define IDM_WINDOW_VIS_3 203
155 #define IDM_WINDOW_VIS_4 204
156 #define IDM_WINDOW_VIS_5 205
157 #define IDM_WINDOW_VIS_6 206
158 #define IDM_WINDOW_VIS_7 207
160 #define IDM_WINDOW_FONT_0 210
161 #define IDM_WINDOW_FONT_1 211
162 #define IDM_WINDOW_FONT_2 212
163 #define IDM_WINDOW_FONT_3 213
164 #define IDM_WINDOW_FONT_4 214
165 #define IDM_WINDOW_FONT_5 215
166 #define IDM_WINDOW_FONT_6 216
167 #define IDM_WINDOW_FONT_7 217
169 #define IDM_WINDOW_POS_0 220
170 #define IDM_WINDOW_POS_1 221
171 #define IDM_WINDOW_POS_2 222
172 #define IDM_WINDOW_POS_3 223
173 #define IDM_WINDOW_POS_4 224
174 #define IDM_WINDOW_POS_5 225
175 #define IDM_WINDOW_POS_6 226
176 #define IDM_WINDOW_POS_7 227
178 #define IDM_WINDOW_BIZ_0 230
179 #define IDM_WINDOW_BIZ_1 231
180 #define IDM_WINDOW_BIZ_2 232
181 #define IDM_WINDOW_BIZ_3 233
182 #define IDM_WINDOW_BIZ_4 234
183 #define IDM_WINDOW_BIZ_5 235
184 #define IDM_WINDOW_BIZ_6 236
185 #define IDM_WINDOW_BIZ_7 237
187 #define IDM_WINDOW_I_WID_0 240
188 #define IDM_WINDOW_I_WID_1 241
189 #define IDM_WINDOW_I_WID_2 242
190 #define IDM_WINDOW_I_WID_3 243
191 #define IDM_WINDOW_I_WID_4 244
192 #define IDM_WINDOW_I_WID_5 245
193 #define IDM_WINDOW_I_WID_6 246
194 #define IDM_WINDOW_I_WID_7 247
196 #define IDM_WINDOW_D_WID_0 250
197 #define IDM_WINDOW_D_WID_1 251
198 #define IDM_WINDOW_D_WID_2 252
199 #define IDM_WINDOW_D_WID_3 253
200 #define IDM_WINDOW_D_WID_4 254
201 #define IDM_WINDOW_D_WID_5 255
202 #define IDM_WINDOW_D_WID_6 256
203 #define IDM_WINDOW_D_WID_7 257
205 #define IDM_WINDOW_I_HGT_0 260
206 #define IDM_WINDOW_I_HGT_1 261
207 #define IDM_WINDOW_I_HGT_2 262
208 #define IDM_WINDOW_I_HGT_3 263
209 #define IDM_WINDOW_I_HGT_4 264
210 #define IDM_WINDOW_I_HGT_5 265
211 #define IDM_WINDOW_I_HGT_6 266
212 #define IDM_WINDOW_I_HGT_7 267
214 #define IDM_WINDOW_D_HGT_0 270
215 #define IDM_WINDOW_D_HGT_1 271
216 #define IDM_WINDOW_D_HGT_2 272
217 #define IDM_WINDOW_D_HGT_3 273
218 #define IDM_WINDOW_D_HGT_4 274
219 #define IDM_WINDOW_D_HGT_5 275
220 #define IDM_WINDOW_D_HGT_6 276
221 #define IDM_WINDOW_D_HGT_7 277
223 #define IDM_OPTIONS_NO_GRAPHICS 400
224 #define IDM_OPTIONS_OLD_GRAPHICS 401
225 #define IDM_OPTIONS_NEW_GRAPHICS 402
226 #define IDM_OPTIONS_NEW2_GRAPHICS 403
227 #define IDM_OPTIONS_BIGTILE 409
228 #define IDM_OPTIONS_SOUND 410
229 #define IDM_OPTIONS_MUSIC 411
230 #define IDM_OPTIONS_SAVER 420
231 #define IDM_OPTIONS_MAP 430
232 #define IDM_OPTIONS_BG 440
233 #define IDM_OPTIONS_OPEN_BG 441
235 #define IDM_DUMP_SCREEN_HTML 450
237 #define IDM_HELP_CONTENTS 901
240 * Exclude parts of WINDOWS.H that are not needed (Win32)
242 #define WIN32_LEAN_AND_MEAN
243 #define NONLS /* All NLS defines and routines */
244 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
245 #define NOMCX /* Modem Configuration Extensions */
248 * Include the "windows" support file
253 * Exclude parts of MMSYSTEM.H that are not needed
255 #define MMNODRV /* Installable driver support */
256 #define MMNOWAVE /* Waveform support */
257 #define MMNOMIDI /* MIDI support */
258 #define MMNOAUX /* Auxiliary audio support */
259 #define MMNOTIMER /* Timer support */
260 #define MMNOJOY /* Joystick support */
261 #define MMNOMCI /* MCI support */
262 #define MMNOMMIO /* Multimedia file I/O support */
264 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
265 #define MOUSE_SENS 40
268 * Include some more files. Note: the Cygnus Cygwin compiler
269 * doesn't use mmsystem.h instead it includes the winmm library
270 * which performs a similar function.
272 #include <mmsystem.h>
276 * Include the support for loading bitmaps
278 #include "term/readdib.h"
280 #define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
283 * Foreground color bits
285 #define VID_BLACK 0x00
286 #define VID_BLUE 0x01
287 #define VID_GREEN 0x02
288 #define VID_CYAN 0x03
290 #define VID_MAGENTA 0x05
291 #define VID_YELLOW 0x06
292 #define VID_WHITE 0x07
297 #define VID_BRIGHT 0x08
301 * @brief ターム情報構造体 / Extra "term" data
304 * pos_x / pos_y は各タームの左上点座標を指す。
307 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
308 * 1ドットずつ調整するステータスを指す。
309 * また、フォントを変更すると都度自動調整される。
312 * Note the use of "font_want" for the names of the font file requested by
313 * the user, and the use of "font_file" for the currently active font file.
315 * The "font_file" is uppercased, and takes the form "8X13.FON", while
316 * "font_want" can be in almost any form as long as it could be construed
317 * as attempting to represent the name of a font.
329 TERM_LEN rows; /* int -> uint */
332 uint pos_x; //!< タームの左上X座標
333 uint pos_y; //!< タームの左上Y座標
348 int font_wid; //!< フォント横幅
349 int font_hgt; //!< フォント縦幅
350 int tile_wid; //!< タイル横幅
351 int tile_hgt; //!< タイル縦幅
362 #define MAX_TERM_DATA 8 //!< Maximum number of windows
364 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
365 static term_data *my_td; //!< Hack -- global "window creation" pointer
366 POINT normsize; //!< Remember normal size of main window when maxmized
369 * was main window maximized on previous playing
371 bool win_maximized = FALSE;
376 bool game_in_progress = FALSE;
379 * note when "open"/"new" become valid
381 bool initialized = FALSE;
384 * screen paletted, i.e. 256 colors
386 bool paletted = FALSE;
389 * 16 colors screen, don't use RGB()
391 bool colors16 = FALSE;
394 * Saved instance handle
396 static HINSTANCE hInstance;
399 * Yellow brush for the cursor
401 static HBRUSH hbrYellow;
411 static HPALETTE hPal;
414 static HBITMAP hBG = NULL;
415 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
416 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
419 * The screen saver window
421 static HWND hwndSaver;
424 * 現在使用中のタイルID(0ならば未使用)
425 * Flag set once "graphics" has been initialized
427 static byte current_graphics_mode = 0;
432 static DIBINIT infGraph;
435 * The global bitmap mask
437 static DIBINIT infMask;
440 * Flag set once "sound" has been initialized
442 static bool can_use_sound = FALSE;
444 #define SAMPLE_SOUND_MAX 16
446 * An array of sound file names
448 static concptr sound_file[SOUND_MAX][SAMPLE_SOUND_MAX];
450 #define SAMPLE_MUSIC_MAX 16
451 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
452 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
453 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
454 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
455 static bool can_use_music = FALSE;
457 static MCI_OPEN_PARMS mop;
458 static char mci_device_type[256];
460 int current_music_type = 0;
461 int current_music_id = 0;
464 * Full path to ANGBAND.INI
466 static concptr ini_file = NULL;
469 * Name of application
471 static concptr AppName = "ANGBAND";
474 * Name of sub-window type
476 static concptr AngList = "AngList";
481 static concptr ANGBAND_DIR_XTRA_GRAF;
482 static concptr ANGBAND_DIR_XTRA_SOUND;
483 static concptr ANGBAND_DIR_XTRA_MUSIC;
484 static concptr ANGBAND_DIR_XTRA_HELP;
485 static concptr ANGBAND_DIR_XTRA_MUSIC;
488 * The "complex" color values
490 static COLORREF win_clr[256];
494 * Flag for macro trigger with dump ASCII
496 static bool term_no_press = FALSE;
501 static bool mouse_down = FALSE;
502 static bool paint_rect = FALSE;
503 static TERM_LEN mousex = 0, mousey = 0;
504 static TERM_LEN oldx, oldy;
507 * @brief The "simple" color values
509 * See "main-ibm.c" for original table information
510 * The entries below are taken from the "color bits" defined above.
511 * Note that many of the choices below suck, but so do crappy monitors.
513 static BYTE win_pal[256] =
515 VID_BLACK, /* Dark */
516 VID_WHITE, /* White */
517 VID_CYAN, /* Slate XXX */
518 VID_RED | VID_BRIGHT, /* Orange XXX */
520 VID_GREEN, /* Green */
522 VID_YELLOW, /* Umber XXX */
523 VID_BLACK | VID_BRIGHT, /* Light Dark */
524 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
525 VID_MAGENTA, /* Violet XXX */
526 VID_YELLOW | VID_BRIGHT, /* Yellow */
527 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
528 VID_GREEN | VID_BRIGHT, /* Light Green */
529 VID_BLUE | VID_BRIGHT, /* Light Blue */
530 VID_YELLOW /* Light Umber XXX */
534 * Hack -- define which keys are "special"
536 static bool special_key[256];
537 static bool ignore_key[256];
540 * Hack -- initialization list for "special_key"
542 static byte special_key_list[] = {
543 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
544 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
545 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
546 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
547 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
548 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
549 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
550 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
551 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
552 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
553 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
554 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
555 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
556 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
557 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
558 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
559 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
564 static byte ignore_key_list[] = {
565 VK_ESCAPE, VK_TAB, VK_SPACE,
566 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
567 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
568 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
573 /* Function prototype */
575 static bool is_already_running(void);
578 static void delete_bg(void)
588 static int init_bg(void)
590 char * bmfile = bg_bitmap_file;
592 if (use_bg == 0) return 0;
594 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
596 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
606 static void DrawBG(HDC hdc, RECT *r)
611 int x = r->left, y = r->top;
615 GetObject(hBG, sizeof(bm), &bm);
616 int swid = bm.bmWidth;
617 int shgt = bm.bmHeight;
619 HDC hdcSrc = CreateCompatibleDC(hdc);
620 HBITMAP hOld = SelectObject(hdcSrc, hBG);
624 int cwid = MIN(swid - sx, r->right - nx);
627 int chgt = MIN(shgt - sy, r->bottom - ny);
628 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
630 } while (ny < r->bottom);
634 } while (nx < r->right);
636 SelectObject(hdcSrc, hOld);
642 * Check for existance of a file
644 static bool check_file(concptr s)
648 DWORD attrib = GetFileAttributes(path);
649 if (attrib == INVALID_FILE_NAME) return FALSE;
650 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return FALSE;
657 * Check for existance of a directory
659 static bool check_dir(concptr s)
663 int i = strlen(path);
664 if (i && (path[i - 1] == '\\')) path[--i] = '\0';
666 DWORD attrib = GetFileAttributes(path);
667 if (attrib == INVALID_FILE_NAME) return FALSE;
668 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return FALSE;
677 static void validate_file(concptr s)
679 if (check_file(s)) return;
681 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
686 * Validate a directory
688 static void validate_dir(concptr s, bool vital)
690 if (check_dir(s)) return;
694 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
698 quit_fmt("Unable to create directory:\n%s", s);
704 * @brief (Windows版固有実装)Get the "size" for a window
706 static void term_getsize(term_data *td)
708 if (td->cols < 1) td->cols = 1;
709 if (td->rows < 1) td->rows = 1;
711 TERM_LEN wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
712 TERM_LEN hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
716 rc.right = rc.left + wid;
718 rc.bottom = rc.top + hgt;
720 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
721 td->size_wid = rc.right - rc.left;
722 td->size_hgt = rc.bottom - rc.top;
725 GetWindowRect(td->w, &rc);
732 * Write the "prefs" for a single term
734 static void save_prefs_aux(int i)
736 term_data *td = &data[i];
737 GAME_TEXT sec_name[128];
742 sprintf(sec_name, "Term-%d", i);
746 strcpy(buf, td->visible ? "1" : "0");
747 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
751 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "MS ゴシック");
753 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "Courier");
756 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
758 wsprintf(buf, "%d", td->lf.lfWidth);
759 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
760 wsprintf(buf, "%d", td->lf.lfHeight);
761 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
762 wsprintf(buf, "%d", td->lf.lfWeight);
763 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
765 strcpy(buf, td->bizarre ? "1" : "0");
766 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
768 wsprintf(buf, "%d", td->tile_wid);
769 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
771 wsprintf(buf, "%d", td->tile_hgt);
772 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
774 WINDOWPLACEMENT lpwndpl;
775 lpwndpl.length = sizeof(WINDOWPLACEMENT);
776 GetWindowPlacement(td->w, &lpwndpl);
778 RECT rc = lpwndpl.rcNormalPosition;
779 if (i == 0) wsprintf(buf, "%d", normsize.x);
780 else wsprintf(buf, "%d", td->cols);
782 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
784 if (i == 0) wsprintf(buf, "%d", normsize.y);
785 else wsprintf(buf, "%d", td->rows);
787 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
790 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
791 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
794 GetWindowRect(td->w, &rc);
795 wsprintf(buf, "%d", rc.left);
796 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
798 wsprintf(buf, "%d", rc.top);
799 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
802 strcpy(buf, td->posfix ? "1" : "0");
803 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
810 * We assume that the windows have all been initialized
812 static void save_prefs(void)
815 sprintf(buf, "%d", arg_graphics);
816 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
818 strcpy(buf, arg_bigtile ? "1" : "0");
819 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
821 strcpy(buf, arg_sound ? "1" : "0");
822 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
824 strcpy(buf, arg_music ? "1" : "0");
825 WritePrivateProfileString("Angband", "Music", buf, ini_file);
827 strcpy(buf, use_bg ? "1" : "0");
828 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
829 WritePrivateProfileString("Angband", "BackGroundBitmap",
830 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
832 for (int i = 0; i < MAX_TERM_DATA; ++i)
840 * Load the "prefs" for a single term
842 static void load_prefs_aux(int i)
844 term_data *td = &data[i];
845 GAME_TEXT sec_name[128];
848 int dispx = GetSystemMetrics(SM_CXVIRTUALSCREEN);
849 int dispy = GetSystemMetrics(SM_CYVIRTUALSCREEN);
853 sprintf(sec_name, "Term-%d", i);
854 sprintf(sec_name, "Term-%d", i);
857 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
861 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
863 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
866 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
868 td->font_want = string_make(tmp);
871 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
872 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
873 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
875 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
876 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
878 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
879 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
880 normsize.x = td->cols; normsize.y = td->rows;
884 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
887 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
888 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
889 td->pos_x = MIN(MAX(0, posx), dispx - 128);
890 td->pos_y = MIN(MAX(0, posy), dispy - 128);
894 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
902 static void load_prefs(void)
904 arg_graphics = (byte)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
905 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
906 use_bigtile = arg_bigtile;
907 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
908 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
909 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
910 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
911 for (int i = 0; i < MAX_TERM_DATA; ++i)
919 * - Taken from files.c.
921 * Extract "tokens" from a buffer
923 * This function uses "whitespace" as delimiters, and treats any amount of
924 * whitespace as a single delimiter. We will never return any empty tokens.
925 * When given an empty buffer, or a buffer containing only "whitespace", we
926 * will return no tokens. We will never extract more than "num" tokens.
928 * By running a token through the "text_to_ascii()" function, you can allow
929 * that token to include (encoded) whitespace, using "\s" to encode spaces.
931 * We save pointers to the tokens in "tokens", and return the number found.
933 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
941 for (; *s && iswspace(*s); ++s) /* loop */;
945 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
957 static void load_sound_prefs(void)
962 char *zz[SAMPLE_SOUND_MAX];
964 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
965 for (int i = 0; i < SOUND_MAX; i++)
967 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
968 int num = tokenize_whitespace(tmp, SAMPLE_SOUND_MAX, zz);
969 for (int j = 0; j < num; j++)
971 /* Access the sound */
972 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
974 /* Save the sound filename, if it exists */
975 if (check_file(wav_path))
976 sound_file[i][j] = string_make(zz[j]);
982 static void load_music_prefs(void)
987 char *zz[SAMPLE_MUSIC_MAX];
990 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
991 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
992 for (int i = 0; i < MUSIC_BASIC_MAX; i++)
994 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
995 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
996 for (int j = 0; j < num; j++)
998 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
999 if (check_file(wav_path))
1000 music_file[i][j] = string_make(zz[j]);
1004 for (int i = 0; i < current_world_ptr->max_d_idx; i++)
1006 sprintf(key, "dungeon%03d", i);
1007 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1008 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1009 for (int j = 0; j < num; j++)
1011 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1012 if (check_file(wav_path))
1013 dungeon_music_file[i][j] = string_make(zz[j]);
1017 for (int i = 0; i < max_q_idx; i++)
1019 sprintf(key, "quest%03d", i);
1020 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1021 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1022 for (int j = 0; j < num; j++)
1024 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1025 if (check_file(wav_path))
1026 quest_music_file[i][j] = string_make(zz[j]);
1030 for (int i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1032 sprintf(key, "town%03d", i);
1033 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1034 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1035 for (int j = 0; j < num; j++)
1037 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1038 if (check_file(wav_path))
1039 town_music_file[i][j] = string_make(zz[j]);
1046 * Create the new global palette based on the bitmap palette
1047 * (if any), and the standard 16 entry palette derived from
1048 * "win_clr[]" which is used for the basic 16 Angband colors.
1050 * This function is never called before all windows are ready.
1052 * This function returns FALSE if the new palette could not be
1053 * prepared, which should normally be a fatal error. XXX XXX
1055 * Note that only some machines actually use a "palette".
1057 static int new_palette(void)
1062 LPLOGPALETTE pLogPal;
1063 LPPALETTEENTRY lppe;
1065 if (!paletted) return TRUE;
1071 HPALETTE hBmPal = infGraph.hPalette;
1074 lppeSize = 256 * sizeof(PALETTEENTRY);
1075 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1076 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1077 if ((nEntries == 0) || (nEntries > 220))
1079 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1080 rnfree(lppe, lppeSize);
1085 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1086 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1087 pLogPal->palVersion = 0x300;
1088 pLogPal->palNumEntries = nEntries + 16;
1089 for (i = 0; i < nEntries; i++)
1091 pLogPal->palPalEntry[i] = lppe[i];
1094 for (i = 0; i < 16; i++)
1097 p = &(pLogPal->palPalEntry[i + nEntries]);
1098 p->peRed = GetRValue(win_clr[i]);
1099 p->peGreen = GetGValue(win_clr[i]);
1100 p->peBlue = GetBValue(win_clr[i]);
1101 p->peFlags = PC_NOCOLLAPSE;
1104 if (lppe) rnfree(lppe, lppeSize);
1106 HPALETTE hNewPal = CreatePalette(pLogPal);
1107 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1109 rnfree(pLogPal, pLogPalSize);
1111 HDC hdc = GetDC(td->w);
1112 SelectPalette(hdc, hNewPal, 0);
1113 i = RealizePalette(hdc);
1114 ReleaseDC(td->w, hdc);
1115 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1117 for (i = 1; i < MAX_TERM_DATA; i++)
1121 SelectPalette(hdc, hNewPal, 0);
1122 ReleaseDC(td->w, hdc);
1125 if (hPal) DeleteObject(hPal);
1133 * @brief グラフィクスを初期化する / Initialize graphics
1136 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1137 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1140 static bool init_graphics(void)
1143 BYTE wid, hgt, twid, thgt, ox, oy;
1146 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1156 ANGBAND_GRAF = "new";
1158 else if (arg_graphics == GRAPHICS_HENGBAND)
1168 ANGBAND_GRAF = "ne2";
1179 ANGBAND_GRAF = "old";
1182 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1183 if (!ReadDIB(data[0].w, buf, &infGraph))
1185 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1189 infGraph.CellWidth = wid;
1190 infGraph.CellHeight = hgt;
1191 infGraph.TileWidth = twid;
1192 infGraph.TileHeight = thgt;
1193 infGraph.OffsetX = ox;
1194 infGraph.OffsetY = oy;
1196 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1198 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1199 if (!ReadDIB(data[0].w, buf, &infMask))
1201 plog_fmt("Cannot read bitmap file '%s'", buf);
1206 if (arg_graphics == GRAPHICS_HENGBAND)
1208 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1209 if (!ReadDIB(data[0].w, buf, &infMask))
1211 plog_fmt("Cannot read bitmap file '%s'", buf);
1218 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1222 current_graphics_mode = arg_graphics;
1223 return (current_graphics_mode);
1230 static void init_music(void)
1235 can_use_music = TRUE;
1240 * Hack -- Stop a music
1242 static void stop_music(void)
1244 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1245 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1252 static void init_sound(void)
1257 can_use_sound = TRUE;
1265 static void term_window_resize(term_data *td)
1269 SetWindowPos(td->w, 0, 0, 0,
1270 td->size_wid, td->size_hgt,
1271 SWP_NOMOVE | SWP_NOZORDER);
1272 InvalidateRect(td->w, NULL, TRUE);
1278 * Force the use of a new "font file" for a term_data.
1279 * This function may be called before the "window" is ready.
1280 * This function returns zero only if everything succeeds.
1281 * Note that the "font name" must be capitalized!!!
1283 static errr term_force_font(term_data *td, concptr path)
1285 if (td->font_id) DeleteObject(td->font_id);
1288 td->font_id = CreateFontIndirect(&(td->lf));
1289 int wid = td->lf.lfWidth;
1290 int hgt = td->lf.lfHeight;
1291 if (!td->font_id) return 1;
1299 hdcDesktop = GetDC(HWND_DESKTOP);
1300 hfOld = SelectObject(hdcDesktop, td->font_id);
1301 GetTextMetrics(hdcDesktop, &tm);
1302 SelectObject(hdcDesktop, hfOld);
1303 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1305 wid = tm.tmAveCharWidth;
1318 * Allow the user to change the font for this window.
1320 static void term_change_font(term_data *td)
1323 memset(&cf, 0, sizeof(cf));
1324 cf.lStructSize = sizeof(cf);
1325 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1326 cf.lpLogFont = &(td->lf);
1328 if (!ChooseFont(&cf)) return;
1330 term_force_font(td, NULL);
1332 td->tile_wid = td->font_wid;
1333 td->tile_hgt = td->font_hgt;
1335 term_window_resize(td);
1340 * Allow the user to lock this window.
1342 static void term_window_pos(term_data *td, HWND hWnd)
1344 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1345 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1348 static void windows_map(player_type *player_ptr);
1351 * Hack -- redraw a term_data
1353 static void term_data_redraw(player_type *player_ptr, term_data *td)
1357 windows_map(player_ptr);
1361 Term_activate(&td->t);
1363 Term_activate(term_screen);
1367 void term_inversed_area(HWND hWnd, int x, int y, int w, int h)
1369 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
1370 int tx = td->size_ow1 + x * td->tile_wid;
1371 int ty = td->size_oh1 + y * td->tile_hgt;
1372 int tw = w * td->tile_wid - 1;
1373 int th = h * td->tile_hgt - 1;
1375 HDC hdc = GetDC(hWnd);
1376 HBRUSH myBrush = CreateSolidBrush(RGB(255, 255, 255));
1377 HBRUSH oldBrush = SelectObject(hdc, myBrush);
1378 HPEN oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1380 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
1382 SelectObject(hdc, oldBrush);
1383 SelectObject(hdc, oldPen);
1388 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
1390 static errr term_user_win(int n)
1398 * React to global changes
1400 static errr term_xtra_win_react(player_type *player_ptr)
1404 for (int i = 0; i < 256; i++)
1406 win_pal[i] = angband_color_table[i][0];
1413 bool change = FALSE;
1414 for (int i = 0; i < 256; i++)
1416 rv = angband_color_table[i][1];
1417 gv = angband_color_table[i][2];
1418 bv = angband_color_table[i][3];
1419 code = PALETTERGB(rv, gv, bv);
1420 if (win_clr[i] != code)
1427 if (change) (void)new_palette();
1430 if (use_sound != arg_sound)
1433 use_sound = arg_sound;
1436 if (use_music != arg_music)
1439 use_music = arg_music;
1440 if (!arg_music) stop_music();
1441 else select_floor_music(player_ptr);
1444 if (use_graphics != arg_graphics)
1446 if (arg_graphics && !init_graphics())
1448 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
1449 arg_graphics = GRAPHICS_NONE;
1452 use_graphics = arg_graphics;
1453 reset_visuals(player_ptr, process_autopick_file_command);
1456 for (int i = 0; i < MAX_TERM_DATA; i++)
1459 term_data *td = &data[i];
1460 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
1462 Term_activate(&td->t);
1463 Term_resize(td->cols, td->rows);
1474 * Process at least one event
1476 static errr term_xtra_win_event(int v)
1481 if (GetMessage(&msg, NULL, 0, 0))
1483 TranslateMessage(&msg);
1484 DispatchMessage(&msg);
1489 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1491 TranslateMessage(&msg);
1492 DispatchMessage(&msg);
1501 * Process all pending events
1503 static errr term_xtra_win_flush(void)
1506 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1508 TranslateMessage(&msg);
1509 DispatchMessage(&msg);
1517 * Hack -- clear the screen
1519 * Make this more efficient
1521 static errr term_xtra_win_clear(void)
1523 term_data *td = (term_data*)(Term->data);
1526 rc.left = td->size_ow1;
1527 rc.right = rc.left + td->cols * td->tile_wid;
1528 rc.top = td->size_oh1;
1529 rc.bottom = rc.top + td->rows * td->tile_hgt;
1531 HDC hdc = GetDC(td->w);
1532 SetBkColor(hdc, RGB(0, 0, 0));
1533 SelectObject(hdc, td->font_id);
1534 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1538 rc.left = 0; rc.top = 0;
1542 ReleaseDC(td->w, hdc);
1548 * Hack -- make a noise
1550 static errr term_xtra_win_noise(void)
1552 MessageBeep(MB_ICONASTERISK);
1558 * Hack -- make a sound
1560 static errr term_xtra_win_sound(int v)
1563 if (!use_sound) return 1;
1564 if ((v < 0) || (v >= SOUND_MAX)) return 1;
1567 for (i = 0; i < SAMPLE_SOUND_MAX; i++)
1569 if (!sound_file[v][i])
1573 if (i == 0) return 1;
1575 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
1576 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
1580 * Hack -- play a music
1582 static errr term_xtra_win_music(int n, int v)
1586 if (n == TERM_XTRA_MUSIC_MUTE)
1588 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1589 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1592 if (!use_music) return 1;
1594 if (n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return 1;
1595 else if (v < 0 || v >= 1000) return(1); /*!< TODO */
1599 case TERM_XTRA_MUSIC_BASIC:
1600 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!music_file[v][i]) break;
1602 case TERM_XTRA_MUSIC_DUNGEON:
1603 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!dungeon_music_file[v][i]) break;
1605 case TERM_XTRA_MUSIC_QUEST:
1606 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!quest_music_file[v][i]) break;
1608 case TERM_XTRA_MUSIC_TOWN:
1609 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!town_music_file[v][i]) break;
1620 case TERM_XTRA_MUSIC_BASIC:
1621 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
1623 case TERM_XTRA_MUSIC_DUNGEON:
1624 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
1626 case TERM_XTRA_MUSIC_QUEST:
1627 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
1629 case TERM_XTRA_MUSIC_TOWN:
1630 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
1634 if (current_music_type == n && current_music_id == v)
1638 current_music_type = n;
1639 current_music_id = v;
1641 mop.lpstrDeviceType = mci_device_type;
1642 mop.lpstrElementName = buf;
1643 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1644 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1645 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
1646 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
1647 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
1653 * Delay for "x" milliseconds
1655 static int term_xtra_win_delay(int v)
1663 * todo z-termに影響があるのでplayer_typeの追加は保留
1664 * Do a "special thing"
1666 static errr term_xtra_win(int n, int v)
1670 case TERM_XTRA_NOISE:
1672 return (term_xtra_win_noise());
1674 case TERM_XTRA_MUSIC_BASIC:
1675 case TERM_XTRA_MUSIC_DUNGEON:
1676 case TERM_XTRA_MUSIC_QUEST:
1677 case TERM_XTRA_MUSIC_TOWN:
1679 return (term_xtra_win_music(n, v));
1681 case TERM_XTRA_SOUND:
1683 return (term_xtra_win_sound(v));
1685 case TERM_XTRA_BORED:
1687 return (term_xtra_win_event(0));
1689 case TERM_XTRA_EVENT:
1691 return (term_xtra_win_event(v));
1693 case TERM_XTRA_FLUSH:
1695 return (term_xtra_win_flush());
1697 case TERM_XTRA_CLEAR:
1699 return (term_xtra_win_clear());
1701 case TERM_XTRA_REACT:
1703 return (term_xtra_win_react(p_ptr));
1705 case TERM_XTRA_DELAY:
1707 return (term_xtra_win_delay(v));
1716 * Low level graphics (Assumes valid input).
1718 * Draw a "cursor" at (x,y), using a "yellow box".
1720 static errr term_curs_win(int x, int y)
1722 term_data *td = (term_data*)(Term->data);
1723 int tile_wid, tile_hgt;
1726 tile_wid = td->map_tile_wid;
1727 tile_hgt = td->map_tile_hgt;
1731 tile_wid = td->tile_wid;
1732 tile_hgt = td->tile_hgt;
1736 rc.left = x * tile_wid + td->size_ow1;
1737 rc.right = rc.left + tile_wid;
1738 rc.top = y * tile_hgt + td->size_oh1;
1739 rc.bottom = rc.top + tile_hgt;
1741 HDC hdc = GetDC(td->w);
1742 FrameRect(hdc, &rc, hbrYellow);
1743 ReleaseDC(td->w, hdc);
1749 * Low level graphics (Assumes valid input).
1751 * Draw a "big cursor" at (x,y), using a "yellow box".
1753 static errr term_bigcurs_win(int x, int y)
1755 term_data *td = (term_data*)(Term->data);
1756 int tile_wid, tile_hgt;
1759 term_curs_win(x, y);
1764 tile_wid = td->tile_wid;
1765 tile_hgt = td->tile_hgt;
1769 rc.left = x * tile_wid + td->size_ow1;
1770 rc.right = rc.left + 2 * tile_wid;
1771 rc.top = y * tile_hgt + td->size_oh1;
1772 rc.bottom = rc.top + tile_hgt;
1774 HDC hdc = GetDC(td->w);
1775 FrameRect(hdc, &rc, hbrYellow);
1776 ReleaseDC(td->w, hdc);
1782 * Low level graphics (Assumes valid input).
1784 * Erase a "block" of "n" characters starting at (x,y).
1786 static errr term_wipe_win(int x, int y, int n)
1788 term_data *td = (term_data*)(Term->data);
1790 rc.left = x * td->tile_wid + td->size_ow1;
1791 rc.right = rc.left + n * td->tile_wid;
1792 rc.top = y * td->tile_hgt + td->size_oh1;
1793 rc.bottom = rc.top + td->tile_hgt;
1795 HDC hdc = GetDC(td->w);
1796 SetBkColor(hdc, RGB(0, 0, 0));
1797 SelectObject(hdc, td->font_id);
1801 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1803 ReleaseDC(td->w, hdc);
1809 * Low level graphics. Assumes valid input.
1811 * Draw several ("n") chars, with an attr, at a given location.
1813 * All "graphic" data is handled by "term_pict_win()", below.
1815 * One would think there is a more efficient method for telling a window
1816 * what color it should be using to draw with, but perhaps simply changing
1817 * it every time is not too inefficient.
1819 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
1821 term_data *td = (term_data*)(Term->data);
1822 static HBITMAP WALL;
1823 static HBRUSH myBrush, oldBrush;
1825 static bool init_done = FALSE;
1828 WALL = LoadBitmap(hInstance, AppName);
1829 myBrush = CreatePatternBrush(WALL);
1834 rc.left = x * td->tile_wid + td->size_ow1;
1835 rc.right = rc.left + n * td->tile_wid;
1836 rc.top = y * td->tile_hgt + td->size_oh1;
1837 rc.bottom = rc.top + td->tile_hgt;
1839 HDC hdc = GetDC(td->w);
1840 SetBkColor(hdc, RGB(0, 0, 0));
1843 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
1847 SetTextColor(hdc, win_clr[a & 0x0F]);
1851 SetTextColor(hdc, win_clr[a]);
1854 SelectObject(hdc, td->font_id);
1855 if (use_bg) SetBkMode(hdc, TRANSPARENT);
1858 (td->tile_hgt != td->font_hgt) ||
1859 (td->tile_wid != td->font_wid))
1861 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1862 if (use_bg) DrawBG(hdc, &rc);
1864 rc.left += ((td->tile_wid - td->font_wid) / 2);
1865 rc.right = rc.left + td->font_wid;
1866 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
1867 rc.bottom = rc.top + td->font_hgt;
1869 for (int i = 0; i < n; i++)
1872 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1])
1874 rc.right += td->font_wid;
1875 oldBrush = SelectObject(hdc, myBrush);
1876 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1877 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1878 SelectObject(hdc, oldBrush);
1879 SelectObject(hdc, oldPen);
1880 rc.right -= td->font_wid;
1882 rc.left += 2 * td->tile_wid;
1883 rc.right += 2 * td->tile_wid;
1885 else if (iskanji(*(s + i))) /* 2バイト文字 */
1887 rc.right += td->font_wid;
1888 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
1890 rc.right -= td->font_wid;
1892 rc.left += 2 * td->tile_wid;
1893 rc.right += 2 * td->tile_wid;
1895 else if (*(s + i) == 127) {
1896 oldBrush = SelectObject(hdc, myBrush);
1897 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1898 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1899 SelectObject(hdc, oldBrush);
1900 SelectObject(hdc, oldPen);
1901 rc.left += td->tile_wid;
1902 rc.right += td->tile_wid;
1906 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1907 rc.left += td->tile_wid;
1908 rc.right += td->tile_wid;
1911 if (*(s + i) == 127)
1913 oldBrush = SelectObject(hdc, myBrush);
1914 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1915 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1916 SelectObject(hdc, oldBrush);
1917 SelectObject(hdc, oldPen);
1918 rc.left += td->tile_wid;
1919 rc.right += td->tile_wid;
1923 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1924 rc.left += td->tile_wid;
1925 rc.right += td->tile_wid;
1932 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc, s, n, NULL);
1935 ReleaseDC(td->w, hdc);
1941 * Low level graphics. Assumes valid input.
1943 * Draw an array of "special" attr/char pairs at the given location.
1945 * We use the "term_pict_win()" function for "graphic" data, which are
1946 * encoded by setting the "high-bits" of both the "attr" and the "char"
1947 * data. We use the "attr" to represent the "row" of the main bitmap,
1948 * and the "char" to represent the "col" of the main bitmap. The use
1949 * of this function is induced by the "higher_pict" flag.
1951 * If "graphics" is not available, we simply "wipe" the given grids.
1953 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)
1955 term_data *td = (term_data*)(Term->data);
1960 return (term_wipe_win(x, y, n));
1963 TERM_LEN w1 = infGraph.CellWidth;
1964 TERM_LEN h1 = infGraph.CellHeight;
1965 TERM_LEN tw1 = infGraph.TileWidth;
1966 TERM_LEN th1 = infGraph.TileHeight;
1967 TERM_LEN w2, h2, tw2 = 0;
1970 w2 = td->map_tile_wid;
1971 h2 = td->map_tile_hgt;
1978 if (use_bigtile) tw2 *= 2;
1981 TERM_LEN x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
1982 TERM_LEN y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
1983 HDC hdc = GetDC(td->w);
1984 HDC hdcSrc = CreateCompatibleDC(hdc);
1985 HBITMAP hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
1987 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
1989 hdcMask = CreateCompatibleDC(hdc);
1990 SelectObject(hdcMask, infMask.hBitmap);
1993 for (i = 0; i < n; i++, x2 += w2)
1995 TERM_COLOR a = ap[i];
1997 int row = (a & 0x7F);
1998 int col = (c & 0x7F);
1999 TERM_LEN x1 = col * w1;
2000 TERM_LEN y1 = row * h1;
2002 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2004 TERM_LEN x3 = (tcp[i] & 0x7F) * w1;
2005 TERM_LEN y3 = (tap[i] & 0x7F) * h1;
2006 tw2 = tw2 * w1 / tw1;
2008 if ((tw1 == tw2) && (th1 == h2))
2010 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2011 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2012 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2016 SetStretchBltMode(hdc, COLORONCOLOR);
2017 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
2018 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
2019 if ((x1 != x3) || (y1 != y3))
2021 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2022 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2028 if ((w1 == tw2) && (h1 == h2))
2030 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2034 SetStretchBltMode(hdc, COLORONCOLOR);
2035 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2038 SelectObject(hdcSrc, hbmSrcOld);
2040 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2042 SelectObject(hdcMask, hbmSrcOld);
2046 ReleaseDC(td->w, hdc);
2051 static void windows_map(player_type *player_ptr)
2053 term_data *td = &data[0];
2055 if (!use_graphics) return;
2057 term_xtra_win_clear();
2058 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2059 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2060 td->map_active = TRUE;
2064 TERM_LEN max_x = player_ptr->current_floor_ptr->width;
2065 TERM_LEN max_y = player_ptr->current_floor_ptr->height;
2068 for (TERM_LEN x = min_x; x < max_x; x++)
2070 for (TERM_LEN y = min_y; y < max_y; y++)
2074 map_info(player_ptr, y, x, &a, (char*)&c, &ta, (char*)&tc);
2075 if ((a & 0x80) && (c & 0x80))
2077 term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2082 term_curs_win(player_ptr->x - min_x, player_ptr->y - min_y);
2083 Term_inkey(&c, TRUE, TRUE);
2085 td->map_active = FALSE;
2086 term_xtra_win_clear();
2092 * Create and initialize a "term_data" given a title
2094 static void term_data_link(term_data *td)
2097 term_init(t, td->cols, td->rows, td->keys);
2098 t->soft_cursor = TRUE;
2099 t->higher_pict = TRUE;
2100 t->attr_blank = TERM_WHITE;
2101 t->char_blank = ' ';
2102 t->user_hook = term_user_win;
2103 t->xtra_hook = term_xtra_win;
2104 t->curs_hook = term_curs_win;
2105 t->bigcurs_hook = term_bigcurs_win;
2106 t->wipe_hook = term_wipe_win;
2107 t->text_hook = term_text_win;
2108 t->pict_hook = term_pict_win;
2109 t->data = (vptr)(td);
2114 * Create the windows
2116 * First, instantiate the "default" values, then read the "ini_file"
2117 * to over-ride selected values, then create the windows, and fonts.
2119 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2120 * must make active to realize the palette.
2122 static void init_windows(void)
2126 WIPE(td, term_data);
2130 td->s = angband_term_name[0];
2146 for (int i = 1; i < MAX_TERM_DATA; i++)
2149 WIPE(td, term_data);
2150 td->s = angband_term_name[i];
2154 td->visible = FALSE;
2159 td->pos_x = (7 - i) * 30;
2160 td->pos_y = (7 - i) * 20;
2167 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2168 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2173 for (int i = 1; i < MAX_TERM_DATA; i++)
2176 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2177 td->dwExStyle = (WS_EX_TOOLWINDOW);
2180 for (int i = 0; i < MAX_TERM_DATA; i++)
2183 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2184 td->lf.lfCharSet = DEFAULT_CHARSET;
2185 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2186 term_force_font(td, NULL);
2187 if (!td->tile_wid) td->tile_wid = td->font_wid;
2188 if (!td->tile_hgt) td->tile_hgt = td->font_hgt;
2191 term_window_resize(td);
2194 for (int i = MAX_TERM_DATA - 1; i >= 1; --i)
2199 td->w = CreateWindowEx(td->dwExStyle, AngList,
2201 td->pos_x, td->pos_y,
2202 td->size_wid, td->size_hgt,
2203 HWND_DESKTOP, NULL, hInstance, NULL);
2205 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
2209 td->size_hack = TRUE;
2210 ShowWindow(td->w, SW_SHOW);
2211 td->size_hack = FALSE;
2215 angband_term[i] = &td->t;
2219 /* Activate the window */
2220 SetActiveWindow(td->w);
2225 term_window_pos(&data[i], HWND_TOPMOST);
2229 term_window_pos(&data[i], td->w);
2235 td->w = CreateWindowEx(td->dwExStyle, AppName,
2237 td->pos_x, td->pos_y,
2238 td->size_wid, td->size_hgt,
2239 HWND_DESKTOP, NULL, hInstance, NULL);
2241 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
2244 angband_term[0] = &td->t;
2245 normsize.x = td->cols;
2246 normsize.y = td->rows;
2248 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
2249 else ShowWindow(td->w, SW_SHOW);
2251 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2252 (void)new_palette();
2253 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
2254 (void)term_xtra_win_flush();
2261 static void setup_menus(void)
2263 HMENU hm = GetMenu(data[0].w);
2264 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2265 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2266 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2267 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2268 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2270 if (!current_world_ptr->character_generated)
2272 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
2273 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
2276 if (current_world_ptr->character_generated)
2278 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_ENABLED);
2281 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_ENABLED);
2282 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_ENABLED);
2284 for (int i = 0; i < MAX_TERM_DATA; i++)
2286 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2287 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i, (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
2288 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_ENABLED);
2291 for (int i = 0; i < MAX_TERM_DATA; i++)
2293 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2295 if (data[i].visible)
2297 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2301 for (int i = 0; i < MAX_TERM_DATA; i++)
2303 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2304 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i, (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
2305 if (data[i].visible)
2307 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_ENABLED);
2311 for (int i = 0; i < MAX_TERM_DATA; i++)
2313 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2314 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i, (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
2315 if (data[i].visible)
2317 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_ENABLED);
2322 for (int i = 0; i < MAX_TERM_DATA; i++)
2324 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2325 if (data[i].visible)
2327 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
2331 for (int i = 0; i < MAX_TERM_DATA; i++)
2333 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2334 if (data[i].visible)
2336 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
2340 for (int i = 0; i < MAX_TERM_DATA; i++)
2342 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2343 if (data[i].visible)
2345 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2349 for (int i = 0; i < MAX_TERM_DATA; i++)
2351 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2353 if (data[i].visible)
2355 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2359 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2360 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2361 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2362 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2363 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2366 EnableMenuItem(hm, IDM_OPTIONS_SAVER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2369 if (use_graphics != GRAPHICS_NONE)
2370 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
2372 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2374 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
2375 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
2376 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
2377 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
2378 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
2379 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
2380 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
2381 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
2382 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
2383 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
2384 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
2385 (arg_music ? MF_CHECKED : MF_UNCHECKED));
2386 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
2387 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
2388 CheckMenuItem(hm, IDM_OPTIONS_BG,
2389 (use_bg ? MF_CHECKED : MF_UNCHECKED));
2392 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
2393 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
2395 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
2396 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
2397 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
2398 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
2399 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
2400 EnableMenuItem(hm, IDM_OPTIONS_SAVER, MF_BYCOMMAND | MF_ENABLED);
2405 * Check for double clicked (or dragged) savefile
2407 * Apparently, Windows copies the entire filename into the first
2408 * piece of the "command line string". Perhaps we should extract
2409 * the "basename" of that filename and append it to the "save" dir.
2411 static void check_for_save_file(player_type *player_ptr, LPSTR cmd_line)
2417 strcat(savefile, s);
2418 validate_file(savefile);
2419 game_in_progress = TRUE;
2420 play_game(player_ptr, FALSE);
2425 * Process a menu command
2427 static void process_menus(player_type *player_ptr, WORD wCmd)
2437 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2439 else if (game_in_progress)
2441 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
2445 game_in_progress = TRUE;
2447 play_game(player_ptr, TRUE);
2457 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2459 else if (game_in_progress)
2461 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
2465 memset(&ofn, 0, sizeof(ofn));
2466 ofn.lStructSize = sizeof(ofn);
2467 ofn.hwndOwner = data[0].w;
2468 ofn.lpstrFilter = "Save Files (*.)\0*\0";
2469 ofn.nFilterIndex = 1;
2470 ofn.lpstrFile = savefile;
2471 ofn.nMaxFile = 1024;
2472 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
2473 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
2475 if (GetOpenFileName(&ofn))
2477 validate_file(savefile);
2478 game_in_progress = TRUE;
2480 play_game(player_ptr, FALSE);
2489 if (game_in_progress && current_world_ptr->character_generated)
2493 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
2498 do_cmd_save_game(player_ptr, FALSE);
2502 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
2509 if (game_in_progress && current_world_ptr->character_generated)
2513 plog(_("今は終了できません。", "You may not do that right now."));
2518 forget_lite(player_ptr->current_floor_ptr);
2519 forget_view(player_ptr->current_floor_ptr);
2520 clear_mon_lite(player_ptr->current_floor_ptr);
2522 Term_key_push(SPECIAL_KEY_QUIT);
2529 case IDM_FILE_SCORE:
2532 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
2533 highscore_fd = fd_open(buf, O_RDONLY);
2534 if (highscore_fd < 0)
2536 msg_print("Score file unavailable.");
2542 display_scores_aux(0, MAX_HISCORES, -1, NULL);
2543 (void)fd_close(highscore_fd);
2551 case IDM_FILE_MOVIE:
2555 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2557 else if (game_in_progress)
2559 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
2563 memset(&ofn, 0, sizeof(ofn));
2564 ofn.lStructSize = sizeof(ofn);
2565 ofn.hwndOwner = data[0].w;
2566 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
2567 ofn.nFilterIndex = 1;
2568 ofn.lpstrFile = savefile;
2569 ofn.nMaxFile = 1024;
2570 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
2571 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2573 if (GetOpenFileName(&ofn))
2575 prepare_browse_movie_aux(savefile);
2576 play_game(player_ptr, FALSE);
2584 case IDM_WINDOW_VIS_0:
2586 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
2589 case IDM_WINDOW_VIS_1:
2590 case IDM_WINDOW_VIS_2:
2591 case IDM_WINDOW_VIS_3:
2592 case IDM_WINDOW_VIS_4:
2593 case IDM_WINDOW_VIS_5:
2594 case IDM_WINDOW_VIS_6:
2595 case IDM_WINDOW_VIS_7:
2597 int i = wCmd - IDM_WINDOW_VIS_0;
2598 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2604 ShowWindow(td->w, SW_SHOW);
2605 term_data_redraw(player_ptr, td);
2609 td->visible = FALSE;
2611 ShowWindow(td->w, SW_HIDE);
2616 case IDM_WINDOW_FONT_0:
2617 case IDM_WINDOW_FONT_1:
2618 case IDM_WINDOW_FONT_2:
2619 case IDM_WINDOW_FONT_3:
2620 case IDM_WINDOW_FONT_4:
2621 case IDM_WINDOW_FONT_5:
2622 case IDM_WINDOW_FONT_6:
2623 case IDM_WINDOW_FONT_7:
2625 int i = wCmd - IDM_WINDOW_FONT_0;
2626 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2629 term_change_font(td);
2632 case IDM_WINDOW_POS_1:
2633 case IDM_WINDOW_POS_2:
2634 case IDM_WINDOW_POS_3:
2635 case IDM_WINDOW_POS_4:
2636 case IDM_WINDOW_POS_5:
2637 case IDM_WINDOW_POS_6:
2638 case IDM_WINDOW_POS_7:
2640 int i = wCmd - IDM_WINDOW_POS_0;
2641 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2644 if (!td->posfix && td->visible)
2647 term_window_pos(td, HWND_TOPMOST);
2652 term_window_pos(td, data[0].w);
2657 case IDM_WINDOW_BIZ_0:
2658 case IDM_WINDOW_BIZ_1:
2659 case IDM_WINDOW_BIZ_2:
2660 case IDM_WINDOW_BIZ_3:
2661 case IDM_WINDOW_BIZ_4:
2662 case IDM_WINDOW_BIZ_5:
2663 case IDM_WINDOW_BIZ_6:
2664 case IDM_WINDOW_BIZ_7:
2666 int i = wCmd - IDM_WINDOW_BIZ_0;
2667 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2670 td->bizarre = !td->bizarre;
2672 term_window_resize(td);
2675 case IDM_WINDOW_I_WID_0:
2676 case IDM_WINDOW_I_WID_1:
2677 case IDM_WINDOW_I_WID_2:
2678 case IDM_WINDOW_I_WID_3:
2679 case IDM_WINDOW_I_WID_4:
2680 case IDM_WINDOW_I_WID_5:
2681 case IDM_WINDOW_I_WID_6:
2682 case IDM_WINDOW_I_WID_7:
2684 int i = wCmd - IDM_WINDOW_I_WID_0;
2685 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2690 term_window_resize(td);
2693 case IDM_WINDOW_D_WID_0:
2694 case IDM_WINDOW_D_WID_1:
2695 case IDM_WINDOW_D_WID_2:
2696 case IDM_WINDOW_D_WID_3:
2697 case IDM_WINDOW_D_WID_4:
2698 case IDM_WINDOW_D_WID_5:
2699 case IDM_WINDOW_D_WID_6:
2700 case IDM_WINDOW_D_WID_7:
2702 int i = wCmd - IDM_WINDOW_D_WID_0;
2703 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2708 term_window_resize(td);
2711 case IDM_WINDOW_I_HGT_0:
2712 case IDM_WINDOW_I_HGT_1:
2713 case IDM_WINDOW_I_HGT_2:
2714 case IDM_WINDOW_I_HGT_3:
2715 case IDM_WINDOW_I_HGT_4:
2716 case IDM_WINDOW_I_HGT_5:
2717 case IDM_WINDOW_I_HGT_6:
2718 case IDM_WINDOW_I_HGT_7:
2720 int i = wCmd - IDM_WINDOW_I_HGT_0;
2721 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2726 term_window_resize(td);
2729 case IDM_WINDOW_D_HGT_0:
2730 case IDM_WINDOW_D_HGT_1:
2731 case IDM_WINDOW_D_HGT_2:
2732 case IDM_WINDOW_D_HGT_3:
2733 case IDM_WINDOW_D_HGT_4:
2734 case IDM_WINDOW_D_HGT_5:
2735 case IDM_WINDOW_D_HGT_6:
2736 case IDM_WINDOW_D_HGT_7:
2738 int i = wCmd - IDM_WINDOW_D_HGT_0;
2739 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2744 term_window_resize(td);
2747 case IDM_OPTIONS_NO_GRAPHICS:
2751 plog("You may not do that right now.");
2755 if (arg_graphics != GRAPHICS_NONE)
2757 arg_graphics = GRAPHICS_NONE;
2758 term_xtra_win_react(player_ptr);
2759 Term_key_push(KTRL('R'));
2764 case IDM_OPTIONS_OLD_GRAPHICS:
2768 plog("You may not do that right now.");
2772 if (arg_graphics != GRAPHICS_ORIGINAL)
2774 arg_graphics = GRAPHICS_ORIGINAL;
2775 term_xtra_win_react(player_ptr);
2776 Term_key_push(KTRL('R'));
2781 case IDM_OPTIONS_NEW_GRAPHICS:
2785 plog("You may not do that right now.");
2789 if (arg_graphics != GRAPHICS_ADAM_BOLT)
2791 arg_graphics = GRAPHICS_ADAM_BOLT;
2792 term_xtra_win_react(player_ptr);
2793 Term_key_push(KTRL('R'));
2798 case IDM_OPTIONS_NEW2_GRAPHICS:
2802 plog("You may not do that right now.");
2806 if (arg_graphics != GRAPHICS_HENGBAND)
2808 arg_graphics = GRAPHICS_HENGBAND;
2809 term_xtra_win_react(player_ptr);
2810 Term_key_push(KTRL('R'));
2815 case IDM_OPTIONS_BIGTILE:
2820 plog("You may not do that right now.");
2824 arg_bigtile = !arg_bigtile;
2825 Term_activate(&td->t);
2826 Term_resize(td->cols, td->rows);
2827 InvalidateRect(td->w, NULL, TRUE);
2830 case IDM_OPTIONS_MUSIC:
2834 plog("You may not do that right now.");
2838 arg_music = !arg_music;
2839 term_xtra_win_react(player_ptr);
2840 Term_key_push(KTRL('R'));
2843 case IDM_OPTIONS_SOUND:
2847 plog("You may not do that right now.");
2851 arg_sound = !arg_sound;
2852 term_xtra_win_react(player_ptr);
2853 Term_key_push(KTRL('R'));
2856 case IDM_OPTIONS_BG:
2860 plog("You may not do that right now.");
2866 term_xtra_win_react(player_ptr);
2867 Term_key_push(KTRL('R'));
2870 case IDM_OPTIONS_OPEN_BG:
2874 plog("You may not do that right now.");
2878 memset(&ofn, 0, sizeof(ofn));
2879 ofn.lStructSize = sizeof(ofn);
2880 ofn.hwndOwner = data[0].w;
2881 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
2882 ofn.nFilterIndex = 1;
2883 ofn.lpstrFile = bg_bitmap_file;
2884 ofn.nMaxFile = 1023;
2885 ofn.lpstrInitialDir = NULL;
2886 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
2887 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
2889 if (GetOpenFileName(&ofn))
2895 term_xtra_win_react(player_ptr);
2896 Term_key_push(KTRL('R'));
2899 case IDM_DUMP_SCREEN_HTML:
2901 static char buf[1024] = "";
2902 memset(&ofn, 0, sizeof(ofn));
2903 ofn.lStructSize = sizeof(ofn);
2904 ofn.hwndOwner = data[0].w;
2905 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
2906 ofn.nFilterIndex = 1;
2907 ofn.lpstrFile = buf;
2908 ofn.nMaxFile = 1023;
2909 ofn.lpstrDefExt = "html";
2910 ofn.lpstrInitialDir = NULL;
2911 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
2912 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
2914 if (GetSaveFileName(&ofn))
2916 do_cmd_save_screen_html_aux(buf, 0);
2921 case IDM_OPTIONS_SAVER:
2925 DestroyWindow(hwndSaver);
2930 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
2931 "Angband Screensaver",
2932 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
2933 0, 0, GetSystemMetrics(SM_CXSCREEN),
2934 GetSystemMetrics(SM_CYSCREEN),
2935 NULL, NULL, hInstance, NULL);
2939 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2943 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
2948 case IDM_OPTIONS_MAP:
2950 windows_map(player_ptr);
2954 case IDM_HELP_CONTENTS:
2958 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
2959 if (check_file(tmp))
2961 sprintf(buf, "winhelp.exe %s", tmp);
2962 WinExec(buf, SW_NORMAL);
2966 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
2967 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
2974 static bool process_keydown(WPARAM wParam, LPARAM lParam)
2980 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
2981 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
2982 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
2984 term_no_press = (ma) ? TRUE : FALSE;
2985 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]))
2987 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
2988 bool numpad = FALSE;
2991 if (mc) Term_keypress('C');
2992 if (ms) Term_keypress('S');
2993 if (ma) Term_keypress('A');
2995 int i = LOBYTE(HIWORD(lParam));
3000 term_no_press = TRUE;
3019 term_no_press = TRUE;
3034 if (numpad) Term_keypress('K');
3036 Term_keypress(hexsym[i / 16]);
3037 Term_keypress(hexsym[i % 16]);
3048 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
3050 LRESULT PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3054 td = (term_data *)GetWindowLong(hWnd, 0);
3060 SetWindowLong(hWnd, 0, (LONG)(my_td));
3065 mop.dwCallback = (DWORD)hWnd;
3068 case WM_GETMINMAXINFO:
3073 lpmmi = (MINMAXINFO*)lParam;
3076 rc.left = rc.top = 0;
3077 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
3078 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
3080 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3082 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
3083 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
3089 BeginPaint(hWnd, &ps);
3090 if (td) term_data_redraw(p_ptr, td);
3091 EndPaint(hWnd, &ps);
3092 ValidateRect(hWnd, NULL);
3097 if (wParam == MCI_NOTIFY_SUCCESSFUL)
3099 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
3100 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
3108 if (process_keydown(wParam, lParam))
3114 if (term_no_press) term_no_press = FALSE;
3115 else Term_keypress(wParam);
3118 case WM_LBUTTONDOWN:
3120 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
3121 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
3131 TERM_LEN dx = abs(oldx - mousex) + 1;
3132 TERM_LEN dy = abs(oldy - mousey) + 1;
3133 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
3134 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
3140 int sz = (dx + 3) * dy;
3142 int sz = (dx + 2) * dy;
3144 hGlobal = GlobalAlloc(GHND, sz + 1);
3145 if (hGlobal == NULL) return 0;
3146 lpStr = (LPSTR)GlobalLock(hGlobal);
3148 for (int i = 0; i < dy; i++)
3152 char **scr = data[0].t.scr->c;
3154 C_MAKE(s, (dx + 1), char);
3155 strncpy(s, &scr[oy + i][ox], dx);
3159 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
3162 if (ox + dx < data[0].cols)
3164 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
3167 for (int j = 0; j < dx; j++)
3169 if (s[j] == 127) s[j] = '#';
3173 for (int j = 0; j < dx; j++)
3175 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
3185 GlobalUnlock(hGlobal);
3186 if (OpenClipboard(hWnd) == 0)
3188 GlobalFree(hGlobal);
3193 SetClipboardData(CF_TEXT, hGlobal);
3200 if (!mouse_down) return 0;
3203 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
3204 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
3209 dx = abs(oldx - mousex) + 1;
3210 dy = abs(oldy - mousey) + 1;
3211 ox = (oldx > mousex) ? mousex : oldx;
3212 oy = (oldy > mousey) ? mousey : oldy;
3213 term_inversed_area(hWnd, ox, oy, dx, dy);
3220 dx = abs(cx - mousex) + 1;
3221 dy = abs(cy - mousey) + 1;
3222 ox = (cx > mousex) ? mousex : cx;
3223 oy = (cy > mousey) ? mousey : cy;
3224 term_inversed_area(hWnd, ox, oy, dx, dy);
3237 if (!game_in_progress || !current_world_ptr->character_generated)
3245 plog(_("今は終了できません。", "You may not do that right now."));
3250 forget_lite(p_ptr->current_floor_ptr);
3251 forget_view(p_ptr->current_floor_ptr);
3252 clear_mon_lite(p_ptr->current_floor_ptr);
3253 Term_key_push(SPECIAL_KEY_QUIT);
3256 case WM_QUERYENDSESSION:
3258 if (!game_in_progress || !current_world_ptr->character_generated)
3265 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
3266 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
3268 p_ptr->panic_save = 1;
3269 signals_ignore_tstp();
3270 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
3271 (void)save_player(p_ptr);
3282 process_menus(p_ptr, LOWORD(wParam));
3288 if (!td->w) return 1;
3289 if (td->size_hack) return 1;
3291 // todo 二重のswitch文。後で分割する.
3294 case SIZE_MINIMIZED:
3296 for (int i = 1; i < MAX_TERM_DATA; i++)
3298 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
3303 case SIZE_MAXIMIZED:
3306 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
3307 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
3308 if ((td->cols != cols) || (td->rows != rows))
3312 if (!IsZoomed(td->w) && !IsIconic(td->w))
3314 normsize.x = td->cols;
3315 normsize.y = td->rows;
3318 Term_activate(&td->t);
3319 Term_resize(td->cols, td->rows);
3320 InvalidateRect(td->w, NULL, TRUE);
3323 td->size_hack = TRUE;
3324 for (int i = 1; i < MAX_TERM_DATA; i++)
3326 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
3329 td->size_hack = FALSE;
3337 case WM_PALETTECHANGED:
3339 if ((HWND)wParam == hWnd) return 0;
3341 case WM_QUERYNEWPALETTE:
3343 if (!paletted) return 0;
3345 HDC hdc = GetDC(hWnd);
3346 SelectPalette(hdc, hPal, FALSE);
3347 int i = RealizePalette(hdc);
3348 if (i) InvalidateRect(hWnd, NULL, TRUE);
3350 ReleaseDC(hWnd, hdc);
3355 if (!wParam || HIWORD(lParam)) break;
3357 for (int i = 1; i < MAX_TERM_DATA; i++)
3359 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
3365 case WM_ACTIVATEAPP:
3367 if (IsIconic(td->w)) break;
3369 for (int i = 1; i < MAX_TERM_DATA; i++)
3371 if (data[i].visible)
3375 ShowWindow(data[i].w, SW_SHOW);
3379 ShowWindow(data[i].w, SW_HIDE);
3386 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3391 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
3393 LRESULT PASCAL AngbandListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3397 td = (term_data *)GetWindowLong(hWnd, 0);
3403 SetWindowLong(hWnd, 0, (LONG)(my_td));
3410 case WM_GETMINMAXINFO:
3415 lpmmi = (MINMAXINFO*)lParam;
3418 rc.left = rc.top = 0;
3419 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
3420 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
3422 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3423 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
3424 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
3430 if (!td->w) return 1;
3431 if (td->size_hack) return 1;
3433 td->size_hack = TRUE;
3435 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
3436 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
3437 if ((td->cols != cols) || (td->rows != rows))
3439 term *old_term = Term;
3442 Term_activate(&td->t);
3443 Term_resize(td->cols, td->rows);
3444 Term_activate(old_term);
3445 InvalidateRect(td->w, NULL, TRUE);
3446 p_ptr->window = 0xFFFFFFFF;
3447 handle_stuff(p_ptr);
3450 td->size_hack = FALSE;
3455 BeginPaint(hWnd, &ps);
3456 if (td) term_data_redraw(p_ptr, td);
3457 EndPaint(hWnd, &ps);
3463 if (process_keydown(wParam, lParam))
3470 if (term_no_press) term_no_press = FALSE;
3471 else Term_keypress(wParam);
3474 case WM_PALETTECHANGED:
3476 if ((HWND)wParam == hWnd) return FALSE;
3478 case WM_QUERYNEWPALETTE:
3480 if (!paletted) return 0;
3482 HDC hdc = GetDC(hWnd);
3483 SelectPalette(hdc, hPal, FALSE);
3484 int i = RealizePalette(hdc);
3485 if (i) InvalidateRect(hWnd, NULL, TRUE);
3487 ReleaseDC(hWnd, hdc);
3490 case WM_NCLBUTTONDOWN:
3493 if (wParam == HTCLOSE) wParam = HTSYSMENU;
3494 #endif /* HTCLOSE */
3496 if (wParam == HTSYSMENU)
3500 td->visible = FALSE;
3501 ShowWindow(td->w, SW_HIDE);
3511 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3515 LRESULT PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3517 static int iMouse = 0;
3518 static WORD xMouse = 0;
3519 static WORD yMouse = 0;
3534 case WM_LBUTTONDOWN:
3535 case WM_MBUTTONDOWN:
3536 case WM_RBUTTONDOWN:
3539 SendMessage(hWnd, WM_CLOSE, 0, 0);
3546 int dx = LOWORD(lParam) - xMouse;
3547 int dy = HIWORD(lParam) - yMouse;
3549 if (dx < 0) dx = -dx;
3550 if (dy < 0) dy = -dy;
3552 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
3554 SendMessage(hWnd, WM_CLOSE, 0, 0);
3559 xMouse = LOWORD(lParam);
3560 yMouse = HIWORD(lParam);
3566 DestroyWindow(hwndSaver);
3572 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3577 * Display warning message (see "z-util.c")
3579 static void hack_plog(concptr str)
3584 MessageBox(NULL, str, "警告!",
3585 MB_ICONEXCLAMATION | MB_OK);
3587 MessageBox(NULL, str, "Warning",
3588 MB_ICONEXCLAMATION | MB_OK);
3596 * Display error message and quit (see "z-util.c")
3598 static void hack_quit(concptr str)
3603 MessageBox(NULL, str, "エラー!",
3604 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3606 MessageBox(NULL, str, "Error",
3607 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3612 UnregisterClass(AppName, hInstance);
3613 if (hIcon) DestroyIcon(hIcon);
3620 * Display warning message (see "z-util.c")
3622 static void hook_plog(concptr str)
3627 MessageBox(data[0].w, str, "警告!",
3628 MB_ICONEXCLAMATION | MB_OK);
3630 MessageBox(data[0].w, str, "Warning",
3631 MB_ICONEXCLAMATION | MB_OK);
3639 * Display error message and quit (see "z-util.c")
3641 static void hook_quit(concptr str)
3646 MessageBox(data[0].w, str, "エラー!",
3647 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3649 MessageBox(data[0].w, str, "Error",
3650 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3655 for (int i = MAX_TERM_DATA - 1; i >= 0; --i)
3657 term_force_font(&data[i], NULL);
3658 if (data[i].font_want) string_free(data[i].font_want);
3659 if (data[i].w) DestroyWindow(data[i].w);
3663 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
3664 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
3665 if (infMask.hPalette) DeleteObject(infMask.hPalette);
3666 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
3668 DeleteObject(hbrYellow);
3671 if (hPal) DeleteObject(hPal);
3673 UnregisterClass(AppName, hInstance);
3674 if (hIcon) DestroyIcon(hIcon);
3683 static void init_stuff(void)
3686 GetModuleFileName(hInstance, path, 512);
3688 strcpy(path + strlen(path) - 4, ".INI");
3689 ini_file = string_make(path);
3690 int i = strlen(path);
3694 if (path[i] == '\\')
3700 strcpy(path + i + 1, "lib\\");
3701 validate_dir(path, TRUE);
3702 init_file_paths(path);
3703 validate_dir(ANGBAND_DIR_APEX, FALSE);
3704 validate_dir(ANGBAND_DIR_BONE, FALSE);
3705 if (!check_dir(ANGBAND_DIR_EDIT))
3707 validate_dir(ANGBAND_DIR_DATA, TRUE);
3711 validate_dir(ANGBAND_DIR_DATA, FALSE);
3714 validate_dir(ANGBAND_DIR_FILE, TRUE);
3715 validate_dir(ANGBAND_DIR_HELP, FALSE);
3716 validate_dir(ANGBAND_DIR_INFO, FALSE);
3717 validate_dir(ANGBAND_DIR_PREF, TRUE);
3718 validate_dir(ANGBAND_DIR_SAVE, FALSE);
3719 validate_dir(ANGBAND_DIR_USER, TRUE);
3720 validate_dir(ANGBAND_DIR_XTRA, TRUE);
3721 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
3723 validate_file(path);
3724 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
3725 ANGBAND_DIR_XTRA_GRAF = string_make(path);
3726 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
3728 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
3729 ANGBAND_DIR_XTRA_SOUND = string_make(path);
3730 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
3732 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
3733 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
3734 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
3736 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
3737 ANGBAND_DIR_XTRA_HELP = string_make(path);
3742 * todo よく見るとhMutexはちゃんと使われていない……?
3743 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
3745 static bool is_already_running(void)
3748 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
3749 if (GetLastError() == ERROR_ALREADY_EXISTS)
3759 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
3761 int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
3767 setlocale(LC_ALL, "ja_JP");
3770 if (is_already_running())
3773 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
3775 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3779 if (hPrevInst == NULL)
3781 wc.style = CS_CLASSDC;
3782 wc.lpfnWndProc = AngbandWndProc;
3785 wc.hInstance = hInst;
3786 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
3787 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
3788 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
3789 wc.lpszMenuName = AppName;
3790 wc.lpszClassName = AppName;
3792 if (!RegisterClass(&wc)) exit(1);
3794 wc.lpfnWndProc = AngbandListProc;
3795 wc.lpszMenuName = NULL;
3796 wc.lpszClassName = AngList;
3798 if (!RegisterClass(&wc)) exit(2);
3800 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
3801 wc.lpfnWndProc = AngbandSaverProc;
3803 wc.lpszMenuName = NULL;
3804 wc.lpszClassName = "WindowsScreenSaverClass";
3806 if (!RegisterClass(&wc)) exit(3);
3809 plog_aux = hack_plog;
3810 quit_aux = hack_quit;
3811 core_aux = hack_quit;
3814 for (int i = 0; special_key_list[i]; ++i)
3816 special_key[special_key_list[i]] = TRUE;
3819 for (int i = 0; ignore_key_list[i]; ++i)
3821 ignore_key[ignore_key_list[i]] = TRUE;
3825 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
3826 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
3827 ReleaseDC(NULL, hdc);
3829 for (int i = 0; i < 256; i++)
3831 byte rv = angband_color_table[i][1];
3832 byte gv = angband_color_table[i][2];
3833 byte bv = angband_color_table[i][3];
3834 win_clr[i] = PALETTERGB(rv, gv, bv);
3835 angband_color_table[i][0] = win_pal[i];
3841 plog_aux = hook_plog;
3842 quit_aux = hook_quit;
3843 core_aux = hook_quit;
3845 ANGBAND_SYS = "win";
3846 if (7 != GetKeyboardType(0))
3847 ANGBAND_KEYBOARD = "0";
3850 switch (GetKeyboardType(1))
3852 case 0x0D01: case 0x0D02:
3853 case 0x0D03: case 0x0D04:
3854 case 0x0D05: case 0x0D06:
3856 ANGBAND_KEYBOARD = "NEC98";
3860 ANGBAND_KEYBOARD = "JAPAN";
3865 Term_activate(term_screen);
3866 init_angband(p_ptr, process_autopick_file_command);
3869 if (lpCmdLine[0] == '-') {
3870 switch (lpCmdLine[1])
3875 if (!lpCmdLine[2]) break;
3876 chuukei_server = TRUE;
3877 if (connect_chuukei_server(&lpCmdLine[2]) < 0) {
3878 msg_print("connect fail");
3881 msg_print("connect");
3889 if (!lpCmdLine[2]) break;
3890 chuukei_client = TRUE;
3891 connect_chuukei_server(&lpCmdLine[2]);
3892 play_game(player_ptr, FALSE);
3899 if (!lpCmdLine[2]) break;
3900 prepare_browse_movie(&lpCmdLine[2]);
3901 play_game(player_ptr, FALSE);
3910 if (!chuukei_server) check_for_save_file(lpCmdLine);
3912 check_for_save_file(p_ptr, lpCmdLine);
3915 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
3917 while (GetMessage(&msg, NULL, 0, 0))
3919 TranslateMessage(&msg);
3920 DispatchMessage(&msg);
3926 #endif /* WINDOWS */