Custom Window Colour

Feb 17, 2011 at 3:50am
closed account (zb0S216C)
Is it possible to use a custom window colour instead of COLOR_BACKGROUND or the other defined window colours?
Feb 17, 2011 at 4:11am
do you want the window itself to have a different color or its controls?
Feb 17, 2011 at 4:28am
iirc you give an HBRUSH to CreateWindowEx() that is used for the background. It only uses the default colors if you give it NULL for that brush.

But is this really wise? The whole point of color schemes is that the user can customize their style and layout to their preference. When you have your program use its own color scheme it just makes it look out of place, tacky, and possibly even clashes with the rest of the environment.

This is one of the things that irks me about Java and other non-native widget APIs. They always] look and feel out of place.
Feb 17, 2011 at 2:12pm
Feb 17, 2011 at 10:28pm
closed account (zb0S216C)
Your link provided me with the answer, kbw. This is what I was looking for:

CreateSolidBrush( RGB ( 10, 10, 10 ) );

Thank you for your time :)
Feb 19, 2011 at 10:29am
closed account (3pj6b7Xj)
A word of advice that I learned the hard way. When you create a brush or any other object in windows, create it only once for the duration of the program and delete it when you are done with it. For example, if you used CreateSolidBrush() continuously you will use up all the GDI resources because your creating brushes but you aren't freeing them!

Create a brush at the start of your program.

HBRUSH hBackground=CreateSolidBrush(RGB(255,0,0); // red brush.

Use the brush how ever you like. And then, delete the brush...

DeleteObject(hBackground);

Now, here are some bad examples...

1
2
3
4
5
6
7
8
9
int a=1,b=2,b=3;

while(!bquit) // some program loop
{
     // create some rect region here.
     /// fill the region with this brush --
     CreateSolidBrush(RGB(a,b,c));
     a++,b++,c++;
}


The reason this is bad practice is because you are creating a load of brushes and sooner or later you use up all the GDI resources, eventually leading to nothing but white brushes.

Brushes are picky, even creating and deleting them several times is asking for trouble.

Last edited on Feb 19, 2011 at 10:31am
Topic archived. No new replies allowed.