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.