Download source files - 1 Kb

Introduction
This is a very quick fix to displaying a disabled combo
box as read only. If you have a form with lots of read only edit boxes, the normal
disabled combo box looks a bit funny. Read only edit boxes have black text with grey
backgrounds. While disabled combo boxes have dark grey text with grey backgrounds.
Hard to explain to users.
This code only works for drop down style combo boxes. This is because I am
setting the child edit box as enabled and read only when the parent combo box is
disabled.
When the combo box gets a WM_ENABLE message, check the bEnable
flag and call EnableWindow and SetReadOnly for the edit box.
A pointer to the edit box is retrieved by just getting the first child window of the
combo box, GetWindow(GW_CHILD).
BEGIN_MESSAGE_MAP(CReadOnlyComboBox, CComboBox)
...
ON_WM_ENABLE()
...
END_MESSAGE_MAP()
void CReadOnlyComboBox::OnEnable(BOOL bEnable)
{
CComboBox::OnEnable(bEnable);
CEdit* pEdit = (CEdit*)GetWindow(GW_CHILD);
pEdit->EnableWindow(TRUE);
pEdit->SetReadOnly(!bEnable);
}
The only down side to this approach is the text can't be selected with the mouse
like a read only edit box.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here