📄 main-win.c
字号:
/* File: main-win.c */
/*
* Copyright (c) 1997 Ben Harrison, Skirmantas Kligys, Robert Ruehlmann,
* and others
*
* This software may be copied and distributed for educational, research,
* and not for profit purposes provided that this copyright and statement
* are included in all such copies.
*/
/*
* This file helps Angband work with Windows computers.
*
* To use this file, use an appropriate "Makefile" or "Project File",
* make sure that "WINDOWS" and/or "WIN32" are defined somewhere, and
* make sure to obtain various extra files as described below.
*
* The Windows version has been tested to compile with Visual C++ 5.0
* and 6.0, CygWin 2.01 Beta, Borland C++ 5.5 command line tools, and
* lcc-win32.
*
*
* See also "main-dos.c" and "main-ibm.c".
*
*
* The "lib/user/pref-win.prf" file contains keymaps, macro definitions,
* and/or color redefinitions.
*
* The "lib/user/font-win.prf" contains attr/char mappings for use with the
* normal "*.fon" font files in the "lib/xtra/font/" directory.
*
* The "lib/user/graf-win.prf" contains attr/char mappings for use with the
* special "*.bmp" bitmap files in the "lib/xtra/graf/" directory, which
* are activated by a menu item.
*
*
* Compiling this file, and using the resulting executable, requires
* several extra files not distributed with the standard Angband code.
* If "USE_GRAPHICS" is defined, then "readdib.h" and "readdib.c" must
* be placed into "src/", and the "8X8.BMP" bitmap file must be placed
* into "lib/xtra/graf". In any case, some "*.fon" files (including
* "8X13.FON" if nothing else) must be placed into "lib/xtra/font/".
* If "USE_SOUND" is defined, then some special library (for example,
* "winmm.lib") may need to be linked in, and desired "*.WAV" sound
* files must be placed into "lib/xtra/sound/". All of these extra
* files can be found in the "ext-win" archive.
*
*
* The "Term_xtra_win_clear()" function should probably do a low-level
* clear of the current window, and redraw the borders and other things,
* if only for efficiency. XXX XXX XXX
*
* A simpler method is needed for selecting the "tile size" for windows.
* XXX XXX XXX
*
* Special "Windows Help Files" can be placed into "lib/xtra/help/" for
* use with the "winhelp.exe" program. These files *may* be available
* at the ftp site somewhere, but I have not seen them. XXX XXX XXX
*
* ToDo: The screensaver mode should implement ScreenSaverConfigureDialog,
* DefScreenSaverProc, and ScreenSaverProc.
*
* Initial framework (and most code) by Ben Harrison (benh@phial.com).
*
* Original code by Skirmantas Kligys (kligys@scf.usc.edu).
*
* Additional code by Ross E Becker (beckerr@cis.ohio-state.edu),
* and Chris R. Martin (crm7479@tam2000.tamu.edu).
*
* Additional code by Robert Ruehlmann <rr9@angband.org>.
*/
#include "angband.h"
#ifdef WINDOWS
/*
* Use HTML-Help.
*/
/* #define HTML_HELP */
#ifdef HTML_HELP
# define HELP_GENERAL "angband.chm"
# define HELP_SPOILERS "angband.chm"
#else /* HTML_HELP */
# define HELP_GENERAL "angband.hlp"
# define HELP_SPOILERS "spoilers.hlp"
#endif /* HTML_HELP */
/*
* Extract the "WIN32" flag from the compiler
*/
#if defined(__WIN32__) || defined(__WINNT__) || defined(__NT__)
# ifndef WIN32
# define WIN32
# endif
#endif
/*
* Hack -- allow use of "screen saver" mode
*/
#define USE_SAVER
/*
* Menu constants -- see "ANGBAND.RC"
*/
#define IDM_FILE_NEW 100
#define IDM_FILE_OPEN 101
#define IDM_FILE_SAVE 110
#define IDM_FILE_SCORE 120
#define IDM_FILE_EXIT 130
#define IDM_WINDOW_VIS_0 200
#define IDM_WINDOW_VIS_1 201
#define IDM_WINDOW_VIS_2 202
#define IDM_WINDOW_VIS_3 203
#define IDM_WINDOW_VIS_4 204
#define IDM_WINDOW_VIS_5 205
#define IDM_WINDOW_VIS_6 206
#define IDM_WINDOW_VIS_7 207
#define IDM_WINDOW_FONT_0 210
#define IDM_WINDOW_FONT_1 211
#define IDM_WINDOW_FONT_2 212
#define IDM_WINDOW_FONT_3 213
#define IDM_WINDOW_FONT_4 214
#define IDM_WINDOW_FONT_5 215
#define IDM_WINDOW_FONT_6 216
#define IDM_WINDOW_FONT_7 217
#define IDM_WINDOW_BIZ_0 230
#define IDM_WINDOW_BIZ_1 231
#define IDM_WINDOW_BIZ_2 232
#define IDM_WINDOW_BIZ_3 233
#define IDM_WINDOW_BIZ_4 234
#define IDM_WINDOW_BIZ_5 235
#define IDM_WINDOW_BIZ_6 236
#define IDM_WINDOW_BIZ_7 237
#define IDM_WINDOW_I_WID_0 240
#define IDM_WINDOW_I_WID_1 241
#define IDM_WINDOW_I_WID_2 242
#define IDM_WINDOW_I_WID_3 243
#define IDM_WINDOW_I_WID_4 244
#define IDM_WINDOW_I_WID_5 245
#define IDM_WINDOW_I_WID_6 246
#define IDM_WINDOW_I_WID_7 247
#define IDM_WINDOW_D_WID_0 250
#define IDM_WINDOW_D_WID_1 251
#define IDM_WINDOW_D_WID_2 252
#define IDM_WINDOW_D_WID_3 253
#define IDM_WINDOW_D_WID_4 254
#define IDM_WINDOW_D_WID_5 255
#define IDM_WINDOW_D_WID_6 256
#define IDM_WINDOW_D_WID_7 257
#define IDM_WINDOW_I_HGT_0 260
#define IDM_WINDOW_I_HGT_1 261
#define IDM_WINDOW_I_HGT_2 262
#define IDM_WINDOW_I_HGT_3 263
#define IDM_WINDOW_I_HGT_4 264
#define IDM_WINDOW_I_HGT_5 265
#define IDM_WINDOW_I_HGT_6 266
#define IDM_WINDOW_I_HGT_7 267
#define IDM_WINDOW_D_HGT_0 270
#define IDM_WINDOW_D_HGT_1 271
#define IDM_WINDOW_D_HGT_2 272
#define IDM_WINDOW_D_HGT_3 273
#define IDM_WINDOW_D_HGT_4 274
#define IDM_WINDOW_D_HGT_5 275
#define IDM_WINDOW_D_HGT_6 276
#define IDM_WINDOW_D_HGT_7 277
#define IDM_OPTIONS_NO_GRAPHICS 400
#define IDM_OPTIONS_OLD_GRAPHICS 401
#define IDM_OPTIONS_NEW_GRAPHICS 402
#define IDM_OPTIONS_SOUND 410
#define IDM_OPTIONS_LOW_PRIORITY 420
#define IDM_OPTIONS_SAVER 430
#define IDM_OPTIONS_MAP 440
#define IDM_HELP_GENERAL 901
#define IDM_HELP_SPOILERS 902
/*
* This may need to be removed for some compilers XXX XXX XXX
*/
#define STRICT
/*
* Exclude parts of WINDOWS.H that are not needed
*/
#define NOCOMM /* Comm driver APIs and definitions */
#define NOLOGERROR /* LogError() and related definitions */
#define NOPROFILER /* Profiler APIs */
#define NOLFILEIO /* _l* file I/O routines */
#define NOOPENFILE /* OpenFile and related definitions */
#define NORESOURCE /* Resource management */
#define NOATOM /* Atom management */
#define NOLANGUAGE /* Character test routines */
#define NOLSTRING /* lstr* string management routines */
#define NODBCS /* Double-byte character set routines */
#define NOKEYBOARDINFO /* Keyboard driver routines */
#define NOCOLOR /* COLOR_* color values */
#define NODRAWTEXT /* DrawText() and related definitions */
#define NOSCALABLEFONT /* Truetype scalable font support */
#define NOMETAFILE /* Metafile support */
#define NOSYSTEMPARAMSINFO /* SystemParametersInfo() and SPI_* definitions */
#define NODEFERWINDOWPOS /* DeferWindowPos and related definitions */
#define NOKEYSTATES /* MK_* message key state flags */
#define NOWH /* SetWindowsHook and related WH_* definitions */
#define NOCLIPBOARD /* Clipboard APIs and definitions */
#define NOICONS /* IDI_* icon IDs */
#define NOMDI /* MDI support */
#define NOHELP /* Help support */
/* Not defined since it breaks Borland C++ 5.5 */
/* #define NOCTLMGR */ /* Control management and controls */
/*
* Exclude parts of WINDOWS.H that are not needed (Win32)
*/
#define WIN32_LEAN_AND_MEAN
#define NONLS /* All NLS defines and routines */
#define NOSERVICE /* All Service Controller routines, SERVICE_ equates, etc. */
#define NOKANJI /* Kanji support stuff. */
#define NOMCX /* Modem Configuration Extensions */
/*
* Include the "windows" support file
*/
#include <windows.h>
/*
* Exclude parts of MMSYSTEM.H that are not needed
*/
#define MMNODRV /* Installable driver support */
#define MMNOWAVE /* Waveform support */
#define MMNOMIDI /* MIDI support */
#define MMNOAUX /* Auxiliary audio support */
#define MMNOTIMER /* Timer support */
#define MMNOJOY /* Joystick support */
#define MMNOMCI /* MCI support */
#define MMNOMMIO /* Multimedia file I/O support */
#define MMNOMMSYSTEM /* General MMSYSTEM functions */
/*
* Include some more files. Note: the Cygnus Cygwin compiler
* doesn't use mmsystem.h instead it includes the winmm library
* which performs a similar function.
*/
#ifndef __CYGWIN__
# include <mmsystem.h>
#endif /* __CYGWIN__ */
#include <commdlg.h>
/*
* HTML-Help requires htmlhelp.h and htmlhelp.lib from Microsoft's
* HTML Workshop < msdn.microsoft.com/workshop/author/htmlhelp/ >.
*/
#ifdef HTML_HELP
#include <htmlhelp.h>
#endif /* HTML_HELP */
/*
* Include the support for loading bitmaps
*/
#ifdef USE_GRAPHICS
# include "readdib.h"
#endif /* USE_GRAPHICS */
/*
* Hack -- Fake declarations from "dos.h" XXX XXX XXX
*/
#ifdef WIN32
#define INVALID_FILE_NAME (DWORD)0xFFFFFFFF
#else /* WIN32 */
#define FA_LABEL 0x08 /* Volume label */
#define FA_DIREC 0x10 /* Directory */
unsigned _cdecl _dos_getfileattr(const char *, unsigned *);
#endif /* WIN32 */
/*
* Silliness in WIN32 drawing routine
*/
#ifdef WIN32
# define MoveTo(H,X,Y) MoveToEx(H, X, Y, NULL)
#endif /* WIN32 */
/*
* Silliness for Windows 95
*/
#ifndef WS_EX_TOOLWINDOW
# define WS_EX_TOOLWINDOW 0
#endif /* WS_EX_TOOLWINDOW */
/*
* Foreground color bits (hard-coded by DOS)
*/
#define VID_BLACK 0x00
#define VID_BLUE 0x01
#define VID_GREEN 0x02
#define VID_CYAN 0x03
#define VID_RED 0x04
#define VID_MAGENTA 0x05
#define VID_YELLOW 0x06
#define VID_WHITE 0x07
/*
* Bright text (hard-coded by DOS)
*/
#define VID_BRIGHT 0x08
/*
* Background color bits (hard-coded by DOS)
*/
#define VUD_BLACK 0x00
#define VUD_BLUE 0x10
#define VUD_GREEN 0x20
#define VUD_CYAN 0x30
#define VUD_RED 0x40
#define VUD_MAGENTA 0x50
#define VUD_YELLOW 0x60
#define VUD_WHITE 0x70
/*
* Blinking text (hard-coded by DOS)
*/
#define VUD_BRIGHT 0x80
/*
* Forward declare
*/
typedef struct _term_data term_data;
/*
* Extra "term" data
*
* Note the use of "font_want" for the names of the font file requested by
* the user, and the use of "font_file" for the currently active font file.
*
* The "font_file" is uppercased, and takes the form "8X13.FON", while
* "font_want" can be in almost any form as long as it could be construed
* as attempting to represent the name of a font.
*/
struct _term_data
{
term t;
cptr s;
HWND w;
DWORD dwStyle;
DWORD dwExStyle;
uint keys;
uint rows;
uint cols;
uint pos_x;
uint pos_y;
uint size_wid;
uint size_hgt;
uint size_ow1;
uint size_oh1;
uint size_ow2;
uint size_oh2;
bool size_hack;
bool xtra_hack;
bool visible;
bool bizarre;
cptr font_want;
cptr font_file;
HFONT font_id;
uint font_wid;
uint font_hgt;
uint tile_wid;
uint tile_hgt;
uint map_tile_wid;
uint map_tile_hgt;
bool map_active;
};
/*
* Maximum number of windows XXX XXX XXX
*/
#define MAX_TERM_DATA 8
/*
* An array of term_data's
*/
static term_data data[MAX_TERM_DATA];
/*
* Hack -- global "window creation" pointer
*/
static term_data *my_td;
/*
* game in progress
*/
bool game_in_progress = FALSE;
/*
* note when "open"/"new" become valid
*/
bool initialized = FALSE;
/*
* screen paletted, i.e. 256 colors
*/
bool paletted = FALSE;
/*
* 16 colors screen, don't use RGB()
*/
bool colors16 = FALSE;
static bool low_priority = FALSE;
/*
* Saved instance handle
*/
static HINSTANCE hInstance;
/*
* Yellow brush for the cursor
*/
static HBRUSH hbrYellow;
/*
* An icon
*/
static HICON hIcon;
/*
* A palette
*/
static HPALETTE hPal;
#ifdef USE_SAVER
/*
* The screen saver window
*/
static HWND hwndSaver;
static bool screensaver = FALSE;
static bool screensaver_active = FALSE;
static HANDLE screensaverSemaphore;
static char saverfilename[1024];
static HMENU main_menu;
#define MOUSE_SENS 10
#endif /* USE_SAVER */
#ifdef USE_GRAPHICS
/*
* Flag set once "graphics" has been initialized
*/
static bool can_use_graphics = FALSE;
/*
* The global bitmap
*/
static DIBINIT infGraph;
#ifdef USE_TRANSPARENCY
/*
* The global bitmap mask
*/
static DIBINIT infMask;
#endif /* USE_TRANSPARENCY */
#endif /* USE_GRAPHICS */
#ifdef USE_SOUND
/*
* Flag set once "sound" has been initialized
*/
static bool can_use_sound = FALSE;
#define SAMPLE_MAX 8
/*
* An array of sound file names
*/
static cptr sound_file[SOUND_MAX][SAMPLE_MAX];
#endif /* USE_SOUND */
/*
* Full path to ANGBAND.INI
*/
static cptr ini_file = NULL;
/*
* Name of application
*/
static cptr AppName = "ANGBAND";
/*
* Name of sub-window type
*/
static cptr AngList = "AngList";
/*
* Directory names
*/
static cptr ANGBAND_DIR_XTRA_FONT;
static cptr ANGBAND_DIR_XTRA_GRAF;
static cptr ANGBAND_DIR_XTRA_SOUND;
static cptr ANGBAND_DIR_XTRA_HELP;
#if 0
static cptr ANGBAND_DIR_XTRA_MUSIC;
#endif /* 0 */
/*
* The "complex" color values
*/
static COLORREF win_clr[256];
/*
* The "simple" color values
*
* See "main-ibm.c" for original table information
*
* The entries below are taken from the "color bits" defined above.
*
* Note that many of the choices below suck, but so do crappy monitors.
*/
static BYTE win_pal[256] =
{
VID_BLACK, /* Dark */
VID_WHITE, /* White */
VID_CYAN, /* Slate XXX */
VID_RED | VID_BRIGHT, /* Orange XXX */
VID_RED, /* Red */
VID_GREEN, /* Green */
VID_BLUE, /* Blue */
VID_YELLOW, /* Umber XXX */
VID_BLACK | VID_BRIGHT, /* Light Dark */
VID_CYAN | VID_BRIGHT, /* Light Slate XXX */
VID_MAGENTA, /* Violet XXX */
VID_YELLOW | VID_BRIGHT, /* Yellow */
VID_MAGENTA | VID_BRIGHT, /* Light Red XXX */
VID_GREEN | VID_BRIGHT, /* Light Green */
VID_BLUE | VID_BRIGHT, /* Light Blue */
VID_YELLOW /* Light Umber XXX */
};
#ifdef SUPPORT_GAMMA
static int gamma_correction;
#endif /* SUPPORT_GAMMA */
/*
* Hack -- define which keys are "special"
*/
static bool special_key[256];
/*
* Hack -- initialization list for "special_key"
*
* We ignore the modifier keys (shift, control, alt, num lock, scroll lock),
* and the normal keys (escape, tab, return, letters, numbers, etc), but we
* catch the keypad keys (with and without numlock set, including keypad 5),
* the function keys (including the "menu" key which maps to F10), and the
* "pause" key (between scroll lock and numlock). We also catch a few odd
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -