Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Changing Edit Box Text Colors in Windows

Reply
Thread Tools

Changing Edit Box Text Colors in Windows

 
 
Matt
Guest
Posts: n/a
 
      08-26-2003
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.


 
Reply With Quote
 
 
 
 
krlll
Guest
Posts: n/a
 
      08-26-2003
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...



 
Reply With Quote
 
 
 
 
Kevin Goodsell
Guest
Posts: n/a
 
      08-26-2003
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
div box questions; float text around a box, fit box to image size Gnarlodious HTML 4 05-05-2010 11:30 AM
Is there any library that can convert RGB colors to ANSI colors? ZelluX Python 3 12-01-2008 11:08 AM
TreeNode colors come from anchor colors AAaron123 ASP .Net 1 08-07-2008 07:56 PM
Snapshot restraint - edit, edit, edit Alan Browne Digital Photography 24 05-10-2005 10:15 PM
Snapshot restraint - edit, edit, edit Patrick Digital Photography 0 05-06-2005 10:53 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57