Sign in to follow this  

WM_CTLCOLORBTN message

This topic is 4686 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

There's no WINAPI section, so I thought this the most appropriate forum... I am trying to use the WM_CTLCOLORBTN message to change the colors of things in my buttons. It seems to work on every other type of control in my dialog (list boxes, static text, edit boxes, etc.) and even my dialog itself (with the correct messages WM_CTLCOLORSTATIC etc.) but not for buttons for some reason. Any Ideas? Here's my message handling code:
[SOURCE]
		case WM_CTLCOLORBTN:
		{
			HDC e_dc = (HDC)wParam;
			j = (int)GetWindowLong((HWND)lParam,GWL_USERDATA);
			GetClassName((HWND)lParam,tmpstr,sizeof(tmpstr));
			if((coms.sel_brush>=0)&&(_stricmp(tmpstr,"BUTTON")==0))
			{
				COLORREF col = coms.brushes[coms.sel_brush].color_vals[j];
				COLORREF inv_col = (~col)&0x00FFFFFF;
				HBRUSH br = CreateSolidBrush(col);
				SetBkMode(e_dc,OPAQUE);
				SetBkColor(e_dc,col);
				SetTextColor(e_dc,inv_col);
				return (BOOL)br;
			}
			break;
			
		}

[/SOURCE]
[/source] Thanks, ~SPH EDIT: My debugger tells me that I do get to the return statement, so it is getting run. And the cast to BOOL works in all other cases, and is suggested in the MSDN documentation.

Share this post


Link to post
Share on other sites
From MSDN (basically it doesn't work for system buttons because they require multiple brushes). That message is kinda misleading, but it should work for
radio buttons and check boxes, which are types of buttons.


By default, the DefWindowProc function selects the default system colors
for the button. Buttons with the BS_PUSHBUTTON, BS_DEFPUSHBUTTON, or
BS_PUSHLIKE styles do not use the returned brush. Buttons with these
styles are always drawn with the default system colors. Drawing push
buttons requires several different brushes-face, highlight and shadow-but
the WM_CTLCOLORBTN message allows only one brush to be returned. To provide
a custom appearance for push buttons, use an owner-drawn button.

Share this post


Link to post
Share on other sites

This topic is 4686 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this