# Child Window Background Doesn't Draw (Win32 C++)

This topic is 3274 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I have a another quick question about creating more then one window on a application. I'm trying to make a child window have a white background and every time I run it the child window's background color doesn't update with the window when its resizing or update at all with the color I want the background to be. Here is my register function:

bool Core::InitDockWindow(char* ClassName, WNDPROC Proc, LPCSTR Menu, HBRUSH bBackground,  HINSTANCE hInstance)
{

WNDCLASSEX	wc;
ZeroMemory(&wc, sizeof(wc));

//Window class for the main application parent window
wc.cbSize			= sizeof(wc);
wc.style			= 0;
wc.lpfnWndProc	=   Proc;
wc.cbClsExtra		= 0;
wc.cbWndExtra		= 0;
wc.hInstance		= hInstance;
wc.hIcon			= 0;
wc.hbrBackground	= (HBRUSH)(bBackground+1);
wc.lpszClassName	= ClassName;
wc.hIconSm		= 0;

if(RegisterClassEx(&wc) == 0){
return false;
}else{
return true;
}
}


I added the 1 in the "hbrBackground" because it seems to fix the problem, but it then turns the background color to something other then I want. Is there anyway to fix this? Thanks, Andrew.

##### Share on other sites
Quote:
 doesn't update with the window when its resizing

First, if you don't have access to a good Windows programming book, you should consider something like Programming Windows by Charles Petzold. It has a fairly thorough description of the WNDCLASS structure.

You don't set any style flags for your window class. In particular, CS_VREDRAW or CS_HREDRAW, so the window does not redraw on vertical or horizontal resizing.

Also, FYI, there's no reason to use WNDCLASSEX instead of WNDCLASS unless you want different icons for your window.

##### Share on other sites
Aw! Ok, thanks for the suggestions and help! I appreciate it! I'll look into that book more. It seems to have very good reviews. :)

##### Share on other sites
The fact that bBackground has type HBRUSH in Core::InitDockWindow is a little worrying. You're only meant to have to add one and cast to HBRUSH explicitly when assigning to hbrBackground if the value you're setting is a standard system color constant, like COLOR_BACKGROUND. These are just integer constants, and the +1 is needed so a NULL hbrBackground and one that has the system color with constant value 0 can be differentiated. If you're using a proper HBRUSH, there's no need for the +1.

That said, if you want a white background, regardless of the user's color settings, you probably want to want to use GetStockObject(WHITE_BRUSH) to set hbrBackground to.

Quote:
 Original post by BuckeyeYou don't set any style flags for your window class. In particular, CS_VREDRAW or CS_HREDRAW, so the window does not redraw on vertical or horizontal resizing.

Those flags make the entire window get repainted on a resize (smaller or larger), instead of just parts created by increasing the window's size. This might not always be desirable, especially to prevent flickering from occuring.

1. 1
2. 2
Rutin
21
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633742
• Total Posts
3013636
×