创建成员变量
在"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);
}
效果:
文本可随鼠标移动