I'm using Visual Studio 2008 to write an application for Windows CE 6 using C++ and MFC.
I want to remove the blue highlight of a CComboBox derived class when I've selected an element. According to this MSDN article, I cannot set the style of the combo box to LBS_OWNERDRAWFIXED or CBS_OWNERDRAWFIXED to choose the color of the selection on my DrawItem function.
I've tried to use the message CBN_SELCHANGE to send a WM_KILLFOCUS message. It partially work : the control loose its focus (the selected element is not blue anymore), but if I click again the combo box, it didnt show the list of elements.
I've read that I can use the paint event to set the color of the highlight, but I didn't know or find how to do this.
How can I remove the blue highlight of the combo box?
Edit: the combobox is read-only (flag CBS_DROPDOWNLIST)
I've found a (dirty) workaroud, in case nobody give a better approach :
I set a parent when I create the combobox :
customCombo.Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_DROPDOWN, CRect(0, 0, 0, 0), **PARENT**, COMBO_ID);
The following lines give the focus to the parent element when I'm done using the combo box.
In CComboBox subclass header file :
public:
afx_msg void OnCbnSelchange();
afx_msg void OnCbnSelendcancel();
afx_msg void OnCbnSelendok();
In source file :
void CustomCombo::OnCbnSelchange() {
//give focus to parent
CWnd* cwnd = GetParent();
if (cwnd != NULL) {
cwnd->SetFocus();
}
}
void CustomCombo::OnCbnSelendcancel() {
//give focus to parent
CWnd* cwnd = GetParent();
if (cwnd != NULL) {
cwnd->SetFocus();
}
}
void CustomCombo::OnCbnSelendok() {
//give focus to parent
CWnd* cwnd = GetParent();
if (cwnd != NULL) {
cwnd->SetFocus();
}
}