Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accelerator problem

Status
Not open for further replies.

timmay3141

Programmer
Dec 3, 2002
468
US
I'm trying to figure out how to use accelerator tables without MFC. I'm trying to get Ctrl+N to do the same as the menu selection File, New. Here is the handler of the menu item:

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. The problem is using the accelerator to handle messages. I put this in the accelerator resource table:

IDM_FILE_NEW Ctrl + N VIRTKEY

I added this to WinMain:

HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_MYACCELERATOR));

I added this to the message pump:

if(TranslateAccelerator(hWnd, hAccelTable, &msg)) continue;

From what I read, this should be sending the WM_COMMAND message, which should then handle it like a File, New. The OnCommand function is called, but the wParam in the function doesn't equal IDM_FILE_NEW. Any ideas?
 
i'm not sure if this wil help but, i'm working in a dialog based app now and allso work with accell keys, but as follows:

BOOL CKassaDlg::preTranslateMessage(MSG* pMsg)
{
switch(pMsg->message)
{ case WM_KEYDOWN: switch(pMsg->wParam)
{ case VK_ESCAPE: OnButtonsluiten();
return TRUE;
case VK_F4: ArtikelGeefAantal();
return TRUE;
case VK_F5: OnButtonTotaal();
return TRUE;
case VK_F6: OnButtonnieuwart();
return TRUE;
case VK_F7: OnButtoneditart();
return TRUE;
case VK_F8: OnButtonleveringen();
return TRUE;


case VK_DELETE: ArtikelDelete();
return TRUE;
case VK_ADD: ArtikelPlus();
return TRUE;
case VK_RIGHT: ArtikelPlus();
return TRUE;
case VK_SUBTRACT: ArtikelMin();
return TRUE;
case VK_LEFT: ArtikelMin();
return TRUE;
}

}
return CDialog::preTranslateMessage(pMsg);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top