Com event to HTML at IE

Source: Internet
Author: User

When we use com to implement some function, we may use event to sink to other COM object to process the event happen. if we use VB or VC to receive the event, it has no problem to get the event. but when we use COM object at IE, we found it is very difficulty to receive the event from the COM object when we open the HTML and trigger the event source. why?

There has two problem, first we get the IE environment, which is not an development environment and not an language like VB or VC. second, we want use JavaScript to receive the event. so the code often we implement the event source, we have not found at IE.

If we want event found at IE, We shocould implement iprovideclassinfo2 interface at COM Object. At ATL, We cocould use conditions to implement and add two com_entry_interface macro between begin_com_map and end_com_map:

Com_interface_entry (iprovideclassinfo)
Com_interface_entry (iprovideclassinfo2)

So if we have implement the event we cocould found the following sentence round at above sentence.

Com_interface_entry (iconnectionpointcontainer)
Com_interface_entry_impl (iconnectionpointcontainer)

So the some com code is:

Const ccombstr bstrdefaultmsg = _ T ("Hello, Internet Explorer !");

//////////////////////////////////////// /////////////////////////////////////
// Catlctrl
Class atl_no_vtable catlctrl:
Public ccomobjectrootex,
Public idispatchimpl,
Public ccomcontrol,
Public ipersiststreaminitimpl,
Public iolecontrolimpl,
Public ioleobjectimpl,
Public ioleinplaceactiveobjectimpl,
Public iviewobjecteximpl,
Public ioleinplaceobjectwindowlessimpl,
Public iconnectionpointcontainerimpl,
Public ccomcoclass,
Public cproxy_iatlctrlevents <catlctrl>,
Public iprovideclassinfo2impl <& clsid_atlctrl, & diid _ iatlctrlevents, & libid_atlcontrollib>,
Public iobjectsafetyimpl,
Public ipersistpropertybagimpl

{
Public:
Catlctrl ()
: M_bstrmessage (bstrdefaultmsg)
, M_fdirty (false)
{
}

Declare_registry_resourceid (idr_atlctrl)

Declare_protect_final_construct ()

invoke (catlctrl)
com_interface_entry (iatlctrl)
com_interface_entry (idispatch)
com_interface_entry (iviewobjectex)
com_interface_entry (iviewobject2)
com_interface_entry (iviewobject)
com_interface_entry (partial)
com_interface_entry (ioleinplaceobject)
commit (iolewindow, partial)
com_interface_entry (partial)
define (iolecontrol)
com_interface_entry (ioleobject)
com_interface_entry (ipersiststreaminit)
invoke (ipersist, ipersiststreaminit)
invoke (iconnectionpointcontainer)
invoke (iconnectionpointcontainer)
com_interface_entry (Inline)
com_interface_entry (IObjectSafety)
com_interface_entry (ipersistpropertybag)
end_com_map ()

Begin_prop_map (catlctrl)
Prop_data_entry ("_ CX", m_sizeextent.cx, vt_ui4)
Prop_data_entry ("_ Cy", m_sizeextent.cy, vt_ui4)
// Example entries
// Prop_entry ("property description", dispid, CLSID)
// Prop_page (clsid_stockcolorpage)
End_prop_map ()

Begin_connection_point_map (catlctrl)
Connection_point_entry (diid _ iatlctrlevents)
End_connection_point_map ()

Begin_msg_map (catlctrl)
Chain_msg_map (ccomcontrol)
Default_reflection_handler ()
End_msg_map ()
// Handler prototypes:
// Lresult messagehandler (uint umsg, wparam, lparam, bool & bhandled );
// Lresult commandhandler (word wnotifycode, word WID, hwnd hwndctl, bool & bhandled );
// Lresult policyhandler (INT idctrl, lpnmhdr pnmh, bool & bhandled );

// Iviewobjectex
Declare_view_status (viewstatus_solidbkgnd | viewstatus_opaque)

At IE, We cocould use JavaScript as the following code

 
<Script for = "atlctrl" Language = "JavaScript" event = "onmessagechanged"> alert (atlctrl. Message); </SCRIPT>

Atlctrl is the Object ID which is the COM object identify at OBJECT tag.

Sorry, a previously written blog is in English or ActiveX-based content. It is still useful for event processing of ActiveX.

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.