Click here to Skip to main content
15,917,862 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I have created a CRichEditCtrl object and set its text mode as RTF
using m_oRichEditCtrl.SetTextMode(TM_RICHTEXT);

after that i set rtf text. now i want to re-position rich edit such that it fits to its content.

Is there any method which give me correct rect which fit the rtf text?
	m_oRichEditCtrl.Create(WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_READONLY/*|WS_DISABLED*/,CRect(0,0,0,0),this,12568);
	m_oRichEditCtrl.SetTextMode(TM_RICHTEXT);
     //RTF text "Hello" which is bold,italic and underline. Actually i am reading this text from file.
	CString strRTFText =L"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\sa200\sl276\slmult1\lang9\ul\b\i\f0\fs22 Hello\ulnone\b0\i0\par
}" ;
	CString strTmp2;
	int il = WideCharToMultiByte(CP_ACP,0,                           (LPCWSTR)strRTFText,strRTFText.GetLength(), (LPSTR)strTmp2.GetBufferSetLength(wcslen(strRTFText)), wcslen(strRTFText),NULL,NULL);
	
        strTmp2.ReleaseBufferSetLength(il);
	int iTextMode = m_oRichEditCtrl.SetTextMode(TM_RICHTEXT);
	m_oRichEditCtrl.SetWindowText(strTmp2);

        CDC * dc = m_oRichEditCtrl.GetDC();
        CString strRichEdit;
	m_oRichEditCtrl.GetWindowText(strRichEdit);
	CRect rcText(0,0,m_uWidth,0);// assume m_uWidth=500
        // DT_CALCRECT not working because its simply calculating using current font
	dc->DrawText(strRichEdit,&rcText,DT_CALCRECT|DT_EDITCONTROL);
Posted
Updated 20-Mar-12 1:25am
v2

1 solution

See the EN_REQUESTRESIZE notification [^] that can be handled by the parent window to adjust the size of the RichEdit control.
 
Share this answer
 
Comments
Bhavin Jagad 20-Mar-12 10:26am    
Thanks, Its perfect that i needed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900