02在普通视图窗口中实现键盘字符的输入

来源:互联网 发布:与人工智能有关的股票 编辑:程序博客网 时间:2024/06/13 21:46

ClientDC:客户区设备上下文

TextOut:将一个字符串写到指定位置

GetTextExtent:获取所选字体中指定字符串的高度和宽度

void CKeyInputView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) {// TODO: Add your message handler code here and/or call defaultif(nChar==13)//按下了回车键{//换行ptCharacter.x=0;ptCharacter.y=ptCharacter.y+25;}else{CClientDC dc(this);dc.TextOut(ptCharacter.x,ptCharacter.y,(LPCTSTR)&nChar);//输出显示字符CSize textsize;textsize=dc.GetTextExtent((LPCTSTR)&nChar);//获取当前字符大小//前进到下一个字符位置ptCharacter.x=ptCharacter.x+textsize.cx;}CView::OnChar(nChar, nRepCnt, nFlags);}


原创粉丝点击