Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Make a read-only CCombBox???

93 views
Skip to first unread message

Clyde Gerber

unread,
May 11, 1998, 3:00:00 AM5/11/98
to

My application displays combo boxes that I would like to make read-only
until the user activates another control that enables input. However, the
combo box should still display the string that is initially selected for the
combobox. I have tried setting the combo boxes initially as disabled, but
the problem with this is that the initial text that's displayed is very
light (much lighter than a read-only CEdit). Does anyone know of a way to:

- Create a read-only combo box that can be easily changed to accept input
which isn't too light?

OR

- Reset the appearance on a combo box that has been disabled so the text is
more readable?

Thanks in advance

Clyde

Guido Ramseier

unread,
May 12, 1998, 3:00:00 AM5/12/98
to Clyde Gerber

If you are using MFC you could use the Class Wizard to make an obect of
type CCombobox and use the Enable(FALSE) Enable(TRUE) functions of CWnd.

Or use GetDlgItem to get a pointer to the Combobox and then use the
functions.


Hope this helps Guido

Jean Cai

unread,
May 12, 1998, 3:00:00 AM5/12/98
to

The "Drop List" type of ComboBox is read only.

Clyde Gerber wrote in message ...

Clyde Gerber

unread,
May 12, 1998, 3:00:00 AM5/12/98
to

Jean Cai wrote in message ...


>The "Drop List" type of ComboBox is read only.

However, the "Drop List" ComboBox doesn't display the initial value of the
control -- I'd like to display data from a database query, then allow the
user to enable the control by pressing another button and selecting from the
combobox.

Clyde Gerber

unread,
May 12, 1998, 3:00:00 AM5/12/98
to

Guido Ramseier wrote in message <3557E0...@rhein-main.netsurf.de>...


>If you are using MFC you could use the Class Wizard to make an obect of
>type CCombobox and use the Enable(FALSE) Enable(TRUE) functions of CWnd.
>
>Or use GetDlgItem to get a pointer to the Combobox and then use the
>functions.


This is exactly what I intended to do, however the displayed text is very
light and hard to read. (It's much light than a read-only CEdit control,
for example.) Is there a simple way to make the font in the control bolder
or darker when the control is disabled?

Current Occupant

unread,
May 13, 1998, 3:00:00 AM5/13/98
to

"Clyde Gerber" <cge...@isd.net> wrote:

>This is exactly what I intended to do, however the displayed text is very
>light and hard to read. (It's much light than a read-only CEdit control,
>for example.) Is there a simple way to make the font in the control bolder
>or darker when the control is disabled?
>

One possibility is to code a handler for the CBN_SETFOCUS message for
the combobox. In the handler, you can either show a message that it is
not allowed to modify that entry at that point, or, you can simply
shift the focus to another control. This way, you don't have to
disable the combobox.


Murali Krishna Devarakonda

unread,
May 19, 1998, 3:00:00 AM5/19/98
to

You can handle OnCtlColor and paint the background and foreground to
resemble a readonly window.
And as suggested by "CurrentOccupant", you can make it behave like a
readonly window.

Here's a sample:

HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
// TODO: Change any attributes of the DC here
switch (nCtlColor)

case CTLCOLOR_EDIT:
case CTLCOLOR_MSGBOX:
case CTLCOLOR_LISTBOX:
// Set color to dark blue on light blue and return the background
brush.
pDC->SetTextColor(RGB(0, 0, 128));
pDC->SetBkColor(RGB(0, 200, 255));
return (HBRUSH)(m_pComboBkBrush->GetSafeHandle());
default:
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}

Murali Krishna Devarakonda

Clyde Gerber wrote in message ...

<<<snip>>>


>light (much lighter than a read-only CEdit). Does anyone know of a way to:
>
>- Create a read-only combo box that can be easily changed to accept input
>which isn't too light?


>OR

>- Reset the appearance on a combo box that has been disabled so the text
is
>more readable?

<<<snip>>>

0 new messages