In the winAPI, how do I change the window background colour?
For example,
wc.hbrBackground = ....;
is for setting the window background initially, but how do I change it there after?
Thanks.
In the winAPI, how do I change the window background colour?
For example,
wc.hbrBackground = ....;
is for setting the window background initially, but how do I change it there after?
Thanks.
Use the SetClassLongPtr function with the GCLP_HBRBACKGROUND argument:
SetClassLongPtr(windowHandle, GCLP_HBRBACKGROUND, brushHandle);
http://msdn.microsoft.com/en-us/library/ms633589%28VS.85%29.aspx
Be wary of using the technique described by PigBen. It will change the background color for all instances of that window class, unless they implement WM_PAINT/WM_ERASBKGND that overrides the windows' default background.
I would make the extra effort of implementing WM_ERASEBKGND for your window, and draw the background explicitly. That way you have full control of the background color, and you can have different colors in different window instances.