Solved

Catching ActiveX events within another ActiveX control

Posted on 1998-12-31
3
381 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

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

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…
I made this because I wanted to get e-mail with a attached csv file so I'd would be able to import user input into a MS Excel template, but I also wanted to register/save all inputs from each day in a file on the server. 1st - It creates a temp C…
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.

628 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