Article ID: 199431
Article Last Modified on 3/27/2002
APPLIES TO
- Microsoft Foundation Class Library 4.2, when used with:
- Microsoft Visual C++ 5.0 Enterprise Edition
- Microsoft Visual C++ 6.0 Enterprise Edition
- Microsoft Visual C++ 5.0 Professional Edition
- Microsoft Visual C++ 6.0 Professional Edition
- Microsoft Visual C++ 6.0 Standard Edition
- Microsoft Visual C++ .NET 2002 Standard Edition
This article was previously published under Q199431
SYMPTOMS
MFC supports the creation of ActiveX controls that can merge a menu resource with its container application though the COleControl::OnGetInPlaceMenu() function, as illustrated by the MFC Button sample. However, you may find that menu items belonging to an MFC ActiveX control cannot be invoked through the keyboard.
CAUSE
The default implementation of an MFC ActiveX control does not give the container application a chance to process menu mnemonics.
RESOLUTION
To work around this problem, you need to give the container an opportunity to translate menu mnemonics by calling the OleTranslateAccelerator() from the control's
PreTranslateMessage() function. You can use the following steps to do this.
- Use ClassWizard to override the PreTranslateMessage function for the control.
- Use the following code in the PreTranslateMessage function:
if (pMsg->message >= WM_KEYFIRST && pMsg->message <= WM_KEYLAST)
if (::OleTranslateAccelerator(m_pInPlaceFrame, &m_frameInfo, pMsg)==S_OK)
return TRUE;
return COleControl::PreTranslateMessage(pMsg);
Adding the earlier function to the
PreTranslateMessage function allows the container to process menu mnemonics and forward the resulting command messages to the control.
STATUS
The MFC implementation at this time does not forward keyboard requests on for menu mnemonics. This is a limitation in the MFC framework that can be worked around with the resolution earlier.
REFERENCES
For additional information concerning handling accelerators and menu mnemonics for in-place active objects, such as ActiveX controls, please consult the following sources of information:
"Inside OLE" - second edition by Kraig Brockschmidt. Microsoft Press. ISBN 1-55615-843-2.
104460 PRB: Menu Mnemonics Not Working During In-Place Activation.
Additional query words: PreTranslateMessage TranslateAccelerator keyboard
Keywords: kbcontainer kbctrlcreate kbkeyaccel kbprb kbacceleratorkey KB199431