How to send events to extended child control?
-
I have extended a CComboBox and implemented three messages (or events) like below
BEGIN\_MESSAGE\_MAP(CComboCtrl, CComboBox) ON\_WM\_KEYDOWN() ON\_CONTROL\_REFLECT(CBN\_EDITUPDATE, &CComboCtrl::OnCbnEditupdate) ON\_CONTROL\_REFLECT(CBN\_SELCHANGE, &CComboCtrl::OnCbnSelchange) END\_MESSAGE\_MAP()
Now when a selection changes it calls OnCbnSelchange message-handler. I am using this class inside a dialog class. I have tried to register a message handler in that dialog class for CBN_SELCHANGE event but I think it is not receiving CBN_SELCHANGE event or it is sending that event to custom control. How can I handle CBN_SELCHANGE event inside a dialog class. This is the implementation inside derived class (or custom control class)
void CComboCtrl::OnCbnSelchange()
{
// TODO: Add your control notification handler code hereGetLBText(GetCurSel(),m\_str\_sel); //get previous text in combo.
}
-
I have extended a CComboBox and implemented three messages (or events) like below
BEGIN\_MESSAGE\_MAP(CComboCtrl, CComboBox) ON\_WM\_KEYDOWN() ON\_CONTROL\_REFLECT(CBN\_EDITUPDATE, &CComboCtrl::OnCbnEditupdate) ON\_CONTROL\_REFLECT(CBN\_SELCHANGE, &CComboCtrl::OnCbnSelchange) END\_MESSAGE\_MAP()
Now when a selection changes it calls OnCbnSelchange message-handler. I am using this class inside a dialog class. I have tried to register a message handler in that dialog class for CBN_SELCHANGE event but I think it is not receiving CBN_SELCHANGE event or it is sending that event to custom control. How can I handle CBN_SELCHANGE event inside a dialog class. This is the implementation inside derived class (or custom control class)
void CComboCtrl::OnCbnSelchange()
{
// TODO: Add your control notification handler code hereGetLBText(GetCurSel(),m\_str\_sel); //get previous text in combo.
}
It's a long time since I used MFC message maps, but it looks to me like you are capturing the
CBN_SELCHANGE
notification in your control, so the dialog box won't see it. I think you may need to move that notification to the dialog or reflect it back somehow. Pual Di Lascia wrote an excellent paper[^] on MFC message processing which I recommend to anyone struggling with this subject.The best things in life are not things.
-
It's a long time since I used MFC message maps, but it looks to me like you are capturing the
CBN_SELCHANGE
notification in your control, so the dialog box won't see it. I think you may need to move that notification to the dialog or reflect it back somehow. Pual Di Lascia wrote an excellent paper[^] on MFC message processing which I recommend to anyone struggling with this subject.The best things in life are not things.
thanks Richard, you got the problem right. I am reading that article now.