Window Maximize and Restore

I developed an application using Win API where I create wnd1 (main window) and wnd2 (child window) whose parent is wnd1.

When wnd2 (child Window) is maximized and I maximize or restore wnd1 (main window), wnd2 must be redrawn within the client area of its parent. This is not happening and I am not able to work it out.
I know I need to manipulate the massages processing of WM_SYSCOMMAND, however, I don't know how. So, if someone can list down the head lines to follow or recommend a link so I can refer to.

Regards,
Ahmad
This should happen automatically. Windows will invalidate the paint rect that needs redrawing and will send a WM_PAINT message. AFAIK the only way this will break is if you are either discarding the WM_PAINT message or incorrectly validating the dirty rect.

1) Are you calling ValidateRect anywhere? (You probably shoudn't be)
2) How are you doing the drawing for wnd2? Are you using the WM_PAINT message? (you should be)
3) In your WM_PAINT handler, how are you getting the drawing DC? Are you using BeginPaint/EndPaint? (You should be).
I am not validating nor invalidating any window or control. As well as I am not processing WM_PAINT in any place. Do I have to process WM_PAINT? Doesn't the OS must take care or painting, validating and invalidating the windows accordingly knowing I am not adding any special functionality to the drawing of my windows? Besides, I never noticed in any of MSDN documentation that I need to process this msg :)

Anyway, I am creating the windows using CreateWindowEx macro. However, I am suspecting the problem to be in wnd1 style or extended style but I am not able to locate the exact needed bit.

Below is a portion of my code showing the creating of the windows. In order to know the exact flow of the code, see below notes:
- Main Window, takes formFlg_p = 0. It is the parent of the other window.
- Window 1, takes formFlg_p = 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 .
 .
 .

void BsolWindow::BsolCreateWindowEx (BsolWindow * prntWnd_p, int formFlg_p, int wndId_p, 
				 LPCWSTR wndTitle_p, int x_p, int y_p, int width_p, int hight_p, 
				 LPVOID objPtr_p) {
wExStyle_v = WS_EX_APPWINDOW;

if (formFlg_p == 0) {
	wStyle_v = WS_CLIPCHILDREN 
		 | WS_OVERLAPPEDWINDOW 
		 | WS_VSCROLL
		 ;
}
// The window is a form window (child window)
else {
	// Set the parent window
	phWnd_v = prntWnd_p->hWnd;

	if (formFlg_p == 1) {
		wStyle_v = WS_CHILDWINDOW 
			 | WS_TILEDWINDOW 
			 | WS_OVERLAPPED 
			 ;
	}
	else if (formFlg_p == 2) {
		wStyle_v = WS_CHILDWINDOW 
			 | WS_OVERLAPPED 
			 | WS_SYSMENU 
			 | WS_CAPTION 
			 | WS_SIZEBOX 
			 ;
	}
}

this->hWnd = CreateWindowEx (wExStyle_v, this->wndClass.lpszClassName, 
				wndTitle_p, wStyle_v, x_p, y_p, width_p, hight_p, 
				phWnd_v, (HMENU)wndId_p, this->hInst, NULL);
 .
 .
 .


Thanks again.
Regards,
Ahmad
So the child window has controls/widgets and isn't just a typical blank window? That's a little outside my area... as I typically use dialogs for that. Don't know if I'll be able to help further =( Sorry.
Andy.. any idea about this?

Disch: Anyway thx for your efforts
Andy.. any idea about this?

Nope.

I assume, of course, that you are passing TRUE for bRepaint when the parent calls MoveWindow to resize its children in response to the WM_SIZE message. And that it's not getting through.

It might be time to fire up Spy++ to see what message are being send and to what window. Other than that,I can't add anymore as you're a bit too far off piste.

Andy

PS the style for your children has got a bit weird again, cf your earlier post
http://www.cplusplus.com/forum/windows/109913/#msg601616

Remember, a window cannot be a top-level overlapped window and a child at the same time. And tiled is the same as overlapped.


Last edited on
Thanks Andy..

Regarding the window styles, I had fixed it as below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 .
 .
 .

	// Parent window
	if (formFlg_p == 0) {
		wStyle_v = WS_CLIPCHILDREN 
			 | WS_OVERLAPPEDWINDOW 
			 | WS_VSCROLL
			 ;
	}
	// The window is a form window (child window)
	else {
		// Set the parent window
		phWnd_v = prntWnd_p->hWnd;

		if (formFlg_p == 1) {
			wStyle_v = WS_CAPTION
				 | WS_CHILDWINDOW 
				 | WS_CLIPSIBLINGS
				 | WS_SYSMENU 
				 | WS_THICKFRAME 
				 | WS_MINIMIZEBOX 
				 | WS_MAXIMIZEBOX 
				 ;
		}
		// The window is for LOV
		else if (formFlg_p == 2) {
			wStyle_v = WS_CHILDWINDOW 
				 | WS_SYSMENU 
				 | WS_CAPTION
				 | WS_CLIPSIBLINGS
				 | WS_SIZEBOX 
				 ;
		}
	}
 .
 .
 .


On the other hand, you mentioned:
I assume, of course, that you are passing TRUE for bRepaint when the parent calls MoveWindow to resize its children in response to the WM_SIZE message

Actually, I was not processing WM_SIZE of the parent window. However, now I processed it and I called MoveWindow macro to resize the child window but still this is not maximizing the child window. It just resize it. As well as, the child window must be redrawn only and only if it was maximized before resizing its parent. So what is the macro that I have to use to check if the child window is maximized?
Below is code of WM_SIZE of parent window:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  .
  .
  .
case WM_SIZE:
	frmId_v = 2001; // ID of child window. It is hard coded for testing purposes
	hWnd_v = BsolMSDN_GetDlgItem (hWnd_p, frmId_v, NULL);
	if (hWnd_v != NULL) {
		GetClientRect (hWnd_p, &rcWnd1_v);
		MoveWindow (hWnd_v, rcWnd1_v.left - 8, // I am subtracting 8 pixels because 
			rcWnd1_v.top - 8, 		// when the window is maximized, its 
			rcWnd1_v.right - rcWnd1_v.left + 16, // border must be hidden. What 
			rcWnd1_v.bottom - rcWnd1_v.top + 16, // shell I use instead of this 
			TRUE); 					// hard coding?
	}
	break;
  .
  .
  .


Thanks,
Ahmad
but still this is not maximizing the child window

I don't get what you mean: it's not resizing it big enough? Or is it that the WM_SIZE message is using SIZE_RESTORED rather than SIZE_MAXIMIZED?

child window must be redrawn only and only if it was maximized before resizing its parent.

Not sure why this is in bold??

So what is the macro that I have to use to check if the child window is maximized?

Macro???

There is the function IsZoomed()
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633531%28v=vs.85%29.aspx

And GetSysMetrics allows to query various system parameters
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724385%28v=vs.85%29.aspx

See MSDN entry for details: you have SM_CXEDGE, SM_CXFIXEDFRAME, ... and their Y counterparts to select from.

Andy
Last edited on
Topic archived. No new replies allowed.