Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 393
  • Last Modified:

Catching ActiveX events within another ActiveX control

Hi there-

I need some basic help on the following problem.  I'd like to have two
ActiveX controls on a web page.  Each control has methods and events that
are exposed, and everything works fine.  I can integrate the controls via
VBScript with no problems.  However, I'd like to be able to operate on the
controls directly, rather than rely on scripting.  So, I'd like to be able
to catch events fired by one control directly within another.  I know I need
an event sink, or a connection point, but I'd really appreciate some sample
code that does this.  Anyone have any pointers?

(I've seen the MSDN article which shows how to do this with non-ActiveX
controls--I don't think it works within a browser, though.)



  • 2
1 Solution
Here is an appropriate excerpt from one of my web pages at

*Responding to ActiveX Events*

The Classwizard Message Maps tab helps you to easily add handlers for the events fired by ActiveX controls if you have placed one of those controls on a dialog resource. However, most useful ActiveX controls will create and position their child controls dynamically so ClassWizard will not be able to detect them. We must therefore resort to entering the macros ourselves. Remember that if you're not sure what the macro should look like for your particular control, you can put an ActiveX control on a dialog and create a Message Map for its events. Just be careful to remove the entries after you have used them to see the form they should take.

Firstly, create an IDR resource symbol for your control. Use View | View Resource Symbols. You should use this resource symbol when creating the control wrapper.


m_SubSectionWrapper.Create( _T("SUB"), WS_CHILD | WS_VISIBLE, tempRect, this, IDR_SUBSECTION);

MFC controls capture ActiveX Events by using an 'Events Sink' which is basically just an extension of the regular message map. You must declare the Events Sink map inside the regular message map declarations in the declaration (.h) file. e.g.

// Message maps
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);

Add the Event Sinks Map near the start of the definition (.cpp) file, before the regular BEGIN_MESSAGE_MAP section, as follows:

BEGIN_EVENTSINK_MAP(CSubContainerCtrl, COleControl)
     ON_EVENT(CSubContainerCtrl, IDR_SUBSECTION, 1 /* ResizeControls */, OnResizeColumns, VTS_NONE)

The BEGIN_EVENTSINK_MAP macro takes the container's Class name, then the base class name as parameters. The container's class name is used again in the AFX_EVENTSINK_MAP macro and the ON_EVENT macro.

The ON_EVENT macro needs the ID number of the ActiveX Event, which you can get from the ODL file, the OLE/COM Object viewer, or by creating an example handler using the classwizard as mentioned above. The final parameter is a space-separated list of parameter types for the event. Again, if you are not sure which types to use here, you could create an example using a dialog and the classwizard.

Next, declare the handler in the declaration (.h) file.

      afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
      afx_msg void OnResizeColumns();
Then just write the definition for your handler. e.g.

void CSubContainerCtrl::OnResizeColumns()

dave81Author Commented:
Murrayc -- Thanks for the answer -- however, my question has to do with activex controls that are not on the same dialog.  That is, I have two activex controls that are on separate panes.  Therefore, there's no Child ID to map to the activex control in the event sink.  Any ideas on this?
Then I don't see anything particularly ActiveX about the problem. I would suggest that you coordinate the two ActiveX controls from a common parent. Maybe you should rephrase the question in terms of normal control messaging and repost.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now