I really appreciate this, Tom, and will look it over as soon as I can.
I'm not sure if this helps or not, but here's some code I clipped out of
one of my classes. This one is only growing until it gets to the edge of
the parent window, but hopefully this will help you get the idea. This
code is called inside the EN_CHANGE or WM_CHAR handler.
CString str;
GetWindowText( str );
CWindowDC dc(this);
CFont *pFont = GetParent()->GetFont();
CFont *pFontDC = dc.SelectObject(pFont);
CSize size = dc.GetTextExtent(str);
dc.SelectObject(pFontDC);
size.cx += 5; // add some extra buffer
// Get client rect
CRect rect, rcParent;
GetClientRect(&rect);
GetParent()->GetClientRect(&rcParent);
// Transform rect to parent coordinates
ClientToScreen(&rect);
GetParent()->ScreenToClient(&rect);
// Check whether control needs to be resized
// and whether there is space to grow
if(size.cx > rect.Width()) {
if(size.cx + rect.left < rcParent.right)
rect.right = rect.left + size.cx;
else
rect.right = rcParent.right;
MoveWindow(&rect);
}
Tom
"SteveR" <srussell@removethisinnernet.net> wrote in message
news:%23sguxAYcHHA.4872@TK2MSFTNGP03.phx.gbl...
Thank you, Joe and Tom.
After doing some study, I am still at a loss as to how to proceed. Using
DrawText is something I do regularly to calculate dimensions of text
rectangles. However, if it's not asking too much, could someone list the
sequence of steps I would take to govern the size of my (CEdit) text box
according to the string length?
I have m_Edit as a CString. Do I need another variable to represent the
control as an object?
In my view:
CMsgDialog dlg;
dlg.m_Edit += strMessage;
// ??????????
if(dlg.DoModal() == IDOK)
Invalidate();
return dlg.m_Edit;
------------------------------------
"Tom Serface" <tom.nospam@camaswood.com> wrote in message
news:8BC4F903-8921-4BB0-BEDB-CE1581BA5C0A@microsoft.com...
To add to Joe's response, this might be useful information for you:
http://msdn2.microsoft.com/en-us/library/ms672117.aspx
Tom
"SteveR" <srussell@removethisinnernet.net> wrote in message
news:OYYQe%23LcHHA.3648@TK2MSFTNGP05.phx.gbl...
Is it difficult to have a CEdit control and its dialog grow according
to the length of the string in the control? I'm interested in using
such an arrangement for my error messages and would like it to fit my
messages.