2 * todo main関数を含むファイルの割に長過ぎる。main-win-utils.cなどといった形で分割したい
4 * @brief Windows版固有実装(メインエントリポイント含む)
6 * @author Hengband Team
10 * Windows98かその前後の頃を起点としたAPI実装。
12 * DirectXといった昨今描画に標準的となったライブラリも用いていない。
13 * タイルの描画処理などについては、現在動作の詳細を検証中。
17 * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
19 * This software may be copied and distributed for educational, research,
20 * and not for profit purposes provided that this copyright and statement
21 * are included in all such copies.
24 * This file helps Angband work with Windows computers.
26 * To use this file, use an appropriate "Makefile" or "Project File",
27 * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
28 * make sure to obtain various extra files as described below.
30 * The official compilation uses the CodeWarrior Pro compiler, which
31 * includes a special project file and precompilable header file.
35 * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
36 * and/or color redefinitions.
40 * The "lib/user/font-win.prf" contains attr/char mappings for use with the
41 * normal "lib/xtra/font/*.fon" font files.
45 * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
46 * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
51 * Compiling this file, and using the resulting executable, requires
52 * several extra files not distributed with the standard Angband code.
53 * In any case, some "*.fon" files (including "8X13.FON" if nothing else)
54 * must be placed into "lib/xtra/font/". All of these extra files can be found
55 * in the "ext-win" archive.
59 * The "term_xtra_win_clear()" function should probably do a low-level
60 * clear of the current window, and redraw the borders and other things,
61 * if only for efficiency.
65 * A simpler method is needed for selecting the "tile size" for windows.
69 * The various "warning" messages assume the existance of the "screen.w"
70 * window, I think, and only a few calls actually check for its existance,
71 * this may be okay since "NULL" means "on top of all windows". (?) The
72 * user must never be allowed to "hide" the main window, or the "menubar"
77 * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
78 * use with the "winhelp.exe" program. These files *may* be available
79 * at the ftp site somewhere, but I have not seen them.
83 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
85 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
87 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
88 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
93 #include "signal-handlers.h"
94 #include "main/sound-definitions-table.h"
99 #include "io/write-diary.h"
100 #include "cmd/cmd-dump.h"
101 #include "cmd/cmd-save.h"
102 #include "view-mainwindow.h"
104 #include "floor-events.h"
112 #include "gameterm.h"
123 * Available graphic modes
125 #define GRAPHICS_NONE 0
126 #define GRAPHICS_ORIGINAL 1
127 #define GRAPHICS_ADAM_BOLT 2
128 #define GRAPHICS_HENGBAND 3
131 * Menu constants -- see "ANGBAND.RC"
133 #define IDM_FILE_NEW 100
134 #define IDM_FILE_OPEN 101
135 #define IDM_FILE_SAVE 110
136 #define IDM_FILE_SCORE 120
137 #define IDM_FILE_MOVIE 121
138 #define IDM_FILE_EXIT 130
140 #define IDM_WINDOW_VIS_0 200
141 #define IDM_WINDOW_VIS_1 201
142 #define IDM_WINDOW_VIS_2 202
143 #define IDM_WINDOW_VIS_3 203
144 #define IDM_WINDOW_VIS_4 204
145 #define IDM_WINDOW_VIS_5 205
146 #define IDM_WINDOW_VIS_6 206
147 #define IDM_WINDOW_VIS_7 207
149 #define IDM_WINDOW_FONT_0 210
150 #define IDM_WINDOW_FONT_1 211
151 #define IDM_WINDOW_FONT_2 212
152 #define IDM_WINDOW_FONT_3 213
153 #define IDM_WINDOW_FONT_4 214
154 #define IDM_WINDOW_FONT_5 215
155 #define IDM_WINDOW_FONT_6 216
156 #define IDM_WINDOW_FONT_7 217
158 #define IDM_WINDOW_POS_0 220
159 #define IDM_WINDOW_POS_1 221
160 #define IDM_WINDOW_POS_2 222
161 #define IDM_WINDOW_POS_3 223
162 #define IDM_WINDOW_POS_4 224
163 #define IDM_WINDOW_POS_5 225
164 #define IDM_WINDOW_POS_6 226
165 #define IDM_WINDOW_POS_7 227
167 #define IDM_WINDOW_BIZ_0 230
168 #define IDM_WINDOW_BIZ_1 231
169 #define IDM_WINDOW_BIZ_2 232
170 #define IDM_WINDOW_BIZ_3 233
171 #define IDM_WINDOW_BIZ_4 234
172 #define IDM_WINDOW_BIZ_5 235
173 #define IDM_WINDOW_BIZ_6 236
174 #define IDM_WINDOW_BIZ_7 237
176 #define IDM_WINDOW_I_WID_0 240
177 #define IDM_WINDOW_I_WID_1 241
178 #define IDM_WINDOW_I_WID_2 242
179 #define IDM_WINDOW_I_WID_3 243
180 #define IDM_WINDOW_I_WID_4 244
181 #define IDM_WINDOW_I_WID_5 245
182 #define IDM_WINDOW_I_WID_6 246
183 #define IDM_WINDOW_I_WID_7 247
185 #define IDM_WINDOW_D_WID_0 250
186 #define IDM_WINDOW_D_WID_1 251
187 #define IDM_WINDOW_D_WID_2 252
188 #define IDM_WINDOW_D_WID_3 253
189 #define IDM_WINDOW_D_WID_4 254
190 #define IDM_WINDOW_D_WID_5 255
191 #define IDM_WINDOW_D_WID_6 256
192 #define IDM_WINDOW_D_WID_7 257
194 #define IDM_WINDOW_I_HGT_0 260
195 #define IDM_WINDOW_I_HGT_1 261
196 #define IDM_WINDOW_I_HGT_2 262
197 #define IDM_WINDOW_I_HGT_3 263
198 #define IDM_WINDOW_I_HGT_4 264
199 #define IDM_WINDOW_I_HGT_5 265
200 #define IDM_WINDOW_I_HGT_6 266
201 #define IDM_WINDOW_I_HGT_7 267
203 #define IDM_WINDOW_D_HGT_0 270
204 #define IDM_WINDOW_D_HGT_1 271
205 #define IDM_WINDOW_D_HGT_2 272
206 #define IDM_WINDOW_D_HGT_3 273
207 #define IDM_WINDOW_D_HGT_4 274
208 #define IDM_WINDOW_D_HGT_5 275
209 #define IDM_WINDOW_D_HGT_6 276
210 #define IDM_WINDOW_D_HGT_7 277
212 #define IDM_OPTIONS_NO_GRAPHICS 400
213 #define IDM_OPTIONS_OLD_GRAPHICS 401
214 #define IDM_OPTIONS_NEW_GRAPHICS 402
215 #define IDM_OPTIONS_NEW2_GRAPHICS 403
216 #define IDM_OPTIONS_BIGTILE 409
217 #define IDM_OPTIONS_SOUND 410
218 #define IDM_OPTIONS_MUSIC 411
219 #define IDM_OPTIONS_SAVER 420
220 #define IDM_OPTIONS_MAP 430
221 #define IDM_OPTIONS_BG 440
222 #define IDM_OPTIONS_OPEN_BG 441
224 #define IDM_DUMP_SCREEN_HTML 450
226 #define IDM_HELP_CONTENTS 901
229 * Exclude parts of WINDOWS.H that are not needed (Win32)
231 #define WIN32_LEAN_AND_MEAN
232 #define NONLS /* All NLS defines and routines */
233 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
234 #define NOMCX /* Modem Configuration Extensions */
237 * Include the "windows" support file
242 * Exclude parts of MMSYSTEM.H that are not needed
244 #define MMNODRV /* Installable driver support */
245 #define MMNOWAVE /* Waveform support */
246 #define MMNOMIDI /* MIDI support */
247 #define MMNOAUX /* Auxiliary audio support */
248 #define MMNOTIMER /* Timer support */
249 #define MMNOJOY /* Joystick support */
250 #define MMNOMCI /* MCI support */
251 #define MMNOMMIO /* Multimedia file I/O support */
253 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
254 #define MOUSE_SENS 40
257 * Standard music names
259 const concptr angband_music_basic_name[MUSIC_BASIC_MAX] =
285 * Include some more files. Note: the Cygnus Cygwin compiler
286 * doesn't use mmsystem.h instead it includes the winmm library
287 * which performs a similar function.
289 #include <mmsystem.h>
293 * Include the support for loading bitmaps
297 #define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
300 * Foreground color bits
302 #define VID_BLACK 0x00
303 #define VID_BLUE 0x01
304 #define VID_GREEN 0x02
305 #define VID_CYAN 0x03
307 #define VID_MAGENTA 0x05
308 #define VID_YELLOW 0x06
309 #define VID_WHITE 0x07
314 #define VID_BRIGHT 0x08
318 * @brief ターム情報構造体 / Extra "term" data
321 * pos_x / pos_y は各タームの左上点座標を指す。
324 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
325 * 1ドットずつ調整するステータスを指す。
326 * また、フォントを変更すると都度自動調整される。
329 * Note the use of "font_want" for the names of the font file requested by
330 * the user, and the use of "font_file" for the currently active font file.
332 * The "font_file" is uppercased, and takes the form "8X13.FON", while
333 * "font_want" can be in almost any form as long as it could be construed
334 * as attempting to represent the name of a font.
346 TERM_LEN rows; /* int -> uint */
349 uint pos_x; //!< タームの左上X座標
350 uint pos_y; //!< タームの左上Y座標
365 int font_wid; //!< フォント横幅
366 int font_hgt; //!< フォント縦幅
367 int tile_wid; //!< タイル横幅
368 int tile_hgt; //!< タイル縦幅
379 #define MAX_TERM_DATA 8 //!< Maximum number of windows
381 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
382 static term_data *my_td; //!< Hack -- global "window creation" pointer
383 POINT normsize; //!< Remember normal size of main window when maxmized
386 * was main window maximized on previous playing
388 bool win_maximized = FALSE;
393 bool game_in_progress = FALSE;
396 * note when "open"/"new" become valid
398 bool initialized = FALSE;
401 * screen paletted, i.e. 256 colors
403 bool paletted = FALSE;
406 * 16 colors screen, don't use RGB()
408 bool colors16 = FALSE;
411 * Saved instance handle
413 static HINSTANCE hInstance;
416 * Yellow brush for the cursor
418 static HBRUSH hbrYellow;
428 static HPALETTE hPal;
431 static HBITMAP hBG = NULL;
432 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
433 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
436 * The screen saver window
438 static HWND hwndSaver;
441 * 現在使用中のタイルID(0ならば未使用)
442 * Flag set once "graphics" has been initialized
444 static byte current_graphics_mode = 0;
449 static DIBINIT infGraph;
452 * The global bitmap mask
454 static DIBINIT infMask;
457 * Flag set once "sound" has been initialized
459 static bool can_use_sound = FALSE;
461 #define SAMPLE_SOUND_MAX 16
463 * An array of sound file names
465 static concptr sound_file[SOUND_MAX][SAMPLE_SOUND_MAX];
467 #define SAMPLE_MUSIC_MAX 16
468 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
469 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
470 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
471 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
472 static bool can_use_music = FALSE;
474 static MCI_OPEN_PARMS mop;
475 static char mci_device_type[256];
477 int current_music_type = 0;
478 int current_music_id = 0;
481 * Full path to ANGBAND.INI
483 static concptr ini_file = NULL;
486 * Name of application
488 static concptr AppName = "ANGBAND";
491 * Name of sub-window type
493 static concptr AngList = "AngList";
498 static concptr ANGBAND_DIR_XTRA_GRAF;
499 static concptr ANGBAND_DIR_XTRA_SOUND;
500 static concptr ANGBAND_DIR_XTRA_MUSIC;
501 static concptr ANGBAND_DIR_XTRA_HELP;
502 static concptr ANGBAND_DIR_XTRA_MUSIC;
505 * The "complex" color values
507 static COLORREF win_clr[256];
511 * Flag for macro trigger with dump ASCII
513 static bool term_no_press = FALSE;
518 static bool mouse_down = FALSE;
519 static bool paint_rect = FALSE;
520 static TERM_LEN mousex = 0, mousey = 0;
521 static TERM_LEN oldx, oldy;
524 * @brief The "simple" color values
526 * See "main-ibm.c" for original table information
527 * The entries below are taken from the "color bits" defined above.
528 * Note that many of the choices below suck, but so do crappy monitors.
530 static BYTE win_pal[256] =
532 VID_BLACK, /* Dark */
533 VID_WHITE, /* White */
534 VID_CYAN, /* Slate XXX */
535 VID_RED | VID_BRIGHT, /* Orange XXX */
537 VID_GREEN, /* Green */
539 VID_YELLOW, /* Umber XXX */
540 VID_BLACK | VID_BRIGHT, /* Light Dark */
541 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
542 VID_MAGENTA, /* Violet XXX */
543 VID_YELLOW | VID_BRIGHT, /* Yellow */
544 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
545 VID_GREEN | VID_BRIGHT, /* Light Green */
546 VID_BLUE | VID_BRIGHT, /* Light Blue */
547 VID_YELLOW /* Light Umber XXX */
551 * Hack -- define which keys are "special"
553 static bool special_key[256];
554 static bool ignore_key[256];
557 * Hack -- initialization list for "special_key"
559 static byte special_key_list[] = {
560 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
561 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
562 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
563 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
564 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
565 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
566 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
567 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
568 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
569 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
570 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
571 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
572 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
573 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
574 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
575 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
576 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
581 static byte ignore_key_list[] = {
582 VK_ESCAPE, VK_TAB, VK_SPACE,
583 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
584 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
585 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
590 /* Function prototype */
592 static bool is_already_running(void);
595 static void delete_bg(void)
605 static int init_bg(void)
607 char * bmfile = bg_bitmap_file;
609 if (use_bg == 0) return 0;
611 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
613 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
623 static void DrawBG(HDC hdc, RECT *r)
628 int x = r->left, y = r->top;
632 GetObject(hBG, sizeof(bm), &bm);
633 int swid = bm.bmWidth;
634 int shgt = bm.bmHeight;
636 HDC hdcSrc = CreateCompatibleDC(hdc);
637 HBITMAP hOld = SelectObject(hdcSrc, hBG);
641 int cwid = MIN(swid - sx, r->right - nx);
644 int chgt = MIN(shgt - sy, r->bottom - ny);
645 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
647 } while (ny < r->bottom);
651 } while (nx < r->right);
653 SelectObject(hdcSrc, hOld);
659 * Check for existance of a file
661 static bool check_file(concptr s)
665 DWORD attrib = GetFileAttributes(path);
666 if (attrib == INVALID_FILE_NAME) return FALSE;
667 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return FALSE;
674 * Check for existance of a directory
676 static bool check_dir(concptr s)
680 int i = strlen(path);
681 if (i && (path[i - 1] == '\\')) path[--i] = '\0';
683 DWORD attrib = GetFileAttributes(path);
684 if (attrib == INVALID_FILE_NAME) return FALSE;
685 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return FALSE;
694 static void validate_file(concptr s)
696 if (check_file(s)) return;
698 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
703 * Validate a directory
705 static void validate_dir(concptr s, bool vital)
707 if (check_dir(s)) return;
711 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
715 quit_fmt("Unable to create directory:\n%s", s);
721 * @brief (Windows版固有実装)Get the "size" for a window
723 static void term_getsize(term_data *td)
725 if (td->cols < 1) td->cols = 1;
726 if (td->rows < 1) td->rows = 1;
728 TERM_LEN wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
729 TERM_LEN hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
733 rc.right = rc.left + wid;
735 rc.bottom = rc.top + hgt;
737 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
738 td->size_wid = rc.right - rc.left;
739 td->size_hgt = rc.bottom - rc.top;
742 GetWindowRect(td->w, &rc);
749 * Write the "prefs" for a single term
751 static void save_prefs_aux(int i)
753 term_data *td = &data[i];
754 GAME_TEXT sec_name[128];
759 sprintf(sec_name, "Term-%d", i);
763 strcpy(buf, td->visible ? "1" : "0");
764 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
768 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "MS ゴシック");
770 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "Courier");
773 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
775 wsprintf(buf, "%d", td->lf.lfWidth);
776 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
777 wsprintf(buf, "%d", td->lf.lfHeight);
778 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
779 wsprintf(buf, "%d", td->lf.lfWeight);
780 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
782 strcpy(buf, td->bizarre ? "1" : "0");
783 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
785 wsprintf(buf, "%d", td->tile_wid);
786 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
788 wsprintf(buf, "%d", td->tile_hgt);
789 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
791 WINDOWPLACEMENT lpwndpl;
792 lpwndpl.length = sizeof(WINDOWPLACEMENT);
793 GetWindowPlacement(td->w, &lpwndpl);
795 RECT rc = lpwndpl.rcNormalPosition;
796 if (i == 0) wsprintf(buf, "%d", normsize.x);
797 else wsprintf(buf, "%d", td->cols);
799 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
801 if (i == 0) wsprintf(buf, "%d", normsize.y);
802 else wsprintf(buf, "%d", td->rows);
804 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
807 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
808 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
811 GetWindowRect(td->w, &rc);
812 wsprintf(buf, "%d", rc.left);
813 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
815 wsprintf(buf, "%d", rc.top);
816 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
819 strcpy(buf, td->posfix ? "1" : "0");
820 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
827 * We assume that the windows have all been initialized
829 static void save_prefs(void)
832 sprintf(buf, "%d", arg_graphics);
833 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
835 strcpy(buf, arg_bigtile ? "1" : "0");
836 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
838 strcpy(buf, arg_sound ? "1" : "0");
839 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
841 strcpy(buf, arg_music ? "1" : "0");
842 WritePrivateProfileString("Angband", "Music", buf, ini_file);
844 strcpy(buf, use_bg ? "1" : "0");
845 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
846 WritePrivateProfileString("Angband", "BackGroundBitmap",
847 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
849 for (int i = 0; i < MAX_TERM_DATA; ++i)
857 * Load the "prefs" for a single term
859 static void load_prefs_aux(int i)
861 term_data *td = &data[i];
862 GAME_TEXT sec_name[128];
865 int dispx = GetSystemMetrics(SM_CXVIRTUALSCREEN);
866 int dispy = GetSystemMetrics(SM_CYVIRTUALSCREEN);
870 sprintf(sec_name, "Term-%d", i);
871 sprintf(sec_name, "Term-%d", i);
874 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
878 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
880 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
883 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
885 td->font_want = string_make(tmp);
888 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
889 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
890 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
892 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
893 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
895 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
896 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
897 normsize.x = td->cols; normsize.y = td->rows;
901 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
904 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
905 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
906 td->pos_x = MIN(MAX(0, posx), dispx - 128);
907 td->pos_y = MIN(MAX(0, posy), dispy - 128);
911 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
919 static void load_prefs(void)
921 arg_graphics = (byte)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
922 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
923 use_bigtile = arg_bigtile;
924 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
925 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
926 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
927 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
928 for (int i = 0; i < MAX_TERM_DATA; ++i)
936 * - Taken from files.c.
938 * Extract "tokens" from a buffer
940 * This function uses "whitespace" as delimiters, and treats any amount of
941 * whitespace as a single delimiter. We will never return any empty tokens.
942 * When given an empty buffer, or a buffer containing only "whitespace", we
943 * will return no tokens. We will never extract more than "num" tokens.
945 * By running a token through the "text_to_ascii()" function, you can allow
946 * that token to include (encoded) whitespace, using "\s" to encode spaces.
948 * We save pointers to the tokens in "tokens", and return the number found.
950 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
958 for (; *s && iswspace(*s); ++s) /* loop */;
962 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
974 static void load_sound_prefs(void)
979 char *zz[SAMPLE_SOUND_MAX];
981 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
982 for (int i = 0; i < SOUND_MAX; i++)
984 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
985 int num = tokenize_whitespace(tmp, SAMPLE_SOUND_MAX, zz);
986 for (int j = 0; j < num; j++)
988 /* Access the sound */
989 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
991 /* Save the sound filename, if it exists */
992 if (check_file(wav_path))
993 sound_file[i][j] = string_make(zz[j]);
999 static void load_music_prefs(void)
1002 char ini_path[1024];
1003 char wav_path[1024];
1004 char *zz[SAMPLE_MUSIC_MAX];
1007 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
1008 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
1009 for (int i = 0; i < MUSIC_BASIC_MAX; i++)
1011 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
1012 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1013 for (int j = 0; j < num; j++)
1015 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1016 if (check_file(wav_path))
1017 music_file[i][j] = string_make(zz[j]);
1021 for (int i = 0; i < current_world_ptr->max_d_idx; i++)
1023 sprintf(key, "dungeon%03d", i);
1024 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1025 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1026 for (int j = 0; j < num; j++)
1028 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1029 if (check_file(wav_path))
1030 dungeon_music_file[i][j] = string_make(zz[j]);
1034 for (int i = 0; i < max_q_idx; i++)
1036 sprintf(key, "quest%03d", i);
1037 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1038 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1039 for (int j = 0; j < num; j++)
1041 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1042 if (check_file(wav_path))
1043 quest_music_file[i][j] = string_make(zz[j]);
1047 for (int i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1049 sprintf(key, "town%03d", i);
1050 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1051 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1052 for (int j = 0; j < num; j++)
1054 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1055 if (check_file(wav_path))
1056 town_music_file[i][j] = string_make(zz[j]);
1063 * Create the new global palette based on the bitmap palette
1064 * (if any), and the standard 16 entry palette derived from
1065 * "win_clr[]" which is used for the basic 16 Angband colors.
1067 * This function is never called before all windows are ready.
1069 * This function returns FALSE if the new palette could not be
1070 * prepared, which should normally be a fatal error. XXX XXX
1072 * Note that only some machines actually use a "palette".
1074 static int new_palette(void)
1079 LPLOGPALETTE pLogPal;
1080 LPPALETTEENTRY lppe;
1082 if (!paletted) return TRUE;
1088 HPALETTE hBmPal = infGraph.hPalette;
1091 lppeSize = 256 * sizeof(PALETTEENTRY);
1092 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1093 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1094 if ((nEntries == 0) || (nEntries > 220))
1096 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1097 rnfree(lppe, lppeSize);
1102 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1103 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1104 pLogPal->palVersion = 0x300;
1105 pLogPal->palNumEntries = nEntries + 16;
1106 for (i = 0; i < nEntries; i++)
1108 pLogPal->palPalEntry[i] = lppe[i];
1111 for (i = 0; i < 16; i++)
1114 p = &(pLogPal->palPalEntry[i + nEntries]);
1115 p->peRed = GetRValue(win_clr[i]);
1116 p->peGreen = GetGValue(win_clr[i]);
1117 p->peBlue = GetBValue(win_clr[i]);
1118 p->peFlags = PC_NOCOLLAPSE;
1121 if (lppe) rnfree(lppe, lppeSize);
1123 HPALETTE hNewPal = CreatePalette(pLogPal);
1124 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1126 rnfree(pLogPal, pLogPalSize);
1128 HDC hdc = GetDC(td->w);
1129 SelectPalette(hdc, hNewPal, 0);
1130 i = RealizePalette(hdc);
1131 ReleaseDC(td->w, hdc);
1132 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1134 for (i = 1; i < MAX_TERM_DATA; i++)
1138 SelectPalette(hdc, hNewPal, 0);
1139 ReleaseDC(td->w, hdc);
1142 if (hPal) DeleteObject(hPal);
1150 * @brief グラフィクスを初期化する / Initialize graphics
1153 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1154 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1157 static bool init_graphics(void)
1160 BYTE wid, hgt, twid, thgt, ox, oy;
1163 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1173 ANGBAND_GRAF = "new";
1175 else if (arg_graphics == GRAPHICS_HENGBAND)
1185 ANGBAND_GRAF = "ne2";
1196 ANGBAND_GRAF = "old";
1199 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1200 if (!ReadDIB(data[0].w, buf, &infGraph))
1202 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1206 infGraph.CellWidth = wid;
1207 infGraph.CellHeight = hgt;
1208 infGraph.TileWidth = twid;
1209 infGraph.TileHeight = thgt;
1210 infGraph.OffsetX = ox;
1211 infGraph.OffsetY = oy;
1213 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1215 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1216 if (!ReadDIB(data[0].w, buf, &infMask))
1218 plog_fmt("Cannot read bitmap file '%s'", buf);
1223 if (arg_graphics == GRAPHICS_HENGBAND)
1225 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1226 if (!ReadDIB(data[0].w, buf, &infMask))
1228 plog_fmt("Cannot read bitmap file '%s'", buf);
1235 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1239 current_graphics_mode = arg_graphics;
1240 return (current_graphics_mode);
1247 static void init_music(void)
1252 can_use_music = TRUE;
1257 * Hack -- Stop a music
1259 static void stop_music(void)
1261 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1262 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1269 static void init_sound(void)
1274 can_use_sound = TRUE;
1282 static void term_window_resize(term_data *td)
1286 SetWindowPos(td->w, 0, 0, 0,
1287 td->size_wid, td->size_hgt,
1288 SWP_NOMOVE | SWP_NOZORDER);
1289 InvalidateRect(td->w, NULL, TRUE);
1295 * Force the use of a new "font file" for a term_data.
1296 * This function may be called before the "window" is ready.
1297 * This function returns zero only if everything succeeds.
1298 * Note that the "font name" must be capitalized!!!
1300 static errr term_force_font(term_data *td, concptr path)
1302 if (td->font_id) DeleteObject(td->font_id);
1305 td->font_id = CreateFontIndirect(&(td->lf));
1306 int wid = td->lf.lfWidth;
1307 int hgt = td->lf.lfHeight;
1308 if (!td->font_id) return 1;
1316 hdcDesktop = GetDC(HWND_DESKTOP);
1317 hfOld = SelectObject(hdcDesktop, td->font_id);
1318 GetTextMetrics(hdcDesktop, &tm);
1319 SelectObject(hdcDesktop, hfOld);
1320 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1322 wid = tm.tmAveCharWidth;
1335 * Allow the user to change the font for this window.
1337 static void term_change_font(term_data *td)
1340 memset(&cf, 0, sizeof(cf));
1341 cf.lStructSize = sizeof(cf);
1342 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1343 cf.lpLogFont = &(td->lf);
1345 if (!ChooseFont(&cf)) return;
1347 term_force_font(td, NULL);
1349 td->tile_wid = td->font_wid;
1350 td->tile_hgt = td->font_hgt;
1352 term_window_resize(td);
1357 * Allow the user to lock this window.
1359 static void term_window_pos(term_data *td, HWND hWnd)
1361 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1362 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1365 static void windows_map(player_type *player_ptr);
1368 * Hack -- redraw a term_data
1370 static void term_data_redraw(player_type *player_ptr, term_data *td)
1374 windows_map(player_ptr);
1378 Term_activate(&td->t);
1380 Term_activate(term_screen);
1384 void term_inversed_area(HWND hWnd, int x, int y, int w, int h)
1386 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
1387 int tx = td->size_ow1 + x * td->tile_wid;
1388 int ty = td->size_oh1 + y * td->tile_hgt;
1389 int tw = w * td->tile_wid - 1;
1390 int th = h * td->tile_hgt - 1;
1392 HDC hdc = GetDC(hWnd);
1393 HBRUSH myBrush = CreateSolidBrush(RGB(255, 255, 255));
1394 HBRUSH oldBrush = SelectObject(hdc, myBrush);
1395 HPEN oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1397 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
1399 SelectObject(hdc, oldBrush);
1400 SelectObject(hdc, oldPen);
1405 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
1407 static errr term_user_win(int n)
1415 * React to global changes
1417 static errr term_xtra_win_react(player_type *player_ptr)
1421 for (int i = 0; i < 256; i++)
1423 win_pal[i] = angband_color_table[i][0];
1430 bool change = FALSE;
1431 for (int i = 0; i < 256; i++)
1433 rv = angband_color_table[i][1];
1434 gv = angband_color_table[i][2];
1435 bv = angband_color_table[i][3];
1436 code = PALETTERGB(rv, gv, bv);
1437 if (win_clr[i] != code)
1444 if (change) (void)new_palette();
1447 if (use_sound != arg_sound)
1450 use_sound = arg_sound;
1453 if (use_music != arg_music)
1456 use_music = arg_music;
1457 if (!arg_music) stop_music();
1458 else select_floor_music(player_ptr);
1461 if (use_graphics != arg_graphics)
1463 if (arg_graphics && !init_graphics())
1465 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
1466 arg_graphics = GRAPHICS_NONE;
1469 use_graphics = arg_graphics;
1470 reset_visuals(player_ptr);
1473 for (int i = 0; i < MAX_TERM_DATA; i++)
1476 term_data *td = &data[i];
1477 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
1479 Term_activate(&td->t);
1480 Term_resize(td->cols, td->rows);
1491 * Process at least one event
1493 static errr term_xtra_win_event(int v)
1498 if (GetMessage(&msg, NULL, 0, 0))
1500 TranslateMessage(&msg);
1501 DispatchMessage(&msg);
1506 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1508 TranslateMessage(&msg);
1509 DispatchMessage(&msg);
1518 * Process all pending events
1520 static errr term_xtra_win_flush(void)
1523 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1525 TranslateMessage(&msg);
1526 DispatchMessage(&msg);
1534 * Hack -- clear the screen
1536 * Make this more efficient
1538 static errr term_xtra_win_clear(void)
1540 term_data *td = (term_data*)(Term->data);
1543 rc.left = td->size_ow1;
1544 rc.right = rc.left + td->cols * td->tile_wid;
1545 rc.top = td->size_oh1;
1546 rc.bottom = rc.top + td->rows * td->tile_hgt;
1548 HDC hdc = GetDC(td->w);
1549 SetBkColor(hdc, RGB(0, 0, 0));
1550 SelectObject(hdc, td->font_id);
1551 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1555 rc.left = 0; rc.top = 0;
1559 ReleaseDC(td->w, hdc);
1565 * Hack -- make a noise
1567 static errr term_xtra_win_noise(void)
1569 MessageBeep(MB_ICONASTERISK);
1575 * Hack -- make a sound
1577 static errr term_xtra_win_sound(int v)
1580 if (!use_sound) return 1;
1581 if ((v < 0) || (v >= SOUND_MAX)) return 1;
1584 for (i = 0; i < SAMPLE_SOUND_MAX; i++)
1586 if (!sound_file[v][i])
1590 if (i == 0) return 1;
1592 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
1593 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
1597 * Hack -- play a music
1599 static errr term_xtra_win_music(int n, int v)
1603 if (n == TERM_XTRA_MUSIC_MUTE)
1605 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1606 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1609 if (!use_music) return 1;
1611 if (n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return 1;
1612 else if (v < 0 || v >= 1000) return(1); /*!< TODO */
1616 case TERM_XTRA_MUSIC_BASIC:
1617 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!music_file[v][i]) break;
1619 case TERM_XTRA_MUSIC_DUNGEON:
1620 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!dungeon_music_file[v][i]) break;
1622 case TERM_XTRA_MUSIC_QUEST:
1623 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!quest_music_file[v][i]) break;
1625 case TERM_XTRA_MUSIC_TOWN:
1626 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!town_music_file[v][i]) break;
1637 case TERM_XTRA_MUSIC_BASIC:
1638 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
1640 case TERM_XTRA_MUSIC_DUNGEON:
1641 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
1643 case TERM_XTRA_MUSIC_QUEST:
1644 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
1646 case TERM_XTRA_MUSIC_TOWN:
1647 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
1651 if (current_music_type == n && current_music_id == v)
1655 current_music_type = n;
1656 current_music_id = v;
1658 mop.lpstrDeviceType = mci_device_type;
1659 mop.lpstrElementName = buf;
1660 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1661 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1662 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
1663 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
1664 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
1670 * Delay for "x" milliseconds
1672 static int term_xtra_win_delay(int v)
1680 * todo z-termに影響があるのでplayer_typeの追加は保留
1681 * Do a "special thing"
1683 static errr term_xtra_win(int n, int v)
1687 case TERM_XTRA_NOISE:
1689 return (term_xtra_win_noise());
1691 case TERM_XTRA_MUSIC_BASIC:
1692 case TERM_XTRA_MUSIC_DUNGEON:
1693 case TERM_XTRA_MUSIC_QUEST:
1694 case TERM_XTRA_MUSIC_TOWN:
1696 return (term_xtra_win_music(n, v));
1698 case TERM_XTRA_SOUND:
1700 return (term_xtra_win_sound(v));
1702 case TERM_XTRA_BORED:
1704 return (term_xtra_win_event(0));
1706 case TERM_XTRA_EVENT:
1708 return (term_xtra_win_event(v));
1710 case TERM_XTRA_FLUSH:
1712 return (term_xtra_win_flush());
1714 case TERM_XTRA_CLEAR:
1716 return (term_xtra_win_clear());
1718 case TERM_XTRA_REACT:
1720 return (term_xtra_win_react(p_ptr));
1722 case TERM_XTRA_DELAY:
1724 return (term_xtra_win_delay(v));
1733 * Low level graphics (Assumes valid input).
1735 * Draw a "cursor" at (x,y), using a "yellow box".
1737 static errr term_curs_win(int x, int y)
1739 term_data *td = (term_data*)(Term->data);
1740 int tile_wid, tile_hgt;
1743 tile_wid = td->map_tile_wid;
1744 tile_hgt = td->map_tile_hgt;
1748 tile_wid = td->tile_wid;
1749 tile_hgt = td->tile_hgt;
1753 rc.left = x * tile_wid + td->size_ow1;
1754 rc.right = rc.left + tile_wid;
1755 rc.top = y * tile_hgt + td->size_oh1;
1756 rc.bottom = rc.top + tile_hgt;
1758 HDC hdc = GetDC(td->w);
1759 FrameRect(hdc, &rc, hbrYellow);
1760 ReleaseDC(td->w, hdc);
1766 * Low level graphics (Assumes valid input).
1768 * Draw a "big cursor" at (x,y), using a "yellow box".
1770 static errr term_bigcurs_win(int x, int y)
1772 term_data *td = (term_data*)(Term->data);
1773 int tile_wid, tile_hgt;
1776 term_curs_win(x, y);
1781 tile_wid = td->tile_wid;
1782 tile_hgt = td->tile_hgt;
1786 rc.left = x * tile_wid + td->size_ow1;
1787 rc.right = rc.left + 2 * tile_wid;
1788 rc.top = y * tile_hgt + td->size_oh1;
1789 rc.bottom = rc.top + tile_hgt;
1791 HDC hdc = GetDC(td->w);
1792 FrameRect(hdc, &rc, hbrYellow);
1793 ReleaseDC(td->w, hdc);
1799 * Low level graphics (Assumes valid input).
1801 * Erase a "block" of "n" characters starting at (x,y).
1803 static errr term_wipe_win(int x, int y, int n)
1805 term_data *td = (term_data*)(Term->data);
1807 rc.left = x * td->tile_wid + td->size_ow1;
1808 rc.right = rc.left + n * td->tile_wid;
1809 rc.top = y * td->tile_hgt + td->size_oh1;
1810 rc.bottom = rc.top + td->tile_hgt;
1812 HDC hdc = GetDC(td->w);
1813 SetBkColor(hdc, RGB(0, 0, 0));
1814 SelectObject(hdc, td->font_id);
1818 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1820 ReleaseDC(td->w, hdc);
1826 * Low level graphics. Assumes valid input.
1828 * Draw several ("n") chars, with an attr, at a given location.
1830 * All "graphic" data is handled by "term_pict_win()", below.
1832 * One would think there is a more efficient method for telling a window
1833 * what color it should be using to draw with, but perhaps simply changing
1834 * it every time is not too inefficient.
1836 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
1838 term_data *td = (term_data*)(Term->data);
1839 static HBITMAP WALL;
1840 static HBRUSH myBrush, oldBrush;
1842 static bool init_done = FALSE;
1845 WALL = LoadBitmap(hInstance, AppName);
1846 myBrush = CreatePatternBrush(WALL);
1851 rc.left = x * td->tile_wid + td->size_ow1;
1852 rc.right = rc.left + n * td->tile_wid;
1853 rc.top = y * td->tile_hgt + td->size_oh1;
1854 rc.bottom = rc.top + td->tile_hgt;
1856 HDC hdc = GetDC(td->w);
1857 SetBkColor(hdc, RGB(0, 0, 0));
1860 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
1864 SetTextColor(hdc, win_clr[a & 0x0F]);
1868 SetTextColor(hdc, win_clr[a]);
1871 SelectObject(hdc, td->font_id);
1872 if (use_bg) SetBkMode(hdc, TRANSPARENT);
1875 (td->tile_hgt != td->font_hgt) ||
1876 (td->tile_wid != td->font_wid))
1878 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1879 if (use_bg) DrawBG(hdc, &rc);
1881 rc.left += ((td->tile_wid - td->font_wid) / 2);
1882 rc.right = rc.left + td->font_wid;
1883 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
1884 rc.bottom = rc.top + td->font_hgt;
1886 for (int i = 0; i < n; i++)
1889 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1])
1891 rc.right += td->font_wid;
1892 oldBrush = SelectObject(hdc, myBrush);
1893 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1894 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1895 SelectObject(hdc, oldBrush);
1896 SelectObject(hdc, oldPen);
1897 rc.right -= td->font_wid;
1899 rc.left += 2 * td->tile_wid;
1900 rc.right += 2 * td->tile_wid;
1902 else if (iskanji(*(s + i))) /* 2バイト文字 */
1904 rc.right += td->font_wid;
1905 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
1907 rc.right -= td->font_wid;
1909 rc.left += 2 * td->tile_wid;
1910 rc.right += 2 * td->tile_wid;
1912 else if (*(s + i) == 127) {
1913 oldBrush = SelectObject(hdc, myBrush);
1914 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1915 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1916 SelectObject(hdc, oldBrush);
1917 SelectObject(hdc, oldPen);
1918 rc.left += td->tile_wid;
1919 rc.right += td->tile_wid;
1923 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1924 rc.left += td->tile_wid;
1925 rc.right += td->tile_wid;
1928 if (*(s + i) == 127)
1930 oldBrush = SelectObject(hdc, myBrush);
1931 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1932 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1933 SelectObject(hdc, oldBrush);
1934 SelectObject(hdc, oldPen);
1935 rc.left += td->tile_wid;
1936 rc.right += td->tile_wid;
1940 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1941 rc.left += td->tile_wid;
1942 rc.right += td->tile_wid;
1949 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc, s, n, NULL);
1952 ReleaseDC(td->w, hdc);
1958 * Low level graphics. Assumes valid input.
1960 * Draw an array of "special" attr/char pairs at the given location.
1962 * We use the "term_pict_win()" function for "graphic" data, which are
1963 * encoded by setting the "high-bits" of both the "attr" and the "char"
1964 * data. We use the "attr" to represent the "row" of the main bitmap,
1965 * and the "char" to represent the "col" of the main bitmap. The use
1966 * of this function is induced by the "higher_pict" flag.
1968 * If "graphics" is not available, we simply "wipe" the given grids.
1970 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)
1972 term_data *td = (term_data*)(Term->data);
1977 return (term_wipe_win(x, y, n));
1980 TERM_LEN w1 = infGraph.CellWidth;
1981 TERM_LEN h1 = infGraph.CellHeight;
1982 TERM_LEN tw1 = infGraph.TileWidth;
1983 TERM_LEN th1 = infGraph.TileHeight;
1984 TERM_LEN w2, h2, tw2 = 0;
1987 w2 = td->map_tile_wid;
1988 h2 = td->map_tile_hgt;
1995 if (use_bigtile) tw2 *= 2;
1998 TERM_LEN x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
1999 TERM_LEN y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
2000 HDC hdc = GetDC(td->w);
2001 HDC hdcSrc = CreateCompatibleDC(hdc);
2002 HBITMAP hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
2004 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2006 hdcMask = CreateCompatibleDC(hdc);
2007 SelectObject(hdcMask, infMask.hBitmap);
2010 for (i = 0; i < n; i++, x2 += w2)
2012 TERM_COLOR a = ap[i];
2014 int row = (a & 0x7F);
2015 int col = (c & 0x7F);
2016 TERM_LEN x1 = col * w1;
2017 TERM_LEN y1 = row * h1;
2019 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2021 TERM_LEN x3 = (tcp[i] & 0x7F) * w1;
2022 TERM_LEN y3 = (tap[i] & 0x7F) * h1;
2023 tw2 = tw2 * w1 / tw1;
2025 if ((tw1 == tw2) && (th1 == h2))
2027 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2028 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2029 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2033 SetStretchBltMode(hdc, COLORONCOLOR);
2034 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
2035 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
2036 if ((x1 != x3) || (y1 != y3))
2038 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2039 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2045 if ((w1 == tw2) && (h1 == h2))
2047 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2051 SetStretchBltMode(hdc, COLORONCOLOR);
2052 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2055 SelectObject(hdcSrc, hbmSrcOld);
2057 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2059 SelectObject(hdcMask, hbmSrcOld);
2063 ReleaseDC(td->w, hdc);
2068 static void windows_map(player_type *player_ptr)
2070 term_data *td = &data[0];
2072 if (!use_graphics) return;
2074 term_xtra_win_clear();
2075 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2076 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2077 td->map_active = TRUE;
2081 TERM_LEN max_x = player_ptr->current_floor_ptr->width;
2082 TERM_LEN max_y = player_ptr->current_floor_ptr->height;
2085 for (TERM_LEN x = min_x; x < max_x; x++)
2087 for (TERM_LEN y = min_y; y < max_y; y++)
2091 map_info(player_ptr, y, x, &a, (char*)&c, &ta, (char*)&tc);
2092 if ((a & 0x80) && (c & 0x80))
2094 term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2099 term_curs_win(player_ptr->x - min_x, player_ptr->y - min_y);
2100 Term_inkey(&c, TRUE, TRUE);
2102 td->map_active = FALSE;
2103 term_xtra_win_clear();
2109 * Create and initialize a "term_data" given a title
2111 static void term_data_link(term_data *td)
2114 term_init(t, td->cols, td->rows, td->keys);
2115 t->soft_cursor = TRUE;
2116 t->higher_pict = TRUE;
2117 t->attr_blank = TERM_WHITE;
2118 t->char_blank = ' ';
2119 t->user_hook = term_user_win;
2120 t->xtra_hook = term_xtra_win;
2121 t->curs_hook = term_curs_win;
2122 t->bigcurs_hook = term_bigcurs_win;
2123 t->wipe_hook = term_wipe_win;
2124 t->text_hook = term_text_win;
2125 t->pict_hook = term_pict_win;
2126 t->data = (vptr)(td);
2131 * Create the windows
2133 * First, instantiate the "default" values, then read the "ini_file"
2134 * to over-ride selected values, then create the windows, and fonts.
2136 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2137 * must make active to realize the palette.
2139 static void init_windows(void)
2143 WIPE(td, term_data);
2147 td->s = angband_term_name[0];
2163 for (int i = 1; i < MAX_TERM_DATA; i++)
2166 WIPE(td, term_data);
2167 td->s = angband_term_name[i];
2171 td->visible = FALSE;
2176 td->pos_x = (7 - i) * 30;
2177 td->pos_y = (7 - i) * 20;
2184 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2185 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2190 for (int i = 1; i < MAX_TERM_DATA; i++)
2193 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2194 td->dwExStyle = (WS_EX_TOOLWINDOW);
2197 for (int i = 0; i < MAX_TERM_DATA; i++)
2200 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2201 td->lf.lfCharSet = DEFAULT_CHARSET;
2202 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2203 term_force_font(td, NULL);
2204 if (!td->tile_wid) td->tile_wid = td->font_wid;
2205 if (!td->tile_hgt) td->tile_hgt = td->font_hgt;
2208 term_window_resize(td);
2211 for (int i = MAX_TERM_DATA - 1; i >= 1; --i)
2216 td->w = CreateWindowEx(td->dwExStyle, AngList,
2218 td->pos_x, td->pos_y,
2219 td->size_wid, td->size_hgt,
2220 HWND_DESKTOP, NULL, hInstance, NULL);
2222 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
2226 td->size_hack = TRUE;
2227 ShowWindow(td->w, SW_SHOW);
2228 td->size_hack = FALSE;
2232 angband_term[i] = &td->t;
2236 /* Activate the window */
2237 SetActiveWindow(td->w);
2242 term_window_pos(&data[i], HWND_TOPMOST);
2246 term_window_pos(&data[i], td->w);
2252 td->w = CreateWindowEx(td->dwExStyle, AppName,
2254 td->pos_x, td->pos_y,
2255 td->size_wid, td->size_hgt,
2256 HWND_DESKTOP, NULL, hInstance, NULL);
2258 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
2261 angband_term[0] = &td->t;
2262 normsize.x = td->cols;
2263 normsize.y = td->rows;
2265 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
2266 else ShowWindow(td->w, SW_SHOW);
2268 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2269 (void)new_palette();
2270 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
2271 (void)term_xtra_win_flush();
2278 static void setup_menus(void)
2280 HMENU hm = GetMenu(data[0].w);
2281 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2282 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2283 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2284 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2285 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2287 if (!current_world_ptr->character_generated)
2289 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
2290 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
2293 if (current_world_ptr->character_generated)
2295 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_ENABLED);
2298 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_ENABLED);
2299 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_ENABLED);
2301 for (int i = 0; i < MAX_TERM_DATA; i++)
2303 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2304 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i, (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
2305 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_ENABLED);
2308 for (int i = 0; i < MAX_TERM_DATA; i++)
2310 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2312 if (data[i].visible)
2314 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2318 for (int i = 0; i < MAX_TERM_DATA; i++)
2320 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2321 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i, (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
2322 if (data[i].visible)
2324 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_ENABLED);
2328 for (int i = 0; i < MAX_TERM_DATA; i++)
2330 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2331 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i, (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
2332 if (data[i].visible)
2334 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_ENABLED);
2339 for (int i = 0; i < MAX_TERM_DATA; i++)
2341 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2342 if (data[i].visible)
2344 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
2348 for (int i = 0; i < MAX_TERM_DATA; i++)
2350 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2351 if (data[i].visible)
2353 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
2357 for (int i = 0; i < MAX_TERM_DATA; i++)
2359 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2360 if (data[i].visible)
2362 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2366 for (int i = 0; i < MAX_TERM_DATA; i++)
2368 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2370 if (data[i].visible)
2372 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2376 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2377 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2378 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2379 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2380 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2383 EnableMenuItem(hm, IDM_OPTIONS_SAVER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2386 if (use_graphics != GRAPHICS_NONE)
2387 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
2389 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2391 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
2392 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
2393 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
2394 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
2395 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
2396 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
2397 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
2398 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
2399 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
2400 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
2401 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
2402 (arg_music ? MF_CHECKED : MF_UNCHECKED));
2403 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
2404 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
2405 CheckMenuItem(hm, IDM_OPTIONS_BG,
2406 (use_bg ? MF_CHECKED : MF_UNCHECKED));
2409 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
2410 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
2412 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
2413 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
2414 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
2415 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
2416 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
2417 EnableMenuItem(hm, IDM_OPTIONS_SAVER, MF_BYCOMMAND | MF_ENABLED);
2422 * Check for double clicked (or dragged) savefile
2424 * Apparently, Windows copies the entire filename into the first
2425 * piece of the "command line string". Perhaps we should extract
2426 * the "basename" of that filename and append it to the "save" dir.
2428 static void check_for_save_file(player_type *player_ptr, LPSTR cmd_line)
2434 strcat(savefile, s);
2435 validate_file(savefile);
2436 game_in_progress = TRUE;
2437 play_game(player_ptr, FALSE);
2442 * Process a menu command
2444 static void process_menus(player_type *player_ptr, WORD wCmd)
2454 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2456 else if (game_in_progress)
2458 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
2462 game_in_progress = TRUE;
2464 play_game(player_ptr, TRUE);
2474 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2476 else if (game_in_progress)
2478 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
2482 memset(&ofn, 0, sizeof(ofn));
2483 ofn.lStructSize = sizeof(ofn);
2484 ofn.hwndOwner = data[0].w;
2485 ofn.lpstrFilter = "Save Files (*.)\0*\0";
2486 ofn.nFilterIndex = 1;
2487 ofn.lpstrFile = savefile;
2488 ofn.nMaxFile = 1024;
2489 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
2490 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
2492 if (GetOpenFileName(&ofn))
2494 validate_file(savefile);
2495 game_in_progress = TRUE;
2497 play_game(player_ptr, FALSE);
2506 if (game_in_progress && current_world_ptr->character_generated)
2510 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
2515 do_cmd_save_game(player_ptr, FALSE);
2519 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
2526 if (game_in_progress && current_world_ptr->character_generated)
2530 plog(_("今は終了できません。", "You may not do that right now."));
2535 forget_lite(player_ptr->current_floor_ptr);
2536 forget_view(player_ptr->current_floor_ptr);
2537 clear_mon_lite(player_ptr->current_floor_ptr);
2539 Term_key_push(SPECIAL_KEY_QUIT);
2546 case IDM_FILE_SCORE:
2549 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
2550 highscore_fd = fd_open(buf, O_RDONLY);
2551 if (highscore_fd < 0)
2553 msg_print("Score file unavailable.");
2559 display_scores_aux(0, MAX_HISCORES, -1, NULL);
2560 (void)fd_close(highscore_fd);
2568 case IDM_FILE_MOVIE:
2572 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2574 else if (game_in_progress)
2576 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
2580 memset(&ofn, 0, sizeof(ofn));
2581 ofn.lStructSize = sizeof(ofn);
2582 ofn.hwndOwner = data[0].w;
2583 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
2584 ofn.nFilterIndex = 1;
2585 ofn.lpstrFile = savefile;
2586 ofn.nMaxFile = 1024;
2587 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
2588 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2590 if (GetOpenFileName(&ofn))
2592 prepare_browse_movie_aux(savefile);
2593 play_game(player_ptr, FALSE);
2601 case IDM_WINDOW_VIS_0:
2603 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
2606 case IDM_WINDOW_VIS_1:
2607 case IDM_WINDOW_VIS_2:
2608 case IDM_WINDOW_VIS_3:
2609 case IDM_WINDOW_VIS_4:
2610 case IDM_WINDOW_VIS_5:
2611 case IDM_WINDOW_VIS_6:
2612 case IDM_WINDOW_VIS_7:
2614 int i = wCmd - IDM_WINDOW_VIS_0;
2615 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2621 ShowWindow(td->w, SW_SHOW);
2622 term_data_redraw(player_ptr, td);
2626 td->visible = FALSE;
2628 ShowWindow(td->w, SW_HIDE);
2633 case IDM_WINDOW_FONT_0:
2634 case IDM_WINDOW_FONT_1:
2635 case IDM_WINDOW_FONT_2:
2636 case IDM_WINDOW_FONT_3:
2637 case IDM_WINDOW_FONT_4:
2638 case IDM_WINDOW_FONT_5:
2639 case IDM_WINDOW_FONT_6:
2640 case IDM_WINDOW_FONT_7:
2642 int i = wCmd - IDM_WINDOW_FONT_0;
2643 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2646 term_change_font(td);
2649 case IDM_WINDOW_POS_1:
2650 case IDM_WINDOW_POS_2:
2651 case IDM_WINDOW_POS_3:
2652 case IDM_WINDOW_POS_4:
2653 case IDM_WINDOW_POS_5:
2654 case IDM_WINDOW_POS_6:
2655 case IDM_WINDOW_POS_7:
2657 int i = wCmd - IDM_WINDOW_POS_0;
2658 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2661 if (!td->posfix && td->visible)
2664 term_window_pos(td, HWND_TOPMOST);
2669 term_window_pos(td, data[0].w);
2674 case IDM_WINDOW_BIZ_0:
2675 case IDM_WINDOW_BIZ_1:
2676 case IDM_WINDOW_BIZ_2:
2677 case IDM_WINDOW_BIZ_3:
2678 case IDM_WINDOW_BIZ_4:
2679 case IDM_WINDOW_BIZ_5:
2680 case IDM_WINDOW_BIZ_6:
2681 case IDM_WINDOW_BIZ_7:
2683 int i = wCmd - IDM_WINDOW_BIZ_0;
2684 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2687 td->bizarre = !td->bizarre;
2689 term_window_resize(td);
2692 case IDM_WINDOW_I_WID_0:
2693 case IDM_WINDOW_I_WID_1:
2694 case IDM_WINDOW_I_WID_2:
2695 case IDM_WINDOW_I_WID_3:
2696 case IDM_WINDOW_I_WID_4:
2697 case IDM_WINDOW_I_WID_5:
2698 case IDM_WINDOW_I_WID_6:
2699 case IDM_WINDOW_I_WID_7:
2701 int i = wCmd - IDM_WINDOW_I_WID_0;
2702 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2707 term_window_resize(td);
2710 case IDM_WINDOW_D_WID_0:
2711 case IDM_WINDOW_D_WID_1:
2712 case IDM_WINDOW_D_WID_2:
2713 case IDM_WINDOW_D_WID_3:
2714 case IDM_WINDOW_D_WID_4:
2715 case IDM_WINDOW_D_WID_5:
2716 case IDM_WINDOW_D_WID_6:
2717 case IDM_WINDOW_D_WID_7:
2719 int i = wCmd - IDM_WINDOW_D_WID_0;
2720 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2725 term_window_resize(td);
2728 case IDM_WINDOW_I_HGT_0:
2729 case IDM_WINDOW_I_HGT_1:
2730 case IDM_WINDOW_I_HGT_2:
2731 case IDM_WINDOW_I_HGT_3:
2732 case IDM_WINDOW_I_HGT_4:
2733 case IDM_WINDOW_I_HGT_5:
2734 case IDM_WINDOW_I_HGT_6:
2735 case IDM_WINDOW_I_HGT_7:
2737 int i = wCmd - IDM_WINDOW_I_HGT_0;
2738 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2743 term_window_resize(td);
2746 case IDM_WINDOW_D_HGT_0:
2747 case IDM_WINDOW_D_HGT_1:
2748 case IDM_WINDOW_D_HGT_2:
2749 case IDM_WINDOW_D_HGT_3:
2750 case IDM_WINDOW_D_HGT_4:
2751 case IDM_WINDOW_D_HGT_5:
2752 case IDM_WINDOW_D_HGT_6:
2753 case IDM_WINDOW_D_HGT_7:
2755 int i = wCmd - IDM_WINDOW_D_HGT_0;
2756 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2761 term_window_resize(td);
2764 case IDM_OPTIONS_NO_GRAPHICS:
2768 plog("You may not do that right now.");
2772 if (arg_graphics != GRAPHICS_NONE)
2774 arg_graphics = GRAPHICS_NONE;
2775 term_xtra_win_react(player_ptr);
2776 Term_key_push(KTRL('R'));
2781 case IDM_OPTIONS_OLD_GRAPHICS:
2785 plog("You may not do that right now.");
2789 if (arg_graphics != GRAPHICS_ORIGINAL)
2791 arg_graphics = GRAPHICS_ORIGINAL;
2792 term_xtra_win_react(player_ptr);
2793 Term_key_push(KTRL('R'));
2798 case IDM_OPTIONS_NEW_GRAPHICS:
2802 plog("You may not do that right now.");
2806 if (arg_graphics != GRAPHICS_ADAM_BOLT)
2808 arg_graphics = GRAPHICS_ADAM_BOLT;
2809 term_xtra_win_react(player_ptr);
2810 Term_key_push(KTRL('R'));
2815 case IDM_OPTIONS_NEW2_GRAPHICS:
2819 plog("You may not do that right now.");
2823 if (arg_graphics != GRAPHICS_HENGBAND)
2825 arg_graphics = GRAPHICS_HENGBAND;
2826 term_xtra_win_react(player_ptr);
2827 Term_key_push(KTRL('R'));
2832 case IDM_OPTIONS_BIGTILE:
2837 plog("You may not do that right now.");
2841 arg_bigtile = !arg_bigtile;
2842 Term_activate(&td->t);
2843 Term_resize(td->cols, td->rows);
2844 InvalidateRect(td->w, NULL, TRUE);
2847 case IDM_OPTIONS_MUSIC:
2851 plog("You may not do that right now.");
2855 arg_music = !arg_music;
2856 term_xtra_win_react(player_ptr);
2857 Term_key_push(KTRL('R'));
2860 case IDM_OPTIONS_SOUND:
2864 plog("You may not do that right now.");
2868 arg_sound = !arg_sound;
2869 term_xtra_win_react(player_ptr);
2870 Term_key_push(KTRL('R'));
2873 case IDM_OPTIONS_BG:
2877 plog("You may not do that right now.");
2883 term_xtra_win_react(player_ptr);
2884 Term_key_push(KTRL('R'));
2887 case IDM_OPTIONS_OPEN_BG:
2891 plog("You may not do that right now.");
2895 memset(&ofn, 0, sizeof(ofn));
2896 ofn.lStructSize = sizeof(ofn);
2897 ofn.hwndOwner = data[0].w;
2898 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
2899 ofn.nFilterIndex = 1;
2900 ofn.lpstrFile = bg_bitmap_file;
2901 ofn.nMaxFile = 1023;
2902 ofn.lpstrInitialDir = NULL;
2903 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
2904 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
2906 if (GetOpenFileName(&ofn))
2912 term_xtra_win_react(player_ptr);
2913 Term_key_push(KTRL('R'));
2916 case IDM_DUMP_SCREEN_HTML:
2918 static char buf[1024] = "";
2919 memset(&ofn, 0, sizeof(ofn));
2920 ofn.lStructSize = sizeof(ofn);
2921 ofn.hwndOwner = data[0].w;
2922 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
2923 ofn.nFilterIndex = 1;
2924 ofn.lpstrFile = buf;
2925 ofn.nMaxFile = 1023;
2926 ofn.lpstrDefExt = "html";
2927 ofn.lpstrInitialDir = NULL;
2928 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
2929 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
2931 if (GetSaveFileName(&ofn))
2933 do_cmd_save_screen_html_aux(buf, 0);
2938 case IDM_OPTIONS_SAVER:
2942 DestroyWindow(hwndSaver);
2947 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
2948 "Angband Screensaver",
2949 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
2950 0, 0, GetSystemMetrics(SM_CXSCREEN),
2951 GetSystemMetrics(SM_CYSCREEN),
2952 NULL, NULL, hInstance, NULL);
2956 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2960 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
2965 case IDM_OPTIONS_MAP:
2967 windows_map(player_ptr);
2971 case IDM_HELP_CONTENTS:
2975 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
2976 if (check_file(tmp))
2978 sprintf(buf, "winhelp.exe %s", tmp);
2979 WinExec(buf, SW_NORMAL);
2983 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
2984 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
2991 static bool process_keydown(WPARAM wParam, LPARAM lParam)
2997 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
2998 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
2999 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
3001 term_no_press = (ma) ? TRUE : FALSE;
3002 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]))
3004 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
3005 bool numpad = FALSE;
3008 if (mc) Term_keypress('C');
3009 if (ms) Term_keypress('S');
3010 if (ma) Term_keypress('A');
3012 int i = LOBYTE(HIWORD(lParam));
3017 term_no_press = TRUE;
3036 term_no_press = TRUE;
3051 if (numpad) Term_keypress('K');
3053 Term_keypress(hexsym[i / 16]);
3054 Term_keypress(hexsym[i % 16]);
3065 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
3067 LRESULT PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3071 td = (term_data *)GetWindowLong(hWnd, 0);
3077 SetWindowLong(hWnd, 0, (LONG)(my_td));
3082 mop.dwCallback = (DWORD)hWnd;
3085 case WM_GETMINMAXINFO:
3090 lpmmi = (MINMAXINFO*)lParam;
3093 rc.left = rc.top = 0;
3094 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
3095 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
3097 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3099 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
3100 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
3106 BeginPaint(hWnd, &ps);
3107 if (td) term_data_redraw(p_ptr, td);
3108 EndPaint(hWnd, &ps);
3109 ValidateRect(hWnd, NULL);
3114 if (wParam == MCI_NOTIFY_SUCCESSFUL)
3116 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
3117 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
3125 if (process_keydown(wParam, lParam))
3131 if (term_no_press) term_no_press = FALSE;
3132 else Term_keypress(wParam);
3135 case WM_LBUTTONDOWN:
3137 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
3138 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
3148 TERM_LEN dx = abs(oldx - mousex) + 1;
3149 TERM_LEN dy = abs(oldy - mousey) + 1;
3150 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
3151 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
3157 int sz = (dx + 3) * dy;
3159 int sz = (dx + 2) * dy;
3161 hGlobal = GlobalAlloc(GHND, sz + 1);
3162 if (hGlobal == NULL) return 0;
3163 lpStr = (LPSTR)GlobalLock(hGlobal);
3165 for (int i = 0; i < dy; i++)
3169 char **scr = data[0].t.scr->c;
3171 C_MAKE(s, (dx + 1), char);
3172 strncpy(s, &scr[oy + i][ox], dx);
3176 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
3179 if (ox + dx < data[0].cols)
3181 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
3184 for (int j = 0; j < dx; j++)
3186 if (s[j] == 127) s[j] = '#';
3190 for (int j = 0; j < dx; j++)
3192 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
3202 GlobalUnlock(hGlobal);
3203 if (OpenClipboard(hWnd) == 0)
3205 GlobalFree(hGlobal);
3210 SetClipboardData(CF_TEXT, hGlobal);
3217 if (!mouse_down) return 0;
3220 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
3221 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
3226 dx = abs(oldx - mousex) + 1;
3227 dy = abs(oldy - mousey) + 1;
3228 ox = (oldx > mousex) ? mousex : oldx;
3229 oy = (oldy > mousey) ? mousey : oldy;
3230 term_inversed_area(hWnd, ox, oy, dx, dy);
3237 dx = abs(cx - mousex) + 1;
3238 dy = abs(cy - mousey) + 1;
3239 ox = (cx > mousex) ? mousex : cx;
3240 oy = (cy > mousey) ? mousey : cy;
3241 term_inversed_area(hWnd, ox, oy, dx, dy);
3254 if (!game_in_progress || !current_world_ptr->character_generated)
3262 plog(_("今は終了できません。", "You may not do that right now."));
3267 forget_lite(p_ptr->current_floor_ptr);
3268 forget_view(p_ptr->current_floor_ptr);
3269 clear_mon_lite(p_ptr->current_floor_ptr);
3270 Term_key_push(SPECIAL_KEY_QUIT);
3273 case WM_QUERYENDSESSION:
3275 if (!game_in_progress || !current_world_ptr->character_generated)
3282 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
3283 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
3285 p_ptr->panic_save = 1;
3286 signals_ignore_tstp();
3287 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
3288 (void)save_player(p_ptr);
3299 process_menus(p_ptr, LOWORD(wParam));
3305 if (!td->w) return 1;
3306 if (td->size_hack) return 1;
3308 // todo 二重のswitch文。後で分割する.
3311 case SIZE_MINIMIZED:
3313 for (int i = 1; i < MAX_TERM_DATA; i++)
3315 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
3320 case SIZE_MAXIMIZED:
3323 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
3324 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
3325 if ((td->cols != cols) || (td->rows != rows))
3329 if (!IsZoomed(td->w) && !IsIconic(td->w))
3331 normsize.x = td->cols;
3332 normsize.y = td->rows;
3335 Term_activate(&td->t);
3336 Term_resize(td->cols, td->rows);
3337 InvalidateRect(td->w, NULL, TRUE);
3340 td->size_hack = TRUE;
3341 for (int i = 1; i < MAX_TERM_DATA; i++)
3343 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
3346 td->size_hack = FALSE;
3354 case WM_PALETTECHANGED:
3356 if ((HWND)wParam == hWnd) return 0;
3358 case WM_QUERYNEWPALETTE:
3360 if (!paletted) return 0;
3362 HDC hdc = GetDC(hWnd);
3363 SelectPalette(hdc, hPal, FALSE);
3364 int i = RealizePalette(hdc);
3365 if (i) InvalidateRect(hWnd, NULL, TRUE);
3367 ReleaseDC(hWnd, hdc);
3372 if (!wParam || HIWORD(lParam)) break;
3374 for (int i = 1; i < MAX_TERM_DATA; i++)
3376 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
3382 case WM_ACTIVATEAPP:
3384 if (IsIconic(td->w)) break;
3386 for (int i = 1; i < MAX_TERM_DATA; i++)
3388 if (data[i].visible)
3392 ShowWindow(data[i].w, SW_SHOW);
3396 ShowWindow(data[i].w, SW_HIDE);
3403 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3408 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
3410 LRESULT PASCAL AngbandListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3414 td = (term_data *)GetWindowLong(hWnd, 0);
3420 SetWindowLong(hWnd, 0, (LONG)(my_td));
3427 case WM_GETMINMAXINFO:
3432 lpmmi = (MINMAXINFO*)lParam;
3435 rc.left = rc.top = 0;
3436 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
3437 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
3439 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3440 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
3441 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
3447 if (!td->w) return 1;
3448 if (td->size_hack) return 1;
3450 td->size_hack = TRUE;
3452 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
3453 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
3454 if ((td->cols != cols) || (td->rows != rows))
3456 term *old_term = Term;
3459 Term_activate(&td->t);
3460 Term_resize(td->cols, td->rows);
3461 Term_activate(old_term);
3462 InvalidateRect(td->w, NULL, TRUE);
3463 p_ptr->window = 0xFFFFFFFF;
3464 handle_stuff(p_ptr);
3467 td->size_hack = FALSE;
3472 BeginPaint(hWnd, &ps);
3473 if (td) term_data_redraw(p_ptr, td);
3474 EndPaint(hWnd, &ps);
3480 if (process_keydown(wParam, lParam))
3487 if (term_no_press) term_no_press = FALSE;
3488 else Term_keypress(wParam);
3491 case WM_PALETTECHANGED:
3493 if ((HWND)wParam == hWnd) return FALSE;
3495 case WM_QUERYNEWPALETTE:
3497 if (!paletted) return 0;
3499 HDC hdc = GetDC(hWnd);
3500 SelectPalette(hdc, hPal, FALSE);
3501 int i = RealizePalette(hdc);
3502 if (i) InvalidateRect(hWnd, NULL, TRUE);
3504 ReleaseDC(hWnd, hdc);
3507 case WM_NCLBUTTONDOWN:
3510 if (wParam == HTCLOSE) wParam = HTSYSMENU;
3511 #endif /* HTCLOSE */
3513 if (wParam == HTSYSMENU)
3517 td->visible = FALSE;
3518 ShowWindow(td->w, SW_HIDE);
3528 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3532 LRESULT PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3534 static int iMouse = 0;
3535 static WORD xMouse = 0;
3536 static WORD yMouse = 0;
3551 case WM_LBUTTONDOWN:
3552 case WM_MBUTTONDOWN:
3553 case WM_RBUTTONDOWN:
3556 SendMessage(hWnd, WM_CLOSE, 0, 0);
3563 int dx = LOWORD(lParam) - xMouse;
3564 int dy = HIWORD(lParam) - yMouse;
3566 if (dx < 0) dx = -dx;
3567 if (dy < 0) dy = -dy;
3569 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
3571 SendMessage(hWnd, WM_CLOSE, 0, 0);
3576 xMouse = LOWORD(lParam);
3577 yMouse = HIWORD(lParam);
3583 DestroyWindow(hwndSaver);
3589 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3594 * Display warning message (see "z-util.c")
3596 static void hack_plog(concptr str)
3601 MessageBox(NULL, str, "警告!",
3602 MB_ICONEXCLAMATION | MB_OK);
3604 MessageBox(NULL, str, "Warning",
3605 MB_ICONEXCLAMATION | MB_OK);
3613 * Display error message and quit (see "z-util.c")
3615 static void hack_quit(concptr str)
3620 MessageBox(NULL, str, "エラー!",
3621 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3623 MessageBox(NULL, str, "Error",
3624 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3629 UnregisterClass(AppName, hInstance);
3630 if (hIcon) DestroyIcon(hIcon);
3637 * Display warning message (see "z-util.c")
3639 static void hook_plog(concptr str)
3644 MessageBox(data[0].w, str, "警告!",
3645 MB_ICONEXCLAMATION | MB_OK);
3647 MessageBox(data[0].w, str, "Warning",
3648 MB_ICONEXCLAMATION | MB_OK);
3656 * Display error message and quit (see "z-util.c")
3658 static void hook_quit(concptr str)
3663 MessageBox(data[0].w, str, "エラー!",
3664 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3666 MessageBox(data[0].w, str, "Error",
3667 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3672 for (int i = MAX_TERM_DATA - 1; i >= 0; --i)
3674 term_force_font(&data[i], NULL);
3675 if (data[i].font_want) string_free(data[i].font_want);
3676 if (data[i].w) DestroyWindow(data[i].w);
3680 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
3681 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
3682 if (infMask.hPalette) DeleteObject(infMask.hPalette);
3683 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
3685 DeleteObject(hbrYellow);
3688 if (hPal) DeleteObject(hPal);
3690 UnregisterClass(AppName, hInstance);
3691 if (hIcon) DestroyIcon(hIcon);
3700 static void init_stuff(void)
3703 GetModuleFileName(hInstance, path, 512);
3705 strcpy(path + strlen(path) - 4, ".INI");
3706 ini_file = string_make(path);
3707 int i = strlen(path);
3711 if (path[i] == '\\')
3717 strcpy(path + i + 1, "lib\\");
3718 validate_dir(path, TRUE);
3719 init_file_paths(path);
3720 validate_dir(ANGBAND_DIR_APEX, FALSE);
3721 validate_dir(ANGBAND_DIR_BONE, FALSE);
3722 if (!check_dir(ANGBAND_DIR_EDIT))
3724 validate_dir(ANGBAND_DIR_DATA, TRUE);
3728 validate_dir(ANGBAND_DIR_DATA, FALSE);
3731 validate_dir(ANGBAND_DIR_FILE, TRUE);
3732 validate_dir(ANGBAND_DIR_HELP, FALSE);
3733 validate_dir(ANGBAND_DIR_INFO, FALSE);
3734 validate_dir(ANGBAND_DIR_PREF, TRUE);
3735 validate_dir(ANGBAND_DIR_SAVE, FALSE);
3736 validate_dir(ANGBAND_DIR_USER, TRUE);
3737 validate_dir(ANGBAND_DIR_XTRA, TRUE);
3738 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
3740 validate_file(path);
3741 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
3742 ANGBAND_DIR_XTRA_GRAF = string_make(path);
3743 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
3745 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
3746 ANGBAND_DIR_XTRA_SOUND = string_make(path);
3747 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
3749 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
3750 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
3751 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
3753 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
3754 ANGBAND_DIR_XTRA_HELP = string_make(path);
3759 * todo よく見るとhMutexはちゃんと使われていない……?
3760 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
3762 static bool is_already_running(void)
3765 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
3766 if (GetLastError() == ERROR_ALREADY_EXISTS)
3776 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
3778 int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
3784 setlocale(LC_ALL, "ja_JP");
3787 if (is_already_running())
3790 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
3792 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3796 if (hPrevInst == NULL)
3798 wc.style = CS_CLASSDC;
3799 wc.lpfnWndProc = AngbandWndProc;
3802 wc.hInstance = hInst;
3803 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
3804 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
3805 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
3806 wc.lpszMenuName = AppName;
3807 wc.lpszClassName = AppName;
3809 if (!RegisterClass(&wc)) exit(1);
3811 wc.lpfnWndProc = AngbandListProc;
3812 wc.lpszMenuName = NULL;
3813 wc.lpszClassName = AngList;
3815 if (!RegisterClass(&wc)) exit(2);
3817 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
3818 wc.lpfnWndProc = AngbandSaverProc;
3820 wc.lpszMenuName = NULL;
3821 wc.lpszClassName = "WindowsScreenSaverClass";
3823 if (!RegisterClass(&wc)) exit(3);
3826 plog_aux = hack_plog;
3827 quit_aux = hack_quit;
3828 core_aux = hack_quit;
3831 for (int i = 0; special_key_list[i]; ++i)
3833 special_key[special_key_list[i]] = TRUE;
3836 for (int i = 0; ignore_key_list[i]; ++i)
3838 ignore_key[ignore_key_list[i]] = TRUE;
3842 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
3843 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
3844 ReleaseDC(NULL, hdc);
3846 for (int i = 0; i < 256; i++)
3848 byte rv = angband_color_table[i][1];
3849 byte gv = angband_color_table[i][2];
3850 byte bv = angband_color_table[i][3];
3851 win_clr[i] = PALETTERGB(rv, gv, bv);
3852 angband_color_table[i][0] = win_pal[i];
3858 plog_aux = hook_plog;
3859 quit_aux = hook_quit;
3860 core_aux = hook_quit;
3862 ANGBAND_SYS = "win";
3863 if (7 != GetKeyboardType(0))
3864 ANGBAND_KEYBOARD = "0";
3867 switch (GetKeyboardType(1))
3869 case 0x0D01: case 0x0D02:
3870 case 0x0D03: case 0x0D04:
3871 case 0x0D05: case 0x0D06:
3873 ANGBAND_KEYBOARD = "NEC98";
3877 ANGBAND_KEYBOARD = "JAPAN";
3882 Term_activate(term_screen);
3883 init_angband(p_ptr);
3886 if (lpCmdLine[0] == '-') {
3887 switch (lpCmdLine[1])
3892 if (!lpCmdLine[2]) break;
3893 chuukei_server = TRUE;
3894 if (connect_chuukei_server(&lpCmdLine[2]) < 0) {
3895 msg_print("connect fail");
3898 msg_print("connect");
3906 if (!lpCmdLine[2]) break;
3907 chuukei_client = TRUE;
3908 connect_chuukei_server(&lpCmdLine[2]);
3909 play_game(player_ptr, FALSE);
3916 if (!lpCmdLine[2]) break;
3917 prepare_browse_movie(&lpCmdLine[2]);
3918 play_game(player_ptr, FALSE);
3927 if (!chuukei_server) check_for_save_file(lpCmdLine);
3929 check_for_save_file(p_ptr, lpCmdLine);
3932 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
3934 while (GetMessage(&msg, NULL, 0, 0))
3936 TranslateMessage(&msg);
3937 DispatchMessage(&msg);
3943 #endif /* WINDOWS */