Changing Edit Box Text Colors in Windows

M

Matt

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.
 
K

krlll

Matt said:
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...
 
K

Kevin Goodsell

krlll said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top