Article ID: 145698 - View products that this article applies to.
This article was previously published under Q145698
Note Microsoft Visual C++ .NET 2002 and Microsoft Visual C++ .NET 2003 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code. Microsoft Visual C++ 2005 supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model.
An accelerator table provided by way of COleControl::OnGetControlInfo that describes an OLE control's mnemonic keys does not work in both MFC 4.0 and Visual Basic 4.0 OLE control containers.
Visual Basic 4.0 and MFC 4.0 provide different mnemonic handling implementations, so they require different accelerator table entries.
Create accelerator table entries that will allow a control's mnemonics to be handled in both a Visual Basic 4.0 and MFC 4.0 OLE control container.
An OLE control overrides the virtual COleControl::OnGetControlInfo method to allow its container to get a description of the control's mnemonic keys. The OnGetControlInfo method returns a filled-out structure of type CONTROLINFO that contains, among other things, a handle to an accelerator table. This accelerator table is used by the container to do checks for mnemonic keys. When the container determines that a control's mnemonic key was pressed, it calls the control's IOleControl::OnMnemonic method. This causes the MFC framework to call the virtual COleControl::OnMnemonic method, which the control can override to do special processing.
The Visual Basic 4.0 and MFC 4.0 OLE control mnemonic handling implementations have different requirements for the entries in the accelerator table returned by way of OnGetControlInfo.
An accelerator key used in an accelerator table is defined by the ACCEL structure. The ACCEL structure has the following definition:
The fVirt member specifies the accelerator flags. This member can be a combination of the following values:
The key member specifies the accelerator key. This member can be either a virtual-key code or an ASCII character code.
Value Meaning --------------------------------------------------------------------- FALT The ALT key must be held down when the accelerator key is pressed. FCONTROL The CTRL key must be held down when the accelerator key is pressed. FNOINVERT Specifies that no top-level menu item is highlighted when the accelerator is used. If this flag is not specified, a top-level menu item will be highlighted, if possible, when the accelerator is used. FSHIFT The SHIFT key must be held down when the accelerator key is pressed. FVIRTKEY The key member specifies a virtual-key code. If this flag is not specified, key is assumed to specify an ASCII character code.
The cmd member specifies the accelerator identifier. This value is placed in the low-order word of the wParam parameter of the WM_COMMAND or WM_SYSCOMMAND message when the accelerator is pressed.
Visual Basic 4.0 has the following requirements for accelerator table entries used for mnemonic handling:
NOTE: Overriding PreTranslateMessage is not necessary if the control is generated with Visual C++ 5.0 or above because OnMnemonic will be called when the control is UI active by way of SendMnemonic in COccManager::IsDialogMessage.
The following sample code shows an overridden OnGetControlInfo, PreTranslateMessage, and OnMnemonic that allow a control's mnemonics to work correctly in both an MFC 4.0 OLE control container as well as a Visual Basic 4.0 container.
Article ID: 145698 - Last Review: November 21, 2006 - Revision: 5.1