使用RichEdit有以下几点注意事项;
1、在应用程序的InitInstance()内要调用AfxInitRichEdit();
2、如果想让RichEdit在显示文本的时候能够自动换行,则需要将以下四个属性设置Horizontal Scroll, Multiline , Vertical Scroll, Want return 设置为true;
并且还要调用如下函数来对RichEdit进行初始化:
void CStartPage::SetRichEditAutoWrap()
{
HDC hdc = ::GetDC(m_ReInfo.m_hWnd);//m_ReInfo.GetDC();
m_ReInfo.SendMessage(EM_SETTARGETDEVICE,(WPARAM)hdc,0);
::ReleaseDC(m_ReInfo.m_hWnd, hdc);
}
其中m_ReInfo就是RichEdit;
3、如何在RichEdit内显示文本?可以调用如下函数:
其中m_ReInfo就是RichEdit
void CStartPage::ShowInfo(CString &info)
{
m_ReInfo.SetSel(0,-1);
CHARRANGE crPos;
m_ReInfo.GetSel(crPos);
if (crPos.cpMin != crPos.cpMax)
{
m_ReInfo.SetSel(crPos.cpMin, crPos.cpMax);
}
else
{
m_ReInfo.SetSel(crPos.cpMax, crPos.cpMax);
}
m_ReInfo.ReplaceSel(info);
}