主题:记事本程序
void CTest5View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetWindowRect(&rect);
CClientDC dc(this);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
if (0x0d == nChar)
{
m_maxLen=(dc.GetTextExtent(m_strLine).cy > m_maxLen? dc.GetTextExtent(m_strLine).cy:m_maxLen);
m_strLine.Empty();
m_OriPoint.y += tm.tmHeight;
}
else if (0x08 == nChar)
{
COLORREF cpre = dc.SetTextColor(dc.GetBkColor());
dc.TextOut(m_OriPoint.x, m_OriPoint.y, m_strLine);
m_strLine = m_strLine.Left(m_strLine.GetLength()-1);
dc.SetTextColor(cpre);
dc.TextOut(m_OriPoint.x, m_OriPoint.y, m_strLine);
if (dc.GetTextExtent(m_strLine).cx==0)
{
m_OriPoint.x += m_maxLen;
m_OriPoint.y=m_OriPoint.y-tm.tmHeight;
}
}
else
{
m_strLine += nChar;
}
CSize size=dc.GetTextExtent(m_strLine);
CPoint point;
point.x=m_OriPoint.x + size.cx;
point.y=m_OriPoint.y;
SetCaretPos(point);
dc.TextOut(m_OriPoint.x, m_OriPoint.y, m_strLine);
CView::OnChar(nChar, nRepCnt, nFlags);
}
想模仿写一个记事本程序,但不知道怎么删除上一行的,这里是如如果换行的话就初始化m_strLine为空,这样就找不到上一行的字符了,难道解决得方法只有把所有的输入字符都记录再m_strLine中吗?这样当有很多输入的时候不是需要很大的缓存??请赐教
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetWindowRect(&rect);
CClientDC dc(this);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
if (0x0d == nChar)
{
m_maxLen=(dc.GetTextExtent(m_strLine).cy > m_maxLen? dc.GetTextExtent(m_strLine).cy:m_maxLen);
m_strLine.Empty();
m_OriPoint.y += tm.tmHeight;
}
else if (0x08 == nChar)
{
COLORREF cpre = dc.SetTextColor(dc.GetBkColor());
dc.TextOut(m_OriPoint.x, m_OriPoint.y, m_strLine);
m_strLine = m_strLine.Left(m_strLine.GetLength()-1);
dc.SetTextColor(cpre);
dc.TextOut(m_OriPoint.x, m_OriPoint.y, m_strLine);
if (dc.GetTextExtent(m_strLine).cx==0)
{
m_OriPoint.x += m_maxLen;
m_OriPoint.y=m_OriPoint.y-tm.tmHeight;
}
}
else
{
m_strLine += nChar;
}
CSize size=dc.GetTextExtent(m_strLine);
CPoint point;
point.x=m_OriPoint.x + size.cx;
point.y=m_OriPoint.y;
SetCaretPos(point);
dc.TextOut(m_OriPoint.x, m_OriPoint.y, m_strLine);
CView::OnChar(nChar, nRepCnt, nFlags);
}
想模仿写一个记事本程序,但不知道怎么删除上一行的,这里是如如果换行的话就初始化m_strLine为空,这样就找不到上一行的字符了,难道解决得方法只有把所有的输入字符都记录再m_strLine中吗?这样当有很多输入的时候不是需要很大的缓存??请赐教