To correctly handle mouse and keyboard events in a browser, ActiveX Control developers can refer to Chapter 12th of "com Principles and Applications" by Pan aimin. The system describes the keyboard interaction principle between ActiveX controls and container programs.
1. perform on-site activation when the control is first loaded. If the simple control ccomcontrol is based on ATL, you can add it in oncreate. If the Atl-based Composite Control ccomcompositecontrol, you can add it in oninitdialog.
// Activate control in Web browser immediately
Inplaceactivate (oleiverb_uiactivate );
2. When the mouse clicks the control, the field should be activated. This mainly responds to the wm_mouseactivate event.
Lresult onmouseactivate (uint/* umsg */, wparam/* wparam */, lparam/* lparam */, bool &/* bhandled */)
{
// Activate control in Web browser immediately
Inplaceactivate (oleiverb_uiactivate );
Return 0;
}
3. Then, you can implement feature keyboard event processing in translateaccelerator.
//Ioleinplaceactiveobject: translateaccelerator ()
Stdmethod (translateaccelerator) (MSG * PMSG)
{
If (
(PMSG-> message >=wm_keyfirst )&&
(PMSG-> message <= wm_keylast ))
&&
(PMSG-> wparam = vk_tab) |
(PMSG-> wparam = vk_return ))
)
{
Ccomqiptr <iolecontrolsite, & iid_iolecontrolsite>
Spctrlsite (m_spclientsite );
If (spctrlsite)
{
Return spctrlsite-> translateaccelerator (PMSG, 0 );
}
}
Return s_false;
}
The above code processes the tab and enter keys in the edit box of the subwindow. If you need to process up arrow, down arrow, page up, and page down, you can use the following example:
If (PMSG-> wparam = vk_up) |
(PMSG-> wparam = vk_down) |
(PMSG-> wparam = vk_left) |
(PMSG-> wparam = vk_right ))
{
: Isdialogmessage (m_hwnd, PMSG );
Return s_ OK;
}
If the Active X control has a scroll bar, you need to process vk_up and vk_down, as shown in the following example:
If (PMSG-> wparam = vk_up)
{
: Sendmessage (m_hwnd, wm_vscroll,
Sb_lineup, makelong (0, m_hwnd ));
Return s_false;
}
Processing of the default button: When you press enter, you should allow the focus to be transferred to the default button (if a button is set to "default"), then you need to implementIolecontrol: getcontrolinfo ()To accept the enter and ESC keys, which is implemented by default by ATL.Iolecontrolimpl: getcontrolinfo ()Returns e_notimpl. You need to overwrite it:
Hresult stdmethodcalltype getcontrolinfo (controlinfo * PCI)
{
If (! PCI)
{
Return e_pointer;
}
PCI-> haccel = NULL; // load your accelerators here, if any
PCI-> caccel = 0;
PCI-> dwflags = 0;
Return s_ OK;
}