Sizing window

I had created a window that contains several components (Edit, List View, Buttons, ...). I need to re-size and rearrange those components upon sizing the window. However, I don't know how and what is the best practice for this.

Thanks in advance of your advice and help
Regards,
Ahmad
You hevan't really given enough information...

Assuming you're talking about WinAPI programming rather than one of the GUI toolkits, then you need to handle WM_SIZE and reposition the child windows using MoveWindow or SetWindowPos.

(Some people use GetClientRect to find out the size of the main window; but the new size is actually passed as the lParam of the WM_SIZE message.)

If this was news to you, and you want to learn about WinAPI programming, then maybe you should check out Petzold's book, "Programming Windows" ??

Programming Windows, 5th Edition
http://www.charlespetzold.com/pw5/

Programming Windows is a tutorial for programmers wishing to write applications for Windows using the C programming language and the native Win32 application programming interface (API). Programs written using this book run under every version of Windows from Windows 95 through Windows XP and beyond. Knowledge of C is required.

If, on the other hand, you're using a GUI toolkit, you just might be lucky and have an automatic resizer you can use.

(You might even be able to find suitable automatic resizing code on the web, I don't know on any that I would trust; but then I've never really looked for it.)

Andy

WM_SIZE message
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632646%28v=vs.85%29.aspx

MoveWindow function
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633534%28v=vs.85%29.aspx

SetWindowPos function
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545%28v=vs.85%29.aspx
Last edited on
Sorry for the lack of information..

Anyway, my application is based on win API and I am already handling several window messages. So those are not new to me..
I tried to handle the WM_SIZE of the re-sized window, but I am not sure how to send this messages to all its children controls. Is there a way to loop over all its children controls in order to get their hWnd to be passed as 1st parameter in SendMessage macro?

Below is how I'm handling the WM_SIZE for the re-sized window:
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
long BsolFrmOnSize (BsolEventHandler::BsolEventArgs * eArgs_p) {
	int flg_v, width_v, hight_v, frmId_v;
	HWND ebhWnd_v, lvhWnd_v;

	width_v = LOWORD (eArgs_p->elParam);
	hight_v = HIWORD (eArgs_p->elParam);

	.
	. // code for debugging logs
	.

	frmId_v = GetWindowLong(eArgs_p->ehWnd, GWL_ID);

	// testing for a specific window ID. 
	// Here I must loop over all the controls related to this specific 
	// frmId but I dont know how to get their hWnd. I need it in a 
	// dynamic way and not by using hard-coded their IDs
	if (frmId_v = 3001) {
		ebhWnd_v = GetDlgItem (eArgs_p->ehWnd, 3002);
		lvhWnd_v = GetDlgItem (eArgs_p->ehWnd, 3003);

		if (lvhWnd_v != NULL && ebhWnd_v != NULL) {
			SendMessage(ebhWnd_v, eArgs_p->eMsg, eArgs_p->ewParam, eArgs_p->elParam);
			SendMessage(lvhWnd_v, eArgs_p->eMsg, eArgs_p->ewParam, eArgs_p->elParam);
		}
	}

	return BsolFrmOnDefaultMsg (eArgs_p);
}

Below is handling the WM_SIZE for the Edit control (I already had sub-classing for my controls)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
long BsolEdtBxOnSize (BsolEventHandler::BsolEventArgs * eArgs_p) {
	int width_v, hight_v, flg_v;
	char * msg_v;
	HWND ebhWnd_v;
	RECT * newRect = NULL;

	width_v = LOWORD (eArgs_p->elParam);
	hight_v = HIWORD (eArgs_p->elParam);

	.
	. // code for debugging logs
	.
	
	int frmId_V = GetWindowLong(eArgs_p->ehWnd, GWL_ID);

	//This macro didn't return values in the RECT *. The newRect is null
	Edit_GetRect(eArgs_p->ehWnd, newRect); 

	// Here I am just testing
	newRect->right = width_v - 20;
	Edit_SetRect(eArgs_p->ehWnd, newRect);

	return BsolEdtBxOnDefaultMsg(eArgs_p);
}


Thanks in advance for your help.
Regards,
Ahmad
You don't forward the WM_SIZE message on to the child windows. You use MoveWindow or SetWindowPos to resize them, as I mentioned in my last mail.

WM_SIZE is sent to a window to tell it what its new size is; not to ask it to resize. It will be sent to the child windows for you when you resize them (with MoveWindow or SetWindowPos.)

Andy
Last edited on
Andy..
Thanks for your update. I was confused in among the documentation of SetWindowPos..

Anyway, what I am trying to do is to re-size all the controls of the window upon re-sizing the window itself.
I don't know which message of the window been re-sized must be processed and what message or macro to use in order to alert all the window's controls (Edit, List View, etc) of the new size of their parent window so that they will be re-sized as well accordingly.
It would be appreciate if you can summarize the needed steps.

Regards,
Ahmad
It would be appreciate if you can summarize the needed steps.

Sorry, but I feel I've provided all the necessary information. See MSDN for further details.

Andy
Anyway thanks..

I am already referring to MSDN in most of the coding done till now.

As well as I applied what you explained and used MoveWindow to re-size the controls while processing the WM_SIZE of the parent window. But when I used SetWindowPos, i got really confused by the flags.

Regards,
Ahmad
Topic archived. No new replies allowed.