Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

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

This topic is 5039 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

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.

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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."

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!