Thread: font & font color in edit control

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    5

    font & font color in edit control

    Hello, I was wondering if someone can show me an example of

    how to change the background color and font color of an edit

    control. Its not a rich edit control.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Add the following to your window procedure:
    Code:
    case WM_CREATE: 
      {
      hbr=CreateSolidBrush(RGB(0,255,0)); /*green */
      return 0;
      }
    case WM_CTLCOLOEDIT: /*WM_CTLCOLORSTATIC for read only edit */
      {
      HDC hdc=(HDC)wParam;
      SetTextColor(hdc,RGB(255,0,0)); /*red text*/
      return (LRESULT)hbr; /*this brush used by system to paint control background */
      }
    case WM_DESTROY:
      {
      if (hbr)
        {
        DeleteObject(hbr); /*free gdi resources*/
        }
      }
    This gets asked a lot so a board search should give further explanation/examples should you require them.

    Dont' forget msdn:
    WM_CTLCOLOREDIT.
    edit controls.

    edit: use SetBkColor or SetBkMode if you want the text background to match the control background.
    Last edited by Ken Fitlike; 10-27-2003 at 05:18 PM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    5

    Thanks alot


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing from a Rich Edit control
    By JustMax in forum Windows Programming
    Replies: 10
    Last Post: 02-14-2009, 07:12 PM
  2. How to know the name of the font face of an edit control?
    By Joelito in forum Windows Programming
    Replies: 3
    Last Post: 12-22-2006, 07:54 PM
  3. Buttons + Edit Control
    By jay kay in forum Windows Programming
    Replies: 6
    Last Post: 03-09-2005, 05:36 PM
  4. Controlling an edit control
    By master5001 in forum Windows Programming
    Replies: 2
    Last Post: 10-16-2001, 03:08 PM
  5. Rich edit control example Win API
    By Echidna in forum Windows Programming
    Replies: 1
    Last Post: 09-17-2001, 02:12 AM