Sign in to follow this  
ajm113

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

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.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground	= (HBRUSH)(bBackground+1);
	wc.lpszMenuName	= Menu;
	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 this post


Link to post
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 this post


Link to post
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 Buckeye
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.

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this