How to handle the mouse and keyboard events of ActiveX controls in a browser

Source: Internet
Author: User

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;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.