void CMouseDemo1View::OnSetFocus(CWnd* pOldWnd)
{
CView::OnSetFocus(pOldWnd);
// TODO: Add your message handler code here
CreateSolidCaret(2,15);//使用指定大小创建一个实心的黑色插入符
SetCaretPos(m_ptCaretPos);//设置插入符的位置
ShowCaret();//显示插入符
}
void CMouseDemo1View::OnKillFocus(CWnd* pNewWnd)
{
CView::OnKillFocus(pNewWnd);
// TODO: Add your message handler code here
m_ptCaretPos=GetCaretPos();
HideCaret();
DestroyCaret();
}
void CMouseDemo1View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CSize sizeTextBox;
CPoint pt=GetCaretPos();//获取插入符位置
HideCaret();//隐藏插入符
if(nChar==VK_RETURN)//换行
{
m_strMessage.Empty();
m_nLine++;
pt.y+=20;
pt.x=0;
}
else
{
m_strMessage+=static_cast<wchar_t>(nChar);
}
//获取用户输入字符并显示
CClientDC dc(this);
dc.TextOutW(0,m_nLine*20,m_strMessage);
sizeTextBox=dc.GetTextExtent((LPCTSTR)&nChar,1);
//移动插入符到新位置
pt.x+=sizeTextBox.cx;
SetCaretPos(pt);
ShowCaret();
CView::OnChar(nChar, nRepCnt, nFlags);
}