当文本模式为TM_RICHTEXT时,如何为CRichEditCtrl的CDC计算rect. [英] how to calculate rect for CRichEditCtrl's CDC when its text mode is TM_RICHTEXT.
本文介绍了当文本模式为TM_RICHTEXT时,如何为CRichEditCtrl的CDC计算rect.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友,
我创建了一个CRichEditCtrl
对象并将其文本模式设置为RTF
使用m_oRichEditCtrl.SetTextMode(TM_RICHTEXT);
之后,我设置rtf文本.现在我想重新定位丰富的编辑,使其适合其内容.
有什么方法可以给我正确的rtf文本吗?
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);
推荐答案
请参见EN_REQUESTRESIZE
通知[
See the EN_REQUESTRESIZE
notification [^] that can be handled by the parent window to adjust the size of the RichEdit control.
这篇关于当文本模式为TM_RICHTEXT时,如何为CRichEditCtrl的CDC计算rect.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文