在"C项目名View.h"里添加
private: int y; int x; CString m_ch;消息 onDraw
void CTest6View::onDraw(CDC* pDC)
{
CTest6Doc* pDoc = Getdocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CFont font;
font.CreatePointFont(300,"楷体");//字体格式大小设置
pDC->SelectObject(&font);//挂载
pDC->SetTextColor(RGB(255,0,0));//通过RGB设置颜色
pDC->TextOut(x,y,m_ch);
}
onChar
void CTest6View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
m_ch+=nChar;
this->Invalidate();
CView::OnChar(nChar, nRepCnt, nFlags);
}
onMouseMove
void CTest6View::onMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
x=point.x;
y=point.y;
m_ch="abc";
this->Invalidate();
CView::onMouseMove(nFlags, point);
}
效果:
文本可随鼠标移动



