Individual color of a text field

This is a discussion on Individual color of a text field within the Windows Programming forums, part of the Platform Specific Boards category; Hello I have some dificulties to change the color of only one text field in my dialog box. I used ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    8

    Individual color of a text field

    Hello

    I have some dificulties to change the color of only one text field in my dialog box. I used first :

    case WM_CTLCOLORSTATIC:
    HBRUSH hBrush;
    hBrush = CreateSolidBrush(RGB(0, 0, 0));
    SetBkColor((HDC)wParam, RGB(0, 0, 0));
    SetTextColor((HDC)wParam, RGB(255, 0, 0));
    return (DWORD)hBrush;

    But this change the color of ALL the text fields.
    The text field I want to change is called HAUTEUR. How can I ask to the program to change only the color of HAUTEUR ?

    All the best

    Pierre

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    In the lParam is passed the window handle(HWND) of the edit control that this message (WM_CTLCOLORSTATIC) applies to.

    If the edit control is in a dialog you can get its control id and compare it with the id of the control that you want to set:
    Code:
    case WM_CTLCOLORSTATIC:
    if (GetDlgCtrlID((HWND) lParam) == ID_HAUTEUR) 
    {
        // set color for height control...
        ...
        return TRUE;
    }
    else
    {
        return FALSE;
    }
    Otherwise, you usually have a variable containing the hwnd of the edit control:
    Code:
    case WM_CTLCOLORSTATIC:
    if ((HWND) lParam == hwndEditHauteur)
    {
        // set color for height control...
        ...
        return 0;
    }
    else
    {
        return DefWindowProc( ... );
    }
    Last edited by anonytmouse; 03-21-2004 at 09:12 AM.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,673
    WM_CTLCOLORSTATIC
    Use lParam...

    gg

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    8
    Thanks a lot !
    So simple, and it Works !

    All the Best

    Pierre

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX | Drawing text
    By gavra in forum Game Programming
    Replies: 4
    Last Post: 06-08-2009, 12:23 AM
  2. Input a Hex number and output hex number to a text field
    By zoobaby in forum C++ Programming
    Replies: 4
    Last Post: 05-12-2009, 11:26 AM
  3. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 02:17 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Replies: 1
    Last Post: 07-13-2002, 05:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21