(from <Someone>)

This patch implements Michael's idea to have a "NetHack mode" for
keypresses. It only does the Alt-keys now, but it should be easy
to extend to pressing space in dialogs; I left that out as we still
have to agree on a new dialog look.

The setting that you choose from the menu is stored in the registry.
Reading and writing the registry is done on init_nhwindows and
exit_nhwindows; there also is a menu item to delete the registry
settings (which makes sure they are not stored again this session.)
This provides a framework for future registry settings.

Also,
Alt-tab should show the app title when a menu or text window is up.

I left the app title as it was, although I still favour "Graphical
Version" or "With Graphics"; Anyway, that's only one resource string.
This commit is contained in:
nethack.allison
2002-03-08 22:23:04 +00:00
parent 416331f4d1
commit c58e5d7afd
8 changed files with 180 additions and 28 deletions

View File

@@ -12,8 +12,6 @@
#include "mhmsgwnd.h"
#include "mhmap.h"
#define MAX_LOADSTRING 100
typedef struct mswin_nethack_main_window {
int mapAcsiiModeSave;
} NHMainWindow, *PNHMainWindow;
@@ -125,9 +123,6 @@ numpad[KEY_LAST][3] = {
{'.', ':', ':'} /* Del */
};
static const unsigned char alt_commands[] = "acdeijlnNopqrstuvw?2";
/* original: "acdefijlmnNopqrstuvw?2"; */
#define STATEON(x) ((GetKeyState(x) & 0xFFFE) != 0)
#define KEYTABLE(x) ((iflags.num_pad ? numpad : keypad)[x] \
[(STATEON(VK_SHIFT) ? 1 : STATEON(VK_CONTROL) ? 2 : 0)])
@@ -366,24 +361,21 @@ LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar
} /* end switch */
} break;
case WM_SYSKEYDOWN:
{
/* see if this is something we need */
WORD c;
BYTE kbd_state[256];
c = 0;
ZeroMemory(kbd_state, sizeof(kbd_state));
GetKeyboardState(kbd_state);
if( ToAscii( wParam, (lParam>>16)&0xFF, kbd_state, &c, 0) &&
index(alt_commands, c&0xFF) ) {
NHEVENT_KBD( M(c&0xFF) );
case WM_SYSCHAR: /* Alt-char pressed */
{
/*
If not nethackmode, don't handle Alt-keys here.
If no Alt-key pressed it can never be an extended command
*/
if (GetNHApp()->regNetHackMode && (lParam & 1<<29))
{
unsigned char c = (unsigned char)(wParam & 0xFF);
NHEVENT_KBD(M(c));
return 0;
} else {
return DefWindowProc(hWnd, message, wParam, lParam);
}
} break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_COMMAND:
/* process commands - menu commands mostly */
@@ -687,6 +679,21 @@ LRESULT onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
}
break;
case IDM_NHMODE:
{
GetNHApp()->regNetHackMode = GetNHApp()->regNetHackMode ? 0 : 1;
mswin_menu_check_intf_mode();
break;
}
case IDM_CLEARSETTINGS:
{
mswin_destroy_reg();
/* Notify the user that windows settings will not be saved this time. */
MessageBox(GetNHApp()->hMainWnd,
"Your Windows Settings will not be stored when you exit this time.",
"NetHack", MB_OK | MB_ICONINFORMATION);
break;
}
case IDM_HELP_LONG:
display_file(HELP, TRUE);
break;
@@ -783,6 +790,17 @@ LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
return FALSE;
}
void mswin_menu_check_intf_mode()
{
HMENU hMenu = GetMenu(GetNHApp()->hMainWnd);
if (GetNHApp()->regNetHackMode)
CheckMenuItem(hMenu, IDM_NHMODE, MF_CHECKED);
else
CheckMenuItem(hMenu, IDM_NHMODE, MF_UNCHECKED);
}
void mswin_select_map_mode(int mode)
{
PNHMainWindow data;

View File

@@ -11,5 +11,6 @@
HWND mswin_init_main_window (void);
void mswin_layout_main_window(HWND changed_child);
void mswin_select_map_mode(int map_mode);
void mswin_menu_check_intf_mode();
#endif /* MSWINMainWindow_h */

View File

@@ -229,6 +229,8 @@ BOOL CALLBACK MenuWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
PNHMenuWindow data;
HWND control;
HDC hdc;
TCHAR title[MAX_LOADSTRING];
data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA);
switch (message)
@@ -254,6 +256,11 @@ BOOL CALLBACK MenuWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
/* subclass edit control */
editControlWndProc = (WNDPROC)GetWindowLong(control, GWL_WNDPROC);
SetWindowLong(control, GWL_WNDPROC, (LONG)NHMenuTextWndProc);
/* Even though the dialog has no caption, you can still set the title
which shows on Alt-Tab */
LoadString(GetNHApp()->hApp, IDS_APP_TITLE, title, MAX_LOADSTRING);
SetWindowText(hWnd, title);
break;
case WM_MSNH_COMMAND:

View File

@@ -80,6 +80,7 @@ BOOL CALLBACK NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara
HWND control;
HDC hdc;
PNHTextWindow data;
TCHAR title[MAX_LOADSTRING];
data = (PNHTextWindow)GetWindowLong(hWnd, GWL_USERDATA);
switch (message)
@@ -100,6 +101,11 @@ BOOL CALLBACK NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara
SetWindowLong(control, GWL_WNDPROC, (LONG)NHEditHookWndProc);
SetFocus(control);
/* Even though the dialog has no caption, you can still set the title
which shows on Alt-Tab */
LoadString(GetNHApp()->hApp, IDS_APP_TITLE, title, MAX_LOADSTRING);
SetWindowText(hWnd, title);
return FALSE;
case WM_MSNH_COMMAND:

View File

@@ -123,7 +123,13 @@ void mswin_init_nhwindows(int* argc, char** argv)
#endif
mswin_nh_input_init();
/* check default values */
/* Read Windows settings from the reqistry */
mswin_read_reg();
/* Set menu check mark for interface mode */
mswin_menu_check_intf_mode();
/* check default values */
if( iflags.wc_fontsiz_status<NHFONT_SIZE_MIN ||
iflags.wc_fontsiz_status>NHFONT_SIZE_MAX )
iflags.wc_fontsiz_status = NHFONT_DEFAULT_SIZE;
@@ -268,6 +274,8 @@ void mswin_get_nh_event(void)
void mswin_exit_nhwindows(const char *str)
{
logDebug("mswin_exit_nhwindows(%s)\n", str);
/* Write Window settings to the registry */
mswin_write_reg();
}
/* Prepare the window to be suspended. */
@@ -1399,3 +1407,98 @@ logDebug(const char *fmt, ...)
}
#endif
/* Reading and writing settings from the registry. */
#define CATEGORYKEY "Software"
#define COMPANYKEY "NetHack"
#define PRODUCTKEY "NetHack 3.4.0"
#define SETTINGSKEY "Settings"
/* #define all the subkeys here */
#define INTFKEY "Interface"
void
mswin_read_reg()
{
HKEY key;
DWORD size;
char keystring[MAX_PATH];
sprintf(keystring, "%s\\%s\\%s\\%s",
CATEGORYKEY, COMPANYKEY, PRODUCTKEY, SETTINGSKEY);
/* Set the defaults here. The very first time the app is started, nothing is
read from the registry, so these defaults apply. */
GetNHApp()->saveRegistrySettings = 1; /* Normally, we always save */
GetNHApp()->regNetHackMode = 0;
if (RegOpenKeyEx(HKEY_CURRENT_USER, keystring, 0, KEY_READ, &key)
!= ERROR_SUCCESS)
return;
/* Read the keys here. */
size = sizeof(DWORD);
RegQueryValueEx(key, INTFKEY, 0, NULL,
(unsigned char *)(&(GetNHApp()->regNetHackMode)), &size);
RegCloseKey(key);
}
void
mswin_write_reg()
{
HKEY key;
DWORD disposition;
if (GetNHApp()->saveRegistrySettings)
{
char keystring[MAX_PATH];
sprintf(keystring, "%s\\%s\\%s\\%s",
CATEGORYKEY, COMPANYKEY, PRODUCTKEY, SETTINGSKEY);
if (RegOpenKeyEx(HKEY_CURRENT_USER, keystring, 0, KEY_WRITE, &key) != ERROR_SUCCESS)
{
RegCreateKeyEx(HKEY_CURRENT_USER, keystring, 0, "",
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, &disposition);
}
/* Write the keys here */
RegSetValueEx(key, INTFKEY, 0, REG_DWORD, (unsigned char *)(&(GetNHApp()->regNetHackMode)), sizeof(DWORD));
RegCloseKey(key);
}
}
void
mswin_destroy_reg()
{
char keystring[MAX_PATH];
HKEY key;
DWORD nrsubkeys;
/* Delete keys one by one, as NT does not delete trees */
sprintf(keystring, "%s\\%s\\%s\\%s",
CATEGORYKEY, COMPANYKEY, PRODUCTKEY, SETTINGSKEY);
RegDeleteKey(HKEY_CURRENT_USER, keystring);
sprintf(keystring, "%s\\%s\\%s",
CATEGORYKEY, COMPANYKEY, PRODUCTKEY);
RegDeleteKey(HKEY_CURRENT_USER, keystring);
/* The company key will also contain information about newer versions
of nethack (e.g. a subkey called NetHack 4.0), so only delete that
if it's empty now. */
sprintf(keystring, "%s\\%s", CATEGORYKEY, COMPANYKEY);
/* If we cannot open it, we probably cannot delete it either... Just
go on and see what happens. */
RegOpenKeyEx(HKEY_CURRENT_USER, keystring, 0, KEY_READ, &key);
nrsubkeys = 0;
RegQueryInfoKey(key, NULL, NULL, NULL, &nrsubkeys, NULL, NULL, NULL,
NULL, NULL, NULL, NULL);
RegCloseKey(key);
if (nrsubkeys == 0)
RegDeleteKey(HKEY_CURRENT_USER, keystring);
/* Prevent saving on exit */
GetNHApp()->saveRegistrySettings = 0;
}

View File

@@ -25,9 +25,9 @@
#define IDB_PETMARK 143
#define IDB_MENU_SEL_COUNT 144
#define IDD_NHRIP 145
#define IDB_SPLASH 146
#define IDB_RIP 147
#define IDD_SPLASH 148
#define IDB_SPLASH 146
#define IDB_RIP 147
#define IDD_SPLASH 148
#define IDC_TEXT_VIEW 1000
#define IDC_TEXT_CONTROL 1000
#define IDC_CMD_MOVE_NW 1001
@@ -132,6 +132,8 @@
#define IDM_MAP_ASCII12X16 32789
#define IDM_MAP_ASCII10X18 32790
#define IDM_MAP_FIT_TO_SCREEN 32791
#define IDM_NHMODE 32793
#define IDM_CLEARSETTINGS 32794
#define IDC_STATIC -1
// Next default values for new objects
@@ -139,7 +141,7 @@
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 145
#define _APS_NEXT_COMMAND_VALUE 32793
#define _APS_NEXT_COMMAND_VALUE 32795
#define _APS_NEXT_CONTROL_VALUE 1331
#define _APS_NEXT_SYMED_VALUE 110
#endif

View File

@@ -33,6 +33,8 @@
#define NHFONT_SIZE_MIN 3
#define NHFONT_SIZE_MAX 20
#define MAX_LOADSTRING 100
typedef struct mswin_nhwindow_data {
HWND win;
int type;
@@ -62,6 +64,9 @@ typedef struct mswin_nhwindow_app {
int mapDisplayModeSave; /* saved map display mode */
char* saved_text;
DWORD saveRegistrySettings; /* Flag if we should save this time */
DWORD regNetHackMode; /* NetHack mode means no Windows keys in some places */
} NHWinApp, *PNHWinApp;
#define E extern
@@ -129,6 +134,10 @@ void nhapply_image_transparent(
COLORREF cTransparent
);
void mswin_read_reg();
void mswin_destroy_reg();
void mswin_write_reg();
/* unicode stuff */
#ifdef UNICODE
#define NH_W2A(w, a, cb) ( WideCharToMultiByte( \

View File

@@ -64,6 +64,12 @@ BEGIN
MENUITEM SEPARATOR
MENUITEM "&Fit To Screen ", IDM_MAP_FIT_TO_SCREEN
END
POPUP "Windows &Settings"
BEGIN
MENUITEM "NetHack Mode", IDM_NHMODE
MENUITEM SEPARATOR
MENUITEM "&Clear All Settings", IDM_CLEARSETTINGS
END
POPUP "&Help"
BEGIN
MENUITEM "&About ...", IDM_ABOUT
@@ -240,7 +246,7 @@ IDB_MENU_UNSEL BITMAP DISCARDABLE "mnunsel.bmp"
IDB_PETMARK BITMAP DISCARDABLE "petmark.bmp"
IDB_MENU_SEL_COUNT BITMAP DISCARDABLE "mnselcnt.bmp"
IDB_RIP BITMAP DISCARDABLE "rip.bmp"
IDB_SPLASH BITMAP DISCARDABLE "splash.bmp"
IDB_SPLASH BITMAP DISCARDABLE "splash.bmp"
/////////////////////////////////////////////////////////////////////////////
//