Click here to Skip to main content
15,920,896 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello!

I try to add controls in a window, but graphic problems occur with my control. Well, I know that if I add control in a dialog window everithing is ok, but what about my case?

BUG 01
When the application start, background of groupbox is not good:
Bug 01
I solve it as follows:
// If this is TRUE, 1st problem is solved
if( FALSE ) {
    ShowWindow( hWnd, SW_MINIMIZE );
    ShowWindow( hWnd, SW_RESTORE );
}

Anyway, I do not like it, but it works

BUG 02
When size the window I see that:
Bug 02
I can not find a solution to this problem!

GOAL
This is what I want to achieve:
GOAL

This is the entire program ( VS2003, VS2008 compatible ):
C#
#include <windows.h>
#include <commctrl.h>

const char *ClsName = "cn_TestSize";
const char *WndName = "TestSize";

// GroupBox Control
HWND hWndGroup;
// GroupBox relative dimensions
#define MACRO_GB_CONTROL	30, rc.top + 5, rc.right - 60, 50

LRESULT CALLBACK WndProcedure( HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam ) {
	switch( Msg ) {
		case WM_CREATE:
			{
				RECT rc;

				// Get size of the window
				GetClientRect( hWnd, &rc );

				// GroupBox Control
				hWndGroup = CreateWindowEx( NULL, WC_BUTTON, "Group Box",
					WS_VISIBLE | WS_CHILD | BS_GROUPBOX, MACRO_GB_CONTROL,
					hWnd, 0, GetModuleHandle( 0 ), NULL );

				// If this is TRUE, 1st problem is solved
				if( FALSE ) {
					ShowWindow( hWnd, SW_MINIMIZE );
					ShowWindow( hWnd, SW_RESTORE );
				}
			}
			break;
		case WM_SIZE:
			{
				RECT rc;
				GetClientRect( hWnd, &rc );
				MoveWindow( hWndGroup, MACRO_GB_CONTROL, TRUE );
			}
			break;
		case WM_DESTROY:
			PostQuitMessage(WM_QUIT);
			break;
		default:
			return DefWindowProc( hWnd, Msg, wParam, lParam );
	}
	return FALSE;
}

INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) {
	MSG			Msg;
	WNDCLASSEX	WndClsEx;
	HWND		hWnd;

	ZeroMemory( &WndClsEx, sizeof( WNDCLASSEX ) );

	WndClsEx.cbSize        = sizeof( WNDCLASSEX );
	WndClsEx.style         = CS_HREDRAW | CS_VREDRAW;
	WndClsEx.lpfnWndProc   = WndProcedure;
	WndClsEx.hIcon         = LoadIcon( NULL, IDI_APPLICATION );
	WndClsEx.hCursor       = LoadCursor( NULL, IDC_ARROW );
	WndClsEx.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
	WndClsEx.lpszClassName = ClsName;
	WndClsEx.hInstance     = hInstance;
	WndClsEx.hIconSm       = LoadIcon( NULL, IDI_APPLICATION );

	RegisterClassEx( &WndClsEx );

	hWnd = CreateWindow( ClsName,WndName, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN ,
		10, 10, 400, 240, NULL, NULL, hInstance, NULL );

	ShowWindow( hWnd, SW_SHOWNORMAL );
	UpdateWindow( hWnd );

	while( GetMessage(&Msg, NULL, 0, 0) ) {
			TranslateMessage( &Msg );
			DispatchMessage( &Msg );
	}

	return (int)Msg.wParam;
}
</commctrl.h></windows.h>


I would be grateful if you could help me!
Posted
v2

Remove the WS_CLIPCHILDREN from your frame window style. Or call InvalidateRect( hWndGroup, 0, 1); on WM_SIZE.
Regards.
 
Share this answer
 
Comments
tc31415 11-Aug-11 16:09pm    
Thank you very mach!
Removing WS_CLIPCHILDREN remove all "bugs"!
It is left from a previous project probably...
InvalidateRect( hWndGroup, 0, 1); is not working.
Where, when and how are you handling the message when something on the control needs to be repainted (WM_PAINT)? The sizing problem should be solved if you invalidate (<a href="http://msdn.microsoft.com/en-us/library/dd145002(v=vs.85).aspx">InvalidateRect</a>) the client area on receiving a WM_SIZE message. You need to make sure before though that you are handling WM_PAINT correctly.

Regards,

—MRB
 
Share this answer
 
v2
Comments
tc31415 11-Aug-11 12:50pm    
Thanks for the reply!
I think it does not work. Before placing the issue, I tried many things.
I do not know how you imagine it to use WM_PAINT ( correctly ).

I tried this:
<pre>
case WM_SIZE:
{
RECT rc;
GetClientRect( hWnd, &rc );
InvalidateRect( hWnd, &rc, TRUE );
MoveWindow( hWndGroup, MACRO_GB_CONTROL, TRUE );
}
</pre>


I tried this, too:
<pre>
case WM_SIZE:
{
RECT rc;
InvalidateRect( hWnd, NULL, TRUE );
GetClientRect( hWnd, &rc );
MoveWindow( hWndGroup, MACRO_GB_CONTROL, TRUE );
}
</pre>

Still same problem... :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900