功能不完全,且有一个bug,原因未知
[cpp]
void CMFCTEXTView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CClientDC dc(this);
CFont font;
font.CreatePointFont(120,_T("微软雅黑"),NULL);
CFont *pOldFont=dc.SelectObject(&font);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
COLORREF clr=dc.SetTextColor(dc.GetBkColor());

switch(nChar)
{
case 0x0d:
m_strLine.Empty();
m_ptOrigin.y+=tm.tmHeight;
break;
case 0x08:
dc.TextOut(m_ptOrigin.x,m_ptOrigin.y,m_strLine);
m_strLine=m_strLine.Left(m_strLine.GetLength()-1);
break;
case 0x61:
m_strLine+=_T("a");
break;
case 0x62:
m_strLine+=_T("b");
break;
case 0x63:
m_strLine+=_T("c");
break;
case 0x64:
m_strLine+=_T("d");
break;
}
dc.SetTextColor(clr);

CSize sz=dc.GetTextExtent(m_strLine);
CPoint pt;
pt.x=m_ptOrigin.x+sz.cx;
pt.y=m_ptOrigin.y;
SetCaretPos(pt);
dc.TextOut(m_ptOrigin.x,m_ptOrigin.y,m_strLine);

dc.SelectObject(pOldFont);

CView::OnChar(nChar, nRepCnt, nFlags);
}

void CMFCTEXTView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
SetCaretPos(point);
m_strLine.Empty();
m_ptOrigin=point;

CView::OnRButtonDown(nFlags, point);
}
[/cpp]