Proper sizing of single-line edit control.
How should I go about resizing a single-line edit control so that the client area's height is the same as the height of the font and perhaps padding by a pixel or two?
I tried to GetObject() the font and then apply the absolute value of the lfHeight member from the generated LOGFONT struct in a RECT to be used in a call to AdjustWindowRectEx() to compensate for the WS_EX_CLIENTEDGE exstyle.
However I feared that the lfHeight member probably wasn't in pixels (MSDN says it's in a "logical unit" format) and the result after finally calling SetWindowPos() wasn't what I wanted either.
The position of the edit control is intended to be at the bottom of the screen.
Here's the code I tried but with the unnecessary stuff removed so treat it as pseudocode:
Code:
HWND hwnd //parent
HWND input; //the edit control
const DWORD inputstyle, inputexstyle; //has the styles for the edit control
RECT ca; //client area
RECT r = {0, 0, 0};
HFONT font;
LOGFONT f;
GetClientRect(hwnd, &ca);
GetObject(font, sizeof(f), &f);
r.bottom = f.lfHeight < 0 ? -f.lfHeight : f.lfHeight;
AdjustWindowRectEx(&r, inputstyle, FALSE, inputexstyle);
SetWindowPos(input, NULL, 0, ca.bottom - r.bottom, ca.right, r.bottom, SWP_NOZORDER);
Like I said it's pseudocode so seemingly unitialized variables are actually initialized, I only had them declared to show their type.