void CMyView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CRect rect;
dc.GetClipBox(rect);
CSize size;
size=dc.GetTextExtent((LPCTSTR)&nChar);
pos.x+=size.cx;
if (pos.x>rect.Width()-10)
{
pos.y+=size.cy;
pos.x=10;
}
dc.TextOut(pos.x,pos.y,(LPCTSTR)&nChar);
CView::OnChar(nChar, nRepCnt, nFlags);
}
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CRect rect;
dc.GetClipBox(rect);
CSize size;
size=dc.GetTextExtent((LPCTSTR)&nChar);
pos.x+=size.cx;
if (pos.x>rect.Width()-10)
{
pos.y+=size.cy;
pos.x=10;
}
dc.TextOut(pos.x,pos.y,(LPCTSTR)&nChar);
CView::OnChar(nChar, nRepCnt, nFlags);
}
博客给出了CMyView类中OnChar函数的代码。该函数处理字符输入事件,通过CClientDC获取设备上下文,计算文本位置和大小,当文本超出显示区域时换行,最后输出字符并调用基类的OnChar函数。
165

被折叠的 条评论
为什么被折叠?



