I've always have difficulties calculating the sizes of windows. Now I know that I can use AdjustWindowRect() for it. But what to do if you want to resize a listview or a combobox? Especially wen the integral height styles are on.
With the combobox, I have a rather small combobox, with longer strings in it. I tried calculating the maximum string length (with GetTextExtentPoint32()), but you have to adjust the width for the borders. And I don't know how.
Also the calculation has to work with different font settings, and sometimes that's also hard.
With the height of the combobox I also had some difficulties, but I think I solved it with this calculation (but again, I don't know the border with or something, because I'm always 2 off, so I always add 2)
This is for 7 items in the list view section...
Is there a better way to do this? (and a general way to calculate text width? with border + margin)
GetWindowRect(GetDlgItem(hDlg, IDC_ONCE), &rCmbBox);
width = rCmbBox.right - rCmbBox.left;
height = SendDlgItemMessage(hDlg, IDC_ONCE, CB_GETITEMHEIGHT, 0 , 0);
height *= 7;
height += rCmbBox.bottom - rCmbBox.top + 2;
SetWindowPos(GetDlgItem(hDlg, IDC_ONCE) , NULL, 0, 0, width, height,
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);