Make menu accelerator keys work on Windows

This commit is contained in:
2015-02-14 15:21:26 -05:00
parent 7ba874f1d2
commit d977a0f457
7 changed files with 156 additions and 3 deletions

View File

@@ -10,6 +10,7 @@
#include "boe.consts.h"
#include "spell.hpp"
#include "winutil.hpp"
#include "menu_accel.win.hpp"
// Include this last because some #defines in the Windows headers cause compile errors in my headers.
// Fortunately they're on symbols not used in this file, so this should work.
@@ -38,17 +39,29 @@ extern eGameMode overall_mode;
extern sf::RenderWindow mainPtr;
LONG_PTR mainProc;
HMENU menuHandle = NULL;
accel_table_t accel;
std::map<int,eMenu> menuChoices;
LRESULT CALLBACK menuProc(HWND handle, UINT message, WPARAM wParam, LPARAM lParam);
void setMenuCommand(HMENU& menu, int i, eMenu cmd) {
static char title[256];
MENUITEMINFOA item;
item.cbSize = sizeof(MENUITEMINFOA);
item.fMask = MIIM_ID | MIIM_FTYPE;
item.cch = 255;
item.dwTypeData = title;
item.fMask = MIIM_ID | MIIM_FTYPE | MIIM_STRING;
GetMenuItemInfoA(menu, i++, true, &item);
if(item.fType == MFT_SEPARATOR) return;
menuChoices[item.wID] = cmd;
// Now set up the accelerator, if any
std::string item_name = item.dwTypeData;
size_t pos = item_name.find_last_of('\t');
if(pos == std::string::npos) return;
pos++;
if(pos >= item_name.size()) return;
std::string key_name = item_name.substr(pos);
accel.add(item.wID, key_name);
}
void init_menubar() {
@@ -117,6 +130,8 @@ void init_menubar() {
menuChoices[IDM_MAGE_ABOUT] = eMenu::ABOUT_MAGE;
menuChoices[IDM_PRIEST_ABOUT] = eMenu::ABOUT_PRIEST;
menuChoices[IDM_MONSTERS_ABOUT] = eMenu::ABOUT_MONSTERS;
accel.build();
}
void adjust_monst_menu() {
@@ -275,6 +290,11 @@ void showMenuBar() {
#include "cursors.hpp"
LRESULT CALLBACK menuProc(HWND handle, UINT message, WPARAM wParam, LPARAM lParam) {
MSG msg = {handle, message, wParam, lParam};
if(HIWORD(wParam) != 1 || message != WM_COMMAND) {
if(TranslateAccelerator(handle, accel.handle, &msg))
return 0;
}
if(message == WM_COMMAND) {
int cmd = LOWORD(wParam);
if(cmd >= 1000 && cmd < 2000) {