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/input-key-acceptor.h"
110 #include "io/signal-handlers.h"
111 #include "io/write-diary.h"
112 #include "main/init.h"
113 #include "main/music-definitions-table.h"
114 #include "main/sound-definitions-table.h"
115 #include "main/sound-of-music.h"
116 #include "system/angband-version.h"
117 #include "system/angband.h"
118 #include "system/system-variables.h"
119 #include "term/gameterm.h"
120 #include "term/screen-processor.h"
121 #include "term/term-color-types.h"
122 #include "util/angband-files.h"
123 #include "util/int-char-converter.h"
124 #include "util/string-processor.h"
125 #include "view/display-map.h"
126 #include "view/display-messages.h"
127 #include "world/world.h"
130 #include "dungeon/dungeon.h"
131 #include "savedata/save.h"
132 #include "term/z-term.h"
138 * Available graphic modes
140 #define GRAPHICS_NONE 0
141 #define GRAPHICS_ORIGINAL 1
142 #define GRAPHICS_ADAM_BOLT 2
143 #define GRAPHICS_HENGBAND 3
146 * Menu constants -- see "ANGBAND.RC"
148 #define IDM_FILE_NEW 100
149 #define IDM_FILE_OPEN 101
150 #define IDM_FILE_SAVE 110
151 #define IDM_FILE_SCORE 120
152 #define IDM_FILE_MOVIE 121
153 #define IDM_FILE_EXIT 130
155 #define IDM_WINDOW_VIS_0 200
156 #define IDM_WINDOW_VIS_1 201
157 #define IDM_WINDOW_VIS_2 202
158 #define IDM_WINDOW_VIS_3 203
159 #define IDM_WINDOW_VIS_4 204
160 #define IDM_WINDOW_VIS_5 205
161 #define IDM_WINDOW_VIS_6 206
162 #define IDM_WINDOW_VIS_7 207
164 #define IDM_WINDOW_FONT_0 210
165 #define IDM_WINDOW_FONT_1 211
166 #define IDM_WINDOW_FONT_2 212
167 #define IDM_WINDOW_FONT_3 213
168 #define IDM_WINDOW_FONT_4 214
169 #define IDM_WINDOW_FONT_5 215
170 #define IDM_WINDOW_FONT_6 216
171 #define IDM_WINDOW_FONT_7 217
173 #define IDM_WINDOW_POS_0 220
174 #define IDM_WINDOW_POS_1 221
175 #define IDM_WINDOW_POS_2 222
176 #define IDM_WINDOW_POS_3 223
177 #define IDM_WINDOW_POS_4 224
178 #define IDM_WINDOW_POS_5 225
179 #define IDM_WINDOW_POS_6 226
180 #define IDM_WINDOW_POS_7 227
182 #define IDM_WINDOW_BIZ_0 230
183 #define IDM_WINDOW_BIZ_1 231
184 #define IDM_WINDOW_BIZ_2 232
185 #define IDM_WINDOW_BIZ_3 233
186 #define IDM_WINDOW_BIZ_4 234
187 #define IDM_WINDOW_BIZ_5 235
188 #define IDM_WINDOW_BIZ_6 236
189 #define IDM_WINDOW_BIZ_7 237
191 #define IDM_WINDOW_I_WID_0 240
192 #define IDM_WINDOW_I_WID_1 241
193 #define IDM_WINDOW_I_WID_2 242
194 #define IDM_WINDOW_I_WID_3 243
195 #define IDM_WINDOW_I_WID_4 244
196 #define IDM_WINDOW_I_WID_5 245
197 #define IDM_WINDOW_I_WID_6 246
198 #define IDM_WINDOW_I_WID_7 247
200 #define IDM_WINDOW_D_WID_0 250
201 #define IDM_WINDOW_D_WID_1 251
202 #define IDM_WINDOW_D_WID_2 252
203 #define IDM_WINDOW_D_WID_3 253
204 #define IDM_WINDOW_D_WID_4 254
205 #define IDM_WINDOW_D_WID_5 255
206 #define IDM_WINDOW_D_WID_6 256
207 #define IDM_WINDOW_D_WID_7 257
209 #define IDM_WINDOW_I_HGT_0 260
210 #define IDM_WINDOW_I_HGT_1 261
211 #define IDM_WINDOW_I_HGT_2 262
212 #define IDM_WINDOW_I_HGT_3 263
213 #define IDM_WINDOW_I_HGT_4 264
214 #define IDM_WINDOW_I_HGT_5 265
215 #define IDM_WINDOW_I_HGT_6 266
216 #define IDM_WINDOW_I_HGT_7 267
218 #define IDM_WINDOW_D_HGT_0 270
219 #define IDM_WINDOW_D_HGT_1 271
220 #define IDM_WINDOW_D_HGT_2 272
221 #define IDM_WINDOW_D_HGT_3 273
222 #define IDM_WINDOW_D_HGT_4 274
223 #define IDM_WINDOW_D_HGT_5 275
224 #define IDM_WINDOW_D_HGT_6 276
225 #define IDM_WINDOW_D_HGT_7 277
227 #define IDM_OPTIONS_NO_GRAPHICS 400
228 #define IDM_OPTIONS_OLD_GRAPHICS 401
229 #define IDM_OPTIONS_NEW_GRAPHICS 402
230 #define IDM_OPTIONS_NEW2_GRAPHICS 403
231 #define IDM_OPTIONS_BIGTILE 409
232 #define IDM_OPTIONS_SOUND 410
233 #define IDM_OPTIONS_MUSIC 411
234 #define IDM_OPTIONS_SAVER 420
235 #define IDM_OPTIONS_MAP 430
236 #define IDM_OPTIONS_BG 440
237 #define IDM_OPTIONS_OPEN_BG 441
239 #define IDM_DUMP_SCREEN_HTML 450
241 #define IDM_HELP_CONTENTS 901
244 * Exclude parts of WINDOWS.H that are not needed (Win32)
246 #define WIN32_LEAN_AND_MEAN
247 #define NONLS /* All NLS defines and routines */
248 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
249 #define NOMCX /* Modem Configuration Extensions */
252 * Include the "windows" support file
257 * Exclude parts of MMSYSTEM.H that are not needed
259 #define MMNODRV /* Installable driver support */
260 #define MMNOWAVE /* Waveform support */
261 #define MMNOMIDI /* MIDI support */
262 #define MMNOAUX /* Auxiliary audio support */
263 #define MMNOTIMER /* Timer support */
264 #define MMNOJOY /* Joystick support */
265 #define MMNOMCI /* MCI support */
266 #define MMNOMMIO /* Multimedia file I/O support */
268 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
269 #define MOUSE_SENS 40
272 * Include some more files. Note: the Cygnus Cygwin compiler
273 * doesn't use mmsystem.h instead it includes the winmm library
274 * which performs a similar function.
277 #include <mmsystem.h>
280 * Include the support for loading bitmaps
282 #include "term/readdib.h"
284 #define MoveTo(H, X, Y) MoveToEx(H, X, Y, NULL)
287 * Foreground color bits
289 #define VID_BLACK 0x00
290 #define VID_BLUE 0x01
291 #define VID_GREEN 0x02
292 #define VID_CYAN 0x03
294 #define VID_MAGENTA 0x05
295 #define VID_YELLOW 0x06
296 #define VID_WHITE 0x07
301 #define VID_BRIGHT 0x08
305 * @brief ターム情報構造体 / Extra "term" data
308 * pos_x / pos_y は各タームの左上点座標を指す。
311 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
312 * 1ドットずつ調整するステータスを指す。
313 * また、フォントを変更すると都度自動調整される。
316 * Note the use of "font_want" for the names of the font file requested by
317 * the user, and the use of "font_file" for the currently active font file.
319 * The "font_file" is uppercased, and takes the form "8X13.FON", while
320 * "font_want" can be in almost any form as long as it could be construed
321 * as attempting to represent the name of a font.
332 TERM_LEN rows; /* int -> uint */
335 uint pos_x; //!< タームの左上X座標
336 uint pos_y; //!< タームの左上Y座標
351 int font_wid; //!< フォント横幅
352 int font_hgt; //!< フォント縦幅
353 int tile_wid; //!< タイル横幅
354 int tile_hgt; //!< タイル縦幅
365 #define MAX_TERM_DATA 8 //!< Maximum number of windows
367 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
368 static term_data *my_td; //!< Hack -- global "window creation" pointer
369 POINT normsize; //!< Remember normal size of main window when maxmized
372 * was main window maximized on previous playing
374 bool win_maximized = FALSE;
379 bool game_in_progress = FALSE;
382 * note when "open"/"new" become valid
384 bool initialized = FALSE;
387 * screen paletted, i.e. 256 colors
389 bool paletted = FALSE;
392 * 16 colors screen, don't use RGB()
394 bool colors16 = FALSE;
397 * Saved instance handle
399 static HINSTANCE hInstance;
402 * Yellow brush for the cursor
404 static HBRUSH hbrYellow;
414 static HPALETTE hPal;
417 static HBITMAP hBG = NULL;
418 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
419 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
422 * The screen saver window
424 static HWND hwndSaver;
427 * 現在使用中のタイルID(0ならば未使用)
428 * Flag set once "graphics" has been initialized
430 static byte current_graphics_mode = 0;
435 static DIBINIT infGraph;
438 * The global bitmap mask
440 static DIBINIT infMask;
443 * Flag set once "sound" has been initialized
445 static bool can_use_sound = FALSE;
447 #define SAMPLE_SOUND_MAX 16
449 * An array of sound file names
451 static concptr sound_file[SOUND_MAX][SAMPLE_SOUND_MAX];
453 #define SAMPLE_MUSIC_MAX 16
454 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
455 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
456 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
457 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
458 static bool can_use_music = FALSE;
460 static MCI_OPEN_PARMS mop;
461 static char mci_device_type[256];
463 int current_music_type = 0;
464 int current_music_id = 0;
467 * Full path to ANGBAND.INI
469 static concptr ini_file = NULL;
472 * Name of application
474 static concptr AppName = "ANGBAND";
477 * Name of sub-window type
479 static concptr AngList = "AngList";
484 static concptr ANGBAND_DIR_XTRA_GRAF;
485 static concptr ANGBAND_DIR_XTRA_SOUND;
486 static concptr ANGBAND_DIR_XTRA_MUSIC;
487 static concptr ANGBAND_DIR_XTRA_HELP;
488 static concptr ANGBAND_DIR_XTRA_MUSIC;
491 * The "complex" color values
493 static COLORREF win_clr[256];
496 * Flag for macro trigger with dump ASCII
498 static bool term_no_press = FALSE;
503 static bool mouse_down = FALSE;
504 static bool paint_rect = FALSE;
505 static TERM_LEN mousex = 0, mousey = 0;
506 static TERM_LEN oldx, oldy;
509 * @brief The "simple" color values
511 * See "main-ibm.c" for original table information
512 * The entries below are taken from the "color bits" defined above.
513 * Note that many of the choices below suck, but so do crappy monitors.
515 static BYTE win_pal[256] = {
516 VID_BLACK, /* Dark */
517 VID_WHITE, /* White */
518 VID_CYAN, /* Slate XXX */
519 VID_RED | VID_BRIGHT, /* Orange XXX */
521 VID_GREEN, /* Green */
523 VID_YELLOW, /* Umber XXX */
524 VID_BLACK | VID_BRIGHT, /* Light Dark */
525 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
526 VID_MAGENTA, /* Violet XXX */
527 VID_YELLOW | VID_BRIGHT, /* Yellow */
528 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
529 VID_GREEN | VID_BRIGHT, /* Light Green */
530 VID_BLUE | VID_BRIGHT, /* Light Blue */
531 VID_YELLOW /* Light Umber XXX */
535 * Hack -- define which keys are "special"
537 static bool special_key[256];
538 static bool ignore_key[256];
541 * Hack -- initialization list for "special_key"
543 static byte special_key_list[] = {
544 VK_CLEAR, VK_PAUSE, VK_CAPITAL, VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI, VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE, VK_PRIOR, VK_NEXT, VK_END,
545 VK_HOME, VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN, VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT, VK_INSERT, VK_DELETE, VK_HELP, VK_APPS, VK_NUMPAD0, VK_NUMPAD1,
546 VK_NUMPAD2, VK_NUMPAD3, VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7, VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD, VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL,
547 VK_DIVIDE, VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6, VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12, VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18, VK_F19,
548 VK_F20, VK_F21, VK_F22, VK_F23, VK_F24, VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL, VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM, VK_NONAME, VK_PA1,
552 static byte ignore_key_list[] = {
553 VK_ESCAPE, VK_TAB, VK_SPACE, 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
554 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN, VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL, VK_LMENU, VK_RMENU, 0 /* End of List */
557 /* Function prototype */
559 static bool is_already_running(void);
562 static void delete_bg(void)
570 static int init_bg(void)
572 char *bmfile = bg_bitmap_file;
577 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
579 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
588 static void DrawBG(HDC hdc, RECT *r)
593 int x = r->left, y = r->top;
597 GetObject(hBG, sizeof(bm), &bm);
598 int swid = bm.bmWidth;
599 int shgt = bm.bmHeight;
601 HDC hdcSrc = CreateCompatibleDC(hdc);
602 HBITMAP hOld = SelectObject(hdcSrc, hBG);
606 int cwid = MIN(swid - sx, r->right - nx);
609 int chgt = MIN(shgt - sy, r->bottom - ny);
610 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
612 } while (ny < r->bottom);
616 } while (nx < r->right);
618 SelectObject(hdcSrc, hOld);
623 * Check for existance of a file
625 static bool check_file(concptr s)
629 DWORD attrib = GetFileAttributes(path);
630 if (attrib == INVALID_FILE_NAME)
632 if (attrib & FILE_ATTRIBUTE_DIRECTORY)
639 * Check for existance of a directory
641 static bool check_dir(concptr s)
645 int i = strlen(path);
646 if (i && (path[i - 1] == '\\'))
649 DWORD attrib = GetFileAttributes(path);
650 if (attrib == INVALID_FILE_NAME)
652 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY))
661 static void validate_file(concptr s)
666 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
670 * Validate a directory
672 static void validate_dir(concptr s, bool vital)
678 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
679 } else if (mkdir(s)) {
680 quit_fmt("Unable to create directory:\n%s", s);
685 * @brief (Windows版固有実装)Get the "size" for a window
687 static void term_getsize(term_data *td)
694 TERM_LEN wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
695 TERM_LEN hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
699 rc.right = rc.left + wid;
701 rc.bottom = rc.top + hgt;
703 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
704 td->size_wid = rc.right - rc.left;
705 td->size_hgt = rc.bottom - rc.top;
709 GetWindowRect(td->w, &rc);
715 * Write the "prefs" for a single term
717 static void save_prefs_aux(int i)
719 term_data *td = &data[i];
720 GAME_TEXT sec_name[128];
726 sprintf(sec_name, "Term-%d", i);
729 strcpy(buf, td->visible ? "1" : "0");
730 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
734 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "MS ゴシック");
736 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "Courier");
739 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
741 wsprintf(buf, "%d", td->lf.lfWidth);
742 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
743 wsprintf(buf, "%d", td->lf.lfHeight);
744 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
745 wsprintf(buf, "%d", td->lf.lfWeight);
746 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
748 strcpy(buf, td->bizarre ? "1" : "0");
749 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
751 wsprintf(buf, "%d", td->tile_wid);
752 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
754 wsprintf(buf, "%d", td->tile_hgt);
755 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
757 WINDOWPLACEMENT lpwndpl;
758 lpwndpl.length = sizeof(WINDOWPLACEMENT);
759 GetWindowPlacement(td->w, &lpwndpl);
761 RECT rc = lpwndpl.rcNormalPosition;
763 wsprintf(buf, "%d", normsize.x);
765 wsprintf(buf, "%d", td->cols);
767 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
770 wsprintf(buf, "%d", normsize.y);
772 wsprintf(buf, "%d", td->rows);
774 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
776 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
777 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
780 GetWindowRect(td->w, &rc);
781 wsprintf(buf, "%d", rc.left);
782 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
784 wsprintf(buf, "%d", rc.top);
785 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
787 strcpy(buf, td->posfix ? "1" : "0");
788 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
794 * We assume that the windows have all been initialized
796 static void save_prefs(void)
799 sprintf(buf, "%d", arg_graphics);
800 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
802 strcpy(buf, arg_bigtile ? "1" : "0");
803 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
805 strcpy(buf, arg_sound ? "1" : "0");
806 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
808 strcpy(buf, arg_music ? "1" : "0");
809 WritePrivateProfileString("Angband", "Music", buf, ini_file);
811 strcpy(buf, use_bg ? "1" : "0");
812 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
813 WritePrivateProfileString("Angband", "BackGroundBitmap", bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
815 for (int i = 0; i < MAX_TERM_DATA; ++i) {
821 * Load the "prefs" for a single term
823 static void load_prefs_aux(int i)
825 term_data *td = &data[i];
826 GAME_TEXT sec_name[128];
829 int dispx = GetSystemMetrics(SM_CXVIRTUALSCREEN);
830 int dispy = GetSystemMetrics(SM_CYVIRTUALSCREEN);
834 sprintf(sec_name, "Term-%d", i);
835 sprintf(sec_name, "Term-%d", i);
837 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
841 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
843 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
846 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
848 td->font_want = string_make(tmp);
851 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
852 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
853 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
855 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
856 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
858 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
859 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
860 normsize.x = td->cols;
861 normsize.y = td->rows;
864 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
867 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
868 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
869 td->pos_x = MIN(MAX(0, posx), dispx - 128);
870 td->pos_y = MIN(MAX(0, posy), dispy - 128);
873 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
880 static void load_prefs(void)
882 arg_graphics = (byte)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
883 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
884 use_bigtile = arg_bigtile;
885 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
886 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
887 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
888 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
889 for (int i = 0; i < MAX_TERM_DATA; ++i) {
895 * - Taken from files.c.
897 * Extract "tokens" from a buffer
899 * This function uses "whitespace" as delimiters, and treats any amount of
900 * whitespace as a single delimiter. We will never return any empty tokens.
901 * When given an empty buffer, or a buffer containing only "whitespace", we
902 * will return no tokens. We will never extract more than "num" tokens.
904 * By running a token through the "text_to_ascii()" function, you can allow
905 * that token to include (encoded) whitespace, using "\s" to encode spaces.
907 * We save pointers to the tokens in "tokens", and return the number found.
909 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
916 for (; *s && iswspace(*s); ++s) /* loop */
922 for (t = s; *t && !iswspace(*t); ++t) /* loop */
935 static void load_sound_prefs(void)
940 char *zz[SAMPLE_SOUND_MAX];
942 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
943 for (int i = 0; i < SOUND_MAX; i++) {
944 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
945 int num = tokenize_whitespace(tmp, SAMPLE_SOUND_MAX, zz);
946 for (int j = 0; j < num; j++) {
947 /* Access the sound */
948 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
950 /* Save the sound filename, if it exists */
951 if (check_file(wav_path))
952 sound_file[i][j] = string_make(zz[j]);
957 static void load_music_prefs(void)
962 char *zz[SAMPLE_MUSIC_MAX];
965 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
966 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
967 for (int i = 0; i < MUSIC_BASIC_MAX; i++) {
968 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
969 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
970 for (int j = 0; j < num; j++) {
971 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
972 if (check_file(wav_path))
973 music_file[i][j] = string_make(zz[j]);
977 for (int i = 0; i < current_world_ptr->max_d_idx; i++) {
978 sprintf(key, "dungeon%03d", i);
979 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
980 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
981 for (int j = 0; j < num; j++) {
982 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
983 if (check_file(wav_path))
984 dungeon_music_file[i][j] = string_make(zz[j]);
988 for (int i = 0; i < max_q_idx; i++) {
989 sprintf(key, "quest%03d", i);
990 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
991 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
992 for (int j = 0; j < num; j++) {
993 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
994 if (check_file(wav_path))
995 quest_music_file[i][j] = string_make(zz[j]);
999 for (int i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1001 sprintf(key, "town%03d", i);
1002 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1003 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1004 for (int j = 0; j < num; j++) {
1005 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1006 if (check_file(wav_path))
1007 town_music_file[i][j] = string_make(zz[j]);
1013 * Create the new global palette based on the bitmap palette
1014 * (if any), and the standard 16 entry palette derived from
1015 * "win_clr[]" which is used for the basic 16 Angband colors.
1017 * This function is never called before all windows are ready.
1019 * This function returns FALSE if the new palette could not be
1020 * prepared, which should normally be a fatal error. XXX XXX
1022 * Note that only some machines actually use a "palette".
1024 static int new_palette(void)
1029 LPLOGPALETTE pLogPal;
1030 LPPALETTEENTRY lppe;
1039 HPALETTE hBmPal = infGraph.hPalette;
1041 lppeSize = 256 * sizeof(PALETTEENTRY);
1042 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1043 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1044 if ((nEntries == 0) || (nEntries > 220)) {
1045 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1046 rnfree(lppe, lppeSize);
1051 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1052 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1053 pLogPal->palVersion = 0x300;
1054 pLogPal->palNumEntries = nEntries + 16;
1055 for (i = 0; i < nEntries; i++) {
1056 pLogPal->palPalEntry[i] = lppe[i];
1059 for (i = 0; i < 16; i++) {
1061 p = &(pLogPal->palPalEntry[i + nEntries]);
1062 p->peRed = GetRValue(win_clr[i]);
1063 p->peGreen = GetGValue(win_clr[i]);
1064 p->peBlue = GetBValue(win_clr[i]);
1065 p->peFlags = PC_NOCOLLAPSE;
1069 rnfree(lppe, lppeSize);
1071 HPALETTE hNewPal = CreatePalette(pLogPal);
1073 quit(_("パレットを作成できません!", "Cannot create palette!"));
1075 rnfree(pLogPal, pLogPalSize);
1077 HDC hdc = GetDC(td->w);
1078 SelectPalette(hdc, hNewPal, 0);
1079 i = RealizePalette(hdc);
1080 ReleaseDC(td->w, hdc);
1082 quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1084 for (i = 1; i < MAX_TERM_DATA; i++) {
1087 SelectPalette(hdc, hNewPal, 0);
1088 ReleaseDC(td->w, hdc);
1099 * @brief グラフィクスを初期化する / Initialize graphics
1102 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1103 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1106 static bool init_graphics(void)
1109 BYTE wid, hgt, twid, thgt, ox, oy;
1112 if (arg_graphics == GRAPHICS_ADAM_BOLT) {
1121 ANGBAND_GRAF = "new";
1122 } else if (arg_graphics == GRAPHICS_HENGBAND) {
1131 ANGBAND_GRAF = "ne2";
1140 ANGBAND_GRAF = "old";
1143 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1144 if (!ReadDIB(data[0].w, buf, &infGraph)) {
1145 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1149 infGraph.CellWidth = wid;
1150 infGraph.CellHeight = hgt;
1151 infGraph.TileWidth = twid;
1152 infGraph.TileHeight = thgt;
1153 infGraph.OffsetX = ox;
1154 infGraph.OffsetY = oy;
1156 if (arg_graphics == GRAPHICS_ADAM_BOLT) {
1157 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1158 if (!ReadDIB(data[0].w, buf, &infMask)) {
1159 plog_fmt("Cannot read bitmap file '%s'", buf);
1164 if (arg_graphics == GRAPHICS_HENGBAND) {
1165 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1166 if (!ReadDIB(data[0].w, buf, &infMask)) {
1167 plog_fmt("Cannot read bitmap file '%s'", buf);
1172 if (!new_palette()) {
1173 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1177 current_graphics_mode = arg_graphics;
1178 return (current_graphics_mode);
1184 static void init_music(void)
1186 if (!can_use_music) {
1188 can_use_music = TRUE;
1193 * Hack -- Stop a music
1195 static void stop_music(void)
1197 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1198 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1204 static void init_sound(void)
1206 if (!can_use_sound) {
1208 can_use_sound = TRUE;
1215 static void term_window_resize(term_data *td)
1220 SetWindowPos(td->w, 0, 0, 0, td->size_wid, td->size_hgt, SWP_NOMOVE | SWP_NOZORDER);
1221 InvalidateRect(td->w, NULL, TRUE);
1226 * Force the use of a new "font file" for a term_data.
1227 * This function may be called before the "window" is ready.
1228 * This function returns zero only if everything succeeds.
1229 * Note that the "font name" must be capitalized!!!
1231 static errr term_force_font(term_data *td, concptr path)
1234 DeleteObject(td->font_id);
1237 td->font_id = CreateFontIndirect(&(td->lf));
1238 int wid = td->lf.lfWidth;
1239 int hgt = td->lf.lfHeight;
1248 hdcDesktop = GetDC(HWND_DESKTOP);
1249 hfOld = SelectObject(hdcDesktop, td->font_id);
1250 GetTextMetrics(hdcDesktop, &tm);
1251 SelectObject(hdcDesktop, hfOld);
1252 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1254 wid = tm.tmAveCharWidth;
1265 * Allow the user to change the font for this window.
1267 static void term_change_font(term_data *td)
1270 memset(&cf, 0, sizeof(cf));
1271 cf.lStructSize = sizeof(cf);
1272 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1273 cf.lpLogFont = &(td->lf);
1275 if (!ChooseFont(&cf))
1278 term_force_font(td, NULL);
1280 td->tile_wid = td->font_wid;
1281 td->tile_hgt = td->font_hgt;
1283 term_window_resize(td);
1287 * Allow the user to lock this window.
1289 static void term_window_pos(term_data *td, HWND hWnd) { SetWindowPos(td->w, hWnd, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); }
1291 static void windows_map(player_type *player_ptr);
1294 * Hack -- redraw a term_data
1296 static void term_data_redraw(player_type *player_ptr, term_data *td)
1298 if (td->map_active) {
1299 windows_map(player_ptr);
1303 term_activate(&td->t);
1305 term_activate(term_screen);
1308 void term_inversed_area(HWND hWnd, int x, int y, int w, int h)
1310 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
1311 int tx = td->size_ow1 + x * td->tile_wid;
1312 int ty = td->size_oh1 + y * td->tile_hgt;
1313 int tw = w * td->tile_wid - 1;
1314 int th = h * td->tile_hgt - 1;
1316 HDC hdc = GetDC(hWnd);
1317 HBRUSH myBrush = CreateSolidBrush(RGB(255, 255, 255));
1318 HBRUSH oldBrush = SelectObject(hdc, myBrush);
1319 HPEN oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1321 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
1323 SelectObject(hdc, oldBrush);
1324 SelectObject(hdc, oldPen);
1328 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
1330 static errr term_user_win(int n)
1337 * React to global changes
1339 static errr term_xtra_win_react(player_type *player_ptr)
1342 for (int i = 0; i < 256; i++) {
1343 win_pal[i] = angband_color_table[i][0];
1348 bool change = FALSE;
1349 for (int i = 0; i < 256; i++) {
1350 rv = angband_color_table[i][1];
1351 gv = angband_color_table[i][2];
1352 bv = angband_color_table[i][3];
1353 code = PALETTERGB(rv, gv, bv);
1354 if (win_clr[i] != code) {
1361 (void)new_palette();
1364 if (use_sound != arg_sound) {
1366 use_sound = arg_sound;
1369 if (use_music != arg_music) {
1371 use_music = arg_music;
1375 select_floor_music(player_ptr);
1378 if (use_graphics != arg_graphics) {
1379 if (arg_graphics && !init_graphics()) {
1380 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
1381 arg_graphics = GRAPHICS_NONE;
1384 use_graphics = arg_graphics;
1385 reset_visuals(player_ptr, process_autopick_file_command);
1388 for (int i = 0; i < MAX_TERM_DATA; i++) {
1390 term_data *td = &data[i];
1391 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt)) {
1392 term_activate(&td->t);
1393 term_resize(td->cols, td->rows);
1403 * Process at least one event
1405 static errr term_xtra_win_event(int v)
1409 if (GetMessage(&msg, NULL, 0, 0)) {
1410 TranslateMessage(&msg);
1411 DispatchMessage(&msg);
1414 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
1415 TranslateMessage(&msg);
1416 DispatchMessage(&msg);
1424 * Process all pending events
1426 static errr term_xtra_win_flush(void)
1429 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
1430 TranslateMessage(&msg);
1431 DispatchMessage(&msg);
1438 * Hack -- clear the screen
1440 * Make this more efficient
1442 static errr term_xtra_win_clear(void)
1444 term_data *td = (term_data *)(Term->data);
1447 rc.left = td->size_ow1;
1448 rc.right = rc.left + td->cols * td->tile_wid;
1449 rc.top = td->size_oh1;
1450 rc.bottom = rc.top + td->rows * td->tile_hgt;
1452 HDC hdc = GetDC(td->w);
1453 SetBkColor(hdc, RGB(0, 0, 0));
1454 SelectObject(hdc, td->font_id);
1455 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1463 ReleaseDC(td->w, hdc);
1468 * Hack -- make a noise
1470 static errr term_xtra_win_noise(void)
1472 MessageBeep(MB_ICONASTERISK);
1477 * Hack -- make a sound
1479 static errr term_xtra_win_sound(int v)
1484 if ((v < 0) || (v >= SOUND_MAX))
1488 for (i = 0; i < SAMPLE_SOUND_MAX; i++) {
1489 if (!sound_file[v][i])
1496 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
1497 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
1501 * Hack -- play a music
1503 static errr term_xtra_win_music(int n, int v)
1507 if (n == TERM_XTRA_MUSIC_MUTE) {
1508 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1509 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1515 if (n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX)))
1517 else if (v < 0 || v >= 1000)
1518 return (1); /*!< TODO */
1521 case TERM_XTRA_MUSIC_BASIC:
1522 for (i = 0; i < SAMPLE_MUSIC_MAX; i++)
1523 if (!music_file[v][i])
1526 case TERM_XTRA_MUSIC_DUNGEON:
1527 for (i = 0; i < SAMPLE_MUSIC_MAX; i++)
1528 if (!dungeon_music_file[v][i])
1531 case TERM_XTRA_MUSIC_QUEST:
1532 for (i = 0; i < SAMPLE_MUSIC_MAX; i++)
1533 if (!quest_music_file[v][i])
1536 case TERM_XTRA_MUSIC_TOWN:
1537 for (i = 0; i < SAMPLE_MUSIC_MAX; i++)
1538 if (!town_music_file[v][i])
1548 case TERM_XTRA_MUSIC_BASIC:
1549 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
1551 case TERM_XTRA_MUSIC_DUNGEON:
1552 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
1554 case TERM_XTRA_MUSIC_QUEST:
1555 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
1557 case TERM_XTRA_MUSIC_TOWN:
1558 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
1562 if (current_music_type == n && current_music_id == v) {
1565 current_music_type = n;
1566 current_music_id = v;
1568 mop.lpstrDeviceType = mci_device_type;
1569 mop.lpstrElementName = buf;
1570 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1571 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1572 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
1573 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
1574 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
1579 * Delay for "x" milliseconds
1581 static int term_xtra_win_delay(int v)
1588 * todo z-termに影響があるのでplayer_typeの追加は保留
1589 * Do a "special thing"
1591 static errr term_xtra_win(int n, int v)
1594 case TERM_XTRA_NOISE: {
1595 return (term_xtra_win_noise());
1597 case TERM_XTRA_MUSIC_BASIC:
1598 case TERM_XTRA_MUSIC_DUNGEON:
1599 case TERM_XTRA_MUSIC_QUEST:
1600 case TERM_XTRA_MUSIC_TOWN: {
1601 return (term_xtra_win_music(n, v));
1603 case TERM_XTRA_SOUND: {
1604 return (term_xtra_win_sound(v));
1606 case TERM_XTRA_BORED: {
1607 return (term_xtra_win_event(0));
1609 case TERM_XTRA_EVENT: {
1610 return (term_xtra_win_event(v));
1612 case TERM_XTRA_FLUSH: {
1613 return (term_xtra_win_flush());
1615 case TERM_XTRA_CLEAR: {
1616 return (term_xtra_win_clear());
1618 case TERM_XTRA_REACT: {
1619 return (term_xtra_win_react(p_ptr));
1621 case TERM_XTRA_DELAY: {
1622 return (term_xtra_win_delay(v));
1630 * Low level graphics (Assumes valid input).
1632 * Draw a "cursor" at (x,y), using a "yellow box".
1634 static errr term_curs_win(int x, int y)
1636 term_data *td = (term_data *)(Term->data);
1637 int tile_wid, tile_hgt;
1638 if (td->map_active) {
1639 tile_wid = td->map_tile_wid;
1640 tile_hgt = td->map_tile_hgt;
1642 tile_wid = td->tile_wid;
1643 tile_hgt = td->tile_hgt;
1647 rc.left = x * tile_wid + td->size_ow1;
1648 rc.right = rc.left + tile_wid;
1649 rc.top = y * tile_hgt + td->size_oh1;
1650 rc.bottom = rc.top + tile_hgt;
1652 HDC hdc = GetDC(td->w);
1653 FrameRect(hdc, &rc, hbrYellow);
1654 ReleaseDC(td->w, hdc);
1659 * Low level graphics (Assumes valid input).
1661 * Draw a "big cursor" at (x,y), using a "yellow box".
1663 static errr term_bigcurs_win(int x, int y)
1665 term_data *td = (term_data *)(Term->data);
1666 int tile_wid, tile_hgt;
1667 if (td->map_active) {
1668 term_curs_win(x, y);
1671 tile_wid = td->tile_wid;
1672 tile_hgt = td->tile_hgt;
1676 rc.left = x * tile_wid + td->size_ow1;
1677 rc.right = rc.left + 2 * tile_wid;
1678 rc.top = y * tile_hgt + td->size_oh1;
1679 rc.bottom = rc.top + tile_hgt;
1681 HDC hdc = GetDC(td->w);
1682 FrameRect(hdc, &rc, hbrYellow);
1683 ReleaseDC(td->w, hdc);
1688 * Low level graphics (Assumes valid input).
1690 * Erase a "block" of "n" characters starting at (x,y).
1692 static errr term_wipe_win(int x, int y, int n)
1694 term_data *td = (term_data *)(Term->data);
1696 rc.left = x * td->tile_wid + td->size_ow1;
1697 rc.right = rc.left + n * td->tile_wid;
1698 rc.top = y * td->tile_hgt + td->size_oh1;
1699 rc.bottom = rc.top + td->tile_hgt;
1701 HDC hdc = GetDC(td->w);
1702 SetBkColor(hdc, RGB(0, 0, 0));
1703 SelectObject(hdc, td->font_id);
1707 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1709 ReleaseDC(td->w, hdc);
1714 * Low level graphics. Assumes valid input.
1716 * Draw several ("n") chars, with an attr, at a given location.
1718 * All "graphic" data is handled by "term_pict_win()", below.
1720 * One would think there is a more efficient method for telling a window
1721 * what color it should be using to draw with, but perhaps simply changing
1722 * it every time is not too inefficient.
1724 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
1726 term_data *td = (term_data *)(Term->data);
1727 static HBITMAP WALL;
1728 static HBRUSH myBrush, oldBrush;
1730 static bool init_done = FALSE;
1733 WALL = LoadBitmap(hInstance, AppName);
1734 myBrush = CreatePatternBrush(WALL);
1739 rc.left = x * td->tile_wid + td->size_ow1;
1740 rc.right = rc.left + n * td->tile_wid;
1741 rc.top = y * td->tile_hgt + td->size_oh1;
1742 rc.bottom = rc.top + td->tile_hgt;
1744 HDC hdc = GetDC(td->w);
1745 SetBkColor(hdc, RGB(0, 0, 0));
1747 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
1748 } else if (paletted) {
1749 SetTextColor(hdc, win_clr[a & 0x0F]);
1751 SetTextColor(hdc, win_clr[a]);
1754 SelectObject(hdc, td->font_id);
1756 SetBkMode(hdc, TRANSPARENT);
1758 if (td->bizarre || (td->tile_hgt != td->font_hgt) || (td->tile_wid != td->font_wid)) {
1759 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1763 rc.left += ((td->tile_wid - td->font_wid) / 2);
1764 rc.right = rc.left + td->font_wid;
1765 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
1766 rc.bottom = rc.top + td->font_hgt;
1768 for (int i = 0; i < n; i++) {
1770 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1]) {
1771 rc.right += td->font_wid;
1772 oldBrush = SelectObject(hdc, myBrush);
1773 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1774 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1775 SelectObject(hdc, oldBrush);
1776 SelectObject(hdc, oldPen);
1777 rc.right -= td->font_wid;
1779 rc.left += 2 * td->tile_wid;
1780 rc.right += 2 * td->tile_wid;
1781 } else if (iskanji(*(s + i))) /* 2バイト文字 */
1783 rc.right += td->font_wid;
1784 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 2, NULL);
1785 rc.right -= td->font_wid;
1787 rc.left += 2 * td->tile_wid;
1788 rc.right += 2 * td->tile_wid;
1789 } else if (*(s + i) == 127) {
1790 oldBrush = SelectObject(hdc, myBrush);
1791 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1792 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1793 SelectObject(hdc, oldBrush);
1794 SelectObject(hdc, oldPen);
1795 rc.left += td->tile_wid;
1796 rc.right += td->tile_wid;
1798 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1799 rc.left += td->tile_wid;
1800 rc.right += td->tile_wid;
1803 if (*(s + i) == 127) {
1804 oldBrush = SelectObject(hdc, myBrush);
1805 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1806 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1807 SelectObject(hdc, oldBrush);
1808 SelectObject(hdc, oldPen);
1809 rc.left += td->tile_wid;
1810 rc.right += td->tile_wid;
1812 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1813 rc.left += td->tile_wid;
1814 rc.right += td->tile_wid;
1819 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc, s, n, NULL);
1822 ReleaseDC(td->w, hdc);
1827 * Low level graphics. Assumes valid input.
1829 * Draw an array of "special" attr/char pairs at the given location.
1831 * We use the "term_pict_win()" function for "graphic" data, which are
1832 * encoded by setting the "high-bits" of both the "attr" and the "char"
1833 * data. We use the "attr" to represent the "row" of the main bitmap,
1834 * and the "char" to represent the "col" of the main bitmap. The use
1835 * of this function is induced by the "higher_pict" flag.
1837 * If "graphics" is not available, we simply "wipe" the given grids.
1839 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)
1841 term_data *td = (term_data *)(Term->data);
1844 if (!use_graphics) {
1845 return (term_wipe_win(x, y, n));
1848 TERM_LEN w1 = infGraph.CellWidth;
1849 TERM_LEN h1 = infGraph.CellHeight;
1850 TERM_LEN tw1 = infGraph.TileWidth;
1851 TERM_LEN th1 = infGraph.TileHeight;
1852 TERM_LEN w2, h2, tw2 = 0;
1853 if (td->map_active) {
1854 w2 = td->map_tile_wid;
1855 h2 = td->map_tile_hgt;
1864 TERM_LEN x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
1865 TERM_LEN y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
1866 HDC hdc = GetDC(td->w);
1867 HDC hdcSrc = CreateCompatibleDC(hdc);
1868 HBITMAP hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
1870 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1871 hdcMask = CreateCompatibleDC(hdc);
1872 SelectObject(hdcMask, infMask.hBitmap);
1875 for (i = 0; i < n; i++, x2 += w2) {
1876 TERM_COLOR a = ap[i];
1878 int row = (a & 0x7F);
1879 int col = (c & 0x7F);
1880 TERM_LEN x1 = col * w1;
1881 TERM_LEN y1 = row * h1;
1883 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1884 TERM_LEN x3 = (tcp[i] & 0x7F) * w1;
1885 TERM_LEN y3 = (tap[i] & 0x7F) * h1;
1886 tw2 = tw2 * w1 / tw1;
1888 if ((tw1 == tw2) && (th1 == h2)) {
1889 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
1890 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
1891 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
1895 SetStretchBltMode(hdc, COLORONCOLOR);
1896 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
1897 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
1898 if ((x1 != x3) || (y1 != y3)) {
1899 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
1900 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
1906 if ((w1 == tw2) && (h1 == h2)) {
1907 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
1911 SetStretchBltMode(hdc, COLORONCOLOR);
1912 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
1915 SelectObject(hdcSrc, hbmSrcOld);
1917 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND) {
1918 SelectObject(hdcMask, hbmSrcOld);
1922 ReleaseDC(td->w, hdc);
1926 static void windows_map(player_type *player_ptr)
1928 term_data *td = &data[0];
1933 term_xtra_win_clear();
1934 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
1935 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
1936 td->map_active = TRUE;
1940 TERM_LEN max_x = player_ptr->current_floor_ptr->width;
1941 TERM_LEN max_y = player_ptr->current_floor_ptr->height;
1944 for (TERM_LEN x = min_x; x < max_x; x++) {
1945 for (TERM_LEN y = min_y; y < max_y; y++) {
1948 map_info(player_ptr, y, x, &a, (char *)&c, &ta, (char *)&tc);
1949 if ((a & 0x80) && (c & 0x80)) {
1950 term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
1955 term_curs_win(player_ptr->x - min_x, player_ptr->y - min_y);
1956 term_inkey(&c, TRUE, TRUE);
1958 td->map_active = FALSE;
1959 term_xtra_win_clear();
1964 * Create and initialize a "term_data" given a title
1966 static void term_data_link(term_data *td)
1969 term_init(t, td->cols, td->rows, td->keys);
1970 t->soft_cursor = TRUE;
1971 t->higher_pict = TRUE;
1972 t->attr_blank = TERM_WHITE;
1973 t->char_blank = ' ';
1974 t->user_hook = term_user_win;
1975 t->xtra_hook = term_xtra_win;
1976 t->curs_hook = term_curs_win;
1977 t->bigcurs_hook = term_bigcurs_win;
1978 t->wipe_hook = term_wipe_win;
1979 t->text_hook = term_text_win;
1980 t->pict_hook = term_pict_win;
1981 t->data = (vptr)(td);
1985 * Create the windows
1987 * First, instantiate the "default" values, then read the "ini_file"
1988 * to over-ride selected values, then create the windows, and fonts.
1990 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
1991 * must make active to realize the palette.
1993 static void init_windows(void)
1997 WIPE(td, term_data);
2001 td->s = angband_term_name[0];
2017 for (int i = 1; i < MAX_TERM_DATA; i++) {
2019 WIPE(td, term_data);
2020 td->s = angband_term_name[i];
2024 td->visible = FALSE;
2029 td->pos_x = (7 - i) * 30;
2030 td->pos_y = (7 - i) * 20;
2037 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_VISIBLE);
2041 for (int i = 1; i < MAX_TERM_DATA; i++) {
2043 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2044 td->dwExStyle = (WS_EX_TOOLWINDOW);
2047 for (int i = 0; i < MAX_TERM_DATA; i++) {
2049 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2050 td->lf.lfCharSet = DEFAULT_CHARSET;
2051 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2052 term_force_font(td, NULL);
2054 td->tile_wid = td->font_wid;
2056 td->tile_hgt = td->font_hgt;
2059 term_window_resize(td);
2062 for (int i = MAX_TERM_DATA - 1; i >= 1; --i) {
2067 = CreateWindowEx(td->dwExStyle, AngList, td->s, td->dwStyle, td->pos_x, td->pos_y, td->size_wid, td->size_hgt, HWND_DESKTOP, NULL, hInstance, NULL);
2070 quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
2073 td->size_hack = TRUE;
2074 ShowWindow(td->w, SW_SHOW);
2075 td->size_hack = FALSE;
2079 angband_term[i] = &td->t;
2082 /* Activate the window */
2083 SetActiveWindow(td->w);
2086 if (data[i].posfix) {
2087 term_window_pos(&data[i], HWND_TOPMOST);
2089 term_window_pos(&data[i], td->w);
2095 td->w = CreateWindowEx(td->dwExStyle, AppName, td->s, td->dwStyle, td->pos_x, td->pos_y, td->size_wid, td->size_hgt, HWND_DESKTOP, NULL, hInstance, NULL);
2098 quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
2101 angband_term[0] = &td->t;
2102 normsize.x = td->cols;
2103 normsize.y = td->rows;
2106 ShowWindow(td->w, SW_SHOWMAXIMIZED);
2108 ShowWindow(td->w, SW_SHOW);
2110 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2111 (void)new_palette();
2112 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
2113 (void)term_xtra_win_flush();
2119 static void setup_menus(void)
2121 HMENU hm = GetMenu(data[0].w);
2122 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2123 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2124 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2125 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2126 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2128 if (!current_world_ptr->character_generated) {
2129 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
2130 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
2133 if (current_world_ptr->character_generated) {
2134 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_ENABLED);
2137 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_ENABLED);
2138 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_ENABLED);
2140 for (int i = 0; i < MAX_TERM_DATA; i++) {
2141 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2142 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i, (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
2143 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_ENABLED);
2146 for (int i = 0; i < MAX_TERM_DATA; i++) {
2147 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2149 if (data[i].visible) {
2150 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2154 for (int i = 0; i < MAX_TERM_DATA; i++) {
2155 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2156 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i, (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
2157 if (data[i].visible) {
2158 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_ENABLED);
2162 for (int i = 0; i < MAX_TERM_DATA; i++) {
2163 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2164 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i, (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
2165 if (data[i].visible) {
2166 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_ENABLED);
2170 for (int i = 0; i < MAX_TERM_DATA; i++) {
2171 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2172 if (data[i].visible) {
2173 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
2177 for (int i = 0; i < MAX_TERM_DATA; i++) {
2178 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2179 if (data[i].visible) {
2180 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
2184 for (int i = 0; i < MAX_TERM_DATA; i++) {
2185 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2186 if (data[i].visible) {
2187 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2191 for (int i = 0; i < MAX_TERM_DATA; i++) {
2192 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2194 if (data[i].visible) {
2195 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2199 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2200 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2201 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2202 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2203 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2206 EnableMenuItem(hm, IDM_OPTIONS_SAVER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2209 if (use_graphics != GRAPHICS_NONE)
2210 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
2212 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2214 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
2215 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
2216 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
2217 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS, (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
2218 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE, (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
2219 CheckMenuItem(hm, IDM_OPTIONS_MUSIC, (arg_music ? MF_CHECKED : MF_UNCHECKED));
2220 CheckMenuItem(hm, IDM_OPTIONS_SOUND, (arg_sound ? MF_CHECKED : MF_UNCHECKED));
2221 CheckMenuItem(hm, IDM_OPTIONS_BG, (use_bg ? MF_CHECKED : MF_UNCHECKED));
2224 CheckMenuItem(hm, IDM_OPTIONS_SAVER, (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
2226 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
2227 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
2228 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
2229 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
2230 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
2231 EnableMenuItem(hm, IDM_OPTIONS_SAVER, MF_BYCOMMAND | MF_ENABLED);
2235 * Check for double clicked (or dragged) savefile
2237 * Apparently, Windows copies the entire filename into the first
2238 * piece of the "command line string". Perhaps we should extract
2239 * the "basename" of that filename and append it to the "save" dir.
2241 static void check_for_save_file(player_type *player_ptr, LPSTR cmd_line)
2248 strcat(savefile, s);
2249 validate_file(savefile);
2250 game_in_progress = TRUE;
2251 play_game(player_ptr, FALSE);
2255 * Process a menu command
2257 static void process_menus(player_type *player_ptr, WORD wCmd)
2262 case IDM_FILE_NEW: {
2264 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2265 } else if (game_in_progress) {
2266 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
2268 game_in_progress = TRUE;
2270 play_game(player_ptr, TRUE);
2276 case IDM_FILE_OPEN: {
2278 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2279 } else if (game_in_progress) {
2280 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
2282 memset(&ofn, 0, sizeof(ofn));
2283 ofn.lStructSize = sizeof(ofn);
2284 ofn.hwndOwner = data[0].w;
2285 ofn.lpstrFilter = "Save Files (*.)\0*\0";
2286 ofn.nFilterIndex = 1;
2287 ofn.lpstrFile = savefile;
2288 ofn.nMaxFile = 1024;
2289 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
2290 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
2292 if (GetOpenFileName(&ofn)) {
2293 validate_file(savefile);
2294 game_in_progress = TRUE;
2296 play_game(player_ptr, FALSE);
2303 case IDM_FILE_SAVE: {
2304 if (game_in_progress && current_world_ptr->character_generated) {
2306 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
2311 do_cmd_save_game(player_ptr, FALSE);
2313 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
2318 case IDM_FILE_EXIT: {
2319 if (game_in_progress && current_world_ptr->character_generated) {
2321 plog(_("今は終了できません。", "You may not do that right now."));
2326 forget_lite(player_ptr->current_floor_ptr);
2327 forget_view(player_ptr->current_floor_ptr);
2328 clear_mon_lite(player_ptr->current_floor_ptr);
2330 term_key_push(SPECIAL_KEY_QUIT);
2337 case IDM_FILE_SCORE: {
2339 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
2340 highscore_fd = fd_open(buf, O_RDONLY);
2341 if (highscore_fd < 0) {
2342 msg_print("Score file unavailable.");
2346 display_scores_aux(0, MAX_HISCORES, -1, NULL);
2347 (void)fd_close(highscore_fd);
2355 case IDM_FILE_MOVIE: {
2357 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2358 } else if (game_in_progress) {
2359 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
2361 memset(&ofn, 0, sizeof(ofn));
2362 ofn.lStructSize = sizeof(ofn);
2363 ofn.hwndOwner = data[0].w;
2364 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
2365 ofn.nFilterIndex = 1;
2366 ofn.lpstrFile = savefile;
2367 ofn.nMaxFile = 1024;
2368 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
2369 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2371 if (GetOpenFileName(&ofn)) {
2372 prepare_browse_movie_aux(savefile);
2373 play_game(player_ptr, FALSE);
2381 case IDM_WINDOW_VIS_0: {
2382 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
2385 case IDM_WINDOW_VIS_1:
2386 case IDM_WINDOW_VIS_2:
2387 case IDM_WINDOW_VIS_3:
2388 case IDM_WINDOW_VIS_4:
2389 case IDM_WINDOW_VIS_5:
2390 case IDM_WINDOW_VIS_6:
2391 case IDM_WINDOW_VIS_7: {
2392 int i = wCmd - IDM_WINDOW_VIS_0;
2393 if ((i < 0) || (i >= MAX_TERM_DATA))
2399 ShowWindow(td->w, SW_SHOW);
2400 term_data_redraw(player_ptr, td);
2402 td->visible = FALSE;
2404 ShowWindow(td->w, SW_HIDE);
2409 case IDM_WINDOW_FONT_0:
2410 case IDM_WINDOW_FONT_1:
2411 case IDM_WINDOW_FONT_2:
2412 case IDM_WINDOW_FONT_3:
2413 case IDM_WINDOW_FONT_4:
2414 case IDM_WINDOW_FONT_5:
2415 case IDM_WINDOW_FONT_6:
2416 case IDM_WINDOW_FONT_7: {
2417 int i = wCmd - IDM_WINDOW_FONT_0;
2418 if ((i < 0) || (i >= MAX_TERM_DATA))
2422 term_change_font(td);
2425 case IDM_WINDOW_POS_1:
2426 case IDM_WINDOW_POS_2:
2427 case IDM_WINDOW_POS_3:
2428 case IDM_WINDOW_POS_4:
2429 case IDM_WINDOW_POS_5:
2430 case IDM_WINDOW_POS_6:
2431 case IDM_WINDOW_POS_7: {
2432 int i = wCmd - IDM_WINDOW_POS_0;
2433 if ((i < 0) || (i >= MAX_TERM_DATA))
2437 if (!td->posfix && td->visible) {
2439 term_window_pos(td, HWND_TOPMOST);
2442 term_window_pos(td, data[0].w);
2447 case IDM_WINDOW_BIZ_0:
2448 case IDM_WINDOW_BIZ_1:
2449 case IDM_WINDOW_BIZ_2:
2450 case IDM_WINDOW_BIZ_3:
2451 case IDM_WINDOW_BIZ_4:
2452 case IDM_WINDOW_BIZ_5:
2453 case IDM_WINDOW_BIZ_6:
2454 case IDM_WINDOW_BIZ_7: {
2455 int i = wCmd - IDM_WINDOW_BIZ_0;
2456 if ((i < 0) || (i >= MAX_TERM_DATA))
2460 td->bizarre = !td->bizarre;
2462 term_window_resize(td);
2465 case IDM_WINDOW_I_WID_0:
2466 case IDM_WINDOW_I_WID_1:
2467 case IDM_WINDOW_I_WID_2:
2468 case IDM_WINDOW_I_WID_3:
2469 case IDM_WINDOW_I_WID_4:
2470 case IDM_WINDOW_I_WID_5:
2471 case IDM_WINDOW_I_WID_6:
2472 case IDM_WINDOW_I_WID_7: {
2473 int i = wCmd - IDM_WINDOW_I_WID_0;
2474 if ((i < 0) || (i >= MAX_TERM_DATA))
2480 term_window_resize(td);
2483 case IDM_WINDOW_D_WID_0:
2484 case IDM_WINDOW_D_WID_1:
2485 case IDM_WINDOW_D_WID_2:
2486 case IDM_WINDOW_D_WID_3:
2487 case IDM_WINDOW_D_WID_4:
2488 case IDM_WINDOW_D_WID_5:
2489 case IDM_WINDOW_D_WID_6:
2490 case IDM_WINDOW_D_WID_7: {
2491 int i = wCmd - IDM_WINDOW_D_WID_0;
2492 if ((i < 0) || (i >= MAX_TERM_DATA))
2498 term_window_resize(td);
2501 case IDM_WINDOW_I_HGT_0:
2502 case IDM_WINDOW_I_HGT_1:
2503 case IDM_WINDOW_I_HGT_2:
2504 case IDM_WINDOW_I_HGT_3:
2505 case IDM_WINDOW_I_HGT_4:
2506 case IDM_WINDOW_I_HGT_5:
2507 case IDM_WINDOW_I_HGT_6:
2508 case IDM_WINDOW_I_HGT_7: {
2509 int i = wCmd - IDM_WINDOW_I_HGT_0;
2510 if ((i < 0) || (i >= MAX_TERM_DATA))
2516 term_window_resize(td);
2519 case IDM_WINDOW_D_HGT_0:
2520 case IDM_WINDOW_D_HGT_1:
2521 case IDM_WINDOW_D_HGT_2:
2522 case IDM_WINDOW_D_HGT_3:
2523 case IDM_WINDOW_D_HGT_4:
2524 case IDM_WINDOW_D_HGT_5:
2525 case IDM_WINDOW_D_HGT_6:
2526 case IDM_WINDOW_D_HGT_7: {
2527 int i = wCmd - IDM_WINDOW_D_HGT_0;
2528 if ((i < 0) || (i >= MAX_TERM_DATA))
2534 term_window_resize(td);
2537 case IDM_OPTIONS_NO_GRAPHICS: {
2539 plog("You may not do that right now.");
2543 if (arg_graphics != GRAPHICS_NONE) {
2544 arg_graphics = GRAPHICS_NONE;
2545 term_xtra_win_react(player_ptr);
2546 term_key_push(KTRL('R'));
2551 case IDM_OPTIONS_OLD_GRAPHICS: {
2553 plog("You may not do that right now.");
2557 if (arg_graphics != GRAPHICS_ORIGINAL) {
2558 arg_graphics = GRAPHICS_ORIGINAL;
2559 term_xtra_win_react(player_ptr);
2560 term_key_push(KTRL('R'));
2565 case IDM_OPTIONS_NEW_GRAPHICS: {
2567 plog("You may not do that right now.");
2571 if (arg_graphics != GRAPHICS_ADAM_BOLT) {
2572 arg_graphics = GRAPHICS_ADAM_BOLT;
2573 term_xtra_win_react(player_ptr);
2574 term_key_push(KTRL('R'));
2579 case IDM_OPTIONS_NEW2_GRAPHICS: {
2581 plog("You may not do that right now.");
2585 if (arg_graphics != GRAPHICS_HENGBAND) {
2586 arg_graphics = GRAPHICS_HENGBAND;
2587 term_xtra_win_react(player_ptr);
2588 term_key_push(KTRL('R'));
2593 case IDM_OPTIONS_BIGTILE: {
2596 plog("You may not do that right now.");
2600 arg_bigtile = !arg_bigtile;
2601 term_activate(&td->t);
2602 term_resize(td->cols, td->rows);
2603 InvalidateRect(td->w, NULL, TRUE);
2606 case IDM_OPTIONS_MUSIC: {
2608 plog("You may not do that right now.");
2612 arg_music = !arg_music;
2613 term_xtra_win_react(player_ptr);
2614 term_key_push(KTRL('R'));
2617 case IDM_OPTIONS_SOUND: {
2619 plog("You may not do that right now.");
2623 arg_sound = !arg_sound;
2624 term_xtra_win_react(player_ptr);
2625 term_key_push(KTRL('R'));
2628 case IDM_OPTIONS_BG: {
2630 plog("You may not do that right now.");
2636 term_xtra_win_react(player_ptr);
2637 term_key_push(KTRL('R'));
2640 case IDM_OPTIONS_OPEN_BG: {
2642 plog("You may not do that right now.");
2646 memset(&ofn, 0, sizeof(ofn));
2647 ofn.lStructSize = sizeof(ofn);
2648 ofn.hwndOwner = data[0].w;
2649 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
2650 ofn.nFilterIndex = 1;
2651 ofn.lpstrFile = bg_bitmap_file;
2652 ofn.nMaxFile = 1023;
2653 ofn.lpstrInitialDir = NULL;
2654 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
2655 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
2657 if (GetOpenFileName(&ofn)) {
2662 term_xtra_win_react(player_ptr);
2663 term_key_push(KTRL('R'));
2666 case IDM_DUMP_SCREEN_HTML: {
2667 static char buf[1024] = "";
2668 memset(&ofn, 0, sizeof(ofn));
2669 ofn.lStructSize = sizeof(ofn);
2670 ofn.hwndOwner = data[0].w;
2671 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
2672 ofn.nFilterIndex = 1;
2673 ofn.lpstrFile = buf;
2674 ofn.nMaxFile = 1023;
2675 ofn.lpstrDefExt = "html";
2676 ofn.lpstrInitialDir = NULL;
2677 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
2678 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
2680 if (GetSaveFileName(&ofn)) {
2681 do_cmd_save_screen_html_aux(buf, 0);
2686 case IDM_OPTIONS_SAVER: {
2688 DestroyWindow(hwndSaver);
2693 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass", "Angband Screensaver", WS_POPUP | WS_MAXIMIZE | WS_VISIBLE, 0, 0,
2694 GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL);
2697 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2699 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
2704 case IDM_OPTIONS_MAP: {
2705 windows_map(player_ptr);
2709 case IDM_HELP_CONTENTS: {
2712 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
2713 if (check_file(tmp)) {
2714 sprintf(buf, "winhelp.exe %s", tmp);
2715 WinExec(buf, SW_NORMAL);
2719 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
2720 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
2726 static bool process_keydown(WPARAM wParam, LPARAM lParam)
2732 if (GetKeyState(VK_CONTROL) & 0x8000)
2734 if (GetKeyState(VK_SHIFT) & 0x8000)
2736 if (GetKeyState(VK_MENU) & 0x8000)
2739 term_no_press = (ma) ? TRUE : FALSE;
2740 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)])) {
2741 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
2742 bool numpad = FALSE;
2752 int i = LOBYTE(HIWORD(lParam));
2756 term_no_press = TRUE;
2775 term_no_press = TRUE;
2793 term_keypress(hexsym[i / 16]);
2794 term_keypress(hexsym[i % 16]);
2804 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
2806 LRESULT PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2810 td = (term_data *)GetWindowLong(hWnd, 0);
2814 SetWindowLong(hWnd, 0, (LONG)(my_td));
2818 mop.dwCallback = (DWORD)hWnd;
2821 case WM_GETMINMAXINFO: {
2825 lpmmi = (MINMAXINFO *)lParam;
2829 rc.left = rc.top = 0;
2830 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
2831 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
2833 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
2835 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
2836 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
2841 BeginPaint(hWnd, &ps);
2843 term_data_redraw(p_ptr, td);
2844 EndPaint(hWnd, &ps);
2845 ValidateRect(hWnd, NULL);
2848 case MM_MCINOTIFY: {
2849 if (wParam == MCI_NOTIFY_SUCCESSFUL) {
2850 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
2851 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
2858 if (process_keydown(wParam, lParam))
2864 term_no_press = FALSE;
2866 term_keypress(wParam);
2869 case WM_LBUTTONDOWN: {
2870 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
2871 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
2877 case WM_LBUTTONUP: {
2880 TERM_LEN dx = abs(oldx - mousex) + 1;
2881 TERM_LEN dy = abs(oldy - mousey) + 1;
2882 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
2883 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
2889 int sz = (dx + 3) * dy;
2891 int sz = (dx + 2) * dy;
2893 hGlobal = GlobalAlloc(GHND, sz + 1);
2894 if (hGlobal == NULL)
2896 lpStr = (LPSTR)GlobalLock(hGlobal);
2898 for (int i = 0; i < dy; i++) {
2901 char **scr = data[0].t.scr->c;
2903 C_MAKE(s, (dx + 1), char);
2904 strncpy(s, &scr[oy + i][ox], dx);
2907 if (iskanji(scr[oy + i][ox - 1]))
2911 if (ox + dx < data[0].cols) {
2912 if (iskanji(scr[oy + i][ox + dx - 1]))
2916 for (int j = 0; j < dx; j++) {
2922 for (int j = 0; j < dx; j++) {
2923 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
2932 GlobalUnlock(hGlobal);
2933 if (OpenClipboard(hWnd) == 0) {
2934 GlobalFree(hGlobal);
2939 SetClipboardData(CF_TEXT, hGlobal);
2944 case WM_MOUSEMOVE: {
2949 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
2950 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
2954 dx = abs(oldx - mousex) + 1;
2955 dy = abs(oldy - mousey) + 1;
2956 ox = (oldx > mousex) ? mousex : oldx;
2957 oy = (oldy > mousey) ? mousey : oldy;
2958 term_inversed_area(hWnd, ox, oy, dx, dy);
2963 dx = abs(cx - mousex) + 1;
2964 dy = abs(cy - mousey) + 1;
2965 ox = (cx > mousex) ? mousex : cx;
2966 oy = (cy > mousey) ? mousey : cy;
2967 term_inversed_area(hWnd, ox, oy, dx, dy);
2978 if (!game_in_progress || !current_world_ptr->character_generated) {
2984 plog(_("今は終了できません。", "You may not do that right now."));
2989 forget_lite(p_ptr->current_floor_ptr);
2990 forget_view(p_ptr->current_floor_ptr);
2991 clear_mon_lite(p_ptr->current_floor_ptr);
2992 term_key_push(SPECIAL_KEY_QUIT);
2995 case WM_QUERYENDSESSION: {
2996 if (!game_in_progress || !current_world_ptr->character_generated) {
3003 p_ptr->is_dead = FALSE;
3004 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
3006 p_ptr->panic_save = 1;
3007 signals_ignore_tstp();
3008 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
3009 (void)save_player(p_ptr);
3018 process_menus(p_ptr, LOWORD(wParam));
3029 // todo 二重のswitch文。後で分割する.
3031 case SIZE_MINIMIZED: {
3032 for (int i = 1; i < MAX_TERM_DATA; i++) {
3033 if (data[i].visible)
3034 ShowWindow(data[i].w, SW_HIDE);
3039 case SIZE_MAXIMIZED:
3040 case SIZE_RESTORED: {
3041 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
3042 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
3043 if ((td->cols != cols) || (td->rows != rows)) {
3046 if (!IsZoomed(td->w) && !IsIconic(td->w)) {
3047 normsize.x = td->cols;
3048 normsize.y = td->rows;
3051 term_activate(&td->t);
3052 term_resize(td->cols, td->rows);
3053 InvalidateRect(td->w, NULL, TRUE);
3056 td->size_hack = TRUE;
3057 for (int i = 1; i < MAX_TERM_DATA; i++) {
3058 if (data[i].visible)
3059 ShowWindow(data[i].w, SW_SHOW);
3062 td->size_hack = FALSE;
3070 case WM_PALETTECHANGED: {
3071 if ((HWND)wParam == hWnd)
3074 case WM_QUERYNEWPALETTE: {
3078 HDC hdc = GetDC(hWnd);
3079 SelectPalette(hdc, hPal, FALSE);
3080 int i = RealizePalette(hdc);
3082 InvalidateRect(hWnd, NULL, TRUE);
3084 ReleaseDC(hWnd, hdc);
3088 if (!wParam || HIWORD(lParam))
3091 for (int i = 1; i < MAX_TERM_DATA; i++) {
3092 if (!data[i].posfix)
3093 term_window_pos(&data[i], hWnd);
3099 case WM_ACTIVATEAPP: {
3100 if (IsIconic(td->w))
3103 for (int i = 1; i < MAX_TERM_DATA; i++) {
3104 if (data[i].visible) {
3105 if (wParam == TRUE) {
3106 ShowWindow(data[i].w, SW_SHOW);
3108 ShowWindow(data[i].w, SW_HIDE);
3115 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3119 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
3121 LRESULT PASCAL AngbandListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3125 td = (term_data *)GetWindowLong(hWnd, 0);
3129 SetWindowLong(hWnd, 0, (LONG)(my_td));
3135 case WM_GETMINMAXINFO: {
3139 lpmmi = (MINMAXINFO *)lParam;
3143 rc.left = rc.top = 0;
3144 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
3145 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
3147 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3148 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
3149 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
3160 td->size_hack = TRUE;
3162 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
3163 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
3164 if ((td->cols != cols) || (td->rows != rows)) {
3165 term *old_term = Term;
3168 term_activate(&td->t);
3169 term_resize(td->cols, td->rows);
3170 term_activate(old_term);
3171 InvalidateRect(td->w, NULL, TRUE);
3172 p_ptr->window = 0xFFFFFFFF;
3173 handle_stuff(p_ptr);
3176 td->size_hack = FALSE;
3180 BeginPaint(hWnd, &ps);
3182 term_data_redraw(p_ptr, td);
3183 EndPaint(hWnd, &ps);
3188 if (process_keydown(wParam, lParam))
3195 term_no_press = FALSE;
3197 term_keypress(wParam);
3200 case WM_PALETTECHANGED: {
3201 if ((HWND)wParam == hWnd)
3204 case WM_QUERYNEWPALETTE: {
3208 HDC hdc = GetDC(hWnd);
3209 SelectPalette(hdc, hPal, FALSE);
3210 int i = RealizePalette(hdc);
3212 InvalidateRect(hWnd, NULL, TRUE);
3214 ReleaseDC(hWnd, hdc);
3217 case WM_NCLBUTTONDOWN: {
3219 if (wParam == HTCLOSE)
3221 #endif /* HTCLOSE */
3223 if (wParam == HTSYSMENU) {
3225 td->visible = FALSE;
3226 ShowWindow(td->w, SW_HIDE);
3236 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3239 LRESULT PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3241 static int iMouse = 0;
3242 static WORD xMouse = 0;
3243 static WORD yMouse = 0;
3250 case WM_SETCURSOR: {
3255 case WM_LBUTTONDOWN:
3256 case WM_MBUTTONDOWN:
3257 case WM_RBUTTONDOWN:
3259 SendMessage(hWnd, WM_CLOSE, 0, 0);
3262 case WM_MOUSEMOVE: {
3264 int dx = LOWORD(lParam) - xMouse;
3265 int dy = HIWORD(lParam) - yMouse;
3272 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS)) {
3273 SendMessage(hWnd, WM_CLOSE, 0, 0);
3278 xMouse = LOWORD(lParam);
3279 yMouse = HIWORD(lParam);
3284 DestroyWindow(hwndSaver);
3290 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3294 * Display warning message (see "z-util.c")
3296 static void hack_plog(concptr str)
3300 MessageBox(NULL, str, "警告!", MB_ICONEXCLAMATION | MB_OK);
3302 MessageBox(NULL, str, "Warning", MB_ICONEXCLAMATION | MB_OK);
3308 * Display error message and quit (see "z-util.c")
3310 static void hack_quit(concptr str)
3314 MessageBox(NULL, str, "エラー!", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3316 MessageBox(NULL, str, "Error", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3320 UnregisterClass(AppName, hInstance);
3328 * Display warning message (see "z-util.c")
3330 static void hook_plog(concptr str)
3334 MessageBox(data[0].w, str, "警告!", MB_ICONEXCLAMATION | MB_OK);
3336 MessageBox(data[0].w, str, "Warning", MB_ICONEXCLAMATION | MB_OK);
3342 * Display error message and quit (see "z-util.c")
3344 static void hook_quit(concptr str)
3348 MessageBox(data[0].w, str, "エラー!", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3350 MessageBox(data[0].w, str, "Error", MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3355 for (int i = MAX_TERM_DATA - 1; i >= 0; --i) {
3356 term_force_font(&data[i], NULL);
3357 if (data[i].font_want)
3358 string_free(data[i].font_want);
3360 DestroyWindow(data[i].w);
3364 if (infGraph.hPalette)
3365 DeleteObject(infGraph.hPalette);
3366 if (infGraph.hBitmap)
3367 DeleteObject(infGraph.hBitmap);
3368 if (infMask.hPalette)
3369 DeleteObject(infMask.hPalette);
3370 if (infMask.hBitmap)
3371 DeleteObject(infMask.hBitmap);
3373 DeleteObject(hbrYellow);
3379 UnregisterClass(AppName, hInstance);
3389 static void init_stuff(void)
3392 GetModuleFileName(hInstance, path, 512);
3394 strcpy(path + strlen(path) - 4, ".INI");
3395 ini_file = string_make(path);
3396 int i = strlen(path);
3398 for (; i > 0; i--) {
3399 if (path[i] == '\\') {
3404 strcpy(path + i + 1, "lib\\");
3405 validate_dir(path, TRUE);
3406 init_file_paths(path);
3407 validate_dir(ANGBAND_DIR_APEX, FALSE);
3408 validate_dir(ANGBAND_DIR_BONE, FALSE);
3409 if (!check_dir(ANGBAND_DIR_EDIT)) {
3410 validate_dir(ANGBAND_DIR_DATA, TRUE);
3412 validate_dir(ANGBAND_DIR_DATA, FALSE);
3415 validate_dir(ANGBAND_DIR_FILE, TRUE);
3416 validate_dir(ANGBAND_DIR_HELP, FALSE);
3417 validate_dir(ANGBAND_DIR_INFO, FALSE);
3418 validate_dir(ANGBAND_DIR_PREF, TRUE);
3419 validate_dir(ANGBAND_DIR_SAVE, FALSE);
3420 validate_dir(ANGBAND_DIR_USER, TRUE);
3421 validate_dir(ANGBAND_DIR_XTRA, TRUE);
3422 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
3424 validate_file(path);
3425 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
3426 ANGBAND_DIR_XTRA_GRAF = string_make(path);
3427 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
3429 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
3430 ANGBAND_DIR_XTRA_SOUND = string_make(path);
3431 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
3433 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
3434 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
3435 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
3437 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
3438 ANGBAND_DIR_XTRA_HELP = string_make(path);
3442 * todo よく見るとhMutexはちゃんと使われていない……?
3443 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
3445 static bool is_already_running(void)
3448 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
3449 if (GetLastError() == ERROR_ALREADY_EXISTS) {
3457 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
3459 int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
3465 setlocale(LC_ALL, "ja_JP");
3468 if (is_already_running()) {
3470 NULL, _("変愚蛮怒はすでに起動しています。", "Hengband is already running."), _("エラー!", "Error"), MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3474 if (hPrevInst == NULL) {
3475 wc.style = CS_CLASSDC;
3476 wc.lpfnWndProc = AngbandWndProc;
3479 wc.hInstance = hInst;
3480 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
3481 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
3482 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
3483 wc.lpszMenuName = AppName;
3484 wc.lpszClassName = AppName;
3486 if (!RegisterClass(&wc))
3489 wc.lpfnWndProc = AngbandListProc;
3490 wc.lpszMenuName = NULL;
3491 wc.lpszClassName = AngList;
3493 if (!RegisterClass(&wc))
3496 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
3497 wc.lpfnWndProc = AngbandSaverProc;
3499 wc.lpszMenuName = NULL;
3500 wc.lpszClassName = "WindowsScreenSaverClass";
3502 if (!RegisterClass(&wc))
3506 plog_aux = hack_plog;
3507 quit_aux = hack_quit;
3508 core_aux = hack_quit;
3511 for (int i = 0; special_key_list[i]; ++i) {
3512 special_key[special_key_list[i]] = TRUE;
3515 for (int i = 0; ignore_key_list[i]; ++i) {
3516 ignore_key[ignore_key_list[i]] = TRUE;
3520 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
3521 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
3522 ReleaseDC(NULL, hdc);
3524 for (int i = 0; i < 256; i++) {
3525 byte rv = angband_color_table[i][1];
3526 byte gv = angband_color_table[i][2];
3527 byte bv = angband_color_table[i][3];
3528 win_clr[i] = PALETTERGB(rv, gv, bv);
3529 angband_color_table[i][0] = win_pal[i];
3535 plog_aux = hook_plog;
3536 quit_aux = hook_quit;
3537 core_aux = hook_quit;
3539 ANGBAND_SYS = "win";
3540 if (7 != GetKeyboardType(0))
3541 ANGBAND_KEYBOARD = "0";
3543 switch (GetKeyboardType(1)) {
3551 ANGBAND_KEYBOARD = "NEC98";
3555 ANGBAND_KEYBOARD = "JAPAN";
3560 term_activate(term_screen);
3561 init_angband(p_ptr, process_autopick_file_command);
3564 if (lpCmdLine[0] == '-') {
3565 switch (lpCmdLine[1]) {
3570 chuukei_server = TRUE;
3571 if (connect_chuukei_server(&lpCmdLine[2]) < 0) {
3572 msg_print("connect fail");
3575 msg_print("connect");
3584 chuukei_client = TRUE;
3585 connect_chuukei_server(&lpCmdLine[2]);
3586 play_game(player_ptr, FALSE);
3594 prepare_browse_movie(&lpCmdLine[2]);
3595 play_game(player_ptr, FALSE);
3604 if (!chuukei_server)
3605 check_for_save_file(lpCmdLine);
3607 check_for_save_file(p_ptr, lpCmdLine);
3610 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
3612 while (GetMessage(&msg, NULL, 0, 0)) {
3613 TranslateMessage(&msg);
3614 DispatchMessage(&msg);
3620 #endif /* WINDOWS */