I know I am late to comment, however, I just ran across this problem and found a solution. I suspect there are many ways for this problem to occur; I found and fixed just one.
I created, a default GUI Window project using Code:: Blocks version 17.12 on Windows 7. I changed the background color, similar to what is presented in the OP's question. I built my project and voila, everything worked. I had my red window.
Then I decided to customize the program by adding handlers for the wm_paint and wm_erasebkgnd messages and this is where things got interesting.
I found that adding the wm_erasebkgnd handler caused the window screen to become white, no more red color. I tried three versions of wm_erasebkgnd and they all caused the program to break.
case WM_ERASEBKGND:{
break;return 0;return 1;}
It turned out that the default message handler was the problem. The default, created by code::blocks 17.12 looked like this:
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
Notice that DefWindowProc is NOT called after a WM_DESTROY message is received, as the break statement takes the program to the first line of code after the switch statement.
I created the same circumstance for myself by handling the wm_erasebkgnd message. Regardless what I did (break, return 0 or return 1) I never called DefWindowProc.
According to Microsoft, it is the wm_erasebkgnd message that causes DefWindowProc to erase the screen with the color specified in the wndclassex structure (hbrbackground).
I fixed my problem by changing the message handler to look like this:
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_PAINT:{
return 0; }
case WM_ERASEBKGND:{
break;
}
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
break; }
return DefWindowProc (hwnd, message, wParam, lParam); }
I hope this post helps someone else.