-
May 16th, 2003, 10:11 AM
#1
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
-
May 16th, 2003, 10:17 AM
#2
One solution is to override PreTranslateMessage() on all the child windows and reflect the events to the parent window.
Kuphryn
-
May 16th, 2003, 10:32 AM
#3
I could! but I am looking for a way by which I can route the message to MainFrame and it would handle the accelrator and shortcut keys correctly.
For the splitter with panes I think I could possibly when CView has focus handle the message by routing it to the form view
Please suggest a way by which I can route messages to the mainframe sucessfully
-
May 16th, 2003, 10:49 AM
#4
One solution is TranslateAccelerator().
Kuphryn
-
May 16th, 2003, 10:51 AM
#5
Can you see any reason why TranslateAccelrator is not working when I overrode it in PretranslateMessage
Code:
BOOL CColorButton::PreTranslateMessage(MSG* pMsg)
{
if(m_hAccel)
{
if(::TranslateAccelerator(AfxGetMainWnd()->GetSafeHwnd(), m_hAccel, pMsg))
return TRUE;
}
return CButton::PreTranslateMessage(pMsg);
}
-
May 16th, 2003, 01:07 PM
#6
How is m_hAccel initialized?
Kuphryn
-
April 20th, 2004, 03:56 PM
#7
I initialize m_hAccel like this
m_hAccel = ::LoadAccelerators(AfxGetResourceHandle(),
MAKEINTRESOURCE( IDR_MAINFRAME ) );
if (!m_hAccel)
MessageBox("The accelerator table was not loaded");
Still the menu does not get activated when the ALT key + F ( file menu should activate )
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|