Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Catching ActiveX events within another ActiveX control

Posted on 1998-12-31
Medium Priority
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 200 total points
ID: 1327073
Here is an appropriate excerpt from one of my web pages at http://www.geocities.com/SiliconValley/Bay/1283/learning/windows/useactivex.html

*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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.

578 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