[comp.windows.ms.programmer] QUESTION: Changing color of Edit Control text

ssl@hpkslx.mayfield.HP.COM (SSL Guest User) (03/27/91)

Dear net,

I hope this hasn't been asked too many times already 
(i've been reading this group for a month or so...)

How does one change the color of text entered and displayed
in a dialog box edit control?

I've tried the following (which failed as predicted by the SDK manuals)

hDC = GetDC(GetDlgItem(hDlg, controlid));
SetTextColor(hDC, RGB(blah, blah, blah));
ReleaseDC(hDC, blah blah);

SetTextColor() is apparently intended for TextOut() type operations.

I'm trying to show text in RED for a money field that has gone negative
(whippeeee).

Please email and i'll post the answer if anyone gives a hoot.

Thanks for your time,

Thomas
thomas@hpssl40.mayfield.hp.com

gpsteffl@sunee.waterloo.edu (Glenn Patrick Steffler) (03/29/91)

In article <25920006@hpkslx.mayfield.HP.COM> ssl@hpkslx.mayfield.HP.COM (SSL Guest User) writes:
>Dear net,
>I hope this hasn't been asked too many times already 
>(i've been reading this group for a month or so...)
Aggggghhht!  Thanks for playing hide the newuser.notice!

>How does one change the color of text entered and displayed
>in a dialog box edit control?
Look up WM_CTLCOLOR message.

>Thomas
>thomas@hpssl40.mayfield.hp.com

-- 
Co-Op Scum                            "Bo doesn't know software" - George Brett

"The galaxial hearth steams the sea as the sky blood red embrasses darkness"
-John Constantine (HellBlazer)                          Glenn Steffler

bonneau@hyper.hyper.com (Paul Bonneau) (03/29/91)

In article <25920006@hpkslx.mayfield.HP.COM> ssl@hpkslx.mayfield.HP.COM (SSL Guest User) writes:
>
>How does one change the color of text entered and displayed
>in a dialog box edit control?
>
>I've tried the following (which failed as predicted by the SDK manuals)
>
>hDC = GetDC(GetDlgItem(hDlg, controlid));
>SetTextColor(hDC, RGB(blah, blah, blah));
>ReleaseDC(hDC, blah blah);
>
The problem is that each time the edit control gets a DC, it
is re-initialized to the default setting.  If the control
were registered with one of the other DC attributes your fix
would work (the text color would not be nuked--see the
discussion of DC attributes in Reference--Volume 2--wndclass).

However, you can use the WM_CTLCOLOR message.  This is sent
just before the control paints itself.  Just call
SetTextColor() as above except use the DC supplied with the
message.

cheers - Paul Bonneau.