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 "system/angband-version.h"
115 #include "system/angband.h"
116 #include "system/system-variables.h"
117 #include "term/gameterm.h"
118 #include "term/term-color-types.h"
119 #include "util/angband-files.h"
120 #include "view/display-main-window.h"
121 #include "world/world.h"
127 #include "term/z-term.h"
129 #include "dungeon/dungeon.h"
132 * Available graphic modes
134 #define GRAPHICS_NONE 0
135 #define GRAPHICS_ORIGINAL 1
136 #define GRAPHICS_ADAM_BOLT 2
137 #define GRAPHICS_HENGBAND 3
140 * Menu constants -- see "ANGBAND.RC"
142 #define IDM_FILE_NEW 100
143 #define IDM_FILE_OPEN 101
144 #define IDM_FILE_SAVE 110
145 #define IDM_FILE_SCORE 120
146 #define IDM_FILE_MOVIE 121
147 #define IDM_FILE_EXIT 130
149 #define IDM_WINDOW_VIS_0 200
150 #define IDM_WINDOW_VIS_1 201
151 #define IDM_WINDOW_VIS_2 202
152 #define IDM_WINDOW_VIS_3 203
153 #define IDM_WINDOW_VIS_4 204
154 #define IDM_WINDOW_VIS_5 205
155 #define IDM_WINDOW_VIS_6 206
156 #define IDM_WINDOW_VIS_7 207
158 #define IDM_WINDOW_FONT_0 210
159 #define IDM_WINDOW_FONT_1 211
160 #define IDM_WINDOW_FONT_2 212
161 #define IDM_WINDOW_FONT_3 213
162 #define IDM_WINDOW_FONT_4 214
163 #define IDM_WINDOW_FONT_5 215
164 #define IDM_WINDOW_FONT_6 216
165 #define IDM_WINDOW_FONT_7 217
167 #define IDM_WINDOW_POS_0 220
168 #define IDM_WINDOW_POS_1 221
169 #define IDM_WINDOW_POS_2 222
170 #define IDM_WINDOW_POS_3 223
171 #define IDM_WINDOW_POS_4 224
172 #define IDM_WINDOW_POS_5 225
173 #define IDM_WINDOW_POS_6 226
174 #define IDM_WINDOW_POS_7 227
176 #define IDM_WINDOW_BIZ_0 230
177 #define IDM_WINDOW_BIZ_1 231
178 #define IDM_WINDOW_BIZ_2 232
179 #define IDM_WINDOW_BIZ_3 233
180 #define IDM_WINDOW_BIZ_4 234
181 #define IDM_WINDOW_BIZ_5 235
182 #define IDM_WINDOW_BIZ_6 236
183 #define IDM_WINDOW_BIZ_7 237
185 #define IDM_WINDOW_I_WID_0 240
186 #define IDM_WINDOW_I_WID_1 241
187 #define IDM_WINDOW_I_WID_2 242
188 #define IDM_WINDOW_I_WID_3 243
189 #define IDM_WINDOW_I_WID_4 244
190 #define IDM_WINDOW_I_WID_5 245
191 #define IDM_WINDOW_I_WID_6 246
192 #define IDM_WINDOW_I_WID_7 247
194 #define IDM_WINDOW_D_WID_0 250
195 #define IDM_WINDOW_D_WID_1 251
196 #define IDM_WINDOW_D_WID_2 252
197 #define IDM_WINDOW_D_WID_3 253
198 #define IDM_WINDOW_D_WID_4 254
199 #define IDM_WINDOW_D_WID_5 255
200 #define IDM_WINDOW_D_WID_6 256
201 #define IDM_WINDOW_D_WID_7 257
203 #define IDM_WINDOW_I_HGT_0 260
204 #define IDM_WINDOW_I_HGT_1 261
205 #define IDM_WINDOW_I_HGT_2 262
206 #define IDM_WINDOW_I_HGT_3 263
207 #define IDM_WINDOW_I_HGT_4 264
208 #define IDM_WINDOW_I_HGT_5 265
209 #define IDM_WINDOW_I_HGT_6 266
210 #define IDM_WINDOW_I_HGT_7 267
212 #define IDM_WINDOW_D_HGT_0 270
213 #define IDM_WINDOW_D_HGT_1 271
214 #define IDM_WINDOW_D_HGT_2 272
215 #define IDM_WINDOW_D_HGT_3 273
216 #define IDM_WINDOW_D_HGT_4 274
217 #define IDM_WINDOW_D_HGT_5 275
218 #define IDM_WINDOW_D_HGT_6 276
219 #define IDM_WINDOW_D_HGT_7 277
221 #define IDM_OPTIONS_NO_GRAPHICS 400
222 #define IDM_OPTIONS_OLD_GRAPHICS 401
223 #define IDM_OPTIONS_NEW_GRAPHICS 402
224 #define IDM_OPTIONS_NEW2_GRAPHICS 403
225 #define IDM_OPTIONS_BIGTILE 409
226 #define IDM_OPTIONS_SOUND 410
227 #define IDM_OPTIONS_MUSIC 411
228 #define IDM_OPTIONS_SAVER 420
229 #define IDM_OPTIONS_MAP 430
230 #define IDM_OPTIONS_BG 440
231 #define IDM_OPTIONS_OPEN_BG 441
233 #define IDM_DUMP_SCREEN_HTML 450
235 #define IDM_HELP_CONTENTS 901
238 * Exclude parts of WINDOWS.H that are not needed (Win32)
240 #define WIN32_LEAN_AND_MEAN
241 #define NONLS /* All NLS defines and routines */
242 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
243 #define NOMCX /* Modem Configuration Extensions */
246 * Include the "windows" support file
251 * Exclude parts of MMSYSTEM.H that are not needed
253 #define MMNODRV /* Installable driver support */
254 #define MMNOWAVE /* Waveform support */
255 #define MMNOMIDI /* MIDI support */
256 #define MMNOAUX /* Auxiliary audio support */
257 #define MMNOTIMER /* Timer support */
258 #define MMNOJOY /* Joystick support */
259 #define MMNOMCI /* MCI support */
260 #define MMNOMMIO /* Multimedia file I/O support */
262 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
263 #define MOUSE_SENS 40
266 * Include some more files. Note: the Cygnus Cygwin compiler
267 * doesn't use mmsystem.h instead it includes the winmm library
268 * which performs a similar function.
270 #include <mmsystem.h>
274 * Include the support for loading bitmaps
276 #include "term/readdib.h"
278 #define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
281 * Foreground color bits
283 #define VID_BLACK 0x00
284 #define VID_BLUE 0x01
285 #define VID_GREEN 0x02
286 #define VID_CYAN 0x03
288 #define VID_MAGENTA 0x05
289 #define VID_YELLOW 0x06
290 #define VID_WHITE 0x07
295 #define VID_BRIGHT 0x08
299 * @brief ターム情報構造体 / Extra "term" data
302 * pos_x / pos_y は各タームの左上点座標を指す。
305 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
306 * 1ドットずつ調整するステータスを指す。
307 * また、フォントを変更すると都度自動調整される。
310 * Note the use of "font_want" for the names of the font file requested by
311 * the user, and the use of "font_file" for the currently active font file.
313 * The "font_file" is uppercased, and takes the form "8X13.FON", while
314 * "font_want" can be in almost any form as long as it could be construed
315 * as attempting to represent the name of a font.
327 TERM_LEN rows; /* int -> uint */
330 uint pos_x; //!< タームの左上X座標
331 uint pos_y; //!< タームの左上Y座標
346 int font_wid; //!< フォント横幅
347 int font_hgt; //!< フォント縦幅
348 int tile_wid; //!< タイル横幅
349 int tile_hgt; //!< タイル縦幅
360 #define MAX_TERM_DATA 8 //!< Maximum number of windows
362 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
363 static term_data *my_td; //!< Hack -- global "window creation" pointer
364 POINT normsize; //!< Remember normal size of main window when maxmized
367 * was main window maximized on previous playing
369 bool win_maximized = FALSE;
374 bool game_in_progress = FALSE;
377 * note when "open"/"new" become valid
379 bool initialized = FALSE;
382 * screen paletted, i.e. 256 colors
384 bool paletted = FALSE;
387 * 16 colors screen, don't use RGB()
389 bool colors16 = FALSE;
392 * Saved instance handle
394 static HINSTANCE hInstance;
397 * Yellow brush for the cursor
399 static HBRUSH hbrYellow;
409 static HPALETTE hPal;
412 static HBITMAP hBG = NULL;
413 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
414 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
417 * The screen saver window
419 static HWND hwndSaver;
422 * 現在使用中のタイルID(0ならば未使用)
423 * Flag set once "graphics" has been initialized
425 static byte current_graphics_mode = 0;
430 static DIBINIT infGraph;
433 * The global bitmap mask
435 static DIBINIT infMask;
438 * Flag set once "sound" has been initialized
440 static bool can_use_sound = FALSE;
442 #define SAMPLE_SOUND_MAX 16
444 * An array of sound file names
446 static concptr sound_file[SOUND_MAX][SAMPLE_SOUND_MAX];
448 #define SAMPLE_MUSIC_MAX 16
449 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
450 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
451 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
452 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
453 static bool can_use_music = FALSE;
455 static MCI_OPEN_PARMS mop;
456 static char mci_device_type[256];
458 int current_music_type = 0;
459 int current_music_id = 0;
462 * Full path to ANGBAND.INI
464 static concptr ini_file = NULL;
467 * Name of application
469 static concptr AppName = "ANGBAND";
472 * Name of sub-window type
474 static concptr AngList = "AngList";
479 static concptr ANGBAND_DIR_XTRA_GRAF;
480 static concptr ANGBAND_DIR_XTRA_SOUND;
481 static concptr ANGBAND_DIR_XTRA_MUSIC;
482 static concptr ANGBAND_DIR_XTRA_HELP;
483 static concptr ANGBAND_DIR_XTRA_MUSIC;
486 * The "complex" color values
488 static COLORREF win_clr[256];
492 * Flag for macro trigger with dump ASCII
494 static bool term_no_press = FALSE;
499 static bool mouse_down = FALSE;
500 static bool paint_rect = FALSE;
501 static TERM_LEN mousex = 0, mousey = 0;
502 static TERM_LEN oldx, oldy;
505 * @brief The "simple" color values
507 * See "main-ibm.c" for original table information
508 * The entries below are taken from the "color bits" defined above.
509 * Note that many of the choices below suck, but so do crappy monitors.
511 static BYTE win_pal[256] =
513 VID_BLACK, /* Dark */
514 VID_WHITE, /* White */
515 VID_CYAN, /* Slate XXX */
516 VID_RED | VID_BRIGHT, /* Orange XXX */
518 VID_GREEN, /* Green */
520 VID_YELLOW, /* Umber XXX */
521 VID_BLACK | VID_BRIGHT, /* Light Dark */
522 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
523 VID_MAGENTA, /* Violet XXX */
524 VID_YELLOW | VID_BRIGHT, /* Yellow */
525 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
526 VID_GREEN | VID_BRIGHT, /* Light Green */
527 VID_BLUE | VID_BRIGHT, /* Light Blue */
528 VID_YELLOW /* Light Umber XXX */
532 * Hack -- define which keys are "special"
534 static bool special_key[256];
535 static bool ignore_key[256];
538 * Hack -- initialization list for "special_key"
540 static byte special_key_list[] = {
541 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
542 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
543 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
544 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
545 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
546 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
547 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
548 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
549 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
550 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
551 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
552 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
553 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
554 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
555 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
556 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
557 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
562 static byte ignore_key_list[] = {
563 VK_ESCAPE, VK_TAB, VK_SPACE,
564 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
565 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
566 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
571 /* Function prototype */
573 static bool is_already_running(void);
576 static void delete_bg(void)
586 static int init_bg(void)
588 char * bmfile = bg_bitmap_file;
590 if (use_bg == 0) return 0;
592 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
594 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
604 static void DrawBG(HDC hdc, RECT *r)
609 int x = r->left, y = r->top;
613 GetObject(hBG, sizeof(bm), &bm);
614 int swid = bm.bmWidth;
615 int shgt = bm.bmHeight;
617 HDC hdcSrc = CreateCompatibleDC(hdc);
618 HBITMAP hOld = SelectObject(hdcSrc, hBG);
622 int cwid = MIN(swid - sx, r->right - nx);
625 int chgt = MIN(shgt - sy, r->bottom - ny);
626 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
628 } while (ny < r->bottom);
632 } while (nx < r->right);
634 SelectObject(hdcSrc, hOld);
640 * Check for existance of a file
642 static bool check_file(concptr s)
646 DWORD attrib = GetFileAttributes(path);
647 if (attrib == INVALID_FILE_NAME) return FALSE;
648 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return FALSE;
655 * Check for existance of a directory
657 static bool check_dir(concptr s)
661 int i = strlen(path);
662 if (i && (path[i - 1] == '\\')) path[--i] = '\0';
664 DWORD attrib = GetFileAttributes(path);
665 if (attrib == INVALID_FILE_NAME) return FALSE;
666 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return FALSE;
675 static void validate_file(concptr s)
677 if (check_file(s)) return;
679 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
684 * Validate a directory
686 static void validate_dir(concptr s, bool vital)
688 if (check_dir(s)) return;
692 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
696 quit_fmt("Unable to create directory:\n%s", s);
702 * @brief (Windows版固有実装)Get the "size" for a window
704 static void term_getsize(term_data *td)
706 if (td->cols < 1) td->cols = 1;
707 if (td->rows < 1) td->rows = 1;
709 TERM_LEN wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
710 TERM_LEN hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
714 rc.right = rc.left + wid;
716 rc.bottom = rc.top + hgt;
718 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
719 td->size_wid = rc.right - rc.left;
720 td->size_hgt = rc.bottom - rc.top;
723 GetWindowRect(td->w, &rc);
730 * Write the "prefs" for a single term
732 static void save_prefs_aux(int i)
734 term_data *td = &data[i];
735 GAME_TEXT sec_name[128];
740 sprintf(sec_name, "Term-%d", i);
744 strcpy(buf, td->visible ? "1" : "0");
745 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
749 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "MS ゴシック");
751 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "Courier");
754 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
756 wsprintf(buf, "%d", td->lf.lfWidth);
757 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
758 wsprintf(buf, "%d", td->lf.lfHeight);
759 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
760 wsprintf(buf, "%d", td->lf.lfWeight);
761 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
763 strcpy(buf, td->bizarre ? "1" : "0");
764 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
766 wsprintf(buf, "%d", td->tile_wid);
767 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
769 wsprintf(buf, "%d", td->tile_hgt);
770 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
772 WINDOWPLACEMENT lpwndpl;
773 lpwndpl.length = sizeof(WINDOWPLACEMENT);
774 GetWindowPlacement(td->w, &lpwndpl);
776 RECT rc = lpwndpl.rcNormalPosition;
777 if (i == 0) wsprintf(buf, "%d", normsize.x);
778 else wsprintf(buf, "%d", td->cols);
780 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
782 if (i == 0) wsprintf(buf, "%d", normsize.y);
783 else wsprintf(buf, "%d", td->rows);
785 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
788 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
789 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
792 GetWindowRect(td->w, &rc);
793 wsprintf(buf, "%d", rc.left);
794 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
796 wsprintf(buf, "%d", rc.top);
797 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
800 strcpy(buf, td->posfix ? "1" : "0");
801 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
808 * We assume that the windows have all been initialized
810 static void save_prefs(void)
813 sprintf(buf, "%d", arg_graphics);
814 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
816 strcpy(buf, arg_bigtile ? "1" : "0");
817 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
819 strcpy(buf, arg_sound ? "1" : "0");
820 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
822 strcpy(buf, arg_music ? "1" : "0");
823 WritePrivateProfileString("Angband", "Music", buf, ini_file);
825 strcpy(buf, use_bg ? "1" : "0");
826 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
827 WritePrivateProfileString("Angband", "BackGroundBitmap",
828 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
830 for (int i = 0; i < MAX_TERM_DATA; ++i)
838 * Load the "prefs" for a single term
840 static void load_prefs_aux(int i)
842 term_data *td = &data[i];
843 GAME_TEXT sec_name[128];
846 int dispx = GetSystemMetrics(SM_CXVIRTUALSCREEN);
847 int dispy = GetSystemMetrics(SM_CYVIRTUALSCREEN);
851 sprintf(sec_name, "Term-%d", i);
852 sprintf(sec_name, "Term-%d", i);
855 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
859 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
861 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
864 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
866 td->font_want = string_make(tmp);
869 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
870 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
871 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
873 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
874 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
876 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
877 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
878 normsize.x = td->cols; normsize.y = td->rows;
882 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
885 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
886 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
887 td->pos_x = MIN(MAX(0, posx), dispx - 128);
888 td->pos_y = MIN(MAX(0, posy), dispy - 128);
892 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
900 static void load_prefs(void)
902 arg_graphics = (byte)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
903 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
904 use_bigtile = arg_bigtile;
905 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
906 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
907 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
908 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
909 for (int i = 0; i < MAX_TERM_DATA; ++i)
917 * - Taken from files.c.
919 * Extract "tokens" from a buffer
921 * This function uses "whitespace" as delimiters, and treats any amount of
922 * whitespace as a single delimiter. We will never return any empty tokens.
923 * When given an empty buffer, or a buffer containing only "whitespace", we
924 * will return no tokens. We will never extract more than "num" tokens.
926 * By running a token through the "text_to_ascii()" function, you can allow
927 * that token to include (encoded) whitespace, using "\s" to encode spaces.
929 * We save pointers to the tokens in "tokens", and return the number found.
931 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
939 for (; *s && iswspace(*s); ++s) /* loop */;
943 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
955 static void load_sound_prefs(void)
960 char *zz[SAMPLE_SOUND_MAX];
962 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
963 for (int i = 0; i < SOUND_MAX; i++)
965 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
966 int num = tokenize_whitespace(tmp, SAMPLE_SOUND_MAX, zz);
967 for (int j = 0; j < num; j++)
969 /* Access the sound */
970 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
972 /* Save the sound filename, if it exists */
973 if (check_file(wav_path))
974 sound_file[i][j] = string_make(zz[j]);
980 static void load_music_prefs(void)
985 char *zz[SAMPLE_MUSIC_MAX];
988 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
989 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
990 for (int i = 0; i < MUSIC_BASIC_MAX; i++)
992 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
993 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
994 for (int j = 0; j < num; j++)
996 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
997 if (check_file(wav_path))
998 music_file[i][j] = string_make(zz[j]);
1002 for (int i = 0; i < current_world_ptr->max_d_idx; i++)
1004 sprintf(key, "dungeon%03d", i);
1005 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1006 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1007 for (int j = 0; j < num; j++)
1009 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1010 if (check_file(wav_path))
1011 dungeon_music_file[i][j] = string_make(zz[j]);
1015 for (int i = 0; i < max_q_idx; i++)
1017 sprintf(key, "quest%03d", i);
1018 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1019 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1020 for (int j = 0; j < num; j++)
1022 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1023 if (check_file(wav_path))
1024 quest_music_file[i][j] = string_make(zz[j]);
1028 for (int i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1030 sprintf(key, "town%03d", i);
1031 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1032 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1033 for (int j = 0; j < num; j++)
1035 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1036 if (check_file(wav_path))
1037 town_music_file[i][j] = string_make(zz[j]);
1044 * Create the new global palette based on the bitmap palette
1045 * (if any), and the standard 16 entry palette derived from
1046 * "win_clr[]" which is used for the basic 16 Angband colors.
1048 * This function is never called before all windows are ready.
1050 * This function returns FALSE if the new palette could not be
1051 * prepared, which should normally be a fatal error. XXX XXX
1053 * Note that only some machines actually use a "palette".
1055 static int new_palette(void)
1060 LPLOGPALETTE pLogPal;
1061 LPPALETTEENTRY lppe;
1063 if (!paletted) return TRUE;
1069 HPALETTE hBmPal = infGraph.hPalette;
1072 lppeSize = 256 * sizeof(PALETTEENTRY);
1073 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1074 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1075 if ((nEntries == 0) || (nEntries > 220))
1077 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1078 rnfree(lppe, lppeSize);
1083 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1084 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1085 pLogPal->palVersion = 0x300;
1086 pLogPal->palNumEntries = nEntries + 16;
1087 for (i = 0; i < nEntries; i++)
1089 pLogPal->palPalEntry[i] = lppe[i];
1092 for (i = 0; i < 16; i++)
1095 p = &(pLogPal->palPalEntry[i + nEntries]);
1096 p->peRed = GetRValue(win_clr[i]);
1097 p->peGreen = GetGValue(win_clr[i]);
1098 p->peBlue = GetBValue(win_clr[i]);
1099 p->peFlags = PC_NOCOLLAPSE;
1102 if (lppe) rnfree(lppe, lppeSize);
1104 HPALETTE hNewPal = CreatePalette(pLogPal);
1105 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1107 rnfree(pLogPal, pLogPalSize);
1109 HDC hdc = GetDC(td->w);
1110 SelectPalette(hdc, hNewPal, 0);
1111 i = RealizePalette(hdc);
1112 ReleaseDC(td->w, hdc);
1113 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1115 for (i = 1; i < MAX_TERM_DATA; i++)
1119 SelectPalette(hdc, hNewPal, 0);
1120 ReleaseDC(td->w, hdc);
1123 if (hPal) DeleteObject(hPal);
1131 * @brief グラフィクスを初期化する / Initialize graphics
1134 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1135 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1138 static bool init_graphics(void)
1141 BYTE wid, hgt, twid, thgt, ox, oy;
1144 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1154 ANGBAND_GRAF = "new";
1156 else if (arg_graphics == GRAPHICS_HENGBAND)
1166 ANGBAND_GRAF = "ne2";
1177 ANGBAND_GRAF = "old";
1180 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1181 if (!ReadDIB(data[0].w, buf, &infGraph))
1183 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1187 infGraph.CellWidth = wid;
1188 infGraph.CellHeight = hgt;
1189 infGraph.TileWidth = twid;
1190 infGraph.TileHeight = thgt;
1191 infGraph.OffsetX = ox;
1192 infGraph.OffsetY = oy;
1194 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1196 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1197 if (!ReadDIB(data[0].w, buf, &infMask))
1199 plog_fmt("Cannot read bitmap file '%s'", buf);
1204 if (arg_graphics == GRAPHICS_HENGBAND)
1206 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1207 if (!ReadDIB(data[0].w, buf, &infMask))
1209 plog_fmt("Cannot read bitmap file '%s'", buf);
1216 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1220 current_graphics_mode = arg_graphics;
1221 return (current_graphics_mode);
1228 static void init_music(void)
1233 can_use_music = TRUE;
1238 * Hack -- Stop a music
1240 static void stop_music(void)
1242 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1243 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1250 static void init_sound(void)
1255 can_use_sound = TRUE;
1263 static void term_window_resize(term_data *td)
1267 SetWindowPos(td->w, 0, 0, 0,
1268 td->size_wid, td->size_hgt,
1269 SWP_NOMOVE | SWP_NOZORDER);
1270 InvalidateRect(td->w, NULL, TRUE);
1276 * Force the use of a new "font file" for a term_data.
1277 * This function may be called before the "window" is ready.
1278 * This function returns zero only if everything succeeds.
1279 * Note that the "font name" must be capitalized!!!
1281 static errr term_force_font(term_data *td, concptr path)
1283 if (td->font_id) DeleteObject(td->font_id);
1286 td->font_id = CreateFontIndirect(&(td->lf));
1287 int wid = td->lf.lfWidth;
1288 int hgt = td->lf.lfHeight;
1289 if (!td->font_id) return 1;
1297 hdcDesktop = GetDC(HWND_DESKTOP);
1298 hfOld = SelectObject(hdcDesktop, td->font_id);
1299 GetTextMetrics(hdcDesktop, &tm);
1300 SelectObject(hdcDesktop, hfOld);
1301 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1303 wid = tm.tmAveCharWidth;
1316 * Allow the user to change the font for this window.
1318 static void term_change_font(term_data *td)
1321 memset(&cf, 0, sizeof(cf));
1322 cf.lStructSize = sizeof(cf);
1323 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1324 cf.lpLogFont = &(td->lf);
1326 if (!ChooseFont(&cf)) return;
1328 term_force_font(td, NULL);
1330 td->tile_wid = td->font_wid;
1331 td->tile_hgt = td->font_hgt;
1333 term_window_resize(td);
1338 * Allow the user to lock this window.
1340 static void term_window_pos(term_data *td, HWND hWnd)
1342 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1343 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1346 static void windows_map(player_type *player_ptr);
1349 * Hack -- redraw a term_data
1351 static void term_data_redraw(player_type *player_ptr, term_data *td)
1355 windows_map(player_ptr);
1359 Term_activate(&td->t);
1361 Term_activate(term_screen);
1365 void term_inversed_area(HWND hWnd, int x, int y, int w, int h)
1367 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
1368 int tx = td->size_ow1 + x * td->tile_wid;
1369 int ty = td->size_oh1 + y * td->tile_hgt;
1370 int tw = w * td->tile_wid - 1;
1371 int th = h * td->tile_hgt - 1;
1373 HDC hdc = GetDC(hWnd);
1374 HBRUSH myBrush = CreateSolidBrush(RGB(255, 255, 255));
1375 HBRUSH oldBrush = SelectObject(hdc, myBrush);
1376 HPEN oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1378 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
1380 SelectObject(hdc, oldBrush);
1381 SelectObject(hdc, oldPen);
1386 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
1388 static errr term_user_win(int n)
1396 * React to global changes
1398 static errr term_xtra_win_react(player_type *player_ptr)
1402 for (int i = 0; i < 256; i++)
1404 win_pal[i] = angband_color_table[i][0];
1411 bool change = FALSE;
1412 for (int i = 0; i < 256; i++)
1414 rv = angband_color_table[i][1];
1415 gv = angband_color_table[i][2];
1416 bv = angband_color_table[i][3];
1417 code = PALETTERGB(rv, gv, bv);
1418 if (win_clr[i] != code)
1425 if (change) (void)new_palette();
1428 if (use_sound != arg_sound)
1431 use_sound = arg_sound;
1434 if (use_music != arg_music)
1437 use_music = arg_music;
1438 if (!arg_music) stop_music();
1439 else select_floor_music(player_ptr);
1442 if (use_graphics != arg_graphics)
1444 if (arg_graphics && !init_graphics())
1446 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
1447 arg_graphics = GRAPHICS_NONE;
1450 use_graphics = arg_graphics;
1451 reset_visuals(player_ptr, process_autopick_file_command);
1454 for (int i = 0; i < MAX_TERM_DATA; i++)
1457 term_data *td = &data[i];
1458 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
1460 Term_activate(&td->t);
1461 Term_resize(td->cols, td->rows);
1472 * Process at least one event
1474 static errr term_xtra_win_event(int v)
1479 if (GetMessage(&msg, NULL, 0, 0))
1481 TranslateMessage(&msg);
1482 DispatchMessage(&msg);
1487 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1489 TranslateMessage(&msg);
1490 DispatchMessage(&msg);
1499 * Process all pending events
1501 static errr term_xtra_win_flush(void)
1504 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1506 TranslateMessage(&msg);
1507 DispatchMessage(&msg);
1515 * Hack -- clear the screen
1517 * Make this more efficient
1519 static errr term_xtra_win_clear(void)
1521 term_data *td = (term_data*)(Term->data);
1524 rc.left = td->size_ow1;
1525 rc.right = rc.left + td->cols * td->tile_wid;
1526 rc.top = td->size_oh1;
1527 rc.bottom = rc.top + td->rows * td->tile_hgt;
1529 HDC hdc = GetDC(td->w);
1530 SetBkColor(hdc, RGB(0, 0, 0));
1531 SelectObject(hdc, td->font_id);
1532 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1536 rc.left = 0; rc.top = 0;
1540 ReleaseDC(td->w, hdc);
1546 * Hack -- make a noise
1548 static errr term_xtra_win_noise(void)
1550 MessageBeep(MB_ICONASTERISK);
1556 * Hack -- make a sound
1558 static errr term_xtra_win_sound(int v)
1561 if (!use_sound) return 1;
1562 if ((v < 0) || (v >= SOUND_MAX)) return 1;
1565 for (i = 0; i < SAMPLE_SOUND_MAX; i++)
1567 if (!sound_file[v][i])
1571 if (i == 0) return 1;
1573 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
1574 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
1578 * Hack -- play a music
1580 static errr term_xtra_win_music(int n, int v)
1584 if (n == TERM_XTRA_MUSIC_MUTE)
1586 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1587 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1590 if (!use_music) return 1;
1592 if (n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return 1;
1593 else if (v < 0 || v >= 1000) return(1); /*!< TODO */
1597 case TERM_XTRA_MUSIC_BASIC:
1598 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!music_file[v][i]) break;
1600 case TERM_XTRA_MUSIC_DUNGEON:
1601 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!dungeon_music_file[v][i]) break;
1603 case TERM_XTRA_MUSIC_QUEST:
1604 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!quest_music_file[v][i]) break;
1606 case TERM_XTRA_MUSIC_TOWN:
1607 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!town_music_file[v][i]) break;
1618 case TERM_XTRA_MUSIC_BASIC:
1619 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
1621 case TERM_XTRA_MUSIC_DUNGEON:
1622 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
1624 case TERM_XTRA_MUSIC_QUEST:
1625 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
1627 case TERM_XTRA_MUSIC_TOWN:
1628 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
1632 if (current_music_type == n && current_music_id == v)
1636 current_music_type = n;
1637 current_music_id = v;
1639 mop.lpstrDeviceType = mci_device_type;
1640 mop.lpstrElementName = buf;
1641 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1642 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1643 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
1644 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
1645 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
1651 * Delay for "x" milliseconds
1653 static int term_xtra_win_delay(int v)
1661 * todo z-termに影響があるのでplayer_typeの追加は保留
1662 * Do a "special thing"
1664 static errr term_xtra_win(int n, int v)
1668 case TERM_XTRA_NOISE:
1670 return (term_xtra_win_noise());
1672 case TERM_XTRA_MUSIC_BASIC:
1673 case TERM_XTRA_MUSIC_DUNGEON:
1674 case TERM_XTRA_MUSIC_QUEST:
1675 case TERM_XTRA_MUSIC_TOWN:
1677 return (term_xtra_win_music(n, v));
1679 case TERM_XTRA_SOUND:
1681 return (term_xtra_win_sound(v));
1683 case TERM_XTRA_BORED:
1685 return (term_xtra_win_event(0));
1687 case TERM_XTRA_EVENT:
1689 return (term_xtra_win_event(v));
1691 case TERM_XTRA_FLUSH:
1693 return (term_xtra_win_flush());
1695 case TERM_XTRA_CLEAR:
1697 return (term_xtra_win_clear());
1699 case TERM_XTRA_REACT:
1701 return (term_xtra_win_react(p_ptr));
1703 case TERM_XTRA_DELAY:
1705 return (term_xtra_win_delay(v));
1714 * Low level graphics (Assumes valid input).
1716 * Draw a "cursor" at (x,y), using a "yellow box".
1718 static errr term_curs_win(int x, int y)
1720 term_data *td = (term_data*)(Term->data);
1721 int tile_wid, tile_hgt;
1724 tile_wid = td->map_tile_wid;
1725 tile_hgt = td->map_tile_hgt;
1729 tile_wid = td->tile_wid;
1730 tile_hgt = td->tile_hgt;
1734 rc.left = x * tile_wid + td->size_ow1;
1735 rc.right = rc.left + tile_wid;
1736 rc.top = y * tile_hgt + td->size_oh1;
1737 rc.bottom = rc.top + tile_hgt;
1739 HDC hdc = GetDC(td->w);
1740 FrameRect(hdc, &rc, hbrYellow);
1741 ReleaseDC(td->w, hdc);
1747 * Low level graphics (Assumes valid input).
1749 * Draw a "big cursor" at (x,y), using a "yellow box".
1751 static errr term_bigcurs_win(int x, int y)
1753 term_data *td = (term_data*)(Term->data);
1754 int tile_wid, tile_hgt;
1757 term_curs_win(x, y);
1762 tile_wid = td->tile_wid;
1763 tile_hgt = td->tile_hgt;
1767 rc.left = x * tile_wid + td->size_ow1;
1768 rc.right = rc.left + 2 * tile_wid;
1769 rc.top = y * tile_hgt + td->size_oh1;
1770 rc.bottom = rc.top + tile_hgt;
1772 HDC hdc = GetDC(td->w);
1773 FrameRect(hdc, &rc, hbrYellow);
1774 ReleaseDC(td->w, hdc);
1780 * Low level graphics (Assumes valid input).
1782 * Erase a "block" of "n" characters starting at (x,y).
1784 static errr term_wipe_win(int x, int y, int n)
1786 term_data *td = (term_data*)(Term->data);
1788 rc.left = x * td->tile_wid + td->size_ow1;
1789 rc.right = rc.left + n * td->tile_wid;
1790 rc.top = y * td->tile_hgt + td->size_oh1;
1791 rc.bottom = rc.top + td->tile_hgt;
1793 HDC hdc = GetDC(td->w);
1794 SetBkColor(hdc, RGB(0, 0, 0));
1795 SelectObject(hdc, td->font_id);
1799 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1801 ReleaseDC(td->w, hdc);
1807 * Low level graphics. Assumes valid input.
1809 * Draw several ("n") chars, with an attr, at a given location.
1811 * All "graphic" data is handled by "term_pict_win()", below.
1813 * One would think there is a more efficient method for telling a window
1814 * what color it should be using to draw with, but perhaps simply changing
1815 * it every time is not too inefficient.
1817 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
1819 term_data *td = (term_data*)(Term->data);
1820 static HBITMAP WALL;
1821 static HBRUSH myBrush, oldBrush;
1823 static bool init_done = FALSE;
1826 WALL = LoadBitmap(hInstance, AppName);
1827 myBrush = CreatePatternBrush(WALL);
1832 rc.left = x * td->tile_wid + td->size_ow1;
1833 rc.right = rc.left + n * td->tile_wid;
1834 rc.top = y * td->tile_hgt + td->size_oh1;
1835 rc.bottom = rc.top + td->tile_hgt;
1837 HDC hdc = GetDC(td->w);
1838 SetBkColor(hdc, RGB(0, 0, 0));
1841 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
1845 SetTextColor(hdc, win_clr[a & 0x0F]);
1849 SetTextColor(hdc, win_clr[a]);
1852 SelectObject(hdc, td->font_id);
1853 if (use_bg) SetBkMode(hdc, TRANSPARENT);
1856 (td->tile_hgt != td->font_hgt) ||
1857 (td->tile_wid != td->font_wid))
1859 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1860 if (use_bg) DrawBG(hdc, &rc);
1862 rc.left += ((td->tile_wid - td->font_wid) / 2);
1863 rc.right = rc.left + td->font_wid;
1864 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
1865 rc.bottom = rc.top + td->font_hgt;
1867 for (int i = 0; i < n; i++)
1870 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1])
1872 rc.right += td->font_wid;
1873 oldBrush = SelectObject(hdc, myBrush);
1874 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1875 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1876 SelectObject(hdc, oldBrush);
1877 SelectObject(hdc, oldPen);
1878 rc.right -= td->font_wid;
1880 rc.left += 2 * td->tile_wid;
1881 rc.right += 2 * td->tile_wid;
1883 else if (iskanji(*(s + i))) /* 2バイト文字 */
1885 rc.right += td->font_wid;
1886 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
1888 rc.right -= td->font_wid;
1890 rc.left += 2 * td->tile_wid;
1891 rc.right += 2 * td->tile_wid;
1893 else if (*(s + i) == 127) {
1894 oldBrush = SelectObject(hdc, myBrush);
1895 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1896 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1897 SelectObject(hdc, oldBrush);
1898 SelectObject(hdc, oldPen);
1899 rc.left += td->tile_wid;
1900 rc.right += td->tile_wid;
1904 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1905 rc.left += td->tile_wid;
1906 rc.right += td->tile_wid;
1909 if (*(s + i) == 127)
1911 oldBrush = SelectObject(hdc, myBrush);
1912 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1913 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1914 SelectObject(hdc, oldBrush);
1915 SelectObject(hdc, oldPen);
1916 rc.left += td->tile_wid;
1917 rc.right += td->tile_wid;
1921 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1922 rc.left += td->tile_wid;
1923 rc.right += td->tile_wid;
1930 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc, s, n, NULL);
1933 ReleaseDC(td->w, hdc);
1939 * Low level graphics. Assumes valid input.
1941 * Draw an array of "special" attr/char pairs at the given location.
1943 * We use the "term_pict_win()" function for "graphic" data, which are
1944 * encoded by setting the "high-bits" of both the "attr" and the "char"
1945 * data. We use the "attr" to represent the "row" of the main bitmap,
1946 * and the "char" to represent the "col" of the main bitmap. The use
1947 * of this function is induced by the "higher_pict" flag.
1949 * If "graphics" is not available, we simply "wipe" the given grids.
1951 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)
1953 term_data *td = (term_data*)(Term->data);
1958 return (term_wipe_win(x, y, n));
1961 TERM_LEN w1 = infGraph.CellWidth;
1962 TERM_LEN h1 = infGraph.CellHeight;
1963 TERM_LEN tw1 = infGraph.TileWidth;
1964 TERM_LEN th1 = infGraph.TileHeight;
1965 TERM_LEN w2, h2, tw2 = 0;
1968 w2 = td->map_tile_wid;
1969 h2 = td->map_tile_hgt;
1976 if (use_bigtile) tw2 *= 2;
1979 TERM_LEN x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
1980 TERM_LEN y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
1981 HDC hdc = GetDC(td->w);
1982 HDC hdcSrc = CreateCompatibleDC(hdc);
1983 HBITMAP hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
1985 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
1987 hdcMask = CreateCompatibleDC(hdc);
1988 SelectObject(hdcMask, infMask.hBitmap);
1991 for (i = 0; i < n; i++, x2 += w2)
1993 TERM_COLOR a = ap[i];
1995 int row = (a & 0x7F);
1996 int col = (c & 0x7F);
1997 TERM_LEN x1 = col * w1;
1998 TERM_LEN y1 = row * h1;
2000 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2002 TERM_LEN x3 = (tcp[i] & 0x7F) * w1;
2003 TERM_LEN y3 = (tap[i] & 0x7F) * h1;
2004 tw2 = tw2 * w1 / tw1;
2006 if ((tw1 == tw2) && (th1 == h2))
2008 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2009 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2010 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2014 SetStretchBltMode(hdc, COLORONCOLOR);
2015 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
2016 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
2017 if ((x1 != x3) || (y1 != y3))
2019 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2020 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2026 if ((w1 == tw2) && (h1 == h2))
2028 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2032 SetStretchBltMode(hdc, COLORONCOLOR);
2033 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2036 SelectObject(hdcSrc, hbmSrcOld);
2038 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2040 SelectObject(hdcMask, hbmSrcOld);
2044 ReleaseDC(td->w, hdc);
2049 static void windows_map(player_type *player_ptr)
2051 term_data *td = &data[0];
2053 if (!use_graphics) return;
2055 term_xtra_win_clear();
2056 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2057 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2058 td->map_active = TRUE;
2062 TERM_LEN max_x = player_ptr->current_floor_ptr->width;
2063 TERM_LEN max_y = player_ptr->current_floor_ptr->height;
2066 for (TERM_LEN x = min_x; x < max_x; x++)
2068 for (TERM_LEN y = min_y; y < max_y; y++)
2072 map_info(player_ptr, y, x, &a, (char*)&c, &ta, (char*)&tc);
2073 if ((a & 0x80) && (c & 0x80))
2075 term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2080 term_curs_win(player_ptr->x - min_x, player_ptr->y - min_y);
2081 Term_inkey(&c, TRUE, TRUE);
2083 td->map_active = FALSE;
2084 term_xtra_win_clear();
2090 * Create and initialize a "term_data" given a title
2092 static void term_data_link(term_data *td)
2095 term_init(t, td->cols, td->rows, td->keys);
2096 t->soft_cursor = TRUE;
2097 t->higher_pict = TRUE;
2098 t->attr_blank = TERM_WHITE;
2099 t->char_blank = ' ';
2100 t->user_hook = term_user_win;
2101 t->xtra_hook = term_xtra_win;
2102 t->curs_hook = term_curs_win;
2103 t->bigcurs_hook = term_bigcurs_win;
2104 t->wipe_hook = term_wipe_win;
2105 t->text_hook = term_text_win;
2106 t->pict_hook = term_pict_win;
2107 t->data = (vptr)(td);
2112 * Create the windows
2114 * First, instantiate the "default" values, then read the "ini_file"
2115 * to over-ride selected values, then create the windows, and fonts.
2117 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2118 * must make active to realize the palette.
2120 static void init_windows(void)
2124 WIPE(td, term_data);
2128 td->s = angband_term_name[0];
2144 for (int i = 1; i < MAX_TERM_DATA; i++)
2147 WIPE(td, term_data);
2148 td->s = angband_term_name[i];
2152 td->visible = FALSE;
2157 td->pos_x = (7 - i) * 30;
2158 td->pos_y = (7 - i) * 20;
2165 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2166 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2171 for (int i = 1; i < MAX_TERM_DATA; i++)
2174 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2175 td->dwExStyle = (WS_EX_TOOLWINDOW);
2178 for (int i = 0; i < MAX_TERM_DATA; i++)
2181 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2182 td->lf.lfCharSet = DEFAULT_CHARSET;
2183 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2184 term_force_font(td, NULL);
2185 if (!td->tile_wid) td->tile_wid = td->font_wid;
2186 if (!td->tile_hgt) td->tile_hgt = td->font_hgt;
2189 term_window_resize(td);
2192 for (int i = MAX_TERM_DATA - 1; i >= 1; --i)
2197 td->w = CreateWindowEx(td->dwExStyle, AngList,
2199 td->pos_x, td->pos_y,
2200 td->size_wid, td->size_hgt,
2201 HWND_DESKTOP, NULL, hInstance, NULL);
2203 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
2207 td->size_hack = TRUE;
2208 ShowWindow(td->w, SW_SHOW);
2209 td->size_hack = FALSE;
2213 angband_term[i] = &td->t;
2217 /* Activate the window */
2218 SetActiveWindow(td->w);
2223 term_window_pos(&data[i], HWND_TOPMOST);
2227 term_window_pos(&data[i], td->w);
2233 td->w = CreateWindowEx(td->dwExStyle, AppName,
2235 td->pos_x, td->pos_y,
2236 td->size_wid, td->size_hgt,
2237 HWND_DESKTOP, NULL, hInstance, NULL);
2239 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
2242 angband_term[0] = &td->t;
2243 normsize.x = td->cols;
2244 normsize.y = td->rows;
2246 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
2247 else ShowWindow(td->w, SW_SHOW);
2249 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2250 (void)new_palette();
2251 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
2252 (void)term_xtra_win_flush();
2259 static void setup_menus(void)
2261 HMENU hm = GetMenu(data[0].w);
2262 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2263 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2264 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2265 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2266 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2268 if (!current_world_ptr->character_generated)
2270 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
2271 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
2274 if (current_world_ptr->character_generated)
2276 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_ENABLED);
2279 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_ENABLED);
2280 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_ENABLED);
2282 for (int i = 0; i < MAX_TERM_DATA; i++)
2284 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2285 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i, (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
2286 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_ENABLED);
2289 for (int i = 0; i < MAX_TERM_DATA; i++)
2291 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2293 if (data[i].visible)
2295 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2299 for (int i = 0; i < MAX_TERM_DATA; i++)
2301 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2302 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i, (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
2303 if (data[i].visible)
2305 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_ENABLED);
2309 for (int i = 0; i < MAX_TERM_DATA; i++)
2311 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2312 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i, (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
2313 if (data[i].visible)
2315 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_ENABLED);
2320 for (int i = 0; i < MAX_TERM_DATA; i++)
2322 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2323 if (data[i].visible)
2325 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
2329 for (int i = 0; i < MAX_TERM_DATA; i++)
2331 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2332 if (data[i].visible)
2334 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
2338 for (int i = 0; i < MAX_TERM_DATA; i++)
2340 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2341 if (data[i].visible)
2343 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2347 for (int i = 0; i < MAX_TERM_DATA; i++)
2349 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2351 if (data[i].visible)
2353 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2357 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2358 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2359 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2360 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2361 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2364 EnableMenuItem(hm, IDM_OPTIONS_SAVER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2367 if (use_graphics != GRAPHICS_NONE)
2368 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
2370 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2372 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
2373 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
2374 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
2375 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
2376 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
2377 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
2378 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
2379 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
2380 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
2381 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
2382 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
2383 (arg_music ? MF_CHECKED : MF_UNCHECKED));
2384 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
2385 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
2386 CheckMenuItem(hm, IDM_OPTIONS_BG,
2387 (use_bg ? MF_CHECKED : MF_UNCHECKED));
2390 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
2391 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
2393 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
2394 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
2395 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
2396 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
2397 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
2398 EnableMenuItem(hm, IDM_OPTIONS_SAVER, MF_BYCOMMAND | MF_ENABLED);
2403 * Check for double clicked (or dragged) savefile
2405 * Apparently, Windows copies the entire filename into the first
2406 * piece of the "command line string". Perhaps we should extract
2407 * the "basename" of that filename and append it to the "save" dir.
2409 static void check_for_save_file(player_type *player_ptr, LPSTR cmd_line)
2415 strcat(savefile, s);
2416 validate_file(savefile);
2417 game_in_progress = TRUE;
2418 play_game(player_ptr, FALSE);
2423 * Process a menu command
2425 static void process_menus(player_type *player_ptr, WORD wCmd)
2435 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2437 else if (game_in_progress)
2439 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
2443 game_in_progress = TRUE;
2445 play_game(player_ptr, TRUE);
2455 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2457 else if (game_in_progress)
2459 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
2463 memset(&ofn, 0, sizeof(ofn));
2464 ofn.lStructSize = sizeof(ofn);
2465 ofn.hwndOwner = data[0].w;
2466 ofn.lpstrFilter = "Save Files (*.)\0*\0";
2467 ofn.nFilterIndex = 1;
2468 ofn.lpstrFile = savefile;
2469 ofn.nMaxFile = 1024;
2470 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
2471 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
2473 if (GetOpenFileName(&ofn))
2475 validate_file(savefile);
2476 game_in_progress = TRUE;
2478 play_game(player_ptr, FALSE);
2487 if (game_in_progress && current_world_ptr->character_generated)
2491 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
2496 do_cmd_save_game(player_ptr, FALSE);
2500 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
2507 if (game_in_progress && current_world_ptr->character_generated)
2511 plog(_("今は終了できません。", "You may not do that right now."));
2516 forget_lite(player_ptr->current_floor_ptr);
2517 forget_view(player_ptr->current_floor_ptr);
2518 clear_mon_lite(player_ptr->current_floor_ptr);
2520 Term_key_push(SPECIAL_KEY_QUIT);
2527 case IDM_FILE_SCORE:
2530 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
2531 highscore_fd = fd_open(buf, O_RDONLY);
2532 if (highscore_fd < 0)
2534 msg_print("Score file unavailable.");
2540 display_scores_aux(0, MAX_HISCORES, -1, NULL);
2541 (void)fd_close(highscore_fd);
2549 case IDM_FILE_MOVIE:
2553 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2555 else if (game_in_progress)
2557 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
2561 memset(&ofn, 0, sizeof(ofn));
2562 ofn.lStructSize = sizeof(ofn);
2563 ofn.hwndOwner = data[0].w;
2564 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
2565 ofn.nFilterIndex = 1;
2566 ofn.lpstrFile = savefile;
2567 ofn.nMaxFile = 1024;
2568 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
2569 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2571 if (GetOpenFileName(&ofn))
2573 prepare_browse_movie_aux(savefile);
2574 play_game(player_ptr, FALSE);
2582 case IDM_WINDOW_VIS_0:
2584 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
2587 case IDM_WINDOW_VIS_1:
2588 case IDM_WINDOW_VIS_2:
2589 case IDM_WINDOW_VIS_3:
2590 case IDM_WINDOW_VIS_4:
2591 case IDM_WINDOW_VIS_5:
2592 case IDM_WINDOW_VIS_6:
2593 case IDM_WINDOW_VIS_7:
2595 int i = wCmd - IDM_WINDOW_VIS_0;
2596 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2602 ShowWindow(td->w, SW_SHOW);
2603 term_data_redraw(player_ptr, td);
2607 td->visible = FALSE;
2609 ShowWindow(td->w, SW_HIDE);
2614 case IDM_WINDOW_FONT_0:
2615 case IDM_WINDOW_FONT_1:
2616 case IDM_WINDOW_FONT_2:
2617 case IDM_WINDOW_FONT_3:
2618 case IDM_WINDOW_FONT_4:
2619 case IDM_WINDOW_FONT_5:
2620 case IDM_WINDOW_FONT_6:
2621 case IDM_WINDOW_FONT_7:
2623 int i = wCmd - IDM_WINDOW_FONT_0;
2624 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2627 term_change_font(td);
2630 case IDM_WINDOW_POS_1:
2631 case IDM_WINDOW_POS_2:
2632 case IDM_WINDOW_POS_3:
2633 case IDM_WINDOW_POS_4:
2634 case IDM_WINDOW_POS_5:
2635 case IDM_WINDOW_POS_6:
2636 case IDM_WINDOW_POS_7:
2638 int i = wCmd - IDM_WINDOW_POS_0;
2639 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2642 if (!td->posfix && td->visible)
2645 term_window_pos(td, HWND_TOPMOST);
2650 term_window_pos(td, data[0].w);
2655 case IDM_WINDOW_BIZ_0:
2656 case IDM_WINDOW_BIZ_1:
2657 case IDM_WINDOW_BIZ_2:
2658 case IDM_WINDOW_BIZ_3:
2659 case IDM_WINDOW_BIZ_4:
2660 case IDM_WINDOW_BIZ_5:
2661 case IDM_WINDOW_BIZ_6:
2662 case IDM_WINDOW_BIZ_7:
2664 int i = wCmd - IDM_WINDOW_BIZ_0;
2665 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2668 td->bizarre = !td->bizarre;
2670 term_window_resize(td);
2673 case IDM_WINDOW_I_WID_0:
2674 case IDM_WINDOW_I_WID_1:
2675 case IDM_WINDOW_I_WID_2:
2676 case IDM_WINDOW_I_WID_3:
2677 case IDM_WINDOW_I_WID_4:
2678 case IDM_WINDOW_I_WID_5:
2679 case IDM_WINDOW_I_WID_6:
2680 case IDM_WINDOW_I_WID_7:
2682 int i = wCmd - IDM_WINDOW_I_WID_0;
2683 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2688 term_window_resize(td);
2691 case IDM_WINDOW_D_WID_0:
2692 case IDM_WINDOW_D_WID_1:
2693 case IDM_WINDOW_D_WID_2:
2694 case IDM_WINDOW_D_WID_3:
2695 case IDM_WINDOW_D_WID_4:
2696 case IDM_WINDOW_D_WID_5:
2697 case IDM_WINDOW_D_WID_6:
2698 case IDM_WINDOW_D_WID_7:
2700 int i = wCmd - IDM_WINDOW_D_WID_0;
2701 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2706 term_window_resize(td);
2709 case IDM_WINDOW_I_HGT_0:
2710 case IDM_WINDOW_I_HGT_1:
2711 case IDM_WINDOW_I_HGT_2:
2712 case IDM_WINDOW_I_HGT_3:
2713 case IDM_WINDOW_I_HGT_4:
2714 case IDM_WINDOW_I_HGT_5:
2715 case IDM_WINDOW_I_HGT_6:
2716 case IDM_WINDOW_I_HGT_7:
2718 int i = wCmd - IDM_WINDOW_I_HGT_0;
2719 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2724 term_window_resize(td);
2727 case IDM_WINDOW_D_HGT_0:
2728 case IDM_WINDOW_D_HGT_1:
2729 case IDM_WINDOW_D_HGT_2:
2730 case IDM_WINDOW_D_HGT_3:
2731 case IDM_WINDOW_D_HGT_4:
2732 case IDM_WINDOW_D_HGT_5:
2733 case IDM_WINDOW_D_HGT_6:
2734 case IDM_WINDOW_D_HGT_7:
2736 int i = wCmd - IDM_WINDOW_D_HGT_0;
2737 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2742 term_window_resize(td);
2745 case IDM_OPTIONS_NO_GRAPHICS:
2749 plog("You may not do that right now.");
2753 if (arg_graphics != GRAPHICS_NONE)
2755 arg_graphics = GRAPHICS_NONE;
2756 term_xtra_win_react(player_ptr);
2757 Term_key_push(KTRL('R'));
2762 case IDM_OPTIONS_OLD_GRAPHICS:
2766 plog("You may not do that right now.");
2770 if (arg_graphics != GRAPHICS_ORIGINAL)
2772 arg_graphics = GRAPHICS_ORIGINAL;
2773 term_xtra_win_react(player_ptr);
2774 Term_key_push(KTRL('R'));
2779 case IDM_OPTIONS_NEW_GRAPHICS:
2783 plog("You may not do that right now.");
2787 if (arg_graphics != GRAPHICS_ADAM_BOLT)
2789 arg_graphics = GRAPHICS_ADAM_BOLT;
2790 term_xtra_win_react(player_ptr);
2791 Term_key_push(KTRL('R'));
2796 case IDM_OPTIONS_NEW2_GRAPHICS:
2800 plog("You may not do that right now.");
2804 if (arg_graphics != GRAPHICS_HENGBAND)
2806 arg_graphics = GRAPHICS_HENGBAND;
2807 term_xtra_win_react(player_ptr);
2808 Term_key_push(KTRL('R'));
2813 case IDM_OPTIONS_BIGTILE:
2818 plog("You may not do that right now.");
2822 arg_bigtile = !arg_bigtile;
2823 Term_activate(&td->t);
2824 Term_resize(td->cols, td->rows);
2825 InvalidateRect(td->w, NULL, TRUE);
2828 case IDM_OPTIONS_MUSIC:
2832 plog("You may not do that right now.");
2836 arg_music = !arg_music;
2837 term_xtra_win_react(player_ptr);
2838 Term_key_push(KTRL('R'));
2841 case IDM_OPTIONS_SOUND:
2845 plog("You may not do that right now.");
2849 arg_sound = !arg_sound;
2850 term_xtra_win_react(player_ptr);
2851 Term_key_push(KTRL('R'));
2854 case IDM_OPTIONS_BG:
2858 plog("You may not do that right now.");
2864 term_xtra_win_react(player_ptr);
2865 Term_key_push(KTRL('R'));
2868 case IDM_OPTIONS_OPEN_BG:
2872 plog("You may not do that right now.");
2876 memset(&ofn, 0, sizeof(ofn));
2877 ofn.lStructSize = sizeof(ofn);
2878 ofn.hwndOwner = data[0].w;
2879 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
2880 ofn.nFilterIndex = 1;
2881 ofn.lpstrFile = bg_bitmap_file;
2882 ofn.nMaxFile = 1023;
2883 ofn.lpstrInitialDir = NULL;
2884 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
2885 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
2887 if (GetOpenFileName(&ofn))
2893 term_xtra_win_react(player_ptr);
2894 Term_key_push(KTRL('R'));
2897 case IDM_DUMP_SCREEN_HTML:
2899 static char buf[1024] = "";
2900 memset(&ofn, 0, sizeof(ofn));
2901 ofn.lStructSize = sizeof(ofn);
2902 ofn.hwndOwner = data[0].w;
2903 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
2904 ofn.nFilterIndex = 1;
2905 ofn.lpstrFile = buf;
2906 ofn.nMaxFile = 1023;
2907 ofn.lpstrDefExt = "html";
2908 ofn.lpstrInitialDir = NULL;
2909 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
2910 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
2912 if (GetSaveFileName(&ofn))
2914 do_cmd_save_screen_html_aux(buf, 0);
2919 case IDM_OPTIONS_SAVER:
2923 DestroyWindow(hwndSaver);
2928 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
2929 "Angband Screensaver",
2930 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
2931 0, 0, GetSystemMetrics(SM_CXSCREEN),
2932 GetSystemMetrics(SM_CYSCREEN),
2933 NULL, NULL, hInstance, NULL);
2937 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2941 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
2946 case IDM_OPTIONS_MAP:
2948 windows_map(player_ptr);
2952 case IDM_HELP_CONTENTS:
2956 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
2957 if (check_file(tmp))
2959 sprintf(buf, "winhelp.exe %s", tmp);
2960 WinExec(buf, SW_NORMAL);
2964 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
2965 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
2972 static bool process_keydown(WPARAM wParam, LPARAM lParam)
2978 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
2979 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
2980 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
2982 term_no_press = (ma) ? TRUE : FALSE;
2983 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]))
2985 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
2986 bool numpad = FALSE;
2989 if (mc) Term_keypress('C');
2990 if (ms) Term_keypress('S');
2991 if (ma) Term_keypress('A');
2993 int i = LOBYTE(HIWORD(lParam));
2998 term_no_press = TRUE;
3017 term_no_press = TRUE;
3032 if (numpad) Term_keypress('K');
3034 Term_keypress(hexsym[i / 16]);
3035 Term_keypress(hexsym[i % 16]);
3046 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
3048 LRESULT PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3052 td = (term_data *)GetWindowLong(hWnd, 0);
3058 SetWindowLong(hWnd, 0, (LONG)(my_td));
3063 mop.dwCallback = (DWORD)hWnd;
3066 case WM_GETMINMAXINFO:
3071 lpmmi = (MINMAXINFO*)lParam;
3074 rc.left = rc.top = 0;
3075 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
3076 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
3078 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3080 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
3081 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
3087 BeginPaint(hWnd, &ps);
3088 if (td) term_data_redraw(p_ptr, td);
3089 EndPaint(hWnd, &ps);
3090 ValidateRect(hWnd, NULL);
3095 if (wParam == MCI_NOTIFY_SUCCESSFUL)
3097 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
3098 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
3106 if (process_keydown(wParam, lParam))
3112 if (term_no_press) term_no_press = FALSE;
3113 else Term_keypress(wParam);
3116 case WM_LBUTTONDOWN:
3118 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
3119 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
3129 TERM_LEN dx = abs(oldx - mousex) + 1;
3130 TERM_LEN dy = abs(oldy - mousey) + 1;
3131 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
3132 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
3138 int sz = (dx + 3) * dy;
3140 int sz = (dx + 2) * dy;
3142 hGlobal = GlobalAlloc(GHND, sz + 1);
3143 if (hGlobal == NULL) return 0;
3144 lpStr = (LPSTR)GlobalLock(hGlobal);
3146 for (int i = 0; i < dy; i++)
3150 char **scr = data[0].t.scr->c;
3152 C_MAKE(s, (dx + 1), char);
3153 strncpy(s, &scr[oy + i][ox], dx);
3157 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
3160 if (ox + dx < data[0].cols)
3162 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
3165 for (int j = 0; j < dx; j++)
3167 if (s[j] == 127) s[j] = '#';
3171 for (int j = 0; j < dx; j++)
3173 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
3183 GlobalUnlock(hGlobal);
3184 if (OpenClipboard(hWnd) == 0)
3186 GlobalFree(hGlobal);
3191 SetClipboardData(CF_TEXT, hGlobal);
3198 if (!mouse_down) return 0;
3201 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
3202 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
3207 dx = abs(oldx - mousex) + 1;
3208 dy = abs(oldy - mousey) + 1;
3209 ox = (oldx > mousex) ? mousex : oldx;
3210 oy = (oldy > mousey) ? mousey : oldy;
3211 term_inversed_area(hWnd, ox, oy, dx, dy);
3218 dx = abs(cx - mousex) + 1;
3219 dy = abs(cy - mousey) + 1;
3220 ox = (cx > mousex) ? mousex : cx;
3221 oy = (cy > mousey) ? mousey : cy;
3222 term_inversed_area(hWnd, ox, oy, dx, dy);
3235 if (!game_in_progress || !current_world_ptr->character_generated)
3243 plog(_("今は終了できません。", "You may not do that right now."));
3248 forget_lite(p_ptr->current_floor_ptr);
3249 forget_view(p_ptr->current_floor_ptr);
3250 clear_mon_lite(p_ptr->current_floor_ptr);
3251 Term_key_push(SPECIAL_KEY_QUIT);
3254 case WM_QUERYENDSESSION:
3256 if (!game_in_progress || !current_world_ptr->character_generated)
3263 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
3264 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
3266 p_ptr->panic_save = 1;
3267 signals_ignore_tstp();
3268 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
3269 (void)save_player(p_ptr);
3280 process_menus(p_ptr, LOWORD(wParam));
3286 if (!td->w) return 1;
3287 if (td->size_hack) return 1;
3289 // todo 二重のswitch文。後で分割する.
3292 case SIZE_MINIMIZED:
3294 for (int i = 1; i < MAX_TERM_DATA; i++)
3296 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
3301 case SIZE_MAXIMIZED:
3304 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
3305 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
3306 if ((td->cols != cols) || (td->rows != rows))
3310 if (!IsZoomed(td->w) && !IsIconic(td->w))
3312 normsize.x = td->cols;
3313 normsize.y = td->rows;
3316 Term_activate(&td->t);
3317 Term_resize(td->cols, td->rows);
3318 InvalidateRect(td->w, NULL, TRUE);
3321 td->size_hack = TRUE;
3322 for (int i = 1; i < MAX_TERM_DATA; i++)
3324 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
3327 td->size_hack = FALSE;
3335 case WM_PALETTECHANGED:
3337 if ((HWND)wParam == hWnd) return 0;
3339 case WM_QUERYNEWPALETTE:
3341 if (!paletted) return 0;
3343 HDC hdc = GetDC(hWnd);
3344 SelectPalette(hdc, hPal, FALSE);
3345 int i = RealizePalette(hdc);
3346 if (i) InvalidateRect(hWnd, NULL, TRUE);
3348 ReleaseDC(hWnd, hdc);
3353 if (!wParam || HIWORD(lParam)) break;
3355 for (int i = 1; i < MAX_TERM_DATA; i++)
3357 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
3363 case WM_ACTIVATEAPP:
3365 if (IsIconic(td->w)) break;
3367 for (int i = 1; i < MAX_TERM_DATA; i++)
3369 if (data[i].visible)
3373 ShowWindow(data[i].w, SW_SHOW);
3377 ShowWindow(data[i].w, SW_HIDE);
3384 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3389 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
3391 LRESULT PASCAL AngbandListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3395 td = (term_data *)GetWindowLong(hWnd, 0);
3401 SetWindowLong(hWnd, 0, (LONG)(my_td));
3408 case WM_GETMINMAXINFO:
3413 lpmmi = (MINMAXINFO*)lParam;
3416 rc.left = rc.top = 0;
3417 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
3418 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
3420 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3421 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
3422 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
3428 if (!td->w) return 1;
3429 if (td->size_hack) return 1;
3431 td->size_hack = TRUE;
3433 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
3434 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
3435 if ((td->cols != cols) || (td->rows != rows))
3437 term *old_term = Term;
3440 Term_activate(&td->t);
3441 Term_resize(td->cols, td->rows);
3442 Term_activate(old_term);
3443 InvalidateRect(td->w, NULL, TRUE);
3444 p_ptr->window = 0xFFFFFFFF;
3445 handle_stuff(p_ptr);
3448 td->size_hack = FALSE;
3453 BeginPaint(hWnd, &ps);
3454 if (td) term_data_redraw(p_ptr, td);
3455 EndPaint(hWnd, &ps);
3461 if (process_keydown(wParam, lParam))
3468 if (term_no_press) term_no_press = FALSE;
3469 else Term_keypress(wParam);
3472 case WM_PALETTECHANGED:
3474 if ((HWND)wParam == hWnd) return FALSE;
3476 case WM_QUERYNEWPALETTE:
3478 if (!paletted) return 0;
3480 HDC hdc = GetDC(hWnd);
3481 SelectPalette(hdc, hPal, FALSE);
3482 int i = RealizePalette(hdc);
3483 if (i) InvalidateRect(hWnd, NULL, TRUE);
3485 ReleaseDC(hWnd, hdc);
3488 case WM_NCLBUTTONDOWN:
3491 if (wParam == HTCLOSE) wParam = HTSYSMENU;
3492 #endif /* HTCLOSE */
3494 if (wParam == HTSYSMENU)
3498 td->visible = FALSE;
3499 ShowWindow(td->w, SW_HIDE);
3509 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3513 LRESULT PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3515 static int iMouse = 0;
3516 static WORD xMouse = 0;
3517 static WORD yMouse = 0;
3532 case WM_LBUTTONDOWN:
3533 case WM_MBUTTONDOWN:
3534 case WM_RBUTTONDOWN:
3537 SendMessage(hWnd, WM_CLOSE, 0, 0);
3544 int dx = LOWORD(lParam) - xMouse;
3545 int dy = HIWORD(lParam) - yMouse;
3547 if (dx < 0) dx = -dx;
3548 if (dy < 0) dy = -dy;
3550 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
3552 SendMessage(hWnd, WM_CLOSE, 0, 0);
3557 xMouse = LOWORD(lParam);
3558 yMouse = HIWORD(lParam);
3564 DestroyWindow(hwndSaver);
3570 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3575 * Display warning message (see "z-util.c")
3577 static void hack_plog(concptr str)
3582 MessageBox(NULL, str, "警告!",
3583 MB_ICONEXCLAMATION | MB_OK);
3585 MessageBox(NULL, str, "Warning",
3586 MB_ICONEXCLAMATION | MB_OK);
3594 * Display error message and quit (see "z-util.c")
3596 static void hack_quit(concptr str)
3601 MessageBox(NULL, str, "エラー!",
3602 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3604 MessageBox(NULL, str, "Error",
3605 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3610 UnregisterClass(AppName, hInstance);
3611 if (hIcon) DestroyIcon(hIcon);
3618 * Display warning message (see "z-util.c")
3620 static void hook_plog(concptr str)
3625 MessageBox(data[0].w, str, "警告!",
3626 MB_ICONEXCLAMATION | MB_OK);
3628 MessageBox(data[0].w, str, "Warning",
3629 MB_ICONEXCLAMATION | MB_OK);
3637 * Display error message and quit (see "z-util.c")
3639 static void hook_quit(concptr str)
3644 MessageBox(data[0].w, str, "エラー!",
3645 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3647 MessageBox(data[0].w, str, "Error",
3648 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3653 for (int i = MAX_TERM_DATA - 1; i >= 0; --i)
3655 term_force_font(&data[i], NULL);
3656 if (data[i].font_want) string_free(data[i].font_want);
3657 if (data[i].w) DestroyWindow(data[i].w);
3661 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
3662 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
3663 if (infMask.hPalette) DeleteObject(infMask.hPalette);
3664 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
3666 DeleteObject(hbrYellow);
3669 if (hPal) DeleteObject(hPal);
3671 UnregisterClass(AppName, hInstance);
3672 if (hIcon) DestroyIcon(hIcon);
3681 static void init_stuff(void)
3684 GetModuleFileName(hInstance, path, 512);
3686 strcpy(path + strlen(path) - 4, ".INI");
3687 ini_file = string_make(path);
3688 int i = strlen(path);
3692 if (path[i] == '\\')
3698 strcpy(path + i + 1, "lib\\");
3699 validate_dir(path, TRUE);
3700 init_file_paths(path);
3701 validate_dir(ANGBAND_DIR_APEX, FALSE);
3702 validate_dir(ANGBAND_DIR_BONE, FALSE);
3703 if (!check_dir(ANGBAND_DIR_EDIT))
3705 validate_dir(ANGBAND_DIR_DATA, TRUE);
3709 validate_dir(ANGBAND_DIR_DATA, FALSE);
3712 validate_dir(ANGBAND_DIR_FILE, TRUE);
3713 validate_dir(ANGBAND_DIR_HELP, FALSE);
3714 validate_dir(ANGBAND_DIR_INFO, FALSE);
3715 validate_dir(ANGBAND_DIR_PREF, TRUE);
3716 validate_dir(ANGBAND_DIR_SAVE, FALSE);
3717 validate_dir(ANGBAND_DIR_USER, TRUE);
3718 validate_dir(ANGBAND_DIR_XTRA, TRUE);
3719 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
3721 validate_file(path);
3722 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
3723 ANGBAND_DIR_XTRA_GRAF = string_make(path);
3724 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
3726 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
3727 ANGBAND_DIR_XTRA_SOUND = string_make(path);
3728 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
3730 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
3731 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
3732 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
3734 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
3735 ANGBAND_DIR_XTRA_HELP = string_make(path);
3740 * todo よく見るとhMutexはちゃんと使われていない……?
3741 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
3743 static bool is_already_running(void)
3746 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
3747 if (GetLastError() == ERROR_ALREADY_EXISTS)
3757 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
3759 int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
3765 setlocale(LC_ALL, "ja_JP");
3768 if (is_already_running())
3771 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
3773 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3777 if (hPrevInst == NULL)
3779 wc.style = CS_CLASSDC;
3780 wc.lpfnWndProc = AngbandWndProc;
3783 wc.hInstance = hInst;
3784 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
3785 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
3786 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
3787 wc.lpszMenuName = AppName;
3788 wc.lpszClassName = AppName;
3790 if (!RegisterClass(&wc)) exit(1);
3792 wc.lpfnWndProc = AngbandListProc;
3793 wc.lpszMenuName = NULL;
3794 wc.lpszClassName = AngList;
3796 if (!RegisterClass(&wc)) exit(2);
3798 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
3799 wc.lpfnWndProc = AngbandSaverProc;
3801 wc.lpszMenuName = NULL;
3802 wc.lpszClassName = "WindowsScreenSaverClass";
3804 if (!RegisterClass(&wc)) exit(3);
3807 plog_aux = hack_plog;
3808 quit_aux = hack_quit;
3809 core_aux = hack_quit;
3812 for (int i = 0; special_key_list[i]; ++i)
3814 special_key[special_key_list[i]] = TRUE;
3817 for (int i = 0; ignore_key_list[i]; ++i)
3819 ignore_key[ignore_key_list[i]] = TRUE;
3823 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
3824 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
3825 ReleaseDC(NULL, hdc);
3827 for (int i = 0; i < 256; i++)
3829 byte rv = angband_color_table[i][1];
3830 byte gv = angband_color_table[i][2];
3831 byte bv = angband_color_table[i][3];
3832 win_clr[i] = PALETTERGB(rv, gv, bv);
3833 angband_color_table[i][0] = win_pal[i];
3839 plog_aux = hook_plog;
3840 quit_aux = hook_quit;
3841 core_aux = hook_quit;
3843 ANGBAND_SYS = "win";
3844 if (7 != GetKeyboardType(0))
3845 ANGBAND_KEYBOARD = "0";
3848 switch (GetKeyboardType(1))
3850 case 0x0D01: case 0x0D02:
3851 case 0x0D03: case 0x0D04:
3852 case 0x0D05: case 0x0D06:
3854 ANGBAND_KEYBOARD = "NEC98";
3858 ANGBAND_KEYBOARD = "JAPAN";
3863 Term_activate(term_screen);
3864 init_angband(p_ptr, process_autopick_file_command);
3867 if (lpCmdLine[0] == '-') {
3868 switch (lpCmdLine[1])
3873 if (!lpCmdLine[2]) break;
3874 chuukei_server = TRUE;
3875 if (connect_chuukei_server(&lpCmdLine[2]) < 0) {
3876 msg_print("connect fail");
3879 msg_print("connect");
3887 if (!lpCmdLine[2]) break;
3888 chuukei_client = TRUE;
3889 connect_chuukei_server(&lpCmdLine[2]);
3890 play_game(player_ptr, FALSE);
3897 if (!lpCmdLine[2]) break;
3898 prepare_browse_movie(&lpCmdLine[2]);
3899 play_game(player_ptr, FALSE);
3908 if (!chuukei_server) check_for_save_file(lpCmdLine);
3910 check_for_save_file(p_ptr, lpCmdLine);
3913 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
3915 while (GetMessage(&msg, NULL, 0, 0))
3917 TranslateMessage(&msg);
3918 DispatchMessage(&msg);
3924 #endif /* WINDOWS */