Thread: Changing the color of controls

  1. #1
    Registered User
    Join Date
    Aug 2003

    Changing the color of controls

    I was wondering which message do i have to handle in order to change the background color of a button/groupbox.

    Ive already tried:
    		case WM_CTLCOLORBTN:
    			HBRUSH hBrush = CreateSolidBrush(RGB(0, 255, 0));
    			return (long)hBrush;
    It doesnt work, ive tried it using a button and a groupbox, and on both tries none of them has worked.

  2. #2
    Join Date
    Jan 2002
    Unfortunately, the WM_CTLCOLORBTN doesn't work for buttons as the other WM_CTLCOLOR* messages work for their respective controls. If you want different coloured buttons you'll have to create your own or use owner-drawn ones.

    This behaviour is described by Petzold:
    Programming Windows, 5th ed. by C. Petzold. Ch9 Child Window Controls
    Only the pushbuttons and owner draw buttons send WM_CTLCOLORBTN to their parent windows, and only owner draw buttons respond to the window processing of the message using the brush for coloring the background. This is fairly useless because the parent window is responsible for drawing owner draw buttons anyway.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Controls
    By osal in forum Windows Programming
    Replies: 7
    Last Post: 06-11-2004, 10:38 AM
  2. Subclassing controls
    By filler_bunny in forum Windows Programming
    Replies: 3
    Last Post: 04-28-2004, 05:43 PM
  3. Changing control's font
    By Devil Panther in forum Windows Programming
    Replies: 1
    Last Post: 05-31-2003, 06:41 AM
  4. I need help disabling Keyboard and Mouse input on Edit controls
    By Templario in forum Windows Programming
    Replies: 4
    Last Post: 01-07-2003, 12:59 AM
  5. Changing Text/Background colours for window controls ...
    By Shag in forum Windows Programming
    Replies: 1
    Last Post: 11-16-2002, 11:57 AM