Changing Edit Box Text Colors in Windows

Discussion in 'C++' started by Matt, Aug 26, 2003.

  1. Matt

    Matt Guest

    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.
    Matt, Aug 26, 2003
    #1
    1. Advertising

  2. Matt

    krlll Guest

    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...
    krlll, Aug 26, 2003
    #2
    1. Advertising

  3. 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.
    Kevin Goodsell, Aug 26, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gnarlodious
    Replies:
    4
    Views:
    17,550
    elizas
    May 5, 2010
  2. AAaron123

    TreeNode colors come from anchor colors

    AAaron123, Aug 7, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    526
    darrel
    Aug 7, 2008
  3. ZelluX
    Replies:
    3
    Views:
    1,857
    Peter Otten
    Dec 1, 2008
  4. Henry

    Underlining text, changing colors

    Henry, May 24, 2004, in forum: Javascript
    Replies:
    5
    Views:
    76
    Henry Hayden
    May 25, 2004
  5. multimatum2

    Changing disabled colors in an input text form

    multimatum2, Oct 5, 2004, in forum: Javascript
    Replies:
    4
    Views:
    178
    Michael Winter
    Oct 6, 2004
Loading...

Share This Page