Changing the color of controls

This is a discussion on Changing the color of controls within the Windows Programming forums, part of the Platform Specific Boards category; I was wondering which message do i have to handle in order to change the background color of a button/groupbox. ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    288

    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:
    Code:
    		case WM_CTLCOLORBTN:
    		{
    			HBRUSH hBrush = CreateSolidBrush(RGB(0, 255, 0));
    			return (long)hBrush;
    		break;
    		}
    It doesnt work, ive tried it using a button and a groupbox, and on both tries none of them has worked.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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, 11:38 AM
  2. Subclassing controls
    By filler_bunny in forum Windows Programming
    Replies: 3
    Last Post: 04-28-2004, 06:43 PM
  3. Changing control's font
    By Devil Panther in forum Windows Programming
    Replies: 1
    Last Post: 05-31-2003, 07: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

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