How to set background colour of a "static" object created with 'CreateWindow' ?

Started by
7 comments, last by johnnyBravo 19 years, 3 months ago
Hi, I've created a "static" object with the CreateWindow function. The background it automatically grey, and I want it to be white, is there any way of changing its background colour? Thanks.
Advertisement
Look up WM_CTLCOLORSTATIC in the MSDN.
ahhh i see now, thanks
Hey I'm doing it like this in the wndproc

switch(msg) {
case WM_CTLCOLORSTATIC:
return (LONG)CreateSolidBrush(RGB(0, 0, 0));
};

But I think you have to delete the object after creating a brush.

So how would I get around to deleting it?

Thanks
Try putting it in a pointertype variable and use delete for a pointer type, call it backgroundcolor or something.
If you only need black as a colour, then instead of calling CreateSolidBrush every time, just call GetStockObject(BLACK_BRUSH) instead. Because the brush returned is a stock object, you do not need to delete it. It will also return the same brush every time so it won't be creating loads and loads of brushes (hence saving memory).
thanks, just one more thing, how would i make a buttons background colour white?

Like I tried doing the same:

case WM_CTLCOLORBTN:
return (LONG)GetStockObject(WHITE_BRUSH);
break;


but it stays grey.
From the MSDN:

"The WM_CTLCOLORBTN message is sent to the parent window of a button before drawing the button. The parent window can change the button's text and background colors. However, only owner-drawn buttons respond to the parent window processing this message."
thx,

This topic is closed to new replies.

Advertisement