I read from your comments 1
Message Mapping is done correctly and message is registered. What I am trying is in class C I am writing SendMessage(Message Id, parameters) so its not working, but when I am doing like CWnd* p = GetTopLeveParent(); then p->SendMessage it is working
and 2
But its hitting the listener function 3 times not sure why?
... that you are just calling SendMessage
within some member function of C
:
void C::something()
{
SendMessage(some_msg_id, p1, p2);
}
But here you are actually calling this->SendMessage(some_msg_id, p1, p2);
because in C++, each member function has an implicit this
parameter (that is - if applicable - also implicitly used for further calls). The value of this
within a member function is the object for which the function is currently called. So if you have an object cObj
of class C
and you call cObj.something
, you invoke the member function C::something
with the implicit parameter this
being cObj
for that call. If you do a call from within a member function, C++ checks two namespaces for resolving that call:
- global functions
- own (and inherited) member functions
In the case of own member functions, this
is used implicitly, so you call SendMessage
for an object of class C
. What you want to do is calling an object of class D
, so you need to get a pointer to some dObj
.
When you call GetTopLevelParent()->SendMessage(...)
, you give the message to a more general message distribution mechanism that broadcasts it to child windows. That's why you see the message more than once in your target object. But this is only because the D
-class object is a child of the same top level parent as the C
-class object.