Dynamic resizing
Hi,
I have an ATL control used to display text.
The control lives inside a CRichEditControl.
The problem is that the application needs to resize the control to fit
the text.
O solution I adopted is to call FieViewChange() inside of OnDraw, after
I calculate the text extent using DC passed as parameter
(CDC::GetTextExtent).
This allows the control to be redrawn inside the boundaries I specify
in the prev call of OnDraw.
So:
CMyComControl::OnDraw(...)
{
....
CRect rcTextSize = pDC->GetTextExtent( strText, nChars );
if( m_sizeNatural != rcTextSize )
{
m_sizeNatural = rcTextSize + some margins
FireViewChange(); //this will alow OnDraw to be called with
correct margins
}
....
}
However in some specific situations the application crashes. I couldn't
figure out why, but I discovered that removing FireViewChange() from
OnDraw solves the crash.
I believe that calling FireViewChange() inside OnDraw() may be tricky,
but this was the only way I could find to calculate m_sizeNatural
function of text extent (DC dependent).
Is there any other solutions to my problem?
Any comments on this are welcomed.
Thanks