Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

catching my own notifications 1

Status
Not open for further replies.

TomasE

Programmer
Aug 4, 2002
6
SE
Hello

I've created a class that inherits from the ATL-class "CComboBox". What I want to do now is capture some of the notifications that "CComboBox" sends, like CBN_SELENDOK before they are sent to the parent window. But I only know how to capture from a child control, not messages from within the class itself. Is it possible to capture "your own" notifications?

Grateful for any help

/Tomas Emilsson
 
you need to add a message handler for (e.g.) CBN_SELENDOK, Go into class wizard, Message Maps, select your class in the Object id's box and look for =CBN_SELENDOK in the messages box. Highlight this and click "Add function". this will create a OnSelendok() function.

Hope this helps

CMR
 
Thanks for the reply, but I don't think you understood the question. I should've mentioned that I'm a professional VC++ programmer, and the problem is a bit more complex. The trouble is that I need to capture class "A's" message from _within_ class "A". It seems quite ridiculous, but since class A inherits from B, I must somehow do this to respond to the events in B.
 
Sorry, I may not have been clear enough here.
The message handler described in my previous post would be added to the CComboBox class, NOT the parent window, so you would be handling the message from within your class, as opposed to the parent window.

As you said, I don't fully understand what your trying to do so I apologise if this isn't what you want, but I hope it helps.

Regards

CMR
 
Ok, but if I simply add a handler for the event like this


class CAnotherComboBox : public CComboBox
{
public:
// ...
BEGIN_MSG_MAP(CAnotherComboBox)
COMMAND_CODE_HANDLER(CBN_SELENDOK, OnSelEndOK)
END_MSG_MAP()
// ...
};


, then it doesn't work; probably because the message is sent to the parent CWnd, and not to CAnotherComboBox.

I'm actually using WTL, not MFC, but they should work similiar in this respect.
 

I'm not familiar with WTL but when I do this in MFC, the code looks like this:

class CMyComboBox : public CComboBox
{
//...
protected:
//{{AFX_MSG(CMyComboBox)
afx_msg void OnSelchange();
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};


and in the implementation file:

BEGIN_MESSAGE_MAP(CMyComboBox, CComboBox)
//{{AFX_MSG_MAP(CMyComboBox)
ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelchange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()


void CMyComboBox::OnSelchange()
{
//do stuff...
}


This is all added by class wizard.

If you can't get this to work (it may only be an MFC thing) then I'm afraid I'm out of ideas

Sorry...

CMR


 
I noticed that your using ON_CONTROL_REFLECT. I tried using reflection before but I didn't get it to work, so I assumed it wasn't the answer. But if you get it to work with MFC then it should work with ATL/WTl too. I haven't used the Class Wizard; so it's very likely that I've missed something.

Anyway, thanks for taking the time to help; I think I might get it to work now. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top