-
I think I get the idea, JasonD. You delete your old brushes as soon as you set a new one, and then delete the final brush in WM_DESTROY. But what if you have a number of brushes that you would like to switch between during your program? Would I be right in saying that they should not be deleted, with a globally scoped reference system (for retrieval purposes)?
-
If you have a number of specific brushes that you will be switching to during the run of the program, you can create them in WM_CREATE and destroy them in WM_DESTROY, and use the SetWindowLong() during the program to change the window's background brush to be any of them.
The code I showed you is a method of changing the background brush to any RGB value whatsoever during the run of your program, when you have no idea what color brushes you will need. It is based off a 'color picker' program that Charles Petzold wrote, and it is a very nice way of handling that situation.
But, generally, I think you get the basic idea - don't destroy a brush that is still currently being used, and destroy brushes right away if you are not going to be using them again. If you have brushes that will definitely be used throughout the program, you can create/destroy them at start up/shut down.