Resizing a child window

I'm creating a notepad, and I've created a child window in the size of the parent window (so the child fit the entire parent window) of text...
I want to resize the child window, if the user resize (with the mouse) the parent window, but nothing works for me :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void AddEditHandle(HWND hwnd) // Creating the text window
{
HWND Edit_Handle = NULL;

void AddEditHandle(HWND hwnd) // Creating the text window
{
	Edit_Handle = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", NULL, WS_CHILD | WS_VSCROLL | WS_HSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_LEFT | ES_MULTILINE |
	ES_WANTRETURN , 0, 0, 780, 560, hwnd, NULL, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);

	if (Edit_Handle == NULL)
		MessageBox(NULL, "Could not create edit control!", "Error", MB_OK | MB_ICONERROR);

	ShowWindow(Edit_Handle, SW_SHOW);
	SetFocus(Edit_Handle);
}


This function creates the child window (parent window is 600X800)....
It fits perfect, and looks like it should be.. but when I want to resize it, the child window doesnt move.. only the parent...

so I've added this code to WndProc :

1
2
3
4
5
case WM_SIZE:
		{
			MoveWindow(Edit_Handle, 0, 0, LOWORD(lParam), HIWORD(lParam), false);
		}
		break;


Though there is no change, the child window still doesnt move...


How can I fix this?

Thanks!

EDIT :

I had an error of 1400 using GetLastError, meaning of invalid handler...
Insted of delcaring the variable as static (I've initialized Edit_Handler inside WndProc) I've used it as a global variable, and now it works using this code :
1
2
3
4
5
6
		case WM_SIZE:
		{
			if(0 == MoveWindow(Edit_Handle, 0, 0, LOWORD(lParam), HIWORD(lParam), false))
				dwLastError = GetLastError(); // Getting errors
		}
		break;


Thanks for you'r help guys!
Last edited on
SetWindowPos() - http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545%28v=vs.85%29.aspx

Use that function in your parent windows' WM_SIZE message to resize the child window to whatever the parent's size is.
SetWindowPos() has several options about the position of the window like what window is on top of others, the x/y position, and the cx/cy size of the window. The toughest part is probably making sure that you have the correct uflag combination (you'll see if you check the msdn link).

Thanks for your comment, but I did use that in my parent window, though it didnt work, so I guess something in my code isnt right ?
Last edited on
So what's GetLastError is saying ? Did you bother to check ?


BTW, the second argument must not be NULL, as you do.
Topic archived. No new replies allowed.