请各位大哥帮我看看下面这一小段程序,谢谢!
请教:
这是一个小球在客户区运动的程序:
oid CEx09View::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// TODO: Add your specialized code here and/or call the base class
m_timer=SetTimer(1,500, NULL); //时间间隔为 0.5s
}
void CEx09View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
InvalidateRect(new CRect(pos.x-radius, pos.y-radius,pos.x+radius,pos.y+radius));
CRect rect;
GetClientRect(&rect);
pos.Offset(cxMove,cyMove);
if (pos.x + radius >= rect.right)
{
cxMove=-cxMove;
pos.x = rect.right - radius;
}
if (pos.x - radius <= 0 )
{
cxMove=-cxMove;
pos.x = radius;
}
if (pos.y + radius >= rect.bottom )
{
cyMove = - cyMove;
pos.y = rect.bottom - radius;
}
if (pos.y - radius <= 0)
{
cyMove = - cyMove;
pos.y = radius;
}
dc.SelectObject(new CBrush(HS_DIAGCROSS,RGB(255,0,0)));
dc.Ellipse(new CRect(pos.x-radius, pos.y-radius,pos.x+radius,pos.y+radius));
CView::OnTimer(nIDEvent);
}
向各位大哥请教几个问题:
问题1:
为什么不在 OnDraw() 函数中显示
问题2:
InvalidateRect(new CRect(pos.x-radius, pos.y-radius,pos.x+radius,pos.y+radius));
这句话有什么作用?
问题3:
CRect rect;
GetClientRect(&rect);
这两句话有什么作用?
问题4:
pos.Offset(cxMove,cyMove);
这句话是什么意思?
问题5:
dc.SelectObject(new CBrush(HS_DIAGCROSS,RGB(255,0,0)));
这句话是什么意思?HS_DIAGCROSS 是不是表示一个小圆圈?
问题6:
dc.Ellipse(new CRect(pos.x-radius, pos.y-radius,pos.x+radius,pos.y+radius));
这句话是什么意思?
谢谢!