WM_CTLCOLORBTN message

Started by
1 comment, last by Dead Eye 19 years, 2 months ago
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.
AIM ME: aGaBoOgAmOnGeR
Advertisement

Noone has used this message before?

AIM ME: aGaBoOgAmOnGeR
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 colorsfor the button. Buttons with the BS_PUSHBUTTON, BS_DEFPUSHBUTTON, orBS_PUSHLIKE styles do not use the returned brush. Buttons with thesestyles are always drawn with the default system colors. Drawing pushbuttons requires several different brushes-face, highlight and shadow-butthe WM_CTLCOLORBTN message allows only one brush to be returned. To providea custom appearance for push buttons, use an owner-drawn button.

This topic is closed to new replies.

Advertisement