-
December 22nd, 2005, 04:03 AM
#1
Single Event Handle for Multiple Controls
Greetings,
I have a program that creates a number of activeX controls. That number is not known until run time. I achive this by having a dynamic array of control pointers allocated once the number of controls needed is know. When creating the controls I must give them a unique ID which I do by starting the ID count from a specific value and incrimenting it for every control. This works fine.
However I want to capture messages fired by these controls. The ugly way to do this would be to write an event handler for evry control and every message, but as I do not know the number of controls until run time, I won't know how many controls event handlers to code.
A nicer solution would be to use ON_CONTROL_RANGE http://msdn.microsoft.com/library/de...trol_range.asp which forwards events from controls with IDs of the specified consecutive range to a single function.
However once in that function I have no way of knowing controls was the one that fired the message in the first place. Does anybody have any other ideas of how this can be achieved? I want one function to handle all messages fired by a number of controls, and I want to still be able to know (preferably inside the handling function) the ID of the control that fired that message.
Thanks,
Aristotel
-
December 22nd, 2005, 04:22 AM
#2
Re: Single Event Handle for Multiple Controls
Originally Posted by greekgoddj
A nicer solution would be to use ON_CONTROL_RANGE http://msdn.microsoft.com/library/de...trol_range.asp which forwards events from controls with IDs of the specified consecutive range to a single function.
However once in that function I have no way of knowing controls was the one that fired the message in the first place.
Sorry, you're wrong.
The prototype for handler for ON_CONTROL_RANGE must be:
Code:
void CMyContainerWindow::OnSomeNotify(UINT ctrlID);
Here in ctrlID you get the id of the control which fired the notification.
Best regards,
Igor
-
December 22nd, 2005, 08:52 AM
#3
Re: Single Event Handle for Multiple Controls
Hi, thanks for that...you are right ofcourse...
However I have a problem:
error C2440: 'initializing' : cannot convert from 'int' to 'LPCTSTR'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
error C2440: 'initializing' : cannot convert from 'WORD' to 'LPCSTR'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
error C2440: 'initializing' : cannot convert from 'AfxSig' to 'AFX_PMSG'
There is no context in which this conversion is possible
with the following code:
Code:
BEGIN_EVENTSINK_MAP(CVSTPage, CWnd)
ON_CONTROL_RANGE(1, IDR_PARAMETERSTART, IDR_PARAMETERSTART + 50, OnParameterChanged)
END_EVENTSINK_MAP()
There was a similar problem in this thread http://www.codeguru.com/forum/showth..._CONTROL_RANGE
but it seems that guys mistake was that the function's argument list did not contain the UINT. I have is like this
Code:
afx_msg void OnParameterChanged(UINT ctrlID);
though and cannot figure what the problem is.
Any ideas?
Thanks
Aristotel
-
December 22nd, 2005, 08:53 AM
#4
Re: Single Event Handle for Multiple Controls
However I want to capture messages fired by these controls.
What kinds of messages? All messages, or, just certain ones? Or, are you speaking in terms of control events? What about the other controls?
Gort...Klaatu, Barada Nikto!
-
December 22nd, 2005, 09:00 AM
#5
Re: Single Event Handle for Multiple Controls
Originally Posted by Mike Harnad
What kinds of messages? All messages, or, just certain ones? Or, are you speaking in terms of control events? What about the other controls?
Specific Messages. Like the controls are all custom knobs made as ActiveX controls. When their value changes (when by mouse or keyboard) then they fire a message saying that the position has changed as well as firing the value indicating the position of the knob. With Igor's suggestion to use ON_CONTROL_RANGE to capture that message and in the handling function where the ID of the firing control is passed, I would know which of the controls it was and I would ask the control directly for what its value is.
-
December 22nd, 2005, 09:11 AM
#6
Re: Single Event Handle for Multiple Controls
More information in case its of help in figuring this out.
At the moment I have:
Code:
BEGIN_EVENTSINK_MAP(CVSTPage, CWnd)
ON_CONTROL_RANGE(1, IDR_PARAMETERSTART, IDR_PARAMETERSTART + 50, OnParameterChanged)
END_EVENTSINK_MAP()
and I get the above mentioned compilation error list. I have it in the event sink section as I am expecting messages from OLE controls. I had it before in the Message map and it had no compilation problems but the messages never were forwarded to the handling function. Perhaps I am wrong in thinking that ON_CONTROL_RANGE should be under the event sink map.
-
December 22nd, 2005, 09:20 AM
#7
Re: Single Event Handle for Multiple Controls
Have you thought about defining a generic event that can be used by all of the controls? The event can pass a structure pointer, or, whatever you need to expose. The event handler will then have all of the information it needs.
Gort...Klaatu, Barada Nikto!
-
December 22nd, 2005, 09:28 AM
#8
Re: Single Event Handle for Multiple Controls
Originally Posted by Mike Harnad
Have you thought about defining a generic event that can be used by all of the controls? The event can pass a structure pointer, or, whatever you need to expose. The event handler will then have all of the information it needs.
That would involve changing the code for the controls themeselves which I am not supposed to go into. The problem is not in the controls. The problem would be the same if I used ActiveX controls from another party (where i cannot go inot the code and create generic events for particular projects).
-
December 22nd, 2005, 09:34 AM
#9
Re: Single Event Handle for Multiple Controls
Sorry, from your initial description it appeared like you owned the source for the controls. Can you provide a specific example of what message you'd like to handle? You are talking about handling the message in the container (ie. dialog), correct?
Gort...Klaatu, Barada Nikto!
-
December 22nd, 2005, 09:51 AM
#10
Re: Single Event Handle for Multiple Controls
I do have the source code to the ActiveX controls, I was the one who wrote them a year ago or so. What I meant to say is that I cannot/should not change the behaviour of the controls which are already being used in many places and different applications, just for them being used in one specific application. Especially since there seems to be a specific macros (ON_CONTROL_RANGE) to deal with my requirements...the trick is to get that macros to work
The ActiveX controls are Knobs...when the knob changes in some way (through the user changing it by the mouse or keys) and everytime that happens, the ActiveX control fires a message "KnobChanged(short)" where short is is a short indicating the new value of the knob.
The following code:
Code:
//in somepage.h
void OnFirstKnobChange(short nPosition);
//in somepage.cpp
BEGIN_EVENTSINK_MAP(CSomePage, CWnd)
ON_EVENT(CSomePage, IDR_PARAMETERSTART, 1 , OnFirstKnobChange, VTS_I2)
END_EVENTSINK_MAP()
void CSomePage::OnFirstKnobChange(short nPosition)
{
int a = 0; //Set breakpoint here
}
Works fine, the breakpoint stops when I fiddle with the first knob in the window. So the aim is to use ON_CONTROL_RANGE to achieve the same thing for a number of such ActiveX controls.
-
December 22nd, 2005, 09:59 AM
#11
Re: Single Event Handle for Multiple Controls
Originally Posted by greekgoddj
with the following code:
Code:
BEGIN_EVENTSINK_MAP(CVSTPage, CWnd)
ON_CONTROL_RANGE(1, IDR_PARAMETERSTART, IDR_PARAMETERSTART + 50, OnParameterChanged)
END_EVENTSINK_MAP()
There was a similar problem in this thread http://www.codeguru.com/forum/showth..._CONTROL_RANGE
but it seems that guys mistake was that the function's argument list did not contain the UINT. I have is like this
Code:
afx_msg void OnParameterChanged(UINT ctrlID);
though and cannot figure what the problem is.
Any ideas?
The idea is the only: why on earth did you placed ON_CONTROL_RANGE into event sink map?!!! It belongs in message map and nowhere else.
Best regards,
Igor
-
December 22nd, 2005, 10:09 AM
#12
Re: Single Event Handle for Multiple Controls
Originally Posted by Igor Vartanov
The idea is the only: why on earth did you placed ON_CONTROL_RANGE into event sink map?!!! It belongs in message map and nowhere else.
Hmmmm....emmm... good question
Well its safe to say now that ON_CONTROL_RANGE is not suitable to be used with ActiveX controls...so the new question is...What is?
-
December 22nd, 2005, 10:16 AM
#13
Re: Single Event Handle for Multiple Controls
From your problem description, it sounds like you want to handle the events in the container, not the control. Is this correct? Are you looking for a mechanishm that will handle events from all controls within a dialog?
Gort...Klaatu, Barada Nikto!
-
December 22nd, 2005, 10:20 AM
#14
Re: Single Event Handle for Multiple Controls
Originally Posted by Mike Harnad
From your problem description, it sounds like you want to handle the events in the container, not the control. Is this correct? Are you looking for a mechanishm that will handle events from all controls within a dialog?
Yes, that is correct. Sorry if it was not clear enough.
-
December 22nd, 2005, 10:23 AM
#15
Re: Single Event Handle for Multiple Controls
Ok, what types of messages, events, etc. are you looking to handle?
Gort...Klaatu, Barada Nikto!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|