April 9th, 2010

Why can't you use WM_CTLCOLORSTATIC to change the color of a SS_BLACKRECT?

If you specify one of the static control styles which draw a frame or rectangle

SS_BLACKRECT SS_BLACKFRAME
SS_GRAYRECT SS_GRAYFRAME
SS_WHITERECT SS_WHITEFRAME

the control will be drawn with the corresponding color (which, as we saw last time, isn’t actually black, gray, or white). If you try to customize the color by handling the WM_CTL­COLOR­STATIC message, you’ll find that it has no effect. Well, yeah, because you said you wanted a black rectangle.

If you want some other color, you could set the style to SS_OWNER­DRAW then draw the solid color in your WM_DRAW­ITEM handler. Or you can just use a text static control with no text. In that case, you can respond to WM_CTL­COLOR­STATIC in the usual way. Since you specified no text, all that will be drawn is the background color.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.