Here's some code you can play with - it's the closest I could get on a single-line edit control. Multiline edit controls may work better since they allow you to change the formatting rect. Hopefully this will give you a general idea of a way to do it :)
CString str = _T("Test Text");
// Get text extent
CFont *pFont = m_Edit1Edit.GetFont();
CWindowDC dc(this);
CFont *pOldFont = dc.SelectObject(pFont);
CSize TextSize = dc.GetTextExtent(str);
dc.SelectObject(pOldFont);
// Calculate the new size and resize the control
CRect WindowRect;
CRect ClientRect;
CRect FormatRect;
m_Edit1Edit.GetWindowRect(&WindowRect);
m_Edit1Edit.GetClientRect(&ClientRect);
m_Edit1Edit.GetRect(&FormatRect);
CSize BorderSize;
BorderSize.cx = WindowRect.Width() - FormatRect.Width();
BorderSize.cy = WindowRect.Height() - ClientRect.Height();
m_Edit1Edit.SetWindowPos(0, 0, 0, TextSize.cx + BorderSize.cx, TextSize.cy + BorderSize.cy, SWP_NOZORDER | SWP_NOMOVE);
// Set the control's text
m_Edit1Edit.SetWindowText(str);
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder