Solved

Catching ActiveX events within another ActiveX control

Posted on 1998-12-31
3
374 Views
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.)

Thanks.

-dave
drodger@mediaone.net

0
Comment
Question by:dave81
  • 2
3 Comments
 

Accepted Solution

by:
murrayc earned 100 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.

e.g.

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(CSubSectionCtrl)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
DECLARE_EVENTSINK_MAP()
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

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)
     //{{AFX_EVENTSINK_MAP(CSubContainerCtrl)
     ON_EVENT(CSubContainerCtrl, IDR_SUBSECTION, 1 /* ResizeControls */, OnResizeColumns, VTS_NONE)
     //}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

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(CSubSectionCtrl)
      afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
      afx_msg void OnResizeColumns();
      DECLARE_EVENTSINK_MAP()
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
Then just write the definition for your handler. e.g.

void CSubContainerCtrl::OnResizeColumns()
{
    ...
}

0
 

Author Comment

by:dave81
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?
0
 

Expert Comment

by:murrayc
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.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now