Catching ActiveX events within another ActiveX control

Posted on 1998-12-31
Last Modified: 2013-11-20
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.)



Question by:dave81
  • 2

Accepted Solution

murrayc earned 100 total points
ID: 1327073
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()


Author Comment

ID: 1327074
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?

Expert Comment

ID: 1327075
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.

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Creating Browser addons to execute actions on the local PC 4 25
maxBlock challenge 30 142
canBalance challenge 34 98
scoreUp challenge 14 64
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question