Is it possible to change the color of text in an edit box, and also change the color of read-only (to make it white, instead of the button-color)?
Is it possible to change the color of text in an edit box, and also change the color of read-only (to make it white, instead of the button-color)?
Definitely. One solution is subclassing.
Kuphryn
It would be WM_CTLCOLOREDIT & WM_CTLCOLORSTATIC.
Something like:
But I have one other, yet related question. Has anyone managed to changeCode:case WM_CTLCOLOREDIT: SetTextColor (hdc, txtColor); SetBkColor (hdc, bkColor); return ((LRESULT) editBkBrush);
the color for disabled edit or static boxes? Seems like they use GetSysColor(COLOR_GRAYTEXT) for that in original edit proc.
Should I try with SetSysColor() just before edit box receives WM_PAINT and
some of its notifications? Can I screw up something else if I play with that?
Any experience?
Use the same method you just posted.
A read-only or disabled edit control will use the WM_CTLCOLORSTATIC message.
gg
Thanks Delf
I also found this not to long ago, and it seems to work. I can change the text color and background color of edit boxes and statics.
Originally Posted by Codeplug
Are you sure? You mean disabled with EnableWindow(..., FALSE) ?
I do handle WM_CTLCOLORSTATIC and it doesn't affect disable controls.
In the CodeProject's article Quantrizi posted above there are these lines:
Code:m_ebCtl.SetReadOnly(); //This makes it so nobody can edit the text. //If you disable the box it does not let you //change colors.
I'd say look at the code on how it's done, and go from there
Just read the manual: WM_CTLCOLORSTATIC
gg
Originally Posted by Codeplug
Thanks for being patient with a stubborn person - ME!
I do handle WM_CTLCOLORSTATIC but it's like this:
I just left SetTextColor() here as a reminder abou something I *could*Code:LRESULT StdOnCtlColorStatic (HWND hwnd, WPARAM wParam, LPARAM lParam) // hwnd of real window! { // on WM_CTLCOLORSTATIC: HDC hdc = (HDC) wParam; // hwnd = (HWND) lParam; // SetTextColor (hdc, RGB(255, 92, 16)); SetBkColor (hdc, gStatBkColor); return ((LRESULT)gStatBkBrush); }
use if I need to. Someone just had to remind me about my reminder! So, thanks!
Originally Posted by Codeplug
For a moment I had a feeling that I'm getting somewhere...
The problem is - well, there are two problems:
1. MSDN is wrong,
2. Disabled edit controls really do use WM_CTLCOLORSTATIC when disabled,
but only for background. Text color is hardcoded deep into User32.dll.
I tried it on Win98 and on XP an it's the same. I can make disabled
edit have background whatever I like, but text is always GRAY.
Bad luck.
Then I looked into WINE, just to make sure.
EDIT_SEND_CTLCOLORSTATIC and EDIT_SEND_CTLCOLOR are macros, butCode:if ( get_app_version() >= 0x40000 &&( !es->bEnableState || (es->style & ES_READONLY))) EDIT_SEND_CTLCOLORSTATIC(hwnd, dc); else EDIT_SEND_CTLCOLOR(hwnd, dc); if (!es->bEnableState) SetTextColor(dc, GetSysColor(COLOR_GRAYTEXT));
you can guess what they do.
Seems like MS changed this thing after Win 3.x, but only halfway.
One day I'll try playing with SetSysColor() and see what happens.
Last edited by Delf; 08-13-2004 at 05:35 PM.