Accelrator keys not working
Accelrator keys do not work if the focus is on a button that is placed on the toolbar.
I can catch all the accelrator events via PreTranslateMesage of the main frame like below and handle them individually but that seems like more work and bad design.
Code:
// Handle CTRL + I
if (pMsg->message == WM_KEYDOWN && GetAsyncKeyState(VK_CONTROL) < 0 && (pMsg->wParam == 'i' || pMsg->wParam == 'I'))
// Export to Image File trap
ExportToImageFile();
//Handle ALT+S
if (pMsg->message == WM_SYSKEYDOWN && GetKeyState(VK_MENU) < 0 && (pMsg->wParam == 's' || pMsg->wParam == 'S'))
// Enter Setup
Setup();
//Handle ALT + R
if (pMsg->message == WM_SYSKEYDOWN && GetAsyncKeyState(VK_MENU) < 0 && (pMsg->wParam == 'r' || pMsg->wParam == 'R'))
// Enter Run
Run();
First issue:
On the toolbar are three buttons and when these buttons get the focus ( like the user clicked on them) then it seems like the messages are routed to CButton but not to the mainframe.
I overrode the pretranslate message of the Buttons class like this
Code:
BOOL CColorButton::PreTranslateMessage(MSG* pMsg)
{
if(m_hAccel)
{
if(::TranslateAccelerator(AfxGetMainWnd()->GetSafeHwnd(), m_hAccel, pMsg))
return TRUE;
}
return CButton::PreTranslateMessage(pMsg);
}
But still the accelrator keys do not work.
Second issue:
We have two views seperated by a splitter. The right side view is derived from a CView and the left side view is derived from a formview. If the CView has focus then the Shortcut keys like ALT + M etc present on CFormView do not work. They work perfectly if the focus is on the CFormview. So here there are two cases when the keyboard shotcuts don't work.. if the focus is on the toolbar buttons(custom) or the focus is on the CView pane.
Any suggestions on overcoming this issue will be greatly appriciated