PRB: Focus and Tab Issues with ATL Subclassed Edit ControlLast reviewed: February 16, 1998Article ID: Q179696 |
The information in this article applies to:
SYMPTOMSIf you use the ATL Wizards to create an ActiveX control that subclasses the Edit common control, you may see one or both of the following problems depending on where you use the control:
CAUSEWhen an ATL-based ActiveX control subclasses a Windows common control, it creates a contained window object to subclass the control. When you use the TAB key to move around an application, the ActiveX control window gets the focus but never shifts the focus to the Edit window within the ActiveX control. As a result, you must click the Edit control to activate it. The second issue results from the way an ATL-based control and its ActiveX control container handle messages. Because of the way some control containers handle messages, they do not get the opportunity to process the TAB keystroke, even if the control itself does not process it.
RESOLUTIONTo activate the ATL-based ActiveX Edit control with the TAB key, you can override the OnSetFocus method and set the focus to the contained Edit window before returning. To use the TAB key to shift the focus away from the ATL-based control, you can override the TranslateAccelerator method. If the message is WM_KEYDOWN and the key is the TAB key, give the IOleControlSite TranslateAccelerator a chance to process the message first.
STATUSMicrosoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATIONTo work around these issues, add the following code to your ATL-based control class:
Sample Code
typedef enum tagKEYMODIFIERS { KEYMOD_NONE = 0X00000000, KEYMOD_SHIFT = 0x00000001, KEYMOD_CONTROL = 0x00000002, KEYMOD_ALT = 0x00000004 } KEYMODIFIERS; class ATL_NO_VTABLE Csc_ctrl2 : ... { ... LRESULT OnSetFocus(UINT /* nMsg */, WPARAM /* wParam */, LPARAM /* lParam */, BOOL& /* bHandled */) { CComQIPtr <IOleControlSite, &IID_IOleControlSite> spSite(m_spClientSite); if (m_bInPlaceActive && spSite) spSite->OnFocus(TRUE); ::SetFocus(m_ctlEdit.m_hWnd); return 0; } STDMETHOD(TranslateAccelerator)(LPMSG lpmsg) { CComQIPtr<IOleControlSite,&IID_IOleControlSite> spCtrlSite(m_spClientSite); if (spCtrlSite) { if ((lpmsg->message == WM_KEYDOWN) && (LOWORD(lpmsg->wParam) == VK_TAB)) { DWORD keymods = 0; keymods += (GetKeyState(VK_SHIFT) < 0) ? KEYMOD_SHIFT : KEYMOD_NONE; keymods += (GetKeyState(VK_CONTROL) < 0) ? KEYMOD_CONTROL : KEYMOD_NONE; keymods += (GetKeyState(VK_MENU) < 0) ? KEYMOD_ALT : KEYMOD_NONE; return spCtrlSite->TranslateAccelerator(lpmsg,keymods); } } return S_FALSE; } ... }; Steps to Reproduce Behavior
REFERENCESFor additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q169434 TITLE : BETA-PRB: Tabbing Broken for ATL Controls in IE 4.0(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Shawn William Karr, Microsoft Corporation
|
Additional query words: 5.00 Visual Studio C++ Basic
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |