//Move 函数
void CMyView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMyDoc *p=GetDocument();
p->p=point;
if(p->flag1%2==1){
p->p2=point;
}
CView::OnMouseMove(nFlags, point);
Invalidate(FALSE);
}
//左键点击函数
void CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMyDoc *p=GetDocument();
p->flag1 += 1;
if((p->flag1)%2==1){
p->p1 = point;
}
if((p->flag1)%2==0){
p->p2 = point;
p->flag1=0;
Invalidate(FALSE);
}
CView::OnLButtonDown(nFlags, point);
}
//onDraw 函数
void CMyView::OnDraw(CDC* pDC)
{
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CString s;
s.Format("x=%d,y=%d",pDoc->p.x,pDoc->p.y);
pDC->TextOut(10,10,s);
if(pDoc->mode==1){
pDC->Ellipse(pDoc->p1.x,pDoc->p1.y,pDoc->p2.x,pDoc->p2.y);
}
}
出现重影
我的想法是,如何再画出下一个图形时,删除上一个图形
刚学VC,学校只教了一周,希望大家点拨点拨
可以InvalidateRect() + UpdateWindow()组合拳