Article ID: 124315
Article Last Modified on 6/29/2004
void ResizeEdit(HWND hwndEdit, HFONT hNewFont)
{
HFONT hSysFont,
hOldFont;
HDC hdc;
TEXTMETRIC tmNew,
tmSys;
RECT rc;
int nTemp;
// Get the DC for the edit control.
hdc = GetDC(hwndEdit);
// Get the metrics for the system font.
hSysFont = GetStockObject(SYSTEM_FONT);
hOldFont = SelectObject(hdc, hSysFont);
GetTextMetrics(hdc, &tmSys);
// Get the metrics for the new font.
SelectObject(hdc, hNewFont);
GetTextMetrics(hdc, &tmNew);
// Select the original font back into the DC and release the DC.
SelectObject(hdc, hOldFont);
DeleteObject(hSysFont);
ReleaseDC(hwndEdit, hdc);
// Calculate the new height for the edit control.
nTemp = tmNew.tmHeight + (min(tmNew.tmHeight, tmSys.tmHeight)/2) +
(GetSystemMetrics(SM_CYEDGE) * 2);
// Re-size the edit control.
GetWindowRect(hwndEdit, &rc);
MapWindowPoints(HWND_DESKTOP, GetParent(hwndEdit), (LPPOINT)&rc, 2);
MoveWindow( hwndEdit,
rc.left,
rc.top,
rc.right - rc.left,
nTemp,
TRUE);
}
Keywords: kbhowto kbeditctrl KB124315