1 /* NetHack 3.7 winMS.h $NHDT-Date: 1596498367 2020/08/03 23:46:07 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.53 $ */ 2 /* Copyright (C) 2001 by Alex Kompel */ 3 /* NetHack may be freely redistributed. See license for details. */ 4 5 #ifndef WINMS_H 6 #define WINMS_H 7 8 #ifdef _MSC_VER 9 #if _MSC_VER >= 1400 10 /* Visual C 8 warning elimination */ 11 #ifndef _CRT_SECURE_NO_DEPRECATE 12 #define _CRT_SECURE_NO_DEPRECATE 13 #endif 14 #ifndef _SCL_SECURE_NO_DEPRECATE 15 #define _SCL_SECURE_NO_DEPRECATE 16 #endif 17 #ifndef _CRT_NONSTDC_NO_DEPRECATE 18 #define _CRT_NONSTDC_NO_DEPRECATE 19 #endif 20 #endif 21 #endif 22 23 #undef Protection /* We have a global name space collision. No source file 24 using win32api.h should be using the Protection macro 25 from youprop.h. 26 A better fix would be to ensure we include all window 27 header files before we start clobbering the global name 28 space with NetHack specific macros. */ 29 30 #define WIN32_LEAN_AND_MEAN 31 #include <windows.h> 32 #include <windowsx.h> 33 #include <commctrl.h> 34 #include <tchar.h> 35 #include "hack.h" 36 #include "color.h" 37 38 #define TEXT_BUFFER_SIZE 4096 39 40 /* Create an array to keep track of the various windows */ 41 42 #ifndef MAXWINDOWS 43 #define MAXWINDOWS 15 44 #endif 45 46 #define NHW_RIP 32 47 #define NHW_INVEN 33 48 49 #ifndef TILE_X 50 #define TILE_X 16 51 #endif 52 #define TILE_Y 16 53 54 #define TILES_PER_LINE 40 55 56 /* tile background color */ 57 #define TILE_BK_COLOR RGB(71, 108, 108) 58 59 /* minimum/maximum font size (in points - 1/72 inch) */ 60 #define NHFONT_DEFAULT_SIZE 9 61 #define NHFONT_SIZE_MIN 3 62 #define NHFONT_SIZE_MAX 20 63 64 #define MAX_LOADSTRING 100 65 #define USE_PILEMARK 66 67 typedef struct mswin_nhwindow_data { 68 HWND win; 69 int type; 70 int dead; 71 } MSNHWinData, *PMSNHWinData; 72 73 typedef BOOL(WINAPI *LPTRANSPARENTBLT)(HDC, int, int, int, int, HDC, int, int, 74 int, int, UINT); 75 76 typedef struct mswin_nhwindow_app { 77 HINSTANCE hApp; 78 HWND hMainWnd; 79 HACCEL hAccelTable; 80 HWND hPopupWnd; /* current popup window */ 81 82 MSNHWinData windowlist[MAXWINDOWS]; 83 84 HBITMAP bmpTiles; 85 HBITMAP bmpPetMark; 86 #ifdef USE_PILEMARK 87 HBITMAP bmpPileMark; 88 #endif 89 HBITMAP bmpMapTiles; /* custom tiles bitmap */ 90 HBITMAP bmpRip; 91 HBITMAP bmpSplash; 92 int mapTile_X; /* tile width */ 93 int mapTile_Y; /* tile height */ 94 int mapTilesPerLine; /* number of tile per row in the bitmap */ 95 96 boolean bNoHScroll; /* disable cliparound for horizontal grid (map) */ 97 boolean bNoVScroll; /* disable cliparound for vertical grid (map) */ 98 99 int mapDisplayModeSave; /* saved map display mode */ 100 101 char *saved_text; 102 103 DWORD saveRegistrySettings; /* Flag if we should save this time */ 104 DWORD 105 regNetHackMode; /* NetHack mode means no Windows keys in some places 106 */ 107 108 COLORREF regMapColors[CLR_MAX]; 109 110 LONG regMainMinX; 111 LONG regMainMinY; 112 LONG regMainMaxX; 113 LONG regMainMaxY; 114 LONG regMainLeft; 115 LONG regMainTop; 116 LONG regMainBottom; 117 LONG regMainRight; 118 DWORD regMainShowState; 119 120 BOOL bAutoLayout; 121 RECT rtMapWindow; 122 RECT rtMsgWindow; 123 RECT rtStatusWindow; 124 RECT rtMenuWindow; 125 RECT rtTextWindow; 126 RECT rtInvenWindow; 127 BOOL bWindowsLocked; /* TRUE if windows are "locked" - no captions */ 128 129 BOOL bNoSounds; /* disable sounds */ 130 131 LPTRANSPARENTBLT lpfnTransparentBlt; /* transparent blt function */ 132 } NHWinApp, *PNHWinApp; 133 134 #define E extern 135 136 E PNHWinApp GetNHApp(void); 137 E struct window_procs mswin_procs; 138 139 #undef E 140 141 /* Some prototypes */ 142 void mswin_init_nhwindows(int *argc, char **argv); 143 void mswin_player_selection(void); 144 void mswin_askname(void); 145 void mswin_get_nh_event(void); 146 void mswin_exit_nhwindows(const char *); 147 void mswin_suspend_nhwindows(const char *); 148 void mswin_resume_nhwindows(void); 149 winid mswin_create_nhwindow(int type); 150 void mswin_clear_nhwindow(winid wid); 151 void mswin_display_nhwindow(winid wid, boolean block); 152 void mswin_destroy_nhwindow(winid wid); 153 void mswin_curs(winid wid, int x, int y); 154 void mswin_putstr(winid wid, int attr, const char *text); 155 void mswin_putstr_ex(winid wid, int attr, const char *text, int); 156 void mswin_display_file(const char *filename, boolean must_exist); 157 void mswin_start_menu(winid wid, unsigned long mbehavior); 158 void mswin_add_menu(winid wid, const glyph_info *glyphinfo, 159 const ANY_P *identifier, 160 char accelerator, char group_accel, int attr, 161 const char *str, unsigned int itemflags); 162 void mswin_end_menu(winid wid, const char *prompt); 163 int mswin_select_menu(winid wid, int how, MENU_ITEM_P **selected); 164 void mswin_update_inventory(int); 165 void mswin_mark_synch(void); 166 void mswin_wait_synch(void); 167 void mswin_cliparound(int x, int y); 168 void mswin_print_glyph(winid wid, xchar x, xchar y, 169 const glyph_info *glyph, const glyph_info *bkglyph); 170 void mswin_raw_print(const char *str); 171 void mswin_raw_print_bold(const char *str); 172 void mswin_raw_print_flush(); 173 int mswin_nhgetch(void); 174 int mswin_nh_poskey(int *x, int *y, int *mod); 175 void mswin_nhbell(void); 176 int mswin_doprev_message(void); 177 char mswin_yn_function(const char *question, const char *choices, char def); 178 void mswin_getlin(const char *question, char *input); 179 int mswin_get_ext_cmd(void); 180 void mswin_number_pad(int state); 181 void mswin_delay_output(void); 182 void mswin_change_color(void); 183 char *mswin_get_color_string(void); 184 void mswin_start_screen(void); 185 void mswin_end_screen(void); 186 void mswin_outrip(winid wid, int how, time_t when); 187 void mswin_preference_update(const char *pref); 188 char *mswin_getmsghistory(boolean init); 189 void mswin_putmsghistory(const char *msg, boolean); 190 191 void mswin_status_init(void); 192 void mswin_status_finish(void); 193 void mswin_status_enablefield(int fieldidx, const char *nm, const char *fmt, 194 boolean enable); 195 void mswin_status_update(int idx, genericptr_t ptr, int chg, int percent, int color, unsigned long *colormasks); 196 197 /* helper function */ 198 HWND mswin_hwnd_from_winid(winid wid); 199 winid mswin_winid_from_type(int type); 200 winid mswin_winid_from_handle(HWND hWnd); 201 void mswin_window_mark_dead(winid wid); 202 void bail(const char *mesg); 203 204 void mswin_popup_display(HWND popup, int *done_indicator); 205 void mswin_popup_destroy(HWND popup); 206 207 void mswin_read_reg(void); 208 void mswin_destroy_reg(void); 209 void mswin_write_reg(void); 210 211 void mswin_get_window_placement(int type, LPRECT rt); 212 void mswin_update_window_placement(int type, LPRECT rt); 213 void mswin_apply_window_style(HWND hwnd); 214 215 int NHMessageBox(HWND hWnd, LPCTSTR text, UINT type); 216 217 extern HBRUSH menu_bg_brush; 218 extern HBRUSH menu_fg_brush; 219 extern HBRUSH text_bg_brush; 220 extern HBRUSH text_fg_brush; 221 extern HBRUSH status_bg_brush; 222 extern HBRUSH status_fg_brush; 223 extern HBRUSH message_bg_brush; 224 extern HBRUSH message_fg_brush; 225 226 extern COLORREF menu_bg_color; 227 extern COLORREF menu_fg_color; 228 extern COLORREF text_bg_color; 229 extern COLORREF text_fg_color; 230 extern COLORREF status_bg_color; 231 extern COLORREF status_fg_color; 232 extern COLORREF message_bg_color; 233 extern COLORREF message_fg_color; 234 235 #define SYSCLR_TO_BRUSH(x) ((HBRUSH)(((intptr_t) x) + 1)) 236 237 /* unicode stuff */ 238 #define NH_CODEPAGE (SYMHANDLING(H_IBM) ? GetOEMCP() : GetACP()) 239 #ifdef _UNICODE 240 #define NH_W2A(w, a, cb) \ 241 (WideCharToMultiByte(NH_CODEPAGE, 0, (w), -1, (a), (cb), NULL, NULL), (a)) 242 243 #define NH_A2W(a, w, cb) \ 244 (MultiByteToWideChar(NH_CODEPAGE, 0, (a), -1, (w), (cb)), (w)) 245 #else 246 #define NH_W2A(w, a, cb) (strncpy((a), (w), (cb))) 247 248 #define NH_A2W(a, w, cb) (strncpy((w), (a), (cb))) 249 #endif 250 251 /* map mode macros */ 252 #define IS_MAP_FIT_TO_SCREEN(mode) \ 253 ((mode) == MAP_MODE_ASCII_FIT_TO_SCREEN \ 254 || (mode) == MAP_MODE_TILES_FIT_TO_SCREEN) 255 256 #define IS_MAP_ASCII(mode) \ 257 ((mode) != MAP_MODE_TILES && (mode) != MAP_MODE_TILES_FIT_TO_SCREEN) 258 259 #endif /* WINMS_H */ 260