DOCUMENT:Q199431 27-MAR-2002 [visualc] TITLE :PRB: Enabling Menu Mnemonics in an MFC ActiveX Control PRODUCT :Microsoft C Compiler PROD/VER::5.0,6.0 OPER/SYS: KEYWORDS:kbActiveX kbCOMt kbContainer kbCtrlCreate kbKeyAccel kbMFC kbVC500 kbVC600 kbDSupport k ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - The Microsoft Foundation Classes (MFC), included with: - Microsoft Visual C++, 32-bit Enterprise Edition, versions 5.0, 6.0 - Microsoft Visual C++, 32-bit Professional Edition, versions 5.0, 6.0 - Microsoft Visual C++, 32-bit Learning Edition, version 6.0 - Microsoft Visual C++.NET (2002) ------------------------------------------------------------------------------- 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. 1. Use ClassWizard to override the PreTranslateMessage function for the control. 2. 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. MORE INFORMATION ================ Steps to reproduce behavior --------------------------- 1. Build and register the MFC Button sample. 2. Run the ActiveX Test Container utility. You can find this from tool on the Tools menu inside of Microsoft Visual C++. Insert the Button control into the ActiveX Test Container. Note the container's menus have changed. 3. Type "ALT+H" (without the quotation marks) to drop down the Help menu. 4. Type "A" (without the quotation marks) to invoke the control's about box. Note that nothing happens. However, when you select the menu item using the mouse, the control's about box is properly displayed. 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. Q104460 PRB: Menu Mnemonics Not Working During In-Place Activation. Additional query words: PreTranslateMessage TranslateAccelerator keyboard ====================================================================== Keywords : kbActiveX kbCOMt kbContainer kbCtrlCreate kbKeyAccel kbMFC kbVC500 kbVC600 kbDSupport kbGrpDSMFCATL kbAcceleratorKey Technology : kbAudDeveloper kbMFC kbVCNET Version : :5.0,6.0 Issue type : kbprb ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2002.