timmay3141
Programmer
I posted this in the Visual C++ forum, but I got no replies and it probably belongs here. I've used accelerators in MFC, but I'm new to the Windows API without using MFC. I'm trying to get Ctrl+N to do the same as the menu selection File, New. Here is the message handler used when File, New is pressed (this function is called when WM_COMMAND is sent):
void OnCommand(WPARAM wParam)
{
switch(wParam)
{
case IDM_FILE_NEW:
MessageBox(NULL, "Recieved Message", "adsfa", MB_OK);
}
}
This works fine when I use the menu, and I see a message box as I should. However, when I press Ctrl+N, it doesn't work. I've figured out that the OnCommand function is being called, but not being sent IDM_FILE_NEW as it should be. Here is what I added to the accelerator table:
IDM_FILE_NEW Ctrl + N VIRTKEY
Then, I added this to WinMain:
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_MYACCELERATOR));
I also added this to the message pump (before handling and dispatching the message):
if(TranslateAccelerator(hWnd, hAccelTable, &msg)) continue;
As far as I can figure, this should be sending the WM_COMMAND message, which should then handle it like I pressed File, New. As I said earlier, the OnCommand function is called, but the wParam in the function doesn't equal IDM_FILE_NEW. Since I'm new to Win API, my problem could be something really stupid. Any ideas?
void OnCommand(WPARAM wParam)
{
switch(wParam)
{
case IDM_FILE_NEW:
MessageBox(NULL, "Recieved Message", "adsfa", MB_OK);
}
}
This works fine when I use the menu, and I see a message box as I should. However, when I press Ctrl+N, it doesn't work. I've figured out that the OnCommand function is being called, but not being sent IDM_FILE_NEW as it should be. Here is what I added to the accelerator table:
IDM_FILE_NEW Ctrl + N VIRTKEY
Then, I added this to WinMain:
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_MYACCELERATOR));
I also added this to the message pump (before handling and dispatching the message):
if(TranslateAccelerator(hWnd, hAccelTable, &msg)) continue;
As far as I can figure, this should be sending the WM_COMMAND message, which should then handle it like I pressed File, New. As I said earlier, the OnCommand function is called, but the wParam in the function doesn't equal IDM_FILE_NEW. Since I'm new to Win API, my problem could be something really stupid. Any ideas?