And now a note on how to resize the daialog.
The first step is to tell windows that it should allow the dialog to be resized, this is done by adding the WS_THICKFRAME style when the window is created:
HWND WindowHandle = CreateWindow("WhateverClass", "Calc", WS_MINIMIZEBOX | WS_VISIBLE | WS_MAXIMIZEBOX | WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_THICKFRAME, 100, 100, 140, 245, NULL, NULL, InstanceHandle, 0);When the dialog is resized we want to resize the controls on it. To do this we must handle the WM_SIZE message send by windows when the dialog box is resized:
case WM_SIZE: OnSize(hwndDlg, LOWORD(lParam), HIWORD(lParam)); break;LOWORD(lParam) is the new width of the dialog box, HIWORD(lParam) is the height. OnSize is a function we must create.
In our case we will let the result listbox take up whatever space is left after the other controls has got there fair part. We will use the MoveWindow function to resize and move the controls:
void OnSize(HWND aMainWnd, int aWidth, int aHeight) { HWND Control; Control = GetDlgItem(aMainWnd, ResultListBoxId); MoveWindow(Control, 5, 60, aWidth - 10, aHeight - 140, FALSE); Control = GetDlgItem(aMainWnd, AddRadioId); MoveWindow(Control, 10, aHeight - 60, 50, 14, FALSE); Control = GetDlgItem(aMainWnd, SubRadioId); MoveWindow(Control, 60, aHeight - 60, 50, 14, FALSE); Control = GetDlgItem(aMainWnd, GroupBoxId); MoveWindow(Control, 5, aHeight - 80, aWidth - 10, 40, FALSE); Control = GetDlgItem(aMainWnd, ButtonId); MoveWindow(Control, 5, aHeight - 32, 75, 25, FALSE); }There is no easy ways to do this, just hard work.
It should be noted that a WM_SIZE message is send before the dialog box is shown for the first time, so the position specified for the controls when they were created is not used. This is not the case if you use DialogBox() to create the dialogbox.
We do not move or resize the edit boxes, we will let them stay in the upper left corner.
There is just one final thing to take care of, if the user makes the dialog very small, it will look a bit funny, and it will not be usable. We solve this problem by telling windows how small it should allow the application to be. This is done by handling the WM_GETMINMAXINFO message:
case WM_GETMINMAXINFO: { MINMAXINFO *MinMaxInfo = (MINMAXINFO *)lParam; MinMaxInfo->ptMinTrackSize.x = 140; MinMaxInfo->ptMinTrackSize.y = 230; break; }The complete code for the application can be found here.