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
    MESSAGE_HANDLER(WM_CTLCOLOREDIT, OnCtlColorEdit)
    
  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;
    }
    


Comments

  • There are no comments yet. Be the first to comment!

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • With the average hard drive now averaging one terabyte in size, the fallout from the explosion of user-created data has become an overwhelming volume of potential evidence that law-enforcement and corporate investigators spend countless hours examining. Join Us and SANS' Rob Lee for our 45-minute webinar, A Triage and Collection Strategy for Time-Sensitive Investigations, will demonstrate how to: Identify the folders and files that often contain key insights Reduce the time spent sifting through content by …

Most Popular Programming Stories

More for Developers

RSS Feeds