//移动插入符,鼠标按下
void CView::OnLButtonDown(UINT nFlags,CPoint point)
{
SetCaretPos(point);//设置位置
m_strLine.empty();
m_ptOrigin =point;
}
//响应OnChar消息,退格和回车和其它按键
void CView::OnChar(UINT nChar,...)
{
CClientDC dc(this);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
if(0x0d == nChar) //回车
{
m_strLine.Empty();
m_ptOrigin.y += tm.tmHeight;
}
else if(0x08 == nChar) // 退格
{
COLORREF clr = dc.SetTextColor(dc.GetBkColor());
dc.TextOutW(m_ptOrigin.x, m_ptOrigin.y, m_strLine);
m_strLine = m_strLine.Left(m_strLine.GetLength()-1);
dc.SetTextColor(clr);
}
else //字符
{
m_strLine += nChar;
}
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);
}