2 * todo main関数を含むファイルの割に長過ぎる。main-win-utils.cなどといった形で分割したい
4 * @brief Windows版固有実装(メインエントリポイント含む)
6 * @author Hengband Team
10 * Windows98かその前後の頃を起点としたAPI実装。
12 * DirectXといった昨今描画に標準的となったライブラリも用いていない。
13 * タイルの描画処理などについては、現在動作の詳細を検証中。
17 * Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, and others
19 * This software may be copied and distributed for educational, research,
20 * and not for profit purposes provided that this copyright and statement
21 * are included in all such copies.
24 * This file helps Angband work with Windows computers.
26 * To use this file, use an appropriate "Makefile" or "Project File",
27 * make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
28 * make sure to obtain various extra files as described below.
30 * The official compilation uses the CodeWarrior Pro compiler, which
31 * includes a special project file and precompilable header file.
35 * The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
36 * and/or color redefinitions.
40 * The "lib/user/font-win.prf" contains attr/char mappings for use with the
41 * normal "lib/xtra/font/*.fon" font files.
45 * The "lib/user/graf-win.prf" contains attr/char mappings for use with the
46 * special "lib/xtra/graf/*.bmp" bitmap files, which are activated by a menu
51 * Compiling this file, and using the resulting executable, requires
52 * several extra files not distributed with the standard Angband code.
53 * In any case, some "*.fon" files (including "8X13.FON" if nothing else)
54 * must be placed into "lib/xtra/font/". All of these extra files can be found
55 * in the "ext-win" archive.
59 * The "term_xtra_win_clear()" function should probably do a low-level
60 * clear of the current window, and redraw the borders and other things,
61 * if only for efficiency.
65 * A simpler method is needed for selecting the "tile size" for windows.
69 * The various "warning" messages assume the existance of the "screen.w"
70 * window, I think, and only a few calls actually check for its existance,
71 * this may be okay since "NULL" means "on top of all windows". (?) The
72 * user must never be allowed to "hide" the main window, or the "menubar"
77 * Special "Windows Help Files" can be placed into "lib/xtra/help/" for
78 * use with the "winhelp.exe" program. These files *may* be available
79 * at the ftp site somewhere, but I have not seen them.
83 * Initial framework (and most code) by Ben Harrison (benh@phial.com).
85 * Original code by Skirmantas Kligys (kligys@scf.usc.edu).
87 * Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
88 * and Chris R. Martin (crm7479@tam2000.tamu.edu).
92 #include "autopick/autopick-pref-processor.h"
93 #include "cmd-io/cmd-process-screen.h"
94 #include "cmd-io/cmd-save.h"
95 #include "core/game-play.h"
96 #include "core/player-processor.h"
97 #include "core/scores.h"
98 #include "core/special-internal-keys.h"
99 #include "core/stuff-handler.h"
100 #include "core/visuals-reseter.h"
101 #include "dungeon/quest.h"
102 #include "floor/floor-events.h"
103 #include "floor/floor.h"
104 #include "game-option/runtime-arguments.h"
105 #include "game-option/special-options.h"
106 #include "io/chuukei.h"
107 #include "io/files-util.h"
109 #include "io/input-key-acceptor.h"
110 #include "io/signal-handlers.h"
111 #include "io/write-diary.h"
112 #include "main/init.h"
113 #include "main/music-definitions-table.h"
114 #include "main/sound-definitions-table.h"
115 #include "main/sound-of-music.h"
116 #include "system/angband-version.h"
117 #include "system/angband.h"
118 #include "system/system-variables.h"
119 #include "term/gameterm.h"
120 #include "term/term-color-types.h"
121 #include "util/angband-files.h"
122 #include "util/string-processor.h"
123 #include "view/display-main-window.h"
124 #include "view/display-messages.h"
125 #include "world/world.h"
131 #include "term/z-term.h"
133 #include "dungeon/dungeon.h"
136 * Available graphic modes
138 #define GRAPHICS_NONE 0
139 #define GRAPHICS_ORIGINAL 1
140 #define GRAPHICS_ADAM_BOLT 2
141 #define GRAPHICS_HENGBAND 3
144 * Menu constants -- see "ANGBAND.RC"
146 #define IDM_FILE_NEW 100
147 #define IDM_FILE_OPEN 101
148 #define IDM_FILE_SAVE 110
149 #define IDM_FILE_SCORE 120
150 #define IDM_FILE_MOVIE 121
151 #define IDM_FILE_EXIT 130
153 #define IDM_WINDOW_VIS_0 200
154 #define IDM_WINDOW_VIS_1 201
155 #define IDM_WINDOW_VIS_2 202
156 #define IDM_WINDOW_VIS_3 203
157 #define IDM_WINDOW_VIS_4 204
158 #define IDM_WINDOW_VIS_5 205
159 #define IDM_WINDOW_VIS_6 206
160 #define IDM_WINDOW_VIS_7 207
162 #define IDM_WINDOW_FONT_0 210
163 #define IDM_WINDOW_FONT_1 211
164 #define IDM_WINDOW_FONT_2 212
165 #define IDM_WINDOW_FONT_3 213
166 #define IDM_WINDOW_FONT_4 214
167 #define IDM_WINDOW_FONT_5 215
168 #define IDM_WINDOW_FONT_6 216
169 #define IDM_WINDOW_FONT_7 217
171 #define IDM_WINDOW_POS_0 220
172 #define IDM_WINDOW_POS_1 221
173 #define IDM_WINDOW_POS_2 222
174 #define IDM_WINDOW_POS_3 223
175 #define IDM_WINDOW_POS_4 224
176 #define IDM_WINDOW_POS_5 225
177 #define IDM_WINDOW_POS_6 226
178 #define IDM_WINDOW_POS_7 227
180 #define IDM_WINDOW_BIZ_0 230
181 #define IDM_WINDOW_BIZ_1 231
182 #define IDM_WINDOW_BIZ_2 232
183 #define IDM_WINDOW_BIZ_3 233
184 #define IDM_WINDOW_BIZ_4 234
185 #define IDM_WINDOW_BIZ_5 235
186 #define IDM_WINDOW_BIZ_6 236
187 #define IDM_WINDOW_BIZ_7 237
189 #define IDM_WINDOW_I_WID_0 240
190 #define IDM_WINDOW_I_WID_1 241
191 #define IDM_WINDOW_I_WID_2 242
192 #define IDM_WINDOW_I_WID_3 243
193 #define IDM_WINDOW_I_WID_4 244
194 #define IDM_WINDOW_I_WID_5 245
195 #define IDM_WINDOW_I_WID_6 246
196 #define IDM_WINDOW_I_WID_7 247
198 #define IDM_WINDOW_D_WID_0 250
199 #define IDM_WINDOW_D_WID_1 251
200 #define IDM_WINDOW_D_WID_2 252
201 #define IDM_WINDOW_D_WID_3 253
202 #define IDM_WINDOW_D_WID_4 254
203 #define IDM_WINDOW_D_WID_5 255
204 #define IDM_WINDOW_D_WID_6 256
205 #define IDM_WINDOW_D_WID_7 257
207 #define IDM_WINDOW_I_HGT_0 260
208 #define IDM_WINDOW_I_HGT_1 261
209 #define IDM_WINDOW_I_HGT_2 262
210 #define IDM_WINDOW_I_HGT_3 263
211 #define IDM_WINDOW_I_HGT_4 264
212 #define IDM_WINDOW_I_HGT_5 265
213 #define IDM_WINDOW_I_HGT_6 266
214 #define IDM_WINDOW_I_HGT_7 267
216 #define IDM_WINDOW_D_HGT_0 270
217 #define IDM_WINDOW_D_HGT_1 271
218 #define IDM_WINDOW_D_HGT_2 272
219 #define IDM_WINDOW_D_HGT_3 273
220 #define IDM_WINDOW_D_HGT_4 274
221 #define IDM_WINDOW_D_HGT_5 275
222 #define IDM_WINDOW_D_HGT_6 276
223 #define IDM_WINDOW_D_HGT_7 277
225 #define IDM_OPTIONS_NO_GRAPHICS 400
226 #define IDM_OPTIONS_OLD_GRAPHICS 401
227 #define IDM_OPTIONS_NEW_GRAPHICS 402
228 #define IDM_OPTIONS_NEW2_GRAPHICS 403
229 #define IDM_OPTIONS_BIGTILE 409
230 #define IDM_OPTIONS_SOUND 410
231 #define IDM_OPTIONS_MUSIC 411
232 #define IDM_OPTIONS_SAVER 420
233 #define IDM_OPTIONS_MAP 430
234 #define IDM_OPTIONS_BG 440
235 #define IDM_OPTIONS_OPEN_BG 441
237 #define IDM_DUMP_SCREEN_HTML 450
239 #define IDM_HELP_CONTENTS 901
242 * Exclude parts of WINDOWS.H that are not needed (Win32)
244 #define WIN32_LEAN_AND_MEAN
245 #define NONLS /* All NLS defines and routines */
246 #define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
247 #define NOMCX /* Modem Configuration Extensions */
250 * Include the "windows" support file
255 * Exclude parts of MMSYSTEM.H that are not needed
257 #define MMNODRV /* Installable driver support */
258 #define MMNOWAVE /* Waveform support */
259 #define MMNOMIDI /* MIDI support */
260 #define MMNOAUX /* Auxiliary audio support */
261 #define MMNOTIMER /* Timer support */
262 #define MMNOJOY /* Joystick support */
263 #define MMNOMCI /* MCI support */
264 #define MMNOMMIO /* Multimedia file I/O support */
266 #define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
267 #define MOUSE_SENS 40
270 * Include some more files. Note: the Cygnus Cygwin compiler
271 * doesn't use mmsystem.h instead it includes the winmm library
272 * which performs a similar function.
274 #include <mmsystem.h>
278 * Include the support for loading bitmaps
280 #include "term/readdib.h"
282 #define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
285 * Foreground color bits
287 #define VID_BLACK 0x00
288 #define VID_BLUE 0x01
289 #define VID_GREEN 0x02
290 #define VID_CYAN 0x03
292 #define VID_MAGENTA 0x05
293 #define VID_YELLOW 0x06
294 #define VID_WHITE 0x07
299 #define VID_BRIGHT 0x08
303 * @brief ターム情報構造体 / Extra "term" data
306 * pos_x / pos_y は各タームの左上点座標を指す。
309 * tile_wid / tile_hgt は[ウィンドウ]メニューのタイルの幅/高さを~を
310 * 1ドットずつ調整するステータスを指す。
311 * また、フォントを変更すると都度自動調整される。
314 * Note the use of "font_want" for the names of the font file requested by
315 * the user, and the use of "font_file" for the currently active font file.
317 * The "font_file" is uppercased, and takes the form "8X13.FON", while
318 * "font_want" can be in almost any form as long as it could be construed
319 * as attempting to represent the name of a font.
331 TERM_LEN rows; /* int -> uint */
334 uint pos_x; //!< タームの左上X座標
335 uint pos_y; //!< タームの左上Y座標
350 int font_wid; //!< フォント横幅
351 int font_hgt; //!< フォント縦幅
352 int tile_wid; //!< タイル横幅
353 int tile_hgt; //!< タイル縦幅
364 #define MAX_TERM_DATA 8 //!< Maximum number of windows
366 static term_data data[MAX_TERM_DATA]; //!< An array of term_data's
367 static term_data *my_td; //!< Hack -- global "window creation" pointer
368 POINT normsize; //!< Remember normal size of main window when maxmized
371 * was main window maximized on previous playing
373 bool win_maximized = FALSE;
378 bool game_in_progress = FALSE;
381 * note when "open"/"new" become valid
383 bool initialized = FALSE;
386 * screen paletted, i.e. 256 colors
388 bool paletted = FALSE;
391 * 16 colors screen, don't use RGB()
393 bool colors16 = FALSE;
396 * Saved instance handle
398 static HINSTANCE hInstance;
401 * Yellow brush for the cursor
403 static HBRUSH hbrYellow;
413 static HPALETTE hPal;
416 static HBITMAP hBG = NULL;
417 static int use_bg = 0; //!< 背景使用フラグ、1なら私用。
418 static char bg_bitmap_file[1024] = "bg.bmp"; //!< 現在の背景ビットマップファイル名。
421 * The screen saver window
423 static HWND hwndSaver;
426 * 現在使用中のタイルID(0ならば未使用)
427 * Flag set once "graphics" has been initialized
429 static byte current_graphics_mode = 0;
434 static DIBINIT infGraph;
437 * The global bitmap mask
439 static DIBINIT infMask;
442 * Flag set once "sound" has been initialized
444 static bool can_use_sound = FALSE;
446 #define SAMPLE_SOUND_MAX 16
448 * An array of sound file names
450 static concptr sound_file[SOUND_MAX][SAMPLE_SOUND_MAX];
452 #define SAMPLE_MUSIC_MAX 16
453 static concptr music_file[MUSIC_BASIC_MAX][SAMPLE_MUSIC_MAX];
454 static concptr dungeon_music_file[1000][SAMPLE_MUSIC_MAX];
455 static concptr town_music_file[1000][SAMPLE_MUSIC_MAX];
456 static concptr quest_music_file[1000][SAMPLE_MUSIC_MAX];
457 static bool can_use_music = FALSE;
459 static MCI_OPEN_PARMS mop;
460 static char mci_device_type[256];
462 int current_music_type = 0;
463 int current_music_id = 0;
466 * Full path to ANGBAND.INI
468 static concptr ini_file = NULL;
471 * Name of application
473 static concptr AppName = "ANGBAND";
476 * Name of sub-window type
478 static concptr AngList = "AngList";
483 static concptr ANGBAND_DIR_XTRA_GRAF;
484 static concptr ANGBAND_DIR_XTRA_SOUND;
485 static concptr ANGBAND_DIR_XTRA_MUSIC;
486 static concptr ANGBAND_DIR_XTRA_HELP;
487 static concptr ANGBAND_DIR_XTRA_MUSIC;
490 * The "complex" color values
492 static COLORREF win_clr[256];
496 * Flag for macro trigger with dump ASCII
498 static bool term_no_press = FALSE;
503 static bool mouse_down = FALSE;
504 static bool paint_rect = FALSE;
505 static TERM_LEN mousex = 0, mousey = 0;
506 static TERM_LEN oldx, oldy;
509 * @brief The "simple" color values
511 * See "main-ibm.c" for original table information
512 * The entries below are taken from the "color bits" defined above.
513 * Note that many of the choices below suck, but so do crappy monitors.
515 static BYTE win_pal[256] =
517 VID_BLACK, /* Dark */
518 VID_WHITE, /* White */
519 VID_CYAN, /* Slate XXX */
520 VID_RED | VID_BRIGHT, /* Orange XXX */
522 VID_GREEN, /* Green */
524 VID_YELLOW, /* Umber XXX */
525 VID_BLACK | VID_BRIGHT, /* Light Dark */
526 VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
527 VID_MAGENTA, /* Violet XXX */
528 VID_YELLOW | VID_BRIGHT, /* Yellow */
529 VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
530 VID_GREEN | VID_BRIGHT, /* Light Green */
531 VID_BLUE | VID_BRIGHT, /* Light Blue */
532 VID_YELLOW /* Light Umber XXX */
536 * Hack -- define which keys are "special"
538 static bool special_key[256];
539 static bool ignore_key[256];
542 * Hack -- initialization list for "special_key"
544 static byte special_key_list[] = {
545 VK_CLEAR, VK_PAUSE, VK_CAPITAL,
546 VK_KANA, VK_JUNJA, VK_FINAL, VK_KANJI,
547 VK_CONVERT, VK_NONCONVERT, VK_ACCEPT, VK_MODECHANGE,
548 VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
549 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN,
550 VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT,
551 VK_INSERT, VK_DELETE, VK_HELP, VK_APPS,
552 VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
553 VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
554 VK_NUMPAD8, VK_NUMPAD9, VK_MULTIPLY, VK_ADD,
555 VK_SEPARATOR, VK_SUBTRACT, VK_DECIMAL, VK_DIVIDE,
556 VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6,
557 VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
558 VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
559 VK_F19,VK_F20, VK_F21, VK_F22, VK_F23, VK_F24,
560 VK_NUMLOCK, VK_SCROLL, VK_ATTN, VK_CRSEL,
561 VK_EXSEL, VK_EREOF, VK_PLAY, VK_ZOOM,
566 static byte ignore_key_list[] = {
567 VK_ESCAPE, VK_TAB, VK_SPACE,
568 'F', 'W', 'O', /*'H',*/ /* these are menu characters.*/
569 VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN,
570 VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL,
575 /* Function prototype */
577 static bool is_already_running(void);
580 static void delete_bg(void)
590 static int init_bg(void)
592 char * bmfile = bg_bitmap_file;
594 if (use_bg == 0) return 0;
596 hBG = LoadImage(NULL, bmfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
598 plog_fmt(_("壁紙用ビットマップ '%s' を読み込めません。", "Can't load the bitmap file '%s'."), bmfile);
608 static void DrawBG(HDC hdc, RECT *r)
613 int x = r->left, y = r->top;
617 GetObject(hBG, sizeof(bm), &bm);
618 int swid = bm.bmWidth;
619 int shgt = bm.bmHeight;
621 HDC hdcSrc = CreateCompatibleDC(hdc);
622 HBITMAP hOld = SelectObject(hdcSrc, hBG);
626 int cwid = MIN(swid - sx, r->right - nx);
629 int chgt = MIN(shgt - sy, r->bottom - ny);
630 BitBlt(hdc, nx, ny, cwid, chgt, hdcSrc, sx, sy, SRCCOPY);
632 } while (ny < r->bottom);
636 } while (nx < r->right);
638 SelectObject(hdcSrc, hOld);
644 * Check for existance of a file
646 static bool check_file(concptr s)
650 DWORD attrib = GetFileAttributes(path);
651 if (attrib == INVALID_FILE_NAME) return FALSE;
652 if (attrib & FILE_ATTRIBUTE_DIRECTORY) return FALSE;
659 * Check for existance of a directory
661 static bool check_dir(concptr s)
665 int i = strlen(path);
666 if (i && (path[i - 1] == '\\')) path[--i] = '\0';
668 DWORD attrib = GetFileAttributes(path);
669 if (attrib == INVALID_FILE_NAME) return FALSE;
670 if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) return FALSE;
679 static void validate_file(concptr s)
681 if (check_file(s)) return;
683 quit_fmt(_("必要なファイル[%s]が見あたりません。", "Cannot find required file:\n%s"), s);
688 * Validate a directory
690 static void validate_dir(concptr s, bool vital)
692 if (check_dir(s)) return;
696 quit_fmt(_("必要なディレクトリ[%s]が見あたりません。", "Cannot find required directory:\n%s"), s);
700 quit_fmt("Unable to create directory:\n%s", s);
706 * @brief (Windows版固有実装)Get the "size" for a window
708 static void term_getsize(term_data *td)
710 if (td->cols < 1) td->cols = 1;
711 if (td->rows < 1) td->rows = 1;
713 TERM_LEN wid = td->cols * td->tile_wid + td->size_ow1 + td->size_ow2;
714 TERM_LEN hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2;
718 rc.right = rc.left + wid;
720 rc.bottom = rc.top + hgt;
722 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
723 td->size_wid = rc.right - rc.left;
724 td->size_hgt = rc.bottom - rc.top;
727 GetWindowRect(td->w, &rc);
734 * Write the "prefs" for a single term
736 static void save_prefs_aux(int i)
738 term_data *td = &data[i];
739 GAME_TEXT sec_name[128];
744 sprintf(sec_name, "Term-%d", i);
748 strcpy(buf, td->visible ? "1" : "0");
749 WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
753 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "MS ゴシック");
755 strcpy(buf, td->lf.lfFaceName[0] != '\0' ? td->lf.lfFaceName : "Courier");
758 WritePrivateProfileString(sec_name, "Font", buf, ini_file);
760 wsprintf(buf, "%d", td->lf.lfWidth);
761 WritePrivateProfileString(sec_name, "FontWid", buf, ini_file);
762 wsprintf(buf, "%d", td->lf.lfHeight);
763 WritePrivateProfileString(sec_name, "FontHgt", buf, ini_file);
764 wsprintf(buf, "%d", td->lf.lfWeight);
765 WritePrivateProfileString(sec_name, "FontWgt", buf, ini_file);
767 strcpy(buf, td->bizarre ? "1" : "0");
768 WritePrivateProfileString(sec_name, "Bizarre", buf, ini_file);
770 wsprintf(buf, "%d", td->tile_wid);
771 WritePrivateProfileString(sec_name, "TileWid", buf, ini_file);
773 wsprintf(buf, "%d", td->tile_hgt);
774 WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
776 WINDOWPLACEMENT lpwndpl;
777 lpwndpl.length = sizeof(WINDOWPLACEMENT);
778 GetWindowPlacement(td->w, &lpwndpl);
780 RECT rc = lpwndpl.rcNormalPosition;
781 if (i == 0) wsprintf(buf, "%d", normsize.x);
782 else wsprintf(buf, "%d", td->cols);
784 WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
786 if (i == 0) wsprintf(buf, "%d", normsize.y);
787 else wsprintf(buf, "%d", td->rows);
789 WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
792 strcpy(buf, IsZoomed(td->w) ? "1" : "0");
793 WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
796 GetWindowRect(td->w, &rc);
797 wsprintf(buf, "%d", rc.left);
798 WritePrivateProfileString(sec_name, "PositionX", buf, ini_file);
800 wsprintf(buf, "%d", rc.top);
801 WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
804 strcpy(buf, td->posfix ? "1" : "0");
805 WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
812 * We assume that the windows have all been initialized
814 static void save_prefs(void)
817 sprintf(buf, "%d", arg_graphics);
818 WritePrivateProfileString("Angband", "Graphics", buf, ini_file);
820 strcpy(buf, arg_bigtile ? "1" : "0");
821 WritePrivateProfileString("Angband", "Bigtile", buf, ini_file);
823 strcpy(buf, arg_sound ? "1" : "0");
824 WritePrivateProfileString("Angband", "Sound", buf, ini_file);
826 strcpy(buf, arg_music ? "1" : "0");
827 WritePrivateProfileString("Angband", "Music", buf, ini_file);
829 strcpy(buf, use_bg ? "1" : "0");
830 WritePrivateProfileString("Angband", "BackGround", buf, ini_file);
831 WritePrivateProfileString("Angband", "BackGroundBitmap",
832 bg_bitmap_file[0] != '\0' ? bg_bitmap_file : "bg.bmp", ini_file);
834 for (int i = 0; i < MAX_TERM_DATA; ++i)
842 * Load the "prefs" for a single term
844 static void load_prefs_aux(int i)
846 term_data *td = &data[i];
847 GAME_TEXT sec_name[128];
850 int dispx = GetSystemMetrics(SM_CXVIRTUALSCREEN);
851 int dispy = GetSystemMetrics(SM_CYVIRTUALSCREEN);
855 sprintf(sec_name, "Term-%d", i);
856 sprintf(sec_name, "Term-%d", i);
859 td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
863 GetPrivateProfileString(sec_name, "Font", "MS ゴシック", tmp, 127, ini_file);
865 GetPrivateProfileString(sec_name, "Font", "Courier", tmp, 127, ini_file);
868 td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0);
870 td->font_want = string_make(tmp);
873 td->lf.lfWidth = GetPrivateProfileInt(sec_name, "FontWid", wid, ini_file);
874 td->lf.lfHeight = GetPrivateProfileInt(sec_name, "FontHgt", hgt, ini_file);
875 td->lf.lfWeight = GetPrivateProfileInt(sec_name, "FontWgt", 0, ini_file);
877 td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", td->lf.lfWidth, ini_file);
878 td->tile_hgt = GetPrivateProfileInt(sec_name, "TileHgt", td->lf.lfHeight, ini_file);
880 td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
881 td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
882 normsize.x = td->cols; normsize.y = td->rows;
886 win_maximized = (GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file) != 0);
889 posx = GetPrivateProfileInt(sec_name, "PositionX", posx, ini_file);
890 posy = GetPrivateProfileInt(sec_name, "PositionY", posy, ini_file);
891 td->pos_x = MIN(MAX(0, posx), dispx - 128);
892 td->pos_y = MIN(MAX(0, posy), dispy - 128);
896 td->posfix = (GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file) != 0);
904 static void load_prefs(void)
906 arg_graphics = (byte)GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
907 arg_bigtile = (GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file) != 0);
908 use_bigtile = arg_bigtile;
909 arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0);
910 arg_music = (GetPrivateProfileInt("Angband", "Music", 0, ini_file) != 0);
911 use_bg = GetPrivateProfileInt("Angband", "BackGround", 0, ini_file);
912 GetPrivateProfileString("Angband", "BackGroundBitmap", "bg.bmp", bg_bitmap_file, 1023, ini_file);
913 for (int i = 0; i < MAX_TERM_DATA; ++i)
921 * - Taken from files.c.
923 * Extract "tokens" from a buffer
925 * This function uses "whitespace" as delimiters, and treats any amount of
926 * whitespace as a single delimiter. We will never return any empty tokens.
927 * When given an empty buffer, or a buffer containing only "whitespace", we
928 * will return no tokens. We will never extract more than "num" tokens.
930 * By running a token through the "text_to_ascii()" function, you can allow
931 * that token to include (encoded) whitespace, using "\s" to encode spaces.
933 * We save pointers to the tokens in "tokens", and return the number found.
935 static s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
943 for (; *s && iswspace(*s); ++s) /* loop */;
947 for (t = s; *t && !iswspace(*t); ++t) /* loop */;
959 static void load_sound_prefs(void)
964 char *zz[SAMPLE_SOUND_MAX];
966 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_SOUND, "sound.cfg");
967 for (int i = 0; i < SOUND_MAX; i++)
969 GetPrivateProfileString("Sound", angband_sound_name[i], "", tmp, 1024, ini_path);
970 int num = tokenize_whitespace(tmp, SAMPLE_SOUND_MAX, zz);
971 for (int j = 0; j < num; j++)
973 /* Access the sound */
974 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_SOUND, zz[j]);
976 /* Save the sound filename, if it exists */
977 if (check_file(wav_path))
978 sound_file[i][j] = string_make(zz[j]);
984 static void load_music_prefs(void)
989 char *zz[SAMPLE_MUSIC_MAX];
992 path_build(ini_path, 1024, ANGBAND_DIR_XTRA_MUSIC, "music.cfg");
993 GetPrivateProfileString("Device", "type", "", mci_device_type, 256, ini_path);
994 for (int i = 0; i < MUSIC_BASIC_MAX; i++)
996 GetPrivateProfileString("Basic", angband_music_basic_name[i], "", tmp, 1024, ini_path);
997 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
998 for (int j = 0; j < num; j++)
1000 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1001 if (check_file(wav_path))
1002 music_file[i][j] = string_make(zz[j]);
1006 for (int i = 0; i < current_world_ptr->max_d_idx; i++)
1008 sprintf(key, "dungeon%03d", i);
1009 GetPrivateProfileString("Dungeon", key, "", tmp, 1024, ini_path);
1010 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1011 for (int j = 0; j < num; j++)
1013 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1014 if (check_file(wav_path))
1015 dungeon_music_file[i][j] = string_make(zz[j]);
1019 for (int i = 0; i < max_q_idx; i++)
1021 sprintf(key, "quest%03d", i);
1022 GetPrivateProfileString("Quest", key, "", tmp, 1024, ini_path);
1023 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1024 for (int j = 0; j < num; j++)
1026 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1027 if (check_file(wav_path))
1028 quest_music_file[i][j] = string_make(zz[j]);
1032 for (int i = 0; i < 1000; i++) /*!< @todo 町最大数指定 */
1034 sprintf(key, "town%03d", i);
1035 GetPrivateProfileString("Town", key, "", tmp, 1024, ini_path);
1036 int num = tokenize_whitespace(tmp, SAMPLE_MUSIC_MAX, zz);
1037 for (int j = 0; j < num; j++)
1039 path_build(wav_path, 1024, ANGBAND_DIR_XTRA_MUSIC, zz[j]);
1040 if (check_file(wav_path))
1041 town_music_file[i][j] = string_make(zz[j]);
1048 * Create the new global palette based on the bitmap palette
1049 * (if any), and the standard 16 entry palette derived from
1050 * "win_clr[]" which is used for the basic 16 Angband colors.
1052 * This function is never called before all windows are ready.
1054 * This function returns FALSE if the new palette could not be
1055 * prepared, which should normally be a fatal error. XXX XXX
1057 * Note that only some machines actually use a "palette".
1059 static int new_palette(void)
1064 LPLOGPALETTE pLogPal;
1065 LPPALETTEENTRY lppe;
1067 if (!paletted) return TRUE;
1073 HPALETTE hBmPal = infGraph.hPalette;
1076 lppeSize = 256 * sizeof(PALETTEENTRY);
1077 lppe = (LPPALETTEENTRY)ralloc(lppeSize);
1078 nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe);
1079 if ((nEntries == 0) || (nEntries > 220))
1081 plog(_("画面を16ビットか24ビットカラーモードにして下さい。", "Please switch to high- or true-color mode."));
1082 rnfree(lppe, lppeSize);
1087 pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY);
1088 pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize);
1089 pLogPal->palVersion = 0x300;
1090 pLogPal->palNumEntries = nEntries + 16;
1091 for (i = 0; i < nEntries; i++)
1093 pLogPal->palPalEntry[i] = lppe[i];
1096 for (i = 0; i < 16; i++)
1099 p = &(pLogPal->palPalEntry[i + nEntries]);
1100 p->peRed = GetRValue(win_clr[i]);
1101 p->peGreen = GetGValue(win_clr[i]);
1102 p->peBlue = GetBValue(win_clr[i]);
1103 p->peFlags = PC_NOCOLLAPSE;
1106 if (lppe) rnfree(lppe, lppeSize);
1108 HPALETTE hNewPal = CreatePalette(pLogPal);
1109 if (!hNewPal) quit(_("パレットを作成できません!", "Cannot create palette!"));
1111 rnfree(pLogPal, pLogPalSize);
1113 HDC hdc = GetDC(td->w);
1114 SelectPalette(hdc, hNewPal, 0);
1115 i = RealizePalette(hdc);
1116 ReleaseDC(td->w, hdc);
1117 if (i == 0) quit(_("パレットをシステムエントリにマップできません!", "Cannot realize palette!"));
1119 for (i = 1; i < MAX_TERM_DATA; i++)
1123 SelectPalette(hdc, hNewPal, 0);
1124 ReleaseDC(td->w, hdc);
1127 if (hPal) DeleteObject(hPal);
1135 * @brief グラフィクスを初期化する / Initialize graphics
1138 * <li>メニュー[オプション]>[グラフィクス]が「なし」以外の時に描画処理を初期化する。</li>
1139 * <li>呼び出されるタイミングはロード時、及び同メニューで「なし」以外に変更される毎になる。</li>
1142 static bool init_graphics(void)
1145 BYTE wid, hgt, twid, thgt, ox, oy;
1148 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1158 ANGBAND_GRAF = "new";
1160 else if (arg_graphics == GRAPHICS_HENGBAND)
1170 ANGBAND_GRAF = "ne2";
1181 ANGBAND_GRAF = "old";
1184 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, name);
1185 if (!ReadDIB(data[0].w, buf, &infGraph))
1187 plog_fmt(_("ビットマップ '%s' を読み込めません。", "Cannot read bitmap file '%s'"), name);
1191 infGraph.CellWidth = wid;
1192 infGraph.CellHeight = hgt;
1193 infGraph.TileWidth = twid;
1194 infGraph.TileHeight = thgt;
1195 infGraph.OffsetX = ox;
1196 infGraph.OffsetY = oy;
1198 if (arg_graphics == GRAPHICS_ADAM_BOLT)
1200 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask.bmp");
1201 if (!ReadDIB(data[0].w, buf, &infMask))
1203 plog_fmt("Cannot read bitmap file '%s'", buf);
1208 if (arg_graphics == GRAPHICS_HENGBAND)
1210 path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA_GRAF, "mask32.bmp");
1211 if (!ReadDIB(data[0].w, buf, &infMask))
1213 plog_fmt("Cannot read bitmap file '%s'", buf);
1220 plog(_("パレットを実現できません!", "Cannot activate palette!"));
1224 current_graphics_mode = arg_graphics;
1225 return (current_graphics_mode);
1232 static void init_music(void)
1237 can_use_music = TRUE;
1242 * Hack -- Stop a music
1244 static void stop_music(void)
1246 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1247 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1254 static void init_sound(void)
1259 can_use_sound = TRUE;
1267 static void term_window_resize(term_data *td)
1271 SetWindowPos(td->w, 0, 0, 0,
1272 td->size_wid, td->size_hgt,
1273 SWP_NOMOVE | SWP_NOZORDER);
1274 InvalidateRect(td->w, NULL, TRUE);
1280 * Force the use of a new "font file" for a term_data.
1281 * This function may be called before the "window" is ready.
1282 * This function returns zero only if everything succeeds.
1283 * Note that the "font name" must be capitalized!!!
1285 static errr term_force_font(term_data *td, concptr path)
1287 if (td->font_id) DeleteObject(td->font_id);
1290 td->font_id = CreateFontIndirect(&(td->lf));
1291 int wid = td->lf.lfWidth;
1292 int hgt = td->lf.lfHeight;
1293 if (!td->font_id) return 1;
1301 hdcDesktop = GetDC(HWND_DESKTOP);
1302 hfOld = SelectObject(hdcDesktop, td->font_id);
1303 GetTextMetrics(hdcDesktop, &tm);
1304 SelectObject(hdcDesktop, hfOld);
1305 ReleaseDC(HWND_DESKTOP, hdcDesktop);
1307 wid = tm.tmAveCharWidth;
1320 * Allow the user to change the font for this window.
1322 static void term_change_font(term_data *td)
1325 memset(&cf, 0, sizeof(cf));
1326 cf.lStructSize = sizeof(cf);
1327 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS | CF_INITTOLOGFONTSTRUCT;
1328 cf.lpLogFont = &(td->lf);
1330 if (!ChooseFont(&cf)) return;
1332 term_force_font(td, NULL);
1334 td->tile_wid = td->font_wid;
1335 td->tile_hgt = td->font_hgt;
1337 term_window_resize(td);
1342 * Allow the user to lock this window.
1344 static void term_window_pos(term_data *td, HWND hWnd)
1346 SetWindowPos(td->w, hWnd, 0, 0, 0, 0,
1347 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1350 static void windows_map(player_type *player_ptr);
1353 * Hack -- redraw a term_data
1355 static void term_data_redraw(player_type *player_ptr, term_data *td)
1359 windows_map(player_ptr);
1363 Term_activate(&td->t);
1365 Term_activate(term_screen);
1369 void term_inversed_area(HWND hWnd, int x, int y, int w, int h)
1371 term_data *td = (term_data *)GetWindowLong(hWnd, 0);
1372 int tx = td->size_ow1 + x * td->tile_wid;
1373 int ty = td->size_oh1 + y * td->tile_hgt;
1374 int tw = w * td->tile_wid - 1;
1375 int th = h * td->tile_hgt - 1;
1377 HDC hdc = GetDC(hWnd);
1378 HBRUSH myBrush = CreateSolidBrush(RGB(255, 255, 255));
1379 HBRUSH oldBrush = SelectObject(hdc, myBrush);
1380 HPEN oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1382 PatBlt(hdc, tx, ty, tw, th, PATINVERT);
1384 SelectObject(hdc, oldBrush);
1385 SelectObject(hdc, oldPen);
1390 * @brief //!< Windows版ユーザ設定項目実装部(実装必須) /Interact with the User
1392 static errr term_user_win(int n)
1400 * React to global changes
1402 static errr term_xtra_win_react(player_type *player_ptr)
1406 for (int i = 0; i < 256; i++)
1408 win_pal[i] = angband_color_table[i][0];
1415 bool change = FALSE;
1416 for (int i = 0; i < 256; i++)
1418 rv = angband_color_table[i][1];
1419 gv = angband_color_table[i][2];
1420 bv = angband_color_table[i][3];
1421 code = PALETTERGB(rv, gv, bv);
1422 if (win_clr[i] != code)
1429 if (change) (void)new_palette();
1432 if (use_sound != arg_sound)
1435 use_sound = arg_sound;
1438 if (use_music != arg_music)
1441 use_music = arg_music;
1442 if (!arg_music) stop_music();
1443 else select_floor_music(player_ptr);
1446 if (use_graphics != arg_graphics)
1448 if (arg_graphics && !init_graphics())
1450 plog(_("グラフィックスを初期化できません!", "Cannot initialize graphics!"));
1451 arg_graphics = GRAPHICS_NONE;
1454 use_graphics = arg_graphics;
1455 reset_visuals(player_ptr, process_autopick_file_command);
1458 for (int i = 0; i < MAX_TERM_DATA; i++)
1461 term_data *td = &data[i];
1462 if ((td->cols != td->t.wid) || (td->rows != td->t.hgt))
1464 Term_activate(&td->t);
1465 Term_resize(td->cols, td->rows);
1476 * Process at least one event
1478 static errr term_xtra_win_event(int v)
1483 if (GetMessage(&msg, NULL, 0, 0))
1485 TranslateMessage(&msg);
1486 DispatchMessage(&msg);
1491 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1493 TranslateMessage(&msg);
1494 DispatchMessage(&msg);
1503 * Process all pending events
1505 static errr term_xtra_win_flush(void)
1508 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1510 TranslateMessage(&msg);
1511 DispatchMessage(&msg);
1519 * Hack -- clear the screen
1521 * Make this more efficient
1523 static errr term_xtra_win_clear(void)
1525 term_data *td = (term_data*)(Term->data);
1528 rc.left = td->size_ow1;
1529 rc.right = rc.left + td->cols * td->tile_wid;
1530 rc.top = td->size_oh1;
1531 rc.bottom = rc.top + td->rows * td->tile_hgt;
1533 HDC hdc = GetDC(td->w);
1534 SetBkColor(hdc, RGB(0, 0, 0));
1535 SelectObject(hdc, td->font_id);
1536 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1540 rc.left = 0; rc.top = 0;
1544 ReleaseDC(td->w, hdc);
1550 * Hack -- make a noise
1552 static errr term_xtra_win_noise(void)
1554 MessageBeep(MB_ICONASTERISK);
1560 * Hack -- make a sound
1562 static errr term_xtra_win_sound(int v)
1565 if (!use_sound) return 1;
1566 if ((v < 0) || (v >= SOUND_MAX)) return 1;
1569 for (i = 0; i < SAMPLE_SOUND_MAX; i++)
1571 if (!sound_file[v][i])
1575 if (i == 0) return 1;
1577 path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, sound_file[v][Rand_external(i)]);
1578 return (PlaySound(buf, 0, SND_FILENAME | SND_ASYNC));
1582 * Hack -- play a music
1584 static errr term_xtra_win_music(int n, int v)
1588 if (n == TERM_XTRA_MUSIC_MUTE)
1590 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1591 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1594 if (!use_music) return 1;
1596 if (n == TERM_XTRA_MUSIC_BASIC && ((v < 0) || (v >= MUSIC_BASIC_MAX))) return 1;
1597 else if (v < 0 || v >= 1000) return(1); /*!< TODO */
1601 case TERM_XTRA_MUSIC_BASIC:
1602 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!music_file[v][i]) break;
1604 case TERM_XTRA_MUSIC_DUNGEON:
1605 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!dungeon_music_file[v][i]) break;
1607 case TERM_XTRA_MUSIC_QUEST:
1608 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!quest_music_file[v][i]) break;
1610 case TERM_XTRA_MUSIC_TOWN:
1611 for (i = 0; i < SAMPLE_MUSIC_MAX; i++) if (!town_music_file[v][i]) break;
1622 case TERM_XTRA_MUSIC_BASIC:
1623 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, music_file[v][Rand_external(i)]);
1625 case TERM_XTRA_MUSIC_DUNGEON:
1626 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, dungeon_music_file[v][Rand_external(i)]);
1628 case TERM_XTRA_MUSIC_QUEST:
1629 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, quest_music_file[v][Rand_external(i)]);
1631 case TERM_XTRA_MUSIC_TOWN:
1632 path_build(buf, 1024, ANGBAND_DIR_XTRA_MUSIC, town_music_file[v][Rand_external(i)]);
1636 if (current_music_type == n && current_music_id == v)
1640 current_music_type = n;
1641 current_music_id = v;
1643 mop.lpstrDeviceType = mci_device_type;
1644 mop.lpstrElementName = buf;
1645 mciSendCommand(mop.wDeviceID, MCI_STOP, 0, 0);
1646 mciSendCommand(mop.wDeviceID, MCI_CLOSE, 0, 0);
1647 mciSendCommand(mop.wDeviceID, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mop);
1648 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
1649 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
1655 * Delay for "x" milliseconds
1657 static int term_xtra_win_delay(int v)
1665 * todo z-termに影響があるのでplayer_typeの追加は保留
1666 * Do a "special thing"
1668 static errr term_xtra_win(int n, int v)
1672 case TERM_XTRA_NOISE:
1674 return (term_xtra_win_noise());
1676 case TERM_XTRA_MUSIC_BASIC:
1677 case TERM_XTRA_MUSIC_DUNGEON:
1678 case TERM_XTRA_MUSIC_QUEST:
1679 case TERM_XTRA_MUSIC_TOWN:
1681 return (term_xtra_win_music(n, v));
1683 case TERM_XTRA_SOUND:
1685 return (term_xtra_win_sound(v));
1687 case TERM_XTRA_BORED:
1689 return (term_xtra_win_event(0));
1691 case TERM_XTRA_EVENT:
1693 return (term_xtra_win_event(v));
1695 case TERM_XTRA_FLUSH:
1697 return (term_xtra_win_flush());
1699 case TERM_XTRA_CLEAR:
1701 return (term_xtra_win_clear());
1703 case TERM_XTRA_REACT:
1705 return (term_xtra_win_react(p_ptr));
1707 case TERM_XTRA_DELAY:
1709 return (term_xtra_win_delay(v));
1718 * Low level graphics (Assumes valid input).
1720 * Draw a "cursor" at (x,y), using a "yellow box".
1722 static errr term_curs_win(int x, int y)
1724 term_data *td = (term_data*)(Term->data);
1725 int tile_wid, tile_hgt;
1728 tile_wid = td->map_tile_wid;
1729 tile_hgt = td->map_tile_hgt;
1733 tile_wid = td->tile_wid;
1734 tile_hgt = td->tile_hgt;
1738 rc.left = x * tile_wid + td->size_ow1;
1739 rc.right = rc.left + tile_wid;
1740 rc.top = y * tile_hgt + td->size_oh1;
1741 rc.bottom = rc.top + tile_hgt;
1743 HDC hdc = GetDC(td->w);
1744 FrameRect(hdc, &rc, hbrYellow);
1745 ReleaseDC(td->w, hdc);
1751 * Low level graphics (Assumes valid input).
1753 * Draw a "big cursor" at (x,y), using a "yellow box".
1755 static errr term_bigcurs_win(int x, int y)
1757 term_data *td = (term_data*)(Term->data);
1758 int tile_wid, tile_hgt;
1761 term_curs_win(x, y);
1766 tile_wid = td->tile_wid;
1767 tile_hgt = td->tile_hgt;
1771 rc.left = x * tile_wid + td->size_ow1;
1772 rc.right = rc.left + 2 * tile_wid;
1773 rc.top = y * tile_hgt + td->size_oh1;
1774 rc.bottom = rc.top + tile_hgt;
1776 HDC hdc = GetDC(td->w);
1777 FrameRect(hdc, &rc, hbrYellow);
1778 ReleaseDC(td->w, hdc);
1784 * Low level graphics (Assumes valid input).
1786 * Erase a "block" of "n" characters starting at (x,y).
1788 static errr term_wipe_win(int x, int y, int n)
1790 term_data *td = (term_data*)(Term->data);
1792 rc.left = x * td->tile_wid + td->size_ow1;
1793 rc.right = rc.left + n * td->tile_wid;
1794 rc.top = y * td->tile_hgt + td->size_oh1;
1795 rc.bottom = rc.top + td->tile_hgt;
1797 HDC hdc = GetDC(td->w);
1798 SetBkColor(hdc, RGB(0, 0, 0));
1799 SelectObject(hdc, td->font_id);
1803 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1805 ReleaseDC(td->w, hdc);
1811 * Low level graphics. Assumes valid input.
1813 * Draw several ("n") chars, with an attr, at a given location.
1815 * All "graphic" data is handled by "term_pict_win()", below.
1817 * One would think there is a more efficient method for telling a window
1818 * what color it should be using to draw with, but perhaps simply changing
1819 * it every time is not too inefficient.
1821 static errr term_text_win(int x, int y, int n, TERM_COLOR a, concptr s)
1823 term_data *td = (term_data*)(Term->data);
1824 static HBITMAP WALL;
1825 static HBRUSH myBrush, oldBrush;
1827 static bool init_done = FALSE;
1830 WALL = LoadBitmap(hInstance, AppName);
1831 myBrush = CreatePatternBrush(WALL);
1836 rc.left = x * td->tile_wid + td->size_ow1;
1837 rc.right = rc.left + n * td->tile_wid;
1838 rc.top = y * td->tile_hgt + td->size_oh1;
1839 rc.bottom = rc.top + td->tile_hgt;
1841 HDC hdc = GetDC(td->w);
1842 SetBkColor(hdc, RGB(0, 0, 0));
1845 SetTextColor(hdc, PALETTEINDEX(win_pal[a]));
1849 SetTextColor(hdc, win_clr[a & 0x0F]);
1853 SetTextColor(hdc, win_clr[a]);
1856 SelectObject(hdc, td->font_id);
1857 if (use_bg) SetBkMode(hdc, TRANSPARENT);
1860 (td->tile_hgt != td->font_hgt) ||
1861 (td->tile_wid != td->font_wid))
1863 ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
1864 if (use_bg) DrawBG(hdc, &rc);
1866 rc.left += ((td->tile_wid - td->font_wid) / 2);
1867 rc.right = rc.left + td->font_wid;
1868 rc.top += ((td->tile_hgt - td->font_hgt) / 2);
1869 rc.bottom = rc.top + td->font_hgt;
1871 for (int i = 0; i < n; i++)
1874 if (use_bigtile && *(s + i) == "■"[0] && *(s + i + 1) == "■"[1])
1876 rc.right += td->font_wid;
1877 oldBrush = SelectObject(hdc, myBrush);
1878 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1879 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1880 SelectObject(hdc, oldBrush);
1881 SelectObject(hdc, oldPen);
1882 rc.right -= td->font_wid;
1884 rc.left += 2 * td->tile_wid;
1885 rc.right += 2 * td->tile_wid;
1887 else if (iskanji(*(s + i))) /* 2バイト文字 */
1889 rc.right += td->font_wid;
1890 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc,
1892 rc.right -= td->font_wid;
1894 rc.left += 2 * td->tile_wid;
1895 rc.right += 2 * td->tile_wid;
1897 else if (*(s + i) == 127) {
1898 oldBrush = SelectObject(hdc, myBrush);
1899 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1900 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1901 SelectObject(hdc, oldBrush);
1902 SelectObject(hdc, oldPen);
1903 rc.left += td->tile_wid;
1904 rc.right += td->tile_wid;
1908 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1909 rc.left += td->tile_wid;
1910 rc.right += td->tile_wid;
1913 if (*(s + i) == 127)
1915 oldBrush = SelectObject(hdc, myBrush);
1916 oldPen = SelectObject(hdc, GetStockObject(NULL_PEN));
1917 Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1918 SelectObject(hdc, oldBrush);
1919 SelectObject(hdc, oldPen);
1920 rc.left += td->tile_wid;
1921 rc.right += td->tile_wid;
1925 ExtTextOut(hdc, rc.left, rc.top, ETO_CLIPPED, &rc, s + i, 1, NULL);
1926 rc.left += td->tile_wid;
1927 rc.right += td->tile_wid;
1934 ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc, s, n, NULL);
1937 ReleaseDC(td->w, hdc);
1943 * Low level graphics. Assumes valid input.
1945 * Draw an array of "special" attr/char pairs at the given location.
1947 * We use the "term_pict_win()" function for "graphic" data, which are
1948 * encoded by setting the "high-bits" of both the "attr" and the "char"
1949 * data. We use the "attr" to represent the "row" of the main bitmap,
1950 * and the "char" to represent the "col" of the main bitmap. The use
1951 * of this function is induced by the "higher_pict" flag.
1953 * If "graphics" is not available, we simply "wipe" the given grids.
1955 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)
1957 term_data *td = (term_data*)(Term->data);
1962 return (term_wipe_win(x, y, n));
1965 TERM_LEN w1 = infGraph.CellWidth;
1966 TERM_LEN h1 = infGraph.CellHeight;
1967 TERM_LEN tw1 = infGraph.TileWidth;
1968 TERM_LEN th1 = infGraph.TileHeight;
1969 TERM_LEN w2, h2, tw2 = 0;
1972 w2 = td->map_tile_wid;
1973 h2 = td->map_tile_hgt;
1980 if (use_bigtile) tw2 *= 2;
1983 TERM_LEN x2 = x * w2 + td->size_ow1 + infGraph.OffsetX;
1984 TERM_LEN y2 = y * h2 + td->size_oh1 + infGraph.OffsetY;
1985 HDC hdc = GetDC(td->w);
1986 HDC hdcSrc = CreateCompatibleDC(hdc);
1987 HBITMAP hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap);
1989 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
1991 hdcMask = CreateCompatibleDC(hdc);
1992 SelectObject(hdcMask, infMask.hBitmap);
1995 for (i = 0; i < n; i++, x2 += w2)
1997 TERM_COLOR a = ap[i];
1999 int row = (a & 0x7F);
2000 int col = (c & 0x7F);
2001 TERM_LEN x1 = col * w1;
2002 TERM_LEN y1 = row * h1;
2004 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2006 TERM_LEN x3 = (tcp[i] & 0x7F) * w1;
2007 TERM_LEN y3 = (tap[i] & 0x7F) * h1;
2008 tw2 = tw2 * w1 / tw1;
2010 if ((tw1 == tw2) && (th1 == h2))
2012 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY);
2013 BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND);
2014 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT);
2018 SetStretchBltMode(hdc, COLORONCOLOR);
2019 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x3, y3, w1, h1, SRCAND);
2020 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCPAINT);
2021 if ((x1 != x3) || (y1 != y3))
2023 StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND);
2024 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT);
2030 if ((w1 == tw2) && (h1 == h2))
2032 BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY);
2036 SetStretchBltMode(hdc, COLORONCOLOR);
2037 StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY);
2040 SelectObject(hdcSrc, hbmSrcOld);
2042 if (arg_graphics == GRAPHICS_ADAM_BOLT || arg_graphics == GRAPHICS_HENGBAND)
2044 SelectObject(hdcMask, hbmSrcOld);
2048 ReleaseDC(td->w, hdc);
2053 static void windows_map(player_type *player_ptr)
2055 term_data *td = &data[0];
2057 if (!use_graphics) return;
2059 term_xtra_win_clear();
2060 td->map_tile_wid = (td->tile_wid * td->cols) / MAX_WID;
2061 td->map_tile_hgt = (td->tile_hgt * td->rows) / MAX_HGT;
2062 td->map_active = TRUE;
2066 TERM_LEN max_x = player_ptr->current_floor_ptr->width;
2067 TERM_LEN max_y = player_ptr->current_floor_ptr->height;
2070 for (TERM_LEN x = min_x; x < max_x; x++)
2072 for (TERM_LEN y = min_y; y < max_y; y++)
2076 map_info(player_ptr, y, x, &a, (char*)&c, &ta, (char*)&tc);
2077 if ((a & 0x80) && (c & 0x80))
2079 term_pict_win(x - min_x, y - min_y, 1, &a, &c, &ta, &tc);
2084 term_curs_win(player_ptr->x - min_x, player_ptr->y - min_y);
2085 Term_inkey(&c, TRUE, TRUE);
2087 td->map_active = FALSE;
2088 term_xtra_win_clear();
2094 * Create and initialize a "term_data" given a title
2096 static void term_data_link(term_data *td)
2099 term_init(t, td->cols, td->rows, td->keys);
2100 t->soft_cursor = TRUE;
2101 t->higher_pict = TRUE;
2102 t->attr_blank = TERM_WHITE;
2103 t->char_blank = ' ';
2104 t->user_hook = term_user_win;
2105 t->xtra_hook = term_xtra_win;
2106 t->curs_hook = term_curs_win;
2107 t->bigcurs_hook = term_bigcurs_win;
2108 t->wipe_hook = term_wipe_win;
2109 t->text_hook = term_text_win;
2110 t->pict_hook = term_pict_win;
2111 t->data = (vptr)(td);
2116 * Create the windows
2118 * First, instantiate the "default" values, then read the "ini_file"
2119 * to over-ride selected values, then create the windows, and fonts.
2121 * Must use SW_SHOW not SW_SHOWNA, since on 256 color display
2122 * must make active to realize the palette.
2124 static void init_windows(void)
2128 WIPE(td, term_data);
2132 td->s = angband_term_name[0];
2148 for (int i = 1; i < MAX_TERM_DATA; i++)
2151 WIPE(td, term_data);
2152 td->s = angband_term_name[i];
2156 td->visible = FALSE;
2161 td->pos_x = (7 - i) * 30;
2162 td->pos_y = (7 - i) * 20;
2169 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU |
2170 WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION |
2175 for (int i = 1; i < MAX_TERM_DATA; i++)
2178 td->dwStyle = (WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU);
2179 td->dwExStyle = (WS_EX_TOOLWINDOW);
2182 for (int i = 0; i < MAX_TERM_DATA; i++)
2185 strncpy(td->lf.lfFaceName, td->font_want, LF_FACESIZE);
2186 td->lf.lfCharSet = DEFAULT_CHARSET;
2187 td->lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2188 term_force_font(td, NULL);
2189 if (!td->tile_wid) td->tile_wid = td->font_wid;
2190 if (!td->tile_hgt) td->tile_hgt = td->font_hgt;
2193 term_window_resize(td);
2196 for (int i = MAX_TERM_DATA - 1; i >= 1; --i)
2201 td->w = CreateWindowEx(td->dwExStyle, AngList,
2203 td->pos_x, td->pos_y,
2204 td->size_wid, td->size_hgt,
2205 HWND_DESKTOP, NULL, hInstance, NULL);
2207 if (!td->w) quit(_("サブウィンドウに作成に失敗しました", "Failed to create sub-window"));
2211 td->size_hack = TRUE;
2212 ShowWindow(td->w, SW_SHOW);
2213 td->size_hack = FALSE;
2217 angband_term[i] = &td->t;
2221 /* Activate the window */
2222 SetActiveWindow(td->w);
2227 term_window_pos(&data[i], HWND_TOPMOST);
2231 term_window_pos(&data[i], td->w);
2237 td->w = CreateWindowEx(td->dwExStyle, AppName,
2239 td->pos_x, td->pos_y,
2240 td->size_wid, td->size_hgt,
2241 HWND_DESKTOP, NULL, hInstance, NULL);
2243 if (!td->w) quit(_("メインウィンドウの作成に失敗しました", "Failed to create Angband window"));
2246 angband_term[0] = &td->t;
2247 normsize.x = td->cols;
2248 normsize.y = td->rows;
2250 if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
2251 else ShowWindow(td->w, SW_SHOW);
2253 SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2254 (void)new_palette();
2255 hbrYellow = CreateSolidBrush(win_clr[TERM_YELLOW]);
2256 (void)term_xtra_win_flush();
2263 static void setup_menus(void)
2265 HMENU hm = GetMenu(data[0].w);
2266 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2267 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2268 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2269 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2270 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2272 if (!current_world_ptr->character_generated)
2274 EnableMenuItem(hm, IDM_FILE_NEW, MF_BYCOMMAND | MF_ENABLED);
2275 EnableMenuItem(hm, IDM_FILE_OPEN, MF_BYCOMMAND | MF_ENABLED);
2278 if (current_world_ptr->character_generated)
2280 EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_ENABLED);
2283 EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_ENABLED);
2284 EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_ENABLED);
2286 for (int i = 0; i < MAX_TERM_DATA; i++)
2288 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2289 CheckMenuItem(hm, IDM_WINDOW_VIS_0 + i, (data[i].visible ? MF_CHECKED : MF_UNCHECKED));
2290 EnableMenuItem(hm, IDM_WINDOW_VIS_0 + i, MF_BYCOMMAND | MF_ENABLED);
2293 for (int i = 0; i < MAX_TERM_DATA; i++)
2295 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2297 if (data[i].visible)
2299 EnableMenuItem(hm, IDM_WINDOW_FONT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2303 for (int i = 0; i < MAX_TERM_DATA; i++)
2305 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2306 CheckMenuItem(hm, IDM_WINDOW_POS_0 + i, (data[i].posfix ? MF_CHECKED : MF_UNCHECKED));
2307 if (data[i].visible)
2309 EnableMenuItem(hm, IDM_WINDOW_POS_0 + i, MF_BYCOMMAND | MF_ENABLED);
2313 for (int i = 0; i < MAX_TERM_DATA; i++)
2315 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2316 CheckMenuItem(hm, IDM_WINDOW_BIZ_0 + i, (data[i].bizarre ? MF_CHECKED : MF_UNCHECKED));
2317 if (data[i].visible)
2319 EnableMenuItem(hm, IDM_WINDOW_BIZ_0 + i, MF_BYCOMMAND | MF_ENABLED);
2324 for (int i = 0; i < MAX_TERM_DATA; i++)
2326 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2327 if (data[i].visible)
2329 EnableMenuItem(hm, IDM_WINDOW_I_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
2333 for (int i = 0; i < MAX_TERM_DATA; i++)
2335 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2336 if (data[i].visible)
2338 EnableMenuItem(hm, IDM_WINDOW_D_WID_0 + i, MF_BYCOMMAND | MF_ENABLED);
2342 for (int i = 0; i < MAX_TERM_DATA; i++)
2344 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2345 if (data[i].visible)
2347 EnableMenuItem(hm, IDM_WINDOW_I_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2351 for (int i = 0; i < MAX_TERM_DATA; i++)
2353 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2355 if (data[i].visible)
2357 EnableMenuItem(hm, IDM_WINDOW_D_HGT_0 + i, MF_BYCOMMAND | MF_ENABLED);
2361 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2362 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2363 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2364 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2365 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2368 EnableMenuItem(hm, IDM_OPTIONS_SAVER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2371 if (use_graphics != GRAPHICS_NONE)
2372 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_ENABLED);
2374 EnableMenuItem(GetMenu(data[0].w), IDM_OPTIONS_MAP, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
2376 CheckMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS,
2377 (arg_graphics == GRAPHICS_NONE ? MF_CHECKED : MF_UNCHECKED));
2378 CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS,
2379 (arg_graphics == GRAPHICS_ORIGINAL ? MF_CHECKED : MF_UNCHECKED));
2380 CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS,
2381 (arg_graphics == GRAPHICS_ADAM_BOLT ? MF_CHECKED : MF_UNCHECKED));
2382 CheckMenuItem(hm, IDM_OPTIONS_NEW2_GRAPHICS,
2383 (arg_graphics == GRAPHICS_HENGBAND ? MF_CHECKED : MF_UNCHECKED));
2384 CheckMenuItem(hm, IDM_OPTIONS_BIGTILE,
2385 (arg_bigtile ? MF_CHECKED : MF_UNCHECKED));
2386 CheckMenuItem(hm, IDM_OPTIONS_MUSIC,
2387 (arg_music ? MF_CHECKED : MF_UNCHECKED));
2388 CheckMenuItem(hm, IDM_OPTIONS_SOUND,
2389 (arg_sound ? MF_CHECKED : MF_UNCHECKED));
2390 CheckMenuItem(hm, IDM_OPTIONS_BG,
2391 (use_bg ? MF_CHECKED : MF_UNCHECKED));
2394 CheckMenuItem(hm, IDM_OPTIONS_SAVER,
2395 (hwndSaver ? MF_CHECKED : MF_UNCHECKED));
2397 EnableMenuItem(hm, IDM_OPTIONS_NO_GRAPHICS, MF_ENABLED);
2398 EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED);
2399 EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED);
2400 EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED);
2401 EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED);
2402 EnableMenuItem(hm, IDM_OPTIONS_SAVER, MF_BYCOMMAND | MF_ENABLED);
2407 * Check for double clicked (or dragged) savefile
2409 * Apparently, Windows copies the entire filename into the first
2410 * piece of the "command line string". Perhaps we should extract
2411 * the "basename" of that filename and append it to the "save" dir.
2413 static void check_for_save_file(player_type *player_ptr, LPSTR cmd_line)
2419 strcat(savefile, s);
2420 validate_file(savefile);
2421 game_in_progress = TRUE;
2422 play_game(player_ptr, FALSE);
2427 * Process a menu command
2429 static void process_menus(player_type *player_ptr, WORD wCmd)
2439 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2441 else if (game_in_progress)
2443 plog(_("プレイ中は新しいゲームを始めることができません!", "You can't start a new game while you're still playing!"));
2447 game_in_progress = TRUE;
2449 play_game(player_ptr, TRUE);
2459 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2461 else if (game_in_progress)
2463 plog(_("プレイ中はゲームをロードすることができません!", "You can't open a new game while you're still playing!"));
2467 memset(&ofn, 0, sizeof(ofn));
2468 ofn.lStructSize = sizeof(ofn);
2469 ofn.hwndOwner = data[0].w;
2470 ofn.lpstrFilter = "Save Files (*.)\0*\0";
2471 ofn.nFilterIndex = 1;
2472 ofn.lpstrFile = savefile;
2473 ofn.nMaxFile = 1024;
2474 ofn.lpstrInitialDir = ANGBAND_DIR_SAVE;
2475 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
2477 if (GetOpenFileName(&ofn))
2479 validate_file(savefile);
2480 game_in_progress = TRUE;
2482 play_game(player_ptr, FALSE);
2491 if (game_in_progress && current_world_ptr->character_generated)
2495 plog(_("今はセーブすることは出来ません。", "You may not do that right now."));
2500 do_cmd_save_game(player_ptr, FALSE);
2504 plog(_("今、セーブすることは出来ません。", "You may not do that right now."));
2511 if (game_in_progress && current_world_ptr->character_generated)
2515 plog(_("今は終了できません。", "You may not do that right now."));
2520 forget_lite(player_ptr->current_floor_ptr);
2521 forget_view(player_ptr->current_floor_ptr);
2522 clear_mon_lite(player_ptr->current_floor_ptr);
2524 Term_key_push(SPECIAL_KEY_QUIT);
2531 case IDM_FILE_SCORE:
2534 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
2535 highscore_fd = fd_open(buf, O_RDONLY);
2536 if (highscore_fd < 0)
2538 msg_print("Score file unavailable.");
2544 display_scores_aux(0, MAX_HISCORES, -1, NULL);
2545 (void)fd_close(highscore_fd);
2553 case IDM_FILE_MOVIE:
2557 plog(_("まだ初期化中です...", "You cannot do that yet..."));
2559 else if (game_in_progress)
2561 plog(_("プレイ中はムービーをロードすることができません!", "You can't open a movie while you're playing!"));
2565 memset(&ofn, 0, sizeof(ofn));
2566 ofn.lStructSize = sizeof(ofn);
2567 ofn.hwndOwner = data[0].w;
2568 ofn.lpstrFilter = "Angband Movie Files (*.amv)\0*.amv\0";
2569 ofn.nFilterIndex = 1;
2570 ofn.lpstrFile = savefile;
2571 ofn.nMaxFile = 1024;
2572 ofn.lpstrInitialDir = ANGBAND_DIR_USER;
2573 ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
2575 if (GetOpenFileName(&ofn))
2577 prepare_browse_movie_aux(savefile);
2578 play_game(player_ptr, FALSE);
2586 case IDM_WINDOW_VIS_0:
2588 plog(_("メインウィンドウは非表示にできません!", "You are not allowed to do that!"));
2591 case IDM_WINDOW_VIS_1:
2592 case IDM_WINDOW_VIS_2:
2593 case IDM_WINDOW_VIS_3:
2594 case IDM_WINDOW_VIS_4:
2595 case IDM_WINDOW_VIS_5:
2596 case IDM_WINDOW_VIS_6:
2597 case IDM_WINDOW_VIS_7:
2599 int i = wCmd - IDM_WINDOW_VIS_0;
2600 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2606 ShowWindow(td->w, SW_SHOW);
2607 term_data_redraw(player_ptr, td);
2611 td->visible = FALSE;
2613 ShowWindow(td->w, SW_HIDE);
2618 case IDM_WINDOW_FONT_0:
2619 case IDM_WINDOW_FONT_1:
2620 case IDM_WINDOW_FONT_2:
2621 case IDM_WINDOW_FONT_3:
2622 case IDM_WINDOW_FONT_4:
2623 case IDM_WINDOW_FONT_5:
2624 case IDM_WINDOW_FONT_6:
2625 case IDM_WINDOW_FONT_7:
2627 int i = wCmd - IDM_WINDOW_FONT_0;
2628 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2631 term_change_font(td);
2634 case IDM_WINDOW_POS_1:
2635 case IDM_WINDOW_POS_2:
2636 case IDM_WINDOW_POS_3:
2637 case IDM_WINDOW_POS_4:
2638 case IDM_WINDOW_POS_5:
2639 case IDM_WINDOW_POS_6:
2640 case IDM_WINDOW_POS_7:
2642 int i = wCmd - IDM_WINDOW_POS_0;
2643 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2646 if (!td->posfix && td->visible)
2649 term_window_pos(td, HWND_TOPMOST);
2654 term_window_pos(td, data[0].w);
2659 case IDM_WINDOW_BIZ_0:
2660 case IDM_WINDOW_BIZ_1:
2661 case IDM_WINDOW_BIZ_2:
2662 case IDM_WINDOW_BIZ_3:
2663 case IDM_WINDOW_BIZ_4:
2664 case IDM_WINDOW_BIZ_5:
2665 case IDM_WINDOW_BIZ_6:
2666 case IDM_WINDOW_BIZ_7:
2668 int i = wCmd - IDM_WINDOW_BIZ_0;
2669 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2672 td->bizarre = !td->bizarre;
2674 term_window_resize(td);
2677 case IDM_WINDOW_I_WID_0:
2678 case IDM_WINDOW_I_WID_1:
2679 case IDM_WINDOW_I_WID_2:
2680 case IDM_WINDOW_I_WID_3:
2681 case IDM_WINDOW_I_WID_4:
2682 case IDM_WINDOW_I_WID_5:
2683 case IDM_WINDOW_I_WID_6:
2684 case IDM_WINDOW_I_WID_7:
2686 int i = wCmd - IDM_WINDOW_I_WID_0;
2687 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2692 term_window_resize(td);
2695 case IDM_WINDOW_D_WID_0:
2696 case IDM_WINDOW_D_WID_1:
2697 case IDM_WINDOW_D_WID_2:
2698 case IDM_WINDOW_D_WID_3:
2699 case IDM_WINDOW_D_WID_4:
2700 case IDM_WINDOW_D_WID_5:
2701 case IDM_WINDOW_D_WID_6:
2702 case IDM_WINDOW_D_WID_7:
2704 int i = wCmd - IDM_WINDOW_D_WID_0;
2705 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2710 term_window_resize(td);
2713 case IDM_WINDOW_I_HGT_0:
2714 case IDM_WINDOW_I_HGT_1:
2715 case IDM_WINDOW_I_HGT_2:
2716 case IDM_WINDOW_I_HGT_3:
2717 case IDM_WINDOW_I_HGT_4:
2718 case IDM_WINDOW_I_HGT_5:
2719 case IDM_WINDOW_I_HGT_6:
2720 case IDM_WINDOW_I_HGT_7:
2722 int i = wCmd - IDM_WINDOW_I_HGT_0;
2723 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2728 term_window_resize(td);
2731 case IDM_WINDOW_D_HGT_0:
2732 case IDM_WINDOW_D_HGT_1:
2733 case IDM_WINDOW_D_HGT_2:
2734 case IDM_WINDOW_D_HGT_3:
2735 case IDM_WINDOW_D_HGT_4:
2736 case IDM_WINDOW_D_HGT_5:
2737 case IDM_WINDOW_D_HGT_6:
2738 case IDM_WINDOW_D_HGT_7:
2740 int i = wCmd - IDM_WINDOW_D_HGT_0;
2741 if ((i < 0) || (i >= MAX_TERM_DATA)) break;
2746 term_window_resize(td);
2749 case IDM_OPTIONS_NO_GRAPHICS:
2753 plog("You may not do that right now.");
2757 if (arg_graphics != GRAPHICS_NONE)
2759 arg_graphics = GRAPHICS_NONE;
2760 term_xtra_win_react(player_ptr);
2761 Term_key_push(KTRL('R'));
2766 case IDM_OPTIONS_OLD_GRAPHICS:
2770 plog("You may not do that right now.");
2774 if (arg_graphics != GRAPHICS_ORIGINAL)
2776 arg_graphics = GRAPHICS_ORIGINAL;
2777 term_xtra_win_react(player_ptr);
2778 Term_key_push(KTRL('R'));
2783 case IDM_OPTIONS_NEW_GRAPHICS:
2787 plog("You may not do that right now.");
2791 if (arg_graphics != GRAPHICS_ADAM_BOLT)
2793 arg_graphics = GRAPHICS_ADAM_BOLT;
2794 term_xtra_win_react(player_ptr);
2795 Term_key_push(KTRL('R'));
2800 case IDM_OPTIONS_NEW2_GRAPHICS:
2804 plog("You may not do that right now.");
2808 if (arg_graphics != GRAPHICS_HENGBAND)
2810 arg_graphics = GRAPHICS_HENGBAND;
2811 term_xtra_win_react(player_ptr);
2812 Term_key_push(KTRL('R'));
2817 case IDM_OPTIONS_BIGTILE:
2822 plog("You may not do that right now.");
2826 arg_bigtile = !arg_bigtile;
2827 Term_activate(&td->t);
2828 Term_resize(td->cols, td->rows);
2829 InvalidateRect(td->w, NULL, TRUE);
2832 case IDM_OPTIONS_MUSIC:
2836 plog("You may not do that right now.");
2840 arg_music = !arg_music;
2841 term_xtra_win_react(player_ptr);
2842 Term_key_push(KTRL('R'));
2845 case IDM_OPTIONS_SOUND:
2849 plog("You may not do that right now.");
2853 arg_sound = !arg_sound;
2854 term_xtra_win_react(player_ptr);
2855 Term_key_push(KTRL('R'));
2858 case IDM_OPTIONS_BG:
2862 plog("You may not do that right now.");
2868 term_xtra_win_react(player_ptr);
2869 Term_key_push(KTRL('R'));
2872 case IDM_OPTIONS_OPEN_BG:
2876 plog("You may not do that right now.");
2880 memset(&ofn, 0, sizeof(ofn));
2881 ofn.lStructSize = sizeof(ofn);
2882 ofn.hwndOwner = data[0].w;
2883 ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0";
2884 ofn.nFilterIndex = 1;
2885 ofn.lpstrFile = bg_bitmap_file;
2886 ofn.nMaxFile = 1023;
2887 ofn.lpstrInitialDir = NULL;
2888 ofn.lpstrTitle = _("壁紙を選んでね。", "Choose wall paper.");
2889 ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
2891 if (GetOpenFileName(&ofn))
2897 term_xtra_win_react(player_ptr);
2898 Term_key_push(KTRL('R'));
2901 case IDM_DUMP_SCREEN_HTML:
2903 static char buf[1024] = "";
2904 memset(&ofn, 0, sizeof(ofn));
2905 ofn.lStructSize = sizeof(ofn);
2906 ofn.hwndOwner = data[0].w;
2907 ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0";
2908 ofn.nFilterIndex = 1;
2909 ofn.lpstrFile = buf;
2910 ofn.nMaxFile = 1023;
2911 ofn.lpstrDefExt = "html";
2912 ofn.lpstrInitialDir = NULL;
2913 ofn.lpstrTitle = _("HTMLでスクリーンダンプを保存", "Save screen dump as HTML.");
2914 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
2916 if (GetSaveFileName(&ofn))
2918 do_cmd_save_screen_html_aux(buf, 0);
2923 case IDM_OPTIONS_SAVER:
2927 DestroyWindow(hwndSaver);
2932 hwndSaver = CreateWindowEx(WS_EX_TOPMOST, "WindowsScreenSaverClass",
2933 "Angband Screensaver",
2934 WS_POPUP | WS_MAXIMIZE | WS_VISIBLE,
2935 0, 0, GetSystemMetrics(SM_CXSCREEN),
2936 GetSystemMetrics(SM_CYSCREEN),
2937 NULL, NULL, hInstance, NULL);
2941 SetWindowPos(hwndSaver, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2945 plog(_("ウィンドウを作成出来ません", "Failed to create saver window"));
2950 case IDM_OPTIONS_MAP:
2952 windows_map(player_ptr);
2956 case IDM_HELP_CONTENTS:
2960 path_build(tmp, sizeof(tmp), ANGBAND_DIR_XTRA_HELP, "zangband.hlp");
2961 if (check_file(tmp))
2963 sprintf(buf, "winhelp.exe %s", tmp);
2964 WinExec(buf, SW_NORMAL);
2968 plog_fmt(_("ヘルプファイル[%s]が見付かりません。", "Cannot find help file: %s"), tmp);
2969 plog(_("代わりにオンラインヘルプを使用してください。", "Use the online help files instead."));
2976 static bool process_keydown(WPARAM wParam, LPARAM lParam)
2982 if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
2983 if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
2984 if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;
2986 term_no_press = (ma) ? TRUE : FALSE;
2987 if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]))
2989 bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
2990 bool numpad = FALSE;
2993 if (mc) Term_keypress('C');
2994 if (ms) Term_keypress('S');
2995 if (ma) Term_keypress('A');
2997 int i = LOBYTE(HIWORD(lParam));
3002 term_no_press = TRUE;
3021 term_no_press = TRUE;
3036 if (numpad) Term_keypress('K');
3038 Term_keypress(hexsym[i / 16]);
3039 Term_keypress(hexsym[i % 16]);
3050 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
3052 LRESULT PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3056 td = (term_data *)GetWindowLong(hWnd, 0);
3062 SetWindowLong(hWnd, 0, (LONG)(my_td));
3067 mop.dwCallback = (DWORD)hWnd;
3070 case WM_GETMINMAXINFO:
3075 lpmmi = (MINMAXINFO*)lParam;
3078 rc.left = rc.top = 0;
3079 rc.right = rc.left + 80 * td->tile_wid + td->size_ow1 + td->size_ow2;
3080 rc.bottom = rc.top + 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
3082 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3084 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
3085 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
3091 BeginPaint(hWnd, &ps);
3092 if (td) term_data_redraw(p_ptr, td);
3093 EndPaint(hWnd, &ps);
3094 ValidateRect(hWnd, NULL);
3099 if (wParam == MCI_NOTIFY_SUCCESSFUL)
3101 mciSendCommand(mop.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);
3102 mciSendCommand(mop.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mop);
3110 if (process_keydown(wParam, lParam))
3116 if (term_no_press) term_no_press = FALSE;
3117 else Term_keypress(wParam);
3120 case WM_LBUTTONDOWN:
3122 mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
3123 mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
3133 TERM_LEN dx = abs(oldx - mousex) + 1;
3134 TERM_LEN dy = abs(oldy - mousey) + 1;
3135 TERM_LEN ox = (oldx > mousex) ? mousex : oldx;
3136 TERM_LEN oy = (oldy > mousey) ? mousey : oldy;
3142 int sz = (dx + 3) * dy;
3144 int sz = (dx + 2) * dy;
3146 hGlobal = GlobalAlloc(GHND, sz + 1);
3147 if (hGlobal == NULL) return 0;
3148 lpStr = (LPSTR)GlobalLock(hGlobal);
3150 for (int i = 0; i < dy; i++)
3154 char **scr = data[0].t.scr->c;
3156 C_MAKE(s, (dx + 1), char);
3157 strncpy(s, &scr[oy + i][ox], dx);
3161 if (iskanji(scr[oy + i][ox - 1])) s[0] = ' ';
3164 if (ox + dx < data[0].cols)
3166 if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' ';
3169 for (int j = 0; j < dx; j++)
3171 if (s[j] == 127) s[j] = '#';
3175 for (int j = 0; j < dx; j++)
3177 *lpStr++ = data[0].t.scr->c[oy + i][ox + j];
3187 GlobalUnlock(hGlobal);
3188 if (OpenClipboard(hWnd) == 0)
3190 GlobalFree(hGlobal);
3195 SetClipboardData(CF_TEXT, hGlobal);
3202 if (!mouse_down) return 0;
3205 int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1);
3206 int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1);
3211 dx = abs(oldx - mousex) + 1;
3212 dy = abs(oldy - mousey) + 1;
3213 ox = (oldx > mousex) ? mousex : oldx;
3214 oy = (oldy > mousey) ? mousey : oldy;
3215 term_inversed_area(hWnd, ox, oy, dx, dy);
3222 dx = abs(cx - mousex) + 1;
3223 dy = abs(cy - mousey) + 1;
3224 ox = (cx > mousex) ? mousex : cx;
3225 oy = (cy > mousey) ? mousey : cy;
3226 term_inversed_area(hWnd, ox, oy, dx, dy);
3239 if (!game_in_progress || !current_world_ptr->character_generated)
3247 plog(_("今は終了できません。", "You may not do that right now."));
3252 forget_lite(p_ptr->current_floor_ptr);
3253 forget_view(p_ptr->current_floor_ptr);
3254 clear_mon_lite(p_ptr->current_floor_ptr);
3255 Term_key_push(SPECIAL_KEY_QUIT);
3258 case WM_QUERYENDSESSION:
3260 if (!game_in_progress || !current_world_ptr->character_generated)
3267 if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
3268 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
3270 p_ptr->panic_save = 1;
3271 signals_ignore_tstp();
3272 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
3273 (void)save_player(p_ptr);
3284 process_menus(p_ptr, LOWORD(wParam));
3290 if (!td->w) return 1;
3291 if (td->size_hack) return 1;
3293 // todo 二重のswitch文。後で分割する.
3296 case SIZE_MINIMIZED:
3298 for (int i = 1; i < MAX_TERM_DATA; i++)
3300 if (data[i].visible) ShowWindow(data[i].w, SW_HIDE);
3305 case SIZE_MAXIMIZED:
3308 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
3309 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
3310 if ((td->cols != cols) || (td->rows != rows))
3314 if (!IsZoomed(td->w) && !IsIconic(td->w))
3316 normsize.x = td->cols;
3317 normsize.y = td->rows;
3320 Term_activate(&td->t);
3321 Term_resize(td->cols, td->rows);
3322 InvalidateRect(td->w, NULL, TRUE);
3325 td->size_hack = TRUE;
3326 for (int i = 1; i < MAX_TERM_DATA; i++)
3328 if (data[i].visible) ShowWindow(data[i].w, SW_SHOW);
3331 td->size_hack = FALSE;
3339 case WM_PALETTECHANGED:
3341 if ((HWND)wParam == hWnd) return 0;
3343 case WM_QUERYNEWPALETTE:
3345 if (!paletted) return 0;
3347 HDC hdc = GetDC(hWnd);
3348 SelectPalette(hdc, hPal, FALSE);
3349 int i = RealizePalette(hdc);
3350 if (i) InvalidateRect(hWnd, NULL, TRUE);
3352 ReleaseDC(hWnd, hdc);
3357 if (!wParam || HIWORD(lParam)) break;
3359 for (int i = 1; i < MAX_TERM_DATA; i++)
3361 if (!data[i].posfix) term_window_pos(&data[i], hWnd);
3367 case WM_ACTIVATEAPP:
3369 if (IsIconic(td->w)) break;
3371 for (int i = 1; i < MAX_TERM_DATA; i++)
3373 if (data[i].visible)
3377 ShowWindow(data[i].w, SW_SHOW);
3381 ShowWindow(data[i].w, SW_HIDE);
3388 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3393 * todo WNDCLASSに影響があるのでplayer_type*の追加は保留
3395 LRESULT PASCAL AngbandListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3399 td = (term_data *)GetWindowLong(hWnd, 0);
3405 SetWindowLong(hWnd, 0, (LONG)(my_td));
3412 case WM_GETMINMAXINFO:
3417 lpmmi = (MINMAXINFO*)lParam;
3420 rc.left = rc.top = 0;
3421 rc.right = rc.left + 20 * td->tile_wid + td->size_ow1 + td->size_ow2;
3422 rc.bottom = rc.top + 3 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1;
3424 AdjustWindowRectEx(&rc, td->dwStyle, TRUE, td->dwExStyle);
3425 lpmmi->ptMinTrackSize.x = rc.right - rc.left;
3426 lpmmi->ptMinTrackSize.y = rc.bottom - rc.top;
3432 if (!td->w) return 1;
3433 if (td->size_hack) return 1;
3435 td->size_hack = TRUE;
3437 TERM_LEN cols = (LOWORD(lParam) - td->size_ow1) / td->tile_wid;
3438 TERM_LEN rows = (HIWORD(lParam) - td->size_oh1) / td->tile_hgt;
3439 if ((td->cols != cols) || (td->rows != rows))
3441 term *old_term = Term;
3444 Term_activate(&td->t);
3445 Term_resize(td->cols, td->rows);
3446 Term_activate(old_term);
3447 InvalidateRect(td->w, NULL, TRUE);
3448 p_ptr->window = 0xFFFFFFFF;
3449 handle_stuff(p_ptr);
3452 td->size_hack = FALSE;
3457 BeginPaint(hWnd, &ps);
3458 if (td) term_data_redraw(p_ptr, td);
3459 EndPaint(hWnd, &ps);
3465 if (process_keydown(wParam, lParam))
3472 if (term_no_press) term_no_press = FALSE;
3473 else Term_keypress(wParam);
3476 case WM_PALETTECHANGED:
3478 if ((HWND)wParam == hWnd) return FALSE;
3480 case WM_QUERYNEWPALETTE:
3482 if (!paletted) return 0;
3484 HDC hdc = GetDC(hWnd);
3485 SelectPalette(hdc, hPal, FALSE);
3486 int i = RealizePalette(hdc);
3487 if (i) InvalidateRect(hWnd, NULL, TRUE);
3489 ReleaseDC(hWnd, hdc);
3492 case WM_NCLBUTTONDOWN:
3495 if (wParam == HTCLOSE) wParam = HTSYSMENU;
3496 #endif /* HTCLOSE */
3498 if (wParam == HTSYSMENU)
3502 td->visible = FALSE;
3503 ShowWindow(td->w, SW_HIDE);
3513 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3517 LRESULT PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3519 static int iMouse = 0;
3520 static WORD xMouse = 0;
3521 static WORD yMouse = 0;
3536 case WM_LBUTTONDOWN:
3537 case WM_MBUTTONDOWN:
3538 case WM_RBUTTONDOWN:
3541 SendMessage(hWnd, WM_CLOSE, 0, 0);
3548 int dx = LOWORD(lParam) - xMouse;
3549 int dy = HIWORD(lParam) - yMouse;
3551 if (dx < 0) dx = -dx;
3552 if (dy < 0) dy = -dy;
3554 if ((dx > MOUSE_SENS) || (dy > MOUSE_SENS))
3556 SendMessage(hWnd, WM_CLOSE, 0, 0);
3561 xMouse = LOWORD(lParam);
3562 yMouse = HIWORD(lParam);
3568 DestroyWindow(hwndSaver);
3574 return DefWindowProc(hWnd, uMsg, wParam, lParam);
3579 * Display warning message (see "z-util.c")
3581 static void hack_plog(concptr str)
3586 MessageBox(NULL, str, "警告!",
3587 MB_ICONEXCLAMATION | MB_OK);
3589 MessageBox(NULL, str, "Warning",
3590 MB_ICONEXCLAMATION | MB_OK);
3598 * Display error message and quit (see "z-util.c")
3600 static void hack_quit(concptr str)
3605 MessageBox(NULL, str, "エラー!",
3606 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3608 MessageBox(NULL, str, "Error",
3609 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3614 UnregisterClass(AppName, hInstance);
3615 if (hIcon) DestroyIcon(hIcon);
3622 * Display warning message (see "z-util.c")
3624 static void hook_plog(concptr str)
3629 MessageBox(data[0].w, str, "警告!",
3630 MB_ICONEXCLAMATION | MB_OK);
3632 MessageBox(data[0].w, str, "Warning",
3633 MB_ICONEXCLAMATION | MB_OK);
3641 * Display error message and quit (see "z-util.c")
3643 static void hook_quit(concptr str)
3648 MessageBox(data[0].w, str, "エラー!",
3649 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3651 MessageBox(data[0].w, str, "Error",
3652 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3657 for (int i = MAX_TERM_DATA - 1; i >= 0; --i)
3659 term_force_font(&data[i], NULL);
3660 if (data[i].font_want) string_free(data[i].font_want);
3661 if (data[i].w) DestroyWindow(data[i].w);
3665 if (infGraph.hPalette) DeleteObject(infGraph.hPalette);
3666 if (infGraph.hBitmap) DeleteObject(infGraph.hBitmap);
3667 if (infMask.hPalette) DeleteObject(infMask.hPalette);
3668 if (infMask.hBitmap) DeleteObject(infMask.hBitmap);
3670 DeleteObject(hbrYellow);
3673 if (hPal) DeleteObject(hPal);
3675 UnregisterClass(AppName, hInstance);
3676 if (hIcon) DestroyIcon(hIcon);
3685 static void init_stuff(void)
3688 GetModuleFileName(hInstance, path, 512);
3690 strcpy(path + strlen(path) - 4, ".INI");
3691 ini_file = string_make(path);
3692 int i = strlen(path);
3696 if (path[i] == '\\')
3702 strcpy(path + i + 1, "lib\\");
3703 validate_dir(path, TRUE);
3704 init_file_paths(path);
3705 validate_dir(ANGBAND_DIR_APEX, FALSE);
3706 validate_dir(ANGBAND_DIR_BONE, FALSE);
3707 if (!check_dir(ANGBAND_DIR_EDIT))
3709 validate_dir(ANGBAND_DIR_DATA, TRUE);
3713 validate_dir(ANGBAND_DIR_DATA, FALSE);
3716 validate_dir(ANGBAND_DIR_FILE, TRUE);
3717 validate_dir(ANGBAND_DIR_HELP, FALSE);
3718 validate_dir(ANGBAND_DIR_INFO, FALSE);
3719 validate_dir(ANGBAND_DIR_PREF, TRUE);
3720 validate_dir(ANGBAND_DIR_SAVE, FALSE);
3721 validate_dir(ANGBAND_DIR_USER, TRUE);
3722 validate_dir(ANGBAND_DIR_XTRA, TRUE);
3723 path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
3725 validate_file(path);
3726 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "graf");
3727 ANGBAND_DIR_XTRA_GRAF = string_make(path);
3728 validate_dir(ANGBAND_DIR_XTRA_GRAF, TRUE);
3730 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");
3731 ANGBAND_DIR_XTRA_SOUND = string_make(path);
3732 validate_dir(ANGBAND_DIR_XTRA_SOUND, FALSE);
3734 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "music");
3735 ANGBAND_DIR_XTRA_MUSIC = string_make(path);
3736 validate_dir(ANGBAND_DIR_XTRA_MUSIC, FALSE);
3738 path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "help");
3739 ANGBAND_DIR_XTRA_HELP = string_make(path);
3744 * todo よく見るとhMutexはちゃんと使われていない……?
3745 * @brief (Windows固有)変愚蛮怒が起動済かどうかのチェック
3747 static bool is_already_running(void)
3750 hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
3751 if (GetLastError() == ERROR_ALREADY_EXISTS)
3761 * @brief (Windows固有)Windowsアプリケーションとしてのエントリポイント
3763 int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
3769 setlocale(LC_ALL, "ja_JP");
3772 if (is_already_running())
3775 _("変愚蛮怒はすでに起動しています。", "Hengband is already running."),
3777 MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
3781 if (hPrevInst == NULL)
3783 wc.style = CS_CLASSDC;
3784 wc.lpfnWndProc = AngbandWndProc;
3787 wc.hInstance = hInst;
3788 wc.hIcon = hIcon = LoadIcon(hInst, AppName);
3789 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
3790 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
3791 wc.lpszMenuName = AppName;
3792 wc.lpszClassName = AppName;
3794 if (!RegisterClass(&wc)) exit(1);
3796 wc.lpfnWndProc = AngbandListProc;
3797 wc.lpszMenuName = NULL;
3798 wc.lpszClassName = AngList;
3800 if (!RegisterClass(&wc)) exit(2);
3802 wc.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_DBLCLKS;
3803 wc.lpfnWndProc = AngbandSaverProc;
3805 wc.lpszMenuName = NULL;
3806 wc.lpszClassName = "WindowsScreenSaverClass";
3808 if (!RegisterClass(&wc)) exit(3);
3811 plog_aux = hack_plog;
3812 quit_aux = hack_quit;
3813 core_aux = hack_quit;
3816 for (int i = 0; special_key_list[i]; ++i)
3818 special_key[special_key_list[i]] = TRUE;
3821 for (int i = 0; ignore_key_list[i]; ++i)
3823 ignore_key[ignore_key_list[i]] = TRUE;
3827 colors16 = (GetDeviceCaps(hdc, BITSPIXEL) == 4);
3828 paletted = ((GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) ? TRUE : FALSE);
3829 ReleaseDC(NULL, hdc);
3831 for (int i = 0; i < 256; i++)
3833 byte rv = angband_color_table[i][1];
3834 byte gv = angband_color_table[i][2];
3835 byte bv = angband_color_table[i][3];
3836 win_clr[i] = PALETTERGB(rv, gv, bv);
3837 angband_color_table[i][0] = win_pal[i];
3843 plog_aux = hook_plog;
3844 quit_aux = hook_quit;
3845 core_aux = hook_quit;
3847 ANGBAND_SYS = "win";
3848 if (7 != GetKeyboardType(0))
3849 ANGBAND_KEYBOARD = "0";
3852 switch (GetKeyboardType(1))
3854 case 0x0D01: case 0x0D02:
3855 case 0x0D03: case 0x0D04:
3856 case 0x0D05: case 0x0D06:
3858 ANGBAND_KEYBOARD = "NEC98";
3862 ANGBAND_KEYBOARD = "JAPAN";
3867 Term_activate(term_screen);
3868 init_angband(p_ptr, process_autopick_file_command);
3871 if (lpCmdLine[0] == '-') {
3872 switch (lpCmdLine[1])
3877 if (!lpCmdLine[2]) break;
3878 chuukei_server = TRUE;
3879 if (connect_chuukei_server(&lpCmdLine[2]) < 0) {
3880 msg_print("connect fail");
3883 msg_print("connect");
3891 if (!lpCmdLine[2]) break;
3892 chuukei_client = TRUE;
3893 connect_chuukei_server(&lpCmdLine[2]);
3894 play_game(player_ptr, FALSE);
3901 if (!lpCmdLine[2]) break;
3902 prepare_browse_movie(&lpCmdLine[2]);
3903 play_game(player_ptr, FALSE);
3912 if (!chuukei_server) check_for_save_file(lpCmdLine);
3914 check_for_save_file(p_ptr, lpCmdLine);
3917 prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
3919 while (GetMessage(&msg, NULL, 0, 0))
3921 TranslateMessage(&msg);
3922 DispatchMessage(&msg);
3928 #endif /* WINDOWS */