From: Bob Masta on
Hello, all:

I'd like to be able to change the color of an edit control during
program operation, as a status indicator. From what I've read,
anything involving control color requires subclassing, so that's what
I'm trying to do.

The control (with a lot of other controls) is on my main window, which
is itself a dialog created with CreateDialogParam. As soon as I
create the main window, I get the handle of the control to be
subclassed via GetDlgItem and call SetWindowLong to subclass it to my
custom window handler. I know this is getting messages, but it never
gets WM_CTLCOLOREDIT, which is the one I think I need to handle to
change the control background color.

Can it be that this message is sent only once, when the control is
first created, and by the time my subclass is up and running it's too
late? If so, what can I do to force the issue? Or is there a better
way to do this whole thing? How about changing text color instead...
would that be easier (and if so, what message do I respond to)?

Many thanks!


Bob Masta

DAQARTA v4.00
Data AcQuisition And Real-Time Analysis
www.daqarta.com
Scope, Spectrum, Spectrogram, Sound Level Meter
FREE Signal Generator
Science with your sound card!
From: Christian ASTOR on
Bob Masta wrote:

> The control (with a lot of other controls) is on my main window, which
> is itself a dialog created with CreateDialogParam. As soon as I
> create the main window, I get the handle of the control to be
> subclassed via GetDlgItem and call SetWindowLong to subclass it to my
> custom window handler. I know this is getting messages, but it never
> gets WM_CTLCOLOREDIT, which is the one I think I need to handle to
> change the control background color.

WM_CTLCOLOREDIT is sent to the parent of Edit control, the Dialog Box.
From: Bob Masta on
On Fri, 04 Jul 2008 22:28:53 +0200, Christian ASTOR
<castorix(a)club-internet.fr> wrote:

>Bob Masta wrote:
>
>> The control (with a lot of other controls) is on my main window, which
>> is itself a dialog created with CreateDialogParam. As soon as I
>> create the main window, I get the handle of the control to be
>> subclassed via GetDlgItem and call SetWindowLong to subclass it to my
>> custom window handler. I know this is getting messages, but it never
>> gets WM_CTLCOLOREDIT, which is the one I think I need to handle to
>> change the control background color.
>
>WM_CTLCOLOREDIT is sent to the parent of Edit control, the Dialog Box.

Ahh, that would explain it! So to change the color of the Edit, I
need to monitor the *parent* for WM_CTLCOLOREDIT and return the handle
of a brush. So there is really no subclassing needed here at all.

Many thanks!


Bob Masta

DAQARTA v4.00
Data AcQuisition And Real-Time Analysis
www.daqarta.com
Scope, Spectrum, Spectrogram, Sound Level Meter
FREE Signal Generator
Science with your sound card!
From: Bob Masta on
Problem solved, thanks to Christian. Here are the details on how to
add color to an Edit control:

1) Get a handle to a brush of the desired background color.
2) Get the handle to the control with GetDlgItem.
3) In the dialog proc, watch for WM_CTLCOLOREDIT message.
4) Check that the message is for the target handle.
5) If so, use SetBkColor to set the same color as the brush you
created earlier. That sets the text background color. Then return
the handle to that brush, which sets the background of the surrounding
Edit control.

If you also want to change the text color, then include SetTextColor
(with some contrasting color) as well as SetBkColor before returning
the background brush.

If you *only* want to change the text color, not the background, then
you don't need a brush handle. Just use SetTextColor and return TRUE.

Best regards,



>
>The control (with a lot of other controls) is on my main window, which
>is itself a dialog created with CreateDialogParam. As soon as I
>create the main window, I get the handle of the control to be
>subclassed via GetDlgItem and call SetWindowLong to subclass it to my
>custom window handler. I know this is getting messages, but it never
>gets WM_CTLCOLOREDIT, which is the one I think I need to handle to
>change the control background color.
>
>Can it be that this message is sent only once, when the control is
>first created, and by the time my subclass is up and running it's too
>late? If so, what can I do to force the issue? Or is there a better
>way to do this whole thing? How about changing text color instead...
>would that be easier (and if so, what message do I respond to)?
>
>Many thanks!
>
>
>Bob Masta
>
> DAQARTA v4.00
> Data AcQuisition And Real-Time Analysis
> www.daqarta.com
>Scope, Spectrum, Spectrogram, Sound Level Meter
> FREE Signal Generator
> Science with your sound card!

Bob Masta

DAQARTA v4.00
Data AcQuisition And Real-Time Analysis
www.daqarta.com
Scope, Spectrum, Spectrogram, Sound Level Meter
FREE Signal Generator
Science with your sound card!