Changing the Color of Edit and Combobox Controls in ATL

Simply follow these steps in order to change the color of the Edit control or Combobox control in ATL.
  1. Add a handler for WM_CTLCOLOREDIT
  2. Implementation of the handler, return the brush that u want to use to color the control
    LRESULT OnCtlColorEdit(UINT uMsg, 
                           WPARAM wParam, 
                           LPARAM lParam,
                           BOOL& bHandled)
     HDC hdcEdit = (HDC) wParam;    // handle to display context 
     HWND hwndEdit = (HWND) lParam; // handle to static control 
     if (( hwndEdit == GetDlgItem(IDC_EDIT) 
     || ( hwndEdit == GetDlgItem(IDC_COMBO))
      // m_hBrush is an instance variable that stores the
      // current Color brush. If this is the first time through
      // we need to create it. The brush is deleted in the destructor
      if ( m_hBrush == NULL )
       m_hBrush = CreateSolidBrush( RGB(255,0,0)
      // Get the DC provided and set the appropriate attributes
      SetBkMode(hdcEdit, TRANSPARENT );
      SetBkColor(hdcEdit, RGB(255,0,0));
      // Return a handle to the brush
      HBRUSH far* hbr = (HBRUSH far*) m_hBrush;
      return ((DWORD) hbr);
     return 0;


  • Changes BkColor and TextColor of 2 different comboboxes edit control

    Posted by Aparna on 08/31/2015 04:34am

    If We have 1 Combobox then We can change Background color and TExtColor easily For Example: case WM_CTLCOLOREDIT: SelectObject((HDC)wParam, hFont); SetTextColor((HDC)wParam, RGB(255, 0, 0)); SetBkColor((HDC) wParam,RGB(255,206, 129)); return (LRESULT) (HBRUSH)CreateSolidBrush(RGB(255,206, 129));

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

  • Enterprises are increasingly looking to platform as a service (PaaS) to lower their costs and speed their time to market for new applications. Developing, deploying, and managing applications in the cloud eliminates the time and expense of managing a physical infrastructure to support them. PaaS offerings must deliver additional long-term benefits, such as a lower total cost of ownership (TCO), rapid scalability, and ease of integration, all while providing robust security and availability. This report …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date