I am having trouble getting Accelerators to work. I am using C++.
After my window is setup and shown.
MENUITEMINFOW mAbout;
mAbout.cbSize = sizeof(MENUITEMINFO);
mAbout.fMask = MIIM_TYPE | MIIM_ID;
mAbout.wID = (UINT) ID_ABOUT;
mAbout.fType = MFT_STRING;
mAbout.dwTypeData = (LPWSTR)L"&About";
InsertMenuItemW(HelpMenu, 0, TRUE, &mAbout);
My menu is working just fine, and calls my "About" box, no issue there.
Now, before the message loop, I load the accelerators:
// Load accelerators.
HACCEL hAccelerators = LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(IDR_ACCELERATOR));
Then my main message loop:
while(GetMessageW(&msg, NULL, 0, 0) > 0) {
if (! TranslateAcceleratorW(msg.hwnd, hAccelerators, &msg)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
My WndProc Message handle (Again, works from the menu)
case WM_COMMAND: {
if (HIWORD(wParam) == 0) {
if (LOWORD(wParam) == 101) {
testDialog(hInstance ,hWnd,(LPSTR)"Testing");
}
if (LOWORD(wParam) == ID_ABOUT) {
DialogBox(hInstance, MAKEINTRESOURCE(IDD_ABOUTDIALOG), hWnd, &AboutDialogProc);
return 0;
}
}
break;
}
My resource.rc file:
//
// Accelerator resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDR_ACCELERATOR ACCELERATORS
{
"a", ID_ABOUT, VIRTKEY, ALT
}
and my resource.h file:
#define IDR_ACCELERATOR 122
#define ID_ABOUT 401
And... well, Alt-a does not bring up the about box. I have walked all over the Microsoft Website, and was vary careful, but I can't find anything glaring I am doing different.
I am on Windows 7 (64bit) using MinGW and compiling in the application for Unicode.
Everything else works but this, what am I missing???
Found it!
From: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646373(v=vs.85).aspx
This was the issue, I was checking wParam for a value of 0, I didn't catch that it is
1
if sent byTranslateAcceleratorW
Geeze, that was a tiny detail.