Greetings all

I am wondering what is the correct way to size an edit control when processing the WM_SIZE message in it's parent. It is a single line edit control, What is the way to find out what it's height should be? I tried using GetTextMetric and using the value in TEXTMETRIC.tmHeight as the height of my edit window but the edit control is still sto small to hit the height of the font. Maybe there is a constant for the hieght of an edit control?
Posted on 2002-04-10 21:07:19 by Kudos
I find 20 to be a safe number, but i dont really get your question because i never use WM_SIZE for this. I simple place it as a setting when i create the window itself. :confused:

Posted on 2002-04-11 01:12:20 by NaN
Getting the font height is the right way to do it but you usually need to add some to handle the top and bottom of characters that go above and below the base line.

Have a look at the API "GetDialogBaseUnits" as well as this is usually used for the size reference of dialog boxes.

Posted on 2002-04-11 03:17:35 by hutch--
I've never had the need to resize an edit control either, but I'll take a guess at what's wrong.

I'm thinking that maybe TEXTMETRIC.tmHeight is given in point size, not pixel size. If that's the case then you'll have to convert to pixel height. GetDeviceCaps( hdc, LOGPIXELSY ) will give you pixels per inch.

If that's not the case then I'm thinking you might want to take the pixel height and add a few pixels to that value to compensate for any frame padding that the edit box might do.

Hope it helps.
Posted on 2002-04-11 03:22:56 by iblis
Thanx for all replies.
To just explain my reason for doing this, When My main window is resized I need to adjust the possition of the edit control using the width from lParam and a suitable height.
Posted on 2002-04-11 09:54:04 by Kudos
Assuming that the edit control starts out with the correct height then heres some code that might help you out...

Moving the edit to a new position and resizing:

local rc :RECT
<<in sizing code>>
invoke GetWindowRect, hEdit, ADDR rc
mov eax, rc.bottom
sub eax,
invoke SetWindowPos, hEdit, 0, x, y, lParam, eax, SWP_NOACTIVATE or SWP_NOZORDER

Where x & y is the new position.

Or, if you dont need to position it (just resize) modify SetWindowPos to:
invoke SetWindowPos, hEdit, 0, 0, 0, lParam, eax, SWP_NOACTIVATE or SWP_NOZORDER or SWP_NOMOVE

Posted on 2002-04-11 11:45:54 by Graebel