Correct way of using HBRUSHes..? If I create a brush like so

HBRUSH hBrush = CreateSolidBrush(RGB(33, 33, 33));


and then later on, I want to change the color of the brush, how would I do this?
I googled a bit and found out that creating a bunch of different brushes is not the way to go.

I was thinking that one possibility would be to just set hBrush to a new brush like so

hBrush = CreateSolidBrush(RGB(0, 0, 0));


everytime I wanted to use a different color, but this seems suspiciously easy, and I'm pretty sure that this would hog resources or something.

Another - presumably bad - idea of mine, was to use the above method, but always use

DeleteObject(hBrush);


immediately after drawing. I have no idea if this is the right way to do things or not. Any help would be greatly appreciated.
Assume any Win32 call that returns a handle allocates a struct with malloc. And assume DeleteObject (DestroyWindow etc) frees allocated memory. you should call DeleteObject every time you creare a GDI object.

Calling CreateSolidBrush twice, and losing the first handle without calling Deleteobject on it causes a resource leak.

Since you are using C++ the correct way to do it is RAII. see http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization

This site has a good tutorial with clear windows programming examples on the subject.
http://www.relisoft.com/book/win/index.htm

This is a good open source library (MIT licence), that you can use in your project directly. Or you can look at gdi.h in the source.
http://win32-framework.sourceforge.net/index.htm