Custom Window Colour

closed account (zb0S216C)
Is it possible to use a custom window colour instead of COLOR_BACKGROUND or the other defined window colours?
do you want the window itself to have a different color or its controls?
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.
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 :)
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
Topic archived. No new replies allowed.