yoavo
asked on
Combobox events with "CBS_DROPDOWN" style.
Hi,
I derive a a class from CComboBox (CMyComboBox), and in it I capture some events such as OnKillFocus, and PreTranslateMessage (in order to handle Enter-pressing, and Escape-pressing). The combo can be created with CBS_DROPDOWN style or with CBS_DROPDOWNLIST style.
If I create it with CBS_DROPDOWNLIST than everything is fine, but when using CBS_DROPDOWN style, a EditBox is created (as a child of the combobox) and The combobox itself does not get the events.
How can I handle the WM_KILLFOCUS events in CMyComboBox class when using CBS_DROPDOWN style ???
Thanks,
Yoav.
I derive a a class from CComboBox (CMyComboBox), and in it I capture some events such as OnKillFocus, and PreTranslateMessage (in order to handle Enter-pressing, and Escape-pressing). The combo can be created with CBS_DROPDOWN style or with CBS_DROPDOWNLIST style.
If I create it with CBS_DROPDOWNLIST than everything is fine, but when using CBS_DROPDOWN style, a EditBox is created (as a child of the combobox) and The combobox itself does not get the events.
How can I handle the WM_KILLFOCUS events in CMyComboBox class when using CBS_DROPDOWN style ???
Thanks,
Yoav.
ASKER
I dont think I like this solussion...
It will work
another thing is that, How can I solve a microsoft bug in a direct way....
Regards
Roshmon
another thing is that, How can I solve a microsoft bug in a direct way....
Regards
Roshmon
Did you try to everwrire REFLECTED CBN_KILLFOCUS?
In class wizard it is =CBN_KILLFOCUS?
In class wizard it is =CBN_KILLFOCUS?
ASKER
mblat,
You are wtite. this solves me the kill focus problem, but how can I catch enter/escape pressed ?
You are wtite. this solves me the kill focus problem, but how can I catch enter/escape pressed ?
Did you try to everwrire REFLECTED CBN_KILLFOCUS?
In class wizard it is =CBN_KILLFOCUS?
In class wizard it is =CBN_KILLFOCUS?
Ok, it's not that simle actually, at list the way I know how to do it isn't. :-(
1. You need to sublclass CEdit control to CMyEdit.
2. Overwrite CMyEdit::OnGetDlgCode() and return DLGC_WANTALLKEYS from it.
3. Declare
CMyEdit m_edit as member variable of your CMyComboBox;
4. In your CMyComboBox owerwrite CMyComboBox::PreSubclassWi ndow.
5. After
CComboBox::PreSubclassWind ow();
line put the following code:
CWnd* ce = GetWindow(GW_CHILD | GW_HWNDFIRST);
m_edit.SubclassWindow(ce-> m_hWnd);
Now you can handle WM_KEYDOWN messages inside CMyEdit class...
Hope it helps...
1. You need to sublclass CEdit control to CMyEdit.
2. Overwrite CMyEdit::OnGetDlgCode() and return DLGC_WANTALLKEYS from it.
3. Declare
CMyEdit m_edit as member variable of your CMyComboBox;
4. In your CMyComboBox owerwrite CMyComboBox::PreSubclassWi
5. After
CComboBox::PreSubclassWind
line put the following code:
CWnd* ce = GetWindow(GW_CHILD | GW_HWNDFIRST);
m_edit.SubclassWindow(ce->
Now you can handle WM_KEYDOWN messages inside CMyEdit class...
Hope it helps...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
// The following code shows how to subclass the edit control and list box
// controls inside a combo box. It uses WM_CTLCOLOR for subclassing.
// CSuperComboBox represents the combo box.
HBRUSH CSuperComboBox::OnCtlColor
{
if (nCtlColor == CTLCOLOR_EDIT)
{
//Edit control
if (m_edit.GetSafeHwnd() == NULL)
m_edit.SubclassWindow(pWnd
}
else if (nCtlColor == CTLCOLOR_LISTBOX)
{
//ListBox control
if (m_listbox.GetSafeHwnd() == NULL)
m_listbox.SubclassWindow(p
}
HBRUSH hbr = CComboBox::OnCtlColor(pDC,
return hbr;
}
GOOD LUCK