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
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 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.)
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:
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)
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..
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.
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.