By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,289 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,289 IT Pros & Developers. It's quick & easy.

Changing Edit Box Text Colors in Windows

P: n/a
I'm having problems changing the text colors in an edit box in my program.
Here's what I'm trying to do, under WM_CREATE I have the following:

ClockFace = CreateWindowEx(0,
"EDIT",
"0.0.00",
WS_CHILD|WS_VISIBLE|WS_BORDER,
125,
75,
300,
100,
hwnd,
HMENU(CLOCKWINDOW),
NULL,
NULL);
HFONT StopFont =
CreateFont(100,24,0,0,700,200,0,0,0,0,0,0,0,TEXT(" Verdana"));
SendMessage(ClockFace, WM_SETFONT, WPARAM(StopFont),
MAKELPARAM(0,0));
hdc = GetDC(ClockFace); //tried putting this section under
WM_CTLCOLOREDIT, still didn't work
SetTextColor(hdc, RGB(0, 200, 0));
SetBkColor(hdc, RGB(0, 0, 0));

However, when I compile this I still get the standard black lettering and
white background. I think my problem lies in how I'm getting the DC handle.
I first tried typecasting the ClockFace HWND variable to a HDC but that
didn't work, but apparently GetDC isn't solving my problems either. How can
I fix this? Thanks for any help.
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Matt wrote:
I'm having problems changing the text colors in an edit box
in my program.


This news group is for discussion of the c++ language itself,
not OS-specific stuff, so you'd do better in future to direct
questions like this to microsoft.public.win32.programmer.ui

With that said, here is the answer: you need to use the
WM_CTLCOLOREDIT message, but don't use GetDC.
Use the wParam and lParam values, and return a HBRUSH
to change the background, like this -

LRESULT CtlColorEdit(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{

// control's window handle is lParam, not hWnd
if((HWND)lParam==ClockFace)
{
// HDC of control is wParam
SetTextColor((HDC)wParam, 0x00C800);
// return new background brush
return (LRESULT)GetStockObject(BLACK_BRUSH);
}

// just use the default settings otherwise
return DefWindowProc(hWnd, message, wParam, lParam);
}
Good luck...

Jul 19 '05 #2

P: n/a
krlll wrote:
Matt wrote:
I'm having problems changing the text colors in an edit box
in my program.

This news group is for discussion of the c++ language itself,
not OS-specific stuff, so you'd do better in future to direct
questions like this to microsoft.public.win32.programmer.ui

With that said, here is the answer:


Why are you posting an off-topic reply to an off-topic question when you
know it's off-topic? The idea is to discourage off-topic posts, not
encourage them.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.