EVENTSINK_MAP for a ctrl passed in at runtime

Posted on 1998-07-08
Last Modified: 2013-11-20
I'm trying to setup an EVENTSINK_MAP for a control that is passed in at runtime.  The problem is that the ON_EVENT macro's second parameter is the control's ID.  I figure that I can put a dummy there and change it by setting _eventsinkEntries[n].nCtrlIDFirst where n is the ordinal number of the ON_EVENT macro.  The problem is getting the the control ID from the custom control that is passed in.
Any ideas?
Question by:skin
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
  • 3
  • 3
LVL 11

Expert Comment

ID: 1318868
What you're thinking of doing is the long way around.

You should override OnCmdMsg() and watch for event notifications from the control.

My book has an elaborate sample that shows how to do this, as well as other issues associated with containing controls at runtime in MFC applications.

B ekiM


Author Comment

ID: 1318869
Oops I should have been clearer in my description.  I have a control, I'll call A.OCX that exposes a write-only automation property for accepting an LPDISPATCH of another Control, B.OCX.  I need A.OCX to be able to receive notification when B.OCX fires certain events.  I bought your book last night and overrode OnCmdMsg() but do not see anything in OnCmdMsg().  
LVL 11

Expert Comment

ID: 1318870
Is A.OCX containing B.OCX?  Or are they side-by-side in the container?

If A.OCX contains B.OCX, then OnCmdMsg() will work fine: you must've made a mistake.

If they're side-by-side in the container, you can't do what you want. You need to code smarts into the container to reflect notifications from one control to all controls. The OLE Control spec has no provision for one control to spy on the invocations of another control--and that makes sense, since the Windows control model doesn't support it, either.

B ekiM

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 1318871
Actually B.OCX creates A.OCX.  
B.OCX may be created on a VB form and in turn creates A.OCX.
I need A.OCX to be able to watch B.OCXs events and take actions to update itself in response to changes in B.OCX.
Because when A.OCX is created it is passed an Dispatch pointer to B.OCX.
I figured there must be some way to sink A.OCXs events.
Thanks for your continued help!  If this still sounds like it's impossible I'll close this one.

Author Comment

ID: 1318872

Assuming this can not be done as per your last repsonse, if you reply again I'll close this.
LVL 11

Accepted Solution

mikeblas earned 300 total points
ID: 1318873
You _can_ do it, if you control the container. Then, you're responsible for the container having an interface that tells controls it contains about other controls it contains.  It's up to you to make that interface, and it's also up to you to make sure your controls gracefully degrade when they're inserted into containers which don't provide that custom interface.

B ekiM

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.

Question has a verified solution.

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

Suggested Solutions

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

740 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